@utexo/rgb-sdk 1.0.4 → 1.0.5
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/Readme.md +261 -299
- package/cli/README.md +348 -0
- package/cli/commands/address.mjs +16 -0
- package/cli/commands/blindreceive.mjs +15 -0
- package/cli/commands/btcbalance.mjs +11 -0
- package/cli/commands/createlightninginvoice.mjs +14 -0
- package/cli/commands/createutxos.mjs +13 -0
- package/cli/commands/decodergbinvoice.mjs +9 -0
- package/cli/commands/generate_keys.mjs +35 -0
- package/cli/commands/getlightningreceiverequest.mjs +10 -0
- package/cli/commands/getlightningsendrequest.mjs +10 -0
- package/cli/commands/getonchainsendstatus.mjs +20 -0
- package/cli/commands/listassets.mjs +11 -0
- package/cli/commands/listtransfers.mjs +10 -0
- package/cli/commands/listunspents.mjs +10 -0
- package/cli/commands/onchainreceive.mjs +16 -0
- package/cli/commands/onchainsend.mjs +11 -0
- package/cli/commands/onchainsendbegin.mjs +9 -0
- package/cli/commands/onchainsendend.mjs +9 -0
- package/cli/commands/paylightninginvoice.mjs +11 -0
- package/cli/commands/paylightninginvoicebegin.mjs +10 -0
- package/cli/commands/paylightninginvoiceend.mjs +9 -0
- package/cli/commands/refresh.mjs +9 -0
- package/cli/commands/send.mjs +31 -0
- package/cli/commands/sign-psbt.mjs +12 -0
- package/cli/commands/signpsbt.mjs +10 -0
- package/cli/commands/witnessreceive.mjs +15 -0
- package/cli/generate_keys.mjs +66 -0
- package/cli/run.mjs +291 -0
- package/cli/utils.mjs +220 -0
- package/dist/index.cjs +1606 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1235 -145
- package/dist/index.d.ts +1235 -145
- package/dist/index.mjs +1592 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -7
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var path3 = require('path');
|
|
4
|
+
var fs2 = require('fs');
|
|
5
5
|
var rgblib = require('@utexo/rgb-lib');
|
|
6
6
|
var noble = require('@noble/hashes/legacy.js');
|
|
7
|
-
var
|
|
7
|
+
var hmac_js = require('@noble/hashes/hmac.js');
|
|
8
|
+
var sha2_js = require('@noble/hashes/sha2.js');
|
|
9
|
+
var axios = require('axios');
|
|
8
10
|
|
|
9
11
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -27,14 +29,30 @@ function _interopNamespace(e) {
|
|
|
27
29
|
return Object.freeze(n);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
+
var path3__namespace = /*#__PURE__*/_interopNamespace(path3);
|
|
33
|
+
var fs2__namespace = /*#__PURE__*/_interopNamespace(fs2);
|
|
32
34
|
var rgblib__default = /*#__PURE__*/_interopDefault(rgblib);
|
|
33
35
|
var noble__namespace = /*#__PURE__*/_interopNamespace(noble);
|
|
34
|
-
var
|
|
36
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
35
37
|
|
|
36
38
|
// src/client/rgb-lib-client.ts
|
|
37
39
|
|
|
40
|
+
// src/client/network-config.ts
|
|
41
|
+
var DEFAULT_TRANSPORT_ENDPOINTS = {
|
|
42
|
+
mainnet: "rpcs://rgb-proxy-mainnet.utexo.com/json-rpc",
|
|
43
|
+
testnet: "rpcs://rgb-proxy-testnet3.utexo.com/json-rpc",
|
|
44
|
+
testnet4: "rpcs://proxy.iriswallet.com/0.2/json-rpc",
|
|
45
|
+
signet: "rpcs://rgb-proxy-utexo.utexo.com/json-rpc",
|
|
46
|
+
regtest: "rpcs://proxy.iriswallet.com/0.2/json-rpc"
|
|
47
|
+
};
|
|
48
|
+
var DEFAULT_INDEXER_URLS = {
|
|
49
|
+
mainnet: "ssl://electrum.iriswallet.com:50003",
|
|
50
|
+
testnet: "ssl://electrum.iriswallet.com:50013",
|
|
51
|
+
testnet4: "ssl://electrum.iriswallet.com:50053",
|
|
52
|
+
signet: "https://esplora-api.utexo.com",
|
|
53
|
+
regtest: "tcp://regtest.thunderstack.org:50001"
|
|
54
|
+
};
|
|
55
|
+
|
|
38
56
|
// src/errors/index.ts
|
|
39
57
|
var SDKError = class _SDKError extends Error {
|
|
40
58
|
constructor(message, code, statusCode, cause) {
|
|
@@ -133,6 +151,135 @@ var DERIVATION_ACCOUNT = 0;
|
|
|
133
151
|
var KEYCHAIN_RGB = 0;
|
|
134
152
|
var KEYCHAIN_BTC = 0;
|
|
135
153
|
|
|
154
|
+
// src/utexo/config/utexo-presets.ts
|
|
155
|
+
function withGetAssetById(config) {
|
|
156
|
+
return {
|
|
157
|
+
...config,
|
|
158
|
+
getAssetById(tokenId) {
|
|
159
|
+
return config.assets.find((a) => a.tokenId === tokenId);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
var testnetPreset = {
|
|
164
|
+
networkMap: {
|
|
165
|
+
mainnet: "testnet",
|
|
166
|
+
utexo: "signet"
|
|
167
|
+
},
|
|
168
|
+
networkIdMap: {
|
|
169
|
+
mainnet: withGetAssetById({
|
|
170
|
+
networkName: "RGB",
|
|
171
|
+
networkId: 36,
|
|
172
|
+
assets: [
|
|
173
|
+
{
|
|
174
|
+
assetId: "rgb:WPRv95Nj-icdrgPp-zpQhIp_-2TyJ~Ge-k~FvuMZ-~vVnkA0",
|
|
175
|
+
tokenName: "tUSD",
|
|
176
|
+
longName: "USDT",
|
|
177
|
+
precision: 6,
|
|
178
|
+
tokenId: 4
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}),
|
|
182
|
+
mainnetLightning: withGetAssetById({
|
|
183
|
+
networkName: "RGB Lightning",
|
|
184
|
+
networkId: 94,
|
|
185
|
+
assets: [
|
|
186
|
+
{
|
|
187
|
+
assetId: "rgb:WPRv95Nj-icdrgPp-zpQhIp_-2TyJ~Ge-k~FvuMZ-~vVnkA0",
|
|
188
|
+
tokenName: "tUSD",
|
|
189
|
+
longName: "USDT",
|
|
190
|
+
precision: 6,
|
|
191
|
+
tokenId: 4
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}),
|
|
195
|
+
utexo: withGetAssetById({
|
|
196
|
+
networkName: "UTEXO",
|
|
197
|
+
networkId: 96,
|
|
198
|
+
assets: [
|
|
199
|
+
{
|
|
200
|
+
assetId: "rgb:yJW4k8si-~8JdNfl-nM91qFu-r5rH_HS-1hM7jpi-L~lBf90",
|
|
201
|
+
tokenName: "tUSD",
|
|
202
|
+
longName: "USDT",
|
|
203
|
+
precision: 6,
|
|
204
|
+
tokenId: 4
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var mainnetPreset = {
|
|
211
|
+
networkMap: {
|
|
212
|
+
mainnet: "mainnet",
|
|
213
|
+
utexo: "signet"
|
|
214
|
+
},
|
|
215
|
+
networkIdMap: {
|
|
216
|
+
mainnet: withGetAssetById({
|
|
217
|
+
networkName: "RGB",
|
|
218
|
+
networkId: 36,
|
|
219
|
+
// TODO: Update to production network ID
|
|
220
|
+
assets: [
|
|
221
|
+
{
|
|
222
|
+
assetId: "rgb:WPRv95Nj-icdrgPp-zpQhIp_-2TyJ~Ge-k~FvuMZ-~vVnkA0",
|
|
223
|
+
// TODO: Update to production asset ID
|
|
224
|
+
tokenName: "tUSD",
|
|
225
|
+
longName: "USDT",
|
|
226
|
+
precision: 6,
|
|
227
|
+
tokenId: 4
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}),
|
|
231
|
+
mainnetLightning: withGetAssetById({
|
|
232
|
+
networkName: "RGB Lightning",
|
|
233
|
+
networkId: 94,
|
|
234
|
+
// TODO: Update to production network ID
|
|
235
|
+
assets: [
|
|
236
|
+
{
|
|
237
|
+
assetId: "rgb:WPRv95Nj-icdrgPp-zpQhIp_-2TyJ~Ge-k~FvuMZ-~vVnkA0",
|
|
238
|
+
// TODO: Update to production asset ID
|
|
239
|
+
tokenName: "tUSD",
|
|
240
|
+
longName: "USDT",
|
|
241
|
+
precision: 6,
|
|
242
|
+
tokenId: 4
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}),
|
|
246
|
+
utexo: withGetAssetById({
|
|
247
|
+
networkName: "UTEXO",
|
|
248
|
+
networkId: 96,
|
|
249
|
+
// TODO: Update to production network ID
|
|
250
|
+
assets: [
|
|
251
|
+
{
|
|
252
|
+
assetId: "rgb:yJW4k8si-~8JdNfl-nM91qFu-r5rH_HS-1hM7jpi-L~lBf90",
|
|
253
|
+
// TODO: Update to production asset ID
|
|
254
|
+
tokenName: "tUSD",
|
|
255
|
+
longName: "USDT",
|
|
256
|
+
precision: 6,
|
|
257
|
+
tokenId: 4
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// src/utexo/utils/network.ts
|
|
265
|
+
var NETWORK_PRESETS = {
|
|
266
|
+
mainnet: mainnetPreset,
|
|
267
|
+
testnet: testnetPreset
|
|
268
|
+
};
|
|
269
|
+
function getUtxoNetworkConfig(preset) {
|
|
270
|
+
return NETWORK_PRESETS[preset];
|
|
271
|
+
}
|
|
272
|
+
var utexoNetworkMap = testnetPreset.networkMap;
|
|
273
|
+
var utexoNetworkIdMap = testnetPreset.networkIdMap;
|
|
274
|
+
function getDestinationAsset(senderNetwork, destinationNetwork, assetIdSender) {
|
|
275
|
+
const destinationConfig = utexoNetworkIdMap[destinationNetwork];
|
|
276
|
+
if (assetIdSender == null) return destinationConfig.assets[0];
|
|
277
|
+
const senderConfig = utexoNetworkIdMap[senderNetwork];
|
|
278
|
+
const senderAsset = senderConfig.assets.find((a) => a.assetId === assetIdSender);
|
|
279
|
+
if (!senderAsset) return void 0;
|
|
280
|
+
return destinationConfig.assets.find((a) => a.tokenId === senderAsset.tokenId);
|
|
281
|
+
}
|
|
282
|
+
|
|
136
283
|
// src/constants/network.ts
|
|
137
284
|
var COIN_RGB_MAINNET = 827166;
|
|
138
285
|
var COIN_RGB_TESTNET = 827167;
|
|
@@ -248,7 +395,6 @@ function validateString(value, field) {
|
|
|
248
395
|
throw new ValidationError(`${field} must be a non-empty string`, field);
|
|
249
396
|
}
|
|
250
397
|
}
|
|
251
|
-
var DEFAULT_TRANSPORT_ENDPOINT = "rpcs://proxy.iriswallet.com/0.2/json-rpc";
|
|
252
398
|
function mapNetworkToRgbLib(network) {
|
|
253
399
|
const networkMap = {
|
|
254
400
|
"mainnet": "Mainnet",
|
|
@@ -262,10 +408,10 @@ function mapNetworkToRgbLib(network) {
|
|
|
262
408
|
}
|
|
263
409
|
var restoreWallet = (params) => {
|
|
264
410
|
const { backupFilePath, password, dataDir } = params;
|
|
265
|
-
if (!
|
|
411
|
+
if (!fs2__namespace.existsSync(backupFilePath)) {
|
|
266
412
|
throw new ValidationError("Backup file not found", "backup");
|
|
267
413
|
}
|
|
268
|
-
if (!
|
|
414
|
+
if (!fs2__namespace.existsSync(dataDir)) {
|
|
269
415
|
throw new ValidationError(`Restore directory does not exist: ${dataDir}`, "restoreDir");
|
|
270
416
|
}
|
|
271
417
|
rgblib__default.default.restoreBackup(backupFilePath, password, dataDir);
|
|
@@ -273,6 +419,26 @@ var restoreWallet = (params) => {
|
|
|
273
419
|
message: "Wallet restored successfully"
|
|
274
420
|
};
|
|
275
421
|
};
|
|
422
|
+
var restoreFromVss = (params) => {
|
|
423
|
+
const anyLib = rgblib__default.default;
|
|
424
|
+
if (typeof anyLib.restoreFromVss !== "function") {
|
|
425
|
+
throw new WalletError("VSS restore is not available in the current rgb-lib build.");
|
|
426
|
+
}
|
|
427
|
+
if (!params.targetDir) {
|
|
428
|
+
throw new ValidationError("targetDir is required", "targetDir");
|
|
429
|
+
}
|
|
430
|
+
const { config, targetDir } = params;
|
|
431
|
+
const mappedConfig = {
|
|
432
|
+
server_url: config.serverUrl,
|
|
433
|
+
store_id: config.storeId,
|
|
434
|
+
signing_key: config.signingKey
|
|
435
|
+
};
|
|
436
|
+
const walletPath = anyLib.restoreFromVss(mappedConfig, targetDir);
|
|
437
|
+
return {
|
|
438
|
+
message: "Wallet restored from VSS successfully",
|
|
439
|
+
walletPath
|
|
440
|
+
};
|
|
441
|
+
};
|
|
276
442
|
var RGBLibClient = class {
|
|
277
443
|
constructor(params) {
|
|
278
444
|
this.online = null;
|
|
@@ -282,21 +448,14 @@ var RGBLibClient = class {
|
|
|
282
448
|
this.originalNetwork = params.network;
|
|
283
449
|
this.network = normalizeNetwork(this.originalNetwork);
|
|
284
450
|
this.dataDir = params.dataDir;
|
|
285
|
-
this.transportEndpoint = params.transportEndpoint ||
|
|
451
|
+
this.transportEndpoint = params.transportEndpoint || DEFAULT_TRANSPORT_ENDPOINTS[this.network] || DEFAULT_TRANSPORT_ENDPOINTS.signet;
|
|
286
452
|
if (params.indexerUrl) {
|
|
287
453
|
this.indexerUrl = params.indexerUrl;
|
|
288
454
|
} else {
|
|
289
|
-
|
|
290
|
-
"mainnet": "ssl://electrum.iriswallet.com:50003",
|
|
291
|
-
"testnet": "ssl://electrum.iriswallet.com:50013",
|
|
292
|
-
"testnet4": "ssl://electrum.iriswallet.com:50053",
|
|
293
|
-
"signet": "tcp://46.224.75.237:50001",
|
|
294
|
-
"regtest": "tcp://regtest.thunderstack.org:50001"
|
|
295
|
-
};
|
|
296
|
-
this.indexerUrl = defaultIndexerUrls[this.network] || defaultIndexerUrls["regtest"];
|
|
455
|
+
this.indexerUrl = DEFAULT_INDEXER_URLS[this.network] || DEFAULT_INDEXER_URLS.signet;
|
|
297
456
|
}
|
|
298
|
-
if (!
|
|
299
|
-
|
|
457
|
+
if (!fs2__namespace.existsSync(this.dataDir)) {
|
|
458
|
+
fs2__namespace.mkdirSync(this.dataDir, { recursive: true });
|
|
300
459
|
}
|
|
301
460
|
const walletData = {
|
|
302
461
|
dataDir: this.dataDir,
|
|
@@ -316,6 +475,7 @@ var RGBLibClient = class {
|
|
|
316
475
|
try {
|
|
317
476
|
this.wallet = new rgblib__default.default.Wallet(new rgblib__default.default.WalletData(walletData));
|
|
318
477
|
} catch (error) {
|
|
478
|
+
console.log("error", error);
|
|
319
479
|
throw new WalletError("Failed to initialize rgb-lib wallet", void 0, error);
|
|
320
480
|
}
|
|
321
481
|
}
|
|
@@ -327,7 +487,6 @@ var RGBLibClient = class {
|
|
|
327
487
|
return;
|
|
328
488
|
}
|
|
329
489
|
try {
|
|
330
|
-
console.log("indexerUrl", this.indexerUrl);
|
|
331
490
|
this.online = this.wallet.goOnline(false, this.indexerUrl);
|
|
332
491
|
} catch (error) {
|
|
333
492
|
throw new WalletError("Failed to establish online connection", void 0, error);
|
|
@@ -377,10 +536,9 @@ var RGBLibClient = class {
|
|
|
377
536
|
}
|
|
378
537
|
sendBegin(params) {
|
|
379
538
|
const online = this.getOnline();
|
|
380
|
-
console.log("sendBegin params", params);
|
|
381
539
|
const feeRate = String(params.feeRate ?? 1);
|
|
382
540
|
const minConfirmations = String(params.minConfirmations ?? 1);
|
|
383
|
-
const donation = false;
|
|
541
|
+
const donation = params.donation ?? false;
|
|
384
542
|
let assetId = params.assetId;
|
|
385
543
|
let amount = params.amount;
|
|
386
544
|
let recipientId;
|
|
@@ -428,6 +586,37 @@ var RGBLibClient = class {
|
|
|
428
586
|
);
|
|
429
587
|
return psbt;
|
|
430
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* Batch send: accepts an already-built recipientMap and calls sendBegin.
|
|
591
|
+
*/
|
|
592
|
+
sendBeginBatch(params) {
|
|
593
|
+
const online = this.getOnline();
|
|
594
|
+
const feeRate = String(params.feeRate ?? 1);
|
|
595
|
+
const minConfirmations = String(params.minConfirmations ?? 1);
|
|
596
|
+
const donation = params.donation ?? true;
|
|
597
|
+
const { recipientMap } = params;
|
|
598
|
+
if (!recipientMap || typeof recipientMap !== "object") {
|
|
599
|
+
throw new ValidationError("recipientMap is required and must be a non-empty object", "recipientMap");
|
|
600
|
+
}
|
|
601
|
+
const assetIds = Object.keys(recipientMap);
|
|
602
|
+
if (assetIds.length === 0) {
|
|
603
|
+
throw new ValidationError("recipientMap must contain at least one asset id", "recipientMap");
|
|
604
|
+
}
|
|
605
|
+
for (const assetId of assetIds) {
|
|
606
|
+
const recipients = recipientMap[assetId];
|
|
607
|
+
if (!Array.isArray(recipients) || recipients.length === 0) {
|
|
608
|
+
throw new ValidationError(`recipientMap["${assetId}"] must be a non-empty array of recipients`, "recipientMap");
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const psbt = this.wallet.sendBegin(
|
|
612
|
+
online,
|
|
613
|
+
recipientMap,
|
|
614
|
+
donation,
|
|
615
|
+
feeRate,
|
|
616
|
+
minConfirmations
|
|
617
|
+
);
|
|
618
|
+
return psbt;
|
|
619
|
+
}
|
|
431
620
|
sendEnd(params) {
|
|
432
621
|
const online = this.getOnline();
|
|
433
622
|
const signedPsbt = params.signedPsbt;
|
|
@@ -531,7 +720,8 @@ var RGBLibClient = class {
|
|
|
531
720
|
const assetId = null;
|
|
532
721
|
const filter = [];
|
|
533
722
|
const skipSync = false;
|
|
534
|
-
this.wallet.refresh(online, assetId, filter, skipSync);
|
|
723
|
+
const result = this.wallet.refresh(online, assetId, filter, skipSync);
|
|
724
|
+
console.log("refresh state:", JSON.stringify(result, null, 2));
|
|
535
725
|
}
|
|
536
726
|
dropWallet() {
|
|
537
727
|
if (this.online) {
|
|
@@ -574,16 +764,105 @@ var RGBLibClient = class {
|
|
|
574
764
|
if (!params.password) {
|
|
575
765
|
throw new ValidationError("password is required", "password");
|
|
576
766
|
}
|
|
577
|
-
if (!
|
|
767
|
+
if (!fs2__namespace.existsSync(params.backupPath)) {
|
|
578
768
|
throw new ValidationError(`Backup directory does not exist: ${params.backupPath}`, "backupPath");
|
|
579
769
|
}
|
|
580
|
-
const fullBackupPath =
|
|
770
|
+
const fullBackupPath = path3__namespace.join(params.backupPath, `${this.masterFingerprint}.backup`);
|
|
581
771
|
this.wallet.backup(fullBackupPath, params.password);
|
|
582
772
|
return {
|
|
583
773
|
message: "Backup created successfully",
|
|
584
774
|
backupPath: fullBackupPath
|
|
585
775
|
};
|
|
586
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* Ensure VSS backup support is available in the underlying rgb-lib bindings.
|
|
779
|
+
* Returns the wallet instance and rgb-lib namespace as `any` for internal use.
|
|
780
|
+
*/
|
|
781
|
+
getVssBindingsOrThrow(methodName) {
|
|
782
|
+
const walletAny = this.wallet;
|
|
783
|
+
const anyLib = rgblib__default.default;
|
|
784
|
+
if (!walletAny || typeof anyLib.VssBackupClient !== "function" || typeof walletAny[methodName] !== "function") {
|
|
785
|
+
throw new WalletError("VSS backup is not available in the current rgb-lib build.");
|
|
786
|
+
}
|
|
787
|
+
return { walletAny, anyLib };
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Configure VSS cloud backup for this wallet.
|
|
791
|
+
*/
|
|
792
|
+
configureVssBackup(config) {
|
|
793
|
+
const walletAny = this.wallet;
|
|
794
|
+
if (!walletAny || typeof walletAny.configureVssBackup !== "function") {
|
|
795
|
+
throw new WalletError("VSS backup is not available in the current rgb-lib build.");
|
|
796
|
+
}
|
|
797
|
+
const mappedConfig = {
|
|
798
|
+
server_url: config.serverUrl,
|
|
799
|
+
store_id: config.storeId,
|
|
800
|
+
signing_key: config.signingKey
|
|
801
|
+
};
|
|
802
|
+
if (config.encryptionEnabled !== void 0) {
|
|
803
|
+
mappedConfig.encryptionEnabled = config.encryptionEnabled;
|
|
804
|
+
}
|
|
805
|
+
if (config.autoBackup !== void 0) {
|
|
806
|
+
mappedConfig.autoBackup = config.autoBackup;
|
|
807
|
+
}
|
|
808
|
+
if (config.backupMode !== void 0) {
|
|
809
|
+
mappedConfig.backupMode = config.backupMode;
|
|
810
|
+
}
|
|
811
|
+
walletAny.configureVssBackup(mappedConfig);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Disable automatic VSS backup for this wallet.
|
|
815
|
+
*/
|
|
816
|
+
disableVssAutoBackup() {
|
|
817
|
+
const walletAny = this.wallet;
|
|
818
|
+
if (!walletAny || typeof walletAny.disableVssAutoBackup !== "function") {
|
|
819
|
+
throw new WalletError("VSS backup is not available in the current rgb-lib build.");
|
|
820
|
+
}
|
|
821
|
+
walletAny.disableVssAutoBackup();
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Trigger a VSS backup immediately using a one-off client created from config.
|
|
825
|
+
* Returns the server version of the stored backup.
|
|
826
|
+
*/
|
|
827
|
+
vssBackup(config) {
|
|
828
|
+
const { walletAny, anyLib } = this.getVssBindingsOrThrow("vssBackup");
|
|
829
|
+
const client = new anyLib.VssBackupClient({
|
|
830
|
+
server_url: config.serverUrl,
|
|
831
|
+
store_id: config.storeId,
|
|
832
|
+
signing_key: config.signingKey
|
|
833
|
+
});
|
|
834
|
+
try {
|
|
835
|
+
const version = walletAny.vssBackup(client);
|
|
836
|
+
return version;
|
|
837
|
+
} finally {
|
|
838
|
+
if (typeof client.drop === "function") {
|
|
839
|
+
client.drop();
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Get VSS backup status information for this wallet using a one-off client.
|
|
845
|
+
*/
|
|
846
|
+
vssBackupInfo(config) {
|
|
847
|
+
const { walletAny, anyLib } = this.getVssBindingsOrThrow("vssBackupInfo");
|
|
848
|
+
const client = new anyLib.VssBackupClient({
|
|
849
|
+
server_url: config.serverUrl,
|
|
850
|
+
store_id: config.storeId,
|
|
851
|
+
signing_key: config.signingKey
|
|
852
|
+
});
|
|
853
|
+
try {
|
|
854
|
+
const info = walletAny.vssBackupInfo(client);
|
|
855
|
+
return {
|
|
856
|
+
backupExists: Boolean(info.backupExists ?? info.backup_exists),
|
|
857
|
+
serverVersion: info.serverVersion ?? info.server_version ?? null,
|
|
858
|
+
backupRequired: Boolean(info.backupRequired ?? info.backup_required)
|
|
859
|
+
};
|
|
860
|
+
} finally {
|
|
861
|
+
if (typeof client.drop === "function") {
|
|
862
|
+
client.drop();
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
587
866
|
/**
|
|
588
867
|
* Cleanup resources
|
|
589
868
|
*/
|
|
@@ -960,8 +1239,8 @@ async function mnemonicToRoot(mnemonic, bitcoinNetwork) {
|
|
|
960
1239
|
}
|
|
961
1240
|
async function getAccountXpub(mnemonic, bitcoinNetwork, rgb) {
|
|
962
1241
|
const root = await mnemonicToRoot(mnemonic, bitcoinNetwork);
|
|
963
|
-
const
|
|
964
|
-
const acct = root.derivePath(
|
|
1242
|
+
const path5 = accountDerivationPath(bitcoinNetwork, rgb);
|
|
1243
|
+
const acct = root.derivePath(path5);
|
|
965
1244
|
return acct.neutered().toBase58();
|
|
966
1245
|
}
|
|
967
1246
|
async function getMasterXpriv(mnemonic, bitcoinNetwork) {
|
|
@@ -1085,6 +1364,27 @@ async function deriveKeysFromSeed(bitcoinNetwork = "regtest", seed) {
|
|
|
1085
1364
|
throw new CryptoError("Failed to derive keys from seed", error);
|
|
1086
1365
|
}
|
|
1087
1366
|
}
|
|
1367
|
+
async function deriveKeysFromMnemonicOrSeed(bitcoinNetwork = "regtest", mnemonicOrSeed) {
|
|
1368
|
+
if (typeof mnemonicOrSeed === "string") {
|
|
1369
|
+
const trimmed = mnemonicOrSeed.trim();
|
|
1370
|
+
const words = trimmed.split(/\s+/);
|
|
1371
|
+
const isLikelyMnemonic = trimmed.includes(" ") && words.length >= 12 && words.length <= 24;
|
|
1372
|
+
if (isLikelyMnemonic) {
|
|
1373
|
+
try {
|
|
1374
|
+
return await deriveKeysFromMnemonic(bitcoinNetwork, trimmed);
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
if (error instanceof ValidationError) {
|
|
1377
|
+
return await deriveKeysFromSeed(bitcoinNetwork, trimmed);
|
|
1378
|
+
}
|
|
1379
|
+
throw error;
|
|
1380
|
+
}
|
|
1381
|
+
} else {
|
|
1382
|
+
return await deriveKeysFromSeed(bitcoinNetwork, trimmed);
|
|
1383
|
+
}
|
|
1384
|
+
} else {
|
|
1385
|
+
return await deriveKeysFromSeed(bitcoinNetwork, mnemonicOrSeed);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1088
1388
|
async function restoreKeys(bitcoinNetwork = "regtest", mnemonic) {
|
|
1089
1389
|
return deriveKeysFromMnemonic(bitcoinNetwork, mnemonic);
|
|
1090
1390
|
}
|
|
@@ -1147,28 +1447,28 @@ async function accountXpubsFromMnemonic(bitcoinNetwork = "regtest", mnemonic) {
|
|
|
1147
1447
|
}
|
|
1148
1448
|
|
|
1149
1449
|
// src/crypto/signer.ts
|
|
1150
|
-
function normalizePath(
|
|
1151
|
-
if (typeof
|
|
1152
|
-
if (
|
|
1153
|
-
return
|
|
1154
|
-
}
|
|
1155
|
-
return
|
|
1156
|
-
} else if (Array.isArray(
|
|
1157
|
-
if (
|
|
1158
|
-
const second =
|
|
1450
|
+
function normalizePath(path5) {
|
|
1451
|
+
if (typeof path5 === "string") {
|
|
1452
|
+
if (path5.startsWith("m/m/")) {
|
|
1453
|
+
return path5.replace(/^m\/m\//, "m/");
|
|
1454
|
+
}
|
|
1455
|
+
return path5;
|
|
1456
|
+
} else if (Array.isArray(path5)) {
|
|
1457
|
+
if (path5.length > 0 && path5[0] === 0 && path5.length > 1) {
|
|
1458
|
+
const second = path5[1];
|
|
1159
1459
|
if (typeof second === "number" && second >= 2147483648) {
|
|
1160
|
-
return
|
|
1460
|
+
return path5.slice(1);
|
|
1161
1461
|
}
|
|
1162
1462
|
}
|
|
1163
|
-
return
|
|
1463
|
+
return path5;
|
|
1164
1464
|
}
|
|
1165
|
-
return
|
|
1465
|
+
return path5;
|
|
1166
1466
|
}
|
|
1167
|
-
function pathToString(
|
|
1168
|
-
if (typeof
|
|
1169
|
-
return
|
|
1170
|
-
} else if (Array.isArray(
|
|
1171
|
-
return
|
|
1467
|
+
function pathToString(path5) {
|
|
1468
|
+
if (typeof path5 === "string") {
|
|
1469
|
+
return path5;
|
|
1470
|
+
} else if (Array.isArray(path5)) {
|
|
1471
|
+
return path5.map((p) => {
|
|
1172
1472
|
if (typeof p === "number") {
|
|
1173
1473
|
return p >= 2147483648 ? `${p & 2147483647}'` : `${p}`;
|
|
1174
1474
|
}
|
|
@@ -1477,6 +1777,14 @@ async function estimatePsbt(psbtBase64) {
|
|
|
1477
1777
|
throw new ValidationError("Invalid PSBT provided", "psbt");
|
|
1478
1778
|
}
|
|
1479
1779
|
}
|
|
1780
|
+
var VSS_SIGNING_KEY_DOMAIN = "rgb-lib-vss-backup-encryption-v1";
|
|
1781
|
+
function deriveVssSigningKeyFromMnemonic(mnemonic) {
|
|
1782
|
+
validateMnemonic(mnemonic, "mnemonic");
|
|
1783
|
+
const keyBytes = new TextEncoder().encode(VSS_SIGNING_KEY_DOMAIN);
|
|
1784
|
+
const messageBytes = new TextEncoder().encode(mnemonic.trim());
|
|
1785
|
+
const digest = hmac_js.hmac(sha2_js.sha256, keyBytes, messageBytes);
|
|
1786
|
+
return Array.from(digest).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1787
|
+
}
|
|
1480
1788
|
var restoreFromBackup = (params) => {
|
|
1481
1789
|
const {
|
|
1482
1790
|
backupFilePath,
|
|
@@ -1520,7 +1828,7 @@ var WalletManager = class {
|
|
|
1520
1828
|
this.mnemonic = params.mnemonic ?? null;
|
|
1521
1829
|
this.xpub = params.xpub ?? null;
|
|
1522
1830
|
this.masterFingerprint = params.masterFingerprint;
|
|
1523
|
-
this.dataDir = params.dataDir ??
|
|
1831
|
+
this.dataDir = params.dataDir ?? path3__namespace.default.join(process.cwd(), ".rgb-wallet", this.network, this.masterFingerprint);
|
|
1524
1832
|
this.client = new RGBLibClient({
|
|
1525
1833
|
xpubVan: params.xpubVan,
|
|
1526
1834
|
xpubCol: params.xpubCol,
|
|
@@ -1531,6 +1839,12 @@ var WalletManager = class {
|
|
|
1531
1839
|
dataDir: params.dataDir ?? this.dataDir
|
|
1532
1840
|
});
|
|
1533
1841
|
}
|
|
1842
|
+
async initialize() {
|
|
1843
|
+
console.log("initializing is not reqire");
|
|
1844
|
+
}
|
|
1845
|
+
async goOnline(indexerUrl, skipConsistencyCheck) {
|
|
1846
|
+
this.client.getOnline();
|
|
1847
|
+
}
|
|
1534
1848
|
/**
|
|
1535
1849
|
* Get wallet's extended public keys
|
|
1536
1850
|
*/
|
|
@@ -1551,7 +1865,7 @@ var WalletManager = class {
|
|
|
1551
1865
|
* Clears mnemonic and seed from memory
|
|
1552
1866
|
* Idempotent - safe to call multiple times
|
|
1553
1867
|
*/
|
|
1554
|
-
dispose() {
|
|
1868
|
+
async dispose() {
|
|
1555
1869
|
if (this.disposed) {
|
|
1556
1870
|
return;
|
|
1557
1871
|
}
|
|
@@ -1583,73 +1897,160 @@ var WalletManager = class {
|
|
|
1583
1897
|
registerWallet() {
|
|
1584
1898
|
return this.client.registerWallet();
|
|
1585
1899
|
}
|
|
1586
|
-
getBtcBalance() {
|
|
1900
|
+
async getBtcBalance() {
|
|
1587
1901
|
return this.client.getBtcBalance();
|
|
1588
1902
|
}
|
|
1589
|
-
getAddress() {
|
|
1903
|
+
async getAddress() {
|
|
1590
1904
|
return this.client.getAddress();
|
|
1591
1905
|
}
|
|
1592
|
-
listUnspents() {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1906
|
+
async listUnspents() {
|
|
1907
|
+
const unspents = this.client.listUnspents();
|
|
1908
|
+
return unspents.map((unspent) => ({
|
|
1909
|
+
utxo: {
|
|
1910
|
+
...unspent.utxo,
|
|
1911
|
+
exists: unspent.utxo.exists ?? true
|
|
1912
|
+
},
|
|
1913
|
+
rgbAllocations: unspent.rgbAllocations.map((allocation) => {
|
|
1914
|
+
const assignmentKeys = Object.keys(allocation.assignment);
|
|
1915
|
+
const assignmentType = assignmentKeys[0];
|
|
1916
|
+
const assignment = {
|
|
1917
|
+
type: assignmentType ?? "Any",
|
|
1918
|
+
amount: assignmentType && allocation.assignment[assignmentType] ? Number(allocation.assignment[assignmentType]) : void 0
|
|
1919
|
+
};
|
|
1920
|
+
return {
|
|
1921
|
+
assetId: allocation.assetId,
|
|
1922
|
+
assignment,
|
|
1923
|
+
settled: allocation.settled
|
|
1924
|
+
};
|
|
1925
|
+
}),
|
|
1926
|
+
pendingBlinded: unspent.pendingBlinded ?? 0
|
|
1927
|
+
}));
|
|
1928
|
+
}
|
|
1929
|
+
async listAssets() {
|
|
1930
|
+
const assets = this.client.listAssets();
|
|
1931
|
+
return assets;
|
|
1932
|
+
}
|
|
1933
|
+
async getAssetBalance(asset_id) {
|
|
1934
|
+
const balance = this.client.getAssetBalance(asset_id);
|
|
1935
|
+
return {
|
|
1936
|
+
settled: balance.settled ?? 0,
|
|
1937
|
+
future: balance.future ?? 0,
|
|
1938
|
+
spendable: balance.spendable ?? 0,
|
|
1939
|
+
offchainOutbound: balance.offchainOutbound ?? 0,
|
|
1940
|
+
offchainInbound: balance.offchainInbound ?? 0
|
|
1941
|
+
};
|
|
1600
1942
|
}
|
|
1601
|
-
createUtxosBegin(params) {
|
|
1943
|
+
async createUtxosBegin(params) {
|
|
1602
1944
|
return this.client.createUtxosBegin(params);
|
|
1603
1945
|
}
|
|
1604
|
-
createUtxosEnd(params) {
|
|
1946
|
+
async createUtxosEnd(params) {
|
|
1605
1947
|
return this.client.createUtxosEnd(params);
|
|
1606
1948
|
}
|
|
1607
|
-
sendBegin(params) {
|
|
1949
|
+
async sendBegin(params) {
|
|
1608
1950
|
return this.client.sendBegin(params);
|
|
1609
1951
|
}
|
|
1610
|
-
|
|
1952
|
+
/**
|
|
1953
|
+
* Batch send begin: accepts already-built recipientMap.
|
|
1954
|
+
* Returns unsigned PSBT (use signPsbt then sendEnd to complete).
|
|
1955
|
+
*/
|
|
1956
|
+
async sendBeginBatch(params) {
|
|
1957
|
+
return this.client.sendBeginBatch(params);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Complete batch send: sendBeginBatch → sign PSBT → sendEnd.
|
|
1961
|
+
*/
|
|
1962
|
+
async sendBatch(params, mnemonic) {
|
|
1963
|
+
this.ensureNotDisposed();
|
|
1964
|
+
const psbt = await this.sendBeginBatch(params);
|
|
1965
|
+
const signedPsbt = await this.signPsbt(psbt, mnemonic);
|
|
1966
|
+
return await this.sendEnd({ signedPsbt });
|
|
1967
|
+
}
|
|
1968
|
+
async sendEnd(params) {
|
|
1611
1969
|
return this.client.sendEnd(params);
|
|
1612
1970
|
}
|
|
1613
|
-
sendBtcBegin(params) {
|
|
1971
|
+
async sendBtcBegin(params) {
|
|
1614
1972
|
return this.client.sendBtcBegin(params);
|
|
1615
1973
|
}
|
|
1616
|
-
sendBtcEnd(params) {
|
|
1974
|
+
async sendBtcEnd(params) {
|
|
1617
1975
|
return this.client.sendBtcEnd(params);
|
|
1618
1976
|
}
|
|
1619
|
-
estimateFeeRate(blocks) {
|
|
1977
|
+
async estimateFeeRate(blocks) {
|
|
1620
1978
|
if (!Number.isFinite(blocks)) {
|
|
1621
1979
|
throw new ValidationError("blocks must be a finite number", "blocks");
|
|
1622
1980
|
}
|
|
1623
1981
|
if (!Number.isInteger(blocks) || blocks <= 0) {
|
|
1624
1982
|
throw new ValidationError("blocks must be a positive integer", "blocks");
|
|
1625
1983
|
}
|
|
1626
|
-
|
|
1984
|
+
const feeEstimation = await this.client.getFeeEstimation({ blocks });
|
|
1985
|
+
return feeEstimation;
|
|
1627
1986
|
}
|
|
1628
1987
|
async estimateFee(psbtBase64) {
|
|
1629
1988
|
return await estimatePsbt(psbtBase64);
|
|
1630
1989
|
}
|
|
1631
1990
|
async sendBtc(params) {
|
|
1632
1991
|
this.ensureNotDisposed();
|
|
1633
|
-
const psbt = this.sendBtcBegin(params);
|
|
1992
|
+
const psbt = await this.sendBtcBegin(params);
|
|
1634
1993
|
const signed = await this.signPsbt(psbt);
|
|
1635
|
-
return this.sendBtcEnd({ signedPsbt: signed });
|
|
1994
|
+
return await this.sendBtcEnd({ signedPsbt: signed });
|
|
1636
1995
|
}
|
|
1637
|
-
blindReceive(params) {
|
|
1638
|
-
|
|
1996
|
+
async blindReceive(params) {
|
|
1997
|
+
const invoice = await this.client.blindReceive({
|
|
1998
|
+
...params,
|
|
1999
|
+
assetId: params.assetId ?? "",
|
|
2000
|
+
amount: params.amount ?? 0
|
|
2001
|
+
});
|
|
2002
|
+
return {
|
|
2003
|
+
invoice: invoice.invoice,
|
|
2004
|
+
recipientId: invoice.recipientId,
|
|
2005
|
+
expirationTimestamp: invoice.expirationTimestamp ?? null,
|
|
2006
|
+
batchTransferIdx: invoice.batchTransferIdx
|
|
2007
|
+
};
|
|
1639
2008
|
}
|
|
1640
|
-
witnessReceive(params) {
|
|
1641
|
-
|
|
2009
|
+
async witnessReceive(params) {
|
|
2010
|
+
const invoice = await this.client.witnessReceive({
|
|
2011
|
+
...params,
|
|
2012
|
+
assetId: params.assetId ?? "",
|
|
2013
|
+
amount: params.amount ?? 0
|
|
2014
|
+
});
|
|
2015
|
+
return {
|
|
2016
|
+
invoice: invoice.invoice,
|
|
2017
|
+
recipientId: invoice.recipientId,
|
|
2018
|
+
expirationTimestamp: invoice.expirationTimestamp ?? null,
|
|
2019
|
+
batchTransferIdx: invoice.batchTransferIdx
|
|
2020
|
+
};
|
|
1642
2021
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
2022
|
+
async decodeRGBInvoice(params) {
|
|
2023
|
+
const invoiceData = await this.client.decodeRGBInvoice(params);
|
|
2024
|
+
const assignmentKeys = Object.keys(invoiceData.assignment);
|
|
2025
|
+
const assignmentType = assignmentKeys[0];
|
|
2026
|
+
const assignment = {
|
|
2027
|
+
type: assignmentType ?? "Any",
|
|
2028
|
+
amount: assignmentType && invoiceData.assignment[assignmentType] ? Number(invoiceData.assignment[assignmentType]) : void 0
|
|
2029
|
+
};
|
|
2030
|
+
return {
|
|
2031
|
+
invoice: params.invoice,
|
|
2032
|
+
recipientId: invoiceData.recipientId,
|
|
2033
|
+
assetSchema: invoiceData.assetSchema,
|
|
2034
|
+
assetId: invoiceData.assetId,
|
|
2035
|
+
network: invoiceData.network,
|
|
2036
|
+
assignment,
|
|
2037
|
+
assignmentName: invoiceData.assignmentName,
|
|
2038
|
+
expirationTimestamp: invoiceData.expirationTimestamp ?? null,
|
|
2039
|
+
transportEndpoints: invoiceData.transportEndpoints
|
|
2040
|
+
};
|
|
1645
2041
|
}
|
|
1646
|
-
|
|
1647
|
-
|
|
2042
|
+
async issueAssetNia(params) {
|
|
2043
|
+
const asset = await this.client.issueAssetNia(params);
|
|
2044
|
+
return asset;
|
|
1648
2045
|
}
|
|
1649
|
-
|
|
2046
|
+
async issueAssetIfa(params) {
|
|
2047
|
+
const asset = await this.client.issueAssetIfa(params);
|
|
2048
|
+
return asset;
|
|
2049
|
+
}
|
|
2050
|
+
async inflateBegin(params) {
|
|
1650
2051
|
return this.client.inflateBegin(params);
|
|
1651
2052
|
}
|
|
1652
|
-
inflateEnd(params) {
|
|
2053
|
+
async inflateEnd(params) {
|
|
1653
2054
|
return this.client.inflateEnd(params);
|
|
1654
2055
|
}
|
|
1655
2056
|
/**
|
|
@@ -1665,24 +2066,51 @@ var WalletManager = class {
|
|
|
1665
2066
|
signedPsbt
|
|
1666
2067
|
});
|
|
1667
2068
|
}
|
|
1668
|
-
refreshWallet() {
|
|
2069
|
+
async refreshWallet() {
|
|
1669
2070
|
this.client.refreshWallet();
|
|
1670
2071
|
}
|
|
1671
|
-
listTransactions() {
|
|
1672
|
-
|
|
2072
|
+
async listTransactions() {
|
|
2073
|
+
const transactions = this.client.listTransactions();
|
|
2074
|
+
return transactions;
|
|
1673
2075
|
}
|
|
1674
|
-
listTransfers(asset_id) {
|
|
1675
|
-
|
|
2076
|
+
async listTransfers(asset_id) {
|
|
2077
|
+
const transfers = this.client.listTransfers(asset_id);
|
|
2078
|
+
return transfers;
|
|
1676
2079
|
}
|
|
1677
|
-
failTransfers(params) {
|
|
2080
|
+
async failTransfers(params) {
|
|
1678
2081
|
return this.client.failTransfers(params);
|
|
1679
2082
|
}
|
|
1680
|
-
|
|
1681
|
-
return this.client.decodeRGBInvoice(params);
|
|
1682
|
-
}
|
|
1683
|
-
createBackup(params) {
|
|
2083
|
+
async createBackup(params) {
|
|
1684
2084
|
return this.client.createBackup(params);
|
|
1685
2085
|
}
|
|
2086
|
+
/**
|
|
2087
|
+
* Configure VSS cloud backup for this wallet.
|
|
2088
|
+
*/
|
|
2089
|
+
async configureVssBackup(config) {
|
|
2090
|
+
this.ensureNotDisposed();
|
|
2091
|
+
this.client.configureVssBackup(config);
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Disable automatic VSS backup.
|
|
2095
|
+
*/
|
|
2096
|
+
async disableVssAutoBackup() {
|
|
2097
|
+
this.ensureNotDisposed();
|
|
2098
|
+
this.client.disableVssAutoBackup();
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Trigger a VSS backup immediately and return the server version.
|
|
2102
|
+
*/
|
|
2103
|
+
async vssBackup(config) {
|
|
2104
|
+
this.ensureNotDisposed();
|
|
2105
|
+
return this.client.vssBackup(config);
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Get VSS backup info for this wallet.
|
|
2109
|
+
*/
|
|
2110
|
+
async vssBackupInfo(config) {
|
|
2111
|
+
this.ensureNotDisposed();
|
|
2112
|
+
return this.client.vssBackupInfo(config);
|
|
2113
|
+
}
|
|
1686
2114
|
/**
|
|
1687
2115
|
* Sign a PSBT using the wallet's mnemonic or a provided mnemonic
|
|
1688
2116
|
* @param psbt - Base64 encoded PSBT
|
|
@@ -1708,16 +2136,15 @@ var WalletManager = class {
|
|
|
1708
2136
|
this.ensureNotDisposed();
|
|
1709
2137
|
const psbt = await this.sendBegin(invoiceTransfer);
|
|
1710
2138
|
const signedPsbt = await this.signPsbt(psbt, mnemonic);
|
|
1711
|
-
console.log("send signedPsbt", signedPsbt);
|
|
1712
2139
|
return await this.sendEnd({ signedPsbt });
|
|
1713
2140
|
}
|
|
1714
2141
|
async createUtxos({ upTo, num, size, feeRate }) {
|
|
1715
2142
|
this.ensureNotDisposed();
|
|
1716
|
-
const psbt = this.createUtxosBegin({ upTo, num, size, feeRate });
|
|
2143
|
+
const psbt = await this.createUtxosBegin({ upTo, num, size, feeRate });
|
|
1717
2144
|
const signedPsbt = await this.signPsbt(psbt);
|
|
1718
2145
|
return this.createUtxosEnd({ signedPsbt });
|
|
1719
2146
|
}
|
|
1720
|
-
syncWallet() {
|
|
2147
|
+
async syncWallet() {
|
|
1721
2148
|
this.client.syncWallet();
|
|
1722
2149
|
}
|
|
1723
2150
|
async signMessage(message) {
|
|
@@ -1762,33 +2189,1081 @@ var wallet = new Proxy({}, {
|
|
|
1762
2189
|
}
|
|
1763
2190
|
});
|
|
1764
2191
|
|
|
1765
|
-
// src/
|
|
1766
|
-
var
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
}
|
|
2192
|
+
// src/utexo/utexo-protocol.ts
|
|
2193
|
+
var LightningProtocol = class {
|
|
2194
|
+
async createLightningInvoice(params) {
|
|
2195
|
+
throw new Error("createLightningInvoice not implemented");
|
|
2196
|
+
}
|
|
2197
|
+
async getLightningReceiveRequest(id) {
|
|
2198
|
+
throw new Error("getLightningReceiveRequest not implemented");
|
|
2199
|
+
}
|
|
2200
|
+
async getLightningSendRequest(id) {
|
|
2201
|
+
throw new Error("getLightningSendRequest not implemented");
|
|
2202
|
+
}
|
|
2203
|
+
async getLightningSendFeeEstimate(params) {
|
|
2204
|
+
throw new Error("getLightningSendFeeEstimate not implemented");
|
|
2205
|
+
}
|
|
2206
|
+
async payLightningInvoiceBegin(params) {
|
|
2207
|
+
throw new Error("payLightningInvoiceBegin not implemented");
|
|
2208
|
+
}
|
|
2209
|
+
async payLightningInvoiceEnd(params) {
|
|
2210
|
+
throw new Error("payLightningInvoiceEnd not implemented");
|
|
2211
|
+
}
|
|
2212
|
+
async payLightningInvoice(params, mnemonic) {
|
|
2213
|
+
throw new Error("payLightningInvoice not implemented");
|
|
2214
|
+
}
|
|
2215
|
+
async listLightningPayments() {
|
|
2216
|
+
throw new Error("listLightningPayments not implemented");
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
var OnchainProtocol = class {
|
|
2220
|
+
async onchainReceive(params) {
|
|
2221
|
+
throw new Error("onchainReceive not implemented");
|
|
2222
|
+
}
|
|
2223
|
+
async onchainSendBegin(params) {
|
|
2224
|
+
throw new Error("onchainSendBegin not implemented");
|
|
2225
|
+
}
|
|
2226
|
+
async onchainSendEnd(params) {
|
|
2227
|
+
throw new Error("onchainSendEnd not implemented");
|
|
2228
|
+
}
|
|
2229
|
+
async onchainSend(params, mnemonic) {
|
|
2230
|
+
throw new Error("onchainSend not implemented");
|
|
2231
|
+
}
|
|
2232
|
+
async getOnchainSendStatus(send_id) {
|
|
2233
|
+
throw new Error("getOnchainSendStatus not implemented");
|
|
2234
|
+
}
|
|
2235
|
+
async listOnchainTransfers(asset_id) {
|
|
2236
|
+
throw new Error("listOnchainTransfers not implemented");
|
|
2237
|
+
}
|
|
2238
|
+
};
|
|
2239
|
+
var UTEXOProtocol = class extends LightningProtocol {
|
|
2240
|
+
constructor() {
|
|
2241
|
+
super(...arguments);
|
|
2242
|
+
this.onchainProtocol = new OnchainProtocol();
|
|
2243
|
+
}
|
|
2244
|
+
async onchainReceive(params) {
|
|
2245
|
+
return this.onchainProtocol.onchainReceive(params);
|
|
2246
|
+
}
|
|
2247
|
+
async onchainSendBegin(params) {
|
|
2248
|
+
return this.onchainProtocol.onchainSendBegin(params);
|
|
2249
|
+
}
|
|
2250
|
+
async onchainSendEnd(params) {
|
|
2251
|
+
return this.onchainProtocol.onchainSendEnd(params);
|
|
2252
|
+
}
|
|
2253
|
+
async onchainSend(params, mnemonic) {
|
|
2254
|
+
return this.onchainProtocol.onchainSend(params, mnemonic);
|
|
2255
|
+
}
|
|
2256
|
+
async getOnchainSendStatus(send_id) {
|
|
2257
|
+
return this.onchainProtocol.getOnchainSendStatus(send_id);
|
|
2258
|
+
}
|
|
2259
|
+
async listOnchainTransfers(asset_id) {
|
|
2260
|
+
return this.onchainProtocol.listOnchainTransfers(asset_id);
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
|
|
2264
|
+
// src/utexo/config/gateway.ts
|
|
2265
|
+
var DEFAULT_GATEWAY_BASE_URLS = {
|
|
2266
|
+
mainnet: "https://gateway.utexo.tricorn.network/",
|
|
2267
|
+
testnet: "https://dev.gateway.utexo.tricorn.network/"
|
|
2268
|
+
};
|
|
2269
|
+
|
|
2270
|
+
// src/utexo/bridge/types.ts
|
|
2271
|
+
var TransferStatuses = /* @__PURE__ */ ((TransferStatuses2) => {
|
|
2272
|
+
TransferStatuses2[TransferStatuses2["Unspecified"] = 0] = "Unspecified";
|
|
2273
|
+
TransferStatuses2[TransferStatuses2["Confirming"] = 1] = "Confirming";
|
|
2274
|
+
TransferStatuses2[TransferStatuses2["Canceled"] = 2] = "Canceled";
|
|
2275
|
+
TransferStatuses2[TransferStatuses2["Finished"] = 3] = "Finished";
|
|
2276
|
+
TransferStatuses2[TransferStatuses2["Waiting"] = 4] = "Waiting";
|
|
2277
|
+
TransferStatuses2[TransferStatuses2["Cancelling"] = 5] = "Cancelling";
|
|
2278
|
+
TransferStatuses2[TransferStatuses2["Failed"] = 6] = "Failed";
|
|
2279
|
+
TransferStatuses2[TransferStatuses2["Fetching"] = 7] = "Fetching";
|
|
2280
|
+
return TransferStatuses2;
|
|
2281
|
+
})(TransferStatuses || {});
|
|
2282
|
+
|
|
2283
|
+
// src/utexo/bridge/api.ts
|
|
2284
|
+
var encodeTransferStatus = (transferStatus) => {
|
|
2285
|
+
const textEncoder = new TextEncoder();
|
|
2286
|
+
return textEncoder.encode(transferStatus.toString())[0];
|
|
2287
|
+
};
|
|
2288
|
+
var UtexoBridgeApiClient = class {
|
|
2289
|
+
/**
|
|
2290
|
+
* Creates a new UtexoBridgeApiClient instance
|
|
2291
|
+
*
|
|
2292
|
+
* @param axiosInstance - Axios instance to use for HTTP requests (required)
|
|
2293
|
+
* @param basePath - Base path for API endpoints (defaults to '/v1/utexo/bridge')
|
|
2294
|
+
*
|
|
2295
|
+
* @example
|
|
2296
|
+
* ```typescript
|
|
2297
|
+
* import axios from 'axios';
|
|
2298
|
+
* import { UtexoBridgeApiClient } from './utexoBridge';
|
|
2299
|
+
*
|
|
2300
|
+
* const axiosInstance = axios.create({
|
|
2301
|
+
* baseURL: 'https://api.example.com'
|
|
2302
|
+
* });
|
|
2303
|
+
*
|
|
2304
|
+
* const client = new UtexoBridgeApiClient(axiosInstance);
|
|
2305
|
+
* ```
|
|
2306
|
+
*/
|
|
2307
|
+
constructor(axiosInstance, basePath = "/v1/utexo/bridge") {
|
|
2308
|
+
this.axios = axiosInstance;
|
|
2309
|
+
this.basePath = basePath;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Gets bridge-in signature for a transfer
|
|
2313
|
+
*
|
|
2314
|
+
* @param request - Bridge-in signature request data
|
|
2315
|
+
* @returns Promise resolving to bridge-in signature response
|
|
2316
|
+
* @throws {ApiError} If the request fails
|
|
2317
|
+
*/
|
|
2318
|
+
async getBridgeInSignature(request) {
|
|
2319
|
+
try {
|
|
2320
|
+
const { data } = await this.axios.post(
|
|
2321
|
+
`${this.basePath}/bridge-in-signature`,
|
|
2322
|
+
request
|
|
2323
|
+
);
|
|
2324
|
+
return data;
|
|
2325
|
+
} catch (error) {
|
|
2326
|
+
const responseData = error.response?.data;
|
|
2327
|
+
if (responseData !== void 0) {
|
|
2328
|
+
const message = typeof responseData === "string" ? responseData : JSON.stringify(responseData);
|
|
2329
|
+
throw new Error(message);
|
|
2330
|
+
}
|
|
2331
|
+
throw error;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
/**
|
|
2335
|
+
* Submits a signed transaction to the blockchain
|
|
2336
|
+
*
|
|
2337
|
+
* @param request - Submit transaction request data
|
|
2338
|
+
* @returns Promise resolving to transaction hash
|
|
2339
|
+
* @throws {ApiError} If the request fails
|
|
2340
|
+
*/
|
|
2341
|
+
async submitTransaction(request) {
|
|
2342
|
+
const { data } = await this.axios.post(
|
|
2343
|
+
`${this.basePath}/submit-transaction`,
|
|
2344
|
+
request
|
|
2345
|
+
);
|
|
2346
|
+
return data.txHash;
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* Verifies a bridge-in transaction after it has been sent
|
|
2350
|
+
*
|
|
2351
|
+
* @param request - Verify bridge-in request data
|
|
2352
|
+
* @returns Promise that resolves when verification is complete
|
|
2353
|
+
* @throws {ApiError} If the request fails
|
|
2354
|
+
*/
|
|
2355
|
+
async verifyBridgeIn(request) {
|
|
2356
|
+
await this.axios.post(`${this.basePath}/verify-bridge-in`, request);
|
|
2357
|
+
}
|
|
2358
|
+
/**
|
|
2359
|
+
* Gets receiver invoice by transfer ID and network ID
|
|
2360
|
+
*
|
|
2361
|
+
* @param transferId - Transfer ID
|
|
2362
|
+
* @param networkId - Network ID
|
|
2363
|
+
* @returns Promise resolving to invoice string
|
|
2364
|
+
* @throws {ApiError} If the request fails
|
|
2365
|
+
*/
|
|
2366
|
+
async getReceiverInvoice(transferId, networkId) {
|
|
2367
|
+
const { data } = await this.axios.get(
|
|
2368
|
+
`${this.basePath}/receiver-invoice/${transferId}/${networkId}`
|
|
2369
|
+
);
|
|
2370
|
+
return data.invoice;
|
|
2371
|
+
}
|
|
2372
|
+
async getWithdrawTransfer(invoice, networkId) {
|
|
2373
|
+
const { data } = await this.axios.get(
|
|
2374
|
+
`${this.basePath}/transfers/history`,
|
|
2375
|
+
{
|
|
2376
|
+
params: {
|
|
2377
|
+
"network_id": String(networkId),
|
|
2378
|
+
"offset": String(0),
|
|
2379
|
+
"limit": String(10),
|
|
2380
|
+
"address": "rgb-address"
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
);
|
|
2384
|
+
if (data.transfers.length === 0) {
|
|
2385
|
+
return null;
|
|
2386
|
+
}
|
|
2387
|
+
const withdrawTransfer = data.transfers.map((transfer) => ({ ...transfer, status: TransferStatuses[encodeTransferStatus(transfer.status)] })).find((transfer) => transfer.recipient.address === invoice);
|
|
2388
|
+
if (!withdrawTransfer) {
|
|
2389
|
+
return null;
|
|
2390
|
+
}
|
|
2391
|
+
return withdrawTransfer;
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Gets transfer information by mainnet invoice
|
|
2395
|
+
*
|
|
2396
|
+
* @param mainnetInvoice - Mainnet invoice string
|
|
2397
|
+
* @param networkId - Network ID
|
|
2398
|
+
* @returns Promise resolving to transfer information
|
|
2399
|
+
* @throws {ApiError} If the request fails
|
|
2400
|
+
*/
|
|
2401
|
+
async getTransferByMainnetInvoice(mainnetInvoice, networkId) {
|
|
2402
|
+
try {
|
|
2403
|
+
const { data } = await this.axios.get(
|
|
2404
|
+
`${this.basePath}/transfer-by-mainnet-invoice`,
|
|
2405
|
+
{
|
|
2406
|
+
params: {
|
|
2407
|
+
mainnet_invoice: mainnetInvoice,
|
|
2408
|
+
network_id: networkId
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
);
|
|
2412
|
+
if (data) {
|
|
2413
|
+
return { ...data, status: TransferStatuses[encodeTransferStatus(data.status)] };
|
|
2414
|
+
}
|
|
2415
|
+
return data;
|
|
2416
|
+
} catch (error) {
|
|
2417
|
+
console.log("Mainnet invoice not found");
|
|
2418
|
+
return null;
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
};
|
|
2422
|
+
function getBridgeAPI(network = "mainnet") {
|
|
2423
|
+
const axiosInstance = axios__default.default.create({
|
|
2424
|
+
baseURL: DEFAULT_GATEWAY_BASE_URLS[network]
|
|
2425
|
+
});
|
|
2426
|
+
return new UtexoBridgeApiClient(axiosInstance);
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/utexo/utils/helpers.ts
|
|
2430
|
+
var UTXO_PATH_INDEX = 2;
|
|
2431
|
+
function toUnitsNumber(value, precision) {
|
|
2432
|
+
const s = String(value).trim();
|
|
2433
|
+
const neg = s.startsWith("-");
|
|
2434
|
+
const [iRaw, fRaw = ""] = (neg ? s.slice(1) : s).split(".");
|
|
2435
|
+
const frac = (fRaw + "0".repeat(precision)).slice(0, precision);
|
|
2436
|
+
const unitsStr = (iRaw || "0") + frac;
|
|
2437
|
+
const units = Number(unitsStr);
|
|
2438
|
+
if (!Number.isSafeInteger(units)) {
|
|
2439
|
+
throw new Error(
|
|
2440
|
+
`Amount exceeds MAX_SAFE_INTEGER. Use BigInt instead. got=${unitsStr}`
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
return neg ? -units : units;
|
|
2444
|
+
}
|
|
2445
|
+
function fromUnitsNumber(units, precision) {
|
|
2446
|
+
const neg = units < 0;
|
|
2447
|
+
const base = 10 ** precision;
|
|
2448
|
+
const value = Math.abs(units) / base;
|
|
2449
|
+
return neg ? -value : value;
|
|
2450
|
+
}
|
|
2451
|
+
function decodeBridgeInvoice(hexInvoice) {
|
|
2452
|
+
const hex = hexInvoice.startsWith("0x") ? hexInvoice.slice(UTXO_PATH_INDEX) : hexInvoice;
|
|
2453
|
+
return Buffer.from(hex, "hex").toString("utf-8");
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
// src/utexo/config/vss.ts
|
|
2457
|
+
var DEFAULT_VSS_SERVER_URL = "https://vss-server.utexo.com/vss";
|
|
2458
|
+
function getVssConfigs(config) {
|
|
2459
|
+
const base = { ...config };
|
|
2460
|
+
return {
|
|
2461
|
+
layer1: { ...base, storeId: `${config.storeId}_layer1` },
|
|
2462
|
+
utexo: { ...base, storeId: `${config.storeId}_utexo` }
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
var BACKUP_FILE_SUFFIX = ".backup";
|
|
2466
|
+
var LAYER1_BACKUP_SUFFIX = "_layer1.backup";
|
|
2467
|
+
var UTEXO_BACKUP_SUFFIX = "_utexo.backup";
|
|
2468
|
+
var UTEXO_BACKUP_TMP_LAYER1 = ".layer1";
|
|
2469
|
+
var UTEXO_BACKUP_TMP_UTEXO = ".utexo";
|
|
2470
|
+
function getBackupStoreId(masterFingerprint) {
|
|
2471
|
+
return `wallet_${masterFingerprint}`;
|
|
2472
|
+
}
|
|
2473
|
+
function prepareUtxoBackupDirs(backupPath, masterFingerprint) {
|
|
2474
|
+
const storeId = getBackupStoreId(masterFingerprint);
|
|
2475
|
+
if (!fs2__namespace.default.existsSync(backupPath)) {
|
|
2476
|
+
fs2__namespace.default.mkdirSync(backupPath, { recursive: true });
|
|
2477
|
+
}
|
|
2478
|
+
const layer1TmpDir = path3__namespace.default.join(backupPath, UTEXO_BACKUP_TMP_LAYER1);
|
|
2479
|
+
const utexoTmpDir = path3__namespace.default.join(backupPath, UTEXO_BACKUP_TMP_UTEXO);
|
|
2480
|
+
fs2__namespace.default.mkdirSync(layer1TmpDir, { recursive: true });
|
|
2481
|
+
fs2__namespace.default.mkdirSync(utexoTmpDir, { recursive: true });
|
|
2482
|
+
return {
|
|
2483
|
+
storeId,
|
|
2484
|
+
layer1TmpDir,
|
|
2485
|
+
utexoTmpDir,
|
|
2486
|
+
layer1FinalPath: path3__namespace.default.join(backupPath, `${storeId}_layer1${BACKUP_FILE_SUFFIX}`),
|
|
2487
|
+
utexoFinalPath: path3__namespace.default.join(backupPath, `${storeId}_utexo${BACKUP_FILE_SUFFIX}`)
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
function finalizeUtxoBackupPaths(params) {
|
|
2491
|
+
const { layer1BackupPath, utexoBackupPath, layer1FinalPath, utexoFinalPath, layer1TmpDir, utexoTmpDir } = params;
|
|
2492
|
+
fs2__namespace.default.renameSync(layer1BackupPath, layer1FinalPath);
|
|
2493
|
+
fs2__namespace.default.renameSync(utexoBackupPath, utexoFinalPath);
|
|
2494
|
+
fs2__namespace.default.rmdirSync(layer1TmpDir);
|
|
2495
|
+
fs2__namespace.default.rmdirSync(utexoTmpDir);
|
|
2496
|
+
}
|
|
2497
|
+
async function buildVssConfigFromMnemonic(mnemonic, serverUrl, networkPreset = "testnet") {
|
|
2498
|
+
const keys = await deriveKeysFromMnemonic(networkPreset, mnemonic.trim());
|
|
2499
|
+
return {
|
|
2500
|
+
serverUrl,
|
|
2501
|
+
storeId: `wallet_${keys.masterFingerprint}`,
|
|
2502
|
+
signingKey: deriveVssSigningKeyFromMnemonic(mnemonic.trim()),
|
|
2503
|
+
backupMode: "Blocking"
|
|
2504
|
+
};
|
|
2505
|
+
}
|
|
2506
|
+
async function restoreUtxoWalletFromVss(params) {
|
|
2507
|
+
const { mnemonic, targetDir, config: providedConfig, networkPreset = "testnet", vssServerUrl } = params;
|
|
2508
|
+
if (!mnemonic || !mnemonic.trim()) {
|
|
2509
|
+
throw new ValidationError("mnemonic is required", "mnemonic");
|
|
2510
|
+
}
|
|
2511
|
+
if (!targetDir) {
|
|
2512
|
+
throw new ValidationError("targetDir is required", "targetDir");
|
|
2513
|
+
}
|
|
2514
|
+
const serverUrl = vssServerUrl ?? DEFAULT_VSS_SERVER_URL;
|
|
2515
|
+
const config = providedConfig ?? await buildVssConfigFromMnemonic(mnemonic.trim(), serverUrl, networkPreset);
|
|
2516
|
+
const presetConfig = getUtxoNetworkConfig(networkPreset);
|
|
2517
|
+
const layer1Network = String(presetConfig.networkMap.mainnet);
|
|
2518
|
+
const utexoNetwork = String(presetConfig.networkMap.utexo);
|
|
2519
|
+
const masterFingerprint = config.storeId.replace(/^wallet_/, "") || config.storeId;
|
|
2520
|
+
const layer1Config = { ...config, storeId: `${config.storeId}_layer1` };
|
|
2521
|
+
const utexoConfig = { ...config, storeId: `${config.storeId}_utexo` };
|
|
2522
|
+
const { walletPath: layer1Path } = restoreFromVss({
|
|
2523
|
+
config: layer1Config,
|
|
2524
|
+
targetDir: path3__namespace.default.join(targetDir, layer1Network, masterFingerprint)
|
|
2525
|
+
});
|
|
2526
|
+
const { walletPath: utexoPath } = restoreFromVss({
|
|
2527
|
+
config: utexoConfig,
|
|
2528
|
+
targetDir: path3__namespace.default.join(targetDir, utexoNetwork, masterFingerprint)
|
|
2529
|
+
});
|
|
2530
|
+
return { layer1Path, utexoPath, targetDir };
|
|
2531
|
+
}
|
|
2532
|
+
function restoreUtxoWalletFromBackup(params) {
|
|
2533
|
+
const { backupPath, password, targetDir, networkPreset = "testnet" } = params;
|
|
2534
|
+
if (!backupPath || !password || !targetDir) {
|
|
2535
|
+
throw new ValidationError("backupPath, password, and targetDir are required", "restoreUtxoWalletFromBackup");
|
|
2536
|
+
}
|
|
2537
|
+
if (!fs2__namespace.default.existsSync(backupPath) || !fs2__namespace.default.statSync(backupPath).isDirectory()) {
|
|
2538
|
+
throw new ValidationError("backupPath must be an existing directory", "backupPath");
|
|
2539
|
+
}
|
|
2540
|
+
const files = fs2__namespace.default.readdirSync(backupPath);
|
|
2541
|
+
const layer1File = files.find((f) => f.endsWith(LAYER1_BACKUP_SUFFIX));
|
|
2542
|
+
const utexoFile = files.find((f) => f.endsWith(UTEXO_BACKUP_SUFFIX));
|
|
2543
|
+
if (!layer1File || !utexoFile) {
|
|
2544
|
+
throw new ValidationError(
|
|
2545
|
+
`backupPath must contain wallet_<fp>_layer1.backup and wallet_<fp>_utexo.backup (from createBackup)`,
|
|
2546
|
+
"backupPath"
|
|
2547
|
+
);
|
|
2548
|
+
}
|
|
2549
|
+
const masterFingerprint = layer1File.slice(0, -LAYER1_BACKUP_SUFFIX.length).replace(/^wallet_/, "");
|
|
2550
|
+
const expectedUtexoFile = `wallet_${masterFingerprint}${UTEXO_BACKUP_SUFFIX}`;
|
|
2551
|
+
if (utexoFile !== expectedUtexoFile) {
|
|
2552
|
+
throw new ValidationError(
|
|
2553
|
+
`Layer1 and utexo backup filenames must share the same wallet id (expected ${expectedUtexoFile})`,
|
|
2554
|
+
"backupPath"
|
|
2555
|
+
);
|
|
2556
|
+
}
|
|
2557
|
+
const layer1BackupFile = path3__namespace.default.join(backupPath, layer1File);
|
|
2558
|
+
const utexoBackupFile = path3__namespace.default.join(backupPath, utexoFile);
|
|
2559
|
+
if (!fs2__namespace.default.existsSync(layer1BackupFile) || !fs2__namespace.default.existsSync(utexoBackupFile)) {
|
|
2560
|
+
throw new ValidationError("Backup files not found", "backupPath");
|
|
2561
|
+
}
|
|
2562
|
+
const presetConfig = getUtxoNetworkConfig(networkPreset);
|
|
2563
|
+
const layer1Network = String(presetConfig.networkMap.mainnet);
|
|
2564
|
+
const utexoNetwork = String(presetConfig.networkMap.utexo);
|
|
2565
|
+
const layer1DataDir = path3__namespace.default.join(targetDir, layer1Network, masterFingerprint);
|
|
2566
|
+
const utexoDataDir = path3__namespace.default.join(targetDir, utexoNetwork, masterFingerprint);
|
|
2567
|
+
for (const dir of [layer1DataDir, utexoDataDir]) {
|
|
2568
|
+
if (!fs2__namespace.default.existsSync(path3__namespace.default.dirname(dir))) {
|
|
2569
|
+
fs2__namespace.default.mkdirSync(path3__namespace.default.dirname(dir), { recursive: true });
|
|
2570
|
+
}
|
|
2571
|
+
if (!fs2__namespace.default.existsSync(dir)) {
|
|
2572
|
+
fs2__namespace.default.mkdirSync(dir, { recursive: true });
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
restoreWallet({ backupFilePath: layer1BackupFile, password, dataDir: layer1DataDir });
|
|
2576
|
+
restoreWallet({ backupFilePath: utexoBackupFile, password, dataDir: utexoDataDir });
|
|
2577
|
+
return {
|
|
2578
|
+
layer1Path: layer1DataDir,
|
|
2579
|
+
utexoPath: utexoDataDir,
|
|
2580
|
+
targetDir
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
// src/utexo/utexo-wallet.ts
|
|
2585
|
+
var UTEXOWallet = class extends UTEXOProtocol {
|
|
2586
|
+
/**
|
|
2587
|
+
* Creates a new UTEXOWallet instance
|
|
2588
|
+
* @param mnemonicOrSeed - Either a mnemonic phrase (string) or seed (Uint8Array)
|
|
2589
|
+
* @param options - Optional configuration options (defaults to { network: 'mainnet' })
|
|
2590
|
+
*/
|
|
2591
|
+
constructor(mnemonicOrSeed, options = {}) {
|
|
2592
|
+
super();
|
|
2593
|
+
this.layer1Keys = null;
|
|
2594
|
+
this.utexoKeys = null;
|
|
2595
|
+
this.layer1RGBWallet = null;
|
|
2596
|
+
this.utexoRGBWallet = null;
|
|
2597
|
+
this.mnemonicOrSeed = mnemonicOrSeed;
|
|
2598
|
+
this.options = options;
|
|
2599
|
+
const preset = options.network ?? "testnet";
|
|
2600
|
+
const networkConfig = getUtxoNetworkConfig(preset);
|
|
2601
|
+
this.networkMap = networkConfig.networkMap;
|
|
2602
|
+
this.networkIdMap = networkConfig.networkIdMap;
|
|
2603
|
+
this.bridge = getBridgeAPI(preset);
|
|
2604
|
+
}
|
|
2605
|
+
async initialize() {
|
|
2606
|
+
this.layer1Keys = await this.derivePublicKeys(this.networkMap.mainnet);
|
|
2607
|
+
this.utexoKeys = await this.derivePublicKeys(this.networkMap.utexo);
|
|
2608
|
+
const fp = this.utexoKeys.masterFingerprint;
|
|
2609
|
+
const dataDir = this.options.dataDir;
|
|
2610
|
+
this.utexoRGBWallet = new WalletManager({
|
|
2611
|
+
xpubVan: this.utexoKeys.accountXpubVanilla,
|
|
2612
|
+
xpubCol: this.utexoKeys.accountXpubColored,
|
|
2613
|
+
masterFingerprint: this.utexoKeys.masterFingerprint,
|
|
2614
|
+
network: this.networkMap.utexo,
|
|
2615
|
+
mnemonic: this.mnemonicOrSeed,
|
|
2616
|
+
dataDir: dataDir ? path3__namespace.default.join(dataDir, String(this.networkMap.utexo), fp) : void 0
|
|
2617
|
+
});
|
|
2618
|
+
this.layer1RGBWallet = new WalletManager({
|
|
2619
|
+
xpubVan: this.layer1Keys.accountXpubVanilla,
|
|
2620
|
+
xpubCol: this.layer1Keys.accountXpubVanilla,
|
|
2621
|
+
masterFingerprint: this.layer1Keys.masterFingerprint,
|
|
2622
|
+
network: this.networkMap.mainnet,
|
|
2623
|
+
mnemonic: this.mnemonicOrSeed,
|
|
2624
|
+
dataDir: dataDir ? path3__namespace.default.join(dataDir, String(this.networkMap.mainnet), fp) : void 0
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Derive public keys from mnemonic or seed
|
|
2629
|
+
* @param network - BitcoinNetwork identifier
|
|
2630
|
+
* @returns Promise resolving to PublicKeys containing xpub, accountXpubVanilla, accountXpubColored, and masterFingerprint
|
|
2631
|
+
* @throws {ValidationError} If mnemonic is invalid
|
|
2632
|
+
*/
|
|
2633
|
+
async derivePublicKeys(network) {
|
|
2634
|
+
const generatedKeys = await deriveKeysFromMnemonicOrSeed(network, this.mnemonicOrSeed);
|
|
2635
|
+
const { xpub, accountXpubVanilla, accountXpubColored, masterFingerprint } = generatedKeys;
|
|
2636
|
+
return { xpub, accountXpubVanilla, accountXpubColored, masterFingerprint };
|
|
2637
|
+
}
|
|
2638
|
+
async getPubKeys() {
|
|
2639
|
+
if (!this.layer1Keys) {
|
|
2640
|
+
throw new ValidationError("Public keys are not set", "publicKeys");
|
|
2641
|
+
}
|
|
2642
|
+
return this.layer1Keys;
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* Guard method to ensure wallet is initialized
|
|
2646
|
+
* @throws {WalletError} if wallet is not initialized
|
|
2647
|
+
*/
|
|
2648
|
+
ensureInitialized() {
|
|
2649
|
+
if (!this.utexoRGBWallet) {
|
|
2650
|
+
throw new WalletError("Wallet not initialized. Call initialize() first.");
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
// ==========================================
|
|
2654
|
+
// IWalletManager Implementation
|
|
2655
|
+
// ==========================================
|
|
2656
|
+
async goOnline(indexerUrl, skipConsistencyCheck) {
|
|
2657
|
+
this.ensureInitialized();
|
|
2658
|
+
throw new Error("goOnline not implemented");
|
|
2659
|
+
}
|
|
2660
|
+
getXpub() {
|
|
2661
|
+
this.ensureInitialized();
|
|
2662
|
+
return this.utexoRGBWallet.getXpub();
|
|
2663
|
+
}
|
|
2664
|
+
getNetwork() {
|
|
2665
|
+
this.ensureInitialized();
|
|
2666
|
+
return this.utexoRGBWallet.getNetwork();
|
|
2667
|
+
}
|
|
2668
|
+
async dispose() {
|
|
2669
|
+
if (this.layer1RGBWallet) {
|
|
2670
|
+
await this.layer1RGBWallet.dispose();
|
|
2671
|
+
}
|
|
2672
|
+
if (this.utexoRGBWallet) {
|
|
2673
|
+
await this.utexoRGBWallet.dispose();
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
isDisposed() {
|
|
2677
|
+
if (!this.utexoRGBWallet) {
|
|
2678
|
+
return false;
|
|
2679
|
+
}
|
|
2680
|
+
return this.utexoRGBWallet.isDisposed();
|
|
2681
|
+
}
|
|
2682
|
+
async getBtcBalance() {
|
|
2683
|
+
this.ensureInitialized();
|
|
2684
|
+
return this.utexoRGBWallet.getBtcBalance();
|
|
2685
|
+
}
|
|
2686
|
+
async getAddress() {
|
|
2687
|
+
this.ensureInitialized();
|
|
2688
|
+
return this.utexoRGBWallet.getAddress();
|
|
2689
|
+
}
|
|
2690
|
+
async listUnspents() {
|
|
2691
|
+
this.ensureInitialized();
|
|
2692
|
+
return this.utexoRGBWallet.listUnspents();
|
|
2693
|
+
}
|
|
2694
|
+
async createUtxosBegin(params) {
|
|
2695
|
+
this.ensureInitialized();
|
|
2696
|
+
return this.utexoRGBWallet.createUtxosBegin(params);
|
|
2697
|
+
}
|
|
2698
|
+
async createUtxosEnd(params) {
|
|
2699
|
+
this.ensureInitialized();
|
|
2700
|
+
return this.utexoRGBWallet.createUtxosEnd(params);
|
|
2701
|
+
}
|
|
2702
|
+
async createUtxos(params) {
|
|
2703
|
+
this.ensureInitialized();
|
|
2704
|
+
return this.utexoRGBWallet.createUtxos(params);
|
|
2705
|
+
}
|
|
2706
|
+
async listAssets() {
|
|
2707
|
+
this.ensureInitialized();
|
|
2708
|
+
return this.utexoRGBWallet.listAssets();
|
|
2709
|
+
}
|
|
2710
|
+
async getAssetBalance(asset_id) {
|
|
2711
|
+
this.ensureInitialized();
|
|
2712
|
+
return this.utexoRGBWallet.getAssetBalance(asset_id);
|
|
2713
|
+
}
|
|
2714
|
+
async issueAssetNia(params) {
|
|
2715
|
+
this.ensureInitialized();
|
|
2716
|
+
return this.utexoRGBWallet.issueAssetNia(params);
|
|
2717
|
+
}
|
|
2718
|
+
async issueAssetIfa(params) {
|
|
2719
|
+
this.ensureInitialized();
|
|
2720
|
+
return this.utexoRGBWallet.issueAssetIfa(params);
|
|
2721
|
+
}
|
|
2722
|
+
async inflateBegin(params) {
|
|
2723
|
+
this.ensureInitialized();
|
|
2724
|
+
return this.utexoRGBWallet.inflateBegin(params);
|
|
2725
|
+
}
|
|
2726
|
+
async inflateEnd(params) {
|
|
2727
|
+
this.ensureInitialized();
|
|
2728
|
+
return this.utexoRGBWallet.inflateEnd(params);
|
|
2729
|
+
}
|
|
2730
|
+
async inflate(params, mnemonic) {
|
|
2731
|
+
this.ensureInitialized();
|
|
2732
|
+
return this.utexoRGBWallet.inflate(params, mnemonic);
|
|
2733
|
+
}
|
|
2734
|
+
async sendBegin(params) {
|
|
2735
|
+
this.ensureInitialized();
|
|
2736
|
+
return this.utexoRGBWallet.sendBegin(params);
|
|
2737
|
+
}
|
|
2738
|
+
async sendEnd(params) {
|
|
2739
|
+
this.ensureInitialized();
|
|
2740
|
+
return this.utexoRGBWallet.sendEnd(params);
|
|
2741
|
+
}
|
|
2742
|
+
async send(invoiceTransfer, mnemonic) {
|
|
2743
|
+
this.ensureInitialized();
|
|
2744
|
+
return this.utexoRGBWallet.send(invoiceTransfer, mnemonic);
|
|
2745
|
+
}
|
|
2746
|
+
async sendBtcBegin(params) {
|
|
2747
|
+
this.ensureInitialized();
|
|
2748
|
+
return this.utexoRGBWallet.sendBtcBegin(params);
|
|
2749
|
+
}
|
|
2750
|
+
async sendBtcEnd(params) {
|
|
2751
|
+
this.ensureInitialized();
|
|
2752
|
+
return this.utexoRGBWallet.sendBtcEnd(params);
|
|
2753
|
+
}
|
|
2754
|
+
async sendBtc(params) {
|
|
2755
|
+
this.ensureInitialized();
|
|
2756
|
+
return this.utexoRGBWallet.sendBtc(params);
|
|
2757
|
+
}
|
|
2758
|
+
async blindReceive(params) {
|
|
2759
|
+
this.ensureInitialized();
|
|
2760
|
+
return this.utexoRGBWallet.blindReceive(params);
|
|
2761
|
+
}
|
|
2762
|
+
async witnessReceive(params) {
|
|
2763
|
+
this.ensureInitialized();
|
|
2764
|
+
return this.utexoRGBWallet.witnessReceive(params);
|
|
2765
|
+
}
|
|
2766
|
+
async decodeRGBInvoice(params) {
|
|
2767
|
+
this.ensureInitialized();
|
|
2768
|
+
return this.utexoRGBWallet.decodeRGBInvoice(params);
|
|
2769
|
+
}
|
|
2770
|
+
async listTransactions() {
|
|
2771
|
+
this.ensureInitialized();
|
|
2772
|
+
return this.utexoRGBWallet.listTransactions();
|
|
2773
|
+
}
|
|
2774
|
+
async listTransfers(asset_id) {
|
|
2775
|
+
this.ensureInitialized();
|
|
2776
|
+
return this.utexoRGBWallet.listTransfers(asset_id);
|
|
2777
|
+
}
|
|
2778
|
+
async failTransfers(params) {
|
|
2779
|
+
this.ensureInitialized();
|
|
2780
|
+
return this.utexoRGBWallet.failTransfers(params);
|
|
2781
|
+
}
|
|
2782
|
+
async refreshWallet() {
|
|
2783
|
+
this.ensureInitialized();
|
|
2784
|
+
this.utexoRGBWallet.refreshWallet();
|
|
2785
|
+
}
|
|
2786
|
+
async syncWallet() {
|
|
2787
|
+
this.ensureInitialized();
|
|
2788
|
+
this.utexoRGBWallet.syncWallet();
|
|
2789
|
+
}
|
|
2790
|
+
async estimateFeeRate(blocks) {
|
|
2791
|
+
this.ensureInitialized();
|
|
2792
|
+
return this.utexoRGBWallet.estimateFeeRate(blocks);
|
|
2793
|
+
}
|
|
2794
|
+
async estimateFee(psbtBase64) {
|
|
2795
|
+
this.ensureInitialized();
|
|
2796
|
+
return this.utexoRGBWallet.estimateFee(psbtBase64);
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Create backup for both layer1 and utexo stores in one folder.
|
|
2800
|
+
* Writes backupPath/wallet_{masterFingerprint}_layer1.backup and backupPath/wallet_{masterFingerprint}_utexo.backup
|
|
2801
|
+
* (same naming convention as VSS: storeId_layer1, storeId_utexo with storeId = wallet_<fp>).
|
|
2802
|
+
* Use restoreUtxoWalletFromBackup with the same backupPath to restore both.
|
|
2803
|
+
*/
|
|
2804
|
+
async createBackup(params) {
|
|
2805
|
+
this.ensureInitialized();
|
|
2806
|
+
const { backupPath, password } = params;
|
|
2807
|
+
if (!backupPath || !password) {
|
|
2808
|
+
throw new ValidationError("backupPath and password are required", "createBackup");
|
|
2809
|
+
}
|
|
2810
|
+
const fp = this.utexoKeys.masterFingerprint;
|
|
2811
|
+
const { layer1TmpDir, utexoTmpDir, layer1FinalPath, utexoFinalPath } = prepareUtxoBackupDirs(backupPath, fp);
|
|
2812
|
+
const layer1Result = await this.layer1RGBWallet.createBackup({ backupPath: layer1TmpDir, password });
|
|
2813
|
+
const utexoResult = await this.utexoRGBWallet.createBackup({ backupPath: utexoTmpDir, password });
|
|
2814
|
+
finalizeUtxoBackupPaths({
|
|
2815
|
+
layer1BackupPath: layer1Result.backupPath,
|
|
2816
|
+
utexoBackupPath: utexoResult.backupPath,
|
|
2817
|
+
layer1FinalPath,
|
|
2818
|
+
utexoFinalPath,
|
|
2819
|
+
layer1TmpDir,
|
|
2820
|
+
utexoTmpDir
|
|
2821
|
+
});
|
|
2822
|
+
return {
|
|
2823
|
+
message: "Backup created successfully (layer1 + utexo)",
|
|
2824
|
+
backupPath,
|
|
2825
|
+
layer1BackupPath: layer1FinalPath,
|
|
2826
|
+
utexoBackupPath: utexoFinalPath
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
async configureVssBackup(config) {
|
|
2830
|
+
this.ensureInitialized();
|
|
2831
|
+
const { layer1, utexo } = getVssConfigs(config);
|
|
2832
|
+
await this.layer1RGBWallet.configureVssBackup(layer1);
|
|
2833
|
+
await this.utexoRGBWallet.configureVssBackup(utexo);
|
|
2834
|
+
}
|
|
2835
|
+
async disableVssAutoBackup() {
|
|
2836
|
+
this.ensureInitialized();
|
|
2837
|
+
await this.layer1RGBWallet.disableVssAutoBackup();
|
|
2838
|
+
await this.utexoRGBWallet.disableVssAutoBackup();
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* Run VSS backup for both layer1 and utexo stores.
|
|
2842
|
+
* Config is optional: when omitted, builds config from mnemonic (option param or wallet mnemonic)
|
|
2843
|
+
* and options.vssServerUrl (or DEFAULT_VSS_SERVER_URL if not set).
|
|
2844
|
+
*
|
|
2845
|
+
* @param config - Optional; when omitted, built from mnemonic and vssServerUrl
|
|
2846
|
+
* @param mnemonic - Optional; when omitted, uses wallet mnemonic (only if wallet was created with mnemonic string)
|
|
2847
|
+
*/
|
|
2848
|
+
async vssBackup(config, mnemonic) {
|
|
2849
|
+
this.ensureInitialized();
|
|
2850
|
+
let vssConfig;
|
|
2851
|
+
if (config) {
|
|
2852
|
+
vssConfig = config;
|
|
2853
|
+
} else {
|
|
2854
|
+
const mnemonicToUse = mnemonic ?? (typeof this.mnemonicOrSeed === "string" ? this.mnemonicOrSeed : null);
|
|
2855
|
+
if (!mnemonicToUse) {
|
|
2856
|
+
throw new ValidationError(
|
|
2857
|
+
"mnemonic is required for VSS backup when config is not passed (wallet was created with seed)",
|
|
2858
|
+
"mnemonic"
|
|
2859
|
+
);
|
|
2860
|
+
}
|
|
2861
|
+
const serverUrl = this.options.vssServerUrl ?? DEFAULT_VSS_SERVER_URL;
|
|
2862
|
+
const preset = this.options.network ?? "mainnet";
|
|
2863
|
+
vssConfig = await buildVssConfigFromMnemonic(mnemonicToUse.trim(), serverUrl, preset);
|
|
2864
|
+
}
|
|
2865
|
+
const { layer1, utexo } = getVssConfigs(vssConfig);
|
|
2866
|
+
await this.layer1RGBWallet.vssBackup(layer1);
|
|
2867
|
+
const version = await this.utexoRGBWallet.vssBackup(utexo);
|
|
2868
|
+
return version;
|
|
2869
|
+
}
|
|
2870
|
+
/**
|
|
2871
|
+
* Get VSS backup info. Config is optional; when omitted, built from mnemonic (param or wallet)
|
|
2872
|
+
* and options.vssServerUrl (or DEFAULT_VSS_SERVER_URL if not set).
|
|
2873
|
+
*/
|
|
2874
|
+
async vssBackupInfo(config, mnemonic) {
|
|
2875
|
+
this.ensureInitialized();
|
|
2876
|
+
let vssConfig;
|
|
2877
|
+
if (config) {
|
|
2878
|
+
vssConfig = config;
|
|
2879
|
+
} else {
|
|
2880
|
+
const mnemonicToUse = mnemonic ?? (typeof this.mnemonicOrSeed === "string" ? this.mnemonicOrSeed : null);
|
|
2881
|
+
if (!mnemonicToUse) {
|
|
2882
|
+
throw new ValidationError("config or mnemonic required for vssBackupInfo", "config");
|
|
2883
|
+
}
|
|
2884
|
+
const serverUrl = this.options.vssServerUrl ?? DEFAULT_VSS_SERVER_URL;
|
|
2885
|
+
const preset = this.options.network ?? "mainnet";
|
|
2886
|
+
vssConfig = await buildVssConfigFromMnemonic(mnemonicToUse.trim(), serverUrl, preset);
|
|
2887
|
+
}
|
|
2888
|
+
const { utexo } = getVssConfigs(vssConfig);
|
|
2889
|
+
return this.utexoRGBWallet.vssBackupInfo(utexo);
|
|
2890
|
+
}
|
|
2891
|
+
async signPsbt(psbt, mnemonic) {
|
|
2892
|
+
this.ensureInitialized();
|
|
2893
|
+
return this.utexoRGBWallet.signPsbt(psbt, mnemonic);
|
|
2894
|
+
}
|
|
2895
|
+
async signMessage(message) {
|
|
2896
|
+
this.ensureInitialized();
|
|
2897
|
+
return this.utexoRGBWallet.signMessage(message);
|
|
2898
|
+
}
|
|
2899
|
+
async verifyMessage(message, signature, accountXpub) {
|
|
2900
|
+
this.ensureInitialized();
|
|
2901
|
+
return this.utexoRGBWallet.verifyMessage(message, signature, accountXpub);
|
|
2902
|
+
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Validates that the wallet has sufficient spendable balance for the given asset and amount.
|
|
2905
|
+
* @param assetId - Asset ID to check balance for
|
|
2906
|
+
* @param amount - Required amount (in asset units)
|
|
2907
|
+
* @throws {ValidationError} If balance is not found or insufficient
|
|
2908
|
+
*/
|
|
2909
|
+
async validateBalance(assetId, amount) {
|
|
2910
|
+
const assetBalance = await this.getAssetBalance(assetId);
|
|
2911
|
+
if (!assetBalance || !assetBalance.spendable) {
|
|
2912
|
+
throw new ValidationError("Asset balance is not found", "assetBalance");
|
|
2913
|
+
}
|
|
2914
|
+
if (assetBalance.spendable < amount) {
|
|
2915
|
+
throw new ValidationError(`Insufficient balance ${assetBalance.spendable} < ${amount}`, "amount");
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Extracts invoice data and destination asset from a bridge transfer.
|
|
2920
|
+
*
|
|
2921
|
+
* @param bridgeTransfer - Bridge transfer response containing recipient invoice and token info
|
|
2922
|
+
* @returns Object containing invoice string, decoded invoice data, and destination asset
|
|
2923
|
+
* @throws {ValidationError} If destination asset is not supported
|
|
2924
|
+
*/
|
|
2925
|
+
async extractInvoiceAndAsset(bridgeTransfer) {
|
|
2926
|
+
const utexoInvoice = bridgeTransfer.recipient.address;
|
|
2927
|
+
const invoiceData = await this.decodeRGBInvoice({ invoice: utexoInvoice });
|
|
2928
|
+
const destinationAsset = this.networkIdMap.utexo.getAssetById(bridgeTransfer.recipientToken.id);
|
|
2929
|
+
if (!destinationAsset) {
|
|
2930
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
2931
|
+
}
|
|
2932
|
+
return { utexoInvoice, invoiceData, destinationAsset };
|
|
2933
|
+
}
|
|
2934
|
+
/**
|
|
2935
|
+
* IUTEXOProtocol Implementation
|
|
2936
|
+
*/
|
|
2937
|
+
async onchainReceive(params) {
|
|
2938
|
+
this.ensureInitialized();
|
|
2939
|
+
const destinationAsset = getDestinationAsset("mainnet", "utexo", params.assetId ?? null);
|
|
2940
|
+
if (!destinationAsset) {
|
|
2941
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
2942
|
+
}
|
|
2943
|
+
if (!params.amount) {
|
|
2944
|
+
throw new ValidationError("Amount is required", "amount");
|
|
2945
|
+
}
|
|
2946
|
+
const destinationInvoice = await this.utexoRGBWallet.witnessReceive({
|
|
2947
|
+
assetId: "",
|
|
2948
|
+
//invoice can receive any asset
|
|
2949
|
+
amount: params.amount,
|
|
2950
|
+
minConfirmations: params.minConfirmations,
|
|
2951
|
+
durationSeconds: params.durationSeconds
|
|
2952
|
+
});
|
|
2953
|
+
const bridgeTransfer = await this.bridge.getBridgeInSignature({
|
|
2954
|
+
sender: {
|
|
2955
|
+
address: "rgb-address",
|
|
2956
|
+
networkName: this.networkIdMap.mainnet.networkName,
|
|
2957
|
+
networkId: this.networkIdMap.mainnet.networkId
|
|
2958
|
+
},
|
|
2959
|
+
tokenId: destinationAsset.tokenId,
|
|
2960
|
+
amount: params.amount.toString(),
|
|
2961
|
+
destination: {
|
|
2962
|
+
address: destinationInvoice.invoice,
|
|
2963
|
+
networkName: this.networkIdMap.utexo.networkName,
|
|
2964
|
+
networkId: this.networkIdMap.utexo.networkId
|
|
2965
|
+
},
|
|
2966
|
+
additionalAddresses: []
|
|
2967
|
+
});
|
|
2968
|
+
const decodedInvoice = decodeBridgeInvoice(bridgeTransfer.signature);
|
|
2969
|
+
return {
|
|
2970
|
+
invoice: decodedInvoice
|
|
2971
|
+
};
|
|
2972
|
+
}
|
|
2973
|
+
async onchainSendBegin(params) {
|
|
2974
|
+
this.ensureInitialized();
|
|
2975
|
+
const bridgeTransfer = await this.bridge.getTransferByMainnetInvoice(params.invoice, this.networkIdMap.mainnet.networkId);
|
|
2976
|
+
if (!bridgeTransfer) {
|
|
2977
|
+
console.log("External invoice UTEXO -> Mainnet initiated");
|
|
2978
|
+
return this.UTEXOToMainnetRGB(params);
|
|
2979
|
+
}
|
|
2980
|
+
const utexoInvoice = bridgeTransfer.recipient.address;
|
|
2981
|
+
const invoiceData = await this.decodeRGBInvoice({ invoice: utexoInvoice });
|
|
2982
|
+
const bridgeAmount = bridgeTransfer.recipientAmount;
|
|
2983
|
+
const destinationAsset = this.networkIdMap.utexo.getAssetById(bridgeTransfer.recipientToken.id);
|
|
2984
|
+
if (!destinationAsset) {
|
|
2985
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
2986
|
+
}
|
|
2987
|
+
const amount = toUnitsNumber(bridgeAmount, destinationAsset.precision);
|
|
2988
|
+
const isWitness = invoiceData.recipientId.includes("wvout:");
|
|
2989
|
+
await this.validateBalance(destinationAsset.assetId, amount);
|
|
2990
|
+
const psbt = await this.utexoRGBWallet.sendBegin({
|
|
2991
|
+
invoice: utexoInvoice,
|
|
2992
|
+
amount,
|
|
2993
|
+
assetId: destinationAsset.assetId,
|
|
2994
|
+
donation: true,
|
|
2995
|
+
...isWitness && {
|
|
2996
|
+
witnessData: {
|
|
2997
|
+
amountSat: 1e3,
|
|
2998
|
+
blinding: 0
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
});
|
|
3002
|
+
return psbt;
|
|
3003
|
+
}
|
|
3004
|
+
async onchainSendEnd(params) {
|
|
3005
|
+
this.ensureInitialized();
|
|
3006
|
+
const sendResult = await this.utexoRGBWallet.sendEnd({ signedPsbt: params.signedPsbt });
|
|
3007
|
+
return sendResult;
|
|
3008
|
+
}
|
|
3009
|
+
async onchainSend(params, mnemonic) {
|
|
3010
|
+
this.ensureInitialized();
|
|
3011
|
+
const psbt = await this.onchainSendBegin(params);
|
|
3012
|
+
const signed_psbt = await this.utexoRGBWallet.signPsbt(psbt, mnemonic);
|
|
3013
|
+
return await this.onchainSendEnd({ signedPsbt: signed_psbt, invoice: params.invoice });
|
|
3014
|
+
}
|
|
3015
|
+
async getOnchainSendStatus(invoice) {
|
|
3016
|
+
const bridgeTransfer = await this.bridge.getTransferByMainnetInvoice(invoice, this.networkIdMap.mainnet.networkId);
|
|
3017
|
+
if (!bridgeTransfer) {
|
|
3018
|
+
const withdrawTransfer = await this.bridge.getWithdrawTransfer(invoice, this.networkIdMap.utexo.networkId);
|
|
3019
|
+
if (!withdrawTransfer) {
|
|
3020
|
+
return null;
|
|
3021
|
+
}
|
|
3022
|
+
return withdrawTransfer.status;
|
|
3023
|
+
}
|
|
3024
|
+
const { invoiceData, destinationAsset } = await this.extractInvoiceAndAsset(bridgeTransfer);
|
|
3025
|
+
const transfers = await this.utexoRGBWallet.listTransfers(destinationAsset.assetId);
|
|
3026
|
+
const transfer = transfers.find((transfer2) => transfer2.recipientId === invoiceData.recipientId);
|
|
3027
|
+
if (transfer) {
|
|
3028
|
+
return transfer.status;
|
|
3029
|
+
}
|
|
3030
|
+
if (bridgeTransfer) {
|
|
3031
|
+
return bridgeTransfer.status;
|
|
3032
|
+
}
|
|
3033
|
+
return null;
|
|
3034
|
+
}
|
|
3035
|
+
async listOnchainTransfers(asset_id) {
|
|
3036
|
+
this.ensureInitialized();
|
|
3037
|
+
return this.utexoRGBWallet.listTransfers(asset_id);
|
|
3038
|
+
}
|
|
3039
|
+
async createLightningInvoice(params) {
|
|
3040
|
+
this.ensureInitialized();
|
|
3041
|
+
const asset = params.asset;
|
|
3042
|
+
if (!asset) {
|
|
3043
|
+
throw new ValidationError("Asset is required", "asset");
|
|
3044
|
+
}
|
|
3045
|
+
if (!asset.assetId) {
|
|
3046
|
+
throw new ValidationError("Asset ID is required", "assetId");
|
|
3047
|
+
}
|
|
3048
|
+
if (!asset.amount) {
|
|
3049
|
+
throw new ValidationError("Amount is required", "amount");
|
|
3050
|
+
}
|
|
3051
|
+
const destinationAsset = getDestinationAsset("mainnet", "utexo", asset.assetId);
|
|
3052
|
+
if (!destinationAsset) {
|
|
3053
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
3054
|
+
}
|
|
3055
|
+
const destinationInvoice = await this.utexoRGBWallet.witnessReceive({
|
|
3056
|
+
assetId: "",
|
|
3057
|
+
//invoice can receive any asset
|
|
3058
|
+
amount: asset.amount
|
|
3059
|
+
});
|
|
3060
|
+
const bridgeTransfer = await this.bridge.getBridgeInSignature({
|
|
3061
|
+
sender: {
|
|
3062
|
+
address: "rgb-address",
|
|
3063
|
+
networkName: this.networkIdMap.mainnetLightning.networkName,
|
|
3064
|
+
networkId: this.networkIdMap.mainnetLightning.networkId
|
|
3065
|
+
},
|
|
3066
|
+
tokenId: destinationAsset.tokenId,
|
|
3067
|
+
amount: asset.amount.toString(),
|
|
3068
|
+
destination: {
|
|
3069
|
+
address: destinationInvoice.invoice,
|
|
3070
|
+
networkName: this.networkIdMap.utexo.networkName,
|
|
3071
|
+
networkId: this.networkIdMap.utexo.networkId
|
|
3072
|
+
},
|
|
3073
|
+
additionalAddresses: []
|
|
3074
|
+
});
|
|
3075
|
+
const decodedLnInvoice = decodeBridgeInvoice(bridgeTransfer.signature);
|
|
3076
|
+
return {
|
|
3077
|
+
lnInvoice: decodedLnInvoice
|
|
3078
|
+
};
|
|
3079
|
+
}
|
|
3080
|
+
async payLightningInvoiceBegin(params) {
|
|
3081
|
+
this.ensureInitialized();
|
|
3082
|
+
const bridgeTransfer = await this.bridge.getTransferByMainnetInvoice(params.lnInvoice, this.networkIdMap.mainnetLightning.networkId);
|
|
3083
|
+
if (!bridgeTransfer) {
|
|
3084
|
+
console.log("External invoice UTEXO -> Mainnet Lightning initiated");
|
|
3085
|
+
return this.UtexoToMainnetLightning(params);
|
|
3086
|
+
}
|
|
3087
|
+
const bridgeAmount = bridgeTransfer.recipientAmount;
|
|
3088
|
+
const { utexoInvoice, invoiceData, destinationAsset } = await this.extractInvoiceAndAsset(bridgeTransfer);
|
|
3089
|
+
const amount = toUnitsNumber(bridgeAmount, destinationAsset.precision);
|
|
3090
|
+
const isWitness = invoiceData.recipientId.includes("wvout:");
|
|
3091
|
+
const psbt = await this.utexoRGBWallet.sendBegin({
|
|
3092
|
+
invoice: utexoInvoice,
|
|
3093
|
+
amount,
|
|
3094
|
+
assetId: destinationAsset.assetId,
|
|
3095
|
+
donation: true,
|
|
3096
|
+
...isWitness && {
|
|
3097
|
+
witnessData: {
|
|
3098
|
+
amountSat: 1e3,
|
|
3099
|
+
blinding: 0
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
});
|
|
3103
|
+
return psbt;
|
|
3104
|
+
}
|
|
3105
|
+
async payLightningInvoiceEnd(params) {
|
|
3106
|
+
this.ensureInitialized();
|
|
3107
|
+
const sendResult = await this.utexoRGBWallet.sendEnd({ signedPsbt: params.signedPsbt });
|
|
3108
|
+
return sendResult;
|
|
3109
|
+
}
|
|
3110
|
+
async payLightningInvoice(params, mnemonic) {
|
|
3111
|
+
this.ensureInitialized();
|
|
3112
|
+
const psbt = await this.payLightningInvoiceBegin(params);
|
|
3113
|
+
const signed_psbt = await this.utexoRGBWallet.signPsbt(psbt, mnemonic);
|
|
3114
|
+
return await this.payLightningInvoiceEnd({ signedPsbt: signed_psbt, lnInvoice: params.lnInvoice });
|
|
3115
|
+
}
|
|
3116
|
+
async getLightningSendRequest(lnInvoice) {
|
|
3117
|
+
this.ensureInitialized();
|
|
3118
|
+
const bridgeTransfer = await this.bridge.getTransferByMainnetInvoice(lnInvoice, this.networkIdMap.mainnetLightning.networkId);
|
|
3119
|
+
if (!bridgeTransfer) {
|
|
3120
|
+
const withdrawTransfer = await this.bridge.getWithdrawTransfer(lnInvoice, this.networkIdMap.utexo.networkId);
|
|
3121
|
+
if (!withdrawTransfer) {
|
|
3122
|
+
return null;
|
|
3123
|
+
}
|
|
3124
|
+
return withdrawTransfer.status;
|
|
3125
|
+
}
|
|
3126
|
+
const { invoiceData, destinationAsset } = await this.extractInvoiceAndAsset(bridgeTransfer);
|
|
3127
|
+
const transfers = await this.utexoRGBWallet.listTransfers(destinationAsset.assetId);
|
|
3128
|
+
return transfers.length > 0 ? transfers.find((transfer) => transfer.recipientId === invoiceData.recipientId)?.status ?? null : null;
|
|
3129
|
+
}
|
|
3130
|
+
async getLightningReceiveRequest(lnInvoice) {
|
|
3131
|
+
this.ensureInitialized();
|
|
3132
|
+
const bridgeTransfer = await this.bridge.getTransferByMainnetInvoice(lnInvoice, this.networkIdMap.mainnetLightning.networkId);
|
|
3133
|
+
if (!bridgeTransfer) {
|
|
3134
|
+
const withdrawTransfer = await this.bridge.getWithdrawTransfer(lnInvoice, this.networkIdMap.utexo.networkId);
|
|
3135
|
+
if (!withdrawTransfer) {
|
|
3136
|
+
return null;
|
|
3137
|
+
}
|
|
3138
|
+
return withdrawTransfer.status;
|
|
3139
|
+
}
|
|
3140
|
+
const { invoiceData, destinationAsset } = await this.extractInvoiceAndAsset(bridgeTransfer);
|
|
3141
|
+
const transfers = await this.utexoRGBWallet.listTransfers(destinationAsset.assetId);
|
|
3142
|
+
return transfers.length > 0 ? transfers.find((transfer) => transfer.recipientId === invoiceData.recipientId)?.status ?? null : null;
|
|
3143
|
+
}
|
|
3144
|
+
async UTEXOToMainnetRGB(params) {
|
|
3145
|
+
this.ensureInitialized();
|
|
3146
|
+
const invoiceData = await this.decodeRGBInvoice({ invoice: params.invoice });
|
|
3147
|
+
if (!params.assetId && !invoiceData.assetId) {
|
|
3148
|
+
throw new ValidationError("Asset ID is required for external invoice", "assetId");
|
|
3149
|
+
}
|
|
3150
|
+
const assetId = params.assetId ?? invoiceData.assetId;
|
|
3151
|
+
const utexoAsset = getDestinationAsset("mainnet", "utexo", assetId ?? null);
|
|
3152
|
+
if (!utexoAsset) {
|
|
3153
|
+
throw new ValidationError("UTEXO asset is not supported", "assetId");
|
|
3154
|
+
}
|
|
3155
|
+
const destinationAsset = this.networkIdMap.mainnet.getAssetById(utexoAsset?.tokenId ?? 0);
|
|
3156
|
+
if (!destinationAsset) {
|
|
3157
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
3158
|
+
}
|
|
3159
|
+
if (!params.amount && !invoiceData.assignment.amount) {
|
|
3160
|
+
throw new ValidationError("Amount is required for external invoice", "amount");
|
|
3161
|
+
}
|
|
3162
|
+
let amount;
|
|
3163
|
+
if (params.amount) {
|
|
3164
|
+
amount = params.amount;
|
|
3165
|
+
} else if (invoiceData.assignment.amount) {
|
|
3166
|
+
amount = fromUnitsNumber(invoiceData.assignment.amount, destinationAsset.precision);
|
|
3167
|
+
} else {
|
|
3168
|
+
throw new ValidationError("Amount is required", "amount");
|
|
3169
|
+
}
|
|
3170
|
+
await this.validateBalance(utexoAsset.assetId, toUnitsNumber(amount.toString(), utexoAsset.precision));
|
|
3171
|
+
const payload = {
|
|
3172
|
+
sender: {
|
|
3173
|
+
address: "rgb-address",
|
|
3174
|
+
networkName: this.networkIdMap.utexo.networkName,
|
|
3175
|
+
networkId: this.networkIdMap.utexo.networkId
|
|
3176
|
+
},
|
|
3177
|
+
tokenId: destinationAsset.tokenId,
|
|
3178
|
+
amount: amount.toString(),
|
|
3179
|
+
destination: {
|
|
3180
|
+
address: params.invoice,
|
|
3181
|
+
networkName: this.networkIdMap.mainnet.networkName,
|
|
3182
|
+
networkId: this.networkIdMap.mainnet.networkId
|
|
3183
|
+
},
|
|
3184
|
+
additionalAddresses: []
|
|
3185
|
+
};
|
|
3186
|
+
console.log("payload", payload);
|
|
3187
|
+
const bridgeOutTransfer = await this.bridge.getBridgeInSignature(payload);
|
|
3188
|
+
const decodedInvoice = decodeBridgeInvoice(bridgeOutTransfer.signature);
|
|
3189
|
+
const isWitness = decodedInvoice.includes("wvout:");
|
|
3190
|
+
const psbt = await this.utexoRGBWallet.sendBegin({
|
|
3191
|
+
invoice: decodedInvoice,
|
|
3192
|
+
amount: Number(bridgeOutTransfer.amount),
|
|
3193
|
+
assetId: utexoAsset.assetId,
|
|
3194
|
+
donation: true,
|
|
3195
|
+
...isWitness && {
|
|
3196
|
+
witnessData: {
|
|
3197
|
+
amountSat: 1e3,
|
|
3198
|
+
blinding: 0
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
});
|
|
3202
|
+
return psbt;
|
|
3203
|
+
}
|
|
3204
|
+
async UtexoToMainnetLightning(params) {
|
|
3205
|
+
this.ensureInitialized();
|
|
3206
|
+
if (!params.assetId) {
|
|
3207
|
+
throw new ValidationError("Asset ID is required for external invoice", "assetId");
|
|
3208
|
+
}
|
|
3209
|
+
const assetId = params.assetId;
|
|
3210
|
+
const utexoAsset = getDestinationAsset("mainnet", "utexo", assetId ?? null);
|
|
3211
|
+
const destinationAsset = this.networkIdMap.mainnet.getAssetById(utexoAsset?.tokenId ?? 0);
|
|
3212
|
+
if (!destinationAsset) {
|
|
3213
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
3214
|
+
}
|
|
3215
|
+
if (!utexoAsset) {
|
|
3216
|
+
throw new ValidationError("Destination asset is not supported", "assetId");
|
|
3217
|
+
}
|
|
3218
|
+
if (!params.amount) {
|
|
3219
|
+
throw new ValidationError("Amount is required for external invoice", "amount");
|
|
3220
|
+
}
|
|
3221
|
+
const amount = params.amount;
|
|
3222
|
+
await this.validateBalance(utexoAsset.assetId, toUnitsNumber(amount.toString(), utexoAsset.precision));
|
|
3223
|
+
const bridgeOutTransfer = await this.bridge.getBridgeInSignature({
|
|
3224
|
+
sender: {
|
|
3225
|
+
address: "rgb-address",
|
|
3226
|
+
networkName: this.networkIdMap.utexo.networkName,
|
|
3227
|
+
networkId: this.networkIdMap.utexo.networkId
|
|
3228
|
+
},
|
|
3229
|
+
tokenId: destinationAsset.tokenId,
|
|
3230
|
+
amount: amount.toString(),
|
|
3231
|
+
destination: {
|
|
3232
|
+
address: params.lnInvoice,
|
|
3233
|
+
networkName: this.networkIdMap.mainnetLightning.networkName,
|
|
3234
|
+
networkId: this.networkIdMap.mainnetLightning.networkId
|
|
3235
|
+
},
|
|
3236
|
+
additionalAddresses: []
|
|
3237
|
+
});
|
|
3238
|
+
const decodedInvoice = decodeBridgeInvoice(bridgeOutTransfer.signature);
|
|
3239
|
+
const isWitness = decodedInvoice.includes("wvout:");
|
|
3240
|
+
const psbt = await this.utexoRGBWallet.sendBegin({
|
|
3241
|
+
invoice: decodedInvoice,
|
|
3242
|
+
amount: Number(bridgeOutTransfer.amount),
|
|
3243
|
+
assetId: utexoAsset.assetId,
|
|
3244
|
+
donation: true,
|
|
3245
|
+
...isWitness && {
|
|
3246
|
+
witnessData: {
|
|
3247
|
+
amountSat: 1e3,
|
|
3248
|
+
blinding: 0
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
});
|
|
3252
|
+
return psbt;
|
|
3253
|
+
}
|
|
3254
|
+
// TODO: Implement remaining methods as needed:
|
|
3255
|
+
// - createLightningInvoice() - will use utexoRGBWallet
|
|
3256
|
+
// - getLightningReceiveRequest() - will use utexoRGBWallet
|
|
3257
|
+
// - getLightningSendRequest() - will use utexoRGBWallet
|
|
3258
|
+
// - getLightningSendFeeEstimate() - will use utexoRGBWallet
|
|
3259
|
+
// - payLightningInvoiceBegin() - will use utexoRGBWallet
|
|
3260
|
+
// - payLightningInvoiceEnd() - will use utexoRGBWallet
|
|
3261
|
+
// - onchainSendBegin() - will use layer1RGBWallet or utexoRGBWallet
|
|
3262
|
+
// - onchainSendEnd() - will use layer1RGBWallet or utexoRGBWallet
|
|
3263
|
+
// - getOnchainSendStatus() - will use layer1RGBWallet or utexoRGBWallet
|
|
3264
|
+
// - listOnchainTransfers() - will use layer1RGBWallet or utexoRGBWallet
|
|
3265
|
+
// - listLightningPayments() - will use utexoRGBWallet
|
|
3266
|
+
};
|
|
1792
3267
|
|
|
1793
3268
|
// src/utils/logger.ts
|
|
1794
3269
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
@@ -1853,8 +3328,6 @@ function configureLogging(level) {
|
|
|
1853
3328
|
logger.setLevel(level);
|
|
1854
3329
|
}
|
|
1855
3330
|
|
|
1856
|
-
exports.AssetIface = AssetIface;
|
|
1857
|
-
exports.AssetSchema = AssetSchema;
|
|
1858
3331
|
exports.BIP32_VERSIONS = BIP32_VERSIONS;
|
|
1859
3332
|
exports.BadRequestError = BadRequestError;
|
|
1860
3333
|
exports.COIN_BITCOIN_MAINNET = COIN_BITCOIN_MAINNET;
|
|
@@ -1868,18 +3341,21 @@ exports.DEFAULT_API_TIMEOUT = DEFAULT_API_TIMEOUT;
|
|
|
1868
3341
|
exports.DEFAULT_LOG_LEVEL = DEFAULT_LOG_LEVEL;
|
|
1869
3342
|
exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
|
|
1870
3343
|
exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
|
|
3344
|
+
exports.DEFAULT_VSS_SERVER_URL = DEFAULT_VSS_SERVER_URL;
|
|
1871
3345
|
exports.DERIVATION_ACCOUNT = DERIVATION_ACCOUNT;
|
|
1872
3346
|
exports.DERIVATION_PURPOSE = DERIVATION_PURPOSE;
|
|
1873
3347
|
exports.KEYCHAIN_BTC = KEYCHAIN_BTC;
|
|
1874
3348
|
exports.KEYCHAIN_RGB = KEYCHAIN_RGB;
|
|
3349
|
+
exports.LightningProtocol = LightningProtocol;
|
|
1875
3350
|
exports.LogLevel = LogLevel;
|
|
1876
3351
|
exports.NETWORK_MAP = NETWORK_MAP;
|
|
1877
3352
|
exports.NetworkError = NetworkError;
|
|
1878
3353
|
exports.NotFoundError = NotFoundError;
|
|
3354
|
+
exports.OnchainProtocol = OnchainProtocol;
|
|
1879
3355
|
exports.RgbNodeError = RgbNodeError;
|
|
1880
3356
|
exports.SDKError = SDKError;
|
|
1881
|
-
exports.
|
|
1882
|
-
exports.
|
|
3357
|
+
exports.UTEXOProtocol = UTEXOProtocol;
|
|
3358
|
+
exports.UTEXOWallet = UTEXOWallet;
|
|
1883
3359
|
exports.ValidationError = ValidationError;
|
|
1884
3360
|
exports.WalletError = WalletError;
|
|
1885
3361
|
exports.WalletManager = WalletManager;
|
|
@@ -1888,10 +3364,14 @@ exports.configureLogging = configureLogging;
|
|
|
1888
3364
|
exports.createWallet = createWallet;
|
|
1889
3365
|
exports.createWalletManager = createWalletManager;
|
|
1890
3366
|
exports.deriveKeysFromMnemonic = deriveKeysFromMnemonic;
|
|
3367
|
+
exports.deriveKeysFromMnemonicOrSeed = deriveKeysFromMnemonicOrSeed;
|
|
1891
3368
|
exports.deriveKeysFromSeed = deriveKeysFromSeed;
|
|
1892
3369
|
exports.deriveKeysFromXpriv = deriveKeysFromXpriv;
|
|
3370
|
+
exports.deriveVssSigningKeyFromMnemonic = deriveVssSigningKeyFromMnemonic;
|
|
1893
3371
|
exports.generateKeys = generateKeys2;
|
|
3372
|
+
exports.getDestinationAsset = getDestinationAsset;
|
|
1894
3373
|
exports.getEnvironment = getEnvironment;
|
|
3374
|
+
exports.getUtxoNetworkConfig = getUtxoNetworkConfig;
|
|
1895
3375
|
exports.getXprivFromMnemonic = getXprivFromMnemonic;
|
|
1896
3376
|
exports.getXpubFromXpriv = getXpubFromXpriv;
|
|
1897
3377
|
exports.isBrowser = isBrowser;
|
|
@@ -1899,11 +3379,16 @@ exports.isNode = isNode;
|
|
|
1899
3379
|
exports.logger = logger;
|
|
1900
3380
|
exports.normalizeNetwork = normalizeNetwork;
|
|
1901
3381
|
exports.restoreFromBackup = restoreFromBackup;
|
|
3382
|
+
exports.restoreFromVss = restoreFromVss;
|
|
1902
3383
|
exports.restoreKeys = restoreKeys;
|
|
3384
|
+
exports.restoreUtxoWalletFromBackup = restoreUtxoWalletFromBackup;
|
|
3385
|
+
exports.restoreUtxoWalletFromVss = restoreUtxoWalletFromVss;
|
|
1903
3386
|
exports.signMessage = signMessage;
|
|
1904
3387
|
exports.signPsbt = signPsbt;
|
|
1905
3388
|
exports.signPsbtFromSeed = signPsbtFromSeed;
|
|
1906
3389
|
exports.signPsbtSync = signPsbtSync;
|
|
3390
|
+
exports.utexoNetworkIdMap = utexoNetworkIdMap;
|
|
3391
|
+
exports.utexoNetworkMap = utexoNetworkMap;
|
|
1907
3392
|
exports.validateBase64 = validateBase64;
|
|
1908
3393
|
exports.validateHex = validateHex;
|
|
1909
3394
|
exports.validateMnemonic = validateMnemonic;
|