createSecp256k1SigningSession
Creates a signing session from a secp256k1 private key.
Import
Section titled “Import”import { function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession
Creates a signing session from a secp256k1 private key.
createSecp256k1SigningSession } from "@category-labs/mera";import { function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession
Creates a signing session from a secp256k1 private key.
createSecp256k1SigningSession, function getEvmAddress(publicKey: Uint8Array): EvmAddress
Derives the EIP-55 checksummed EVM address for a secp256k1 public key.
getEvmAddress,} 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);
const const 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 });
const const address: `0x${string}`
address = function getEvmAddress(publicKey: Uint8Array): EvmAddress
Derives the EIP-55 checksummed EVM address for a secp256k1 public key.
getEvmAddress(const session: Secp256k1SigningSession
session.publicKey: Uint8Array<ArrayBuffer>
65-byte uncompressed secp256k1 public key for the session.
publicKey);const { const compact: Uint8Array<ArrayBuffer>
Compact 64-byte r || s ECDSA signature.
compact, const recovery: 0 | 1
Recovery ID (the y-parity bit).
recovery } = await const session: Secp256k1SigningSession
session.function signDigest(digest32: Uint8Array): Promise<Secp256k1Signature>
Signs a 32-byte digest without prehashing it.
signDigest(const digest32: Uint8Array<ArrayBuffer>
digest32);
const session: Secp256k1SigningSession
session.function end(): void
Zeroes the session-owned private-key copy; later signing throws
SESSION_ENDED.
end();Parameters
Section titled “Parameters”options is a CreateSigningSessionOptions.
options.privateKey
Section titled “options.privateKey”- Type:
Uint8Array - Required
secp256k1 private key. Must be exactly 32 bytes and a valid scalar, an integer inside the curve’s private-key range.
Returns
Section titled “Returns”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";
type type ReturnType = SigningSession & { readonly publicKey: Uint8Array<ArrayBuffer>; signDigest(digest32: Uint8Array): Promise<Secp256k1Signature>;}
ReturnType = 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;A live Secp256k1SigningSession.
Errors
Section titled “Errors”INPUT_INVALID:privateKeyis not 32 bytes or not a valid secp256k1 scalar.
See also
Section titled “See also”- getEvmAddress: the address for
session.publicKey. - toViemAccount: a viem account backed by the session.
- Signing sessions: how a session owns the key, and the lifecycle.