# @filoz/keysmith

## Interfaces

| Interface | Description |
| ------ | ------ |
| [Claim](/reference/filoz/keysmith/interfaces/claim/) | One link: what its bearer may read, and how much further they may delegate. |
| [ClaimChain](/reference/filoz/keysmith/interfaces/claimchain/) | A chain, root first, with the fields every link inherits from the root. |
| [ClaimSigner](/reference/filoz/keysmith/interfaces/claimsigner/) | Anything that signs EIP-712 typed data: a viem account or wallet client. |
| [DerivedGroupKey](/reference/filoz/keysmith/interfaces/derivedgroupkey/) | What `deriveGroupKey()` hands back. The signature it came from is never exposed. |
| [DeriveGroupKeyOptions](/reference/filoz/keysmith/interfaces/derivegroupkeyoptions/) | - |
| [Grant](/reference/filoz/keysmith/interfaces/grant/) | A node key wrapped to one recipient. Safe to store or send anywhere. |
| [GrantDescriptor](/reference/filoz/keysmith/interfaces/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](/reference/filoz/keysmith/interfaces/groupkeyref/) | Identifies the group key a key belongs to. |
| [PieceMetadataView](/reference/filoz/keysmith/interfaces/piecemetadataview/) | A piece's labels as `readPieceMetadata()` returns them: canonical, validated. |
| [ReadRequest](/reference/filoz/keysmith/interfaces/readrequest/) | A request for one piece, from whichever provider holds it, signed by the chain's final bearer. |
| [TypedDataSigner](/reference/filoz/keysmith/interfaces/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](/reference/filoz/keysmith/interfaces/verifiedclaim/) | The final claim of a verified chain. |
| [WriteTarget](/reference/filoz/keysmith/interfaces/writetarget/) | What `writeTarget()` hands a delegate: everything needed to write one piece. |

## Type Aliases

| Type Alias | Description |
| ------ | ------ |
| [DecodedGrant](/reference/filoz/keysmith/type-aliases/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](/reference/filoz/keysmith/type-aliases/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](/reference/filoz/keysmith/type-aliases/granttarget/) | What a grant is picked for: reading one piece, or writing (or reading) under a group of a group key. |
| [GroupKeyMessage](/reference/filoz/keysmith/type-aliases/groupkeymessage/) | The message an owner signs to start the derivation tree. |
| [Holding](/reference/filoz/keysmith/type-aliases/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](/reference/filoz/keysmith/type-aliases/grantnode/) to one of them. |
| [PieceLabels](/reference/filoz/keysmith/type-aliases/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](/reference/filoz/keysmith/type-aliases/piecemetadata/) | The format `pieceMetadata()` writes and `readPieceMetadata()` reads. |
| [PieceMetadataV2](/reference/filoz/keysmith/type-aliases/piecemetadatav2/) | FEE envelope entries to enable key derivation/recovery. |

## Variables

| Variable | Description |
| ------ | ------ |
| [COMMITMENT\_KEY](/reference/filoz/keysmith/variables/commitment_key/) | The FWSS data-set metadata key the commitment is written to. |
| [DOMAIN](/reference/filoz/keysmith/variables/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](/reference/filoz/keysmith/variables/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](/reference/filoz/keysmith/variables/max_chain_length/) | - |
| [MAX\_REQUEST\_LIFETIME](/reference/filoz/keysmith/variables/max_request_lifetime/) | - |
| [READ\_GRANT\_TYPES](/reference/filoz/keysmith/variables/read_grant_types/) | EIP-712 types for every link and for a request. The domain is Keysmith's [DOMAIN](/reference/filoz/keysmith/variables/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](/reference/filoz/keysmith/variables/read_request_types/) | - |

## Functions

| Function | Description |
| ------ | ------ |
| [authorizationHeader](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/commitment/)) under `foc/kc`, so the chain alone can list a wallet's group keys. |
| [decodeDelivery](/reference/filoz/keysmith/functions/decodedelivery/) | - |
| [decodeGrant](/reference/filoz/keysmith/functions/decodegrant/) | Read a grant delivered as bytes, without opening it: to see what it names before unwrapping, or to pass to [holdingOf](/reference/filoz/keysmith/functions/holdingof/). |
| [decodePresentation](/reference/filoz/keysmith/functions/decodepresentation/) | - |
| [delegateClaim](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/derivegroupkey/) | Sign for one group key and derive its key. |
| [encodeDelivery](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/encodegrant/) | Pack the grant to deliver or store it |
| [encodePresentation](/reference/filoz/keysmith/functions/encodepresentation/) | A presentation: sent to a provider with each gated request, as `Authorization: FOC-Grant <base64url>`. |
| [grantDescriptor](/reference/filoz/keysmith/functions/grantdescriptor/) | The descriptor naming what a grant unlocks, ready for `wrapTo()`. |
| [groupKeyId](/reference/filoz/keysmith/functions/groupkeyid/) | Canonical form of a group key id: 16 bytes of hex, lowercase, prefixed with `0x`. |
| [groupKeyIdOf](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/groupkeymessage/) | - |
| [groupName](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/grouppath/) | Canonicalize group path: canonical names joined by `/`, top group first. |
| [holdingOf](/reference/filoz/keysmith/functions/holdingof/) | Which node a grant carries, ready to pass to [keyForEnvelope](/reference/filoz/keysmith/functions/keyforenvelope/). |
| [keyCommitmentOf](/reference/filoz/keysmith/functions/keycommitmentof/) | A key's commitment as the 16 bytes a claim carries. |
| [keyForEnvelope](/reference/filoz/keysmith/functions/keyforenvelope/) | Derive a piece's key from whichever node the caller holds. |
| [keyForGroup](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/lowsrs/) | Canonicalize signature:`r‖s` with `s` normalised to the low half, and `v` dropped. |
| [matchesCommitment](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/newsalt/) | A fresh per-piece salt. Public: it only has to travel with the piece. |
| [openDelivery](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/piecekey/) | The key for one piece. Never reused: FEE requires a fresh key per object. |
| [pieceMetadata](/reference/filoz/keysmith/functions/piecemetadata/) | Piece FEE envelope metadata entries. Read them back with [readPieceMetadata](/reference/filoz/keysmith/functions/readpiecemetadata/). |
| [pieceNode](/reference/filoz/keysmith/functions/piecenode/) | The grant node for one piece, from its envelope metadata: `piece:<salt>`. |
| [publicKeyOf](/reference/filoz/keysmith/functions/publickeyof/) | The public key a sender wraps to, for the holder of a secp256k1 private key. |
| [reaches](/reference/filoz/keysmith/functions/reaches/) | Whether `node` reaches the piece these labels describe. Reads only the label the node's kind needs. |
| [readPieceMetadata](/reference/filoz/keysmith/functions/readpiecemetadata/) | Read a piece's envelope metadata (`foc/v` 2: `foc/gkid`, `foc/group`) into one canonical shape. |
| [rootClaim](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/signrequest/) | Sign a request for one piece, as the chain's final bearer. Any provider holding it may serve it. |
| [unwrapWith](/reference/filoz/keysmith/functions/unwrapwith/) | Open a grant with the recipient's private key: the grant as delivered, in bytes, or as decoded by [decodeGrant](/reference/filoz/keysmith/functions/decodegrant/). |
| [verifyChain](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/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](/reference/filoz/keysmith/functions/wrapto/) | Wrap a node key — a group key, a group's key, or one piece's key — to a recipient. |
| [writeTarget](/reference/filoz/keysmith/functions/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. |