@arkade-os/sdk 0.4.65 → 0.4.67

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 (82) hide show
  1. package/README.md +66 -15
  2. package/dist/adapters/expo.cjs +5 -5
  3. package/dist/adapters/expo.d.cts +3 -6
  4. package/dist/adapters/expo.d.ts +3 -6
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/adapters/indexedDB.cjs +5 -5
  7. package/dist/adapters/indexedDB.js +4 -4
  8. package/dist/{asyncStorageTaskQueue-Chwe60Ce.d.cts → asyncStorageTaskQueue-LTpeXYaD.d.cts} +2 -2
  9. package/dist/{asyncStorageTaskQueue-Dq_UcvDx.d.ts → asyncStorageTaskQueue-Za-e_zMk.d.ts} +2 -2
  10. package/dist/{chunk-G552MISJ.cjs → chunk-2JV4VQ7C.cjs} +56 -28
  11. package/dist/chunk-2JV4VQ7C.cjs.map +1 -0
  12. package/dist/{chunk-TFSVXMTM.js → chunk-3WIWNE4P.js} +56 -29
  13. package/dist/chunk-3WIWNE4P.js.map +1 -0
  14. package/dist/{chunk-XMOIRDLF.js → chunk-6TAQF6EV.js} +118 -16
  15. package/dist/chunk-6TAQF6EV.js.map +1 -0
  16. package/dist/{chunk-5YTSQSLE.js → chunk-AEWJU6NZ.js} +1033 -193
  17. package/dist/chunk-AEWJU6NZ.js.map +1 -0
  18. package/dist/{chunk-XN55B6EP.cjs → chunk-CO3KKSWM.cjs} +46 -19
  19. package/dist/chunk-CO3KKSWM.cjs.map +1 -0
  20. package/dist/{chunk-RESN6QHP.js → chunk-EALWOVHK.js} +4 -4
  21. package/dist/{chunk-RESN6QHP.js.map → chunk-EALWOVHK.js.map} +1 -1
  22. package/dist/{chunk-GFZNEMGL.cjs → chunk-MJUTO3PY.cjs} +1425 -574
  23. package/dist/chunk-MJUTO3PY.cjs.map +1 -0
  24. package/dist/{chunk-TYTPVPKD.js → chunk-MZFUZUTQ.js} +4 -4
  25. package/dist/{chunk-TYTPVPKD.js.map → chunk-MZFUZUTQ.js.map} +1 -1
  26. package/dist/{chunk-BABJ77NG.cjs → chunk-OIZ2V2VD.cjs} +163 -60
  27. package/dist/chunk-OIZ2V2VD.cjs.map +1 -0
  28. package/dist/{chunk-SJQM5AVB.cjs → chunk-R2YAMONM.cjs} +17 -17
  29. package/dist/{chunk-SJQM5AVB.cjs.map → chunk-R2YAMONM.cjs.map} +1 -1
  30. package/dist/{chunk-3G5V564P.js → chunk-X3VEMUVV.js} +32 -6
  31. package/dist/chunk-X3VEMUVV.js.map +1 -0
  32. package/dist/{chunk-7X744EFF.cjs → chunk-YDRZDZPP.cjs} +10 -10
  33. package/dist/{chunk-7X744EFF.cjs.map → chunk-YDRZDZPP.cjs.map} +1 -1
  34. package/dist/contracts/handlers/index.cjs +9 -9
  35. package/dist/contracts/handlers/index.d.cts +3 -3
  36. package/dist/contracts/handlers/index.d.ts +3 -3
  37. package/dist/contracts/handlers/index.js +2 -2
  38. package/dist/{delegate-BBQW61ym.d.cts → delegate-Bz2e2zXY.d.cts} +1 -1
  39. package/dist/{delegate-Dv_9OVHv.d.ts → delegate-cdmzb2f9.d.ts} +1 -1
  40. package/dist/{wallet-DJUnN939.d.ts → hdWalletCapable-BSjuUYOO.d.cts} +319 -128
  41. package/dist/{wallet-C2NvHjWB.d.cts → hdWalletCapable-Hi12xjCJ.d.ts} +319 -128
  42. package/dist/{index-fDDiA1-L.d.ts → index-BiACuWaf.d.ts} +109 -13
  43. package/dist/{index-BtTtQFUX.d.cts → index-D2GjZxBr.d.cts} +109 -13
  44. package/dist/{index-CFOMyVMt.d.cts → index-DU5o_hz7.d.cts} +275 -51
  45. package/dist/{index-CFOMyVMt.d.ts → index-DU5o_hz7.d.ts} +275 -51
  46. package/dist/index.cjs +328 -276
  47. package/dist/index.d.cts +312 -41
  48. package/dist/index.d.ts +312 -41
  49. package/dist/index.js +4 -4
  50. package/dist/repositories/realm/index.cjs +19 -19
  51. package/dist/repositories/realm/index.d.cts +2 -2
  52. package/dist/repositories/realm/index.d.ts +2 -2
  53. package/dist/repositories/realm/index.js +5 -5
  54. package/dist/repositories/sqlite/index.cjs +18 -18
  55. package/dist/repositories/sqlite/index.d.cts +2 -2
  56. package/dist/repositories/sqlite/index.d.ts +2 -2
  57. package/dist/repositories/sqlite/index.js +5 -5
  58. package/dist/{taskRunner-CIKOS2OO.d.cts → taskRunner-BZJMLQ6g.d.cts} +2 -2
  59. package/dist/{taskRunner-BDzWbpct.d.ts → taskRunner-DATaRQus.d.ts} +2 -2
  60. package/dist/wallet/expo/background.cjs +14 -14
  61. package/dist/wallet/expo/background.d.cts +3 -3
  62. package/dist/wallet/expo/background.d.ts +3 -3
  63. package/dist/wallet/expo/background.js +6 -6
  64. package/dist/wallet/expo/index.cjs +18 -14
  65. package/dist/wallet/expo/index.cjs.map +1 -1
  66. package/dist/wallet/expo/index.d.cts +7 -5
  67. package/dist/wallet/expo/index.d.ts +7 -5
  68. package/dist/wallet/expo/index.js +10 -6
  69. package/dist/wallet/expo/index.js.map +1 -1
  70. package/dist/worker/expo/index.cjs +9 -9
  71. package/dist/worker/expo/index.d.cts +4 -4
  72. package/dist/worker/expo/index.d.ts +4 -4
  73. package/dist/worker/expo/index.js +5 -5
  74. package/package.json +3 -3
  75. package/dist/chunk-3G5V564P.js.map +0 -1
  76. package/dist/chunk-5YTSQSLE.js.map +0 -1
  77. package/dist/chunk-BABJ77NG.cjs.map +0 -1
  78. package/dist/chunk-G552MISJ.cjs.map +0 -1
  79. package/dist/chunk-GFZNEMGL.cjs.map +0 -1
  80. package/dist/chunk-TFSVXMTM.js.map +0 -1
  81. package/dist/chunk-XMOIRDLF.js.map +0 -1
  82. package/dist/chunk-XN55B6EP.cjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, timelockToSequence, sequenceToTimelock, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript, SCRIPT_QUERY_CHUNK_SIZE, getNormalizedVtxos, DEFAULT_PAGE_SIZE } from './chunk-TFSVXMTM.js';
