Comments (4)
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.
Of course.
- hashToPrivateKey has no implementations in other libraries i'm aware of. It is exclusive to noble.
- 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.
- Pass random 64-char hex string to elliptic keyFromPrivate and to noble getPublicKey (as-is): you will see the same output.
from noble-secp256k1.
Of course.
- hashToPrivateKey has no implementations in other libraries i'm aware of. It is exclusive to noble.
- 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.
- Pass random 64-char hex string to elliptic keyFromPrivate and to noble getPublicKey (as-is): you will see the same output.
from noble-secp256k1.
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)
- Hex private keys should be more permissive. HOT 3
- Need a new function for a recovery(v) for HSM
- Upgrade to v2 causes etc.hmacSha256Sync not set HOT 1
- How do I initialize a Signature with the v2? HOT 3
- Non-https website don't have subtle property in window.crypto HOT 1
- 33bytes PK? (Migrating from curves => secp256k1) HOT 4
- Got Error [ERR_REQUIRE_ESM] on import HOT 1
- why secp256k1.utils.randomPrivateKey() produce a 32 bytes key? HOT 1
- Is it possible to use sha3_256 for secp256k1 HOT 2
- SyntaxError with @noble/secp256k1 in React Native 0.67.4 HOT 1
- How to encrypt a messege (in bytes) provided that a public key from backend? HOT 1
- Must use import to load ES Module HOT 2
- nodeCrypto is truthy when disabled HOT 6
- Backwards compatbility with secp256k1-node HOT 3
- 1.7.1: `Point.add` is not throwing for "1 + -1 == 0/Infinity" HOT 3
- Removed v2 code snippets HOT 4
- [doc] privateKeyTweakAdd and publicKeyTweakAdd for HD Wallets HOT 3
- Suggestion: Use globalThis.crypto instead of node crypto for cross-platform compatibility. HOT 2
- Generate seed phrase from private key 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 noble-secp256k1.