@arkade-os/sdk 0.5.0-rc.26 → 0.5.0-rc.28

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 (76) hide show
  1. package/README.md +37 -0
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +4 -4
  4. package/dist/adapters/expo.d.ts +4 -4
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/{index-BfvbSL0W.d.cts → ark-CgZYyMpf.d.cts} +4369 -4205
  7. package/dist/{index-BfvbSL0W.d.ts → ark-CgZYyMpf.d.ts} +4369 -4205
  8. package/dist/{asyncStorageTaskQueue-CFWscYpG.d.cts → asyncStorageTaskQueue-B099Jii3.d.cts} +1 -1
  9. package/dist/{asyncStorageTaskQueue-DrFapzPg.d.ts → asyncStorageTaskQueue-BeQji1Ee.d.ts} +1 -1
  10. package/dist/{chunk-K2YTDYQF.cjs → chunk-3P7SXAAC.cjs} +16 -16
  11. package/dist/{chunk-K2YTDYQF.cjs.map → chunk-3P7SXAAC.cjs.map} +1 -1
  12. package/dist/{chunk-B2YMUJD5.cjs → chunk-4BT6HBZQ.cjs} +1155 -701
  13. package/dist/chunk-4BT6HBZQ.cjs.map +1 -0
  14. package/dist/{chunk-FEBAG2K2.cjs → chunk-6BJJ47JM.cjs} +18 -18
  15. package/dist/{chunk-FEBAG2K2.cjs.map → chunk-6BJJ47JM.cjs.map} +1 -1
  16. package/dist/{chunk-HPUKFTZV.js → chunk-BDTASM5W.js} +4 -4
  17. package/dist/{chunk-HPUKFTZV.js.map → chunk-BDTASM5W.js.map} +1 -1
  18. package/dist/{chunk-U5ZRDVVB.js → chunk-BIN2DVKS.js} +675 -222
  19. package/dist/chunk-BIN2DVKS.js.map +1 -0
  20. package/dist/{chunk-HTCIPDVW.js → chunk-CG7S6CDR.js} +5 -4
  21. package/dist/chunk-CG7S6CDR.js.map +1 -0
  22. package/dist/{chunk-N2VM6V6K.js → chunk-CR5YHHEM.js} +154 -51
  23. package/dist/chunk-CR5YHHEM.js.map +1 -0
  24. package/dist/{chunk-VVFCCNU2.cjs → chunk-FGKBQH5S.cjs} +5 -3
  25. package/dist/chunk-FGKBQH5S.cjs.map +1 -0
  26. package/dist/{chunk-Y5VSJURH.js → chunk-FSSINCR6.js} +4 -4
  27. package/dist/{chunk-Y5VSJURH.js.map → chunk-FSSINCR6.js.map} +1 -1
  28. package/dist/{chunk-QCD3SJOL.cjs → chunk-HFSC7T5I.cjs} +10 -10
  29. package/dist/{chunk-QCD3SJOL.cjs.map → chunk-HFSC7T5I.cjs.map} +1 -1
  30. package/dist/{chunk-5JQ5EOYE.js → chunk-PHSUZSRH.js} +3 -3
  31. package/dist/{chunk-5JQ5EOYE.js.map → chunk-PHSUZSRH.js.map} +1 -1
  32. package/dist/{chunk-CFOIHLON.cjs → chunk-YFQOJTG3.cjs} +201 -96
  33. package/dist/chunk-YFQOJTG3.cjs.map +1 -0
  34. package/dist/contracts/handlers/index.cjs +9 -9
  35. package/dist/contracts/handlers/index.d.cts +5 -5
  36. package/dist/contracts/handlers/index.d.ts +5 -5
  37. package/dist/contracts/handlers/index.js +2 -2
  38. package/dist/{delegate-Cz8FnLqi.d.ts → delegate-B8KSoeVz.d.ts} +1 -1
  39. package/dist/{delegate-r3jh7UcH.d.cts → delegate-wuf6DBpr.d.cts} +1 -1
  40. package/dist/{index-DOION7Ta.d.cts → index-1pLGuueL.d.ts} +58 -52
  41. package/dist/{index-Chgwl4dO.d.ts → index-CP3v0PVS.d.cts} +58 -52
  42. package/dist/index.cjs +328 -316
  43. package/dist/index.d.cts +332 -286
  44. package/dist/index.d.ts +332 -286
  45. package/dist/index.js +4 -4
  46. package/dist/repositories/realm/index.cjs +35 -35
  47. package/dist/repositories/realm/index.d.cts +4 -4
  48. package/dist/repositories/realm/index.d.ts +4 -4
  49. package/dist/repositories/realm/index.js +5 -5
  50. package/dist/repositories/sqlite/index.cjs +33 -33
  51. package/dist/repositories/sqlite/index.d.cts +4 -4
  52. package/dist/repositories/sqlite/index.d.ts +4 -4
  53. package/dist/repositories/sqlite/index.js +5 -5
  54. package/dist/{taskRunner-CXAcjtdU.d.ts → taskRunner-D4IF7tc8.d.cts} +1 -1
  55. package/dist/{taskRunner-BO8a-SQh.d.cts → taskRunner-DzEg63qV.d.ts} +1 -1
  56. package/dist/wallet/expo/background.cjs +14 -14
  57. package/dist/wallet/expo/background.d.cts +5 -5
  58. package/dist/wallet/expo/background.d.ts +5 -5
  59. package/dist/wallet/expo/background.js +6 -6
  60. package/dist/wallet/expo/index.cjs +15 -15
  61. package/dist/wallet/expo/index.d.cts +4 -4
  62. package/dist/wallet/expo/index.d.ts +4 -4
  63. package/dist/wallet/expo/index.js +5 -5
  64. package/dist/{wallet-CFIfUlQP.d.ts → walletRepository-BA5C6Slk.d.cts} +29 -29
  65. package/dist/{wallet-s90p-vIk.d.cts → walletRepository-BE2yiIHF.d.ts} +29 -29
  66. package/dist/worker/expo/index.cjs +9 -9
  67. package/dist/worker/expo/index.d.cts +6 -6
  68. package/dist/worker/expo/index.d.ts +6 -6
  69. package/dist/worker/expo/index.js +5 -5
  70. package/package.json +1 -1
  71. package/dist/chunk-B2YMUJD5.cjs.map +0 -1
  72. package/dist/chunk-CFOIHLON.cjs.map +0 -1
  73. package/dist/chunk-HTCIPDVW.js.map +0 -1
  74. package/dist/chunk-N2VM6V6K.js.map +0 -1
  75. package/dist/chunk-U5ZRDVVB.js.map +0 -1
  76. package/dist/chunk-VVFCCNU2.cjs.map +0 -1
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkVVFCCNU2_cjs = require('./chunk-VVFCCNU2.cjs');
3
+ var chunkFGKBQH5S_cjs = require('./chunk-FGKBQH5S.cjs');
4
4
  var base = require('@scure/base');
