@arkade-os/sdk 0.4.28 → 0.4.30
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 +14 -16
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +4 -4
- package/dist/adapters/expo.d.ts +4 -4
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-TZ1gXAXU.d.cts → ark-C0TMXvwO.d.cts} +92 -63
- package/dist/{ark-TZ1gXAXU.d.ts → ark-C0TMXvwO.d.ts} +92 -63
- package/dist/{asyncStorageTaskQueue-EFqSmYTg.d.cts → asyncStorageTaskQueue-DHOoNvRy.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-Cb1F_Z9s.d.ts → asyncStorageTaskQueue-Iip3xMF_.d.ts} +2 -2
- package/dist/{chunk-ADV27S4N.cjs → chunk-6FLL2Q36.cjs} +8 -8
- package/dist/chunk-6FLL2Q36.cjs.map +1 -0
- package/dist/{chunk-ZBUDLTBO.js → chunk-6NWNOLL3.js} +5 -5
- package/dist/chunk-6NWNOLL3.js.map +1 -0
- package/dist/{chunk-BQLHADL7.js → chunk-6NY27WL6.js} +341 -183
- package/dist/chunk-6NY27WL6.js.map +1 -0
- package/dist/{chunk-CFZMTDWI.js → chunk-ABWRLTX5.js} +6 -5
- package/dist/chunk-ABWRLTX5.js.map +1 -0
- package/dist/{chunk-FG5ACJJW.cjs → chunk-GIGILVVP.cjs} +11 -10
- package/dist/chunk-GIGILVVP.cjs.map +1 -0
- package/dist/{chunk-A3EMF7RN.js → chunk-GRJKJNBO.js} +3 -3
- package/dist/{chunk-A3EMF7RN.js.map → chunk-GRJKJNBO.js.map} +1 -1
- package/dist/{chunk-I3DGUUCT.cjs → chunk-IEO3XDKI.cjs} +28 -28
- package/dist/{chunk-I3DGUUCT.cjs.map → chunk-IEO3XDKI.cjs.map} +1 -1
- package/dist/{chunk-IPX2R7FR.cjs → chunk-PCEE6DRL.cjs} +7 -7
- package/dist/{chunk-IPX2R7FR.cjs.map → chunk-PCEE6DRL.cjs.map} +1 -1
- package/dist/{chunk-HW3JJ323.js → chunk-TU3LVAPX.js} +32 -31
- package/dist/chunk-TU3LVAPX.js.map +1 -0
- package/dist/{chunk-5PG7DV7A.cjs → chunk-WMIPYZSB.cjs} +34 -36
- package/dist/chunk-WMIPYZSB.cjs.map +1 -0
- package/dist/{chunk-ZLO6NETT.cjs → chunk-XWJFOP5G.cjs} +505 -337
- package/dist/chunk-XWJFOP5G.cjs.map +1 -0
- package/dist/{chunk-T64LAI7L.js → chunk-YA4G7RFB.js} +3 -3
- package/dist/{chunk-T64LAI7L.js.map → chunk-YA4G7RFB.js.map} +1 -1
- package/dist/contracts/handlers/index.cjs +6 -6
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-aaVGfWsV.d.ts → delegate-CEk9RHVj.d.cts} +2 -2
- package/dist/{delegate-BFZs69hp.d.cts → delegate-Ds4Hi7Xy.d.ts} +2 -2
- package/dist/{index-NDla_UoJ.d.ts → index-DA9r_7Vg.d.ts} +2 -2
- package/dist/{index-B22cA64m.d.cts → index-WIAY0DDn.d.cts} +2 -2
- package/dist/index.cjs +161 -137
- package/dist/index.d.cts +144 -17
- package/dist/index.d.ts +144 -17
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +13 -13
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +4 -4
- package/dist/repositories/sqlite/index.cjs +13 -13
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.js +4 -4
- package/dist/{taskRunner-C6Ff4OaU.d.cts → taskRunner-CdEVYgoP.d.cts} +2 -2
- package/dist/{taskRunner-yvPN8Z0K.d.ts → taskRunner-JNjIWWJi.d.ts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +19 -15
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +9 -7
- package/dist/wallet/expo/index.d.ts +9 -7
- package/dist/wallet/expo/index.js +11 -7
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-D9NBRqvC.d.ts → wallet-BGL6SzKQ.d.ts} +19 -15
- package/dist/{wallet-AF-p-OWj.d.cts → wallet-CMgzKP0o.d.cts} +19 -15
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-5PG7DV7A.cjs.map +0 -1
- package/dist/chunk-ADV27S4N.cjs.map +0 -1
- package/dist/chunk-BQLHADL7.js.map +0 -1
- package/dist/chunk-CFZMTDWI.js.map +0 -1
- package/dist/chunk-FG5ACJJW.cjs.map +0 -1
- package/dist/chunk-HW3JJ323.js.map +0 -1
- package/dist/chunk-ZBUDLTBO.js.map +0 -1
- package/dist/chunk-ZLO6NETT.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunk6FLL2Q36_cjs = require('./chunk-6FLL2Q36.cjs');
|
|
4
|
+
var chunkIEO3XDKI_cjs = require('./chunk-IEO3XDKI.cjs');
|
|
5
|
+
var chunkWMIPYZSB_cjs = require('./chunk-WMIPYZSB.cjs');
|
|
6
6
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
7
7
|
var btcSigner = require('@scure/btc-signer');
|
|
8
8
|
var base = require('@scure/base');
|
|
@@ -181,7 +181,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
181
181
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
182
182
|
const tx = this.graph.find(txid);
|
|
183
183
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
184
|
-
const cosigners =
|
|
184
|
+
const cosigners = chunk6FLL2Q36_cjs.getArkPsbtFields(tx.root, 0, chunk6FLL2Q36_cjs.CosignerPublicKey).map(
|
|
185
185
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
186
186
|
// xonly pubkey
|
|
187
187
|
);
|
|
@@ -233,7 +233,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
233
233
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
234
234
|
const prevoutAmounts = [];
|
|
235
235
|
const prevoutScripts = [];
|
|
236
|
-
const cosigners =
|
|
236
|
+
const cosigners = chunk6FLL2Q36_cjs.getArkPsbtFields(g.root, 0, chunk6FLL2Q36_cjs.CosignerPublicKey).map((c) => c.key);
|
|
237
237
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
238
238
|
taprootTweak: this.scriptRoot
|
|
239
239
|
});
|
|
@@ -411,7 +411,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
411
411
|
let network;
|
|
412
412
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
413
413
|
descriptor = opts.descriptor;
|
|
414
|
-
network =
|
|
414
|
+
network = chunkIEO3XDKI_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
415
415
|
} else {
|
|
416
416
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
417
417
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -496,7 +496,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
496
496
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
497
497
|
*/
|
|
498
498
|
isOurs(descriptor) {
|
|
499
|
-
return
|
|
499
|
+
return chunkIEO3XDKI_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
500
500
|
}
|
|
501
501
|
/**
|
|
502
502
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -533,7 +533,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
533
533
|
}
|
|
534
534
|
// ── internal helpers ─────────────────────────────────────────────
|
|
535
535
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
536
|
-
const network =
|
|
536
|
+
const network = chunkIEO3XDKI_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
537
537
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
538
538
|
if (expansion.isRanged) {
|
|
539
539
|
throw new Error(
|
|
@@ -619,7 +619,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
619
619
|
*/
|
|
620
620
|
descriptor;
|
|
621
621
|
constructor(descriptor) {
|
|
622
|
-
const network =
|
|
622
|
+
const network = chunkIEO3XDKI_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
623
623
|
let expansion;
|
|
624
624
|
try {
|
|
625
625
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -669,7 +669,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
669
669
|
* `StaticDescriptorProvider` for legacy single-key wallets.
|
|
670
670
|
*/
|
|
671
671
|
isOurs(descriptor) {
|
|
672
|
-
return
|
|
672
|
+
return chunkIEO3XDKI_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
673
673
|
}
|
|
674
674
|
};
|
|
675
675
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -960,12 +960,12 @@ async function getActiveServiceWorker(path) {
|
|
|
960
960
|
return serviceWorker;
|
|
961
961
|
}
|
|
962
962
|
|
|
963
|
-
// src/providers/
|
|
964
|
-
var
|
|
963
|
+
// src/providers/delegate.ts
|
|
964
|
+
var RestDelegateProvider = class {
|
|
965
965
|
/**
|
|
966
|
-
* Create a REST
|
|
966
|
+
* Create a REST delegate provider targeting the given base URL.
|
|
967
967
|
*
|
|
968
|
-
* @param url - Base URL of the delegation service
|
|
968
|
+
* @param url - Base URL of the remote delegation service.
|
|
969
969
|
*/
|
|
970
970
|
constructor(url) {
|
|
971
971
|
this.url = url;
|
|
@@ -987,7 +987,7 @@ var RestDelegatorProvider = class {
|
|
|
987
987
|
},
|
|
988
988
|
body: JSON.stringify({
|
|
989
989
|
intent: {
|
|
990
|
-
message:
|
|
990
|
+
message: chunk6FLL2Q36_cjs.Intent.encodeMessage(intent.message),
|
|
991
991
|
proof: intent.proof
|
|
992
992
|
},
|
|
993
993
|
forfeit_txs: forfeitTxs,
|
|
@@ -1016,35 +1016,13 @@ var RestDelegatorProvider = class {
|
|
|
1016
1016
|
if (!isDelegateInfo(data)) {
|
|
1017
1017
|
throw new Error("Invalid delegate info");
|
|
1018
1018
|
}
|
|
1019
|
-
|
|
1019
|
+
const delegateAddress = typeof data.delegateAddress === "string" && data.delegateAddress !== "" ? data.delegateAddress : typeof data.delegatorAddress === "string" && data.delegatorAddress !== "" ? data.delegatorAddress : "";
|
|
1020
|
+
return { ...data, delegateAddress };
|
|
1020
1021
|
}
|
|
1021
1022
|
};
|
|
1023
|
+
var RestDelegatorProvider = RestDelegateProvider;
|
|
1022
1024
|
function isDelegateInfo(data) {
|
|
1023
|
-
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && "
|
|
1024
|
-
}
|
|
1025
|
-
var getNetwork = (network) => {
|
|
1026
|
-
return networks2[network];
|
|
1027
|
-
};
|
|
1028
|
-
var networks2 = {
|
|
1029
|
-
bitcoin: withArkPrefix(utils_js.NETWORK, "ark"),
|
|
1030
|
-
testnet: withArkPrefix(utils_js.TEST_NETWORK, "tark"),
|
|
1031
|
-
signet: withArkPrefix(utils_js.TEST_NETWORK, "tark"),
|
|
1032
|
-
mutinynet: withArkPrefix(utils_js.TEST_NETWORK, "tark"),
|
|
1033
|
-
regtest: withArkPrefix(
|
|
1034
|
-
{
|
|
1035
|
-
...utils_js.TEST_NETWORK,
|
|
1036
|
-
bech32: "bcrt",
|
|
1037
|
-
pubKeyHash: 111,
|
|
1038
|
-
scriptHash: 196
|
|
1039
|
-
},
|
|
1040
|
-
"tark"
|
|
1041
|
-
)
|
|
1042
|
-
};
|
|
1043
|
-
function withArkPrefix(network, prefix) {
|
|
1044
|
-
return {
|
|
1045
|
-
...network,
|
|
1046
|
-
hrp: prefix
|
|
1047
|
-
};
|
|
1025
|
+
return !!data && typeof data === "object" && "pubkey" in data && "fee" in data && typeof data.pubkey === "string" && typeof data.fee === "string" && data.pubkey !== "" && data.fee !== "" && (typeof data.delegateAddress === "string" && data.delegateAddress !== "" || typeof data.delegatorAddress === "string" && data.delegatorAddress !== "");
|
|
1048
1026
|
}
|
|
1049
1027
|
|
|
1050
1028
|
// src/providers/onchain.ts
|
|
@@ -1056,7 +1034,7 @@ var ESPLORA_URL = {
|
|
|
1056
1034
|
regtest: "http://localhost:3000"
|
|
1057
1035
|
};
|
|
1058
1036
|
var EsploraProvider = class {
|
|
1059
|
-
constructor(baseUrl, opts) {
|
|
1037
|
+
constructor(baseUrl = ESPLORA_URL[chunkWMIPYZSB_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1060
1038
|
this.baseUrl = baseUrl;
|
|
1061
1039
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1062
1040
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1299,7 +1277,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
1299
1277
|
);
|
|
1300
1278
|
}
|
|
1301
1279
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
1302
|
-
const tx = new
|
|
1280
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction({
|
|
1303
1281
|
version: 3,
|
|
1304
1282
|
lockTime: txLocktime
|
|
1305
1283
|
});
|
|
@@ -1375,7 +1353,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
1375
1353
|
if (previousScriptKey.length !== 32) {
|
|
1376
1354
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
1377
1355
|
}
|
|
1378
|
-
const cosigners =
|
|
1356
|
+
const cosigners = chunk6FLL2Q36_cjs.getArkPsbtFields(child.root, 0, chunk6FLL2Q36_cjs.CosignerPublicKey);
|
|
1379
1357
|
if (cosigners.length === 0) {
|
|
1380
1358
|
throw ErrMissingCosignersPublicKeys;
|
|
1381
1359
|
}
|
|
@@ -1475,7 +1453,7 @@ var Extension = class _Extension {
|
|
|
1475
1453
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
1476
1454
|
);
|
|
1477
1455
|
}
|
|
1478
|
-
const reader = new
|
|
1456
|
+
const reader = new chunk6FLL2Q36_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
1479
1457
|
const packets = [];
|
|
1480
1458
|
while (reader.remaining() > 0) {
|
|
1481
1459
|
const packetType = reader.readByte();
|
|
@@ -1549,7 +1527,7 @@ var Extension = class _Extension {
|
|
|
1549
1527
|
*/
|
|
1550
1528
|
getAssetPacket() {
|
|
1551
1529
|
for (const p of this.packets) {
|
|
1552
|
-
if (p instanceof
|
|
1530
|
+
if (p instanceof chunk6FLL2Q36_cjs.Packet) {
|
|
1553
1531
|
return p;
|
|
1554
1532
|
}
|
|
1555
1533
|
}
|
|
@@ -1557,8 +1535,8 @@ var Extension = class _Extension {
|
|
|
1557
1535
|
}
|
|
1558
1536
|
};
|
|
1559
1537
|
function parsePacket(packetType, data) {
|
|
1560
|
-
if (packetType ===
|
|
1561
|
-
return
|
|
1538
|
+
if (packetType === chunk6FLL2Q36_cjs.Packet.PACKET_TYPE) {
|
|
1539
|
+
return chunk6FLL2Q36_cjs.Packet.fromBytes(data);
|
|
1562
1540
|
}
|
|
1563
1541
|
return new UnknownPacket(packetType, data);
|
|
1564
1542
|
}
|
|
@@ -1616,7 +1594,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
1616
1594
|
for (const recipient of recipients) {
|
|
1617
1595
|
let arkAddress;
|
|
1618
1596
|
try {
|
|
1619
|
-
arkAddress =
|
|
1597
|
+
arkAddress = chunkWMIPYZSB_cjs.ArkAddress.decode(recipient.address);
|
|
1620
1598
|
} catch {
|
|
1621
1599
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
1622
1600
|
continue;
|
|
@@ -1717,6 +1695,30 @@ function validateAssetGroupOutput(packet, outputIndex, assetId, expectedAmount)
|
|
|
1717
1695
|
}
|
|
1718
1696
|
}
|
|
1719
1697
|
|
|
1698
|
+
// src/wallet/index.ts
|
|
1699
|
+
var TxType = /* @__PURE__ */ ((TxType2) => {
|
|
1700
|
+
TxType2["TxSent"] = "SENT";
|
|
1701
|
+
TxType2["TxReceived"] = "RECEIVED";
|
|
1702
|
+
return TxType2;
|
|
1703
|
+
})(TxType || {});
|
|
1704
|
+
function isSpendable(vtxo) {
|
|
1705
|
+
return !vtxo.isSpent;
|
|
1706
|
+
}
|
|
1707
|
+
function isRecoverable(vtxo) {
|
|
1708
|
+
return vtxo.virtualStatus.state === "swept" && isSpendable(vtxo);
|
|
1709
|
+
}
|
|
1710
|
+
function isExpired(vtxo) {
|
|
1711
|
+
if (vtxo.virtualStatus.state === "swept") return true;
|
|
1712
|
+
const expiry = vtxo.virtualStatus.batchExpiry;
|
|
1713
|
+
if (!expiry) return false;
|
|
1714
|
+
const expireAt = new Date(expiry);
|
|
1715
|
+
if (expireAt.getFullYear() < 2025) return false;
|
|
1716
|
+
return expiry <= Date.now();
|
|
1717
|
+
}
|
|
1718
|
+
function isSubdust(vtxo, dust) {
|
|
1719
|
+
return vtxo.value < dust;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1720
1722
|
// src/wallet/asset.ts
|
|
1721
1723
|
function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
1722
1724
|
const inputsByAssetId = /* @__PURE__ */ new Map();
|
|
@@ -1725,7 +1727,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1725
1727
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
1726
1728
|
inputsByAssetId.set(asset.assetId, [
|
|
1727
1729
|
...existing ?? [],
|
|
1728
|
-
|
|
1730
|
+
chunk6FLL2Q36_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
1729
1731
|
]);
|
|
1730
1732
|
}
|
|
1731
1733
|
}
|
|
@@ -1737,7 +1739,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1737
1739
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
1738
1740
|
outputsByAssetId.set(asset.assetId, [
|
|
1739
1741
|
...existing ?? [],
|
|
1740
|
-
|
|
1742
|
+
chunk6FLL2Q36_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
1741
1743
|
]);
|
|
1742
1744
|
}
|
|
1743
1745
|
}
|
|
@@ -1748,7 +1750,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1748
1750
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
1749
1751
|
outputsByAssetId.set(asset.assetId, [
|
|
1750
1752
|
...existing ?? [],
|
|
1751
|
-
|
|
1753
|
+
chunk6FLL2Q36_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
1752
1754
|
]);
|
|
1753
1755
|
}
|
|
1754
1756
|
}
|
|
@@ -1757,11 +1759,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
1757
1759
|
for (const assetIdStr of allAssetIds) {
|
|
1758
1760
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
1759
1761
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
1760
|
-
const assetId =
|
|
1761
|
-
const group =
|
|
1762
|
+
const assetId = chunk6FLL2Q36_cjs.AssetId.fromString(assetIdStr);
|
|
1763
|
+
const group = chunk6FLL2Q36_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
1762
1764
|
groups.push(group);
|
|
1763
1765
|
}
|
|
1764
|
-
return
|
|
1766
|
+
return chunk6FLL2Q36_cjs.Packet.create(groups);
|
|
1765
1767
|
}
|
|
1766
1768
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
1767
1769
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -1827,8 +1829,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
1827
1829
|
function buildVirtualTx(inputs, outputs) {
|
|
1828
1830
|
let lockTime = 0n;
|
|
1829
1831
|
for (const input of inputs) {
|
|
1830
|
-
const tapscript =
|
|
1831
|
-
if (
|
|
1832
|
+
const tapscript = chunkWMIPYZSB_cjs.decodeTapscript(chunkWMIPYZSB_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
1833
|
+
if (chunkWMIPYZSB_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
1832
1834
|
if (lockTime !== 0n) {
|
|
1833
1835
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
1834
1836
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -1839,7 +1841,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
1839
1841
|
}
|
|
1840
1842
|
}
|
|
1841
1843
|
}
|
|
1842
|
-
const tx = new
|
|
1844
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction({
|
|
1843
1845
|
version: 3,
|
|
1844
1846
|
lockTime: Number(lockTime)
|
|
1845
1847
|
});
|
|
@@ -1849,12 +1851,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
1849
1851
|
index: input.vout,
|
|
1850
1852
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
1851
1853
|
witnessUtxo: {
|
|
1852
|
-
script:
|
|
1854
|
+
script: chunkWMIPYZSB_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
1853
1855
|
amount: BigInt(input.value)
|
|
1854
1856
|
},
|
|
1855
1857
|
tapLeafScript: [input.tapLeafScript]
|
|
1856
1858
|
});
|
|
1857
|
-
|
|
1859
|
+
chunk6FLL2Q36_cjs.setArkPsbtField(tx, i, chunk6FLL2Q36_cjs.VtxoTaprootTree, input.tapTree);
|
|
1858
1860
|
}
|
|
1859
1861
|
for (const output of outputs) {
|
|
1860
1862
|
tx.addOutput(output);
|
|
@@ -1863,8 +1865,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
1863
1865
|
return tx;
|
|
1864
1866
|
}
|
|
1865
1867
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
1866
|
-
const collaborativeClosure =
|
|
1867
|
-
const checkpointVtxoScript = new
|
|
1868
|
+
const collaborativeClosure = chunkWMIPYZSB_cjs.decodeTapscript(chunkWMIPYZSB_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
1869
|
+
const checkpointVtxoScript = new chunkWMIPYZSB_cjs.VtxoScript([
|
|
1868
1870
|
serverUnrollScript.script,
|
|
1869
1871
|
collaborativeClosure.script
|
|
1870
1872
|
]);
|
|
@@ -1998,7 +2000,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
1998
2000
|
}
|
|
1999
2001
|
function isValidArkAddress(address) {
|
|
2000
2002
|
try {
|
|
2001
|
-
|
|
2003
|
+
chunkWMIPYZSB_cjs.ArkAddress.decode(address);
|
|
2002
2004
|
return true;
|
|
2003
2005
|
} catch (e) {
|
|
2004
2006
|
return false;
|
|
@@ -2263,6 +2265,77 @@ function parseProgram(text, env) {
|
|
|
2263
2265
|
}
|
|
2264
2266
|
return { program, text };
|
|
2265
2267
|
}
|
|
2268
|
+
var DUST_AMOUNT = 546;
|
|
2269
|
+
var FALLBACK_WALLET_DUST_AMOUNT = 330n;
|
|
2270
|
+
function getDustAmount(wallet) {
|
|
2271
|
+
return "dustAmount" in wallet ? wallet.dustAmount : FALLBACK_WALLET_DUST_AMOUNT;
|
|
2272
|
+
}
|
|
2273
|
+
function extendCoin(wallet, utxo) {
|
|
2274
|
+
return {
|
|
2275
|
+
...utxo,
|
|
2276
|
+
forfeitTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
2277
|
+
intentTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
2278
|
+
tapTree: wallet.boardingTapscript.encode()
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
function extendVtxoFromContract(vtxo, contract) {
|
|
2282
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(contract.type);
|
|
2283
|
+
if (!handler) {
|
|
2284
|
+
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
2285
|
+
}
|
|
2286
|
+
const script = handler.createScript(contract.params);
|
|
2287
|
+
return {
|
|
2288
|
+
...vtxo,
|
|
2289
|
+
forfeitTapLeafScript: script.forfeit(),
|
|
2290
|
+
intentTapLeafScript: script.forfeit(),
|
|
2291
|
+
tapTree: script.encode()
|
|
2292
|
+
};
|
|
2293
|
+
}
|
|
2294
|
+
function extendVirtualCoinForContract(vtxo, contractOrMap) {
|
|
2295
|
+
const contract = resolveContract(vtxo, contractOrMap);
|
|
2296
|
+
if (!contract) {
|
|
2297
|
+
throw new Error(
|
|
2298
|
+
"extendVirtualCoinForContract: no contract matched vtxo.script \u2014 callers must resolve the owning contract before annotating"
|
|
2299
|
+
);
|
|
2300
|
+
}
|
|
2301
|
+
return extendVtxoFromContract(vtxo, contract);
|
|
2302
|
+
}
|
|
2303
|
+
function isContractMap(value) {
|
|
2304
|
+
return typeof value.get === "function";
|
|
2305
|
+
}
|
|
2306
|
+
function resolveContract(vtxo, contractOrMap) {
|
|
2307
|
+
if (!contractOrMap) return void 0;
|
|
2308
|
+
if (isContractMap(contractOrMap)) {
|
|
2309
|
+
return contractOrMap.get(vtxo.script);
|
|
2310
|
+
}
|
|
2311
|
+
return contractOrMap;
|
|
2312
|
+
}
|
|
2313
|
+
function getRandomId() {
|
|
2314
|
+
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
2315
|
+
return base.hex.encode(randomValue);
|
|
2316
|
+
}
|
|
2317
|
+
function validateRecipients(recipients, dustAmount) {
|
|
2318
|
+
const validatedRecipients = [];
|
|
2319
|
+
for (const recipient of recipients) {
|
|
2320
|
+
let address;
|
|
2321
|
+
try {
|
|
2322
|
+
address = chunkWMIPYZSB_cjs.ArkAddress.decode(recipient.address);
|
|
2323
|
+
} catch (e) {
|
|
2324
|
+
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
2325
|
+
}
|
|
2326
|
+
const amount = recipient.amount || dustAmount;
|
|
2327
|
+
if (amount <= 0) {
|
|
2328
|
+
throw new Error("Amount must be positive");
|
|
2329
|
+
}
|
|
2330
|
+
validatedRecipients.push({
|
|
2331
|
+
address: recipient.address,
|
|
2332
|
+
assets: recipient.assets ?? [],
|
|
2333
|
+
amount,
|
|
2334
|
+
script: amount < dustAmount ? address.subdustPkScript : address.pkScript
|
|
2335
|
+
});
|
|
2336
|
+
}
|
|
2337
|
+
return validatedRecipients;
|
|
2338
|
+
}
|
|
2266
2339
|
|
|
2267
2340
|
// src/wallet/vtxo-manager.ts
|
|
2268
2341
|
function isSweepCapable(wallet) {
|
|
@@ -2287,7 +2360,7 @@ async function runWithCrossInstanceLock(name, fn) {
|
|
|
2287
2360
|
await fn();
|
|
2288
2361
|
});
|
|
2289
2362
|
}
|
|
2290
|
-
var DEFAULT_THRESHOLD_SECONDS =
|
|
2363
|
+
var DEFAULT_THRESHOLD_SECONDS = 259200;
|
|
2291
2364
|
var DEFAULT_THRESHOLD_MS = DEFAULT_THRESHOLD_SECONDS * 1e3;
|
|
2292
2365
|
var DEFAULT_RENEWAL_CONFIG = {
|
|
2293
2366
|
thresholdMs: DEFAULT_THRESHOLD_MS
|
|
@@ -2298,18 +2371,15 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
2298
2371
|
boardingUtxoSweep: true,
|
|
2299
2372
|
pollIntervalMs: 6e4
|
|
2300
2373
|
};
|
|
2301
|
-
function getDustAmount(wallet) {
|
|
2302
|
-
return "dustAmount" in wallet ? wallet.dustAmount : 330n;
|
|
2303
|
-
}
|
|
2304
2374
|
function getRecoverableVtxos(vtxos, dustAmount) {
|
|
2305
2375
|
return vtxos.filter((vtxo) => {
|
|
2306
|
-
if (
|
|
2376
|
+
if (isRecoverable(vtxo)) {
|
|
2307
2377
|
return true;
|
|
2308
2378
|
}
|
|
2309
|
-
if (
|
|
2379
|
+
if (isSpendable(vtxo) && isExpired(vtxo)) {
|
|
2310
2380
|
return true;
|
|
2311
2381
|
}
|
|
2312
|
-
if (vtxo.virtualStatus.state === "preconfirmed" &&
|
|
2382
|
+
if (vtxo.virtualStatus.state === "preconfirmed" && isSubdust(vtxo, dustAmount)) {
|
|
2313
2383
|
return true;
|
|
2314
2384
|
}
|
|
2315
2385
|
return false;
|
|
@@ -2320,7 +2390,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount) {
|
|
|
2320
2390
|
const subdust = [];
|
|
2321
2391
|
const regular = [];
|
|
2322
2392
|
for (const vtxo of recoverableVtxos) {
|
|
2323
|
-
if (
|
|
2393
|
+
if (isSubdust(vtxo, dustAmount)) {
|
|
2324
2394
|
subdust.push(vtxo);
|
|
2325
2395
|
} else {
|
|
2326
2396
|
regular.push(vtxo);
|
|
@@ -2350,7 +2420,7 @@ function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
|
2350
2420
|
}
|
|
2351
2421
|
function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount) {
|
|
2352
2422
|
return vtxos.filter(
|
|
2353
|
-
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
2423
|
+
(vtxo) => isVtxoExpiringSoon(vtxo, thresholdMs) || isRecoverable(vtxo) || isSpendable(vtxo) && isExpired(vtxo) || isSubdust(vtxo, dustAmount)
|
|
2354
2424
|
);
|
|
2355
2425
|
}
|
|
2356
2426
|
var VtxoManager = class _VtxoManager {
|
|
@@ -2516,7 +2586,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2516
2586
|
* ```typescript
|
|
2517
2587
|
* const wallet = await Wallet.create({
|
|
2518
2588
|
* identity,
|
|
2519
|
-
*
|
|
2589
|
+
* arkProvider: new RestArkProvider(),
|
|
2520
2590
|
* settlementConfig: {
|
|
2521
2591
|
* vtxoThreshold: 86_400 // 24 hours
|
|
2522
2592
|
* },
|
|
@@ -2551,6 +2621,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2551
2621
|
* primary way to prevent virtual outputs from expiring.
|
|
2552
2622
|
*
|
|
2553
2623
|
* @param eventCallback - Optional callback for settlement events
|
|
2624
|
+
* @param options - Optional per-call overrides; see {@link RenewVtxosOptions}
|
|
2554
2625
|
* @returns Settlement transaction ID
|
|
2555
2626
|
* @throws Error if no virtual outputs available to renew
|
|
2556
2627
|
* @throws Error if total amount is below dust threshold
|
|
@@ -2566,15 +2637,33 @@ var VtxoManager = class _VtxoManager {
|
|
|
2566
2637
|
* const txid = await manager.renewVtxos((event) => {
|
|
2567
2638
|
* console.log('Settlement event:', event.type);
|
|
2568
2639
|
* });
|
|
2640
|
+
*
|
|
2641
|
+
* // Renew only VTXOs that expire within 6 hours
|
|
2642
|
+
* const txid = await manager.renewVtxos(undefined, { thresholdSeconds: 6 * 60 * 60 });
|
|
2569
2643
|
* ```
|
|
2570
2644
|
*/
|
|
2571
|
-
async renewVtxos(eventCallback) {
|
|
2645
|
+
async renewVtxos(eventCallback, options) {
|
|
2646
|
+
if (options?.thresholdSeconds !== void 0) {
|
|
2647
|
+
const { thresholdSeconds } = options;
|
|
2648
|
+
if (typeof thresholdSeconds !== "number" || !Number.isFinite(thresholdSeconds) || thresholdSeconds <= 0) {
|
|
2649
|
+
throw new TypeError(
|
|
2650
|
+
`Invalid thresholdSeconds: expected a positive finite number, got ${String(thresholdSeconds)}`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2572
2654
|
if (this.renewalInProgress) {
|
|
2573
2655
|
throw new Error("Renewal already in progress");
|
|
2574
2656
|
}
|
|
2575
2657
|
this.renewalInProgress = true;
|
|
2576
2658
|
try {
|
|
2577
|
-
|
|
2659
|
+
let threshold;
|
|
2660
|
+
if (options?.thresholdSeconds !== void 0) {
|
|
2661
|
+
threshold = options.thresholdSeconds * 1e3;
|
|
2662
|
+
} else if (this.settlementConfig !== false && this.settlementConfig?.vtxoThreshold !== void 0) {
|
|
2663
|
+
threshold = this.settlementConfig.vtxoThreshold * 1e3;
|
|
2664
|
+
} else {
|
|
2665
|
+
threshold = DEFAULT_RENEWAL_CONFIG.thresholdMs;
|
|
2666
|
+
}
|
|
2578
2667
|
let vtxos = await this.getExpiringVtxos(threshold);
|
|
2579
2668
|
if (vtxos.length === 0) {
|
|
2580
2669
|
throw new Error("No VTXOs available to renew");
|
|
@@ -2660,7 +2749,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2660
2749
|
* ```typescript
|
|
2661
2750
|
* const wallet = await Wallet.create({
|
|
2662
2751
|
* identity,
|
|
2663
|
-
*
|
|
2752
|
+
* arkProvider: new RestArkProvider(),
|
|
2664
2753
|
* settlementConfig: {
|
|
2665
2754
|
* boardingUtxoSweep: true,
|
|
2666
2755
|
* },
|
|
@@ -2690,7 +2779,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2690
2779
|
const boardingAddress = await this.wallet.getBoardingAddress();
|
|
2691
2780
|
const feeRate = await this.getOnchainProvider().getFeeRate() ?? 1;
|
|
2692
2781
|
const exitTapLeafScript = this.getBoardingExitLeaf();
|
|
2693
|
-
const sequence =
|
|
2782
|
+
const sequence = chunkWMIPYZSB_cjs.getSequence(exitTapLeafScript);
|
|
2694
2783
|
const leafScript = exitTapLeafScript[1];
|
|
2695
2784
|
const leafScriptSize = leafScript.length - 1;
|
|
2696
2785
|
const controlBlockSize = exitTapLeafScript[0].merklePath.length * 32;
|
|
@@ -2709,7 +2798,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2709
2798
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
2710
2799
|
);
|
|
2711
2800
|
}
|
|
2712
|
-
const tx = new
|
|
2801
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction();
|
|
2713
2802
|
for (const utxo of expiredUtxos) {
|
|
2714
2803
|
tx.addInput({
|
|
2715
2804
|
txid: utxo.txid,
|
|
@@ -2741,7 +2830,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2741
2830
|
/** Decodes the boarding tapscript exit path to extract the CSV timelock. */
|
|
2742
2831
|
getBoardingTimelock() {
|
|
2743
2832
|
const wallet = this.getSweepWallet();
|
|
2744
|
-
const exitScript =
|
|
2833
|
+
const exitScript = chunkWMIPYZSB_cjs.CSVMultisigTapscript.decode(
|
|
2745
2834
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
2746
2835
|
);
|
|
2747
2836
|
return exitScript.params.timelock;
|
|
@@ -2779,8 +2868,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
2779
2868
|
this.startBoardingUtxoPoll();
|
|
2780
2869
|
}, 1e3);
|
|
2781
2870
|
try {
|
|
2782
|
-
const [
|
|
2783
|
-
this.wallet.
|
|
2871
|
+
const [delegateManager, contractManager, destination] = await Promise.all([
|
|
2872
|
+
this.wallet.getDelegateManager(),
|
|
2784
2873
|
this.wallet.getContractManager(),
|
|
2785
2874
|
this.wallet.getAddress()
|
|
2786
2875
|
]);
|
|
@@ -2810,8 +2899,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
2810
2899
|
console.error("Error renewing VTXOs:", e);
|
|
2811
2900
|
});
|
|
2812
2901
|
}
|
|
2813
|
-
if (
|
|
2814
|
-
|
|
2902
|
+
if (delegateManager) {
|
|
2903
|
+
delegateManager.delegate(event.vtxos, destination).catch((e) => {
|
|
2815
2904
|
console.error("Error delegating VTXOs:", e);
|
|
2816
2905
|
});
|
|
2817
2906
|
}
|
|
@@ -2870,7 +2959,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
2870
2959
|
* or doesn't carry the metadata.
|
|
2871
2960
|
*/
|
|
2872
2961
|
extractSpentOutpoint(error) {
|
|
2873
|
-
const ark =
|
|
2962
|
+
const ark = chunk6FLL2Q36_cjs.maybeArkError(error);
|
|
2874
2963
|
if (!ark || ark.name !== "VTXO_ALREADY_SPENT") return void 0;
|
|
2875
2964
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
2876
2965
|
if (typeof raw !== "string") return void 0;
|
|
@@ -3070,7 +3159,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
3070
3159
|
const arkAddress = await this.wallet.getAddress();
|
|
3071
3160
|
const outputFee = estimator.evalOffchainOutput({
|
|
3072
3161
|
amount: totalAmount,
|
|
3073
|
-
script: base.hex.encode(
|
|
3162
|
+
script: base.hex.encode(chunkWMIPYZSB_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
3074
3163
|
});
|
|
3075
3164
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
3076
3165
|
if (totalAmount < dustAmount) return;
|
|
@@ -3151,7 +3240,7 @@ var ArkNote = class _ArkNote {
|
|
|
3151
3240
|
this.value = value;
|
|
3152
3241
|
this.HRP = HRP;
|
|
3153
3242
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
3154
|
-
this.vtxoScript = new
|
|
3243
|
+
this.vtxoScript = new chunkWMIPYZSB_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
3155
3244
|
const leaf = this.vtxoScript.leaves[0];
|
|
3156
3245
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
3157
3246
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -3252,73 +3341,6 @@ function readUInt32BE(array, offset) {
|
|
|
3252
3341
|
function noteTapscript(preimageHash) {
|
|
3253
3342
|
return btcSigner.Script.encode(["SHA256", preimageHash, "EQUAL"]);
|
|
3254
3343
|
}
|
|
3255
|
-
var DUST_AMOUNT = 546;
|
|
3256
|
-
function extendCoin(wallet, utxo) {
|
|
3257
|
-
return {
|
|
3258
|
-
...utxo,
|
|
3259
|
-
forfeitTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
3260
|
-
intentTapLeafScript: wallet.boardingTapscript.forfeit(),
|
|
3261
|
-
tapTree: wallet.boardingTapscript.encode()
|
|
3262
|
-
};
|
|
3263
|
-
}
|
|
3264
|
-
function extendVtxoFromContract(vtxo, contract) {
|
|
3265
|
-
const handler = chunkI3DGUUCT_cjs.contractHandlers.get(contract.type);
|
|
3266
|
-
if (!handler) {
|
|
3267
|
-
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
3268
|
-
}
|
|
3269
|
-
const script = handler.createScript(contract.params);
|
|
3270
|
-
return {
|
|
3271
|
-
...vtxo,
|
|
3272
|
-
forfeitTapLeafScript: script.forfeit(),
|
|
3273
|
-
intentTapLeafScript: script.forfeit(),
|
|
3274
|
-
tapTree: script.encode()
|
|
3275
|
-
};
|
|
3276
|
-
}
|
|
3277
|
-
function extendVirtualCoinForContract(vtxo, contractOrMap) {
|
|
3278
|
-
const contract = resolveContract(vtxo, contractOrMap);
|
|
3279
|
-
if (!contract) {
|
|
3280
|
-
throw new Error(
|
|
3281
|
-
"extendVirtualCoinForContract: no contract matched vtxo.script \u2014 callers must resolve the owning contract before annotating"
|
|
3282
|
-
);
|
|
3283
|
-
}
|
|
3284
|
-
return extendVtxoFromContract(vtxo, contract);
|
|
3285
|
-
}
|
|
3286
|
-
function isContractMap(value) {
|
|
3287
|
-
return typeof value.get === "function";
|
|
3288
|
-
}
|
|
3289
|
-
function resolveContract(vtxo, contractOrMap) {
|
|
3290
|
-
if (!contractOrMap) return void 0;
|
|
3291
|
-
if (isContractMap(contractOrMap)) {
|
|
3292
|
-
return contractOrMap.get(vtxo.script);
|
|
3293
|
-
}
|
|
3294
|
-
return contractOrMap;
|
|
3295
|
-
}
|
|
3296
|
-
function getRandomId() {
|
|
3297
|
-
const randomValue = crypto.getRandomValues(new Uint8Array(16));
|
|
3298
|
-
return base.hex.encode(randomValue);
|
|
3299
|
-
}
|
|
3300
|
-
function validateRecipients(recipients, dustAmount) {
|
|
3301
|
-
const validatedRecipients = [];
|
|
3302
|
-
for (const recipient of recipients) {
|
|
3303
|
-
let address;
|
|
3304
|
-
try {
|
|
3305
|
-
address = chunk5PG7DV7A_cjs.ArkAddress.decode(recipient.address);
|
|
3306
|
-
} catch (e) {
|
|
3307
|
-
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
3308
|
-
}
|
|
3309
|
-
const amount = recipient.amount || dustAmount;
|
|
3310
|
-
if (amount <= 0) {
|
|
3311
|
-
throw new Error("Amount must be positive");
|
|
3312
|
-
}
|
|
3313
|
-
validatedRecipients.push({
|
|
3314
|
-
address: recipient.address,
|
|
3315
|
-
assets: recipient.assets ?? [],
|
|
3316
|
-
amount,
|
|
3317
|
-
script: amount < dustAmount ? address.subdustPkScript : address.pkScript
|
|
3318
|
-
});
|
|
3319
|
-
}
|
|
3320
|
-
return validatedRecipients;
|
|
3321
|
-
}
|
|
3322
3344
|
var TxTree = class {
|
|
3323
3345
|
constructor(root, children = /* @__PURE__ */ new Map()) {
|
|
3324
3346
|
this.root = root;
|
|
@@ -3808,7 +3830,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3808
3830
|
const virtualCoins = await this.wallet.getVtxos({
|
|
3809
3831
|
withRecoverable: false
|
|
3810
3832
|
});
|
|
3811
|
-
const controlAssetRef = params.controlAssetId ?
|
|
3833
|
+
const controlAssetRef = params.controlAssetId ? chunk6FLL2Q36_cjs.AssetRef.fromId(chunk6FLL2Q36_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
3812
3834
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
3813
3835
|
let totalBtcSelected = 0n;
|
|
3814
3836
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -3821,8 +3843,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3821
3843
|
}
|
|
3822
3844
|
}
|
|
3823
3845
|
const groups = [];
|
|
3824
|
-
const issuedAssetOutput =
|
|
3825
|
-
const issuedAssetGroup =
|
|
3846
|
+
const issuedAssetOutput = chunk6FLL2Q36_cjs.AssetOutput.create(0, params.amount);
|
|
3847
|
+
const issuedAssetGroup = chunk6FLL2Q36_cjs.AssetGroup.create(
|
|
3826
3848
|
null,
|
|
3827
3849
|
controlAssetRef,
|
|
3828
3850
|
[],
|
|
@@ -3837,28 +3859,28 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3837
3859
|
for (const [inputIndex, assets] of assetInputs) {
|
|
3838
3860
|
for (const asset of assets) {
|
|
3839
3861
|
if (asset.assetId !== assetId) continue;
|
|
3840
|
-
changeInputs.push(
|
|
3862
|
+
changeInputs.push(chunk6FLL2Q36_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
3841
3863
|
}
|
|
3842
3864
|
}
|
|
3843
3865
|
groups.push(
|
|
3844
|
-
|
|
3845
|
-
|
|
3866
|
+
chunk6FLL2Q36_cjs.AssetGroup.create(
|
|
3867
|
+
chunk6FLL2Q36_cjs.AssetId.fromString(assetId),
|
|
3846
3868
|
null,
|
|
3847
3869
|
changeInputs,
|
|
3848
|
-
[
|
|
3870
|
+
[chunk6FLL2Q36_cjs.AssetOutput.create(0, amount)],
|
|
3849
3871
|
[]
|
|
3850
3872
|
)
|
|
3851
3873
|
);
|
|
3852
3874
|
}
|
|
3853
3875
|
}
|
|
3854
3876
|
const address = await this.wallet.getAddress();
|
|
3855
|
-
const outputAddress =
|
|
3877
|
+
const outputAddress = chunkWMIPYZSB_cjs.ArkAddress.decode(address);
|
|
3856
3878
|
const outputs = [
|
|
3857
3879
|
{
|
|
3858
3880
|
script: outputAddress.pkScript,
|
|
3859
3881
|
amount: BigInt(totalBtcSelected)
|
|
3860
3882
|
},
|
|
3861
|
-
Extension.create([
|
|
3883
|
+
Extension.create([chunk6FLL2Q36_cjs.Packet.create(groups)]).txOut()
|
|
3862
3884
|
];
|
|
3863
3885
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
|
|
3864
3886
|
coinSelection.inputs,
|
|
@@ -3866,7 +3888,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3866
3888
|
);
|
|
3867
3889
|
return {
|
|
3868
3890
|
arkTxId: arkTxid,
|
|
3869
|
-
assetId:
|
|
3891
|
+
assetId: chunk6FLL2Q36_cjs.AssetId.create(arkTxid, 0).toString()
|
|
3870
3892
|
};
|
|
3871
3893
|
}
|
|
3872
3894
|
/**
|
|
@@ -3938,16 +3960,16 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3938
3960
|
for (const [inputIndex, assets] of assetInputs) {
|
|
3939
3961
|
for (const asset of assets) {
|
|
3940
3962
|
if (asset.assetId !== params.assetId) continue;
|
|
3941
|
-
reissueInputs.push(
|
|
3963
|
+
reissueInputs.push(chunk6FLL2Q36_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
3942
3964
|
}
|
|
3943
3965
|
}
|
|
3944
3966
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
3945
|
-
const reissueAssetIdObj =
|
|
3946
|
-
const reissueAssetGroup =
|
|
3967
|
+
const reissueAssetIdObj = chunk6FLL2Q36_cjs.AssetId.fromString(params.assetId);
|
|
3968
|
+
const reissueAssetGroup = chunk6FLL2Q36_cjs.AssetGroup.create(
|
|
3947
3969
|
reissueAssetIdObj,
|
|
3948
3970
|
null,
|
|
3949
3971
|
reissueInputs,
|
|
3950
|
-
[
|
|
3972
|
+
[chunk6FLL2Q36_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
3951
3973
|
[]
|
|
3952
3974
|
);
|
|
3953
3975
|
const groups = [reissueAssetGroup];
|
|
@@ -3956,27 +3978,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
3956
3978
|
for (const [inputIndex, assets] of assetInputs) {
|
|
3957
3979
|
for (const asset of assets) {
|
|
3958
3980
|
if (asset.assetId !== assetId) continue;
|
|
3959
|
-
changeInputs.push(
|
|
3981
|
+
changeInputs.push(chunk6FLL2Q36_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
3960
3982
|
}
|
|
3961
3983
|
}
|
|
3962
3984
|
groups.push(
|
|
3963
|
-
|
|
3964
|
-
|
|
3985
|
+
chunk6FLL2Q36_cjs.AssetGroup.create(
|
|
3986
|
+
chunk6FLL2Q36_cjs.AssetId.fromString(assetId),
|
|
3965
3987
|
null,
|
|
3966
3988
|
changeInputs,
|
|
3967
|
-
[
|
|
3989
|
+
[chunk6FLL2Q36_cjs.AssetOutput.create(0, amount)],
|
|
3968
3990
|
[]
|
|
3969
3991
|
)
|
|
3970
3992
|
);
|
|
3971
3993
|
}
|
|
3972
3994
|
const address = await this.wallet.getAddress();
|
|
3973
|
-
const outputAddress =
|
|
3995
|
+
const outputAddress = chunkWMIPYZSB_cjs.ArkAddress.decode(address);
|
|
3974
3996
|
const outputs = [
|
|
3975
3997
|
{
|
|
3976
3998
|
script: outputAddress.pkScript,
|
|
3977
3999
|
amount: BigInt(totalBtcSelected)
|
|
3978
4000
|
},
|
|
3979
|
-
Extension.create([
|
|
4001
|
+
Extension.create([chunk6FLL2Q36_cjs.Packet.create(groups)]).txOut()
|
|
3980
4002
|
];
|
|
3981
4003
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
3982
4004
|
return arkTxid;
|
|
@@ -4043,27 +4065,27 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
4043
4065
|
for (const [inputIndex, assets] of assetInputs) {
|
|
4044
4066
|
for (const asset of assets) {
|
|
4045
4067
|
if (asset.assetId !== assetId) continue;
|
|
4046
|
-
changeInputs.push(
|
|
4068
|
+
changeInputs.push(chunk6FLL2Q36_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
4047
4069
|
}
|
|
4048
4070
|
}
|
|
4049
4071
|
groups.push(
|
|
4050
|
-
|
|
4051
|
-
|
|
4072
|
+
chunk6FLL2Q36_cjs.AssetGroup.create(
|
|
4073
|
+
chunk6FLL2Q36_cjs.AssetId.fromString(assetId),
|
|
4052
4074
|
null,
|
|
4053
4075
|
changeInputs,
|
|
4054
|
-
amount > 0n ? [
|
|
4076
|
+
amount > 0n ? [chunk6FLL2Q36_cjs.AssetOutput.create(0, amount)] : [],
|
|
4055
4077
|
[]
|
|
4056
4078
|
)
|
|
4057
4079
|
);
|
|
4058
4080
|
}
|
|
4059
4081
|
const address = await this.wallet.getAddress();
|
|
4060
|
-
const outputAddress =
|
|
4082
|
+
const outputAddress = chunkWMIPYZSB_cjs.ArkAddress.decode(address);
|
|
4061
4083
|
const outputs = [
|
|
4062
4084
|
{
|
|
4063
4085
|
script: outputAddress.pkScript,
|
|
4064
4086
|
amount: BigInt(totalBtcSelected)
|
|
4065
4087
|
},
|
|
4066
|
-
Extension.create([
|
|
4088
|
+
Extension.create([chunk6FLL2Q36_cjs.Packet.create(groups)]).txOut()
|
|
4067
4089
|
];
|
|
4068
4090
|
const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
|
|
4069
4091
|
return arkTxid;
|
|
@@ -4088,27 +4110,27 @@ function castMetadata(metadata) {
|
|
|
4088
4110
|
} else {
|
|
4089
4111
|
throw new Error("Invalid metadata value type");
|
|
4090
4112
|
}
|
|
4091
|
-
md.push(
|
|
4113
|
+
md.push(chunk6FLL2Q36_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
4092
4114
|
}
|
|
4093
4115
|
return md;
|
|
4094
4116
|
}
|
|
4095
|
-
var
|
|
4096
|
-
/** Create a
|
|
4097
|
-
constructor(
|
|
4098
|
-
this.
|
|
4117
|
+
var DelegateManagerImpl = class {
|
|
4118
|
+
/** Create a delegate manager from the configured provider, Arkade info source, and wallet identity. */
|
|
4119
|
+
constructor(delegateProvider, arkInfoProvider, identity) {
|
|
4120
|
+
this.delegateProvider = delegateProvider;
|
|
4099
4121
|
this.arkInfoProvider = arkInfoProvider;
|
|
4100
4122
|
this.identity = identity;
|
|
4101
4123
|
}
|
|
4102
4124
|
async getDelegateInfo() {
|
|
4103
|
-
return this.
|
|
4125
|
+
return this.delegateProvider.getDelegateInfo();
|
|
4104
4126
|
}
|
|
4105
4127
|
async delegate(vtxos, destination, delegateAt) {
|
|
4106
4128
|
if (vtxos.length === 0) {
|
|
4107
4129
|
return { delegated: [], failed: [] };
|
|
4108
4130
|
}
|
|
4109
|
-
const destinationScript =
|
|
4131
|
+
const destinationScript = chunkWMIPYZSB_cjs.ArkAddress.decode(destination).pkScript;
|
|
4110
4132
|
const arkInfo = await this.arkInfoProvider.getInfo();
|
|
4111
|
-
const delegateInfo = await this.
|
|
4133
|
+
const delegateInfo = await this.delegateProvider.getDelegateInfo();
|
|
4112
4134
|
const eligible = vtxos.filter(
|
|
4113
4135
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
4114
4136
|
);
|
|
@@ -4119,7 +4141,7 @@ var DelegatorManagerImpl = class {
|
|
|
4119
4141
|
try {
|
|
4120
4142
|
await delegate(
|
|
4121
4143
|
this.identity,
|
|
4122
|
-
this.
|
|
4144
|
+
this.delegateProvider,
|
|
4123
4145
|
arkInfo,
|
|
4124
4146
|
delegateInfo,
|
|
4125
4147
|
eligible,
|
|
@@ -4137,7 +4159,7 @@ var DelegatorManagerImpl = class {
|
|
|
4137
4159
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
4138
4160
|
let recoverableVtxos = [];
|
|
4139
4161
|
for (const vtxo of eligible) {
|
|
4140
|
-
if (
|
|
4162
|
+
if (isRecoverable(vtxo)) {
|
|
4141
4163
|
recoverableVtxos.push(vtxo);
|
|
4142
4164
|
continue;
|
|
4143
4165
|
}
|
|
@@ -4150,7 +4172,7 @@ var DelegatorManagerImpl = class {
|
|
|
4150
4172
|
try {
|
|
4151
4173
|
await delegate(
|
|
4152
4174
|
this.identity,
|
|
4153
|
-
this.
|
|
4175
|
+
this.delegateProvider,
|
|
4154
4176
|
arkInfo,
|
|
4155
4177
|
delegateInfo,
|
|
4156
4178
|
recoverableVtxos,
|
|
@@ -4175,7 +4197,7 @@ var DelegatorManagerImpl = class {
|
|
|
4175
4197
|
groupsList.map(
|
|
4176
4198
|
async ([, vtxosGroup]) => delegate(
|
|
4177
4199
|
this.identity,
|
|
4178
|
-
this.
|
|
4200
|
+
this.delegateProvider,
|
|
4179
4201
|
arkInfo,
|
|
4180
4202
|
delegateInfo,
|
|
4181
4203
|
vtxosGroup,
|
|
@@ -4196,15 +4218,16 @@ var DelegatorManagerImpl = class {
|
|
|
4196
4218
|
return { delegated, failed };
|
|
4197
4219
|
}
|
|
4198
4220
|
};
|
|
4199
|
-
|
|
4221
|
+
var DelegatorManagerImpl = DelegateManagerImpl;
|
|
4222
|
+
async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos, destinationScript, delegateAt) {
|
|
4200
4223
|
if (vtxos.length === 0) {
|
|
4201
4224
|
throw new Error("unable to delegate: no vtxos provided");
|
|
4202
4225
|
}
|
|
4203
|
-
if (!
|
|
4204
|
-
throw new Error("unable to delegate:
|
|
4226
|
+
if (!delegateProvider) {
|
|
4227
|
+
throw new Error("unable to delegate: delegate provider not configured");
|
|
4205
4228
|
}
|
|
4206
4229
|
if (!delegateAt) {
|
|
4207
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
4230
|
+
const expiryTimestamp = vtxos.filter((coin) => !isRecoverable(coin) && coin.virtualStatus.batchExpiry).reduce(
|
|
4208
4231
|
(min, coin) => Math.min(min, coin.virtualStatus.batchExpiry),
|
|
4209
4232
|
Number.MAX_SAFE_INTEGER
|
|
4210
4233
|
);
|
|
@@ -4247,13 +4270,14 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4247
4270
|
}
|
|
4248
4271
|
amount += BigInt(coin.value) - BigInt(inputFee.value);
|
|
4249
4272
|
}
|
|
4250
|
-
const {
|
|
4273
|
+
const { pubkey, fee } = delegateInfo;
|
|
4274
|
+
const delegateAddress = delegateInfo.delegateAddress;
|
|
4251
4275
|
const outputs = [];
|
|
4252
|
-
const
|
|
4253
|
-
if (
|
|
4276
|
+
const delegateFee = BigInt(Number(fee));
|
|
4277
|
+
if (delegateFee > 0n) {
|
|
4254
4278
|
outputs.push({
|
|
4255
|
-
script:
|
|
4256
|
-
amount:
|
|
4279
|
+
script: chunkWMIPYZSB_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
4280
|
+
amount: delegateFee
|
|
4257
4281
|
});
|
|
4258
4282
|
}
|
|
4259
4283
|
const outputFee = outputs.reduce((fee2, output) => {
|
|
@@ -4267,7 +4291,7 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4267
4291
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
4268
4292
|
}
|
|
4269
4293
|
amount -= BigInt(outputFee);
|
|
4270
|
-
amount -=
|
|
4294
|
+
amount -= delegateFee;
|
|
4271
4295
|
if (amount <= dust) {
|
|
4272
4296
|
throw new Error("Amount is below dust limit, cannot delegate");
|
|
4273
4297
|
}
|
|
@@ -4285,10 +4309,10 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4285
4309
|
destinationScript
|
|
4286
4310
|
);
|
|
4287
4311
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
4288
|
-
btcSigner.Address(getNetwork(network)).decode(forfeitAddress)
|
|
4312
|
+
btcSigner.Address(chunkWMIPYZSB_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
4289
4313
|
);
|
|
4290
4314
|
const forfeits = await Promise.all(
|
|
4291
|
-
vtxos.filter((v) => !
|
|
4315
|
+
vtxos.filter((v) => !isRecoverable(v)).map(async (coin) => {
|
|
4292
4316
|
const forfeit = await makeDelegateForfeitTx(
|
|
4293
4317
|
coin,
|
|
4294
4318
|
dust,
|
|
@@ -4299,7 +4323,7 @@ async function delegate(identity, delegatorProvider, arkInfo, delegateInfo, vtxo
|
|
|
4299
4323
|
return base.base64.encode(forfeit.toPSBT());
|
|
4300
4324
|
})
|
|
4301
4325
|
);
|
|
4302
|
-
await
|
|
4326
|
+
await delegateProvider.delegate(registerIntent, forfeits);
|
|
4303
4327
|
}
|
|
4304
4328
|
async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, forfeitOutputScript, identity) {
|
|
4305
4329
|
const delegateTapLeaf = findDelegateTapLeaf(input, delegatePubkey);
|
|
@@ -4313,7 +4337,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
4313
4337
|
index: input.vout,
|
|
4314
4338
|
witnessUtxo: {
|
|
4315
4339
|
amount: BigInt(input.value),
|
|
4316
|
-
script:
|
|
4340
|
+
script: chunkWMIPYZSB_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
4317
4341
|
},
|
|
4318
4342
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
4319
4343
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -4371,7 +4395,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
4371
4395
|
expire_at: 0,
|
|
4372
4396
|
cosigners_public_keys: cosignerPubKeys
|
|
4373
4397
|
};
|
|
4374
|
-
const proof =
|
|
4398
|
+
const proof = chunk6FLL2Q36_cjs.Intent.create(message, coins, outputs);
|
|
4375
4399
|
const signedProof = await identity.sign(proof);
|
|
4376
4400
|
return {
|
|
4377
4401
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -4389,10 +4413,10 @@ function getDayTimestamp(timestamp) {
|
|
|
4389
4413
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
4390
4414
|
if (!vtxo.tapTree) return void 0;
|
|
4391
4415
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
4392
|
-
const vtxoScript =
|
|
4416
|
+
const vtxoScript = chunkWMIPYZSB_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
4393
4417
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
4394
|
-
const arkTapscript =
|
|
4395
|
-
if (!
|
|
4418
|
+
const arkTapscript = chunkWMIPYZSB_cjs.decodeTapscript(chunkWMIPYZSB_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
4419
|
+
if (!chunkWMIPYZSB_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
4396
4420
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
4397
4421
|
});
|
|
4398
4422
|
}
|
|
@@ -4596,7 +4620,7 @@ var InMemoryContractRepository = class {
|
|
|
4596
4620
|
}
|
|
4597
4621
|
};
|
|
4598
4622
|
function scriptFromArkAddress(address) {
|
|
4599
|
-
return base.hex.encode(
|
|
4623
|
+
return base.hex.encode(chunkWMIPYZSB_cjs.ArkAddress.decode(address).pkScript);
|
|
4600
4624
|
}
|
|
4601
4625
|
|
|
4602
4626
|
// src/repositories/indexedDB/schema.ts
|
|
@@ -6111,7 +6135,7 @@ var ContractWatcher = class {
|
|
|
6111
6135
|
this.connectionState = "connected";
|
|
6112
6136
|
this.reconnectAttempts = 0;
|
|
6113
6137
|
this.listenLoop().catch((e) => {
|
|
6114
|
-
if (
|
|
6138
|
+
if (chunk6FLL2Q36_cjs.isEventSourceError(e)) {
|
|
6115
6139
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
6116
6140
|
} else {
|
|
6117
6141
|
console.error(e);
|
|
@@ -6551,7 +6575,7 @@ var ContractManager = class _ContractManager {
|
|
|
6551
6575
|
* `persisted` is `true`.
|
|
6552
6576
|
*/
|
|
6553
6577
|
async upsertContract(params) {
|
|
6554
|
-
const handler =
|
|
6578
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(params.type);
|
|
6555
6579
|
if (!handler) {
|
|
6556
6580
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
6557
6581
|
}
|
|
@@ -6612,7 +6636,7 @@ var ContractManager = class _ContractManager {
|
|
|
6612
6636
|
`scanContracts: gapLimit must be a positive integer (got ${String(opts.gapLimit)})`
|
|
6613
6637
|
);
|
|
6614
6638
|
}
|
|
6615
|
-
const discoverables =
|
|
6639
|
+
const discoverables = chunkIEO3XDKI_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkIEO3XDKI_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
6616
6640
|
const maxIdx = opts.hd ? SCAN_MAX_INDEX : 0;
|
|
6617
6641
|
const handlerErrors = [];
|
|
6618
6642
|
let lastIndexUsed = -1;
|
|
@@ -6767,7 +6791,7 @@ var ContractManager = class _ContractManager {
|
|
|
6767
6791
|
const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
|
|
6768
6792
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
6769
6793
|
if (!contract) return [];
|
|
6770
|
-
const handler =
|
|
6794
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(contract.type);
|
|
6771
6795
|
if (!handler) return [];
|
|
6772
6796
|
const script = handler.createScript(contract.params);
|
|
6773
6797
|
const context = {
|
|
@@ -6787,7 +6811,7 @@ var ContractManager = class _ContractManager {
|
|
|
6787
6811
|
const { contractScript, collaborative = true, walletPubKey } = options;
|
|
6788
6812
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
6789
6813
|
if (!contract) return [];
|
|
6790
|
-
const handler =
|
|
6814
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(contract.type);
|
|
6791
6815
|
if (!handler) return [];
|
|
6792
6816
|
const script = handler.createScript(contract.params);
|
|
6793
6817
|
const context = {
|
|
@@ -7197,7 +7221,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
7197
7221
|
*/
|
|
7198
7222
|
materializeDescriptorAt(index) {
|
|
7199
7223
|
const descriptor = this.identity.descriptor;
|
|
7200
|
-
const network =
|
|
7224
|
+
const network = chunkIEO3XDKI_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
7201
7225
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
7202
7226
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
7203
7227
|
if (!keyInfo?.keyExpression) {
|
|
@@ -7340,7 +7364,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
7340
7364
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
7341
7365
|
if (!provider) return void 0;
|
|
7342
7366
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
7343
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
7367
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkIEO3XDKI_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
7344
7368
|
const factoryOpts = {
|
|
7345
7369
|
walletRepository: setup.walletRepository,
|
|
7346
7370
|
contractRepository: setup.contractRepository,
|
|
@@ -7502,8 +7526,8 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
7502
7526
|
const newScript = base.hex.encode(newTapscript.pkScript);
|
|
7503
7527
|
const newAddress = newTapscript.address(wallet.network.hrp, wallet.arkServerPublicKey).encode();
|
|
7504
7528
|
const manager = await wallet.getContractManager();
|
|
7505
|
-
const csvTimelock = newTapscript.options.csvTimelock ??
|
|
7506
|
-
const csvTimelockStr =
|
|
7529
|
+
const csvTimelock = newTapscript.options.csvTimelock ?? chunkIEO3XDKI_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
7530
|
+
const csvTimelockStr = chunkWMIPYZSB_cjs.timelockToSequence(csvTimelock).toString();
|
|
7507
7531
|
const serverPubKeyHex = base.hex.encode(newTapscript.options.serverPubKey);
|
|
7508
7532
|
const baseParams = {
|
|
7509
7533
|
script: newScript,
|
|
@@ -7517,11 +7541,11 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
7517
7541
|
// produce unsigned PSBTs that the server rejects with
|
|
7518
7542
|
// `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
7519
7543
|
metadata: {
|
|
7520
|
-
source:
|
|
7544
|
+
source: chunkIEO3XDKI_cjs.WALLET_RECEIVE_SOURCE,
|
|
7521
7545
|
signingDescriptor: descriptor
|
|
7522
7546
|
}
|
|
7523
7547
|
};
|
|
7524
|
-
if (newTapscript instanceof
|
|
7548
|
+
if (newTapscript instanceof chunkIEO3XDKI_cjs.DelegateVtxo.Script) {
|
|
7525
7549
|
await manager.createContract({
|
|
7526
7550
|
...baseParams,
|
|
7527
7551
|
type: "delegate",
|
|
@@ -7553,7 +7577,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
7553
7577
|
};
|
|
7554
7578
|
function deriveLeafPubkey(descriptor) {
|
|
7555
7579
|
try {
|
|
7556
|
-
return
|
|
7580
|
+
return chunkIEO3XDKI_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
7557
7581
|
} catch (e) {
|
|
7558
7582
|
throw new NonRangeableDescriptorError(
|
|
7559
7583
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -7562,10 +7586,10 @@ function deriveLeafPubkey(descriptor) {
|
|
|
7562
7586
|
}
|
|
7563
7587
|
}
|
|
7564
7588
|
function rebuildTapscript(current, pubKey) {
|
|
7565
|
-
if (current instanceof
|
|
7566
|
-
return new
|
|
7589
|
+
if (current instanceof chunkIEO3XDKI_cjs.DelegateVtxo.Script) {
|
|
7590
|
+
return new chunkIEO3XDKI_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
7567
7591
|
}
|
|
7568
|
-
return new
|
|
7592
|
+
return new chunkIEO3XDKI_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
7569
7593
|
}
|
|
7570
7594
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
7571
7595
|
const candidates = await contractRepository.getContracts({
|
|
@@ -7574,7 +7598,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
|
|
|
7574
7598
|
});
|
|
7575
7599
|
const serverPubKeyHex = base.hex.encode(serverPubKey);
|
|
7576
7600
|
const matching = candidates.filter(
|
|
7577
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
7601
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkIEO3XDKI_cjs.WALLET_RECEIVE_SOURCE
|
|
7578
7602
|
).sort((a, b) => {
|
|
7579
7603
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
7580
7604
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -7709,12 +7733,12 @@ var InputSignerRouter = class {
|
|
|
7709
7733
|
};
|
|
7710
7734
|
|
|
7711
7735
|
// src/wallet/wallet.ts
|
|
7712
|
-
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl ||
|
|
7736
|
+
var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkWMIPYZSB_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
7713
7737
|
function intentProofJobs(coins) {
|
|
7714
7738
|
if (coins.length === 0) return [];
|
|
7715
7739
|
const coinJobs = coins.map((coin, i) => ({
|
|
7716
7740
|
index: i + 1,
|
|
7717
|
-
lookupScript:
|
|
7741
|
+
lookupScript: chunkWMIPYZSB_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
7718
7742
|
}));
|
|
7719
7743
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
7720
7744
|
}
|
|
@@ -7733,7 +7757,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
7733
7757
|
const seen = /* @__PURE__ */ new Set();
|
|
7734
7758
|
const deduped = [];
|
|
7735
7759
|
for (const timelock of timelocks) {
|
|
7736
|
-
const sequence =
|
|
7760
|
+
const sequence = chunkWMIPYZSB_cjs.timelockToSequence(timelock).toString();
|
|
7737
7761
|
if (seen.has(sequence)) continue;
|
|
7738
7762
|
seen.add(sequence);
|
|
7739
7763
|
deduped.push(timelock);
|
|
@@ -7744,7 +7768,7 @@ function hasToReadonly(identity) {
|
|
|
7744
7768
|
return typeof identity === "object" && identity !== null && "toReadonly" in identity && typeof identity.toReadonly === "function";
|
|
7745
7769
|
}
|
|
7746
7770
|
var ReadonlyWallet = class _ReadonlyWallet {
|
|
7747
|
-
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository,
|
|
7771
|
+
constructor(identity, network, onchainProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, dustAmount, walletRepository, contractRepository, delegateProvider, watcherConfig, walletContractTimelocks) {
|
|
7748
7772
|
this.identity = identity;
|
|
7749
7773
|
this.network = network;
|
|
7750
7774
|
this.onchainProvider = onchainProvider;
|
|
@@ -7754,7 +7778,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7754
7778
|
this.dustAmount = dustAmount;
|
|
7755
7779
|
this.walletRepository = walletRepository;
|
|
7756
7780
|
this.contractRepository = contractRepository;
|
|
7757
|
-
this.
|
|
7781
|
+
this.delegateProvider = delegateProvider;
|
|
7758
7782
|
if ("descriptor" in identity) {
|
|
7759
7783
|
const descriptor = identity.descriptor;
|
|
7760
7784
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -7769,7 +7793,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7769
7793
|
this.watcherConfig = watcherConfig;
|
|
7770
7794
|
this._assetManager = new ReadonlyAssetManager(this.indexerProvider);
|
|
7771
7795
|
this.walletContractTimelocks = walletContractTimelocks && walletContractTimelocks.length > 0 ? dedupeTimelocks(walletContractTimelocks) : [
|
|
7772
|
-
this.offchainTapscript.options.csvTimelock ??
|
|
7796
|
+
this.offchainTapscript.options.csvTimelock ?? chunkIEO3XDKI_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK
|
|
7773
7797
|
];
|
|
7774
7798
|
}
|
|
7775
7799
|
_contractManager;
|
|
@@ -7808,7 +7832,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7808
7832
|
*/
|
|
7809
7833
|
static async setupWalletConfig(config, pubKey) {
|
|
7810
7834
|
const arkadeServerUrl = getArkadeServerUrl(config);
|
|
7811
|
-
const arkProvider = config.arkProvider
|
|
7835
|
+
const arkProvider = config.arkProvider || new chunk6FLL2Q36_cjs.RestArkProvider(arkadeServerUrl);
|
|
7812
7836
|
let indexerProvider = config.indexerProvider;
|
|
7813
7837
|
if (!indexerProvider) {
|
|
7814
7838
|
let indexerUrl = config.indexerUrl;
|
|
@@ -7825,10 +7849,10 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7825
7849
|
indexerUrl = arkadeServerUrl;
|
|
7826
7850
|
}
|
|
7827
7851
|
}
|
|
7828
|
-
indexerProvider = new
|
|
7852
|
+
indexerProvider = new chunk6FLL2Q36_cjs.RestIndexerProvider(indexerUrl);
|
|
7829
7853
|
}
|
|
7830
7854
|
const info = await arkProvider.getInfo();
|
|
7831
|
-
const network = getNetwork(info.network);
|
|
7855
|
+
const network = chunkWMIPYZSB_cjs.getNetwork(info.network);
|
|
7832
7856
|
if ("descriptor" in config.identity) {
|
|
7833
7857
|
const descriptor = config.identity.descriptor;
|
|
7834
7858
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -7869,14 +7893,14 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7869
7893
|
type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
|
|
7870
7894
|
};
|
|
7871
7895
|
const serverPubKey = base.hex.decode(info.signerPubkey).slice(1);
|
|
7872
|
-
const delegatePubKey = config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => base.hex.decode(info2.pubkey).slice(1)) : void 0;
|
|
7896
|
+
const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => base.hex.decode(info2.pubkey).slice(1)) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => base.hex.decode(info2.pubkey).slice(1)) : void 0;
|
|
7873
7897
|
const offchainOptions = {
|
|
7874
7898
|
pubKey,
|
|
7875
7899
|
serverPubKey,
|
|
7876
7900
|
csvTimelock: exitTimelock
|
|
7877
7901
|
};
|
|
7878
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
7879
|
-
const boardingTapscript = new
|
|
7902
|
+
const offchainTapscript = !delegatePubKey ? new chunkIEO3XDKI_cjs.DefaultVtxo.Script(offchainOptions) : new chunkIEO3XDKI_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
7903
|
+
const boardingTapscript = new chunkIEO3XDKI_cjs.DefaultVtxo.Script({
|
|
7880
7904
|
...offchainOptions,
|
|
7881
7905
|
csvTimelock: boardingTimelock
|
|
7882
7906
|
});
|
|
@@ -7895,7 +7919,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7895
7919
|
walletRepository,
|
|
7896
7920
|
contractRepository,
|
|
7897
7921
|
info,
|
|
7898
|
-
|
|
7922
|
+
delegateProvider: config.delegateProvider || config.delegatorProvider,
|
|
7923
|
+
/** @deprecated alias for `delegateProvider` */
|
|
7924
|
+
delegatorProvider: config.delegateProvider || config.delegatorProvider,
|
|
7899
7925
|
walletContractTimelocks
|
|
7900
7926
|
};
|
|
7901
7927
|
}
|
|
@@ -7922,7 +7948,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7922
7948
|
setup.dustAmount,
|
|
7923
7949
|
setup.walletRepository,
|
|
7924
7950
|
setup.contractRepository,
|
|
7925
|
-
setup.delegatorProvider,
|
|
7951
|
+
setup.delegateProvider || setup.delegatorProvider,
|
|
7926
7952
|
config.watcherConfig,
|
|
7927
7953
|
setup.walletContractTimelocks
|
|
7928
7954
|
);
|
|
@@ -7967,12 +7993,12 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
7967
7993
|
let recoverable = 0;
|
|
7968
7994
|
settled = vtxos.filter((coin) => coin.virtualStatus.state === "settled").reduce((sum, coin) => sum + coin.value, 0);
|
|
7969
7995
|
preconfirmed = vtxos.filter((coin) => coin.virtualStatus.state === "preconfirmed").reduce((sum, coin) => sum + coin.value, 0);
|
|
7970
|
-
recoverable = vtxos.filter((coin) =>
|
|
7996
|
+
recoverable = vtxos.filter((coin) => isSpendable(coin) && coin.virtualStatus.state === "swept").reduce((sum, coin) => sum + coin.value, 0);
|
|
7971
7997
|
const totalBoarding = confirmed + unconfirmed;
|
|
7972
7998
|
const totalOffchain = settled + preconfirmed + recoverable;
|
|
7973
7999
|
const assetBalances = /* @__PURE__ */ new Map();
|
|
7974
8000
|
for (const vtxo of vtxos) {
|
|
7975
|
-
if (!
|
|
8001
|
+
if (!isSpendable(vtxo)) continue;
|
|
7976
8002
|
if (vtxo.assets) {
|
|
7977
8003
|
for (const a of vtxo.assets) {
|
|
7978
8004
|
const current = assetBalances.get(a.assetId) ?? 0n;
|
|
@@ -8011,8 +8037,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8011
8037
|
if (this._pendingSpendOutpoints.has(`${vtxo.txid}:${vtxo.vout}`)) {
|
|
8012
8038
|
return false;
|
|
8013
8039
|
}
|
|
8014
|
-
if (
|
|
8015
|
-
if (!f.withRecoverable && (
|
|
8040
|
+
if (isSpendable(vtxo)) {
|
|
8041
|
+
if (!f.withRecoverable && (isRecoverable(vtxo) || isExpired(vtxo))) {
|
|
8016
8042
|
return false;
|
|
8017
8043
|
}
|
|
8018
8044
|
return true;
|
|
@@ -8216,7 +8242,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8216
8242
|
});
|
|
8217
8243
|
for (const contract of contracts) {
|
|
8218
8244
|
if (map.has(contract.script)) continue;
|
|
8219
|
-
const handler =
|
|
8245
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(contract.type);
|
|
8220
8246
|
if (handler) {
|
|
8221
8247
|
const script = handler.createScript(contract.params);
|
|
8222
8248
|
map.set(contract.script, script);
|
|
@@ -8282,8 +8308,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8282
8308
|
});
|
|
8283
8309
|
const baselinePubkey = await this.identity.xOnlyPublicKey();
|
|
8284
8310
|
for (const csvTimelock of this.walletContractTimelocks) {
|
|
8285
|
-
const csvTimelockStr =
|
|
8286
|
-
const defaultScript = new
|
|
8311
|
+
const csvTimelockStr = chunkWMIPYZSB_cjs.timelockToSequence(csvTimelock).toString();
|
|
8312
|
+
const defaultScript = new chunkIEO3XDKI_cjs.DefaultVtxo.Script({
|
|
8287
8313
|
pubKey: baselinePubkey,
|
|
8288
8314
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
8289
8315
|
csvTimelock
|
|
@@ -8300,8 +8326,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8300
8326
|
address: defaultScript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
8301
8327
|
state: "active"
|
|
8302
8328
|
});
|
|
8303
|
-
if (this.offchainTapscript instanceof
|
|
8304
|
-
const delegateScript = new
|
|
8329
|
+
if (this.offchainTapscript instanceof chunkIEO3XDKI_cjs.DelegateVtxo.Script) {
|
|
8330
|
+
const delegateScript = new chunkIEO3XDKI_cjs.DelegateVtxo.Script({
|
|
8305
8331
|
pubKey: baselinePubkey,
|
|
8306
8332
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
8307
8333
|
delegatePubKey: this.offchainTapscript.options.delegatePubKey,
|
|
@@ -8337,7 +8363,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
8337
8363
|
}
|
|
8338
8364
|
};
|
|
8339
8365
|
var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
8340
|
-
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig,
|
|
8366
|
+
constructor(identity, network, onchainProvider, arkProvider, indexerProvider, arkServerPublicKey, offchainTapscript, boardingTapscript, serverUnrollScript, forfeitOutputScript, forfeitPubkey, dustAmount, walletRepository, contractRepository, renewalConfig, delegateProvider, watcherConfig, settlementConfig, walletContractTimelocks, receiveRotator, descriptorProvider) {
|
|
8341
8367
|
super(
|
|
8342
8368
|
identity,
|
|
8343
8369
|
network,
|
|
@@ -8349,7 +8375,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8349
8375
|
dustAmount,
|
|
8350
8376
|
walletRepository,
|
|
8351
8377
|
contractRepository,
|
|
8352
|
-
|
|
8378
|
+
delegateProvider,
|
|
8353
8379
|
watcherConfig,
|
|
8354
8380
|
walletContractTimelocks
|
|
8355
8381
|
);
|
|
@@ -8374,7 +8400,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8374
8400
|
} else {
|
|
8375
8401
|
this.settlementConfig = { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
8376
8402
|
}
|
|
8377
|
-
this.
|
|
8403
|
+
this._delegateManager = delegateProvider ? new DelegateManagerImpl(delegateProvider, arkProvider, identity) : void 0;
|
|
8378
8404
|
this._receiveRotator = receiveRotator;
|
|
8379
8405
|
this._descriptorProvider = descriptorProvider;
|
|
8380
8406
|
this._signerRouter = new InputSignerRouter({
|
|
@@ -8387,7 +8413,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8387
8413
|
static MIN_FEE_RATE = 1;
|
|
8388
8414
|
// sats/vbyte
|
|
8389
8415
|
identity;
|
|
8390
|
-
|
|
8416
|
+
_delegateManager;
|
|
8391
8417
|
_vtxoManager;
|
|
8392
8418
|
_vtxoManagerInitializing;
|
|
8393
8419
|
_walletAssetManager;
|
|
@@ -8502,7 +8528,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8502
8528
|
const hd = provider instanceof HDDescriptorProvider;
|
|
8503
8529
|
const staticDescriptor = hd ? void 0 : `tr(${base.hex.encode(await this.identity.xOnlyPublicKey())})`;
|
|
8504
8530
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
8505
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
8531
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkIEO3XDKI_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
8506
8532
|
const deps = {
|
|
8507
8533
|
indexerProvider: this.indexerProvider,
|
|
8508
8534
|
onchainProvider: this.onchainProvider,
|
|
@@ -8596,7 +8622,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8596
8622
|
* ```typescript
|
|
8597
8623
|
* const wallet = await Wallet.create({
|
|
8598
8624
|
* identity,
|
|
8599
|
-
*
|
|
8625
|
+
* arkProvider: new RestArkProvider(),
|
|
8600
8626
|
* });
|
|
8601
8627
|
* ```
|
|
8602
8628
|
*/
|
|
@@ -8609,7 +8635,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8609
8635
|
let serverUnrollScript;
|
|
8610
8636
|
try {
|
|
8611
8637
|
const raw = base.hex.decode(setup.info.checkpointTapscript);
|
|
8612
|
-
serverUnrollScript =
|
|
8638
|
+
serverUnrollScript = chunkWMIPYZSB_cjs.CSVMultisigTapscript.decode(raw);
|
|
8613
8639
|
} catch (e) {
|
|
8614
8640
|
throw new Error("Invalid checkpointTapscript from server");
|
|
8615
8641
|
}
|
|
@@ -8633,7 +8659,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8633
8659
|
setup.walletRepository,
|
|
8634
8660
|
setup.contractRepository,
|
|
8635
8661
|
config.renewalConfig,
|
|
8636
|
-
config.delegatorProvider,
|
|
8662
|
+
config.delegateProvider || config.delegatorProvider,
|
|
8637
8663
|
config.watcherConfig,
|
|
8638
8664
|
config.settlementConfig,
|
|
8639
8665
|
setup.walletContractTimelocks,
|
|
@@ -8673,14 +8699,18 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8673
8699
|
this.dustAmount,
|
|
8674
8700
|
this.walletRepository,
|
|
8675
8701
|
this.contractRepository,
|
|
8676
|
-
this.
|
|
8702
|
+
this.delegateProvider,
|
|
8677
8703
|
this.watcherConfig,
|
|
8678
8704
|
this.walletContractTimelocks
|
|
8679
8705
|
);
|
|
8680
8706
|
}
|
|
8681
|
-
/** Returns the
|
|
8707
|
+
/** Returns the delegate manager when delegation support is configured. */
|
|
8708
|
+
async getDelegateManager() {
|
|
8709
|
+
return this._delegateManager;
|
|
8710
|
+
}
|
|
8711
|
+
/** @deprecated alias for @see Wallet.getDelegateManager */
|
|
8682
8712
|
async getDelegatorManager() {
|
|
8683
|
-
return this.
|
|
8713
|
+
return this.getDelegateManager();
|
|
8684
8714
|
}
|
|
8685
8715
|
/**
|
|
8686
8716
|
* Send bitcoin to an Arkade address.
|
|
@@ -8711,7 +8741,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8711
8741
|
inputs: params.selectedVtxos,
|
|
8712
8742
|
changeAmount: BigInt(changeAmount)
|
|
8713
8743
|
};
|
|
8714
|
-
const outputAddress =
|
|
8744
|
+
const outputAddress = chunkWMIPYZSB_cjs.ArkAddress.decode(params.address);
|
|
8715
8745
|
const outputScript = BigInt(params.amount) < this.dustAmount ? outputAddress.subdustPkScript : outputAddress.pkScript;
|
|
8716
8746
|
const outputs = [
|
|
8717
8747
|
{
|
|
@@ -8778,7 +8808,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8778
8808
|
const { fees } = await this.arkProvider.getInfo();
|
|
8779
8809
|
const estimator = new Estimator(fees.intentFee);
|
|
8780
8810
|
let amount = 0;
|
|
8781
|
-
const exitScript =
|
|
8811
|
+
const exitScript = chunkWMIPYZSB_cjs.CSVMultisigTapscript.decode(
|
|
8782
8812
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
8783
8813
|
);
|
|
8784
8814
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -8827,7 +8857,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8827
8857
|
};
|
|
8828
8858
|
const outputFee = estimator.evalOffchainOutput({
|
|
8829
8859
|
amount: output.amount,
|
|
8830
|
-
script: base.hex.encode(
|
|
8860
|
+
script: base.hex.encode(chunkWMIPYZSB_cjs.ArkAddress.decode(output.address).pkScript)
|
|
8831
8861
|
});
|
|
8832
8862
|
output.amount -= BigInt(outputFee.satoshis);
|
|
8833
8863
|
if (output.amount <= this.dustAmount) {
|
|
@@ -8844,7 +8874,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8844
8874
|
for (const [index, output] of params.outputs.entries()) {
|
|
8845
8875
|
let script;
|
|
8846
8876
|
try {
|
|
8847
|
-
const addr =
|
|
8877
|
+
const addr = chunkWMIPYZSB_cjs.ArkAddress.decode(output.address);
|
|
8848
8878
|
script = addr.pkScript;
|
|
8849
8879
|
hasOffchainOutputs = true;
|
|
8850
8880
|
} catch {
|
|
@@ -8867,7 +8897,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8867
8897
|
}
|
|
8868
8898
|
}
|
|
8869
8899
|
let outputAssets;
|
|
8870
|
-
const destinationScript =
|
|
8900
|
+
const destinationScript = chunkWMIPYZSB_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
8871
8901
|
const assetOutputIndex = findDestinationOutputIndex(outputs, destinationScript);
|
|
8872
8902
|
if (assetInputs.size > 0) {
|
|
8873
8903
|
if (assetOutputIndex === -1) {
|
|
@@ -8989,7 +9019,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
8989
9019
|
}
|
|
8990
9020
|
continue;
|
|
8991
9021
|
}
|
|
8992
|
-
if (
|
|
9022
|
+
if (isRecoverable(input) || isSubdust(input, this.dustAmount)) {
|
|
8993
9023
|
continue;
|
|
8994
9024
|
}
|
|
8995
9025
|
if (connectorsLeaves.length === 0) {
|
|
@@ -9017,7 +9047,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9017
9047
|
index: input.vout,
|
|
9018
9048
|
witnessUtxo: {
|
|
9019
9049
|
amount: BigInt(input.value),
|
|
9020
|
-
script:
|
|
9050
|
+
script: chunkWMIPYZSB_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
9021
9051
|
},
|
|
9022
9052
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
9023
9053
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -9036,7 +9066,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9036
9066
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
9037
9067
|
{
|
|
9038
9068
|
index: 0,
|
|
9039
|
-
lookupScript:
|
|
9069
|
+
lookupScript: chunkWMIPYZSB_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
9040
9070
|
}
|
|
9041
9071
|
]);
|
|
9042
9072
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -9076,7 +9106,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9076
9106
|
if (skip) {
|
|
9077
9107
|
return { skip };
|
|
9078
9108
|
}
|
|
9079
|
-
const sweepTapscript =
|
|
9109
|
+
const sweepTapscript = chunkWMIPYZSB_cjs.CSVMultisigTapscript.encode({
|
|
9080
9110
|
timelock: {
|
|
9081
9111
|
value: event.batchExpiry,
|
|
9082
9112
|
type: event.batchExpiry >= 512n ? "seconds" : "blocks"
|
|
@@ -9167,7 +9197,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9167
9197
|
try {
|
|
9168
9198
|
return await this.arkProvider.registerIntent(intent);
|
|
9169
9199
|
} catch (error) {
|
|
9170
|
-
if (error instanceof
|
|
9200
|
+
if (error instanceof chunk6FLL2Q36_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
9171
9201
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
9172
9202
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
9173
9203
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -9183,7 +9213,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9183
9213
|
expire_at: 0,
|
|
9184
9214
|
cosigners_public_keys: cosignerPubKeys
|
|
9185
9215
|
};
|
|
9186
|
-
const proof =
|
|
9216
|
+
const proof = chunk6FLL2Q36_cjs.Intent.create(message, coins, outputs);
|
|
9187
9217
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
9188
9218
|
return {
|
|
9189
9219
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -9195,7 +9225,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9195
9225
|
type: "delete",
|
|
9196
9226
|
expire_at: 0
|
|
9197
9227
|
};
|
|
9198
|
-
const proof =
|
|
9228
|
+
const proof = chunk6FLL2Q36_cjs.Intent.create(message, coins, []);
|
|
9199
9229
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
9200
9230
|
return {
|
|
9201
9231
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -9207,7 +9237,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9207
9237
|
type: "get-pending-tx",
|
|
9208
9238
|
expire_at: 0
|
|
9209
9239
|
};
|
|
9210
|
-
const proof =
|
|
9240
|
+
const proof = chunk6FLL2Q36_cjs.Intent.create(message, coins, []);
|
|
9211
9241
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
9212
9242
|
return {
|
|
9213
9243
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -9502,7 +9532,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
|
|
|
9502
9532
|
);
|
|
9503
9533
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
9504
9534
|
index,
|
|
9505
|
-
lookupScript:
|
|
9535
|
+
lookupScript: chunkWMIPYZSB_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
9506
9536
|
}));
|
|
9507
9537
|
const signedVirtualTx = await this._signerRouter.sign(offchainTx.arkTx, arkTxJobs);
|
|
9508
9538
|
await this.setPendingTxFlag(true);
|
|
@@ -9931,12 +9961,12 @@ var MessageBus = class {
|
|
|
9931
9961
|
this.initialized = true;
|
|
9932
9962
|
}
|
|
9933
9963
|
async buildServices(config) {
|
|
9934
|
-
const arkProvider = new
|
|
9964
|
+
const arkProvider = new chunk6FLL2Q36_cjs.RestArkProvider(config.arkServer.url);
|
|
9935
9965
|
const storage = {
|
|
9936
9966
|
walletRepository: this.walletRepository,
|
|
9937
9967
|
contractRepository: this.contractRepository
|
|
9938
9968
|
};
|
|
9939
|
-
const
|
|
9969
|
+
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : config.delegatorUrl ? new RestDelegateProvider(config.delegatorUrl) : void 0;
|
|
9940
9970
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
9941
9971
|
if (isSigningSerialized(serialized)) {
|
|
9942
9972
|
const identity2 = hydrateIdentity(serialized);
|
|
@@ -9947,7 +9977,7 @@ var MessageBus = class {
|
|
|
9947
9977
|
indexerUrl: config.indexerUrl,
|
|
9948
9978
|
esploraUrl: config.esploraUrl,
|
|
9949
9979
|
storage,
|
|
9950
|
-
|
|
9980
|
+
delegateProvider,
|
|
9951
9981
|
settlementConfig: config.settlementConfig,
|
|
9952
9982
|
walletMode: config.walletMode,
|
|
9953
9983
|
watcherConfig: config.watcherConfig
|
|
@@ -9962,7 +9992,7 @@ var MessageBus = class {
|
|
|
9962
9992
|
indexerUrl: config.indexerUrl,
|
|
9963
9993
|
esploraUrl: config.esploraUrl,
|
|
9964
9994
|
storage,
|
|
9965
|
-
|
|
9995
|
+
delegateProvider,
|
|
9966
9996
|
watcherConfig: config.watcherConfig
|
|
9967
9997
|
});
|
|
9968
9998
|
return { readonlyWallet, arkProvider };
|
|
@@ -10241,6 +10271,18 @@ var MessageBus = class {
|
|
|
10241
10271
|
function toError(value) {
|
|
10242
10272
|
return value instanceof Error ? value : new Error(String(value));
|
|
10243
10273
|
}
|
|
10274
|
+
var DustChangeError = class extends Error {
|
|
10275
|
+
change;
|
|
10276
|
+
dustAmount;
|
|
10277
|
+
constructor(change, dustAmount) {
|
|
10278
|
+
super(
|
|
10279
|
+
`change ${change} sats is below dust threshold ${dustAmount}; consider exiting the full balance`
|
|
10280
|
+
);
|
|
10281
|
+
this.name = "DustChangeError";
|
|
10282
|
+
this.change = change;
|
|
10283
|
+
this.dustAmount = dustAmount;
|
|
10284
|
+
}
|
|
10285
|
+
};
|
|
10244
10286
|
var Ramps = class {
|
|
10245
10287
|
/**
|
|
10246
10288
|
* Create convenience wrappers for onboarding and offboarding flows.
|
|
@@ -10295,7 +10337,7 @@ var Ramps = class {
|
|
|
10295
10337
|
}
|
|
10296
10338
|
amount = amount ?? totalAmount;
|
|
10297
10339
|
const offchainAddress = await this.wallet.getAddress();
|
|
10298
|
-
const offchainAddr =
|
|
10340
|
+
const offchainAddr = chunkWMIPYZSB_cjs.ArkAddress.decode(offchainAddress);
|
|
10299
10341
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
10300
10342
|
const outputFee = estimator.evalOffchainOutput({
|
|
10301
10343
|
amount,
|
|
@@ -10378,6 +10420,10 @@ var Ramps = class {
|
|
|
10378
10420
|
}
|
|
10379
10421
|
change = totalAmount - amount;
|
|
10380
10422
|
}
|
|
10423
|
+
const dustAmount = getDustAmount(this.wallet);
|
|
10424
|
+
if (change > 0n && change < dustAmount) {
|
|
10425
|
+
throw new DustChangeError(change, dustAmount);
|
|
10426
|
+
}
|
|
10381
10427
|
amount = amount ?? totalAmount;
|
|
10382
10428
|
const networkNames = [
|
|
10383
10429
|
"bitcoin",
|
|
@@ -10389,7 +10435,7 @@ var Ramps = class {
|
|
|
10389
10435
|
let destinationScript;
|
|
10390
10436
|
for (const networkName of networkNames) {
|
|
10391
10437
|
try {
|
|
10392
|
-
const network =
|
|
10438
|
+
const network = chunkWMIPYZSB_cjs.networks[networkName];
|
|
10393
10439
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
10394
10440
|
destinationScript = btcSigner.OutScript.encode(addr);
|
|
10395
10441
|
break;
|
|
@@ -10440,18 +10486,47 @@ var WalletNotInitializedError = class extends Error {
|
|
|
10440
10486
|
this.name = "WalletNotInitializedError";
|
|
10441
10487
|
}
|
|
10442
10488
|
};
|
|
10489
|
+
function isSerializedAggregateError(value) {
|
|
10490
|
+
if (!value || typeof value !== "object") return false;
|
|
10491
|
+
const v = value;
|
|
10492
|
+
return v.name === "AggregateError" && typeof v.message === "string" && Array.isArray(v.errors) && v.errors.every((e) => e && typeof e.name === "string" && typeof e.message === "string");
|
|
10493
|
+
}
|
|
10494
|
+
function serializeAggregateError(error) {
|
|
10495
|
+
const errors = [];
|
|
10496
|
+
for (const child of error.errors ?? []) {
|
|
10497
|
+
if (child instanceof Error) {
|
|
10498
|
+
errors.push({ name: child.name, message: child.message });
|
|
10499
|
+
} else {
|
|
10500
|
+
errors.push({ name: "Error", message: String(child) });
|
|
10501
|
+
}
|
|
10502
|
+
}
|
|
10503
|
+
return {
|
|
10504
|
+
name: "AggregateError",
|
|
10505
|
+
message: error.message,
|
|
10506
|
+
errors
|
|
10507
|
+
};
|
|
10508
|
+
}
|
|
10509
|
+
function deserializeAggregateError(payload) {
|
|
10510
|
+
const errs = payload.errors.map((e) => {
|
|
10511
|
+
const err = new Error(e.message);
|
|
10512
|
+
err.name = e.name;
|
|
10513
|
+
return err;
|
|
10514
|
+
});
|
|
10515
|
+
return new AggregateError(errs, payload.message);
|
|
10516
|
+
}
|
|
10443
10517
|
var ReadonlyWalletError = class extends Error {
|
|
10444
10518
|
constructor() {
|
|
10445
10519
|
super("Read-only wallet: operation requires signing");
|
|
10446
10520
|
this.name = "ReadonlyWalletError";
|
|
10447
10521
|
}
|
|
10448
10522
|
};
|
|
10449
|
-
var
|
|
10523
|
+
var DelegateNotConfiguredError = class extends Error {
|
|
10450
10524
|
constructor() {
|
|
10451
|
-
super("
|
|
10452
|
-
this.name = "
|
|
10525
|
+
super("Delegate not configured");
|
|
10526
|
+
this.name = "DelegateNotConfiguredError";
|
|
10453
10527
|
}
|
|
10454
10528
|
};
|
|
10529
|
+
var DelegatorNotConfiguredError = DelegateNotConfiguredError;
|
|
10455
10530
|
var DEFAULT_MESSAGE_TAG = "WALLET_UPDATER";
|
|
10456
10531
|
var WalletMessageHandler = class {
|
|
10457
10532
|
messageTag;
|
|
@@ -10534,7 +10609,10 @@ var WalletMessageHandler = class {
|
|
|
10534
10609
|
// page-side PING / MESSAGE_BUS_NOT_INITIALIZED path triggered by concurrent
|
|
10535
10610
|
// short requests (GET_STATUS, GET_BALANCE, ...).
|
|
10536
10611
|
isLongRunning(message) {
|
|
10537
|
-
return message.type === "SETTLE" || message.type === "RECOVER_VTXOS" || message.type === "RENEW_VTXOS"
|
|
10612
|
+
return message.type === "SETTLE" || message.type === "RECOVER_VTXOS" || message.type === "RENEW_VTXOS" || // HD restore walks the index range with one indexer round-trip per
|
|
10613
|
+
// step until it hits gapLimit consecutive unused indices. The bus
|
|
10614
|
+
// deadline must not race the scan; liveness stays covered by PING.
|
|
10615
|
+
message.type === "RESTORE_WALLET";
|
|
10538
10616
|
}
|
|
10539
10617
|
async handleMessage(message) {
|
|
10540
10618
|
const id = message.id;
|
|
@@ -10803,11 +10881,11 @@ var WalletMessageHandler = class {
|
|
|
10803
10881
|
}
|
|
10804
10882
|
case "GET_DELEGATE_INFO": {
|
|
10805
10883
|
const wallet = this.requireWallet();
|
|
10806
|
-
const
|
|
10807
|
-
if (!
|
|
10808
|
-
throw new
|
|
10884
|
+
const delegateManager = await wallet.getDelegateManager();
|
|
10885
|
+
if (!delegateManager) {
|
|
10886
|
+
throw new DelegateNotConfiguredError();
|
|
10809
10887
|
}
|
|
10810
|
-
const info = await
|
|
10888
|
+
const info = await delegateManager.getDelegateInfo();
|
|
10811
10889
|
return this.tagged({
|
|
10812
10890
|
id,
|
|
10813
10891
|
type: "DELEGATE_INFO",
|
|
@@ -10870,7 +10948,7 @@ var WalletMessageHandler = class {
|
|
|
10870
10948
|
payload: e
|
|
10871
10949
|
})
|
|
10872
10950
|
);
|
|
10873
|
-
});
|
|
10951
|
+
}, message.payload);
|
|
10874
10952
|
return this.tagged({
|
|
10875
10953
|
id,
|
|
10876
10954
|
type: "RENEW_VTXOS_SUCCESS",
|
|
@@ -10897,6 +10975,24 @@ var WalletMessageHandler = class {
|
|
|
10897
10975
|
payload: { txid }
|
|
10898
10976
|
});
|
|
10899
10977
|
}
|
|
10978
|
+
case "RESTORE_WALLET": {
|
|
10979
|
+
const wallet = this.requireWallet();
|
|
10980
|
+
try {
|
|
10981
|
+
await wallet.restore(message.payload);
|
|
10982
|
+
} catch (error) {
|
|
10983
|
+
if (error instanceof AggregateError) {
|
|
10984
|
+
return this.tagged({
|
|
10985
|
+
id,
|
|
10986
|
+
error: serializeAggregateError(error)
|
|
10987
|
+
});
|
|
10988
|
+
}
|
|
10989
|
+
throw error;
|
|
10990
|
+
}
|
|
10991
|
+
return this.tagged({
|
|
10992
|
+
id,
|
|
10993
|
+
type: "RESTORE_WALLET_SUCCESS"
|
|
10994
|
+
});
|
|
10995
|
+
}
|
|
10900
10996
|
default:
|
|
10901
10997
|
console.error("Unknown message type", message);
|
|
10902
10998
|
throw new Error("Unknown message");
|
|
@@ -10908,7 +11004,7 @@ var WalletMessageHandler = class {
|
|
|
10908
11004
|
// Wallet methods
|
|
10909
11005
|
async handleInitWallet({ payload }) {
|
|
10910
11006
|
const { arkServerUrl } = payload;
|
|
10911
|
-
this.indexerProvider = new
|
|
11007
|
+
this.indexerProvider = new chunk6FLL2Q36_cjs.RestIndexerProvider(arkServerUrl);
|
|
10912
11008
|
await this.onWalletInitialized();
|
|
10913
11009
|
}
|
|
10914
11010
|
async handleGetBalance() {
|
|
@@ -10925,7 +11021,7 @@ var WalletMessageHandler = class {
|
|
|
10925
11021
|
unconfirmed += utxo.value;
|
|
10926
11022
|
}
|
|
10927
11023
|
}
|
|
10928
|
-
const spendableVtxos = allVtxos.filter(
|
|
11024
|
+
const spendableVtxos = allVtxos.filter(isSpendable);
|
|
10929
11025
|
const sweptVtxos = allVtxos.filter((vtxo) => vtxo.virtualStatus.state === "swept");
|
|
10930
11026
|
let settled = 0;
|
|
10931
11027
|
let preconfirmed = 0;
|
|
@@ -10938,7 +11034,7 @@ var WalletMessageHandler = class {
|
|
|
10938
11034
|
}
|
|
10939
11035
|
}
|
|
10940
11036
|
for (const vtxo of sweptVtxos) {
|
|
10941
|
-
if (
|
|
11037
|
+
if (isSpendable(vtxo)) {
|
|
10942
11038
|
recoverable += vtxo.value;
|
|
10943
11039
|
}
|
|
10944
11040
|
}
|
|
@@ -10980,7 +11076,7 @@ var WalletMessageHandler = class {
|
|
|
10980
11076
|
*/
|
|
10981
11077
|
async getSpendableVtxos() {
|
|
10982
11078
|
const vtxos = await this.getVtxosFromRepo();
|
|
10983
|
-
return vtxos.filter(
|
|
11079
|
+
return vtxos.filter(isSpendable);
|
|
10984
11080
|
}
|
|
10985
11081
|
async onWalletInitialized() {
|
|
10986
11082
|
if (!this.readonlyWallet || !this.arkProvider || !this.indexerProvider || !this.walletRepository) {
|
|
@@ -11151,15 +11247,15 @@ var WalletMessageHandler = class {
|
|
|
11151
11247
|
}
|
|
11152
11248
|
async handleDelegate(message) {
|
|
11153
11249
|
const wallet = this.requireWallet();
|
|
11154
|
-
const
|
|
11155
|
-
if (!
|
|
11156
|
-
throw new
|
|
11250
|
+
const delegateManager = await wallet.getDelegateManager();
|
|
11251
|
+
if (!delegateManager) {
|
|
11252
|
+
throw new DelegateNotConfiguredError();
|
|
11157
11253
|
}
|
|
11158
11254
|
const { vtxoOutpoints, destination, delegateAt } = message.payload;
|
|
11159
11255
|
const allVtxos = await wallet.getVtxos();
|
|
11160
11256
|
const outpointSet = new Set(vtxoOutpoints.map((o) => `${o.txid}:${o.vout}`));
|
|
11161
11257
|
const filtered = allVtxos.filter((v) => outpointSet.has(`${v.txid}:${v.vout}`)).map((v) => ({ ...v, contractScript: v.script }));
|
|
11162
|
-
const result = await
|
|
11258
|
+
const result = await delegateManager.delegate(
|
|
11163
11259
|
filtered,
|
|
11164
11260
|
destination,
|
|
11165
11261
|
delegateAt !== void 0 ? new Date(delegateAt) : void 0
|
|
@@ -11190,13 +11286,13 @@ var WalletMessageHandler = class {
|
|
|
11190
11286
|
const dustAmount = this.readonlyWallet.dustAmount;
|
|
11191
11287
|
const includeRecoverable = message.payload.filter?.withRecoverable ?? false;
|
|
11192
11288
|
const filteredVtxos = includeRecoverable ? vtxos : vtxos.filter((v) => {
|
|
11193
|
-
if (dustAmount != null &&
|
|
11289
|
+
if (dustAmount != null && isSubdust(v, dustAmount)) {
|
|
11194
11290
|
return false;
|
|
11195
11291
|
}
|
|
11196
|
-
if (
|
|
11292
|
+
if (isRecoverable(v)) {
|
|
11197
11293
|
return false;
|
|
11198
11294
|
}
|
|
11199
|
-
if (
|
|
11295
|
+
if (isExpired(v)) {
|
|
11200
11296
|
return false;
|
|
11201
11297
|
}
|
|
11202
11298
|
return true;
|
|
@@ -11366,6 +11462,10 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
11366
11462
|
RECOVER_VTXOS: 5e4,
|
|
11367
11463
|
RENEW_VTXOS: 5e4,
|
|
11368
11464
|
SWEEP_EXPIRED_BOARDING_UTXOS: 5e4,
|
|
11465
|
+
// RESTORE_WALLET is a streaming/long-running path (sendMessageWithEvents)
|
|
11466
|
+
// like SETTLE; the value here is kept for type completeness and is never
|
|
11467
|
+
// enforced as an inactivity deadline.
|
|
11468
|
+
RESTORE_WALLET: 5e4,
|
|
11369
11469
|
// Misc writes
|
|
11370
11470
|
INIT_WALLET: 3e4,
|
|
11371
11471
|
CLEAR: 1e4,
|
|
@@ -11507,6 +11607,8 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11507
11607
|
// these immediately after construction.
|
|
11508
11608
|
arkServerUrl;
|
|
11509
11609
|
arkServerPublicKey;
|
|
11610
|
+
delegateUrl;
|
|
11611
|
+
/** @deprecated alias for @see ServiceWorkerReadonlyWallet.delegateUrl */
|
|
11510
11612
|
delegatorUrl;
|
|
11511
11613
|
indexerUrl;
|
|
11512
11614
|
esploraUrl;
|
|
@@ -11545,7 +11647,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11545
11647
|
key: { publicKey },
|
|
11546
11648
|
arkServerUrl: getArkadeServerUrl(options),
|
|
11547
11649
|
arkServerPublicKey: options.arkServerPublicKey,
|
|
11548
|
-
|
|
11650
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
11651
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11652
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11653
|
+
// a newer version.
|
|
11654
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
11549
11655
|
};
|
|
11550
11656
|
const messageTimeouts = options.messageTimeouts ? {
|
|
11551
11657
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -11557,7 +11663,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11557
11663
|
url: getArkadeServerUrl(options),
|
|
11558
11664
|
publicKey: options.arkServerPublicKey
|
|
11559
11665
|
},
|
|
11560
|
-
|
|
11666
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
11667
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11668
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11669
|
+
// a newer version.
|
|
11670
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
11561
11671
|
indexerUrl: options.indexerUrl,
|
|
11562
11672
|
esploraUrl: options.esploraUrl,
|
|
11563
11673
|
watcherConfig: options.watcherConfig,
|
|
@@ -11779,7 +11889,11 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
11779
11889
|
url: this.arkServerUrl,
|
|
11780
11890
|
publicKey: this.arkServerPublicKey
|
|
11781
11891
|
},
|
|
11782
|
-
|
|
11892
|
+
delegateUrl: this.delegateUrl || this.delegatorUrl,
|
|
11893
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
11894
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
11895
|
+
// a newer version.
|
|
11896
|
+
delegatorUrl: this.delegateUrl || this.delegatorUrl,
|
|
11783
11897
|
indexerUrl: this.indexerUrl,
|
|
11784
11898
|
esploraUrl: this.esploraUrl,
|
|
11785
11899
|
watcherConfig: this.watcherConfig,
|
|
@@ -12148,7 +12262,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
12148
12262
|
}
|
|
12149
12263
|
};
|
|
12150
12264
|
var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadonlyWallet {
|
|
12151
|
-
constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag,
|
|
12265
|
+
constructor(serviceWorker, identity, walletRepository, contractRepository, messageTag, hasDelegate) {
|
|
12152
12266
|
super(serviceWorker, identity, walletRepository, contractRepository, messageTag);
|
|
12153
12267
|
this.serviceWorker = serviceWorker;
|
|
12154
12268
|
this.identity = identity;
|
|
@@ -12158,13 +12272,13 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12158
12272
|
(msg) => this.sendMessage(msg),
|
|
12159
12273
|
messageTag
|
|
12160
12274
|
);
|
|
12161
|
-
this.
|
|
12275
|
+
this.hasDelegate = hasDelegate;
|
|
12162
12276
|
}
|
|
12163
12277
|
walletRepository;
|
|
12164
12278
|
contractRepository;
|
|
12165
12279
|
identity;
|
|
12166
12280
|
_assetManager;
|
|
12167
|
-
|
|
12281
|
+
hasDelegate;
|
|
12168
12282
|
get assetManager() {
|
|
12169
12283
|
return this._assetManager;
|
|
12170
12284
|
}
|
|
@@ -12188,14 +12302,18 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12188
12302
|
walletRepository,
|
|
12189
12303
|
contractRepository,
|
|
12190
12304
|
messageTag,
|
|
12191
|
-
!!options.delegatorUrl
|
|
12305
|
+
!!(options.delegateUrl || options.delegatorUrl)
|
|
12192
12306
|
);
|
|
12193
12307
|
const legacyPrivateKey = serializedWallet.type === "single-key" ? serializedWallet.privateKey : null;
|
|
12194
12308
|
const initWalletPayload = {
|
|
12195
12309
|
key: legacyPrivateKey ? { privateKey: legacyPrivateKey } : {},
|
|
12196
12310
|
arkServerUrl: getArkadeServerUrl(options),
|
|
12197
12311
|
arkServerPublicKey: options.arkServerPublicKey,
|
|
12198
|
-
|
|
12312
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
12313
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
12314
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
12315
|
+
// a newer version.
|
|
12316
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl
|
|
12199
12317
|
};
|
|
12200
12318
|
const messageTimeouts = options.messageTimeouts ? {
|
|
12201
12319
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -12207,7 +12325,11 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12207
12325
|
url: getArkadeServerUrl(options),
|
|
12208
12326
|
publicKey: options.arkServerPublicKey
|
|
12209
12327
|
},
|
|
12210
|
-
|
|
12328
|
+
delegateUrl: options.delegateUrl || options.delegatorUrl,
|
|
12329
|
+
// Keep the deprecated field populated so pre-#519 service workers
|
|
12330
|
+
// (which only read delegatorUrl) keep delegating until they activate
|
|
12331
|
+
// a newer version.
|
|
12332
|
+
delegatorUrl: options.delegateUrl || options.delegatorUrl,
|
|
12211
12333
|
indexerUrl: options.indexerUrl,
|
|
12212
12334
|
esploraUrl: options.esploraUrl,
|
|
12213
12335
|
settlementConfig: options.settlementConfig,
|
|
@@ -12288,6 +12410,38 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12288
12410
|
throw new Error(`Settlement failed: ${error}`);
|
|
12289
12411
|
}
|
|
12290
12412
|
}
|
|
12413
|
+
/**
|
|
12414
|
+
* Explicitly recover this wallet's contracts and balance on a fresh repo.
|
|
12415
|
+
* Mirrors {@link Wallet.restore} but drives the scan inside the service
|
|
12416
|
+
* worker — the materialize() callback used by `scanContracts` cannot
|
|
12417
|
+
* cross the postMessage boundary, so the entire flow runs worker-side
|
|
12418
|
+
* and only the gapLimit / outcome cross the wire.
|
|
12419
|
+
*
|
|
12420
|
+
* Uses the streaming send path so the bus deadline does not race a
|
|
12421
|
+
* long indexer-bound scan. AggregateError thrown by the worker is
|
|
12422
|
+
* reconstructed here so callers can inspect `.errors`.
|
|
12423
|
+
*/
|
|
12424
|
+
async restore(opts) {
|
|
12425
|
+
const message = {
|
|
12426
|
+
id: getRandomId(),
|
|
12427
|
+
tag: this.messageTag,
|
|
12428
|
+
type: "RESTORE_WALLET",
|
|
12429
|
+
payload: opts ?? {}
|
|
12430
|
+
};
|
|
12431
|
+
try {
|
|
12432
|
+
await this.sendMessageWithEvents(
|
|
12433
|
+
message,
|
|
12434
|
+
() => {
|
|
12435
|
+
},
|
|
12436
|
+
(resp) => resp.type === "RESTORE_WALLET_SUCCESS"
|
|
12437
|
+
);
|
|
12438
|
+
} catch (error) {
|
|
12439
|
+
if (isSerializedAggregateError(error)) {
|
|
12440
|
+
throw deserializeAggregateError(error);
|
|
12441
|
+
}
|
|
12442
|
+
throw error;
|
|
12443
|
+
}
|
|
12444
|
+
}
|
|
12291
12445
|
async send(...recipients) {
|
|
12292
12446
|
const message = {
|
|
12293
12447
|
tag: this.messageTag,
|
|
@@ -12302,8 +12456,8 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12302
12456
|
throw new Error(`Send failed: ${error}`);
|
|
12303
12457
|
}
|
|
12304
12458
|
}
|
|
12305
|
-
async
|
|
12306
|
-
if (!this.
|
|
12459
|
+
async getDelegateManager() {
|
|
12460
|
+
if (!this.hasDelegate) {
|
|
12307
12461
|
return void 0;
|
|
12308
12462
|
}
|
|
12309
12463
|
const wallet = this;
|
|
@@ -12353,6 +12507,10 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12353
12507
|
};
|
|
12354
12508
|
return manager;
|
|
12355
12509
|
}
|
|
12510
|
+
/** @deprecated alias for @see ServiceWorkerWallet.getDelegateManager */
|
|
12511
|
+
async getDelegatorManager() {
|
|
12512
|
+
return await this.getDelegateManager();
|
|
12513
|
+
}
|
|
12356
12514
|
async getVtxoManager() {
|
|
12357
12515
|
const wallet = this;
|
|
12358
12516
|
const messageTag = this.messageTag;
|
|
@@ -12407,11 +12565,12 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
12407
12565
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
12408
12566
|
}
|
|
12409
12567
|
},
|
|
12410
|
-
async renewVtxos(eventCallback) {
|
|
12568
|
+
async renewVtxos(eventCallback, options) {
|
|
12411
12569
|
const message = {
|
|
12412
12570
|
tag: messageTag,
|
|
12413
12571
|
type: "RENEW_VTXOS",
|
|
12414
|
-
id: getRandomId()
|
|
12572
|
+
id: getRandomId(),
|
|
12573
|
+
payload: options
|
|
12415
12574
|
};
|
|
12416
12575
|
try {
|
|
12417
12576
|
const response = await wallet.sendMessageWithEvents(
|
|
@@ -12476,15 +12635,14 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
12476
12635
|
* @param networkName - Bitcoin network name, @see NetworkName
|
|
12477
12636
|
* @param provider - Optional onchain provider override, @see OnchainProvider
|
|
12478
12637
|
* @returns Configured onchain wallet
|
|
12479
|
-
* @defaultValue `provider = new EsploraProvider('https://mempool.space/api')`
|
|
12480
12638
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
12481
12639
|
*/
|
|
12482
|
-
static async create(identity, networkName =
|
|
12640
|
+
static async create(identity, networkName = chunkWMIPYZSB_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
12483
12641
|
const pubkey = await identity.xOnlyPublicKey();
|
|
12484
12642
|
if (!pubkey) {
|
|
12485
12643
|
throw new Error("Invalid configured public key");
|
|
12486
12644
|
}
|
|
12487
|
-
const network = getNetwork(networkName);
|
|
12645
|
+
const network = chunkWMIPYZSB_cjs.getNetwork(networkName);
|
|
12488
12646
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
12489
12647
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
12490
12648
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -12590,7 +12748,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
12590
12748
|
if (!inputs) {
|
|
12591
12749
|
throw new Error("Fee estimation failed");
|
|
12592
12750
|
}
|
|
12593
|
-
let tx = new
|
|
12751
|
+
let tx = new chunk6FLL2Q36_cjs.Transaction();
|
|
12594
12752
|
for (const input of inputs) {
|
|
12595
12753
|
tx.addInput({
|
|
12596
12754
|
txid: input.txid,
|
|
@@ -12621,7 +12779,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
12621
12779
|
*/
|
|
12622
12780
|
async bumpP2A(parent) {
|
|
12623
12781
|
const parentVsize = parent.vsize;
|
|
12624
|
-
let child = new
|
|
12782
|
+
let child = new chunk6FLL2Q36_cjs.Transaction({
|
|
12625
12783
|
version: 3,
|
|
12626
12784
|
allowLegacyWitnessUtxo: true
|
|
12627
12785
|
});
|
|
@@ -13378,7 +13536,7 @@ exports.BIP322 = void 0;
|
|
|
13378
13536
|
async function sign2(message, identity, network) {
|
|
13379
13537
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
13380
13538
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
13381
|
-
const toSpend =
|
|
13539
|
+
const toSpend = chunk6FLL2Q36_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
13382
13540
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
13383
13541
|
const signed = await identity.sign(toSign, [0]);
|
|
13384
13542
|
signed.finalizeIdx(0);
|
|
@@ -13436,7 +13594,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
13436
13594
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
13437
13595
|
return false;
|
|
13438
13596
|
}
|
|
13439
|
-
const toSpend =
|
|
13597
|
+
const toSpend = chunk6FLL2Q36_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
13440
13598
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
|
|
13441
13599
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
13442
13600
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -13457,7 +13615,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
13457
13615
|
}
|
|
13458
13616
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
13459
13617
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
13460
|
-
const toSpend =
|
|
13618
|
+
const toSpend = chunk6FLL2Q36_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
13461
13619
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
13462
13620
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
13463
13621
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -13510,7 +13668,7 @@ function encodeCompactSize(n) {
|
|
|
13510
13668
|
return buf;
|
|
13511
13669
|
}
|
|
13512
13670
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
13513
|
-
const tx = new
|
|
13671
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction({ version: 0 });
|
|
13514
13672
|
tx.addInput({
|
|
13515
13673
|
txid: toSpend.id,
|
|
13516
13674
|
index: 0,
|
|
@@ -13524,12 +13682,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
13524
13682
|
});
|
|
13525
13683
|
tx.addOutput({
|
|
13526
13684
|
amount: 0n,
|
|
13527
|
-
script:
|
|
13685
|
+
script: chunk6FLL2Q36_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
13528
13686
|
});
|
|
13529
13687
|
return tx;
|
|
13530
13688
|
}
|
|
13531
13689
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
13532
|
-
const tx = new
|
|
13690
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction({ version: 0 });
|
|
13533
13691
|
tx.addInput({
|
|
13534
13692
|
txid: toSpend.id,
|
|
13535
13693
|
index: 0,
|
|
@@ -13541,7 +13699,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
13541
13699
|
});
|
|
13542
13700
|
tx.addOutput({
|
|
13543
13701
|
amount: 0n,
|
|
13544
|
-
script:
|
|
13702
|
+
script: chunk6FLL2Q36_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
13545
13703
|
});
|
|
13546
13704
|
return tx;
|
|
13547
13705
|
}
|
|
@@ -13602,7 +13760,7 @@ exports.Unroll = void 0;
|
|
|
13602
13760
|
if (virtualTxs.txs.length === 0) {
|
|
13603
13761
|
throw new Error(`Tx ${nextTxToBroadcast.txid} not found`);
|
|
13604
13762
|
}
|
|
13605
|
-
const tx =
|
|
13763
|
+
const tx = chunk6FLL2Q36_cjs.Transaction.fromPSBT(base.base64.decode(virtualTxs.txs[0]));
|
|
13606
13764
|
if (nextTxToBroadcast.type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
13607
13765
|
const input = tx.getInput(0);
|
|
13608
13766
|
if (!input) {
|
|
@@ -13679,12 +13837,12 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
13679
13837
|
if (!exit) {
|
|
13680
13838
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
13681
13839
|
}
|
|
13682
|
-
const spendingLeaf =
|
|
13840
|
+
const spendingLeaf = chunkWMIPYZSB_cjs.VtxoScript.decode(vtxo.tapTree).findLeaf(base.hex.encode(exit.script));
|
|
13683
13841
|
if (!spendingLeaf) {
|
|
13684
13842
|
throw new Error(`spending leaf not found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
13685
13843
|
}
|
|
13686
13844
|
totalAmount += BigInt(vtxo.value);
|
|
13687
|
-
const sequence =
|
|
13845
|
+
const sequence = chunkWMIPYZSB_cjs.timelockToSequence(exit.params.timelock);
|
|
13688
13846
|
inputs.push({
|
|
13689
13847
|
txid: vtxo.txid,
|
|
13690
13848
|
index: vtxo.vout,
|
|
@@ -13692,7 +13850,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
13692
13850
|
sequence,
|
|
13693
13851
|
witnessUtxo: {
|
|
13694
13852
|
amount: BigInt(vtxo.value),
|
|
13695
|
-
script:
|
|
13853
|
+
script: chunkWMIPYZSB_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
13696
13854
|
},
|
|
13697
13855
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
13698
13856
|
});
|
|
@@ -13702,7 +13860,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
13702
13860
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
13703
13861
|
);
|
|
13704
13862
|
}
|
|
13705
|
-
const tx = new
|
|
13863
|
+
const tx = new chunk6FLL2Q36_cjs.Transaction({ version: 2 });
|
|
13706
13864
|
for (const input of inputs) {
|
|
13707
13865
|
tx.addInput(input);
|
|
13708
13866
|
}
|
|
@@ -13749,7 +13907,7 @@ function doWait(onchainProvider, txid) {
|
|
|
13749
13907
|
};
|
|
13750
13908
|
}
|
|
13751
13909
|
function availableExitPath(confirmedAt, current, vtxo) {
|
|
13752
|
-
const exits =
|
|
13910
|
+
const exits = chunkWMIPYZSB_cjs.VtxoScript.decode(vtxo.tapTree).exitPaths();
|
|
13753
13911
|
for (const exit of exits) {
|
|
13754
13912
|
if (exit.params.timelock.type === "blocks") {
|
|
13755
13913
|
if (current.height >= confirmedAt.height + Number(exit.params.timelock.value)) {
|
|
@@ -13788,7 +13946,7 @@ function decodeArkContract(encoded) {
|
|
|
13788
13946
|
}
|
|
13789
13947
|
function contractFromArkContract(encoded, options = {}) {
|
|
13790
13948
|
const parsed = decodeArkContract(encoded);
|
|
13791
|
-
const handler =
|
|
13949
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.get(parsed.type);
|
|
13792
13950
|
if (!handler) {
|
|
13793
13951
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
13794
13952
|
}
|
|
@@ -13802,9 +13960,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
13802
13960
|
metadata: options.metadata
|
|
13803
13961
|
};
|
|
13804
13962
|
}
|
|
13805
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
13963
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkWMIPYZSB_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
13806
13964
|
const parsed = decodeArkContract(encoded);
|
|
13807
|
-
const handler =
|
|
13965
|
+
const handler = chunkIEO3XDKI_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
13808
13966
|
const params = parsed.data;
|
|
13809
13967
|
const vtxoScript = handler.createScript(params);
|
|
13810
13968
|
return {
|
|
@@ -13823,14 +13981,18 @@ function isArkContract(str) {
|
|
|
13823
13981
|
}
|
|
13824
13982
|
|
|
13825
13983
|
exports.ArkNote = ArkNote;
|
|
13984
|
+
exports.AssetManager = AssetManager;
|
|
13826
13985
|
exports.ContractManager = ContractManager;
|
|
13827
13986
|
exports.ContractRepositoryImpl = ContractRepositoryImpl;
|
|
13828
13987
|
exports.ContractWatcher = ContractWatcher;
|
|
13829
13988
|
exports.DB_VERSION = DB_VERSION;
|
|
13830
13989
|
exports.DEFAULT_MESSAGE_TIMEOUTS = DEFAULT_MESSAGE_TIMEOUTS;
|
|
13990
|
+
exports.DelegateManagerImpl = DelegateManagerImpl;
|
|
13991
|
+
exports.DelegateNotConfiguredError = DelegateNotConfiguredError;
|
|
13831
13992
|
exports.DelegatorManagerImpl = DelegatorManagerImpl;
|
|
13832
13993
|
exports.DelegatorNotConfiguredError = DelegatorNotConfiguredError;
|
|
13833
13994
|
exports.DescriptorSigningProviderMissingError = DescriptorSigningProviderMissingError;
|
|
13995
|
+
exports.DustChangeError = DustChangeError;
|
|
13834
13996
|
exports.ELECTRUM_TCP_HOST = ELECTRUM_TCP_HOST;
|
|
13835
13997
|
exports.ELECTRUM_WS_URL = ELECTRUM_WS_URL;
|
|
13836
13998
|
exports.ESPLORA_URL = ESPLORA_URL;
|
|
@@ -13851,10 +14013,12 @@ exports.MnemonicIdentity = MnemonicIdentity;
|
|
|
13851
14013
|
exports.OnchainWallet = OnchainWallet;
|
|
13852
14014
|
exports.P2A = P2A;
|
|
13853
14015
|
exports.Ramps = Ramps;
|
|
14016
|
+
exports.ReadonlyAssetManager = ReadonlyAssetManager;
|
|
13854
14017
|
exports.ReadonlyDescriptorIdentity = ReadonlyDescriptorIdentity;
|
|
13855
14018
|
exports.ReadonlySingleKey = ReadonlySingleKey;
|
|
13856
14019
|
exports.ReadonlyWallet = ReadonlyWallet;
|
|
13857
14020
|
exports.ReadonlyWalletError = ReadonlyWalletError;
|
|
14021
|
+
exports.RestDelegateProvider = RestDelegateProvider;
|
|
13858
14022
|
exports.RestDelegatorProvider = RestDelegatorProvider;
|
|
13859
14023
|
exports.SeedIdentity = SeedIdentity;
|
|
13860
14024
|
exports.ServiceWorkerReadonlyWallet = ServiceWorkerReadonlyWallet;
|
|
@@ -13862,6 +14026,7 @@ exports.ServiceWorkerTimeoutError = ServiceWorkerTimeoutError;
|
|
|
13862
14026
|
exports.ServiceWorkerWallet = ServiceWorkerWallet;
|
|
13863
14027
|
exports.SingleKey = SingleKey;
|
|
13864
14028
|
exports.TxTree = TxTree;
|
|
14029
|
+
exports.TxType = TxType;
|
|
13865
14030
|
exports.TxWeightEstimator = TxWeightEstimator;
|
|
13866
14031
|
exports.VtxoManager = VtxoManager;
|
|
13867
14032
|
exports.Wallet = Wallet2;
|
|
@@ -13887,11 +14052,14 @@ exports.hasBoardingTxExpired = hasBoardingTxExpired;
|
|
|
13887
14052
|
exports.isArkContract = isArkContract;
|
|
13888
14053
|
exports.isBatchSignable = isBatchSignable;
|
|
13889
14054
|
exports.isDiscoverable = isDiscoverable;
|
|
14055
|
+
exports.isExpired = isExpired;
|
|
14056
|
+
exports.isRecoverable = isRecoverable;
|
|
14057
|
+
exports.isSpendable = isSpendable;
|
|
14058
|
+
exports.isSubdust = isSubdust;
|
|
13890
14059
|
exports.isValidArkAddress = isValidArkAddress;
|
|
13891
14060
|
exports.isVtxoExpiringSoon = isVtxoExpiringSoon;
|
|
13892
14061
|
exports.isVtxoForScript = isVtxoForScript;
|
|
13893
14062
|
exports.migrateWalletRepository = migrateWalletRepository;
|
|
13894
|
-
exports.networks = networks2;
|
|
13895
14063
|
exports.openDatabase = openDatabase;
|
|
13896
14064
|
exports.requiresMigration = requiresMigration;
|
|
13897
14065
|
exports.rollbackMigration = rollbackMigration;
|
|
@@ -13906,5 +14074,5 @@ exports.validateVtxoTxGraph = validateVtxoTxGraph;
|
|
|
13906
14074
|
exports.verifyTapscriptSignatures = verifyTapscriptSignatures;
|
|
13907
14075
|
exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
13908
14076
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
13909
|
-
//# sourceMappingURL=chunk-
|
|
13910
|
-
//# sourceMappingURL=chunk-
|
|
14077
|
+
//# sourceMappingURL=chunk-XWJFOP5G.cjs.map
|
|
14078
|
+
//# sourceMappingURL=chunk-XWJFOP5G.cjs.map
|