@web5/agent
Version:
107 lines • 4.67 kB
TypeScript
import type { RequireOnly } from '@web5/common';
import type { AgentDataStore } from './store-data.js';
import type { Web5PlatformAgent } from './types/agent.js';
import type { DidMethodCreateOptions } from './did-api.js';
import type { AgentKeyManager } from './types/key-manager.js';
import type { IdentityMetadata, PortableIdentity } from './types/identity.js';
import { BearerIdentity } from './bearer-identity.js';
export interface IdentityApiParams<TKeyManager extends AgentKeyManager> {
agent?: Web5PlatformAgent<TKeyManager>;
store?: AgentDataStore<IdentityMetadata>;
}
export interface IdentityCreateParams<TKeyManager = AgentKeyManager, TMethod extends keyof DidMethodCreateOptions<TKeyManager> = keyof DidMethodCreateOptions<TKeyManager>> {
metadata: RequireOnly<IdentityMetadata, 'name'>;
didMethod?: TMethod;
didOptions?: DidMethodCreateOptions<TKeyManager>[TMethod];
store?: boolean;
}
export declare function isPortableIdentity(obj: unknown): obj is PortableIdentity;
/**
* This API is used to manage and interact with Identities within the Web5 Agent framework.
* An Identity is a DID that is associated with metadata that describes the Identity.
* Metadata includes A name(label), and whether or not the Identity is connected (delegated to act on the behalf of another DID).
*
* A KeyManager is used to manage the cryptographic keys associated with the Identities.
*
* The `DidApi` is used internally to create, store, and manage DIDs.
* When a DWN Data Store is used, the Identity and DID information are stored under the Agent DID's tenant.
*/
export declare class AgentIdentityApi<TKeyManager extends AgentKeyManager = AgentKeyManager> {
/**
* Holds the instance of a `Web5PlatformAgent` that represents the current execution context for
* the `AgentIdentityApi`. This agent is used to interact with other Web5 agent components. It's
* vital to ensure this instance is set to correctly contextualize operations within the broader
* Web5 Agent framework.
*/
private _agent?;
private _store;
constructor({ agent, store }?: IdentityApiParams<TKeyManager>);
/**
* Retrieves the `Web5PlatformAgent` execution context.
*
* @returns The `Web5PlatformAgent` instance that represents the current execution context.
* @throws Will throw an error if the `agent` instance property is undefined.
*/
get agent(): Web5PlatformAgent<TKeyManager>;
set agent(agent: Web5PlatformAgent<TKeyManager>);
get tenant(): string;
create({ metadata, didMethod, didOptions, store }: IdentityCreateParams<TKeyManager>): Promise<BearerIdentity>;
export({ didUri }: {
didUri: string;
}): Promise<PortableIdentity>;
get({ didUri }: {
didUri: string;
}): Promise<BearerIdentity | undefined>;
import({ portableIdentity }: {
portableIdentity: PortableIdentity;
}): Promise<BearerIdentity>;
list({ tenant }?: {
tenant?: string;
}): Promise<BearerIdentity[]>;
delete({ didUri }: {
didUri: string;
}): Promise<void>;
/**
* Returns the DWN endpoints for the given DID.
*
* @param didUri - The DID URI to get the DWN endpoints for.
* @returns An array of DWN endpoints.
* @throws An error if the DID is not found, or no DWN service exists.
*/
getDwnEndpoints({ didUri }: {
didUri: string;
}): Promise<string[]>;
/**
* Sets the DWN endpoints for the given DID.
*
* @param didUri - The DID URI to set the DWN endpoints for.
* @param endpoints - The array of DWN endpoints to set.
* @throws An error if the DID is not found, or if an update cannot be performed.
*/
setDwnEndpoints({ didUri, endpoints }: {
didUri: string;
endpoints: string[];
}): Promise<void>;
/**
* Updates the Identity's metadata name field.
*
* @param didUri - The DID URI of the Identity to update.
* @param name - The new name to set for the Identity.
*
* @throws An error if the Identity is not found, name is not provided, or no changes are detected.
*/
setMetadataName({ didUri, name }: {
didUri: string;
name: string;
}): Promise<void>;
/**
* Returns the connected Identity, if one is available.
*
* Accepts optional `connectedDid` parameter to filter the a specific connected identity,
* if none is provided the first connected identity is returned.
*/
connectedIdentity({ connectedDid }?: {
connectedDid?: string;
}): Promise<BearerIdentity | undefined>;
}
//# sourceMappingURL=identity-api.d.ts.map