@arkade-os/sdk 0.4.15 → 0.4.17

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 (197) hide show
  1. package/README.md +102 -96
  2. package/dist/cjs/arkfee/estimator.js +1 -1
  3. package/dist/cjs/arkfee/types.js +2 -1
  4. package/dist/cjs/arknote/index.js +43 -4
  5. package/dist/cjs/bip322/index.js +1 -1
  6. package/dist/cjs/contracts/arkcontract.js +1 -1
  7. package/dist/cjs/contracts/contractManager.js +60 -28
  8. package/dist/cjs/contracts/contractWatcher.js +29 -22
  9. package/dist/cjs/contracts/handlers/default.js +1 -1
  10. package/dist/cjs/contracts/handlers/delegate.js +1 -1
  11. package/dist/cjs/contracts/handlers/helpers.js +1 -1
  12. package/dist/cjs/extension/asset/assetGroup.js +92 -5
  13. package/dist/cjs/extension/asset/assetId.js +67 -3
  14. package/dist/cjs/extension/asset/assetInput.js +18 -0
  15. package/dist/cjs/extension/asset/assetOutput.js +15 -0
  16. package/dist/cjs/extension/asset/assetRef.js +66 -0
  17. package/dist/cjs/extension/asset/metadata.js +15 -0
  18. package/dist/cjs/extension/asset/packet.js +4 -1
  19. package/dist/cjs/extension/index.js +1 -1
  20. package/dist/cjs/forfeit.js +14 -0
  21. package/dist/cjs/identity/seedIdentity.js +2 -2
  22. package/dist/cjs/identity/singleKey.js +4 -0
  23. package/dist/cjs/intent/index.js +28 -12
  24. package/dist/cjs/providers/ark.js +3 -2
  25. package/dist/cjs/providers/delegator.js +20 -1
  26. package/dist/cjs/providers/expoArk.js +2 -2
  27. package/dist/cjs/providers/indexer.js +2 -2
  28. package/dist/cjs/providers/onchain.js +2 -1
  29. package/dist/cjs/repositories/realm/schemas.js +2 -2
  30. package/dist/cjs/repositories/realm/types.js +1 -1
  31. package/dist/cjs/script/address.js +37 -6
  32. package/dist/cjs/script/base.js +70 -1
  33. package/dist/cjs/script/default.js +3 -0
  34. package/dist/cjs/script/delegate.js +4 -0
  35. package/dist/cjs/script/tapscript.js +17 -2
  36. package/dist/cjs/script/vhtlc.js +35 -27
  37. package/dist/cjs/storage/fileSystem.js +1 -1
  38. package/dist/cjs/storage/inMemory.js +1 -1
  39. package/dist/cjs/storage/indexedDB.js +1 -1
  40. package/dist/cjs/storage/localStorage.js +1 -1
  41. package/dist/cjs/tree/validation.js +1 -1
  42. package/dist/cjs/utils/arkTransaction.js +5 -5
  43. package/dist/cjs/utils/bip21.js +16 -3
  44. package/dist/cjs/utils/syncCursors.js +4 -4
  45. package/dist/cjs/utils/transaction.js +1 -1
  46. package/dist/cjs/utils/transactionHistory.js +11 -11
  47. package/dist/cjs/utils/unknownFields.js +3 -3
  48. package/dist/cjs/wallet/asset-manager.js +4 -4
  49. package/dist/cjs/wallet/batch.js +5 -5
  50. package/dist/cjs/wallet/delegator.js +9 -8
  51. package/dist/cjs/wallet/expo/background.js +3 -3
  52. package/dist/cjs/wallet/expo/wallet.js +7 -7
  53. package/dist/cjs/wallet/index.js +43 -0
  54. package/dist/cjs/wallet/onchain.js +43 -5
  55. package/dist/cjs/wallet/ramps.js +44 -14
  56. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +22 -22
  57. package/dist/cjs/wallet/serviceWorker/wallet.js +28 -24
  58. package/dist/cjs/wallet/unroll.js +12 -8
  59. package/dist/cjs/wallet/utils.js +1 -1
  60. package/dist/cjs/wallet/vtxo-manager.js +122 -82
  61. package/dist/cjs/wallet/wallet.js +140 -77
  62. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +1 -1
  63. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +2 -2
  64. package/dist/cjs/worker/expo/taskRunner.js +3 -3
  65. package/dist/cjs/worker/messageBus.js +3 -0
  66. package/dist/esm/arkfee/estimator.js +1 -1
  67. package/dist/esm/arkfee/types.js +2 -1
  68. package/dist/esm/arknote/index.js +43 -4
  69. package/dist/esm/bip322/index.js +1 -1
  70. package/dist/esm/contracts/arkcontract.js +1 -1
  71. package/dist/esm/contracts/contractManager.js +60 -28
  72. package/dist/esm/contracts/contractWatcher.js +29 -22
  73. package/dist/esm/contracts/handlers/default.js +1 -1
  74. package/dist/esm/contracts/handlers/delegate.js +1 -1
  75. package/dist/esm/contracts/handlers/helpers.js +1 -1
  76. package/dist/esm/extension/asset/assetGroup.js +92 -5
  77. package/dist/esm/extension/asset/assetId.js +67 -3
  78. package/dist/esm/extension/asset/assetInput.js +18 -0
  79. package/dist/esm/extension/asset/assetOutput.js +15 -0
  80. package/dist/esm/extension/asset/assetRef.js +66 -0
  81. package/dist/esm/extension/asset/metadata.js +15 -0
  82. package/dist/esm/extension/asset/packet.js +4 -1
  83. package/dist/esm/extension/index.js +1 -1
  84. package/dist/esm/forfeit.js +14 -0
  85. package/dist/esm/identity/seedIdentity.js +2 -2
  86. package/dist/esm/identity/singleKey.js +4 -0
  87. package/dist/esm/index.js +1 -1
  88. package/dist/esm/intent/index.js +28 -12
  89. package/dist/esm/providers/ark.js +3 -2
  90. package/dist/esm/providers/delegator.js +20 -1
  91. package/dist/esm/providers/expoArk.js +2 -2
  92. package/dist/esm/providers/indexer.js +2 -2
  93. package/dist/esm/providers/onchain.js +2 -1
  94. package/dist/esm/repositories/realm/schemas.js +2 -2
  95. package/dist/esm/repositories/realm/types.js +1 -1
  96. package/dist/esm/script/address.js +37 -6
  97. package/dist/esm/script/base.js +70 -1
  98. package/dist/esm/script/default.js +3 -0
  99. package/dist/esm/script/delegate.js +4 -0
  100. package/dist/esm/script/tapscript.js +17 -2
  101. package/dist/esm/script/vhtlc.js +35 -27
  102. package/dist/esm/storage/fileSystem.js +1 -1
  103. package/dist/esm/storage/inMemory.js +1 -1
  104. package/dist/esm/storage/indexedDB.js +1 -1
  105. package/dist/esm/storage/localStorage.js +1 -1
  106. package/dist/esm/tree/validation.js +1 -1
  107. package/dist/esm/utils/arkTransaction.js +5 -5
  108. package/dist/esm/utils/bip21.js +16 -3
  109. package/dist/esm/utils/syncCursors.js +4 -4
  110. package/dist/esm/utils/transaction.js +1 -1
  111. package/dist/esm/utils/transactionHistory.js +11 -11
  112. package/dist/esm/utils/unknownFields.js +3 -3
  113. package/dist/esm/wallet/asset-manager.js +4 -4
  114. package/dist/esm/wallet/batch.js +5 -5
  115. package/dist/esm/wallet/delegator.js +9 -8
  116. package/dist/esm/wallet/expo/background.js +3 -3
  117. package/dist/esm/wallet/expo/wallet.js +7 -7
  118. package/dist/esm/wallet/index.js +43 -0
  119. package/dist/esm/wallet/onchain.js +43 -5
  120. package/dist/esm/wallet/ramps.js +44 -14
  121. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +22 -22
  122. package/dist/esm/wallet/serviceWorker/wallet.js +28 -24
  123. package/dist/esm/wallet/unroll.js +12 -8
  124. package/dist/esm/wallet/utils.js +1 -1
  125. package/dist/esm/wallet/vtxo-manager.js +121 -81
  126. package/dist/esm/wallet/wallet.js +140 -77
  127. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +1 -1
  128. package/dist/esm/worker/expo/processors/contractPollProcessor.js +2 -2
  129. package/dist/esm/worker/expo/taskRunner.js +3 -3
  130. package/dist/esm/worker/messageBus.js +3 -0
  131. package/dist/types/arkfee/estimator.d.ts +1 -1
  132. package/dist/types/arkfee/types.d.ts +2 -1
  133. package/dist/types/arknote/index.d.ts +44 -4
  134. package/dist/types/bip322/index.d.ts +1 -1
  135. package/dist/types/contracts/arkcontract.d.ts +1 -1
  136. package/dist/types/contracts/contractManager.d.ts +39 -65
  137. package/dist/types/contracts/contractWatcher.d.ts +39 -18
  138. package/dist/types/contracts/handlers/default.d.ts +1 -1
  139. package/dist/types/contracts/handlers/delegate.d.ts +1 -1
  140. package/dist/types/contracts/handlers/helpers.d.ts +1 -1
  141. package/dist/types/contracts/types.d.ts +36 -26
  142. package/dist/types/extension/asset/assetGroup.d.ts +92 -1
  143. package/dist/types/extension/asset/assetId.d.ts +67 -3
  144. package/dist/types/extension/asset/assetInput.d.ts +18 -0
  145. package/dist/types/extension/asset/assetOutput.d.ts +15 -0
  146. package/dist/types/extension/asset/assetRef.d.ts +66 -0
  147. package/dist/types/extension/asset/metadata.d.ts +15 -0
  148. package/dist/types/extension/asset/packet.d.ts +4 -1
  149. package/dist/types/extension/index.d.ts +1 -1
  150. package/dist/types/forfeit.d.ts +14 -0
  151. package/dist/types/identity/index.d.ts +16 -0
  152. package/dist/types/identity/seedIdentity.d.ts +8 -6
  153. package/dist/types/identity/singleKey.d.ts +4 -0
  154. package/dist/types/intent/index.d.ts +19 -6
  155. package/dist/types/providers/ark.d.ts +40 -2
  156. package/dist/types/providers/delegator.d.ts +54 -1
  157. package/dist/types/providers/expoArk.d.ts +2 -2
  158. package/dist/types/providers/indexer.d.ts +105 -2
  159. package/dist/types/providers/onchain.d.ts +62 -1
  160. package/dist/types/repositories/realm/schemas.d.ts +2 -2
  161. package/dist/types/repositories/realm/types.d.ts +2 -2
  162. package/dist/types/repositories/walletRepository.d.ts +16 -0
  163. package/dist/types/script/address.d.ts +35 -2
  164. package/dist/types/script/base.d.ts +66 -1
  165. package/dist/types/script/default.d.ts +3 -0
  166. package/dist/types/script/delegate.d.ts +4 -0
  167. package/dist/types/script/tapscript.d.ts +17 -2
  168. package/dist/types/script/vhtlc.d.ts +35 -27
  169. package/dist/types/storage/fileSystem.d.ts +1 -1
  170. package/dist/types/storage/inMemory.d.ts +1 -1
  171. package/dist/types/storage/index.d.ts +1 -1
  172. package/dist/types/storage/indexedDB.d.ts +1 -1
  173. package/dist/types/storage/localStorage.d.ts +1 -1
  174. package/dist/types/utils/arkTransaction.d.ts +3 -3
  175. package/dist/types/utils/bip21.d.ts +17 -0
  176. package/dist/types/utils/syncCursors.d.ts +4 -4
  177. package/dist/types/utils/transaction.d.ts +1 -1
  178. package/dist/types/utils/transactionHistory.d.ts +3 -3
  179. package/dist/types/utils/unknownFields.d.ts +5 -5
  180. package/dist/types/wallet/asset-manager.d.ts +3 -3
  181. package/dist/types/wallet/batch.d.ts +27 -7
  182. package/dist/types/wallet/delegator.d.ts +10 -0
  183. package/dist/types/wallet/expo/background.d.ts +4 -4
  184. package/dist/types/wallet/expo/wallet.d.ts +10 -10
  185. package/dist/types/wallet/index.d.ts +457 -25
  186. package/dist/types/wallet/onchain.d.ts +42 -4
  187. package/dist/types/wallet/ramps.d.ts +40 -10
  188. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +4 -4
  189. package/dist/types/wallet/serviceWorker/wallet.d.ts +71 -33
  190. package/dist/types/wallet/unroll.d.ts +8 -6
  191. package/dist/types/wallet/vtxo-manager.d.ts +146 -93
  192. package/dist/types/wallet/wallet.d.ts +91 -33
  193. package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +1 -1
  194. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +1 -1
  195. package/dist/types/worker/expo/taskRunner.d.ts +6 -6
  196. package/dist/types/worker/messageBus.d.ts +5 -3
  197. package/package.json +1 -1
