@utexo/rgb-lib-linux-x64 0.3.0-beta.15 → 0.3.0-beta.16.dev
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/wrapper.js
CHANGED
|
@@ -102,7 +102,16 @@ function validateArrayElements(array, expectedElementType) {
|
|
|
102
102
|
function validateEnumValues(object, enumValidValues) {
|
|
103
103
|
Object.keys(enumValidValues).forEach((key) => {
|
|
104
104
|
const allowedValues = Object.values(enumValidValues[key]);
|
|
105
|
-
|
|
105
|
+
const value = object[key];
|
|
106
|
+
if (Array.isArray(value)) {
|
|
107
|
+
value.forEach((item, index) => {
|
|
108
|
+
if (!allowedValues.includes(item)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`${key}[${index}] is invalid. Expected one of: ${allowedValues.join(", ")}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} else if (!allowedValues.includes(value)) {
|
|
106
115
|
throw new Error(
|
|
107
116
|
`${key} is invalid. Expected one of: ${allowedValues.join(", ")}`,
|
|
108
117
|
);
|
|
@@ -112,14 +121,24 @@ function validateEnumValues(object, enumValidValues) {
|
|
|
112
121
|
|
|
113
122
|
function validateTypes(values, expectedTypes) {
|
|
114
123
|
Object.keys(expectedTypes).forEach((key) => {
|
|
115
|
-
if (!(key in values)) {
|
|
116
|
-
throw new Error(`${key} must be defined`);
|
|
117
|
-
}
|
|
118
124
|
const type = expectedTypes[key];
|
|
119
125
|
const isOptional = type.endsWith("?");
|
|
126
|
+
const baseType = isOptional ? type.slice(0, -1) : type;
|
|
127
|
+
|
|
128
|
+
if (isOptional) {
|
|
129
|
+
if (
|
|
130
|
+
!(key in values) ||
|
|
131
|
+
values[key] === undefined ||
|
|
132
|
+
values[key] === null
|
|
133
|
+
) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
} else if (!(key in values) || values[key] === undefined) {
|
|
137
|
+
throw new Error(`${key} must be defined`);
|
|
138
|
+
}
|
|
139
|
+
|
|
120
140
|
let val = values[key];
|
|
121
141
|
let actualType = trueTypeOf(val);
|
|
122
|
-
const baseType = isOptional ? type.slice(0, -1) : type;
|
|
123
142
|
|
|
124
143
|
if (val !== null && isNumberType(baseType)) {
|
|
125
144
|
if (actualType != "string") {
|
|
@@ -135,13 +154,8 @@ function validateTypes(values, expectedTypes) {
|
|
|
135
154
|
}
|
|
136
155
|
const elementType = arrayMatch[1];
|
|
137
156
|
validateArrayElements(val, elementType);
|
|
138
|
-
} else if (
|
|
139
|
-
|
|
140
|
-
!(isOptional && val === null)
|
|
141
|
-
) {
|
|
142
|
-
throw new Error(
|
|
143
|
-
`${key} type must be ${baseType}${isOptional ? " or null" : ""}`,
|
|
144
|
-
);
|
|
157
|
+
} else if (!isTypeSubset(actualType, baseType)) {
|
|
158
|
+
throw new Error(`${key} type must be ${baseType}`);
|
|
145
159
|
}
|
|
146
160
|
});
|
|
147
161
|
}
|
|
@@ -157,6 +171,7 @@ exports.BitcoinNetwork = BitcoinNetwork = {
|
|
|
157
171
|
Testnet: "Testnet",
|
|
158
172
|
Testnet4: "Testnet4",
|
|
159
173
|
Signet: "Signet",
|
|
174
|
+
SignetCustom: "SignetCustom",
|
|
160
175
|
Regtest: "Regtest",
|
|
161
176
|
};
|
|
162
177
|
|
|
@@ -200,6 +215,20 @@ exports.restoreKeys = function (bitcoinNetwork, mnemonic) {
|
|
|
200
215
|
return JSON.parse(lib.rgblib_restore_keys(bitcoinNetwork, mnemonic));
|
|
201
216
|
};
|
|
202
217
|
|
|
218
|
+
exports.SinglesigKeys = class SinglesigKeys {
|
|
219
|
+
constructor(singlesigKeys) {
|
|
220
|
+
const expectedTypes = {
|
|
221
|
+
accountXpubVanilla: "string",
|
|
222
|
+
accountXpubColored: "string",
|
|
223
|
+
vanillaKeychain: "u8?",
|
|
224
|
+
masterFingerprint: "string",
|
|
225
|
+
mnemonic: "string?",
|
|
226
|
+
};
|
|
227
|
+
validateTypes(singlesigKeys, expectedTypes);
|
|
228
|
+
return singlesigKeys;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
203
232
|
exports.restoreFromVss = function (config, targetDir) {
|
|
204
233
|
const expectedTypes = {
|
|
205
234
|
server_url: "string",
|
|
@@ -242,23 +271,26 @@ exports.WalletData = class WalletData {
|
|
|
242
271
|
dataDir: "string",
|
|
243
272
|
bitcoinNetwork: "string",
|
|
244
273
|
databaseType: "string",
|
|
245
|
-
accountXpubVanilla: "string",
|
|
246
|
-
accountXpubColored: "string",
|
|
247
274
|
maxAllocationsPerUtxo: "u32",
|
|
248
|
-
|
|
275
|
+
supportedSchemas: "array[string]",
|
|
276
|
+
reuseAddresses: "boolean?",
|
|
249
277
|
};
|
|
250
278
|
validateTypes(walletData, expectedTypes);
|
|
251
279
|
validateEnumValues(walletData, {
|
|
252
280
|
bitcoinNetwork: BitcoinNetwork,
|
|
253
281
|
databaseType: DatabaseType,
|
|
282
|
+
supportedSchemas: AssetSchema,
|
|
254
283
|
});
|
|
255
284
|
return walletData;
|
|
256
285
|
}
|
|
257
286
|
};
|
|
258
287
|
|
|
259
288
|
exports.Wallet = class Wallet {
|
|
260
|
-
constructor(walletData) {
|
|
261
|
-
this.wallet = lib.rgblib_new_wallet(
|
|
289
|
+
constructor(walletData, singlesigKeys) {
|
|
290
|
+
this.wallet = lib.rgblib_new_wallet(
|
|
291
|
+
JSON.stringify(walletData),
|
|
292
|
+
JSON.stringify(singlesigKeys),
|
|
293
|
+
);
|
|
262
294
|
}
|
|
263
295
|
|
|
264
296
|
drop() {
|
|
@@ -315,21 +347,21 @@ exports.Wallet = class Wallet {
|
|
|
315
347
|
blindReceive(
|
|
316
348
|
assetId,
|
|
317
349
|
assignment,
|
|
318
|
-
|
|
350
|
+
expirationTimestamp,
|
|
319
351
|
transportEndpoints,
|
|
320
352
|
minConfirmations,
|
|
321
353
|
) {
|
|
322
354
|
const params = {
|
|
323
355
|
assetId,
|
|
324
356
|
assignment,
|
|
325
|
-
|
|
357
|
+
expirationTimestamp,
|
|
326
358
|
transportEndpoints,
|
|
327
359
|
minConfirmations,
|
|
328
360
|
};
|
|
329
361
|
const expectedTypes = {
|
|
330
362
|
assetId: "string?",
|
|
331
363
|
assignment: "string",
|
|
332
|
-
|
|
364
|
+
expirationTimestamp: "u64?",
|
|
333
365
|
transportEndpoints: "array[string]",
|
|
334
366
|
minConfirmations: "u8",
|
|
335
367
|
};
|
|
@@ -339,7 +371,7 @@ exports.Wallet = class Wallet {
|
|
|
339
371
|
this.wallet,
|
|
340
372
|
assetId,
|
|
341
373
|
assignment,
|
|
342
|
-
|
|
374
|
+
expirationTimestamp,
|
|
343
375
|
JSON.stringify(transportEndpoints),
|
|
344
376
|
minConfirmations,
|
|
345
377
|
),
|
|
@@ -408,10 +440,62 @@ exports.Wallet = class Wallet {
|
|
|
408
440
|
);
|
|
409
441
|
}
|
|
410
442
|
|
|
443
|
+
deleteTransfers(batchTransferIdx, noAssetOnly) {
|
|
444
|
+
const params = {
|
|
445
|
+
batchTransferIdx,
|
|
446
|
+
noAssetOnly,
|
|
447
|
+
};
|
|
448
|
+
const expectedTypes = {
|
|
449
|
+
batchTransferIdx: "i32?",
|
|
450
|
+
noAssetOnly: "boolean",
|
|
451
|
+
};
|
|
452
|
+
validateTypes(params, expectedTypes);
|
|
453
|
+
return JSON.parse(
|
|
454
|
+
lib.rgblib_delete_transfers(
|
|
455
|
+
this.wallet,
|
|
456
|
+
batchTransferIdx,
|
|
457
|
+
noAssetOnly,
|
|
458
|
+
),
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
failTransfers(online, batchTransferIdx, noAssetOnly, skipSync) {
|
|
463
|
+
const params = {
|
|
464
|
+
online,
|
|
465
|
+
batchTransferIdx,
|
|
466
|
+
noAssetOnly,
|
|
467
|
+
skipSync,
|
|
468
|
+
};
|
|
469
|
+
const expectedTypes = {
|
|
470
|
+
online: "object",
|
|
471
|
+
batchTransferIdx: "i32?",
|
|
472
|
+
noAssetOnly: "boolean",
|
|
473
|
+
skipSync: "boolean",
|
|
474
|
+
};
|
|
475
|
+
validateTypes(params, expectedTypes);
|
|
476
|
+
return JSON.parse(
|
|
477
|
+
lib.rgblib_fail_transfers(
|
|
478
|
+
this.wallet,
|
|
479
|
+
online,
|
|
480
|
+
batchTransferIdx,
|
|
481
|
+
noAssetOnly,
|
|
482
|
+
skipSync,
|
|
483
|
+
),
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
411
487
|
getAddress() {
|
|
412
488
|
return lib.rgblib_get_address(this.wallet);
|
|
413
489
|
}
|
|
414
490
|
|
|
491
|
+
rotateVanillaAddress() {
|
|
492
|
+
return lib.rgblib_rotate_vanilla_address(this.wallet);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
rotateColoredAddress() {
|
|
496
|
+
return lib.rgblib_rotate_colored_address(this.wallet);
|
|
497
|
+
}
|
|
498
|
+
|
|
415
499
|
getAssetBalance(assetId) {
|
|
416
500
|
const params = { assetId };
|
|
417
501
|
const expectedTypes = {
|
|
@@ -421,6 +505,15 @@ exports.Wallet = class Wallet {
|
|
|
421
505
|
return JSON.parse(lib.rgblib_get_asset_balance(this.wallet, assetId));
|
|
422
506
|
}
|
|
423
507
|
|
|
508
|
+
getAssetMetadata(assetId) {
|
|
509
|
+
const params = { assetId };
|
|
510
|
+
const expectedTypes = {
|
|
511
|
+
assetId: "string",
|
|
512
|
+
};
|
|
513
|
+
validateTypes(params, expectedTypes);
|
|
514
|
+
return JSON.parse(lib.rgblib_get_asset_metadata(this.wallet, assetId));
|
|
515
|
+
}
|
|
516
|
+
|
|
424
517
|
getBtcBalance(online, skipSync) {
|
|
425
518
|
const params = { online, skipSync };
|
|
426
519
|
const expectedTypes = {
|
|
@@ -555,6 +648,9 @@ exports.Wallet = class Wallet {
|
|
|
555
648
|
filterAssetSchemas: "array[string]",
|
|
556
649
|
};
|
|
557
650
|
validateTypes(params, expectedTypes);
|
|
651
|
+
validateEnumValues(params, {
|
|
652
|
+
filterAssetSchemas: AssetSchema,
|
|
653
|
+
});
|
|
558
654
|
return JSON.parse(
|
|
559
655
|
lib.rgblib_list_assets(
|
|
560
656
|
this.wallet,
|
|
@@ -633,57 +729,22 @@ exports.Wallet = class Wallet {
|
|
|
633
729
|
);
|
|
634
730
|
}
|
|
635
731
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
validateTypes(params, expectedTypes);
|
|
646
|
-
return JSON.parse(
|
|
647
|
-
lib.rgblib_delete_transfers(
|
|
648
|
-
this.wallet,
|
|
649
|
-
batchTransferIdx,
|
|
650
|
-
noAssetOnly,
|
|
651
|
-
),
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
failTransfers(online, batchTransferIdx, noAssetOnly, skipSync) {
|
|
656
|
-
const params = {
|
|
657
|
-
online,
|
|
658
|
-
batchTransferIdx,
|
|
659
|
-
noAssetOnly,
|
|
660
|
-
skipSync,
|
|
661
|
-
};
|
|
662
|
-
const expectedTypes = {
|
|
663
|
-
online: "object",
|
|
664
|
-
batchTransferIdx: "i32?",
|
|
665
|
-
noAssetOnly: "boolean",
|
|
666
|
-
skipSync: "boolean",
|
|
667
|
-
};
|
|
668
|
-
validateTypes(params, expectedTypes);
|
|
669
|
-
return JSON.parse(
|
|
670
|
-
lib.rgblib_fail_transfers(
|
|
671
|
-
this.wallet,
|
|
672
|
-
online,
|
|
673
|
-
batchTransferIdx,
|
|
674
|
-
noAssetOnly,
|
|
675
|
-
skipSync,
|
|
676
|
-
),
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
send(online, recipientMap, donation, feeRate, minConfirmations, skipSync) {
|
|
732
|
+
send(
|
|
733
|
+
online,
|
|
734
|
+
recipientMap,
|
|
735
|
+
donation,
|
|
736
|
+
feeRate,
|
|
737
|
+
minConfirmations,
|
|
738
|
+
expirationTimestamp,
|
|
739
|
+
skipSync,
|
|
740
|
+
) {
|
|
681
741
|
const params = {
|
|
682
742
|
online,
|
|
683
743
|
recipientMap,
|
|
684
744
|
donation,
|
|
685
745
|
feeRate,
|
|
686
746
|
minConfirmations,
|
|
747
|
+
expirationTimestamp,
|
|
687
748
|
skipSync,
|
|
688
749
|
};
|
|
689
750
|
const expectedTypes = {
|
|
@@ -692,6 +753,7 @@ exports.Wallet = class Wallet {
|
|
|
692
753
|
donation: "boolean",
|
|
693
754
|
feeRate: "u64",
|
|
694
755
|
minConfirmations: "u8",
|
|
756
|
+
expirationTimestamp: "u64?",
|
|
695
757
|
skipSync: "boolean",
|
|
696
758
|
};
|
|
697
759
|
validateTypes(params, expectedTypes);
|
|
@@ -703,18 +765,29 @@ exports.Wallet = class Wallet {
|
|
|
703
765
|
donation,
|
|
704
766
|
feeRate,
|
|
705
767
|
minConfirmations,
|
|
768
|
+
expirationTimestamp,
|
|
706
769
|
skipSync,
|
|
707
770
|
),
|
|
708
771
|
);
|
|
709
772
|
}
|
|
710
773
|
|
|
711
|
-
sendBegin(
|
|
774
|
+
sendBegin(
|
|
775
|
+
online,
|
|
776
|
+
recipientMap,
|
|
777
|
+
donation,
|
|
778
|
+
feeRate,
|
|
779
|
+
minConfirmations,
|
|
780
|
+
expirationTimestamp,
|
|
781
|
+
dryRun,
|
|
782
|
+
) {
|
|
712
783
|
const params = {
|
|
713
784
|
online,
|
|
714
785
|
recipientMap,
|
|
715
786
|
donation,
|
|
716
787
|
feeRate,
|
|
717
788
|
minConfirmations,
|
|
789
|
+
expirationTimestamp,
|
|
790
|
+
dryRun,
|
|
718
791
|
};
|
|
719
792
|
const expectedTypes = {
|
|
720
793
|
online: "object",
|
|
@@ -722,6 +795,8 @@ exports.Wallet = class Wallet {
|
|
|
722
795
|
donation: "boolean",
|
|
723
796
|
feeRate: "u64",
|
|
724
797
|
minConfirmations: "u8",
|
|
798
|
+
expirationTimestamp: "u64?",
|
|
799
|
+
dryRun: "boolean",
|
|
725
800
|
};
|
|
726
801
|
validateTypes(params, expectedTypes);
|
|
727
802
|
return lib.rgblib_send_begin(
|
|
@@ -731,28 +806,8 @@ exports.Wallet = class Wallet {
|
|
|
731
806
|
donation,
|
|
732
807
|
feeRate,
|
|
733
808
|
minConfirmations,
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
sendEnd(online, signedPsbt, skipSync) {
|
|
738
|
-
const params = {
|
|
739
|
-
online,
|
|
740
|
-
signedPsbt,
|
|
741
|
-
skipSync,
|
|
742
|
-
};
|
|
743
|
-
const expectedTypes = {
|
|
744
|
-
online: "object",
|
|
745
|
-
signedPsbt: "string",
|
|
746
|
-
skipSync: "boolean",
|
|
747
|
-
};
|
|
748
|
-
validateTypes(params, expectedTypes);
|
|
749
|
-
return JSON.parse(
|
|
750
|
-
lib.rgblib_send_end(
|
|
751
|
-
this.wallet,
|
|
752
|
-
online,
|
|
753
|
-
signedPsbt,
|
|
754
|
-
skipSync,
|
|
755
|
-
),
|
|
809
|
+
expirationTimestamp,
|
|
810
|
+
dryRun,
|
|
756
811
|
);
|
|
757
812
|
}
|
|
758
813
|
|
|
@@ -782,33 +837,7 @@ exports.Wallet = class Wallet {
|
|
|
782
837
|
);
|
|
783
838
|
}
|
|
784
839
|
|
|
785
|
-
|
|
786
|
-
const params = {
|
|
787
|
-
online,
|
|
788
|
-
address,
|
|
789
|
-
amount,
|
|
790
|
-
feeRate,
|
|
791
|
-
skipSync,
|
|
792
|
-
};
|
|
793
|
-
const expectedTypes = {
|
|
794
|
-
online: "object",
|
|
795
|
-
address: "string",
|
|
796
|
-
amount: "u64",
|
|
797
|
-
feeRate: "u64",
|
|
798
|
-
skipSync: "boolean",
|
|
799
|
-
};
|
|
800
|
-
validateTypes(params, expectedTypes);
|
|
801
|
-
return lib.rgblib_send_btc_begin(
|
|
802
|
-
this.wallet,
|
|
803
|
-
online,
|
|
804
|
-
address,
|
|
805
|
-
amount,
|
|
806
|
-
feeRate,
|
|
807
|
-
skipSync,
|
|
808
|
-
);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
sendBtcEnd(online, signedPsbt, skipSync) {
|
|
840
|
+
sendEnd(online, signedPsbt, skipSync) {
|
|
812
841
|
const params = {
|
|
813
842
|
online,
|
|
814
843
|
signedPsbt,
|
|
@@ -820,11 +849,8 @@ exports.Wallet = class Wallet {
|
|
|
820
849
|
skipSync: "boolean",
|
|
821
850
|
};
|
|
822
851
|
validateTypes(params, expectedTypes);
|
|
823
|
-
return
|
|
824
|
-
this.wallet,
|
|
825
|
-
online,
|
|
826
|
-
signedPsbt,
|
|
827
|
-
skipSync,
|
|
852
|
+
return JSON.parse(
|
|
853
|
+
lib.rgblib_send_end(this.wallet, online, signedPsbt, skipSync),
|
|
828
854
|
);
|
|
829
855
|
}
|
|
830
856
|
|
|
@@ -849,21 +875,21 @@ exports.Wallet = class Wallet {
|
|
|
849
875
|
witnessReceive(
|
|
850
876
|
assetId,
|
|
851
877
|
assignment,
|
|
852
|
-
|
|
878
|
+
expirationTimestamp,
|
|
853
879
|
transportEndpoints,
|
|
854
880
|
minConfirmations,
|
|
855
881
|
) {
|
|
856
882
|
const params = {
|
|
857
883
|
assetId,
|
|
858
884
|
assignment,
|
|
859
|
-
|
|
885
|
+
expirationTimestamp,
|
|
860
886
|
transportEndpoints,
|
|
861
887
|
minConfirmations,
|
|
862
888
|
};
|
|
863
889
|
const expectedTypes = {
|
|
864
890
|
assetId: "string?",
|
|
865
891
|
assignment: "string",
|
|
866
|
-
|
|
892
|
+
expirationTimestamp: "u64?",
|
|
867
893
|
transportEndpoints: "array[string]",
|
|
868
894
|
minConfirmations: "u8",
|
|
869
895
|
};
|
|
@@ -873,7 +899,7 @@ exports.Wallet = class Wallet {
|
|
|
873
899
|
this.wallet,
|
|
874
900
|
assetId,
|
|
875
901
|
assignment,
|
|
876
|
-
|
|
902
|
+
expirationTimestamp,
|
|
877
903
|
JSON.stringify(transportEndpoints),
|
|
878
904
|
minConfirmations,
|
|
879
905
|
),
|
|
@@ -898,6 +924,34 @@ exports.validateConsignment = function validateConsignment(filePath, indexerUrl,
|
|
|
898
924
|
);
|
|
899
925
|
};
|
|
900
926
|
|
|
927
|
+
exports.validateConsignmentOffchain = function validateConsignmentOffchain(
|
|
928
|
+
filePath,
|
|
929
|
+
txid,
|
|
930
|
+
indexerUrl,
|
|
931
|
+
bitcoinNetwork,
|
|
932
|
+
) {
|
|
933
|
+
const params = { filePath, txid, indexerUrl, bitcoinNetwork };
|
|
934
|
+
const expectedTypes = {
|
|
935
|
+
filePath: "string",
|
|
936
|
+
txid: "string",
|
|
937
|
+
indexerUrl: "string",
|
|
938
|
+
bitcoinNetwork: "string",
|
|
939
|
+
};
|
|
940
|
+
validateTypes(params, expectedTypes);
|
|
941
|
+
validateEnumValues(
|
|
942
|
+
{ bitcoinNetwork },
|
|
943
|
+
{ bitcoinNetwork: BitcoinNetwork },
|
|
944
|
+
);
|
|
945
|
+
return JSON.parse(
|
|
946
|
+
lib.rgblib_validate_consignment_offchain(
|
|
947
|
+
filePath,
|
|
948
|
+
txid,
|
|
949
|
+
indexerUrl,
|
|
950
|
+
bitcoinNetwork,
|
|
951
|
+
),
|
|
952
|
+
);
|
|
953
|
+
};
|
|
954
|
+
|
|
901
955
|
exports.Invoice = class Invoice {
|
|
902
956
|
constructor(invoiceString) {
|
|
903
957
|
const params = { invoiceString };
|