- Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Apparently all the snippets I found use HDNode which results undefined in testing.
- Is solely using this package enough for this task? https://github.com/bitcoinjs/bip32
Also my xpub starts with zpub, was there any major change or is there any difference when working with it? zpub6nYqvTejCbqMTRTGz9rHkJnrJKbLsx36LqLnUJChDdJ6a5NA7hBumEpn9HTSDgWpNTNCponkPCBL5VKeAaScVxbXa1H4RPmA4j19rzgJPRp
Here are some of the codes I tested:
let bitcoin = require("bitcoinjs-lib"); function fromXpub(xpub, acctNumber, keyindex, callback){ let address = bitcoin.HDNode.fromBase58(xpub).derivePath(acctNumber+"/"+keyindex).getAddress(); callback(address); } let myxpub = "xpub6C6RXXtdbxSnfB78Y4WjJSjQuChKqHXh9JCZPeKtdGeWRiptL9oJePPtrYKPWaoem9W3Wvp8eEh8dFFuN7u4zT6x6A1H6D67bVVvufv3uJ1"; fromXpub(myxpub, 0, 0, function(cb){ console.log(cb); }); Is this here still up-to-date? #997
// on the server const bitcoin = require('bitcoinjs-lib') let address0FromXpub = bitcoin.HDNode.fromBase58('xpub6CBhr9A6hYbCH4S35uAoDVYcs31' + 'vMTwh9kaQ177ftZ6tVhWbFAov1C1ekKwu6KJ4Ydvdmp9cuDArAN9TUFpVjfJwZ9nqKMWcrmbzCcTSqU8') let key0 = address0FromXpub.derivePath("0/0").keyPair let address0 = address0FromXpub.derivePath("0/0").keyPair.getAddress() let address1 = address0FromXpub.derivePath("0/1").keyPair.getAddress() let address2 = address0FromXpub.derivePath("0/2").keyPair.getAddress() let address3 = address0FromXpub.derivePath("0/3").keyPair.getAddress() // '15a3JRVLot7dVgBqa1GcXwC7wx3yf4dw1P' // '1LUxjkAp1JzxPA3y8LV9PGFxqgPv9Rri1h' // '13LqgJGEzERsLLhx2WbjM5Z1dJBLgZbpD7' // '1CoE8VJVSbCzmzRDnpJ4iuSmPSg7ry3hMT' console.log(key0.toWIF()) // Error: Missing private key // at ECPair.toWIF (/home/linux/node_modules/bitcoinjs-lib/src/ecpair.js:122:22) Sidequestion:
- These generated public keys are the ones valid for 15 minutes?
- Further readings on these path derivations methods "/m/0/1"?
jackyzq and mmmilione