@arkade-os/sdk 0.4.33 → 0.4.35
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 +1 -1
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +3 -3
- package/dist/adapters/indexedDB.cjs +5 -5
- package/dist/adapters/indexedDB.js +4 -4
- package/dist/{ark-DEsDMYGv.d.cts → ark-D6sau_6-.d.cts} +522 -9
- package/dist/{ark-DEsDMYGv.d.ts → ark-D6sau_6-.d.ts} +522 -9
- package/dist/{asyncStorageTaskQueue-D8T1VXEx.d.cts → asyncStorageTaskQueue-CpC027t_.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-CMrTYlKG.d.ts → asyncStorageTaskQueue-GT8fmPUG.d.ts} +2 -2
- package/dist/{chunk-E22HEKLN.js → chunk-3JR77WQ4.js} +140 -42
- package/dist/chunk-3JR77WQ4.js.map +1 -0
- package/dist/{chunk-WMIPYZSB.cjs → chunk-CMPJR3HS.cjs} +42 -9
- package/dist/chunk-CMPJR3HS.cjs.map +1 -0
- package/dist/{chunk-AOJUURHM.js → chunk-CUSABEUQ.js} +141 -37
- package/dist/chunk-CUSABEUQ.js.map +1 -0
- package/dist/{chunk-HAVA4XB7.cjs → chunk-FM7T7JVL.cjs} +7 -7
- package/dist/{chunk-HAVA4XB7.cjs.map → chunk-FM7T7JVL.cjs.map} +1 -1
- package/dist/{chunk-GYSK5R57.cjs → chunk-GUTKJMSF.cjs} +164 -59
- package/dist/chunk-GUTKJMSF.cjs.map +1 -0
- package/dist/{chunk-7K3ROJF6.cjs → chunk-H2LX2KKY.cjs} +2161 -466
- package/dist/chunk-H2LX2KKY.cjs.map +1 -0
- package/dist/{chunk-DSS2GQUG.js → chunk-NOR7XOKN.js} +2021 -331
- package/dist/chunk-NOR7XOKN.js.map +1 -0
- package/dist/{chunk-BU3BU6XK.js → chunk-OURFR4UR.js} +3 -3
- package/dist/{chunk-BU3BU6XK.js.map → chunk-OURFR4UR.js.map} +1 -1
- package/dist/{chunk-TU3LVAPX.js → chunk-OUVTG72A.js} +43 -11
- package/dist/chunk-OUVTG72A.js.map +1 -0
- package/dist/{chunk-5CCRRL5S.cjs → chunk-VYS3KGRI.cjs} +19 -13
- package/dist/chunk-VYS3KGRI.cjs.map +1 -0
- package/dist/{chunk-SPDNHPM4.cjs → chunk-X2EQLK4O.cjs} +149 -46
- package/dist/chunk-X2EQLK4O.cjs.map +1 -0
- package/dist/{chunk-L6ZETTX3.js → chunk-XQS2HW4Q.js} +11 -5
- package/dist/chunk-XQS2HW4Q.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +7 -7
- 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-BJeBNP5a.d.cts → delegate-C-L6gSZx.d.cts} +1 -1
- package/dist/{delegate-EXN2mfkb.d.ts → delegate-De5__fpZ.d.ts} +1 -1
- package/dist/{index-BG2ooYKO.d.ts → index-BETdjE_o.d.ts} +22 -16
- package/dist/{index-DHjEeHEp.d.cts → index-jwQfHP6D.d.cts} +22 -16
- package/dist/index.cjs +158 -130
- package/dist/index.d.cts +125 -16
- package/dist/index.d.ts +125 -16
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +14 -14
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +5 -5
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +13 -13
- package/dist/repositories/sqlite/index.d.cts +1 -1
- package/dist/repositories/sqlite/index.d.ts +1 -1
- package/dist/repositories/sqlite/index.js +4 -4
- package/dist/{taskRunner-pIGyarFG.d.cts → taskRunner-DCyp6Gea.d.cts} +2 -2
- package/dist/{taskRunner-B7lBU45X.d.ts → taskRunner-DnxtObeq.d.ts} +2 -2
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/index.cjs +13 -13
- package/dist/wallet/expo/index.d.cts +5 -5
- package/dist/wallet/expo/index.d.ts +5 -5
- package/dist/wallet/expo/index.js +5 -5
- package/dist/{wallet-D4Dll5Gu.d.cts → wallet-BWHbd5b1.d.cts} +388 -10
- package/dist/{wallet-C4L_X0i6.d.ts → wallet-Bth5uucA.d.ts} +388 -10
- 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 +5 -5
- package/dist/chunk-5CCRRL5S.cjs.map +0 -1
- package/dist/chunk-7K3ROJF6.cjs.map +0 -1
- package/dist/chunk-AOJUURHM.js.map +0 -1
- package/dist/chunk-DSS2GQUG.js.map +0 -1
- package/dist/chunk-E22HEKLN.js.map +0 -1
- package/dist/chunk-GYSK5R57.cjs.map +0 -1
- package/dist/chunk-L6ZETTX3.js.map +0 -1
- package/dist/chunk-SPDNHPM4.cjs.map +0 -1
- package/dist/chunk-TU3LVAPX.js.map +0 -1
- package/dist/chunk-WMIPYZSB.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkCMPJR3HS_cjs = require('./chunk-CMPJR3HS.cjs');
|
|
4
4
|
var base = require('@scure/base');
|
|
5
5
|
var descriptorsScure = require('@bitcoinerlab/descriptors-scure');
|
|
6
6
|
var btcSigner = require('@scure/btc-signer');
|
|
@@ -73,14 +73,14 @@ var ContractHandlerRegistry = class {
|
|
|
73
73
|
var contractHandlers = new ContractHandlerRegistry();
|
|
74
74
|
exports.DefaultVtxo = void 0;
|
|
75
75
|
((DefaultVtxo2) => {
|
|
76
|
-
class Script2 extends
|
|
76
|
+
class Script2 extends chunkCMPJR3HS_cjs.VtxoScript {
|
|
77
77
|
/** Create the default virtual output script with one forfeit path and one exit path. */
|
|
78
78
|
constructor(options) {
|
|
79
79
|
const { pubKey, serverPubKey, csvTimelock } = options;
|
|
80
|
-
const forfeitScript =
|
|
80
|
+
const forfeitScript = chunkCMPJR3HS_cjs.MultisigTapscript.encode({
|
|
81
81
|
pubkeys: [pubKey, serverPubKey]
|
|
82
82
|
}).script;
|
|
83
|
-
const exitScript =
|
|
83
|
+
const exitScript = chunkCMPJR3HS_cjs.CSVMultisigTapscript.encode({
|
|
84
84
|
timelock: csvTimelock,
|
|
85
85
|
pubkeys: [pubKey]
|
|
86
86
|
}).script;
|
|
@@ -190,6 +190,9 @@ function deriveDescriptorLeafPubKey(descriptor) {
|
|
|
190
190
|
return key.pubkey;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
// src/contracts/constants.ts
|
|
194
|
+
var DEFAULT_PAGE_SIZE = 500;
|
|
195
|
+
|
|
193
196
|
// src/contracts/handlers/helpers.ts
|
|
194
197
|
function extractRawPubKey(value) {
|
|
195
198
|
if (!isDescriptor(value)) {
|
|
@@ -245,7 +248,7 @@ function isCltvSatisfied(context, locktime) {
|
|
|
245
248
|
function isCsvSpendable(context, sequence) {
|
|
246
249
|
if (sequence === void 0) return true;
|
|
247
250
|
if (!context.vtxo) return false;
|
|
248
|
-
const timelock =
|
|
251
|
+
const timelock = chunkCMPJR3HS_cjs.sequenceToTimelock(sequence);
|
|
249
252
|
if (timelock.type === "blocks") {
|
|
250
253
|
if (context.blockHeight === void 0 || context.vtxo.status.block_height === void 0) {
|
|
251
254
|
return false;
|
|
@@ -259,6 +262,26 @@ function isCsvSpendable(context, sequence) {
|
|
|
259
262
|
}
|
|
260
263
|
return false;
|
|
261
264
|
}
|
|
265
|
+
async function detectUsedScripts(indexerProvider, scriptHexes) {
|
|
266
|
+
const used = /* @__PURE__ */ new Set();
|
|
267
|
+
if (scriptHexes.length === 0) return used;
|
|
268
|
+
const remaining = new Set(scriptHexes);
|
|
269
|
+
let pageIndex = 0;
|
|
270
|
+
let hasMore = true;
|
|
271
|
+
while (hasMore && remaining.size > 0) {
|
|
272
|
+
const { vtxos, page } = await indexerProvider.getVtxos({
|
|
273
|
+
scripts: scriptHexes,
|
|
274
|
+
pageIndex,
|
|
275
|
+
pageSize: DEFAULT_PAGE_SIZE
|
|
276
|
+
});
|
|
277
|
+
for (const vtxo of vtxos) {
|
|
278
|
+
if (remaining.delete(vtxo.script)) used.add(vtxo.script);
|
|
279
|
+
}
|
|
280
|
+
hasMore = page ? vtxos.length === DEFAULT_PAGE_SIZE : false;
|
|
281
|
+
pageIndex++;
|
|
282
|
+
}
|
|
283
|
+
return used;
|
|
284
|
+
}
|
|
262
285
|
|
|
263
286
|
// src/contracts/metadata.ts
|
|
264
287
|
var WALLET_RECEIVE_SOURCE = "wallet-receive";
|
|
@@ -277,11 +300,11 @@ var DefaultContractHandler = {
|
|
|
277
300
|
return {
|
|
278
301
|
pubKey: base.hex.encode(params.pubKey),
|
|
279
302
|
serverPubKey: base.hex.encode(params.serverPubKey),
|
|
280
|
-
csvTimelock:
|
|
303
|
+
csvTimelock: chunkCMPJR3HS_cjs.timelockToSequence(params.csvTimelock).toString()
|
|
281
304
|
};
|
|
282
305
|
},
|
|
283
306
|
deserializeParams(params) {
|
|
284
|
-
const csvTimelock = params.csvTimelock !== void 0 && params.csvTimelock !== "" ?
|
|
307
|
+
const csvTimelock = params.csvTimelock !== void 0 && params.csvTimelock !== "" ? chunkCMPJR3HS_cjs.sequenceToTimelock(Number(params.csvTimelock)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
|
|
285
308
|
return {
|
|
286
309
|
pubKey: extractPubKeyBytes(params.pubKey),
|
|
287
310
|
serverPubKey: extractPubKeyBytes(params.serverPubKey),
|
|
@@ -330,27 +353,38 @@ var DefaultContractHandler = {
|
|
|
330
353
|
},
|
|
331
354
|
async discoverAt(index, descriptor, deps) {
|
|
332
355
|
const pubKey = deriveDescriptorLeafPubKey(descriptor);
|
|
356
|
+
const signers = [deps.serverPubKey, ...deps.deprecatedSignerPubKeys ?? []];
|
|
357
|
+
const seen = /* @__PURE__ */ new Set();
|
|
358
|
+
const candidates = [];
|
|
359
|
+
for (const serverPubKey of signers) {
|
|
360
|
+
for (const csvTimelock of deps.csvTimelocks) {
|
|
361
|
+
const script = new exports.DefaultVtxo.Script({
|
|
362
|
+
pubKey,
|
|
363
|
+
serverPubKey,
|
|
364
|
+
csvTimelock
|
|
365
|
+
});
|
|
366
|
+
const scriptHex = base.hex.encode(script.pkScript);
|
|
367
|
+
if (seen.has(scriptHex)) continue;
|
|
368
|
+
seen.add(scriptHex);
|
|
369
|
+
candidates.push({ serverPubKey, csvTimelock, script, scriptHex });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const used = await detectUsedScripts(
|
|
373
|
+
deps.indexerProvider,
|
|
374
|
+
candidates.map((c) => c.scriptHex)
|
|
375
|
+
);
|
|
333
376
|
const out = [];
|
|
334
|
-
for (const
|
|
335
|
-
|
|
336
|
-
pubKey,
|
|
337
|
-
serverPubKey: deps.serverPubKey,
|
|
338
|
-
csvTimelock
|
|
339
|
-
});
|
|
340
|
-
const scriptHex = base.hex.encode(script.pkScript);
|
|
341
|
-
const { vtxos } = await deps.indexerProvider.getVtxos({
|
|
342
|
-
scripts: [scriptHex]
|
|
343
|
-
});
|
|
344
|
-
if (vtxos.length === 0) continue;
|
|
377
|
+
for (const c of candidates) {
|
|
378
|
+
if (!used.has(c.scriptHex)) continue;
|
|
345
379
|
out.push({
|
|
346
380
|
type: "default",
|
|
347
381
|
params: {
|
|
348
382
|
pubKey: base.hex.encode(pubKey),
|
|
349
|
-
serverPubKey: base.hex.encode(
|
|
350
|
-
csvTimelock:
|
|
383
|
+
serverPubKey: base.hex.encode(c.serverPubKey),
|
|
384
|
+
csvTimelock: chunkCMPJR3HS_cjs.timelockToSequence(c.csvTimelock).toString()
|
|
351
385
|
},
|
|
352
|
-
script: scriptHex,
|
|
353
|
-
address: script.address(deps.network.hrp,
|
|
386
|
+
script: c.scriptHex,
|
|
387
|
+
address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
|
|
354
388
|
...index > 0 ? {
|
|
355
389
|
metadata: {
|
|
356
390
|
source: WALLET_RECEIVE_SOURCE,
|
|
@@ -364,12 +398,12 @@ var DefaultContractHandler = {
|
|
|
364
398
|
};
|
|
365
399
|
exports.DelegateVtxo = void 0;
|
|
366
400
|
((DelegateVtxo2) => {
|
|
367
|
-
class Script2 extends
|
|
401
|
+
class Script2 extends chunkCMPJR3HS_cjs.VtxoScript {
|
|
368
402
|
/** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
|
|
369
403
|
constructor(options) {
|
|
370
404
|
const defaultVtxo = new exports.DefaultVtxo.Script(options);
|
|
371
405
|
const { delegatePubKey, pubKey, serverPubKey } = options;
|
|
372
|
-
const delegateScript =
|
|
406
|
+
const delegateScript = chunkCMPJR3HS_cjs.MultisigTapscript.encode({
|
|
373
407
|
pubkeys: [pubKey, delegatePubKey, serverPubKey]
|
|
374
408
|
}).script;
|
|
375
409
|
super([...defaultVtxo.scripts, delegateScript]);
|
|
@@ -407,11 +441,11 @@ var DelegateContractHandler = {
|
|
|
407
441
|
pubKey: base.hex.encode(params.pubKey),
|
|
408
442
|
serverPubKey: base.hex.encode(params.serverPubKey),
|
|
409
443
|
delegatePubKey: base.hex.encode(params.delegatePubKey),
|
|
410
|
-
csvTimelock:
|
|
444
|
+
csvTimelock: chunkCMPJR3HS_cjs.timelockToSequence(params.csvTimelock).toString()
|
|
411
445
|
};
|
|
412
446
|
},
|
|
413
447
|
deserializeParams(params) {
|
|
414
|
-
const csvTimelock =
|
|
448
|
+
const csvTimelock = chunkCMPJR3HS_cjs.sequenceToTimelock(Number(params.csvTimelock));
|
|
415
449
|
return {
|
|
416
450
|
pubKey: base.hex.decode(params.pubKey),
|
|
417
451
|
serverPubKey: base.hex.decode(params.serverPubKey),
|
|
@@ -465,29 +499,40 @@ var DelegateContractHandler = {
|
|
|
465
499
|
async discoverAt(index, descriptor, deps) {
|
|
466
500
|
if (!deps.delegatePubKey) return [];
|
|
467
501
|
const pubKey = deriveDescriptorLeafPubKey(descriptor);
|
|
502
|
+
const signers = [deps.serverPubKey, ...deps.deprecatedSignerPubKeys ?? []];
|
|
503
|
+
const seen = /* @__PURE__ */ new Set();
|
|
504
|
+
const candidates = [];
|
|
505
|
+
for (const serverPubKey of signers) {
|
|
506
|
+
for (const csvTimelock of deps.csvTimelocks) {
|
|
507
|
+
const script = new exports.DelegateVtxo.Script({
|
|
508
|
+
pubKey,
|
|
509
|
+
serverPubKey,
|
|
510
|
+
delegatePubKey: deps.delegatePubKey,
|
|
511
|
+
csvTimelock
|
|
512
|
+
});
|
|
513
|
+
const scriptHex = base.hex.encode(script.pkScript);
|
|
514
|
+
if (seen.has(scriptHex)) continue;
|
|
515
|
+
seen.add(scriptHex);
|
|
516
|
+
candidates.push({ serverPubKey, csvTimelock, script, scriptHex });
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const used = await detectUsedScripts(
|
|
520
|
+
deps.indexerProvider,
|
|
521
|
+
candidates.map((c) => c.scriptHex)
|
|
522
|
+
);
|
|
468
523
|
const out = [];
|
|
469
|
-
for (const
|
|
470
|
-
|
|
471
|
-
pubKey,
|
|
472
|
-
serverPubKey: deps.serverPubKey,
|
|
473
|
-
delegatePubKey: deps.delegatePubKey,
|
|
474
|
-
csvTimelock
|
|
475
|
-
});
|
|
476
|
-
const scriptHex = base.hex.encode(script.pkScript);
|
|
477
|
-
const { vtxos } = await deps.indexerProvider.getVtxos({
|
|
478
|
-
scripts: [scriptHex]
|
|
479
|
-
});
|
|
480
|
-
if (vtxos.length === 0) continue;
|
|
524
|
+
for (const c of candidates) {
|
|
525
|
+
if (!used.has(c.scriptHex)) continue;
|
|
481
526
|
out.push({
|
|
482
527
|
type: "delegate",
|
|
483
528
|
params: {
|
|
484
529
|
pubKey: base.hex.encode(pubKey),
|
|
485
|
-
serverPubKey: base.hex.encode(
|
|
530
|
+
serverPubKey: base.hex.encode(c.serverPubKey),
|
|
486
531
|
delegatePubKey: base.hex.encode(deps.delegatePubKey),
|
|
487
|
-
csvTimelock:
|
|
532
|
+
csvTimelock: chunkCMPJR3HS_cjs.timelockToSequence(c.csvTimelock).toString()
|
|
488
533
|
},
|
|
489
|
-
script: scriptHex,
|
|
490
|
-
address: script.address(deps.network.hrp,
|
|
534
|
+
script: c.scriptHex,
|
|
535
|
+
address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
|
|
491
536
|
...index > 0 ? {
|
|
492
537
|
metadata: {
|
|
493
538
|
source: WALLET_RECEIVE_SOURCE,
|
|
@@ -501,7 +546,7 @@ var DelegateContractHandler = {
|
|
|
501
546
|
};
|
|
502
547
|
exports.VHTLC = void 0;
|
|
503
548
|
((VHTLC2) => {
|
|
504
|
-
class Script2 extends
|
|
549
|
+
class Script2 extends chunkCMPJR3HS_cjs.VtxoScript {
|
|
505
550
|
/** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
|
|
506
551
|
constructor(options) {
|
|
507
552
|
validateOptions(options);
|
|
@@ -516,27 +561,27 @@ exports.VHTLC = void 0;
|
|
|
516
561
|
unilateralRefundWithoutReceiverDelay
|
|
517
562
|
} = options;
|
|
518
563
|
const conditionScript = preimageConditionScript(preimageHash);
|
|
519
|
-
const claimScript =
|
|
564
|
+
const claimScript = chunkCMPJR3HS_cjs.ConditionMultisigTapscript.encode({
|
|
520
565
|
conditionScript,
|
|
521
566
|
pubkeys: [receiver, server]
|
|
522
567
|
}).script;
|
|
523
|
-
const refundScript =
|
|
568
|
+
const refundScript = chunkCMPJR3HS_cjs.MultisigTapscript.encode({
|
|
524
569
|
pubkeys: [sender, receiver, server]
|
|
525
570
|
}).script;
|
|
526
|
-
const refundWithoutReceiverScript =
|
|
571
|
+
const refundWithoutReceiverScript = chunkCMPJR3HS_cjs.CLTVMultisigTapscript.encode({
|
|
527
572
|
absoluteTimelock: refundLocktime,
|
|
528
573
|
pubkeys: [sender, server]
|
|
529
574
|
}).script;
|
|
530
|
-
const unilateralClaimScript =
|
|
575
|
+
const unilateralClaimScript = chunkCMPJR3HS_cjs.ConditionCSVMultisigTapscript.encode({
|
|
531
576
|
conditionScript,
|
|
532
577
|
timelock: unilateralClaimDelay,
|
|
533
578
|
pubkeys: [receiver]
|
|
534
579
|
}).script;
|
|
535
|
-
const unilateralRefundScript =
|
|
580
|
+
const unilateralRefundScript = chunkCMPJR3HS_cjs.CSVMultisigTapscript.encode({
|
|
536
581
|
timelock: unilateralRefundDelay,
|
|
537
582
|
pubkeys: [sender, receiver]
|
|
538
583
|
}).script;
|
|
539
|
-
const unilateralRefundWithoutReceiverScript =
|
|
584
|
+
const unilateralRefundWithoutReceiverScript = chunkCMPJR3HS_cjs.CSVMultisigTapscript.encode({
|
|
540
585
|
timelock: unilateralRefundWithoutReceiverDelay,
|
|
541
586
|
pubkeys: [sender]
|
|
542
587
|
}).script;
|
|
@@ -663,9 +708,9 @@ var VHTLCContractHandler = {
|
|
|
663
708
|
server: base.hex.encode(params.server),
|
|
664
709
|
hash: base.hex.encode(params.preimageHash),
|
|
665
710
|
refundLocktime: params.refundLocktime.toString(),
|
|
666
|
-
claimDelay:
|
|
667
|
-
refundDelay:
|
|
668
|
-
refundNoReceiverDelay:
|
|
711
|
+
claimDelay: chunkCMPJR3HS_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
|
|
712
|
+
refundDelay: chunkCMPJR3HS_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
|
|
713
|
+
refundNoReceiverDelay: chunkCMPJR3HS_cjs.timelockToSequence(
|
|
669
714
|
params.unilateralRefundWithoutReceiverDelay
|
|
670
715
|
).toString()
|
|
671
716
|
};
|
|
@@ -677,9 +722,9 @@ var VHTLCContractHandler = {
|
|
|
677
722
|
server: base.hex.decode(params.server),
|
|
678
723
|
preimageHash: base.hex.decode(params.hash),
|
|
679
724
|
refundLocktime: BigInt(params.refundLocktime),
|
|
680
|
-
unilateralClaimDelay:
|
|
681
|
-
unilateralRefundDelay:
|
|
682
|
-
unilateralRefundWithoutReceiverDelay:
|
|
725
|
+
unilateralClaimDelay: chunkCMPJR3HS_cjs.sequenceToTimelock(Number(params.claimDelay)),
|
|
726
|
+
unilateralRefundDelay: chunkCMPJR3HS_cjs.sequenceToTimelock(Number(params.refundDelay)),
|
|
727
|
+
unilateralRefundWithoutReceiverDelay: chunkCMPJR3HS_cjs.sequenceToTimelock(
|
|
683
728
|
Number(params.refundNoReceiverDelay)
|
|
684
729
|
)
|
|
685
730
|
};
|
|
@@ -820,8 +865,6 @@ var VHTLCContractHandler = {
|
|
|
820
865
|
return paths;
|
|
821
866
|
}
|
|
822
867
|
};
|
|
823
|
-
|
|
824
|
-
// src/contracts/handlers/boarding.ts
|
|
825
868
|
var BoardingContractHandler = {
|
|
826
869
|
type: "boarding",
|
|
827
870
|
createScript(params) {
|
|
@@ -841,6 +884,67 @@ var BoardingContractHandler = {
|
|
|
841
884
|
},
|
|
842
885
|
getSpendablePaths(script, contract, context) {
|
|
843
886
|
return DefaultContractHandler.getSpendablePaths(script, contract, context);
|
|
887
|
+
},
|
|
888
|
+
/**
|
|
889
|
+
* Probe the on-chain UTXO set for a boarding output at this HD index.
|
|
890
|
+
*
|
|
891
|
+
* Boarding's source of truth is the **current** on-chain coin set
|
|
892
|
+
* (`OnchainProvider.getCoins`), not the Ark indexer: a boarded (spent)
|
|
893
|
+
* boarding output becomes an L2 VTXO at the receive index, so the
|
|
894
|
+
* indexer probe already keeps the gap window open for it; only an
|
|
895
|
+
* *unspent* boarding output needs the on-chain probe (see plan §2).
|
|
896
|
+
*
|
|
897
|
+
* No-ops (returns `[]`) when boarding discovery is not plumbed — i.e.
|
|
898
|
+
* `deps.boardingTimelock` or `deps.onchainNetwork` is absent — so the
|
|
899
|
+
* scanner unit harness (which sets neither) is unaffected.
|
|
900
|
+
*
|
|
901
|
+
* Always emits `type: "boarding"`, even in the degenerate equal-delay case
|
|
902
|
+
* where the boarding script is byte-identical to a `default` script at this
|
|
903
|
+
* index (`boardingExitDelay === unilateralExitDelay`). The collision is no
|
|
904
|
+
* longer pre-judged in discovery; it is tolerated FIRST-WINS at the
|
|
905
|
+
* persistence layer ({@link ContractManager.upsertContract}). `deps.csvTimelocks`
|
|
906
|
+
* is intentionally not read here.
|
|
907
|
+
*/
|
|
908
|
+
async discoverAt(index, descriptor, deps) {
|
|
909
|
+
if (!deps.boardingTimelock || !deps.onchainNetwork) return [];
|
|
910
|
+
const pubKey = deriveDescriptorLeafPubKey(descriptor);
|
|
911
|
+
const script = new exports.DefaultVtxo.Script({
|
|
912
|
+
pubKey,
|
|
913
|
+
serverPubKey: deps.serverPubKey,
|
|
914
|
+
csvTimelock: deps.boardingTimelock
|
|
915
|
+
});
|
|
916
|
+
const onchainAddress = script.onchainAddress(deps.onchainNetwork);
|
|
917
|
+
const coins = await deps.onchainProvider.getCoins(onchainAddress);
|
|
918
|
+
if (coins.length === 0) return [];
|
|
919
|
+
const scriptHex = base.hex.encode(script.pkScript);
|
|
920
|
+
const boardingSeq = chunkCMPJR3HS_cjs.timelockToSequence(deps.boardingTimelock);
|
|
921
|
+
return [
|
|
922
|
+
{
|
|
923
|
+
type: "boarding",
|
|
924
|
+
params: {
|
|
925
|
+
pubKey: base.hex.encode(pubKey),
|
|
926
|
+
serverPubKey: base.hex.encode(deps.serverPubKey),
|
|
927
|
+
csvTimelock: boardingSeq.toString()
|
|
928
|
+
},
|
|
929
|
+
script: scriptHex,
|
|
930
|
+
// The persisted row's `address` is the *Ark* address (not the
|
|
931
|
+
// on-chain P2TR), matching the row registered at init so the
|
|
932
|
+
// ContractWatcher keeps monitoring the same L2 script and the
|
|
933
|
+
// VTXO repository bucket lines up (plan §6-I.4). The P2TR is
|
|
934
|
+
// recomputed from params only for the `getCoins` probe.
|
|
935
|
+
address: script.address(deps.network.hrp, deps.serverPubKey).encode(),
|
|
936
|
+
// Tag rotated rows (index > 0) so boot resolution can find the
|
|
937
|
+
// newest boarding address and descriptor-aware signing can
|
|
938
|
+
// recover the per-index key (plan §6-II/§6-III.3). The index-0
|
|
939
|
+
// baseline stays untagged, matching `default`/`delegate`.
|
|
940
|
+
...index > 0 ? {
|
|
941
|
+
metadata: {
|
|
942
|
+
source: WALLET_RECEIVE_SOURCE,
|
|
943
|
+
signingDescriptor: descriptor
|
|
944
|
+
}
|
|
945
|
+
} : {}
|
|
946
|
+
}
|
|
947
|
+
];
|
|
844
948
|
}
|
|
845
949
|
};
|
|
846
950
|
|
|
@@ -851,6 +955,7 @@ contractHandlers.register(VHTLCContractHandler);
|
|
|
851
955
|
contractHandlers.register(BoardingContractHandler);
|
|
852
956
|
|
|
853
957
|
exports.BoardingContractHandler = BoardingContractHandler;
|
|
958
|
+
exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
|
|
854
959
|
exports.DefaultContractHandler = DefaultContractHandler;
|
|
855
960
|
exports.DelegateContractHandler = DelegateContractHandler;
|
|
856
961
|
exports.VHTLCContractHandler = VHTLCContractHandler;
|
|
@@ -861,5 +966,5 @@ exports.descriptorIsOurs = descriptorIsOurs;
|
|
|
861
966
|
exports.isCltvSatisfied = isCltvSatisfied;
|
|
862
967
|
exports.isCsvSpendable = isCsvSpendable;
|
|
863
968
|
exports.isMainnetDescriptor = isMainnetDescriptor;
|
|
864
|
-
//# sourceMappingURL=chunk-
|
|
865
|
-
//# sourceMappingURL=chunk-
|
|
969
|
+
//# sourceMappingURL=chunk-GUTKJMSF.cjs.map
|
|
970
|
+
//# sourceMappingURL=chunk-GUTKJMSF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contracts/handlers/registry.ts","../src/script/default.ts","../src/identity/descriptor.ts","../src/contracts/constants.ts","../src/contracts/handlers/helpers.ts","../src/contracts/metadata.ts","../src/contracts/handlers/default.ts","../src/script/delegate.ts","../src/contracts/handlers/delegate.ts","../src/script/vhtlc.ts","../src/contracts/handlers/vhtlc.ts","../src/contracts/handlers/boarding.ts","../src/contracts/handlers/index.ts"],"names":["DefaultVtxo","Script","VtxoScript","MultisigTapscript","CSVMultisigTapscript","hex","expand","networks","sequenceToTimelock","timelockToSequence","DelegateVtxo","VHTLC","ConditionMultisigTapscript","CLTVMultisigTapscript","ConditionCSVMultisigTapscript"],"mappings":";;;;;;;;AAkBA,IAAM,0BAAN,MAA8B;AAAA,EAClB,QAAA,uBAAe,GAAA,EAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7D,SAAS,OAAA,EAAyC;AAC9C,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAA,CAAQ,IAAI,CAAA,EAAG;AACjC,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,2BAAA,EAA8B,OAAA,CAAQ,IAAI,CAAA,uBAAA,CAAyB,CAAA;AAAA,IACvF;AACA,IAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IAAI,IAAA,EAAoD;AACpD,IAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,IAAI,CAAA;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW,IAAA,EAAwC;AAC/C,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA;AAC7B,IAAA,IAAI,CAAC,OAAA,EAAS;AACV,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,yCAAA,EAA4C,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,IACvE;AACA,IAAA,OAAO,OAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,CAAK,eAAA,CAAgB,SAAS,cAAc,CAAA;AAChE,IAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,EAAC;AAEhC,IAAA,MAAM,SAAA,GAAYK,QAAAA,CAAI,MAAA,CAAO,MAAA,CAAO,QAAQ,CAAA;AAC5C,IAAA,MAAM,WAAA,GAAcI,oCAAA,CAAmB,IAAA,CAAK,gBAAgB,CAAA;AAQ5D,IAAA,OAAO;AAAA,MACH;AAAA,QACI,IAAA,EAAM,UAAA;AAAA,QACN,MAAA,EAAQ;AAAA,UACJ,MAAA,EAAQJ,QAAAA,CAAI,MAAA,CAAO,MAAM,CAAA;AAAA,UACzB,YAAA,EAAcA,QAAAA,CAAI,MAAA,CAAO,IAAA,CAAK,YAAY,CAAA;AAAA,UAC1C,WAAA,EAAa,YAAY,QAAA;AAAS,SACtC;AAAA,QACA,MAAA,EAAQ,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAMR,OAAA,EAAS,OAAO,OAAA,CAAQ,IAAA,CAAK,QAAQ,GAAA,EAAK,IAAA,CAAK,YAAY,CAAA,CAAE,MAAA,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA,QAKpE,GAAI,QAAQ,CAAA,GACN;AAAA,UACI,QAAA,EAAU;AAAA,YACN,MAAA,EAAQ,qBAAA;AAAA,YACR,iBAAA,EAAmB;AAAA;AACvB,YAEJ;AAAC;AACX,KACJ;AAAA,EACJ;AACJ;;;ACxKA,gBAAA,CAAiB,SAAS,sBAAsB,CAAA;AAChD,gBAAA,CAAiB,SAAS,uBAAuB,CAAA;AACjD,gBAAA,CAAiB,SAAS,oBAAoB,CAAA;AAC9C,gBAAA,CAAiB,SAAS,uBAAuB,CAAA","file":"chunk-GUTKJMSF.cjs","sourcesContent":["import { ContractHandler } from \"../types\";\n\n/**\n * Registry for contract handlers.\n *\n * Each contract type (\"default\", \"vhtlc\", etc.) has a handler that knows\n * how to create VtxoScripts, serialize params, and select spending paths.\n *\n * @example\n * ```typescript\n * // Register a custom handler\n * contractHandlers.register(myCustomHandler);\n *\n * // Get handler for a type\n * const handler = contractHandlers.get(\"vhtlc\");\n * const script = handler.createScript(contract.params);\n * ```\n */\nclass ContractHandlerRegistry {\n private handlers = new Map<string, ContractHandler<unknown>>();\n\n /**\n * Register a contract handler.\n *\n * @param handler - The handler to register\n * @throws If a handler for this type is already registered\n */\n register(handler: ContractHandler<unknown>): void {\n if (this.handlers.has(handler.type)) {\n throw new Error(`Contract handler for type '${handler.type}' is already registered`);\n }\n this.handlers.set(handler.type, handler);\n }\n\n /**\n * Get a handler by type.\n *\n * @param type - The contract type\n * @returns The handler, or undefined if not found\n */\n get(type: string): ContractHandler<unknown> | undefined {\n return this.handlers.get(type);\n }\n\n /**\n * Get a handler by type, throwing if not found.\n *\n * @param type - The contract type\n * @returns The handler\n * @throws If no handler is registered for this type\n */\n getOrThrow(type: string): ContractHandler<unknown> {\n const handler = this.get(type);\n if (!handler) {\n throw new Error(`No contract handler registered for type '${type}'`);\n }\n return handler;\n }\n\n /**\n * Check if a handler is registered.\n *\n * @param type - The contract type\n */\n has(type: string): boolean {\n return this.handlers.has(type);\n }\n\n /**\n * Get all registered types.\n */\n getRegisteredTypes(): string[] {\n return Array.from(this.handlers.keys());\n }\n\n /**\n * Unregister a handler (mainly for testing).\n */\n unregister(type: string): boolean {\n return this.handlers.delete(type);\n }\n\n /**\n * Clear all handlers (mainly for testing).\n */\n clear(): void {\n this.handlers.clear();\n }\n}\n\n/**\n * Global registry of contract handlers.\n */\nexport const contractHandlers = new ContractHandlerRegistry();\n","import { Bytes } from \"@scure/btc-signer/utils.js\";\nimport { TapLeafScript, VtxoScript } from \"./base\";\nimport { CSVMultisigTapscript, MultisigTapscript, RelativeTimelock } from \"./tapscript\";\nimport { hex } from \"@scure/base\";\n\n/**\n * DefaultVtxo is the default implementation of a VtxoScript.\n * It contains 1 forfeit path and 1 exit path.\n * - forfeit = (Alice + Server)\n * - exit = (Alice) after csvTimelock\n */\nexport namespace DefaultVtxo {\n /**\n * Options is the options for the DefaultVtxo.Script class.\n * csvTimelock is the exit path timelock, default is 144 blocks (1 day).\n */\n export interface Options {\n pubKey: Bytes;\n serverPubKey: Bytes;\n csvTimelock: RelativeTimelock;\n }\n\n /**\n * DefaultVtxo.Script is the class letting to create the vtxo script.\n * @example\n * ```typescript\n * const vtxoScript = new DefaultVtxo.Script({\n * pubKey: new Uint8Array(32),\n * serverPubKey: new Uint8Array(32),\n * csvTimelock: {\n * value: 605184n,\n * type: \"seconds\"\n * }\n * });\n *\n * console.log(\"script pub key:\", vtxoScript.pkScript)\n * ```\n */\n export class Script extends VtxoScript {\n static readonly DEFAULT_TIMELOCK: RelativeTimelock = {\n value: 144n,\n type: \"blocks\",\n }; // 1 day in blocks\n\n readonly forfeitScript: string;\n readonly exitScript: string;\n\n /** Create the default virtual output script with one forfeit path and one exit path. */\n constructor(readonly options: Options) {\n const { pubKey, serverPubKey, csvTimelock } = options;\n\n const forfeitScript = MultisigTapscript.encode({\n pubkeys: [pubKey, serverPubKey],\n }).script;\n\n const exitScript = CSVMultisigTapscript.encode({\n timelock: csvTimelock,\n pubkeys: [pubKey],\n }).script;\n\n super([forfeitScript, exitScript]);\n\n this.forfeitScript = hex.encode(forfeitScript);\n this.exitScript = hex.encode(exitScript);\n }\n\n /** Return the forfeit tapleaf script. */\n forfeit(): TapLeafScript {\n return this.findLeaf(this.forfeitScript);\n }\n\n /** Return the unilateral exit tapleaf script. */\n exit(): TapLeafScript {\n return this.findLeaf(this.exitScript);\n }\n }\n}\n","import { expand, networks } from \"@bitcoinerlab/descriptors-scure\";\nimport { hex } from \"@scure/base\";\n\n/**\n * True iff `descriptor` is a Bitcoin mainnet descriptor (xpub-prefixed\n * BIP32 key).\n *\n * Note: testnet, signet, regtest, mutinynet, and other non-mainnet\n * networks all share the same `tpub` BIP32 version bytes — they cannot\n * be distinguished from one another at the descriptor level. Callers\n * that need a `Network` constants object for `expand()` pick\n * `networks.bitcoin` vs `networks.testnet` themselves; callers that\n * need the *actual* network the wallet is on must track that\n * out-of-band.\n */\nexport function isMainnetDescriptor(descriptor: string): boolean {\n return !descriptor.includes(\"tpub\");\n}\n\n/**\n * Shared \"does `candidate` belong to the identity backed by\n * `ourDescriptor`?\" predicate.\n *\n * - HD descriptors (expanding to a `bip32` key) match by account xpub\n * on both sides — index-agnostic, so a wildcard template and any\n * concrete index under it all collapse to the same xpub.\n * - Bare `tr(pubkey)` candidates fall back to comparing the candidate\n * pubkey against `ourXOnlyPubkey` (the cached pubkey on the identity\n * side, since pulling it from `ourDescriptor` would require an index\n * substitution the caller already performed).\n */\nexport function descriptorIsOurs(\n candidate: string,\n ourDescriptor: string,\n ourXOnlyPubkey: Uint8Array,\n): boolean {\n if (!isDescriptor(candidate)) return false;\n try {\n const candidateInfo = expand({\n descriptor: candidate,\n network: isMainnetDescriptor(candidate) ? networks.bitcoin : networks.testnet,\n }).expansionMap?.[\"@0\"];\n if (!candidateInfo) return false;\n\n if (candidateInfo.bip32) {\n const ourBip32 = expand({\n descriptor: ourDescriptor,\n network: isMainnetDescriptor(ourDescriptor) ? networks.bitcoin : networks.testnet,\n }).expansionMap?.[\"@0\"]?.bip32;\n if (!ourBip32) return false;\n return ourBip32.toBase58() === candidateInfo.bip32.toBase58();\n }\n if (candidateInfo.pubkey) {\n // For tr() the library hands back a 32-byte x-only key, but\n // strip a leading parity byte defensively so a 33-byte\n // compressed key (mismatched length) doesn't silently\n // false-negative against our 32-byte x-only side.\n const candidatePub =\n candidateInfo.pubkey.length === 33\n ? candidateInfo.pubkey.subarray(1)\n : candidateInfo.pubkey;\n if (candidatePub.length !== ourXOnlyPubkey.length) return false;\n return hex.encode(candidatePub) === hex.encode(ourXOnlyPubkey);\n }\n return false;\n } catch {\n return false;\n }\n}\n\n/**\n * Check if a string is a descriptor of the shape `tr(...)`.\n *\n * This is a shape check only — it does not validate the inner key material.\n * Use {@link expand} (via {@link extractPubKey} / {@link parseHDDescriptor})\n * for full parsing. The guard rejects empty bodies and missing/trailing\n * parentheses so callers can safely branch on descriptor vs. raw pubkey.\n */\nexport function isDescriptor(value: string): boolean {\n if (typeof value !== \"string\") return false;\n if (!value.startsWith(\"tr(\") || !value.endsWith(\")\")) return false;\n // body length > 0 after stripping \"tr(\" and \")\"\n return value.length > \"tr()\".length;\n}\n\n/**\n * Normalize a value to descriptor format.\n * If already a descriptor, return as-is. If hex pubkey, wrap as tr(pubkey).\n * Throws when the value is empty or not a string so we never produce\n * malformed descriptors like `tr()` that downstream parsers would reject.\n */\nexport function normalizeToDescriptor(value: string): string {\n if (typeof value !== \"string\" || value.length === 0) {\n throw new Error(\"normalizeToDescriptor: expected a non-empty string value\");\n }\n if (isDescriptor(value)) {\n return value;\n }\n return `tr(${value})`;\n}\n\n/**\n * Extract the public key from a simple descriptor.\n * For simple descriptors (tr(pubkey)), extracts the pubkey using the library.\n * For HD descriptors, throws — use DescriptorProvider to derive the key.\n */\nexport function extractPubKey(descriptor: string): string {\n if (!isDescriptor(descriptor)) {\n return descriptor;\n }\n\n const network = isMainnetDescriptor(descriptor) ? networks.bitcoin : networks.testnet;\n const expansion = expand({ descriptor, network });\n\n if (!expansion.expansionMap) {\n throw new Error(\"Cannot extract pubkey from descriptor: expansion failed.\");\n }\n\n const key = expansion.expansionMap[\"@0\"];\n\n // HD descriptors (have a bip32 key) require DescriptorProvider for derivation\n if (key?.bip32) {\n throw new Error(\n \"Cannot extract pubkey from HD descriptor without derivation. \" +\n \"Use DescriptorProvider to derive the key from the xpub.\",\n );\n }\n\n if (!key?.pubkey) {\n throw new Error(\"Cannot extract pubkey from descriptor: no key found.\");\n }\n\n return hex.encode(key.pubkey);\n}\n\n/**\n * Extract the x-only (32-byte) pubkey from a materialized descriptor.\n * Handles both static `tr(pubkey)` and materialized HD\n * `tr([fp/..]xpub/0/<i>)` shapes via the descriptors-scure expansion map.\n * Throws a plain Error when the descriptor is non-rangeable / unparseable;\n * callers that need a typed error wrap this.\n */\nexport function deriveDescriptorLeafPubKey(descriptor: string): Uint8Array {\n const network = isMainnetDescriptor(descriptor) ? networks.bitcoin : networks.testnet;\n let expansion;\n try {\n expansion = expand({ descriptor, network });\n } catch (e) {\n throw new Error(\n `Cannot derive leaf pubkey from descriptor (length=${descriptor.length}): ` +\n `ensure it is materialized (no wildcard) and parsable.`,\n { cause: e },\n );\n }\n const key = expansion.expansionMap?.[\"@0\"];\n if (!key?.pubkey) {\n throw new Error(\n `Cannot derive leaf pubkey from descriptor (length=${descriptor.length}): ` +\n `parsed but no '@0' pubkey in the expansion map.`,\n );\n }\n return key.pubkey;\n}\n\n/** Parsed HD descriptor components. */\nexport interface ParsedHDDescriptor {\n fingerprint: string;\n basePath: string;\n xpub: string;\n derivationPath: string;\n}\n\n/**\n * Parse an HD descriptor into its components.\n * HD descriptors have the format: tr([fingerprint/path']xpub/derivation)\n * Returns null if the descriptor is not in HD format.\n */\nexport function parseHDDescriptor(descriptor: string): ParsedHDDescriptor | null {\n if (!isDescriptor(descriptor)) {\n return null;\n }\n\n let expansion;\n try {\n const network = isMainnetDescriptor(descriptor) ? networks.bitcoin : networks.testnet;\n expansion = expand({ descriptor, network });\n } catch {\n return null;\n }\n\n const key = expansion.expansionMap?.[\"@0\"];\n if (!key?.masterFingerprint || !key.originPath || !key.keyPath || !key.bip32) {\n return null;\n }\n\n return {\n fingerprint: hex.encode(key.masterFingerprint),\n basePath: key.originPath.replace(/^\\//, \"\"),\n xpub: key.bip32.toBase58(),\n derivationPath: key.keyPath.replace(/^\\//, \"\"),\n };\n}\n","/**\n * Default indexer pagination size for batched VTXO queries (`getVtxos`).\n *\n * Shared by {@link ContractManager}'s bulk history sync and the discovery\n * handlers' batched `detectUsedScripts` probe so the two can't drift. It lives\n * in its own leaf module (importing nothing) so both the manager and the\n * handler layer can use it without a `handlers → contractManager` import cycle —\n * contractManager imports the handler registry, so the handlers must not import\n * back from contractManager.\n *\n * Large enough that a single wallet index's candidate scripts resolve in one\n * page in the common case.\n */\nexport const DEFAULT_PAGE_SIZE = 500;\n","import { sequenceToTimelock } from \"../../utils/timelock\";\nimport { Contract, PathContext } from \"../types\";\nimport { isDescriptor, extractPubKey } from \"../../identity/descriptor\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport { DEFAULT_PAGE_SIZE } from \"../constants\";\n\n/**\n * Extract raw hex pubkey from a value that may be a descriptor or raw hex.\n * Returns undefined for HD descriptors or unparseable values so role\n * resolution stays best-effort and never throws.\n */\nfunction extractRawPubKey(value: string): string | undefined {\n if (!isDescriptor(value)) {\n return value.toLowerCase();\n }\n try {\n return extractPubKey(value).toLowerCase();\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve wallet's role from explicit role or by matching descriptor/pubkey.\n */\nexport function resolveRole(\n contract: Contract,\n context: PathContext,\n): \"sender\" | \"receiver\" | undefined {\n // Explicit role takes precedence\n if (context.role === \"sender\" || context.role === \"receiver\") {\n return context.role;\n }\n\n const senderKey = contract.params.sender ? extractRawPubKey(contract.params.sender) : undefined;\n const receiverKey = contract.params.receiver\n ? extractRawPubKey(contract.params.receiver)\n : undefined;\n\n const matchRole = (rawWalletKey: string | undefined): \"sender\" | \"receiver\" | undefined => {\n if (!rawWalletKey) return undefined;\n if (senderKey && rawWalletKey === senderKey) {\n return \"sender\";\n }\n if (receiverKey && rawWalletKey === receiverKey) {\n return \"receiver\";\n }\n return undefined;\n };\n\n // Try the preferred descriptor first. If it cannot be resolved\n // (for example an HD descriptor without derivation support), fall back\n // to walletPubKey for backward compatibility.\n if (context.walletDescriptor) {\n const walletDescriptorKey = extractRawPubKey(context.walletDescriptor);\n const matchedRole = matchRole(walletDescriptorKey);\n if (matchedRole) {\n return matchedRole;\n }\n\n if (!walletDescriptorKey && context.walletPubKey) {\n return matchRole(extractRawPubKey(context.walletPubKey));\n }\n return undefined;\n }\n\n if (context.walletPubKey) {\n return matchRole(extractRawPubKey(context.walletPubKey));\n }\n\n return undefined;\n}\n\n/**\n * BIP65 threshold: locktime values below this are interpreted as block heights,\n * values at or above are interpreted as Unix timestamps (seconds).\n */\nconst CLTV_HEIGHT_THRESHOLD = 500_000_000n;\n\n/**\n * Check if an absolute (CLTV) locktime is currently satisfied.\n *\n * Following the BIP65 convention:\n * - locktime < 500_000_000 → interpreted as a block height; compared against `context.blockHeight`\n * - locktime >= 500_000_000 → interpreted as a Unix timestamp (seconds); compared against `context.currentTime`\n *\n * Returns false if the relevant context field is missing.\n */\nexport function isCltvSatisfied(context: PathContext, locktime: bigint): boolean {\n if (locktime < CLTV_HEIGHT_THRESHOLD) {\n if (context.blockHeight === undefined) return false;\n return BigInt(context.blockHeight) >= locktime;\n }\n const currentTimeSec = BigInt(Math.floor(context.currentTime / 1000));\n return currentTimeSec >= locktime;\n}\n\n/**\n * Check if a CSV timelock is currently satisfied for the given context/virtual output.\n */\nexport function isCsvSpendable(context: PathContext, sequence?: number): boolean {\n if (sequence === undefined) return true;\n if (!context.vtxo) return false;\n const timelock = sequenceToTimelock(sequence);\n\n if (timelock.type === \"blocks\") {\n if (context.blockHeight === undefined || context.vtxo.status.block_height === undefined) {\n return false;\n }\n return context.blockHeight - context.vtxo.status.block_height >= Number(timelock.value);\n }\n\n if (timelock.type === \"seconds\") {\n const blockTime = context.vtxo.status.block_time;\n if (blockTime === undefined) return false;\n return context.currentTime / 1000 - blockTime >= Number(timelock.value);\n }\n\n return false;\n}\n\n/**\n * Batched discovery probe for a single wallet index: given the candidate\n * pkScripts a `discoverAt` built (the signer × CSV-timelock cross-product,\n * already deduped), return the subset the indexer has at least one VTXO for —\n * in any state, since restore counts a spent-but-used script as activity.\n *\n * Collapses what used to be one `getVtxos` call per candidate script into a\n * single call per page, the same batching shape as\n * {@link ContractManager.fetchContractVtxosBulk}: the indexer reports each\n * returned VTXO's `script`, which is matched back to the candidate set. It\n * pages only as far as needed to observe every candidate (stopping early once\n * all are seen), and otherwise to the end of history, so the discovered set is\n * identical to the prior per-script path — a heavily-reused candidate cannot\n * starve another candidate off the first page.\n */\nexport async function detectUsedScripts(\n indexerProvider: IndexerProvider,\n scriptHexes: string[],\n): Promise<Set<string>> {\n const used = new Set<string>();\n if (scriptHexes.length === 0) return used;\n\n // `scripts` stays the full candidate set across pages so the indexer's\n // pagination is consistent; `remaining` only drives the early stop.\n const remaining = new Set(scriptHexes);\n let pageIndex = 0;\n let hasMore = true;\n while (hasMore && remaining.size > 0) {\n const { vtxos, page } = await indexerProvider.getVtxos({\n scripts: scriptHexes,\n pageIndex,\n pageSize: DEFAULT_PAGE_SIZE,\n });\n for (const vtxo of vtxos) {\n if (remaining.delete(vtxo.script)) used.add(vtxo.script);\n }\n // Same end-of-history heuristic as fetchContractVtxosBulk: a short page\n // (or absent page metadata) means there is nothing left to fetch.\n hasMore = page ? vtxos.length === DEFAULT_PAGE_SIZE : false;\n pageIndex++;\n }\n return used;\n}\n","/**\n * Sentinel stored in `contract.metadata.source` to mark a contract the\n * wallet generated for its own rotating receive address. Lives here (the\n * contracts layer) so contract handlers can tag/discover without importing\n * the wallet module. Re-exported from `wallet/walletReceiveRotator` for\n * backward compatibility of existing import paths.\n *\n * Tagging makes the boot lookup unambiguous — the rotator filters on\n * `metadata.source === WALLET_RECEIVE_SOURCE` rather than on \"any active\n * default contract\", so a contract repo that also holds default contracts\n * created for other reasons (legacy timelock variants, external\n * integrations) doesn't confuse the wallet's display state.\n */\nexport const WALLET_RECEIVE_SOURCE = \"wallet-receive\";\n","import { hex } from \"@scure/base\";\nimport { DefaultVtxo } from \"../../script/default\";\nimport { RelativeTimelock } from \"../../script/tapscript\";\nimport { Contract, ContractHandler, Discoverable, PathContext, PathSelection } from \"../types\";\nimport type { DiscoveredContract, DiscoveryDeps } from \"../types\";\nimport { isCsvSpendable, detectUsedScripts } from \"./helpers\";\nimport { sequenceToTimelock, timelockToSequence } from \"../../utils/timelock\";\nimport {\n normalizeToDescriptor,\n extractPubKey,\n deriveDescriptorLeafPubKey,\n} from \"../../identity/descriptor\";\nimport { WALLET_RECEIVE_SOURCE } from \"../metadata\";\n\n/**\n * Typed parameters for DefaultVtxo contracts.\n */\nexport interface DefaultContractParams {\n pubKey: Uint8Array;\n serverPubKey: Uint8Array;\n csvTimelock: RelativeTimelock;\n}\n\n/**\n * Extract pubkey bytes from a descriptor or hex string.\n */\nfunction extractPubKeyBytes(value: string): Uint8Array {\n return hex.decode(extractPubKey(normalizeToDescriptor(value)));\n}\n\n/**\n * Handler for default wallet VTXOs.\n *\n * Default contracts use the standard forfeit + exit tapscript:\n * - forfeit: (Alice + Server) multisig for collaborative spending\n * - exit: (Alice) + CSV timelock for unilateral exit\n */\nexport const DefaultContractHandler: ContractHandler<DefaultContractParams, DefaultVtxo.Script> &\n Discoverable = {\n type: \"default\",\n\n createScript(params: Record<string, string>): DefaultVtxo.Script {\n const typed = this.deserializeParams(params);\n return new DefaultVtxo.Script(typed);\n },\n\n serializeParams(params: DefaultContractParams): Record<string, string> {\n return {\n pubKey: hex.encode(params.pubKey),\n serverPubKey: hex.encode(params.serverPubKey),\n csvTimelock: timelockToSequence(params.csvTimelock).toString(),\n };\n },\n\n deserializeParams(params: Record<string, string>): DefaultContractParams {\n // csvTimelock may be absent on legacy/minimal params (e.g. hex pubkeys\n // with no timelock). DefaultVtxo.Script no longer applies its own\n // fallback, so restore it here rather than feeding sequenceToTimelock\n // a NaN (which silently decodes to a zero timelock).\n const csvTimelock =\n params.csvTimelock !== undefined && params.csvTimelock !== \"\"\n ? sequenceToTimelock(Number(params.csvTimelock))\n : DefaultVtxo.Script.DEFAULT_TIMELOCK;\n return {\n pubKey: extractPubKeyBytes(params.pubKey),\n serverPubKey: extractPubKeyBytes(params.serverPubKey),\n csvTimelock,\n };\n },\n\n selectPath(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection | null {\n if (context.collaborative) {\n // Use forfeit path for collaborative spending\n return { leaf: script.forfeit() };\n }\n\n // Use exit path for unilateral exit (only if CSV is satisfied)\n const sequence = contract.params.csvTimelock\n ? Number(contract.params.csvTimelock)\n : undefined;\n if (!isCsvSpendable(context, sequence)) {\n return null;\n }\n return {\n leaf: script.exit(),\n sequence,\n };\n },\n\n getAllSpendingPaths(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const paths: PathSelection[] = [];\n\n // Forfeit path available with server cooperation\n if (context.collaborative) {\n paths.push({ leaf: script.forfeit() });\n }\n\n // Exit path always possible (CSV checked at tx time)\n const exitPath: PathSelection = { leaf: script.exit() };\n if (contract.params.csvTimelock) {\n exitPath.sequence = Number(contract.params.csvTimelock);\n }\n paths.push(exitPath);\n\n return paths;\n },\n\n getSpendablePaths(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const paths: PathSelection[] = [];\n\n if (context.collaborative) {\n paths.push({ leaf: script.forfeit() });\n }\n\n const exitSequence = contract.params.csvTimelock\n ? Number(contract.params.csvTimelock)\n : undefined;\n\n if (isCsvSpendable(context, exitSequence)) {\n const exitPath: PathSelection = { leaf: script.exit() };\n if (exitSequence !== undefined) {\n exitPath.sequence = exitSequence;\n }\n paths.push(exitPath);\n }\n\n return paths;\n },\n\n async discoverAt(\n index: number,\n descriptor: string,\n deps: DiscoveryDeps,\n ): Promise<DiscoveredContract[]> {\n const pubKey = deriveDescriptorLeafPubKey(descriptor);\n // Build the candidate set for this wallet index: the current signer\n // first, then any deprecated signers (so a VTXO minted under a\n // now-rotated server key is still discovered), each crossed with the\n // CSV-timelock matrix. Dedup by scriptHex — a deprecated signer that\n // produced no rotation yields the same scripts as the current key, so\n // it must neither be probed nor emitted twice; the current signer wins\n // the attribution.\n const signers = [deps.serverPubKey, ...(deps.deprecatedSignerPubKeys ?? [])];\n const seen = new Set<string>();\n const candidates: {\n serverPubKey: Uint8Array;\n csvTimelock: RelativeTimelock;\n script: DefaultVtxo.Script;\n scriptHex: string;\n }[] = [];\n for (const serverPubKey of signers) {\n for (const csvTimelock of deps.csvTimelocks) {\n const script = new DefaultVtxo.Script({\n pubKey,\n serverPubKey,\n csvTimelock,\n });\n const scriptHex = hex.encode(script.pkScript);\n if (seen.has(scriptHex)) continue;\n seen.add(scriptHex);\n candidates.push({ serverPubKey, csvTimelock, script, scriptHex });\n }\n }\n\n // One batched indexer query over every candidate, instead of one call\n // per (signer × CSV) variant.\n const used = await detectUsedScripts(\n deps.indexerProvider,\n candidates.map((c) => c.scriptHex),\n );\n\n const out: DiscoveredContract[] = [];\n for (const c of candidates) {\n if (!used.has(c.scriptHex)) continue;\n // The matched signer is threaded through the script (already built),\n // the persisted params, and the encoded address so signing/forfeit\n // later resolves the right key.\n out.push({\n type: \"default\",\n params: {\n pubKey: hex.encode(pubKey),\n serverPubKey: hex.encode(c.serverPubKey),\n csvTimelock: timelockToSequence(c.csvTimelock).toString(),\n },\n script: c.scriptHex,\n address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),\n ...(index > 0\n ? {\n metadata: {\n source: WALLET_RECEIVE_SOURCE,\n signingDescriptor: descriptor,\n },\n }\n : {}),\n });\n }\n return out;\n },\n};\n","import { Bytes } from \"@scure/btc-signer/utils.js\";\nimport { DefaultVtxo } from \"./default\";\nimport { MultisigTapscript } from \"./tapscript\";\nimport { TapLeafScript, VtxoScript } from \"./base\";\nimport { hex } from \"@scure/base\";\n\n/**\n * DelegateVtxo extends DefaultVtxo with an extra delegate path\n */\nexport namespace DelegateVtxo {\n /**\n * Options extends DefaultVtxo.Options and adds a delegatePubKey\n */\n export interface Options extends DefaultVtxo.Options {\n delegatePubKey: Bytes;\n }\n\n /**\n * DelegateVtxo.Script extends DefaultVtxo.Script and adds a delegate path.\n * @example\n * ```typescript\n * const vtxoScript = new DelegateVtxo.Script({\n * pubKey: new Uint8Array(32),\n * serverPubKey: new Uint8Array(32),\n * delegatePubKey: new Uint8Array(32),\n * csvTimelock: {\n * value: 605184n,\n * type: \"seconds\"\n * }\n * });\n *\n * console.log(\"script pub key:\", vtxoScript.pkScript)\n * ```\n */\n export class Script extends VtxoScript {\n readonly defaultVtxo: DefaultVtxo.Script;\n readonly delegateScript: string;\n\n /** Create a delegated virtual output script with forfeit, exit, and delegate paths. */\n constructor(readonly options: Options) {\n const defaultVtxo = new DefaultVtxo.Script(options);\n const { delegatePubKey, pubKey, serverPubKey } = options;\n const delegateScript = MultisigTapscript.encode({\n pubkeys: [pubKey, delegatePubKey, serverPubKey],\n }).script;\n\n super([...defaultVtxo.scripts, delegateScript]);\n\n this.defaultVtxo = defaultVtxo;\n this.delegateScript = hex.encode(delegateScript);\n }\n\n /** Return the forfeit tapleaf script. */\n forfeit(): TapLeafScript {\n return this.findLeaf(this.defaultVtxo.forfeitScript);\n }\n\n /** Return the unilateral exit tapleaf script. */\n exit(): TapLeafScript {\n return this.findLeaf(this.defaultVtxo.exitScript);\n }\n\n /** Return the delegate tapleaf script. */\n delegate(): TapLeafScript {\n return this.findLeaf(this.delegateScript);\n }\n }\n}\n","import { hex } from \"@scure/base\";\nimport { DelegateVtxo } from \"../../script/delegate\";\nimport { RelativeTimelock } from \"../../script/tapscript\";\nimport { Contract, ContractHandler, Discoverable, PathContext, PathSelection } from \"../types\";\nimport type { DiscoveredContract, DiscoveryDeps } from \"../types\";\nimport { isCsvSpendable, detectUsedScripts } from \"./helpers\";\nimport { sequenceToTimelock, timelockToSequence } from \"../../utils/timelock\";\nimport { deriveDescriptorLeafPubKey } from \"../../identity/descriptor\";\nimport { WALLET_RECEIVE_SOURCE } from \"../metadata\";\n\n/**\n * Typed parameters for DelegateVtxo contracts.\n */\nexport interface DelegateContractParams {\n pubKey: Uint8Array;\n serverPubKey: Uint8Array;\n delegatePubKey: Uint8Array;\n csvTimelock: RelativeTimelock;\n}\n\n/**\n * Handler for delegate wallet virtual outputs.\n *\n * Delegate contracts extend the default tapscript with an additional delegate path:\n * - forfeit: (Alice + Server) multisig for collaborative spending\n * - exit: (Alice) + CSV timelock for unilateral exit\n * - delegate: (Alice + Delegate + Server) multisig for delegated renewal\n */\nexport const DelegateContractHandler: ContractHandler<DelegateContractParams, DelegateVtxo.Script> &\n Discoverable = {\n type: \"delegate\",\n\n createScript(params: Record<string, string>): DelegateVtxo.Script {\n const typed = this.deserializeParams(params);\n return new DelegateVtxo.Script(typed);\n },\n\n serializeParams(params: DelegateContractParams): Record<string, string> {\n return {\n pubKey: hex.encode(params.pubKey),\n serverPubKey: hex.encode(params.serverPubKey),\n delegatePubKey: hex.encode(params.delegatePubKey),\n csvTimelock: timelockToSequence(params.csvTimelock).toString(),\n };\n },\n\n deserializeParams(params: Record<string, string>): DelegateContractParams {\n const csvTimelock = sequenceToTimelock(Number(params.csvTimelock));\n return {\n pubKey: hex.decode(params.pubKey),\n serverPubKey: hex.decode(params.serverPubKey),\n delegatePubKey: hex.decode(params.delegatePubKey),\n csvTimelock,\n };\n },\n\n selectPath(\n script: DelegateVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection | null {\n if (context.collaborative) {\n return { leaf: script.forfeit() };\n }\n\n const sequence = contract.params.csvTimelock\n ? Number(contract.params.csvTimelock)\n : undefined;\n if (!isCsvSpendable(context, sequence)) {\n return null;\n }\n return {\n leaf: script.exit(),\n sequence,\n };\n },\n\n getAllSpendingPaths(\n script: DelegateVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const paths: PathSelection[] = [];\n\n if (context.collaborative) {\n paths.push({ leaf: script.forfeit() });\n }\n\n const exitPath: PathSelection = { leaf: script.exit() };\n if (contract.params.csvTimelock) {\n exitPath.sequence = Number(contract.params.csvTimelock);\n }\n paths.push(exitPath);\n\n // Delegate path (Alice + Delegate + Server) — collaborative only\n if (context.collaborative) {\n paths.push({ leaf: script.delegate() });\n }\n\n return paths;\n },\n\n getSpendablePaths(\n script: DelegateVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const paths: PathSelection[] = [];\n\n if (context.collaborative) {\n paths.push({ leaf: script.forfeit() });\n }\n\n const exitSequence = contract.params.csvTimelock\n ? Number(contract.params.csvTimelock)\n : undefined;\n\n if (isCsvSpendable(context, exitSequence)) {\n const exitPath: PathSelection = { leaf: script.exit() };\n if (exitSequence !== undefined) {\n exitPath.sequence = exitSequence;\n }\n paths.push(exitPath);\n }\n\n return paths;\n },\n\n async discoverAt(\n index: number,\n descriptor: string,\n deps: DiscoveryDeps,\n ): Promise<DiscoveredContract[]> {\n if (!deps.delegatePubKey) return [];\n const pubKey = deriveDescriptorLeafPubKey(descriptor);\n // Build the candidate set: current signer first, then any deprecated\n // signers, each crossed with the CSV-timelock matrix (see\n // DefaultContractHandler.discoverAt for the rationale). Dedup by\n // scriptHex so a non-rotating signer is neither probed nor emitted\n // twice; the current signer wins the attribution.\n const signers = [deps.serverPubKey, ...(deps.deprecatedSignerPubKeys ?? [])];\n const seen = new Set<string>();\n const candidates: {\n serverPubKey: Uint8Array;\n csvTimelock: RelativeTimelock;\n script: DelegateVtxo.Script;\n scriptHex: string;\n }[] = [];\n for (const serverPubKey of signers) {\n for (const csvTimelock of deps.csvTimelocks) {\n const script = new DelegateVtxo.Script({\n pubKey,\n serverPubKey,\n delegatePubKey: deps.delegatePubKey,\n csvTimelock,\n });\n const scriptHex = hex.encode(script.pkScript);\n if (seen.has(scriptHex)) continue;\n seen.add(scriptHex);\n candidates.push({ serverPubKey, csvTimelock, script, scriptHex });\n }\n }\n\n // One batched indexer query over every candidate, instead of one call\n // per (signer × CSV) variant.\n const used = await detectUsedScripts(\n deps.indexerProvider,\n candidates.map((c) => c.scriptHex),\n );\n\n const out: DiscoveredContract[] = [];\n for (const c of candidates) {\n if (!used.has(c.scriptHex)) continue;\n // The matched signer is threaded through script, params, and\n // address so signing/forfeit later resolves the right key.\n out.push({\n type: \"delegate\",\n params: {\n pubKey: hex.encode(pubKey),\n serverPubKey: hex.encode(c.serverPubKey),\n delegatePubKey: hex.encode(deps.delegatePubKey),\n csvTimelock: timelockToSequence(c.csvTimelock).toString(),\n },\n script: c.scriptHex,\n address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),\n ...(index > 0\n ? {\n metadata: {\n source: WALLET_RECEIVE_SOURCE,\n signingDescriptor: descriptor,\n },\n }\n : {}),\n });\n }\n return out;\n },\n};\n","import { Script } from \"@scure/btc-signer\";\nimport { Bytes } from \"@scure/btc-signer/utils.js\";\nimport {\n CLTVMultisigTapscript,\n ConditionCSVMultisigTapscript,\n ConditionMultisigTapscript,\n CSVMultisigTapscript,\n MultisigTapscript,\n RelativeTimelock,\n} from \"./tapscript\";\nimport { hex } from \"@scure/base\";\nimport { TapLeafScript, VtxoScript } from \"./base\";\n\n/** Virtual Hash Time Lock Contract (VHTLC) namespace. */\nexport namespace VHTLC {\n export interface Options {\n sender: Bytes;\n receiver: Bytes;\n server: Bytes;\n preimageHash: Bytes;\n refundLocktime: bigint;\n unilateralClaimDelay: RelativeTimelock;\n unilateralRefundDelay: RelativeTimelock;\n unilateralRefundWithoutReceiverDelay: RelativeTimelock;\n }\n\n /**\n * Virtual Hash Time Lock Contract (VHTLC) script implementation.\n *\n * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.\n * It provides multiple spending paths:\n *\n * - **claim**: Receiver can claim funds by revealing the preimage\n * - **refund**: Sender and receiver can collaboratively refund\n * - **refundWithoutReceiver**: Sender can refund after locktime expires\n * - **unilateralClaim**: Receiver can claim unilaterally after delay\n * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay\n * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay\n *\n * @example\n * ```typescript\n * const vhtlc = new VHTLC.Script({\n * sender: alicePubKey,\n * receiver: bobPubKey,\n * server: serverPubKey,\n * preimageHash: hash160(secret),\n * refundLocktime: BigInt(chainTip + 10),\n * unilateralClaimDelay: { type: 'blocks', value: 100n },\n * unilateralRefundDelay: { type: 'blocks', value: 102n },\n * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }\n * });\n * ```\n */\n export class Script extends VtxoScript {\n readonly claimScript: string;\n readonly refundScript: string;\n readonly refundWithoutReceiverScript: string;\n readonly unilateralClaimScript: string;\n readonly unilateralRefundScript: string;\n readonly unilateralRefundWithoutReceiverScript: string;\n\n /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */\n constructor(readonly options: Options) {\n validateOptions(options);\n\n const {\n sender,\n receiver,\n server,\n preimageHash,\n refundLocktime,\n unilateralClaimDelay,\n unilateralRefundDelay,\n unilateralRefundWithoutReceiverDelay,\n } = options;\n\n const conditionScript = preimageConditionScript(preimageHash);\n\n const claimScript = ConditionMultisigTapscript.encode({\n conditionScript,\n pubkeys: [receiver, server],\n }).script;\n\n const refundScript = MultisigTapscript.encode({\n pubkeys: [sender, receiver, server],\n }).script;\n\n const refundWithoutReceiverScript = CLTVMultisigTapscript.encode({\n absoluteTimelock: refundLocktime,\n pubkeys: [sender, server],\n }).script;\n\n const unilateralClaimScript = ConditionCSVMultisigTapscript.encode({\n conditionScript,\n timelock: unilateralClaimDelay,\n pubkeys: [receiver],\n }).script;\n\n const unilateralRefundScript = CSVMultisigTapscript.encode({\n timelock: unilateralRefundDelay,\n pubkeys: [sender, receiver],\n }).script;\n\n const unilateralRefundWithoutReceiverScript = CSVMultisigTapscript.encode({\n timelock: unilateralRefundWithoutReceiverDelay,\n pubkeys: [sender],\n }).script;\n\n super([\n claimScript,\n refundScript,\n refundWithoutReceiverScript,\n unilateralClaimScript,\n unilateralRefundScript,\n unilateralRefundWithoutReceiverScript,\n ]);\n\n this.claimScript = hex.encode(claimScript);\n this.refundScript = hex.encode(refundScript);\n this.refundWithoutReceiverScript = hex.encode(refundWithoutReceiverScript);\n this.unilateralClaimScript = hex.encode(unilateralClaimScript);\n this.unilateralRefundScript = hex.encode(unilateralRefundScript);\n this.unilateralRefundWithoutReceiverScript = hex.encode(\n unilateralRefundWithoutReceiverScript,\n );\n }\n\n /** Return the collaborative claim tapleaf script. */\n claim(): TapLeafScript {\n return this.findLeaf(this.claimScript);\n }\n\n /** Return the collaborative refund tapleaf script. */\n refund(): TapLeafScript {\n return this.findLeaf(this.refundScript);\n }\n\n /** Return the refund-without-receiver tapleaf script. */\n refundWithoutReceiver(): TapLeafScript {\n return this.findLeaf(this.refundWithoutReceiverScript);\n }\n\n /** Return the unilateral claim tapleaf script. */\n unilateralClaim(): TapLeafScript {\n return this.findLeaf(this.unilateralClaimScript);\n }\n\n /** Return the unilateral refund tapleaf script. */\n unilateralRefund(): TapLeafScript {\n return this.findLeaf(this.unilateralRefundScript);\n }\n\n /** Return the unilateral refund-without-receiver tapleaf script. */\n unilateralRefundWithoutReceiver(): TapLeafScript {\n return this.findLeaf(this.unilateralRefundWithoutReceiverScript);\n }\n }\n\n function validateOptions(options: Options): void {\n const {\n sender,\n receiver,\n server,\n preimageHash,\n refundLocktime,\n unilateralClaimDelay,\n unilateralRefundDelay,\n unilateralRefundWithoutReceiverDelay,\n } = options;\n\n if (!preimageHash || preimageHash.length !== 20) {\n throw new Error(\"preimage hash must be 20 bytes\");\n }\n if (!receiver || receiver.length !== 32) {\n throw new Error(\"Invalid public key length (receiver)\");\n }\n if (!sender || sender.length !== 32) {\n throw new Error(\"Invalid public key length (sender)\");\n }\n if (!server || server.length !== 32) {\n throw new Error(\"Invalid public key length (server)\");\n }\n if (typeof refundLocktime !== \"bigint\" || refundLocktime <= 0n) {\n throw new Error(\"refund locktime must be greater than 0\");\n }\n if (\n !unilateralClaimDelay ||\n typeof unilateralClaimDelay.value !== \"bigint\" ||\n unilateralClaimDelay.value <= 0n\n ) {\n throw new Error(\"unilateral claim delay must greater than 0\");\n }\n if (unilateralClaimDelay.type === \"seconds\" && unilateralClaimDelay.value % 512n !== 0n) {\n throw new Error(\"seconds timelock must be multiple of 512\");\n }\n if (unilateralClaimDelay.type === \"seconds\" && unilateralClaimDelay.value < 512n) {\n throw new Error(\"seconds timelock must be greater or equal to 512\");\n }\n if (\n !unilateralRefundDelay ||\n typeof unilateralRefundDelay.value !== \"bigint\" ||\n unilateralRefundDelay.value <= 0n\n ) {\n throw new Error(\"unilateral refund delay must greater than 0\");\n }\n if (unilateralRefundDelay.type === \"seconds\" && unilateralRefundDelay.value % 512n !== 0n) {\n throw new Error(\"seconds timelock must be multiple of 512\");\n }\n if (unilateralRefundDelay.type === \"seconds\" && unilateralRefundDelay.value < 512n) {\n throw new Error(\"seconds timelock must be greater or equal to 512\");\n }\n if (\n !unilateralRefundWithoutReceiverDelay ||\n typeof unilateralRefundWithoutReceiverDelay.value !== \"bigint\" ||\n unilateralRefundWithoutReceiverDelay.value <= 0n\n ) {\n throw new Error(\"unilateral refund without receiver delay must greater than 0\");\n }\n if (\n unilateralRefundWithoutReceiverDelay.type === \"seconds\" &&\n unilateralRefundWithoutReceiverDelay.value % 512n !== 0n\n ) {\n throw new Error(\"seconds timelock must be multiple of 512\");\n }\n if (\n unilateralRefundWithoutReceiverDelay.type === \"seconds\" &&\n unilateralRefundWithoutReceiverDelay.value < 512n\n ) {\n throw new Error(\"seconds timelock must be greater or equal to 512\");\n }\n }\n}\n\nfunction preimageConditionScript(preimageHash: Bytes): Bytes {\n return Script.encode([\"HASH160\", preimageHash, \"EQUAL\"]);\n}\n","import { hex } from \"@scure/base\";\nimport { VHTLC } from \"../../script/vhtlc\";\nimport { RelativeTimelock } from \"../../script/tapscript\";\nimport { Contract, ContractHandler, PathContext, PathSelection } from \"../types\";\nimport { isCltvSatisfied, isCsvSpendable, resolveRole } from \"./helpers\";\nimport { sequenceToTimelock, timelockToSequence } from \"../../utils/timelock\";\n\n/**\n * Typed parameters for VHTLC contracts.\n */\nexport interface VHTLCContractParams {\n sender: Uint8Array;\n receiver: Uint8Array;\n server: Uint8Array;\n preimageHash: Uint8Array;\n refundLocktime: bigint;\n unilateralClaimDelay: RelativeTimelock;\n unilateralRefundDelay: RelativeTimelock;\n unilateralRefundWithoutReceiverDelay: RelativeTimelock;\n}\n\n/**\n * Handler for Virtual Hash Time Lock Contract (VHTLC).\n *\n * VHTLC supports multiple spending paths:\n *\n * Collaborative paths (with server):\n * - claim: Receiver + Server with preimage\n * - refund: Sender + Receiver + Server\n * - refundWithoutReceiver: Sender + Server after CLTV locktime\n *\n * Unilateral paths (without server):\n * - unilateralClaim: Receiver with preimage after CSV delay\n * - unilateralRefund: Sender + Receiver after CSV delay\n * - unilateralRefundWithoutReceiver: Sender after CSV delay\n */\nexport const VHTLCContractHandler: ContractHandler<VHTLCContractParams, VHTLC.Script> = {\n type: \"vhtlc\",\n\n createScript(params: Record<string, string>): VHTLC.Script {\n const typed = this.deserializeParams(params);\n return new VHTLC.Script(typed);\n },\n\n serializeParams(params: VHTLCContractParams): Record<string, string> {\n return {\n sender: hex.encode(params.sender),\n receiver: hex.encode(params.receiver),\n server: hex.encode(params.server),\n hash: hex.encode(params.preimageHash),\n refundLocktime: params.refundLocktime.toString(),\n claimDelay: timelockToSequence(params.unilateralClaimDelay).toString(),\n refundDelay: timelockToSequence(params.unilateralRefundDelay).toString(),\n refundNoReceiverDelay: timelockToSequence(\n params.unilateralRefundWithoutReceiverDelay,\n ).toString(),\n };\n },\n\n deserializeParams(params: Record<string, string>): VHTLCContractParams {\n return {\n sender: hex.decode(params.sender),\n receiver: hex.decode(params.receiver),\n server: hex.decode(params.server),\n preimageHash: hex.decode(params.hash),\n refundLocktime: BigInt(params.refundLocktime),\n unilateralClaimDelay: sequenceToTimelock(Number(params.claimDelay)),\n unilateralRefundDelay: sequenceToTimelock(Number(params.refundDelay)),\n unilateralRefundWithoutReceiverDelay: sequenceToTimelock(\n Number(params.refundNoReceiverDelay),\n ),\n };\n },\n\n /**\n * Select spending path based on context.\n *\n * Role is determined from `context.role` or by matching\n * `context.walletDescriptor` (preferred) / `context.walletPubKey`\n * against sender/receiver in contract params.\n */\n selectPath(\n script: VHTLC.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection | null {\n const role = resolveRole(contract, context);\n const preimage = contract.params?.preimage;\n const refundLocktime = BigInt(contract.params.refundLocktime);\n\n if (!role) {\n return null;\n }\n\n if (context.collaborative) {\n if (role === \"receiver\" && preimage) {\n return {\n leaf: script.claim(),\n extraWitness: [hex.decode(preimage)],\n };\n }\n\n if (role === \"sender\" && isCltvSatisfied(context, refundLocktime)) {\n return {\n leaf: script.refundWithoutReceiver(),\n };\n }\n\n return null;\n }\n\n // Unilateral paths\n if (role === \"receiver\" && preimage) {\n const sequence = Number(contract.params.claimDelay);\n if (!isCsvSpendable(context, sequence)) return null;\n return {\n leaf: script.unilateralClaim(),\n extraWitness: [hex.decode(preimage)],\n sequence,\n };\n }\n\n if (role === \"sender\") {\n const sequence = Number(contract.params.refundNoReceiverDelay);\n if (!isCsvSpendable(context, sequence)) return null;\n return {\n leaf: script.unilateralRefundWithoutReceiver(),\n sequence,\n };\n }\n\n return null;\n },\n\n /**\n * Get all possible spending paths (no timelock checks).\n *\n * Role is determined from `context.role` or by matching\n * `context.walletDescriptor` (preferred) / `context.walletPubKey`\n * against sender/receiver in contract params.\n */\n getAllSpendingPaths(\n script: VHTLC.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const role = resolveRole(contract, context);\n const paths: PathSelection[] = [];\n\n if (!role) {\n return paths;\n }\n\n const preimage = contract.params?.preimage;\n\n if (context.collaborative) {\n // Collaborative paths (no timelock checks)\n if (role === \"receiver\" && preimage) {\n paths.push({\n leaf: script.claim(),\n extraWitness: [hex.decode(preimage)],\n });\n }\n if (role === \"sender\") {\n paths.push({\n leaf: script.refundWithoutReceiver(),\n });\n }\n } else {\n // Unilateral paths (no timelock checks)\n if (role === \"receiver\" && preimage) {\n const sequence = Number(contract.params.claimDelay);\n paths.push({\n leaf: script.unilateralClaim(),\n extraWitness: [hex.decode(preimage)],\n sequence,\n });\n }\n if (role === \"sender\") {\n const sequence = Number(contract.params.refundNoReceiverDelay);\n paths.push({\n leaf: script.unilateralRefundWithoutReceiver(),\n sequence,\n });\n }\n }\n\n return paths;\n },\n\n getSpendablePaths(\n script: VHTLC.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n const role = resolveRole(contract, context);\n const paths: PathSelection[] = [];\n\n if (!role) {\n return paths;\n }\n\n const preimage = contract.params?.preimage;\n const refundLocktime = BigInt(contract.params.refundLocktime);\n\n if (context.collaborative) {\n if (role === \"receiver\" && preimage) {\n paths.push({\n leaf: script.claim(),\n extraWitness: [hex.decode(preimage)],\n });\n }\n if (role === \"sender\" && isCltvSatisfied(context, refundLocktime)) {\n paths.push({\n leaf: script.refundWithoutReceiver(),\n });\n }\n return paths;\n }\n\n if (role === \"receiver\" && preimage) {\n const sequence = Number(contract.params.claimDelay);\n if (isCsvSpendable(context, sequence)) {\n paths.push({\n leaf: script.unilateralClaim(),\n extraWitness: [hex.decode(preimage)],\n sequence,\n });\n }\n }\n if (role === \"sender\") {\n const sequence = Number(contract.params.refundNoReceiverDelay);\n if (isCsvSpendable(context, sequence)) {\n paths.push({\n leaf: script.unilateralRefundWithoutReceiver(),\n sequence,\n });\n }\n }\n\n return paths;\n },\n};\n","import { hex } from \"@scure/base\";\nimport { DefaultVtxo } from \"../../script/default\";\nimport { Contract, ContractHandler, Discoverable, PathContext, PathSelection } from \"../types\";\nimport type { DiscoveredContract, DiscoveryDeps } from \"../types\";\nimport { DefaultContractHandler, DefaultContractParams } from \"./default\";\nimport { deriveDescriptorLeafPubKey } from \"../../identity/descriptor\";\nimport { timelockToSequence } from \"../../utils/timelock\";\nimport { WALLET_RECEIVE_SOURCE } from \"../metadata\";\n\n/**\n * Typed parameters for boarding contracts.\n *\n * Boarding reuses the exact `default` contract parameter shape\n * (`pubKey` / `serverPubKey` / `csvTimelock`) rather than inventing\n * boarding-specific names — the boarding semantics come from the\n * contract type and from populating `csvTimelock` with the server's\n * boarding-exit delay (`ArkInfo.boardingExitDelay`) instead of the\n * offchain unilateral-exit delay.\n */\nexport type BoardingContractParams = DefaultContractParams;\n\n/**\n * Handler for the boarding contract (registered type `boarding`).\n *\n * The boarding contract derives the on-chain Bitcoin address used to\n * board funds onto Arkade. It shares the exact `DefaultVtxo.Script`\n * shape with the `default` contract — a Taproot output co-owned by the\n * wallet and the Ark server, with a CSV exit path back to the wallet —\n * and therefore reuses the `default` handler's path logic (forfeit via\n * server cooperation, exit after the boarding CSV).\n *\n * Boarding semantics come entirely from the contract type and from\n * sourcing the CSV timelock from the server's boarding-exit delay\n * (`ArkInfo.boardingExitDelay`), not from renamed parameters. The\n * offchain `default` contract is built from `ArkInfo.unilateralExitDelay`\n * instead, so the two share a script shape but differ in their CSV\n * timelock value. Parameters round-trip through the same\n * `timelockToSequence` / `sequenceToTimelock` helpers and BIP68 sequence\n * encoding as `default` / `delegate`.\n *\n * Like `default` / `delegate`, the boarding handler implements\n * {@link Discoverable.discoverAt} so `wallet.restore()` can rediscover\n * used boarding indices from authoritative on-chain data. It differs from\n * the L2 handlers in its source of truth: boarding probes the **on-chain**\n * UTXO set at its P2TR address (`OnchainProvider.getCoins`) rather than the\n * Ark indexer, and builds its candidate from the boarding-exit CSV\n * (`deps.boardingTimelock`). When boarding discovery is not plumbed (no\n * `deps.boardingTimelock` / `deps.onchainNetwork`) `discoverAt` no-ops.\n *\n * Identity & the default/boarding collision: a contract's `script` (pkScript)\n * is its unique identity — a script owns exactly one repository row. `boarding`\n * is a first-class type with its own row **when its script is distinct** from\n * the wallet's `default` baseline — the real-world case, since a sound Ark\n * server keeps boardingExitDelay strictly longer than unilateralExitDelay (equal\n * delays would expose the provider to a double-spend). Should those delays ever\n * coincide (a misconfigured/malicious server), the boarding script is\n * byte-identical to the default script. `discoverAt` does NOT pre-coalesce that\n * collision: it always emits `type: \"boarding\"`, and the single shared row is\n * resolved FIRST-WINS at the persistence layer\n * ({@link ContractManager.upsertContract}) — whichever purpose is persisted\n * first keeps the row, and the scan deliberately probes boarding first\n * (see docs/hd-wallets_onchain_rotation_collision_fix.md §5.1–5.2). Either way\n * the funds are equally spendable through the shared `DefaultVtxo.Script` paths.\n * Consumers must NOT rely on `contract.type === \"boarding\"` to identify the\n * boarding purpose — resolve the boarding script via\n * `wallet.getBoardingAddress()` / `wallet.boardingTapscript` (which never depend\n * on the persisted contract's type) and match by script when needed.\n */\nexport const BoardingContractHandler: ContractHandler<BoardingContractParams, DefaultVtxo.Script> &\n Discoverable = {\n type: \"boarding\",\n\n createScript(params: Record<string, string>): DefaultVtxo.Script {\n return DefaultContractHandler.createScript(params);\n },\n\n serializeParams(params: BoardingContractParams): Record<string, string> {\n return DefaultContractHandler.serializeParams(params);\n },\n\n deserializeParams(params: Record<string, string>): BoardingContractParams {\n return DefaultContractHandler.deserializeParams(params);\n },\n\n selectPath(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection | null {\n return DefaultContractHandler.selectPath(script, contract, context);\n },\n\n getAllSpendingPaths(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n return DefaultContractHandler.getAllSpendingPaths(script, contract, context);\n },\n\n getSpendablePaths(\n script: DefaultVtxo.Script,\n contract: Contract,\n context: PathContext,\n ): PathSelection[] {\n return DefaultContractHandler.getSpendablePaths(script, contract, context);\n },\n\n /**\n * Probe the on-chain UTXO set for a boarding output at this HD index.\n *\n * Boarding's source of truth is the **current** on-chain coin set\n * (`OnchainProvider.getCoins`), not the Ark indexer: a boarded (spent)\n * boarding output becomes an L2 VTXO at the receive index, so the\n * indexer probe already keeps the gap window open for it; only an\n * *unspent* boarding output needs the on-chain probe (see plan §2).\n *\n * No-ops (returns `[]`) when boarding discovery is not plumbed — i.e.\n * `deps.boardingTimelock` or `deps.onchainNetwork` is absent — so the\n * scanner unit harness (which sets neither) is unaffected.\n *\n * Always emits `type: \"boarding\"`, even in the degenerate equal-delay case\n * where the boarding script is byte-identical to a `default` script at this\n * index (`boardingExitDelay === unilateralExitDelay`). The collision is no\n * longer pre-judged in discovery; it is tolerated FIRST-WINS at the\n * persistence layer ({@link ContractManager.upsertContract}). `deps.csvTimelocks`\n * is intentionally not read here.\n */\n async discoverAt(\n index: number,\n descriptor: string,\n deps: DiscoveryDeps,\n ): Promise<DiscoveredContract[]> {\n if (!deps.boardingTimelock || !deps.onchainNetwork) return [];\n\n const pubKey = deriveDescriptorLeafPubKey(descriptor);\n const script = new DefaultVtxo.Script({\n pubKey,\n serverPubKey: deps.serverPubKey,\n csvTimelock: deps.boardingTimelock,\n });\n const onchainAddress = script.onchainAddress(deps.onchainNetwork);\n\n const coins = await deps.onchainProvider.getCoins(onchainAddress);\n if (coins.length === 0) return [];\n\n const scriptHex = hex.encode(script.pkScript);\n const boardingSeq = timelockToSequence(deps.boardingTimelock);\n\n // Always `type: \"boarding\"` (see method doc). The equal-delay\n // same-script collision is resolved first-wins at persistence, and the\n // scan probes boarding before default so a both-purpose rotated index\n // resolves to a `boarding` row — keeping both the on-chain UTXO and any\n // L2 VTXO recoverable (docs/hd-wallets_onchain_rotation_collision_fix.md\n // §5.2, §5.4).\n return [\n {\n type: \"boarding\",\n params: {\n pubKey: hex.encode(pubKey),\n serverPubKey: hex.encode(deps.serverPubKey),\n csvTimelock: boardingSeq.toString(),\n },\n script: scriptHex,\n // The persisted row's `address` is the *Ark* address (not the\n // on-chain P2TR), matching the row registered at init so the\n // ContractWatcher keeps monitoring the same L2 script and the\n // VTXO repository bucket lines up (plan §6-I.4). The P2TR is\n // recomputed from params only for the `getCoins` probe.\n address: script.address(deps.network.hrp, deps.serverPubKey).encode(),\n // Tag rotated rows (index > 0) so boot resolution can find the\n // newest boarding address and descriptor-aware signing can\n // recover the per-index key (plan §6-II/§6-III.3). The index-0\n // baseline stays untagged, matching `default`/`delegate`.\n ...(index > 0\n ? {\n metadata: {\n source: WALLET_RECEIVE_SOURCE,\n signingDescriptor: descriptor,\n },\n }\n : {}),\n },\n ];\n },\n};\n","export { contractHandlers } from \"./registry\";\nexport { DefaultContractHandler } from \"./default\";\nexport type { DefaultContractParams } from \"./default\";\nexport { DelegateContractHandler } from \"./delegate\";\nexport type { DelegateContractParams } from \"./delegate\";\nexport { VHTLCContractHandler } from \"./vhtlc\";\nexport type { VHTLCContractParams } from \"./vhtlc\";\nexport { BoardingContractHandler } from \"./boarding\";\nexport type { BoardingContractParams } from \"./boarding\";\n\n// Register built-in handlers\nimport { contractHandlers } from \"./registry\";\nimport { DefaultContractHandler } from \"./default\";\nimport { DelegateContractHandler } from \"./delegate\";\nimport { VHTLCContractHandler } from \"./vhtlc\";\nimport { BoardingContractHandler } from \"./boarding\";\n\ncontractHandlers.register(DefaultContractHandler);\ncontractHandlers.register(DelegateContractHandler);\ncontractHandlers.register(VHTLCContractHandler);\ncontractHandlers.register(BoardingContractHandler);\n"]}
|