@dfinity/oisy-wallet-signer
Version:
A library designed to facilitate communication between a dApp and the OISY Wallet on the Internet Computer.
134 lines (133 loc) • 8.24 kB
TypeScript
import type { IcrcAccounts } from './types/icrc-accounts';
import type { IcrcAnyRequestedScopes, IcrcCallCanisterRequestParams } from './types/icrc-requests';
import { type IcrcCallCanisterResult, type IcrcScopesArray, type IcrcSupportedStandards } from './types/icrc-responses';
import type { Origin } from './types/post-message';
import { type RelyingPartyHost, type RelyingPartyOptions } from './types/relying-party-options';
import { type RelyingPartyRequestOptions } from './types/relying-party-requests';
export declare class RelyingParty {
#private;
protected readonly host: RelyingPartyHost;
protected constructor({ origin, popup, onDisconnect, host }: {
origin: Origin;
popup: Window;
} & Pick<RelyingPartyOptions, 'onDisconnect' | 'host'>);
/**
* Establishes a connection with a signer.
*
* @static
* @param {RelyingPartyOptions} options - The options to initialize the signer.
* @returns {Promise<RelyingParty>} A promise that resolves to an object, which can be used to interact with the signer when it is connected.
*/
static connect({ onDisconnect, ...rest }: RelyingPartyOptions): Promise<RelyingParty>;
protected static connectSigner<T extends RelyingParty>({ options, init }: {
options: RelyingPartyOptions;
init: (params: {
origin: Origin;
popup: Window;
}) => T;
}): Promise<T>;
/**
* Disconnects the signer by closing the associated popup window.
*
* @returns {Promise<void>} A promise that resolves when the signer has been successfully disconnected.
*/
disconnect: () => Promise<void>;
private checkWalletStatusCallback;
private checkWalletStatus;
/**
* Sends an asynchronous request to the signer and handles the response with the provided handlers.
*
* @template T - The type of the result expected from the response.
*
* @param {Object} params - Parameters for the request.
* @param {RelyingPartyRequestOptions} params.options - Options for configuring the signer request.
* @param {(id: RpcId) => void} params.postRequest - The request function that sends the request to the signer using either the provided ID or a generated ID.
* @param {(params: { data: RelyingPartyMessageEventData; id: RpcId }) => Promise<{ handled: boolean; result?: T }>} params.handleMessage -
* A function to handle incoming messages, which should return an object indicating whether the message was handled and optionally include the result. If both `handled` is `true` and the `result` is not `null`, the process is disconnected, i.e., no more listeners will await an answer from the relying party.
*
* @returns {Promise<T>} A promise that resolves with the result of the request.
*
* @throws {Error} If the signer request options cannot be parsed or if the request times out.
*
* @private
*/
private readonly request;
private assertWalletConnected;
/**
* List the standards supported by the signer.
*
* @async
* @param {RelyingPartyRequestOptions} options - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @returns {Promise<IcrcSupportedStandards>} A promise that resolves to an object containing the supported ICRC standards by the relying party. This includes details about each standard that the relying party can handle.
* @see [ICRC25 Supported Standards](https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_25_signer_interaction_standard.md#icrc25_supported_standards)
*/
supportedStandards: ({ options: { timeoutInMilliseconds, ...rest } }?: {
options?: RelyingPartyRequestOptions;
}) => Promise<IcrcSupportedStandards>;
/**
* Query the state of all permissions of the signer.
*
* @async
* @param {RelyingPartyRequestOptions} options - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @returns {Promise<IcrcScopes>} A promise that resolves to all permissions the signer knows about. The result might be empty if no permissions were ever requested or if the permissions are outdated.
* @see [ICRC25 Permissions](https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_25_signer_interaction_standard.md#icrc25_permissions)
*/
permissions: ({ options: { timeoutInMilliseconds, ...rest } }?: {
options?: RelyingPartyRequestOptions;
}) => Promise<IcrcScopesArray>;
/**
* Request permissions from the signer.
*
* @async
* @param {Object} args - The arguments object.
* @param {RelyingPartyRequestOptions} [args.options] - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @param {Partial<IcrcAnyRequestedScopes>} [args.params] - The specific scopes being requested from the signer. These define the permissions that the signer may grant.
* @returns {Promise<IcrcScopesArray>} A promise that resolves to the permissions that were confirmed by the user of the signer.
* @see [ICRC25 Request Permissions](https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_25_signer_interaction_standard.md#icrc25_request_permissions)
*/
requestPermissions: ({ options: { timeoutInMilliseconds, ...rest }, params }?: {
options?: RelyingPartyRequestOptions;
params?: IcrcAnyRequestedScopes;
}) => Promise<IcrcScopesArray>;
private readonly requestPermissionsScopes;
/**
* List the accounts supported by the signer.
*
* @async
* @param {RelyingPartyRequestOptions} options - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @returns {Promise<IcrcAccounts>} A promise that resolves to an object containing the supported ICRC accounts by the signer.
* @see [ICRC27 Get Accounts](https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_27_accounts.md)
*/
accounts: ({ options: { timeoutInMilliseconds, ...rest } }?: {
options?: RelyingPartyRequestOptions;
}) => Promise<IcrcAccounts>;
/**
* Call a canister method via the signer.
*
* @async
* @template T - The type of the argument being passed to the canister call.
* @param {Object} args - The arguments for the call.
* @param {IcrcCallCanisterRequestParams} args.params - The parameters required to call the canister, including the canister ID, method name, and the encoded argument payload.
* @param {RelyingPartyRequestOptions} [args.options] - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @returns {Promise<IcrcCallCanisterResult>} A promise that resolves to the result of the canister call.
* @see [ICRC49 Call Canister](https://github.com/dfinity/wg-identity-authentication/blob/main/topics/icrc_49_call_canister.md)
*/
protected call: ({ options: { timeoutInMilliseconds, ...rest }, params }: {
options?: RelyingPartyRequestOptions;
params: IcrcCallCanisterRequestParams;
}) => Promise<IcrcCallCanisterResult>;
private readonly handleErrorMessage;
/**
* Checks the current set of permissions and automatically requests any that have not yet been granted.
* This is useful for dApps that wish to request all necessary permissions up-front.
*
* @async
* @param {RelyingPartyRequestOptions} options - The options for the signer request, which may include parameters such as timeout settings and other request-specific configurations.
* @returns {Promise<{allPermissionsGranted: boolean}>} - A promise resolving to an object indicating whether all required permissions have been granted.
*/
requestPermissionsNotGranted: ({ options }?: {
options?: RelyingPartyRequestOptions;
}) => Promise<{
allPermissionsGranted: boolean;
}>;
}