From: Chris Duncan Date: Thu, 4 Dec 2025 17:26:04 +0000 (-0800) Subject: Remvoe unused Point methods. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=2a824bc4c4a5cd0c4aaaad4d92a9a54c7ab614a0;p=libnemo.git Remvoe unused Point methods. --- diff --git a/src/lib/crypto/secp256k1.ts b/src/lib/crypto/secp256k1.ts index dc6e05c..2451df6 100644 --- a/src/lib/crypto/secp256k1.ts +++ b/src/lib/crypto/secp256k1.ts @@ -19,13 +19,11 @@ type Point = { negate: () => Point double: () => Point add: (other: Point) => Point - subtract: (other: Point) => Point multiply: (n: bigint, safe?: boolean) => Point multiplyUnsafe: (scalar: bigint) => Point toAffine: () => AffinePoint assertValidity: () => Point toBytes: (isCompressed?: boolean) => Bytes - toHex: (isCompressed?: boolean) => string } /** Alias to Uint8Array. */ @@ -124,7 +122,6 @@ export class Secp256k1 { const r = a % b return r >= 0n ? r : b + r } - static modN = (a: bigint) => this.M(a, this.N) static modP = (a: bigint) => this.M(a, this.P) /** Modular inversion using eucledian GCD (non-CT). No negative exponent for now. */ @@ -152,9 +149,7 @@ export class Secp256k1 { /** assert is element of field mod N (excl. 0) */ static FnIsValidNot0 = (n: bigint) => this.bigintInRange(n, 1n, this.N) static isEven = (y: bigint) => (y & 1n) === 0n - /** create Uint8Array of byte n */ - static u8of = (n: number): Bytes => Uint8Array.of(n) - static getPrefix = (y: bigint) => this.u8of(this.isEven(y) ? 0x02 : 0x03) + static getPrefix = (y: bigint) => Uint8Array.of(this.isEven(y) ? 0x02 : 0x03) /** lift_x from BIP340 calculates square root. Validates x, then validates root*root. */ static lift_x (x: bigint) { // Let c = x³ + 7 mod p. Fail if x ≥ p. (also fail if x < 1) @@ -229,9 +224,6 @@ export class Secp256k1 { Z3 = M(Z3 + t0) // step 40 return secp256k1.Point(X3, Y3, Z3) }, - subtract (other: Point): Point { - return this.add(other.negate()) - }, /** * Point-by-scalar multiplication. Scalar must be in range 1 <= n < CURVE.n. * Uses {@link wNAF} for base point. @@ -283,11 +275,7 @@ export class Secp256k1 { const { x, y } = this.assertValidity().toAffine() const x32b = secp256k1.bigintTo32Bytes(x) if (isCompressed) return secp256k1.concatBytes(secp256k1.getPrefix(y), x32b) - return secp256k1.concatBytes(secp256k1.u8of(0x04), x32b, secp256k1.bigintTo32Bytes(y)) - }, - /** Converts bytes to hex string */ - toHex (isCompressed?: boolean): string { - return Array.from(secp256k1.abytes(this.toBytes(isCompressed))).map((e) => e.toString(16).padStart(2, '0')).join('') + return secp256k1.concatBytes(Uint8Array.of(0x04), x32b, secp256k1.bigintTo32Bytes(y)) } }) } @@ -420,7 +408,7 @@ export class Secp256k1 { * Any time `G.multiply` is done, precomputes are used. * * w-ary non-adjacent form (wNAF) precomputation method is 10% slower than windowed method, - * but takes 2x less RAM. RAM reduction is possible by utilizing `.subtract`. + * but takes 2x less RAM. RAM reduction is possible by utilizing subtraction. * * !! Precomputes can be disabled by commenting-out call of the wNAF() inside Point#multiply(). */