From fbb74c5ab2b0b37fe55079c69e776d103463f7c8 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Thu, 8 Apr 2021 11:25:21 -0700 Subject: [PATCH] btc: fix issue with wallet generation from master ticket --- .../src/js/components/lib/walletModal.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkg/btc-wallet/src/js/components/lib/walletModal.js b/pkg/btc-wallet/src/js/components/lib/walletModal.js index f862aaec8..576bb4ba0 100644 --- a/pkg/btc-wallet/src/js/components/lib/walletModal.js +++ b/pkg/btc-wallet/src/js/components/lib/walletModal.js @@ -14,18 +14,22 @@ const bitcoin = require('bitcoinjs-lib'); const bs58check = require('bs58check') import { Buffer } from 'buffer'; - -function xpubToZpub(xpub) { +function bip44To84(network, xpub) { + var prefix = (network === 'bitcoin') ? '04b24746' : '045f1cf6'; + console.log('xpub', xpub); var data = bs58check.decode(xpub); data = data.slice(4); - data = Buffer.concat([Buffer.from('04b24746', 'hex'), data]); + data = Buffer.concat([Buffer.from(prefix, 'hex'), data]); return bs58check.encode(data); } -const BTC_DERIVATION_PATH = "m/84'/0'/0'" +const NETWORK = "testnet" // "bitcoin" +const DERIVATIONS = { + bitcoin: "m/84'/0'/0'/0", + testnet: "m/84'/1'/0'/0", +} const BTC_DERIVATION_TYPE = 'bitcoin' -// const NETWORK = bitcoin.networks.bitcoin -const NETWORK = bitcoin.networks.testnet +const BTC_DERIVATION_PATH = DERIVATIONS[NETWORK] export default class WalletModal extends Component { constructor(props) { @@ -65,19 +69,20 @@ export default class WalletModal extends Component { BTC_DERIVATION_PATH ); - const zpub = xpubToZpub( + const zpub = bip44To84(NETWORK, bitcoin.bip32.fromPublicKey( Buffer.from(node.keys.public, 'hex'), Buffer.from(node.keys.chain, 'hex'), - NETWORK + bitcoin.networks[NETWORK] ).toBase58() ); + console.log('zpub', zpub); + this.submitXPub(zpub); } submitXPub(xpub){ - console.log("xpub", xpub); const command = { "add-wallet": { "xpub": xpub,