nexa-wallet-sdk 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.parcel-cache/3e09f086f3c4d605-AssetGraph +0 -0
  2. package/.parcel-cache/5eac57ec674cdae8-AssetGraph +0 -0
  3. package/.parcel-cache/data.mdb +0 -0
  4. package/.parcel-cache/e43547b6c9167b58-RequestGraph +0 -0
  5. package/.parcel-cache/ecfe15d74834bbfd-BundleGraph +0 -0
  6. package/.parcel-cache/lock.mdb +0 -0
  7. package/.parcel-cache/snapshot-e43547b6c9167b58.txt +2 -0
  8. package/README.md +445 -0
  9. package/dist/browser/index.js +2456 -0
  10. package/dist/browser/index.js.map +1 -0
  11. package/dist/index.d.ts +918 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +2915 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/index.mjs +2456 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/package.json +90 -0
  18. package/spec.md +257 -0
  19. package/src/index.ts +93 -0
  20. package/src/models/rostrum.entities.ts +159 -0
  21. package/src/models/transaction.entities.ts +46 -0
  22. package/src/models/wallet.entities.ts +42 -0
  23. package/src/network/RostrumProvider.ts +137 -0
  24. package/src/types.ts +0 -0
  25. package/src/utils/CommonUtils.ts +123 -0
  26. package/src/utils/TXUtils.ts +445 -0
  27. package/src/utils/TokenUtils.ts +75 -0
  28. package/src/utils/ValidationUtils.ts +86 -0
  29. package/src/utils/WalletUtils.ts +522 -0
  30. package/src/utils/WatchOnlyTXUtils.ts +275 -0
  31. package/src/wallet/Wallet.ts +397 -0
  32. package/src/wallet/WatchOnlyWallet.ts +169 -0
  33. package/src/wallet/accounts/AccountStore.ts +173 -0
  34. package/src/wallet/accounts/interfaces/BaseAccountInterface.ts +56 -0
  35. package/src/wallet/accounts/models/DappAccount.ts +80 -0
  36. package/src/wallet/accounts/models/DefaultAccount.ts +96 -0
  37. package/src/wallet/accounts/models/VaultAccount.ts +81 -0
  38. package/src/wallet/transactions/WalletTransactionCreator.ts +145 -0
  39. package/src/wallet/transactions/WatchOnlyTransactionCreator.ts +189 -0
  40. package/src/wallet/transactions/interfaces/TransactionCreator.ts +438 -0
  41. package/tests/core/tx/transactioncreator.test.ts +455 -0
  42. package/tests/core/tx/wallettransactioncreator.test.ts +362 -0
  43. package/tests/core/tx/watchonlytransactioncreator.test.ts +258 -0
  44. package/tests/core/wallet/accountstore.test.ts +341 -0
  45. package/tests/core/wallet/wallet.test.ts +69 -0
  46. package/tests/core/watchonlywallet/watchonlywallet.test.ts +251 -0
  47. package/tests/index.test.ts +12 -0
  48. package/tsconfig.json +113 -0
