-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release #44
base: master
Are you sure you want to change the base?
Release #44
Conversation
himanshuchawla009
commented
Nov 4, 2024
- Move from elliptic to noble curves
- Remove buffer
fix tests
feat: replace elliptic with noble curves
@@ -1,6 +1,6 @@ | |||
{ | |||
"name": "@toruslabs/eccrypto", | |||
"version": "5.0.4", | |||
"version": "6.0.0-0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why -0
?
@@ -74,6 +72,6 @@ | |||
"npm": ">=9.x" | |||
}, | |||
"dependencies": { | |||
"elliptic": "^6.5.7" | |||
"@noble/curves": "^1.6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned, if we only use secp256k1
, we could use the more compact package @noble/secp256k1
package. See here for more details on the differences. not saying this is necessary (not sure how much package size this actually saves), but wanted to mention the option.
iv: Uint8Array; | ||
ephemPublicKey: Uint8Array; | ||
ciphertext: Uint8Array; | ||
mac: Uint8Array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are our other libraries fine with switching to Uint8Array
? Might incur a bit of work, but I guess at some point we would have to do that anyways.
|
||
const EC_GROUP_ORDER = Buffer.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", "hex"); | ||
const ZERO32 = Buffer.alloc(32, 0); | ||
const EC_GROUP_ORDER = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const EC_GROUP_ORDER = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); | |
const SECP256K1_GROUP_ORDER = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"); |
// XXX(Kagami): `elliptic.utils.encode` returns array for every | ||
// encoding except `hex`. | ||
return Buffer.from(ec.keyFromPrivate(privateKey).getPublic("array")); | ||
return secp256k1.getPublicKey(privateKey, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment.
also: does this return expected format? i remember elliptic was sometimes using 64 bytes pub key? while noble probably outputs 65 byte sec1.
// assert(Buffer.isBuffer(privateKeyA), "Bad private key"); | ||
// assert(Buffer.isBuffer(publicKeyB), "Bad public key"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above
export const derivePadded = async function (privateKeyA: Buffer, publicKeyB: Buffer): Promise<Buffer> { | ||
assert(Buffer.isBuffer(privateKeyA), "Bad private key"); | ||
assert(Buffer.isBuffer(publicKeyB), "Bad public key"); | ||
export const derivePadded = async function (privateKeyA: Uint8Array, publicKeyB: Uint8Array): Promise<Uint8Array> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does the same as derive
except for the last part (padding)? if so, derive
should call this function and just add the part where leading zeros are removed.
expect(Buffer.isBuffer(publicKey)).to.equal(true); | ||
expect(publicKey.toString("hex")).to.equal( | ||
"041b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f70beaf8f588b541507fed6a642c5ab42dfdf8120a7f639de5122d47a69a8e8d1" | ||
// expect(Buffer.isBuffer(publicKey)).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this do anything important? if not, just remove the whole line. no reason to leave the comment.
expect(Buffer.isBuffer(sig)).to.equal(true); | ||
expect(sig.toString("hex")).to.equal( | ||
"3044022078c15897a34de6566a0d396fdef660698c59fef56d34ee36bef14ad89ee0f6f8022016e02e8b7285d93feafafbe745702f142973a77d5c2fa6293596357e17b3b47c" | ||
// expect(Buffer.isBuffer(sig)).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
expect(Buffer.isBuffer(sig)).to.equal(true); | ||
expect(sig.toString("hex")).to.equal( | ||
"3044022078c15897a34de6566a0d396fdef660698c59fef56d34ee36bef14ad89ee0f6f8022016e02e8b7285d93feafafbe745702f142973a77d5c2fa6293596357e17b3b47c" | ||
// expect(Buffer.isBuffer(sig)).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
// expect(Buffer.isBuffer(sig)).to.equal(true); | |
// expect(Buffer.isBuffer(sig)).to.equal(true); |