Skip to content
Get startedGetting started →

Create passkey accounts

Prerequisites:

  • @category-labs/mera, @scure/bip32, @scure/bip39, and @noble/hashes installed.
  • A PRF-capable authenticator (authenticator support).
The recipe's two flows. On the first visit, createPasskeyWithPrfOutput creates the passkey and the app stores the credential metadata, credentialId and transports, which holds no key material. On a returning visit, getPasskeyPrfOutput signs in using the stored metadata. The PRF output becomes the seed through BIP-39, held in memory for the session, and HD derivation by index produces the EVM and Solana signing sessions, ended by end(). first visit Create the passkey createPasskeyWithPrfOutput Credential metadata returning visit Sign in getPasskeyPrfOutput PRF output BIP-39 Seed derivation by index Signing sessions end()
import {
function createPasskeyWithPrfOutput({ rp, user, timeout, prfSalt, webAuthnClient, }: createPasskeyWithPrfOutput.Options): Promise<createPasskeyWithPrfOutput.Result>

Creates a discoverable, user-verified passkey that requires WebAuthn PRF support and returns the first PRF output.

@paramoptions - Passkey creation inputs.

@returnsCredential metadata and the first PRF output.

@remarks

Runs one creation ceremony and shows one user-verification prompt. On authenticators that do not evaluate PRF during creation, a fallback assertion evaluates the same salt and shows a second prompt.

WebAuthn challenges and the credential's user handle (user.id) are generated internally, 32 random bytes each. An authenticator overwrites a discoverable credential that has the same rp.id and user.id, so a fresh handle per call adds a passkey instead of replacing one.

The credential is requested with fixed parameters: ES256 or RS256 key types, attestation "none", a required resident key, and required user verification (getPasskeyPrfOutput explains the requirement).

Any failure after the creation ceremony completes leaves the passkey on the authenticator, but the thrown error does not carry its metadata.

@throwsMeraError with code PRF_UNAVAILABLE when the authenticator reports no PRF support and returns no create-time output, returns an output that is not 32 bytes, or returns none on the fallback ceremony.

@throwsMeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes.

@throwsMeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throwsMeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, cancelled, or returns an unexpected credential.

createPasskeyWithPrfOutput
} from "@category-labs/mera";
const
const rpId: string
rpId
=
var location: Location

The Window.location read-only property returns a Location object with information about the current location of the document.

MDN Reference

location
.
Location.hostname: string

The hostname property of the Location interface is a string containing either the domain name or IP address of the location URL.

MDN Reference

hostname
;
const
const created: createPasskeyWithPrfOutput.Result
created
= await
function createPasskeyWithPrfOutput({ rp, user, timeout, prfSalt, webAuthnClient, }: createPasskeyWithPrfOutput.Options): Promise<createPasskeyWithPrfOutput.Result>

Creates a discoverable, user-verified passkey that requires WebAuthn PRF support and returns the first PRF output.

@paramoptions - Passkey creation inputs.

@returnsCredential metadata and the first PRF output.

@remarks

Runs one creation ceremony and shows one user-verification prompt. On authenticators that do not evaluate PRF during creation, a fallback assertion evaluates the same salt and shows a second prompt.

WebAuthn challenges and the credential's user handle (user.id) are generated internally, 32 random bytes each. An authenticator overwrites a discoverable credential that has the same rp.id and user.id, so a fresh handle per call adds a passkey instead of replacing one.

The credential is requested with fixed parameters: ES256 or RS256 key types, attestation "none", a required resident key, and required user verification (getPasskeyPrfOutput explains the requirement).

Any failure after the creation ceremony completes leaves the passkey on the authenticator, but the thrown error does not carry its metadata.

@throwsMeraError with code PRF_UNAVAILABLE when the authenticator reports no PRF support and returns no create-time output, returns an output that is not 32 bytes, or returns none on the fallback ceremony.

@throwsMeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes.

@throwsMeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throwsMeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, cancelled, or returns an unexpected credential.

createPasskeyWithPrfOutput
({
rp: PasskeyRelyingParty

Relying party identity passed to WebAuthn. id is required so the fallback assertion can target the same relying party.

rp
: {
id: string

Relying party ID: the host the passkey is scoped to.

id
:
const rpId: string
rpId
,
name: string

Relying party name the authenticator may show.

name
: "Example" },
user: {
name: string;
displayName: string;
}

User identity passed to WebAuthn.

user
: {
name: string

User name displayed or stored by the authenticator.

name
: "account@example.com",
displayName: string

Human-readable display name for the authenticator UI.

displayName
: "Example account" },
});

