@arkade-os/sdk 0.5.12 → 0.5.14

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.
Files changed (106) hide show
  1. package/README.md +6 -0
  2. package/dist/adapters/expo.cjs +7 -7
  3. package/dist/adapters/expo.d.cts +2 -2
  4. package/dist/adapters/expo.d.ts +2 -2
  5. package/dist/adapters/expo.js +4 -4
  6. package/dist/{asyncStorageTaskQueue-DTNS2qfN.d.cts → asyncStorageTaskQueue-DzO5SBcm.d.cts} +2 -2
  7. package/dist/{asyncStorageTaskQueue-Bsty8W7d.d.ts → asyncStorageTaskQueue-p7zeFhA3.d.ts} +2 -2
  8. package/dist/{chunk-4OY5BCIE.js → chunk-4HZQSKWG.js} +628 -23
  9. package/dist/chunk-4HZQSKWG.js.map +1 -0
  10. package/dist/{chunk-4X4SY3RH.cjs → chunk-6J4GABF7.cjs} +28 -20
  11. package/dist/chunk-6J4GABF7.cjs.map +1 -0
  12. package/dist/{chunk-YAVF2PR6.cjs → chunk-6TBTL42M.cjs} +87 -2
  13. package/dist/chunk-6TBTL42M.cjs.map +1 -0
  14. package/dist/{chunk-5NY5EOS2.js → chunk-72EC3ASW.js} +4 -4
  15. package/dist/{chunk-5NY5EOS2.js.map → chunk-72EC3ASW.js.map} +1 -1
  16. package/dist/{chunk-QV7AOZZN.cjs → chunk-7LPT6AYH.cjs} +21 -21
  17. package/dist/{chunk-QV7AOZZN.cjs.map → chunk-7LPT6AYH.cjs.map} +1 -1
  18. package/dist/{chunk-JA4SYFC7.cjs → chunk-ACIQZLWL.cjs} +379 -20
  19. package/dist/chunk-ACIQZLWL.cjs.map +1 -0
  20. package/dist/{chunk-BA3GPO5C.js → chunk-AZHBGWVC.js} +5 -5
  21. package/dist/{chunk-BA3GPO5C.js.map → chunk-AZHBGWVC.js.map} +1 -1
  22. package/dist/{chunk-HNLC6F73.cjs → chunk-EVVLVFY7.cjs} +20 -20
  23. package/dist/{chunk-HNLC6F73.cjs.map → chunk-EVVLVFY7.cjs.map} +1 -1
  24. package/dist/{chunk-2YXVU5TK.js → chunk-GB67AGXG.js} +81 -3
  25. package/dist/chunk-GB67AGXG.js.map +1 -0
  26. package/dist/{chunk-WBZYYRAB.js → chunk-HWWSLCQN.js} +9724 -8151
  27. package/dist/chunk-HWWSLCQN.js.map +1 -0
  28. package/dist/{chunk-4TMJBLJT.js → chunk-J2JZZTOE.js} +20 -14
  29. package/dist/chunk-J2JZZTOE.js.map +1 -0
  30. package/dist/{chunk-3RO63OPW.js → chunk-LCGRZ24T.js} +4 -4
  31. package/dist/{chunk-3RO63OPW.js.map → chunk-LCGRZ24T.js.map} +1 -1
  32. package/dist/{chunk-CJUVKHK4.cjs → chunk-LQH7DACV.cjs} +10204 -8628
  33. package/dist/chunk-LQH7DACV.cjs.map +1 -0
  34. package/dist/{chunk-QDX2HUBK.cjs → chunk-MEIE2AEU.cjs} +11 -11
  35. package/dist/{chunk-QDX2HUBK.cjs.map → chunk-MEIE2AEU.cjs.map} +1 -1
  36. package/dist/{chunk-3ABF4EMM.js → chunk-X57WKONW.js} +369 -10
  37. package/dist/chunk-X57WKONW.js.map +1 -0
  38. package/dist/{chunk-C3NKBKRY.cjs → chunk-XZHTYYW5.cjs} +680 -68
  39. package/dist/chunk-XZHTYYW5.cjs.map +1 -0
  40. package/dist/compiler.cjs +3 -4
  41. package/dist/compiler.cjs.map +1 -1
  42. package/dist/compiler.d.cts +1 -1
  43. package/dist/compiler.d.ts +1 -1
  44. package/dist/compiler.js +2 -3
  45. package/dist/compiler.js.map +1 -1
  46. package/dist/contracts/handlers/index.cjs +15 -11
  47. package/dist/contracts/handlers/index.d.cts +5 -5
  48. package/dist/contracts/handlers/index.d.ts +5 -5
  49. package/dist/contracts/handlers/index.js +4 -4
  50. package/dist/{index-D_zLtU-F.d.ts → index-CaOBA9Ev.d.ts} +2 -2
  51. package/dist/{index-BBmZXXqk.d.cts → index-Cy57QdcL.d.cts} +589 -23
  52. package/dist/{index-DJ32LpfD.d.ts → index-Db5qzYRi.d.ts} +589 -23
  53. package/dist/{index-DenQfCn1.d.cts → index-Lq_u0hqj.d.cts} +2 -2
  54. package/dist/index.cjs +403 -368
  55. package/dist/index.d.cts +197 -117
  56. package/dist/index.d.ts +197 -117
  57. package/dist/index.js +6 -7
  58. package/dist/{program-DPzf5qsk.d.cts → program-ZWUAWy_9.d.cts} +1 -1
  59. package/dist/{program-38A2Twvj.d.ts → program-zdDO4cMt.d.ts} +1 -1
  60. package/dist/repositories/realm/index.cjs +39 -40
  61. package/dist/repositories/realm/index.cjs.map +1 -1
  62. package/dist/repositories/realm/index.d.cts +2 -2
  63. package/dist/repositories/realm/index.d.ts +2 -2
  64. package/dist/repositories/realm/index.js +7 -8
  65. package/dist/repositories/realm/index.js.map +1 -1
  66. package/dist/repositories/sqlite/index.cjs +37 -38
  67. package/dist/repositories/sqlite/index.cjs.map +1 -1
  68. package/dist/repositories/sqlite/index.d.cts +2 -2
  69. package/dist/repositories/sqlite/index.d.ts +2 -2
  70. package/dist/repositories/sqlite/index.js +7 -8
  71. package/dist/repositories/sqlite/index.js.map +1 -1
  72. package/dist/{taskRunner-BBGaN4cq.d.cts → taskRunner-DhZ-KQBW.d.cts} +2 -2
  73. package/dist/{taskRunner-Cck24OnC.d.ts → taskRunner-amPuilMW.d.ts} +2 -2
  74. package/dist/wallet/expo/background.cjs +16 -17
  75. package/dist/wallet/expo/background.cjs.map +1 -1
  76. package/dist/wallet/expo/background.d.cts +3 -3
  77. package/dist/wallet/expo/background.d.ts +3 -3
  78. package/dist/wallet/expo/background.js +8 -9
  79. package/dist/wallet/expo/background.js.map +1 -1
  80. package/dist/wallet/expo/index.cjs +17 -18
  81. package/dist/wallet/expo/index.cjs.map +1 -1
  82. package/dist/wallet/expo/index.d.cts +2 -2
  83. package/dist/wallet/expo/index.d.ts +2 -2
  84. package/dist/wallet/expo/index.js +7 -8
  85. package/dist/wallet/expo/index.js.map +1 -1
  86. package/dist/worker/expo/index.cjs +11 -12
  87. package/dist/worker/expo/index.cjs.map +1 -1
  88. package/dist/worker/expo/index.d.cts +4 -4
  89. package/dist/worker/expo/index.d.ts +4 -4
  90. package/dist/worker/expo/index.js +7 -8
  91. package/dist/worker/expo/index.js.map +1 -1
  92. package/package.json +1 -1
  93. package/dist/chunk-2YXVU5TK.js.map +0 -1
  94. package/dist/chunk-3ABF4EMM.js.map +0 -1
  95. package/dist/chunk-4OY5BCIE.js.map +0 -1
  96. package/dist/chunk-4TMJBLJT.js.map +0 -1
  97. package/dist/chunk-4X4SY3RH.cjs.map +0 -1
  98. package/dist/chunk-C3NKBKRY.cjs.map +0 -1
  99. package/dist/chunk-CJUVKHK4.cjs.map +0 -1
  100. package/dist/chunk-JA4SYFC7.cjs.map +0 -1
  101. package/dist/chunk-PHOJF7OK.cjs +0 -376
  102. package/dist/chunk-PHOJF7OK.cjs.map +0 -1
  103. package/dist/chunk-UXLETBNK.js +0 -373
  104. package/dist/chunk-UXLETBNK.js.map +0 -1
  105. package/dist/chunk-WBZYYRAB.js.map +0 -1
  106. package/dist/chunk-YAVF2PR6.cjs.map +0 -1
