-
Notifications
You must be signed in to change notification settings - Fork 0
/
Univers.js
38 lines (31 loc) · 1.19 KB
/
Univers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Voici notre Wallet
const crypto = require('crypto');
const { Creation } = require('./Creation');
const { Molecule } = require('./Molecule');
class Univers {
constructor() {
//On indique les formats utilisés
const keys = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {type: 'spki', format: 'pem'},
privateKeyEncoding: {type: 'pkcs8', format: 'pem'},
});
this.privateKey = keys.privateKey,
this.publicKey = keys.publicKey
}
// Pour envoyer nos composants dans d'autres univers (wallets) sur le réseau :
send(amount, recieverPublicKey) {
const transaction = new Creation(
amount,
this.publicKey,
recieverPublicKey
);
const shaSign = crypto.createSign('SHA256');
shaSign.update(transaction.toString()).end();
// Signature avec la clef privée
const signaturePrivee = shaSign.sign(this.privateKey);
//Ajout dans notre molécule (chaîne)
Molecule.instance.insertAtome(transaction, this.publicKey, signaturePrivee);
}
}
module.exports = { Univers };