@dolaned/wallet-sdk-ts
Version:
Wallet SDK for the Nexa blockchain
919 lines (917 loc) • 32.3 kB
TypeScript
import { HDPrivateKey, PublicKey, Script, Networkish, TransactionBuilder } from "libnexa-ts";
import { SubscribeCallback } from "@vgrunner/electrum-cash";
type RostrumTransportScheme = 'ws' | 'wss';
interface RostrumParams {
scheme: RostrumTransportScheme;
host: string;
port: number;
}
interface BlockTip {
height: number;
hex: string;
}
interface IFirstUse {
block_hash: string;
block_height: number;
height: number;
tx_hash: string;
}
interface ITokenGenesis {
decimal_places?: number;
document_hash?: string;
document_url?: string;
group: string;
height: number;
name?: string;
op_return?: string;
ticker?: string;
token_id_hex: string;
txid: string;
txidem: string;
op_return_id: number;
}
interface ITokensBalance {
cursor?: any;
confirmed: Record<string, bigint | number>;
unconfirmed: Record<string, bigint | number>;
}
interface ITokenUtxo {
group: string;
height: number;
outpoint_hash: string;
token_amount: number | bigint;
token_id_hex: string;
tx_hash: string;
tx_pos: number;
value: number;
}
interface IListUnspentRecord {
has_token: boolean;
height: number;
outpoint_hash: string;
tx_hash: string;
tx_pos: number;
value: number;
}
interface IUtxo {
addresses: string[];
amount: number;
group: string;
group_authority: bigint | number;
group_quantity: bigint | number;
height: number;
scripthash: string;
scriptpubkey: string;
spent: ISpent;
status: string;
template_argumenthash: string;
template_scripthash: string;
token_id_hex: string;
tx_hash: string;
tx_idem: string;
tx_pos: number;
}
interface ISpent {
height: number;
tx_hash: string;
tx_pos: number;
}
interface ITransaction {
blockhash: string;
blocktime: number;
confirmations: number;
fee: number;
fee_satoshi: number;
hash: string;
height: number;
hex: string;
locktime: number;
size: number;
time: number;
txid: string;
txidem: string;
version: number;
vin: ITXInput[];
vout: ITXOutput[];
}
interface ITXInput {
outpoint: string;
scriptSig: IScriptSig;
sequence: number;
value: number;
value_satoshi: bigint | number;
addresses: string[];
group: string;
groupAuthority: bigint | number;
groupQuantity: bigint | number;
}
interface ITXOutput {
n: number;
outpoint_hash: string;
scriptPubKey: IScriptPubKey;
type: number;
value: number;
value_satoshi: bigint | number;
}
interface IScriptSig {
asm: string;
hex: string;
}
interface IScriptPubKey {
addresses: string[];
argHash: string;
asm: string;
group: string;
groupAuthority: bigint | number;
groupQuantity: bigint | number;
hex: string;
scriptHash: string;
token_id_hex?: string;
type: string;
}
interface ITXHistory {
fee?: number;
height: number;
tx_hash: string;
}
export interface AccountKeys {
receiveKeys: AddressKey[];
changeKeys: AddressKey[];
}
export interface WatchOnlyAddress {
address: string;
xPub?: PublicKey;
derivationPath?: string;
}
export interface AccountIndexes {
rIndex: number;
cIndex: number;
}
export interface TxStatus {
height: number;
}
export interface HodlStatus {
idx: number;
}
export interface AddressKey {
key: HDPrivateKey;
address: string;
balance: string;
tokensBalance: Record<string, Balance>;
}
export interface Balance {
confirmed: string | number;
unconfirmed: string | number;
}
declare class RostrumProvider {
constructor();
getVersion(): Promise<string[]>;
getBlockTip(): Promise<BlockTip>;
getBalance(address: string): Promise<Balance>;
getTransactionsHistory(address: string): Promise<ITXHistory[]>;
getFirstUse(address: string): Promise<IFirstUse>;
getTransaction(id: string, verbose?: boolean): Promise<ITransaction>;
getUtxo(outpoint: string): Promise<IUtxo>;
getNexaUtxos(address: string): Promise<IListUnspentRecord[]>;
getTokenUtxos(address: string, token: string): Promise<ITokenUtxo[]>;
getTokensBalance(address: string, token?: string): Promise<ITokensBalance>;
getTokenGenesis(token: string): Promise<ITokenGenesis>;
subscribeToAddresses(addresses: string[], callback: SubscribeCallback): Promise<void>;
broadcast(txHex: string): Promise<string>;
getLatency(): Promise<number>;
connect(params?: RostrumParams): Promise<void>;
disconnect(force?: boolean): Promise<boolean>;
}
export const rostrumProvider: RostrumProvider;
export type PermissionLabel = 'authorise' | 'mint' | 'melt' | 'rescript' | 'subgroup';
export type TxEntityState = 'incoming' | 'outgoing' | 'both';
export interface TxTemplateData {
templateScript: Script;
constraintScript: Script;
visibleArgs: any[];
publicKey: PublicKey;
}
export interface TxOptions {
isConsolidate?: boolean;
toChange?: string;
templateData?: TxTemplateData;
feeFromAmount?: boolean;
}
export interface TokenAction {
token?: string;
parentToken?: string;
amount: bigint;
action: string;
extraData?: {
perms?: PermissionLabel[];
outpoint?: string;
opReturnData?: string;
address?: string;
};
}
export interface TransactionEntity {
txIdem: string;
txId: string;
time: number;
height: number;
payTo: string;
state: TxEntityState;
value: string;
fee: number;
token: string;
extraGroup: string;
txGroupType: number;
tokenAmount: string;
}
export class DefaultAccount extends BaseAccount {
constructor(bip44Account: number, accountIndexes: AccountIndexes, accountKeys: AccountKeys);
getAccountStoreKey(): string;
getAccountType(): AccountType;
getNewAddress(): string;
getNewChangeAddress(): string;
get accountIndexes(): AccountIndexes;
get accountKeys(): AccountKeys;
loadBalances(): Promise<void>;
getKeyFromAddress(address: string): AddressKey;
getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
}
export abstract class BaseAccount {
get transactions(): Map<string, TransactionEntity>;
set transactions(value: Map<string, TransactionEntity>);
protected readonly _bip44Account: number;
protected constructor(_bip44Account: number);
abstract get accountIndexes(): AccountIndexes;
abstract get accountKeys(): AccountKeys;
abstract getNewChangeAddress(): string;
abstract getNewAddress(): string;
abstract getAccountStoreKey(): string;
abstract getAccountType(): AccountType;
abstract loadBalances(): Promise<void>;
abstract getKeyFromAddress(address: string): AddressKey;
abstract getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
get balance(): Balance;
set balance(value: Balance);
get tokenBalances(): Record<string, Balance>;
set tokenBalances(value: Record<string, Balance>);
}
export class DappAccount extends BaseAccount {
constructor(bip44Account: number, accountIndex: number, addressKey: AddressKey);
getAccountStoreKey(): string;
getAccountType(): AccountType;
getNewAddress(): string;
getNewChangeAddress(): string;
get accountIndexes(): AccountIndexes;
get accountKeys(): AccountKeys;
loadBalances(): Promise<void>;
getKeyFromAddress(address: string): AddressKey;
getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
}
export class VaultAccount extends BaseAccount {
constructor(bip44Account: number, accountIndex: number, addressKey: AddressKey);
getAccountStoreKey(): string;
getAccountType(): AccountType;
getNewAddress(): string;
getNewChangeAddress(): string;
get accountIndexes(): AccountIndexes;
get accountKeys(): AccountKeys;
loadBalances(): Promise<void>;
getKeyFromAddress(address: string): AddressKey;
getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
}
export enum TxTokenType {
NO_GROUP = 0,
CREATE = 1,
MINT = 2,
MELT = 3,
RENEW = 4,
TRANSFER = 5
}
export enum AccountType {
NEXA_ACCOUNT = 0,
VAULT_ACCOUNT = 1,
DAPP_ACCOUNT = 2
}
/**
* Abstract base class for creating and managing transactions in the NEXA blockchain.
* Provides common functionality for transaction building including token operations,
* address validation, and output creation.
*/
declare abstract class TransactionCreator {
/**
* Creates a new TransactionCreator instance
* @param tx Optional existing TransactionBuilder, hex string, or buffer
*/
protected constructor(tx?: TransactionBuilder | string | Buffer);
/** Parse transaction from hex string - must be implemented by subclasses */
abstract parseTxHex(tx: string): this;
/** Parse transaction from buffer - must be implemented by subclasses */
abstract parseTxBuffer(tx: Buffer): this;
/**
* Sets the network for this transaction
* @param network Network name or Networkish object
* @returns This instance for chaining
*/
onNetwork(network: string | Networkish): this;
/** Gets transaction options */
get txOptions(): TxOptions;
/** Sets transaction options */
set txOptions(value: TxOptions);
/** Gets the network for this transaction */
get network(): Networkish;
/** Sets the network for this transaction */
set network(value: Networkish);
/** Gets the builder function array */
get builder(): (() => Promise<any>)[];
/** Sets the builder function array */
set builder(value: (() => Promise<any>)[]);
/** Gets the underlying transaction builder */
get transactionBuilder(): TransactionBuilder;
/** Sets the underlying transaction builder */
set transactionBuilder(value: TransactionBuilder);
/** Gets the set of token actions */
get tokens(): Set<TokenAction>;
/** Sets the set of token actions */
set tokens(value: Set<TokenAction>);
/** Gets the total NEXA value being sent */
get totalValue(): bigint;
/** Sets the total NEXA value being sent */
set totalValue(value: bigint);
/**
* Validates and creates a token action
* @param toAddr Destination address
* @param amount Amount to send
* @param token Token ID
* @param action Action type (mint, melt, send, etc.)
* @throws Error if validation fails
*/
protected tokenAction(toAddr: string, amount: string, token: string, action: string): void;
/**
* Configures transaction to consolidate UTXOs to a single address
* @param toAddr Address to consolidate funds to
* @returns This instance for chaining
*/
consolidate(toAddr: string): this;
/**
* Configures transaction to deduct fee from the send amount
* @returns This instance for chaining
*/
feeFromAmount(): this;
/**
* Adds a token send operation to the transaction
* @param toAddr Destination address
* @param amount Amount of tokens to send
* @param token Token ID
* @returns This instance for chaining
*/
sendToToken(toAddr: string, amount: string, token: string): this;
/**
* Adds a NEXA send operation to the transaction
* @param toAddr Destination address
* @param amount Amount of NEXA to send
* @returns This instance for chaining
*/
sendTo(toAddr: string, amount: string): this;
/**
* Adds a token authority renewal operation
* @param token Token ID to renew authority for
* @param perms Permissions to renew
* @param toAddr
* @returns This instance for chaining
*/
renewAuthority(token: string, perms: PermissionLabel[], toAddr?: string): this;
/**
* Adds a token authority deletion operation
* @param token Token ID to delete authority for
* @param outpoint Outpoint of the authority to delete
* @returns This instance for chaining
*/
deleteAuthority(token: string, outpoint: string): this;
/**
* Creates a legacy token (not implemented)
* @returns This instance for chaining
*/
legacyToken(name: string, ticker: string, decimals: number, docUrl: string, docHash: string): this;
/**
* Creates a legacy group (not implemented)
* @returns This instance for chaining
*/
legacyGroup(name: string, ticker: string, docUrl: string, docHash: string): this;
/**
* Creates a token with metadata
* @param name Token name
* @param ticker Token ticker symbol
* @param decimals Number of decimal places
* @param docUrl URL to token documentation
* @param docHash Hash of token documentation
* @returns This instance for chaining
*/
token(name: string, ticker: string, decimals: number, docUrl: string, docHash: string): this;
/**
* Creates an NFT collection with metadata
* @param name Collection name
* @param ticker Collection ticker symbol
* @param docUrl URL to collection documentation
* @param docHash Hash of collection documentation
* @returns This instance for chaining
*/
collection(name: string, ticker: string, docUrl: string, docHash: string): this;
/**
* Creates an NFT within a collection
* @param parent Parent collection token ID
* @param zipUrl URL to NFT content ZIP file
* @param zipHash Hash of NFT content ZIP file
* @returns This instance for chaining
*/
nft(parent: string, zipUrl: string, zipHash: string): this;
/**
* Adds an OP_RETURN output to the transaction
* @param data Data to include in the OP_RETURN
* @param isFullScript Whether the data is already a complete script
* @returns This instance for chaining
*/
addOpReturn(data: Buffer | string | Script, isFullScript?: boolean): this;
/** Populates the transaction with inputs and outputs - must be implemented by subclasses */
abstract populate(): this;
/**
* Builds the transaction by executing all queued operations
* @returns Promise resolving to the serialized transaction hex
*/
build(): Promise<string>;
}
export class WalletTransactionCreator extends TransactionCreator {
constructor(fromAccount: BaseAccount, tx?: TransactionBuilder | string | Buffer);
fromAccount(fromAccount: BaseAccount): this;
parseTxHex(tx: string): this;
parseTxBuffer(tx: Buffer): this;
mint(token: string, amount: string): this;
melt(token: string, amount: string): this;
populate(): this;
sign(): this;
}
/**
* AccountStore manages a collection of wallet accounts of different types.
* It provides functionality to create, import, export, and manage accounts
* including DApp accounts, Vault accounts, and Default NEXA accounts.
*/
export class AccountStore {
/**
* Creates a new AccountStore instance
* Initializes an empty map to store accounts
*/
constructor();
/**
* Creates a new account of the specified type
* @param accountType Type of account to create (DAPP, VAULT, or DEFAULT)
* @param masterKey Master HD private key for deriving account keys
* @returns Promise resolving to the created account
*/
createAccount(accountType: AccountType, masterKey: HDPrivateKey): Promise<BaseAccount>;
/**
* Finds the private key associated with a given address across all accounts
* @param address The address to search for
* @returns The AddressKey containing the private key, or null if not found
*/
findKeyForAddress(address: string): AddressKey | null;
/**
* Imports an existing account into the store
* @param accountData The account data to import
* @throws Error if an account with the same key already exists
*/
importAccount(accountData: BaseAccount): void;
/**
* Exports account data by index
* @param accountIndex The account index to export
* @returns The account data
* @throws Error if the account doesn't exist
*/
exportAccount(accountIndex: string): BaseAccount;
/**
* Removes an account from the store
* @param accountIndex The account index to remove
* @throws Error if the account doesn't exist
*/
removeAccount(accountIndex: string): void;
/**
* Returns all accounts in the store
* @returns Map of account store keys to BaseAccount objects
*/
listAccounts(): Map<string, BaseAccount>;
/**
* Retrieves a specific account by its index
* @param index The account index to retrieve
* @returns The account if found, undefined otherwise
*/
getAccount(index: string): BaseAccount | undefined;
}
/**
* Main Wallet class for managing Nexa blockchain wallet operations
*
* This class provides comprehensive wallet functionality including:
* - Creating wallets from seed phrases or private keys
* - Account discovery and management
* - Transaction creation and signing
* - Message signing and verification
* - Multi-account support with different account types
*
* @example
* ```typescript
* // Create a new wallet with random seed phrase
* const wallet = Wallet.create();
*
* // Restore wallet from existing seed phrase
* const wallet = Wallet.fromSeedPhrase('your twelve word seed phrase here');
*
* // Initialize wallet (discovers accounts and balances)
* await wallet.initialize();
*
* // Create a new account
* const account = await wallet.newAccount('DefaultAccount');
*
* // Create and send a transaction
* const tx = wallet.newTransaction(account)
* .to('nexa:address', 1000000) // 1 NEXA in satoshis
* .sign();
*
* const txId = await wallet.sendTransaction(tx.toHex());
* ```
*/
export class Wallet {
/**
* Creates a new Wallet instance
*
* @param data - Optional wallet data:
* - undefined: Generate new random seed phrase
* - string: Use as BIP39 seed phrase
* - HDPrivateKey: Use as master key directly
* @param network - Network name ('mainnet', 'testnet', 'regtest'). Defaults to 'mainnet'
*
* @example
* ```typescript
* // Create new wallet with random seed
* const wallet = new Wallet();
*
* // Create from seed phrase
* const wallet = new Wallet('abandon abandon abandon...');
*
* // Create from master key
* const masterKey = HDPrivateKey.fromString('xprv...');
* const wallet = new Wallet(masterKey);
*
* // Create on testnet
* const wallet = new Wallet(undefined, 'testnet');
* ```
*/
constructor(data?: string | HDPrivateKey | undefined, network?: string);
/**
* Create a new wallet with a randomly generated seed phrase
*
* This is the recommended way to create a new wallet for first-time users.
* The generated seed phrase should be securely stored by the user.
*
* @returns A new Wallet instance with a random 12-word seed phrase
*
* @example
* ```typescript
* const wallet = Wallet.create();
* console.log(wallet.export().phrase); // Store this securely!
* ```
*/
static create(): Wallet;
/**
* Create a wallet from an existing BIP39 seed phrase
*
* Use this method to restore a wallet from a previously generated seed phrase.
* The seed phrase should be a valid BIP39 mnemonic.
*
* @param phrase - The BIP39 seed phrase (12 or 24 words)
* @param network - Optional network name ('mainnet', 'testnet', 'regtest')
* @returns A new Wallet instance restored from the seed phrase
* @throws {Error} If the seed phrase is invalid or not provided
*
* @example
* ```typescript
* const wallet = Wallet.fromSeedPhrase(
* 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
* 'testnet'
* );
* ```
*/
static fromSeedPhrase(phrase: string, network?: string): Wallet;
/**
* Create a wallet from an extended private key (xpriv)
*
* Use this method to create a wallet from a master private key in extended format.
* This is useful for advanced users who want to use a specific key derivation.
*
* @param xpriv - The extended private key string (starts with 'xprv')
* @param network - Optional network name ('mainnet', 'testnet', 'regtest')
* @returns A new Wallet instance using the provided master key
* @throws {Error} If the private key is invalid or not provided
*
* @example
* ```typescript
* const wallet = Wallet.fromXpriv(
* 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
* );
* ```
*/
static fromXpriv(xpriv: string, network?: string): Wallet;
/**
* Initialize the wallet by discovering accounts and loading balances
*
* This method performs account discovery using the BIP44 derivation path
* and scans for existing accounts with transaction history or balances.
* Must be called before using the wallet's accounts.
*
* @returns Promise that resolves when initialization is complete
*
* @example
* ```typescript
* const wallet = Wallet.fromSeedPhrase('your seed phrase');
* await wallet.initialize();
*
* // Now you can access discovered accounts
* const accounts = wallet.accountStore.listAccounts();
* ```
*/
initialize(): Promise<void>;
/**
* Create a new transaction builder for this wallet
*
* @param fromAccount - The account to send the transaction from
* @param x - Optional existing transaction data:
* - TransactionBuilder: Use existing transaction builder
* - string: Parse from hex string
* - Buffer: Parse from binary buffer
* - undefined: Create new empty transaction
* @returns A new WalletTransactionCreator instance
*
* @example
* ```typescript
* const account = wallet.accountStore.getAccount(0);
* const tx = wallet.newTransaction(account)
* .to('nexa:address', 1000000) // 1 NEXA
* .sign();
*
* // Or from existing transaction hex
* const tx = wallet.newTransaction(account, 'raw_tx_hex')
* .sign();
* ```
*/
newTransaction(fromAccount: BaseAccount, x?: TransactionBuilder | string | Buffer): WalletTransactionCreator;
/**
* Create a new account for this wallet
*
* @param accountType - The type of account to create:
* - 'DefaultAccount': Standard account for general use
* - 'VaultAccount': Secured account with additional protection
* - 'DappAccount': Account optimized for dApp interactions
* @returns Promise that resolves to the newly created account
*
* @example
* ```typescript
* const defaultAccount = await wallet.newAccount('DefaultAccount');
* const vaultAccount = await wallet.newAccount('VaultAccount');
* const dappAccount = await wallet.newAccount('DappAccount');
* ```
*/
newAccount(accountType: AccountType): Promise<BaseAccount>;
/**
* Broadcast a signed transaction to the Nexa network
*
* @param transaction - The signed transaction in hex format
* @returns Promise that resolves to the transaction ID (txid)
* @throws {Error} If the transaction is invalid or broadcast fails
*
* @example
* ```typescript
* const tx = wallet.newTransaction(account)
* .to('nexa:address', 1000000)
* .sign();
*
* const txId = await wallet.sendTransaction(tx.toHex());
* console.log('Transaction sent:', txId);
* ```
*/
sendTransaction(transaction: string): Promise<string>;
/**
* Sign a message using a specific address from this wallet
*
* The message is signed using the private key associated with the given address.
* This can be used for authentication or to prove ownership of an address.
*
* @param message - The message to sign
* @param addressToUse - The address whose private key should sign the message
* @returns The signature as a base64-encoded string
* @throws {Error} If the address is not owned by this wallet
*
* @example
* ```typescript
* const account = wallet.accountStore.getAccount(0);
* const address = account.getReceiveAddress();
* const signature = wallet.signMessage('Hello World', address);
* ```
*/
signMessage(message: string, addressToUse: string): string;
/**
* Verify a message signature against an address
*
* This method can verify signatures created by any address, not just addresses
* owned by this wallet. It's useful for verifying messages from other parties.
*
* @param message - The original message that was signed
* @param signature - The signature to verify (base64-encoded)
* @param address - The address that supposedly signed the message
* @returns true if the signature is valid, false otherwise
* @throws {Error} If any parameters are missing or invalid
*
* @example
* ```typescript
* const isValid = wallet.verifyMessage(
* 'Hello World',
* 'signature_string',
* 'nexa:address'
* );
* console.log('Signature valid:', isValid);
* ```
*/
verifyMessage(message: string, signature: string, address: string): boolean;
/**
* Export the wallet data for backup or storage
*
* Returns an object containing the wallet's seed phrase, master key, and accounts.
* This data can be used to restore the wallet later. The seed phrase should be
* stored securely as it provides full access to the wallet.
*
* @returns Object containing wallet data
* @property {string} phrase - The BIP39 seed phrase (if available)
* @property {HDPrivateKey} masterKey - The master private key
* @property {BaseAccount[]} accounts - Array of discovered accounts
*
* @example
* ```typescript
* const walletData = wallet.export();
*
* // Store the seed phrase securely
* const seedPhrase = walletData.phrase;
*
* // Later, restore the wallet
* const restoredWallet = Wallet.fromSeedPhrase(seedPhrase);
* ```
*/
export(): any;
/**
* Get the account store for managing wallet accounts
*
* The account store provides methods to create, import, and manage accounts
* within this wallet. Each account has its own set of addresses and keys.
*
* @returns The wallet's account store
*
* @example
* ```typescript
* const accountStore = wallet.accountStore;
* const accounts = accountStore.listAccounts();
* const firstAccount = accountStore.getAccount(0);
* ```
*/
get accountStore(): AccountStore;
/**
* Get the network this wallet is operating on
*
* @returns The network object (mainnet, testnet, or regtest)
*
* @example
* ```typescript
* const network = wallet.network;
* console.log('Network:', network.name);
* ```
*/
get network(): Networkish;
}
/**
* WatchOnlyTransactionCreator extends TransactionCreator to handle transaction creation
* for watch-only wallets. It manages addresses without private keys and delegates
* UTXO selection and input population to specialized utility functions.
*/
export class WatchOnlyTransactionCreator extends TransactionCreator {
/**
* Creates a new WatchOnlyTransactionCreator
* @param tx Optional existing transaction builder or transaction data
*/
constructor(tx?: TransactionBuilder | string | Buffer);
/**
* Sets the source addresses for transaction inputs
* @param address Single address string, array of addresses, or WatchOnlyAddress objects
* @returns This instance for chaining
*/
from(address: string | string[] | WatchOnlyAddress[] | WatchOnlyAddress): this;
/**
* Adds a token minting operation to the transaction
* @param token Token ID to mint
* @param amount Amount to mint
* @param toAddr Destination address for minted tokens
* @returns This instance for chaining
*/
mint(token: string, amount: string, toAddr: string): this;
/**
* Adds a token melting operation to the transaction
* @param token Token ID to melt
* @param amount Amount to melt
* @param toAddr Destination address for melted tokens
* @returns This instance for chaining
*/
melt(token: string, amount: string, toAddr: string): this;
/**
* Populates the transaction with inputs and outputs based on the configured actions.
* Handles different token operations (mint, melt, group creation, etc.) and
* populates NEXA inputs for transaction fees.
* @returns This instance for chaining
*/
populate(): this;
/**
* Parse transaction from buffer (not implemented for watch-only)
* @param tx Transaction buffer
* @returns This instance for chaining
* @throws Error indicating method not implemented
*/
parseTxBuffer(tx: Buffer): this;
/**
* Parse transaction from hex string (not implemented for watch-only)
* @param tx Transaction hex string
* @returns This instance for chaining
* @throws Error indicating method not implemented
*/
parseTxHex(tx: string): this;
}
/**
* WatchOnlyWallet provides functionality for monitoring and creating transactions
* for addresses without storing private keys. This allows users to track balances
* and create unsigned transactions that can be signed elsewhere.
*/
export class WatchOnlyWallet {
/**
* Creates a new WatchOnlyWallet instance
* @param addressesToWatch Array of addresses to monitor
* @param network Optional network name (defaults to mainnet)
* @throws Error if validation fails
*/
constructor(addressesToWatch: WatchOnlyAddress[], network?: string);
/**
* Creates a new transaction creator for this watch-only wallet
* @param x Optional transaction data - can be a TransactionBuilder, hex string, or Buffer
* @returns WatchOnlyTransactionCreator configured with wallet's addresses and network
*/
newTransaction(x?: TransactionBuilder | string | Buffer): WatchOnlyTransactionCreator;
/**
* Broadcasts a signed transaction to the network
* @param transaction Hex-encoded signed transaction
* @returns Promise resolving to transaction ID
* @throws Error if transaction is invalid or broadcast fails
*/
sendTransaction(transaction: string): Promise<string>;
subscribeToAddressNotifications(callback: SubscribeCallback): Promise<void>;
/**
* Gets the list of addresses being watched
* @returns Array of watched addresses (copy to prevent mutation)
*/
getWatchedAddresses(): WatchOnlyAddress[];
}
/**
* Guards against multiple instances of the wallet SDK being loaded.
* This prevents conflicts and ensures only one version is active at a time.
* @param version - The version string to check
* @throws {Error} When multiple instances are detected
*/
declare function versionGuard(version: string): void;
/**
* Wallet SDK - A TypeScript SDK for the Nexa blockchain
*
* This SDK provides comprehensive wallet functionality including:
* - Creating and managing wallets from seed phrases or private keys
* - Account management with different account types
* - Transaction building and signing
* - Token operations and management
* - Message signing and verification
*
* @example
* ```typescript
* import { Wallet } from 'wallet-sdk-ts';
*
* // Create a new wallet
* const wallet = Wallet.create();
*
* // Or restore from seed phrase
* const wallet = Wallet.fromSeedPhrase('your seed phrase here');
*
* // Initialize and discover accounts
* await wallet.initialize();
* ```
*/
declare const walletSdk: {
versionGuard: typeof versionGuard;
version: string;
Wallet: typeof Wallet;
};
export default walletSdk;
//# sourceMappingURL=index.d.ts.map