diff --git a/src.ts/utils/hdnode.ts b/src.ts/utils/hdnode.ts index ffd3e3a6..b1637535 100644 --- a/src.ts/utils/hdnode.ts +++ b/src.ts/utils/hdnode.ts @@ -19,7 +19,7 @@ import { toUtf8Bytes, UnicodeNormalizationForm } from './utf8'; import { pbkdf2 } from './pbkdf2'; import { computeHmac, SupportedAlgorithms } from './hmac'; import { defineReadOnly, isType, setType } from './properties'; -import { KeyPair } from './secp256k1'; +import { computeAddress, KeyPair } from './secp256k1'; import { sha256 } from './sha2'; const N = bigNumberify("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); @@ -54,6 +54,8 @@ export class HDNode { readonly privateKey: string; readonly publicKey: string; + readonly address: string; + readonly mnemonic: string; readonly path: string; @@ -81,6 +83,8 @@ export class HDNode { defineReadOnly(this, 'privateKey', this.keyPair.privateKey); defineReadOnly(this, 'publicKey', this.keyPair.compressedPublicKey); + defineReadOnly(this, 'address', computeAddress(this.publicKey)); + defineReadOnly(this, 'chainCode', hexlify(chainCode)); defineReadOnly(this, 'index', index); diff --git a/tests/test-hdnode.js b/tests/test-hdnode.js index a5f16a80..cdd8f871 100644 --- a/tests/test-hdnode.js +++ b/tests/test-hdnode.js @@ -22,6 +22,8 @@ describe('Test HD Node Derivation', function(test) { var wallet = new ethers.Wallet(node.privateKey); assert.equal(wallet.address.toLowerCase(), nodeTest.address, 'Generates address - ' + nodeTest.privateKey); + + assert.equal(node.address, (new ethers.Wallet(node)).address, 'HDNode address matches - ' + nodeTest.privateKey); }); }); });