Skip to content

createSecp256k1SigningSession

Creates a signing session from a secp256k1 private key.

import {
function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession

Creates a signing session from a secp256k1 private key.

@param ― options - Signing session inputs.

@returns ― A live secp256k1 signing session.

@throws ― MeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

createSecp256k1SigningSession
} from "@category-labs/mera";
import {
function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession

Creates a signing session from a secp256k1 private key.

@param ― options - Signing session inputs.

@returns ― A live secp256k1 signing session.

@throws ― MeraError with code INPUT_INVALID when privateKey is not a valid secp256k1 scalar.

createSecp256k1SigningSession
,
function getEvmAddress(publicKey: Uint8Array): EvmAddress

Derives the EIP-55 checksummed EVM address for a secp256k1 public key.

@param ― publicKey - A compressed or uncompressed secp256k1 public key.

@returns ― The EIP-55 mixed-case checksummed EVM address.

@throws ― MeraError with code INPUT_INVALID when publicKey is not valid secp256k1.

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.

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);
const
const session: Secp256k1SigningSession
session
=
function createSecp256k1SigningSession({ privateKey, }: CreateSigningSessionOptions): Secp256k1SigningSession

Creates a signing session from a secp256k1 private key.

@param ― options - Signing session inputs.

@returns ― A live secp256k1 signing session.

@throws ― MeraError 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
});
const
const address: `0x${string}`
address
=
function getEvmAddress(publicKey: Uint8Array): EvmAddress

Derives the EIP-55 checksummed EVM address for a secp256k1 public key.

@param ― publicKey - A compressed or uncompressed secp256k1 public key.

@returns ― The EIP-55 mixed-case checksummed EVM address.

@throws ― MeraError with code INPUT_INVALID when publicKey is not valid secp256k1.

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
} =
const session: Secp256k1SigningSession
session
.
function signDigest(digest32: Uint8Array): Secp256k1Signature

Signs a 32-byte digest without prehashing it.

@param ― digest32 - The digest to sign.

@returns ― A compact secp256k1 ECDSA signature with its recovery ID.

@throws ― MeraError with code INPUT_INVALID when digest32 is not 32 bytes.

@throws ― MeraError with code SESSION_ENDED after end has been called.

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
();
  • Type: Uint8Array
  • Required

secp256k1 private key. Must be exactly 32 bytes and a valid scalar, an integer inside the curve’s private-key range.

import type {
type Secp256k1SigningSession = SigningSession & {
readonly publicKey: Uint8Array<ArrayBuffer>;
signDigest(digest32: Uint8Array): 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): Secp256k1Signature;
}
ReturnType
=
type Secp256k1SigningSession = SigningSession & {
readonly publicKey: Uint8Array<ArrayBuffer>;
signDigest(digest32: Uint8Array): Secp256k1Signature;
}

secp256k1 signing session that can sign 32-byte digests until end is called.

Secp256k1SigningSession
;

A live Secp256k1SigningSession.

  • INPUT_INVALID: privateKey is not 32 bytes or not a valid secp256k1 scalar.