/** Number to 32b. Must be 0 <= num < 2²⁵⁶. validate, pad, to bytes. */
static bigintTo32Bytes (num: bigint): Bytes {
- return this.hexToBytes(this
- .bigintInRange(num, 0n, 2n ** 256n) // secp256k1 is weierstrass curve. Equation is x³ + ax + b.
- .toString(16)
- .padStart(this.L2, '0')
- )
+ this.bigintInRange(num, 0n, 2n ** 256n) // secp256k1 is weierstrass curve. Equation is x³ + ax + b.
+ let len = this.L, bytes = new Uint8Array(len)
+ for (let i = len - 1; i >= 0; i--) {
+ bytes[i] = Number(num & 0xffn)
+ num >>= 8n
+ }
+ return bytes
}
/** Normalize private key to scalar (bigint). Verifies scalar is in range 1<s<N */