@signumjs/wallets
Version:
Wallets communication package for DApps in the Signum Network
130 lines (129 loc) • 4.64 kB
TypeScript
/**
* Original work Copyright (c) 2022, 2026 Signum Network
*/
import { ExtensionWalletConnection } from './extensionWalletConnection';
/**
* Arguments for {@link ExtensionWallet.sendEncryptedMessage}
*/
export interface SendEncryptedMessageArgs {
/**
* The fee in signa.
*/
feeSigna: number | string;
/**
* The public key of the recipient.
*/
recipientPublicKey: string;
/**
* The message to be sent.
*/
message?: string;
/**
* The hex message to be sent - as alternative to `message`.
*/
hexMessage?: string;
}
/**
* Object returned from {@link ExtensionWallet.confirm}
*/
export interface ConfirmedTransaction {
/**
* The transaction id
*/
transactionId: string;
/**
* The hash of the transaction
*/
fullHash: string;
}
/**
* Connection parameters for {@link ExtensionWallet.connect}
*/
export interface ExtensionWalletConnectArgs {
/**
* The name of the app to be connected.
*/
appName: string;
/**
* The name of the network to be used.
* The network name is available with `getNetworkInfo`.
* For original Signum Network it is `Signum` and `Signum-TESTNET` respectively.
*/
networkName: string | 'Signum' | 'Signum-TESTNET';
}
/**
* This wallet (proxy) allows interacting with the CIPXX compatible extension wallets.
*
* @example
*
* ```js
* const wallet = new ExtensionWallet()
* wallet
* .connect({appName: 'MySuperDApp', networkName: NetworkName.SignumMainnet})
* .then( connection => {
* console.log('Successfully connected', connection)
* const ledger = LedgerClientFactory.createClient({ nodeHost: connection.currentNodeHost });
* console.log('Sending some money...')
* return ledger.transaction.sendAmountToSingleRecipient({
* senderPublicKey: connection.publicKey,
* recipientId: Address.fromReedSolomonAddress('TS-K37B-9V85-FB95-793HN').getNumericId(),
* feePlanck: String(FeeQuantPlanck),
* amountPlanck: Amount.fromSigna(1).getPlanck()
* })
* })
* .then( unsignedTransaction => {
* return wallet.confirm(unsignedTransaction.unsignedTransactionBytes)
* })
* .then( confirmedTransaction => {
* console.log('Successfully sent money:', confirmedTransaction)
* }).catch(console.error)
* ```
*
* > At this time, this wallet does only work in the browser
*/
export declare class ExtensionWallet {
private _connection;
private adapter;
private assertConnection;
private fetchPermission;
/**
* @return the current connection, iff exists
*/
get connection(): ExtensionWalletConnection | null;
/**
* Tries to connect to the extension wallet. Each recurring call tries overwrites current connection
* @param args The argument object
* @return The connection if successful, or null, if not available
* @throws Errors on unavailability, wrong networks or permission issues
*/
connect(args: ExtensionWalletConnectArgs): Promise<ExtensionWalletConnection>;
/**
* Requests a confirmation, i.e. cryptographic signing, of a transaction.
*
* The unsignedTransaction byte sequence is being returned by any of the SignumJS operations as long as no private key is
* passed as parameter to the operation
*
* @example
* ```ts
* const { unsignedTransactionBytes } = await ledger.transaction.sendAmountToSingleRecipient({
* senderPublicKey: connection.publicKey, // only public key is passed!
* recipientId: Address.fromReedSolomonAddress('TS-K37B-9V85-FB95-793HN').getNumericId(),
* feePlanck: String(FeeQuantPlanck),
* amountPlanck: Amount.fromSigna(1).getPlanck()
* })
* const { transactionId, fullHash } = await wallet.confirm(unsignedTransactionBytes)
* ```
* @param unsignedTransaction The hexadecimal byte string of an unsigned transaction.
* @return The confirmed transaction, in case of success
* @throws Error if signing failed for some reason, i.e. rejected operation or invalid transaction data
*/
confirm(unsignedTransaction: string): Promise<ConfirmedTransaction>;
/**
* Requests to send an encrypted P2P message via the extension
*
* @param args The send parameters
* @return The confirmed transaction, in case of success
* @throws Error if signing failed for some reason, i.e. rejected operation or invalid transaction data
*/
sendEncryptedMessage(args: SendEncryptedMessageArgs): Promise<ConfirmedTransaction>;
}