Every call creates a new passkey.

The app can store the credential metadata and pass it back on the next sign-in, so the browser reuses the same passkey instead of offering a choice.

var localStorage: Storage
localStorage
.
Storage.setItem(key: string, value: string): void

The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key's value if it already exists.

MDN Reference

setItem
(
"app.derivedCredential",
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
({
credentialId: string
credentialId
:
const created: createPasskeyWithPrfOutput.Result
created
.
credentialId: string

Credential ID encoded as canonical unpadded base64url.

credentialId
,
transports: readonly PasskeyCredentialTransport[] | undefined
transports
:
const created: createPasskeyWithPrfOutput.Result
created
.
transports?: readonly PasskeyCredentialTransport[] | undefined

Authenticator transports reported by the platform, when available.

transports
,
}),
);

transports is optional and only a hint: the browser uses it to reach the authenticator directly (a platform prompt for a platform passkey, a QR flow for a phone) instead of offering every option.

import {
function getPasskeyPrfOutput({ rpId, credential: allowCredential, prfSalt, timeout, webAuthnClient, }: getPasskeyPrfOutput.Options): Promise<getPasskeyPrfOutput.Result>

Requests a passkey PRF evaluation and returns the first output.

@paramoptions - Passkey PRF request inputs.

@returnsThe selected credential ID and first WebAuthn PRF output.

@remarks

Runs one assertion ceremony and shows one user-verification prompt.

The WebAuthn challenge is generated internally.

The default salt is sha256("mera.prf.salt.v1") and will not change across library versions. The PRF output is a deterministic function of the credential, rpId, and salt; a different salt yields an unrelated output.

The assertion requires user verification, and the requirement is not configurable. User verification is the authenticator's local check; the gesture depends on the platform (a biometric, a device PIN, or a password). Authenticators built on CTAP's hmac-secret keep two PRFs per credential, one for user-verified requests and one for the rest; WebAuthn exposes only the user-verified PRF and overrides a weaker userVerification setting when evaluating it, so a configurable setting could neither change the PRF output nor skip the check.

@seehttps://www.w3.org/TR/webauthn-3/#prf-extension WebAuthn: the PRF extension

@seehttps://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement WebAuthn: UserVerificationRequirement

@throwsMeraError with code PRF_UNAVAILABLE when the authenticator does not return a usable 32-byte PRF output.

@throwsMeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes, or credential.credentialId is empty or not canonical base64url.

@throwsMeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throwsMeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, cancelled, or returns an unexpected credential.

getPasskeyPrfOutput
} from "@category-labs/mera";
const
const stored: string | null
stored
=
var localStorage: Storage
localStorage
.
Storage.getItem(key: string): string | null

The getItem() method of the Storage interface, when passed a key name, will return that key's value, or null if the key does not exist, in the given Storage object.

MDN Reference

getItem
("app.derivedCredential");
const
const known: any
known
=
const stored: string | null
stored
?
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.parse(text: string, reviver?: (this: any, key: string, value: any) => any): any

Converts a JavaScript Object Notation (JSON) string into an object.

@paramtext A valid JSON string.

@paramreviver A function that transforms the results. This function is called for each member of the object. If a member contains nested objects, the nested objects are transformed before the parent object is.

@throws{SyntaxError} If text is not valid JSON.

parse
(
const stored: string
stored
) :
var undefined
undefined
;
const {
const prfOutput: Uint8Array<ArrayBuffer>

First PRF output from WebAuthn. Always 32 bytes.

prfOutput
,
const credentialId: string

Credential ID selected by the platform, as canonical unpadded base64url.

credentialId
} = await
function getPasskeyPrfOutput({ rpId, credential: allowCredential, prfSalt, timeout, webAuthnClient, }: getPasskeyPrfOutput.Options): Promise<getPasskeyPrfOutput.Result>

Requests a passkey PRF evaluation and returns the first output.

@paramoptions - Passkey PRF request inputs.

@returnsThe selected credential ID and first WebAuthn PRF output.

@remarks

Runs one assertion ceremony and shows one user-verification prompt.

The WebAuthn challenge is generated internally.

