Delegation API
delegate
Issues a delegation credential from an owner to an agent, granting specific scoped permissions.
function delegate(options: DelegateOptions): Promise<DelegationCredential>Parameters
DelegateOptions
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
agent | string | Yes | --- | DID of the agent receiving the delegation |
owner | string | Yes | --- | DID of the owner granting it |
ownerKeyPair | KeyPair | Yes | --- | Owner’s signing key pair |
scopes | string[] | Yes | --- | Permissions to grant (min 1) |
constraints | DelegationConstraints | No | --- | Additional limits |
validFrom | string | No | --- | ISO 8601 start time |
validUntil | string | No | --- | ISO 8601 expiration time |
statusList | { url: string; index: number } | No | --- | Status list entry for revocation |
parentDelegation | { token: string; parentOwnerPublicKey: Uint8Array } | No | --- | Parent delegation for chaining (see Delegation Chains) |
maxChainDepth | number | No | 3 | Maximum allowed chain depth |
DelegationConstraints
| Field | Type | Description |
|---|---|---|
maxTransactionValue | number | Maximum value per operation |
validUntil | string | ISO 8601 expiration |
allowedDomains | string[] | Permitted domains |
rateLimit | number | Max operations per time window |
[key: string] | unknown | Any custom constraint |
Returns
DelegationCredential
| Field | Type | Description |
|---|---|---|
token | string | The signed SD-JWT VC token (send this to services) |
claims | DelegationClaims | The decoded claims for local use |
DelegationClaims
| Field | Type | Description |
|---|---|---|
agent | string | Agent DID |
owner | string | Owner DID |
scopes | string[] | Granted scopes |
constraints | DelegationConstraints | undefined | Constraints, if set |
validFrom | string | undefined | Start time |
validUntil | string | undefined | Expiration time |
Example
import { delegate, generateKeyPair } from "@credat/sdk";
const ownerKeyPair = generateKeyPair("ES256");
const delegation = await delegate({
agent: "did:web:acme.com:agents:bot",
owner: "did:web:acme.com",
ownerKeyPair: ownerKeyPair,
scopes: ["files:read", "files:write"],
constraints: {
allowedDomains: ["storage.acme.com"],
},
validUntil: "2026-06-01T00:00:00Z",
});Errors
| Code | When |
|---|---|
DELEGATION_SCOPE_INVALID | Empty scopes array, or scopes not a subset of parent delegation |
DELEGATION_INVALID | Parent delegation is invalid, or chain depth exceeds maxChainDepth |
verifyDelegation
Verifies a delegation credential’s signature and expiration.
function verifyDelegation(
token: string,
options: VerifyDelegationOptions,
): Promise<DelegationResult>Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
token | string | Yes | The raw SD-JWT VC token from delegation.token |
VerifyDelegationOptions
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
ownerPublicKey | Uint8Array | Yes | --- | The owner’s public key |
checkRevocation | (entry: StatusListEntry) => Promise<boolean> | No | --- | Callback to check if a credential is revoked |
maxChainDepth | number | No | 3 | Maximum allowed chain depth for chained delegations |
resolveSignerKey | (agentDid: string) => Promise<Uint8Array> | No | --- | Resolve an agent’s public key by DID (required for chained delegations) |
Returns
DelegationResult
| Field | Type | Description |
|---|---|---|
valid | boolean | Whether the delegation is valid |
agent | string | undefined | Agent DID (may be undefined if verification failed before parsing) |
owner | string | Owner DID |
scopes | string[] | Granted scopes |
constraints | DelegationConstraints | undefined | Constraints |
validFrom | string | undefined | Start time |
validUntil | string | undefined | Expiration time |
errors | VerificationError[] | Errors (empty if valid) |
Example
import { verifyDelegation } from "@credat/sdk";
const result = await verifyDelegation(delegation.token, {
ownerPublicKey: ownerKeyPair.publicKey,
});
if (result.valid) {
console.log(result.scopes);
} else {
console.error(result.errors);
}Errors in result
| Code | Meaning |
|---|---|
DELEGATION_SIGNATURE_INVALID | Token was not signed by the given public key |
DELEGATION_EXPIRED | Delegation has expired |
DELEGATION_NOT_YET_VALID | Delegation’s validFrom is in the future |
DELEGATION_REVOKED | Delegation was revoked via status list |
DELEGATION_INVALID | Chain depth exceeded, parent invalid, or missing resolveSignerKey |
Related guides
- Enforce delegation constraints — How to check
maxTransactionValue,allowedDomains,rateLimit, and custom constraints - Credential revocation — End-to-end revocation workflow with status lists
Last updated on