Skip to content
Get startedGetting started →

Secp256k1SigningSession

A live signing session holding a secp256k1 private key. createSecp256k1SigningSession returns it.

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";

Uint8Array, 65 bytes, the uncompressed secp256k1 public key with the 0x04 prefix.

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.

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.

@paramoptions - Signing session inputs.

@returnsA live secp256k1 signing session.

@throwsMeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

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.

MDN Reference

getRandomValues
(new
var Uint8Array: Uint8ArrayConstructor
new (length: number) => Uint8Array<ArrayBuffer> (+6 overloads)
Uint8Array
(32));
const
const digest32: Uint8Array<ArrayBuffer>
digest32
= new
var Uint8Array: Uint8ArrayConstructor
new (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.

@paramoptions - Signing session inputs.

@returnsA live secp256k1 signing session.

@throwsMeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

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.

@paramdigest32 - The digest to sign.

@returnsA compact secp256k1 ECDSA signature with its recovery ID.

@throwsMeraError with code INPUT_INVALID when digest32 is not 32 bytes.

@throwsMeraError with code SESSION_ENDED after end has been called.

signDigest
(
const digest32: Uint8Array<ArrayBuffer>
digest32
);
} // ended here