diff --git a/sandbox.mjs b/sandbox.mjs index 54ab724..1e75e44 100644 --- a/sandbox.mjs +++ b/sandbox.mjs @@ -121,6 +121,11 @@ import { Bitcoin, BitcoinTestnet, Sapphire, Jackpot, Kyanite, ChangeType } from /* =============================== MultiWallet ============================= */ +/* wallet for testing + aa503ac1c0c1a312694aa1e8bc2dbfd8e5b1f9503b7fb677ca390af6fd44776157502533d4a3cd64055f44388366e1787512b0efcf020576111d5be53d1c2e79 + ozone top useful absent trash kitchen burst abandon rule trial truck donkey viable dice essence exile struggle hungry bicycle polar brand margin sorry hire +*/ + const bitcoin = new Bitcoin(bitcoinjs, bip39); const sapphire = new Sapphire(bitcoinjs, bip39); const kyanite = new Kyanite(bitcoinjs, bip39); @@ -154,6 +159,9 @@ console.log(sapp_address); const { xprv: kyan_xpriv } = kyanite.getXPriv(seed); console.log(kyan_xpriv); const kyan_account = kyanite.getWalletAccountXPub(kyan_xpriv, 0); -const { address: kyan_address } = kyanite.deriveFromAccount(kyan_account.xpub, ChangeType.EXTERNAL, 0); +console.log('KYAN'); console.log(kyan_account.xpub); -console.log(kyan_address); +for (let i = 0; i < 10; i++) { + console.log(kyanite.deriveFromAccount(kyan_account.xpub, ChangeType.EXTERNAL, i).address); + console.log(kyanite.derive(kyan_xpriv, 0, ChangeType.EXTERNAL, i)); +} diff --git a/src/dsw.js b/src/dsw.js index 526b8c8..047ced1 100644 --- a/src/dsw.js +++ b/src/dsw.js @@ -88,13 +88,16 @@ class DSW { const path = `m/44'/${this.COIN_TYPE}'/${account}'/${change}${ mobile ? '' : "'" }/${address_index}${mobile ? '' : "'"}`; + const node = this._bitcoinjs.bip32 + .fromBase58(xprv, this._network) + .derivePath(path); + const { publicKey } = node; + const wif = node.toWIF(); const { address } = this._bitcoinjs.payments.p2pkh({ - pubkey: this._bitcoinjs.bip32 - .fromBase58(xprv, this._network) - .derivePath(path).publicKey, + pubkey: publicKey, network: this._network, }); - return { path, address }; + return { path, address, wif }; } // m / purpose' / coin_type' / 0' / ECOMMERCE / address_index deriveEcommerce(xpub, address_index) { diff --git a/ts_src/dsw.ts b/ts_src/dsw.ts index 420374b..81d7dcc 100644 --- a/ts_src/dsw.ts +++ b/ts_src/dsw.ts @@ -54,8 +54,11 @@ export class DSW { throw new Error('invalid change type'); } const path = `m/44'/${this.COIN_TYPE}'/${account}'/${change}${mobile ? "" : "'"}/${address_index}${mobile ? "" : "'"}`; - const { address } = this._bitcoinjs.payments.p2pkh({ pubkey: this._bitcoinjs.bip32.fromBase58(xprv, this._network).derivePath(path).publicKey, network: this._network }); - return { path, address }; + const node = this._bitcoinjs.bip32.fromBase58(xprv, this._network).derivePath(path); + const { publicKey } = node; + const wif = node.toWIF(); + const { address } = this._bitcoinjs.payments.p2pkh({ pubkey: publicKey, network: this._network }); + return { path, address, wif }; } // m / purpose' / coin_type' / 0' / ECOMMERCE / address_index