@signumjs/wallets
Version:
Wallets communication package for DApps in the Signum Network
143 lines (142 loc) • 4.85 kB
TypeScript
/**
* Original work Copyright (c) 2026 Signum Network
*/
/**
* Represents the various status types that can be assigned to an operation or process.
*
* 'success' - Indicates that the operation was completed successfully.
* 'rejected' - Indicates that the operation was explicitly declined or denied.
* 'failed' - Indicates that the operation encountered an error or was unsuccessful.
*/
export type StatusType = 'success' | 'rejected' | 'failed';
/**
* Callback data for 'connect' command
*/
export interface ConnectCallbackData {
/**
* Public key returned from connect callback
*/
publicKey: string;
/**
* Status from sign callback: 'success' | 'rejected' | 'failed'
*/
status?: StatusType;
}
/**
* Callback data for 'sign' command
*/
export interface SignCallbackData {
/**
* Status from sign callback: 'success' | 'rejected' | 'failed'
*/
status: StatusType;
/**
* Transaction ID returned on _successful_ sign
*/
transactionId?: string;
}
/**
* The options for the Mobile Wallet
*/
export interface MobileWalletOpts {
/**
* If true in browser environment, the method calls will try to open the deep link.
* If set to false, the methods just return the generated deeplink.
* In NodeJS this flag will be ignored
*/
openInBrowser?: boolean;
}
/**
* Arguments for the connect method
* {@link MobileWallet.connect}
*/
export interface MobileWalletConnectArgs {
/**
* The URL the mobile wallet should redirect to after successful/accepted connection
*/
callbackUrl: string;
/**
* The name of the mobile wallet app
*/
appName: string;
/**
* The network to connect to (mainnet or testnet)
*/
network: 'mainnet' | 'testnet';
}
/**
* Arguments for the sign method
* {@link MobileWallet.sign}
*/
export interface MobileWalletSignArgs {
/**
* The unsigned transaction bytes to sign
*/
unsignedTransactionBytes: string;
/**
* The URL the mobile wallet should redirect to after successful/accepted connection
*/
callbackUrl: string;
/**
* The network to connect to (mainnet or testnet)
*/
network: 'mainnet' | 'testnet';
}
/**
* This wallet allows interacting with SIP22 compatible mobile wallets via deeplinks.
*
* Unlike the DesktopWallet, the MobileWallet uses direct deeplinks (signum://)
* supports the versatile sign command, and callback URLs for receiving responses from the mobile wallet app.
*/
export declare class MobileWallet {
private readonly openInBrowser;
constructor(options?: MobileWalletOpts);
/**
* Opens the mobile wallet to request connection and public key.
* The wallet will redirect to the callback URL with the public key as a URL parameter.
*
* Example callbacks:
* https://myapp.com/connected
* https://myotherapp.com?action=connected
*
* In the callback page you can use {@link MobileWallet.parseConnectCallback} to extract the public key
*
* @param args - The connection arguments. See {@link MobileWalletConnectArgs}.
* @returns The deeplink URL (for testing or custom handling)
*/
connect({ callbackUrl, appName, network }: MobileWalletConnectArgs): string;
/**
* Opens the mobile wallet to sign an unsigned transaction.
* The wallet will redirect to the callback URL with status and transactionId parameters.
*
* Example callback on success: https://myapp.com/signed?status=success&transactionId=xyz789...
* Example callback on rejection: https://myapp.com/signed?status=rejected
*
* @returns The deeplink URL (for testing or custom handling)
*/
sign({ network, callbackUrl, unsignedTransactionBytes }: MobileWalletSignArgs): string;
/**
* Static helper to parse callback data from URL parameters.
* Use this in your callback pages to extract the data sent by the mobile wallet.
*
* The returned public key should be stored and used for further signing requests.
* The public key is required to create unsigned transactions byte sequences.
*
* Example usage in callback page:
* ```typescript
* const data = MobileWallet.parseCallback();
* if (data.publicKey) {
* localStorage.setItem('signum-wallet-publicKey', data.publicKey);
* }
* if (data.status === 'success' && data.transactionId) {
* localStorage.setItem('signum-wallet-txId', data.transactionId);
* }
* ```
*/
static parseConnectCallback(): ConnectCallbackData;
/**
* Static helper to parse callback data from URL parameters from _sign_ command.
* Use this in your callback pages to extract the data sent by the mobile wallet.
*/
static parseSignCallback(): SignCallbackData;
}