@@ -0,0 +1,918 @@
1
+ import { HDPrivateKey, PublicKey, Script, Networkish, TransactionBuilder } from "libnexa-ts";
2
+ import { SubscribeCallback } from "@vgrunner/electrum-cash";
3
+ type RostrumTransportScheme = 'ws' | 'wss';
4
+ interface RostrumParams {
5
+ scheme: RostrumTransportScheme;
6
+ host: string;
7
+ port: number;
8
+ }
9
+ interface BlockTip {
10
+ height: number;
11
+ hex: string;
12
+ }
13
+ interface IFirstUse {
14
+ block_hash: string;
15
+ block_height: number;
16
+ height: number;
17
+ tx_hash: string;
18
+ }
19
+ interface ITokenGenesis {
20
+ decimal_places?: number;
21
+ document_hash?: string;
22
+ document_url?: string;
23
+ group: string;
24
+ height: number;
25
+ name?: string;
26
+ op_return?: string;
27
+ ticker?: string;
28
+ token_id_hex: string;
29
+ txid: string;
30
+ txidem: string;
31
+ op_return_id: number;
32
+ }
33
+ interface ITokensBalance {
34
+ cursor?: any;
35
+ confirmed: Record<string, bigint | number>;
36
+ unconfirmed: Record<string, bigint | number>;
37
+ }
38
+ interface ITokenUtxo {
39
+ group: string;
40
+ height: number;
41
+ outpoint_hash: string;
42
+ token_amount: number | bigint;
43
+ token_id_hex: string;
44
+ tx_hash: string;
45
+ tx_pos: number;
46
+ value: number;
47
+ }
48
+ interface IListUnspentRecord {
49
+ has_token: boolean;
50
+ height: number;
51
+ outpoint_hash: string;
52
+ tx_hash: string;
53
+ tx_pos: number;
54
+ value: number;
55
+ }
56
+ interface IUtxo {
57
+ addresses: string[];
58
+ amount: number;
59
+ group: string;
60
+ group_authority: bigint | number;
61
+ group_quantity: bigint | number;
62
+ height: number;
63
+ scripthash: string;
64
+ scriptpubkey: string;
65
+ spent: ISpent;
66
+ status: string;
67
+ template_argumenthash: string;
68
+ template_scripthash: string;
69
+ token_id_hex: string;
70
+ tx_hash: string;
71
+ tx_idem: string;
72
+ tx_pos: number;
73
+ }
74
+ interface ISpent {
75
+ height: number;
76
+ tx_hash: string;
77
+ tx_pos: number;
78
+ }
79
+ interface ITransaction {
80
+ blockhash: string;
81
+ blocktime: number;
82
+ confirmations: number;
83
+ fee: number;
84
+ fee_satoshi: number;
85
+ hash: string;
86
+ height: number;
87
+ hex: string;
88
+ locktime: number;
89
+ size: number;
90
+ time: number;
91
+ txid: string;
92
+ txidem: string;
93
+ version: number;
94
+ vin: ITXInput[];
95
+ vout: ITXOutput[];
96
+ }
97
+ interface ITXInput {
98
+ outpoint: string;
99
+ scriptSig: IScriptSig;
100
+ sequence: number;
101
+ value: number;
102
+ value_satoshi: bigint | number;
103
+ addresses: string[];
104
+ group: string;
105
+ groupAuthority: bigint | number;
106
+ groupQuantity: bigint | number;
107
+ }
108
+ interface ITXOutput {
109
+ n: number;
110
+ outpoint_hash: string;
111
+ scriptPubKey: IScriptPubKey;
112
+ type: number;
113
+ value: number;
114
+ value_satoshi: bigint | number;
115
+ }
116
+ interface IScriptSig {
117
+ asm: string;
118
+ hex: string;
119
+ }
120
+ interface IScriptPubKey {
121
+ addresses: string[];
122
+ argHash: string;
123
+ asm: string;
124
+ group: string;
125
+ groupAuthority: bigint | number;
126
+ groupQuantity: bigint | number;
127
+ hex: string;
128
+ scriptHash: string;
129
+ token_id_hex?: string;
130
+ type: string;
131
+ }
132
+ interface ITXHistory {
133
+ fee?: number;
134
+ height: number;
135
+ tx_hash: string;
136
+ }
137
+ export interface AccountKeys {
138
+ receiveKeys: AddressKey[];
139
+ changeKeys: AddressKey[];
140
+ }
141
+ export interface WatchOnlyAddress {
142
+ address: string;
143
+ xPub?: PublicKey;
144
+ derivationPath?: string;
145
+ }
146
+ export interface AccountIndexes {
147
+ rIndex: number;
148
+ cIndex: number;
149
+ }
150
+ export interface TxStatus {
151
+ height: number;
152
+ }
153
+ export interface HodlStatus {
154
+ idx: number;
155
+ }
156
+ export interface AddressKey {
157
+ key: HDPrivateKey;
158
+ address: string;
159
+ balance: string;
160
+ tokensBalance: Record<string, Balance>;
161
+ }
162
+ export interface Balance {
163
+ confirmed: string | number;
164
+ unconfirmed: string | number;
165
+ }
166
+ declare class RostrumProvider {
167
+ constructor();
168
+ getVersion(): Promise<string[]>;
169
+ getBlockTip(): Promise<BlockTip>;
170
+ getBalance(address: string): Promise<Balance>;
171
+ getTransactionsHistory(address: string): Promise<ITXHistory[]>;
172
+ getFirstUse(address: string): Promise<IFirstUse>;
173
+ getTransaction(id: string, verbose?: boolean): Promise<ITransaction>;
174
+ getUtxo(outpoint: string): Promise<IUtxo>;
175
+ getNexaUtxos(address: string): Promise<IListUnspentRecord[]>;
176
+ getTokenUtxos(address: string, token: string): Promise<ITokenUtxo[]>;
177
+ getTokensBalance(address: string, token?: string): Promise<ITokensBalance>;
178
+ getTokenGenesis(token: string): Promise<ITokenGenesis>;
179
+ subscribeToAddresses(addresses: string[], callback: SubscribeCallback): Promise<void>;
180
+ broadcast(txHex: string): Promise<string>;
181
+ getLatency(): Promise<number>;
182
+ connect(params?: RostrumParams): Promise<void>;
183
+ disconnect(force?: boolean): Promise<boolean>;
184
+ }
185
+ export const rostrumProvider: RostrumProvider;
186
+ export type PermissionLabel = 'authorise' | 'mint' | 'melt' | 'rescript' | 'subgroup';
187
+ export type TxEntityState = 'incoming' | 'outgoing' | 'both';
188
+ export interface TxTemplateData {
189
+ templateScript: Script;
190
+ constraintScript: Script;
191
+ visibleArgs: any[];
192
+ publicKey: PublicKey;
193
+ }
194
+ export interface TxOptions {
195
+ isConsolidate?: boolean;
196
+ toChange?: string;
197
+ templateData?: TxTemplateData;
198
+ feeFromAmount?: boolean;
199
+ }
200
+ export interface TokenAction {
201
+ token?: string;
202
+ parentToken?: string;
203
+ amount: bigint;
204
+ action: string;
205
+ extraData?: {
206
+ perms?: PermissionLabel[];
207
+ outpoint?: string;
208
+ opReturnData?: string;
209
+ address?: string;
210
+ };
211
+ }
212
+ export interface TransactionEntity {
213
+ txIdem: string;
214
+ txId: string;
215
+ time: number;
216
+ height: number;
217
+ payTo: string;
218
+ state: TxEntityState;
219
+ value: string;
220
+ fee: number;
221
+ token: string;
222
+ extraGroup: string;
223
+ txGroupType: number;
224
+ tokenAmount: string;
225
+ }
226
+ export class DefaultAccount extends BaseAccount {
227
+ constructor(bip44Account: number, accountIndexes: AccountIndexes, accountKeys: AccountKeys);
228
+ getAccountStoreKey(): string;
229
+ getAccountType(): AccountType;
230
+ getNewAddress(): string;
231
+ getNewChangeAddress(): string;
232
+ get accountIndexes(): AccountIndexes;
233
+ get accountKeys(): AccountKeys;
234
+ loadBalances(): Promise<void>;
235
+ getKeyFromAddress(address: string): AddressKey;
236
+ getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
237
+ }
238
+ export abstract class BaseAccount {
239
+ get transactions(): Map<string, TransactionEntity>;
240
+ set transactions(value: Map<string, TransactionEntity>);
241
+ protected readonly _bip44Account: number;
242
+ protected constructor(_bip44Account: number);
243
+ abstract get accountIndexes(): AccountIndexes;
244
+ abstract get accountKeys(): AccountKeys;
245
+ abstract getNewChangeAddress(): string;
246
+ abstract getNewAddress(): string;
247
+ abstract getAccountStoreKey(): string;
248
+ abstract getAccountType(): AccountType;
249
+ abstract loadBalances(): Promise<void>;
250
+ abstract getKeyFromAddress(address: string): AddressKey;
251
+ abstract getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
252
+ get balance(): Balance;
253
+ set balance(value: Balance);
254
+ get tokenBalances(): Record<string, Balance>;
255
+ set tokenBalances(value: Record<string, Balance>);
256
+ }
257
+ export class DappAccount extends BaseAccount {
258
+ constructor(bip44Account: number, accountIndex: number, addressKey: AddressKey);
259
+ getAccountStoreKey(): string;
260
+ getAccountType(): AccountType;
261
+ getNewAddress(): string;
262
+ getNewChangeAddress(): string;
263
+ get accountIndexes(): AccountIndexes;
264
+ get accountKeys(): AccountKeys;
265
+ loadBalances(): Promise<void>;
266
+ getKeyFromAddress(address: string): AddressKey;
267
+ getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
268
+ }
269
+ export class VaultAccount extends BaseAccount {
270
+ constructor(bip44Account: number, accountIndex: number, addressKey: AddressKey);
271
+ getAccountStoreKey(): string;
272
+ getAccountType(): AccountType;
273
+ getNewAddress(): string;
274
+ getNewChangeAddress(): string;
275
+ get accountIndexes(): AccountIndexes;
276
+ get accountKeys(): AccountKeys;
277
+ loadBalances(): Promise<void>;
278
+ getKeyFromAddress(address: string): AddressKey;
279
+ getTransactions(fromHeight?: number, address?: string): Promise<Map<string, TransactionEntity>>;
280
+ }
281
+ export enum TxTokenType {
282
+ NO_GROUP = 0,
283
+ CREATE = 1,
284
+ MINT = 2,
285
+ MELT = 3,
286
+ RENEW = 4,
287
+ TRANSFER = 5
288
+ }
289
+ export enum AccountType {
290
+ NEXA_ACCOUNT = 0,
291
+ VAULT_ACCOUNT = 1,
292
+ DAPP_ACCOUNT = 2
293
+ }
294
+ /**
295
+ * Abstract base class for creating and managing transactions in the NEXA blockchain.
296
+ * Provides common functionality for transaction building including token operations,
297
+ * address validation, and output creation.
298
+ */
299
+ declare abstract class TransactionCreator {
300
+ /**
301
+ * Creates a new TransactionCreator instance
302
+ * @param tx Optional existing TransactionBuilder, hex string, or buffer
303
+ */
304
+ protected constructor(tx?: TransactionBuilder | string | Buffer);
305
+ /** Parse transaction from hex string - must be implemented by subclasses */
306
+ abstract parseTxHex(tx: string): this;
307
+ /** Parse transaction from buffer - must be implemented by subclasses */
308
+ abstract parseTxBuffer(tx: Buffer): this;
309
+ /**
310
+ * Sets the network for this transaction
311
+ * @param network Network name or Networkish object
312
+ * @returns This instance for chaining
313
+ */
314
+ onNetwork(network: string | Networkish): this;
315
+ /** Gets transaction options */
316
+ get txOptions(): TxOptions;
317
+ /** Sets transaction options */
318
+ set txOptions(value: TxOptions);
319
+ /** Gets the network for this transaction */
320
+ get network(): Networkish;
321
+ /** Sets the network for this transaction */
322
+ set network(value: Networkish);
323
+ /** Gets the builder function array */
324
+ get builder(): (() => Promise<any>)[];
325
+ /** Sets the builder function array */
326
+ set builder(value: (() => Promise<any>)[]);
327
+ /** Gets the underlying transaction builder */
328
+ get transactionBuilder(): TransactionBuilder;
329
+ /** Sets the underlying transaction builder */
330
+ set transactionBuilder(value: TransactionBuilder);
331
+ /** Gets the set of token actions */
332
+ get tokens(): Set<TokenAction>;
333
+ /** Sets the set of token actions */
334
+ set tokens(value: Set<TokenAction>);
335
+ /** Gets the total NEXA value being sent */
336
+ get totalValue(): bigint;
337
+ /** Sets the total NEXA value being sent */
338
+ set totalValue(value: bigint);
339
+ /**
340
+ * Validates and creates a token action
341
+ * @param toAddr Destination address
342
+ * @param amount Amount to send
343
+ * @param token Token ID
344
+ * @param action Action type (mint, melt, send, etc.)
345
+ * @throws Error if validation fails
346
+ */
347
+ protected tokenAction(toAddr: string, amount: string, token: string, action: string): void;
348
+ /**
349
+ * Configures transaction to consolidate UTXOs to a single address
350
+ * @param toAddr Address to consolidate funds to
351
+ * @returns This instance for chaining
352
+ */
353
+ consolidate(toAddr: string): this;
354
+ /**
355
+ * Configures transaction to deduct fee from the send amount
356
+ * @returns This instance for chaining
357
+ */
358
+ feeFromAmount(): this;
359
+ /**
360
+ * Adds a token send operation to the transaction
361
+ * @param toAddr Destination address
362
+ * @param amount Amount of tokens to send
363
+ * @param token Token ID
364
+ * @returns This instance for chaining
365
+ */
366
+ sendToToken(toAddr: string, amount: string, token: string): this;
367
+ /**
368
+ * Adds a NEXA send operation to the transaction
369
+ * @param toAddr Destination address
370
+ * @param amount Amount of NEXA to send
371
+ * @returns This instance for chaining
372
+ */
373
+ sendTo(toAddr: string, amount: string): this;
374
+ /**
375
+ * Adds a token authority renewal operation
376
+ * @param token Token ID to renew authority for
377
+ * @param perms Permissions to renew
378
+ * @param toAddr
379
+ * @returns This instance for chaining
380
+ */
381
+ renewAuthority(token: string, perms: PermissionLabel[], toAddr?: string): this;
382
+ /**
383
+ * Adds a token authority deletion operation
384
+ * @param token Token ID to delete authority for
385
+ * @param outpoint Outpoint of the authority to delete
386
+ * @returns This instance for chaining
387
+ */
388
+ deleteAuthority(token: string, outpoint: string): this;
389
+ /**
390
+ * Creates a legacy token (not implemented)
391
+ * @returns This instance for chaining
392
+ */
393
+ legacyToken(name: string, ticker: string, decimals: number, docUrl: string, docHash: string): this;
394
+ /**
395
+ * Creates a legacy group (not implemented)
396
+ * @returns This instance for chaining
397
+ */
398
+ legacyGroup(name: string, ticker: string, docUrl: string, docHash: string): this;
399
+ /**
400
+ * Creates a token with metadata
401
+ * @param name Token name
402
+ * @param ticker Token ticker symbol
403
+ * @param decimals Number of decimal places
404
+ * @param docUrl URL to token documentation
405
+ * @param docHash Hash of token documentation
406
+ * @returns This instance for chaining
407
+ */
408
+ token(name: string, ticker: string, decimals: number, docUrl: string, docHash: string): this;
409
+ /**
410
+ * Creates an NFT collection with metadata
411
+ * @param name Collection name
412
+ * @param ticker Collection ticker symbol
413
+ * @param docUrl URL to collection documentation
414
+ * @param docHash Hash of collection documentation
415
+ * @returns This instance for chaining
416
+ */
417
+ collection(name: string, ticker: string, docUrl: string, docHash: string): this;
418
+ /**
419
+ * Creates an NFT within a collection
420
+ * @param parent Parent collection token ID
421
+ * @param zipUrl URL to NFT content ZIP file
422
+ * @param zipHash Hash of NFT content ZIP file
423
+ * @returns This instance for chaining
424
+ */
425
+ nft(parent: string, zipUrl: string, zipHash: string): this;
426
+ /**
427
+ * Adds an OP_RETURN output to the transaction
428
+ * @param data Data to include in the OP_RETURN
429
+ * @param isFullScript Whether the data is already a complete script
430
+ * @returns This instance for chaining
431
+ */
432
+ addOpReturn(data: Buffer | string | Script, isFullScript?: boolean): this;
433
+ /** Populates the transaction with inputs and outputs - must be implemented by subclasses */
434
+ abstract populate(): this;
435
+ /**
436
+ * Builds the transaction by executing all queued operations
437
+ * @returns Promise resolving to the serialized transaction hex
438
+ */
439
+ build(): Promise<string>;
440
+ }
441
+ export class WalletTransactionCreator extends TransactionCreator {
442
+ constructor(fromAccount: BaseAccount, tx?: TransactionBuilder | string | Buffer);
443
+ fromAccount(fromAccount: BaseAccount): this;
444
+ parseTxHex(tx: string): this;
445
+ parseTxBuffer(tx: Buffer): this;
446
+ mint(token: string, amount: string): this;
447
+ melt(token: string, amount: string): this;
448
+ populate(): this;
449
+ sign(): this;
450
+ }
451
+ /**
452
+ * AccountStore manages a collection of wallet accounts of different types.
453
+ * It provides functionality to create, import, export, and manage accounts
454
+ * including DApp accounts, Vault accounts, and Default NEXA accounts.
455
+ */
456
+ export class AccountStore {
457
+ /**
458
+ * Creates a new AccountStore instance
459
+ * Initializes an empty map to store accounts
460
+ */
461
+ constructor();
462
+ /**
463
+ * Creates a new account of the specified type
464
+ * @param accountType Type of account to create (DAPP, VAULT, or DEFAULT)
465
+ * @param masterKey Master HD private key for deriving account keys
466
+ * @returns Promise resolving to the created account
467
+ */
468
+ createAccount(accountType: AccountType, masterKey: HDPrivateKey): Promise<BaseAccount>;
469
+ /**
470
+ * Finds the private key associated with a given address across all accounts
471
+ * @param address The address to search for
472
+ * @returns The AddressKey containing the private key, or null if not found
473
+ */
474
+ findKeyForAddress(address: string): AddressKey | null;
475
+ /**
476
+ * Imports an existing account into the store
477
+ * @param accountData The account data to import
478
+ * @throws Error if an account with the same key already exists
479
+ */
480
+ importAccount(accountData: BaseAccount): void;
481
+ /**
482
+ * Exports account data by index
483
+ * @param accountIndex The account index to export
484
+ * @returns The account data
485
+ * @throws Error if the account doesn't exist
486
+ */
487
+ exportAccount(accountIndex: string): BaseAccount;
488
+ /**
489
+ * Removes an account from the store
490
+ * @param accountIndex The account index to remove
491
+ * @throws Error if the account doesn't exist
492
+ */
493
+ removeAccount(accountIndex: string): void;
494
+ /**
495
+ * Returns all accounts in the store
496
+ * @returns Map of account store keys to BaseAccount objects
497
+ */
498
+ listAccounts(): Map<string, BaseAccount>;
499
+ /**
500
+ * Retrieves a specific account by its index
501
+ * @param index The account index to retrieve
502
+ * @returns The account if found, undefined otherwise
503
+ */
504
+ getAccount(index: string): BaseAccount | undefined;
505
+ }
506
+ /**
507
+ * Main Wallet class for managing Nexa blockchain wallet operations
508
+ *
509
+ * This class provides comprehensive wallet functionality including:
510
+ * - Creating wallets from seed phrases or private keys
511
+ * - Account discovery and management
512
+ * - Transaction creation and signing
513
+ * - Message signing and verification
514
+ * - Multi-account support with different account types
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * // Create a new wallet with random seed phrase
519
+ * const wallet = Wallet.create();
520
+ *
521
+ * // Restore wallet from existing seed phrase
522
+ * const wallet = Wallet.fromSeedPhrase('your twelve word seed phrase here');
523
+ *
524
+ * // Initialize wallet (discovers accounts and balances)
525
+ * await wallet.initialize();
526
+ *
527
+ * // Create a new account
528
+ * const account = await wallet.newAccount('DefaultAccount');
529
+ *
530
+ * // Create and send a transaction
531
+ * const tx = wallet.newTransaction(account)
532
+ * .to('nexa:address', 1000000) // 1 NEXA in satoshis
533
+ * .sign();
534
+ *
535
+ * const txId = await wallet.sendTransaction(tx.toHex());
536
+ * ```
537
+ */
538
+ export class Wallet {
539
+ /**
540
+ * Creates a new Wallet instance
541
+ *
542
+ * @param data - Optional wallet data:
543
+ * - undefined: Generate new random seed phrase
544
+ * - string: Use as BIP39 seed phrase
545
+ * - HDPrivateKey: Use as master key directly
546
+ * @param network - Network name ('mainnet', 'testnet', 'regtest'). Defaults to 'mainnet'
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * // Create new wallet with random seed
551
+ * const wallet = new Wallet();
552
+ *
553
+ * // Create from seed phrase
554
+ * const wallet = new Wallet('abandon abandon abandon...');
555
+ *
556
+ * // Create from master key
557
+ * const masterKey = HDPrivateKey.fromString('xprv...');
558
+ * const wallet = new Wallet(masterKey);
559
+ *
560
+ * // Create on testnet
561
+ * const wallet = new Wallet(undefined, 'testnet');
562
+ * ```
563
+ */
564
+ constructor(data?: string | HDPrivateKey | undefined, network?: string);
565
+ /**
566
+ * Create a new wallet with a randomly generated seed phrase
567
+ *
568
+ * This is the recommended way to create a new wallet for first-time users.
569
+ * The generated seed phrase should be securely stored by the user.
570
+ *
571
+ * @returns A new Wallet instance with a random 12-word seed phrase
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * const wallet = Wallet.create();
576
+ * console.log(wallet.export().phrase); // Store this securely!
577
+ * ```
578
+ */
579
+ static create(): Wallet;
580
+ /**
581
+ * Create a wallet from an existing BIP39 seed phrase
582
+ *
583
+ * Use this method to restore a wallet from a previously generated seed phrase.
584
+ * The seed phrase should be a valid BIP39 mnemonic.
585
+ *
586
+ * @param phrase - The BIP39 seed phrase (12 or 24 words)
587
+ * @param network - Optional network name ('mainnet', 'testnet', 'regtest')
588
+ * @returns A new Wallet instance restored from the seed phrase
589
+ * @throws {Error} If the seed phrase is invalid or not provided
590
+ *
591
+ * @example
592
+ * ```typescript
593
+ * const wallet = Wallet.fromSeedPhrase(
594
+ * 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
595
+ * 'testnet'
596
+ * );
597
+ * ```
598
+ */
599
+ static fromSeedPhrase(phrase: string, network?: string): Wallet;
600
+ /**
601
+ * Create a wallet from an extended private key (xpriv)
602
+ *
603
+ * Use this method to create a wallet from a master private key in extended format.
604
+ * This is useful for advanced users who want to use a specific key derivation.
605
+ *
606
+ * @param xpriv - The extended private key string (starts with 'xprv')
607
+ * @param network - Optional network name ('mainnet', 'testnet', 'regtest')
608
+ * @returns A new Wallet instance using the provided master key
609
+ * @throws {Error} If the private key is invalid or not provided
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * const wallet = Wallet.fromXpriv(
614
+ * 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'
615
+ * );
616
+ * ```
617
+ */
618
+ static fromXpriv(xpriv: string, network?: string): Wallet;
619
+ /**
620
+ * Initialize the wallet by discovering accounts and loading balances
621
+ *
622
+ * This method performs account discovery using the BIP44 derivation path
623
+ * and scans for existing accounts with transaction history or balances.
624
+ * Must be called before using the wallet's accounts.
625
+ *
626
+ * @returns Promise that resolves when initialization is complete
627
+ *
628
+ * @example
629
+ * ```typescript
630
+ * const wallet = Wallet.fromSeedPhrase('your seed phrase');
631
+ * await wallet.initialize();
632
+ *
633
+ * // Now you can access discovered accounts
634
+ * const accounts = wallet.accountStore.listAccounts();
635
+ * ```
636
+ */
637
+ initialize(): Promise<void>;
638
+ /**
639
+ * Create a new transaction builder for this wallet
640
+ *
641
+ * @param fromAccount - The account to send the transaction from
642
+ * @param x - Optional existing transaction data:
643
+ * - TransactionBuilder: Use existing transaction builder
644
+ * - string: Parse from hex string
645
+ * - Buffer: Parse from binary buffer
646
+ * - undefined: Create new empty transaction
647
+ * @returns A new WalletTransactionCreator instance
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * const account = wallet.accountStore.getAccount(0);
652
+ * const tx = wallet.newTransaction(account)
653
+ * .to('nexa:address', 1000000) // 1 NEXA
654
+ * .sign();
655
+ *
656
+ * // Or from existing transaction hex
657
+ * const tx = wallet.newTransaction(account, 'raw_tx_hex')
658
+ * .sign();
659
+ * ```
660
+ */
661
+ newTransaction(fromAccount: BaseAccount, x?: TransactionBuilder | string | Buffer): WalletTransactionCreator;
662
+ /**
663
+ * Create a new account for this wallet
664
+ *
665
+ * @param accountType - The type of account to create:
666
+ * - 'DefaultAccount': Standard account for general use
667
+ * - 'VaultAccount': Secured account with additional protection
668
+ * - 'DappAccount': Account optimized for dApp interactions
669
+ * @returns Promise that resolves to the newly created account
670
+ *
671
+ * @example
672
+ * ```typescript
673
+ * const defaultAccount = await wallet.newAccount('DefaultAccount');
674
+ * const vaultAccount = await wallet.newAccount('VaultAccount');
675
+ * const dappAccount = await wallet.newAccount('DappAccount');
676
+ * ```
677
+ */
678
+ newAccount(accountType: AccountType): Promise<BaseAccount>;
679
+ /**
680
+ * Broadcast a signed transaction to the Nexa network
681
+ *
682
+ * @param transaction - The signed transaction in hex format
683
+ * @returns Promise that resolves to the transaction ID (txid)
684
+ * @throws {Error} If the transaction is invalid or broadcast fails
685
+ *
686
+ * @example
687
+ * ```typescript
688
+ * const tx = wallet.newTransaction(account)
689
+ * .to('nexa:address', 1000000)
690
+ * .sign();
691
+ *
692
+ * const txId = await wallet.sendTransaction(tx.toHex());
693
+ * console.log('Transaction sent:', txId);
694
+ * ```
695
+ */
696
+ sendTransaction(transaction: string): Promise<string>;
697
+ /**
698
+ * Sign a message using a specific address from this wallet
699
+ *
700
+ * The message is signed using the private key associated with the given address.
701
+ * This can be used for authentication or to prove ownership of an address.
702
+ *
703
+ * @param message - The message to sign
704
+ * @param addressToUse - The address whose private key should sign the message
705
+ * @returns The signature as a base64-encoded string
706
+ * @throws {Error} If the address is not owned by this wallet
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * const account = wallet.accountStore.getAccount(0);
711
+ * const address = account.getReceiveAddress();
712
+ * const signature = wallet.signMessage('Hello World', address);
713
+ * ```
714
+ */
715
+ signMessage(message: string, addressToUse: string): string;
716
+ /**
717
+ * Verify a message signature against an address
718
+ *
719
+ * This method can verify signatures created by any address, not just addresses
720
+ * owned by this wallet. It's useful for verifying messages from other parties.
721
+ *
722
+ * @param message - The original message that was signed
723
+ * @param signature - The signature to verify (base64-encoded)
724
+ * @param address - The address that supposedly signed the message
725
+ * @returns true if the signature is valid, false otherwise
726
+ * @throws {Error} If any parameters are missing or invalid
727
+ *
728
+ * @example
729
+ * ```typescript
730
+ * const isValid = wallet.verifyMessage(
731
+ * 'Hello World',
732
+ * 'signature_string',
733
+ * 'nexa:address'
734
+ * );
735
+ * console.log('Signature valid:', isValid);
736
+ * ```
737
+ */
738
+ verifyMessage(message: string, signature: string, address: string): boolean;
739
+ /**
740
+ * Export the wallet data for backup or storage
741
+ *
742
+ * Returns an object containing the wallet's seed phrase, master key, and accounts.
743
+ * This data can be used to restore the wallet later. The seed phrase should be
744
+ * stored securely as it provides full access to the wallet.
745
+ *
746
+ * @returns Object containing wallet data
747
+ * @property {string} phrase - The BIP39 seed phrase (if available)
748
+ * @property {HDPrivateKey} masterKey - The master private key
749
+ * @property {BaseAccount[]} accounts - Array of discovered accounts
750
+ *
751
+ * @example
752
+ * ```typescript
753
+ * const walletData = wallet.export();
754
+ *
755
+ * // Store the seed phrase securely
756
+ * const seedPhrase = walletData.phrase;
757
+ *
758
+ * // Later, restore the wallet
759
+ * const restoredWallet = Wallet.fromSeedPhrase(seedPhrase);
760
+ * ```
761
+ */
762
+ export(): any;
763
+ /**
764
+ * Get the account store for managing wallet accounts
765
+ *
766
+ * The account store provides methods to create, import, and manage accounts
767
+ * within this wallet. Each account has its own set of addresses and keys.
768
+ *
769
+ * @returns The wallet's account store
770
+ *
771
+ * @example
772
+ * ```typescript
773
+ * const accountStore = wallet.accountStore;
774
+ * const accounts = accountStore.listAccounts();
775
+ * const firstAccount = accountStore.getAccount(0);
776
+ * ```
777
+ */
778
+ get accountStore(): AccountStore;
779
+ /**
780
+ * Get the network this wallet is operating on
781
+ *
782
+ * @returns The network object (mainnet, testnet, or regtest)
783
+ *
784
+ * @example
785
+ * ```typescript
786
+ * const network = wallet.network;
787
+ * console.log('Network:', network.name);
788
+ * ```
789
+ */
790
+ get network(): Networkish;
791
+ }
792
+ /**
793
+ * WatchOnlyTransactionCreator extends TransactionCreator to handle transaction creation
794
+ * for watch-only wallets. It manages addresses without private keys and delegates
795
+ * UTXO selection and input population to specialized utility functions.
796
+ */
797
+ export class WatchOnlyTransactionCreator extends TransactionCreator {
798
+ /**
799
+ * Creates a new WatchOnlyTransactionCreator
800
+ * @param tx Optional existing transaction builder or transaction data
801
+ */
802
+ constructor(tx?: TransactionBuilder | string | Buffer);
803
+ /**
804
+ * Sets the source addresses for transaction inputs
805
+ * @param address Single address string, array of addresses, or WatchOnlyAddress objects
806
+ * @returns This instance for chaining
807
+ */
808
+ from(address: string | string[] | WatchOnlyAddress[] | WatchOnlyAddress): this;
809
+ /**
810
+ * Adds a token minting operation to the transaction
811
+ * @param token Token ID to mint
812
+ * @param amount Amount to mint
813
+ * @param toAddr Destination address for minted tokens
814
+ * @returns This instance for chaining
815
+ */
816
+ mint(token: string, amount: string, toAddr: string): this;
817
+ /**
818
+ * Adds a token melting operation to the transaction
819
+ * @param token Token ID to melt
820
+ * @param amount Amount to melt
821
+ * @param toAddr Destination address for melted tokens
822
+ * @returns This instance for chaining
823
+ */
824
+ melt(token: string, amount: string, toAddr: string): this;
825
+ /**
826
+ * Populates the transaction with inputs and outputs based on the configured actions.
827
+ * Handles different token operations (mint, melt, group creation, etc.) and
828
+ * populates NEXA inputs for transaction fees.
829
+ * @returns This instance for chaining
830
+ */
831
+ populate(): this;
832
+ /**
833
+ * Parse transaction from buffer (not implemented for watch-only)
834
+ * @param tx Transaction buffer
835
+ * @returns This instance for chaining
836
+ * @throws Error indicating method not implemented
837
+ */
838
+ parseTxBuffer(tx: Buffer): this;
839
+ /**
840
+ * Parse transaction from hex string (not implemented for watch-only)
841
+ * @param tx Transaction hex string
842
+ * @returns This instance for chaining
843
+ * @throws Error indicating method not implemented
844
+ */
845
+ parseTxHex(tx: string): this;
846
+ }
847
+ /**
848
+ * WatchOnlyWallet provides functionality for monitoring and creating transactions
849
+ * for addresses without storing private keys. This allows users to track balances
850
+ * and create unsigned transactions that can be signed elsewhere.
851
+ */
852
+ export class WatchOnlyWallet {
853
+ /**
854
+ * Creates a new WatchOnlyWallet instance
855
+ * @param addressesToWatch Array of addresses to monitor
856
+ * @param network Optional network name (defaults to mainnet)
857
+ * @throws Error if validation fails
858
+ */
859
+ constructor(addressesToWatch: WatchOnlyAddress[], network?: string);
860
+ /**
861
+ * Creates a new transaction creator for this watch-only wallet
862
+ * @param x Optional transaction data - can be a TransactionBuilder, hex string, or Buffer
863
+ * @returns WatchOnlyTransactionCreator configured with wallet's addresses and network
864
+ */
865
+ newTransaction(x?: TransactionBuilder | string | Buffer): WatchOnlyTransactionCreator;
866
+ /**
867
+ * Broadcasts a signed transaction to the network
868
+ * @param transaction Hex-encoded signed transaction
869
+ * @returns Promise resolving to transaction ID
870
+ * @throws Error if transaction is invalid or broadcast fails
871
+ */
872
+ sendTransaction(transaction: string): Promise<string>;
873
+ subscribeToAddressNotifications(callback: SubscribeCallback): Promise<void>;
874
+ /**
875
+ * Gets the list of addresses being watched
876
+ * @returns Array of watched addresses (copy to prevent mutation)
877
+ */
878
+ getWatchedAddresses(): WatchOnlyAddress[];
879
+ }
880
+ /**
881
+ * Guards against multiple instances of the wallet SDK being loaded.
882
+ * This prevents conflicts and ensures only one version is active at a time.
883
+ * @param version - The version string to check
884
+ * @throws {Error} When multiple instances are detected
885
+ */
886
+ declare function versionGuard(version: string): void;
887
+ /**
888
+ * Wallet SDK - A TypeScript SDK for the Nexa blockchain
889
+ *
890
+ * This SDK provides comprehensive wallet functionality including:
891
+ * - Creating and managing wallets from seed phrases or private keys
892
+ * - Account management with different account types
893
+ * - Transaction building and signing
894
+ * - Token operations and management
895
+ * - Message signing and verification
896
+ *
897
+ * @example
898
+ * ```typescript
899
+ * import { Wallet } from 'wallet-sdk-ts';
900
+ *
901
+ * // Create a new wallet
902
+ * const wallet = Wallet.create();
903
+ *
904
+ * // Or restore from seed phrase
905
+ * const wallet = Wallet.fromSeedPhrase('your seed phrase here');
906
+ *
907
+ * // Initialize and discover accounts
908
+ * await wallet.initialize();
909
+ * ```
910
+ */
911
+ declare const walletSdk: {
912
+ versionGuard: typeof versionGuard;
913
+ version: string;
914
+ Wallet: typeof Wallet;
915
+ };
916
+ export default walletSdk;
917
+
918
+ //# sourceMappingURL=index.d.ts.map