The default salt is sha256("mera.prf.salt.v1") and will not change across library versions. The PRF output is a deterministic function of the credential, rpId, and salt; a different salt yields an unrelated output.

The assertion requires user verification, and the requirement is not configurable. User verification is the authenticator's local check; the gesture depends on the platform (a biometric, a device PIN, or a password). Authenticators built on CTAP's hmac-secret keep two PRFs per credential, one for user-verified requests and one for the rest; WebAuthn exposes only the user-verified PRF and overrides a weaker userVerification setting when evaluating it, so a configurable setting could neither change the PRF output nor skip the check.

@seehttps://www.w3.org/TR/webauthn-3/#prf-extension WebAuthn: the PRF extension

@seehttps://www.w3.org/TR/webauthn-3/#enumdef-userverificationrequirement WebAuthn: UserVerificationRequirement

@throwsMeraError with code PRF_UNAVAILABLE when the authenticator does not return a usable 32-byte PRF output.

@throwsMeraError with code INPUT_INVALID when an explicit prfSalt is not 32 bytes, or credential.credentialId is empty or not canonical base64url.

@throwsMeraError with code CRYPTO_UNAVAILABLE when crypto.getRandomValues is unavailable.

@throwsMeraError with code PASSKEY_OPERATION_FAILED when WebAuthn is unavailable, cancelled, or returns an unexpected credential.

getPasskeyPrfOutput
({
rpId: string

Relying party ID for the WebAuthn assertion.

rpId
,
credential?: PasskeyCredentialMetadata | undefined

Credential metadata to restrict the assertion to one passkey. When omitted, WebAuthn may choose any discoverable credential for the relying party.

credential
:
const known: any
known
,
});
// With no stored record, the browser may have used any discoverable passkey.
const
const record: any
record
=
const known: any
known
?.
any
credentialId
===
const credentialId: string

Credential ID selected by the platform, as canonical unpadded base64url.

credentialId
?
const known: any
known
: {
credentialId: string
credentialId
};
var localStorage: Storage
localStorage
.
Storage.setItem(key: string, value: string): void

The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key's value if it already exists.

MDN Reference

setItem
("app.derivedCredential",
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
const record: any
record
));

Turn the PRF output into a BIP-39 seed.