1
+ import { VtxoScript, MultisigTapscript, CSVMultisigTapscript, timelockToSequence, sequenceToTimelock, ConditionMultisigTapscript, CLTVMultisigTapscript, ConditionCSVMultisigTapscript, SCRIPT_QUERY_CHUNK_SIZE, getNormalizedVtxos, DEFAULT_PAGE_SIZE } from './chunk-3WIWNE4P.js';
2
2
  import { __export } from './chunk-NSBPE2FW.js';
3
3
  import { hex } from '@scure/base';
4
4
  import { networks, expand } from '@bitcoinerlab/descriptors-scure';
@@ -1412,6 +1412,15 @@ function asmToBytes(asm) {
1412
1412
  function bytesToASM(script) {
1413
1413
  return toASM(ArkadeScript.decode(script));
1414
1414
  }
1415
+
1416
+ // src/utils/keys.ts
1417
+ function toXOnly(key, label = "public key") {
1418
+ if (key.length === 32) return key;
1419
+ if (key.length === 33 && (key[0] === 2 || key[0] === 3)) return key.subarray(1);
1420
+ throw new Error(`${label} is not a compressed or x-only public key`);
1421
+ }
1422
+
1423
+ // src/arkade/tweak.ts
1415
1424
  var TAG_SCRIPT = "ArkScriptHash";
1416
1425
  var TAG_WITNESS = "ArkWitnessHash";
1417
1426
  function arkadeScriptHash(script) {
@@ -1425,8 +1434,7 @@ function arkadeWitnessHash(witness) {
1425
1434
  }
1426
1435
  function computeArkadeScriptPublicKey(pubKey, script) {
1427
1436
  const hash = arkadeScriptHash(script);
1428
- const xOnly = pubKey.length === 33 ? pubKey.subarray(1) : pubKey;
1429
- const point = schnorr.utils.lift_x(bytesToNumberBE(xOnly));
1437
+ const point = schnorr.utils.lift_x(bytesToNumberBE(toXOnly(pubKey, "emulator key")));
1430
1438
  const scalar = bytesToNumberBE(hash) % secp256k1.Point.CURVE().n;
1431
1439
  const tweak = secp256k1.Point.BASE.multiply(scalar);
1432
1440
  return schnorr.utils.pointToBytes(point.add(tweak));
@@ -1447,6 +1455,8 @@ var VHTLC;
1447
1455
  nonInteractiveClaimArkadeScript;
1448
1456
  nonInteractiveRefundScript;
1449
1457
  nonInteractiveRefundArkadeScript;
1458
+ nonInteractiveRefundWithoutReceiverScript;
1459
+ nonInteractiveRefundWithoutReceiverArkadeScript;
1450
1460
  constructor(options, preimageCondition) {
1451
1461
  validateOptions(options);
1452
1462
  const {
@@ -1514,22 +1524,27 @@ var VHTLC;
1514
1524
  }
1515
1525
  let arkadeScriptNir;
1516
1526
  let nonInteractiveRefundScript;
1527
+ let nonInteractiveRefundWithoutReceiverScript;
1517
1528
  if (options.nonInteractiveRefund) {
1518
1529
  arkadeScriptNir = enforcePayToMaybeAsset(
1519
1530
  options.nonInteractiveRefund.senderPkScript,
1520
1531
  options.asset
1521
1532
  );
1533
+ const nirCosigner = computeArkadeScriptPublicKey(
1534
+ options.nonInteractiveRefund.emulatorPubkey,
1535
+ arkadeScriptNir
1536
+ );
1522
1537
  nonInteractiveRefundScript = MultisigTapscript.encode({
1523
- pubkeys: [
1524
- server,
1525
- receiver,
1526
- computeArkadeScriptPublicKey(
1527
- options.nonInteractiveRefund.emulatorPubkey,
1528
- arkadeScriptNir
1529
- )
1530
- ]
1538
+ pubkeys: [server, receiver, nirCosigner]
1531
1539
  }).script;
1532
1540
  scripts.push(nonInteractiveRefundScript);
1541
+ if (options.nonInteractiveRefund.withoutReceiver) {
1542
+ nonInteractiveRefundWithoutReceiverScript = CLTVMultisigTapscript.encode({
1543
+ absoluteTimelock: refundLocktime,
1544
+ pubkeys: [server, nirCosigner]
1545
+ }).script;
1546
+ scripts.push(nonInteractiveRefundWithoutReceiverScript);
1547
+ }
1533
1548
  }
1534
1549
  super(scripts);
1535
1550
  this.options = options;
@@ -1549,6 +1564,12 @@ var VHTLC;
1549
1564
  this.nonInteractiveRefundScript = hex.encode(nonInteractiveRefundScript);
1550
1565
  this.nonInteractiveRefundArkadeScript = arkadeScriptNir;
1551
1566
  }
1567
+ if (nonInteractiveRefundWithoutReceiverScript) {
1568
+ this.nonInteractiveRefundWithoutReceiverScript = hex.encode(
1569
+ nonInteractiveRefundWithoutReceiverScript
1570
+ );
1571
+ this.nonInteractiveRefundWithoutReceiverArkadeScript = arkadeScriptNir;
1572
+ }
1552
1573
  }
1553
1574
  /** Return the collaborative claim tapleaf script. */
1554
1575
  claim() {
@@ -1594,6 +1615,67 @@ var VHTLC;
1594
1615
  this.nonInteractiveRefundArkadeScript
1595
1616
  ];
1596
1617
  }
1618
+ /**
1619
+ * Return the timelocked non-interactive refund tapleaf and its ArkadeScript.
1620
+ *
1621
+ * SPENDING THIS LEAF, CONCRETELY — confirmed from this SDK's own
1622
+ * emulator client and covenant-spend builder ({@link
1623
+ * EmulatorProvider} in `src/providers/emulator.ts`, and {@link
1624
+ * ArkadeTransactionBuilder} in `src/arkade/contract.ts`), which is
1625
+ * the general machinery every covenant leaf in this file goes
1626
+ * through:
1627
+ *
1628
+ * 1. Build the ark tx spending this leaf (this method's {@link
1629
+ * TapLeafScript} as `tapLeafScript`, this script's {@link
1630
+ * VtxoScript.encode} as `tapTree`), plus its checkpoint tx.
1631
+ * 2. Attach the ArkadeScript this method returns to the spent
1632
+ * input via an `EmulatorPacket` (type 1) — `{ vin, script:
1633
+ * <this ArkadeScript>, witness: <empty> }`, empty because the
1634
+ * script pushes its own input/output index with
1635
+ * `PUSHCURRENTINPUTINDEX` rather than reading one from the
1636
+ * witness — wrapped in an `Extension` OP_RETURN output on the
1637
+ * ark tx.
1638
+ * 3. Attach the spent input's OWN creating ark tx as `PrevArkTx` on
1639
+ * input 0 — required so the emulator can resolve that input's
1640
+ * prevout pkScript/value; it does not otherwise have them.
1641
+ * 4. POST the (base64-PSBT) ark tx and checkpoint(s) as `{ arkTx,
1642
+ * checkpointTxs }` to the emulator's `POST /v1/tx`.
1643
+ *
1644
+ * THE COVENANT CHECK the emulator runs against that ArkadeScript —
1645
+ * `enforcePayTo(senderPkScript)`, see that function above — is: the
1646
+ * output at this SAME input's index is a v1 P2TR output paying
1647
+ * `senderPkScript`, with a value at least the input's. Only on that
1648
+ * check passing does the emulator sign for `nirCosigner` (the
1649
+ * `emulatorPubkey` tweaked by this ArkadeScript's hash); the
1650
+ * response carries the fully co-signed `signedArkTx` and
1651
+ * `signedCheckpointTxs` — `ArkadeTransactionBuilder.send()`'s own
1652
+ * comment on this path: "the emulator executes the arkade script
1653
+ * and finalizes with arkd" — no separate call to arkd is made by
1654
+ * this SDK for a covenant spend.
1655
+ * Neither `server` nor `receiver` play any part in that check: this
1656
+ * leaf's tapscript still requires `server`'s own signature
1657
+ * alongside `nirCosigner`'s (see the class doc above), but that is
1658
+ * consensus-level multisig, not something the covenant enforces.
1659
+ *
1660
+ * NOT SPENDABLE UNTIL `refundLocktime` MATURES — the tapscript's
1661
+ * `OP_CHECKLOCKTIMEVERIFY` is arkd's concern, not the emulator's;
1662
+ * the emulator will happily co-sign an immature spend and arkd will
1663
+ * then refuse it. A block-height-typed `refundLocktime` (below the
1664
+ * standard height/timestamp boundary this SDK names
1665
+ * `CLTV_HEIGHT_THRESHOLD`, 500,000,000, in
1666
+ * `src/contracts/handlers/helpers.ts`) is refused by arkd for a
1667
+ * forfeit-eligible leaf independent of maturity — use a
1668
+ * seconds-typed (absolute Unix timestamp) value.
1669
+ */
1670
+ nonInteractiveRefundWithoutReceiver() {
1671
+ if (!this.nonInteractiveRefundWithoutReceiverScript || !this.nonInteractiveRefundWithoutReceiverArkadeScript) {
1672
+ throw new Error("VHTLC has no non-interactive refund-without-receiver leaf");
1673
+ }
1674
+ return [
1675
+ this.findLeaf(this.nonInteractiveRefundWithoutReceiverScript),
1676
+ this.nonInteractiveRefundWithoutReceiverArkadeScript
1677
+ ];
1678
+ }
1597
1679
  }
