From: Chris Duncan Date: Wed, 3 Dec 2025 23:32:00 +0000 (-0800) Subject: Remove redundant Weierstrass curve object. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=d4d07419ed03b79d52113a35c5954640654d9a9a;p=libnemo.git Remove redundant Weierstrass curve object. --- diff --git a/src/lib/crypto/secp256k1.ts b/src/lib/crypto/secp256k1.ts index 28804b2..683b37a 100644 --- a/src/lib/crypto/secp256k1.ts +++ b/src/lib/crypto/secp256k1.ts @@ -33,16 +33,6 @@ type Signature = ReturnType export type Bytes = Uint8Array /** Signature instance, which allows recovering pubkey from it. */ export type RecoveredSignature = Signature & { recovery: number } -/** Weierstrass elliptic curve options. */ -export type WeierstrassOpts = Readonly<{ - p: bigint - n: bigint - h: bigint - a: T - b: T - Gx: T - Gy: T -}> /** Point in 2d xy affine coordinates. */ export type AffinePoint = { x: bigint @@ -124,20 +114,10 @@ export class Secp256k1 { static N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n static h = 1n static a = 0n - static _b = 7n + static b = 7n static Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n static Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n - static CURVE: WeierstrassOpts = { - p: this.P, - n: this.N, - h: 1n, - a: 0n, - b: this._b, - Gx: this.Gx, - Gy: this.Gy, - } - static L: 32 = 32 // field / group byte length static L2: 64 = 64 static lengths: Secp256k1Lengths = { @@ -244,7 +224,7 @@ export class Secp256k1 { // ----------------- /** secp256k1 formula. Koblitz curves are subclass of weierstrass curves with a=0, making it x³+b */ - static koblitz = (x: bigint) => this.modP(this.modP(x * x) * x + this._b) + static koblitz = (x: bigint) => this.modP(this.modP(x * x) * x + this.b) /** assert is element of field mod P (incl. 0) */ static FpIsValid = (n: bigint) => this.bigintInRange(n, 0n, this.P) /** assert is element of field mod P (excl. 0) */ @@ -308,7 +288,7 @@ export class Secp256k1 { const { X: X1, Y: Y1, Z: Z1 } = { X, Y, Z } const { X: X2, Y: Y2, Z: Z2 } = other const a = 0n - const b = secp256k1.CURVE.b + const b = secp256k1.b const b3 = M(b * 3n) let X3 = 0n, Y3 = 0n, Z3 = 0n let t0 = M(X1 * X2), t1 = M(Y1 * Y2), t2 = M(Z1 * Z2), t3 = M(X1 + Y1) // step 1