import { ChainLegacy, GatewayToken, RootState } from '../types'; import { Action } from '../useReducer'; import { NetworkConfig } from '../networkConfig'; import GatekeeperClient from '../utils/gatekeeperClient'; export type HookFunctions = { waitForGatekeeperIssuanceRequest: (_value: { proof?: string; payload?: unknown; abortController?: AbortController; }) => Promise; waitForTransactionConfirm: () => Promise; waitForHandleTransaction: (transaction: string) => Promise; dispatchTokenExpectedTimerAdded: (listenerId: number) => void; dispatchTokenExpectedTimerCleared: (listenerId: number) => void; onGatewayTokenCreatedOrChanged: (token: GatewayToken) => void; addTokenChangeListener: (gatewayToken: GatewayToken, tokenChange: (GatewayToken: GatewayToken) => void) => Promise; }; export interface StateInterface { getState: () => RootState; } export interface DispatchInterface { dispatch: (a: Action) => void; } /** * The PassOrchestrator uses state (provided by the host-framework) to decide * which actions to emit based for different flows such as token issuance & refresh. */ export declare class PassOrchestrator { readonly stateInterface: StateInterface; readonly dispatchInterface: DispatchInterface; readonly abortController: AbortController; readonly hookFns: HookFunctions; readonly chainImplementation: ChainLegacy | undefined; readonly networkConfig: NetworkConfig; readonly gatekeeperClient: GatekeeperClient | undefined; private static instance; constructor(stateInterface: StateInterface, dispatchInterface: DispatchInterface, abortController: AbortController, hookFns: HookFunctions, chainImplementation: ChainLegacy | undefined, networkConfig: NetworkConfig, gatekeeperClient: GatekeeperClient | undefined); static getInstance(stateInterface: StateInterface, dispatchInterface: DispatchInterface, abortController: AbortController, hookFns: HookFunctions, chainImplementation: ChainLegacy | undefined, networkConfig: NetworkConfig, gatekeeperClient: GatekeeperClient | undefined): PassOrchestrator; private get state(); private clearWaitForActiveTimer; /** * poll until a gatekeeper record is found, once active check the chain for a token * then dispatch a tokenChange event that will result in the token getting saved to state * start token refresh polling once a valid token is set */ private pollForOnChainToken; /** * This function runs when the timeout period for an expected on-chain token to be found is finished. * For owner signs/sends: * - dispatch a timeout event to prompt the user to retry * For civic sends: * - check the status of issuance with the gatekeeper: * - if the retries have been exhausted, prompt the user to retry * - if issuance is still pending, then retry after a delay (max 3 retries) * - if all retries have been tried then dispatch an error to prompt the user to retry * @param numberOfRetries * @returns {Promise} */ private onTokenTimeoutEnd; private dispatchIfNotAborted; /** * New token request flow for civic-sends: * use the issuance payload from the civic-pass iframe. The payload can optionally contain a proof requirement * if so, then wait for the proof requirement to be fulfilled before triggering an issuance request to the gatekeeper * when this flow completes successfully, the gatekeeper API should initiate a civic-sends gateway token issuance, if * all the strategy checks finish successfully */ newTokenRequestFlowWhenCivicSendsTx(): Promise; /** * Sets up a flow to expect an on-chain token to be available within the network-based-config timeout */ private expectTokenCreatedOnChain; /** * New token request flow for when the client is responsible for sending the tx * use the issuance payload from the civic-pass iframe. The payload can optionally contain a proof requirement * if so, then wait for the proof requirement to be fulfilled before triggering the flow to prompt the user to sign * and send the transaction to send to chain. This flow will get run multiple times, as the tokenIssuanceState * changes. The last state in the orchestrator flow is PENDING_ONCHAIN_CONFIRMATION, once this is detected, * the transaction is in the hands of the user to sign, and the RC will trigger a 'awaiting owner signs transaction' screen */ newTokenRequestFlowWhenCivicDoesNotSendTx(): Promise; /** * Decide which flow to run depending on state, then run the flow * Currently supported flows: * - issuance flow * - post-gatewayToken creation flow * - TODO: implement refresh flows */ orchestrate(): Promise; }