react-native-rgb 0.2.0

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 (44) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +165 -0
  3. package/Rgb.podspec +23 -0
  4. package/android/build.gradle +80 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/rgb/AppConstants.kt +57 -0
  8. package/android/src/main/java/com/rgb/RgbModule.kt +1959 -0
  9. package/android/src/main/java/com/rgb/RgbPackage.kt +33 -0
  10. package/android/src/main/java/com/rgb/WalletStore.kt +49 -0
  11. package/ios/AppConstants.swift +71 -0
  12. package/ios/Rgb.h +5 -0
  13. package/ios/Rgb.mm +1740 -0
  14. package/ios/Rgb.swift +1916 -0
  15. package/ios/RgbLib.swift +7615 -0
  16. package/ios/WalletStore.swift +61 -0
  17. package/lib/module/Interfaces.js +65 -0
  18. package/lib/module/Interfaces.js.map +1 -0
  19. package/lib/module/NativeRgb.js +5 -0
  20. package/lib/module/NativeRgb.js.map +1 -0
  21. package/lib/module/RgbError.js +65 -0
  22. package/lib/module/RgbError.js.map +1 -0
  23. package/lib/module/Wallet.js +854 -0
  24. package/lib/module/Wallet.js.map +1 -0
  25. package/lib/module/index.js +39 -0
  26. package/lib/module/index.js.map +1 -0
  27. package/lib/module/package.json +1 -0
  28. package/lib/typescript/package.json +1 -0
  29. package/lib/typescript/src/Interfaces.d.ts +390 -0
  30. package/lib/typescript/src/Interfaces.d.ts.map +1 -0
  31. package/lib/typescript/src/NativeRgb.d.ts +417 -0
  32. package/lib/typescript/src/NativeRgb.d.ts.map +1 -0
  33. package/lib/typescript/src/RgbError.d.ts +28 -0
  34. package/lib/typescript/src/RgbError.d.ts.map +1 -0
  35. package/lib/typescript/src/Wallet.d.ts +648 -0
  36. package/lib/typescript/src/Wallet.d.ts.map +1 -0
  37. package/lib/typescript/src/index.d.ts +28 -0
  38. package/lib/typescript/src/index.d.ts.map +1 -0
  39. package/package.json +174 -0
  40. package/src/Interfaces.ts +376 -0
  41. package/src/NativeRgb.ts +630 -0
  42. package/src/RgbError.ts +84 -0
  43. package/src/Wallet.ts +1118 -0
  44. package/src/index.tsx +46 -0
