Giter VIP home page Giter VIP logo

Comments (3)

junderw avatar junderw commented on June 3, 2024

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.

tempo-beme avatar tempo-beme commented on June 3, 2024

of course! thanks!

from bip32.

LeeKorbisCa avatar LeeKorbisCa commented on June 3, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.