Skip to content
Get startedGetting started →

Ed25519SigningSession

A live signing session holding an Ed25519 private key. createEd25519SigningSession returns it.

import type {
type Ed25519SigningSession = SigningSession & {
readonly publicKey: Uint8Array<ArrayBuffer>;
signMessage(message: Uint8Array): Promise<Uint8Array<ArrayBuffer>>;
}

Ed25519 signing session that can sign messages until end is called.

Ed25519SigningSession
} from "@category-labs/mera";

Uint8Array, the 32-byte Ed25519 public key.

Signs an arbitrary-length message and resolves to the 64-byte Ed25519 signature (R || s). Hashing happens inside Ed25519 itself.

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 createEd25519SigningSession({ privateKey, }: CreateSigningSessionOptions): Ed25519SigningSession

Creates a signing session from an Ed25519 private key.

@paramoptions - Signing session inputs.

@returnsA live Ed25519 signing session.

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

createEd25519SigningSession
} 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 message: Uint8Array<ArrayBuffer>
message
= new
var TextEncoder: new () => TextEncoder

The TextEncoder interface takes a stream of code points as input and emits a stream of UTF-8 bytes.

MDN Reference

TextEncoder class is a global reference for import { TextEncoder } from 'node:util' https://nodejs.org/api/globals.html#textencoder

@sincev11.0.0

TextEncoder
().
TextEncoder.encode(input?: string): Uint8Array<ArrayBuffer>

The TextEncoder.encode() method takes a string as input, and returns a Global_Objects/Uint8Array containing the text given in parameters encoded with the specific method for that TextEncoder object.

MDN Reference

encode
("hello mera");
{
using
using session: Ed25519SigningSession
session
=
function createEd25519SigningSession({ privateKey, }: CreateSigningSessionOptions): Ed25519SigningSession

Creates a signing session from an Ed25519 private key.

@paramoptions - Signing session inputs.

@returnsA live Ed25519 signing session.

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

createEd25519SigningSession
({
privateKey: Uint8Array<ArrayBufferLike>

Curve private key. Must be exactly 32 bytes and, for secp256k1, a valid scalar.

privateKey
});
await
using session: Ed25519SigningSession
session
.
function signMessage(message: Uint8Array): Promise<Uint8Array<ArrayBuffer>>

Signs an arbitrary-length message.

@parammessage - The message to sign; hashing happens inside Ed25519 itself.

@returnsA 64-byte Ed25519 signature (R || s).

@throwsMeraError with code SESSION_ENDED after end has been called.

signMessage
(
const message: Uint8Array<ArrayBuffer>
message
);
} // ended here