UNPKG

@dfinity/oisy-wallet-signer

Version:

A library designed to facilitate communication between a dApp and the OISY Wallet on the Internet Computer.

70 lines (69 loc) 4.23 kB
import type { PrincipalText } from '@dfinity/zod-schemas'; import { type ApproveParams, type IcrcLedgerDid, type TransferFromParams, type TransferParams } from '@icp-sdk/canisters/ledger/icrc'; import { RelyingParty } from './relying-party'; import type { IcrcAccount } from './types/icrc-accounts'; import type { RelyingPartyOptions } from './types/relying-party-options'; import type { RelyingPartyRequestOptions } from './types/relying-party-requests'; export declare class IcrcWallet extends RelyingParty { /** * Establishes a connection with an ICRC Wallet. * * @override * @static * @param {RelyingPartyOptions} options - The options to initialize the ICRC Wallet signer. * @returns {Promise<IcrcWallet>} A promise that resolves to an object, which can be used to interact with the ICRC Wallet when it is connected. */ static connect({ onDisconnect, host, ...rest }: RelyingPartyOptions): Promise<IcrcWallet>; /** * Transfer Icrc tokens to the destination Account. Returns the index of the block containing the tx if it was successful. * * @param {Object} params - The transfer parameters. * @param {TransferParams} params.params - The object containing transfer details, such as amount and destination. * @param {string} params.owner - The owner of the wallet. * @param {PrincipalText} [params.ledgerCanisterId] - The ledger canister ID. * @param {RelyingPartyRequestOptions} [params.options] - Optional parameters for the request, such as request ID, authorization, or timeout. * * @returns {Promise<IcrcBlockIndex>} A promise that resolves to the block index of the transfer transaction if successful. */ transfer: ({ params, owner, ledgerCanisterId: canisterId, options }: { params: TransferParams; ledgerCanisterId: PrincipalText; options?: RelyingPartyRequestOptions; } & Pick<IcrcAccount, "owner">) => Promise<IcrcLedgerDid.BlockIndex>; /** * Approves a spender to transfer a specified amount of ICRC tokens from the owner's account. * * @param {Object} params - The approve parameters. * @param {ApproveParams} params.params - The details of the approval, including the spender's account and amount. * @param {string} params.owner - The owner of the wallet authorizing the spender. * @param {PrincipalText} [params.ledgerCanisterId] - The ledger canister ID. * @param {RelyingPartyRequestOptions} [params.options] - Optional parameters for the request, such as request ID, authorization, or timeout. * * @throws {IcrcTransferError} Throws an error if the approval fails. * * @returns {Promise<IcrcBlockIndex>} A promise that resolves to the block index of the approval transaction if successful. */ approve: ({ params, owner, ledgerCanisterId: canisterId, options }: { params: ApproveParams; ledgerCanisterId: PrincipalText; options?: RelyingPartyRequestOptions; } & Pick<IcrcAccount, "owner">) => Promise<IcrcLedgerDid.BlockIndex>; /** * Transfers ICRC tokens from one account to another using an approved allowance. * * @param {Object} params - The transfer-from parameters. * @param {TransferFromParams} params.params - The details of the transfer, including the source, destination, and amount. * @param {string} params.owner - The owner of the wallet initiating the transfer. * @param {PrincipalText} [params.ledgerCanisterId] - Optional ledger canister ID, defaults to the ICRC ledger if not provided. * @param {RelyingPartyRequestOptions} [params.options] - Optional parameters for the request, such as request ID, authorization, or timeout. * * @throws {IcrcTransferError} Throws an error if the transfer fails. * * @returns {Promise<IcrcBlockIndex>} A promise that resolves to the block index of the transfer transaction if successful. */ transferFrom: ({ params, owner, ledgerCanisterId: canisterId, options }: { params: TransferFromParams; ledgerCanisterId: PrincipalText; options?: RelyingPartyRequestOptions; } & Pick<IcrcAccount, "owner">) => Promise<IcrcLedgerDid.BlockIndex>; }