Skip to content

@filoz/keysmith

Interface Description
Claim One link: what its bearer may read, and how much further they may delegate.
ClaimChain A chain, root first, with the fields every link inherits from the root.
ClaimSigner Anything that signs EIP-712 typed data: a viem account or wallet client.
DerivedGroupKey What deriveGroupKey() hands back. The signature it came from is never exposed.
DeriveGroupKeyOptions -
Grant A node key wrapped to one recipient. Safe to store or send anywhere.
GrantDescriptor Encryption grant metadata. Exactly these fields are authenticated, so a grant cannot be relabelled; anything else carried alongside a grant is informational and unauthenticated.
GroupKeyRef Identifies the group key a key belongs to.
PieceMetadataView A piece’s labels as readPieceMetadata() returns them: canonical, validated.
ReadRequest A request for one piece, from whichever provider holds it, signed by the chain’s final bearer.
TypedDataSigner Anything that can sign EIP-712 typed data: a viem Account, a WalletClient, or a session key. Keysmith itself never sees a private key.
VerifiedClaim The final claim of a verified chain.
WriteTarget What writeTarget() hands a delegate: everything needed to write one piece.
Type Alias Description
DecodedGrant A decoded grant. Text-keyed fields such as pieceCid are informational and unauthenticated, so treat them as untrusted. Only pieceCid is typed: there is deliberately no index signature, so a misspelled field is a compile error rather than a silent undefined. Any other informational key is present at runtime; narrow it from Reflect.get(grant, key).
GrantNode What a grant may unlock: the whole group key, one group within it, or one piece, named by its salt. The strings are wire values, signed into claims.
GrantTarget What a grant is picked for: reading one piece, or writing (or reading) under a group of a group key.
GroupKeyMessage The message an owner signs to start the derivation tree.
Holding Which node the caller holds when deriving a piece key: the whole group key, a group by its path, or one piece by its salt. These are API names, not wire strings: holdingOf() maps a grant’s GrantNode to one of them.
PieceLabels The labels a provider read from a piece’s FEE envelope. foc/v may be absent, 2 or “2”; keysmith 0.1.0 labels (foc/v 1, as a number or string, or foc/ks) and any other value are refused. Hand-written: fields are plain strings (not Address/Hex) and foc/own is optional.
PieceMetadata The format pieceMetadata() writes and readPieceMetadata() reads.
PieceMetadataV2 FEE envelope entries to enable key derivation/recovery.
Variable Description
COMMITMENT_KEY The FWSS data-set metadata key the commitment is written to.
DOMAIN Sparse EIP-712 message block to be signed by the root wallet. Note: Deliberately carries neither chainId nor verifyingContract as out primary concern is long-term access to the stored pieces, no matter what chain or contract they were initially associated with.
GROUP_KEY_TYPES Parameters of the typed data signature that roots a group key. GroupKey and groupKeyId are wire names: do not rename.
MAX_CHAIN_LENGTH -
MAX_REQUEST_LIFETIME -
READ_GRANT_TYPES EIP-712 types for every link and for a request. The domain is Keysmith’s DOMAIN. A link’s signature covers the fields it inherits from the root, so a link cannot be moved under a root that differs in any of them. Links name their parent by its bearer’s address, not by hash, so a parent can be re-issued without invalidating the links beneath it.
READ_REQUEST_TYPES -
Function Description
authorizationHeader The Authorization header for one gated request: a request for pieceCid signed by the chain’s final bearer, presented with its chain. Make a fresh one per fetch; it expires expiresIn seconds after now (default 240).
canonicalNode A grant node with path and salt canonical. The node is signed or bound into the wrap’s AAD, so it is written only in this form.
commitment A non-secret commitment to the group key, for FWSS data-set metadata: v2.<32 hex digits>, where v2 is the format of the value.
dataSetMetadata The metadata to record on a data set for this group key: its id under foc/gkid and the group key commitment (from commitment) under foc/kc, so the chain alone can list a wallet’s group keys.
decodeDelivery -
decodeGrant Read a grant delivered as bytes, without opening it: to see what it names before unwrapping, or to pass to holdingOf.
decodePresentation -
delegateClaim Delegate: the chain’s final bearer signs a narrower link for bearer. Takes the key the bearer holds for its own link, checks it against that link’s commitment, and derives the child’s key from it, so an honest delegate cannot commit to a wrong key. Hands the child key back to wrap. A piece link needs the piece’s labels, to check the parent’s node reaches it.
deriveGroupKey Sign for one group key and derive its key.
encodeDelivery A delivery: sent once to a new bearer, never to a provider. Carries the v2 grant that wraps the key. The grant must name the chain’s final node, owner and group key; that the wrapped key matches the link’s commitment is checked by openDelivery, which holds the private key to unwrap it.
encodeGrant Pack the grant to deliver or store it
encodePresentation A presentation: sent to a provider with each gated request, as Authorization: FOC-Grant <base64url>.
grantDescriptor The descriptor naming what a grant unlocks, ready for wrapTo().
groupKeyId Canonical form of a group key id: 16 bytes of hex, lowercase, prefixed with 0x.
groupKeyIdOf The group key id a data set’s metadata records under foc/gkid, canonical, or undefined if it records none. A data set without foc/gkid, including one written by keysmith 0.1.0 (foc/ks), returns undefined, so a lookup across a wallet’s data sets skips it. undefined does not mean “not encrypted”: a data set recording foc/ks, or a v1. foc/kc, is a keysmith 0.1.0 encrypted data set, and an app should not add new data to it.
groupKeyMessage -
groupName Canonicalize group name in the form it is derived from: Unicode NFC, non-empty, no leading or trailing whitespace, and no / (which would indicate a path). Case is significant.
groupPath Canonicalize group path: canonical names joined by /, top group first.
holdingOf Which node a grant carries, ready to pass to keyForEnvelope.
keyCommitmentOf A key’s commitment as the 16 bytes a claim carries.
keyForEnvelope Derive a piece’s key from whichever node the caller holds.
keyForGroup The key for a group. Groups form a tree, and a group’s key is derived from its parent’s, so holding a group also opens every group beneath it.
keyResolver A FEE key resolver for pieces this node reaches: pass it to fee.decrypt(), which calls it with the envelope’s metadata before decrypting a byte.
lowSrs Canonicalize signature:r‖s with s normalised to the low half, and v dropped.
matchesCommitment Verifies that groupKey is the key you expect: the right root wallet and the right group key. Check this before using any key received in a grant.
newGroupKeyId A fresh group key id: 16 random bytes. Public, not a key. Must be unique to a wallet, so that a grant for one group key cannot be relabelled as another.
newSalt A fresh per-piece salt. Public: it only has to travel with the piece.
openDelivery Open a delivery as its final bearer: verify the chain, unwrap the key, and check it against the commitment in its claim, which the owner (or the delegate above) signed. The group key commitment comes back too, for a bearer that writes the group key’s first datasets.
pickGrant The narrowest held grant that reaches target: a piece grant before a group grant, a deeper group before a shallower one, the group key last; on a tie, the one that expires last. Grants for another network or group key, or expired ones, or whose node does not parse, are skipped. Undefined when none reaches it: ask for a grant to that group or piece.
pieceKey The key for one piece. Never reused: FEE requires a fresh key per object.
pieceMetadata Piece FEE envelope metadata entries. Read them back with readPieceMetadata.
pieceNode The grant node for one piece, from its envelope metadata: piece:<salt>.
publicKeyOf The public key a sender wraps to, for the holder of a secp256k1 private key.
reaches Whether node reaches the piece these labels describe. Reads only the label the node’s kind needs.
readPieceMetadata Read a piece’s envelope metadata (foc/v 2: foc/gkid, foc/group) into one canonical shape.
rootClaim The root of a chain, signed by the owner’s wallet: one EIP-712 prompt. Derives the bearer’s node key from the group key, so the root cannot commit to a wrong one, and hands it back to wrap for the bearer. When the bearer is a session key, set expires to the session key’s expiry.
signRequest Sign a request for one piece, as the chain’s final bearer. Any provider holding it may serve it.
unwrapWith Open a grant with the recipient’s private key: the grant as delivered, in bytes, or as decoded by decodeGrant.
verifyChain Check a chain with nothing but the chain: the root signed by the owner and unexpired, every later link signed by the previous bearer and no wider than it. Pass piece when a link names a piece.
verifyPresentation What a gating provider checks on a request, with only the header and the piece’s labels: the chain, the request’s piece, lifetime and signer, and that the final node reaches the piece. A piece whose foc/own is absent or falsy is not gated.
wrapTo Wrap a node key — a group key, a group’s key, or one piece’s key — to a recipient.
writeTarget Everything a delegate needs to write a piece, taken from the grant that delegated it: the group key to record, the group to label it with, and the key to derive its piece key from.