Skip to content
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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

Release #44

wants to merge 7 commits into from

Conversation

himanshuchawla009
Copy link
Member

  • Move from elliptic to noble curves
  • Remove buffer

@@ -1,6 +1,6 @@
{
"name": "@toruslabs/eccrypto",
"version": "5.0.4",
"version": "6.0.0-0",
Copy link
Member

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"
Copy link
Member

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.

Comment on lines +11 to +14
iv: Uint8Array;
ephemPublicKey: Uint8Array;
ciphertext: Uint8Array;
mac: Uint8Array;
Copy link
Member

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const EC_GROUP_ORDER = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
const SECP256K1_GROUP_ORDER = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");

Comment on lines 149 to +151
// 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);
Copy link
Member

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.

Comment on lines +223 to +224
// assert(Buffer.isBuffer(privateKeyA), "Bad private key");
// assert(Buffer.isBuffer(publicKeyB), "Bad public key");
Copy link
Member

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> {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Suggested change
// expect(Buffer.isBuffer(sig)).to.equal(true);
// expect(Buffer.isBuffer(sig)).to.equal(true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants