@arkade-os/sdk 0.5.3 → 0.5.4
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 +36 -34
- package/dist/adapters/expo.cjs +9 -5
- package/dist/adapters/expo.d.cts +11 -7
- package/dist/adapters/expo.d.ts +11 -7
- package/dist/adapters/expo.js +3 -3
- package/dist/{asyncStorageTaskQueue-B3U5gQ-i.d.ts → asyncStorageTaskQueue-DHMIxY04.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-C9PkPcW_.d.cts → asyncStorageTaskQueue-DTBa8EH7.d.cts} +2 -2
- package/dist/{chunk-P7B4LQ3H.js → chunk-6CUP6ZIF.js} +4 -4
- package/dist/{chunk-P7B4LQ3H.js.map → chunk-6CUP6ZIF.js.map} +1 -1
- package/dist/{chunk-OPX2HRWM.js → chunk-AG4TFD6F.js} +137 -59
- package/dist/chunk-AG4TFD6F.js.map +1 -0
- package/dist/{chunk-5WRA66RV.cjs → chunk-B6VNKGIH.cjs} +10 -10
- package/dist/chunk-B6VNKGIH.cjs.map +1 -0
- package/dist/{chunk-6FL4N4S2.js → chunk-BTRCN4JJ.js} +22 -19
- package/dist/chunk-BTRCN4JJ.js.map +1 -0
- package/dist/{chunk-ZPF4I3K2.cjs → chunk-DNITZVNG.cjs} +28 -47
- package/dist/chunk-DNITZVNG.cjs.map +1 -0
- package/dist/{chunk-BYPBVHVA.cjs → chunk-E6OOJEHL.cjs} +49 -49
- package/dist/{chunk-BYPBVHVA.cjs.map → chunk-E6OOJEHL.cjs.map} +1 -1
- package/dist/{chunk-OUTWUYJ4.cjs → chunk-F3FAE7VJ.cjs} +769 -619
- package/dist/chunk-F3FAE7VJ.cjs.map +1 -0
- package/dist/{chunk-KW7ZEWYS.cjs → chunk-GHUUT54D.cjs} +140 -58
- package/dist/chunk-GHUUT54D.cjs.map +1 -0
- package/dist/{chunk-Y4BL3YYX.js → chunk-MWVAWFX6.js} +4 -4
- package/dist/chunk-MWVAWFX6.js.map +1 -0
- package/dist/{chunk-T7C3E2HL.js → chunk-TUOLZBNC.js} +19 -39
- package/dist/chunk-TUOLZBNC.js.map +1 -0
- package/dist/{chunk-ZMSM3NOH.cjs → chunk-WXNSISXK.cjs} +37 -34
- package/dist/chunk-WXNSISXK.cjs.map +1 -0
- package/dist/{chunk-HAQAWBYG.js → chunk-ZJHLLDBP.js} +283 -136
- package/dist/chunk-ZJHLLDBP.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +9 -9
- 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-ByfKszb6.d.cts → delegate-f4_t864Z.d.cts} +1 -1
- package/dist/{delegate-Cd28gxpM.d.ts → delegate-xrSBNybC.d.ts} +1 -1
- package/dist/{index-DgH_0j14.d.cts → index-BJDz15ms.d.ts} +5 -5
- package/dist/{index-B6X2E7W_.d.ts → index-BjiVGtp8.d.cts} +5 -5
- package/dist/{index-BURzbRup.d.ts → index-DRwe0UDN.d.cts} +182 -114
- package/dist/{index-BURzbRup.d.cts → index-DRwe0UDN.d.ts} +182 -114
- package/dist/index.cjs +333 -313
- package/dist/index.d.cts +66 -44
- package/dist/index.d.ts +66 -44
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +65 -36
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +7 -3
- package/dist/repositories/realm/index.d.ts +7 -3
- package/dist/repositories/realm/index.js +35 -6
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +176 -110
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +23 -13
- package/dist/repositories/sqlite/index.d.ts +23 -13
- package/dist/repositories/sqlite/index.js +148 -83
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-i56-drQV.d.cts → taskRunner-BPPU-YHG.d.cts} +4 -4
- package/dist/{taskRunner-BaNCSxqK.d.ts → taskRunner-CDlNeth0.d.ts} +4 -4
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +7 -7
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +15 -15
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +6 -6
- package/dist/wallet/expo/index.d.ts +6 -6
- package/dist/wallet/expo/index.js +6 -6
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/{wallet-BjQugVUt.d.cts → wallet-Oc3Wd5gv.d.ts} +22 -18
- package/dist/{wallet-BnmhohgZ.d.ts → wallet-jVBDQl6R.d.cts} +22 -18
- 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-5WRA66RV.cjs.map +0 -1
- package/dist/chunk-6FL4N4S2.js.map +0 -1
- package/dist/chunk-HAQAWBYG.js.map +0 -1
- package/dist/chunk-KW7ZEWYS.cjs.map +0 -1
- package/dist/chunk-OPX2HRWM.js.map +0 -1
- package/dist/chunk-OUTWUYJ4.cjs.map +0 -1
- package/dist/chunk-T7C3E2HL.js.map +0 -1
- package/dist/chunk-Y4BL3YYX.js.map +0 -1
- package/dist/chunk-ZMSM3NOH.cjs.map +0 -1
- package/dist/chunk-ZPF4I3K2.cjs.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var utils_js = require('@scure/btc-signer/utils.js');
|
|
7
|
-
var btcSigner = require('@scure/btc-signer');
|
|
8
|
-
var base = require('@scure/base');
|
|
3
|
+
var chunkWXNSISXK_cjs = require('./chunk-WXNSISXK.cjs');
|
|
4
|
+
var chunkE6OOJEHL_cjs = require('./chunk-E6OOJEHL.cjs');
|
|
5
|
+
var chunkGHUUT54D_cjs = require('./chunk-GHUUT54D.cjs');
|
|
9
6
|
var musig2 = require('@scure/btc-signer/musig2.js');
|
|
7
|
+
var base = require('@scure/base');
|
|
10
8
|
var utils_js$1 = require('@noble/curves/utils.js');
|
|
11
9
|
var secp256k1 = require('@noble/secp256k1');
|
|
12
10
|
var secp256k1_js = require('@noble/curves/secp256k1.js');
|
|
13
11
|
var script_js = require('@scure/btc-signer/script.js');
|
|
14
12
|
var transaction_js = require('@scure/btc-signer/transaction.js');
|
|
13
|
+
var utils_js = require('@scure/btc-signer/utils.js');
|
|
14
|
+
var btcSigner = require('@scure/btc-signer');
|
|
15
15
|
var bip39 = require('@scure/bip39');
|
|
16
16
|
var english_js = require('@scure/bip39/wordlists/english.js');
|
|
17
17
|
var descriptorsScure = require('@bitcoinerlab/descriptors-scure');
|
|
@@ -145,6 +145,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
145
145
|
graph = null;
|
|
146
146
|
scriptRoot = null;
|
|
147
147
|
rootSharedOutputAmount = null;
|
|
148
|
+
/** Use a fresh key/session per signing attempt; never reuse sessions or their nonces. */
|
|
148
149
|
static random() {
|
|
149
150
|
const secretKey = utils_js.randomPrivateKeyBytes();
|
|
150
151
|
return new _TreeSignerSession(secretKey);
|
|
@@ -187,7 +188,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
187
188
|
noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
|
|
188
189
|
const tx = this.graph.find(txid);
|
|
189
190
|
if (!tx) throw new Error(`missing tx for txid ${txid}`);
|
|
190
|
-
const cosigners =
|
|
191
|
+
const cosigners = chunkGHUUT54D_cjs.getArkPsbtFields(tx.root, 0, chunkGHUUT54D_cjs.CosignerPublicKey).map(
|
|
191
192
|
(c) => base.hex.encode(c.key.subarray(1))
|
|
192
193
|
// xonly pubkey
|
|
193
194
|
);
|
|
@@ -239,7 +240,7 @@ var TreeSignerSession = class _TreeSignerSession {
|
|
|
239
240
|
if (!aggNonce) throw new Error("missing aggregate nonce");
|
|
240
241
|
const prevoutAmounts = [];
|
|
241
242
|
const prevoutScripts = [];
|
|
242
|
-
const cosigners =
|
|
243
|
+
const cosigners = chunkGHUUT54D_cjs.getArkPsbtFields(g.root, 0, chunkGHUUT54D_cjs.CosignerPublicKey).map((c) => c.key);
|
|
243
244
|
const { finalKey } = aggregateKeys(cosigners, true, {
|
|
244
245
|
taprootTweak: this.scriptRoot
|
|
245
246
|
});
|
|
@@ -322,7 +323,7 @@ var SingleKey = class _SingleKey {
|
|
|
322
323
|
async sign(tx, inputIndexes) {
|
|
323
324
|
const txCpy = tx.clone();
|
|
324
325
|
if (!inputIndexes) {
|
|
325
|
-
|
|
326
|
+
chunkGHUUT54D_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
|
|
326
327
|
try {
|
|
327
328
|
if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
|
|
328
329
|
throw new Error("Failed to sign transaction");
|
|
@@ -422,7 +423,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
422
423
|
let network;
|
|
423
424
|
if ("descriptor" in opts && typeof opts.descriptor === "string") {
|
|
424
425
|
descriptor = opts.descriptor;
|
|
425
|
-
network =
|
|
426
|
+
network = chunkE6OOJEHL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
426
427
|
} else {
|
|
427
428
|
network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
428
429
|
descriptor = descriptorsScure.scriptExpressions.trBIP32({
|
|
@@ -499,7 +500,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
499
500
|
}
|
|
500
501
|
/** Returns true when `descriptor` is derived from this identity's seed. */
|
|
501
502
|
ownsDescriptor(descriptor) {
|
|
502
|
-
return
|
|
503
|
+
return chunkE6OOJEHL_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
|
|
503
504
|
}
|
|
504
505
|
/**
|
|
505
506
|
* Signs each request with the key derived from its descriptor.
|
|
@@ -538,7 +539,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
538
539
|
}
|
|
539
540
|
// ── internal helpers ─────────────────────────────────────────────
|
|
540
541
|
derivePrivateKeyForDescriptor(descriptor) {
|
|
541
|
-
const network =
|
|
542
|
+
const network = chunkE6OOJEHL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
542
543
|
const expansion = descriptorsScure.expand({ descriptor, network });
|
|
543
544
|
if (expansion.isRanged) {
|
|
544
545
|
throw new Error(
|
|
@@ -563,7 +564,7 @@ var SeedIdentity = class _SeedIdentity {
|
|
|
563
564
|
signTxWithKey(tx, key, inputIndexes) {
|
|
564
565
|
const txCpy = tx.clone();
|
|
565
566
|
if (!inputIndexes) {
|
|
566
|
-
|
|
567
|
+
chunkGHUUT54D_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
|
|
567
568
|
try {
|
|
568
569
|
if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
|
|
569
570
|
throw new Error("Failed to sign transaction");
|
|
@@ -615,7 +616,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
615
616
|
/** Wildcard account-descriptor template (e.g. `tr([fp/86'/0'/0']xpub/0/*)`). */
|
|
616
617
|
descriptor;
|
|
617
618
|
constructor(descriptor) {
|
|
618
|
-
const network =
|
|
619
|
+
const network = chunkE6OOJEHL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
619
620
|
let expansion;
|
|
620
621
|
try {
|
|
621
622
|
expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
|
|
@@ -650,7 +651,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
|
|
|
650
651
|
}
|
|
651
652
|
/** Returns true when `descriptor` derives from this identity's xpub. */
|
|
652
653
|
ownsDescriptor(descriptor) {
|
|
653
|
-
return
|
|
654
|
+
return chunkE6OOJEHL_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
|
|
654
655
|
}
|
|
655
656
|
};
|
|
656
657
|
function serializeSeedOwnedSigningIdentity(identity) {
|
|
@@ -793,10 +794,10 @@ var DescriptorIdentity = class {
|
|
|
793
794
|
this.base = base;
|
|
794
795
|
}
|
|
795
796
|
async xOnlyPublicKey() {
|
|
796
|
-
return
|
|
797
|
+
return chunkE6OOJEHL_cjs.deriveDescriptorLeafPubKey(this.descriptor);
|
|
797
798
|
}
|
|
798
799
|
async compressedPublicKey() {
|
|
799
|
-
return
|
|
800
|
+
return chunkE6OOJEHL_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
|
|
800
801
|
}
|
|
801
802
|
async sign(tx, inputIndexes) {
|
|
802
803
|
const [signed] = await this.signer.signWithDescriptor([
|
|
@@ -856,8 +857,8 @@ var StaticDescriptorProvider = class _StaticDescriptorProvider {
|
|
|
856
857
|
}
|
|
857
858
|
isOurs(descriptor) {
|
|
858
859
|
try {
|
|
859
|
-
const normalized =
|
|
860
|
-
const pubKey =
|
|
860
|
+
const normalized = chunkE6OOJEHL_cjs.normalizeToDescriptor(descriptor);
|
|
861
|
+
const pubKey = chunkE6OOJEHL_cjs.extractPubKey(normalized);
|
|
861
862
|
return pubKey.toLowerCase() === this.pubKeyHex.toLowerCase();
|
|
862
863
|
} catch {
|
|
863
864
|
return false;
|
|
@@ -913,9 +914,14 @@ var OVERLAP_MS = 24 * 60 * 60 * 1e3;
|
|
|
913
914
|
var walletStateLocks = /* @__PURE__ */ new WeakMap();
|
|
914
915
|
var WALLET_STATE_LOCK_NAME = "arkade-wallet-state";
|
|
915
916
|
async function updateWalletState(repo, updater) {
|
|
917
|
+
const atomic = repo.atomicWalletState;
|
|
916
918
|
const prev = walletStateLocks.get(repo) ?? Promise.resolve();
|
|
917
919
|
const op = prev.then(
|
|
918
920
|
() => withWebLock(WALLET_STATE_LOCK_NAME, async () => {
|
|
921
|
+
if (atomic !== void 0) {
|
|
922
|
+
await atomic.update(updater);
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
919
925
|
const state = await repo.getWalletState() ?? {};
|
|
920
926
|
await repo.saveWalletState(updater(state));
|
|
921
927
|
})
|
|
@@ -1194,7 +1200,7 @@ function unwrapKeyring(provider) {
|
|
|
1194
1200
|
}
|
|
1195
1201
|
function keyOf(descriptor) {
|
|
1196
1202
|
try {
|
|
1197
|
-
return
|
|
1203
|
+
return chunkE6OOJEHL_cjs.extractPubKey(chunkE6OOJEHL_cjs.normalizeToDescriptor(descriptor)).toLowerCase();
|
|
1198
1204
|
} catch {
|
|
1199
1205
|
return void 0;
|
|
1200
1206
|
}
|
|
@@ -1285,12 +1291,12 @@ async function resolveDescriptorSigner(descriptor, identity, provider) {
|
|
|
1285
1291
|
signMessageWithDescriptor: (ownedDescriptor, message, signatureType) => identity.signDescriptorMessage(ownedDescriptor, message, signatureType)
|
|
1286
1292
|
} : void 0;
|
|
1287
1293
|
const owner = providerOwner ?? identityOwner;
|
|
1288
|
-
if (owner &&
|
|
1294
|
+
if (owner && chunkE6OOJEHL_cjs.parseHDDescriptor(descriptor)) {
|
|
1289
1295
|
return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
|
|
1290
1296
|
}
|
|
1291
1297
|
let key;
|
|
1292
1298
|
try {
|
|
1293
|
-
key =
|
|
1299
|
+
key = chunkE6OOJEHL_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1294
1300
|
} catch {
|
|
1295
1301
|
throw new ForeignDescriptorError(descriptor);
|
|
1296
1302
|
}
|
|
@@ -1343,14 +1349,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
|
|
|
1343
1349
|
}
|
|
1344
1350
|
var PREIMAGE_INDEX = 0;
|
|
1345
1351
|
function isPerArtifactDescriptor(descriptor) {
|
|
1346
|
-
return
|
|
1352
|
+
return chunkE6OOJEHL_cjs.parseHDDescriptor(descriptor) !== null;
|
|
1347
1353
|
}
|
|
1348
1354
|
async function provisionDescriptor(wallet) {
|
|
1349
1355
|
const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
|
|
1350
|
-
return allocated ?? await
|
|
1356
|
+
return allocated ?? await chunkE6OOJEHL_cjs.identityDescriptor(wallet.identity);
|
|
1351
1357
|
}
|
|
1352
1358
|
async function provisionRefundKey(wallet) {
|
|
1353
|
-
const descriptorPromise =
|
|
1359
|
+
const descriptorPromise = chunkE6OOJEHL_cjs.identityDescriptor(wallet.identity);
|
|
1354
1360
|
const identityPubkeyPromise = wallet.identity.xOnlyPublicKey();
|
|
1355
1361
|
void identityPubkeyPromise.catch(() => void 0);
|
|
1356
1362
|
const descriptor = await descriptorPromise;
|
|
@@ -1365,7 +1371,7 @@ async function provisionRefundKey(wallet) {
|
|
|
1365
1371
|
);
|
|
1366
1372
|
}
|
|
1367
1373
|
const address = await wallet.getAddress();
|
|
1368
|
-
const { pkScript } =
|
|
1374
|
+
const { pkScript } = chunkGHUUT54D_cjs.ArkAddress.decode(address);
|
|
1369
1375
|
return { descriptor, pubkey, pkScript, address };
|
|
1370
1376
|
}
|
|
1371
1377
|
async function provisionClaimSecret(wallet, opts = {}) {
|
|
@@ -1413,7 +1419,7 @@ async function contractSigner(wallet, descriptor) {
|
|
|
1413
1419
|
const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
|
|
1414
1420
|
let expected;
|
|
1415
1421
|
try {
|
|
1416
|
-
expected =
|
|
1422
|
+
expected = chunkE6OOJEHL_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
1417
1423
|
} catch (cause) {
|
|
1418
1424
|
throw new ForeignDescriptorError(descriptor, { cause });
|
|
1419
1425
|
}
|
|
@@ -1495,7 +1501,7 @@ function debugLog(debug, ...args) {
|
|
|
1495
1501
|
}
|
|
1496
1502
|
function normalizeOptions(pathOrOptions) {
|
|
1497
1503
|
const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
1498
|
-
|
|
1504
|
+
chunkGHUUT54D_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
|
|
1499
1505
|
return {
|
|
1500
1506
|
path: o.path,
|
|
1501
1507
|
updateViaCache: o.updateViaCache ?? "none",
|
|
@@ -1618,14 +1624,14 @@ var RestDelegateProvider = class {
|
|
|
1618
1624
|
*/
|
|
1619
1625
|
async delegate(intent, forfeitTxs, options) {
|
|
1620
1626
|
const url = `${this.url}/v1/delegate`;
|
|
1621
|
-
const response = await
|
|
1627
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(url, {
|
|
1622
1628
|
method: "POST",
|
|
1623
1629
|
headers: {
|
|
1624
1630
|
"Content-Type": "application/json"
|
|
1625
1631
|
},
|
|
1626
1632
|
body: JSON.stringify({
|
|
1627
1633
|
intent: {
|
|
1628
|
-
message:
|
|
1634
|
+
message: chunkGHUUT54D_cjs.Proof.encodeMessage(intent.message),
|
|
1629
1635
|
proof: intent.proof
|
|
1630
1636
|
},
|
|
1631
1637
|
forfeit_txs: forfeitTxs,
|
|
@@ -1644,7 +1650,7 @@ var RestDelegateProvider = class {
|
|
|
1644
1650
|
*/
|
|
1645
1651
|
async getDelegateInfo() {
|
|
1646
1652
|
const url = `${this.url}/v1/delegator/info`;
|
|
1647
|
-
const response = await
|
|
1653
|
+
const response = await chunkGHUUT54D_cjs.rateGate.runHttp(url, () => chunkGHUUT54D_cjs.baseFetch(url));
|
|
1648
1654
|
if (!response.ok) {
|
|
1649
1655
|
const errorText2 = await response.text();
|
|
1650
1656
|
throw new Error(`Failed to get delegate info: ${errorText2}`);
|
|
@@ -1700,7 +1706,7 @@ async function collectPages(read) {
|
|
|
1700
1706
|
return items;
|
|
1701
1707
|
}
|
|
1702
1708
|
function scriptFromArkAddress(address) {
|
|
1703
|
-
return base.hex.encode(
|
|
1709
|
+
return base.hex.encode(chunkGHUUT54D_cjs.ArkAddress.decode(address).pkScript);
|
|
1704
1710
|
}
|
|
1705
1711
|
|
|
1706
1712
|
// src/repositories/walletRepository.ts
|
|
@@ -1722,6 +1728,15 @@ function assertHistoryPageFilter(filter) {
|
|
|
1722
1728
|
throw new RangeError("history since must be non-negative Unix milliseconds");
|
|
1723
1729
|
}
|
|
1724
1730
|
}
|
|
1731
|
+
function applyWalletStateUpdate(state, updater) {
|
|
1732
|
+
const updated = updater(state);
|
|
1733
|
+
if (updated && typeof updated.then === "function") {
|
|
1734
|
+
if (updated instanceof Promise) void updated.catch(() => {
|
|
1735
|
+
});
|
|
1736
|
+
throw new TypeError("wallet-state updater must be synchronous");
|
|
1737
|
+
}
|
|
1738
|
+
return updated;
|
|
1739
|
+
}
|
|
1725
1740
|
function compareScriptVtxoCursors(a, b) {
|
|
1726
1741
|
return a.address < b.address ? -1 : a.address > b.address ? 1 : compareOutpoints(a, b);
|
|
1727
1742
|
}
|
|
@@ -1762,9 +1777,9 @@ async function collectScriptVtxos(repository, script, options) {
|
|
|
1762
1777
|
return [...byOutpoint.values()].map((row) => row.vtxo);
|
|
1763
1778
|
}
|
|
1764
1779
|
function unspentScriptVtxos(rows, copies) {
|
|
1765
|
-
const spent = copies.filter((copy) =>
|
|
1780
|
+
const spent = copies.filter((copy) => chunkGHUUT54D_cjs.isVtxoSpent(copy.vtxo));
|
|
1766
1781
|
return rows.filter(
|
|
1767
|
-
(row) => !
|
|
1782
|
+
(row) => !chunkGHUUT54D_cjs.isVtxoSpent(row.vtxo) && !spent.some(
|
|
1768
1783
|
(copy) => copy.address !== row.address && copy.vtxo.txid === row.vtxo.txid && copy.vtxo.vout === row.vtxo.vout && shouldReplaceScriptVtxo(row, copy)
|
|
1769
1784
|
)
|
|
1770
1785
|
);
|
|
@@ -1847,7 +1862,7 @@ var ESPLORA_URL = {
|
|
|
1847
1862
|
regtest: "http://localhost:3000/api"
|
|
1848
1863
|
};
|
|
1849
1864
|
var EsploraProvider = class {
|
|
1850
|
-
constructor(baseUrl = ESPLORA_URL[
|
|
1865
|
+
constructor(baseUrl = ESPLORA_URL[chunkGHUUT54D_cjs.DEFAULT_NETWORK_NAME], opts) {
|
|
1851
1866
|
this.baseUrl = baseUrl;
|
|
1852
1867
|
this.pollingInterval = opts?.pollingInterval ?? 15e3;
|
|
1853
1868
|
this.forcePolling = opts?.forcePolling ?? false;
|
|
@@ -1862,7 +1877,7 @@ var EsploraProvider = class {
|
|
|
1862
1877
|
*/
|
|
1863
1878
|
addressWatches = /* @__PURE__ */ new Map();
|
|
1864
1879
|
async getCoins(address) {
|
|
1865
|
-
const response = await
|
|
1880
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
1866
1881
|
if (!response.ok) {
|
|
1867
1882
|
throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
|
|
1868
1883
|
}
|
|
@@ -1871,12 +1886,12 @@ var EsploraProvider = class {
|
|
|
1871
1886
|
async getFeeRate() {
|
|
1872
1887
|
let url = `${this.baseUrl}/fee-estimates`;
|
|
1873
1888
|
let key = "1";
|
|
1874
|
-
let response = await
|
|
1889
|
+
let response = await chunkGHUUT54D_cjs.baseFetch(url);
|
|
1875
1890
|
if (response.status === 404) {
|
|
1876
1891
|
await response.body?.cancel();
|
|
1877
1892
|
url = `${this.baseUrl}/v1/fees/recommended`;
|
|
1878
1893
|
key = "fastestFee";
|
|
1879
|
-
response = await
|
|
1894
|
+
response = await chunkGHUUT54D_cjs.baseFetch(url);
|
|
1880
1895
|
}
|
|
1881
1896
|
if (response.status === 404) {
|
|
1882
1897
|
await response.body?.cancel();
|
|
@@ -1913,7 +1928,7 @@ var EsploraProvider = class {
|
|
|
1913
1928
|
}
|
|
1914
1929
|
}
|
|
1915
1930
|
async getTxOutspends(txid) {
|
|
1916
|
-
const response = await
|
|
1931
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
|
|
1917
1932
|
if (!response.ok) {
|
|
1918
1933
|
const error = await response.text();
|
|
1919
1934
|
throw new Error(`Failed to get transaction outspends: ${error}`);
|
|
@@ -1921,7 +1936,7 @@ var EsploraProvider = class {
|
|
|
1921
1936
|
return response.json();
|
|
1922
1937
|
}
|
|
1923
1938
|
async getTransactions(address) {
|
|
1924
|
-
const response = await
|
|
1939
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
|
|
1925
1940
|
if (!response.ok) {
|
|
1926
1941
|
const error = await response.text();
|
|
1927
1942
|
throw new Error(`Failed to get transactions: ${error}`);
|
|
@@ -1930,14 +1945,14 @@ var EsploraProvider = class {
|
|
|
1930
1945
|
}
|
|
1931
1946
|
/** Orders of magnitude smaller than `/address/{addr}/txs`: the polling fallback's probe. */
|
|
1932
1947
|
async getAddressStats(address) {
|
|
1933
|
-
const response = await
|
|
1948
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
|
|
1934
1949
|
if (!response.ok) {
|
|
1935
1950
|
throw new Error(`Failed to get address stats: ${response.statusText}`);
|
|
1936
1951
|
}
|
|
1937
1952
|
return response.json();
|
|
1938
1953
|
}
|
|
1939
1954
|
async getRawTransaction(txid) {
|
|
1940
|
-
const response = await
|
|
1955
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
|
|
1941
1956
|
if (!response.ok) {
|
|
1942
1957
|
const error = await response.text();
|
|
1943
1958
|
throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
|
|
@@ -1945,7 +1960,7 @@ var EsploraProvider = class {
|
|
|
1945
1960
|
return base.hex.decode((await response.text()).trim());
|
|
1946
1961
|
}
|
|
1947
1962
|
async getTxStatus(txid) {
|
|
1948
|
-
const txresponse = await
|
|
1963
|
+
const txresponse = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
|
|
1949
1964
|
if (!txresponse.ok) {
|
|
1950
1965
|
throw new Error(txresponse.statusText);
|
|
1951
1966
|
}
|
|
@@ -1953,7 +1968,7 @@ var EsploraProvider = class {
|
|
|
1953
1968
|
if (!tx.status.confirmed) {
|
|
1954
1969
|
return { confirmed: false };
|
|
1955
1970
|
}
|
|
1956
|
-
const response = await
|
|
1971
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
|
|
1957
1972
|
if (!response.ok) {
|
|
1958
1973
|
throw new Error(`Failed to get transaction status: ${response.statusText}`);
|
|
1959
1974
|
}
|
|
@@ -2227,9 +2242,9 @@ var EsploraProvider = class {
|
|
|
2227
2242
|
return { subscribers, teardown, started };
|
|
2228
2243
|
}
|
|
2229
2244
|
async getChainTip() {
|
|
2230
|
-
let tipBlocks = await
|
|
2245
|
+
let tipBlocks = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/blocks`);
|
|
2231
2246
|
if (tipBlocks.status === 404) {
|
|
2232
|
-
tipBlocks = await
|
|
2247
|
+
tipBlocks = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
|
|
2233
2248
|
}
|
|
2234
2249
|
if (!tipBlocks.ok) {
|
|
2235
2250
|
throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
|
|
@@ -2250,7 +2265,7 @@ var EsploraProvider = class {
|
|
|
2250
2265
|
};
|
|
2251
2266
|
}
|
|
2252
2267
|
async broadcastPackage(parent, child) {
|
|
2253
|
-
const response = await
|
|
2268
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
|
|
2254
2269
|
method: "POST",
|
|
2255
2270
|
headers: {
|
|
2256
2271
|
"Content-Type": "application/json"
|
|
@@ -2266,7 +2281,7 @@ var EsploraProvider = class {
|
|
|
2266
2281
|
return result;
|
|
2267
2282
|
}
|
|
2268
2283
|
async broadcastTx(tx) {
|
|
2269
|
-
const response = await
|
|
2284
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(`${this.baseUrl}/tx`, {
|
|
2270
2285
|
method: "POST",
|
|
2271
2286
|
headers: {
|
|
2272
2287
|
"Content-Type": "text/plain"
|
|
@@ -2438,7 +2453,7 @@ function findP2AOutput(tx) {
|
|
|
2438
2453
|
var CHILD_DUST_AMOUNT = 546;
|
|
2439
2454
|
function buildAnchorChild(params) {
|
|
2440
2455
|
const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
|
|
2441
|
-
const child = new
|
|
2456
|
+
const child = new chunkGHUUT54D_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
|
|
2442
2457
|
const anchor = findP2AOutput(parent);
|
|
2443
2458
|
child.addInput(anchor);
|
|
2444
2459
|
const estimator = TxWeightEstimator.create().addP2AInput();
|
|
@@ -2487,7 +2502,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
|
|
|
2487
2502
|
);
|
|
2488
2503
|
}
|
|
2489
2504
|
function buildForfeitTxWithOutput(inputs, output, txLocktime) {
|
|
2490
|
-
const tx = new
|
|
2505
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({
|
|
2491
2506
|
version: 3,
|
|
2492
2507
|
lockTime: txLocktime
|
|
2493
2508
|
});
|
|
@@ -2514,7 +2529,7 @@ function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
|
|
|
2514
2529
|
connectorsGraph.validate();
|
|
2515
2530
|
if (connectorsGraph.root.inputsLength !== 1) throw ErrNumberOfInputs;
|
|
2516
2531
|
const rootInput = connectorsGraph.root.getInput(0);
|
|
2517
|
-
const settlementTx =
|
|
2532
|
+
const settlementTx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(settlementTxB64));
|
|
2518
2533
|
if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
|
|
2519
2534
|
throw ErrInvalidSettlementTxOutputs;
|
|
2520
2535
|
const expectedRootTxid = settlementTx.id;
|
|
@@ -2563,7 +2578,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
|
|
|
2563
2578
|
if (previousScriptKey.length !== 32) {
|
|
2564
2579
|
throw new Error(`parent output ${childIndex} has invalid script`);
|
|
2565
2580
|
}
|
|
2566
|
-
const cosigners =
|
|
2581
|
+
const cosigners = chunkGHUUT54D_cjs.getArkPsbtFields(child.root, 0, chunkGHUUT54D_cjs.CosignerPublicKey);
|
|
2567
2582
|
if (cosigners.length === 0) {
|
|
2568
2583
|
throw ErrMissingCosignersPublicKeys;
|
|
2569
2584
|
}
|
|
@@ -2621,7 +2636,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2621
2636
|
return new _EmulatorPacket(entries);
|
|
2622
2637
|
}
|
|
2623
2638
|
static fromBytes(data) {
|
|
2624
|
-
const reader = new
|
|
2639
|
+
const reader = new chunkWXNSISXK_cjs.BufferReader(data);
|
|
2625
2640
|
const entryCount = reader.readCompactSize();
|
|
2626
2641
|
const entries = [];
|
|
2627
2642
|
for (let i = 0; i < entryCount; i++) {
|
|
@@ -2639,7 +2654,7 @@ var EmulatorPacket = class _EmulatorPacket {
|
|
|
2639
2654
|
return _EmulatorPacket.PACKET_TYPE;
|
|
2640
2655
|
}
|
|
2641
2656
|
serialize() {
|
|
2642
|
-
const writer = new
|
|
2657
|
+
const writer = new chunkWXNSISXK_cjs.BufferWriter();
|
|
2643
2658
|
writer.writeCompactSize(this.entries.length);
|
|
2644
2659
|
for (const entry of this.entries) {
|
|
2645
2660
|
writer.writeUint16LE(entry.vin);
|
|
@@ -2726,7 +2741,7 @@ var Extension = class _Extension {
|
|
|
2726
2741
|
`expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
|
|
2727
2742
|
);
|
|
2728
2743
|
}
|
|
2729
|
-
const reader = new
|
|
2744
|
+
const reader = new chunkWXNSISXK_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
|
|
2730
2745
|
const packets = [];
|
|
2731
2746
|
while (reader.remaining() > 0) {
|
|
2732
2747
|
const packetType = reader.readByte();
|
|
@@ -2799,7 +2814,7 @@ var Extension = class _Extension {
|
|
|
2799
2814
|
* getAssetPacket returns the embedded Packet, or null if not present.
|
|
2800
2815
|
*/
|
|
2801
2816
|
getAssetPacket() {
|
|
2802
|
-
return this.packets.find((p) => p instanceof
|
|
2817
|
+
return this.packets.find((p) => p instanceof chunkWXNSISXK_cjs.Packet) ?? null;
|
|
2803
2818
|
}
|
|
2804
2819
|
/**
|
|
2805
2820
|
* getEmulatorPacket returns the embedded EmulatorPacket, or null if not present.
|
|
@@ -2823,8 +2838,8 @@ var Extension = class _Extension {
|
|
|
2823
2838
|
};
|
|
2824
2839
|
function parsePacket(packetType, data) {
|
|
2825
2840
|
switch (packetType) {
|
|
2826
|
-
case
|
|
2827
|
-
return
|
|
2841
|
+
case chunkWXNSISXK_cjs.Packet.PACKET_TYPE:
|
|
2842
|
+
return chunkWXNSISXK_cjs.Packet.fromBytes(data);
|
|
2828
2843
|
case EmulatorPacket.PACKET_TYPE:
|
|
2829
2844
|
return EmulatorPacket.fromBytes(data);
|
|
2830
2845
|
default:
|
|
@@ -2871,23 +2886,23 @@ function buildOpReturnScript(data) {
|
|
|
2871
2886
|
}
|
|
2872
2887
|
return script;
|
|
2873
2888
|
}
|
|
2874
|
-
var ErrOffchainOutputNotFound = (address) => new
|
|
2875
|
-
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new
|
|
2889
|
+
var ErrOffchainOutputNotFound = (address) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
|
|
2890
|
+
var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2876
2891
|
`invalid asset output amount for ${assetId}: got ${got}, want ${want}`
|
|
2877
2892
|
);
|
|
2878
|
-
var ErrAssetGroupNotFound = (assetId) => new
|
|
2879
|
-
var ErrAssetOutputNotFound = (assetId, outputIndex) => new
|
|
2893
|
+
var ErrAssetGroupNotFound = (assetId) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
|
|
2894
|
+
var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2880
2895
|
`asset output not found in asset group ${assetId} at index ${outputIndex}`
|
|
2881
2896
|
);
|
|
2882
|
-
var ErrOnchainOutputNotFound = (address) => new
|
|
2883
|
-
var ErrUnvalidatedOffchainOutput = (address) => new
|
|
2897
|
+
var ErrOnchainOutputNotFound = (address) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
|
|
2898
|
+
var ErrUnvalidatedOffchainOutput = (address) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2884
2899
|
`offchain output ${address} cannot be validated: virtual output tree signing did not run`
|
|
2885
2900
|
);
|
|
2886
|
-
var ErrIntentOutputNotFound = (index, kind) => new
|
|
2887
|
-
`${kind} output ${index} of the
|
|
2901
|
+
var ErrIntentOutputNotFound = (index, kind) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2902
|
+
`${kind} output ${index} of the proof is not present in what the server built`
|
|
2888
2903
|
);
|
|
2889
|
-
var ErrUnvalidatedIntentOutput = (index) => new
|
|
2890
|
-
`offchain output ${index} of the
|
|
2904
|
+
var ErrUnvalidatedIntentOutput = (index) => new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2905
|
+
`offchain output ${index} of the proof cannot be validated: virtual output tree signing did not run`
|
|
2891
2906
|
);
|
|
2892
2907
|
var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
|
|
2893
2908
|
var ErrInvalidOnchainOutputAssets = (address) => new Error(`onchain output ${address} cannot have assets`);
|
|
@@ -2895,7 +2910,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
|
|
|
2895
2910
|
function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
|
|
2896
2911
|
if (!validatedCommitmentTxid) return;
|
|
2897
2912
|
if (finalCommitmentTx.id === validatedCommitmentTxid) return;
|
|
2898
|
-
throw new
|
|
2913
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
2899
2914
|
`${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
|
|
2900
2915
|
);
|
|
2901
2916
|
}
|
|
@@ -2905,7 +2920,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
|
|
|
2905
2920
|
for (const recipient of recipients) {
|
|
2906
2921
|
let arkAddress;
|
|
2907
2922
|
try {
|
|
2908
|
-
arkAddress =
|
|
2923
|
+
arkAddress = chunkGHUUT54D_cjs.ArkAddress.decode(recipient.address);
|
|
2909
2924
|
} catch {
|
|
2910
2925
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2911
2926
|
continue;
|
|
@@ -2917,7 +2932,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2917
2932
|
const usedOnchainOutputs = /* @__PURE__ */ new Set();
|
|
2918
2933
|
for (const recipient of recipients) {
|
|
2919
2934
|
try {
|
|
2920
|
-
|
|
2935
|
+
chunkGHUUT54D_cjs.ArkAddress.decode(recipient.address);
|
|
2921
2936
|
} catch {
|
|
2922
2937
|
validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
|
|
2923
2938
|
continue;
|
|
@@ -2926,7 +2941,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
|
|
|
2926
2941
|
}
|
|
2927
2942
|
}
|
|
2928
2943
|
function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
|
|
2929
|
-
const proof =
|
|
2944
|
+
const proof = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
|
|
2930
2945
|
const onchain = new Set(onchainOutputIndexes);
|
|
2931
2946
|
const declared = [];
|
|
2932
2947
|
for (let i = 0; i < proof.outputsLength; i++) {
|
|
@@ -3218,7 +3233,7 @@ function assetMintResolver() {
|
|
|
3218
3233
|
if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
|
|
3219
3234
|
const minted = tx.assets.filter((a) => {
|
|
3220
3235
|
try {
|
|
3221
|
-
return base.hex.encode(
|
|
3236
|
+
return base.hex.encode(chunkWXNSISXK_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
|
|
3222
3237
|
} catch {
|
|
3223
3238
|
return false;
|
|
3224
3239
|
}
|
|
@@ -3295,7 +3310,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3295
3310
|
const existing = inputsByAssetId.get(asset.assetId);
|
|
3296
3311
|
inputsByAssetId.set(asset.assetId, [
|
|
3297
3312
|
...existing ?? [],
|
|
3298
|
-
|
|
3313
|
+
chunkWXNSISXK_cjs.AssetInput.create(inputIndex, asset.amount)
|
|
3299
3314
|
]);
|
|
3300
3315
|
}
|
|
3301
3316
|
}
|
|
@@ -3307,7 +3322,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3307
3322
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3308
3323
|
outputsByAssetId.set(asset.assetId, [
|
|
3309
3324
|
...existing ?? [],
|
|
3310
|
-
|
|
3325
|
+
chunkWXNSISXK_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3311
3326
|
]);
|
|
3312
3327
|
}
|
|
3313
3328
|
}
|
|
@@ -3318,7 +3333,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3318
3333
|
const existing = outputsByAssetId.get(asset.assetId);
|
|
3319
3334
|
outputsByAssetId.set(asset.assetId, [
|
|
3320
3335
|
...existing ?? [],
|
|
3321
|
-
|
|
3336
|
+
chunkWXNSISXK_cjs.AssetOutput.create(outputIndex, asset.amount)
|
|
3322
3337
|
]);
|
|
3323
3338
|
}
|
|
3324
3339
|
}
|
|
@@ -3327,11 +3342,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
|
|
|
3327
3342
|
for (const assetIdStr of allAssetIds) {
|
|
3328
3343
|
const inputs = inputsByAssetId.get(assetIdStr);
|
|
3329
3344
|
const outputs = outputsByAssetId.get(assetIdStr);
|
|
3330
|
-
const assetId =
|
|
3331
|
-
const group =
|
|
3345
|
+
const assetId = chunkWXNSISXK_cjs.AssetId.fromString(assetIdStr);
|
|
3346
|
+
const group = chunkWXNSISXK_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
|
|
3332
3347
|
groups.push(group);
|
|
3333
3348
|
}
|
|
3334
|
-
return
|
|
3349
|
+
return chunkWXNSISXK_cjs.Packet.create(groups);
|
|
3335
3350
|
}
|
|
3336
3351
|
function selectCoinsWithAsset(coins, assetId, requiredAmount) {
|
|
3337
3352
|
const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
|
|
@@ -3415,7 +3430,7 @@ function meetsInputExpiryFloor(coin, floor) {
|
|
|
3415
3430
|
}
|
|
3416
3431
|
function toXOnlySignerHex(pubkeyHex) {
|
|
3417
3432
|
const bytes = base.hex.decode(pubkeyHex);
|
|
3418
|
-
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(
|
|
3433
|
+
if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunkE6OOJEHL_cjs.toXOnly(bytes, "signer key"));
|
|
3419
3434
|
throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes.length}`);
|
|
3420
3435
|
}
|
|
3421
3436
|
function signerSetFromInfo(info) {
|
|
@@ -3462,14 +3477,14 @@ var toTimelock = (value) => ({
|
|
|
3462
3477
|
var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
|
|
3463
3478
|
function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
|
|
3464
3479
|
if (policy.requireSeconds && timelock.type === "blocks") {
|
|
3465
|
-
throw new
|
|
3480
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3466
3481
|
`${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
|
|
3467
3482
|
);
|
|
3468
3483
|
}
|
|
3469
3484
|
const seconds = toSeconds(timelock);
|
|
3470
3485
|
if (seconds < policy.minSeconds) {
|
|
3471
3486
|
const remedy = overrideOption ? `; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it` : "";
|
|
3472
|
-
throw new
|
|
3487
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3473
3488
|
`${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor${remedy}`
|
|
3474
3489
|
);
|
|
3475
3490
|
}
|
|
@@ -3490,7 +3505,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
|
|
|
3490
3505
|
}
|
|
3491
3506
|
function assertValidBatchExpiry(batchExpiry, policy) {
|
|
3492
3507
|
if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
|
|
3493
|
-
throw new
|
|
3508
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3494
3509
|
`batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
|
|
3495
3510
|
);
|
|
3496
3511
|
}
|
|
@@ -3499,21 +3514,21 @@ function assertValidBatchExpiry(batchExpiry, policy) {
|
|
|
3499
3514
|
function assertValidServerUnrollScript(checkpointTapscript, network, advertisedForfeitPubkey) {
|
|
3500
3515
|
let script;
|
|
3501
3516
|
try {
|
|
3502
|
-
script =
|
|
3517
|
+
script = chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
|
|
3503
3518
|
} catch (e) {
|
|
3504
|
-
throw new
|
|
3519
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3505
3520
|
`checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
|
|
3506
3521
|
);
|
|
3507
3522
|
}
|
|
3508
3523
|
if (advertisedForfeitPubkey !== void 0) {
|
|
3509
3524
|
const { pubkeys } = script.params;
|
|
3510
3525
|
if (pubkeys.length !== 1) {
|
|
3511
|
-
throw new
|
|
3526
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3512
3527
|
`checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
|
|
3513
3528
|
);
|
|
3514
3529
|
}
|
|
3515
3530
|
if (!utils_js.equalBytes(pubkeys[0], advertisedForfeitPubkey)) {
|
|
3516
|
-
throw new
|
|
3531
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3517
3532
|
`checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(advertisedForfeitPubkey)}`
|
|
3518
3533
|
);
|
|
3519
3534
|
}
|
|
@@ -3556,8 +3571,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
|
|
|
3556
3571
|
function buildVirtualTx(inputs, outputs) {
|
|
3557
3572
|
let lockTime = 0n;
|
|
3558
3573
|
for (const input of inputs) {
|
|
3559
|
-
const tapscript =
|
|
3560
|
-
if (
|
|
3574
|
+
const tapscript = chunkGHUUT54D_cjs.decodeTapscript(chunkGHUUT54D_cjs.scriptFromTapLeafScript(input.tapLeafScript));
|
|
3575
|
+
if (chunkGHUUT54D_cjs.CLTVMultisigTapscript.is(tapscript)) {
|
|
3561
3576
|
if (lockTime !== 0n) {
|
|
3562
3577
|
if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
|
|
3563
3578
|
throw new Error("cannot mix seconds and blocks locktime");
|
|
@@ -3568,7 +3583,7 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3568
3583
|
}
|
|
3569
3584
|
}
|
|
3570
3585
|
}
|
|
3571
|
-
const tx = new
|
|
3586
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({
|
|
3572
3587
|
version: 3,
|
|
3573
3588
|
lockTime: Number(lockTime)
|
|
3574
3589
|
});
|
|
@@ -3578,12 +3593,12 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3578
3593
|
index: input.vout,
|
|
3579
3594
|
sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
|
|
3580
3595
|
witnessUtxo: {
|
|
3581
|
-
script:
|
|
3596
|
+
script: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript,
|
|
3582
3597
|
amount: BigInt(input.value)
|
|
3583
3598
|
},
|
|
3584
3599
|
tapLeafScript: [input.tapLeafScript]
|
|
3585
3600
|
});
|
|
3586
|
-
|
|
3601
|
+
chunkGHUUT54D_cjs.setArkPsbtField(tx, i, chunkGHUUT54D_cjs.VtxoTaprootTree, input.tapTree);
|
|
3587
3602
|
}
|
|
3588
3603
|
for (const output of outputs) {
|
|
3589
3604
|
tx.addOutput(output);
|
|
@@ -3594,8 +3609,8 @@ function buildVirtualTx(inputs, outputs) {
|
|
|
3594
3609
|
return tx;
|
|
3595
3610
|
}
|
|
3596
3611
|
function buildCheckpointTx(vtxo, serverUnrollScript) {
|
|
3597
|
-
const collaborativeClosure =
|
|
3598
|
-
const checkpointVtxoScript = new
|
|
3612
|
+
const collaborativeClosure = chunkGHUUT54D_cjs.decodeTapscript(chunkGHUUT54D_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
|
|
3613
|
+
const checkpointVtxoScript = new chunkGHUUT54D_cjs.VtxoScript([
|
|
3599
3614
|
serverUnrollScript.script,
|
|
3600
3615
|
collaborativeClosure.script
|
|
3601
3616
|
]);
|
|
@@ -3671,7 +3686,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
|
|
|
3671
3686
|
const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
|
|
3672
3687
|
const sig = signature.subarray(0, 64);
|
|
3673
3688
|
if (!allowedSighashTypes.includes(sighashType)) {
|
|
3674
|
-
const sighashName =
|
|
3689
|
+
const sighashName = chunkGHUUT54D_cjs.formatSighash(sighashType);
|
|
3675
3690
|
throw new Error(
|
|
3676
3691
|
`Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
|
|
3677
3692
|
);
|
|
@@ -3745,7 +3760,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
|
|
|
3745
3760
|
}
|
|
3746
3761
|
function isValidArkAddress(address) {
|
|
3747
3762
|
try {
|
|
3748
|
-
|
|
3763
|
+
chunkGHUUT54D_cjs.ArkAddress.decode(address);
|
|
3749
3764
|
return true;
|
|
3750
3765
|
} catch (e) {
|
|
3751
3766
|
return false;
|
|
@@ -3753,16 +3768,16 @@ function isValidArkAddress(address) {
|
|
|
3753
3768
|
}
|
|
3754
3769
|
function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
|
|
3755
3770
|
if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
|
|
3756
|
-
throw new
|
|
3771
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3757
3772
|
`${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
|
|
3758
3773
|
);
|
|
3759
3774
|
}
|
|
3760
3775
|
const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
|
|
3761
3776
|
return serverCheckpointTxs.map((encoded, index) => {
|
|
3762
|
-
const server =
|
|
3777
|
+
const server = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
3763
3778
|
const local = byTxid.get(server.id);
|
|
3764
3779
|
if (!local) {
|
|
3765
|
-
throw new
|
|
3780
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3766
3781
|
`${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
|
|
3767
3782
|
);
|
|
3768
3783
|
}
|
|
@@ -3772,14 +3787,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
|
|
|
3772
3787
|
}
|
|
3773
3788
|
function assertSubmittedArkTxid(response, signedArkTx, context) {
|
|
3774
3789
|
if (response.arkTxid !== signedArkTx.id) {
|
|
3775
|
-
throw new
|
|
3790
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3776
3791
|
`${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
|
|
3777
3792
|
);
|
|
3778
3793
|
}
|
|
3779
3794
|
if (response.finalArkTx === void 0) return;
|
|
3780
|
-
const finalTxid =
|
|
3795
|
+
const finalTxid = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
|
|
3781
3796
|
if (finalTxid !== signedArkTx.id) {
|
|
3782
|
-
throw new
|
|
3797
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3783
3798
|
`${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
|
|
3784
3799
|
);
|
|
3785
3800
|
}
|
|
@@ -3791,20 +3806,20 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
3791
3806
|
`${context}: input ${inputIndex} carries no spend leaf to verify the server signature against`
|
|
3792
3807
|
);
|
|
3793
3808
|
}
|
|
3794
|
-
const script =
|
|
3809
|
+
const script = chunkGHUUT54D_cjs.scriptFromTapLeafScript(leaf);
|
|
3795
3810
|
let leafPubkeys;
|
|
3796
3811
|
try {
|
|
3797
|
-
leafPubkeys =
|
|
3798
|
-
(key) => base.hex.encode(
|
|
3812
|
+
leafPubkeys = chunkGHUUT54D_cjs.decodeTapscript(script).params.pubkeys.map(
|
|
3813
|
+
(key) => base.hex.encode(chunkE6OOJEHL_cjs.toXOnly(key, "leaf key"))
|
|
3799
3814
|
);
|
|
3800
3815
|
} catch (error) {
|
|
3801
|
-
throw new
|
|
3816
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3802
3817
|
`${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
|
|
3803
3818
|
);
|
|
3804
3819
|
}
|
|
3805
3820
|
const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
|
|
3806
3821
|
if (!signer) {
|
|
3807
|
-
throw new
|
|
3822
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3808
3823
|
`${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
|
|
3809
3824
|
);
|
|
3810
3825
|
}
|
|
@@ -3818,7 +3833,7 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
|
|
|
3818
3833
|
payment_js.tapLeafHash(script)
|
|
3819
3834
|
);
|
|
3820
3835
|
} catch (error) {
|
|
3821
|
-
throw new
|
|
3836
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3822
3837
|
`${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
|
|
3823
3838
|
);
|
|
3824
3839
|
}
|
|
@@ -3827,20 +3842,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3827
3842
|
const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
|
|
3828
3843
|
for (const [index, checkpoint] of checkpoints.entries()) {
|
|
3829
3844
|
if (checkpoint.inputsLength !== 1) {
|
|
3830
|
-
throw new
|
|
3845
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3831
3846
|
`${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
|
|
3832
3847
|
);
|
|
3833
3848
|
}
|
|
3834
3849
|
const spent = checkpoint.getInput(0);
|
|
3835
3850
|
if (!spent.txid || spent.index === void 0) {
|
|
3836
|
-
throw new
|
|
3851
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3837
3852
|
`${context}: checkpoint ${index} has no input outpoint`
|
|
3838
3853
|
);
|
|
3839
3854
|
}
|
|
3840
3855
|
const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
|
|
3841
3856
|
const input = byOutpoint.get(outpoint);
|
|
3842
3857
|
if (!input) {
|
|
3843
|
-
throw new
|
|
3858
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3844
3859
|
`${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
|
|
3845
3860
|
);
|
|
3846
3861
|
}
|
|
@@ -3848,7 +3863,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
|
|
|
3848
3863
|
(unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
|
|
3849
3864
|
);
|
|
3850
3865
|
if (!rebuilt) {
|
|
3851
|
-
throw new
|
|
3866
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3852
3867
|
`${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
|
|
3853
3868
|
);
|
|
3854
3869
|
}
|
|
@@ -3877,9 +3892,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3877
3892
|
if (!oneShot) {
|
|
3878
3893
|
matched.forEach(({ server }, index) => {
|
|
3879
3894
|
try {
|
|
3880
|
-
|
|
3895
|
+
chunkGHUUT54D_cjs.assertAllowedSighashTypes(server);
|
|
3881
3896
|
} catch (error) {
|
|
3882
|
-
throw new
|
|
3897
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3883
3898
|
`submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
|
|
3884
3899
|
);
|
|
3885
3900
|
}
|
|
@@ -3888,14 +3903,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3888
3903
|
const verify = options?.verifyServerSignatures;
|
|
3889
3904
|
if (verify) {
|
|
3890
3905
|
if (response.finalArkTx === void 0) {
|
|
3891
|
-
throw new
|
|
3906
|
+
throw new chunkGHUUT54D_cjs.ServerResponseMismatchError(
|
|
3892
3907
|
"submitTx: server returned no final ark tx to verify its signatures against"
|
|
3893
3908
|
);
|
|
3894
3909
|
}
|
|
3895
|
-
const finalArkTx =
|
|
3910
|
+
const finalArkTx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
|
|
3896
3911
|
const serverPubkeys = new Set(
|
|
3897
3912
|
[verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
|
|
3898
|
-
(key) => base.hex.encode(
|
|
3913
|
+
(key) => base.hex.encode(chunkE6OOJEHL_cjs.toXOnly(key, "server key"))
|
|
3899
3914
|
)
|
|
3900
3915
|
);
|
|
3901
3916
|
for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
|
|
@@ -3943,19 +3958,19 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
|
|
|
3943
3958
|
return result;
|
|
3944
3959
|
}
|
|
3945
3960
|
function carryConditionWitness(ours, server) {
|
|
3946
|
-
if (
|
|
3947
|
-
const [witness] =
|
|
3948
|
-
if (witness)
|
|
3961
|
+
if (chunkGHUUT54D_cjs.getArkPsbtFields(server, 0, chunkGHUUT54D_cjs.ConditionWitness).length > 0) return;
|
|
3962
|
+
const [witness] = chunkGHUUT54D_cjs.getArkPsbtFields(ours, 0, chunkGHUUT54D_cjs.ConditionWitness);
|
|
3963
|
+
if (witness) chunkGHUUT54D_cjs.setArkPsbtField(server, 0, chunkGHUUT54D_cjs.ConditionWitness, witness);
|
|
3949
3964
|
}
|
|
3950
3965
|
function withArkInputWitness(checkpoint, signedArkTx) {
|
|
3951
|
-
if (
|
|
3966
|
+
if (chunkGHUUT54D_cjs.getArkPsbtFields(checkpoint, 0, chunkGHUUT54D_cjs.ConditionWitness).length > 0) return checkpoint;
|
|
3952
3967
|
for (let i = 0; i < signedArkTx.inputsLength; i++) {
|
|
3953
3968
|
const { txid } = signedArkTx.getInput(i);
|
|
3954
3969
|
if (!txid || base.hex.encode(txid) !== checkpoint.id) continue;
|
|
3955
|
-
const [witness] =
|
|
3970
|
+
const [witness] = chunkGHUUT54D_cjs.getArkPsbtFields(signedArkTx, i, chunkGHUUT54D_cjs.ConditionWitness);
|
|
3956
3971
|
if (!witness) return checkpoint;
|
|
3957
3972
|
const carried = checkpoint.clone();
|
|
3958
|
-
|
|
3973
|
+
chunkGHUUT54D_cjs.setArkPsbtField(carried, 0, chunkGHUUT54D_cjs.ConditionWitness, witness);
|
|
3959
3974
|
return carried;
|
|
3960
3975
|
}
|
|
3961
3976
|
return checkpoint;
|
|
@@ -3996,7 +4011,7 @@ async function submitViaEmulator(emulator, offchainTx, signer, opts) {
|
|
|
3996
4011
|
base.base64.encode(arkTx.toPSBT()),
|
|
3997
4012
|
checkpoints.map((c) => base.base64.encode(c.toPSBT()))
|
|
3998
4013
|
);
|
|
3999
|
-
const txid =
|
|
4014
|
+
const txid = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(res.signedArkTx)).id;
|
|
4000
4015
|
assertSubmittedArkTxid({ arkTxid: txid }, arkTx, "emulator submitTx");
|
|
4001
4016
|
return { txid, signedArkTx: res.signedArkTx, signedCheckpointTxs: res.signedCheckpointTxs };
|
|
4002
4017
|
}
|
|
@@ -4004,12 +4019,12 @@ function claimWithPreimageIdentity(identity, preimage) {
|
|
|
4004
4019
|
return {
|
|
4005
4020
|
...identity,
|
|
4006
4021
|
sign: async (tx, inputIndexes) => {
|
|
4007
|
-
const signed =
|
|
4022
|
+
const signed = chunkGHUUT54D_cjs.Transaction.fromPSBT(
|
|
4008
4023
|
(await identity.sign(tx.clone(), inputIndexes)).toPSBT()
|
|
4009
4024
|
);
|
|
4010
4025
|
const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
|
|
4011
4026
|
for (const index of indexes) {
|
|
4012
|
-
|
|
4027
|
+
chunkGHUUT54D_cjs.setArkPsbtField(signed, index, chunkGHUUT54D_cjs.ConditionWitness, [preimage]);
|
|
4013
4028
|
}
|
|
4014
4029
|
return signed;
|
|
4015
4030
|
}
|
|
@@ -4192,7 +4207,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
|
|
|
4192
4207
|
};
|
|
4193
4208
|
}
|
|
4194
4209
|
function deriveContractTapscripts(contract) {
|
|
4195
|
-
const handler =
|
|
4210
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
4196
4211
|
if (!handler) {
|
|
4197
4212
|
throw new Error(`No handler for contract type '${contract.type}'`);
|
|
4198
4213
|
}
|
|
@@ -4295,7 +4310,7 @@ function assertRecipientArkadeAddress(encoded, address, context) {
|
|
|
4295
4310
|
function assertTapTreeDerivesAddress(encoded, tapTree, address) {
|
|
4296
4311
|
let derived;
|
|
4297
4312
|
try {
|
|
4298
|
-
derived =
|
|
4313
|
+
derived = chunkGHUUT54D_cjs.VtxoScript.decode(tapTree).pkScript;
|
|
4299
4314
|
} catch (e) {
|
|
4300
4315
|
throw new Error(
|
|
4301
4316
|
`Invalid tapTree for ${encoded}: ${e instanceof Error ? e.message : String(e)}`
|
|
@@ -4312,7 +4327,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
4312
4327
|
for (const recipient of recipients) {
|
|
4313
4328
|
let address;
|
|
4314
4329
|
try {
|
|
4315
|
-
address =
|
|
4330
|
+
address = chunkGHUUT54D_cjs.ArkAddress.decode(recipient.address);
|
|
4316
4331
|
} catch (e) {
|
|
4317
4332
|
throw new Error(`Invalid Arkade address: ${recipient.address}`);
|
|
4318
4333
|
}
|
|
@@ -4337,7 +4352,7 @@ function validateRecipients(recipients, dustAmount, context) {
|
|
|
4337
4352
|
|
|
4338
4353
|
// src/contracts/spendability.ts
|
|
4339
4354
|
function isContractGenericallySpendable(contract) {
|
|
4340
|
-
return
|
|
4355
|
+
return chunkE6OOJEHL_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
|
|
4341
4356
|
}
|
|
4342
4357
|
function gatedContracts(contracts) {
|
|
4343
4358
|
const gated = /* @__PURE__ */ new Map();
|
|
@@ -4359,7 +4374,7 @@ function gateExclusion(gated) {
|
|
|
4359
4374
|
return (vtxo) => {
|
|
4360
4375
|
const type = gatedTypeOf(vtxo, gated);
|
|
4361
4376
|
if (type === void 0) return void 0;
|
|
4362
|
-
if (!
|
|
4377
|
+
if (!chunkE6OOJEHL_cjs.contractHandlers.has(type)) {
|
|
4363
4378
|
return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
|
|
4364
4379
|
}
|
|
4365
4380
|
return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
|
|
@@ -4395,7 +4410,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
|
|
|
4395
4410
|
continue;
|
|
4396
4411
|
}
|
|
4397
4412
|
for (const v of vtxos) {
|
|
4398
|
-
if (!
|
|
4413
|
+
if (!chunkGHUUT54D_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
|
|
4399
4414
|
out.add(`${v.txid}:${v.vout}`);
|
|
4400
4415
|
}
|
|
4401
4416
|
}
|
|
@@ -4426,19 +4441,19 @@ async function runWithCrossInstanceLock(name, fn) {
|
|
|
4426
4441
|
});
|
|
4427
4442
|
}
|
|
4428
4443
|
var MAX_VTXOS_PER_SETTLEMENT = 50;
|
|
4429
|
-
var
|
|
4444
|
+
var MAX_INPUTS_PER_PROOF = 20;
|
|
4430
4445
|
function byValueDescending(vtxos) {
|
|
4431
4446
|
return [...vtxos].sort((a, b) => b.value - a.value);
|
|
4432
4447
|
}
|
|
4433
4448
|
async function fetchTimeHeight(wallet) {
|
|
4434
|
-
return
|
|
4449
|
+
return chunkGHUUT54D_cjs.resolveTimeHeight(wallet.onchainProvider);
|
|
4435
4450
|
}
|
|
4436
4451
|
function heldVtxosOf(wallet) {
|
|
4437
4452
|
const held = wallet.getHeldVtxos;
|
|
4438
4453
|
return typeof held === "function" ? held.call(wallet) : Promise.resolve([]);
|
|
4439
4454
|
}
|
|
4440
4455
|
function canMigrateBySend(vtxo, now) {
|
|
4441
|
-
if (!
|
|
4456
|
+
if (!chunkGHUUT54D_cjs.canSpendOffchain(vtxo, now)) return false;
|
|
4442
4457
|
return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
|
|
4443
4458
|
}
|
|
4444
4459
|
function byExpiryAscending(vtxos, now) {
|
|
@@ -4446,7 +4461,7 @@ function byExpiryAscending(vtxos, now) {
|
|
|
4446
4461
|
if (vtxo.isSwept) return -Infinity;
|
|
4447
4462
|
if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
|
|
4448
4463
|
if (vtxo.expiresAtHeight !== void 0) {
|
|
4449
|
-
return
|
|
4464
|
+
return chunkGHUUT54D_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
|
|
4450
4465
|
}
|
|
4451
4466
|
return Infinity;
|
|
4452
4467
|
};
|
|
@@ -4473,7 +4488,7 @@ function priceSettlementInputs(vtxos, estimator) {
|
|
|
4473
4488
|
const payable = [];
|
|
4474
4489
|
const net = /* @__PURE__ */ new Map();
|
|
4475
4490
|
for (const vtxo of vtxos) {
|
|
4476
|
-
const inputFee = estimator.evalOffchainInput(
|
|
4491
|
+
const inputFee = estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(vtxo));
|
|
4477
4492
|
if (inputFee.satoshis >= vtxo.value) {
|
|
4478
4493
|
continue;
|
|
4479
4494
|
}
|
|
@@ -4502,7 +4517,7 @@ function offchainOutputFee(amount, estimator, arkAddress) {
|
|
|
4502
4517
|
}
|
|
4503
4518
|
const outputFee = estimator.evalOffchainOutput({
|
|
4504
4519
|
amount,
|
|
4505
|
-
script: base.hex.encode(
|
|
4520
|
+
script: base.hex.encode(chunkGHUUT54D_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
4506
4521
|
});
|
|
4507
4522
|
return BigInt(outputFee.satoshis);
|
|
4508
4523
|
}
|
|
@@ -4553,10 +4568,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
|
|
|
4553
4568
|
};
|
|
4554
4569
|
function getRecoverableVtxos(vtxos, dustAmount, now) {
|
|
4555
4570
|
return vtxos.filter((vtxo) => {
|
|
4556
|
-
if (
|
|
4571
|
+
if (chunkGHUUT54D_cjs.canRecoverOnchain(vtxo, now)) {
|
|
4557
4572
|
return true;
|
|
4558
4573
|
}
|
|
4559
|
-
if (
|
|
4574
|
+
if (chunkGHUUT54D_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
|
|
4560
4575
|
return true;
|
|
4561
4576
|
}
|
|
4562
4577
|
return false;
|
|
@@ -4588,7 +4603,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
|
|
|
4588
4603
|
function isVtxoExpiringSoon(vtxo, thresholdMs) {
|
|
4589
4604
|
if (vtxo.isUnrolled) return false;
|
|
4590
4605
|
const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
|
|
4591
|
-
const expiresAt =
|
|
4606
|
+
const expiresAt = chunkGHUUT54D_cjs.normalizeVtxo(vtxo).expiresAt;
|
|
4592
4607
|
if (expiresAt === void 0) return false;
|
|
4593
4608
|
const now = Date.now();
|
|
4594
4609
|
const batchExpiry = expiresAt.getTime();
|
|
@@ -4599,7 +4614,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
|
|
|
4599
4614
|
return vtxos.filter(
|
|
4600
4615
|
// The leading exclusion covers the `isSubdust` arm too, which is a value
|
|
4601
4616
|
// property and would otherwise re-admit an exited coin on its own.
|
|
4602
|
-
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) ||
|
|
4617
|
+
(vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkGHUUT54D_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
|
|
4603
4618
|
);
|
|
4604
4619
|
}
|
|
4605
4620
|
function isMigrationCapable(wallet) {
|
|
@@ -4659,7 +4674,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4659
4674
|
constructor(wallet, settlementConfig) {
|
|
4660
4675
|
this.wallet = wallet;
|
|
4661
4676
|
if (settlementConfig !== false) {
|
|
4662
|
-
|
|
4677
|
+
chunkGHUUT54D_cjs.assertTimerMs("pollIntervalMs", settlementConfig?.pollIntervalMs);
|
|
4663
4678
|
}
|
|
4664
4679
|
this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
|
|
4665
4680
|
this.contractEventsSubscriptionReady = this.initializeSubscription();
|
|
@@ -4971,7 +4986,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4971
4986
|
* {@link recoverImportedContracts}).
|
|
4972
4987
|
*/
|
|
4973
4988
|
async recoverOneImportedContract(wallet, contract, vtxos, info, dustAmount) {
|
|
4974
|
-
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !
|
|
4989
|
+
const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !chunkGHUUT54D_cjs.isVtxoSpent(vtxo));
|
|
4975
4990
|
const estimator = new Estimator(info?.fees.intentFee ?? {});
|
|
4976
4991
|
const { payable, net } = priceSettlementInputs(recoverable, estimator);
|
|
4977
4992
|
const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
|
|
@@ -4993,7 +5008,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
4993
5008
|
if (vtxos.length === 0) return;
|
|
4994
5009
|
const spent = new Set(batch.map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
|
|
4995
5010
|
const stillSpendable = vtxos.some(
|
|
4996
|
-
(vtxo) => !
|
|
5011
|
+
(vtxo) => !chunkGHUUT54D_cjs.isVtxoSpent(vtxo) && !spent.has(`${vtxo.txid}:${vtxo.vout}`)
|
|
4997
5012
|
);
|
|
4998
5013
|
if (!stillSpendable) {
|
|
4999
5014
|
await wallet.removeRecoveryContract(contract.script);
|
|
@@ -5010,7 +5025,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5010
5025
|
* ```typescript
|
|
5011
5026
|
* const wallet = await Wallet.create({
|
|
5012
5027
|
* identity,
|
|
5013
|
-
*
|
|
5028
|
+
* operatorProvider: new RestOperatorProvider(),
|
|
5014
5029
|
* settlementConfig: {
|
|
5015
5030
|
* vtxoThreshold: 86_400 // 24 hours
|
|
5016
5031
|
* },
|
|
@@ -5238,7 +5253,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5238
5253
|
* ```typescript
|
|
5239
5254
|
* const wallet = await Wallet.create({
|
|
5240
5255
|
* identity,
|
|
5241
|
-
*
|
|
5256
|
+
* operatorProvider: new RestOperatorProvider(),
|
|
5242
5257
|
* settlementConfig: {
|
|
5243
5258
|
* boardingUtxoSweep: true,
|
|
5244
5259
|
* },
|
|
@@ -5286,11 +5301,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
5286
5301
|
`Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
|
|
5287
5302
|
);
|
|
5288
5303
|
}
|
|
5289
|
-
const tx = new
|
|
5304
|
+
const tx = new chunkGHUUT54D_cjs.Transaction();
|
|
5290
5305
|
for (const utxo of expiredUtxos) {
|
|
5291
|
-
const utxoScript =
|
|
5306
|
+
const utxoScript = chunkGHUUT54D_cjs.VtxoScript.decode(utxo.tapTree);
|
|
5292
5307
|
const utxoExitLeaf = utxoScript.leaves.find(
|
|
5293
|
-
(leaf) =>
|
|
5308
|
+
(leaf) => chunkGHUUT54D_cjs.CSVMultisigTapscript.isScriptValid(chunkGHUUT54D_cjs.scriptFromTapLeafScript(leaf)) === true
|
|
5294
5309
|
);
|
|
5295
5310
|
if (!utxoExitLeaf) {
|
|
5296
5311
|
throw new Error(
|
|
@@ -5305,7 +5320,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5305
5320
|
amount: BigInt(utxo.value)
|
|
5306
5321
|
},
|
|
5307
5322
|
tapLeafScript: [utxoExitLeaf],
|
|
5308
|
-
sequence:
|
|
5323
|
+
sequence: chunkGHUUT54D_cjs.getSequence(utxoExitLeaf)
|
|
5309
5324
|
});
|
|
5310
5325
|
}
|
|
5311
5326
|
tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
|
|
@@ -5532,8 +5547,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5532
5547
|
const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
|
|
5533
5548
|
if (cls.status === "CURRENT") continue;
|
|
5534
5549
|
const live = vtxos.filter((v) => !v.isUnrolled);
|
|
5535
|
-
const recoverable = live.filter((v) => v.isSwept && !
|
|
5536
|
-
const spendable = live.filter((v) => !
|
|
5550
|
+
const recoverable = live.filter((v) => v.isSwept && !chunkGHUUT54D_cjs.isVtxoSpent(v));
|
|
5551
|
+
const spendable = live.filter((v) => !chunkGHUUT54D_cjs.isVtxoSpent(v) && !v.isSwept);
|
|
5537
5552
|
const value = spendable.reduce((sum, v) => sum + v.value, 0);
|
|
5538
5553
|
let recoverableCount = 0;
|
|
5539
5554
|
let recoverableValue = 0;
|
|
@@ -5773,7 +5788,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
5773
5788
|
}
|
|
5774
5789
|
getBoardingTimelock() {
|
|
5775
5790
|
const wallet = this.getSweepWallet();
|
|
5776
|
-
const exitScript =
|
|
5791
|
+
const exitScript = chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(
|
|
5777
5792
|
base.hex.decode(wallet.boardingTapscript.exitScript)
|
|
5778
5793
|
);
|
|
5779
5794
|
return exitScript.params.timelock;
|
|
@@ -5781,11 +5796,11 @@ var VtxoManager = class _VtxoManager {
|
|
|
5781
5796
|
getOnchainProvider() {
|
|
5782
5797
|
return this.getSweepWallet().onchainProvider;
|
|
5783
5798
|
}
|
|
5784
|
-
|
|
5799
|
+
getOperatorProvider() {
|
|
5785
5800
|
return this.getSweepWallet().arkProvider;
|
|
5786
5801
|
}
|
|
5787
5802
|
/**
|
|
5788
|
-
* Unlike {@link
|
|
5803
|
+
* Unlike {@link getOperatorProvider}, doesn't require boarding-sweep capability. Undefined when no
|
|
5789
5804
|
* provider is wired, which callers treat as "no limit".
|
|
5790
5805
|
*/
|
|
5791
5806
|
getInfoProvider() {
|
|
@@ -5881,8 +5896,8 @@ var VtxoManager = class _VtxoManager {
|
|
|
5881
5896
|
}
|
|
5882
5897
|
/** The outpoint a `VTXO_ALREADY_SPENT` error carries in `metadata.vtxo_outpoint`, if any. */
|
|
5883
5898
|
extractSpentOutpoint(error) {
|
|
5884
|
-
const ark =
|
|
5885
|
-
if (!
|
|
5899
|
+
const ark = chunkGHUUT54D_cjs.maybeArkError(error);
|
|
5900
|
+
if (!chunkGHUUT54D_cjs.isArkError(ark, chunkGHUUT54D_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
|
|
5886
5901
|
const raw = ark.metadata?.vtxo_outpoint;
|
|
5887
5902
|
if (typeof raw !== "string") return void 0;
|
|
5888
5903
|
const [txid, voutStr] = raw.split(":");
|
|
@@ -6036,7 +6051,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
6036
6051
|
return;
|
|
6037
6052
|
}
|
|
6038
6053
|
const dustAmount = getDustAmount(this.wallet);
|
|
6039
|
-
const info = await this.
|
|
6054
|
+
const info = await this.getOperatorProvider().getInfo();
|
|
6040
6055
|
const { fees, vtxoMaxAmount } = info;
|
|
6041
6056
|
const estimator = new Estimator(fees.intentFee);
|
|
6042
6057
|
let totalAmount = 0n;
|
|
@@ -6056,7 +6071,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
6056
6071
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
6057
6072
|
break;
|
|
6058
6073
|
}
|
|
6059
|
-
const inputFee = estimator.evalOffchainInput(
|
|
6074
|
+
const inputFee = estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(v));
|
|
6060
6075
|
if (inputFee.satoshis >= v.value) {
|
|
6061
6076
|
continue;
|
|
6062
6077
|
}
|
|
@@ -6076,7 +6091,7 @@ var VtxoManager = class _VtxoManager {
|
|
|
6076
6091
|
const arkAddress = await this.wallet.getAddress();
|
|
6077
6092
|
const outputFee = estimator.evalOffchainOutput({
|
|
6078
6093
|
amount: totalAmount,
|
|
6079
|
-
script: base.hex.encode(
|
|
6094
|
+
script: base.hex.encode(chunkGHUUT54D_cjs.ArkAddress.decode(arkAddress).pkScript)
|
|
6080
6095
|
});
|
|
6081
6096
|
totalAmount -= BigInt(outputFee.satoshis);
|
|
6082
6097
|
if (totalAmount < dustAmount) return;
|
|
@@ -6160,7 +6175,7 @@ var ArkNote = class _ArkNote {
|
|
|
6160
6175
|
this.value = value;
|
|
6161
6176
|
this.HRP = HRP;
|
|
6162
6177
|
const preimageHash = utils_js.sha256(this.preimage);
|
|
6163
|
-
this.vtxoScript = new
|
|
6178
|
+
this.vtxoScript = new chunkGHUUT54D_cjs.VtxoScript([noteTapscript(preimageHash)]);
|
|
6164
6179
|
const leaf = this.vtxoScript.leaves[0];
|
|
6165
6180
|
this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
|
|
6166
6181
|
this.tapTree = this.vtxoScript.encode();
|
|
@@ -6333,7 +6348,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6333
6348
|
const privateKey = data.slice(1, 33);
|
|
6334
6349
|
const serverPubKey = data.slice(33, 65);
|
|
6335
6350
|
const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
|
|
6336
|
-
const csvTimelock2 =
|
|
6351
|
+
const csvTimelock2 = chunkGHUUT54D_cjs.sequenceToTimelock(sequence);
|
|
6337
6352
|
return new _ArkadeCash(privateKey, serverPubKey, csvTimelock2, decoded.prefix);
|
|
6338
6353
|
}
|
|
6339
6354
|
toString() {
|
|
@@ -6341,7 +6356,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6341
6356
|
data[0] = _ArkadeCash.Version;
|
|
6342
6357
|
data.set(this._privateKey, 1);
|
|
6343
6358
|
data.set(this._serverPubKey, 33);
|
|
6344
|
-
const sequence =
|
|
6359
|
+
const sequence = chunkGHUUT54D_cjs.timelockToSequence(this.csvTimelock);
|
|
6345
6360
|
new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
|
|
6346
6361
|
const words = base.bech32m.toWords(data);
|
|
6347
6362
|
return base.bech32m.encode(this.hrp, words, 1023);
|
|
@@ -6350,7 +6365,7 @@ var ArkadeCash = class _ArkadeCash {
|
|
|
6350
6365
|
return SingleKey.fromPrivateKey(this._privateKey);
|
|
6351
6366
|
}
|
|
6352
6367
|
get vtxoScript() {
|
|
6353
|
-
return new
|
|
6368
|
+
return new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
6354
6369
|
pubKey: this._publicKey,
|
|
6355
6370
|
serverPubKey: this._serverPubKey,
|
|
6356
6371
|
csvTimelock: this.csvTimelock
|
|
@@ -6366,7 +6381,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
|
|
|
6366
6381
|
(s) => !isTerminalIntentState(s)
|
|
6367
6382
|
);
|
|
6368
6383
|
function isConsumed(vtxo) {
|
|
6369
|
-
return vtxo !== void 0 &&
|
|
6384
|
+
return vtxo !== void 0 && chunkGHUUT54D_cjs.isVtxoSpent(vtxo);
|
|
6370
6385
|
}
|
|
6371
6386
|
async function classifyIntent(intent, vtxosByOutpoint, now) {
|
|
6372
6387
|
if (isTerminalIntentState(intent.state)) return void 0;
|
|
@@ -6404,7 +6419,7 @@ async function reconcileIntents(deps) {
|
|
|
6404
6419
|
let vtxosByOutpoint = /* @__PURE__ */ new Map();
|
|
6405
6420
|
if (outpoints.length > 0) {
|
|
6406
6421
|
try {
|
|
6407
|
-
const { vtxos } = await
|
|
6422
|
+
const { vtxos } = await chunkGHUUT54D_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
|
|
6408
6423
|
vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
|
|
6409
6424
|
} catch (e) {
|
|
6410
6425
|
console.error("reconcileIntents: failed to fetch input VTXO state", e);
|
|
@@ -6464,7 +6479,7 @@ async function releaseFromServer(intent, deps, now) {
|
|
|
6464
6479
|
});
|
|
6465
6480
|
}
|
|
6466
6481
|
function isNoMatchingIntentsError(e) {
|
|
6467
|
-
return
|
|
6482
|
+
return chunkGHUUT54D_cjs.isArkError(e, chunkGHUUT54D_cjs.ArkErrorName.INVALID_INTENT_PROOF) && e.message.includes("no matching intents found");
|
|
6468
6483
|
}
|
|
6469
6484
|
function terminal(intent, state, now, patch) {
|
|
6470
6485
|
return { ...intent, ...patch, state, updatedAt: now };
|
|
@@ -6691,7 +6706,7 @@ async function captureExitBranch(params) {
|
|
|
6691
6706
|
const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
|
|
6692
6707
|
if (nonCommitment.length > 0) {
|
|
6693
6708
|
for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
|
|
6694
|
-
psbtByTxid.set(
|
|
6709
|
+
psbtByTxid.set(chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6695
6710
|
}
|
|
6696
6711
|
}
|
|
6697
6712
|
}
|
|
@@ -6734,10 +6749,10 @@ var IndexerExitDataSource = class {
|
|
|
6734
6749
|
while (hasMore) {
|
|
6735
6750
|
const { chain: page, page: meta } = await this.indexer.getVtxoChain(
|
|
6736
6751
|
{ txid: vtxo.txid, vout: vtxo.vout },
|
|
6737
|
-
{ pageIndex, pageSize:
|
|
6752
|
+
{ pageIndex, pageSize: chunkGHUUT54D_cjs.DEFAULT_PAGE_SIZE }
|
|
6738
6753
|
);
|
|
6739
6754
|
chain.push(...page);
|
|
6740
|
-
hasMore = meta ? page.length ===
|
|
6755
|
+
hasMore = meta ? page.length === chunkGHUUT54D_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6741
6756
|
pageIndex++;
|
|
6742
6757
|
}
|
|
6743
6758
|
return chain;
|
|
@@ -6749,12 +6764,12 @@ var IndexerExitDataSource = class {
|
|
|
6749
6764
|
while (hasMore) {
|
|
6750
6765
|
const { txs, page } = await this.indexer.getVirtualTxs(txids, {
|
|
6751
6766
|
pageIndex,
|
|
6752
|
-
pageSize:
|
|
6767
|
+
pageSize: chunkGHUUT54D_cjs.DEFAULT_PAGE_SIZE
|
|
6753
6768
|
});
|
|
6754
6769
|
for (const psbt of txs) {
|
|
6755
|
-
out.set(
|
|
6770
|
+
out.set(chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
6756
6771
|
}
|
|
6757
|
-
hasMore = page ? txs.length ===
|
|
6772
|
+
hasMore = page ? txs.length === chunkGHUUT54D_cjs.DEFAULT_PAGE_SIZE : false;
|
|
6758
6773
|
pageIndex++;
|
|
6759
6774
|
}
|
|
6760
6775
|
return out;
|
|
@@ -6775,7 +6790,7 @@ function chainedTxTypeToChainTxType(t) {
|
|
|
6775
6790
|
}
|
|
6776
6791
|
}
|
|
6777
6792
|
function psbtInputTxids(psbtBase64) {
|
|
6778
|
-
return txInputTxids(
|
|
6793
|
+
return txInputTxids(chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64)));
|
|
6779
6794
|
}
|
|
6780
6795
|
function txInputTxids(tx) {
|
|
6781
6796
|
const ids = [];
|
|
@@ -7080,10 +7095,10 @@ async function resolveArkInfo(arkProvider, walletRepository, opts) {
|
|
|
7080
7095
|
try {
|
|
7081
7096
|
info = await arkProvider.getInfo();
|
|
7082
7097
|
} catch (err) {
|
|
7083
|
-
if (opts?.requireLive || !
|
|
7098
|
+
if (opts?.requireLive || !chunkGHUUT54D_cjs.isRetryableProviderError(err)) throw err;
|
|
7084
7099
|
const snapshot = await loadArkInfoSnapshot(walletRepository);
|
|
7085
7100
|
if (!snapshot) {
|
|
7086
|
-
throw new
|
|
7101
|
+
throw new chunkGHUUT54D_cjs.ProviderUnavailableError(
|
|
7087
7102
|
"Arkade server info is unavailable and no cached snapshot exists",
|
|
7088
7103
|
{ cause: err }
|
|
7089
7104
|
);
|
|
@@ -7275,7 +7290,7 @@ function buildGraph(rootTxid, chunksByTxid) {
|
|
|
7275
7290
|
return new TxTree(rootTx, children);
|
|
7276
7291
|
}
|
|
7277
7292
|
function decodeNode(chunk) {
|
|
7278
|
-
const tx =
|
|
7293
|
+
const tx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(chunk.tx));
|
|
7279
7294
|
return { tx, children: chunk.children };
|
|
7280
7295
|
}
|
|
7281
7296
|
exports.Batch = void 0;
|
|
@@ -7429,6 +7444,16 @@ function gatedTouchpoints(gated) {
|
|
|
7429
7444
|
}
|
|
7430
7445
|
return { paidIn, paidOut };
|
|
7431
7446
|
}
|
|
7447
|
+
function groupBy(items, key) {
|
|
7448
|
+
const groups = /* @__PURE__ */ new Map();
|
|
7449
|
+
for (const item of items) {
|
|
7450
|
+
const k = key(item);
|
|
7451
|
+
const group = groups.get(k);
|
|
7452
|
+
if (group) group.push(item);
|
|
7453
|
+
else groups.set(k, [item]);
|
|
7454
|
+
}
|
|
7455
|
+
return groups;
|
|
7456
|
+
}
|
|
7432
7457
|
var txKey = {
|
|
7433
7458
|
commitmentTxid: "",
|
|
7434
7459
|
boardingTxid: "",
|
|
@@ -7478,7 +7503,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
|
|
|
7478
7503
|
return [...txids];
|
|
7479
7504
|
}
|
|
7480
7505
|
async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
|
|
7481
|
-
const normalized = vtxos.map(
|
|
7506
|
+
const normalized = vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
7482
7507
|
const localCreatedAt = localCreatedAtByTxid(normalized);
|
|
7483
7508
|
const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
|
|
7484
7509
|
const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
|
|
@@ -7486,6 +7511,15 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
7486
7511
|
const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(ownVtxos, localCreatedAt) : [];
|
|
7487
7512
|
const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
|
|
7488
7513
|
const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
|
|
7514
|
+
const bySettledBy = groupBy(ownVtxos, (v) => v.settledBy);
|
|
7515
|
+
const byArkTxId = groupBy(ownVtxos, (v) => v.arkTxId);
|
|
7516
|
+
const byTxid = groupBy(ownVtxos, (v) => v.txid);
|
|
7517
|
+
const leavesBySoleCommitment = groupBy(
|
|
7518
|
+
ownVtxos,
|
|
7519
|
+
(v) => v.status.isLeaf && v.commitmentTxIds.length > 0 && v.commitmentTxIds.every((c) => c === v.commitmentTxIds[0]) ? v.commitmentTxIds[0] : void 0
|
|
7520
|
+
);
|
|
7521
|
+
const handledArkTxids = /* @__PURE__ */ new Set();
|
|
7522
|
+
const handledCommitments = /* @__PURE__ */ new Set();
|
|
7489
7523
|
const sent = [];
|
|
7490
7524
|
let received = [];
|
|
7491
7525
|
for (const vtxo of ownVtxos) {
|
|
@@ -7498,7 +7532,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
7498
7532
|
unmatchedSettledBoardingTxs,
|
|
7499
7533
|
(tx) => tx.createdAt <= vtxoCreatedAt && (tx.key.commitmentTxid === commitmentTxid || tx.key.commitmentTxid === vtxo.settledBy)
|
|
7500
7534
|
);
|
|
7501
|
-
} else if (
|
|
7535
|
+
} else if (!bySettledBy.has(vtxo.commitmentTxIds[0])) {
|
|
7502
7536
|
const duplicateBoardingReceive = consumeBoardingReceive(
|
|
7503
7537
|
unmatchedSettledBoardingTxs,
|
|
7504
7538
|
(tx) => tx.amount === vtxo.value && tx.createdAt <= vtxoCreatedAt
|
|
@@ -7519,7 +7553,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
7519
7553
|
});
|
|
7520
7554
|
}
|
|
7521
7555
|
}
|
|
7522
|
-
} else if (
|
|
7556
|
+
} else if (!byArkTxId.has(vtxo.txid)) {
|
|
7523
7557
|
const assets = subtractAssets([], [vtxo]);
|
|
7524
7558
|
received.push({
|
|
7525
7559
|
key: { ...txKey, arkTxid: vtxo.txid },
|
|
@@ -7535,9 +7569,10 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
7535
7569
|
});
|
|
7536
7570
|
}
|
|
7537
7571
|
if (vtxo.isSpent) {
|
|
7538
|
-
if (vtxo.arkTxId && !
|
|
7539
|
-
|
|
7540
|
-
const
|
|
7572
|
+
if (vtxo.arkTxId && !handledArkTxids.has(vtxo.arkTxId)) {
|
|
7573
|
+
handledArkTxids.add(vtxo.arkTxId);
|
|
7574
|
+
const changes = byTxid.get(vtxo.arkTxId) ?? [];
|
|
7575
|
+
const allSpent = byArkTxId.get(vtxo.arkTxId);
|
|
7541
7576
|
const spentAmount = allSpent.reduce((acc, v) => acc + v.value, 0);
|
|
7542
7577
|
let txAmount = 0;
|
|
7543
7578
|
let txTime = 0;
|
|
@@ -7565,11 +7600,10 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
|
|
|
7565
7600
|
});
|
|
7566
7601
|
}
|
|
7567
7602
|
}
|
|
7568
|
-
if (vtxo.settledBy && !commitmentsToIgnore.has(vtxo.settledBy) && !
|
|
7569
|
-
|
|
7570
|
-
|
|
7571
|
-
);
|
|
7572
|
-
const forfeitVtxos = ownVtxos.filter((v) => v.settledBy === vtxo.settledBy);
|
|
7603
|
+
if (vtxo.settledBy && !commitmentsToIgnore.has(vtxo.settledBy) && !handledCommitments.has(vtxo.settledBy)) {
|
|
7604
|
+
handledCommitments.add(vtxo.settledBy);
|
|
7605
|
+
const changes = leavesBySoleCommitment.get(vtxo.settledBy) ?? [];
|
|
7606
|
+
const forfeitVtxos = bySettledBy.get(vtxo.settledBy);
|
|
7573
7607
|
const forfeitAmount = forfeitVtxos.reduce((acc, v) => acc + v.value, 0);
|
|
7574
7608
|
if (changes.length > 0) {
|
|
7575
7609
|
const settledAmount = changes.reduce((acc, v) => acc + v.value, 0);
|
|
@@ -7656,7 +7690,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7656
7690
|
withRecoverable: false,
|
|
7657
7691
|
genericallySpendableOnly: true
|
|
7658
7692
|
});
|
|
7659
|
-
const controlAssetRef = params.controlAssetId ?
|
|
7693
|
+
const controlAssetRef = params.controlAssetId ? chunkWXNSISXK_cjs.AssetRef.fromId(chunkWXNSISXK_cjs.AssetId.fromString(params.controlAssetId)) : null;
|
|
7660
7694
|
const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
|
|
7661
7695
|
let totalBtcSelected = 0n;
|
|
7662
7696
|
const assetChanges = /* @__PURE__ */ new Map();
|
|
@@ -7669,8 +7703,8 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7669
7703
|
}
|
|
7670
7704
|
}
|
|
7671
7705
|
const groups = [];
|
|
7672
|
-
const issuedAssetOutput =
|
|
7673
|
-
const issuedAssetGroup =
|
|
7706
|
+
const issuedAssetOutput = chunkWXNSISXK_cjs.AssetOutput.create(0, params.amount);
|
|
7707
|
+
const issuedAssetGroup = chunkWXNSISXK_cjs.AssetGroup.create(
|
|
7674
7708
|
null,
|
|
7675
7709
|
controlAssetRef,
|
|
7676
7710
|
[],
|
|
@@ -7683,11 +7717,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7683
7717
|
for (const [assetId, amount] of assetChanges) {
|
|
7684
7718
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
7685
7719
|
groups.push(
|
|
7686
|
-
|
|
7687
|
-
|
|
7720
|
+
chunkWXNSISXK_cjs.AssetGroup.create(
|
|
7721
|
+
chunkWXNSISXK_cjs.AssetId.fromString(assetId),
|
|
7688
7722
|
null,
|
|
7689
7723
|
changeInputs,
|
|
7690
|
-
[
|
|
7724
|
+
[chunkWXNSISXK_cjs.AssetOutput.create(0, amount)],
|
|
7691
7725
|
[]
|
|
7692
7726
|
)
|
|
7693
7727
|
);
|
|
@@ -7702,7 +7736,7 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7702
7736
|
);
|
|
7703
7737
|
return {
|
|
7704
7738
|
arkTxId: arkTxid,
|
|
7705
|
-
assetId:
|
|
7739
|
+
assetId: chunkWXNSISXK_cjs.AssetId.create(arkTxid, 0).toString()
|
|
7706
7740
|
};
|
|
7707
7741
|
}
|
|
7708
7742
|
/**
|
|
@@ -7776,23 +7810,23 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7776
7810
|
const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
|
|
7777
7811
|
const reissueInputs = inputsForAsset(assetInputs, params.assetId);
|
|
7778
7812
|
const totalAssetAmount = assetToReissueAmount + params.amount;
|
|
7779
|
-
const reissueAssetIdObj =
|
|
7780
|
-
const reissueAssetGroup =
|
|
7813
|
+
const reissueAssetIdObj = chunkWXNSISXK_cjs.AssetId.fromString(params.assetId);
|
|
7814
|
+
const reissueAssetGroup = chunkWXNSISXK_cjs.AssetGroup.create(
|
|
7781
7815
|
reissueAssetIdObj,
|
|
7782
7816
|
null,
|
|
7783
7817
|
reissueInputs,
|
|
7784
|
-
[
|
|
7818
|
+
[chunkWXNSISXK_cjs.AssetOutput.create(0, totalAssetAmount)],
|
|
7785
7819
|
[]
|
|
7786
7820
|
);
|
|
7787
7821
|
const groups = [reissueAssetGroup];
|
|
7788
7822
|
for (const [assetId, amount] of assetChanges) {
|
|
7789
7823
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
7790
7824
|
groups.push(
|
|
7791
|
-
|
|
7792
|
-
|
|
7825
|
+
chunkWXNSISXK_cjs.AssetGroup.create(
|
|
7826
|
+
chunkWXNSISXK_cjs.AssetId.fromString(assetId),
|
|
7793
7827
|
null,
|
|
7794
7828
|
changeInputs,
|
|
7795
|
-
[
|
|
7829
|
+
[chunkWXNSISXK_cjs.AssetOutput.create(0, amount)],
|
|
7796
7830
|
[]
|
|
7797
7831
|
)
|
|
7798
7832
|
);
|
|
@@ -7863,11 +7897,11 @@ var AssetManager = class extends ReadonlyAssetManager {
|
|
|
7863
7897
|
for (const [assetId, amount] of assetChanges) {
|
|
7864
7898
|
const changeInputs = inputsForAsset(assetInputs, assetId);
|
|
7865
7899
|
groups.push(
|
|
7866
|
-
|
|
7867
|
-
|
|
7900
|
+
chunkWXNSISXK_cjs.AssetGroup.create(
|
|
7901
|
+
chunkWXNSISXK_cjs.AssetId.fromString(assetId),
|
|
7868
7902
|
null,
|
|
7869
7903
|
changeInputs,
|
|
7870
|
-
amount > 0n ? [
|
|
7904
|
+
amount > 0n ? [chunkWXNSISXK_cjs.AssetOutput.create(0, amount)] : [],
|
|
7871
7905
|
[]
|
|
7872
7906
|
)
|
|
7873
7907
|
);
|
|
@@ -7880,16 +7914,16 @@ function inputsForAsset(assetInputs, assetId) {
|
|
|
7880
7914
|
for (const [inputIndex, assets] of assetInputs) {
|
|
7881
7915
|
for (const asset of assets) {
|
|
7882
7916
|
if (asset.assetId !== assetId) continue;
|
|
7883
|
-
inputs.push(
|
|
7917
|
+
inputs.push(chunkWXNSISXK_cjs.AssetInput.create(inputIndex, asset.amount));
|
|
7884
7918
|
}
|
|
7885
7919
|
}
|
|
7886
7920
|
return inputs;
|
|
7887
7921
|
}
|
|
7888
7922
|
async function submitToSelf(submit, wallet, inputs, amount, groups) {
|
|
7889
|
-
const outputAddress =
|
|
7923
|
+
const outputAddress = chunkGHUUT54D_cjs.ArkAddress.decode(await wallet.getAddress());
|
|
7890
7924
|
const outputs = [
|
|
7891
7925
|
{ script: outputAddress.pkScript, amount: BigInt(amount) },
|
|
7892
|
-
Extension.create([
|
|
7926
|
+
Extension.create([chunkWXNSISXK_cjs.Packet.create(groups)]).txOut()
|
|
7893
7927
|
];
|
|
7894
7928
|
const { arkTxid } = await submit(inputs, outputs);
|
|
7895
7929
|
return arkTxid;
|
|
@@ -7913,7 +7947,7 @@ function castMetadata(metadata) {
|
|
|
7913
7947
|
} else {
|
|
7914
7948
|
throw new Error("Invalid metadata value type");
|
|
7915
7949
|
}
|
|
7916
|
-
md.push(
|
|
7950
|
+
md.push(chunkWXNSISXK_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
|
|
7917
7951
|
}
|
|
7918
7952
|
return md;
|
|
7919
7953
|
}
|
|
@@ -7934,12 +7968,12 @@ var DelegateManagerImpl = class {
|
|
|
7934
7968
|
if (vtxos.length === 0) {
|
|
7935
7969
|
return { delegated: [], failed: [] };
|
|
7936
7970
|
}
|
|
7937
|
-
const destinationScript =
|
|
7971
|
+
const destinationScript = chunkGHUUT54D_cjs.ArkAddress.decode(destination).pkScript;
|
|
7938
7972
|
const [arkInfo, delegateInfo] = await Promise.all([
|
|
7939
7973
|
this.arkInfoProvider.getInfo(),
|
|
7940
7974
|
this.delegateProvider.getDelegateInfo()
|
|
7941
7975
|
]);
|
|
7942
|
-
const eligible = vtxos.map(
|
|
7976
|
+
const eligible = vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo).filter(
|
|
7943
7977
|
(v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
|
|
7944
7978
|
);
|
|
7945
7979
|
if (eligible.length === 0) {
|
|
@@ -7971,7 +8005,7 @@ var DelegateManagerImpl = class {
|
|
|
7971
8005
|
const groupByExpiry = /* @__PURE__ */ new Map();
|
|
7972
8006
|
let recoverableVtxos = [];
|
|
7973
8007
|
for (const vtxo of eligible) {
|
|
7974
|
-
if (
|
|
8008
|
+
if (chunkGHUUT54D_cjs.canRecoverOnchain(vtxo, now)) {
|
|
7975
8009
|
recoverableVtxos.push(vtxo);
|
|
7976
8010
|
continue;
|
|
7977
8011
|
}
|
|
@@ -8023,7 +8057,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
8023
8057
|
}
|
|
8024
8058
|
if (!delegateAt) {
|
|
8025
8059
|
const now = { timestamp: /* @__PURE__ */ new Date() };
|
|
8026
|
-
const expiryTimestamp = vtxos.filter((coin) => !
|
|
8060
|
+
const expiryTimestamp = vtxos.filter((coin) => !chunkGHUUT54D_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
|
|
8027
8061
|
(min, coin) => Math.min(min, coin.expiresAt.getTime()),
|
|
8028
8062
|
Number.MAX_SAFE_INTEGER
|
|
8029
8063
|
);
|
|
@@ -8043,7 +8077,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
8043
8077
|
let amount = 0n;
|
|
8044
8078
|
for (const coin of vtxos) {
|
|
8045
8079
|
const inputFee = estimator.evalOffchainInput({
|
|
8046
|
-
...
|
|
8080
|
+
...chunkGHUUT54D_cjs.toOffchainInputFeeParams(coin),
|
|
8047
8081
|
type: "vtxo"
|
|
8048
8082
|
});
|
|
8049
8083
|
if (inputFee.satoshis >= coin.value) {
|
|
@@ -8057,7 +8091,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
8057
8091
|
const delegateFee = BigInt(Number(fee));
|
|
8058
8092
|
if (delegateFee > 0n) {
|
|
8059
8093
|
outputs.push({
|
|
8060
|
-
script:
|
|
8094
|
+
script: chunkGHUUT54D_cjs.ArkAddress.decode(delegateAddress).pkScript,
|
|
8061
8095
|
amount: delegateFee
|
|
8062
8096
|
});
|
|
8063
8097
|
}
|
|
@@ -8090,10 +8124,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
|
|
|
8090
8124
|
destinationScript
|
|
8091
8125
|
);
|
|
8092
8126
|
const forfeitOutputScript = btcSigner.OutScript.encode(
|
|
8093
|
-
btcSigner.Address(
|
|
8127
|
+
btcSigner.Address(chunkGHUUT54D_cjs.getNetwork(network)).decode(forfeitAddress)
|
|
8094
8128
|
);
|
|
8095
8129
|
const forfeits = await Promise.all(
|
|
8096
|
-
vtxos.filter((v) =>
|
|
8130
|
+
vtxos.filter((v) => chunkGHUUT54D_cjs.requiresForfeit(v)).map(async (coin) => {
|
|
8097
8131
|
const forfeit = await makeDelegateForfeitTx(
|
|
8098
8132
|
coin,
|
|
8099
8133
|
dust,
|
|
@@ -8118,7 +8152,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
|
|
|
8118
8152
|
index: input.vout,
|
|
8119
8153
|
witnessUtxo: {
|
|
8120
8154
|
amount: BigInt(input.value),
|
|
8121
|
-
script:
|
|
8155
|
+
script: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
8122
8156
|
},
|
|
8123
8157
|
sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
|
|
8124
8158
|
tapLeafScript: [delegateTapLeaf]
|
|
@@ -8176,7 +8210,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
|
|
|
8176
8210
|
expire_at: 0,
|
|
8177
8211
|
cosigners_public_keys: cosignerPubKeys
|
|
8178
8212
|
};
|
|
8179
|
-
const proof =
|
|
8213
|
+
const proof = chunkGHUUT54D_cjs.Proof.create(message, coins, outputs);
|
|
8180
8214
|
const signedProof = await identity.sign(proof);
|
|
8181
8215
|
return {
|
|
8182
8216
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -8194,10 +8228,10 @@ function getDayTimestamp(timestamp) {
|
|
|
8194
8228
|
function findDelegateTapLeaf(vtxo, delegatePubkey) {
|
|
8195
8229
|
if (!vtxo.tapTree) return void 0;
|
|
8196
8230
|
const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
|
|
8197
|
-
const vtxoScript =
|
|
8231
|
+
const vtxoScript = chunkGHUUT54D_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
8198
8232
|
return vtxoScript.leaves.find((tapLeaf) => {
|
|
8199
|
-
const arkTapscript =
|
|
8200
|
-
if (!
|
|
8233
|
+
const arkTapscript = chunkGHUUT54D_cjs.decodeTapscript(chunkGHUUT54D_cjs.scriptFromTapLeafScript(tapLeaf));
|
|
8234
|
+
if (!chunkGHUUT54D_cjs.MultisigTapscript.is(arkTapscript)) return false;
|
|
8201
8235
|
return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
|
|
8202
8236
|
});
|
|
8203
8237
|
}
|
|
@@ -8761,8 +8795,8 @@ function checkSaveVtxosForScript(backend, key, vtxos) {
|
|
|
8761
8795
|
}
|
|
8762
8796
|
async function getVtxosForContract(repo, contract, options) {
|
|
8763
8797
|
const vtxos = repo.getVtxosForScriptPage ? await collectScriptVtxos(repo, contract.script, options) : filterVtxosForScript(await collectVtxos(repo, contract.address), contract.script);
|
|
8764
|
-
const normalized = vtxos.map(
|
|
8765
|
-
return options?.unspentOnly ? normalized.filter((vtxo) => !
|
|
8798
|
+
const normalized = vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
8799
|
+
return options?.unspentOnly ? normalized.filter((vtxo) => !chunkGHUUT54D_cjs.isVtxoSpent(vtxo)) : normalized;
|
|
8766
8800
|
}
|
|
8767
8801
|
async function hasVtxosForContract(repo, contract) {
|
|
8768
8802
|
if (repo.getVtxosForScriptPage) {
|
|
@@ -8848,6 +8882,21 @@ var InMemoryWalletRepository = class {
|
|
|
8848
8882
|
utxosByAddress = /* @__PURE__ */ new Map();
|
|
8849
8883
|
txsByAddress = /* @__PURE__ */ new Map();
|
|
8850
8884
|
walletState = null;
|
|
8885
|
+
atomicWalletState;
|
|
8886
|
+
constructor() {
|
|
8887
|
+
const clone2 = typeof globalThis.structuredClone === "function" ? globalThis.structuredClone.bind(globalThis) : void 0;
|
|
8888
|
+
if (clone2) {
|
|
8889
|
+
this.atomicWalletState = {
|
|
8890
|
+
version: 1,
|
|
8891
|
+
update: async (updater) => {
|
|
8892
|
+
this.walletState = applyWalletStateUpdate(
|
|
8893
|
+
clone2(this.walletState ?? {}),
|
|
8894
|
+
updater
|
|
8895
|
+
);
|
|
8896
|
+
}
|
|
8897
|
+
};
|
|
8898
|
+
}
|
|
8899
|
+
}
|
|
8851
8900
|
async getVtxosPage(address, page) {
|
|
8852
8901
|
return pageOutpoints(this.vtxosByAddress.get(address) ?? [], page);
|
|
8853
8902
|
}
|
|
@@ -8993,7 +9042,7 @@ function decodeArkContract(encoded) {
|
|
|
8993
9042
|
}
|
|
8994
9043
|
function contractFromArkContract(encoded, options = {}) {
|
|
8995
9044
|
const parsed = decodeArkContract(encoded);
|
|
8996
|
-
const handler =
|
|
9045
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(parsed.type);
|
|
8997
9046
|
if (!handler) {
|
|
8998
9047
|
throw new Error(`No handler registered for contract type '${parsed.type}'`);
|
|
8999
9048
|
}
|
|
@@ -9007,9 +9056,9 @@ function contractFromArkContract(encoded, options = {}) {
|
|
|
9007
9056
|
metadata: options.metadata
|
|
9008
9057
|
};
|
|
9009
9058
|
}
|
|
9010
|
-
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix =
|
|
9059
|
+
function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkGHUUT54D_cjs.DEFAULT_NETWORK.hrp, options = {}) {
|
|
9011
9060
|
const parsed = decodeArkContract(encoded);
|
|
9012
|
-
const handler =
|
|
9061
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.getOrThrow(parsed.type);
|
|
9013
9062
|
const params = parsed.data;
|
|
9014
9063
|
const vtxoScript = handler.createScript(params);
|
|
9015
9064
|
return {
|
|
@@ -9066,10 +9115,10 @@ var ContractWatcher = class {
|
|
|
9066
9115
|
eventSourceReported = false;
|
|
9067
9116
|
/** @see ContractWatcherConfig */
|
|
9068
9117
|
constructor(config) {
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9118
|
+
chunkGHUUT54D_cjs.assertTimerMs("failsafePollIntervalMs", config.failsafePollIntervalMs);
|
|
9119
|
+
chunkGHUUT54D_cjs.assertTimerMs("reconnectDelayMs", config.reconnectDelayMs);
|
|
9120
|
+
chunkGHUUT54D_cjs.assertTimerMs("maxReconnectDelayMs", config.maxReconnectDelayMs);
|
|
9121
|
+
chunkGHUUT54D_cjs.assertTimerMs("subscriptionRequestTimeoutMs", config.subscriptionRequestTimeoutMs);
|
|
9073
9122
|
if (config.subscriptionRequestTimeoutMs === 0) {
|
|
9074
9123
|
throw new Error("subscriptionRequestTimeoutMs must be greater than 0");
|
|
9075
9124
|
}
|
|
@@ -9292,9 +9341,9 @@ var ContractWatcher = class {
|
|
|
9292
9341
|
this.reconnectAttempts = 0;
|
|
9293
9342
|
this.listenLoop().catch((e) => {
|
|
9294
9343
|
if (!this.isWatching || signal?.aborted) return;
|
|
9295
|
-
if (
|
|
9344
|
+
if (chunkGHUUT54D_cjs.isEventSourceError(e)) {
|
|
9296
9345
|
console.debug("ContractWatcher subscription disconnected; reconnecting");
|
|
9297
|
-
} else if (!
|
|
9346
|
+
} else if (!chunkGHUUT54D_cjs.isEventSourceUnavailableError(e)) {
|
|
9298
9347
|
console.error(e);
|
|
9299
9348
|
}
|
|
9300
9349
|
this.connectionState = "disconnected";
|
|
@@ -9304,7 +9353,7 @@ var ContractWatcher = class {
|
|
|
9304
9353
|
});
|
|
9305
9354
|
} catch (error) {
|
|
9306
9355
|
if (!this.isWatching || signal?.aborted) return;
|
|
9307
|
-
if (!
|
|
9356
|
+
if (!chunkGHUUT54D_cjs.isEventSourceUnavailableError(error)) {
|
|
9308
9357
|
console.error("ContractWatcher connection failed:", error);
|
|
9309
9358
|
}
|
|
9310
9359
|
this.connectionState = "disconnected";
|
|
@@ -9320,7 +9369,7 @@ var ContractWatcher = class {
|
|
|
9320
9369
|
* few seconds.
|
|
9321
9370
|
*/
|
|
9322
9371
|
reportEventSourceUnavailable(error) {
|
|
9323
|
-
if (!
|
|
9372
|
+
if (!chunkGHUUT54D_cjs.isEventSourceUnavailableError(error)) return false;
|
|
9324
9373
|
if (!this.eventSourceReported) {
|
|
9325
9374
|
this.eventSourceReported = true;
|
|
9326
9375
|
console.warn(
|
|
@@ -9385,7 +9434,7 @@ var ContractWatcher = class {
|
|
|
9385
9434
|
const now = Date.now();
|
|
9386
9435
|
let current;
|
|
9387
9436
|
try {
|
|
9388
|
-
current = await
|
|
9437
|
+
current = await chunkGHUUT54D_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
|
|
9389
9438
|
spendableOnly: true
|
|
9390
9439
|
});
|
|
9391
9440
|
} catch (error) {
|
|
@@ -9667,14 +9716,14 @@ var ContractWatcher = class {
|
|
|
9667
9716
|
const timestamp = Date.now();
|
|
9668
9717
|
if (update.newVtxos?.length) {
|
|
9669
9718
|
this.processSubscriptionVtxos(
|
|
9670
|
-
update.newVtxos.map(
|
|
9719
|
+
update.newVtxos.map(chunkGHUUT54D_cjs.normalizeVtxo),
|
|
9671
9720
|
"vtxo_received",
|
|
9672
9721
|
timestamp
|
|
9673
9722
|
);
|
|
9674
9723
|
}
|
|
9675
9724
|
if (update.spentVtxos?.length) {
|
|
9676
9725
|
this.processSubscriptionVtxos(
|
|
9677
|
-
update.spentVtxos.map(
|
|
9726
|
+
update.spentVtxos.map(chunkGHUUT54D_cjs.normalizeVtxo),
|
|
9678
9727
|
"vtxo_spent",
|
|
9679
9728
|
timestamp
|
|
9680
9729
|
);
|
|
@@ -9699,8 +9748,8 @@ var ContractWatcher = class {
|
|
|
9699
9748
|
continue;
|
|
9700
9749
|
}
|
|
9701
9750
|
if (target === byWatchedScript && eventType === "vtxo_received") {
|
|
9702
|
-
const n =
|
|
9703
|
-
if (
|
|
9751
|
+
const n = chunkGHUUT54D_cjs.normalizeVtxo(vtxo);
|
|
9752
|
+
if (chunkGHUUT54D_cjs.isVtxoSpent(n) || n.isSwept || chunkGHUUT54D_cjs.isPastExpiry(n, now)) continue;
|
|
9704
9753
|
}
|
|
9705
9754
|
let bucket = target.get(vtxo.script);
|
|
9706
9755
|
if (!bucket) {
|
|
@@ -9841,7 +9890,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
9841
9890
|
if (!contract) continue;
|
|
9842
9891
|
try {
|
|
9843
9892
|
const key = contractKey(contract);
|
|
9844
|
-
const handler =
|
|
9893
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
9845
9894
|
const hit = memo?.get(script);
|
|
9846
9895
|
let tapscripts;
|
|
9847
9896
|
if (hit && hit.key === key && hit.handler === handler) {
|
|
@@ -9862,7 +9911,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
9862
9911
|
scripts.add(script);
|
|
9863
9912
|
} catch (err) {
|
|
9864
9913
|
const reason = `'${contract.type}' at ${script}: ${err instanceof Error ? err.message : String(err)}`;
|
|
9865
|
-
if (err instanceof
|
|
9914
|
+
if (err instanceof chunkE6OOJEHL_cjs.UnsupportedProgramVersionError) {
|
|
9866
9915
|
unsupported.set(script, { key: contractKey(contract), reason });
|
|
9867
9916
|
} else {
|
|
9868
9917
|
failures.set(script, reason);
|
|
@@ -9873,7 +9922,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
|
|
|
9873
9922
|
}
|
|
9874
9923
|
function annotateAgainst(vtxos, byScript, tapscripts = /* @__PURE__ */ new Map()) {
|
|
9875
9924
|
return vtxos.map(
|
|
9876
|
-
(vtxo) => extendVirtualCoinForContract(
|
|
9925
|
+
(vtxo) => extendVirtualCoinForContract(chunkGHUUT54D_cjs.normalizeVtxo(vtxo), byScript, tapscripts)
|
|
9877
9926
|
);
|
|
9878
9927
|
}
|
|
9879
9928
|
var SCAN_MAX_INDEX = 1e4;
|
|
@@ -9917,8 +9966,8 @@ var ContractManager = class _ContractManager {
|
|
|
9917
9966
|
* `dispose()`, so it re-checks this at every await rather than run on a torn-down watcher. */
|
|
9918
9967
|
disposed = false;
|
|
9919
9968
|
constructor(config) {
|
|
9920
|
-
|
|
9921
|
-
|
|
9969
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", config.vtxoSyncMaxAgeMs);
|
|
9970
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", config.vtxoSyncOverlapMs);
|
|
9922
9971
|
this.config = { ...config };
|
|
9923
9972
|
this.watcher = new ContractWatcher({
|
|
9924
9973
|
indexerProvider: config.indexerProvider,
|
|
@@ -9954,12 +10003,12 @@ var ContractManager = class _ContractManager {
|
|
|
9954
10003
|
}
|
|
9955
10004
|
/** @see ContractManagerConfig.vtxoSyncMaxAgeMs — for factory-built managers. */
|
|
9956
10005
|
setVtxoSyncMaxAge(maxAgeMs) {
|
|
9957
|
-
|
|
10006
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", maxAgeMs);
|
|
9958
10007
|
this.config.vtxoSyncMaxAgeMs = maxAgeMs;
|
|
9959
10008
|
}
|
|
9960
10009
|
/** @see ContractManagerConfig.vtxoSyncOverlapMs — for factory-built managers. */
|
|
9961
10010
|
setVtxoSyncOverlap(overlapMs) {
|
|
9962
|
-
|
|
10011
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", overlapMs);
|
|
9963
10012
|
this.config.vtxoSyncOverlapMs = overlapMs;
|
|
9964
10013
|
}
|
|
9965
10014
|
markSyncOnline() {
|
|
@@ -10023,10 +10072,10 @@ var ContractManager = class _ContractManager {
|
|
|
10023
10072
|
if (this.unsupportedContracts.get(contract.script) === key) return true;
|
|
10024
10073
|
if (this.tapscriptMemo.get(contract.script)?.key === key) return false;
|
|
10025
10074
|
try {
|
|
10026
|
-
|
|
10075
|
+
chunkE6OOJEHL_cjs.contractHandlers.get(contract.type)?.createScript(contract.params);
|
|
10027
10076
|
return false;
|
|
10028
10077
|
} catch (err) {
|
|
10029
|
-
if (!(err instanceof
|
|
10078
|
+
if (!(err instanceof chunkE6OOJEHL_cjs.UnsupportedProgramVersionError)) return false;
|
|
10030
10079
|
this.unsupportedContracts.set(contract.script, key);
|
|
10031
10080
|
return true;
|
|
10032
10081
|
}
|
|
@@ -10039,7 +10088,7 @@ var ContractManager = class _ContractManager {
|
|
|
10039
10088
|
this.markSyncOnline();
|
|
10040
10089
|
return void 0;
|
|
10041
10090
|
} catch (err) {
|
|
10042
|
-
if (!
|
|
10091
|
+
if (!chunkGHUUT54D_cjs.isRetryableProviderError(err)) throw err;
|
|
10043
10092
|
this.markSyncDegraded(err);
|
|
10044
10093
|
return err;
|
|
10045
10094
|
}
|
|
@@ -10062,7 +10111,7 @@ var ContractManager = class _ContractManager {
|
|
|
10062
10111
|
try {
|
|
10063
10112
|
await this.scheduleLookAheadDrain();
|
|
10064
10113
|
} catch (err) {
|
|
10065
|
-
if (!
|
|
10114
|
+
if (!chunkGHUUT54D_cjs.isRetryableProviderError(err)) throw err;
|
|
10066
10115
|
this.lookAheadRefillOwed = true;
|
|
10067
10116
|
this.markSyncDegraded(err);
|
|
10068
10117
|
}
|
|
@@ -10125,7 +10174,7 @@ var ContractManager = class _ContractManager {
|
|
|
10125
10174
|
/** No throw: construction returned long ago, so the state is the channel. */
|
|
10126
10175
|
reportBackgroundFailure(stage, err) {
|
|
10127
10176
|
this.markSyncDegraded(err);
|
|
10128
|
-
if (!
|
|
10177
|
+
if (!chunkGHUUT54D_cjs.isRetryableProviderError(err)) {
|
|
10129
10178
|
console.error(`[contracts] background ${stage} failed`, err);
|
|
10130
10179
|
}
|
|
10131
10180
|
}
|
|
@@ -10227,7 +10276,7 @@ var ContractManager = class _ContractManager {
|
|
|
10227
10276
|
const from = Math.max(0, watermark - lookAhead.size);
|
|
10228
10277
|
const to = watermark + lookAhead.size;
|
|
10229
10278
|
const deps = lookAhead.candidateDeps();
|
|
10230
|
-
const handlers =
|
|
10279
|
+
const handlers = chunkE6OOJEHL_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkE6OOJEHL_cjs.contractHandlers.get(t)).filter(hasCandidates);
|
|
10231
10280
|
const band = /* @__PURE__ */ new Map();
|
|
10232
10281
|
for (let index = from; index <= to; index++) {
|
|
10233
10282
|
const descriptor = lookAhead.materialize(index);
|
|
@@ -10238,7 +10287,7 @@ var ContractManager = class _ContractManager {
|
|
|
10238
10287
|
index,
|
|
10239
10288
|
params: {
|
|
10240
10289
|
...candidate,
|
|
10241
|
-
...
|
|
10290
|
+
...chunkE6OOJEHL_cjs.speculativeReceiveMetadata(descriptor)
|
|
10242
10291
|
}
|
|
10243
10292
|
});
|
|
10244
10293
|
}
|
|
@@ -10297,7 +10346,7 @@ var ContractManager = class _ContractManager {
|
|
|
10297
10346
|
});
|
|
10298
10347
|
for (const entry of pending) entry.catchUpPending = false;
|
|
10299
10348
|
} catch (err) {
|
|
10300
|
-
if (!
|
|
10349
|
+
if (!chunkGHUUT54D_cjs.isRetryableProviderError(err)) throw err;
|
|
10301
10350
|
this.markSyncDegraded(err);
|
|
10302
10351
|
}
|
|
10303
10352
|
}
|
|
@@ -10388,7 +10437,7 @@ var ContractManager = class _ContractManager {
|
|
|
10388
10437
|
return result;
|
|
10389
10438
|
}
|
|
10390
10439
|
async upsertContractRow(params) {
|
|
10391
|
-
const handler =
|
|
10440
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(params.type);
|
|
10392
10441
|
if (!handler) {
|
|
10393
10442
|
throw new Error(`No handler registered for contract type '${params.type}'`);
|
|
10394
10443
|
}
|
|
@@ -10487,7 +10536,7 @@ var ContractManager = class _ContractManager {
|
|
|
10487
10536
|
`scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
|
|
10488
10537
|
);
|
|
10489
10538
|
}
|
|
10490
|
-
const registered =
|
|
10539
|
+
const registered = chunkE6OOJEHL_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkE6OOJEHL_cjs.contractHandlers.get(t)).filter(isDiscoverable);
|
|
10491
10540
|
const discoverables = [
|
|
10492
10541
|
...registered.filter((h) => h.type === "boarding"),
|
|
10493
10542
|
...registered.filter((h) => h.type !== "boarding")
|
|
@@ -10618,7 +10667,7 @@ var ContractManager = class _ContractManager {
|
|
|
10618
10667
|
return contracts.filter((contract) => this.isUnsupported(contract));
|
|
10619
10668
|
}
|
|
10620
10669
|
async getContractsWithVtxos(filter, pageSize, options) {
|
|
10621
|
-
|
|
10670
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("maxSyncAgeMs", options?.maxSyncAgeMs);
|
|
10622
10671
|
const contracts = await this.getContracts(filter);
|
|
10623
10672
|
if (this.syncedWithin(
|
|
10624
10673
|
contracts,
|
|
@@ -10726,7 +10775,7 @@ var ContractManager = class _ContractManager {
|
|
|
10726
10775
|
const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
|
|
10727
10776
|
const asking = vtxos.filter((vtxo) => {
|
|
10728
10777
|
const contract = byScript.get(vtxo.script);
|
|
10729
|
-
return contract !== void 0 &&
|
|
10778
|
+
return contract !== void 0 && chunkE6OOJEHL_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
|
|
10730
10779
|
});
|
|
10731
10780
|
if (asking.length === 0) return refused;
|
|
10732
10781
|
const [tip, walletDescriptorValue] = await Promise.all([
|
|
@@ -10735,7 +10784,7 @@ var ContractManager = class _ContractManager {
|
|
|
10735
10784
|
]);
|
|
10736
10785
|
for (const vtxo of asking) {
|
|
10737
10786
|
const contract = byScript.get(vtxo.script);
|
|
10738
|
-
const handler =
|
|
10787
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
10739
10788
|
if (!handler?.assertSpendableNow) continue;
|
|
10740
10789
|
const context = {
|
|
10741
10790
|
collaborative: true,
|
|
@@ -10745,7 +10794,7 @@ var ContractManager = class _ContractManager {
|
|
|
10745
10794
|
walletDescriptor: walletDescriptorValue,
|
|
10746
10795
|
// `isVirtualCoin` only checks `script`, which every input has; `isCsvSpendable`
|
|
10747
10796
|
// reads `vtxo.status.block_time` unguarded, so require `status` too.
|
|
10748
|
-
vtxo:
|
|
10797
|
+
vtxo: chunkGHUUT54D_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
|
|
10749
10798
|
};
|
|
10750
10799
|
try {
|
|
10751
10800
|
await handler.assertSpendableNow(
|
|
@@ -10858,7 +10907,7 @@ var ContractManager = class _ContractManager {
|
|
|
10858
10907
|
const { contractScript, collaborative = true, walletDescriptor, vtxo } = options;
|
|
10859
10908
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10860
10909
|
if (!contract) return [];
|
|
10861
|
-
const handler =
|
|
10910
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
10862
10911
|
if (!handler) return [];
|
|
10863
10912
|
const script = handler.createScript(contract.params);
|
|
10864
10913
|
const tip = await this.currentChainTip();
|
|
@@ -10880,7 +10929,7 @@ var ContractManager = class _ContractManager {
|
|
|
10880
10929
|
const { contractScript, collaborative = true, walletDescriptor } = options;
|
|
10881
10930
|
const [contract] = await this.getContracts({ script: contractScript });
|
|
10882
10931
|
if (!contract) return [];
|
|
10883
|
-
const handler =
|
|
10932
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
10884
10933
|
if (!handler) return [];
|
|
10885
10934
|
const script = handler.createScript(contract.params);
|
|
10886
10935
|
const context = {
|
|
@@ -10926,7 +10975,7 @@ var ContractManager = class _ContractManager {
|
|
|
10926
10975
|
}
|
|
10927
10976
|
async refreshOutpoints(outpoints) {
|
|
10928
10977
|
if (outpoints.length === 0) return;
|
|
10929
|
-
const { vtxos } = await
|
|
10978
|
+
const { vtxos } = await chunkGHUUT54D_cjs.getNormalizedVtxos(this.config.indexerProvider, {
|
|
10930
10979
|
outpoints
|
|
10931
10980
|
});
|
|
10932
10981
|
if (vtxos.length === 0) return;
|
|
@@ -11028,7 +11077,7 @@ var ContractManager = class _ContractManager {
|
|
|
11028
11077
|
break;
|
|
11029
11078
|
}
|
|
11030
11079
|
} catch (err) {
|
|
11031
|
-
if (!
|
|
11080
|
+
if (!chunkGHUUT54D_cjs.isRetryableProviderError(err)) throw err;
|
|
11032
11081
|
this.markSyncDegraded(err);
|
|
11033
11082
|
synced = false;
|
|
11034
11083
|
}
|
|
@@ -11116,7 +11165,7 @@ var ContractManager = class _ContractManager {
|
|
|
11116
11165
|
*/
|
|
11117
11166
|
async reconcilePendingFrontier(contracts) {
|
|
11118
11167
|
const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
|
|
11119
|
-
const vtxos = await
|
|
11168
|
+
const vtxos = await chunkGHUUT54D_cjs.getAllNormalizedVtxos(
|
|
11120
11169
|
this.config.indexerProvider,
|
|
11121
11170
|
contracts.map((c) => c.script),
|
|
11122
11171
|
{ pendingOnly: true }
|
|
@@ -11191,7 +11240,7 @@ var ContractManager = class _ContractManager {
|
|
|
11191
11240
|
}
|
|
11192
11241
|
return result;
|
|
11193
11242
|
}
|
|
11194
|
-
async fetchContractVtxosBulk(contracts, pageSize =
|
|
11243
|
+
async fetchContractVtxosBulk(contracts, pageSize = chunkGHUUT54D_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
|
|
11195
11244
|
if (contracts.length === 0) {
|
|
11196
11245
|
return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
|
|
11197
11246
|
}
|
|
@@ -11207,7 +11256,7 @@ var ContractManager = class _ContractManager {
|
|
|
11207
11256
|
before: syncWindow.before
|
|
11208
11257
|
}
|
|
11209
11258
|
} : {};
|
|
11210
|
-
const vtxos = await
|
|
11259
|
+
const vtxos = await chunkGHUUT54D_cjs.getAllNormalizedVtxos(
|
|
11211
11260
|
this.config.indexerProvider,
|
|
11212
11261
|
contracts.map((c) => c.script),
|
|
11213
11262
|
{ ...windowOpts, pageSize }
|
|
@@ -11310,7 +11359,7 @@ function parseLegacyExpiry(batchExpiry) {
|
|
|
11310
11359
|
if (typeof batchExpiry !== "number" || !Number.isFinite(batchExpiry) || batchExpiry <= 0) {
|
|
11311
11360
|
return {};
|
|
11312
11361
|
}
|
|
11313
|
-
if (batchExpiry >=
|
|
11362
|
+
if (batchExpiry >= chunkGHUUT54D_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
|
|
11314
11363
|
return { expiresAtHeight: batchExpiry / 1e3 };
|
|
11315
11364
|
}
|
|
11316
11365
|
function legacyVtxoFacts(status) {
|
|
@@ -11548,7 +11597,7 @@ function backfillContractWatchState(store) {
|
|
|
11548
11597
|
};
|
|
11549
11598
|
readPage();
|
|
11550
11599
|
}
|
|
11551
|
-
var unspentFlag = (vtxo) =>
|
|
11600
|
+
var unspentFlag = (vtxo) => chunkGHUUT54D_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
|
|
11552
11601
|
function backfillVtxoIndexFields(transaction) {
|
|
11553
11602
|
const store = transaction.objectStore(STORE_VTXOS);
|
|
11554
11603
|
const pageSize = 1e3;
|
|
@@ -11579,7 +11628,7 @@ var DEFAULT_DB_NAME = "arkade-service-worker";
|
|
|
11579
11628
|
var DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS = 1e4;
|
|
11580
11629
|
function normalizeOptions2(pathOrOptions) {
|
|
11581
11630
|
const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
|
|
11582
|
-
|
|
11631
|
+
chunkGHUUT54D_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
|
|
11583
11632
|
return {
|
|
11584
11633
|
path: o.path,
|
|
11585
11634
|
activationTimeoutMs: o.activationTimeoutMs ?? DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS
|
|
@@ -11800,7 +11849,7 @@ var deserializeTapLeaf = (t) => {
|
|
|
11800
11849
|
const s = base.hex.decode(t.s);
|
|
11801
11850
|
return [cb, s];
|
|
11802
11851
|
};
|
|
11803
|
-
var deserializeVtxo = (o) =>
|
|
11852
|
+
var deserializeVtxo = (o) => chunkGHUUT54D_cjs.normalizeVtxo({
|
|
11804
11853
|
...o,
|
|
11805
11854
|
createdAt: new Date(o.createdAt),
|
|
11806
11855
|
tapTree: base.hex.decode(o.tapTree),
|
|
@@ -11821,8 +11870,12 @@ var deserializeUtxo = (o) => ({
|
|
|
11821
11870
|
var IndexedDBWalletRepository = class {
|
|
11822
11871
|
version = 2;
|
|
11823
11872
|
connection;
|
|
11824
|
-
|
|
11873
|
+
/** persistentWalletState asserts persistence beyond this process; it cannot detect browser eviction. */
|
|
11874
|
+
constructor(dbName = DEFAULT_DB_NAME, options) {
|
|
11825
11875
|
this.connection = createManagedConnection(dbName, DB_VERSION, initDatabase);
|
|
11876
|
+
if (options?.persistentWalletState === true) {
|
|
11877
|
+
this.atomicWalletState = { ...this.atomicWalletState, persistent: true };
|
|
11878
|
+
}
|
|
11826
11879
|
}
|
|
11827
11880
|
async clear() {
|
|
11828
11881
|
try {
|
|
@@ -12091,6 +12144,47 @@ var IndexedDBWalletRepository = class {
|
|
|
12091
12144
|
throw error;
|
|
12092
12145
|
}
|
|
12093
12146
|
}
|
|
12147
|
+
atomicWalletState = {
|
|
12148
|
+
version: 1,
|
|
12149
|
+
update: async (updater) => {
|
|
12150
|
+
const db = await this.getDB();
|
|
12151
|
+
const transaction = db.transaction([STORE_WALLET_STATE], "readwrite");
|
|
12152
|
+
const completion = awaitTransaction(transaction);
|
|
12153
|
+
let failed = false;
|
|
12154
|
+
let failure;
|
|
12155
|
+
try {
|
|
12156
|
+
const store = transaction.objectStore(STORE_WALLET_STATE);
|
|
12157
|
+
const request = store.get("state");
|
|
12158
|
+
request.onerror = () => {
|
|
12159
|
+
failed = true;
|
|
12160
|
+
failure = request.error;
|
|
12161
|
+
};
|
|
12162
|
+
request.onsuccess = () => {
|
|
12163
|
+
try {
|
|
12164
|
+
const state = applyWalletStateUpdate(request.result?.data ?? {}, updater);
|
|
12165
|
+
const write = store.put({ key: "state", data: state });
|
|
12166
|
+
write.onerror = () => {
|
|
12167
|
+
failed = true;
|
|
12168
|
+
failure = write.error;
|
|
12169
|
+
};
|
|
12170
|
+
} catch (error) {
|
|
12171
|
+
failed = true;
|
|
12172
|
+
failure = error;
|
|
12173
|
+
transaction.abort();
|
|
12174
|
+
}
|
|
12175
|
+
};
|
|
12176
|
+
} catch (error) {
|
|
12177
|
+
failed = true;
|
|
12178
|
+
failure = error;
|
|
12179
|
+
transaction.abort();
|
|
12180
|
+
}
|
|
12181
|
+
try {
|
|
12182
|
+
await completion;
|
|
12183
|
+
} catch (error) {
|
|
12184
|
+
throw failed ? failure : error;
|
|
12185
|
+
}
|
|
12186
|
+
}
|
|
12187
|
+
};
|
|
12094
12188
|
async getWalletState() {
|
|
12095
12189
|
try {
|
|
12096
12190
|
const db = await this.getDB();
|
|
@@ -12101,7 +12195,7 @@ var IndexedDBWalletRepository = class {
|
|
|
12101
12195
|
return result?.data ?? null;
|
|
12102
12196
|
} catch (error) {
|
|
12103
12197
|
console.error("Failed to get wallet state:", error);
|
|
12104
|
-
|
|
12198
|
+
throw error;
|
|
12105
12199
|
}
|
|
12106
12200
|
}
|
|
12107
12201
|
async saveWalletState(state) {
|
|
@@ -12155,7 +12249,7 @@ var RestEmulatorProvider = class {
|
|
|
12155
12249
|
serverUrl;
|
|
12156
12250
|
async getInfo() {
|
|
12157
12251
|
const url = `${this.serverUrl}/v1/info`;
|
|
12158
|
-
const response = await
|
|
12252
|
+
const response = await chunkGHUUT54D_cjs.baseFetch(url);
|
|
12159
12253
|
if (!response.ok) {
|
|
12160
12254
|
const errorText2 = await response.text();
|
|
12161
12255
|
throw new Error(`Failed to get emulator info: ${errorText2}`);
|
|
@@ -12275,11 +12369,11 @@ var RestEmulatorProvider = class {
|
|
|
12275
12369
|
|
|
12276
12370
|
// src/arkade/service.ts
|
|
12277
12371
|
function arkadeServiceUrl(service) {
|
|
12278
|
-
return "operatorUrl" in service ? service.operatorUrl :
|
|
12372
|
+
return "operatorUrl" in service ? service.operatorUrl : chunkGHUUT54D_cjs.DEFAULT_ARKADE_SERVER_URL;
|
|
12279
12373
|
}
|
|
12280
12374
|
async function resolveArkadeService(service, opts = {}) {
|
|
12281
12375
|
const operatorUrl = arkadeServiceUrl(service);
|
|
12282
|
-
const arkProvider = opts.arkProvider ?? new
|
|
12376
|
+
const arkProvider = opts.arkProvider ?? new chunkGHUUT54D_cjs.RestOperatorProvider(operatorUrl);
|
|
12283
12377
|
const info = opts.info ?? await arkProvider.getInfo();
|
|
12284
12378
|
if ("network" in service && service.network !== info.network) {
|
|
12285
12379
|
throw new Error(
|
|
@@ -12292,13 +12386,13 @@ async function resolveArkadeService(service, opts = {}) {
|
|
|
12292
12386
|
}
|
|
12293
12387
|
let emulator;
|
|
12294
12388
|
if ("network" in service) {
|
|
12295
|
-
emulator = new RestEmulatorProvider(
|
|
12389
|
+
emulator = new RestEmulatorProvider(chunkGHUUT54D_cjs.DEFAULT_ARKADE_EMULATOR_URL);
|
|
12296
12390
|
} else if (service.emulatorUrl) {
|
|
12297
12391
|
emulator = new RestEmulatorProvider(service.emulatorUrl);
|
|
12298
12392
|
}
|
|
12299
12393
|
return {
|
|
12300
12394
|
arkProvider,
|
|
12301
|
-
indexerProvider: new
|
|
12395
|
+
indexerProvider: new chunkWXNSISXK_cjs.RestIndexerProvider(operatorUrl),
|
|
12302
12396
|
onchainProvider: new EsploraProvider(esploraUrl),
|
|
12303
12397
|
emulator,
|
|
12304
12398
|
info
|
|
@@ -12382,7 +12476,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
|
|
|
12382
12476
|
*/
|
|
12383
12477
|
materializeDescriptorAt(index) {
|
|
12384
12478
|
const descriptor = this.identity.descriptor;
|
|
12385
|
-
const network =
|
|
12479
|
+
const network = chunkE6OOJEHL_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
|
|
12386
12480
|
const expansion = descriptorsScure.expand({ descriptor, network, index });
|
|
12387
12481
|
const keyInfo = expansion.expansionMap?.["@0"];
|
|
12388
12482
|
if (!keyInfo?.keyExpression) {
|
|
@@ -12450,7 +12544,7 @@ function signingDescriptorIndex(descriptor) {
|
|
|
12450
12544
|
}
|
|
12451
12545
|
function newestWalletReceiveContract(contracts, serverPubKeyHex) {
|
|
12452
12546
|
return contracts.filter(
|
|
12453
|
-
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source ===
|
|
12547
|
+
(c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkE6OOJEHL_cjs.WALLET_RECEIVE_SOURCE
|
|
12454
12548
|
).sort((a, b) => {
|
|
12455
12549
|
if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
|
|
12456
12550
|
return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
|
|
@@ -12501,7 +12595,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12501
12595
|
const provider = await resolveDescriptorProvider(config, setup.walletRepository);
|
|
12502
12596
|
if (!provider) return void 0;
|
|
12503
12597
|
const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
|
|
12504
|
-
const expectedContractType = setup.offchainTapscript instanceof
|
|
12598
|
+
const expectedContractType = setup.offchainTapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? "delegate" : "default";
|
|
12505
12599
|
const factoryOpts = {
|
|
12506
12600
|
walletRepository: setup.walletRepository,
|
|
12507
12601
|
contractRepository: setup.contractRepository,
|
|
@@ -12661,7 +12755,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
|
|
|
12661
12755
|
};
|
|
12662
12756
|
function deriveLeafPubkey(descriptor) {
|
|
12663
12757
|
try {
|
|
12664
|
-
return
|
|
12758
|
+
return chunkE6OOJEHL_cjs.deriveDescriptorLeafPubKey(descriptor);
|
|
12665
12759
|
} catch (e) {
|
|
12666
12760
|
throw new NonRangeableDescriptorError(
|
|
12667
12761
|
"Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
|
|
@@ -12673,7 +12767,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12673
12767
|
const pubKey = deriveLeafPubkey(descriptor);
|
|
12674
12768
|
const tapscript = rebuildTapscript(current, pubKey);
|
|
12675
12769
|
const serverPubKey = tapscript.options.serverPubKey;
|
|
12676
|
-
const csvTimelock2 =
|
|
12770
|
+
const csvTimelock2 = chunkGHUUT54D_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
|
|
12677
12771
|
const base$1 = {
|
|
12678
12772
|
script: base.hex.encode(tapscript.pkScript),
|
|
12679
12773
|
address: tapscript.address(hrp, serverPubKey).encode(),
|
|
@@ -12681,11 +12775,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12681
12775
|
// Read at sign time to route rotated-pubkey inputs through `signWithDescriptor`; without
|
|
12682
12776
|
// it spends are rejected with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
|
|
12683
12777
|
metadata: {
|
|
12684
|
-
...tagSource && { source:
|
|
12778
|
+
...tagSource && { source: chunkE6OOJEHL_cjs.WALLET_RECEIVE_SOURCE },
|
|
12685
12779
|
signingDescriptor: descriptor
|
|
12686
12780
|
}
|
|
12687
12781
|
};
|
|
12688
|
-
const params = tapscript instanceof
|
|
12782
|
+
const params = tapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? {
|
|
12689
12783
|
...base$1,
|
|
12690
12784
|
type: "delegate",
|
|
12691
12785
|
params: {
|
|
@@ -12706,10 +12800,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
|
|
|
12706
12800
|
return { tapscript, params };
|
|
12707
12801
|
}
|
|
12708
12802
|
function rebuildTapscript(current, pubKey) {
|
|
12709
|
-
if (current instanceof
|
|
12710
|
-
return new
|
|
12803
|
+
if (current instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script) {
|
|
12804
|
+
return new chunkE6OOJEHL_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
|
|
12711
12805
|
}
|
|
12712
|
-
return new
|
|
12806
|
+
return new chunkE6OOJEHL_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
|
|
12713
12807
|
}
|
|
12714
12808
|
async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
|
|
12715
12809
|
const candidates = await collectContracts(contractRepository, {
|
|
@@ -12768,7 +12862,7 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12768
12862
|
}
|
|
12769
12863
|
};
|
|
12770
12864
|
for (const vtxo of vtxos) {
|
|
12771
|
-
if (
|
|
12865
|
+
if (chunkGHUUT54D_cjs.isVtxoSpent(vtxo)) continue;
|
|
12772
12866
|
addAssets(owned, vtxo);
|
|
12773
12867
|
if (vtxo.isUnrolled) {
|
|
12774
12868
|
unrolled += vtxo.value;
|
|
@@ -12778,11 +12872,11 @@ function computeOffchainBalance(vtxos, caps) {
|
|
|
12778
12872
|
deprecatedSignerLocked += vtxo.value;
|
|
12779
12873
|
continue;
|
|
12780
12874
|
}
|
|
12781
|
-
if (
|
|
12875
|
+
if (chunkGHUUT54D_cjs.canRecoverOnchain(vtxo, now)) {
|
|
12782
12876
|
recoverable += vtxo.value;
|
|
12783
12877
|
continue;
|
|
12784
12878
|
}
|
|
12785
|
-
if (!
|
|
12879
|
+
if (!chunkGHUUT54D_cjs.canSpendOffchain(vtxo, now)) continue;
|
|
12786
12880
|
if (vtxo.isPreconfirmed) {
|
|
12787
12881
|
preconfirmed += vtxo.value;
|
|
12788
12882
|
} else {
|
|
@@ -13001,7 +13095,7 @@ function intentProofJobs(coins) {
|
|
|
13001
13095
|
if (coins.length === 0) return [];
|
|
13002
13096
|
const coinJobs = coins.map((coin, i) => ({
|
|
13003
13097
|
index: i + 1,
|
|
13004
|
-
lookupScript:
|
|
13098
|
+
lookupScript: chunkGHUUT54D_cjs.VtxoScript.decode(coin.tapTree).pkScript
|
|
13005
13099
|
}));
|
|
13006
13100
|
return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
|
|
13007
13101
|
}
|
|
@@ -13016,7 +13110,7 @@ function asSendParams(args) {
|
|
|
13016
13110
|
}
|
|
13017
13111
|
return { recipients: args };
|
|
13018
13112
|
}
|
|
13019
|
-
function
|
|
13113
|
+
function extractOperatorProviderUrl(provider) {
|
|
13020
13114
|
const serverUrl = provider.serverUrl;
|
|
13021
13115
|
return typeof serverUrl === "string" && serverUrl.length > 0 ? serverUrl : void 0;
|
|
13022
13116
|
}
|
|
@@ -13041,7 +13135,7 @@ function dedupeTimelocks(timelocks) {
|
|
|
13041
13135
|
const seen = /* @__PURE__ */ new Set();
|
|
13042
13136
|
const deduped = [];
|
|
13043
13137
|
for (const timelock of timelocks) {
|
|
13044
|
-
const sequence =
|
|
13138
|
+
const sequence = chunkGHUUT54D_cjs.timelockToSequence(timelock).toString();
|
|
13045
13139
|
if (seen.has(sequence)) continue;
|
|
13046
13140
|
seen.add(sequence);
|
|
13047
13141
|
deduped.push(timelock);
|
|
@@ -13057,7 +13151,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
|
|
|
13057
13151
|
if (!newest?.params.pubKey) return baseline;
|
|
13058
13152
|
try {
|
|
13059
13153
|
const pubKey = base.hex.decode(newest.params.pubKey);
|
|
13060
|
-
return new
|
|
13154
|
+
return new chunkE6OOJEHL_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
|
|
13061
13155
|
} catch (e) {
|
|
13062
13156
|
console.warn("Skipping malformed boarding contract at boot", newest.script, e);
|
|
13063
13157
|
return baseline;
|
|
@@ -13089,21 +13183,21 @@ function filterFlatVtxos(vtxos, filter, pendingSpendOutpoints) {
|
|
|
13089
13183
|
if (vtxo.isUnrolled) {
|
|
13090
13184
|
return !!f.withUnrolled;
|
|
13091
13185
|
}
|
|
13092
|
-
if (
|
|
13186
|
+
if (chunkGHUUT54D_cjs.isVtxoSpent(vtxo)) {
|
|
13093
13187
|
return false;
|
|
13094
13188
|
}
|
|
13095
|
-
if (!f.withRecoverable &&
|
|
13189
|
+
if (!f.withRecoverable && chunkGHUUT54D_cjs.canRecoverOnchain(vtxo, now)) {
|
|
13096
13190
|
return false;
|
|
13097
13191
|
}
|
|
13098
13192
|
return true;
|
|
13099
13193
|
});
|
|
13100
13194
|
}
|
|
13101
13195
|
async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
13102
|
-
const candidates = inputs.filter(
|
|
13196
|
+
const candidates = inputs.filter(chunkGHUUT54D_cjs.isVirtualCoin).map(chunkGHUUT54D_cjs.normalizeVtxo).filter((v) => !v.isSwept);
|
|
13103
13197
|
if (candidates.length === 0) return inputs;
|
|
13104
|
-
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await
|
|
13198
|
+
const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await chunkGHUUT54D_cjs.resolveTimeHeight(wallet.onchainProvider) : { timestamp: /* @__PURE__ */ new Date() };
|
|
13105
13199
|
const suspects = candidates.filter(
|
|
13106
|
-
(v) =>
|
|
13200
|
+
(v) => chunkGHUUT54D_cjs.isPastExpiry(v, now) || v.expiresAtHeight !== void 0 && now.height === void 0
|
|
13107
13201
|
);
|
|
13108
13202
|
if (suspects.length === 0) return inputs;
|
|
13109
13203
|
let sweptNow;
|
|
@@ -13117,12 +13211,12 @@ async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
|
|
|
13117
13211
|
);
|
|
13118
13212
|
} catch (e) {
|
|
13119
13213
|
const message = "could not confirm the swept state of expired settlement inputs; retry the settlement";
|
|
13120
|
-
throw
|
|
13214
|
+
throw chunkGHUUT54D_cjs.isRetryableProviderError(e) ? new chunkGHUUT54D_cjs.ProviderUnavailableError(message, { cause: e }) : new Error(message, { cause: e });
|
|
13121
13215
|
}
|
|
13122
13216
|
if (sweptNow.size === 0) return inputs;
|
|
13123
13217
|
return inputs.map((input) => {
|
|
13124
|
-
if (!
|
|
13125
|
-
return { ...
|
|
13218
|
+
if (!chunkGHUUT54D_cjs.isVirtualCoin(input) || !sweptNow.has(`${input.txid}:${input.vout}`)) return input;
|
|
13219
|
+
return { ...chunkGHUUT54D_cjs.normalizeVtxo(input), isSwept: true };
|
|
13126
13220
|
});
|
|
13127
13221
|
}
|
|
13128
13222
|
var PENDING_RECOVERY_REASON = "is past its operator signer's rotation cutoff \u2014 the operator will not co-sign it until it recovers";
|
|
@@ -13411,7 +13505,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13411
13505
|
async getArkadeReader() {
|
|
13412
13506
|
const indexer = this.indexerProvider;
|
|
13413
13507
|
return {
|
|
13414
|
-
getVtxos: (opts) =>
|
|
13508
|
+
getVtxos: (opts) => chunkGHUUT54D_cjs.getNormalizedVtxos(indexer, opts),
|
|
13415
13509
|
getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
|
|
13416
13510
|
};
|
|
13417
13511
|
}
|
|
@@ -13446,25 +13540,29 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13446
13540
|
}
|
|
13447
13541
|
/** Shared setup for ReadonlyWallet.create() and Wallet.create(). */
|
|
13448
13542
|
static async setupWalletConfig(config, pubKey) {
|
|
13449
|
-
if (config.
|
|
13543
|
+
if (config.operatorProvider && config.arkProvider) {
|
|
13544
|
+
throw new Error("Pass either `operatorProvider` or `arkProvider`, not both");
|
|
13545
|
+
}
|
|
13546
|
+
const callerProvider = config.operatorProvider ?? config.arkProvider;
|
|
13547
|
+
if (config.service && (callerProvider || config.indexerProvider || config.onchainProvider)) {
|
|
13450
13548
|
throw new Error(
|
|
13451
|
-
"Pass either `service` or `
|
|
13549
|
+
"Pass either `service` or `operatorProvider`/`indexerProvider`/`onchainProvider`, not both"
|
|
13452
13550
|
);
|
|
13453
13551
|
}
|
|
13454
|
-
const arkProvider =
|
|
13552
|
+
const arkProvider = callerProvider || new chunkGHUUT54D_cjs.RestOperatorProvider(config.service ? arkadeServiceUrl(config.service) : void 0);
|
|
13455
13553
|
let indexerProvider = config.indexerProvider;
|
|
13456
13554
|
if (!indexerProvider && !config.service) {
|
|
13457
|
-
const derived =
|
|
13458
|
-
if (!derived &&
|
|
13555
|
+
const derived = extractOperatorProviderUrl(arkProvider);
|
|
13556
|
+
if (!derived && callerProvider) {
|
|
13459
13557
|
throw new Error(
|
|
13460
|
-
"indexerProvider is required when
|
|
13558
|
+
"indexerProvider is required when operatorProvider is provided without a discoverable serverUrl"
|
|
13461
13559
|
);
|
|
13462
13560
|
}
|
|
13463
|
-
indexerProvider = new
|
|
13561
|
+
indexerProvider = new chunkWXNSISXK_cjs.RestIndexerProvider(derived ?? chunkGHUUT54D_cjs.DEFAULT_ARKADE_SERVER_URL);
|
|
13464
13562
|
}
|
|
13465
13563
|
const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
|
|
13466
13564
|
const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
|
|
13467
|
-
const delegatePubKeyPromise = config.delegateProvider?.getDelegateInfo().then((info2) =>
|
|
13565
|
+
const delegatePubKeyPromise = config.delegateProvider?.getDelegateInfo().then((info2) => chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0);
|
|
13468
13566
|
const {
|
|
13469
13567
|
info,
|
|
13470
13568
|
source: serverInfoSource,
|
|
@@ -13475,7 +13573,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13475
13573
|
if (!resolvedService) throw new Error("indexerProvider is unresolved");
|
|
13476
13574
|
indexerProvider = resolvedService.indexerProvider;
|
|
13477
13575
|
}
|
|
13478
|
-
const network =
|
|
13576
|
+
const network = chunkGHUUT54D_cjs.networkFromArkadeInfo(info);
|
|
13479
13577
|
if ("descriptor" in config.identity) {
|
|
13480
13578
|
const descriptor = config.identity.descriptor;
|
|
13481
13579
|
const identityIsMainnet = !descriptor.includes("tpub");
|
|
@@ -13511,18 +13609,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13511
13609
|
}
|
|
13512
13610
|
}
|
|
13513
13611
|
const boardingTimelock = config.boardingTimelock ?? toTimelock(info.boardingExitDelay);
|
|
13514
|
-
const serverPubKey =
|
|
13612
|
+
const serverPubKey = chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
13515
13613
|
const delegatePubKey = await delegatePubKeyPromise;
|
|
13516
13614
|
const offchainOptions = {
|
|
13517
13615
|
pubKey,
|
|
13518
13616
|
serverPubKey,
|
|
13519
13617
|
csvTimelock: exitTimelock
|
|
13520
13618
|
};
|
|
13521
|
-
const offchainTapscript = !delegatePubKey ? new
|
|
13522
|
-
const boardingTapscript =
|
|
13619
|
+
const offchainTapscript = !delegatePubKey ? new chunkE6OOJEHL_cjs.DefaultVtxo.Script(offchainOptions) : new chunkE6OOJEHL_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
|
|
13620
|
+
const boardingTapscript = chunkE6OOJEHL_cjs.BoardingContractHandler.createScript({
|
|
13523
13621
|
pubKey: base.hex.encode(pubKey),
|
|
13524
13622
|
serverPubKey: base.hex.encode(serverPubKey),
|
|
13525
|
-
csvTimelock:
|
|
13623
|
+
csvTimelock: chunkGHUUT54D_cjs.timelockToSequence(boardingTimelock).toString()
|
|
13526
13624
|
});
|
|
13527
13625
|
return {
|
|
13528
13626
|
arkProvider,
|
|
@@ -13688,7 +13786,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13688
13786
|
if (!filter?.withUnrolled) {
|
|
13689
13787
|
logExcludedVtxos(
|
|
13690
13788
|
"getSpendableVtxos",
|
|
13691
|
-
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !
|
|
13789
|
+
snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkGHUUT54D_cjs.isVtxoSpent(vtxo)),
|
|
13692
13790
|
[() => UNROLLED_REASON]
|
|
13693
13791
|
);
|
|
13694
13792
|
}
|
|
@@ -13831,7 +13929,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
13831
13929
|
this.getBoardingTxs()
|
|
13832
13930
|
]);
|
|
13833
13931
|
const allVtxos = snapshot.flatMap((_) => _.vtxos);
|
|
13834
|
-
const resolveTxCreatedAt = (txids) =>
|
|
13932
|
+
const resolveTxCreatedAt = (txids) => chunkGHUUT54D_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
|
|
13835
13933
|
return buildTransactionHistory(
|
|
13836
13934
|
allVtxos,
|
|
13837
13935
|
boardingTxs,
|
|
@@ -14025,9 +14123,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14025
14123
|
async getBoardingTapscripts(allowedSigners) {
|
|
14026
14124
|
const byScript = /* @__PURE__ */ new Map();
|
|
14027
14125
|
const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
|
|
14028
|
-
const boardingCsv = this.boardingTapscript.options.csvTimelock ??
|
|
14126
|
+
const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkE6OOJEHL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14029
14127
|
add(
|
|
14030
|
-
new
|
|
14128
|
+
new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
14031
14129
|
pubKey: await this.identity.xOnlyPublicKey(),
|
|
14032
14130
|
serverPubKey: this.boardingTapscript.options.serverPubKey,
|
|
14033
14131
|
csvTimelock: boardingCsv
|
|
@@ -14042,7 +14140,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14042
14140
|
for (const c of boardingContracts) {
|
|
14043
14141
|
if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
|
|
14044
14142
|
try {
|
|
14045
|
-
add(
|
|
14143
|
+
add(chunkE6OOJEHL_cjs.BoardingContractHandler.createScript(c.params));
|
|
14046
14144
|
} catch (e) {
|
|
14047
14145
|
console.warn("Skipping malformed boarding contract", c.script, e);
|
|
14048
14146
|
}
|
|
@@ -14071,7 +14169,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14071
14169
|
// Per-row CSV delay decoded from THIS tapscript's exit leaf —
|
|
14072
14170
|
// not the wallet's current boarding timelock, which a signer
|
|
14073
14171
|
// rotation may have changed.
|
|
14074
|
-
csvTimelock:
|
|
14172
|
+
csvTimelock: chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
|
|
14075
14173
|
coins: utxos
|
|
14076
14174
|
};
|
|
14077
14175
|
})
|
|
@@ -14236,7 +14334,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14236
14334
|
/** Fetch Arkade transaction ids that are still pending final settlement. */
|
|
14237
14335
|
async fetchPendingTxs() {
|
|
14238
14336
|
const scripts = await this.getWalletScripts();
|
|
14239
|
-
const vtxos = await
|
|
14337
|
+
const vtxos = await chunkGHUUT54D_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
|
|
14240
14338
|
return vtxos.filter(
|
|
14241
14339
|
(vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
|
|
14242
14340
|
).map((_) => _.arkTxId);
|
|
@@ -14267,7 +14365,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14267
14365
|
});
|
|
14268
14366
|
for (const contract of contracts) {
|
|
14269
14367
|
if (map.has(contract.script)) continue;
|
|
14270
|
-
const handler =
|
|
14368
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
14271
14369
|
if (handler) {
|
|
14272
14370
|
const script = handler.createScript(contract.params);
|
|
14273
14371
|
map.set(contract.script, script);
|
|
@@ -14382,85 +14480,90 @@ var ReadonlyWallet = class _ReadonlyWallet {
|
|
|
14382
14480
|
return { height, time };
|
|
14383
14481
|
}
|
|
14384
14482
|
});
|
|
14385
|
-
|
|
14386
|
-
|
|
14387
|
-
|
|
14388
|
-
|
|
14389
|
-
|
|
14390
|
-
|
|
14391
|
-
|
|
14392
|
-
|
|
14393
|
-
|
|
14394
|
-
for (const
|
|
14395
|
-
const
|
|
14396
|
-
|
|
14397
|
-
|
|
14398
|
-
serverPubKey,
|
|
14399
|
-
csvTimelock: csvTimelock2
|
|
14400
|
-
});
|
|
14401
|
-
const defaultScriptHex = base.hex.encode(defaultScript.pkScript);
|
|
14402
|
-
if (!seenBaselineScripts.has(defaultScriptHex)) {
|
|
14403
|
-
seenBaselineScripts.add(defaultScriptHex);
|
|
14404
|
-
baseline.push({
|
|
14405
|
-
type: "default",
|
|
14406
|
-
params: {
|
|
14407
|
-
pubKey: base.hex.encode(defaultScript.options.pubKey),
|
|
14408
|
-
serverPubKey: base.hex.encode(serverPubKey),
|
|
14409
|
-
csvTimelock: csvTimelockStr
|
|
14410
|
-
},
|
|
14411
|
-
script: defaultScriptHex,
|
|
14412
|
-
address: defaultScript.address(this.network.hrp, serverPubKey).encode(),
|
|
14413
|
-
state: "active"
|
|
14414
|
-
});
|
|
14415
|
-
}
|
|
14416
|
-
if (delegatePubKey) {
|
|
14417
|
-
const delegateScript = new chunkBYPBVHVA_cjs.DelegateVtxo.Script({
|
|
14483
|
+
try {
|
|
14484
|
+
const baselinePubkey = await baselinePubkeyPromise;
|
|
14485
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
14486
|
+
const baselineSigners = [
|
|
14487
|
+
this.offchainTapscript.options.serverPubKey,
|
|
14488
|
+
...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
|
|
14489
|
+
];
|
|
14490
|
+
const seenBaselineScripts = /* @__PURE__ */ new Set();
|
|
14491
|
+
const baseline = [];
|
|
14492
|
+
for (const serverPubKey of baselineSigners) {
|
|
14493
|
+
for (const csvTimelock2 of this.walletContractTimelocks) {
|
|
14494
|
+
const csvTimelockStr = chunkGHUUT54D_cjs.timelockToSequence(csvTimelock2).toString();
|
|
14495
|
+
const defaultScript = new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
14418
14496
|
pubKey: baselinePubkey,
|
|
14419
14497
|
serverPubKey,
|
|
14420
|
-
delegatePubKey,
|
|
14421
14498
|
csvTimelock: csvTimelock2
|
|
14422
14499
|
});
|
|
14423
|
-
const
|
|
14424
|
-
if (seenBaselineScripts.has(
|
|
14425
|
-
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
}
|
|
14500
|
+
const defaultScriptHex = base.hex.encode(defaultScript.pkScript);
|
|
14501
|
+
if (!seenBaselineScripts.has(defaultScriptHex)) {
|
|
14502
|
+
seenBaselineScripts.add(defaultScriptHex);
|
|
14503
|
+
baseline.push({
|
|
14504
|
+
type: "default",
|
|
14505
|
+
params: {
|
|
14506
|
+
pubKey: base.hex.encode(defaultScript.options.pubKey),
|
|
14507
|
+
serverPubKey: base.hex.encode(serverPubKey),
|
|
14508
|
+
csvTimelock: csvTimelockStr
|
|
14509
|
+
},
|
|
14510
|
+
script: defaultScriptHex,
|
|
14511
|
+
address: defaultScript.address(this.network.hrp, serverPubKey).encode(),
|
|
14512
|
+
state: "active"
|
|
14513
|
+
});
|
|
14514
|
+
}
|
|
14515
|
+
if (delegatePubKey) {
|
|
14516
|
+
const delegateScript = new chunkE6OOJEHL_cjs.DelegateVtxo.Script({
|
|
14517
|
+
pubKey: baselinePubkey,
|
|
14518
|
+
serverPubKey,
|
|
14519
|
+
delegatePubKey,
|
|
14520
|
+
csvTimelock: csvTimelock2
|
|
14521
|
+
});
|
|
14522
|
+
const delegateScriptHex = base.hex.encode(delegateScript.pkScript);
|
|
14523
|
+
if (seenBaselineScripts.has(delegateScriptHex)) continue;
|
|
14524
|
+
seenBaselineScripts.add(delegateScriptHex);
|
|
14525
|
+
baseline.push({
|
|
14526
|
+
type: "delegate",
|
|
14527
|
+
params: {
|
|
14528
|
+
pubKey: base.hex.encode(delegateScript.options.pubKey),
|
|
14529
|
+
serverPubKey: base.hex.encode(serverPubKey),
|
|
14530
|
+
delegatePubKey: base.hex.encode(delegateScript.options.delegatePubKey),
|
|
14531
|
+
csvTimelock: csvTimelockStr
|
|
14532
|
+
},
|
|
14533
|
+
script: delegateScriptHex,
|
|
14534
|
+
address: delegateScript.address(this.network.hrp, serverPubKey).encode(),
|
|
14535
|
+
state: "active"
|
|
14536
|
+
});
|
|
14537
|
+
}
|
|
14438
14538
|
}
|
|
14439
14539
|
}
|
|
14540
|
+
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkE6OOJEHL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14541
|
+
for (const serverPubKey of baselineSigners) {
|
|
14542
|
+
const baselineBoarding = new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
14543
|
+
pubKey: baselinePubkey,
|
|
14544
|
+
serverPubKey,
|
|
14545
|
+
csvTimelock: boardingCsvTimelock
|
|
14546
|
+
});
|
|
14547
|
+
const boardingScriptHex = base.hex.encode(baselineBoarding.pkScript);
|
|
14548
|
+
if (seenBaselineScripts.has(boardingScriptHex)) continue;
|
|
14549
|
+
seenBaselineScripts.add(boardingScriptHex);
|
|
14550
|
+
baseline.push({
|
|
14551
|
+
type: "boarding",
|
|
14552
|
+
params: {
|
|
14553
|
+
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14554
|
+
serverPubKey: base.hex.encode(serverPubKey),
|
|
14555
|
+
csvTimelock: chunkGHUUT54D_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14556
|
+
},
|
|
14557
|
+
script: boardingScriptHex,
|
|
14558
|
+
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
14559
|
+
state: "active"
|
|
14560
|
+
});
|
|
14561
|
+
}
|
|
14562
|
+
await manager.createContracts(baseline);
|
|
14563
|
+
} catch (error) {
|
|
14564
|
+
await manager.dispose().catch(() => void 0);
|
|
14565
|
+
throw error;
|
|
14440
14566
|
}
|
|
14441
|
-
const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkBYPBVHVA_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14442
|
-
for (const serverPubKey of baselineSigners) {
|
|
14443
|
-
const baselineBoarding = new chunkBYPBVHVA_cjs.DefaultVtxo.Script({
|
|
14444
|
-
pubKey: baselinePubkey,
|
|
14445
|
-
serverPubKey,
|
|
14446
|
-
csvTimelock: boardingCsvTimelock
|
|
14447
|
-
});
|
|
14448
|
-
const boardingScriptHex = base.hex.encode(baselineBoarding.pkScript);
|
|
14449
|
-
if (seenBaselineScripts.has(boardingScriptHex)) continue;
|
|
14450
|
-
seenBaselineScripts.add(boardingScriptHex);
|
|
14451
|
-
baseline.push({
|
|
14452
|
-
type: "boarding",
|
|
14453
|
-
params: {
|
|
14454
|
-
pubKey: base.hex.encode(baselineBoarding.options.pubKey),
|
|
14455
|
-
serverPubKey: base.hex.encode(serverPubKey),
|
|
14456
|
-
csvTimelock: chunkKW7ZEWYS_cjs.timelockToSequence(boardingCsvTimelock).toString()
|
|
14457
|
-
},
|
|
14458
|
-
script: boardingScriptHex,
|
|
14459
|
-
address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
|
|
14460
|
-
state: "active"
|
|
14461
|
-
});
|
|
14462
|
-
}
|
|
14463
|
-
await manager.createContracts(baseline);
|
|
14464
14567
|
return manager;
|
|
14465
14568
|
}
|
|
14466
14569
|
/** Dispose wallet-owned managers and release background resources. */
|
|
@@ -14641,7 +14744,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14641
14744
|
serverPubKey: this.offchainTapscript.options.serverPubKey,
|
|
14642
14745
|
deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
|
|
14643
14746
|
csvTimelocks: this.walletContractTimelocks,
|
|
14644
|
-
delegatePubKey: this.offchainTapscript instanceof
|
|
14747
|
+
delegatePubKey: this.offchainTapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
|
|
14645
14748
|
};
|
|
14646
14749
|
}
|
|
14647
14750
|
_signerRouter;
|
|
@@ -14801,7 +14904,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14801
14904
|
const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
|
|
14802
14905
|
const persisted = row?.metadata?.signingDescriptor;
|
|
14803
14906
|
if (typeof persisted === "string") return persisted;
|
|
14804
|
-
return
|
|
14907
|
+
return chunkE6OOJEHL_cjs.identityDescriptor(this.identity);
|
|
14805
14908
|
}
|
|
14806
14909
|
/**
|
|
14807
14910
|
* Build, persist and shape one address of `type` owned by `descriptor`. The descriptor is the
|
|
@@ -14811,7 +14914,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14811
14914
|
async mintAddress(manager, type, descriptor, tagSource, allocated) {
|
|
14812
14915
|
if (type === "boarding") {
|
|
14813
14916
|
const built2 = this.buildBoardingContract(
|
|
14814
|
-
|
|
14917
|
+
chunkE6OOJEHL_cjs.deriveDescriptorLeafPubKey(descriptor),
|
|
14815
14918
|
descriptor,
|
|
14816
14919
|
tagSource
|
|
14817
14920
|
);
|
|
@@ -14848,11 +14951,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14848
14951
|
* (offchain analogue: {@link buildReceiveContract}).
|
|
14849
14952
|
*/
|
|
14850
14953
|
buildBoardingContract(pubKey, descriptor, tagSource) {
|
|
14851
|
-
const tapscript = new
|
|
14954
|
+
const tapscript = new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
14852
14955
|
...this._boardingTapscript.options,
|
|
14853
14956
|
pubKey
|
|
14854
14957
|
});
|
|
14855
|
-
const csvTimelock2 = tapscript.options.csvTimelock ??
|
|
14958
|
+
const csvTimelock2 = tapscript.options.csvTimelock ?? chunkE6OOJEHL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
14856
14959
|
return {
|
|
14857
14960
|
tapscript,
|
|
14858
14961
|
params: {
|
|
@@ -14860,13 +14963,13 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14860
14963
|
params: {
|
|
14861
14964
|
pubKey: base.hex.encode(pubKey),
|
|
14862
14965
|
serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
|
|
14863
|
-
csvTimelock:
|
|
14966
|
+
csvTimelock: chunkGHUUT54D_cjs.timelockToSequence(csvTimelock2).toString()
|
|
14864
14967
|
},
|
|
14865
14968
|
script: base.hex.encode(tapscript.pkScript),
|
|
14866
14969
|
address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
|
|
14867
14970
|
state: "active",
|
|
14868
14971
|
metadata: {
|
|
14869
|
-
...tagSource && { source:
|
|
14972
|
+
...tagSource && { source: chunkE6OOJEHL_cjs.WALLET_RECEIVE_SOURCE },
|
|
14870
14973
|
signingDescriptor: descriptor
|
|
14871
14974
|
}
|
|
14872
14975
|
}
|
|
@@ -14888,7 +14991,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14888
14991
|
if (this._hdProvider) {
|
|
14889
14992
|
return (await this.getContractManager()).getNextSigningDescriptor();
|
|
14890
14993
|
}
|
|
14891
|
-
return
|
|
14994
|
+
return chunkE6OOJEHL_cjs.identityDescriptor(this.identity);
|
|
14892
14995
|
}
|
|
14893
14996
|
/**
|
|
14894
14997
|
* @see HDAllocationCapable.advanceSigningDescriptorWatermark
|
|
@@ -14964,7 +15067,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14964
15067
|
* the stable public API.
|
|
14965
15068
|
*/
|
|
14966
15069
|
async rotateServerSigner(newServerPubKey, checkpointTapscript) {
|
|
14967
|
-
const xonly =
|
|
15070
|
+
const xonly = chunkE6OOJEHL_cjs.toXOnly(newServerPubKey, "ark signer key");
|
|
14968
15071
|
const newServerUnrollScript = assertValidServerUnrollScript(
|
|
14969
15072
|
checkpointTapscript,
|
|
14970
15073
|
this.network,
|
|
@@ -14994,21 +15097,21 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
14994
15097
|
]);
|
|
14995
15098
|
const [currentOffchainRow] = offchainRows;
|
|
14996
15099
|
const [currentBoardingRow] = boardingRows;
|
|
14997
|
-
const newOffchain = this.offchainTapscript instanceof
|
|
15100
|
+
const newOffchain = this.offchainTapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? new chunkE6OOJEHL_cjs.DelegateVtxo.Script({
|
|
14998
15101
|
...this.offchainTapscript.options,
|
|
14999
15102
|
serverPubKey: xonly
|
|
15000
|
-
}) : new
|
|
15103
|
+
}) : new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
15001
15104
|
...this.offchainTapscript.options,
|
|
15002
15105
|
serverPubKey: xonly
|
|
15003
15106
|
});
|
|
15004
|
-
const newBoarding = new
|
|
15107
|
+
const newBoarding = new chunkE6OOJEHL_cjs.DefaultVtxo.Script({
|
|
15005
15108
|
...this._boardingTapscript.options,
|
|
15006
15109
|
serverPubKey: xonly
|
|
15007
15110
|
});
|
|
15008
|
-
const offchainCsv =
|
|
15111
|
+
const offchainCsv = chunkGHUUT54D_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
|
|
15009
15112
|
const newOffchainScript = base.hex.encode(newOffchain.pkScript);
|
|
15010
15113
|
const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
|
|
15011
|
-
if (newOffchain instanceof
|
|
15114
|
+
if (newOffchain instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script) {
|
|
15012
15115
|
await manager.createContract({
|
|
15013
15116
|
type: "delegate",
|
|
15014
15117
|
params: {
|
|
@@ -15036,13 +15139,13 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15036
15139
|
metadata: currentOffchainRow?.metadata
|
|
15037
15140
|
});
|
|
15038
15141
|
}
|
|
15039
|
-
const boardingCsv = newBoarding.options.csvTimelock ??
|
|
15142
|
+
const boardingCsv = newBoarding.options.csvTimelock ?? chunkE6OOJEHL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
15040
15143
|
await manager.createContract({
|
|
15041
15144
|
type: "boarding",
|
|
15042
15145
|
params: {
|
|
15043
15146
|
pubKey: base.hex.encode(newBoarding.options.pubKey),
|
|
15044
15147
|
serverPubKey: base.hex.encode(xonly),
|
|
15045
|
-
csvTimelock:
|
|
15148
|
+
csvTimelock: chunkGHUUT54D_cjs.timelockToSequence(boardingCsv).toString()
|
|
15046
15149
|
},
|
|
15047
15150
|
script: base.hex.encode(newBoarding.pkScript),
|
|
15048
15151
|
address: newBoarding.address(this.network.hrp, xonly).encode(),
|
|
@@ -15070,14 +15173,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15070
15173
|
_restoreInFlight;
|
|
15071
15174
|
_addPendingSpends(inputs) {
|
|
15072
15175
|
for (const input of inputs) {
|
|
15073
|
-
if (
|
|
15176
|
+
if (chunkGHUUT54D_cjs.isVirtualCoin(input)) {
|
|
15074
15177
|
this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
|
|
15075
15178
|
}
|
|
15076
15179
|
}
|
|
15077
15180
|
}
|
|
15078
15181
|
_removePendingSpends(inputs) {
|
|
15079
15182
|
for (const input of inputs) {
|
|
15080
|
-
if (
|
|
15183
|
+
if (chunkGHUUT54D_cjs.isVirtualCoin(input)) {
|
|
15081
15184
|
this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
|
|
15082
15185
|
}
|
|
15083
15186
|
}
|
|
@@ -15141,7 +15244,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15141
15244
|
if (clashing.length > 0) throw new VtxoReservedError(clashing, "in-flight");
|
|
15142
15245
|
}
|
|
15143
15246
|
_assertNotHeld(inputs) {
|
|
15144
|
-
const held = coinKeys(inputs.filter(
|
|
15247
|
+
const held = coinKeys(inputs.filter(chunkGHUUT54D_cjs.isVirtualCoin)).filter(
|
|
15145
15248
|
(key) => this._heldOutpoints.has(key)
|
|
15146
15249
|
);
|
|
15147
15250
|
if (held.length > 0) throw new VtxoReservedError(held, "held");
|
|
@@ -15180,14 +15283,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15180
15283
|
const hd = provider !== void 0;
|
|
15181
15284
|
const [manager, staticDescriptor, arkInfo] = await Promise.all([
|
|
15182
15285
|
this.getContractManager(),
|
|
15183
|
-
hd ? void 0 :
|
|
15286
|
+
hd ? void 0 : chunkE6OOJEHL_cjs.identityDescriptor(this.identity),
|
|
15184
15287
|
this.arkProvider.getInfo()
|
|
15185
15288
|
]);
|
|
15186
15289
|
const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
|
|
15187
|
-
const delegatePubKey = this.offchainTapscript instanceof
|
|
15188
|
-
const currentSignerPubKey =
|
|
15290
|
+
const delegatePubKey = this.offchainTapscript instanceof chunkE6OOJEHL_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
|
|
15291
|
+
const currentSignerPubKey = chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
|
|
15189
15292
|
const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
|
|
15190
|
-
(s) =>
|
|
15293
|
+
(s) => chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
|
|
15191
15294
|
);
|
|
15192
15295
|
const deps = {
|
|
15193
15296
|
indexerProvider: this.indexerProvider,
|
|
@@ -15199,7 +15302,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15199
15302
|
deprecatedSignerPubKeys,
|
|
15200
15303
|
csvTimelocks: this.walletContractTimelocks,
|
|
15201
15304
|
// Boarding-exit CSV, distinct from the unilateral-exit matrix.
|
|
15202
|
-
boardingTimelock: this.boardingTapscript.options.csvTimelock ??
|
|
15305
|
+
boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkE6OOJEHL_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
|
|
15203
15306
|
delegatePubKey
|
|
15204
15307
|
};
|
|
15205
15308
|
const result = await manager.scanContracts({
|
|
@@ -15316,7 +15419,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15316
15419
|
throw new Error("Invalid configured public key");
|
|
15317
15420
|
}
|
|
15318
15421
|
const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
|
|
15319
|
-
const forfeitPubkey =
|
|
15422
|
+
const forfeitPubkey = chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
|
|
15320
15423
|
const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
|
|
15321
15424
|
const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
|
|
15322
15425
|
const serverUnrollScript = assertValidServerUnrollScript(
|
|
@@ -15485,13 +15588,13 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15485
15588
|
void this.logUngatedInputs("settle({ inputs })", params.inputs);
|
|
15486
15589
|
}
|
|
15487
15590
|
const offchainAddress = await this.getAddress();
|
|
15488
|
-
const offchainPkScript =
|
|
15591
|
+
const offchainPkScript = chunkGHUUT54D_cjs.ArkAddress.decode(offchainAddress).pkScript;
|
|
15489
15592
|
const offchainOutputScript = base.hex.encode(offchainPkScript);
|
|
15490
15593
|
if (!params) {
|
|
15491
15594
|
const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
|
|
15492
15595
|
const estimator = new Estimator(fees.intentFee);
|
|
15493
15596
|
let amount = 0;
|
|
15494
|
-
const exitScript =
|
|
15597
|
+
const exitScript = chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(
|
|
15495
15598
|
base.hex.decode(this.boardingTapscript.exitScript)
|
|
15496
15599
|
);
|
|
15497
15600
|
const boardingTimelock = exitScript.params.timelock;
|
|
@@ -15523,7 +15626,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15523
15626
|
if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
|
|
15524
15627
|
break;
|
|
15525
15628
|
}
|
|
15526
|
-
const inputFee = estimator.evalOffchainInput(
|
|
15629
|
+
const inputFee = estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(vtxo));
|
|
15527
15630
|
if (inputFee.satoshis >= vtxo.value) {
|
|
15528
15631
|
continue;
|
|
15529
15632
|
}
|
|
@@ -15575,7 +15678,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15575
15678
|
let script;
|
|
15576
15679
|
let arkAddress;
|
|
15577
15680
|
try {
|
|
15578
|
-
arkAddress =
|
|
15681
|
+
arkAddress = chunkGHUUT54D_cjs.ArkAddress.decode(output.address);
|
|
15579
15682
|
} catch {
|
|
15580
15683
|
arkAddress = void 0;
|
|
15581
15684
|
}
|
|
@@ -15647,11 +15750,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15647
15750
|
]);
|
|
15648
15751
|
let intentTxId;
|
|
15649
15752
|
try {
|
|
15650
|
-
intentTxId =
|
|
15753
|
+
intentTxId = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(intent.proof)).id;
|
|
15651
15754
|
} catch {
|
|
15652
15755
|
intentTxId = params.inputs.map((i) => `${i.txid}:${i.vout}`).sort().join("|");
|
|
15653
15756
|
}
|
|
15654
|
-
const settleInputVtxos = params.inputs.filter(
|
|
15757
|
+
const settleInputVtxos = params.inputs.filter(chunkGHUUT54D_cjs.isVirtualCoin);
|
|
15655
15758
|
const contractManager = await this.getContractManager();
|
|
15656
15759
|
await contractManager.assertAnnotatable(settleInputVtxos);
|
|
15657
15760
|
await contractManager.assertSpendableNow?.(
|
|
@@ -15660,7 +15763,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15660
15763
|
);
|
|
15661
15764
|
if (picked) this._assertNotHeld(params.inputs);
|
|
15662
15765
|
this._addPendingSpends(params.inputs);
|
|
15663
|
-
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !
|
|
15766
|
+
const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !chunkGHUUT54D_cjs.isVirtualCoin(i))) : [];
|
|
15664
15767
|
for (const key of boardingKeys) this._pendingSpendOutpoints.add(key);
|
|
15665
15768
|
const settlingKeys = params.inputs.map((i) => `${i.txid}:${i.vout}`);
|
|
15666
15769
|
for (const key of settlingKeys) this._settlingOutpoints.add(key);
|
|
@@ -15779,7 +15882,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15779
15882
|
async maybeRotateBoardingAfterBoard(inputs) {
|
|
15780
15883
|
if (!this._descriptorProvider) return;
|
|
15781
15884
|
const consumedBoarding = inputs.some(
|
|
15782
|
-
(input) => typeof input !== "string" && !
|
|
15885
|
+
(input) => typeof input !== "string" && !chunkGHUUT54D_cjs.isVirtualCoin(input)
|
|
15783
15886
|
);
|
|
15784
15887
|
if (!consumedBoarding) return;
|
|
15785
15888
|
try {
|
|
@@ -15790,7 +15893,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15790
15893
|
}
|
|
15791
15894
|
async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, expectedRecipients, connectorsGraph, validatedCommitmentTxid) {
|
|
15792
15895
|
const signedForfeits = [];
|
|
15793
|
-
let settlementPsbt =
|
|
15896
|
+
let settlementPsbt = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
15794
15897
|
assertFinalCommitmentMatchesValidated(
|
|
15795
15898
|
settlementPsbt,
|
|
15796
15899
|
validatedCommitmentTxid,
|
|
@@ -15803,7 +15906,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15803
15906
|
let connectorIndex = 0;
|
|
15804
15907
|
const connectorsLeaves = connectorsGraph?.leaves() || [];
|
|
15805
15908
|
for (const input of inputs) {
|
|
15806
|
-
if (!
|
|
15909
|
+
if (!chunkGHUUT54D_cjs.isVirtualCoin(input)) {
|
|
15807
15910
|
let matched = false;
|
|
15808
15911
|
for (let i = 0; i < settlementPsbt.inputsLength; i++) {
|
|
15809
15912
|
const settlementInput = settlementPsbt.getInput(i);
|
|
@@ -15841,7 +15944,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15841
15944
|
}
|
|
15842
15945
|
continue;
|
|
15843
15946
|
}
|
|
15844
|
-
if (!
|
|
15947
|
+
if (!chunkGHUUT54D_cjs.requiresForfeit(input) || isSubdust({ value: input.value }, this.dustAmount)) {
|
|
15845
15948
|
continue;
|
|
15846
15949
|
}
|
|
15847
15950
|
if (connectorsLeaves.length === 0) {
|
|
@@ -15869,7 +15972,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15869
15972
|
index: input.vout,
|
|
15870
15973
|
witnessUtxo: {
|
|
15871
15974
|
amount: BigInt(input.value),
|
|
15872
|
-
script:
|
|
15975
|
+
script: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15873
15976
|
},
|
|
15874
15977
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
15875
15978
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -15888,7 +15991,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15888
15991
|
forfeitTx = await this._signerRouter.sign(forfeitTx, [
|
|
15889
15992
|
{
|
|
15890
15993
|
index: 0,
|
|
15891
|
-
lookupScript:
|
|
15994
|
+
lookupScript: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
15892
15995
|
}
|
|
15893
15996
|
]);
|
|
15894
15997
|
signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
|
|
@@ -15939,14 +16042,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15939
16042
|
return { skip };
|
|
15940
16043
|
}
|
|
15941
16044
|
if (!this.arkProvider) {
|
|
15942
|
-
throw new Error("
|
|
16045
|
+
throw new Error("Operator provider not configured");
|
|
15943
16046
|
}
|
|
15944
16047
|
const timelock = assertValidBatchExpiry(
|
|
15945
16048
|
event.batchExpiry,
|
|
15946
16049
|
resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
|
|
15947
16050
|
);
|
|
15948
16051
|
await this.arkProvider.confirmRegistration(intentId);
|
|
15949
|
-
const sweepTapscript =
|
|
16052
|
+
const sweepTapscript = chunkGHUUT54D_cjs.CSVMultisigTapscript.encode({
|
|
15950
16053
|
timelock,
|
|
15951
16054
|
pubkeys: [this.forfeitPubkey]
|
|
15952
16055
|
}).script;
|
|
@@ -15961,14 +16064,14 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
15961
16064
|
throw new Error("Sweep tap tree root not set");
|
|
15962
16065
|
}
|
|
15963
16066
|
const xOnlyPublicKeys = event.cosignersPublicKeys.map(
|
|
15964
|
-
(k) => base.hex.encode(
|
|
16067
|
+
(k) => base.hex.encode(chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
15965
16068
|
);
|
|
15966
16069
|
const signerPublicKey = await session.getPublicKey();
|
|
15967
|
-
const xonlySignerPublicKey =
|
|
16070
|
+
const xonlySignerPublicKey = chunkE6OOJEHL_cjs.toXOnly(signerPublicKey, "signer key");
|
|
15968
16071
|
if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
|
|
15969
16072
|
return { skip: true };
|
|
15970
16073
|
}
|
|
15971
|
-
const commitmentTx =
|
|
16074
|
+
const commitmentTx = chunkGHUUT54D_cjs.Transaction.fromPSBT(
|
|
15972
16075
|
base.base64.decode(event.unsignedCommitmentTx)
|
|
15973
16076
|
);
|
|
15974
16077
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
@@ -16050,9 +16153,9 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16050
16153
|
...existing ?? {},
|
|
16051
16154
|
intentTxId,
|
|
16052
16155
|
registerProof: intent.proof,
|
|
16053
|
-
registerProofMessage:
|
|
16156
|
+
registerProofMessage: chunkGHUUT54D_cjs.Proof.encodeMessage(intent.message),
|
|
16054
16157
|
deleteProof: deleteIntent.proof,
|
|
16055
|
-
deleteProofMessage:
|
|
16158
|
+
deleteProofMessage: chunkGHUUT54D_cjs.Intent.encodeMessage(deleteIntent.message),
|
|
16056
16159
|
intentVtxos: inputs.map((i) => ({
|
|
16057
16160
|
txid: i.txid,
|
|
16058
16161
|
vout: i.vout
|
|
@@ -16085,7 +16188,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16085
16188
|
try {
|
|
16086
16189
|
return await this.arkProvider.registerIntent(intent);
|
|
16087
16190
|
} catch (error) {
|
|
16088
|
-
if (error instanceof
|
|
16191
|
+
if (error instanceof chunkGHUUT54D_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
|
|
16089
16192
|
const deleteIntent = await this.makeDeleteIntentSignature(inputs);
|
|
16090
16193
|
await this.arkProvider.deleteIntent(deleteIntent);
|
|
16091
16194
|
return this.arkProvider.registerIntent(intent);
|
|
@@ -16101,7 +16204,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16101
16204
|
expire_at: 0,
|
|
16102
16205
|
cosigners_public_keys: cosignerPubKeys
|
|
16103
16206
|
};
|
|
16104
|
-
const proof =
|
|
16207
|
+
const proof = chunkGHUUT54D_cjs.Proof.create(message, coins, outputs);
|
|
16105
16208
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
16106
16209
|
return {
|
|
16107
16210
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -16113,7 +16216,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16113
16216
|
type: "delete",
|
|
16114
16217
|
expire_at: 0
|
|
16115
16218
|
};
|
|
16116
|
-
const proof =
|
|
16219
|
+
const proof = chunkGHUUT54D_cjs.Proof.create(message, coins, []);
|
|
16117
16220
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
16118
16221
|
return {
|
|
16119
16222
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -16125,7 +16228,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16125
16228
|
type: "get-pending-tx",
|
|
16126
16229
|
expire_at: 0
|
|
16127
16230
|
};
|
|
16128
|
-
const proof =
|
|
16231
|
+
const proof = chunkGHUUT54D_cjs.Proof.create(message, coins, []);
|
|
16129
16232
|
const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
|
|
16130
16233
|
return {
|
|
16131
16234
|
proof: base.base64.encode(signedProof.toPSBT()),
|
|
@@ -16146,7 +16249,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16146
16249
|
if (!vtxos || vtxos.length === 0) {
|
|
16147
16250
|
const scriptMap = await this.getScriptMap();
|
|
16148
16251
|
const allExtended = [];
|
|
16149
|
-
const fetchedVtxos = await
|
|
16252
|
+
const fetchedVtxos = await chunkGHUUT54D_cjs.getAllNormalizedVtxos(this.indexerProvider, [
|
|
16150
16253
|
...scriptMap.keys()
|
|
16151
16254
|
]);
|
|
16152
16255
|
for (const vtxo of fetchedVtxos) {
|
|
@@ -16168,8 +16271,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16168
16271
|
vtxos = allExtended;
|
|
16169
16272
|
}
|
|
16170
16273
|
const batches = [];
|
|
16171
|
-
for (let i = 0; i < vtxos.length; i +=
|
|
16172
|
-
batches.push(vtxos.slice(i, i +
|
|
16274
|
+
for (let i = 0; i < vtxos.length; i += MAX_INPUTS_PER_PROOF) {
|
|
16275
|
+
batches.push(vtxos.slice(i, i + MAX_INPUTS_PER_PROOF));
|
|
16173
16276
|
}
|
|
16174
16277
|
const unrollCandidates = this.checkpointUnrollCandidates(await this.arkProvider.getInfo());
|
|
16175
16278
|
const checkpointInputs = vtxos.map((vtxo) => ({
|
|
@@ -16189,8 +16292,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16189
16292
|
batchPending.push(pendingTx.arkTxid);
|
|
16190
16293
|
try {
|
|
16191
16294
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
|
|
16192
|
-
const tx =
|
|
16193
|
-
|
|
16295
|
+
const tx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(c));
|
|
16296
|
+
chunkGHUUT54D_cjs.assertAllowedSighashTypes(tx);
|
|
16194
16297
|
return tx;
|
|
16195
16298
|
});
|
|
16196
16299
|
assertCheckpointsMatchInputs(
|
|
@@ -16259,11 +16362,11 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16259
16362
|
* and one per deprecated signer — else a pre-rotation tx would stay pending forever.
|
|
16260
16363
|
*/
|
|
16261
16364
|
checkpointUnrollCandidates(info) {
|
|
16262
|
-
const current =
|
|
16365
|
+
const current = chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
16263
16366
|
const candidates = [this._serverUnrollScript, current];
|
|
16264
16367
|
for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
|
|
16265
16368
|
candidates.push(
|
|
16266
|
-
|
|
16369
|
+
chunkGHUUT54D_cjs.CSVMultisigTapscript.encode({
|
|
16267
16370
|
...current.params,
|
|
16268
16371
|
pubkeys: [base.hex.decode(deprecated)]
|
|
16269
16372
|
})
|
|
@@ -16358,7 +16461,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16358
16461
|
if (vtxos.length === 0) {
|
|
16359
16462
|
throw new Error("No VTXOs found for this arkadeCash");
|
|
16360
16463
|
}
|
|
16361
|
-
const myPkScript =
|
|
16464
|
+
const myPkScript = chunkGHUUT54D_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
|
|
16362
16465
|
let { spendable, recoverable, unclaimed } = this.classifyCashVtxos(vtxos);
|
|
16363
16466
|
let swept = 0;
|
|
16364
16467
|
const drainable = vtxos.filter(
|
|
@@ -16486,7 +16589,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16486
16589
|
params: {
|
|
16487
16590
|
pubKey: base.hex.encode(cash.publicKey),
|
|
16488
16591
|
serverPubKey: base.hex.encode(cash.serverPubKey),
|
|
16489
|
-
csvTimelock:
|
|
16592
|
+
csvTimelock: chunkGHUUT54D_cjs.timelockToSequence(cash.csvTimelock).toString()
|
|
16490
16593
|
},
|
|
16491
16594
|
script: base.hex.encode(cashScript.pkScript),
|
|
16492
16595
|
address: cashAddress.encode(),
|
|
@@ -16567,7 +16670,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16567
16670
|
const recoverable = [];
|
|
16568
16671
|
const unclaimed = [];
|
|
16569
16672
|
for (const vtxo of vtxos) {
|
|
16570
|
-
if (
|
|
16673
|
+
if (chunkGHUUT54D_cjs.isVtxoSpent(vtxo)) {
|
|
16571
16674
|
unclaimed.push(cashReport(vtxo, "already-spent"));
|
|
16572
16675
|
} else if (vtxo.isUnrolled) {
|
|
16573
16676
|
unclaimed.push(cashReport(vtxo, "exited"));
|
|
@@ -16589,7 +16692,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16589
16692
|
const all = [];
|
|
16590
16693
|
const seen = /* @__PURE__ */ new Set();
|
|
16591
16694
|
for (let pageIndex = 0; ; pageIndex++) {
|
|
16592
|
-
const { vtxos, page } = await
|
|
16695
|
+
const { vtxos, page } = await chunkGHUUT54D_cjs.getNormalizedVtxos(this.indexerProvider, {
|
|
16593
16696
|
scripts,
|
|
16594
16697
|
pageIndex,
|
|
16595
16698
|
pageSize
|
|
@@ -16624,10 +16727,10 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16624
16727
|
const identity = cash.identity;
|
|
16625
16728
|
const seenTxids = /* @__PURE__ */ new Set();
|
|
16626
16729
|
const pendingTxs = [];
|
|
16627
|
-
for (let i = 0; i < inputs.length; i +=
|
|
16628
|
-
const batch = inputs.slice(i, i +
|
|
16730
|
+
for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_PROOF) {
|
|
16731
|
+
const batch = inputs.slice(i, i + MAX_INPUTS_PER_PROOF);
|
|
16629
16732
|
const message = { type: "get-pending-tx", expire_at: 0 };
|
|
16630
|
-
const proof =
|
|
16733
|
+
const proof = chunkGHUUT54D_cjs.Proof.create(message, batch, []);
|
|
16631
16734
|
const signedProof = await identity.sign(
|
|
16632
16735
|
proof,
|
|
16633
16736
|
Array.from({ length: batch.length + 1 }, (_, j) => j)
|
|
@@ -16648,8 +16751,8 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16648
16751
|
for (const pendingTx of pendingTxs) {
|
|
16649
16752
|
try {
|
|
16650
16753
|
const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
|
|
16651
|
-
const tx =
|
|
16652
|
-
|
|
16754
|
+
const tx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(checkpoint));
|
|
16755
|
+
chunkGHUUT54D_cjs.assertAllowedSighashTypes(tx);
|
|
16653
16756
|
return tx;
|
|
16654
16757
|
});
|
|
16655
16758
|
assertCheckpointsMatchInputs(
|
|
@@ -16689,7 +16792,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16689
16792
|
}
|
|
16690
16793
|
/** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
|
|
16691
16794
|
arkTxAmountPaidTo(arkTxPsbt, pkScriptHex) {
|
|
16692
|
-
const arkTx =
|
|
16795
|
+
const arkTx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
|
|
16693
16796
|
let total = 0;
|
|
16694
16797
|
for (let i = 0; i < arkTx.outputsLength; i++) {
|
|
16695
16798
|
const output = arkTx.getOutput(i);
|
|
@@ -16748,7 +16851,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16748
16851
|
throw new Error("send({ maxChangeFee }): expected a non-negative safe integer");
|
|
16749
16852
|
}
|
|
16750
16853
|
if (selectedVtxos) {
|
|
16751
|
-
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(
|
|
16854
|
+
if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
16752
16855
|
if (inputExpiryFloor && selectedVtxos.some((coin) => !meetsInputExpiryFloor(coin, inputExpiryFloor))) {
|
|
16753
16856
|
throw new Error("send({ selectedVtxos }): input expiry floor not met");
|
|
16754
16857
|
}
|
|
@@ -16883,7 +16986,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
16883
16986
|
script: recipient.script,
|
|
16884
16987
|
amount: BigInt(recipient.amount),
|
|
16885
16988
|
// Already checked against the recipient address in `validateRecipients`.
|
|
16886
|
-
...recipient.tapTree ? { tapTree:
|
|
16989
|
+
...recipient.tapTree ? { tapTree: chunkGHUUT54D_cjs.toBIP371TapTree(recipient.tapTree) } : {}
|
|
16887
16990
|
}));
|
|
16888
16991
|
const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
|
|
16889
16992
|
let changeAmount = totalBtcSelected - totalBtcOutput;
|
|
@@ -17075,10 +17178,10 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17075
17178
|
const serverPubKey = this.arkServerPublicKey;
|
|
17076
17179
|
const serverUnrollScript = this.serverUnrollScript;
|
|
17077
17180
|
const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
|
|
17078
|
-
const normalizedInputs = inputs.map(
|
|
17079
|
-
const at = now ?? await
|
|
17181
|
+
const normalizedInputs = inputs.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
17182
|
+
const at = now ?? await chunkGHUUT54D_cjs.resolveTimeHeight(this.onchainProvider);
|
|
17080
17183
|
for (const input of normalizedInputs) {
|
|
17081
|
-
if (!
|
|
17184
|
+
if (!chunkGHUUT54D_cjs.canSpendOffchain(input, at)) {
|
|
17082
17185
|
throw new Error(
|
|
17083
17186
|
`sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
|
|
17084
17187
|
);
|
|
@@ -17132,7 +17235,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17132
17235
|
}
|
|
17133
17236
|
/**
|
|
17134
17237
|
* Build an offchain transaction from the given inputs and outputs,
|
|
17135
|
-
* sign it, submit to the
|
|
17238
|
+
* sign it, submit to the operator provider, and finalize.
|
|
17136
17239
|
*
|
|
17137
17240
|
* Signs whatever it is handed, ungated — see {@link settle} for the trade.
|
|
17138
17241
|
*
|
|
@@ -17162,7 +17265,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17162
17265
|
);
|
|
17163
17266
|
const arkTxJobs = inputs.map((input, index) => ({
|
|
17164
17267
|
index,
|
|
17165
|
-
lookupScript:
|
|
17268
|
+
lookupScript: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
17166
17269
|
}));
|
|
17167
17270
|
const identity = this.identity;
|
|
17168
17271
|
const signer = {
|
|
@@ -17272,7 +17375,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17272
17375
|
}
|
|
17273
17376
|
const checkpointIdByOutpoint = /* @__PURE__ */ new Map();
|
|
17274
17377
|
for (const encoded of signedCheckpointTxs) {
|
|
17275
|
-
const checkpoint =
|
|
17378
|
+
const checkpoint = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
|
|
17276
17379
|
for (let i = 0; i < checkpoint.inputsLength; i++) {
|
|
17277
17380
|
const input = checkpoint.getInput(i);
|
|
17278
17381
|
if (!input.txid) continue;
|
|
@@ -17388,12 +17491,12 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17388
17491
|
const spentVtxos = [];
|
|
17389
17492
|
const inputArkTxIds = /* @__PURE__ */ new Set();
|
|
17390
17493
|
const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
|
|
17391
|
-
const vtxoInputs = inputs.filter(
|
|
17494
|
+
const vtxoInputs = inputs.filter(chunkGHUUT54D_cjs.isVirtualCoin);
|
|
17392
17495
|
const cm = await this.getContractManager();
|
|
17393
17496
|
const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
|
|
17394
17497
|
const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
|
|
17395
17498
|
for (const input of inputs) {
|
|
17396
|
-
if (
|
|
17499
|
+
if (chunkGHUUT54D_cjs.isVirtualCoin(input)) {
|
|
17397
17500
|
const outpoint = `${input.txid}:${input.vout}`;
|
|
17398
17501
|
const vtxo = annotatedByKey.get(outpoint);
|
|
17399
17502
|
if (!vtxo) {
|
|
@@ -17410,7 +17513,7 @@ var Wallet2 = class extends ReadonlyWallet {
|
|
|
17410
17513
|
} else {
|
|
17411
17514
|
let sourceAddress;
|
|
17412
17515
|
try {
|
|
17413
|
-
sourceAddress =
|
|
17516
|
+
sourceAddress = chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
|
|
17414
17517
|
this.network
|
|
17415
17518
|
);
|
|
17416
17519
|
} catch {
|
|
@@ -17482,7 +17585,7 @@ function bySelectionOrder(a, b) {
|
|
|
17482
17585
|
return b.value - a.value;
|
|
17483
17586
|
}
|
|
17484
17587
|
function selectVirtualCoins(coins, targetAmount) {
|
|
17485
|
-
const sortedCoins = coins.map(
|
|
17588
|
+
const sortedCoins = coins.map(chunkGHUUT54D_cjs.normalizeVtxo).sort(bySelectionOrder);
|
|
17486
17589
|
const selectedCoins = [];
|
|
17487
17590
|
let selectedAmount = 0;
|
|
17488
17591
|
for (const coin of sortedCoins) {
|
|
@@ -17599,7 +17702,7 @@ function assertTimeoutMap(name, timeouts) {
|
|
|
17599
17702
|
if (value === void 0) {
|
|
17600
17703
|
throw new Error(`${name}.${key} must be a non-negative safe integer`);
|
|
17601
17704
|
}
|
|
17602
|
-
|
|
17705
|
+
chunkGHUUT54D_cjs.assertTimerMs(`${name}.${key}`, value);
|
|
17603
17706
|
}
|
|
17604
17707
|
}
|
|
17605
17708
|
var MessageBus = class {
|
|
@@ -17616,8 +17719,8 @@ var MessageBus = class {
|
|
|
17616
17719
|
}) {
|
|
17617
17720
|
this.walletRepository = walletRepository;
|
|
17618
17721
|
this.contractRepository = contractRepository;
|
|
17619
|
-
|
|
17620
|
-
|
|
17722
|
+
chunkGHUUT54D_cjs.assertTimerMs("tickIntervalMs", tickIntervalMs);
|
|
17723
|
+
chunkGHUUT54D_cjs.assertTimerMs("messageTimeoutMs", messageTimeoutMs);
|
|
17621
17724
|
assertTimeoutMap("messageTimeoutOverrides", messageTimeoutOverrides);
|
|
17622
17725
|
this.intentRepository = intentRepository;
|
|
17623
17726
|
this.onchainProvider = onchainProvider;
|
|
@@ -17873,14 +17976,14 @@ var MessageBus = class {
|
|
|
17873
17976
|
this.initialized = true;
|
|
17874
17977
|
}
|
|
17875
17978
|
async buildServices(config) {
|
|
17876
|
-
const arkProvider = new
|
|
17979
|
+
const arkProvider = new chunkGHUUT54D_cjs.RestOperatorProvider(config.arkServer.url);
|
|
17877
17980
|
const storage = {
|
|
17878
17981
|
walletRepository: this.walletRepository,
|
|
17879
17982
|
contractRepository: this.contractRepository,
|
|
17880
17983
|
...this.intentRepository && { intentRepository: this.intentRepository }
|
|
17881
17984
|
};
|
|
17882
17985
|
const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : void 0;
|
|
17883
|
-
const indexerProvider = new
|
|
17986
|
+
const indexerProvider = new chunkWXNSISXK_cjs.RestIndexerProvider(config.arkServer.url);
|
|
17884
17987
|
const serialized = normalizeSerializedIdentity(config.wallet);
|
|
17885
17988
|
if (isSigningSerialized(serialized)) {
|
|
17886
17989
|
const identity2 = hydrateIdentity(serialized);
|
|
@@ -18223,7 +18326,7 @@ var offboardNetworkNames = [
|
|
|
18223
18326
|
function offboardDestinationScript(destinationAddress) {
|
|
18224
18327
|
for (const networkName of offboardNetworkNames) {
|
|
18225
18328
|
try {
|
|
18226
|
-
const network =
|
|
18329
|
+
const network = chunkGHUUT54D_cjs.networks[networkName];
|
|
18227
18330
|
const addr = btcSigner.Address(network).decode(destinationAddress);
|
|
18228
18331
|
return btcSigner.OutScript.encode(addr);
|
|
18229
18332
|
} catch {
|
|
@@ -18263,7 +18366,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
|
|
|
18263
18366
|
const inputs = [];
|
|
18264
18367
|
let subtotal = 0n;
|
|
18265
18368
|
for (const vtxo of vtxos) {
|
|
18266
|
-
const inputFee = estimator.evalOffchainInput(
|
|
18369
|
+
const inputFee = estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(vtxo));
|
|
18267
18370
|
if (inputFee.satoshis >= vtxo.value) {
|
|
18268
18371
|
if (named) {
|
|
18269
18372
|
throw new Error(
|
|
@@ -18360,7 +18463,7 @@ var Ramps = class {
|
|
|
18360
18463
|
}
|
|
18361
18464
|
amount = amount ?? totalAmount;
|
|
18362
18465
|
const offchainAddress = await this.wallet.getAddress();
|
|
18363
|
-
const offchainAddr =
|
|
18466
|
+
const offchainAddr = chunkGHUUT54D_cjs.ArkAddress.decode(offchainAddress);
|
|
18364
18467
|
const offchainScript = base.hex.encode(offchainAddr.pkScript);
|
|
18365
18468
|
const outputFee = estimator.evalOffchainOutput({
|
|
18366
18469
|
amount,
|
|
@@ -18510,7 +18613,7 @@ var Ramps = class {
|
|
|
18510
18613
|
const ordered = [...candidates].sort(bySelectionOrder);
|
|
18511
18614
|
let covered = 0n;
|
|
18512
18615
|
for (let i = 0; i < ordered.length && i < MAX_VTXOS_PER_SETTLEMENT; i++) {
|
|
18513
|
-
const fee = estimator.evalOffchainInput(
|
|
18616
|
+
const fee = estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(ordered[i])).satoshis;
|
|
18514
18617
|
covered += BigInt(ordered[i].value) - BigInt(fee);
|
|
18515
18618
|
if (covered < needed) continue;
|
|
18516
18619
|
try {
|
|
@@ -18544,7 +18647,7 @@ var Ramps = class {
|
|
|
18544
18647
|
async fundChange(left, estimator) {
|
|
18545
18648
|
if (left <= 0n) return { change: 0n };
|
|
18546
18649
|
const changeAddress = await this.wallet.getAddress();
|
|
18547
|
-
const changeScript = base.hex.encode(
|
|
18650
|
+
const changeScript = base.hex.encode(chunkGHUUT54D_cjs.ArkAddress.decode(changeAddress).pkScript);
|
|
18548
18651
|
const { change } = changeAfterOutputFee(
|
|
18549
18652
|
left,
|
|
18550
18653
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script: changeScript }).satoshis)
|
|
@@ -19487,7 +19590,7 @@ var WalletMessageHandler = class {
|
|
|
19487
19590
|
this.lazyBoardingInit = payload.lazyBoarding ?? false;
|
|
19488
19591
|
this.boardingEpoch++;
|
|
19489
19592
|
this.boardingLoaded = false;
|
|
19490
|
-
this.indexerProvider = new
|
|
19593
|
+
this.indexerProvider = new chunkWXNSISXK_cjs.RestIndexerProvider(arkServerUrl);
|
|
19491
19594
|
await this.onWalletInitialized();
|
|
19492
19595
|
}
|
|
19493
19596
|
/** @see RequestInitWallet.payload.lazyBoarding */
|
|
@@ -19956,7 +20059,7 @@ var WalletMessageHandler = class {
|
|
|
19956
20059
|
this.readonlyWallet.getBoardingTxs()
|
|
19957
20060
|
]);
|
|
19958
20061
|
const indexerProvider = this.indexerProvider;
|
|
19959
|
-
const resolveTxCreatedAt = indexerProvider ? (txids) =>
|
|
20062
|
+
const resolveTxCreatedAt = indexerProvider ? (txids) => chunkGHUUT54D_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
|
|
19960
20063
|
return buildTransactionHistory(
|
|
19961
20064
|
vtxos,
|
|
19962
20065
|
boardingTxs,
|
|
@@ -20025,7 +20128,7 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
|
|
|
20025
20128
|
// budget so the worker's snapshot fallback stays reachable before this
|
|
20026
20129
|
// page deadline fires — lowering it below the budget would time the page
|
|
20027
20130
|
// out while the worker is still seconds from answering from cache.
|
|
20028
|
-
GET_ARKADE_INFO:
|
|
20131
|
+
GET_ARKADE_INFO: chunkGHUUT54D_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
|
|
20029
20132
|
INDEXER_GET_VTXOS: 2e4,
|
|
20030
20133
|
INDEXER_GET_VIRTUAL_TXS: 2e4,
|
|
20031
20134
|
GET_VTXOS: 2e4,
|
|
@@ -20170,7 +20273,7 @@ var ServiceWorkerAssetManager = class extends ServiceWorkerReadonlyAssetManager
|
|
|
20170
20273
|
}
|
|
20171
20274
|
};
|
|
20172
20275
|
var initializeMessageBus = (serviceWorker, config, timeoutMs = 2e3) => {
|
|
20173
|
-
|
|
20276
|
+
chunkGHUUT54D_cjs.assertTimerMs("messageBusTimeoutMs", timeoutMs);
|
|
20174
20277
|
const initCmd = {
|
|
20175
20278
|
tag: "INITIALIZE_MESSAGE_BUS",
|
|
20176
20279
|
id: getRandomId(),
|
|
@@ -20258,7 +20361,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20258
20361
|
}
|
|
20259
20362
|
/** Shared tail of both `create()` factories: boot the bus, INIT_WALLET, cache for reinit. */
|
|
20260
20363
|
static async bootstrap(wallet, options, serializedWallet, busConfig) {
|
|
20261
|
-
const arkServer = options.arkServer ?? { url:
|
|
20364
|
+
const arkServer = options.arkServer ?? { url: chunkGHUUT54D_cjs.DEFAULT_ARKADE_SERVER_URL };
|
|
20262
20365
|
const initWalletPayload = {
|
|
20263
20366
|
lazyBoarding: options.lazyBoarding,
|
|
20264
20367
|
arkServerUrl: arkServer.url,
|
|
@@ -20268,7 +20371,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20268
20371
|
Object.entries(options.messageTimeouts ?? {}).filter(([, ms]) => ms !== void 0)
|
|
20269
20372
|
);
|
|
20270
20373
|
for (const [key, value] of Object.entries(overrides)) {
|
|
20271
|
-
|
|
20374
|
+
chunkGHUUT54D_cjs.assertTimerMs(`messageTimeouts.${key}`, value);
|
|
20272
20375
|
}
|
|
20273
20376
|
const messageTimeouts = {
|
|
20274
20377
|
...DEFAULT_MESSAGE_TIMEOUTS,
|
|
@@ -20608,7 +20711,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20608
20711
|
try {
|
|
20609
20712
|
const response = await this.sendMessage(message);
|
|
20610
20713
|
const { vtxos, page } = response.payload;
|
|
20611
|
-
return { vtxos: vtxos.map(
|
|
20714
|
+
return { vtxos: vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo), page: page && { ...page } };
|
|
20612
20715
|
} catch (cause) {
|
|
20613
20716
|
throw new Error(`Failed to get vtxos: ${cause}`, { cause });
|
|
20614
20717
|
}
|
|
@@ -20717,7 +20820,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20717
20820
|
};
|
|
20718
20821
|
try {
|
|
20719
20822
|
const response = await this.sendMessage(message);
|
|
20720
|
-
return response.payload.vtxos.map(
|
|
20823
|
+
return response.payload.vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
20721
20824
|
} catch (error) {
|
|
20722
20825
|
throw new Error(`Failed to get vtxos: ${error}`);
|
|
20723
20826
|
}
|
|
@@ -20748,7 +20851,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20748
20851
|
"Service worker does not support the requested contract scope or freshness check"
|
|
20749
20852
|
);
|
|
20750
20853
|
}
|
|
20751
|
-
return payload.vtxos.map(
|
|
20854
|
+
return payload.vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
20752
20855
|
} catch (error) {
|
|
20753
20856
|
throw new Error(`Failed to get spendable vtxos: ${error}`);
|
|
20754
20857
|
}
|
|
@@ -20943,7 +21046,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
|
|
|
20943
21046
|
};
|
|
20944
21047
|
try {
|
|
20945
21048
|
const response = await sendContractMessage(message);
|
|
20946
|
-
return response.payload.vtxos.map(
|
|
21049
|
+
return response.payload.vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
20947
21050
|
} catch (cause) {
|
|
20948
21051
|
throw new Error(`Failed to annotate vtxos: ${cause}`, { cause });
|
|
20949
21052
|
}
|
|
@@ -21587,7 +21690,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
|
|
|
21587
21690
|
};
|
|
21588
21691
|
try {
|
|
21589
21692
|
const response = await wallet.sendMessage(message);
|
|
21590
|
-
return response.payload.vtxos.map(
|
|
21693
|
+
return response.payload.vtxos.map(chunkGHUUT54D_cjs.normalizeVtxo);
|
|
21591
21694
|
} catch (e) {
|
|
21592
21695
|
throw new Error(`Failed to get expiring vtxos: ${e}`);
|
|
21593
21696
|
}
|
|
@@ -21704,12 +21807,12 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21704
21807
|
* @returns Configured onchain wallet
|
|
21705
21808
|
* @throws Error if the configured identity cannot produce a valid x-only public key
|
|
21706
21809
|
*/
|
|
21707
|
-
static async create(identity, networkName =
|
|
21810
|
+
static async create(identity, networkName = chunkGHUUT54D_cjs.DEFAULT_NETWORK_NAME, provider) {
|
|
21708
21811
|
const pubkey = await identity.xOnlyPublicKey();
|
|
21709
21812
|
if (!pubkey) {
|
|
21710
21813
|
throw new Error("Invalid configured public key");
|
|
21711
21814
|
}
|
|
21712
|
-
const network =
|
|
21815
|
+
const network = chunkGHUUT54D_cjs.getNetwork(networkName);
|
|
21713
21816
|
const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
|
|
21714
21817
|
const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
|
|
21715
21818
|
return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
|
|
@@ -21809,7 +21912,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21809
21912
|
feeRate,
|
|
21810
21913
|
params.address
|
|
21811
21914
|
);
|
|
21812
|
-
let tx = new
|
|
21915
|
+
let tx = new chunkGHUUT54D_cjs.Transaction();
|
|
21813
21916
|
for (const input of inputs) {
|
|
21814
21917
|
tx.addInput({
|
|
21815
21918
|
txid: input.txid,
|
|
@@ -21867,7 +21970,7 @@ var OnchainWallet = class _OnchainWallet {
|
|
|
21867
21970
|
* @throws If the parent has no anchor, or funding cannot be selected/signed
|
|
21868
21971
|
*/
|
|
21869
21972
|
async bumpAnchor(parentHex, feeRate) {
|
|
21870
|
-
const parent =
|
|
21973
|
+
const parent = chunkGHUUT54D_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
|
|
21871
21974
|
const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
|
|
21872
21975
|
const child = await this.buildBumpPackage(parent, feeRate, coins);
|
|
21873
21976
|
return [parent.hex, child.hex];
|
|
@@ -22690,11 +22793,11 @@ function childTxidFromHex(txHex) {
|
|
|
22690
22793
|
|
|
22691
22794
|
// src/providers/cachingArk.ts
|
|
22692
22795
|
var DEFAULT_TTL_MS = 6e4;
|
|
22693
|
-
var
|
|
22796
|
+
var CachingOperatorProvider = class {
|
|
22694
22797
|
constructor(inner, ttlMs = DEFAULT_TTL_MS) {
|
|
22695
22798
|
this.inner = inner;
|
|
22696
22799
|
this.ttlMs = ttlMs;
|
|
22697
|
-
|
|
22800
|
+
chunkGHUUT54D_cjs.assertNonNegativeMs("ttlMs", ttlMs);
|
|
22698
22801
|
this.unsubscribe = inner.onServerInfoChanged?.((info) => {
|
|
22699
22802
|
this.cached = info;
|
|
22700
22803
|
this.expiresAt = Date.now() + this.ttlMs;
|
|
@@ -22771,6 +22874,7 @@ var CachingArkProvider = class {
|
|
|
22771
22874
|
});
|
|
22772
22875
|
}
|
|
22773
22876
|
};
|
|
22877
|
+
var CachingArkProvider = CachingOperatorProvider;
|
|
22774
22878
|
var PrevTxUnavailableError = class extends Error {
|
|
22775
22879
|
constructor(message, txids = []) {
|
|
22776
22880
|
super(message);
|
|
@@ -22786,7 +22890,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
22786
22890
|
try {
|
|
22787
22891
|
const { txs } = await source.getVirtualTxs(wanted);
|
|
22788
22892
|
for (const psbt of txs) {
|
|
22789
|
-
const tx =
|
|
22893
|
+
const tx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
|
|
22790
22894
|
resolved.set(tx.id, tx.toBytes());
|
|
22791
22895
|
}
|
|
22792
22896
|
} catch (err) {
|
|
@@ -22819,7 +22923,7 @@ async function resolvePrevTxs(txids, source, onchain) {
|
|
|
22819
22923
|
async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
22820
22924
|
const pending = [];
|
|
22821
22925
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
22822
|
-
if (
|
|
22926
|
+
if (chunkGHUUT54D_cjs.getArkPsbtFields(tx, i, chunkGHUUT54D_cjs.PrevArkTxField).length === 0) pending.push(i);
|
|
22823
22927
|
}
|
|
22824
22928
|
if (pending.length === 0) return;
|
|
22825
22929
|
const resolved = await resolvePrevTxs(
|
|
@@ -22828,13 +22932,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
|
|
|
22828
22932
|
onchain
|
|
22829
22933
|
);
|
|
22830
22934
|
for (const i of pending) {
|
|
22831
|
-
|
|
22935
|
+
chunkGHUUT54D_cjs.setArkPsbtField(tx, i, chunkGHUUT54D_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
|
|
22832
22936
|
}
|
|
22833
22937
|
}
|
|
22834
22938
|
async function attachPrevoutTxs(tx, source) {
|
|
22835
22939
|
const pending = [];
|
|
22836
22940
|
for (let i = 0; i < tx.inputsLength; i++) {
|
|
22837
|
-
if (
|
|
22941
|
+
if (chunkGHUUT54D_cjs.getArkPsbtFields(tx, i, chunkGHUUT54D_cjs.PrevoutTxField).length > 0) continue;
|
|
22838
22942
|
const input = tx.getInput(i);
|
|
22839
22943
|
if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
|
|
22840
22944
|
pending.push({ index: i, txid: base.hex.encode(input.txid) });
|
|
@@ -22849,7 +22953,7 @@ async function attachPrevoutTxs(tx, source) {
|
|
|
22849
22953
|
resolved.set(txids[i], result.value);
|
|
22850
22954
|
}
|
|
22851
22955
|
for (const { index, txid } of pending) {
|
|
22852
|
-
|
|
22956
|
+
chunkGHUUT54D_cjs.setArkPsbtField(tx, index, chunkGHUUT54D_cjs.PrevoutTxField, resolved.get(txid));
|
|
22853
22957
|
}
|
|
22854
22958
|
}
|
|
22855
22959
|
async function withPrevTxs(coins, source, onchain) {
|
|
@@ -22875,7 +22979,7 @@ exports.BIP322 = void 0;
|
|
|
22875
22979
|
async function sign2(message, identity, network) {
|
|
22876
22980
|
const xOnlyPubKey = await identity.xOnlyPublicKey();
|
|
22877
22981
|
const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
|
|
22878
|
-
const toSpend =
|
|
22982
|
+
const toSpend = chunkGHUUT54D_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
|
|
22879
22983
|
const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
|
|
22880
22984
|
const signed = await identity.sign(toSign, [0]);
|
|
22881
22985
|
signed.finalizeIdx(0);
|
|
@@ -22933,7 +23037,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
|
|
|
22933
23037
|
if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
|
|
22934
23038
|
return false;
|
|
22935
23039
|
}
|
|
22936
|
-
const toSpend =
|
|
23040
|
+
const toSpend = chunkGHUUT54D_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22937
23041
|
const toSign = craftBIP322ToSignP2TR(toSpend, pkScript);
|
|
22938
23042
|
const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
|
|
22939
23043
|
const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
|
|
@@ -22954,7 +23058,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
|
|
|
22954
23058
|
}
|
|
22955
23059
|
const sighashType = sigWithHash[sigWithHash.length - 1];
|
|
22956
23060
|
const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
|
|
22957
|
-
const toSpend =
|
|
23061
|
+
const toSpend = chunkGHUUT54D_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
|
|
22958
23062
|
const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
|
|
22959
23063
|
const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
|
|
22960
23064
|
const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
|
|
@@ -23007,7 +23111,7 @@ function encodeCompactSize(n) {
|
|
|
23007
23111
|
return buf;
|
|
23008
23112
|
}
|
|
23009
23113
|
function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
23010
|
-
const tx = new
|
|
23114
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({ version: 0 });
|
|
23011
23115
|
tx.addInput({
|
|
23012
23116
|
txid: toSpend.id,
|
|
23013
23117
|
index: 0,
|
|
@@ -23021,12 +23125,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
|
|
|
23021
23125
|
});
|
|
23022
23126
|
tx.addOutput({
|
|
23023
23127
|
amount: 0n,
|
|
23024
|
-
script:
|
|
23128
|
+
script: chunkGHUUT54D_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
23025
23129
|
});
|
|
23026
23130
|
return tx;
|
|
23027
23131
|
}
|
|
23028
23132
|
function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
23029
|
-
const tx = new
|
|
23133
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({ version: 0 });
|
|
23030
23134
|
tx.addInput({
|
|
23031
23135
|
txid: toSpend.id,
|
|
23032
23136
|
index: 0,
|
|
@@ -23038,12 +23142,12 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
|
|
|
23038
23142
|
});
|
|
23039
23143
|
tx.addOutput({
|
|
23040
23144
|
amount: 0n,
|
|
23041
|
-
script:
|
|
23145
|
+
script: chunkGHUUT54D_cjs.OP_RETURN_EMPTY_PKSCRIPT
|
|
23042
23146
|
});
|
|
23043
23147
|
return tx;
|
|
23044
23148
|
}
|
|
23045
23149
|
function finalizeVirtualTx(type, psbtBase64) {
|
|
23046
|
-
const tx =
|
|
23150
|
+
const tx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
|
|
23047
23151
|
if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
|
|
23048
23152
|
const input = tx.getInput(0);
|
|
23049
23153
|
if (!input) {
|
|
@@ -23070,14 +23174,14 @@ var ExitPathError = class extends Error {
|
|
|
23070
23174
|
reason;
|
|
23071
23175
|
};
|
|
23072
23176
|
function delayWeight(sequence) {
|
|
23073
|
-
const t =
|
|
23177
|
+
const t = chunkGHUUT54D_cjs.sequenceToTimelock(sequence);
|
|
23074
23178
|
return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
|
|
23075
23179
|
}
|
|
23076
23180
|
async function resolveUnilateralPath(params) {
|
|
23077
23181
|
const { vtxo, scriptHex, contractRepository } = params;
|
|
23078
23182
|
const contract = contractRepository ? (await collectContracts(contractRepository, { script: scriptHex }))[0] : void 0;
|
|
23079
23183
|
if (contract) {
|
|
23080
|
-
const handler =
|
|
23184
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
23081
23185
|
if (!handler) {
|
|
23082
23186
|
throw new ExitPathError(
|
|
23083
23187
|
"no-handler",
|
|
@@ -23099,12 +23203,12 @@ async function resolveUnilateralPath(params) {
|
|
|
23099
23203
|
paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
|
|
23100
23204
|
return { selection: paths[0], label: `${contract.type}:unilateral` };
|
|
23101
23205
|
}
|
|
23102
|
-
const decoded =
|
|
23206
|
+
const decoded = chunkGHUUT54D_cjs.VtxoScript.decode(vtxo.tapTree);
|
|
23103
23207
|
let best;
|
|
23104
23208
|
for (const exit of decoded.exitPaths()) {
|
|
23105
23209
|
const leaf = decoded.findLeaf(base.hex.encode(exit.script));
|
|
23106
23210
|
if (!leaf) continue;
|
|
23107
|
-
const sequence =
|
|
23211
|
+
const sequence = chunkGHUUT54D_cjs.timelockToSequence(exit.params.timelock);
|
|
23108
23212
|
const weight = delayWeight(sequence);
|
|
23109
23213
|
if (!best || weight < best.weight) {
|
|
23110
23214
|
best = { selection: { leaf, sequence }, weight };
|
|
@@ -23313,7 +23417,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
23313
23417
|
let totalAmount = 0n;
|
|
23314
23418
|
const txWeightEstimator = TxWeightEstimator.create();
|
|
23315
23419
|
for (const vtxo of vtxos) {
|
|
23316
|
-
if (!
|
|
23420
|
+
if (!chunkGHUUT54D_cjs.canSweepOnchain(vtxo)) {
|
|
23317
23421
|
throw new Error(
|
|
23318
23422
|
`Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
|
|
23319
23423
|
);
|
|
@@ -23325,7 +23429,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
23325
23429
|
wallet.onchainProvider.getTxStatus(vtxo.txid),
|
|
23326
23430
|
resolveUnilateralPath({
|
|
23327
23431
|
vtxo,
|
|
23328
|
-
scriptHex: base.hex.encode(
|
|
23432
|
+
scriptHex: base.hex.encode(chunkGHUUT54D_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
23329
23433
|
contractRepository: wallet.contractRepository,
|
|
23330
23434
|
walletDescriptor,
|
|
23331
23435
|
currentTime: Date.now()
|
|
@@ -23336,7 +23440,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
23336
23440
|
}
|
|
23337
23441
|
const spendingLeaf = resolved.selection.leaf;
|
|
23338
23442
|
const sequence = resolved.selection.sequence;
|
|
23339
|
-
const timelock =
|
|
23443
|
+
const timelock = chunkGHUUT54D_cjs.sequenceToTimelock(sequence);
|
|
23340
23444
|
const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
|
|
23341
23445
|
if (!elapsed) {
|
|
23342
23446
|
throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
|
|
@@ -23355,7 +23459,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
23355
23459
|
sequence,
|
|
23356
23460
|
witnessUtxo: {
|
|
23357
23461
|
amount: BigInt(vtxo.value),
|
|
23358
|
-
script:
|
|
23462
|
+
script: chunkGHUUT54D_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
|
|
23359
23463
|
},
|
|
23360
23464
|
sighashType: btcSigner.SigHash.DEFAULT
|
|
23361
23465
|
});
|
|
@@ -23365,7 +23469,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
|
|
|
23365
23469
|
btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
|
|
23366
23470
|
);
|
|
23367
23471
|
}
|
|
23368
|
-
const tx = new
|
|
23472
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({ version: 2 });
|
|
23369
23473
|
for (const input of inputs) {
|
|
23370
23474
|
tx.addInput(input);
|
|
23371
23475
|
}
|
|
@@ -23448,7 +23552,7 @@ async function buildSignedSweep(params) {
|
|
|
23448
23552
|
`uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
|
|
23449
23553
|
);
|
|
23450
23554
|
}
|
|
23451
|
-
const tx = new
|
|
23555
|
+
const tx = new chunkGHUUT54D_cjs.Transaction({ version: 2 });
|
|
23452
23556
|
tx.addInput({
|
|
23453
23557
|
txid: vtxo.txid,
|
|
23454
23558
|
index: vtxo.vout,
|
|
@@ -23473,7 +23577,7 @@ async function buildSignedSweep(params) {
|
|
|
23473
23577
|
finalScriptWitness: [
|
|
23474
23578
|
tapScriptSig[0][1],
|
|
23475
23579
|
...path.extraWitness,
|
|
23476
|
-
|
|
23580
|
+
chunkGHUUT54D_cjs.scriptFromTapLeafScript(path.leaf),
|
|
23477
23581
|
btcSigner.TaprootControlBlock.encode(controlBlock)
|
|
23478
23582
|
]
|
|
23479
23583
|
});
|
|
@@ -23503,7 +23607,7 @@ async function resolveFeeRate(opts) {
|
|
|
23503
23607
|
}
|
|
23504
23608
|
async function selectExitVtxos(opts) {
|
|
23505
23609
|
if (!opts.vtxos) return opts.wallet.getVtxos();
|
|
23506
|
-
const res = await
|
|
23610
|
+
const res = await chunkGHUUT54D_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
|
|
23507
23611
|
const scripts = [
|
|
23508
23612
|
...new Set(res.vtxos.filter((vtxo) => !vtxo.isSpent).map((vtxo) => vtxo.script))
|
|
23509
23613
|
];
|
|
@@ -23521,7 +23625,7 @@ async function selectExitVtxos(opts) {
|
|
|
23521
23625
|
`no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
|
|
23522
23626
|
);
|
|
23523
23627
|
}
|
|
23524
|
-
const handler =
|
|
23628
|
+
const handler = chunkE6OOJEHL_cjs.contractHandlers.get(contract.type);
|
|
23525
23629
|
if (!handler) {
|
|
23526
23630
|
throw new Error(`no contract handler registered for type '${contract.type}'`);
|
|
23527
23631
|
}
|
|
@@ -23555,7 +23659,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
23555
23659
|
if (pendingNodes.length > 0) {
|
|
23556
23660
|
const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
|
|
23557
23661
|
for (const psbt of txs) {
|
|
23558
|
-
psbts.set(
|
|
23662
|
+
psbts.set(chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
|
|
23559
23663
|
}
|
|
23560
23664
|
}
|
|
23561
23665
|
const childVsize = Number(
|
|
@@ -23583,7 +23687,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
23583
23687
|
vtxo,
|
|
23584
23688
|
resolved: await resolveUnilateralPath({
|
|
23585
23689
|
vtxo,
|
|
23586
|
-
scriptHex: base.hex.encode(
|
|
23690
|
+
scriptHex: base.hex.encode(chunkGHUUT54D_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
|
|
23587
23691
|
contractRepository: wallet.contractRepository,
|
|
23588
23692
|
walletDescriptor,
|
|
23589
23693
|
currentTime: Date.now()
|
|
@@ -23620,7 +23724,7 @@ async function computeExitLayout(opts, feeRate) {
|
|
|
23620
23724
|
});
|
|
23621
23725
|
continue;
|
|
23622
23726
|
}
|
|
23623
|
-
const t =
|
|
23727
|
+
const t = chunkGHUUT54D_cjs.sequenceToTimelock(resolved.selection.sequence);
|
|
23624
23728
|
const delay = { type: t.type, value: Number(t.value) };
|
|
23625
23729
|
infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
|
|
23626
23730
|
sweeps.push({ vtxo, resolved, sweepFee, delay });
|
|
@@ -23720,7 +23824,7 @@ var Executor = class {
|
|
|
23720
23824
|
constructor(pkg, provider, opts) {
|
|
23721
23825
|
this.pkg = pkg;
|
|
23722
23826
|
this.provider = provider;
|
|
23723
|
-
|
|
23827
|
+
chunkGHUUT54D_cjs.assertTimerMs("pollIntervalMs", opts?.pollIntervalMs);
|
|
23724
23828
|
this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
|
|
23725
23829
|
this.feeWallet = opts?.feeWallet;
|
|
23726
23830
|
this.signal = opts?.signal;
|
|
@@ -24015,7 +24119,7 @@ async function prepare(opts) {
|
|
|
24015
24119
|
txid: sweep.vtxo.txid,
|
|
24016
24120
|
vout: sweep.vtxo.vout,
|
|
24017
24121
|
value: sweep.vtxo.value,
|
|
24018
|
-
pkScript:
|
|
24122
|
+
pkScript: chunkGHUUT54D_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
|
|
24019
24123
|
},
|
|
24020
24124
|
path: sweep.resolved.selection,
|
|
24021
24125
|
outputAddress: opts.sweepAddress,
|
|
@@ -24104,7 +24208,7 @@ async function prepare(opts) {
|
|
|
24104
24208
|
if (newFee <= splitterFee) break;
|
|
24105
24209
|
splitterFee = newFee;
|
|
24106
24210
|
}
|
|
24107
|
-
const splitter = new
|
|
24211
|
+
const splitter = new chunkGHUUT54D_cjs.Transaction({ version: 2 });
|
|
24108
24212
|
for (const coin of selected.inputs) {
|
|
24109
24213
|
splitter.addInput({
|
|
24110
24214
|
txid: coin.txid,
|
|
@@ -24243,46 +24347,46 @@ var UnilateralExit = {
|
|
|
24243
24347
|
|
|
24244
24348
|
// src/arkade/index.ts
|
|
24245
24349
|
var arkade_exports = {};
|
|
24246
|
-
|
|
24247
|
-
ARKADE_OP: () =>
|
|
24248
|
-
ARKADE_OPCODES: () =>
|
|
24249
|
-
ARKADE_OPCODE_NAMES: () =>
|
|
24250
|
-
ARKADE_OPCODE_VALUES: () =>
|
|
24251
|
-
ARKADE_OPS: () =>
|
|
24350
|
+
chunkGHUUT54D_cjs.__export(arkade_exports, {
|
|
24351
|
+
ARKADE_OP: () => chunkE6OOJEHL_cjs.ARKADE_OP,
|
|
24352
|
+
ARKADE_OPCODES: () => chunkE6OOJEHL_cjs.ARKADE_OPCODES,
|
|
24353
|
+
ARKADE_OPCODE_NAMES: () => chunkE6OOJEHL_cjs.ARKADE_OPCODE_NAMES,
|
|
24354
|
+
ARKADE_OPCODE_VALUES: () => chunkE6OOJEHL_cjs.ARKADE_OPCODE_VALUES,
|
|
24355
|
+
ARKADE_OPS: () => chunkE6OOJEHL_cjs.ARKADE_OPS,
|
|
24252
24356
|
Arkade: () => Arkade,
|
|
24253
24357
|
ArkadeContract: () => ArkadeContract,
|
|
24254
|
-
ArkadeProgramScript: () =>
|
|
24255
|
-
ArkadeScript: () =>
|
|
24358
|
+
ArkadeProgramScript: () => chunkE6OOJEHL_cjs.ArkadeProgramScript,
|
|
24359
|
+
ArkadeScript: () => chunkE6OOJEHL_cjs.ArkadeScript,
|
|
24256
24360
|
ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
|
|
24257
|
-
BigNum: () =>
|
|
24361
|
+
BigNum: () => chunkE6OOJEHL_cjs.bignum_exports,
|
|
24258
24362
|
OP: () => btcSigner.OP,
|
|
24259
|
-
OPCODE_NAMES: () =>
|
|
24260
|
-
OPCODE_VALUES: () =>
|
|
24261
|
-
SUPPORTED_PROGRAM_VERSION: () =>
|
|
24363
|
+
OPCODE_NAMES: () => chunkE6OOJEHL_cjs.OPCODE_NAMES,
|
|
24364
|
+
OPCODE_VALUES: () => chunkE6OOJEHL_cjs.OPCODE_VALUES,
|
|
24365
|
+
SUPPORTED_PROGRAM_VERSION: () => chunkE6OOJEHL_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
24262
24366
|
Script: () => btcSigner.Script,
|
|
24263
|
-
UnsupportedProgramVersionError: () =>
|
|
24264
|
-
arkadeScriptHash: () =>
|
|
24265
|
-
arkadeWitnessHash: () =>
|
|
24266
|
-
asmToBytes: () =>
|
|
24267
|
-
bytesToASM: () =>
|
|
24268
|
-
computeArkadeScriptPublicKey: () =>
|
|
24367
|
+
UnsupportedProgramVersionError: () => chunkE6OOJEHL_cjs.UnsupportedProgramVersionError,
|
|
24368
|
+
arkadeScriptHash: () => chunkE6OOJEHL_cjs.arkadeScriptHash,
|
|
24369
|
+
arkadeWitnessHash: () => chunkE6OOJEHL_cjs.arkadeWitnessHash,
|
|
24370
|
+
asmToBytes: () => chunkE6OOJEHL_cjs.asmToBytes,
|
|
24371
|
+
bytesToASM: () => chunkE6OOJEHL_cjs.bytesToASM,
|
|
24372
|
+
computeArkadeScriptPublicKey: () => chunkE6OOJEHL_cjs.computeArkadeScriptPublicKey,
|
|
24269
24373
|
createArkadeBatchHandler: () => createArkadeBatchHandler,
|
|
24270
|
-
deserializeArkadeContractParams: () =>
|
|
24271
|
-
fromASM: () =>
|
|
24272
|
-
getOpcodeName: () =>
|
|
24273
|
-
getOpcodeValue: () =>
|
|
24374
|
+
deserializeArkadeContractParams: () => chunkE6OOJEHL_cjs.deserializeArkadeContractParams,
|
|
24375
|
+
fromASM: () => chunkE6OOJEHL_cjs.fromASM,
|
|
24376
|
+
getOpcodeName: () => chunkE6OOJEHL_cjs.getOpcodeName,
|
|
24377
|
+
getOpcodeValue: () => chunkE6OOJEHL_cjs.getOpcodeValue,
|
|
24274
24378
|
isContractArtifact: () => isContractArtifact,
|
|
24275
|
-
parseArtifact: () =>
|
|
24379
|
+
parseArtifact: () => chunkE6OOJEHL_cjs.parseArtifact,
|
|
24276
24380
|
programFromArtifact: () => programFromArtifact,
|
|
24277
24381
|
resolveArkadeService: () => resolveArkadeService,
|
|
24278
|
-
resolveAsm: () =>
|
|
24279
|
-
serializeArkadeContractParams: () =>
|
|
24280
|
-
stringifyArtifact: () =>
|
|
24281
|
-
toASM: () =>
|
|
24282
|
-
validateProgram: () =>
|
|
24283
|
-
witnessRefToBytes: () =>
|
|
24382
|
+
resolveAsm: () => chunkE6OOJEHL_cjs.resolveAsm,
|
|
24383
|
+
serializeArkadeContractParams: () => chunkE6OOJEHL_cjs.serializeArkadeContractParams,
|
|
24384
|
+
stringifyArtifact: () => chunkE6OOJEHL_cjs.stringifyArtifact,
|
|
24385
|
+
toASM: () => chunkE6OOJEHL_cjs.toASM,
|
|
24386
|
+
validateProgram: () => chunkE6OOJEHL_cjs.validateProgram,
|
|
24387
|
+
witnessRefToBytes: () => chunkE6OOJEHL_cjs.witnessRefToBytes
|
|
24284
24388
|
});
|
|
24285
|
-
var isVtxoCoin = (input) =>
|
|
24389
|
+
var isVtxoCoin = (input) => chunkGHUUT54D_cjs.isVirtualCoin(input);
|
|
24286
24390
|
function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
|
|
24287
24391
|
let batchId;
|
|
24288
24392
|
let sweepTapTreeRoot;
|
|
@@ -24303,23 +24407,23 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
24303
24407
|
);
|
|
24304
24408
|
await arkProvider.confirmRegistration(intentId);
|
|
24305
24409
|
batchId = event.id;
|
|
24306
|
-
const sweepTapscript =
|
|
24410
|
+
const sweepTapscript = chunkGHUUT54D_cjs.CSVMultisigTapscript.encode({
|
|
24307
24411
|
timelock,
|
|
24308
|
-
pubkeys: [
|
|
24412
|
+
pubkeys: [chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
|
|
24309
24413
|
}).script;
|
|
24310
24414
|
sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
|
|
24311
24415
|
return { skip: false };
|
|
24312
24416
|
},
|
|
24313
24417
|
onTreeSigningStarted: async (event, vtxoTree) => {
|
|
24314
24418
|
const signerPubKey = await session.getPublicKey();
|
|
24315
|
-
const xonlySignerPubKey =
|
|
24419
|
+
const xonlySignerPubKey = chunkE6OOJEHL_cjs.toXOnly(signerPubKey, "signer key");
|
|
24316
24420
|
const xOnlyPubkeys = event.cosignersPublicKeys.map(
|
|
24317
|
-
(k) => base.hex.encode(
|
|
24421
|
+
(k) => base.hex.encode(chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
|
|
24318
24422
|
);
|
|
24319
24423
|
if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
|
|
24320
24424
|
return { skip: true };
|
|
24321
24425
|
}
|
|
24322
|
-
const commitmentTx =
|
|
24426
|
+
const commitmentTx = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
|
|
24323
24427
|
validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
|
|
24324
24428
|
if (recipients && recipients.length > 0) {
|
|
24325
24429
|
validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
|
|
@@ -24357,7 +24461,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
24357
24461
|
if (connectorTree) {
|
|
24358
24462
|
validateConnectorsTxGraph(event.commitmentTx, connectorTree);
|
|
24359
24463
|
}
|
|
24360
|
-
let commitmentPsbt =
|
|
24464
|
+
let commitmentPsbt = chunkGHUUT54D_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
|
|
24361
24465
|
assertFinalCommitmentMatchesValidated(
|
|
24362
24466
|
commitmentPsbt,
|
|
24363
24467
|
validatedCommitmentTxid,
|
|
@@ -24399,7 +24503,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
24399
24503
|
boardingIndices.push(boardingIdx);
|
|
24400
24504
|
continue;
|
|
24401
24505
|
}
|
|
24402
|
-
if (!
|
|
24506
|
+
if (!chunkGHUUT54D_cjs.requiresForfeit(input) || isSubdust(input, info.dust)) {
|
|
24403
24507
|
continue;
|
|
24404
24508
|
}
|
|
24405
24509
|
if (connectorIndex >= connectorLeaves.length) {
|
|
@@ -24420,7 +24524,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
|
|
|
24420
24524
|
index: input.vout,
|
|
24421
24525
|
witnessUtxo: {
|
|
24422
24526
|
amount: BigInt(input.value),
|
|
24423
|
-
script:
|
|
24527
|
+
script: chunkGHUUT54D_cjs.VtxoScript.decode(input.tapTree).pkScript
|
|
24424
24528
|
},
|
|
24425
24529
|
sighashType: btcSigner.SigHash.DEFAULT,
|
|
24426
24530
|
tapLeafScript: [input.forfeitTapLeafScript]
|
|
@@ -24531,7 +24635,7 @@ function inputDef(name, type) {
|
|
|
24531
24635
|
return { name, type: argType(type) };
|
|
24532
24636
|
}
|
|
24533
24637
|
function argType(arkType) {
|
|
24534
|
-
if (!Object.hasOwn(
|
|
24638
|
+
if (!Object.hasOwn(chunkE6OOJEHL_cjs.ARKADE_TYPE_ENCODINGS, arkType)) fail(`unknown type '${arkType}'`);
|
|
24535
24639
|
return arkType;
|
|
24536
24640
|
}
|
|
24537
24641
|
function arrayParts(type) {
|
|
@@ -24572,7 +24676,7 @@ function flatten(param, structs, stack = []) {
|
|
|
24572
24676
|
function opcodeToken(token) {
|
|
24573
24677
|
const base = token.slice(3);
|
|
24574
24678
|
const name = base === "0" || /^([1-9]|1[0-6])$/.test(base) ? token : base;
|
|
24575
|
-
if (!Object.hasOwn(
|
|
24679
|
+
if (!Object.hasOwn(chunkE6OOJEHL_cjs.ARKADE_OPS, name)) {
|
|
24576
24680
|
fail(`opcode '${token}' is not in this SDK's table`);
|
|
24577
24681
|
}
|
|
24578
24682
|
return name;
|
|
@@ -24619,7 +24723,7 @@ function providedWitness(witness) {
|
|
|
24619
24723
|
fail(`witness '${item.name}': injected must be boolean`);
|
|
24620
24724
|
if (item.injected && item.type !== "signature")
|
|
24621
24725
|
fail(`witness '${item.name}': only infrastructure signatures can be injected`);
|
|
24622
|
-
if (item.encoding !== void 0 && item.encoding !==
|
|
24726
|
+
if (item.encoding !== void 0 && item.encoding !== chunkE6OOJEHL_cjs.ARKADE_TYPE_ENCODINGS[type])
|
|
24623
24727
|
fail(
|
|
24624
24728
|
`witness '${item.name}': encoding '${item.encoding}' does not match type '${item.type}'`
|
|
24625
24729
|
);
|
|
@@ -24628,7 +24732,7 @@ function providedWitness(witness) {
|
|
|
24628
24732
|
}
|
|
24629
24733
|
function csvTimelock(leafName, operand) {
|
|
24630
24734
|
if (typeof operand === "string") return { type: "sequence", value: operand };
|
|
24631
|
-
const timelock =
|
|
24735
|
+
const timelock = chunkGHUUT54D_cjs.sequenceToCanonicalTimelock(operand);
|
|
24632
24736
|
if (!timelock) {
|
|
24633
24737
|
fail(`leaf '${leafName}': CSV literal ${operand} is not a canonical BIP68 sequence`);
|
|
24634
24738
|
}
|
|
@@ -24722,7 +24826,7 @@ function programFromArtifact(artifact) {
|
|
|
24722
24826
|
if (!isNamed(field)) fail(`struct '${struct.name}': field needs a name and type`);
|
|
24723
24827
|
claim(fields, field.name, "struct field");
|
|
24724
24828
|
}
|
|
24725
|
-
if (Object.hasOwn(
|
|
24829
|
+
if (Object.hasOwn(chunkE6OOJEHL_cjs.ARKADE_TYPE_ENCODINGS, struct.name) || Object.hasOwn(NATIVE_STRUCTS, struct.name)) {
|
|
24726
24830
|
fail(`struct name '${struct.name}' shadows a built-in type`);
|
|
24727
24831
|
}
|
|
24728
24832
|
claim(structNames, struct.name, "struct");
|
|
@@ -24805,7 +24909,7 @@ function programFromArtifact(artifact) {
|
|
|
24805
24909
|
const paramNames = /* @__PURE__ */ new Set();
|
|
24806
24910
|
for (const param of params) claim(paramNames, param.name, "program parameter");
|
|
24807
24911
|
return {
|
|
24808
|
-
version:
|
|
24912
|
+
version: chunkE6OOJEHL_cjs.SUPPORTED_PROGRAM_VERSION,
|
|
24809
24913
|
name: artifact.contractName,
|
|
24810
24914
|
params,
|
|
24811
24915
|
functions
|
|
@@ -24889,16 +24993,16 @@ var Arkade = class _Arkade {
|
|
|
24889
24993
|
indexer = opts.indexer;
|
|
24890
24994
|
info = await opts.arkade.getInfo();
|
|
24891
24995
|
}
|
|
24892
|
-
const serverKey =
|
|
24893
|
-
const checkpoint =
|
|
24894
|
-
const network = opts.network ?? (Object.hasOwn(
|
|
24996
|
+
const serverKey = chunkE6OOJEHL_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
|
|
24997
|
+
const checkpoint = chunkGHUUT54D_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
|
|
24998
|
+
const network = opts.network ?? (Object.hasOwn(chunkGHUUT54D_cjs.networks, info.network) ? chunkGHUUT54D_cjs.getNetwork(info.network) : chunkGHUUT54D_cjs.DEFAULT_NETWORK);
|
|
24895
24999
|
let emulatorKey;
|
|
24896
25000
|
if (emulator) {
|
|
24897
|
-
emulatorKey = base.hex.decode(
|
|
25001
|
+
emulatorKey = base.hex.decode(chunkGHUUT54D_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
|
|
24898
25002
|
}
|
|
24899
25003
|
let userKey;
|
|
24900
25004
|
if (opts.identity) {
|
|
24901
|
-
userKey =
|
|
25005
|
+
userKey = chunkE6OOJEHL_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
|
|
24902
25006
|
}
|
|
24903
25007
|
let contractManager = opts.contractManager;
|
|
24904
25008
|
let ownsContractManager = false;
|
|
@@ -24997,6 +25101,7 @@ var Arkade = class _Arkade {
|
|
|
24997
25101
|
*
|
|
24998
25102
|
* Declared `server`/`user` params default to the client's keys. Compiler
|
|
24999
25103
|
* artifacts reserve the server key and exit delay to the connected server.
|
|
25104
|
+
* Struct and array params are passed whole by name (see {@link ArkadeNestedValue}).
|
|
25000
25105
|
*/
|
|
25001
25106
|
contract(program, args = {}) {
|
|
25002
25107
|
const declared = (program.params ?? []).map((p) => p.name);
|
|
@@ -25018,7 +25123,7 @@ var Arkade = class _Arkade {
|
|
|
25018
25123
|
`compiler artifact: server exit delay ${delay}s must be a multiple of 512 seconds`
|
|
25019
25124
|
);
|
|
25020
25125
|
}
|
|
25021
|
-
const sequence = BigInt(
|
|
25126
|
+
const sequence = BigInt(chunkGHUUT54D_cjs.timelockToSequence(typed));
|
|
25022
25127
|
if (args.SERVER_EXIT_DELAY !== void 0 && args.SERVER_EXIT_DELAY !== sequence && args.SERVER_EXIT_DELAY !== Number(sequence)) {
|
|
25023
25128
|
throw new Error(
|
|
25024
25129
|
"compiler artifact: reserved SERVER_EXIT_DELAY must match the connected server"
|
|
@@ -25040,19 +25145,19 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
25040
25145
|
constructor(client, program, args = {}, keys) {
|
|
25041
25146
|
this.client = client;
|
|
25042
25147
|
this.program = program;
|
|
25043
|
-
this.args =
|
|
25148
|
+
this.args = /* @__PURE__ */ Object.create(null);
|
|
25149
|
+
for (const [name, value] of Object.entries(args)) flattenValue(name, value, this.args);
|
|
25044
25150
|
this.keys = keys ?? {
|
|
25045
25151
|
serverKey: client.serverKey,
|
|
25046
25152
|
userKey: client.userKey,
|
|
25047
25153
|
emulatorKey: client.emulatorKey
|
|
25048
25154
|
};
|
|
25049
|
-
this.vtxoScript = new
|
|
25155
|
+
this.vtxoScript = new chunkE6OOJEHL_cjs.ArkadeProgramScript(program, this.args, this.keys);
|
|
25050
25156
|
this.tapTree = this.vtxoScript.encode();
|
|
25051
25157
|
this.compiled = this.vtxoScript.compiled;
|
|
25052
25158
|
}
|
|
25053
25159
|
client;
|
|
25054
25160
|
program;
|
|
25055
|
-
args;
|
|
25056
25161
|
/** The compiled taproot tree of spending-path leaves. */
|
|
25057
25162
|
vtxoScript;
|
|
25058
25163
|
/** Encoded taproot tree (shared spend context for every path). */
|
|
@@ -25061,6 +25166,8 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
25061
25166
|
keys;
|
|
25062
25167
|
/** Spending paths in declaration order. */
|
|
25063
25168
|
compiled;
|
|
25169
|
+
/** Constructor bindings by flattened name (`owners.0.key`), as persisted. */
|
|
25170
|
+
args;
|
|
25064
25171
|
/**
|
|
25065
25172
|
* Rebuild a callable contract from a persisted `"arkade"` row. Compiles with the stored keys,
|
|
25066
25173
|
* not the client's current ones, so script and address survive a server signer rotation.
|
|
@@ -25071,7 +25178,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
25071
25178
|
`ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
|
|
25072
25179
|
);
|
|
25073
25180
|
}
|
|
25074
|
-
const typed =
|
|
25181
|
+
const typed = chunkE6OOJEHL_cjs.deserializeArkadeContractParams(contract.params);
|
|
25075
25182
|
return new _ArkadeContract(client, typed.program, typed.args, {
|
|
25076
25183
|
serverKey: typed.serverKey,
|
|
25077
25184
|
userKey: typed.userKey,
|
|
@@ -25123,7 +25230,7 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
25123
25230
|
toContractParams() {
|
|
25124
25231
|
return {
|
|
25125
25232
|
type: "arkade",
|
|
25126
|
-
params:
|
|
25233
|
+
params: chunkE6OOJEHL_cjs.serializeArkadeContractParams({
|
|
25127
25234
|
program: this.program,
|
|
25128
25235
|
args: this.args,
|
|
25129
25236
|
serverKey: this.keys.serverKey,
|
|
@@ -25210,17 +25317,17 @@ var ArkadeContract = class _ArkadeContract {
|
|
|
25210
25317
|
const [registered] = await manager.getContracts({ script: scriptHex });
|
|
25211
25318
|
if (registered) {
|
|
25212
25319
|
const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
|
|
25213
|
-
return (withVtxos?.vtxos ?? []).filter((v) => !
|
|
25320
|
+
return (withVtxos?.vtxos ?? []).filter((v) => !chunkGHUUT54D_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
25214
25321
|
}
|
|
25215
25322
|
}
|
|
25216
25323
|
if (!this.client.indexer) {
|
|
25217
25324
|
throw new Error("ArkadeContract.getUtxos: an indexer is required");
|
|
25218
25325
|
}
|
|
25219
|
-
const { vtxos } = await
|
|
25326
|
+
const { vtxos } = await chunkGHUUT54D_cjs.getNormalizedVtxos(this.client.indexer, {
|
|
25220
25327
|
scripts: [scriptHex],
|
|
25221
25328
|
spendableOnly: true
|
|
25222
25329
|
});
|
|
25223
|
-
return vtxos.filter((v) => !
|
|
25330
|
+
return vtxos.filter((v) => !chunkGHUUT54D_cjs.isVtxoSpent(v) && !v.isUnrolled);
|
|
25224
25331
|
}
|
|
25225
25332
|
/** Total spendable balance (requires an indexer). */
|
|
25226
25333
|
async getBalance() {
|
|
@@ -25380,7 +25487,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
25380
25487
|
this.client.checkpoint
|
|
25381
25488
|
);
|
|
25382
25489
|
inputs.forEach(({ coin }, i) => {
|
|
25383
|
-
if (coin.sourceTx)
|
|
25490
|
+
if (coin.sourceTx) chunkGHUUT54D_cjs.setArkPsbtField(arkTx, i, chunkGHUUT54D_cjs.PrevArkTxField, coin.sourceTx);
|
|
25384
25491
|
});
|
|
25385
25492
|
if (inputs.some(({ unlocker }) => unlocker.fn.arkadeScript)) {
|
|
25386
25493
|
const indexer = this.client.indexer;
|
|
@@ -25400,8 +25507,8 @@ var ArkadeTransactionBuilder = class {
|
|
|
25400
25507
|
(w) => witnessBytes(unlocker, w)
|
|
25401
25508
|
);
|
|
25402
25509
|
if (condition.length === 0) return;
|
|
25403
|
-
|
|
25404
|
-
|
|
25510
|
+
chunkGHUUT54D_cjs.setArkPsbtField(arkTx, i, chunkGHUUT54D_cjs.ConditionWitness, condition);
|
|
25511
|
+
chunkGHUUT54D_cjs.setArkPsbtField(checkpoints[i], 0, chunkGHUUT54D_cjs.ConditionWitness, condition);
|
|
25405
25512
|
});
|
|
25406
25513
|
const packets = [];
|
|
25407
25514
|
if (this.assetSpecs.length > 0) {
|
|
@@ -25490,7 +25597,7 @@ var ArkadeTransactionBuilder = class {
|
|
|
25490
25597
|
);
|
|
25491
25598
|
return {
|
|
25492
25599
|
txid: res.arkTxid,
|
|
25493
|
-
// Required by ArkadeBroadcaster;
|
|
25600
|
+
// Required by ArkadeBroadcaster; RestOperatorProvider.submitTx rejects a response without it.
|
|
25494
25601
|
signedArkTx: res.finalArkTx,
|
|
25495
25602
|
signedCheckpointTxs: res.signedCheckpointTxs
|
|
25496
25603
|
};
|
|
@@ -25534,20 +25641,20 @@ var ArkadeTransactionBuilder = class {
|
|
|
25534
25641
|
* A caller's packet counts for every input, unread; arkd checks what it actually routes.
|
|
25535
25642
|
*/
|
|
25536
25643
|
routesAssetsFrom(vin) {
|
|
25537
|
-
return this.extraPackets.some((p) => p.type() ===
|
|
25644
|
+
return this.extraPackets.some((p) => p.type() === chunkWXNSISXK_cjs.Packet.PACKET_TYPE) || this.assetSpecs.some((spec) => spec.inputs.some((i) => i.vin === vin));
|
|
25538
25645
|
}
|
|
25539
25646
|
buildAssetPacket() {
|
|
25540
25647
|
const groups = this.assetSpecs.map((s) => {
|
|
25541
|
-
const id = typeof s.assetId === "string" ?
|
|
25542
|
-
return
|
|
25648
|
+
const id = typeof s.assetId === "string" ? chunkWXNSISXK_cjs.AssetId.fromString(s.assetId) : chunkWXNSISXK_cjs.AssetId.fromBytes(s.assetId);
|
|
25649
|
+
return chunkWXNSISXK_cjs.AssetGroup.create(
|
|
25543
25650
|
id,
|
|
25544
25651
|
null,
|
|
25545
|
-
s.inputs.map((i) =>
|
|
25546
|
-
s.outputs.map((o) =>
|
|
25547
|
-
(s.metadata ?? []).map((m) =>
|
|
25652
|
+
s.inputs.map((i) => chunkWXNSISXK_cjs.AssetInput.create(i.vin, i.amount)),
|
|
25653
|
+
s.outputs.map((o) => chunkWXNSISXK_cjs.AssetOutput.create(o.vout, o.amount)),
|
|
25654
|
+
(s.metadata ?? []).map((m) => chunkWXNSISXK_cjs.Metadata.create(m.key, m.value))
|
|
25548
25655
|
);
|
|
25549
25656
|
});
|
|
25550
|
-
return
|
|
25657
|
+
return chunkWXNSISXK_cjs.Packet.create(groups);
|
|
25551
25658
|
}
|
|
25552
25659
|
};
|
|
25553
25660
|
function unspendable(coin, now) {
|
|
@@ -25556,22 +25663,62 @@ function unspendable(coin, now) {
|
|
|
25556
25663
|
return void 0;
|
|
25557
25664
|
}
|
|
25558
25665
|
function witnessBytes({ contract, args }, ref) {
|
|
25559
|
-
return
|
|
25666
|
+
return chunkE6OOJEHL_cjs.witnessRefToBytes(ref, args, contract.args);
|
|
25667
|
+
}
|
|
25668
|
+
function flattenValue(name, value, out, ancestors = /* @__PURE__ */ new Set()) {
|
|
25669
|
+
if (typeof value !== "object" || value === null || ArrayBuffer.isView(value)) {
|
|
25670
|
+
if (Object.hasOwn(out, name)) throw new Error(`duplicate argument '${name}'`);
|
|
25671
|
+
out[name] = value;
|
|
25672
|
+
return;
|
|
25673
|
+
}
|
|
25674
|
+
if (ancestors.has(value)) throw new Error(`argument '${name}' must not be cyclic`);
|
|
25675
|
+
if (Array.isArray(value)) {
|
|
25676
|
+
for (let i = 0; i < value.length; i++) {
|
|
25677
|
+
if (!Object.hasOwn(value, i))
|
|
25678
|
+
throw new Error(`argument '${name}.${i}' is a sparse array element`);
|
|
25679
|
+
}
|
|
25680
|
+
}
|
|
25681
|
+
const entries = Object.entries(value);
|
|
25682
|
+
if (entries.length === 0) {
|
|
25683
|
+
const proto = Object.getPrototypeOf(value);
|
|
25684
|
+
if (proto !== Object.prototype && proto !== Array.prototype && proto !== null)
|
|
25685
|
+
throw new Error(`argument '${name}' must be bytes, a number, a struct or an array`);
|
|
25686
|
+
throw new Error(`argument '${name}' must not be an empty struct or array`);
|
|
25687
|
+
}
|
|
25688
|
+
ancestors.add(value);
|
|
25689
|
+
for (const [key, item] of entries) flattenValue(`${name}.${key}`, item, out, ancestors);
|
|
25690
|
+
ancestors.delete(value);
|
|
25560
25691
|
}
|
|
25561
25692
|
function bindInputs(fn, callArgs) {
|
|
25562
25693
|
const inputs = fn.def.inputs ?? [];
|
|
25563
|
-
|
|
25694
|
+
const declared = /* @__PURE__ */ new Set();
|
|
25695
|
+
for (const def of inputs) {
|
|
25696
|
+
if (declared.has(def.name)) throw new Error(`${fn.name}: duplicate input '${def.name}'`);
|
|
25697
|
+
declared.add(def.name);
|
|
25698
|
+
}
|
|
25699
|
+
const params = [
|
|
25700
|
+
...new Map(
|
|
25701
|
+
inputs.map(({ name }) => {
|
|
25702
|
+
const root = name.split(".")[0];
|
|
25703
|
+
return [name.includes(".") ? `${root}.` : root, root];
|
|
25704
|
+
})
|
|
25705
|
+
).values()
|
|
25706
|
+
];
|
|
25707
|
+
if (callArgs.length !== params.length) {
|
|
25564
25708
|
throw new Error(
|
|
25565
|
-
`${fn.name}: expected ${
|
|
25709
|
+
`${fn.name}: expected ${params.length} argument(s), got ${callArgs.length}`
|
|
25566
25710
|
);
|
|
25567
25711
|
}
|
|
25568
25712
|
const bound = /* @__PURE__ */ Object.create(null);
|
|
25569
|
-
|
|
25570
|
-
|
|
25571
|
-
|
|
25572
|
-
|
|
25573
|
-
|
|
25574
|
-
|
|
25713
|
+
params.forEach((param, i) => flattenValue(param, callArgs[i], bound));
|
|
25714
|
+
for (const name of Object.keys(bound)) {
|
|
25715
|
+
if (!declared.has(name)) throw new Error(`${fn.name}: unexpected input '${name}'`);
|
|
25716
|
+
}
|
|
25717
|
+
for (const def of inputs) {
|
|
25718
|
+
if (bound[def.name] === void 0)
|
|
25719
|
+
throw new Error(`${fn.name}: missing input '${def.name}'`);
|
|
25720
|
+
chunkE6OOJEHL_cjs.validateParamValue(def, bound[def.name]);
|
|
25721
|
+
}
|
|
25575
25722
|
return bound;
|
|
25576
25723
|
}
|
|
25577
25724
|
function attachExtension(tx, newPackets) {
|
|
@@ -25980,17 +26127,17 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
|
|
|
25980
26127
|
function offchainInputFees(vtxos, fees) {
|
|
25981
26128
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
25982
26129
|
return vtxos.reduce(
|
|
25983
|
-
(total, vtxo) => total + estimator.evalOffchainInput(
|
|
26130
|
+
(total, vtxo) => total + estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
|
|
25984
26131
|
0
|
|
25985
26132
|
);
|
|
25986
26133
|
}
|
|
25987
26134
|
async function changeOutputFee(wallet, inputs, needed, fees) {
|
|
25988
26135
|
const estimator = new Estimator(fees?.intentFee ?? {});
|
|
25989
26136
|
const net = inputs.reduce(
|
|
25990
|
-
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(
|
|
26137
|
+
(total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkGHUUT54D_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
|
|
25991
26138
|
0n
|
|
25992
26139
|
);
|
|
25993
|
-
const script = base.hex.encode(
|
|
26140
|
+
const script = base.hex.encode(chunkGHUUT54D_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
|
|
25994
26141
|
return changeAfterOutputFee(
|
|
25995
26142
|
net - needed,
|
|
25996
26143
|
(amount) => BigInt(estimator.evalOffchainOutput({ amount, script }).satoshis)
|
|
@@ -26073,6 +26220,7 @@ exports.BIP21 = BIP21;
|
|
|
26073
26220
|
exports.BIP21Error = BIP21Error;
|
|
26074
26221
|
exports.BLOCKED_UPGRADE_TIMEOUT_MS = BLOCKED_UPGRADE_TIMEOUT_MS;
|
|
26075
26222
|
exports.CachingArkProvider = CachingArkProvider;
|
|
26223
|
+
exports.CachingOperatorProvider = CachingOperatorProvider;
|
|
26076
26224
|
exports.ChainedTxType = ChainedTxType;
|
|
26077
26225
|
exports.ConnectionDisposedError = ConnectionDisposedError;
|
|
26078
26226
|
exports.ContractManager = ContractManager;
|
|
@@ -26136,6 +26284,7 @@ exports.ServiceWorkerTimeoutError = ServiceWorkerTimeoutError;
|
|
|
26136
26284
|
exports.ServiceWorkerWallet = ServiceWorkerWallet;
|
|
26137
26285
|
exports.SingleKey = SingleKey;
|
|
26138
26286
|
exports.StaticDescriptorProvider = StaticDescriptorProvider;
|
|
26287
|
+
exports.TreeSignerSession = TreeSignerSession;
|
|
26139
26288
|
exports.TxTree = TxTree;
|
|
26140
26289
|
exports.TxType = TxType;
|
|
26141
26290
|
exports.TxWeightEstimator = TxWeightEstimator;
|
|
@@ -26151,6 +26300,7 @@ exports.WalletMessageHandler = WalletMessageHandler;
|
|
|
26151
26300
|
exports.WalletNotInitializedError = WalletNotInitializedError;
|
|
26152
26301
|
exports.WsElectrumChainSource = WsElectrumChainSource;
|
|
26153
26302
|
exports.adoptContractDescriptor = adoptContractDescriptor;
|
|
26303
|
+
exports.applyWalletStateUpdate = applyWalletStateUpdate;
|
|
26154
26304
|
exports.arkAssetRail = arkAssetRail;
|
|
26155
26305
|
exports.arkRail = arkRail;
|
|
26156
26306
|
exports.arkTarget = arkTarget;
|
|
@@ -26215,7 +26365,7 @@ exports.deserializeVtxo = deserializeVtxo;
|
|
|
26215
26365
|
exports.encodeArkContract = encodeArkContract;
|
|
26216
26366
|
exports.exitObserverFor = exitObserverFor;
|
|
26217
26367
|
exports.extendVirtualCoinForContract = extendVirtualCoinForContract;
|
|
26218
|
-
exports.
|
|
26368
|
+
exports.extractOperatorProviderUrl = extractOperatorProviderUrl;
|
|
26219
26369
|
exports.gateExclusion = gateExclusion;
|
|
26220
26370
|
exports.gatedContracts = gatedContracts;
|
|
26221
26371
|
exports.getAllByIndexValues = getAllByIndexValues;
|
|
@@ -26293,5 +26443,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
|
|
|
26293
26443
|
exports.walletFeeSource = walletFeeSource;
|
|
26294
26444
|
exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
|
|
26295
26445
|
exports.withPrevTxs = withPrevTxs;
|
|
26296
|
-
//# sourceMappingURL=chunk-
|
|
26297
|
-
//# sourceMappingURL=chunk-
|
|
26446
|
+
//# sourceMappingURL=chunk-F3FAE7VJ.cjs.map
|
|
26447
|
+
//# sourceMappingURL=chunk-F3FAE7VJ.cjs.map
|