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.
- package/LICENSE +20 -0
- package/README.md +165 -0
- package/Rgb.podspec +23 -0
- package/android/build.gradle +80 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/rgb/AppConstants.kt +57 -0
- package/android/src/main/java/com/rgb/RgbModule.kt +1959 -0
- package/android/src/main/java/com/rgb/RgbPackage.kt +33 -0
- package/android/src/main/java/com/rgb/WalletStore.kt +49 -0
- package/ios/AppConstants.swift +71 -0
- package/ios/Rgb.h +5 -0
- package/ios/Rgb.mm +1740 -0
- package/ios/Rgb.swift +1916 -0
- package/ios/RgbLib.swift +7615 -0
- package/ios/WalletStore.swift +61 -0
- package/lib/module/Interfaces.js +65 -0
- package/lib/module/Interfaces.js.map +1 -0
- package/lib/module/NativeRgb.js +5 -0
- package/lib/module/NativeRgb.js.map +1 -0
- package/lib/module/RgbError.js +65 -0
- package/lib/module/RgbError.js.map +1 -0
- package/lib/module/Wallet.js +854 -0
- package/lib/module/Wallet.js.map +1 -0
- package/lib/module/index.js +39 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Interfaces.d.ts +390 -0
- package/lib/typescript/src/Interfaces.d.ts.map +1 -0
- package/lib/typescript/src/NativeRgb.d.ts +417 -0
- package/lib/typescript/src/NativeRgb.d.ts.map +1 -0
- package/lib/typescript/src/RgbError.d.ts +28 -0
- package/lib/typescript/src/RgbError.d.ts.map +1 -0
- package/lib/typescript/src/Wallet.d.ts +648 -0
- package/lib/typescript/src/Wallet.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +28 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +174 -0
- package/src/Interfaces.ts +376 -0
- package/src/NativeRgb.ts +630 -0
- package/src/RgbError.ts +84 -0
- package/src/Wallet.ts +1118 -0
- package/src/index.tsx +46 -0
package/src/NativeRgb.ts
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
|
+
import type { InvoiceData } from './Interfaces';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
generateKeys(
|
|
6
|
+
bitcoinNetwork: 'MAINNET' | 'TESTNET' | 'TESTNET4' | 'REGTEST' | 'SIGNET'
|
|
7
|
+
): Promise<{
|
|
8
|
+
mnemonic: string;
|
|
9
|
+
xpub: string;
|
|
10
|
+
accountXpubVanilla: string;
|
|
11
|
+
accountXpubColored: string;
|
|
12
|
+
masterFingerprint: string;
|
|
13
|
+
}>;
|
|
14
|
+
restoreKeys(
|
|
15
|
+
bitcoinNetwork: 'MAINNET' | 'TESTNET' | 'TESTNET4' | 'REGTEST' | 'SIGNET',
|
|
16
|
+
mnemonic: string
|
|
17
|
+
): Promise<{
|
|
18
|
+
mnemonic: string;
|
|
19
|
+
xpub: string;
|
|
20
|
+
accountXpubVanilla: string;
|
|
21
|
+
accountXpubColored: string;
|
|
22
|
+
masterFingerprint: string;
|
|
23
|
+
}>;
|
|
24
|
+
initializeWallet(
|
|
25
|
+
network: string,
|
|
26
|
+
accountXpubVanilla: string,
|
|
27
|
+
accountXpubColored: string,
|
|
28
|
+
mnemonic: string,
|
|
29
|
+
masterFingerprint: string,
|
|
30
|
+
supportedSchemas: string[],
|
|
31
|
+
maxAllocationsPerUtxo: number,
|
|
32
|
+
vanillaKeychain: number
|
|
33
|
+
): Promise<number>;
|
|
34
|
+
goOnline(
|
|
35
|
+
walletId: number,
|
|
36
|
+
skipConsistencyCheck: boolean,
|
|
37
|
+
indexerUrl: string
|
|
38
|
+
): Promise<void>;
|
|
39
|
+
getBtcBalance(
|
|
40
|
+
walletId: number,
|
|
41
|
+
skipSync: boolean
|
|
42
|
+
): Promise<{
|
|
43
|
+
vanilla: {
|
|
44
|
+
settled: number;
|
|
45
|
+
future: number;
|
|
46
|
+
spendable: number;
|
|
47
|
+
};
|
|
48
|
+
colored: {
|
|
49
|
+
settled: number;
|
|
50
|
+
future: number;
|
|
51
|
+
spendable: number;
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
walletClose(walletId: number): Promise<void>;
|
|
55
|
+
backup(walletId: number, backupPath: string, password: string): Promise<void>;
|
|
56
|
+
backupInfo(walletId: number): Promise<boolean>;
|
|
57
|
+
blindReceive(
|
|
58
|
+
walletId: number,
|
|
59
|
+
assetId: string | null,
|
|
60
|
+
assignment: {
|
|
61
|
+
type:
|
|
62
|
+
| 'FUNGIBLE'
|
|
63
|
+
| 'NON_FUNGIBLE'
|
|
64
|
+
| 'INFLATION_RIGHT'
|
|
65
|
+
| 'REPLACE_RIGHT'
|
|
66
|
+
| 'ANY';
|
|
67
|
+
amount?: number;
|
|
68
|
+
},
|
|
69
|
+
durationSeconds: number | null,
|
|
70
|
+
transportEndpoints: string[],
|
|
71
|
+
minConfirmations: number
|
|
72
|
+
): Promise<{
|
|
73
|
+
invoice: string;
|
|
74
|
+
recipientId: string;
|
|
75
|
+
expirationTimestamp: number | null;
|
|
76
|
+
batchTransferIdx: number;
|
|
77
|
+
}>;
|
|
78
|
+
createUtxos(
|
|
79
|
+
walletId: number,
|
|
80
|
+
upTo: boolean,
|
|
81
|
+
num: number | null,
|
|
82
|
+
size: number | null,
|
|
83
|
+
feeRate: number,
|
|
84
|
+
skipSync: boolean
|
|
85
|
+
): Promise<number>;
|
|
86
|
+
createUtxosBegin(
|
|
87
|
+
walletId: number,
|
|
88
|
+
upTo: boolean,
|
|
89
|
+
num: number | null,
|
|
90
|
+
size: number | null,
|
|
91
|
+
feeRate: number,
|
|
92
|
+
skipSync: boolean
|
|
93
|
+
): Promise<string>;
|
|
94
|
+
createUtxosEnd(
|
|
95
|
+
walletId: number,
|
|
96
|
+
signedPsbt: string,
|
|
97
|
+
skipSync: boolean
|
|
98
|
+
): Promise<number>;
|
|
99
|
+
deleteTransfers(
|
|
100
|
+
walletId: number,
|
|
101
|
+
batchTransferIdx: number | null,
|
|
102
|
+
noAssetOnly: boolean
|
|
103
|
+
): Promise<boolean>;
|
|
104
|
+
drainTo(
|
|
105
|
+
walletId: number,
|
|
106
|
+
address: string,
|
|
107
|
+
destroyAssets: boolean,
|
|
108
|
+
feeRate: number
|
|
109
|
+
): Promise<string>;
|
|
110
|
+
drainToBegin(
|
|
111
|
+
walletId: number,
|
|
112
|
+
address: string,
|
|
113
|
+
destroyAssets: boolean,
|
|
114
|
+
feeRate: number
|
|
115
|
+
): Promise<string>;
|
|
116
|
+
drainToEnd(walletId: number, signedPsbt: string): Promise<string>;
|
|
117
|
+
failTransfers(
|
|
118
|
+
walletId: number,
|
|
119
|
+
batchTransferIdx: number | null,
|
|
120
|
+
noAssetOnly: boolean,
|
|
121
|
+
skipSync: boolean
|
|
122
|
+
): Promise<boolean>;
|
|
123
|
+
finalizePsbt(walletId: number, signedPsbt: string): Promise<string>;
|
|
124
|
+
getAddress(walletId: number): Promise<string>;
|
|
125
|
+
getAssetBalance(
|
|
126
|
+
walletId: number,
|
|
127
|
+
assetId: string
|
|
128
|
+
): Promise<{
|
|
129
|
+
settled: number;
|
|
130
|
+
future: number;
|
|
131
|
+
spendable: number;
|
|
132
|
+
}>;
|
|
133
|
+
getAssetMetadata(
|
|
134
|
+
walletId: number,
|
|
135
|
+
assetId: string
|
|
136
|
+
): Promise<{
|
|
137
|
+
assetId: string;
|
|
138
|
+
name: string;
|
|
139
|
+
ticker?: string;
|
|
140
|
+
details?: string;
|
|
141
|
+
precision?: number;
|
|
142
|
+
issuedSupply?: number;
|
|
143
|
+
timestamp?: number;
|
|
144
|
+
amounts?: number[];
|
|
145
|
+
assetNia?: {
|
|
146
|
+
assetId: string;
|
|
147
|
+
ticker: string;
|
|
148
|
+
name: string;
|
|
149
|
+
precision: number;
|
|
150
|
+
amounts: number;
|
|
151
|
+
timestamp: number;
|
|
152
|
+
addedAt: number;
|
|
153
|
+
balance: {
|
|
154
|
+
settled: number;
|
|
155
|
+
future: number;
|
|
156
|
+
spendable: number;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
assetUda?: {
|
|
160
|
+
assetId: string;
|
|
161
|
+
ticker: string;
|
|
162
|
+
name: string;
|
|
163
|
+
details?: string;
|
|
164
|
+
precision: number;
|
|
165
|
+
timestamp: number;
|
|
166
|
+
addedAt: number;
|
|
167
|
+
balance: {
|
|
168
|
+
settled: number;
|
|
169
|
+
future: number;
|
|
170
|
+
spendable: number;
|
|
171
|
+
};
|
|
172
|
+
media?: {
|
|
173
|
+
filePath: string;
|
|
174
|
+
mime: string;
|
|
175
|
+
};
|
|
176
|
+
attachments: Array<{
|
|
177
|
+
filePath: string;
|
|
178
|
+
mime: string;
|
|
179
|
+
}>;
|
|
180
|
+
};
|
|
181
|
+
assetCfa?: {
|
|
182
|
+
assetId: string;
|
|
183
|
+
name: string;
|
|
184
|
+
details?: string;
|
|
185
|
+
precision: number;
|
|
186
|
+
issuedSupply: number;
|
|
187
|
+
timestamp: number;
|
|
188
|
+
addedAt: number;
|
|
189
|
+
balance: {
|
|
190
|
+
settled: number;
|
|
191
|
+
future: number;
|
|
192
|
+
spendable: number;
|
|
193
|
+
};
|
|
194
|
+
media?: {
|
|
195
|
+
filePath: string;
|
|
196
|
+
mime: string;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
assetIfa?: {
|
|
200
|
+
assetId: string;
|
|
201
|
+
ticker: string;
|
|
202
|
+
name: string;
|
|
203
|
+
details?: string;
|
|
204
|
+
precision: number;
|
|
205
|
+
initialSupply: number;
|
|
206
|
+
maxSupply: number;
|
|
207
|
+
knownCirculatingSupply: number;
|
|
208
|
+
timestamp: number;
|
|
209
|
+
addedAt: number;
|
|
210
|
+
balance: {
|
|
211
|
+
settled: number;
|
|
212
|
+
future: number;
|
|
213
|
+
spendable: number;
|
|
214
|
+
};
|
|
215
|
+
media?: {
|
|
216
|
+
filePath: string;
|
|
217
|
+
mime: string;
|
|
218
|
+
};
|
|
219
|
+
rejectListUrl?: string;
|
|
220
|
+
};
|
|
221
|
+
}>;
|
|
222
|
+
getFeeEstimation(walletId: number, blocks: number): Promise<number>;
|
|
223
|
+
getMediaDir(walletId: number): Promise<string>;
|
|
224
|
+
getWalletData(walletId: number): Promise<{
|
|
225
|
+
dataDir: string;
|
|
226
|
+
bitcoinNetwork: string;
|
|
227
|
+
databaseType: string;
|
|
228
|
+
maxAllocationsPerUtxo: number;
|
|
229
|
+
accountXpubVanilla: string;
|
|
230
|
+
accountXpubColored: string;
|
|
231
|
+
mnemonic?: string;
|
|
232
|
+
masterFingerprint: string;
|
|
233
|
+
vanillaKeychain?: number;
|
|
234
|
+
supportedSchemas: string[];
|
|
235
|
+
}>;
|
|
236
|
+
getWalletDir(walletId: number): Promise<string>;
|
|
237
|
+
inflate(
|
|
238
|
+
walletId: number,
|
|
239
|
+
assetId: string,
|
|
240
|
+
inflationAmounts: number[],
|
|
241
|
+
feeRate: number,
|
|
242
|
+
minConfirmations: number
|
|
243
|
+
): Promise<{
|
|
244
|
+
txid: string;
|
|
245
|
+
batchTransferIdx: number;
|
|
246
|
+
}>;
|
|
247
|
+
inflateBegin(
|
|
248
|
+
walletId: number,
|
|
249
|
+
assetId: string,
|
|
250
|
+
inflationAmounts: number[],
|
|
251
|
+
feeRate: number,
|
|
252
|
+
minConfirmations: number
|
|
253
|
+
): Promise<string>;
|
|
254
|
+
inflateEnd(
|
|
255
|
+
walletId: number,
|
|
256
|
+
signedPsbt: string
|
|
257
|
+
): Promise<{
|
|
258
|
+
txid: string;
|
|
259
|
+
batchTransferIdx: number;
|
|
260
|
+
}>;
|
|
261
|
+
issueAssetCfa(
|
|
262
|
+
walletId: number,
|
|
263
|
+
name: string,
|
|
264
|
+
details: string | null,
|
|
265
|
+
precision: number,
|
|
266
|
+
amounts: number[],
|
|
267
|
+
filePath: string | null
|
|
268
|
+
): Promise<{
|
|
269
|
+
assetId: string;
|
|
270
|
+
name: string;
|
|
271
|
+
details?: string;
|
|
272
|
+
precision: number;
|
|
273
|
+
issuedSupply: number;
|
|
274
|
+
timestamp: number;
|
|
275
|
+
addedAt: number;
|
|
276
|
+
balance: {
|
|
277
|
+
settled: number;
|
|
278
|
+
future: number;
|
|
279
|
+
spendable: number;
|
|
280
|
+
};
|
|
281
|
+
media?: {
|
|
282
|
+
filePath: string;
|
|
283
|
+
mime: string;
|
|
284
|
+
};
|
|
285
|
+
}>;
|
|
286
|
+
issueAssetIfa(
|
|
287
|
+
walletId: number,
|
|
288
|
+
ticker: string,
|
|
289
|
+
name: string,
|
|
290
|
+
precision: number,
|
|
291
|
+
amounts: number[],
|
|
292
|
+
inflationAmounts: number[],
|
|
293
|
+
replaceRightsNum: number,
|
|
294
|
+
rejectListUrl: string | null
|
|
295
|
+
): Promise<{
|
|
296
|
+
assetId: string;
|
|
297
|
+
ticker: string;
|
|
298
|
+
name: string;
|
|
299
|
+
details?: string;
|
|
300
|
+
precision: number;
|
|
301
|
+
initialSupply: number;
|
|
302
|
+
maxSupply: number;
|
|
303
|
+
knownCirculatingSupply: number;
|
|
304
|
+
timestamp: number;
|
|
305
|
+
addedAt: number;
|
|
306
|
+
balance: {
|
|
307
|
+
settled: number;
|
|
308
|
+
future: number;
|
|
309
|
+
spendable: number;
|
|
310
|
+
};
|
|
311
|
+
media?: {
|
|
312
|
+
filePath: string;
|
|
313
|
+
mime: string;
|
|
314
|
+
};
|
|
315
|
+
rejectListUrl?: string;
|
|
316
|
+
}>;
|
|
317
|
+
issueAssetNia(
|
|
318
|
+
walletId: number,
|
|
319
|
+
ticker: string,
|
|
320
|
+
name: string,
|
|
321
|
+
precision: number,
|
|
322
|
+
amounts: number[]
|
|
323
|
+
): Promise<{
|
|
324
|
+
assetId: string;
|
|
325
|
+
ticker: string;
|
|
326
|
+
name: string;
|
|
327
|
+
precision: number;
|
|
328
|
+
amounts: number;
|
|
329
|
+
timestamp: number;
|
|
330
|
+
addedAt: number;
|
|
331
|
+
balance: {
|
|
332
|
+
settled: number;
|
|
333
|
+
future: number;
|
|
334
|
+
spendable: number;
|
|
335
|
+
};
|
|
336
|
+
}>;
|
|
337
|
+
issueAssetUda(
|
|
338
|
+
walletId: number,
|
|
339
|
+
ticker: string,
|
|
340
|
+
name: string,
|
|
341
|
+
details: string | null,
|
|
342
|
+
precision: number,
|
|
343
|
+
mediaFilePath: string | null,
|
|
344
|
+
attachmentsFilePaths: string[]
|
|
345
|
+
): Promise<{
|
|
346
|
+
assetId: string;
|
|
347
|
+
ticker: string;
|
|
348
|
+
name: string;
|
|
349
|
+
details?: string;
|
|
350
|
+
precision: number;
|
|
351
|
+
timestamp: number;
|
|
352
|
+
addedAt: number;
|
|
353
|
+
balance: {
|
|
354
|
+
settled: number;
|
|
355
|
+
future: number;
|
|
356
|
+
spendable: number;
|
|
357
|
+
};
|
|
358
|
+
media?: {
|
|
359
|
+
filePath: string;
|
|
360
|
+
mime: string;
|
|
361
|
+
};
|
|
362
|
+
attachments: Array<{
|
|
363
|
+
filePath: string;
|
|
364
|
+
mime: string;
|
|
365
|
+
}>;
|
|
366
|
+
}>;
|
|
367
|
+
listAssets(
|
|
368
|
+
walletId: number,
|
|
369
|
+
filterAssetSchemas: string[]
|
|
370
|
+
): Promise<{
|
|
371
|
+
nia: Array<{
|
|
372
|
+
assetId: string;
|
|
373
|
+
ticker: string;
|
|
374
|
+
name: string;
|
|
375
|
+
precision: number;
|
|
376
|
+
amounts: number;
|
|
377
|
+
timestamp: number;
|
|
378
|
+
addedAt: number;
|
|
379
|
+
balance: {
|
|
380
|
+
settled: number;
|
|
381
|
+
future: number;
|
|
382
|
+
spendable: number;
|
|
383
|
+
};
|
|
384
|
+
}>;
|
|
385
|
+
uda: Array<{
|
|
386
|
+
assetId: string;
|
|
387
|
+
ticker: string;
|
|
388
|
+
name: string;
|
|
389
|
+
details?: string;
|
|
390
|
+
precision: number;
|
|
391
|
+
timestamp: number;
|
|
392
|
+
addedAt: number;
|
|
393
|
+
balance: {
|
|
394
|
+
settled: number;
|
|
395
|
+
future: number;
|
|
396
|
+
spendable: number;
|
|
397
|
+
};
|
|
398
|
+
media?: {
|
|
399
|
+
filePath: string;
|
|
400
|
+
mime: string;
|
|
401
|
+
};
|
|
402
|
+
attachments: Array<{
|
|
403
|
+
filePath: string;
|
|
404
|
+
mime: string;
|
|
405
|
+
}>;
|
|
406
|
+
}>;
|
|
407
|
+
cfa: Array<{
|
|
408
|
+
assetId: string;
|
|
409
|
+
name: string;
|
|
410
|
+
details?: string;
|
|
411
|
+
precision: number;
|
|
412
|
+
issuedSupply: number;
|
|
413
|
+
timestamp: number;
|
|
414
|
+
addedAt: number;
|
|
415
|
+
balance: {
|
|
416
|
+
settled: number;
|
|
417
|
+
future: number;
|
|
418
|
+
spendable: number;
|
|
419
|
+
};
|
|
420
|
+
media?: {
|
|
421
|
+
filePath: string;
|
|
422
|
+
mime: string;
|
|
423
|
+
};
|
|
424
|
+
}>;
|
|
425
|
+
ifa: Array<{
|
|
426
|
+
assetId: string;
|
|
427
|
+
ticker: string;
|
|
428
|
+
name: string;
|
|
429
|
+
details?: string;
|
|
430
|
+
precision: number;
|
|
431
|
+
initialSupply: number;
|
|
432
|
+
maxSupply: number;
|
|
433
|
+
knownCirculatingSupply: number;
|
|
434
|
+
timestamp: number;
|
|
435
|
+
addedAt: number;
|
|
436
|
+
balance: {
|
|
437
|
+
settled: number;
|
|
438
|
+
future: number;
|
|
439
|
+
spendable: number;
|
|
440
|
+
};
|
|
441
|
+
media?: {
|
|
442
|
+
filePath: string;
|
|
443
|
+
mime: string;
|
|
444
|
+
};
|
|
445
|
+
rejectListUrl?: string;
|
|
446
|
+
}>;
|
|
447
|
+
}>;
|
|
448
|
+
listTransactions(
|
|
449
|
+
walletId: number,
|
|
450
|
+
skipSync: boolean
|
|
451
|
+
): Promise<
|
|
452
|
+
Array<{
|
|
453
|
+
transactionType: 'RGB_SEND' | 'DRAIN' | 'CREATE_UTXOS' | 'USER';
|
|
454
|
+
txid: string;
|
|
455
|
+
received: number;
|
|
456
|
+
sent: number;
|
|
457
|
+
fee: number;
|
|
458
|
+
confirmationTime?: number;
|
|
459
|
+
}>
|
|
460
|
+
>;
|
|
461
|
+
listTransfers(
|
|
462
|
+
walletId: number,
|
|
463
|
+
assetId: string | null
|
|
464
|
+
): Promise<
|
|
465
|
+
Array<{
|
|
466
|
+
transferIdx: number;
|
|
467
|
+
batchTransferIdx: number;
|
|
468
|
+
createdAt: number;
|
|
469
|
+
updatedAt: number;
|
|
470
|
+
kind:
|
|
471
|
+
| 'ISSUANCE'
|
|
472
|
+
| 'RECEIVE_BLIND'
|
|
473
|
+
| 'RECEIVE_WITNESS'
|
|
474
|
+
| 'SEND'
|
|
475
|
+
| 'INFLATION';
|
|
476
|
+
status:
|
|
477
|
+
| 'WAITING_COUNTERPARTY'
|
|
478
|
+
| 'WAITING_CONFIRMATIONS'
|
|
479
|
+
| 'SETTLED'
|
|
480
|
+
| 'FAILED';
|
|
481
|
+
txid?: string;
|
|
482
|
+
recipientId?: string;
|
|
483
|
+
receiveUtxo?: number;
|
|
484
|
+
changeUtxo?: number;
|
|
485
|
+
expiration?: number;
|
|
486
|
+
transportEndpoints: string;
|
|
487
|
+
invoiceString?: string;
|
|
488
|
+
consignmentPath?: string;
|
|
489
|
+
assignments: number;
|
|
490
|
+
}>
|
|
491
|
+
>;
|
|
492
|
+
listUnspents(
|
|
493
|
+
walletId: number,
|
|
494
|
+
settledOnly: boolean,
|
|
495
|
+
skipSync: boolean
|
|
496
|
+
): Promise<
|
|
497
|
+
Array<{
|
|
498
|
+
utxo: string;
|
|
499
|
+
vout: number;
|
|
500
|
+
amount: number;
|
|
501
|
+
colorable: string;
|
|
502
|
+
rgbAllocations: number;
|
|
503
|
+
}>
|
|
504
|
+
>;
|
|
505
|
+
refresh(
|
|
506
|
+
walletId: number,
|
|
507
|
+
assetId: string | null,
|
|
508
|
+
filter: Array<{
|
|
509
|
+
status: 'WAITING_COUNTERPARTY' | 'WAITING_CONFIRMATIONS';
|
|
510
|
+
incoming: boolean;
|
|
511
|
+
}>,
|
|
512
|
+
skipSync: boolean
|
|
513
|
+
): Promise<{
|
|
514
|
+
[key: string]: {
|
|
515
|
+
updatedStatus?:
|
|
516
|
+
| 'WAITING_COUNTERPARTY'
|
|
517
|
+
| 'WAITING_CONFIRMATIONS'
|
|
518
|
+
| 'SETTLED'
|
|
519
|
+
| 'FAILED';
|
|
520
|
+
failure?: string;
|
|
521
|
+
};
|
|
522
|
+
}>;
|
|
523
|
+
send(
|
|
524
|
+
walletId: number,
|
|
525
|
+
recipientMap: {
|
|
526
|
+
[key: string]: Array<{
|
|
527
|
+
recipientId: string;
|
|
528
|
+
witnessData?: {
|
|
529
|
+
amountSat: number;
|
|
530
|
+
blinding?: number;
|
|
531
|
+
};
|
|
532
|
+
assignment: {
|
|
533
|
+
type:
|
|
534
|
+
| 'FUNGIBLE'
|
|
535
|
+
| 'NON_FUNGIBLE'
|
|
536
|
+
| 'INFLATION_RIGHT'
|
|
537
|
+
| 'REPLACE_RIGHT'
|
|
538
|
+
| 'ANY';
|
|
539
|
+
amount?: number;
|
|
540
|
+
};
|
|
541
|
+
transportEndpoints: string[];
|
|
542
|
+
}>;
|
|
543
|
+
},
|
|
544
|
+
donation: boolean,
|
|
545
|
+
feeRate: number,
|
|
546
|
+
minConfirmations: number,
|
|
547
|
+
skipSync: boolean
|
|
548
|
+
): Promise<{
|
|
549
|
+
txid: string;
|
|
550
|
+
batchTransferIdx: number;
|
|
551
|
+
}>;
|
|
552
|
+
sendBegin(
|
|
553
|
+
walletId: number,
|
|
554
|
+
recipientMap: {
|
|
555
|
+
[key: string]: Array<{
|
|
556
|
+
recipientId: string;
|
|
557
|
+
witnessData?: {
|
|
558
|
+
amountSat: number;
|
|
559
|
+
blinding?: number;
|
|
560
|
+
};
|
|
561
|
+
assignment: {
|
|
562
|
+
type:
|
|
563
|
+
| 'FUNGIBLE'
|
|
564
|
+
| 'NON_FUNGIBLE'
|
|
565
|
+
| 'INFLATION_RIGHT'
|
|
566
|
+
| 'REPLACE_RIGHT'
|
|
567
|
+
| 'ANY';
|
|
568
|
+
amount?: number;
|
|
569
|
+
};
|
|
570
|
+
transportEndpoints: string[];
|
|
571
|
+
}>;
|
|
572
|
+
},
|
|
573
|
+
donation: boolean,
|
|
574
|
+
feeRate: number,
|
|
575
|
+
minConfirmations: number
|
|
576
|
+
): Promise<string>;
|
|
577
|
+
sendBtc(
|
|
578
|
+
walletId: number,
|
|
579
|
+
address: string,
|
|
580
|
+
amount: number,
|
|
581
|
+
feeRate: number,
|
|
582
|
+
skipSync: boolean
|
|
583
|
+
): Promise<string>;
|
|
584
|
+
sendBtcBegin(
|
|
585
|
+
walletId: number,
|
|
586
|
+
address: string,
|
|
587
|
+
amount: number,
|
|
588
|
+
feeRate: number,
|
|
589
|
+
skipSync: boolean
|
|
590
|
+
): Promise<string>;
|
|
591
|
+
sendBtcEnd(
|
|
592
|
+
walletId: number,
|
|
593
|
+
signedPsbt: string,
|
|
594
|
+
skipSync: boolean
|
|
595
|
+
): Promise<string>;
|
|
596
|
+
sendEnd(
|
|
597
|
+
walletId: number,
|
|
598
|
+
signedPsbt: string,
|
|
599
|
+
skipSync: boolean
|
|
600
|
+
): Promise<{
|
|
601
|
+
txid: string;
|
|
602
|
+
batchTransferIdx: number;
|
|
603
|
+
}>;
|
|
604
|
+
signPsbt(walletId: number, unsignedPsbt: string): Promise<string>;
|
|
605
|
+
sync(walletId: number): Promise<void>;
|
|
606
|
+
witnessReceive(
|
|
607
|
+
walletId: number,
|
|
608
|
+
assetId: string | null,
|
|
609
|
+
assignment: {
|
|
610
|
+
type:
|
|
611
|
+
| 'FUNGIBLE'
|
|
612
|
+
| 'NON_FUNGIBLE'
|
|
613
|
+
| 'INFLATION_RIGHT'
|
|
614
|
+
| 'REPLACE_RIGHT'
|
|
615
|
+
| 'ANY';
|
|
616
|
+
amount?: number;
|
|
617
|
+
},
|
|
618
|
+
durationSeconds: number | null,
|
|
619
|
+
transportEndpoints: string[],
|
|
620
|
+
minConfirmations: number
|
|
621
|
+
): Promise<{
|
|
622
|
+
invoice: string;
|
|
623
|
+
recipientId: string;
|
|
624
|
+
expirationTimestamp: number | null;
|
|
625
|
+
batchTransferIdx: number;
|
|
626
|
+
}>;
|
|
627
|
+
decodeInvoice(invoice: string): Promise<InvoiceData>;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('Rgb');
|
package/src/RgbError.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { RgbLibErrors } from './Interfaces';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for RGB library errors.
|
|
5
|
+
* Provides structured error information with error codes and messages.
|
|
6
|
+
*/
|
|
7
|
+
export class RgbError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Error code from the native module.
|
|
10
|
+
* This helps identify which operation failed.
|
|
11
|
+
*/
|
|
12
|
+
public readonly code: RgbLibErrors;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Original error message from the native module.
|
|
16
|
+
*/
|
|
17
|
+
public readonly nativeMessage: string;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
code: RgbLibErrors,
|
|
21
|
+
message: string,
|
|
22
|
+
public readonly originalError?: unknown
|
|
23
|
+
) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'RgbError';
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.nativeMessage = message;
|
|
28
|
+
|
|
29
|
+
if (Error.captureStackTrace) {
|
|
30
|
+
Error.captureStackTrace(this, RgbError);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public isCode(code: RgbLibErrors): boolean {
|
|
35
|
+
if (typeof this.code === 'string' && typeof code === 'string') {
|
|
36
|
+
return this.code === code;
|
|
37
|
+
}
|
|
38
|
+
if (
|
|
39
|
+
typeof this.code === 'object' &&
|
|
40
|
+
typeof code === 'object' &&
|
|
41
|
+
code !== null
|
|
42
|
+
) {
|
|
43
|
+
return (
|
|
44
|
+
'type' in this.code && 'type' in code && this.code.type === code.type
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public toString(): string {
|
|
51
|
+
const codeStr =
|
|
52
|
+
typeof this.code === 'string'
|
|
53
|
+
? this.code
|
|
54
|
+
: `[${this.code.type}] ${JSON.stringify(this.code)}`;
|
|
55
|
+
return `[${codeStr}] ${this.message}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Converts a React Native error to an RgbError.
|
|
60
|
+
* React Native errors from native modules typically have a code and message.
|
|
61
|
+
* @param error - The error from React Native
|
|
62
|
+
* @returns An RgbError instance, or the original error if it cannot be converted
|
|
63
|
+
*/
|
|
64
|
+
public static fromReactNativeError(error: unknown): RgbError | Error {
|
|
65
|
+
// Check if it's already an RgbError
|
|
66
|
+
if (error instanceof RgbError) {
|
|
67
|
+
return error;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (error instanceof Error && 'code' in error) {
|
|
71
|
+
const code = (error as any).code;
|
|
72
|
+
const message = error.message || 'Unknown error';
|
|
73
|
+
if (typeof code === 'string') {
|
|
74
|
+
return new RgbError(code as RgbLibErrors, message, error);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (error instanceof Error) {
|
|
79
|
+
return error;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return new Error(String(error));
|
|
83
|
+
}
|
|
84
|
+
}
|