@@ -1,9 +1,10 @@
1
- import { deserializeArkadeContractParams, serializeArkadeContractParams, ArkadeProgramScript, computeArkadeScriptPublicKey, staticWitness, resolveCsvTimelock, resolveTimelockValue, ArkadeScript } from './chunk-3ABF4EMM.js';
2
- import { SCRIPT_QUERY_CHUNK_SIZE, indexerPages, getNormalizedVtxos, DEFAULT_PAGE_SIZE } from './chunk-4TMJBLJT.js';
3
- import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, timelockToSequence, sequenceToTimelock, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript } from './chunk-2YXVU5TK.js';
1
+ import { deserializeArkadeContractParams, serializeArkadeContractParams, ArkadeProgramScript, computeArkadeScriptPublicKey, staticWitness, resolveCsvTimelock, resolveTimelockValue, programFromArtifact, ArkadeScript } from './chunk-X57WKONW.js';
2
+ import { SCRIPT_QUERY_CHUNK_SIZE, indexerPages, getNormalizedVtxos, DEFAULT_PAGE_SIZE } from './chunk-J2JZZTOE.js';
3
+ import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, timelockToSequence, sequenceToTimelock, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript, sequenceToCanonicalTimelock } from './chunk-GB67AGXG.js';
4
4
  import { hex } from '@scure/base';
