]> git.codecow.com Git - libnemo.git/commitdiff
Deprecate single-use method and use directly.
authorChris Duncan <chris@zoso.dev>
Thu, 4 Dec 2025 05:34:04 +0000 (21:34 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 4 Dec 2025 05:34:04 +0000 (21:34 -0800)
src/lib/crypto/secp256k1.ts

index 7e66c8094ea302069a4b1ce7a94738e5f5cc0ed6..7dbff1783506d72953cbc40ce38c2d02478787b3 100644 (file)
@@ -31,14 +31,19 @@ type Signature = ReturnType<typeof Secp256k1.Signature>
 
 /** Alias to Uint8Array. */
 export type Bytes = Uint8Array<ArrayBuffer>
+
 /** Signature instance, which allows recovering pubkey from it. */
+
 export type RecoveredSignature = Signature & { recovery: number }
+
 /** Point in 2d xy affine coordinates. */
 export type AffinePoint = {
        x: bigint
        y: bigint
 }
+
 export type ECDSAExtraEntropy = boolean | Bytes
+
 /**
  * - `compact` is the default format
  * - `recovered` is the same as compact, but with an extra byte indicating recovery byte
@@ -46,6 +51,7 @@ export type ECDSAExtraEntropy = boolean | Bytes
  *   Switch to noble-curves if you need der.
  */
 export type ECDSASignatureFormat = 'compact' | 'recovered' | 'der'
+
 /**
  * - `prehash`: (default: true) indicates whether to do sha256(message).
  *   When a custom hash is used, it must be set to `false`.
@@ -53,20 +59,7 @@ export type ECDSASignatureFormat = 'compact' | 'recovered' | 'der'
 export type ECDSARecoverOpts = {
        prehash?: boolean
 }
-/**
- * - `prehash`: (default: true) indicates whether to do sha256(message).
- *   When a custom hash is used, it must be set to `false`.
- * - `lowS`: (default: true) prohibits signatures which have (sig.s >= CURVE.n/2n).
- *   Compatible with BTC/ETH. Setting `lowS: false` allows to create malleable signatures,
- *   which is default openssl behavior.
- *   Non-malleable signatures can still be successfully verified in openssl.
- * - `format`: (default: 'compact') 'compact' or 'recovered' with recovery byte
- */
-export type ECDSAVerifyOpts = {
-       prehash?: boolean
-       lowS?: boolean
-       format?: ECDSASignatureFormat
-}
+
 /**
  * - `prehash`: (default: true) indicates whether to do sha256(message).
  *   When a custom hash is used, it must be set to `false`.
@@ -127,8 +120,6 @@ export class Secp256k1 {
                seed: 48,
        }
 
-       // Helpers and Precomputes sections are reused between libraries
-
        // ## Helpers
        // ----------
        static err (message = ''): never {
@@ -153,11 +144,6 @@ export class Secp256k1 {
                return value
        }
 
-       /** converts bytes to hex string */
-       static bytesToHex (b: Bytes): string {
-               return Array.from(this.abytes(b)).map((e) => e.toString(16).padStart(2, '0')).join('')
-       }
-
        // ASCII characters
        static C = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 } as const
 
@@ -365,8 +351,9 @@ export class Secp256k1 {
                                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 secp256k1.bytesToHex(this.toBytes(isCompressed))
+                               return Array.from(secp256k1.abytes(this.toBytes(isCompressed))).map((e) => e.toString(16).padStart(2, '0')).join('')
                        }
                })
        }
@@ -401,6 +388,7 @@ export class Secp256k1 {
                // Validate point
                return p ? p.assertValidity() : this.err('bad point: not on curve')
        }
+
        static pointFromHex (hex: string): Point {
                return this.pointFromBytes(this.hexToBytes(hex))
        }