import BaseAuthenticator from './base.js'; export interface ApplicationInfo { name: string; description: string; icon: string; link?: string; path?: string; publisher?: string; } export interface ChainInfo { id: string; type: string; host: string; } /** * Encodes an on-chain transaction into a signed buffer. * * Inject this to support `signature` / `prepareTx` claims that reference * concrete transaction types (e.g. `TransferV2Tx`). When omitted, those * code paths throw a clear error — lightweight runtimes (Cloudflare Workers, * Edge) can skip the ~2.5 MB `@ocap/client` dependency entirely. * * A typical implementation using `@ocap/client`: * ```ts * import Client from '@ocap/client'; * const txEncoder: TxEncoder = async ({ type, data, wallet, chainHost }) => { * const client = new Client(chainHost); * const { buffer } = await client[`encode${type}`]({ tx: data, wallet }); * return buffer; * }; * ``` */ export type TxEncoder = (params: { /** Transaction type name, e.g. `"TransferV2Tx"` */ type: string; /** Transaction data object */ data: any; /** Wallet used for encoding */ wallet: any; /** Chain RPC endpoint */ chainHost: string; }) => Promise; export interface WalletAuthenticatorConfig { wallet: any; appInfo: ApplicationInfo | ((params: any) => ApplicationInfo | Promise); memberAppInfo?: ApplicationInfo | ((params: any) => ApplicationInfo | Promise) | null; delegator?: any; delegation?: string | ((params: any) => string | Promise); timeout?: number; chainInfo?: ChainInfo | ((params: any) => ChainInfo | Promise); baseUrl?: string; tokenKey?: string; /** Optional transaction encoder — required only when using on-chain Tx signature claims. */ txEncoder?: TxEncoder; } declare class WalletAuthenticator extends BaseAuthenticator { wallet: any; appInfo: any; memberAppInfo: any; chainInfo: any; delegator: any; delegation: any; baseUrl: string; tokenKey: string; timeout: number; txEncoder?: TxEncoder; static formatDisplay(display: any): string; /** * Creates an instance of DID Authenticator. * * @class * @param {object} config * @param {WalletObject|Function} config.wallet - wallet instance {@see @ocap/wallet} or a function that returns wallet instance * @param {WalletObject|Function} [config.delegator] - the party that authorizes `wallet` to perform actions on behalf of `wallet` * @param {string|Function} [config.delegation] - the jwt token that proves delegation relationship * @param {ApplicationInfo|Function} config.appInfo - application basic info or a function that returns application info * @param {ChainInfo|Function} config.chainInfo - application chain info or a function that returns chain info * @param {Number} [config.timeout=8000] - timeout in milliseconds when generating claim * @param {object} [config.baseUrl] - url to assemble wallet request uri, can be inferred from request object * @param {string} [config.tokenKey='_t_'] - query param key for `token` */ constructor({ wallet, appInfo, memberAppInfo, delegator, delegation, timeout, chainInfo, baseUrl, tokenKey, txEncoder, }: WalletAuthenticatorConfig); /** * Generate a deep link url that can be displayed as QRCode for DID Wallet to consume * * @method * @param {object} params * @param {string} params.baseUrl - baseUrl inferred from request object * @param {string} params.pathname - wallet callback pathname * @param {string} params.token - action token * @param {object} params.query - params that should be persisted in wallet callback url * @returns {string} */ uri({ baseUrl, pathname, token, query, }?: { baseUrl?: string; pathname?: string; token?: string; query?: Record; }): string; /** * Compute public url to return to wallet * * @method * @param {string} pathname * @param {object} params * @returns {string} */ getPublicUrl(pathname: string, params?: Record, baseUrl?: string): string; /** * Sign a plain response, usually on auth success or error * * @method * @param {object} params * @param {object} params.response - response * @param {string} params.errorMessage - error message, default to empty * @param {string} params.successMessage - success message, default to empty * @param {string} params.nextWorkflow - https://github.com/ArcBlock/ABT-DID-Protocol#concatenate-multiple-workflow * @param {string} params.nextUrl - tell wallet do open this url in webview * @param {object} params.cookies - key-value pairs to be set as cookie before open nextUrl * @param {object} params.storages - key-value pairs to be set as localStorage before open nextUrl * @param {string} baseUrl * @param {object} request * @returns {Promise} { appPk, agentPk, authInfo } */ signResponse({ response, errorMessage, successMessage, nextWorkflow, nextUrl, cookies, storages, }: { response?: any; errorMessage?: string; successMessage?: string; nextWorkflow?: string; nextUrl?: string; cookies?: Record; storages?: any; }, baseUrl: string, request: any, extraParams?: Record): Promise; /** * Sign a auth response that returned to wallet: tell the wallet the appInfo/chainInfo * * @method * @param {object} params * @param {object} params.claims - info required by application to complete the auth * @param {string} params.pathname - pathname to assemble callback url * @param {string} params.baseUrl - baseUrl * @param {object} params.challenge - random challenge to be included in the body * @param {object} params.extraParams - extra query params and locale * @param {object} params.request * @param {object} params.context * @param {string} params.context.token - action token * @param {number} params.context.currentStep - current step * @param {string} [params.context.sharedKey] - shared key between app and wallet * @param {string} [params.context.encryptionKey] - encryption key from wallet * @param {Function} [params.context.mfaCode] - function used to generate mfa code * @param {string} params.context.userDid - decoded from req.query, base58 * @param {string} params.context.userPk - decoded from req.query, base58 * @param {string} params.context.didwallet - DID Wallet os and version * @returns {Promise} { appPk, agentPk, sharedKey, authInfo } */ sign({ context, request, claims, pathname, baseUrl, challenge, extraParams, }: { context: any; request: any; claims: any; pathname?: string; baseUrl?: string; challenge?: string; extraParams?: Record; }): Promise; /** * Determine chainInfo on the fly * * @param {object} params - contains the context of this request * @param {object|undefined} [info=undefined] - chain info object or function * @returns {Promise} * @memberof WalletAuthenticator */ getChainInfo(params: any, info?: any): Promise; /** * Determine appInfo/memberAppInfo on the fly * * @param {object} params - contains the context of this request * @param {string} key - appInfo | memberAppInfo * @returns {Promise} * @memberof WalletAuthenticator */ getAppInfo(params: any, key?: 'appInfo' | 'memberAppInfo'): Promise; getWalletInfo(params: any): Promise; getDelegator(params: any): Promise; getDelegation(params: any): Promise; /** * Verify a DID auth response sent from DID Wallet * * @method * @param {object} data * @param {string} [locale=en] * @param {boolean} [enforceTimestamp=true] * @returns Promise */ verify(data: any, locale?: string, enforceTimestamp?: boolean): Promise<{ token: any; userDid: string; userPk: any; claims: any; action: any; challenge: any; timestamp: string; }>; genRequestedClaims({ claims, context, extraParams, }: { claims: any; context: any; extraParams: Record; }): Promise; getClaimInfo({ claim, context, extraParams, }: { claim: any; context: any; extraParams: Record; }): Promise; signature({ claim, context, extraParams, }: { claim: any; context: any; extraParams: Record; }): Promise<{ type: string; description: any; origin: string; typeUrl: any; display: string; method: any; digest: any; chainInfo: any; meta: any; mfa: any; nonce: any; requirement: any; }>; prepareTx({ claim, context, extraParams, }: { claim: any; context: any; extraParams: Record; }): Promise<{ type: string; description: any; partialTx: string; display: string; requirement: any; chainInfo: any; meta: any; mfa: any; nonce: any; }>; _validateAppInfo(info: any, allowEmpty?: boolean): any; _isValidChainInfo(x: any): boolean; tryWithTimeout(asyncFn: () => Promise, label?: string): Promise; } export default WalletAuthenticator; //# sourceMappingURL=wallet.d.ts.map