]> git.codecow.com Git - libnemo.git/commitdiff
Remove redundant Weierstrass curve object.
authorChris Duncan <chris@zoso.dev>
Wed, 3 Dec 2025 23:32:00 +0000 (15:32 -0800)
committerChris Duncan <chris@zoso.dev>
Wed, 3 Dec 2025 23:32:00 +0000 (15:32 -0800)
src/lib/crypto/secp256k1.ts

index 28804b244b000eed627b04bb58693ffe2ec2f0d7..683b37ab1ca8b7be58597c5f5674bb46bd9019d2 100644 (file)
@@ -33,16 +33,6 @@ type Signature = ReturnType<typeof Secp256k1.Signature>
 export type Bytes = Uint8Array<ArrayBuffer>
 /** Signature instance, which allows recovering pubkey from it. */
 export type RecoveredSignature = Signature & { recovery: number }
-/** Weierstrass elliptic curve options. */
-export type WeierstrassOpts<T> = 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<bigint> = {
-               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