1598
1680
  class Script3 extends BaseScript {
1599
1681
  constructor(options) {
@@ -2093,7 +2175,14 @@ var VHTLCV2ContractHandler = {
2093
2175
  ),
2094
2176
  nonInteractiveRefundEmulatorPubkey: hex.encode(
2095
2177
  params.nonInteractiveRefund.emulatorPubkey
2096
- )
2178
+ ),
2179
+ // Spread rather than a "false"/"undefined" string: a dropped
2180
+ // flag re-derives the EIGHT-leaf script, a different pkScript,
2181
+ // and registration dies at `upsertContractRow` with an opaque
2182
+ // `Script mismatch`. Same silent-drop class as the asset keys.
2183
+ ...params.nonInteractiveRefund.withoutReceiver && {
2184
+ nonInteractiveRefundWithoutReceiver: "1"
2185
+ }
2097
2186
  },
2098
2187
  // The asset must round-trip, and its absence here used to be silent
2099
2188
  // in the worst way. `ContractManager` re-derives a contract from
@@ -2133,6 +2222,16 @@ var VHTLCV2ContractHandler = {
2133
2222
  "strictClaimAssetAmount without strictClaimAmount: reading this as 'not strict' would re-derive the default claim covenant, which is weaker than the row asked for"
2134
2223
  );
