-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwallet.js
36 lines (30 loc) · 947 Bytes
/
wallet.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
// Import the ChainUtil class used for hashing and verification
const ChainUtil = require("./chain-util");
// Import transaction class used for creating transactions
const Transaction = require("./transaction");
class Wallet {
// The secret phase is passed an argument when creating a wallet
// The keypair generated for a secret phrase is always the same
constructor(secret) {
this.keyPair = ChainUtil.genKeyPair(secret);
this.publicKey = this.keyPair.getPublic("hex");
}
// Used for prining the wallet details
toString() {
return `Wallet -
publicKey: ${this.publicKey.toString()}`;
}
// Used for signing data hashes
sign(dataHash) {
return this.keyPair.sign(dataHash).toHex();
}
// Creates and returns transactions
createTransaction(data) {
return new Transaction(data, this);
}
// Return public key
getPublicKey() {
return this.publicKey;
}
}
module.exports = Wallet;