Skip to main content
Use this guide to grant another signed-in TinyCloud principal access to a path in your space. In the examples, alice and bob are SDK instances that have already completed signIn().

Create and use a delegation

Use the recipient’s owner DID. After wallet sign-in, bob.did is that owner DID; bob.sessionDid identifies the ephemeral session key instead.
useDelegation() returns a DelegatedAccess handle for the delegator’s space. Its KV service is already rooted at shared/, so its keys are relative to that delegated path. It does not copy the data into the recipient’s space.

Serialize for transport

createDelegation() returns a PortableDelegation object. To send it as text, use the SDK helpers instead of manually converting its Date fields:
The same helpers are exported by @tinycloud/web-sdk for browser applications. The serialized delegation is a bearer credential; do not log it or send it through an untrusted channel.

Narrow access further

If the parent permits sub-delegation, Bob can grant Carol a narrower subset:
The child must stay within the parent’s resources and action set, cannot outlive the parent, and cannot bypass a parent’s sub-delegation restriction. Without expiryMs, createSubDelegation defaults to the longest lifetime the parent allows. Sessions activated from a received delegation default the same way.

Block further delegation

createSubDelegation() signs with the wallet, so it cannot set disableSubDelegation; passing true throws. To issue a grant the recipient cannot pass on, use createDelegation() with disableSubDelegation: true and address it to the recipient’s session-key did:key, not its did:pkh owner DID. Here carolSession is a client without a wallet signer. Its credentialHolderDid is the bare did:key session-key DID; use it rather than carolSession.did, which carries a #fragment that createDelegation rejects as an invalid audience DID:
The delegation carries the node’s terminal marker, so the node refuses any delegation that cites it as a parent. A recipient in wallet mode chains a new session from the grant, which the node refuses for a terminal parent, so createDelegation() throws if disableSubDelegation is combined with a did:pkh recipient. Drop the flag for a wallet recipient.

Revoke access

Both the Node and Web SDKs expose revokeDelegation():
Revocation is node-confirmed and invalidates use of that delegation. Revoking an ancestor also prevents its descendants from being used. The Node SDK can query the node-confirmed lifecycle state:
Delegations also stop working at their signed expiry. Expiry limits exposure, but it is not a substitute for revokeDelegation() when access must end now.

Inspect received grants

The Node SDK records delegations installed by useDelegation():
For the SDK transport fields and the node’s validation model, see Delegations.