/** * @typedef {API.Service} Service * @typedef {API.Receipt} Receipt */ /** * Creates a Ucanto connection for the w3access API * * Usage: * * ```js * import { connection } from '@storacha/access/agent' * ``` * * @template {API.DID} T - DID method * @template {Record} [S=Service] * @param {object} [options] * @param {API.Principal} [options.principal] - w3access API Principal * @param {URL} [options.url] - w3access API URL * @param {API.Transport.Channel} [options.channel] - Ucanto channel to use * @param {typeof fetch} [options.fetch] - Fetch implementation to use * @returns {API.ConnectionView} */ export function connection = API.Service>(options?: { principal?: Client.Principal | undefined; url?: URL | undefined; channel?: Client.Channel | undefined; fetch?: typeof fetch | undefined; }): API.ConnectionView; /** * Given a list of delegations, add to agent data spaces list. * * @deprecated - trying to remove explicit space tracking from Agent/AgentData * in favor of functions that derive the space set from access.delegations * * @template {Record} [S=Service] * @param {Agent} agent * @param {API.Delegation[]} delegations */ export function addSpacesFromDelegations = API.Service>(agent: Agent, delegations: API.Delegation[]): Promise; export * from "./types.js"; export * from "./delegations.js"; export * from "./agent-use-cases.js"; /** * Agent * * Usage: * * ```js * import { Agent } from '@storacha/access/agent' * ``` * * @template {Record} [S=Service] */ export class Agent = API.Service> { /** * Create a new Agent instance, optionally with the passed initialization data. * * @template {Record} [R=Service] * @param {Partial} [init] * @param {import('./types.js').AgentOptions & import('./types.js').AgentDataOptions} [options] */ static create = API.Service>(init?: Partial, options?: import("./types.js").AgentOptions & import("./types.js").AgentDataOptions): Promise>; /** * Instantiate an Agent from pre-exported agent data. * * @template {Record} [R=Service] * @param {import('./types.js').AgentDataExport} raw * @param {import('./types.js').AgentOptions & import('./types.js').AgentDataOptions} [options] */ static from = API.Service>(raw: import("./types.js").AgentDataExport, options?: import("./types.js").AgentOptions & import("./types.js").AgentDataOptions): API.Agent; /** * @param {import('./agent-data.js').AgentData} data - Agent data * @param {import('./types.js').AgentOptions} [options] */ constructor(data: import("./agent-data.js").AgentData, options?: import("./types.js").AgentOptions); url: URL; connection: Client.ConnectionView; get issuer(): Client.Signer<`did:key:${string}`, Client.SigAlg>; get meta(): API.AgentMeta; get spaces(): Map<`did:${string}:${string}`, API.SpaceMeta>; did(): `did:key:${string}`; /** * Add a proof to the agent store. * * @param {API.Delegation} delegation */ addProof(delegation: API.Delegation): Promise<{}>; /** * Adds set of proofs to the agent store. * * @param {Iterable} delegations */ addProofs(delegations: Iterable): Promise<{}>; /** * Clean up any expired delegations. */ removeExpiredDelegations(): Promise; /** * Revoke a delegation by CID. * * If the delegation was issued by this agent (and therefore is stored in the * delegation store) you can just pass the CID. If not, or if the current agent's * delegation store no longer contains the delegation, you MUST pass a chain of * proofs that proves your authority to revoke this delegation as `options.proofs`. * * @param {API.UCANLink} delegationCID * @param {object} [options] * @param {API.Delegation[]} [options.proofs] */ revoke(delegationCID: API.UCANLink, options?: { proofs?: Client.Delegation[] | undefined; }): Promise>; /** * Get all the proofs matching the capabilities. * * Proofs are delegations with an audience matching agent DID, or with an * audience matching the session DID. * * Proof of session will also be included in the returned proofs if any * proofs matching the passed capabilities require it. * * @param {API.CapabilityQuery[]} [caps] - Capabilities to filter by. Empty or undefined caps with return all the proofs. * @param {object} [options] * @param {API.DID|API.DID[]} [options.sessionProofIssuer] - only include session proofs for these issuer(s) */ proofs(caps?: API.CapabilityQuery[], options?: { sessionProofIssuer?: `did:${string}:${string}` | `did:${string}:${string}`[] | undefined; }): Client.Delegation[]; /** * Get delegations created by the agent for others. * * @param {API.CapabilityQuery[]} [caps] - Capabilities to filter by. Empty or undefined caps with return all the delegations. */ delegations(caps?: API.CapabilityQuery[]): Client.Delegation[]; /** * Get delegations created by the agent for others and their metadata. * * @param {API.CapabilityQuery[]} [caps] - Capabilities to filter by. Empty or undefined caps with return all the delegations. */ delegationsWithMeta(caps?: API.CapabilityQuery[]): { delegation: API.Delegation; meta: API.DelegationMeta; }[]; /** * Creates a space signer and a delegation to the agent * * @param {string} name * @param {object} [options] * @param {API.SpaceAccessType} [options.access] - The access type for the space. Defaults to { type: 'public' }. */ createSpace(name: string, { access }?: { access?: API.SpaceAccessType | undefined; }): Promise>; /** * @param {string} secret * @param {object} options * @param {string} options.name - The name of the space. * @param {API.SpaceAccessType} [options.access] - The access type for the space. Defaults to { type: 'public' }. */ recoverSpace(secret: string, { name, access }: { name: string; access?: API.SpaceAccessType | undefined; }): Promise>; /** * Import a space from a delegation. * * @param {API.Delegation} delegation * @param {object} options * @param {string} [options.name] */ importSpaceFromDelegation(delegation: API.Delegation, { name }?: { name?: string | undefined; }): Promise; /** * Sets the current selected space * * Other methods will default to use the current space if no resource is defined * * @param {API.SpaceDID} space */ setCurrentSpace(space: API.SpaceDID): Promise<`did:key:${string}`>; /** * Get current space DID */ currentSpace(): `did:key:${string}` | undefined; /** * Get current space DID, proofs and abilities */ currentSpaceWithMeta(): { did: `did:key:${string}`; proofs: Client.Delegation[]; capabilities: any[]; meta: API.SpaceMeta | undefined; } | undefined; /** * * @param {import('./types.js').DelegationOptions} options */ delegate(options: import("./types.js").DelegationOptions): Promise>; /** * Invoke and execute the given capability on the Access service connection * * ```js * * await agent.invokeAndExecute(Space.recover, { * nb: { * identity: 'mailto: email@gmail.com', * }, * }) * * // sugar for * const recoverInvocation = await agent.invoke(Space.recover, { * nb: { * identity: 'mailto: email@gmail.com', * }, * }) * * await recoverInvocation.execute(agent.connection) * ``` * * @template {API.Ability} A * @template {API.URI} R * @template {API.Caveats} C * @param {API.TheCapabilityParser>} cap * @param {API.InvokeOptions>>} options * @returns {Promise, S>>} */ invokeAndExecute(cap: API.TheCapabilityParser>, options: API.InvokeOptions>>): Promise, S>>; /** * Execute invocations on the agent's connection * * @example * ```js * const i1 = await agent.invoke(Space.info, {}) * const i2 = await agent.invoke(Space.recover, { * nb: { * identity: 'mailto:hello@storacha.network', * }, * }) * * const results = await agent.execute2(i1, i2) * * ``` * @template {API.Capability} C * @template {API.Tuple>} I * @param {I} invocations */ execute>>(...invocations: I): Client.Await>; /** * Creates an invocation for the given capability with Agent's proofs, service, issuer and space. * * @example * ```js * const recoverInvocation = await agent.invoke(Space.recover, { * nb: { * identity: 'mailto: email@gmail.com', * }, * }) * * await recoverInvocation.execute(agent.connection) * // or * await agent.execute(recoverInvocation) * ``` * * @template {API.Ability} A * @template {API.URI} R * @template {API.TheCapabilityParser>} CAP * @template {API.Caveats} [C={}] * @param {CAP} cap * @param {import('./types.js').InvokeOptions} options */ invoke>, C extends API.Caveats = {}>(cap: CAP, options: import("./types.js").InvokeOptions): Promise>>; /** * Get Space information from Access service * * @param {API.URI<"did:">} [space] * @param {object} [options] * @param {string} [options.nonce] */ getSpaceInfo(space?: API.URI<"did:">, options?: { nonce?: string | undefined; }): Promise; #private; } export function importAuthorization(agent: Agent, { proofs }: { proofs: API.Delegation[]; }): Promise>; export type Service = API.Service; export type Receipt = API.Receipt; import * as API from './types.js'; import * as Client from '@ucanto/client'; import { AgentData } from './agent-data.js'; import * as Access from './access.js'; import * as Space from './space.js'; import { Delegation } from '@ucanto/core'; import { Schema } from '@ucanto/core'; export { AgentData, Access, Space, Delegation, Schema }; //# sourceMappingURL=agent.d.ts.map