-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.js
45 lines (34 loc) · 1.04 KB
/
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
37
38
39
40
41
42
43
44
45
'use strict';
var crypto = require('crypto');
var ethUtils = require('ethereumjs-util');
var Wallet = function(pk) {
this.privateKey = pk.length == 32 ? pk : Buffer(pk, 'hex');
};
Wallet.generate = function() {
return new Wallet(crypto.randomBytes(32));
};
Wallet.prototype.getPrivateKey = function() {
return this.privateKey;
};
Wallet.prototype.getPrivateKeyString = function() {
return this.getPrivateKey().toString('hex');
};
Wallet.prototype.getPublicKey = function() {
return ethUtils.privateToPublic(this.privateKey);
};
Wallet.prototype.getPublicKeyString = function() {
return '0x' + this.getPublicKey().toString('hex');
};
Wallet.prototype.getAddress = function() {
return ethUtils.privateToAddress(this.privateKey);
};
Wallet.prototype.getAddressString = function() {
return '0x' + this.getAddress().toString('hex');
};
Wallet.prototype.getChecksumAddressString = function() {
return ethUtils.toChecksumAddress(this.getAddressString());
};
Wallet.fromPrivateKey = function(pk) {
return new Wallet(pk);
};
module.exports = Wallet;