@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
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RestDelegatorProvider = void 0;
4
4
  const intent_1 = require("../intent");
5
5
  /**
6
- * REST-based Delegator provider implementation.
6
+ * REST-based delegation provider implementation.
7
7
  * @example
8
8
  * ```typescript
9
9
  * const provider = new RestDelegatorProvider('https://delegator.example.com');
@@ -12,9 +12,22 @@ const intent_1 = require("../intent");
12
12
  * ```
13
13
  */
14
14
  class RestDelegatorProvider {
15
+ /**
16
+ * Create a REST delegation provider targeting the given base URL.
17
+ *
18
+ * @param url - Base URL of the delegation service
19
+ */
15
20
  constructor(url) {
16
21
  this.url = url;
17
22
  }
23
+ /**
24
+ * Submit a delegation request to the remote delegation service.
25
+ *
26
+ * @param intent - Signed register intent to delegate
27
+ * @param forfeitTxs - Forfeit transactions associated with the delegation request
28
+ * @param options - Optional delegate behavior flags
29
+ * @throws Error if the remote service rejects the request
30
+ */
18
31
  async delegate(intent, forfeitTxs, options) {
19
32
  const url = `${this.url}/v1/delegate`;
20
33
  const response = await fetch(url, {
@@ -36,6 +49,12 @@ class RestDelegatorProvider {
36
49
  throw new Error(`Failed to delegate: ${errorText}`);
37
50
  }
38
51
  }
52
+ /**
53
+ * Fetch delegate metadata exposed by the remote delegation service.
54
+ *
55
+ * @returns Delegate identity and fee information
56
+ * @throws Error if the remote service returns invalid data
57
+ */
39
58
  async getDelegateInfo() {
40
59
  const url = `${this.url}/v1/delegator/info`;
41
60
  const response = await fetch(url);
@@ -4,7 +4,7 @@ exports.ExpoArkProvider = void 0;
4
4
  const ark_1 = require("./ark");
5
5
  const expoUtils_1 = require("./expoUtils");
6
6
  /**
7
- * Expo-compatible Ark provider implementation using expo/fetch for SSE support.
7
+ * Expo-compatible Arkade provider implementation using expo/fetch for SSE support.
8
8
  * This provider works specifically in React Native/Expo environments where
9
9
  * standard EventSource is not available but expo/fetch provides SSE capabilities.
10
10
  *
@@ -12,7 +12,7 @@ const expoUtils_1 = require("./expoUtils");
12
12
  * ```typescript
13
13
  * import { ExpoArkProvider } from '@arkade-os/sdk/providers/expo';
14
14
  *
15
- * const provider = new ExpoArkProvider('https://ark.example.com');
15
+ * const provider = new ExpoArkProvider('https://arkade.computer');
16
16
  * const info = await provider.getInfo();
17
17
  * ```
18
18
  */
@@ -20,11 +20,11 @@ var ChainTxType;
20
20
  ChainTxType["CHECKPOINT"] = "INDEXER_CHAINED_TX_TYPE_CHECKPOINT";
21
21
  })(ChainTxType || (exports.ChainTxType = ChainTxType = {}));
22
22
  /**
23
- * REST-based Indexer provider implementation.
23
+ * REST-based indexer provider implementation.
24
24
  * @see https://buf.build/arkade-os/arkd/docs/main:ark.v1#ark.v1.IndexerService
25
25
  * @example
26
26
  * ```typescript
27
- * const provider = new RestIndexerProvider('https://ark.indexer.example.com');
27
+ * const provider = new RestIndexerProvider('https://arkade.computer');
28
28
  * const commitmentTx = await provider.getCommitmentTx("6686af8f3be3517880821f62e6c3d749b9d6713736a1d8e229a55daa659446b2");
29
29
  * ```
30
30
  */
@@ -13,11 +13,12 @@ exports.ESPLORA_URL = {
13
13
  };
14
14
  /**
15
15
  * Implementation of the onchain provider interface for esplora REST API.
16
+ *
16
17
  * @see https://mempool.space/docs/api/rest
17
18
  * @example
18
19
  * ```typescript
19
20
  * const provider = new EsploraProvider("https://mempool.space/api");
20
- * const utxos = await provider.getCoins("bcrt1q679zsd45msawvr7782r0twvmukns3drlstjt77");
21
+ * const outputs = await provider.getCoins("bcrt1q679zsd45msawvr7782r0twvmukns3drlstjt77");
21
22
  * ```
22
23
  */
23
24
  class EsploraProvider {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Realm object schemas for the Ark wallet.
3
+ * Realm object schemas for the Arkade wallet.
4
4
  *
5
5
  * All schema names are prefixed with "Ark" to avoid collisions with
6
6
  * other Realm schemas in the consuming application.
@@ -96,7 +96,7 @@ exports.ArkContractSchema = {
96
96
  },
97
97
  };
98
98
  /**
99
- * All Realm schemas needed by the Ark wallet repositories.
99
+ * All Realm schemas needed by the Arkade wallet repositories.
100
100
  * Pass this array to your Realm configuration's `schema` property.
101
101
  */
102
102
  exports.ArkRealmSchemas = [
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Minimal interface for the subset of the Realm API used by the
4
- * Ark repositories. Consumers pass their real Realm instance and
4
+ * Arkade repositories. Consumers pass their real Realm instance and
5
5
  * the compiler validates it satisfies this shape.
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,13 +4,20 @@ exports.ArkAddress = void 0;
4
4
  const base_1 = require("@scure/base");
5
5
  const script_js_1 = require("@scure/btc-signer/script.js");
6
6
  /**
7
- * ArkAddress allows to create and decode bech32m encoded ark address.
8
- * An ark address is composed of:
7
+ * ArkAddress allows creating and decoding bech32m-encoded Arkade addresses.
8
+ *
9
+ * An Arkade address is composed of:
9
10
  * - a human readable prefix (hrp)
10
11
  * - a version byte (1 byte)
11
12
  * - a server public key (32 bytes)
12
13
  * - a vtxo taproot public key (32 bytes)
13
14
  *
15
+ * @remarks
16
+ * This is an Arkade-specific address format.
17
+ * It is distinct from the Taproot onchain address returned by `VtxoScript.onchainAddress`.
18
+ *
19
+ * @see VtxoScript
20
+ *
14
21
  * @example
15
22
  * ```typescript
16
23
  * const address = new ArkAddress(
@@ -26,6 +33,16 @@ const script_js_1 = require("@scure/btc-signer/script.js");
26
33
  * ```
27
34
  */
28
35
  class ArkAddress {
36
+ /**
37
+ * Create an Arkade address from its server key, vtxo taproot public key, and prefix.
38
+ *
39
+ * @param serverPubKey - 32-byte Arkade server public key
40
+ * @param vtxoTaprootKey - 32-byte tweaked vtxo taproot public key
41
+ * @param hrp - Bech32 human-readable prefix
42
+ * @param version - Address version byte
43
+ * @defaultValue `version = 0`
44
+ * @throws Error if either public key is not 32 bytes long
45
+ */
29
46
  constructor(serverPubKey, vtxoTaprootKey, hrp, version = 0) {
30
47
  this.serverPubKey = serverPubKey;
31
48
  this.vtxoTaprootKey = vtxoTaprootKey;
@@ -40,13 +57,21 @@ class ArkAddress {
40
57
  vtxoTaprootKey.length);
41
58
  }
42
59
  }
60
+ /**
61
+ * Decode an Arkade address from its bech32m string form.
62
+ *
63
+ * @param address - Bech32m-encoded Arkade address
64
+ * @returns Decoded Arkade address
65
+ * @throws Error if the address is malformed or has an invalid payload length
66
+ * @see encode
67
+ */
43
68
  static decode(address) {
44
69
  const decoded = base_1.bech32m.decodeUnsafe(address, 1023);
45
70
  if (!decoded) {
46
71
  throw new Error("Invalid address");
47
72
  }
48
73
  const data = new Uint8Array(base_1.bech32m.fromWords(decoded.words));
49
- // First the version byte, then 32 bytes server pubkey, then 32 bytes vtxo taproot pubkey
74
+ // First the version byte, then 32 bytes server pubkey, then 32 bytes vtxo taproot public key.
50
75
  if (data.length !== 1 + 32 + 32) {
51
76
  throw new Error("Invalid data length, expected 65 bytes, got " + data.length);
52
77
  }
@@ -55,8 +80,14 @@ class ArkAddress {
55
80
  const vtxoTaprootPubKey = data.slice(33, 65);
56
81
  return new ArkAddress(serverPubKey, vtxoTaprootPubKey, decoded.prefix, version);
57
82
  }
83
+ /**
84
+ * Encode the address to its bech32m string form.
85
+ *
86
+ * @returns Bech32m-encoded Arkade address
87
+ * @see decode
88
+ */
58
89
  encode() {
59
- // Combine version byte, server pubkey, and vtxo taproot pubkey
90
+ // Combine version byte, server pubkey, and vtxo taproot public key.
60
91
  const data = new Uint8Array(1 + 32 + 32);
61
92
  data[0] = this.version;
62
93
  data.set(this.serverPubKey, 1);
@@ -64,11 +95,11 @@ class ArkAddress {
64
95
  const words = base_1.bech32m.toWords(data);
65
96
  return base_1.bech32m.encode(this.hrp, words, 1023);
66
97
  }
67
- // pkScript is the script that should be used to send non-dust funds to the address
98
+ /** ScriptPubKey used to send non-dust funds to the address. */
68
99
  get pkScript() {
69
100
  return script_js_1.Script.encode(["OP_1", this.vtxoTaprootKey]);
70
101
  }
71
- // subdustPkScript is the script that should be used to send sub-dust funds to the address
102
+ /** ScriptPubKey used to send sub-dust funds to the address. */
72
103
  get subdustPkScript() {
73
104
  return script_js_1.Script.encode(["RETURN", this.vtxoTaprootKey]);
74
105
  }
@@ -49,18 +49,35 @@ function scriptFromTapLeafScript(leaf) {
49
49
  }
50
50
  /**
51
51
  * VtxoScript is a script that contains a list of tapleaf scripts.
52
- * It is used to create vtxo scripts.
52
+ * It is used to create virtual output scripts.
53
+ *
54
+ * @see ArkAddress
53
55
  *
54
56
  * @example
55
57
  * ```typescript
56
58
  * const vtxoScript = new VtxoScript([new Uint8Array(32), new Uint8Array(32)]);
59
+ * ```
57
60
  */
58
61
  class VtxoScript {
62
+ /**
63
+ * Decode a virtual output script from an encoded TapTree.
64
+ *
65
+ * @param tapTree - Encoded TapTree bytes
66
+ * @returns Decoded virtual output script
67
+ * @throws Error if the TapTree cannot be decoded into a valid script set
68
+ * @see encode
69
+ */
59
70
  static decode(tapTree) {
60
71
  const leaves = exports.TapTreeCoder.decode(tapTree);
61
72
  const scripts = leaves.map((leaf) => leaf.script);
62
73
  return new VtxoScript(scripts);
63
74
  }
75
+ /**
76
+ * Create a virtual output script from its tapleaf scripts.
77
+ *
78
+ * @param scripts - Raw tapscript bytes for each leaf
79
+ * @throws Error if the provided leaves cannot produce a valid Taproot tree
80
+ */
64
81
  constructor(scripts) {
65
82
  this.scripts = scripts;
66
83
  // reverse the scripts if the number of scripts is odd
@@ -81,6 +98,12 @@ class VtxoScript {
81
98
  this.leaves = payment.tapLeafScript;
82
99
  this.tweakedPublicKey = payment.tweakedPubkey;
83
100
  }
101
+ /**
102
+ * Encode the virtual output script to a TapTree byte representation.
103
+ *
104
+ * @returns Encoded TapTree bytes
105
+ * @see decode
106
+ */
84
107
  encode() {
85
108
  const tapTree = exports.TapTreeCoder.encode(this.scripts.map((script) => ({
86
109
  depth: 1,
@@ -89,18 +112,40 @@ class VtxoScript {
89
112
  })));
90
113
  return tapTree;
91
114
  }
115
+ /**
116
+ * Build the Arkade address corresponding to this virtual output script.
117
+ *
118
+ * @param prefix - Bech32 human-readable prefix
119
+ * @param serverPubKey - 32-byte Arkade server public key
120
+ * @returns Arkade address for this script
121
+ * @see ArkAddress
122
+ */
92
123
  address(prefix, serverPubKey) {
93
124
  return new address_1.ArkAddress(serverPubKey, this.tweakedPublicKey, prefix);
94
125
  }
95
126
  get pkScript() {
96
127
  return btc_signer_1.Script.encode(["OP_1", this.tweakedPublicKey]);
97
128
  }
129
+ /**
130
+ * Build the Taproot onchain address corresponding to this virtual output script.
131
+ *
132
+ * @param network - Bitcoin network descriptor
133
+ * @returns Taproot onchain address
134
+ * @see address
135
+ */
98
136
  onchainAddress(network) {
99
137
  return (0, btc_signer_1.Address)(network).encode({
100
138
  type: "tr",
101
139
  pubkey: this.tweakedPublicKey,
102
140
  });
103
141
  }
142
+ /**
143
+ * Look up a tapleaf script by its hex-encoded tapscript body.
144
+ *
145
+ * @param scriptHex - Hex-encoded tapscript body without the leaf version byte
146
+ * @returns Matching tapleaf script
147
+ * @throws Error if no matching leaf exists
148
+ */
104
149
  findLeaf(scriptHex) {
105
150
  const leaf = this.leaves.find((leaf) => base_1.hex.encode(scriptFromTapLeafScript(leaf)) === scriptHex);
106
151
  if (!leaf) {
@@ -108,6 +153,12 @@ class VtxoScript {
108
153
  }
109
154
  return leaf;
110
155
  }
156
+ /**
157
+ * Return all unilateral exit paths embedded in the virtual output script.
158
+ *
159
+ * @returns CSV-based exit paths found in the leaves
160
+ * @see getSequence
161
+ */
111
162
  exitPaths() {
112
163
  const paths = [];
113
164
  for (const leaf of this.leaves) {
@@ -130,6 +181,24 @@ class VtxoScript {
130
181
  }
131
182
  }
132
183
  exports.VtxoScript = VtxoScript;
184
+ /**
185
+ * Extract the timelock value encoded in a timelocked tapleaf, if any.
186
+ *
187
+ * The return value is unit-ambiguous: for a CSV leaf it is a BIP-68
188
+ * nSequence (relative timelock); for a CLTV leaf it is an absolute
189
+ * nLockTime. Callers must know which leaf shape they are inspecting to
190
+ * interpret the number correctly, and must not copy a CSV result into
191
+ * `Transaction.lockTime` (or vice versa).
192
+ *
193
+ * @param tapLeafScript - Tapleaf script to inspect
194
+ * @returns The encoded timelock value, or `undefined` when neither a CSV
195
+ * nor CLTV path is present
196
+ * @see VtxoScript.exitPaths
197
+ */
198
+ // TODO(next-major): return a discriminated union
199
+ // (`{ kind: "relative", nSequence } | { kind: "absolute", lockTime }`)
200
+ // so callers can't conflate the two. Deferred because changing the
201
+ // return type is a breaking change.
133
202
  function getSequence(tapLeafScript) {
134
203
  let sequence = undefined;
135
204
  try {
@@ -25,6 +25,7 @@ var DefaultVtxo;
25
25
  * ```
26
26
  */
27
27
  class Script extends base_1.VtxoScript {
28
+ /** Create the default virtual output script with one forfeit path and one exit path. */
28
29
  constructor(options) {
29
30
  const { pubKey, serverPubKey, csvTimelock = Script.DEFAULT_TIMELOCK, } = options;
30
31
  const forfeitScript = tapscript_1.MultisigTapscript.encode({
@@ -39,9 +40,11 @@ var DefaultVtxo;
39
40
  this.forfeitScript = base_2.hex.encode(forfeitScript);
40
41
  this.exitScript = base_2.hex.encode(exitScript);
41
42
  }
43
+ /** Return the forfeit tapleaf script. */
42
44
  forfeit() {
43
45
  return this.findLeaf(this.forfeitScript);
44
46
  }
47
+ /** Return the unilateral exit tapleaf script. */
45
48
  exit() {
46
49
  return this.findLeaf(this.exitScript);
47
50
  }
@@ -24,6 +24,7 @@ var DelegateVtxo;
24
24
  * ```
25
25
  */
26
26
  class Script extends base_1.VtxoScript {
27
+ /** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
27
28
  constructor(options) {
28
29
  const defaultVtxo = new default_1.DefaultVtxo.Script(options);
29
30
  const { delegatePubKey, pubKey, serverPubKey } = options;
@@ -35,12 +36,15 @@ var DelegateVtxo;
35
36
  this.defaultVtxo = defaultVtxo;
36
37
  this.delegateScript = base_2.hex.encode(delegateScript);
37
38
  }
39
+ /** Return the forfeit tapleaf script. */
38
40
  forfeit() {
39
41
  return this.findLeaf(this.defaultVtxo.forfeitScript);
40
42
  }
43
+ /** Return the unilateral exit tapleaf script. */
41
44
  exit() {
42
45
  return this.findLeaf(this.defaultVtxo.exitScript);
43
46
  }
47
+ /** Return the delegate tapleaf script. */
44
48
  delegate() {
45
49
  return this.findLeaf(this.delegateScript);
46
50
  }
@@ -48,9 +48,9 @@ var TapscriptType;
48
48
  TapscriptType["CLTVMultisig"] = "cltv-multisig";
49
49
  })(TapscriptType || (exports.TapscriptType = TapscriptType = {}));
50
50
  /**
51
- * decodeTapscript is a function that decodes an ark tapsript from a raw script.
51
+ * decodeTapscript is a function that decodes an Arkade tapscript from a raw script.
52
52
  *
53
- * @throws {Error} if the script is not a valid ark tapscript
53
+ * @throws {Error} if the script is not a valid Arkade tapscript
54
54
  * @example
55
55
  * ```typescript
56
56
  * const arkTapscript = decodeTapscript(new Uint8Array(32));
@@ -92,6 +92,7 @@ var MultisigTapscript;
92
92
  MultisigType[MultisigType["CHECKSIG"] = 0] = "CHECKSIG";
93
93
  MultisigType[MultisigType["CHECKSIGADD"] = 1] = "CHECKSIGADD";
94
94
  })(MultisigType = MultisigTapscript.MultisigType || (MultisigTapscript.MultisigType = {}));
95
+ /** Encode a plain multisig tapscript. */
95
96
  function encode(params) {
96
97
  if (params.pubkeys.length === 0) {
97
98
  throw new Error("At least 1 pubkey is required");
@@ -129,6 +130,7 @@ var MultisigTapscript;
129
130
  };
130
131
  }
131
132
  MultisigTapscript.encode = encode;
133
+ /** Decode a plain multisig tapscript from raw script bytes. */
132
134
  function decode(script) {
133
135
  if (script.length === 0) {
134
136
  throw new Error("Failed to decode: script is empty");
@@ -241,6 +243,7 @@ var MultisigTapscript;
241
243
  script,
242
244
  };
243
245
  }
246
+ /** Return true when the tapscript is a plain multisig tapscript. */
244
247
  function is(tapscript) {
245
248
  return tapscript.type === TapscriptType.Multisig;
246
249
  }
@@ -261,6 +264,7 @@ var MultisigTapscript;
261
264
  */
262
265
  var CSVMultisigTapscript;
263
266
  (function (CSVMultisigTapscript) {
267
+ /** Encode a CSV multisig tapscript. */
264
268
  function encode(params) {
265
269
  for (const pubkey of params.pubkeys) {
266
270
  if (pubkey.length !== 32) {
@@ -287,6 +291,7 @@ var CSVMultisigTapscript;
287
291
  };
288
292
  }
289
293
  CSVMultisigTapscript.encode = encode;
294
+ /** Decode a CSV multisig tapscript from raw script bytes. */
290
295
  function decode(script) {
291
296
  if (script.length === 0) {
292
297
  throw new Error("Failed to decode: script is empty");
@@ -338,6 +343,7 @@ var CSVMultisigTapscript;
338
343
  };
339
344
  }
340
345
  CSVMultisigTapscript.decode = decode;
346
+ /** Return true when the tapscript is a CSV multisig tapscript. */
341
347
  function is(tapscript) {
342
348
  return tapscript.type === TapscriptType.CSVMultisig;
343
349
  }
@@ -357,6 +363,7 @@ var CSVMultisigTapscript;
357
363
  */
358
364
  var ConditionCSVMultisigTapscript;
359
365
  (function (ConditionCSVMultisigTapscript) {
366
+ /** Encode a condition + CSV multisig tapscript. */
360
367
  function encode(params) {
361
368
  const script = new Uint8Array([
362
369
  ...params.conditionScript,
@@ -370,6 +377,7 @@ var ConditionCSVMultisigTapscript;
370
377
  };
371
378
  }
372
379
  ConditionCSVMultisigTapscript.encode = encode;
380
+ /** Decode a condition + CSV multisig tapscript from raw script bytes. */
373
381
  function decode(script) {
374
382
  if (script.length === 0) {
375
383
  throw new Error("Failed to decode: script is empty");
@@ -413,6 +421,7 @@ var ConditionCSVMultisigTapscript;
413
421
  };
414
422
  }
415
423
  ConditionCSVMultisigTapscript.decode = decode;
424
+ /** Return true when the tapscript is a condition + CSV multisig tapscript. */
416
425
  function is(tapscript) {
417
426
  return tapscript.type === TapscriptType.ConditionCSVMultisig;
418
427
  }
@@ -432,6 +441,7 @@ var ConditionCSVMultisigTapscript;
432
441
  */
433
442
  var ConditionMultisigTapscript;
434
443
  (function (ConditionMultisigTapscript) {
444
+ /** Encode a condition + multisig tapscript. */
435
445
  function encode(params) {
436
446
  const script = new Uint8Array([
437
447
  ...params.conditionScript,
@@ -445,6 +455,7 @@ var ConditionMultisigTapscript;
445
455
  };
446
456
  }
447
457
  ConditionMultisigTapscript.encode = encode;
458
+ /** Decode a condition + multisig tapscript from raw script bytes. */
448
459
  function decode(script) {
449
460
  if (script.length === 0) {
450
461
  throw new Error("Failed to decode: script is empty");
@@ -488,6 +499,7 @@ var ConditionMultisigTapscript;
488
499
  };
489
500
  }
490
501
  ConditionMultisigTapscript.decode = decode;
502
+ /** Return true when the tapscript is a condition + multisig tapscript. */
491
503
  function is(tapscript) {
492
504
  return tapscript.type === TapscriptType.ConditionMultisig;
493
505
  }
@@ -507,6 +519,7 @@ var ConditionMultisigTapscript;
507
519
  */
508
520
  var CLTVMultisigTapscript;
509
521
  (function (CLTVMultisigTapscript) {
522
+ /** Encode a CLTV multisig tapscript. */
510
523
  function encode(params) {
511
524
  const locktime = MinimalScriptNum.encode(params.absoluteTimelock);
512
525
  const asm = [
@@ -526,6 +539,7 @@ var CLTVMultisigTapscript;
526
539
  };
527
540
  }
528
541
  CLTVMultisigTapscript.encode = encode;
542
+ /** Decode a CLTV multisig tapscript from raw script bytes. */
529
543
  function decode(script) {
530
544
  if (script.length === 0) {
531
545
  throw new Error("Failed to decode: script is empty");
@@ -573,6 +587,7 @@ var CLTVMultisigTapscript;
573
587
  };
574
588
  }
575
589
  CLTVMultisigTapscript.decode = decode;
590
+ /** Return true when the tapscript is a CLTV multisig tapscript. */
576
591
  function is(tapscript) {
577
592
  return tapscript.type === TapscriptType.CLTVMultisig;
578
593
  }
@@ -5,36 +5,38 @@ const btc_signer_1 = require("@scure/btc-signer");
5
5
  const tapscript_1 = require("./tapscript");
6
6
  const base_1 = require("@scure/base");
7
7
  const base_2 = require("./base");
8
- /**
9
- * Virtual Hash Time Lock Contract (VHTLC) implementation.
10
- *
11
- * VHTLC is a contract that enables atomic swaps and conditional payments
12
- * in the Ark protocol. 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
- */
8
+ /** Virtual Hash Time Lock Contract (VHTLC) namespace. */
35
9
  var VHTLC;
36
10
  (function (VHTLC) {
11
+ /**
12
+ * Virtual Hash Time Lock Contract (VHTLC) script implementation.
13
+ *
14
+ * VHTLC enables atomic swaps and conditional payments in the Arkade protocol.
15
+ * It provides multiple spending paths:
16
+ *
17
+ * - **claim**: Receiver can claim funds by revealing the preimage
18
+ * - **refund**: Sender and receiver can collaboratively refund
19
+ * - **refundWithoutReceiver**: Sender can refund after locktime expires
20
+ * - **unilateralClaim**: Receiver can claim unilaterally after delay
21
+ * - **unilateralRefund**: Sender and receiver can refund unilaterally after delay
22
+ * - **unilateralRefundWithoutReceiver**: Sender can refund unilaterally after delay
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const vhtlc = new VHTLC.Script({
27
+ * sender: alicePubKey,
28
+ * receiver: bobPubKey,
29
+ * server: serverPubKey,
30
+ * preimageHash: hash160(secret),
31
+ * refundLocktime: BigInt(chainTip + 10),
32
+ * unilateralClaimDelay: { type: 'blocks', value: 100n },
33
+ * unilateralRefundDelay: { type: 'blocks', value: 102n },
34
+ * unilateralRefundWithoutReceiverDelay: { type: 'blocks', value: 103n }
35
+ * });
36
+ * ```
37
+ */
37
38
  class Script extends base_2.VtxoScript {
39
+ /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
38
40
  constructor(options) {
39
41
  validateOptions(options);
40
42
  const { sender, receiver, server, preimageHash, refundLocktime, unilateralClaimDelay, unilateralRefundDelay, unilateralRefundWithoutReceiverDelay, } = options;
@@ -79,21 +81,27 @@ var VHTLC;
79
81
  this.unilateralRefundScript = base_1.hex.encode(unilateralRefundScript);
80
82
  this.unilateralRefundWithoutReceiverScript = base_1.hex.encode(unilateralRefundWithoutReceiverScript);
81
83
  }
84
+ /** Return the collaborative claim tapleaf script. */
82
85
  claim() {
83
86
  return this.findLeaf(this.claimScript);
84
87
  }
88
+ /** Return the collaborative refund tapleaf script. */
85
89
  refund() {
86
90
  return this.findLeaf(this.refundScript);
87
91
  }
92
+ /** Return the refund-without-receiver tapleaf script. */
88
93
  refundWithoutReceiver() {
89
94
  return this.findLeaf(this.refundWithoutReceiverScript);
90
95
  }
96
+ /** Return the unilateral claim tapleaf script. */
91
97
  unilateralClaim() {
92
98
  return this.findLeaf(this.unilateralClaimScript);
93
99
  }
100
+ /** Return the unilateral refund tapleaf script. */
94
101
  unilateralRefund() {
95
102
  return this.findLeaf(this.unilateralRefundScript);
96
103
  }
104
+ /** Return the unilateral refund-without-receiver tapleaf script. */
97
105
  unilateralRefundWithoutReceiver() {
98
106
  return this.findLeaf(this.unilateralRefundWithoutReceiverScript);
99
107
  }
@@ -37,7 +37,7 @@ exports.FileSystemStorageAdapter = void 0;
37
37
  const fs = __importStar(require("fs/promises"));
38
38
  const path = __importStar(require("path"));
39
39
  /**
40
- * @deprecated Use repositories instead
40
+ * @deprecated Use repository implementations via `StorageConfig` instead.
41
41
  */
42
42
  class FileSystemStorageAdapter {
43
43
  constructor(dirPath) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryStorageAdapter = void 0;
4
4
  /**
5
- * @deprecated Use repositories instead
5
+ * @deprecated Use repository implementations via `StorageConfig` instead.
6
6
  */
7
7
  class InMemoryStorageAdapter {
8
8
  constructor() {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IndexedDBStorageAdapter = void 0;
4
4
  const db_1 = require("../repositories/indexedDB/db");
5
5
  /**
6
- * @deprecated Use repositories instead
6
+ * @deprecated Use repository implementations via `StorageConfig` instead.
7
7
  */
8
8
  class IndexedDBStorageAdapter {
9
9
  constructor(dbName, version = db_1.DB_VERSION) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LocalStorageAdapter = void 0;
4
4
  /**
5
- * @deprecated Use repositories instead
5
+ * @deprecated Use repository implementations via `StorageConfig` instead.
6
6
  */
7
7
  class LocalStorageAdapter {
8
8
  getSafeLocalStorage() {
@@ -38,7 +38,7 @@ function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
38
38
  if (rootInput.index !== BATCH_OUTPUT_CONNECTORS_INDEX)
39
39
  throw exports.ErrWrongSettlementTxid;
40
40
  }
41
- // ValidateVtxoTxGraph checks if the given vtxo graph is valid.
41
+ // ValidateVtxoTxGraph checks if the given virtual output tx graph is valid.
42
42
  // The function validates:
43
43
  // - the number of nodes
44
44
  // - the number of leaves