import {
function entropyToMnemonic(entropy: TArg<Uint8Array>, wordlist: string[]): string

Reversible: Converts raw entropy in form of byte array to mnemonic string.

@paramentropy - Byte array.

@paramwordlist - Imported wordlist for a specific language.

@returns12-24 words.

@throwsOn wrong argument types. TypeError

@throwsOn wrong argument ranges or values. RangeError

@example

Convert raw entropy into an English mnemonic.

import { entropyToMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english.js';
const ent = new Uint8Array([
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
]);
const mnemonic = entropyToMnemonic(ent, wordlist);
// 'legal winner thank year wave sausage worth useful legal winner thank yellow'

entropyToMnemonic
,
function mnemonicToSeedSync(mnemonic: string, passphrase?: string): TRet<Uint8Array>

Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.

@parammnemonic - 12-24 words.

@parampassphrase - String that will additionally protect the key.

@returns64 bytes of key data.

@throwsIf the mnemonic shape is invalid. Error

@throwsOn wrong argument types. TypeError

@example

Derive a seed from a mnemonic with the sync PBKDF2 helper.

const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
const seed = mnemonicToSeedSync(mnem, 'password');
// => new Uint8Array([...64 bytes])

mnemonicToSeedSync
} from "@scure/bip39";
import {
const wordlist: string[]

English BIP39 wordlist.

wordlist
} from "@scure/bip39/wordlists/english.js";
const
const seed: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
seed
=
function mnemonicToSeedSync(mnemonic: string, passphrase?: string): TRet<Uint8Array>

Irreversible: Uses KDF to derive 64 bytes of key data from mnemonic + optional password.

@parammnemonic - 12-24 words.

@parampassphrase - String that will additionally protect the key.

@returns64 bytes of key data.

@throwsIf the mnemonic shape is invalid. Error

@throwsOn wrong argument types. TypeError

@example

Derive a seed from a mnemonic with the sync PBKDF2 helper.

const mnem = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
const seed = mnemonicToSeedSync(mnem, 'password');
// => new Uint8Array([...64 bytes])

mnemonicToSeedSync
(
function entropyToMnemonic(entropy: TArg<Uint8Array>, wordlist: string[]): string

Reversible: Converts raw entropy in form of byte array to mnemonic string.

@paramentropy - Byte array.

@paramwordlist - Imported wordlist for a specific language.

@returns12-24 words.

@throwsOn wrong argument types. TypeError

@throwsOn wrong argument ranges or values. RangeError

@example

Convert raw entropy into an English mnemonic.

import { entropyToMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english.js';
const ent = new Uint8Array([
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
]);
const mnemonic = entropyToMnemonic(ent, wordlist);
// 'legal winner thank year wave sausage worth useful legal winner thank yellow'

entropyToMnemonic
(
const prfOutput: Uint8Array<ArrayBufferLike>
prfOutput
,
const wordlist: string[]

English BIP39 wordlist.

wordlist
));

EVM accounts follow BIP-32 over the BIP-44 Ethereum path:

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
,
function getEvmAddress(publicKey: Uint8Array): EvmAddress

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

@parampublicKey - A compressed or uncompressed secp256k1 public key.

@returnsThe EIP-55 mixed-case checksummed EVM address.

@throwsMeraError with code INPUT_INVALID when publicKey is not valid secp256k1.

getEvmAddress
,
} from "@category-labs/mera";
import {
class HDKey

HDKey from BIP32

@paramopt - Node fields used to construct one HDKey instance.

@example

import { HDKey } from '@scure/bip32';
import { randomBytes } from '@noble/hashes/utils.js';
const seed = randomBytes(32);
const root = HDKey.fromMasterSeed(seed);
const account0 = root.derive("m/0/1'");
account0.publicKey;

HDKey
} from "@scure/bip32";
function
function deriveEvmAccount(seed: Uint8Array, index: number): {
session: Secp256k1SigningSession;
address: `0x${string}`;
}
deriveEvmAccount
(
seed: Uint8Array<ArrayBufferLike>
seed
:
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

Uint8Array
,
index: number
index
: number) {
const
const ethereumAccountPath: string
ethereumAccountPath
= `m/44'/60'/0'/0/${
index: number
index
}`;
const
const node: HDKey
node
=
class HDKey

HDKey from BIP32

@paramopt - Node fields used to construct one HDKey instance.

@example

import { HDKey } from '@scure/bip32';
import { randomBytes } from '@noble/hashes/utils.js';
const seed = randomBytes(32);
const root = HDKey.fromMasterSeed(seed);
const account0 = root.derive("m/0/1'");
account0.publicKey;

HDKey
.
HDKey.fromMasterSeed(seed: Uint8Array, versions?: Versions): HDKey
fromMasterSeed
(
seed: Uint8Array<ArrayBufferLike>
seed
).
HDKey.derive(path: string): HDKey
derive
(
const ethereumAccountPath: string
ethereumAccountPath
);
if (
const node: HDKey
node
.
HDKey.privateKey: Uint8Array<ArrayBufferLike> | null
privateKey
=== null) throw new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("derivation produced no key");
const
const 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
:
const node: HDKey
node
.
HDKey.privateKey: Uint8Array<ArrayBufferLike>
privateKey
,
});
return {
session: Secp256k1SigningSession
session
,
address: `0x${string}`
address
:
function getEvmAddress(publicKey: Uint8Array): EvmAddress

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

@parampublicKey - A compressed or uncompressed secp256k1 public key.

@returnsThe EIP-55 mixed-case checksummed EVM address.

@throwsMeraError 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
) };
}

Solana uses SLIP-0010, the Ed25519 counterpart of BIP-32, and its derivation is a short chain of HMAC (keyed hash) calls:

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
,
function getSolanaAddress(publicKey: Uint8Array): SolanaAddress

Derives the base58-encoded Solana address for an Ed25519 public key.

@parampublicKey - A 32-byte Ed25519 public key.

@returnsThe base58-encoded Solana address.

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