@@ -22,6 +22,7 @@ export var DefaultVtxo;
22
22
  * ```
23
23
  */
24
24
  class Script extends VtxoScript {
25
+ /** Create the default virtual output script with one forfeit path and one exit path. */
25
26
  constructor(options) {
26
27
  const { pubKey, serverPubKey, csvTimelock = Script.DEFAULT_TIMELOCK, } = options;
27
28
  const forfeitScript = MultisigTapscript.encode({
@@ -36,9 +37,11 @@ export var DefaultVtxo;
36
37
  this.forfeitScript = hex.encode(forfeitScript);
37
38
  this.exitScript = hex.encode(exitScript);
38
39
  }
40
+ /** Return the forfeit tapleaf script. */
39
41
  forfeit() {
40
42
  return this.findLeaf(this.forfeitScript);
41
43
  }
44
+ /** Return the unilateral exit tapleaf script. */
42
45
  exit() {
43
46
  return this.findLeaf(this.exitScript);
44
47
  }
@@ -21,6 +21,7 @@ export var DelegateVtxo;
21
21
  * ```
22
22
  */
23
23
  class Script extends VtxoScript {
24
+ /** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
24
25
  constructor(options) {
25
26
  const defaultVtxo = new DefaultVtxo.Script(options);
26
27
  const { delegatePubKey, pubKey, serverPubKey } = options;
@@ -32,12 +33,15 @@ export var DelegateVtxo;
32
33
  this.defaultVtxo = defaultVtxo;
33
34
  this.delegateScript = hex.encode(delegateScript);
34
35
  }
36
+ /** Return the forfeit tapleaf script. */
35
37
  forfeit() {
36
38
  return this.findLeaf(this.defaultVtxo.forfeitScript);
37
39
  }
40
+ /** Return the unilateral exit tapleaf script. */
38
41
  exit() {
39
42
  return this.findLeaf(this.defaultVtxo.exitScript);
40
43
  }
44
+ /** Return the delegate tapleaf script. */
41
45
  delegate() {
42
46
  return this.findLeaf(this.delegateScript);
43
47
  }
@@ -11,9 +11,9 @@ export var TapscriptType;
11
11
  TapscriptType["CLTVMultisig"] = "cltv-multisig";
12
12
  })(TapscriptType || (TapscriptType = {}));
