Comments (9)
Yeah, you can get these functions from there.
BTW, there's a full implementation in the link I copied above as an npm package ready to use and heavily tested:
https://github.com/bitcoinerlab/secp256k1
Let me know if I can help you somehow.
from noble-secp256k1.
Thanks. This should be adjusted then
from noble-secp256k1.
On the other hand, the current behavior was made on purpose. Why would you add an all-zero private key? It's certainly invalid in ECDH context, and in some others.
from noble-secp256k1.
On the other hand, the current behavior was made on purpose. Why would you add an all-zero private key? It's certainly invalid in ECDH context, and in some others.
I understand your point. It's more of an interoperability issue with ecpair. Not really a bug.
This issue concerns tweakUtils
which aren't exposed anyway.
I copied and adjusted tweakUtils
in my project with this little change. I just wanted to share this with you so you are aware.
BTW, in order to make noble-secp256k1 and ecpair work together, I also had to adjust tweakUtils functions (in fact, in the wrapper around them) so that they throw when the computed private key is zero.
Feel free to close the issue as this is more of a comment than a bug.
from noble-secp256k1.
@landabaso, I'm also trying to use this with HD wallet paths (to make a fully browser-compatible implementation).
What is "tweakUtils"? Whether I do a search for "tweakutils" on npm or "tweakutils secp256k1" on the web, I don't seem to get back any relevant results.
What privateAdd()
function are you referring to? I don't see it in the docs or code here or the ecpair repo.
Could you post a link to your implementation?
from noble-secp256k1.
For tweak utils, look into secp tests: they have the utils. It was part of the main pkg, then got removed because I think it has bad UX and it's just legacy of other libraries while here we have better primitives (Point).
For hdkey, take a look at scure/bip32.
from noble-secp256k1.
Could you post a link to your implementation?
I hope it helps @coolaj86: https://github.com/bitcoinerlab/secp256k1
from noble-secp256k1.
@landabaso I was able to get this to work with our APIs.
For anyone looking on, this is the code that's missing (i.e. for HD Wallets):
privateAdd
is known in other libraries asprivateKeyTweakAdd
pointAddScalar
is known in other libraries aspublicKeyTweakAdd
let tweakUtils = {
/**
* @param {Uint8Array} privateKey
* @param {Uint8Array} tweak
* @returns {Uint8Array} - a new (derivative) privateKey
*/
privateAdd: function (privateKey, tweak) {
const p = Secp256k1.utils._normalizePrivateKey(privateKey);
const t = Secp256k1.utils._normalizePrivateKey(tweak);
return Secp256k1.utils._bigintTo32Bytes(
Secp256k1.utils.mod(p + t, Secp256k1.CURVE.n),
);
},
/**
* @param {Uint8Array} p
* @param {Uint8Array} tweak
* @param {Boolean} [isCompressed]
* @returns {Uint8Array} - a new (derivative) publicKey
*/
pointAddScalar: function (p, tweak, isCompressed) {
const P = Secp256k1.Point.fromHex(p);
const t = Secp256k1.utils._normalizePrivateKey(tweak);
const Q = Secp256k1.Point.BASE.multiplyAndAddUnsafe(P, t, 1n);
if (!Q) {
throw new Error("Tweaked point at infinity");
}
return Q.toRawBytes(isCompressed);
},
};
Adapted from ./test/index.ts
:
Lines 466 to 492 in e125abd
This may need to be updated again for the upcoming major refactor.
from noble-secp256k1.
Thanks.
We're optimizing for the fewest dependencies and using only WebCrypto for both Web and node v18+.
(dropping node-crypto and <= node v16 entirely)
We have our own fork for a number of repos, as well as from-scratch rewrites, and the goal is that they should all work with CommonJS, ESM, Browsers, Node, and Bundlers without transpiling (adds about 5 lines of wrapper boilerplate per module).
We're preparing our "launch" of these tools for not this Monday, but the following Monday:
It's mostly just for our own community and our own tools - moving towards a fully vertically integrated model for a more optimized client experience and better developer experience - rather than so many half-baked, decade-old modules across so many ecosystems (hence @noble for secp256k1).
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
- What `xOnlyPointFromPoint()` equivalent would look like? HOT 1
- Signatures will randomly return as invalid. HOT 1
- 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
- Is this compatible with the elliptic package? 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.