package/src/Wallet.ts ADDED
@@ -0,0 +1,1118 @@
1
+ import Rgb from './NativeRgb';
2
+ import * as Interfaces from './Interfaces';
3
+
4
+ export interface WalletOptions {
5
+ network?: Interfaces.BitcoinNetwork;
6
+ supportedSchemas?: Interfaces.AssetSchema[];
7
+ maxAllocationsPerUtxo?: number;
8
+ vanillaKeychain?: number;
9
+ }
10
+
11
+ export class Wallet {
12
+ private walletId: number | null = null;
13
+ private keys: Interfaces.Keys;
14
+ private network: Interfaces.BitcoinNetwork;
15
+ private supportedSchemas: Interfaces.AssetSchema[];
16
+ private maxAllocationsPerUtxo: number;
17
+ private vanillaKeychain: number;
18
+ private initializationPromise: Promise<void> | null = null;
19
+
20
+ /**
21
+ * Creates a new Wallet instance with the provided keys and configuration.
22
+ * @param keys - The cryptographic keys required for wallet operations (mnemonic, master fingerprint, xPubs)
23
+ * @param options - Optional wallet configuration settings
24
+ * @param options.network - The Bitcoin network to use (defaults to 'TESTNET')
25
+ * @param options.supportedSchemas - List of RGB asset schemas the wallet supports (defaults to CFA, NIA, UDA)
26
+ * @param options.maxAllocationsPerUtxo - Maximum number of RGB allocations allowed per UTXO (defaults to 1)
27
+ * @param options.vanillaKeychain - Keychain index for the vanilla-side of the wallet (defaults to 0)
28
+ */
29
+ constructor(keys: Interfaces.Keys, options?: WalletOptions) {
30
+ this.keys = keys;
31
+ this.network = options?.network || 'TESTNET';
32
+ this.supportedSchemas = options?.supportedSchemas || [
33
+ Interfaces.AssetSchema.CFA,
34
+ Interfaces.AssetSchema.NIA,
35
+ Interfaces.AssetSchema.UDA,
36
+ ];
37
+ this.maxAllocationsPerUtxo = options?.maxAllocationsPerUtxo ?? 1;
38
+ this.vanillaKeychain = options?.vanillaKeychain ?? 0;
39
+ }
40
+
41
+ /**
42
+ * Ensures the wallet is initialized before performing operations.
43
+ * This method is called automatically by other wallet methods and handles
44
+ * concurrent initialization attempts safely.
45
+ * @returns Promise that resolves when wallet initialization is complete
46
+ */
47
+ private async ensureInitialized(): Promise<void> {
48
+ if (this.walletId !== null) {
49
+ return; // Already initialized
50
+ }
51
+
52
+ // If initialization is in progress, wait for it
53
+ if (this.initializationPromise !== null) {
54
+ return this.initializationPromise;
55
+ }
56
+
57
+ // Start initialization
58
+ this.initializationPromise = (async () => {
59
+ this.walletId = await Rgb.initializeWallet(
60
+ this.network,
61
+ this.keys.accountXpubVanilla,
62
+ this.keys.accountXpubColored,
63
+ this.keys.mnemonic,
64
+ this.keys.masterFingerprint,
65
+ this.supportedSchemas,
66
+ this.maxAllocationsPerUtxo,
67
+ this.vanillaKeychain
68
+ );
69
+ })();
70
+
71
+ await this.initializationPromise;
72
+ }
73
+
74
+ /**
75
+ * Connects the wallet to an online indexer service for syncing and transaction operations.
76
+ * Must be called before performing operations that require network connectivity.
77
+ * @param indexerUrl - The URL of the RGB indexer service to connect to
78
+ * @param skipConsistencyCheck - If true, skips the consistency check with the indexer (default: false)
79
+ * @returns Promise that resolves when the wallet is successfully connected online
80
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
81
+ * - The wallet is not found
82
+ * - The indexer URL is invalid or unreachable
83
+ * - Network connectivity issues occur
84
+ * - The consistency check fails (if skipConsistencyCheck is false)
85
+ */
86
+ async goOnline(
87
+ indexerUrl: string,
88
+ skipConsistencyCheck: boolean = false
89
+ ): Promise<void> {
90
+ await this.ensureInitialized();
91
+
92
+ if (this.walletId === null) {
93
+ throw new Error('Failed to initialize wallet');
94
+ }
95
+
96
+ await Rgb.goOnline(this.walletId, skipConsistencyCheck, indexerUrl);
97
+ }
98
+
99
+ /**
100
+ * Retrieves the Bitcoin balance for both vanilla and colored wallets.
101
+ * Returns settled, future, and spendable balances for each wallet side.
102
+ * @param skipSync - If true, skips syncing with the indexer before calculating balance (default: false)
103
+ * @returns Promise resolving to BtcBalance containing vanilla and colored wallet balances
104
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
105
+ * - The wallet is not found
106
+ * - The wallet is not online
107
+ * - Sync operation fails (if skipSync is false)
108
+ */
109
+ async getBtcBalance(
110
+ skipSync: boolean = false
111
+ ): Promise<Interfaces.BtcBalance> {
112
+ await this.ensureInitialized();
113
+
114
+ if (this.walletId === null) {
115
+ throw new Error('Failed to initialize wallet');
116
+ }
117
+
118
+ return await Rgb.getBtcBalance(this.walletId, skipSync);
119
+ }
120
+
121
+ /**
122
+ * Closes the wallet and releases all associated resources.
123
+ * After calling this method, the wallet instance can no longer be used for operations.
124
+ * @returns Promise that resolves when the wallet has been successfully closed
125
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
126
+ * - The wallet is not found
127
+ * - An error occurs while closing the wallet
128
+ */
129
+ async close(): Promise<void> {
130
+ if (this.walletId === null) {
131
+ return; // Already closed or never initialized
132
+ }
133
+
134
+ await Rgb.walletClose(this.walletId);
135
+ this.walletId = null;
136
+ this.initializationPromise = null;
137
+ }
138
+
139
+ /**
140
+ * Checks whether the wallet has been initialized.
141
+ * @returns True if the wallet is initialized and ready to use, false otherwise
142
+ */
143
+ isInitialized(): boolean {
144
+ return this.walletId !== null;
145
+ }
146
+
147
+ /**
148
+ * Retrieves the internal wallet identifier.
149
+ * @returns The wallet ID number
150
+ * @throws Error if the wallet is not initialized
151
+ * @internal This method is for internal use only
152
+ */
153
+ private getWalletId(): number {
154
+ if (this.walletId === null) {
155
+ throw new Error('Wallet is not initialized');
156
+ }
157
+ return this.walletId;
158
+ }
159
+
160
+ /**
161
+ * Creates an encrypted backup of the wallet data to the specified location.
162
+ * The backup includes all wallet state necessary for full restoration.
163
+ * @param backupPath - The file path where the backup should be saved
164
+ * @param password - The encryption password for securing the backup file
165
+ * @returns Promise that resolves when the backup has been successfully created
166
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
167
+ * - The wallet is not found
168
+ * - The backup path is invalid or inaccessible
169
+ * - Encryption fails
170
+ * - File system errors occur
171
+ */
172
+ async backup(backupPath: string, password: string): Promise<void> {
173
+ await this.ensureInitialized();
174
+ await Rgb.backup(this.getWalletId(), backupPath, password);
175
+ }
176
+
177
+ /**
178
+ * Checks whether a backup of the wallet has been created.
179
+ * @returns Promise resolving to true if a backup exists, false otherwise
180
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
181
+ * - The wallet is not found
182
+ * - An error occurs while checking backup status
183
+ */
184
+ async backupInfo(): Promise<boolean> {
185
+ await this.ensureInitialized();
186
+ return await Rgb.backupInfo(this.getWalletId());
187
+ }
188
+
189
+ /**
190
+ * Creates a blinded UTXO for receiving RGB assets and generates an invoice.
191
+ * This method blinds an existing UTXO to maintain privacy when receiving assets.
192
+ * An optional asset ID can be specified to restrict the invoice to a specific asset.
193
+ * @param assetId - Optional asset ID to embed in the invoice (null accepts any asset)
194
+ * @param assignment - The type and amount of assignment to receive (FUNGIBLE, NON_FUNGIBLE, etc.)
195
+ * @param durationSeconds - Optional invoice expiration duration in seconds (null uses default, 0 means no expiration)
196
+ * @param transportEndpoints - Array of transport endpoint URLs (1-3 endpoints) for RGB data exchange (e.g., 'rpc://127.0.0.1')
197
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
198
+ * @returns Promise resolving to ReceiveData containing invoice, recipient ID, expiration, and batch transfer index
199
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
200
+ * - The wallet is not found
201
+ * - Invalid assignment parameters
202
+ * - Insufficient UTXOs available
203
+ * - Invalid transport endpoints
204
+ */
205
+ async blindReceive(
206
+ assetId: string | null,
207
+ assignment: Interfaces.Assignment,
208
+ durationSeconds: number | null,
209
+ transportEndpoints: string[],
210
+ minConfirmations: number
211
+ ): Promise<Interfaces.ReceiveData> {
212
+ await this.ensureInitialized();
213
+ return await Rgb.blindReceive(
214
+ this.getWalletId(),
215
+ assetId,
216
+ assignment,
217
+ durationSeconds,
218
+ transportEndpoints,
219
+ minConfirmations
220
+ );
221
+ }
222
+
223
+ /**
224
+ * Creates a Bitcoin address for receiving RGB assets via witness transaction and generates an invoice.
225
+ * This method generates a new address from the vanilla wallet for receiving assets.
226
+ * An optional asset ID can be specified to restrict the invoice to a specific asset.
227
+ * @param assetId - Optional asset ID to embed in the invoice (null accepts any asset)
228
+ * @param assignment - The type and amount of assignment to receive (FUNGIBLE, NON_FUNGIBLE, etc.)
229
+ * @param durationSeconds - Optional invoice expiration duration in seconds (null uses default, 0 means no expiration)
230
+ * @param transportEndpoints - Array of transport endpoint URLs (1-3 endpoints) for RGB data exchange (e.g., 'rpc://127.0.0.1')
231
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
232
+ * @returns Promise resolving to ReceiveData containing invoice, recipient ID, expiration, and batch transfer index
233
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
234
+ * - The wallet is not found
235
+ * - Invalid assignment parameters
236
+ * - Invalid transport endpoints
237
+ */
238
+ async witnessReceive(
239
+ assetId: string | null,
240
+ assignment: Interfaces.Assignment,
241
+ durationSeconds: number | null,
242
+ transportEndpoints: string[],
243
+ minConfirmations: number
244
+ ): Promise<Interfaces.ReceiveData> {
245
+ await this.ensureInitialized();
246
+ return await Rgb.witnessReceive(
247
+ this.getWalletId(),
248
+ assetId,
249
+ assignment,
250
+ durationSeconds,
251
+ transportEndpoints,
252
+ minConfirmations
253
+ );
254
+ }
255
+
256
+ /**
257
+ * Creates new UTXOs for RGB operations in a single operation.
258
+ * UTXOs are necessary for receiving and managing RGB asset allocations.
259
+ * This method creates the PSBT, signs it, finalizes it, and broadcasts the transaction.
260
+ * @param upTo - If true, creates UTXOs until reaching the target count (ignores num parameter)
261
+ * @param num - Target number of UTXOs to create (required if upTo is false)
262
+ * @param size - Size in sats for each UTXO to create (required if upTo is false)
263
+ * @param feeRate - Transaction fee rate in sat/vbyte
264
+ * @param skipSync - If true, skips syncing with the indexer before creating UTXOs (default: false)
265
+ * @returns Promise resolving to the number of UTXOs successfully created
266
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
267
+ * - The wallet is not found
268
+ * - The wallet is not online
269
+ * - Insufficient funds for UTXO creation
270
+ * - Invalid fee rate
271
+ * - Sync operation fails (if skipSync is false)
272
+ */
273
+ async createUtxos(
274
+ upTo: boolean,
275
+ num: number | null,
276
+ size: number | null,
277
+ feeRate: number,
278
+ skipSync: boolean = false
279
+ ): Promise<number> {
280
+ await this.ensureInitialized();
281
+ return await Rgb.createUtxos(
282
+ this.getWalletId(),
283
+ upTo,
284
+ num,
285
+ size,
286
+ feeRate,
287
+ skipSync
288
+ );
289
+ }
290
+
291
+ /**
292
+ * Begins the process of creating UTXOs by generating an unsigned PSBT.
293
+ * Use this method when you need to sign the transaction externally.
294
+ * Must be followed by createUtxosEnd to complete the operation.
295
+ * @param upTo - If true, creates UTXOs until reaching the target count (ignores num parameter)
296
+ * @param num - Target number of UTXOs to create (required if upTo is false)
297
+ * @param size - Size in sats for each UTXO to create (required if upTo is false)
298
+ * @param feeRate - Transaction fee rate in sat/vbyte
299
+ * @param skipSync - If true, skips syncing with the indexer before creating UTXOs (default: false)
300
+ * @returns Promise resolving to an unsigned PSBT string that needs to be signed externally
301
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
302
+ * - The wallet is not found
303
+ * - The wallet is not online
304
+ * - Insufficient funds for UTXO creation
305
+ * - Invalid fee rate
306
+ * - Sync operation fails (if skipSync is false)
307
+ */
308
+ async createUtxosBegin(
309
+ upTo: boolean,
310
+ num: number | null,
311
+ size: number | null,
312
+ feeRate: number,
313
+ skipSync: boolean = false
314
+ ): Promise<string> {
315
+ await this.ensureInitialized();
316
+ return await Rgb.createUtxosBegin(
317
+ this.getWalletId(),
318
+ upTo,
319
+ num,
320
+ size,
321
+ feeRate,
322
+ skipSync
323
+ );
324
+ }
325
+
326
+ /**
327
+ * Completes the UTXO creation process by finalizing and broadcasting a signed PSBT.
328
+ * This method should be called after createUtxosBegin and external signing.
329
+ * @param signedPsbt - The PSBT string that has been signed externally
330
+ * @param skipSync - If true, skips syncing with the indexer after processing (default: false)
331
+ * @returns Promise resolving to the number of UTXOs successfully created
332
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
333
+ * - The wallet is not found
334
+ * - The wallet is not online
335
+ * - Invalid or improperly signed PSBT
336
+ * - Transaction broadcast fails
337
+ * - Sync operation fails (if skipSync is false)
338
+ */
339
+ async createUtxosEnd(
340
+ signedPsbt: string,
341
+ skipSync: boolean = false
342
+ ): Promise<number> {
343
+ await this.ensureInitialized();
344
+ return await Rgb.createUtxosEnd(this.getWalletId(), signedPsbt, skipSync);
345
+ }
346
+
347
+ /**
348
+ * Deletes eligible failed transfers from the wallet database.
349
+ * Only transfers in FAILED status can be deleted. When batchTransferIdx is provided,
350
+ * only that specific batch transfer is deleted (if noAssetOnly is true, transfers with
351
+ * an associated asset ID will be rejected). When batchTransferIdx is null, all failed
352
+ * transfers are deleted (if noAssetOnly is true, transfers with asset IDs are skipped).
353
+ * @param batchTransferIdx - Optional specific batch transfer index to delete (null deletes all failed transfers)
354
+ * @param noAssetOnly - If true, only deletes transfers without associated asset IDs
355
+ * @returns Promise resolving to true if any transfers were deleted, false otherwise
356
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
357
+ * - The wallet is not found
358
+ * - Database operation fails
359
+ */
360
+ async deleteTransfers(
361
+ batchTransferIdx: number | null,
362
+ noAssetOnly: boolean
363
+ ): Promise<boolean> {
364
+ await this.ensureInitialized();
365
+ return await Rgb.deleteTransfers(
366
+ this.getWalletId(),
367
+ batchTransferIdx,
368
+ noAssetOnly
369
+ );
370
+ }
371
+
372
+ /**
373
+ * Marks eligible transfers as failed in the wallet database.
374
+ * This is useful for cleaning up stuck or expired transfers. When batchTransferIdx
375
+ * is provided, only that batch transfer is marked as failed. When null, all eligible
376
+ * transfers are marked as failed (subject to noAssetOnly filter).
377
+ * @param batchTransferIdx - Optional specific batch transfer index to mark as failed (null marks all eligible)
378
+ * @param noAssetOnly - If true, only affects transfers without associated asset IDs
379
+ * @param skipSync - If true, skips syncing with the indexer before failing transfers (default: false)
380
+ * @returns Promise resolving to true if any transfers were marked as failed, false otherwise
381
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
382
+ * - The wallet is not found
383
+ * - The wallet is not online
384
+ * - Sync operation fails (if skipSync is false)
385
+ * - Database operation fails
386
+ */
387
+ async failTransfers(
388
+ batchTransferIdx: number | null,
389
+ noAssetOnly: boolean,
390
+ skipSync: boolean = false
391
+ ): Promise<boolean> {
392
+ await this.ensureInitialized();
393
+ return await Rgb.failTransfers(
394
+ this.getWalletId(),
395
+ batchTransferIdx,
396
+ noAssetOnly,
397
+ skipSync
398
+ );
399
+ }
400
+
401
+ /**
402
+ * Drains all funds (Bitcoin and RGB assets) from the wallet to a specified address in a single operation.
403
+ * This method creates the PSBT, signs it, finalizes it, and broadcasts the transaction.
404
+ * When destroyAssets is true, RGB assets are destroyed rather than transferred.
405
+ * @param address - The Bitcoin address to send all funds to
406
+ * @param destroyAssets - If true, RGB assets are destroyed; if false, they are transferred if possible
407
+ * @param feeRate - Transaction fee rate in sat/vbyte
408
+ * @returns Promise resolving to the transaction ID of the drain transaction
409
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
410
+ * - The wallet is not found
411
+ * - The wallet is not online
412
+ * - Invalid Bitcoin address
413
+ * - Insufficient funds
414
+ * - Invalid fee rate
415
+ */
416
+ async drainTo(
417
+ address: string,
418
+ destroyAssets: boolean,
419
+ feeRate: number
420
+ ): Promise<string> {
421
+ await this.ensureInitialized();
422
+ return await Rgb.drainTo(
423
+ this.getWalletId(),
424
+ address,
425
+ destroyAssets,
426
+ feeRate
427
+ );
428
+ }
429
+
430
+ /**
431
+ * Begins the drain operation by generating an unsigned PSBT.
432
+ * Use this method when you need to sign the transaction externally.
433
+ * Must be followed by drainToEnd to complete the operation.
434
+ * @param address - The Bitcoin address to send all funds to
435
+ * @param destroyAssets - If true, RGB assets are destroyed; if false, they are transferred if possible
436
+ * @param feeRate - Transaction fee rate in sat/vbyte
437
+ * @returns Promise resolving to an unsigned PSBT string that needs to be signed externally
438
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
439
+ * - The wallet is not found
440
+ * - The wallet is not online
441
+ * - Invalid Bitcoin address
442
+ * - Insufficient funds
443
+ * - Invalid fee rate
444
+ */
445
+ async drainToBegin(
446
+ address: string,
447
+ destroyAssets: boolean,
448
+ feeRate: number
449
+ ): Promise<string> {
450
+ await this.ensureInitialized();
451
+ return await Rgb.drainToBegin(
452
+ this.getWalletId(),
453
+ address,
454
+ destroyAssets,
455
+ feeRate
456
+ );
457
+ }
458
+
459
+ /**
460
+ * Completes the drain operation by finalizing and broadcasting a signed PSBT.
461
+ * This method should be called after drainToBegin and external signing.
462
+ * @param signedPsbt - The PSBT string that has been signed externally
463
+ * @returns Promise resolving to the transaction ID of the drain transaction
464
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
465
+ * - The wallet is not found
466
+ * - The wallet is not online
467
+ * - Invalid or improperly signed PSBT
468
+ * - Transaction broadcast fails
469
+ */
470
+ async drainToEnd(signedPsbt: string): Promise<string> {
471
+ await this.ensureInitialized();
472
+ return await Rgb.drainToEnd(this.getWalletId(), signedPsbt);
473
+ }
474
+
475
+ /**
476
+ * Finalizes a partially signed Bitcoin transaction (PSBT).
477
+ * This completes the transaction by combining all signatures and preparing it for broadcast.
478
+ * @param signedPsbt - The PSBT string that has been signed (may be partially signed)
479
+ * @returns Promise resolving to the finalized PSBT string ready for broadcast
480
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
481
+ * - The wallet is not found
482
+ * - Invalid or improperly formatted PSBT
483
+ * - Insufficient signatures
484
+ */
485
+ async finalizePsbt(signedPsbt: string): Promise<string> {
486
+ await this.ensureInitialized();
487
+ return await Rgb.finalizePsbt(this.getWalletId(), signedPsbt);
488
+ }
489
+
490
+ /**
491
+ * Signs a Bitcoin transaction (PSBT) with the wallet's keys.
492
+ * This method signs all inputs that the wallet can sign and returns the signed PSBT.
493
+ * @param unsignedPsbt - The unsigned PSBT string to sign
494
+ * @returns Promise resolving to the signed PSBT string
495
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
496
+ * - The wallet is not found
497
+ * - Invalid or improperly formatted PSBT
498
+ * - The wallet cannot sign the required inputs
499
+ */
500
+ async signPsbt(unsignedPsbt: string): Promise<string> {
501
+ await this.ensureInitialized();
502
+ return await Rgb.signPsbt(this.getWalletId(), unsignedPsbt);
503
+ }
504
+
505
+ /**
506
+ * Generates and returns a new Bitcoin address from the vanilla wallet.
507
+ * Each call returns the next address in the derivation sequence.
508
+ * @returns Promise resolving to a new Bitcoin address string
509
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
510
+ * - The wallet is not found
511
+ * - Address generation fails
512
+ */
513
+ async getAddress(): Promise<string> {
514
+ await this.ensureInitialized();
515
+ return await Rgb.getAddress(this.getWalletId());
516
+ }
517
+
518
+ /**
519
+ * Retrieves the balance information for a specific RGB asset.
520
+ * Returns settled, future, and spendable balances for the asset.
521
+ * @param assetId - The RGB asset identifier to query balance for
522
+ * @returns Promise resolving to Balance containing settled, future, and spendable amounts
523
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
524
+ * - The wallet is not found
525
+ * - Invalid asset ID
526
+ * - Asset not found in wallet
527
+ */
528
+ async getAssetBalance(assetId: string): Promise<Interfaces.Balance> {
529
+ await this.ensureInitialized();
530
+ return await Rgb.getAssetBalance(this.getWalletId(), assetId);
531
+ }
532
+
533
+ /**
534
+ * Retrieves comprehensive metadata for a specific RGB asset.
535
+ * Includes information such as supply, precision, schema type, token data (for UDA), and more.
536
+ * @param assetId - The RGB asset identifier to retrieve metadata for
537
+ * @returns Promise resolving to AssetMetadata containing all asset information
538
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
539
+ * - The wallet is not found
540
+ * - Invalid asset ID
541
+ * - Asset not found in wallet
542
+ */
543
+ async getAssetMetadata(assetId: string): Promise<Interfaces.AssetMetadata> {
544
+ await this.ensureInitialized();
545
+ return await Rgb.getAssetMetadata(this.getWalletId(), assetId);
546
+ }
547
+
548
+ /**
549
+ * Estimates the fee rate required for a transaction to be confirmed within a target number of blocks.
550
+ * @param blocks - The target number of blocks for confirmation
551
+ * @returns Promise resolving to the estimated fee rate in sat/vbyte
552
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
553
+ * - The wallet is not found
554
+ * - The wallet is not online
555
+ * - Fee estimation service unavailable
556
+ */
557
+ async getFeeEstimation(blocks: number): Promise<number> {
558
+ await this.ensureInitialized();
559
+ return await Rgb.getFeeEstimation(this.getWalletId(), blocks);
560
+ }
561
+
562
+ /**
563
+ * Returns the file system path to the wallet's media directory.
564
+ * This directory stores media files associated with RGB assets (e.g., images for UDA tokens).
565
+ * @returns Promise resolving to the absolute path of the media directory
566
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
567
+ * - The wallet is not found
568
+ * - Media directory path cannot be determined
569
+ */
570
+ async getMediaDir(): Promise<string> {
571
+ await this.ensureInitialized();
572
+ return await Rgb.getMediaDir(this.getWalletId());
573
+ }
574
+
575
+ /**
576
+ * Retrieves the wallet configuration and metadata.
577
+ * Returns information such as network, supported schemas, xPubs, and wallet directory.
578
+ * @returns Promise resolving to WalletData containing all wallet configuration
579
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
580
+ * - The wallet is not found
581
+ * - Wallet data cannot be retrieved
582
+ */
583
+ async getWalletData(): Promise<Interfaces.WalletData> {
584
+ await this.ensureInitialized();
585
+ return await Rgb.getWalletData(this.getWalletId());
586
+ }
587
+
588
+ /**
589
+ * Returns the file system path to the wallet's data directory.
590
+ * This directory contains all wallet files including the database and media files.
591
+ * @returns Promise resolving to the absolute path of the wallet directory
592
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
593
+ * - The wallet is not found
594
+ * - Wallet directory path cannot be determined
595
+ */
596
+ async getWalletDir(): Promise<string> {
597
+ await this.ensureInitialized();
598
+ return await Rgb.getWalletDir(this.getWalletId());
599
+ }
600
+
601
+ /**
602
+ * Inflates an Inflatable Fungible Asset (IFA) by minting additional supply in a single operation.
603
+ * This method creates the PSBT, signs it, finalizes it, and broadcasts the transaction.
604
+ * The asset must support inflation and you must have inflation rights.
605
+ * @param assetId - The IFA asset identifier to inflate
606
+ * @param inflationAmounts - Array of amounts to mint (each amount is allocated to a separate UTXO)
607
+ * @param feeRate - Transaction fee rate in sat/vbyte
608
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
609
+ * @returns Promise resolving to OperationResult containing the transaction ID and batch transfer index
610
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
611
+ * - The wallet is not found
612
+ * - The wallet is not online
613
+ * - Invalid asset ID
614
+ * - Asset does not support inflation
615
+ * - Insufficient inflation rights
616
+ * - Insufficient funds for fees
617
+ * - Invalid fee rate
618
+ */
619
+ async inflate(
620
+ assetId: string,
621
+ inflationAmounts: number[],
622
+ feeRate: number,
623
+ minConfirmations: number
624
+ ): Promise<Interfaces.OperationResult> {
625
+ await this.ensureInitialized();
626
+ return await Rgb.inflate(
627
+ this.getWalletId(),
628
+ assetId,
629
+ inflationAmounts,
630
+ feeRate,
631
+ minConfirmations
632
+ );
633
+ }
634
+
635
+ /**
636
+ * Begins the inflation process by generating an unsigned PSBT.
637
+ * Use this method when you need to sign the transaction externally.
638
+ * Must be followed by inflateEnd to complete the operation.
639
+ * @param assetId - The IFA asset identifier to inflate
640
+ * @param inflationAmounts - Array of amounts to mint (each amount is allocated to a separate UTXO)
641
+ * @param feeRate - Transaction fee rate in sat/vbyte
642
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
643
+ * @returns Promise resolving to an unsigned PSBT string that needs to be signed externally
644
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
645
+ * - The wallet is not found
646
+ * - The wallet is not online
647
+ * - Invalid asset ID
648
+ * - Asset does not support inflation
649
+ * - Insufficient inflation rights
650
+ * - Insufficient funds for fees
651
+ * - Invalid fee rate
652
+ */
653
+ async inflateBegin(
654
+ assetId: string,
655
+ inflationAmounts: number[],
656
+ feeRate: number,
657
+ minConfirmations: number
658
+ ): Promise<string> {
659
+ await this.ensureInitialized();
660
+ return await Rgb.inflateBegin(
661
+ this.getWalletId(),
662
+ assetId,
663
+ inflationAmounts,
664
+ feeRate,
665
+ minConfirmations
666
+ );
667
+ }
668
+
669
+ /**
670
+ * Completes the inflation process by finalizing and broadcasting a signed PSBT.
671
+ * This method should be called after inflateBegin and external signing.
672
+ * @param signedPsbt - The PSBT string that has been signed externally
673
+ * @returns Promise resolving to OperationResult containing the transaction ID and batch transfer index
674
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
675
+ * - The wallet is not found
676
+ * - The wallet is not online
677
+ * - Invalid or improperly signed PSBT
678
+ * - Transaction broadcast fails
679
+ */
680
+ async inflateEnd(signedPsbt: string): Promise<Interfaces.OperationResult> {
681
+ await this.ensureInitialized();
682
+ return await Rgb.inflateEnd(this.getWalletId(), signedPsbt);
683
+ }
684
+
685
+ /**
686
+ * Issues a new Collectible Fungible Asset (CFA) with the specified parameters.
687
+ * CFA assets are fungible tokens that can have associated media files.
688
+ * Each amount in the amounts array will be allocated to a separate UTXO.
689
+ * @param name - The name of the asset
690
+ * @param details - Optional detailed description of the asset
691
+ * @param precision - The decimal precision (divisibility) of the asset (0-18)
692
+ * @param amounts - Array of initial amounts to issue (each allocated to a separate UTXO)
693
+ * @param filePath - Optional path to a media file to associate with the asset
694
+ * @returns Promise resolving to AssetCfa containing the asset ID and details
695
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
696
+ * - The wallet is not found
697
+ * - Invalid asset parameters (name, precision, amounts)
698
+ * - Media file not found or invalid (if filePath provided)
699
+ * - Insufficient UTXOs for allocation
700
+ */
701
+ async issueAssetCfa(
702
+ name: string,
703
+ details: string | null,
704
+ precision: number,
705
+ amounts: number[],
706
+ filePath: string | null
707
+ ): Promise<Interfaces.AssetCfa> {
708
+ await this.ensureInitialized();
709
+ return await Rgb.issueAssetCfa(
710
+ this.getWalletId(),
711
+ name,
712
+ details,
713
+ precision,
714
+ amounts,
715
+ filePath
716
+ );
717
+ }
718
+
719
+ /**
720
+ * Issues a new Inflatable Fungible Asset (IFA) with the specified parameters.
721
+ * IFA assets are fungible tokens that support inflation and replace rights.
722
+ * The inflationAmounts array can be empty. If provided, the sum of inflationAmounts
723
+ * and amounts cannot exceed the maximum u64 value. replaceRightsNum can be 0 or
724
+ * represent the number of replace rights to create.
725
+ * @param ticker - The ticker symbol of the asset (e.g., 'BTC', 'USD')
726
+ * @param name - The name of the asset
727
+ * @param precision - The decimal precision (divisibility) of the asset (0-18)
728
+ * @param amounts - Array of initial amounts to issue (each allocated to a separate UTXO)
729
+ * @param inflationAmounts - Array of inflation amounts to issue initially (each allocated to a separate UTXO)
730
+ * @param replaceRightsNum - Number of replace rights to create (can be 0)
731
+ * @param rejectListUrl - Optional URL to a reject list for the asset
732
+ * @returns Promise resolving to AssetIfa containing the asset ID and details
733
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
734
+ * - The wallet is not found
735
+ * - Invalid asset parameters (ticker, name, precision, amounts)
736
+ * - Invalid inflation amounts or replace rights configuration
737
+ * - Invalid reject list URL (if provided)
738
+ * - Insufficient UTXOs for allocation
739
+ */
740
+ async issueAssetIfa(
741
+ ticker: string,
742
+ name: string,
743
+ precision: number,
744
+ amounts: number[],
745
+ inflationAmounts: number[],
746
+ replaceRightsNum: number,
747
+ rejectListUrl: string | null
748
+ ): Promise<Interfaces.AssetIfa> {
749
+ await this.ensureInitialized();
750
+ return await Rgb.issueAssetIfa(
751
+ this.getWalletId(),
752
+ ticker,
753
+ name,
754
+ precision,
755
+ amounts,
756
+ inflationAmounts,
757
+ replaceRightsNum,
758
+ rejectListUrl
759
+ );
760
+ }
761
+
762
+ /**
763
+ * Issues a new Non-Inflatable Asset (NIA) with the specified parameters.
764
+ * NIA assets are simple fungible tokens that cannot be inflated after issuance.
765
+ * Each amount in the amounts array will be allocated to a separate UTXO.
766
+ * @param ticker - The ticker symbol of the asset (e.g., 'BTC', 'USD')
767
+ * @param name - The name of the asset
768
+ * @param precision - The decimal precision (divisibility) of the asset (0-18)
769
+ * @param amounts - Array of initial amounts to issue (each allocated to a separate UTXO)
770
+ * @returns Promise resolving to AssetNia containing the asset ID and details
771
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
772
+ * - The wallet is not found
773
+ * - Invalid asset parameters (ticker, name, precision, amounts)
774
+ * - Insufficient UTXOs for allocation
775
+ */
776
+ async issueAssetNia(
777
+ ticker: string,
778
+ name: string,
779
+ precision: number,
780
+ amounts: number[]
781
+ ): Promise<Interfaces.AssetNia> {
782
+ await this.ensureInitialized();
783
+ return await Rgb.issueAssetNia(
784
+ this.getWalletId(),
785
+ ticker,
786
+ name,
787
+ precision,
788
+ amounts
789
+ );
790
+ }
791
+
792
+ /**
793
+ * Issues a new Unique Digital Asset (UDA) with the specified parameters.
794
+ * UDA assets are non-fungible tokens that represent unique digital items.
795
+ * Each UDA can have a primary media file and multiple attachment files.
796
+ * @param ticker - The ticker symbol of the asset
797
+ * @param name - The name of the asset
798
+ * @param details - Optional detailed description of the asset
799
+ * @param precision - The decimal precision (divisibility) of the asset (typically 0 for NFTs)
800
+ * @param mediaFilePath - Optional path to the primary media file for the asset
801
+ * @param attachmentsFilePaths - Array of paths to additional attachment files (max 20)
802
+ * @returns Promise resolving to AssetUda containing the asset ID and details
803
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
804
+ * - The wallet is not found
805
+ * - Invalid asset parameters (ticker, name, precision)
806
+ * - Media file not found or invalid (if mediaFilePath provided)
807
+ * - Attachment files not found or invalid (if attachmentsFilePaths provided)
808
+ * - Too many attachment files (max 20)
809
+ * - Insufficient UTXOs for allocation
810
+ */
811
+ async issueAssetUda(
812
+ ticker: string,
813
+ name: string,
814
+ details: string | null,
815
+ precision: number,
816
+ mediaFilePath: string | null,
817
+ attachmentsFilePaths: string[]
818
+ ): Promise<Interfaces.AssetUda> {
819
+ await this.ensureInitialized();
820
+ return await Rgb.issueAssetUda(
821
+ this.getWalletId(),
822
+ ticker,
823
+ name,
824
+ details,
825
+ precision,
826
+ mediaFilePath,
827
+ attachmentsFilePaths
828
+ );
829
+ }
830
+
831
+ /**
832
+ * Lists all RGB assets known to the wallet, optionally filtered by schema type.
833
+ * Returns assets grouped by schema (NIA, UDA, CFA, IFA). If filterAssetSchemas is empty,
834
+ * all assets are returned. Otherwise, only assets matching the provided schemas are returned.
835
+ * @param filterAssetSchemas - Array of asset schemas to filter by (empty array returns all schemas)
836
+ * @returns Promise resolving to Assets object containing arrays of assets grouped by schema
837
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
838
+ * - The wallet is not found
839
+ * - Invalid schema filter values
840
+ * - Database query fails
841
+ */
842
+ async listAssets(
843
+ filterAssetSchemas: Interfaces.AssetSchema[]
844
+ ): Promise<Interfaces.Assets> {
845
+ await this.ensureInitialized();
846
+ return await Rgb.listAssets(this.getWalletId(), filterAssetSchemas);
847
+ }
848
+
849
+ /**
850
+ * Lists all Bitcoin transactions known to the wallet.
851
+ * Includes transactions created for RGB operations (sends, UTXO creation, drains) as well as regular Bitcoin transactions.
852
+ * @param skipSync - If true, skips syncing with the indexer before listing transactions (default: false)
853
+ * @returns Promise resolving to an array of Transaction objects
854
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
855
+ * - The wallet is not found
856
+ * - Sync operation fails (if skipSync is false)
857
+ * - Database query fails
858
+ */
859
+ async listTransactions(
860
+ skipSync: boolean = false
861
+ ): Promise<Interfaces.Transaction[]> {
862
+ await this.ensureInitialized();
863
+ return await Rgb.listTransactions(this.getWalletId(), skipSync);
864
+ }
865
+
866
+ /**
867
+ * Lists all RGB transfers for a specific asset or all assets.
868
+ * Returns user-driven transfers including incoming, outgoing, issuance, and inflation transfers.
869
+ * @param assetId - Optional asset ID to filter transfers for a specific asset (null returns all transfers)
870
+ * @returns Promise resolving to an array of Transfer objects
871
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
872
+ * - The wallet is not found
873
+ * - Invalid asset ID (if provided)
874
+ * - Database query fails
875
+ */
876
+ async listTransfers(assetId: string | null): Promise<Interfaces.Transfer[]> {
877
+ await this.ensureInitialized();
878
+ return await Rgb.listTransfers(this.getWalletId(), assetId);
879
+ }
880
+
881
+ /**
882
+ * Lists all unspent transaction outputs (UTXOs) in the wallet.
883
+ * Each UTXO includes its Bitcoin balance and any RGB asset allocations.
884
+ * @param settledOnly - If true, only includes settled RGB allocations (default: false includes all)
885
+ * @param skipSync - If true, skips syncing with the indexer before listing unspents (default: false)
886
+ * @returns Promise resolving to an array of Unspent objects
887
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
888
+ * - The wallet is not found
889
+ * - Sync operation fails (if skipSync is false)
890
+ * - Database query fails
891
+ */
892
+ async listUnspents(
893
+ settledOnly: boolean,
894
+ skipSync: boolean = false
895
+ ): Promise<Interfaces.Unspent[]> {
896
+ await this.ensureInitialized();
897
+ return await Rgb.listUnspents(this.getWalletId(), settledOnly, skipSync);
898
+ }
899
+
900
+ /**
901
+ * Refreshes RGB transfers by checking for new consignments and updating transfer statuses.
902
+ * This method queries the transport endpoints to fetch new transfer data and processes any
903
+ * pending incoming or outgoing transfers. The filter parameter controls which transfers to refresh.
904
+ * @param assetId - Optional asset ID to refresh transfers for a specific asset (null refreshes all)
905
+ * @param filter - Array of RefreshFilter values to control which transfers are refreshed
906
+ * @param skipSync - If true, skips syncing with the indexer before refreshing (default: false)
907
+ * @returns Promise resolving to a record mapping transfer IDs to RefreshedTransfer objects
908
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
909
+ * - The wallet is not found
910
+ * - The wallet is not online
911
+ * - Invalid filter parameters
912
+ * - Transport endpoint connection fails
913
+ * - Sync operation fails (if skipSync is false)
914
+ */
915
+ async refresh(
916
+ assetId: string | null,
917
+ filter: Interfaces.RefreshFilter[],
918
+ skipSync: boolean = false
919
+ ): Promise<Record<string, Interfaces.RefreshedTransfer>> {
920
+ await this.ensureInitialized();
921
+ return await Rgb.refresh(this.getWalletId(), assetId, filter, skipSync);
922
+ }
923
+
924
+ /**
925
+ * Sends RGB assets to recipients in a single operation.
926
+ * This method creates the PSBT, signs it, finalizes it, and broadcasts the transaction.
927
+ * The recipientMap maps asset IDs to arrays of recipients. When donation is true, assets
928
+ * that cannot be fully sent are donated (destroyed) rather than creating change.
929
+ * @param recipientMap - Map of asset IDs to arrays of recipients for that asset
930
+ * @param donation - If true, assets that cannot be fully sent are donated rather than creating change
931
+ * @param feeRate - Transaction fee rate in sat/vbyte
932
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
933
+ * @param skipSync - If true, skips syncing with the indexer before sending (default: false)
934
+ * @returns Promise resolving to OperationResult containing the transaction ID and batch transfer index
935
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
936
+ * - The wallet is not found
937
+ * - The wallet is not online
938
+ * - Invalid recipient data
939
+ * - Insufficient asset balance
940
+ * - Insufficient funds for fees
941
+ * - Invalid fee rate
942
+ * - Sync operation fails (if skipSync is false)
943
+ */
944
+ async send(
945
+ recipientMap: Record<string, Interfaces.Recipient[]>,
946
+ donation: boolean,
947
+ feeRate: number,
948
+ minConfirmations: number,
949
+ skipSync: boolean = false
950
+ ): Promise<Interfaces.OperationResult> {
951
+ await this.ensureInitialized();
952
+ return await Rgb.send(
953
+ this.getWalletId(),
954
+ recipientMap,
955
+ donation,
956
+ feeRate,
957
+ minConfirmations,
958
+ skipSync
959
+ );
960
+ }
961
+
962
+ /**
963
+ * Begins the send operation by generating an unsigned PSBT.
964
+ * Use this method when you need to sign the transaction externally.
965
+ * Must be followed by sendEnd to complete the operation.
966
+ * @param recipientMap - Map of asset IDs to arrays of recipients for that asset
967
+ * @param donation - If true, assets that cannot be fully sent are donated rather than creating change
968
+ * @param feeRate - Transaction fee rate in sat/vbyte
969
+ * @param minConfirmations - Minimum number of confirmations required for the transaction to be considered settled
970
+ * @returns Promise resolving to an unsigned PSBT string that needs to be signed externally
971
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
972
+ * - The wallet is not found
973
+ * - The wallet is not online
974
+ * - Invalid recipient data
975
+ * - Insufficient asset balance
976
+ * - Insufficient funds for fees
977
+ * - Invalid fee rate
978
+ */
979
+ async sendBegin(
980
+ recipientMap: Record<string, Interfaces.Recipient[]>,
981
+ donation: boolean,
982
+ feeRate: number,
983
+ minConfirmations: number
984
+ ): Promise<string> {
985
+ await this.ensureInitialized();
986
+ return await Rgb.sendBegin(
987
+ this.getWalletId(),
988
+ recipientMap,
989
+ donation,
990
+ feeRate,
991
+ minConfirmations
992
+ );
993
+ }
994
+
995
+ /**
996
+ * Completes the send operation by finalizing and broadcasting a signed PSBT.
997
+ * This method should be called after sendBegin and external signing.
998
+ * @param signedPsbt - The PSBT string that has been signed externally
999
+ * @param skipSync - If true, skips syncing with the indexer after processing (default: false)
1000
+ * @returns Promise resolving to OperationResult containing the transaction ID and batch transfer index
1001
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
1002
+ * - The wallet is not found
1003
+ * - The wallet is not online
1004
+ * - Invalid or improperly signed PSBT
1005
+ * - Transaction broadcast fails
1006
+ * - Sync operation fails (if skipSync is false)
1007
+ */
1008
+ async sendEnd(
1009
+ signedPsbt: string,
1010
+ skipSync: boolean = false
1011
+ ): Promise<Interfaces.OperationResult> {
1012
+ await this.ensureInitialized();
1013
+ return await Rgb.sendEnd(this.getWalletId(), signedPsbt, skipSync);
1014
+ }
1015
+
1016
+ /**
1017
+ * Sends Bitcoin to a specified address in a single operation.
1018
+ * This method creates the PSBT, signs it, finalizes it, and broadcasts the transaction.
1019
+ * @param address - The Bitcoin address to send to
1020
+ * @param amount - The amount to send in satoshis
1021
+ * @param feeRate - Transaction fee rate in sat/vbyte
1022
+ * @param skipSync - If true, skips syncing with the indexer before sending (default: false)
1023
+ * @returns Promise resolving to the transaction ID of the Bitcoin transaction
1024
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
1025
+ * - The wallet is not found
1026
+ * - The wallet is not online
1027
+ * - Invalid Bitcoin address
1028
+ * - Insufficient balance
1029
+ * - Invalid fee rate
1030
+ * - Sync operation fails (if skipSync is false)
1031
+ */
1032
+ async sendBtc(
1033
+ address: string,
1034
+ amount: number,
1035
+ feeRate: number,
1036
+ skipSync: boolean = false
1037
+ ): Promise<string> {
1038
+ await this.ensureInitialized();
1039
+ return await Rgb.sendBtc(
1040
+ this.getWalletId(),
1041
+ address,
1042
+ amount,
1043
+ feeRate,
1044
+ skipSync
1045
+ );
1046
+ }
1047
+
1048
+ /**
1049
+ * Begins the Bitcoin send operation by generating an unsigned PSBT.
1050
+ * Use this method when you need to sign the transaction externally.
1051
+ * Must be followed by sendBtcEnd to complete the operation.
1052
+ * @param address - The Bitcoin address to send to
1053
+ * @param amount - The amount to send in satoshis
1054
+ * @param feeRate - Transaction fee rate in sat/vbyte
1055
+ * @param skipSync - If true, skips syncing with the indexer before creating the PSBT (default: false)
1056
+ * @returns Promise resolving to an unsigned PSBT string that needs to be signed externally
1057
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
1058
+ * - The wallet is not found
1059
+ * - The wallet is not online
1060
+ * - Invalid Bitcoin address
1061
+ * - Insufficient balance
1062
+ * - Invalid fee rate
1063
+ * - Sync operation fails (if skipSync is false)
1064
+ */
1065
+ async sendBtcBegin(
1066
+ address: string,
1067
+ amount: number,
1068
+ feeRate: number,
1069
+ skipSync: boolean = false
1070
+ ): Promise<string> {
1071
+ await this.ensureInitialized();
1072
+ return await Rgb.sendBtcBegin(
1073
+ this.getWalletId(),
1074
+ address,
1075
+ amount,
1076
+ feeRate,
1077
+ skipSync
1078
+ );
1079
+ }
1080
+
1081
+ /**
1082
+ * Completes the Bitcoin send operation by finalizing and broadcasting a signed PSBT.
1083
+ * This method should be called after sendBtcBegin and external signing.
1084
+ * @param signedPsbt - The PSBT string that has been signed externally
1085
+ * @param skipSync - If true, skips syncing with the indexer after processing (default: false)
1086
+ * @returns Promise resolving to the transaction ID of the Bitcoin transaction
1087
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
1088
+ * - The wallet is not found
1089
+ * - The wallet is not online
1090
+ * - Invalid or improperly signed PSBT
1091
+ * - Transaction broadcast fails
1092
+ * - Sync operation fails (if skipSync is false)
1093
+ */
1094
+ async sendBtcEnd(
1095
+ signedPsbt: string,
1096
+ skipSync: boolean = false
1097
+ ): Promise<string> {
1098
+ await this.ensureInitialized();
1099
+ return await Rgb.sendBtcEnd(this.getWalletId(), signedPsbt, skipSync);
1100
+ }
1101
+
1102
+ /**
1103
+ * Synchronizes the wallet with the connected indexer.
1104
+ * Updates the wallet's view of the blockchain state, including UTXO status,
1105
+ * transaction confirmations, and RGB transfer states. This method requires
1106
+ * the wallet to be online (goOnline must be called first).
1107
+ * @returns Promise that resolves when synchronization is complete
1108
+ * @throws {RgbError} Throws RgbError with a code from {@link RgbLibErrors} if:
1109
+ * - The wallet is not found
1110
+ * - The wallet is not online
1111
+ * - Indexer connection fails
1112
+ * - Network connectivity issues occur
1113
+ */
1114
+ async sync(): Promise<void> {
1115
+ await this.ensureInitialized();
1116
+ await Rgb.sync(this.getWalletId());
1117
+ }
1118
+ }