Comments (3)
version !== network.bip32.private
= "If version is not the private version."
&&
= "and"
version !== network.bip32.public
= "If version is not the public version."
In order words: "If version is not the public nor private version." which is correct.
The if statement later on is saying "If version IS the private version."
Are you trying to decode a Ypub or Zpub instead of an xpub? The default versions only support extended keys that start with xpub (public) and xprv (private)
from bip32.
of course! thanks!
from bip32.
@junderw I didn't want to open a new issue for this since there are many already on the subject.
It seems there's a nice way to pass in the correct version bytes. It could be really nice if bip32 included this function (maybe renamed to something better), since it's bip32 that consumes the output (rather than include it in bitcoinjs-lib). Let me know if you'd like me to open a PR. It does rely on bitcoinjs-lib's Network type, so, I think it could be best to place this code into a "contrib" directory, in order to avoid adding a dependency. It was really a pain getting to this point so I'm sure others would appreciate it...
// Thank you https://github.com/bitcoinjs/bitcoinjs-lib/issues/1238#issuecomment-426880691
const fixNetworkVersionBytes = (xkey: string, network: bitcoin.Network): string => {
let type = undefined;
if (xkey.slice(1, 4) == "prv") type = "private";
if (xkey.slice(1, 4) == "pub") type = "public";
if (type === undefined) throw new Error("Bad xkey prefix");
let data = b58.decode(xkey);
data = data.slice(4);
data = Buffer.concat([Buffer.from(network.bip32[type].toString(16).padStart(8, '0'),'hex'), data]);
return b58.encode(data);
};
from bip32.
Related Issues (20)
- Key Derivation Path HOT 1
- Path to derive grandchildren from children HOT 1
- Non-hardened keys have... private keys? HOT 1
- TypeError: BIP32Factory is not a function HOT 9
- Alternatives to tiny-secp256k1? HOT 11
- Improve usage with hw-app-eth keys HOT 4
- [ERROR] Digital envelope routines::unsupported HOT 7
- Buffer is not defined HOT 8
- TypeError: bip32.fromSeed is not a function HOT 7
- TypeError: bip32.fromSeed is not a function HOT 2
- Add support for other xpub versions (zpub & ypub) HOT 2
- Derivation path elements > 2147483647 should throw? HOT 3
- ecc.isPoint is not a function HOT 1
- Optional passphrase upon wallet generation HOT 1
- Serializing to Extended keys HOT 1
- How to use this version of bip32 to port some code? HOT 10
- "Invalid network version" when calling the toWIF() method on derived private key HOT 2
- Not able to run in browser HOT 1
- How to sign a message using ECDSA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bip32.