type CasperWalletProviderOptions = { timeout: number; // timeout of request to extension (in ms) }; type CasperWalletProvider = ( options?: CasperWalletProviderOptions ) => { /** * Get the connection status of the Casper Wallet extension * @returns `true` value when currently connected at least one account, `false` otherwise. */ isConnected: () => Promise; /** * Request the connect interface with the Casper Wallet extension. * Will not show UI for already connected accounts and return true immediately * * emits event of type `Connected` when successfully connected. * @returns `true` value when connection request is accepted by the user or when account is already connected, `false` otherwise. */ requestConnection: () => Promise; /** * Request the switch account interface with the Casper Wallet extension * * emits event of type `ActiveKeyChanged` when successfully switched account. * @returns `true` value when successfully switched account, `false` otherwise. */ requestSwitchAccount(): Promise; /** * Request the sign deploy interface with the Casper Wallet extension * @param deployJson stringified json of a deploy can be generated by `DeployUtil.deployToJson` * @param signingPublicKeyHex public key (in hex format) * @returns a payload response when user responded to transaction request, it will contain signature if approved, or cancelled === true flag when rejected. */ sign( deployJson: string, signingPublicKeyHex: string ): Promise; /** * Request the sign message interface with the Casper Wallet extension * @param message message to sign as string * @param signingPublicKeyHex public key (in hex format) * @returns a payload response when user responded to transaction request, it will contain signature if approved, or cancelled === true flag when rejected. */ signMessage( message: string, signingPublicKeyHex: string ): Promise; /** * Disconnect the Casper Wallet extension * * emits event of type `Disconnected` when successfully disconnected. * @returns `true` when successfully disconnected, `false` otherwise. */ disconnectFromSite(): Promise; /** * Get the active public key of the Casper Wallet extension * @returns hex of the active public key. * @throws when wallet is locked (err.code: 1) * @throws when active account not approved to connect with the site (err.code: 2) */ getActivePublicKey(): Promise; /** * Get version of the Casper Wallet extension * @returns version of the installed wallet extension. */ getVersion(): Promise; }; type SignatureResponse = | { cancelled: true; // if sign was cancelled } | { cancelled: false; // if sign was successfull signatureHex: string; // signature as hex hash signature: Uint8Array; // signature as byte array }; type CasperWalletState = { /** contain wallet is locked flag */ isLocked: boolean; /** if unlocked contain connected status flag of active key otherwise null */ isConnected: boolean | null; /** if unlocked and connected contain active key otherwise null */ activeKey: string | null; }; const EVENT_TYPE_PREFIX = 'casper-wallet'; /** * Event types emitted by the Casper Wallet extension. */ const CasperWalletEventTypes = { /** Account was connected using the wallet: */ Connected: `${EVENT_TYPE_PREFIX}:connected`, /** Active key was changed using the Wallet interface: */ ActiveKeyChanged: `${EVENT_TYPE_PREFIX}:activeKeyChanged`, /** Account was disconnected using the wallet: */ Disconnected: `${EVENT_TYPE_PREFIX}:disconnected`, /** Browser tab was changed to some connected site: */ TabChanged: `${EVENT_TYPE_PREFIX}:tabChanged`, /** Wallet was locked: */ Locked: `${EVENT_TYPE_PREFIX}:locked`, /** Wallet was unlocked: */ Unlocked: `${EVENT_TYPE_PREFIX}:unlocked` } as const; interface Window { CasperWalletProvider?: CasperWalletProvider; CasperWalletEventTypes?: typeof CasperWalletEventTypes; }