From 5e6a55c93093181ed536cb6631e5153fc8ef7e39 Mon Sep 17 00:00:00 2001 From: Tracey Boydston Date: Wed, 9 Feb 2022 16:19:26 +0800 Subject: [PATCH] Added tests for xpub address generation with alternate interal/external(change) option. --- .gitignore | 4 +++- hdAddressGenerator.js | 2 +- package.json | 2 +- tests/coinTests.js | 20 +++++++++++++++++++- tests/coins/BTC.js | 7 +++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 40b878d..3f91c25 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -node_modules/ \ No newline at end of file +node_modules/ +test.js +.DS_Store \ No newline at end of file diff --git a/hdAddressGenerator.js b/hdAddressGenerator.js index f565898..fafc369 100644 --- a/hdAddressGenerator.js +++ b/hdAddressGenerator.js @@ -649,7 +649,7 @@ class AddressGenerator { /** * Checks if a coin has a test in the 'coins' folder. - * @param {sting} coinName Short name of the coin. + * @param {string} coinName Short name of the coin. */ coinHasTest(coinName){ diff --git a/package.json b/package.json index 3180a1d..db81aeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hdaddressgenerator", - "version": "1.0.7", + "version": "1.1.7", "description": "Generate hierarchical deterministic(HD) coin specific crypto addresses ( legacy, segwit, bech32 ) from single master key pair for over 190 different cryptocurrencies.", "main": "hdAddressGenerator.js", "scripts": { diff --git a/tests/coinTests.js b/tests/coinTests.js index d33bd56..be6e9e7 100644 --- a/tests/coinTests.js +++ b/tests/coinTests.js @@ -46,6 +46,7 @@ for (const coin in coinData) { let withExtPub44 = false let withExtPub49 = false let withExtPub84 = false + let withExtPub44Internal = false try{ bip44 = Gen.withMnemonic(settings.mnemonic,false,ref.shortName) } catch(e){} try{ bip44WithPassPhrase = Gen.withMnemonic(settings.mnemonic,settings.passphrase,ref.shortName,false) } catch(e){} @@ -60,8 +61,10 @@ for (const coin in coinData) { try{ bip141 = Gen.withMnemonicBIP141(settings.mnemonic,false,ref.shortName,"m/0'/0'","p2wpkhInP2sh") } catch(e){} try{ bip141seed = Gen.withSeedBIP141(settings.bip32Seed,ref.shortName,"m/0'/0'","p2wpkhInP2sh") } catch(e){} try{ withExtPub44 = Gen.withExtPub(ref.bip44AccountExtPubKey,ref.shortName ) } catch(e){} + try{ withExtPub44Internal = Gen.withExtPub(ref.bip44AccountExtPubKey,ref.shortName,44,0,1) } catch(e){} try{ withExtPub49 = Gen.withExtPub(ref.bip49AccountExtPubKey,ref.shortName,49 ) } catch(e){} - try{ withExtPub84 = Gen.withExtPub(ref.bip84AccountExtPubKey,ref.shortName,84 ) } catch(e){} + try{ withExtPub84 = Gen.withExtPub(ref.bip84AccountExtPubKey,ref.shortName,84 ) } catch(e){} + // Test root Keys if ( ref.bip32RootKeyBip44 != undefined ){ @@ -274,6 +277,21 @@ for (const coin in coinData) { }) } + if ( ref.bip44AccountExtPubKey !== undefined && ref.addressBip44index0 != undefined && ref.addressBip44index1 != undefined && ref.shortName == "BTC" ){ + it('Expect extPub generated address using internal option ( i.e. m/44\'/0\'/0\'/1/0 ) with addressBip44index0 and addressBip44index1 address and pub keys to match reference.', async () => { + + let addresses = await withExtPub44Internal.generate(2) + + assert.strictEqual(addresses[0].address,ref.addressBip44index0Internal) + assert.strictEqual(addresses[0].pubKey,ref.pubKeyBip44index0Internal) + assert.strictEqual(addresses[0].privKey,'') + assert.strictEqual(addresses[1].address,ref.addressBip44index1Internal) + assert.strictEqual(addresses[1].pubKey,ref.pubKeyBip44index1Internal) + assert.strictEqual(addresses[1].privKey,'') + + }) + } + if ( ref.bip49AccountExtPubKey !== undefined && ref.addressBip49index0 != undefined && ref.addressBip49index1 != undefined ){ it('Expect extPub generated address addressBip49index0 and addressBip49index1 address and pub keys to match reference.', async () => { diff --git a/tests/coins/BTC.js b/tests/coins/BTC.js index 174a6d0..b7b7937 100644 --- a/tests/coins/BTC.js +++ b/tests/coins/BTC.js @@ -32,6 +32,13 @@ module.exports = { pubKeyBip44EncryptedIndex0:"0430175f65585b898540016463ac077776b5da6e8dcfd18e086e3d5f9735293c4236e68d79975b57a124d434d9c0ff73bd726bc9286fb88c0e1e867c551c85edce", privKeyBip44EncryptedIndex0:"6PRVD9KM1EmjTZ2xrmg83qpeDoKnhxgJSsRJEUroWTViF1fkFzJXJz3GSq", + addressBip44index0Internal:"19TGQmBdTsS6ghQrkZs6b4LLuAMnLzNke8", + pubKeyBip44index0Internal:"037922ca607a670dbfc7108ae779d593b0fcd6436bc7887dad4fd138bd389c0337", + + addressBip44index1Internal:"1PT3h8jPVzisaEGSx4S9Xudpax7M6hX63U", + pubKeyBip44index1Internal:"03904cb21857450eb62eed84815bba65f895a8b4624ab451952e9acc5e663b016e", + + // BIP 49 Addresses addressBip49index0:"34Rqef93KR98XMaLneHEhzkr1kxaHg5AAA", pubKeyBip49index0:"0269c38d634710f8db4c543b62754abf5cc276b5227e81ef82be13ebfac7804d01",