Skip to content
Quickstart

Quickstart

Worker-safe bearer-key generation and hashing primitives

This helper creates a prefixed key, stores its digest, then hands the plaintext to the host’s authorized delivery function. The host supplies both operations; neither the key nor the digest is logged:

import { generateKeyAndHash } from "@fungi.computer/ear-tag";
export async function issueInvite(
storeDigest: (digest: string) => Promise<void>,
deliverKey: (key: string) => Promise<void>,
): Promise<void> {
const { key, digest } = await generateKeyAndHash({ prefix: "invite" });
await storeDigest(digest);
await deliverKey(key);
}

The existing tests verify that a generated digest matches the plaintext key in test/crypto.test.ts.