UNPKG

@web5/agent

Version:
88 lines 4.29 kB
import type { DwnPermissionScope, DwnProtocolDefinition } from './index.js'; /** * Initiates the wallet connect process. Used when a client wants to obtain * a did from a provider. */ declare function initClient({ displayName, connectServerUrl, walletUri, permissionRequests, onWalletUriReady, validatePin, }: WalletConnectOptions): Promise<{ delegateGrants: import("@tbd54566975/dwn-sdk-js").DataEncodedRecordsWriteMessage[]; delegatePortableDid: import("@web5/dids").PortableDid; connectedDid: string; } | undefined>; /** * Initiates the wallet connect process. Used when a client wants to obtain * a did from a provider. */ export type WalletConnectOptions = { /** The user friendly name of the client/app to be displayed when prompting end-user with permission requests. */ displayName: string; /** The URL of the intermediary server which relays messages between the client and provider. */ connectServerUrl: string; /** * The URI of the Provider (wallet).The `onWalletUriReady` will take this wallet * uri and add a payload to it which will be used to obtain and decrypt from the `request_uri`. * @example `web5://` or `http://localhost:3000/`. */ walletUri: string; /** * The protocols of permissions requested, along with the definition and * permission scopes for each protocol. The key is the protocol URL and * the value is an object with the protocol definition and the permission scopes. */ permissionRequests: ConnectPermissionRequest[]; /** * The Web5 API provides a URI to the wallet based on the `walletUri` plus a query params payload valid for 5 minutes. * The link can either be used as a deep link on the same device or a QR code for cross device or both. * The query params are `{ request_uri: string; encryption_key: string; }` * The wallet will use the `request_uri to contact the intermediary server's `authorize` endpoint * and pull down the {@link Web5ConnectAuthRequest} and use the `encryption_key` to decrypt it. * * @param uri - The URI returned by the web5 connect API to be passed to a provider. */ onWalletUriReady: (uri: string) => void; /** * Function that must be provided to submit the pin entered by the user on the client. * The pin is used to decrypt the {@link Web5ConnectAuthResponse} that was retrieved from the * token endpoint by the client inside of web5 connect. * * @returns A promise that resolves to the PIN as a string. */ validatePin: () => Promise<string>; }; /** * The protocols of permissions requested, along with the definition and permission scopes for each protocol. */ export type ConnectPermissionRequest = { /** * The definition of the protocol the permissions are being requested for. * In the event that the protocol is not already installed, the wallet will install this given protocol definition. */ protocolDefinition: DwnProtocolDefinition; /** The scope of the permissions being requested for the given protocol */ permissionScopes: DwnPermissionScope[]; }; /** * Shorthand for the types of permissions that can be requested. */ export type Permission = 'write' | 'read' | 'delete' | 'query' | 'subscribe' | 'configure'; /** * The options for creating a permission request for a given protocol. */ export type ProtocolPermissionOptions = { /** The protocol definition for the protocol being requested */ definition: DwnProtocolDefinition; /** The permissions being requested for the protocol */ permissions: Permission[]; }; /** * Creates a set of Dwn Permission Scopes to request for a given protocol. * * If no permissions are provided, the default is to request all relevant record permissions (write, read, delete, query, subscribe). * 'configure' is not included by default, as this gives the application a lot of control over the protocol. */ declare function createPermissionRequestForProtocol({ definition, permissions }: ProtocolPermissionOptions): ConnectPermissionRequest; export declare const WalletConnect: { initClient: typeof initClient; createPermissionRequestForProtocol: typeof createPermissionRequestForProtocol; }; export {}; //# sourceMappingURL=connect.d.ts.map