/** 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
* 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`.
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`.
seed: 48,
}
- // Helpers and Precomputes sections are reused between libraries
-
// ## Helpers
// ----------
static err (message = ''): never {
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
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('')
}
})
}
// Validate point
return p ? p.assertValidity() : this.err('bad point: not on curve')
}
+
static pointFromHex (hex: string): Point {
return this.pointFromBytes(this.hexToBytes(hex))
}