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