import { CID } from 'multiformats' import { DelegationPayload as IsoUcanDelegationPayload } from 'iso-ucan/types' /** * Delegation spec payload - matches ucan-wg/delegation * @see https://github.com/ucan-wg/delegation */ export interface DelegationPayload { /** Issuer DID - who is granting the delegation */ iss: string /** Audience DID - who receives the delegation */ aud: string /** Subject DID - the resource being delegated (e.g., storage server) */ sub: string /** Command path - the action being authorized (e.g., "/storage/store") */ cmd: string /** Policy predicates - constraints on the delegation (empty for now) */ pol: Policy[] /** Expiration timestamp in seconds since Unix epoch */ exp: number /** Not before timestamp (optional) */ nbf?: number /** Nonce for replay protection (REQUIRED per delegation spec) */ nonce: string } // not sure we ought to reinvent the wheel here ^ export type localDel = IsoUcanDelegationPayload /** * Serializable delegation payload for DAG-CBOR encoding. * Uses CID bytes instead of CID objects for proper CBOR serialization. */ export interface SerializableDelegationPayload extends Omit { /** Proof chain - CIDs of parent delegations (as link objects for DAG-CBOR) */ prf: CID[] } /** * Policy predicate - empty tuple for phase 1 (no constraints). * Will be expanded to predicate arrays in future phases. */ export type Policy = [] /** Storage commands supported by the delegation */ export type StorageCommand = '/storage/store' | '/storage/retrieve' | '/storage/read' | '/storage/pin' /** All UCAN commands (storage + IPNS) */ export type UcanCommand = StorageCommand | '/ipns/publish' /** * Signed delegation with serialized payload and signature. * This is what gets transmitted over the wire. */ export interface SignedDelegation { /** DAG-CBOR encoded and signed delegation bytes */ bytes: Uint8Array /** CID of the signed delegation */ cid: CID /** Original payload (for accessing fields without re-parsing) */ payload: DelegationPayload /** Proof delegations (full objects, not just CIDs) */ proofs: SignedDelegation[] } /** * Options for creating a storage delegation */ export interface CreateDelegationOptions { /** Issuer DID */ issuer: string /** Audience DID */ audience: string /** Subject DID (the storage server) */ subject: string /** Command to authorize */ command: UcanCommand /** Expiration timestamp (seconds since epoch), or Infinity for no expiration */ expiration: number /** Parent delegations as proofs */ proofs?: SignedDelegation[] /** Not-before timestamp (optional) */ notBefore?: number /** Nonce for replay protection (optional) */ nonce?: string }