Skip to content
API reference

seam

Import
import * as api from "@fungi.computer/seam";
Kind Export Description
class SeamReplayGuard Bounded process-local history; deliberately not durable across reconstruction.
type alias SeamSigner Sender identity and private Ed25519 key used to sign seam requests.
type alias SeamVerifiers Receiver-pinned public Ed25519 verification keys, indexed by sender key ID.
type alias SeamReplayAdmission An atomic admission decision; refusal never discards still-live history.
type alias SeamReplayRecord Seam supplies the retention deadline, inclusive of its last fresh instant.
type alias SeamReplayStore One logical receiver’s bounded replay history. A durable host must reopen the same receiver namespace after reconstruction, never fall back to memory. Admission atomically prunes expired records, checks nonce uniqueness and the implementation’s finite capacity, then records the nonce before answering admitted. Persist before success; never shorten Seam’s inclusive deadline. Storage mechanics and the numeric capacity belong to the implementation.
constant seamHeader Mutual authentication for on-box host seams: every request in either direction is signed with Ed25519 by its sender and verified against a public key the receiver pins.
constant unsignedPayload Digest sentinel for a body whose integrity is supplied by its transport.
function importSeamSigner() keyId:base64(pkcs8), the form a Worker secret or key file holds.
function importSeamVerifiers() { keyId: base64(raw 32-byte public key) }, the pinned peers.
function seamBodyDigest() The body digest to sign: SHA-256 hex of buffered bytes, or unsigned.
function signSeamRequest() The x-fungi-seam header value for one request.
function verifySeamRequest() Verify one request’s seam header. digest is the receiver’s own digest of the buffered body, or null when the route accepts an unsigned stream. Answers the sender’s key id.

Bounded process-local history; deliberately not durable across reconstruction.

Signature
new SeamReplayGuard(): SeamReplayGuard;

SeamReplayGuard

Signature
admit(__namedParameters): SeamReplayAdmission;

Record one nonce, refusing capacity rather than evicting live history.

Parameter Type
__namedParameters SeamReplayRecord

SeamReplayAdmission

Signature
SeamReplayStore.admit;

SeamSignertype alias

Section titled “SeamSigner”
Signature
type SeamSigner = Readonly<{
keyId: string;
key: CryptoKey;
}>;

Sender identity and private Ed25519 key used to sign seam requests.


SeamVerifierstype alias

Section titled “SeamVerifiers”
Signature
type SeamVerifiers = ReadonlyMap<string, CryptoKey>;

Receiver-pinned public Ed25519 verification keys, indexed by sender key ID.


SeamReplayAdmissiontype alias

Section titled “SeamReplayAdmission”
Signature
type SeamReplayAdmission =
"admitted" | "replayed" | "at-capacity" | "unavailable";

An atomic admission decision; refusal never discards still-live history.


SeamReplayRecordtype alias

Section titled “SeamReplayRecord”
Signature
type SeamReplayRecord = Readonly<{
nonce: string;
now: number;
expiresAt: number;
}>;

Seam supplies the retention deadline, inclusive of its last fresh instant.


SeamReplayStoretype alias

Section titled “SeamReplayStore”
Signature
type SeamReplayStore = Readonly<{
admit: (record) => SeamReplayAdmission | Promise<SeamReplayAdmission>;
}>;

One logical receiver’s bounded replay history. A durable host must reopen the same receiver namespace after reconstruction, never fall back to memory. Admission atomically prunes expired records, checks nonce uniqueness and the implementation’s finite capacity, then records the nonce before answering admitted. Persist before success; never shorten Seam’s inclusive deadline. Storage mechanics and the numeric capacity belong to the implementation.

seamHeaderconstant

Section titled “seamHeader”
Signature
const seamHeader: "x-fungi-seam" = "x-fungi-seam";

Mutual authentication for on-box host seams: every request in either direction is signed with Ed25519 by its sender and verified against a public key the receiver pins.

  • Down: the Hub signs with the platform seam key; the host pins its public key.
  • Up: the host signs reports with its host key; the Hub pins it in the host registry.

The signature covers an audience (so a request meant for one side cannot be replayed at the other), the method, path and query, a timestamp, a nonce and the body digest. Streaming bodies (forwarded guest traffic, port previews, WebSocket upgrades) sign UNSIGNED-PAYLOAD and rely on the TLS transport (Cloudflare Tunnel) for body integrity. Receivers reject a timestamp outside the skew window and a nonce seen within it. Private keys stay with their owner; projections and registries carry public data only.

This module is plain Web Crypto so the Worker and the Node.js host share it.


unsignedPayloadconstant

Section titled “unsignedPayload”
Signature
const unsignedPayload: "UNSIGNED-PAYLOAD" = "UNSIGNED-PAYLOAD";

Digest sentinel for a body whose integrity is supplied by its transport.

importSeamSigner()function

Section titled “importSeamSigner()”
Signature
function importSeamSigner(secret): Promise<
Readonly<{
keyId: string;
key: CryptoKey;
}>
>;

keyId:base64(pkcs8), the form a Worker secret or key file holds.

Parameter Type
secret string

Promise<Readonly<{ keyId: string; key: CryptoKey; }>>


importSeamVerifiers()function

Section titled “importSeamVerifiers()”
Signature
function importSeamVerifiers(publicKeys): Promise<SeamVerifiers>;

{ keyId: base64(raw 32-byte public key) }, the pinned peers.

Parameter Type
publicKeys Readonly<Record<string, string>>

Promise<SeamVerifiers>


seamBodyDigest()function

Section titled “seamBodyDigest()”
Signature
function seamBodyDigest(body): Promise<string>;

The body digest to sign: SHA-256 hex of buffered bytes, or unsigned.

Parameter Type
body ArrayBuffer | Uint8Array<ArrayBuffer> | null

Promise<string>


signSeamRequest()function

Section titled “signSeamRequest()”
Signature
function signSeamRequest(
signer,
audience,
method,
url,
digest,
now?,
): Promise<string>;

The x-fungi-seam header value for one request.

Parameter Type
signer SeamSigner
audience string
method string
url string
digest string
now number

Promise<string>


verifySeamRequest()function

Section titled “verifySeamRequest()”
Signature
function verifySeamRequest(
verifiers,
audience,
method,
url,
header,
digest,
replay,
now?,
): Promise<string>;

Verify one request’s seam header. digest is the receiver’s own digest of the buffered body, or null when the route accepts an unsigned stream. Answers the sender’s key id.

Parameter Type
verifiers SeamVerifiers
audience string
method string
url string
header string | null
digest string | null
replay SeamReplayStore
now number

Promise<string>