5
5
  var descriptorsScure = require('@bitcoinerlab/descriptors-scure');
6
6
  var btcSigner = require('@scure/btc-signer');
7
7
  var P = require('micro-packed');
8
8
  var secp256k1_js = require('@noble/curves/secp256k1.js');
9
9
  var utils_js = require('@noble/curves/utils.js');
10
+ var utils_js$1 = require('@scure/btc-signer/utils.js');
10
11
 
11
12
  function _interopNamespace(e) {
12
13
  if (e && e.__esModule) return e;
@@ -67,14 +68,14 @@ var ContractHandlerRegistry = class {
67
68
  var contractHandlers = new ContractHandlerRegistry();
68
69
  exports.DefaultVtxo = void 0;
69
70
  ((DefaultVtxo2) => {
70
- class Script3 extends chunkVVFCCNU2_cjs.VtxoScript {
71
+ class Script3 extends chunkFGKBQH5S_cjs.VtxoScript {
71
72
  /** Create the default virtual output script with one forfeit path and one exit path. */
72
73
  constructor(options) {
73
74
  const { pubKey, serverPubKey, csvTimelock } = options;
74
- const forfeitScript = chunkVVFCCNU2_cjs.MultisigTapscript.encode({
75
+ const forfeitScript = chunkFGKBQH5S_cjs.MultisigTapscript.encode({
75
76
  pubkeys: [pubKey, serverPubKey]
76
77
  }).script;
77
- const exitScript = chunkVVFCCNU2_cjs.CSVMultisigTapscript.encode({
78
+ const exitScript = chunkFGKBQH5S_cjs.CSVMultisigTapscript.encode({
78
79
  timelock: csvTimelock,
79
80
  pubkeys: [pubKey]
80
81
  }).script;
@@ -266,7 +267,7 @@ function extractPubKeyBytes(value) {
266
267
  return base.hex.decode(extractPubKey(normalizeToDescriptor(value)));
267
268
  }
268
269
  function deserializeCsvTimelock(value) {
269
- return value !== void 0 && value !== "" ? chunkVVFCCNU2_cjs.sequenceToTimelock(Number(value)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
270
+ return value !== void 0 && value !== "" ? chunkFGKBQH5S_cjs.sequenceToTimelock(Number(value)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
270
271
  }
271
272
  var CLTV_HEIGHT_THRESHOLD = 500000000n;
272
273
  function isCltvSatisfied(context, locktime) {
@@ -437,7 +438,7 @@ function deriveVhtlcTapscripts(script) {
437
438
  function isCsvSpendable(context, sequence) {
438
439
  if (sequence === void 0) return true;
439
440
  if (!context.vtxo) return false;
440
- const timelock = chunkVVFCCNU2_cjs.sequenceToTimelock(sequence);
441
+ const timelock = chunkFGKBQH5S_cjs.sequenceToTimelock(sequence);
441
442
  if (timelock.type === "blocks") {
442
443
  if (context.blockHeight === void 0 || context.vtxo.status.block_height === void 0) {
443
444
  return false;
@@ -495,21 +496,21 @@ function forfeitExitSpendablePaths(script, contract, context) {
495
496
  async function detectUsedScripts(indexerProvider, scriptHexes) {
496
497
  const used = /* @__PURE__ */ new Set();
497
498
  const unique = [...new Set(scriptHexes)];
498
- for (let offset = 0; offset < unique.length; offset += chunkVVFCCNU2_cjs.SCRIPT_QUERY_CHUNK_SIZE) {
499
- const scripts = unique.slice(offset, offset + chunkVVFCCNU2_cjs.SCRIPT_QUERY_CHUNK_SIZE);
499
+ for (let offset = 0; offset < unique.length; offset += chunkFGKBQH5S_cjs.SCRIPT_QUERY_CHUNK_SIZE) {
500
+ const scripts = unique.slice(offset, offset + chunkFGKBQH5S_cjs.SCRIPT_QUERY_CHUNK_SIZE);
500
501
  const remaining = new Set(scripts);
501
502
  let pageIndex = 0;
502
503
  let hasMore = true;
503
504
  while (hasMore && remaining.size > 0) {
504
- const { vtxos, page } = await chunkVVFCCNU2_cjs.getNormalizedVtxos(indexerProvider, {
505
+ const { vtxos, page } = await chunkFGKBQH5S_cjs.getNormalizedVtxos(indexerProvider, {
505
506
  scripts,
506
507
  pageIndex,
507
- pageSize: chunkVVFCCNU2_cjs.DEFAULT_PAGE_SIZE
508
+ pageSize: chunkFGKBQH5S_cjs.DEFAULT_PAGE_SIZE
508
509
  });
509
510
  for (const vtxo of vtxos) {
510
511
  if (remaining.delete(vtxo.script)) used.add(vtxo.script);
511
512
  }
512
- hasMore = page ? vtxos.length === chunkVVFCCNU2_cjs.DEFAULT_PAGE_SIZE : false;
513
+ hasMore = page ? vtxos.length === chunkFGKBQH5S_cjs.DEFAULT_PAGE_SIZE : false;
513
514
  pageIndex++;
514
515
  }
515
516
  }
@@ -570,7 +571,7 @@ var DefaultContractHandler = {
570
571
  return {
571
572
  pubKey: base.hex.encode(params.pubKey),
572
573
  serverPubKey: base.hex.encode(params.serverPubKey),
573
- csvTimelock: chunkVVFCCNU2_cjs.timelockToSequence(params.csvTimelock).toString()
574
+ csvTimelock: chunkFGKBQH5S_cjs.timelockToSequence(params.csvTimelock).toString()
574
575
  };
575
576
  },
576
577
  deserializeParams(params) {
@@ -617,12 +618,12 @@ function discoverDefaultRange(entries, deps) {
617
618
  }
618
619
  exports.DelegateVtxo = void 0;
619
620
  ((DelegateVtxo2) => {
620
- class Script3 extends chunkVVFCCNU2_cjs.VtxoScript {
621
+ class Script3 extends chunkFGKBQH5S_cjs.VtxoScript {
621
622
  /** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
622
623
  constructor(options) {
623
624
  const defaultVtxo = new exports.DefaultVtxo.Script(options);
624
625
  const { delegatePubKey, pubKey, serverPubKey } = options;
625
- const delegateScript = chunkVVFCCNU2_cjs.MultisigTapscript.encode({
626
+ const delegateScript = chunkFGKBQH5S_cjs.MultisigTapscript.encode({
626
627
  pubkeys: [pubKey, delegatePubKey, serverPubKey]
627
628
  }).script;
628
629
  super([...defaultVtxo.scripts, delegateScript]);
@@ -661,7 +662,7 @@ var DelegateContractHandler = {
661
662
  pubKey: base.hex.encode(params.pubKey),
662
663
  serverPubKey: base.hex.encode(params.serverPubKey),
663
664
  delegatePubKey: base.hex.encode(params.delegatePubKey),
664
- csvTimelock: chunkVVFCCNU2_cjs.timelockToSequence(params.csvTimelock).toString()
665
+ csvTimelock: chunkFGKBQH5S_cjs.timelockToSequence(params.csvTimelock).toString()
665
666
  };
666
667
  },
667
668
  deserializeParams(params) {
@@ -855,7 +856,7 @@ function getOpcodeValue(name) {
855
856
 
856
857
  // src/arkade/bignum.ts
857
858
  var bignum_exports = {};
858
- chunkVVFCCNU2_cjs.__export(bignum_exports, {
859
+ chunkFGKBQH5S_cjs.__export(bignum_exports, {
859
860
  BIGNUM_MAX_BYTES: () => BIGNUM_MAX_BYTES,
860
861
  decode: () => decode,
861
862
  encode: () => encode
@@ -1044,7 +1045,7 @@ function computeArkadeScriptPublicKey(pubKey, script) {
1044
1045
  // src/script/vhtlc.ts
1045
1046
  exports.VHTLC = void 0;
1046
1047
  ((VHTLC2) => {
1047
- class BaseScript extends chunkVVFCCNU2_cjs.VtxoScript {
1048
+ class BaseScript extends chunkFGKBQH5S_cjs.VtxoScript {
1048
1049
  options;
1049
1050
  claimScript;
1050
1051
  refundScript;
@@ -1071,27 +1072,27 @@ exports.VHTLC = void 0;
1071
1072
  unilateralRefundWithoutReceiverDelay
1072
1073
  } = options;
1073
1074
  const conditionScript = preimageCondition(preimageHash);
1074
- const claimScript = chunkVVFCCNU2_cjs.ConditionMultisigTapscript.encode({
1075
+ const claimScript = chunkFGKBQH5S_cjs.ConditionMultisigTapscript.encode({
1075
1076
  conditionScript,
1076
1077
  pubkeys: [receiver, server]
1077
1078
  }).script;
1078
- const refundScript = chunkVVFCCNU2_cjs.MultisigTapscript.encode({
1079
+ const refundScript = chunkFGKBQH5S_cjs.MultisigTapscript.encode({
1079
1080
  pubkeys: [sender, receiver, server]
1080
1081
  }).script;
1081
- const refundWithoutReceiverScript = chunkVVFCCNU2_cjs.CLTVMultisigTapscript.encode({
1082
+ const refundWithoutReceiverScript = chunkFGKBQH5S_cjs.CLTVMultisigTapscript.encode({
1082
1083
  absoluteTimelock: refundLocktime,
1083
1084
  pubkeys: [sender, server]
1084
1085
  }).script;
1085
- const unilateralClaimScript = chunkVVFCCNU2_cjs.ConditionCSVMultisigTapscript.encode({
1086
+ const unilateralClaimScript = chunkFGKBQH5S_cjs.ConditionCSVMultisigTapscript.encode({
1086
1087
  conditionScript,
1087
1088
  timelock: unilateralClaimDelay,
1088
1089
  pubkeys: [receiver]
1089
1090
  }).script;
1090
- const unilateralRefundScript = chunkVVFCCNU2_cjs.CSVMultisigTapscript.encode({
1091
+ const unilateralRefundScript = chunkFGKBQH5S_cjs.CSVMultisigTapscript.encode({
1091
1092
  timelock: unilateralRefundDelay,
1092
1093
  pubkeys: [sender, receiver]
1093
1094
  }).script;
1094
- const unilateralRefundWithoutReceiverScript = chunkVVFCCNU2_cjs.CSVMultisigTapscript.encode({
1095
+ const unilateralRefundWithoutReceiverScript = chunkFGKBQH5S_cjs.CSVMultisigTapscript.encode({
1095
1096
  timelock: unilateralRefundWithoutReceiverDelay,
1096
1097
  pubkeys: [sender]
1097
1098
  }).script;
@@ -1111,7 +1112,7 @@ exports.VHTLC = void 0;
1111
1112
  const covenants = options.nonInteractiveParameters;
1112
1113
  if (covenants) {
1113
1114
  arkadeScriptNic = enforcePayToMaybeAsset(covenants.receiverPkScript, options.asset);
1114
- nonInteractiveClaimScript = chunkVVFCCNU2_cjs.ConditionMultisigTapscript.encode({
1115
+ nonInteractiveClaimScript = chunkFGKBQH5S_cjs.ConditionMultisigTapscript.encode({
1115
1116
  conditionScript,
1116
1117
  pubkeys: [
1117
1118
  server,
@@ -1124,12 +1125,12 @@ exports.VHTLC = void 0;
1124
1125
  covenants.emulatorPubkey,
1125
1126
  arkadeScriptNir
1126
1127
  );
1127
- nonInteractiveRefundScript = chunkVVFCCNU2_cjs.MultisigTapscript.encode({
1128
+ nonInteractiveRefundScript = chunkFGKBQH5S_cjs.MultisigTapscript.encode({
1128
1129
  pubkeys: [server, receiver, nirCosigner]
1129
1130
  }).script;
1130
1131
  scripts.push(nonInteractiveRefundScript);
1131
1132
  if (covenants.legacy !== "preTimelockedRefund") {
1132
- nonInteractiveRefundWithoutReceiverScript = chunkVVFCCNU2_cjs.CLTVMultisigTapscript.encode({
1133
+ nonInteractiveRefundWithoutReceiverScript = chunkFGKBQH5S_cjs.CLTVMultisigTapscript.encode({
1133
1134
  absoluteTimelock: refundLocktime,
1134
1135
  pubkeys: [server, nirCosigner]
1135
1136
  }).script;
@@ -1405,9 +1406,9 @@ var VHTLCContractHandler = {
1405
1406
  server: base.hex.encode(params.server),
1406
1407
  hash: base.hex.encode(params.preimageHash),
1407
1408
  refundLocktime: params.refundLocktime.toString(),
1408
- claimDelay: chunkVVFCCNU2_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
1409
- refundDelay: chunkVVFCCNU2_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
1410
- refundNoReceiverDelay: chunkVVFCCNU2_cjs.timelockToSequence(
1409
+ claimDelay: chunkFGKBQH5S_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
1410
+ refundDelay: chunkFGKBQH5S_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
1411
+ refundNoReceiverDelay: chunkFGKBQH5S_cjs.timelockToSequence(
1411
1412
  params.unilateralRefundWithoutReceiverDelay
1412
1413
  ).toString()
1413
1414
  };
@@ -1419,9 +1420,9 @@ var VHTLCContractHandler = {
1419
1420
  server: base.hex.decode(params.server),
1420
1421
  preimageHash: base.hex.decode(params.hash),
1421
1422
  refundLocktime: BigInt(params.refundLocktime),
1422
- unilateralClaimDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(Number(params.claimDelay)),
1423
- unilateralRefundDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(Number(params.refundDelay)),
1424
- unilateralRefundWithoutReceiverDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(
1423
+ unilateralClaimDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(Number(params.claimDelay)),
1424
+ unilateralRefundDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(Number(params.refundDelay)),
1425
+ unilateralRefundWithoutReceiverDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(
1425
1426
  Number(params.refundNoReceiverDelay)
1426
1427
  )
1427
1428
  };
@@ -1514,9 +1515,9 @@ var VHTLCV2ContractHandler = {
1514
1515
  server: base.hex.encode(params.server),
1515
1516
  hash: base.hex.encode(params.preimageHash),
1516
1517
  refundLocktime: params.refundLocktime.toString(),
1517
- claimDelay: chunkVVFCCNU2_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
1518
- refundDelay: chunkVVFCCNU2_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
1519
- refundNoReceiverDelay: chunkVVFCCNU2_cjs.timelockToSequence(
1518
+ claimDelay: chunkFGKBQH5S_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
1519
+ refundDelay: chunkFGKBQH5S_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
1520
+ refundNoReceiverDelay: chunkFGKBQH5S_cjs.timelockToSequence(
1520
1521
  params.unilateralRefundWithoutReceiverDelay
1521
1522
  ).toString(),
1522
1523
  // Per-leaf on-disk keys predate the grouped param and older rows carry exactly these;
@@ -1594,9 +1595,9 @@ var VHTLCV2ContractHandler = {
1594
1595
  preimageHash: base.hex.decode(params.hash),
1595
1596
  refundLocktime: BigInt(params.refundLocktime),
1596
1597
  ...asset && { asset },
1597
- unilateralClaimDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(Number(params.claimDelay)),
1598
- unilateralRefundDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(Number(params.refundDelay)),
1599
- unilateralRefundWithoutReceiverDelay: chunkVVFCCNU2_cjs.sequenceToTimelock(
1598
+ unilateralClaimDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(Number(params.claimDelay)),
1599
+ unilateralRefundDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(Number(params.refundDelay)),
1600
+ unilateralRefundWithoutReceiverDelay: chunkFGKBQH5S_cjs.sequenceToTimelock(
1600
1601
  Number(params.refundNoReceiverDelay)
1601
1602
  ),
1602
1603
  ...claim && refund && {
@@ -1716,12 +1717,30 @@ var BoardingContractHandler = {
1716
1717
  }
1717
1718
  };
1718
1719
  var MinimalScriptNum = btcSigner.ScriptNum(void 0, true);
1719
- var SUPPORTED_PROGRAM_VERSION = 0;
1720
- function inputName(ref) {
1721
- return typeof ref === "string" ? ref : ref.name;
1722
- }
1720
+ var ARKADE_TYPE_ENCODINGS = {
1721
+ pubkey: "raw",
1722
+ signature: "schnorr-64",
1723
+ bytes: "raw",
1724
+ bytes20: "raw-20",
1725
+ bytes32: "raw-32",
1726
+ asset: "raw-32",
1727
+ int: "scriptnum",
1728
+ bool: "scriptnum",
1729
+ AssetGroup: "scriptnum"
1730
+ };
1731
+ var SUPPORTED_PROGRAM_VERSION = 1;
1732
+ var UnsupportedProgramVersionError = class extends Error {
1733
+ constructor(version, context) {
1734
+ super(
1735
+ `${context}: unsupported program version ${String(version)}; this SDK supports version ${SUPPORTED_PROGRAM_VERSION}. Recover it with an SDK that reads version ${String(version)}, re-create it with current params, or delete it.`
1736
+ );
1737
+ this.version = version;
1738
+ }
1739
+ version;
1740
+ name = "UnsupportedProgramVersionError";
1741
+ };
1723
1742
  function bindValue(bind, name) {
1724
- const v = bind[name];
1743
+ const v = Object.hasOwn(bind, name) ? bind[name] : void 0;
1725
1744
  if (v === void 0) throw new Error(`unbound parameter '${name}'`);
1726
1745
  return v;
1727
1746
  }
@@ -1739,7 +1758,7 @@ function resolveTimelockValue(value, args) {
1739
1758
  function resolveCsvTimelock(csv, args) {
1740
1759
  const value = resolveTimelockValue(csv.value, args);
1741
1760
  if (csv.type !== "sequence") return { type: csv.type, value };
1742
- const timelock = chunkVVFCCNU2_cjs.sequenceToCanonicalTimelock(value);
1761
+ const timelock = chunkFGKBQH5S_cjs.sequenceToCanonicalTimelock(value);
1743
1762
  if (!timelock) {
1744
1763
  throw new Error(
1745
1764
  `csv '${csv.value}' resolved to ${value}, which is not a canonical BIP68 sequence`
@@ -1810,11 +1829,28 @@ function collectParamRefs(program) {
1810
1829
  }
1811
1830
  return refs;
1812
1831
  }
1813
- var TYPED_BYTE_LENGTHS = { pubkey: 32, sig: 64 };
1832
+ var TYPED_BYTE_LENGTHS = {
1833
+ pubkey: 32,
1834
+ signature: 64,
1835
+ bytes20: 20,
1836
+ bytes32: 32,
1837
+ asset: 32
1838
+ };
1814
1839
  function validateParamValue(def, value) {
1815
- if (def.type === "int") {
1840
+ if (typeof def.type !== "string" || !Object.hasOwn(ARKADE_TYPE_ENCODINGS, def.type)) {
1841
+ throw new Error(`program parameter '${def.name}': unknown type '${def.type}'`);
1842
+ }
1843
+ if (ARKADE_TYPE_ENCODINGS[def.type] === "scriptnum") {
1816
1844
  if (typeof value !== "bigint" && typeof value !== "number") {
1817
- throw new Error(`program parameter '${def.name}' expects an int, got bytes`);
1845
+ throw new Error(`program parameter '${def.name}' expects ${def.type}, got bytes`);
1846
+ }
1847
+ if (typeof value === "number" && !Number.isSafeInteger(value)) {
1848
+ throw new Error(
1849
+ `program parameter '${def.name}' expects a safe integer; use bigint for larger values`
1850
+ );
1851
+ }
1852
+ if (def.type === "bool" && value !== 0 && value !== 1 && value !== 0n && value !== 1n) {
1853
+ throw new Error(`program parameter '${def.name}' expects a boolean encoded as 0 or 1`);
1818
1854
  }
1819
1855
  return;
1820
1856
  }
@@ -1831,11 +1867,10 @@ function validateParamValue(def, value) {
1831
1867
  }
1832
1868
  }
1833
1869
  function validateProgram(program, args) {
1834
- const params = program.params;
1835
- if (!params || !params.some((p) => typeof p !== "string")) return;
1836
- const declared = new Set(params.map(inputName));
1870
+ const params = program.params ?? [];
1871
+ const declared = new Set(params.map((p) => p.name));
1837
1872
  for (const name of declared) {
1838
- if (args[name] === void 0) {
1873
+ if (!Object.hasOwn(args, name) || args[name] === void 0) {
1839
1874
  throw new Error(`program parameter '${name}' is declared but not bound in args`);
1840
1875
  }
1841
1876
  }
@@ -1845,7 +1880,10 @@ function validateProgram(program, args) {
1845
1880
  }
1846
1881
  }
1847
1882
  for (const p of params) {
1848
- if (typeof p !== "string") validateParamValue(p, args[p.name]);
1883
+ validateParamValue(p, args[p.name]);
1884
+ }
1885
+ for (const name of Object.keys(args)) {
1886
+ if (!declared.has(name)) throw new Error(`program: undeclared argument '${name}'`);
1849
1887
  }
1850
1888
  }
1851
1889
  function isTweakedSigner(ref) {
@@ -1868,33 +1906,31 @@ function encodeTapscriptSegment(seg, pubkeys, args) {
1868
1906
  if (seg.csv) {
1869
1907
  const timelock = resolveCsvTimelock(seg.csv, args);
1870
1908
  if (seg.asm) {
1871
- return chunkVVFCCNU2_cjs.ConditionCSVMultisigTapscript.encode({
1909
+ return chunkFGKBQH5S_cjs.ConditionCSVMultisigTapscript.encode({
1872
1910
  conditionScript: resolveAsm(seg.asm, args),
1873
1911
  timelock,
1874
1912
  pubkeys
1875
1913
  });
1876
1914
  }
1877
- return chunkVVFCCNU2_cjs.CSVMultisigTapscript.encode({ timelock, pubkeys });
1915
+ return chunkFGKBQH5S_cjs.CSVMultisigTapscript.encode({ timelock, pubkeys });
1878
1916
  }
1879
1917
  if (seg.cltv !== void 0) {
1880
- return chunkVVFCCNU2_cjs.CLTVMultisigTapscript.encode({
1918
+ return chunkFGKBQH5S_cjs.CLTVMultisigTapscript.encode({
1881
1919
  absoluteTimelock: resolveTimelockValue(seg.cltv, args),
1882
1920
  pubkeys
1883
1921
  });
1884
1922
  }
1885
1923
  if (seg.asm) {
1886
- return chunkVVFCCNU2_cjs.ConditionMultisigTapscript.encode({
1924
+ return chunkFGKBQH5S_cjs.ConditionMultisigTapscript.encode({
1887
1925
  conditionScript: resolveAsm(seg.asm, args),
1888
1926
  pubkeys
1889
1927
  });
1890
1928
  }
1891
- return chunkVVFCCNU2_cjs.MultisigTapscript.encode({ pubkeys });
1929
+ return chunkFGKBQH5S_cjs.MultisigTapscript.encode({ pubkeys });
1892
1930
  }
1893
1931
  function compileFunctions(program, args, keys) {
1894
1932
  if (program.version !== SUPPORTED_PROGRAM_VERSION) {
1895
- throw new Error(
1896
- `ArkadeContract: unsupported program version ${program.version} \u2014 this SDK supports version ${SUPPORTED_PROGRAM_VERSION}`
1897
- );
1933
+ throw new UnsupportedProgramVersionError(program.version, "ArkadeContract");
1898
1934
  }
1899
1935
  const functions = program.functions;
1900
1936
  const names = Object.keys(functions);
@@ -1902,35 +1938,74 @@ function compileFunctions(program, args, keys) {
1902
1938
  throw new Error("ArkadeContract: program has no functions");
1903
1939
  }
1904
1940
  validateProgram(program, args);
1941
+ if (args.server !== void 0 && (!(args.server instanceof Uint8Array) || !utils_js$1.equalBytes(args.server, keys.serverKey))) {
1942
+ throw new Error(
1943
+ "ArkadeContract: reserved server parameter must match the contract server key"
1944
+ );
1945
+ }
1905
1946
  const defs = names.map((n) => functions[n]);
1906
- const covenant = names.find((_, i) => defs[i].arkadeScript);
1947
+ const covenants = /* @__PURE__ */ new Map();
1948
+ for (const [name, def] of Object.entries(functions)) {
1949
+ if (!def.arkadeScript) continue;
1950
+ const script = resolveAsm(def.arkadeScript.asm, args);
1951
+ for (const target of [name, ...def.group ? [def.group] : []]) {
1952
+ const previous = covenants.get(target);
1953
+ if (previous && !utils_js$1.equalBytes(previous, script)) {
1954
+ throw new Error(`ArkadeContract: ambiguous covenant '${target}'`);
1955
+ }
1956
+ covenants.set(target, script);
1957
+ }
1958
+ }
1959
+ const covenant = names.find(
1960
+ (_, i) => defs[i].arkadeScript && defs[i].tapscript.emulator !== null
1961
+ );
1907
1962
  if (covenant && !keys.emulatorKey) {
1908
1963
  throw new Error(
1909
1964
  `ArkadeContract: function '${covenant}' has an arkadeScript but no emulator is configured \u2014 pass an \`emulator\` to Arkade.connect`
1910
1965
  );
1911
1966
  }
1912
1967
  return defs.map((def, i) => {
1913
- validateTapscript(def.tapscript);
1914
1968
  const pubkeys = def.tapscript.signers.map((signer) => {
1915
1969
  if (!isTweakedSigner(signer)) return resolveSigner(signer, args);
1916
- const asm = functions[signer.fn]?.arkadeScript?.asm;
1917
- if (!asm) {
1970
+ const script = covenants.get(signer.fn);
1971
+ if (!script) {
1918
1972
  throw new Error(
1919
1973
  `ArkadeContract: function '${names[i]}' tweaks '${signer.fn}', which has no arkade script`
1920
1974
  );
1921
1975
  }
1922
- return computeArkadeScriptPublicKey(
1923
- resolveSigner(signer.tweak, args),
1924
- resolveAsm(asm, args)
1925
- );
1976
+ return computeArkadeScriptPublicKey(resolveSigner(signer.tweak, args), script);
1926
1977
  });
1927
- const arkadeScript = def.arkadeScript ? resolveAsm(def.arkadeScript.asm, args) : void 0;
1928
- const leafPubkeys = arkadeScript && def.tapscript.emulator !== null ? [...pubkeys, computeArkadeScriptPublicKey(keys.emulatorKey, arkadeScript)] : pubkeys;
1978
+ const arkadeScript = def.arkadeScript ? covenants.get(names[i]) : void 0;
1979
+ const leafPubkeys = [...pubkeys];
1980
+ if (arkadeScript && def.tapscript.emulator !== null) {
1981
+ const position = def.tapscript.emulatorIndex ?? pubkeys.length;
1982
+ if (!Number.isInteger(position) || position < 0 || position > pubkeys.length) {
1983
+ throw new Error(
1984
+ `ArkadeContract: function '${names[i]}' has an invalid emulator position ${position}`
1985
+ );
1986
+ }
1987
+ const target = def.group ? covenants.get(def.tapscript.emulator ?? def.group) : arkadeScript;
1988
+ if (!target || !utils_js$1.equalBytes(target, arkadeScript)) {
1989
+ throw new Error(
1990
+ `ArkadeContract: function '${names[i]}' has an invalid emulator covenant '${def.tapscript.emulator}'`
1991
+ );
1992
+ }
1993
+ leafPubkeys.splice(
1994
+ position,
1995
+ 0,
1996
+ computeArkadeScriptPublicKey(keys.emulatorKey, target)
1997
+ );
1998
+ } else if (def.tapscript.emulatorIndex !== void 0) {
1999
+ throw new Error(
2000
+ `ArkadeContract: function '${names[i]}' specifies an emulator position without an emulator`
2001
+ );
2002
+ }
2003
+ validateTapscript({ ...def.tapscript, signers: leafPubkeys });
1929
2004
  const leafScript = encodeTapscriptSegment(def.tapscript, leafPubkeys, args).script;
1930
2005
  return { name: names[i], def, leafScript, arkadeScript, signerKeys: pubkeys };
1931
2006
  });
1932
2007
  }
1933
- var ArkadeProgramScript = class extends chunkVVFCCNU2_cjs.VtxoScript {
2008
+ var ArkadeProgramScript = class extends chunkFGKBQH5S_cjs.VtxoScript {
1934
2009
  constructor(program, args, keys) {
1935
2010
  const partial = compileFunctions(program, args, keys);
1936
2011
  super(partial.map((p) => p.leafScript));
@@ -1968,22 +2043,57 @@ function parseArtifact(artifact) {
1968
2043
  throw new Error("parseArtifact: a tweaked signer needs string `tweak` and `fn`");
1969
2044
  };
1970
2045
  const timelockValue = (v) => typeof v === "string" && v.startsWith("$") ? v : BigInt(v);
1971
- const functions = {};
2046
+ if (artifact.version !== void 0 && artifact.version !== SUPPORTED_PROGRAM_VERSION) {
2047
+ throw new UnsupportedProgramVersionError(artifact.version, "parseArtifact");
2048
+ }
2049
+ const declarations = [artifact.params];
2050
+ for (const [name, fn] of Object.entries(artifact.functions)) {
2051
+ if (!fn || typeof fn !== "object" || Array.isArray(fn)) {
2052
+ throw new Error(`parseArtifact: function '${name}' must be an object`);
2053
+ }
2054
+ const tap = fn.tapscript;
2055
+ if (tap !== void 0 && (!tap || typeof tap !== "object" || Array.isArray(tap))) {
2056
+ throw new Error(`parseArtifact: function '${name}' tapscript must be an object`);
2057
+ }
2058
+ declarations.push(fn.inputs, tap?.signatures);
2059
+ if (tap?.emulatorIndex !== void 0 && (!Number.isInteger(tap.emulatorIndex) || tap.emulatorIndex < 0)) {
2060
+ throw new Error(`parseArtifact: function '${name}' has an invalid emulator position`);
2061
+ }
2062
+ }
2063
+ for (const defs of declarations) {
2064
+ if (defs === void 0) continue;
2065
+ if (!Array.isArray(defs)) {
2066
+ throw new Error(
2067
+ "parseArtifact: parameters, inputs and signatures require arrays of typed declarations"
2068
+ );
2069
+ }
2070
+ for (const def of defs) {
2071
+ if (!def || typeof def.name !== "string" || def.name.length === 0 || typeof def.type !== "string" || !Object.hasOwn(ARKADE_TYPE_ENCODINGS, def.type)) {
2072
+ throw new Error(
2073
+ "parseArtifact: parameters, inputs and signatures require typed { name, type } declarations"
2074
+ );
2075
+ }
2076
+ }
2077
+ }
2078
+ const functions = /* @__PURE__ */ Object.create(null);
1972
2079
  for (const [name, fn] of Object.entries(artifact.functions)) {
1973
2080
  const tap = fn.tapscript ?? {};
1974
2081
  const tapscript = {
1975
2082
  signers: (tap.signers ?? []).map(signerRef),
2083
+ ...tap.signatures ? { signatures: tap.signatures } : {},
1976
2084
  ...tap.asm ? { asm: tap.asm.map(hexToken) } : {},
1977
2085
  ...tap.witness ? { witness: tap.witness.map(hexToken) } : {},
1978
2086
  ...tap.csv ? { csv: { type: tap.csv.type, value: timelockValue(tap.csv.value) } } : {},
1979
2087
  ...tap.cltv !== void 0 ? { cltv: timelockValue(tap.cltv) } : {},
1980
- ..."emulator" in tap ? { emulator: tap.emulator } : {}
2088
+ ..."emulator" in tap ? { emulator: tap.emulator } : {},
2089
+ ...tap.emulatorIndex !== void 0 ? { emulatorIndex: tap.emulatorIndex } : {}
1981
2090
  };
1982
2091
  const arkadeScript = fn.arkadeScript ? {
1983
2092
  asm: fn.arkadeScript.asm.map(hexToken),
1984
2093
  ...fn.arkadeScript.witness ? { witness: fn.arkadeScript.witness.map(hexToken) } : {}
1985
2094
  } : void 0;
1986
2095
  functions[name] = {
2096
+ ...fn.group !== void 0 ? { group: fn.group } : {},
1987
2097
  ...fn.inputs ? { inputs: fn.inputs } : {},
1988
2098
  tapscript,
1989
2099
  ...arkadeScript ? { arkadeScript } : {}
@@ -2007,18 +2117,21 @@ function stringifyArtifact(program) {
2007
2117
  }
2008
2118
  return t;
2009
2119
  };
2010
- const functions = {};
2120
+ const functions = /* @__PURE__ */ Object.create(null);
2011
2121
  for (const [name, fn] of Object.entries(program.functions)) {
2012
2122
  const tap = fn.tapscript;
2013
2123
  functions[name] = {
2124
+ ...fn.group !== void 0 ? { group: fn.group } : {},
2014
2125
  ...fn.inputs ? { inputs: fn.inputs } : {},
2015
2126
  tapscript: {
2016
2127
  signers: tap.signers.map(token),
2128
+ ...tap.signatures ? { signatures: tap.signatures } : {},
2017
2129
  ...tap.asm ? { asm: tap.asm.map(token) } : {},
2018
2130
  ...tap.witness ? { witness: tap.witness.map(token) } : {},
2019
2131
  ...tap.csv ? { csv: { type: tap.csv.type, value: tap.csv.value.toString() } } : {},
2020
2132
  ...tap.cltv !== void 0 ? { cltv: tap.cltv.toString() } : {},
2021
- ...tap.emulator !== void 0 ? { emulator: tap.emulator } : {}
2133
+ ...tap.emulator !== void 0 ? { emulator: tap.emulator } : {},
2134
+ ...tap.emulatorIndex !== void 0 ? { emulatorIndex: tap.emulatorIndex } : {}
2022
2135
  },
2023
2136
  ...fn.arkadeScript ? {
2024
2137
  arkadeScript: {
@@ -2040,20 +2153,12 @@ function serializeArgValue(v) {
2040
2153
  if (typeof v === "bigint") return v.toString();
2041
2154
  return v;
2042
2155
  }
2043
- function parseArgValue(v) {
2044
- if (typeof v === "number") return v;
2045
- if (typeof v === "string") {
2046
- if (v.startsWith("0x")) return base.hex.decode(v.slice(2));
2047
- return BigInt(v);
2048
- }
2049
- throw new Error(`invalid arkade arg value: ${JSON.stringify(v)}`);
2050
- }
2051
2156
  function parseTypedArgValue(name, type, v) {
2052
- if (type === "int") {
2157
+ if (ARKADE_TYPE_ENCODINGS[type] === "scriptnum") {
2053
2158
  if (typeof v === "number") return v;
2054
2159
  if (typeof v === "string") return BigInt(v);
2055
2160
  throw new Error(
2056
- `arkade contract params: '${name}' expects an int, got ${JSON.stringify(v)}`
2161
+ `arkade contract params: '${name}' expects ${type}, got ${JSON.stringify(v)}`
2057
2162
  );
2058
2163
  }
2059
2164
  if (typeof v === "string" && v.startsWith("0x")) return base.hex.decode(v.slice(2));
@@ -2062,7 +2167,7 @@ function parseTypedArgValue(name, type, v) {
2062
2167
  );
2063
2168
  }
2064
2169
  function serializeArkadeContractParams(typed) {
2065
- const args = {};
2170
+ const args = /* @__PURE__ */ Object.create(null);
2066
2171
  for (const [k, v] of Object.entries(typed.args)) {
2067
2172
  args[k] = serializeArgValue(v);
2068
2173
  }
@@ -2082,15 +2187,13 @@ function deserializeArkadeContractParams(params) {
2082
2187
  throw new Error("arkade contract params: missing 'serverKey'");
2083
2188
  }
2084
2189
  const program = parseArtifact(JSON.parse(params.program));
2085
- const paramTypes = /* @__PURE__ */ new Map();
2086
- for (const p of program.params ?? []) {
2087
- if (typeof p !== "string") paramTypes.set(p.name, p.type);
2088
- }
2089
- const args = {};
2190
+ const paramTypes = new Map((program.params ?? []).map((p) => [p.name, p.type]));
2191
+ const args = /* @__PURE__ */ Object.create(null);
2090
2192
  if (params.args) {
2091
2193
  for (const [k, v] of Object.entries(JSON.parse(params.args))) {
2092
2194
  const type = paramTypes.get(k);
2093
- args[k] = type ? parseTypedArgValue(k, type, v) : parseArgValue(v);
2195
+ if (!type) throw new Error(`arkade contract params: undeclared argument '${k}'`);
2196
+ args[k] = parseTypedArgValue(k, type, v);
2094
2197
  }
2095
2198
  }
2096
2199
  return {
@@ -2148,7 +2251,7 @@ function pathsFor(script, context, opts) {
2148
2251
  continue;
2149
2252
  }
2150
2253
  if (requiresServer) continue;
2151
- const sequence = csv ? Number(chunkVVFCCNU2_cjs.timelockToSequence(csv)) : void 0;
2254
+ const sequence = csv ? Number(chunkFGKBQH5S_cjs.timelockToSequence(csv)) : void 0;
2152
2255
  if (opts.checkTimelocks && csv && !isCsvSpendable(context, sequence)) continue;
2153
2256
  if (opts.checkTimelocks && cltv !== void 0 && !isCltvSatisfied(context, cltv)) {
2154
2257
  continue;
@@ -2235,6 +2338,7 @@ exports.ARKADE_OPCODES = ARKADE_OPCODES;
2235
2338
  exports.ARKADE_OPCODE_NAMES = ARKADE_OPCODE_NAMES;
2236
2339
  exports.ARKADE_OPCODE_VALUES = ARKADE_OPCODE_VALUES;
2237
2340
  exports.ARKADE_OPS = ARKADE_OPS;
2341
+ exports.ARKADE_TYPE_ENCODINGS = ARKADE_TYPE_ENCODINGS;
2238
2342
  exports.ArkadeContractHandler = ArkadeContractHandler;
2239
2343
  exports.ArkadeProgramScript = ArkadeProgramScript;
2240
2344
  exports.ArkadeScript = ArkadeScript;
@@ -2244,6 +2348,7 @@ exports.DelegateContractHandler = DelegateContractHandler;
2244
2348
  exports.OPCODE_NAMES = OPCODE_NAMES;
2245
2349
  exports.OPCODE_VALUES = OPCODE_VALUES;
2246
2350
  exports.SUPPORTED_PROGRAM_VERSION = SUPPORTED_PROGRAM_VERSION;
2351
+ exports.UnsupportedProgramVersionError = UnsupportedProgramVersionError;
2247
2352
  exports.VHTLCContractHandler = VHTLCContractHandler;
2248
2353
  exports.VHTLCV2ContractHandler = VHTLCV2ContractHandler;
2249
2354
  exports.WALLET_RECEIVE_SOURCE = WALLET_RECEIVE_SOURCE;
@@ -2263,7 +2368,6 @@ exports.fromASM = fromASM;
2263
2368
  exports.getOpcodeName = getOpcodeName;
2264
2369
  exports.getOpcodeValue = getOpcodeValue;
2265
2370
  exports.identityDescriptor = identityDescriptor;
2266
- exports.inputName = inputName;
2267
2371
  exports.isCltvSatisfied = isCltvSatisfied;
2268
2372
  exports.isCsvSpendable = isCsvSpendable;
2269
2373
  exports.isMainnetDescriptor = isMainnetDescriptor;
@@ -2276,7 +2380,8 @@ exports.speculativeReceiveMetadata = speculativeReceiveMetadata;
2276
2380
  exports.stringifyArtifact = stringifyArtifact;
2277
2381
  exports.toASM = toASM;
2278
2382
  exports.toXOnly = toXOnly;
2383
+ exports.validateParamValue = validateParamValue;
2279
2384
  exports.validateProgram = validateProgram;
2280
2385
  exports.witnessRefToBytes = witnessRefToBytes;
2281
- //# sourceMappingURL=chunk-CFOIHLON.cjs.map
2282
- //# sourceMappingURL=chunk-CFOIHLON.cjs.map
2386
+ //# sourceMappingURL=chunk-YFQOJTG3.cjs.map
2387
+ //# sourceMappingURL=chunk-YFQOJTG3.cjs.map