getSolanaAddress
,
} from "@category-labs/mera";
import {
const hmac: HmacFn & ((hash: TArg<TArg<CHash>>, key: TArg<TArg<Uint8Array<ArrayBufferLike>>>, message: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
create: (hash: TArg<CHash>, key: TArg<Uint8Array>) => TRet<_HMAC<any>>;
}
hmac
} from "@noble/hashes/hmac.js";
import {
const sha512: {
outputLen: number;
blockLen: number;
canXOF: boolean;
} & HashInfo & {
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
create(): _SHA512;
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
outputLen: number;
blockLen: number;
canXOF: boolean;
oid?: TRet<Uint8Array> | undefined;
create: () => _SHA512;
}

SHA2-512 hash function from RFC 4634.

@parammsg - message bytes to hash

@paramopts - Reserved hash options.

@returnsDigest bytes.

@example

Hash a message with SHA2-512.

sha512(new Uint8Array([97, 98, 99]));

sha512
} from "@noble/hashes/sha2.js";
import {
function utf8ToBytes(str: string): TRet<Uint8Array>

Converts string to bytes using UTF8 encoding. Built-in doesn't validate input to be string: we do the check. Non-ASCII details are delegated to the platform TextEncoder.

@paramstr - string to encode

@returnsUTF-8 encoded bytes.

@throwsOn wrong argument types. TypeError

@example

Encode a string as UTF-8 bytes.

utf8ToBytes('abc'); // Uint8Array.from([97, 98, 99])

utf8ToBytes
} from "@noble/hashes/utils.js";
function
function deriveSolanaSeed(seed: Uint8Array, index: number): Uint8Array
deriveSolanaSeed
(
seed: Uint8Array<ArrayBufferLike>
seed
:
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

Uint8Array
,
index: number
index
: number):
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

Uint8Array
{
// The SLIP-0010 path m/44'/501'/{index}'/0'; every step is hardened.
const
const solanaAccountPath: number[]
solanaAccountPath
= [44, 501,
index: number
index
, 0];
let
let i: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
i
=
function hmac(hash: TArg<CHash>, key: TArg<Uint8Array>, message: TArg<Uint8Array>): TRet<Uint8Array>
hmac
(
const sha512: {
outputLen: number;
blockLen: number;
canXOF: boolean;
} & HashInfo & {
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
create(): _SHA512;
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
outputLen: number;
blockLen: number;
canXOF: boolean;
oid?: TRet<Uint8Array> | undefined;
create: () => _SHA512;
}

SHA2-512 hash function from RFC 4634.

@parammsg - message bytes to hash

@paramopts - Reserved hash options.

@returnsDigest bytes.

@example

Hash a message with SHA2-512.

sha512(new Uint8Array([97, 98, 99]));

sha512
,
function utf8ToBytes(str: string): TRet<Uint8Array>

Converts string to bytes using UTF8 encoding. Built-in doesn't validate input to be string: we do the check. Non-ASCII details are delegated to the platform TextEncoder.

@paramstr - string to encode

@returnsUTF-8 encoded bytes.

@throwsOn wrong argument types. TypeError

@example

Encode a string as UTF-8 bytes.

utf8ToBytes('abc'); // Uint8Array.from([97, 98, 99])

utf8ToBytes
("ed25519 seed"),
seed: Uint8Array<ArrayBufferLike>
seed
);
for (const
const step: number
step
of
const solanaAccountPath: number[]
solanaAccountPath
) {
const
const data: Uint8Array<ArrayBuffer>
data
= new
var Uint8Array: Uint8ArrayConstructor
new (length: number) => Uint8Array<ArrayBuffer> (+6 overloads)
Uint8Array
(1 + 32 + 4);
const data: Uint8Array<ArrayBuffer>
data
.
Uint8Array<ArrayBuffer>.set(array: ArrayLike<number>, offset?: number): void

Sets a value or an array of values.

@paramarray A typed or untyped array of values to set.

@paramoffset The index in the current array at which the values are to be written.

set
(
let i: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
i
.
Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>.slice(start?: number, end?: number): Uint8Array<ArrayBuffer>

Returns a section of an array.

@paramstart The beginning of the specified portion of the array.

@paramend The end of the specified portion of the array. This is exclusive of the element at the index 'end'.

slice
(0, 32), 1);
new
var DataView: DataViewConstructor
new <ArrayBuffer>(buffer: ArrayBuffer, byteOffset?: number, byteLength?: number) => DataView<ArrayBuffer>
DataView
(
const data: Uint8Array<ArrayBuffer>
data
.
Uint8Array<ArrayBuffer>.buffer: ArrayBuffer

The ArrayBuffer instance referenced by the array.

buffer
).
DataView<ArrayBuffer>.setUint32(byteOffset: number, value: number, littleEndian?: boolean): void

Stores an Uint32 value at the specified byte offset from the start of the view.

@parambyteOffset The place in the buffer at which the value should be set.

@paramvalue The value to set.

@paramlittleEndian If false or undefined, a big-endian value should be written.

setUint32
(33, (
const step: number
step
+ 0x80000000) >>> 0, false);
let i: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
i
=
function hmac(hash: TArg<CHash>, key: TArg<Uint8Array>, message: TArg<Uint8Array>): TRet<Uint8Array>
hmac
(
const sha512: {
outputLen: number;
blockLen: number;
canXOF: boolean;
} & HashInfo & {
(msg: TArg<Uint8Array>): TRet<Uint8Array>;
create(): _SHA512;
} & ((msg: TArg<TArg<Uint8Array<ArrayBufferLike>>>) => Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>) & {
outputLen: number;
blockLen: number;
canXOF: boolean;
oid?: TRet<Uint8Array> | undefined;
create: () => _SHA512;
}

SHA2-512 hash function from RFC 4634.

@parammsg - message bytes to hash

@paramopts - Reserved hash options.

@returnsDigest bytes.

@example

Hash a message with SHA2-512.

sha512(new Uint8Array([97, 98, 99]));

sha512
,
let i: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
i
.
Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>.slice(start?: number, end?: number): Uint8Array<ArrayBuffer>

Returns a section of an array.

@paramstart The beginning of the specified portion of the array.

@paramend The end of the specified portion of the array. This is exclusive of the element at the index 'end'.

slice
(32),
const data: Uint8Array<ArrayBuffer>
data
);
}
return
let i: Uint8Array<ArrayBufferLike> & Uint8Array<ArrayBuffer>
i
.
Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>.slice(start?: number, end?: number): Uint8Array<ArrayBuffer>

Returns a section of an array.

@paramstart The beginning of the specified portion of the array.

@paramend The end of the specified portion of the array. This is exclusive of the element at the index 'end'.

slice
(0, 32);
}
function
function deriveSolanaAccount(seed: Uint8Array, index: number): {
session: Ed25519SigningSession;
address: SolanaAddress;
}
deriveSolanaAccount
(
seed: Uint8Array<ArrayBufferLike>
seed
:
interface Uint8Array<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike>

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.

Uint8Array
,
index: number
index
: number) {
const
const 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
:
function deriveSolanaSeed(seed: Uint8Array, index: number): Uint8Array
deriveSolanaSeed
(
seed: Uint8Array<ArrayBufferLike>
seed
,
index: number
index
),
});
return {
session: Ed25519SigningSession
session
,
address: SolanaAddress
address
:
function getSolanaAddress(publicKey: Uint8Array): SolanaAddress

Derives the base58-encoded Solana address for an Ed25519 public key.

@parampublicKey - A 32-byte Ed25519 public key.

@returnsThe base58-encoded Solana address.

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

getSolanaAddress
(
const session: Ed25519SigningSession
session
.
publicKey: Uint8Array<ArrayBuffer>

32-byte Ed25519 public key for the session.

publicKey
) };
}

Build the account list from these helpers:

const
const accounts: ({
session: Secp256k1SigningSession;
address: EvmAddress;
} | {
session: Ed25519SigningSession;
address: SolanaAddress;
})[]
accounts
= [
function deriveEvmAccount(seed: Uint8Array, index: number): {
session: Secp256k1SigningSession;
address: EvmAddress;
}
deriveEvmAccount
(
const seed: Uint8Array<ArrayBufferLike>
seed
, 0),
function deriveSolanaAccount(seed: Uint8Array, index: number): {
session: Ed25519SigningSession;
address: SolanaAddress;
}
deriveSolanaAccount
(
const seed: Uint8Array<ArrayBufferLike>
seed
, 0)];
for (const
const account: {
session: Ed25519SigningSession | Secp256k1SigningSession;
}
account
of
const accounts: {
session: Ed25519SigningSession | Secp256k1SigningSession;
}[]
accounts
) {
const account: {
session: Ed25519SigningSession | Secp256k1SigningSession;
}
account
.
session: Ed25519SigningSession | Secp256k1SigningSession
session
.
function end(): void

Zeroes the session-owned private-key copy; later signing throws SESSION_ENDED.

end
();
}

Ending a session zeroes the private keys it owns.