Secp256k1SigningSession
A live signing session holding a secp256k1 private key. createSecp256k1SigningSession returns it.
Import
Section titled “Import”import type { type Secp256k1SigningSession = SigningSession & { readonly publicKey: Uint8Array<ArrayBuffer>; signDigest(digest32: Uint8Array): Promise<Secp256k1Signature>;}
secp256k1 signing session that can sign 32-byte digests until end is called.
Secp256k1SigningSession } from "@category-labs/mera";Members
Section titled “Members”publicKey
Section titled “publicKey”Uint8Array, 65 bytes, the uncompressed secp256k1 public key with the 0x04 prefix.
signDigest(digest32)
Section titled “signDigest(digest32)”Signs a 32-byte digest without prehashing it and resolves to a Secp256k1Signature: compact (64 bytes, r || s, low-S: s lies in the lower half of the curve order) plus recovery (0 or 1).
Zeroes the session-owned private-key copy and permanently ends the session; later signing throws SESSION_ENDED.
[Symbol.dispose]()
Section titled “[Symbol.dispose]()”Calls end, so a using declaration ends the session when its scope exits:
import { function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession
Creates a signing session from a secp256k1 private key.
createSecp256k1SigningSession } from "@category-labs/mera";
const const privateKey: Uint8Array<ArrayBuffer>
privateKey = var crypto: Crypto
crypto.Crypto.getRandomValues<Uint8Array<ArrayBuffer>>(array: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>
The Crypto.getRandomValues() method lets you get cryptographically strong random values.
getRandomValues(new var Uint8Array: Uint8ArrayConstructornew (length: number) => Uint8Array<ArrayBuffer> (+6 overloads)
Uint8Array(32));const const digest32: Uint8Array<ArrayBuffer>
digest32 = new var Uint8Array: Uint8ArrayConstructornew (length: number) => Uint8Array<ArrayBuffer> (+6 overloads)
Uint8Array(32);
{ using using session: Secp256k1SigningSession
session = function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession
Creates a signing session from a secp256k1 private key.
createSecp256k1SigningSession({ privateKey: Uint8Array<ArrayBufferLike>
Curve private key. Must be exactly 32 bytes and, for secp256k1, a valid
scalar.
privateKey }); await using session: Secp256k1SigningSession
session.function signDigest(digest32: Uint8Array): Promise<Secp256k1Signature>
Signs a 32-byte digest without prehashing it.
signDigest(const digest32: Uint8Array<ArrayBuffer>
digest32);} // ended hereErrors
Section titled “Errors”INPUT_INVALID:digest32is not 32 bytes.SESSION_ENDED:signDigestwas called afterend.
See also
Section titled “See also”- createSecp256k1SigningSession: creates the session from a private key.
- getEvmAddress: the address for
publicKey. - toViemAccount: a viem account backed by the session.
- Signing sessions: how a session owns the key, and the lifecycle.