13
13
  /**
14
- * decodeTapscript is a function that decodes an ark tapsript from a raw script.
14
+ * decodeTapscript is a function that decodes an Arkade tapscript from a raw script.
15
15
  *
16
- * @throws {Error} if the script is not a valid ark tapscript
16
+ * @throws {Error} if the script is not a valid Arkade tapscript
17
17
  * @example
18
18
  * ```typescript
19
19
  * const arkTapscript = decodeTapscript(new Uint8Array(32));
@@ -55,6 +55,7 @@ export var MultisigTapscript;
55
55
  MultisigType[MultisigType["CHECKSIG"] = 0] = "CHECKSIG";
56
56
  MultisigType[MultisigType["CHECKSIGADD"] = 1] = "CHECKSIGADD";
57
57
  })(MultisigType = MultisigTapscript.MultisigType || (MultisigTapscript.MultisigType = {}));
58
+ /** Encode a plain multisig tapscript. */
58
59
  function encode(params) {
59
60
  if (params.pubkeys.length === 0) {
60
61
  throw new Error("At least 1 pubkey is required");
@@ -92,6 +93,7 @@ export var MultisigTapscript;
92
93
  };
93
94
  }
94
95
  MultisigTapscript.encode = encode;
96
+ /** Decode a plain multisig tapscript from raw script bytes. */
95
97
  function decode(script) {
96
98
  if (script.length === 0) {
97
99
  throw new Error("Failed to decode: script is empty");
@@ -204,6 +206,7 @@ export var MultisigTapscript;
204
206
  script,
205
207
  };
206
208
  }
