Skip to content

Commit

Permalink
adds the wif field to the derive method
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-at-decenomy committed Oct 14, 2021
1 parent aa6c7e3 commit 0036b88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
12 changes: 10 additions & 2 deletions sandbox.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
11 changes: 7 additions & 4 deletions src/dsw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions ts_src/dsw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0036b88

Please sign in to comment.