5
5
  import { networks, expand } from '@bitcoinerlab/descriptors-scure';
6
- import { Script } from '@scure/btc-signer';
6
+ import { Script, ScriptNum } from '@scure/btc-signer';
7
+ import { equalBytes } from '@scure/btc-signer/utils.js';
7
8
 
8
9
  // src/contracts/handlers/registry.ts
9
10
  var ContractHandlerRegistry = class {
@@ -45,8 +46,12 @@ var contractHandlers = new ContractHandlerRegistry();
45
46
  var DefaultVtxo;
46
47
  ((DefaultVtxo2) => {
47
48
  class Script2 extends VtxoScript {
48
- /** Create the default virtual output script with one forfeit path and one exit path. */
49
- constructor(options) {
49
+ /**
50
+ * Create the default virtual output script with one forfeit path and one exit path.
51
+ * @param extraLeaves leaves after forfeit and exit, e.g. the Executor's emulator-enforced
52
+ * renewal leaf, which keeps the wallet's paths and adds one it never signs.
53
+ */
54
+ constructor(options, extraLeaves = []) {
50
55
  const { pubKey, serverPubKey, csvTimelock } = options;
51
56
  const forfeitScript = MultisigTapscript.encode({
52
57
  pubkeys: [pubKey, serverPubKey]
@@ -55,7 +60,7 @@ var DefaultVtxo;
55
60
  timelock: csvTimelock,
56
61
  pubkeys: [pubKey]
57
62
  }).script;
58
- super([forfeitScript, exitScript]);
63
+ super([forfeitScript, exitScript, ...extraLeaves]);
59
64
  this.options = options;
60
65
  this.forfeitScript = hex.encode(forfeitScript);
61
66
  this.exitScript = hex.encode(exitScript);
@@ -429,6 +434,22 @@ function isCsvSpendable(context, sequence) {
429
434
  return false;
430
435
  }
431
436
  function exitSequence(contract) {
437
+ if (contract.type === "executor") {
438
+ const { template } = contract.params;
439
+ if (template !== "renewal" && template !== "boarding") {
440
+ throw new Error(`unknown Executor template ${template}`);
441
+ }
442
+ const name = template === "boarding" ? "boardingExitDelay" : "exitDelay";
443
+ const raw = contract.params[name];
444
+ const sequence = Number(raw);
445
+ if (!/^[0-9]+$/.test(raw ?? "") || !Number.isSafeInteger(sequence)) {
446
+ throw new Error(`${name} must be a non-negative integer`);
447
+ }
448
+ if (!sequenceToCanonicalTimelock(BigInt(sequence))) {
449
+ throw new Error(`${name} must be a canonical BIP68 sequence`);
450
+ }
451
+ return sequence;
452
+ }
432
453
  return contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
433
454
  }
434
455
  function selectForfeitOrExitPath(script, contract, context) {
@@ -667,22 +688,33 @@ var DelegateContractHandler = {
667
688
  discoverRange: discoverDelegateRange,
668
689
  candidatesAt: delegateCandidatesAt
669
690
  };
691
+ function delegateDiscoveryKeys(deps) {
692
+ const keys = /* @__PURE__ */ new Map();
693
+ for (const key of [
694
+ ...deps.delegatePubKey ? [deps.delegatePubKey] : [],
695
+ ...deps.retiredDelegatePubKeys ?? []
696
+ ]) {
697
+ const id = hex.encode(key);
698
+ if (!keys.has(id)) keys.set(id, key);
699
+ }
700
+ return [...keys.values()];
701
+ }
670
702
  function delegateCandidatesAt(_index, descriptor, deps) {
671
- const delegatePubKey = deps.delegatePubKey;
672
- if (!delegatePubKey) return [];
673
- return buildSignerTimelockCandidates(
674
- descriptor,
675
- deps,
676
- (opts) => new DelegateVtxo.Script({ ...opts, delegatePubKey })
677
- ).map((c) => ({
678
- type: "delegate",
679
- params: DelegateContractHandler.serializeParams({ ...c, delegatePubKey }),
680
- script: c.scriptHex,
681
- address: c.script.address(deps.network.hrp, c.serverPubKey).encode()
682
- }));
703
+ return delegateDiscoveryKeys(deps).flatMap(
704
+ (delegatePubKey) => buildSignerTimelockCandidates(
705
+ descriptor,
706
+ deps,
707
+ (opts) => new DelegateVtxo.Script({ ...opts, delegatePubKey })
708
+ ).map((c) => ({
709
+ type: "delegate",
710
+ params: DelegateContractHandler.serializeParams({ ...c, delegatePubKey }),
711
+ script: c.scriptHex,
712
+ address: c.script.address(deps.network.hrp, c.serverPubKey).encode()
713
+ }))
714
+ );
683
715
  }
684
716
  function discoverDelegateRange(entries, deps) {
685
- if (!deps.delegatePubKey) {
717
+ if (delegateDiscoveryKeys(deps).length === 0) {
686
718
  return Promise.resolve(new Map(entries.map((e) => [e.index, []])));
687
719
  }
688
720
  return discoverIndexerCandidates(
@@ -1477,6 +1509,578 @@ var ArkadeContractHandler = {
1477
1509
  }
1478
1510
  };
1479
1511
 
1512
+ // src/script/executor/board.json
1513
+ var board_default = {
1514
+ format: "template/v1",
1515
+ type: "proof",
1516
+ variables: {
1517
+ owner: "pubkey",
1518
+ boarding_exit_delay: "int",
1519
+ exit_delay: "int",
1520
+ renewal_window: "int",
1521
+ max_fee: "int"
1522
+ },
1523
+ inputs: [
1524
+ {
1525
+ name: "deposit",
1526
+ type: "onchain",
1527
+ contract: {
1528
+ definition: {
1529
+ artifact: "e3c0fa053fbb529a252a1025e3453a41f01949f4e49d50de7dfe5d3510470ed3"
1530
+ },
1531
+ arguments: {
1532
+ owner: "<owner>",
1533
+ boardingExitDelay: "<boarding_exit_delay>",
1534
+ renewalProgram: { program: "funds" },
1535
+ maxFee: "<max_fee>"
1536
+ }
1537
+ },
1538
+ spend: { function: "board", leaf: "board" }
1539
+ }
1540
+ ],
1541
+ outputs: [
1542
+ {
1543
+ name: "funds",
1544
+ value: { from: "deposit" },
1545
+ locking: {
1546
+ contract: {
1547
+ definition: {
1548
+ artifact: "faa3249b8a28e999963994e4020e832285351eb7ce3b4821bcb3b4498f5b8ef3"
1549
+ },
1550
+ arguments: {
1551
+ owner: "<owner>",
1552
+ exitDelay: "<exit_delay>",
1553
+ renewalWindow: "<renewal_window>",
1554
+ maxFee: "<max_fee>"
1555
+ }
1556
+ }
1557
+ }
1558
+ }
1559
+ ],
1560
+ fees: { from: "deposit", max: "<max_fee>" },
1561
+ delegation: { schedule: { deposit: { min_confirmations: 1 } } }
1562
+ };
1563
+
1564
+ // src/script/executor/delegated_boarding.json
1565
+ var delegated_boarding_default = {
1566
+ contractName: "DelegatedBoarding",
1567
+ constructorInputs: [
1568
+ {
1569
+ name: "owner",
1570
+ type: "pubkey"
1571
+ },
1572
+ {
1573
+ name: "boardingExitDelay",
1574
+ type: "int"
1575
+ },
1576
+ {
1577
+ name: "renewalProgram",
1578
+ type: "bytes32"
1579
+ },
1580
+ {
1581
+ name: "maxFee",
1582
+ type: "int"
1583
+ }
1584
+ ],
1585
+ structs: [],
1586
+ functions: [
1587
+ {
1588
+ name: "forfeit",
1589
+ leaves: [
1590
+ {
1591
+ name: "forfeit",
1592
+ asm: ["<owner>", "OP_CHECKSIGVERIFY", "<SERVER_KEY>", "OP_CHECKSIG"],
1593
+ witness: [
1594
+ {
1595
+ name: "ownerSig",
1596
+ type: "signature",
1597
+ encoding: "schnorr-64"
1598
+ },
1599
+ {
1600
+ name: "serverSig",
1601
+ type: "signature",
1602
+ encoding: "schnorr-64",
1603
+ injected: true
1604
+ }
1605
+ ]
1606
+ }
1607
+ ]
1608
+ },
1609
+ {
1610
+ name: "exit",
1611
+ leaves: [
1612
+ {
1613
+ name: "exit",
1614
+ asm: [
1615
+ "<boardingExitDelay>",
1616
+ "OP_CHECKSEQUENCEVERIFY",
1617
+ "OP_DROP",
1618
+ "<owner>",
1619
+ "OP_CHECKSIG"
1620
+ ],
1621
+ witness: [
1622
+ {
1623
+ name: "ownerSig",
1624
+ type: "signature",
1625
+ encoding: "schnorr-64"
1626
+ }
1627
+ ]
1628
+ }
1629
+ ]
1630
+ },
1631
+ {
1632
+ name: "board",
1633
+ arkade: {
1634
+ inputs: [],
1635
+ asm: [
1636
+ "0x74797065",
1637
+ "OP_INSPECTINTENTMESSAGE",
1638
+ "OP_VERIFY",
1639
+ "0x7265676973746572",
1640
+ "OP_EQUALVERIFY",
1641
+ "0x6f6e636861696e5f6f75747075745f696e6465786573",
1642
+ "OP_INSPECTINTENTMESSAGE",
1643
+ "OP_VERIFY",
1644
+ "0x5b5d",
1645
+ "OP_EQUALVERIFY",
1646
+ "OP_PUSHCURRENTINPUTINDEX",
1647
+ "OP_1SUB",
1648
+ "OP_INSPECTOUTPUTSCRIPTPUBKEY",
1649
+ "1",
1650
+ "OP_EQUALVERIFY",
1651
+ "<renewalProgram>",
1652
+ "OP_EQUALVERIFY",
1653
+ "OP_PUSHCURRENTINPUTINDEX",
1654
+ "OP_1SUB",
1655
+ "OP_INSPECTOUTPUTVALUE",
1656
+ "<maxFee>",
1657
+ "OP_ADD",
1658
+ "OP_PUSHCURRENTINPUTINDEX",
1659
+ "OP_INSPECTINPUTVALUE",
1660
+ "OP_GREATERTHANOREQUAL"
1661
+ ]
1662
+ },
1663
+ leaves: [
1664
+ {
1665
+ name: "board",
1666
+ asm: [
1667
+ "<SERVER_KEY>",
1668
+ "OP_CHECKSIGVERIFY",
1669
+ "<EMULATOR_KEY:board>",
1670
+ "OP_CHECKSIG"
1671
+ ],
1672
+ witness: [
1673
+ {
1674
+ name: "serverSig",
1675
+ type: "signature",
1676
+ encoding: "schnorr-64",
1677
+ injected: true
1678
+ },
1679
+ {
1680
+ name: "emulatorSig",
1681
+ type: "signature",
1682
+ encoding: "schnorr-64",
1683
+ injected: true
1684
+ }
1685
+ ]
1686
+ }
1687
+ ]
1688
+ }
1689
+ ]
1690
+ };
1691
+
1692
+ // src/script/executor/delegated_vtxo.json
1693
+ var delegated_vtxo_default = {
1694
+ contractName: "DelegatedVtxo",
1695
+ constructorInputs: [
1696
+ {
1697
+ name: "owner",
1698
+ type: "pubkey"
1699
+ },
1700
+ {
1701
+ name: "exitDelay",
1702
+ type: "int"
1703
+ },
1704
+ {
1705
+ name: "renewalWindow",
1706
+ type: "int"
1707
+ },
1708
+ {
1709
+ name: "maxFee",
1710
+ type: "int"
1711
+ }
1712
+ ],
1713
+ structs: [],
1714
+ functions: [
1715
+ {
1716
+ name: "forfeit",
1717
+ leaves: [
1718
+ {
1719
+ name: "forfeit",
1720
+ asm: ["<owner>", "OP_CHECKSIGVERIFY", "<SERVER_KEY>", "OP_CHECKSIG"],
1721
+ witness: [
1722
+ {
1723
+ name: "ownerSig",
1724
+ type: "signature",
1725
+ encoding: "schnorr-64"
1726
+ },
1727
+ {
1728
+ name: "serverSig",
1729
+ type: "signature",
1730
+ encoding: "schnorr-64",
1731
+ injected: true
1732
+ }
1733
+ ]
1734
+ }
1735
+ ]
1736
+ },
1737
+ {
1738
+ name: "exit",
1739
+ leaves: [
1740
+ {
1741
+ name: "exit",
1742
+ asm: [
1743
+ "<exitDelay>",
1744
+ "OP_CHECKSEQUENCEVERIFY",
1745
+ "OP_DROP",
1746
+ "<owner>",
1747
+ "OP_CHECKSIG"
1748
+ ],
1749
+ witness: [
1750
+ {
1751
+ name: "ownerSig",
1752
+ type: "signature",
1753
+ encoding: "schnorr-64"
1754
+ }
1755
+ ]
1756
+ }
1757
+ ]
1758
+ },
1759
+ {
1760
+ name: "renew",
1761
+ arkade: {
1762
+ inputs: [],
1763
+ asm: [
1764
+ "OP_PUSHEXPIRY",
1765
+ "<renewalWindow>",
1766
+ "OP_SUB",
1767
+ "OP_CHECKTIME",
1768
+ "OP_VERIFY",
1769
+ "0x74797065",
1770
+ "OP_INSPECTINTENTMESSAGE",
1771
+ "OP_VERIFY",
1772
+ "0x7265676973746572",
1773
+ "OP_EQUALVERIFY",
1774
+ "0x6f6e636861696e5f6f75747075745f696e6465786573",
1775
+ "OP_INSPECTINTENTMESSAGE",
1776
+ "OP_VERIFY",
1777
+ "0x5b5d",
1778
+ "OP_EQUALVERIFY",
1779
+ "OP_PUSHCURRENTINPUTINDEX",
1780
+ "OP_1SUB",
1781
+ "OP_INSPECTOUTPUTVALUE",
1782
+ "<maxFee>",
1783
+ "OP_ADD",
1784
+ "OP_PUSHCURRENTINPUTINDEX",
1785
+ "OP_INSPECTINPUTVALUE",
1786
+ "OP_GREATERTHANOREQUAL",
1787
+ "OP_VERIFY",
1788
+ "OP_PUSHCURRENTINPUTINDEX",
1789
+ "OP_1SUB",
1790
+ "5",
1791
+ "0",
1792
+ "OP_TUNNEL"
1793
+ ]
1794
+ },
1795
+ leaves: [
1796
+ {
1797
+ name: "renew",
1798
+ asm: [
1799
+ "<SERVER_KEY>",
1800
+ "OP_CHECKSIGVERIFY",
1801
+ "<EMULATOR_KEY:renew>",
1802
+ "OP_CHECKSIG"
1803
+ ],
1804
+ witness: [
1805
+ {
1806
+ name: "serverSig",
1807
+ type: "signature",
1808
+ encoding: "schnorr-64",
1809
+ injected: true
1810
+ },
1811
+ {
1812
+ name: "emulatorSig",
1813
+ type: "signature",
1814
+ encoding: "schnorr-64",
1815
+ injected: true
1816
+ }
1817
+ ]
1818
+ }
1819
+ ]
1820
+ }
1821
+ ]
1822
+ };
1823
+
1824
+ // src/script/executor/renew.json
1825
+ var renew_default = {
1826
+ format: "template/v1",
1827
+ type: "proof",
1828
+ variables: {
1829
+ owner: "pubkey",
1830
+ exit_delay: "int",
1831
+ renewal_window: "int",
1832
+ max_fee: "int"
1833
+ },
1834
+ inputs: [
1835
+ {
1836
+ name: "funds",
1837
+ contract: {
1838
+ definition: {
1839
+ artifact: "faa3249b8a28e999963994e4020e832285351eb7ce3b4821bcb3b4498f5b8ef3"
1840
+ },
1841
+ arguments: {
1842
+ owner: "<owner>",
1843
+ exitDelay: "<exit_delay>",
1844
+ renewalWindow: "<renewal_window>",
1845
+ maxFee: "<max_fee>"
1846
+ }
1847
+ },
1848
+ spend: { function: "renew", leaf: "renew" }
1849
+ }
1850
+ ],
1851
+ outputs: [
1852
+ {
1853
+ name: "renewed",
1854
+ value: { from: "funds" },
1855
+ locking: { from: "funds" },
1856
+ assets: [{ from: "funds" }]
1857
+ }
1858
+ ],
1859
+ fees: { from: "funds", max: "<max_fee>" },
1860
+ delegation: { schedule: { funds: { before_expiry_seconds: "<renewal_window>" } } }
1861
+ };
1862
+
1863
+ // src/script/executor/executorTemplate.ts
1864
+ var EXECUTOR_TEMPLATES = {
1865
+ renewal: renew_default,
1866
+ boarding: board_default
1867
+ };
1868
+ var EXECUTOR_ARTIFACTS = {
1869
+ faa3249b8a28e999963994e4020e832285351eb7ce3b4821bcb3b4498f5b8ef3: delegated_vtxo_default,
1870
+ e3c0fa053fbb529a252a1025e3453a41f01949f4e49d50de7dfe5d3510470ed3: delegated_boarding_default
1871
+ };
1872
+ var DEFAULT_TEMPLATE_IDS = {
1873
+ renewal: "d78996bc48dca7d9cc6da69bf2ee8d8feaa521c4aa5998c410e3e9ba2dc69297",
1874
+ boarding: "2f8b8761c3d98230cbb170814643f591c29f737c0cf68f600f81920024dccbf8"
1875
+ };
1876
+ function variablesOf(kind, owner, params) {
1877
+ if (owner.length !== 33) throw new Error("owner must be a compressed public key");
1878
+ const variables = {
1879
+ owner,
1880
+ exit_delay: params.exitDelay,
1881
+ renewal_window: params.renewalWindow,
1882
+ max_fee: params.maxFee
1883
+ };
1884
+ if (kind === "boarding") {
1885
+ if (params.boardingExitDelay === void 0) throw new Error("boarding needs an exit delay");
1886
+ variables.boarding_exit_delay = params.boardingExitDelay;
1887
+ }
1888
+ return variables;
1889
+ }
1890
+ function defaultVariables(kind, owner, params) {
1891
+ const variables = variablesOf(kind, owner, params);
1892
+ return Object.fromEntries(
1893
+ Object.entries(variables).map(([name, v]) => [
1894
+ name,
1895
+ hex.encode(typeof v === "number" ? ScriptNum().encode(BigInt(v)) : v)
1896
+ ])
1897
+ );
1898
+ }
1899
+ function defaultContract(kind, keys, owner, params) {
1900
+ const doc = EXECUTOR_TEMPLATES[kind];
1901
+ return instantiate(doc, doc.inputs[0].contract, variablesOf(kind, owner, params), keys);
1902
+ }
1903
+ function instantiate(doc, construction, variables, keys) {
1904
+ const def = "artifact" in construction.definition ? EXECUTOR_ARTIFACTS[construction.definition.artifact] : construction.definition;
1905
+ if (!def)
1906
+ throw new Error(
1907
+ `unknown artifact ${construction.definition.artifact}`
1908
+ );
1909
+ const serverKey = hex.decode(keys.serverPubkey).subarray(1);
1910
+ const args = { server: serverKey };
1911
+ for (const [field, binding] of Object.entries(construction.arguments)) {
1912
+ if (typeof binding === "string") {
1913
+ const value = variables[binding.slice(1, -1)];
1914
+ if (value === void 0) throw new Error(`missing constructor value ${field}`);
1915
+ args[field] = value;
1916
+ } else {
1917
+ const output = doc.outputs.find((o) => o.name === binding.program)?.locking.contract;
1918
+ if (!output) throw new Error(`program ${binding.program} names no contract output`);
1919
+ args[field] = instantiate(doc, output, variables, keys).pkScript.subarray(2);
1920
+ }
1921
+ }
1922
+ for (const field of def.constructorInputs) {
1923
+ const value = args[field.name];
1924
+ if (value === void 0) throw new Error(`missing constructor value ${field.name}`);
1925
+ if (field.type === "pubkey") args[field.name] = value.subarray(1);
1926
+ }
1927
+ return new ArkadeProgramScript(programFromArtifact(def), args, {
1928
+ serverKey,
1929
+ emulatorKey: hex.decode(keys.emulatorPubkey)
1930
+ });
1931
+ }
1932
+
1933
+ // src/contracts/handlers/executor.ts
1934
+ var TEMPLATES = ["renewal", "boarding"];
1935
+ function compressed(value, name) {
1936
+ const key = hex.decode(value ?? "");
1937
+ if (key.length !== 33) throw new Error(`${name} must be a compressed public key`);
1938
+ return key;
1939
+ }
1940
+ function integer(value, name) {
1941
+ const n = Number(value);
1942
+ if (!/^[0-9]+$/.test(value ?? "") || !Number.isSafeInteger(n)) {
1943
+ throw new Error(`${name} must be a non-negative integer`);
1944
+ }
1945
+ return n;
1946
+ }
1947
+ function evenOwnerKey(xOnly) {
1948
+ const key = new Uint8Array(33);
1949
+ key[0] = 2;
1950
+ key.set(xOnly, 1);
1951
+ return key;
1952
+ }
1953
+ function executorContractParams(template, owner, keys, params) {
1954
+ return ExecutorContractHandler.serializeParams({
1955
+ template,
1956
+ owner,
1957
+ exitDelay: params.exitDelay,
1958
+ renewalWindow: params.renewalWindow,
1959
+ maxFee: params.maxFee,
1960
+ ...template === "boarding" ? { boardingExitDelay: params.boardingExitDelay } : {},
1961
+ cosignerPubKey: hex.decode(keys.cosignerPubkey),
1962
+ serverPubKey: hex.decode(keys.serverPubkey),
1963
+ emulatorPubKey: hex.decode(keys.emulatorPubkey)
1964
+ });
1965
+ }
1966
+ function executorKeysOf(p) {
1967
+ return {
1968
+ cosignerPubkey: hex.encode(p.cosignerPubKey),
1969
+ serverPubkey: hex.encode(p.serverPubKey),
1970
+ emulatorPubkey: hex.encode(p.emulatorPubKey)
1971
+ };
1972
+ }
1973
+ var ExecutorContractHandler = {
1974
+ type: "executor",
1975
+ /** The default script of the owner with the emulator-enforced leaf after forfeit and exit. */
1976
+ createScript(params) {
1977
+ const p = this.deserializeParams(params);
1978
+ const derived = defaultContract(p.template, executorKeysOf(p), p.owner, p);
1979
+ const script = new DefaultVtxo.Script(
1980
+ {
1981
+ pubKey: p.owner.subarray(1),
1982
+ serverPubKey: p.serverPubKey.subarray(1),
1983
+ csvTimelock: sequenceToTimelock(p.boardingExitDelay ?? p.exitDelay)
1984
+ },
1985
+ derived.scripts.slice(2)
1986
+ );
1987
+ if (!equalBytes(script.pkScript, derived.pkScript)) {
1988
+ throw new Error(
1989
+ `delegated ${p.template} contract is not forfeit, exit and an emulator-enforced leaf`
1990
+ );
1991
+ }
1992
+ return script;
1993
+ },
1994
+ serializeParams(params) {
1995
+ return {
1996
+ template: params.template,
1997
+ owner: hex.encode(params.owner),
1998
+ exitDelay: params.exitDelay.toString(),
1999
+ renewalWindow: params.renewalWindow.toString(),
2000
+ maxFee: params.maxFee.toString(),
2001
+ ...params.boardingExitDelay !== void 0 ? { boardingExitDelay: params.boardingExitDelay.toString() } : {},
2002
+ cosignerPubKey: hex.encode(params.cosignerPubKey),
2003
+ serverPubKey: hex.encode(params.serverPubKey),
2004
+ emulatorPubKey: hex.encode(params.emulatorPubKey)
2005
+ };
2006
+ },
2007
+ deserializeParams(params) {
2008
+ if (!TEMPLATES.includes(params.template)) {
2009
+ throw new Error(`unknown Executor template ${params.template}`);
2010
+ }
2011
+ return {
2012
+ template: params.template,
2013
+ owner: compressed(params.owner, "owner"),
2014
+ exitDelay: integer(params.exitDelay, "exitDelay"),
2015
+ renewalWindow: integer(params.renewalWindow, "renewalWindow"),
2016
+ maxFee: integer(params.maxFee, "maxFee"),
2017
+ ...params.template === "boarding" ? { boardingExitDelay: integer(params.boardingExitDelay, "boardingExitDelay") } : {},
2018
+ cosignerPubKey: compressed(params.cosignerPubKey, "cosignerPubKey"),
2019
+ serverPubKey: compressed(params.serverPubKey, "serverPubKey"),
2020
+ emulatorPubKey: compressed(params.emulatorPubKey, "emulatorPubKey")
2021
+ };
2022
+ },
2023
+ selectPath(script, contract, context) {
2024
+ return selectForfeitOrExitPath(script, contract, context);
2025
+ },
2026
+ getAllSpendingPaths(script, contract, context) {
2027
+ return forfeitExitAllPaths(script, contract, context);
2028
+ },
2029
+ getSpendablePaths(script, contract, context) {
2030
+ return forfeitExitSpendablePaths(script, contract, context);
2031
+ },
2032
+ /** The wallet's own money, renewed by the service. */
2033
+ isGenericallySpendable: () => true,
2034
+ discoverAt: discoverAtViaRange(discoverExecutorRange),
2035
+ discoverRange: discoverExecutorRange
2036
+ };
2037
+ async function discoverExecutorRange(entries, deps) {
2038
+ const out = new Map(entries.map((e) => [e.index, []]));
2039
+ const watches = deps.executorWatches ?? [];
2040
+ if (watches.length === 0) return out;
2041
+ const pairs = entries.flatMap(
2042
+ ({ index, descriptor }) => watches.map((watch) => ({
2043
+ index,
2044
+ renewal: discovered("renewal", descriptor, watch, deps),
2045
+ boarding: watch.params.boardingExitDelay === void 0 ? void 0 : discovered("boarding", descriptor, watch, deps)
2046
+ }))
2047
+ );
2048
+ const onchain = deps.onchainNetwork;
2049
+ const [used, funded] = await Promise.all([
2050
+ detectUsedScripts(
2051
+ deps.indexerProvider,
2052
+ pairs.map((p) => p.renewal.contract.script)
2053
+ ),
2054
+ Promise.all(
2055
+ pairs.map(
2056
+ async ({ boarding }) => boarding && onchain ? (await deps.onchainProvider.getCoins(boarding.script.onchainAddress(onchain))).length > 0 : false
2057
+ )
2058
+ )
2059
+ ]);
2060
+ pairs.forEach(({ index, renewal, boarding }, i) => {
2061
+ if (!used.has(renewal.contract.script) && !funded[i]) return;
2062
+ out.get(index).push(renewal.contract, ...boarding ? [boarding.contract] : []);
2063
+ });
2064
+ return out;
2065
+ }
2066
+ function discovered(template, descriptor, { keys, params }, deps) {
2067
+ const owner = evenOwnerKey(deriveDescriptorLeafPubKey(descriptor));
2068
+ const serialized = executorContractParams(template, owner, keys, params);
2069
+ const script = ExecutorContractHandler.createScript(serialized);
2070
+ return {
2071
+ script,
2072
+ contract: {
2073
+ type: ExecutorContractHandler.type,
2074
+ params: serialized,
2075
+ script: hex.encode(script.pkScript),
2076
+ address: script.address(deps.network.hrp, hex.decode(keys.serverPubkey).subarray(1)).encode(),
2077
+ scope: template === "boarding" ? "onchain" : "offchain",
2078
+ label: template === "renewal" ? "Delegated renewal" : "Delegated boarding",
2079
+ metadata: { signingDescriptor: descriptor }
2080
+ }
2081
+ };
2082
+ }
2083
+
1480
2084
  // src/contracts/handlers/index.ts
1481
2085
  contractHandlers.register(DefaultContractHandler);
1482
2086
  contractHandlers.register(DelegateContractHandler);
@@ -1484,7 +2088,8 @@ contractHandlers.register(VHTLCContractHandler);
1484
2088
  contractHandlers.register(VHTLCV2ContractHandler);
1485
2089
  contractHandlers.register(BoardingContractHandler);
1486
2090
  contractHandlers.register(ArkadeContractHandler);
2091
+ contractHandlers.register(ExecutorContractHandler);
1487
2092
 
1488
- export { ArkadeContractHandler, BoardingContractHandler, DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, VHTLC, VHTLCContractHandler, VHTLCV2ContractHandler, WALLET_RECEIVE_SOURCE, contractHandlers, deriveDescriptorLeafCompressedPubKey, deriveDescriptorLeafPubKey, descriptorIsOurs, exitSequence, extractPubKey, identityDescriptor, isCltvSatisfied, isCsvSpendable, isMainnetDescriptor, normalizeToDescriptor, parseHDDescriptor, speculativeReceiveMetadata };
1489
- //# sourceMappingURL=chunk-4OY5BCIE.js.map
1490
- //# sourceMappingURL=chunk-4OY5BCIE.js.map
2093
+ export { ArkadeContractHandler, BoardingContractHandler, DEFAULT_TEMPLATE_IDS, DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, ExecutorContractHandler, VHTLC, VHTLCContractHandler, VHTLCV2ContractHandler, WALLET_RECEIVE_SOURCE, contractHandlers, defaultVariables, delegateDiscoveryKeys, deriveDescriptorLeafCompressedPubKey, deriveDescriptorLeafPubKey, descriptorIsOurs, evenOwnerKey, executorContractParams, executorKeysOf, exitSequence, extractPubKey, identityDescriptor, isCltvSatisfied, isCsvSpendable, isMainnetDescriptor, normalizeToDescriptor, parseHDDescriptor, speculativeReceiveMetadata };
2094
+ //# sourceMappingURL=chunk-4HZQSKWG.js.map
2095
+ //# sourceMappingURL=chunk-4HZQSKWG.js.map