209
+ /** Return true when the tapscript is a plain multisig tapscript. */
207
210
  function is(tapscript) {
208
211
  return tapscript.type === TapscriptType.Multisig;
209
212
  }
@@ -224,6 +227,7 @@ export var MultisigTapscript;
224
227
  */
225
228
  export var CSVMultisigTapscript;
226
229
  (function (CSVMultisigTapscript) {
230
+ /** Encode a CSV multisig tapscript. */
227
231
  function encode(params) {
228
232
  for (const pubkey of params.pubkeys) {
229
233
  if (pubkey.length !== 32) {
@@ -250,6 +254,7 @@ export var CSVMultisigTapscript;
250
254
  };
251
255
  }
252
256
  CSVMultisigTapscript.encode = encode;
257
+ /** Decode a CSV multisig tapscript from raw script bytes. */
253
258
  function decode(script) {
254
259
  if (script.length === 0) {
255
260
  throw new Error("Failed to decode: script is empty");
@@ -301,6 +306,7 @@ export var CSVMultisigTapscript;
301
306
  };
302
307
  }
303
308
  CSVMultisigTapscript.decode = decode;
309
+ /** Return true when the tapscript is a CSV multisig tapscript. */
304
310
  function is(tapscript) {
305
311
  return tapscript.type === TapscriptType.CSVMultisig;
306
312
  }
@@ -320,6 +326,7 @@ export var CSVMultisigTapscript;
320
326
  */
321
327
  export var ConditionCSVMultisigTapscript;
322
328
  (function (ConditionCSVMultisigTapscript) {
329
+ /** Encode a condition + CSV multisig tapscript. */
323
330
  function encode(params) {
324
331
  const script = new Uint8Array([
325
332
  ...params.conditionScript,
@@ -333,6 +340,7 @@ export var ConditionCSVMultisigTapscript;
333
340
  };
334
341
  }
335
342
  ConditionCSVMultisigTapscript.encode = encode;
343
+ /** Decode a condition + CSV multisig tapscript from raw script bytes. */
336
344
  function decode(script) {
337
345
  if (script.length === 0) {
338
346
  throw new Error("Failed to decode: script is empty");
@@ -376,6 +384,7 @@ export var ConditionCSVMultisigTapscript;
376
384
  };
377
385
  }
378
386
  ConditionCSVMultisigTapscript.decode = decode;
387
+ /** Return true when the tapscript is a condition + CSV multisig tapscript. */
379
388
  function is(tapscript) {
380
389
  return tapscript.type === TapscriptType.ConditionCSVMultisig;
381
390
  }
@@ -395,6 +404,7 @@ export var ConditionCSVMultisigTapscript;
395
404
  */
396
405
  export var ConditionMultisigTapscript;
397
406
  (function (ConditionMultisigTapscript) {
407
+ /** Encode a condition + multisig tapscript. */
398
408
  function encode(params) {
399
409
  const script = new Uint8Array([
400
410
  ...params.conditionScript,
@@ -408,6 +418,7 @@ export var ConditionMultisigTapscript;
408
418
  };
409
419
  }
410
420
  ConditionMultisigTapscript.encode = encode;
421
+ /** Decode a condition + multisig tapscript from raw script bytes. */
411
422
  function decode(script) {
412
423
  if (script.length === 0) {
413
424
  throw new Error("Failed to decode: script is empty");
@@ -451,6 +462,7 @@ export var ConditionMultisigTapscript;
451
462
  };
452
463
  }
453
464
  ConditionMultisigTapscript.decode = decode;
465
+ /** Return true when the tapscript is a condition + multisig tapscript. */
454
466
  function is(tapscript) {
455
467
  return tapscript.type === TapscriptType.ConditionMultisig;
456
468
  }
@@ -470,6 +482,7 @@ export var ConditionMultisigTapscript;
470
482
  */
471
483
  export var CLTVMultisigTapscript;
472
484
  (function (CLTVMultisigTapscript) {
485
+ /** Encode a CLTV multisig tapscript. */
473
486
  function encode(params) {
474
487
  const locktime = MinimalScriptNum.encode(params.absoluteTimelock);
475
488
  const asm = [
@@ -489,6 +502,7 @@ export var CLTVMultisigTapscript;
489
502
  };
490
503
  }
491
504
  CLTVMultisigTapscript.encode = encode;
505
+ /** Decode a CLTV multisig tapscript from raw script bytes. */
492
506
  function decode(script) {
493
507
  if (script.length === 0) {
494
508
  throw new Error("Failed to decode: script is empty");
@@ -536,6 +550,7 @@ export var CLTVMultisigTapscript;
536
550
  };
537
551
  }
538
552
  CLTVMultisigTapscript.decode = decode;
553
+ /** Return true when the tapscript is a CLTV multisig tapscript. */
539
554
  function is(tapscript) {
540
555
  return tapscript.type === TapscriptType.CLTVMultisig;
541
556
  }
@@ -2,36 +2,38 @@ import { Script } from "@scure/btc-signer";
2
2
  import { CLTVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CSVMultisigTapscript, MultisigTapscript, } from './tapscript.js';
3
3
  import { hex } from "@scure/base";
4
4
  import { VtxoScript } from './base.js';
5
- /**
6
- * Virtual Hash Time Lock Contract (VHTLC) implementation.
7
- *
8
- * VHTLC is a contract that enables atomic swaps and conditional payments
9
- * in the Ark protocol. It provides multiple spending paths:
10
- *
11
- * - **claim**: Receiver can claim funds by revealing the preimage
12
- * - **refund**: Sender and receiver can collaboratively refund
13
- * - **refundWithoutReceiver**: Sender can refund after locktime expires
14
- * - **unilateralClaim**: Receiver can claim unilaterally after delay
15
- * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
16
- * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
17
- *
18
- * @example
19
- * ```typescript
20
- * const vhtlc = new VHTLC.Script({
21
- * sender: alicePubKey,
22
- * receiver: bobPubKey,
23
- * server: serverPubKey,
24
- * preimageHash: hash160(secret),
25
- * refundLocktime: BigInt(chainTip + 10),
26
- * unilateralClaimDelay: { type: 'blocks', value: 100n },
27
- * unilateralRefundDelay: { type: 'blocks', value: 102n },
28
- * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
29
- * });
30
- * ```
31
- */
5
+ /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
32
6
  export var VHTLC;
33
7
  (function (VHTLC) {
8
+ /**
9
+ * Virtual Hash Time Lock Contract (VHTLC) script implementation.
10
+ *
11
+ * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
12
+ * It provides multiple spending paths:
13
+ *
14
+ * - **claim**: Receiver can claim funds by revealing the preimage
15
+ * - **refund**: Sender and receiver can collaboratively refund
16
+ * - **refundWithoutReceiver**: Sender can refund after locktime expires
17
+ * - **unilateralClaim**: Receiver can claim unilaterally after delay
18
+ * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
19
+ * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const vhtlc = new VHTLC.Script({
24
+ * sender: alicePubKey,
25
+ * receiver: bobPubKey,
26
+ * server: serverPubKey,
27
+ * preimageHash: hash160(secret),
28
+ * refundLocktime: BigInt(chainTip + 10),
29
+ * unilateralClaimDelay: { type: 'blocks', value: 100n },
30
+ * unilateralRefundDelay: { type: 'blocks', value: 102n },
31
+ * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
32
+ * });
33
+ * ```
34
+ */
34
35
  class Script extends VtxoScript {
36
+ /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
35
37
  constructor(options) {
36
38
  validateOptions(options);
37
39
  const { sender, receiver, server, preimageHash, refundLocktime, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, } = options;
@@ -76,21 +78,27 @@ export var VHTLC;
76
78
  this.unilateralRefundScript = hex.encode(unilateralRefundScript);
77
79
  this.unilateralRefundWithoutReceiverScript = hex.encode(unilateralRefundWithoutReceiverScript);
78
80
  }
81
+ /** Return the collaborative claim tapleaf script. */
79
82
  claim() {
80
83
  return this.findLeaf(this.claimScript);
81
84
  }
85
+ /** Return the collaborative refund tapleaf script. */
82
86
  refund() {
83
87
  return this.findLeaf(this.refundScript);
84
88
  }
89
+ /** Return the refund-without-receiver tapleaf script. */
85
90
  refundWithoutReceiver() {
86
91
  return this.findLeaf(this.refundWithoutReceiverScript);
87
92
  }
93
+ /** Return the unilateral claim tapleaf script. */
88
94
  unilateralClaim() {
89
95
  return this.findLeaf(this.unilateralClaimScript);
90
96
  }
97
+ /** Return the unilateral refund tapleaf script. */
91
98
  unilateralRefund() {
92
99
  return this.findLeaf(this.unilateralRefundScript);
93
100
  }
101
+ /** Return the unilateral refund-without-receiver tapleaf script. */
94
102
  unilateralRefundWithoutReceiver() {
95
103
  return this.findLeaf(this.unilateralRefundWithoutReceiverScript);
96
104
  }
@@ -1,7 +1,7 @@
1
1
  import * as fs from "fs/promises";
2
2
  import * as path from "path";
3
3
  /**
4
- * @deprecated Use repositories instead
4
+ * @deprecated Use repository implementations via `StorageConfig` instead.
5
5
  */
6
6
  export class FileSystemStorageAdapter {
7
7
  constructor(dirPath) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @deprecated Use repositories instead
2
+ * @deprecated Use repository implementations via `StorageConfig` instead.
3
3
  */
4
4
  export class InMemoryStorageAdapter {
5
5
  constructor() {
@@ -1,6 +1,6 @@
1
1
  import { DB_VERSION } from '../repositories/indexedDB/db.js';
2
2
  /**
3
- * @deprecated Use repositories instead
3
+ * @deprecated Use repository implementations via `StorageConfig` instead.
4
4
  */
5
5
  export class IndexedDBStorageAdapter {
6
6
  constructor(dbName, version = DB_VERSION) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @deprecated Use repositories instead
2
+ * @deprecated Use repository implementations via `StorageConfig` instead.
3
3
  */
4
4
  export class LocalStorageAdapter {
5
5
  getSafeLocalStorage() {
@@ -32,7 +32,7 @@ export function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
32
32
  if (rootInput.index !== BATCH_OUTPUT_CONNECTORS_INDEX)
33
33
  throw ErrWrongSettlementTxid;
34
34
  }
35
- // ValidateVtxoTxGraph checks if the given vtxo graph is valid.
35
+ // ValidateVtxoTxGraph checks if the given virtual output tx graph is valid.
36
36
  // The function validates:
37
37
  // - the number of nodes
38
38
  // - the number of leaves
@@ -14,7 +14,7 @@ import { Extension } from '../extension/index.js';
14
14
  *
15
15
  * Creates one checkpoint transaction per input and a virtual transaction that
16
16
  * combines all the checkpoints, sending to the specified outputs. This is the
17
- * core function for creating Ark transactions.
17
+ * core function for creating Arkade transactions.
18
18
  *
19
19
  * @param inputs - Array of virtual transaction inputs
20
20
  * @param outputs - Array of transaction outputs
@@ -92,9 +92,9 @@ function buildVirtualTx(inputs, outputs) {
92
92
  return tx;
93
93
  }
94
94
  function buildCheckpointTx(vtxo, serverUnrollScript) {
95
- // create the checkpoint vtxo script from collaborative closure
95
+ // create the checkpoint virtual output script from collaborative closure
96
96
  const collaborativeClosure = decodeTapscript(scriptFromTapLeafScript(vtxo.tapLeafScript));
97
- // create the checkpoint vtxo script combining collaborative closure and server unroll script
97
+ // create the checkpoint virtual output script combining collaborative closure and server unroll script
98
98
  const checkpointVtxoScript = new VtxoScript([
99
99
  serverUnrollScript.script,
100
100
  collaborativeClosure.script,
@@ -249,8 +249,8 @@ export function combineTapscriptSigs(signedTx, originalTx) {
249
249
  return originalTx;
250
250
  }
251
251
  /**
252
- * Validates if a given string is a valid Ark address by attempting to decode it.
253
- * @param address The Ark address to validate.
252
+ * Validates if a given string is a valid Arkade address by attempting to decode it.
253
+ * @param address The Arkade address to validate.
254
254
  * @returns True if the address is valid, false otherwise.
255
255
  */
256
256
  export function isValidArkAddress(address) {
@@ -4,6 +4,12 @@ export var BIP21Error;
4
4
  BIP21Error["INVALID_ADDRESS"] = "Invalid address";
5
5
  })(BIP21Error || (BIP21Error = {}));
6
6
  export class BIP21 {
7
+ /**
8
+ * Create a BIP21 URI from the provided parameters.
9
+ *
10
+ * @param params - BIP21 parameters to encode
11
+ * @returns Encoded BIP21 URI
12
+ */
7
13
  static create(params) {
8
14
  const { address, ...options } = params;
9
15
  // Build query string
@@ -22,7 +28,7 @@ export class BIP21 {
22
28
  queryParams[key] = value;
23
29
  }
24
30
  else if (key === "ark") {
25
- // Validate ARK address format
31
+ // Validate Arkade address format
26
32
  if (typeof value === "string" &&
27
33
  (value.startsWith("ark") || value.startsWith("tark"))) {
28
34
  queryParams[key] = value;
@@ -53,11 +59,18 @@ export class BIP21 {
53
59
  : "";
54
60
  return `bitcoin:${address ? address.toLowerCase() : ""}${query}`;
55
61
  }
62
+ /**
63
+ * Parse a BIP21 URI and return its decoded parameters.
64
+ *
65
+ * @param uri - BIP21 URI to parse
66
+ * @returns Parsed BIP21 URI data
67
+ * @throws Error if the URI does not start with the `bitcoin:` scheme
68
+ */
56
69
  static parse(uri) {
57
70
  if (!uri.toLowerCase().startsWith("bitcoin:")) {
58
71
  throw new Error(BIP21Error.INVALID_URI);
59
72
  }
60
- // Remove bitcoin: prefix, preserving case of the rest
73
+ // Remove the `bitcoin:` prefix while preserving the case of the rest.
61
74
  const withoutPrefix = uri.slice(uri.toLowerCase().indexOf("bitcoin:") + 8);
62
75
  const [address, query] = withoutPrefix.split("?");
63
76
  const params = {};
@@ -80,7 +93,7 @@ export class BIP21 {
80
93
  params[key] = amount;
81
94
  }
82
95
  else if (key === "ark") {
83
- // Validate ARK address format
96
+ // Validate Arkade address format
84
97
  if (value.startsWith("ark") || value.startsWith("tark")) {
85
98
  params[key] = value;
86
99
  }
@@ -1,6 +1,6 @@
1
1
  /** Lag behind real-time to avoid racing with indexer writes. */
2
2
  export const SAFETY_LAG_MS = 30000;
3
- /** Overlap window so boundary VTXOs are never missed. */
3
+ /** Overlap window so boundary virtual outputs are never missed. */
4
4
  export const OVERLAP_MS = 60000;
5
5
  /**
6
6
  * Per-repository mutex that serializes wallet-state mutations so that
@@ -101,8 +101,8 @@ export async function clearSyncCursors(repo, scripts) {
101
101
  * Returns `undefined` when the script has no cursor (bootstrap needed).
102
102
  *
103
103
  * No upper bound (`before`) is applied to the query so that freshly
104
- * created VTXOs are never excluded. The safety lag is applied only
105
- * when advancing the cursor (see {@link cursorCutoff}).
104
+ * created virtual outputs are never excluded. The safety lag is applied only
105
+ * when advancing the cursor (see @see cursorCutoff).
106
106
  */
107
107
  export function computeSyncWindow(cursor) {
108
108
  if (cursor === undefined)
@@ -112,7 +112,7 @@ export function computeSyncWindow(cursor) {
112
112
  }
113
113
  /**
114
114
  * The safe high-water mark for cursor advancement.
115
- * Lags behind real-time by {@link SAFETY_LAG_MS} so that VTXOs still
115
+ * Lags behind real-time by @see SAFETY_LAG_MS so that virtual outputs still
116
116
  * being indexed are re-queried on the next sync.
117
117
  *
118
118
  * When `requestStartedAt` is provided the cutoff is frozen to the
@@ -1,7 +1,7 @@
1
1
  import { Transaction as BtcSignerTransaction } from "@scure/btc-signer";
2
2
  /**
3
3
  * Transaction is a wrapper around the @scure/btc-signer Transaction class.
4
- * It adds the Ark protocol specific options to the transaction.
4
+ * It adds the Arkade protocol specific options to the transaction.
5
5
  */
6
6
  export class Transaction extends BtcSignerTransaction {
7
7
  constructor(opts) {
@@ -45,13 +45,13 @@ function subtractAssets(spent, change) {
45
45
  return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
46
46
  }
47
47
  /**
48
- * Builds the transaction history by analyzing virtual coins (VTXOs), boarding transactions, and ignored commitments.
48
+ * Builds the transaction history by analyzing virtual outputs, boarding transactions, and ignored commitments.
49
49
  * History is sorted from newest to oldest and is composed only of SENT and RECEIVED transactions.
50
50
  *
51
- * @param {VirtualCoin[]} vtxos - An array of virtual coins representing the user's transactions and balances.
51
+ * @param {VirtualCoin[]} vtxos - An array of virtual outputs representing the user's transactions and balances.
52
52
  * @param {ArkTransaction[]} allBoardingTxs - An array of boarding transactions to include in the history.
53
53
  * @param {Set<string>} commitmentsToIgnore - A set of commitment IDs that should be excluded from processing.
54
- * @return {ExtendedArkTransaction[]} A sorted array of extended Ark transactions, representing the transaction history.
54
+ * @return {ExtendedArkTransaction[]} A sorted array of extended Arkade transactions, representing the transaction history.
55
55
  */
56
56
  export async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, getTxCreatedAt) {
57
57
  const fromOldestVtxo = [...vtxos].sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
@@ -59,7 +59,7 @@ export async function buildTransactionHistory(vtxos, allBoardingTxs, commitments
59
59
  let received = [];
60
60
  for (const vtxo of fromOldestVtxo) {
61
61
  if (vtxo.status.isLeaf) {
62
- // If this vtxo is a leaf and it's not the settlement of a boarding or there's no vtxo refreshed by it,
62
+ // If this virtual output is a leaf and it's not the settlement of a boarding or there's no virtual output refreshed by it,
63
63
  // it's translated into a received batch transaction
64
64
  if (!commitmentsToIgnore.has(vtxo.virtualStatus.commitmentTxIds[0]) &&
65
65
  fromOldestVtxo.filter((v) => v.settledBy === vtxo.virtualStatus.commitmentTxIds[0]).length === 0) {
@@ -79,7 +79,7 @@ export async function buildTransactionHistory(vtxos, allBoardingTxs, commitments
79
79
  }
80
80
  }
81
81
  else if (fromOldestVtxo.filter((v) => v.arkTxId === vtxo.txid).length === 0) {
82
- // If this vtxo is preconfirmed and does not spend any other vtxos,
82
+ // If this virtual output is preconfirmed and does not spend any other virtual outputs,
83
83
  // it's translated into a received offchain transaction
84
84
  const assets = collectAssets([vtxo]);
85
85
  received.push({
@@ -92,15 +92,15 @@ export async function buildTransactionHistory(vtxos, allBoardingTxs, commitments
92
92
  ...(assets && { assets }),
93
93
  });
94
94
  }
95
- // If the vtxo is spent, it's translated into a sent transaction unless:
95
+ // If the virtual output is spent, it's translated into a sent transaction unless:
96
96
  // - it's been refreshed (we don't want to add any record in this case)
97
- // - a sent transaction has been already added to avoid duplicates (can happen if many vtxos have been spent in the same tx or forfeited in the same batch)
97
+ // - a sent transaction has been already added to avoid duplicates (can happen if many virtual outputs have been spent in the same tx or forfeited in the same batch)
98
98
  if (vtxo.isSpent) {
99
- // If the vtxo is spent offchain, it's translated into offchain sent tx
99
+ // If the virtual output is spent offchain, it's translated into an offchain sent tx
100
100
  if (vtxo.arkTxId &&
101
101
  !sent.some((s) => s.key.arkTxid === vtxo.arkTxId)) {
102
102
  const changes = fromOldestVtxo.filter((_) => _.txid === vtxo.arkTxId);
103
- // We want to find all the other VTXOs spent by the same transaction to
103
+ // We want to find all the other virtual outputs spent by the same transaction to
104
104
  // calculate the full amount of the change.
105
105
  const allSpent = fromOldestVtxo.filter((v) => v.arkTxId === vtxo.arkTxId);
106
106
  const spentAmount = allSpent.reduce((acc, v) => acc + v.value, 0);
@@ -113,7 +113,7 @@ export async function buildTransactionHistory(vtxos, allBoardingTxs, commitments
113
113
  }
114
114
  else {
115
115
  txAmount = spentAmount;
116
- // TODO: fetch the vtxo with /v1/indexer/vtxos?outpoints=<vtxo.arkTxid:0> to know when the tx was made
116
+ // TODO: fetch the virtual output with /v1/indexer/vtxos?outpoints=<vtxo.arkTxid:0> to know when the tx was made
117
117
  txTime = getTxCreatedAt
118
118
  ? ((await getTxCreatedAt(vtxo.arkTxId)) ??
119
119
  vtxo.createdAt.getTime() + 1)
@@ -130,7 +130,7 @@ export async function buildTransactionHistory(vtxos, allBoardingTxs, commitments
130
130
  ...(assets && { assets }),
131
131
  });
132
132
  }
133
- // If the vtxo is forfeited in a batch and the total sum of forfeited vtxos is bigger than the sum of new vtxos,
133
+ // If the virtual output is forfeited in a batch and the total sum of forfeited virtual outputs is bigger than the sum of new virtual outputs,
134
134
  // it's translated into an exit sent tx
135
135
  if (vtxo.settledBy &&
136
136
  !commitmentsToIgnore.has(vtxo.settledBy) &&
@@ -2,7 +2,7 @@ import * as bip68 from "bip68";
2
2
  import { RawWitness, ScriptNum } from "@scure/btc-signer";
3
3
  import { hex } from "@scure/base";
4
4
  /**
5
- * ArkPsbtFieldKey is the key values for ark psbt fields.
5
+ * ArkPsbtFieldKey are the available key names for the Arkade PSBT custom fields.
6
6
  */
7
7
  export var ArkPsbtFieldKey;
8
8
  (function (ArkPsbtFieldKey) {
@@ -12,8 +12,8 @@ export var ArkPsbtFieldKey;
12
12
  ArkPsbtFieldKey["ConditionWitness"] = "condition";
13
13
  })(ArkPsbtFieldKey || (ArkPsbtFieldKey = {}));
14
14
  /**
15
- * ArkPsbtFieldKeyType is the type of the ark psbt field key.
16
- * Every ark psbt field has key type 222.
15
+ * ArkPsbtFieldKeyType is the key type of the Arkade PSBT custom field.
16
+ * Every Arkade PSBT field has key type 222.
17
17
  */
18
18
  export const ArkPsbtFieldKeyType = 222;
19
19
  /**
@@ -23,7 +23,7 @@ export class AssetManager extends ReadonlyAssetManager {
23
23
  * @param params.amount - Amount of asset units to issue
24
24
  * @param params.controlAssetId - Optional control asset ID (for reissuable assets)
25
25
  * @param params.metadata - Optional metadata to attach to the asset
26
- * @returns Promise resolving to the ark transaction ID and asset ID
26
+ * @returns Promise resolving to the Arkade transaction ID and asset ID
27
27
  *
28
28
  * @example
29
29
  * ```typescript
@@ -108,7 +108,7 @@ export class AssetManager extends ReadonlyAssetManager {
108
108
  * @param params - Parameters for asset reissuance
109
109
  * @param params.assetId - The asset ID to reissue (control asset ID is resolved via getAssetDetails)
110
110
  * @param params.amount - Amount of additional units to issue
111
- * @returns Promise resolving to the ark transaction ID
111
+ * @returns Promise resolving to the Arkade transaction ID
112
112
  *
113
113
  * @example
114
114
  * ```typescript
@@ -215,7 +215,7 @@ export class AssetManager extends ReadonlyAssetManager {
215
215
  * @param params - Parameters for burning
216
216
  * @param params.assetId - The asset ID to burn
217
217
  * @param params.amount - Amount of units to burn
218
- * @returns Promise resolving to the ark transaction ID
218
+ * @returns Promise resolving to the Arkade transaction ID
219
219
  *
220
220
  * @example
221
221
  * ```typescript
@@ -233,7 +233,7 @@ export class AssetManager extends ReadonlyAssetManager {
233
233
  withRecoverable: false,
234
234
  });
235
235
  const assetChanges = new Map();
236
- // select vtxos with the asset to burn
236
+ // select virtual outputs with the asset to burn
237
237
  const { selected: assetCoins } = selectCoinsWithAsset(virtualCoins, params.assetId, BigInt(params.amount));
238
238
  const selectedCoins = [...assetCoins];
239
239
  let totalBtcSelected = 0;
@@ -11,7 +11,7 @@ import { hex } from "@scure/base";
11
11
  * const handler = wallet.createBatchHandler(intentId, inputs, expectedRecipients, musig2session);
12
12
  *
13
13
  * const abortController = new AbortController();
14
- * // Get event stream from Ark provider
14
+ * // Get event stream from the Arkade provider
15
15
  * const eventStream = arkProvider.getEventStream(
16
16
  * abortController.signal,
17
17
  * ['your-topic-1', 'your-topic-2']
@@ -96,7 +96,7 @@ export var Batch;
96
96
  step !== Step.TreeNoncesAggregated) {
97
97
  continue;
98
98
  }
99
- // batchIndex 0 = vtxo tree, batchIndex 1 = connector tree
99
+ // batchIndex 0 = virtual output tree, batchIndex 1 = connector tree
100
100
  if (event.batchIndex === 0) {
101
101
  flatVtxoTree.push(event.chunk);
102
102
  }
@@ -115,7 +115,7 @@ export var Batch;
115
115
  if (!vtxoTree) {
116
116
  throw new Error("vtxo tree not initialized");
117
117
  }
118
- // push signature to the vtxo tree
118
+ // push signature to the virtual output tree
119
119
  const tapKeySig = hex.decode(event.signature);
120
120
  vtxoTree.update(event.txid, (tx) => {
121
121
  tx.updateInput(0, {
@@ -131,7 +131,7 @@ export var Batch;
131
131
  if (step !== Step.BatchStarted) {
132
132
  continue;
133
133
  }
134
- // create vtxo tree from collected chunks
134
+ // create virtual output tree from collected chunks
135
135
  vtxoTree = TxTree.create(flatVtxoTree);
136
136
  const { skip } = await handler.onTreeSigningStarted(event, vtxoTree);
137
137
  if (!skip) {
@@ -153,7 +153,7 @@ export var Batch;
153
153
  if (step !== Step.TreeNoncesAggregated) {
154
154
  continue;
155
155
  }
156
- // Build vtxo tree if it hasn't been built yet
156
+ // Build virtual output tree if it hasn't been built yet
157
157
  if (!vtxoTree && flatVtxoTree.length > 0) {
158
158
  vtxoTree = TxTree.create(flatVtxoTree);
159
159
  }