-
-
Notifications
You must be signed in to change notification settings - Fork 11
chore: update deps #175
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
base: master
Are you sure you want to change the base?
chore: update deps #175
Conversation
|
Warning MetaMask internal reviewing guidelines:
Ignoring alerts on:
|
… related functions
…tils, and metadataUtils
…eplacing BN with bigint and enhancing encoding/decoding methods
…lass for improved type consistency and utility functions
|
@cursor review |
|
Skipping Bugbot: Bugbot is disabled for this repository |
|
@cursor review |
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.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
|
@SocketSecurity ignore npm/@isaacs/brace-expansion@5.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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
|
@cursor can you do a review? please don't push any commits |
|
Based on the PR comments and code review, here are my findings: Code Review Summary1. CODEOWNERS File Location ✅ RESOLVEDThe CODEOWNERS file is correctly placed at 2. Code Splitting Improvements (common.ts lines 63, 76) if (keyType === KEY_TYPE.SECP256K1) {
return secp256k1.utils.randomSecretKey();
} else if (keyType === KEY_TYPE.ED25519) {
return ed25519.utils.randomSecretKey();
}
throw new Error(`Invalid keyType: ${keyType}`);Issue: Direct imports of Recommendation: Consider refactoring to pass the curve instance as a parameter where possible, allowing consumers to import only the curves they need. 3. Potential API Duplication (common.ts line 163)export function encParamsBufToHex(encParams: Ecies): EciesHex {
return {
iv: bytesToHex(encParams.iv),
ephemPublicKey: bytesToHex(encParams.ephemPublicKey),
ciphertext: bytesToHex(encParams.ciphertext),
mac: bytesToHex(encParams.mac),
mode: "AES256",
};
}
export function encParamsHexToBuf(eciesData: Omit<EciesHex, "ciphertext">): Omit<Ecies, "ciphertext"> {
return {
ephemPublicKey: hexToBytes(eciesData.ephemPublicKey),
iv: hexToBytes(eciesData.iv),
mac: hexToBytes(eciesData.mac),
};
}Question: These conversion utilities may already exist in 4. API Abstraction (keyUtils.ts line 180)export function derivePubKey(ecCurve: Curve, sk: bigint): Point2D {
return ecCurve.Point.BASE.multiply(sk).toAffine();
}Good Practice: While this is correct, the manual
5. Type Strictness - BigIntString UsageMultiple reviewers suggested tightening type constraints: Share.ts constructor: constructor(shareIndex: BigIntString, share: BigIntString) {
this.share = toBigIntBE(share);
this.shareIndex = toBigIntBE(shareIndex);
}Polynomial.ts generateShares: generateShares(shareIndexes: BigIntString[]): ShareMap {
const newShareIndexes = shareIndexes.map((index) => {
if (typeof index === "number") {
return BigInt(index);
}
if (typeof index === "bigint") {
return index;
}
if (typeof index === "string") {
return toBigIntBE(index);
}
return index;
});Recommendation: Consider this refactoring approach:
Benefits:
6. Type Casting Concerns (nodeUtils.ts line 747) sessionTokensResolved.forEach((x, index) => {
if (!x || !sessionSigsResolved[index]) sessionTokenData.push(undefined);
else
sessionTokenData.push({
token: bytesToBase64(x as Uint8Array),
signature: bytesToHex(sessionSigsResolved[index] as Uint8Array),
node_pubx: (completedRequests[index] as JRPCResponse<ShareRequestResult>).result.node_pubx,
node_puby: (completedRequests[index] as JRPCResponse<ShareRequestResult>).result.node_puby,
});
});Issue: The Recommendation: Since there's already a null check ( token: bytesToBase64(x), // Remove 'as'
signature: bytesToHex(sessionSigsResolved[index]), // Remove 'as'If type errors occur, fix the promise array typing rather than casting away the problem. Overall AssessmentThe migration from
These are refinements rather than blockers. The changes are architecturally sound and achieve the stated modernization goals. |
ieow
left a comment
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.
Buffer.from still being used in torus.ts
|
rename all places Buffer is used with bytes |
|
Most of the places don't need keccak256 in hex. It's causing double conversions where you convert hash to hex and hex back to bytes/bigint |
|
@cursor address all comments and create a new branch and push fixes there |
|
❌ Unable to add follow-up after multiple attempts. The agent may be experiencing issues. Please try again later or Open in Web to view the status. Learn more about Cursor Agents |
| export const getSecp256k1 = () => secp256k1; | ||
| export const getEd25519 = () => ed25519; |
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.
still don't get why we do this? Why don't we simply reference the object as a constant? (without calling a function)
|
|
||
| import { TorusUtilsExtraParams } from "./TorusUtilsExtraParams"; | ||
|
|
||
| export type Point2D = { x: bigint; y: bigint }; |
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.
could be renamed to AffinePoint, which is the technical term in the context of elliptic curves.
| const evmAddressLower = `0x${keccak256(Buffer.from(publicKey, "hex")).slice(64 - 38)}`; | ||
| const uncompressed = getSecp256k1().Point.fromAffine(point).toBytes(false); | ||
| const publicKey = uncompressed.slice(1); // remove 04 prefix | ||
| const evmAddressLower = `0x${keccak256(publicKey).slice(64 - 38)}`; |
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.
could have a dedicated function for this.


Motivation and Context
Jira Link
https://consensyssoftware.atlassian.net/browse/W3APD-5248
Description
Stack upgrade:
Summary
elliptic,bn.js,Buffer) with modern alternatives (@noble/curves, nativebigint,Uint8Array) across the entire codebase for improved security, bundle size, and ESM compatibility.@toruslabs/constantsv16,@toruslabs/eccryptov7,@toruslabs/http-helpersv9,vitestv4,typescriptv5.9, and more.sourceandauthorizationServerUrlas new optional parameters toTorusCtorOptions.Change Patterns
Crypto Library Migration
new EC("secp256k1")/new EC("ed25519")→secp256k1/ed25519from@noble/curvesecCurve.keyFromPrivate(sk).getPublic()→ecCurve.Point.BASE.multiply(sk).toAffine()ecCurve.keyFromPublic({x, y})→ecCurve.Point.fromAffine({x, y})ecCurve.genKeyPair().getPrivate()→ecCurve.utils.randomSecretKey()ecCurve.n→ecCurve.Point.CURVE().necCurve.sign(msg, key)→secp256k1.sign(msg, key, { prehash: false })Data Type Replacements
BN→bigint(all arithmetic uses native operators +mod()/invert()from@noble/curves/abstract/modular)new BN(x, "hex")→toBigIntBE(x)bn.toString("hex", 64)→bigintToHex(bn)bn.add/sub/mul/umod→+/-/*/mod()bn.invm(n)→invert(bn, n)bn.cmp(other)→ native comparison operators (===,<,>)Buffer → Uint8Array
Buffer.from(hex, "hex")→hexToBytes(hex)buffer.toString("hex")→bytesToHex(bytes)Buffer.from(str, "utf8")→utf8ToBytes(str)(viaTextEncoder)buffer.toString("base64")→bytesToBase64(bytes)(viabtoa)Buffer.from(b64, "base64")→base64ToBytes(b64)(viaatob)Buffer.concat([...])→concatBytes(...)Buffer.from(keccakHash(...))→bytesToHex(keccakHash(...))Type Definitions
ECtype →Curve(typeof secp256k1 | typeof ed25519)BNString→BigIntString(string | bigint)curve.base.BasePoint→Point2D({ x: bigint; y: bigint })Edge Case Handling
0nscalar inPoint.multiply()(noble-curves rejects zero scalar)secp256k1.sign()called with{ prehash: false }to avoid double-hashingBreaking Changes
BN→bigintin all public APIs (Point,Share,Polynomial, utility functions)Buffer→Uint8Arrayin all public APIsEC→Curvetype for curve parametersellipticandbn.jsremoved from dependenciesTypes of changes
Checklist
Note
Low Risk
Only repo configuration/documentation changes (code ownership, tooling ignores, and Node version baseline) with no runtime/library logic changes.
Overview
Adds a
.github/CODEOWNERSfile to enforce review ownership, with admin fallback ownership and separate owners forsrc/andtest/.Updates
.nvmrcto require Node>=24.xand adjustseslint.config.mjsto ignoredist/**andbabel.config.js, plus disablesimport/no-extraneous-dependenciesundertest/**(and removes the README’s UMD build mention).Written by Cursor Bugbot for commit b114b3d. This will update automatically on new commits. Configure here.