= {
channel: "wallet";
operation: Op;
payload: WalletOperations[Op]["request"];
};
export type MessageResponse = CoreApiResponse;
export interface WalletWebExVersion {
version_name?: string | undefined;
version: string;
}
type F = WalletConfig["features"];
type kf = keyof F;
type WebexWalletConfig = {
[P in keyof F as `wallet${Capitalize}`]: F[P];
};
export interface Settings extends WebexWalletConfig {
injectTalerSupport: boolean;
advanceMode: boolean;
backup: boolean;
langSelector: boolean;
showJsonOnError: boolean;
extendedAccountTypes: boolean;
suspendIndividualTransaction: boolean;
}
export const defaultSettings: Settings = {
injectTalerSupport: false,
advanceMode: false,
backup: false,
langSelector: false,
suspendIndividualTransaction: false,
showJsonOnError: false,
extendedAccountTypes: false,
walletAllowHttp: false,
walletBatchWithdrawal: false,
};
/**
* Compatibility helpers needed for browsers that don't implement
* WebExtension APIs consistently.
*/
export interface BackgroundPlatformAPI {
/**
*
*/
getSettingsFromStorage(): Promise;
/**
* Guarantee that the service workers don't die
*/
keepAlive(cb: VoidFunction): void;
/**
* FIXME: should not be needed
*
* check if the platform is firefox
*/
isFirefox(): boolean;
registerOnInstalled(callback: () => void): void;
/**
*
* Check if background process run as service worker. This is used from the
* wallet use different http api and crypto worker.
*/
useServiceWorkerAsBackgroundProcess(): boolean;
/**
*
* Open a page into the wallet UI
* @param page
*/
openWalletPage(page: string): void;
/**
*
* Register a callback to be called when the wallet is ready to start
* @param callback
*/
notifyWhenAppIsReady(): Promise;
/**
* Get the wallet version from manifest
*/
getWalletWebExVersion(): WalletWebExVersion;
/**
* Backend API
*/
registerAllIncomingConnections(): void;
/**
* Backend API
*/
registerReloadOnNewVersion(): void;
/**
* Permission API for checking and add a listener
*/
getPermissionsApi(): CrossBrowserPermissionsApi;
/**
* Used by the wallet backend to send notification about new information
* @param message
*/
sendMessageToAllChannels(message: MessageFromBackend): void;
/**
* Backend API
*
* When a tab has been detected to have a Taler action the background process
* can use this function to redirect the tab to the wallet UI
*
* @param tabId
* @param page
*/
redirectTabToWalletPage(tabId: number, page: string): void;
/**
* Use by the wallet backend to receive operations from frontend (popup & wallet)
* and send a response back.
*
* @param onNewMessage
*/
listenToAllChannels(
notifyNewMessage: (
message: MessageFromFrontend & { id: string },
) => Promise,
): void;
}
export interface ForegroundPlatformAPI {
/**
* FIXME: should not be needed
*
* check if the platform is firefox
*/
isFirefox(): boolean;
/**
* Permission API for checking and add a listener
*/
getPermissionsApi(): CrossBrowserPermissionsApi;
/**
* Popup API
*
* Used when an TalerURI is found and open up from the popup UI.
* Closes the popup and open the URI into the wallet UI.
*
* @param talerUri
*/
openWalletURIFromPopup(talerUri: TalerUri): void;
/**
* Popup API
*
* Open a page into the wallet UI and closed the popup
* @param page
*/
openWalletPageFromPopup(page: string): void;
/**
* Get the wallet version from manifest
*/
getWalletWebExVersion(): WalletWebExVersion;
/**
* Popup API
*
* Read the current tab html and try to find any Taler URI or QR code present.
*
* @return Taler URI if found
*/
findTalerUriInActiveTab(): Promise;
/**
* Popup API
*
* Read the current tab html and try to find any Taler URI or QR code present.
*
* @return Taler URI if found
*/
findTalerUriInClipboard(): Promise;
/**
* Used from the frontend to send commands to the wallet
*
* @param operation
* @param payload
*
* @return response from the backend
*/
sendMessageToBackground(
message: MessageFromFrontend,
): Promise;
/**
* Used from the frontend to receive notifications about new information
* @param listener
* @return function to unsubscribe the listener
*/
listenToWalletBackground(
listener: (message: MessageFromBackend) => void,
): () => void;
/**
* Notify when platform went offline
*/
listenNetworkConnectionState(
listener: (state: "on" | "off") => void,
): () => void;
}