Git Product home page Git Product logo

Comments (4)

jackson-dean avatar jackson-dean commented on June 20, 2024 1

Hey thanks for the quick response! Yea so I just got back around to playing with this again, and I was just misusing things. I am picking things up as I go, so bear with me if some of this is bone headed. In any case:

This works perfect.

const seedHex =
  "caf797541983d115976714b8fb33720439e0790a6186106016d427c128b4e7e3";

// elliptic key pair
const ec = new EC("secp256k1");
const ecKeys = ec.keyFromPrivate(seedHex);
const ecPublicKey = ecKeys.getPublic("hex");

const noblePublicKey = secp.getPublicKey(seedHex);

Also you're right about the too long hex string. This is how I actually ended up with that thing in my little testing script:

const mnemonic = bip39.generateMnemonic();
const seed = bip39.mnemonicToSeedSync(mnemonic); // produces 64 byte array (not 32)
const seedHex = secp.utils.bytesToHex(seed); // length 128

In such case where i've generated an invalid hex, you are also right, this does the trick. Though if I'm generating the seed hex properly in the first place its unnecessary:

secp.utils.mod(BigInt(`0x${seedHex}`), secp.CURVE.n)

Anyway, thanks again. Great lib. Life saver for crypto web/browser projects! I think this issue is sorted.

from noble-secp256k1.

paulmillr avatar paulmillr commented on June 20, 2024

Of course.

  1. hashToPrivateKey has no implementations in other libraries i'm aware of. It is exclusive to noble.
  2. caf797541983d115976714b8fb33720439e0790a6186106016d427c128b4e7e35e7f9dd8e2b0b8ccd08a50de574f9b6233e52fcec32a5bcd8e005e38f5dcd572 seems like invalid private key. secp private keys must be 256 bit, which is basically 32-byte uint8array, or 64-character hex string. Your test vector seems to have more chars. If elliptic can handle this private key, then elliptic is wrong and this is a bug.
  3. Pass random 64-char hex string to elliptic keyFromPrivate and to noble getPublicKey (as-is): you will see the same output.

from noble-secp256k1.

paulmillr avatar paulmillr commented on June 20, 2024

Of course.

  1. hashToPrivateKey has no implementations in other libraries i'm aware of. It is exclusive to noble.
  2. caf797541983d115976714b8fb33720439e0790a6186106016d427c128b4e7e35e7f9dd8e2b0b8ccd08a50de574f9b6233e52fcec32a5bcd8e005e38f5dcd572 seems like invalid private key. secp private keys must be 256 bit, which is basically 32-byte uint8array, or 64-character hex string. Your test vector seems to have more chars. If elliptic can handle this private key, then elliptic is wrong and this is a bug.
  3. Pass random 64-char hex string to elliptic keyFromPrivate and to noble getPublicKey (as-is): you will see the same output.

from noble-secp256k1.

paulmillr avatar paulmillr commented on June 20, 2024

Yeah, elliptic basically divides the key by modulus. You could do utils.mod(0x caf797541983d115976714b8fb33720439e0790a6186106016d427c128b4e7e35e7f9dd8e2b0b8ccd08a50de574f9b6233e52fcec32a5bcd8e005e38f5dcd572n, CURVE.n) and you'll get proper private key.

from noble-secp256k1.

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.