Added address to HDNode (#196).
This commit is contained in:
parent
71f781d542
commit
e39e2ed718
@ -19,7 +19,7 @@ import { toUtf8Bytes, UnicodeNormalizationForm } from './utf8';
|
|||||||
import { pbkdf2 } from './pbkdf2';
|
import { pbkdf2 } from './pbkdf2';
|
||||||
import { computeHmac, SupportedAlgorithms } from './hmac';
|
import { computeHmac, SupportedAlgorithms } from './hmac';
|
||||||
import { defineReadOnly, isType, setType } from './properties';
|
import { defineReadOnly, isType, setType } from './properties';
|
||||||
import { KeyPair } from './secp256k1';
|
import { computeAddress, KeyPair } from './secp256k1';
|
||||||
import { sha256 } from './sha2';
|
import { sha256 } from './sha2';
|
||||||
|
|
||||||
const N = bigNumberify("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
const N = bigNumberify("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
||||||
@ -54,6 +54,8 @@ export class HDNode {
|
|||||||
readonly privateKey: string;
|
readonly privateKey: string;
|
||||||
readonly publicKey: string;
|
readonly publicKey: string;
|
||||||
|
|
||||||
|
readonly address: string;
|
||||||
|
|
||||||
readonly mnemonic: string;
|
readonly mnemonic: string;
|
||||||
readonly path: string;
|
readonly path: string;
|
||||||
|
|
||||||
@ -81,6 +83,8 @@ export class HDNode {
|
|||||||
defineReadOnly(this, 'privateKey', this.keyPair.privateKey);
|
defineReadOnly(this, 'privateKey', this.keyPair.privateKey);
|
||||||
defineReadOnly(this, 'publicKey', this.keyPair.compressedPublicKey);
|
defineReadOnly(this, 'publicKey', this.keyPair.compressedPublicKey);
|
||||||
|
|
||||||
|
defineReadOnly(this, 'address', computeAddress(this.publicKey));
|
||||||
|
|
||||||
defineReadOnly(this, 'chainCode', hexlify(chainCode));
|
defineReadOnly(this, 'chainCode', hexlify(chainCode));
|
||||||
|
|
||||||
defineReadOnly(this, 'index', index);
|
defineReadOnly(this, 'index', index);
|
||||||
|
@ -22,6 +22,8 @@ describe('Test HD Node Derivation', function(test) {
|
|||||||
var wallet = new ethers.Wallet(node.privateKey);
|
var wallet = new ethers.Wallet(node.privateKey);
|
||||||
assert.equal(wallet.address.toLowerCase(), nodeTest.address,
|
assert.equal(wallet.address.toLowerCase(), nodeTest.address,
|
||||||
'Generates address - ' + nodeTest.privateKey);
|
'Generates address - ' + nodeTest.privateKey);
|
||||||
|
|
||||||
|
assert.equal(node.address, (new ethers.Wallet(node)).address, 'HDNode address matches - ' + nodeTest.privateKey);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user