2135
2224
  }
2225
+ if (params.nonInteractiveRefundWithoutReceiver !== void 0 && !refund) {
2226
+ throw new Error(
2227
+ "nonInteractiveRefundWithoutReceiver without the nonInteractiveRefund keys it extends: reading this as 'not set' would re-derive a script without the leaf"
2228
+ );
2229
+ }
2230
+ if (params.nonInteractiveRefundWithoutReceiver !== void 0 && params.nonInteractiveRefundWithoutReceiver !== "1") {
2231
+ throw new Error(
2232
+ `nonInteractiveRefundWithoutReceiver must be "1" when present, got ` + JSON.stringify(params.nonInteractiveRefundWithoutReceiver)
2233
+ );
2234
+ }
2136
2235
  const asset = params.assetTxid !== void 0 && params.assetGroupIndex !== void 0 ? {
2137
2236
  txid: hex.decode(params.assetTxid),
2138
2237
  groupIndex: parseGroupIndex(params.assetGroupIndex)
@@ -2166,7 +2265,10 @@ var VHTLCV2ContractHandler = {
2166
2265
  ...refund && {
2167
2266
  nonInteractiveRefund: {
2168
2267
  senderPkScript: refund.destination,
2169
- emulatorPubkey: refund.emulatorPubkey
2268
+ emulatorPubkey: refund.emulatorPubkey,
2269
+ ...params.nonInteractiveRefundWithoutReceiver === "1" && {
2270
+ withoutReceiver: true
2271
+ }
2170
2272
  }
2171
2273
  }
2172
2274
  };
@@ -2933,6 +3035,6 @@ contractHandlers.register(VHTLCV2ContractHandler);
2933
3035
  contractHandlers.register(BoardingContractHandler);
2934
3036
  contractHandlers.register(ArkadeContractHandler);
2935
3037
 
2936
- export { ARKADE_OP, ARKADE_OPCODES, ARKADE_OPCODE_NAMES, ARKADE_OPCODE_VALUES, ARKADE_OPS, ArkadeContractHandler, ArkadeProgramScript, ArkadeScript, BoardingContractHandler, DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, OPCODE_NAMES, OPCODE_VALUES, SUPPORTED_PROGRAM_VERSION, VHTLC, VHTLCContractHandler, VHTLCV2ContractHandler, WALLET_RECEIVE_SOURCE, arkadeScriptHash, arkadeWitnessHash, asmToBytes, bignum_exports, bytesToASM, computeArkadeScriptPublicKey, contractHandlers, deriveDescriptorLeafCompressedPubKey, deriveDescriptorLeafPubKey, descriptorIsOurs, deserializeArkadeContractParams, fromASM, getOpcodeName, getOpcodeValue, identityDescriptor, inputName, isCltvSatisfied, isCsvSpendable, isMainnetDescriptor, normalizeToDescriptor, parseArtifact, parseHDDescriptor, resolveAsm, serializeArkadeContractParams, speculativeReceiveMetadata, stringifyArtifact, toASM, validateProgram, witnessRefToBytes };
2937
- //# sourceMappingURL=chunk-XMOIRDLF.js.map
2938
- //# sourceMappingURL=chunk-XMOIRDLF.js.map
3038
+ export { ARKADE_OP, ARKADE_OPCODES, ARKADE_OPCODE_NAMES, ARKADE_OPCODE_VALUES, ARKADE_OPS, ArkadeContractHandler, ArkadeProgramScript, ArkadeScript, BoardingContractHandler, DefaultContractHandler, DefaultVtxo, DelegateContractHandler, DelegateVtxo, OPCODE_NAMES, OPCODE_VALUES, SUPPORTED_PROGRAM_VERSION, VHTLC, VHTLCContractHandler, VHTLCV2ContractHandler, WALLET_RECEIVE_SOURCE, arkadeScriptHash, arkadeWitnessHash, asmToBytes, bignum_exports, bytesToASM, computeArkadeScriptPublicKey, contractHandlers, deriveDescriptorLeafCompressedPubKey, deriveDescriptorLeafPubKey, descriptorIsOurs, deserializeArkadeContractParams, fromASM, getOpcodeName, getOpcodeValue, identityDescriptor, inputName, isCltvSatisfied, isCsvSpendable, isMainnetDescriptor, normalizeToDescriptor, parseArtifact, parseHDDescriptor, resolveAsm, serializeArkadeContractParams, speculativeReceiveMetadata, stringifyArtifact, toASM, toXOnly, validateProgram, witnessRefToBytes };
3039
+ //# sourceMappingURL=chunk-6TAQF6EV.js.map
3040
+ //# sourceMappingURL=chunk-6TAQF6EV.js.map