@arkade-os/sdk 0.4.14 → 0.4.16

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 (203) hide show
  1. package/README.md +287 -215
  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 +40 -24
  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 +25 -1
  12. package/dist/cjs/contracts/handlers/vhtlc.js +2 -4
  13. package/dist/cjs/extension/asset/assetGroup.js +92 -5
  14. package/dist/cjs/extension/asset/assetId.js +67 -3
  15. package/dist/cjs/extension/asset/assetInput.js +18 -0
  16. package/dist/cjs/extension/asset/assetOutput.js +15 -0
  17. package/dist/cjs/extension/asset/assetRef.js +66 -0
  18. package/dist/cjs/extension/asset/metadata.js +15 -0
  19. package/dist/cjs/extension/asset/packet.js +4 -1
  20. package/dist/cjs/extension/index.js +1 -1
  21. package/dist/cjs/forfeit.js +14 -0
  22. package/dist/cjs/identity/index.js +6 -0
  23. package/dist/cjs/identity/seedIdentity.js +5 -5
  24. package/dist/cjs/identity/singleKey.js +4 -0
  25. package/dist/cjs/index.js +5 -3
  26. package/dist/cjs/intent/index.js +28 -12
  27. package/dist/cjs/providers/ark.js +3 -2
  28. package/dist/cjs/providers/delegator.js +20 -1
  29. package/dist/cjs/providers/expoArk.js +2 -2
  30. package/dist/cjs/providers/indexer.js +2 -2
  31. package/dist/cjs/providers/onchain.js +2 -1
  32. package/dist/cjs/repositories/realm/schemas.js +2 -2
  33. package/dist/cjs/repositories/realm/types.js +1 -1
  34. package/dist/cjs/script/address.js +37 -6
  35. package/dist/cjs/script/base.js +70 -1
  36. package/dist/cjs/script/default.js +3 -0
  37. package/dist/cjs/script/delegate.js +4 -0
  38. package/dist/cjs/script/tapscript.js +25 -4
  39. package/dist/cjs/script/vhtlc.js +35 -27
  40. package/dist/cjs/storage/fileSystem.js +1 -1
  41. package/dist/cjs/storage/inMemory.js +1 -1
  42. package/dist/cjs/storage/indexedDB.js +1 -1
  43. package/dist/cjs/storage/localStorage.js +1 -1
  44. package/dist/cjs/tree/validation.js +1 -1
  45. package/dist/cjs/utils/arkTransaction.js +5 -5
  46. package/dist/cjs/utils/bip21.js +16 -3
  47. package/dist/cjs/utils/syncCursors.js +4 -4
  48. package/dist/cjs/utils/transaction.js +1 -1
  49. package/dist/cjs/utils/transactionHistory.js +11 -11
  50. package/dist/cjs/utils/unknownFields.js +3 -3
  51. package/dist/cjs/wallet/asset-manager.js +4 -4
  52. package/dist/cjs/wallet/batch.js +5 -5
  53. package/dist/cjs/wallet/delegator.js +9 -8
  54. package/dist/cjs/wallet/expo/background.js +3 -3
  55. package/dist/cjs/wallet/expo/wallet.js +7 -7
  56. package/dist/cjs/wallet/index.js +43 -0
  57. package/dist/cjs/wallet/onchain.js +43 -5
  58. package/dist/cjs/wallet/ramps.js +44 -14
  59. package/dist/cjs/wallet/serviceWorker/wallet-message-handler.js +22 -22
  60. package/dist/cjs/wallet/serviceWorker/wallet.js +28 -24
  61. package/dist/cjs/wallet/unroll.js +12 -8
  62. package/dist/cjs/wallet/utils.js +1 -1
  63. package/dist/cjs/wallet/vtxo-manager.js +123 -82
  64. package/dist/cjs/wallet/wallet.js +231 -98
  65. package/dist/cjs/worker/expo/asyncStorageTaskQueue.js +1 -1
  66. package/dist/cjs/worker/expo/processors/contractPollProcessor.js +2 -2
  67. package/dist/cjs/worker/expo/taskRunner.js +3 -3
  68. package/dist/cjs/worker/messageBus.js +3 -0
  69. package/dist/esm/arkfee/estimator.js +1 -1
  70. package/dist/esm/arkfee/types.js +2 -1
  71. package/dist/esm/arknote/index.js +43 -4
  72. package/dist/esm/bip322/index.js +1 -1
  73. package/dist/esm/contracts/arkcontract.js +1 -1
  74. package/dist/esm/contracts/contractManager.js +40 -24
  75. package/dist/esm/contracts/contractWatcher.js +29 -22
  76. package/dist/esm/contracts/handlers/default.js +1 -1
  77. package/dist/esm/contracts/handlers/delegate.js +1 -1
  78. package/dist/esm/contracts/handlers/helpers.js +24 -1
  79. package/dist/esm/contracts/handlers/vhtlc.js +3 -5
  80. package/dist/esm/extension/asset/assetGroup.js +92 -5
  81. package/dist/esm/extension/asset/assetId.js +67 -3
  82. package/dist/esm/extension/asset/assetInput.js +18 -0
  83. package/dist/esm/extension/asset/assetOutput.js +15 -0
  84. package/dist/esm/extension/asset/assetRef.js +66 -0
  85. package/dist/esm/extension/asset/metadata.js +15 -0
  86. package/dist/esm/extension/asset/packet.js +4 -1
  87. package/dist/esm/extension/index.js +1 -1
  88. package/dist/esm/forfeit.js +14 -0
  89. package/dist/esm/identity/index.js +5 -0
  90. package/dist/esm/identity/seedIdentity.js +5 -5
  91. package/dist/esm/identity/singleKey.js +4 -0
  92. package/dist/esm/index.js +3 -2
  93. package/dist/esm/intent/index.js +28 -12
  94. package/dist/esm/providers/ark.js +3 -2
  95. package/dist/esm/providers/delegator.js +20 -1
  96. package/dist/esm/providers/expoArk.js +2 -2
  97. package/dist/esm/providers/indexer.js +2 -2
  98. package/dist/esm/providers/onchain.js +2 -1
  99. package/dist/esm/repositories/realm/schemas.js +2 -2
  100. package/dist/esm/repositories/realm/types.js +1 -1
  101. package/dist/esm/script/address.js +37 -6
  102. package/dist/esm/script/base.js +70 -1
  103. package/dist/esm/script/default.js +3 -0
  104. package/dist/esm/script/delegate.js +4 -0
  105. package/dist/esm/script/tapscript.js +25 -4
  106. package/dist/esm/script/vhtlc.js +35 -27
  107. package/dist/esm/storage/fileSystem.js +1 -1
  108. package/dist/esm/storage/inMemory.js +1 -1
  109. package/dist/esm/storage/indexedDB.js +1 -1
  110. package/dist/esm/storage/localStorage.js +1 -1
  111. package/dist/esm/tree/validation.js +1 -1
  112. package/dist/esm/utils/arkTransaction.js +5 -5
  113. package/dist/esm/utils/bip21.js +16 -3
  114. package/dist/esm/utils/syncCursors.js +4 -4
  115. package/dist/esm/utils/transaction.js +1 -1
  116. package/dist/esm/utils/transactionHistory.js +11 -11
  117. package/dist/esm/utils/unknownFields.js +3 -3
  118. package/dist/esm/wallet/asset-manager.js +4 -4
  119. package/dist/esm/wallet/batch.js +5 -5
  120. package/dist/esm/wallet/delegator.js +9 -8
  121. package/dist/esm/wallet/expo/background.js +3 -3
  122. package/dist/esm/wallet/expo/wallet.js +7 -7
  123. package/dist/esm/wallet/index.js +43 -0
  124. package/dist/esm/wallet/onchain.js +43 -5
  125. package/dist/esm/wallet/ramps.js +44 -14
  126. package/dist/esm/wallet/serviceWorker/wallet-message-handler.js +22 -22
  127. package/dist/esm/wallet/serviceWorker/wallet.js +28 -24
  128. package/dist/esm/wallet/unroll.js +12 -8
  129. package/dist/esm/wallet/utils.js +1 -1
  130. package/dist/esm/wallet/vtxo-manager.js +122 -81
  131. package/dist/esm/wallet/wallet.js +232 -99
  132. package/dist/esm/worker/expo/asyncStorageTaskQueue.js +1 -1
  133. package/dist/esm/worker/expo/processors/contractPollProcessor.js +2 -2
  134. package/dist/esm/worker/expo/taskRunner.js +3 -3
  135. package/dist/esm/worker/messageBus.js +3 -0
  136. package/dist/types/arkfee/estimator.d.ts +1 -1
  137. package/dist/types/arkfee/types.d.ts +2 -1
  138. package/dist/types/arknote/index.d.ts +44 -4
  139. package/dist/types/bip322/index.d.ts +1 -1
  140. package/dist/types/contracts/arkcontract.d.ts +1 -1
  141. package/dist/types/contracts/contractManager.d.ts +40 -63
  142. package/dist/types/contracts/contractWatcher.d.ts +39 -18
  143. package/dist/types/contracts/handlers/default.d.ts +1 -1
  144. package/dist/types/contracts/handlers/delegate.d.ts +1 -1
  145. package/dist/types/contracts/handlers/helpers.d.ts +11 -1
  146. package/dist/types/contracts/types.d.ts +36 -26
  147. package/dist/types/extension/asset/assetGroup.d.ts +92 -1
  148. package/dist/types/extension/asset/assetId.d.ts +67 -3
  149. package/dist/types/extension/asset/assetInput.d.ts +18 -0
  150. package/dist/types/extension/asset/assetOutput.d.ts +15 -0
  151. package/dist/types/extension/asset/assetRef.d.ts +66 -0
  152. package/dist/types/extension/asset/metadata.d.ts +15 -0
  153. package/dist/types/extension/asset/packet.d.ts +4 -1
  154. package/dist/types/extension/index.d.ts +1 -1
  155. package/dist/types/forfeit.d.ts +14 -0
  156. package/dist/types/identity/index.d.ts +36 -0
  157. package/dist/types/identity/seedIdentity.d.ts +10 -8
  158. package/dist/types/identity/singleKey.d.ts +4 -0
  159. package/dist/types/index.d.ts +3 -3
  160. package/dist/types/intent/index.d.ts +19 -6
  161. package/dist/types/providers/ark.d.ts +40 -2
  162. package/dist/types/providers/delegator.d.ts +54 -1
  163. package/dist/types/providers/expoArk.d.ts +2 -2
  164. package/dist/types/providers/indexer.d.ts +105 -2
  165. package/dist/types/providers/onchain.d.ts +62 -1
  166. package/dist/types/repositories/realm/schemas.d.ts +2 -2
  167. package/dist/types/repositories/realm/types.d.ts +2 -2
  168. package/dist/types/repositories/walletRepository.d.ts +16 -0
  169. package/dist/types/script/address.d.ts +35 -2
  170. package/dist/types/script/base.d.ts +66 -1
  171. package/dist/types/script/default.d.ts +3 -0
  172. package/dist/types/script/delegate.d.ts +4 -0
  173. package/dist/types/script/tapscript.d.ts +17 -2
  174. package/dist/types/script/vhtlc.d.ts +35 -27
  175. package/dist/types/storage/fileSystem.d.ts +1 -1
  176. package/dist/types/storage/inMemory.d.ts +1 -1
  177. package/dist/types/storage/index.d.ts +1 -1
  178. package/dist/types/storage/indexedDB.d.ts +1 -1
  179. package/dist/types/storage/localStorage.d.ts +1 -1
  180. package/dist/types/utils/arkTransaction.d.ts +3 -3
  181. package/dist/types/utils/bip21.d.ts +17 -0
  182. package/dist/types/utils/syncCursors.d.ts +4 -4
  183. package/dist/types/utils/transaction.d.ts +1 -1
  184. package/dist/types/utils/transactionHistory.d.ts +3 -3
  185. package/dist/types/utils/unknownFields.d.ts +5 -5
  186. package/dist/types/wallet/asset-manager.d.ts +3 -3
  187. package/dist/types/wallet/batch.d.ts +27 -7
  188. package/dist/types/wallet/delegator.d.ts +10 -0
  189. package/dist/types/wallet/expo/background.d.ts +4 -4
  190. package/dist/types/wallet/expo/wallet.d.ts +10 -10
  191. package/dist/types/wallet/index.d.ts +457 -25
  192. package/dist/types/wallet/onchain.d.ts +42 -4
  193. package/dist/types/wallet/ramps.d.ts +40 -10
  194. package/dist/types/wallet/serviceWorker/wallet-message-handler.d.ts +4 -4
  195. package/dist/types/wallet/serviceWorker/wallet.d.ts +71 -33
  196. package/dist/types/wallet/unroll.d.ts +8 -6
  197. package/dist/types/wallet/vtxo-manager.d.ts +146 -93
  198. package/dist/types/wallet/wallet.d.ts +91 -33
  199. package/dist/types/worker/expo/asyncStorageTaskQueue.d.ts +1 -1
  200. package/dist/types/worker/expo/processors/contractPollProcessor.d.ts +1 -1
  201. package/dist/types/worker/expo/taskRunner.d.ts +6 -6
  202. package/dist/types/worker/messageBus.d.ts +5 -3
  203. package/package.json +18 -10
@@ -49,7 +49,7 @@ export class AsyncStorageTaskQueue {
49
49
  // ── Config persistence (for background handler rehydration) ──────
50
50
  /**
51
51
  * Persist a config blob alongside the queue data.
52
- * Used by {@link ExpoWallet.setup} to store the wallet parameters
52
+ * Used by @see ExpoWallet.setup to store the wallet parameters
53
53
  * that the background handler needs to reconstruct providers.
54
54
  */
55
55
  async persistConfig(config) {
@@ -3,7 +3,7 @@ export const CONTRACT_POLL_TASK_TYPE = "contract-poll";
3
3
  * Polls the indexer for the latest VTXO state of every contract and
4
4
  * persists the results to the wallet repository.
5
5
  *
6
- * Replicates the polling subset of {@link ContractManager.initialize}:
6
+ * Replicates the polling subset of @see ContractManager.initialize:
7
7
  * 1. Load all contracts from the contract repository.
8
8
  * 2. Mark expired active contracts as inactive.
9
9
  * 3. Paginated fetch of spendable VTXOs from the indexer.
@@ -26,7 +26,7 @@ export const contractPollProcessor = {
26
26
  contract.state = "inactive";
27
27
  await contractRepository.saveContract(contract);
28
28
  }
29
- // Paginated fetch of spendable VTXOs
29
+ // Paginated fetch of spendable virtual outputs
30
30
  const pageSize = 100;
31
31
  let pageIndex = 0;
32
32
  let hasMore = true;
@@ -4,7 +4,7 @@ import { getRandomId, extendVirtualCoin, extendVtxoFromContract, } from '../../w
4
4
  *
5
5
  * For each task in the inbox:
6
6
  * 1. Find the processor whose `taskType` matches `task.type`.
7
- * 2. Execute it, producing a {@link TaskResult}.
7
+ * 2. Execute it, producing a @see TaskResult.
8
8
  * 3. Push the result to the outbox and remove the task from the inbox.
9
9
  *
10
10
  * Tasks with no matching processor produce a `"noop"` result.
@@ -53,8 +53,8 @@ export async function runTasks(queue, processors, deps) {
53
53
  return results;
54
54
  }
55
55
  /**
56
- * Build the {@link TaskDependencies} needed by task processors
57
- * (e.g. {@link import("./processors").contractPollProcessor}).
56
+ * Build the @see TaskDependencies needed by task processors
57
+ * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)
58
58
  *
59
59
  * This is the same construction that `defineExpoBackgroundTask` does
60
60
  * internally, extracted so that consumers with custom schedulers
@@ -7,6 +7,7 @@ import { ReadonlyWallet, Wallet } from '../wallet/wallet.js';
7
7
  import { hex } from "@scure/base";
8
8
  import { MessageBusNotInitializedError, ServiceWorkerTimeoutError, } from './errors.js';
9
9
  export class MessageBus {
10
+ /** Create the service-worker message bus with repositories and handler configuration. */
10
11
  constructor(walletRepository, contractRepository, { messageHandlers, tickIntervalMs = 10000, messageTimeoutMs = 30000, debug = false, buildServices, }) {
11
12
  this.walletRepository = walletRepository;
12
13
  this.contractRepository = contractRepository;
@@ -22,6 +23,7 @@ export class MessageBus {
22
23
  this.debug = debug;
23
24
  this.buildServicesFn = buildServices ?? this.buildServices.bind(this);
24
25
  }
26
+ /** Start the message bus and attach service-worker event listeners. */
25
27
  async start() {
26
28
  if (this.running)
27
29
  return;
@@ -42,6 +44,7 @@ export class MessageBus {
42
44
  }
43
45
  });
44
46
  }
47
+ /** Stop the message bus, cancel ticks, and stop all registered handlers. */
45
48
  async stop() {
46
49
  if (this.debug)
47
50
  console.log("MessageBus stopping");
@@ -1,6 +1,6 @@
1
1
  import { IntentFeeConfig, OffchainInput, OnchainInput, FeeOutput, FeeAmount } from "./types.js";
2
2
  /**
3
- * Estimator evaluates CEL expressions to calculate fees for Ark intents
3
+ * Estimator evaluates CEL expressions to calculate fees for Arkade intents
4
4
  */
5
5
  export declare class Estimator {
6
6
  readonly config: IntentFeeConfig;
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * FeeAmount is a wrapper around a number that represents a fee amount in satoshis floating point.
3
3
  * @param value - The fee amount in floating point.
4
- * @method satoshis - Returns the fee amount in satoshis as a integer.
5
4
  * @example
6
5
  * const fee = new FeeAmount(1.23456789);
7
6
  * console.log(fee.value); // 1.23456789
@@ -11,7 +10,9 @@ export declare class FeeAmount {
11
10
  readonly value: number;
12
11
  static ZERO: FeeAmount;
13
12
  constructor(value: number);
13
+ /** Returns the fee amount rounded up to whole satoshis. */
14
14
  get satoshis(): number;
15
+ /** Add two fee amounts together. */
15
16
  add(other: FeeAmount): FeeAmount;
16
17
  }
17
18
  export interface IntentFeeConfig {
@@ -2,10 +2,12 @@ import { Bytes } from "@scure/btc-signer/utils.js";
2
2
  import { TapLeafScript, VtxoScript } from "../script/base";
3
3
  import { ExtendedCoin, Status } from "../wallet";
4
4
  /**
5
- * ArkNotes are special virtual coins in the Ark protocol that can be created
6
- * and spent without requiring any transactions. The server mints them, and they
7
- * are encoded as base58 strings with a human-readable prefix. It contains a
8
- * preimage and value.
5
+ * ArkNotes are special virtual outputs in the Arkade protocol that
6
+ * can be created and spent without requiring any transactions.
7
+ * The server mints them, and they are encoded as base58 strings
8
+ * with a human-readable prefix, a preimage and a value.
9
+ *
10
+ * @see VtxoScript
9
11
  *
10
12
  * @example
11
13
  * ```typescript
@@ -29,6 +31,7 @@ export declare class ArkNote implements ExtendedCoin {
29
31
  static readonly Length: number;
30
32
  static readonly FakeOutpointIndex = 0;
31
33
  readonly vtxoScript: VtxoScript;
34
+ /** Hashlock script backing the note. */
32
35
  readonly txid: string;
33
36
  readonly vout = 0;
34
37
  readonly forfeitTapLeafScript: TapLeafScript;
@@ -36,9 +39,46 @@ export declare class ArkNote implements ExtendedCoin {
36
39
  readonly tapTree: Bytes;
37
40
  readonly status: Status;
38
41
  readonly extraWitness?: Bytes[] | undefined;
42
+ /**
43
+ * Create an ArkNote from a preimage and value.
44
+ *
45
+ * @param preimage - 32-byte preimage revealed to spend the note
46
+ * @param value - Note value in satoshis
47
+ * @param HRP - Optional human-readable prefix for string encoding
48
+ */
39
49
  constructor(preimage: Uint8Array, value: number, HRP?: string);
50
+ /**
51
+ * Encode the note as raw bytes.
52
+ *
53
+ * @returns Serialized note bytes
54
+ * @see decode
55
+ */
40
56
  encode(): Uint8Array;
57
+ /**
58
+ * Decode a note from raw bytes.
59
+ *
60
+ * @param data - Serialized note bytes
61
+ * @param hrp - Human-readable prefix expected for future string encoding
62
+ * @returns Decoded ArkNote
63
+ * @throws Error if the payload length is invalid
64
+ * @see encode
65
+ */
41
66
  static decode(data: Uint8Array, hrp?: string): ArkNote;
67
+ /**
68
+ * Decode a note from its base58 string form.
69
+ *
70
+ * @param noteStr - Base58-encoded note string
71
+ * @param hrp - Human-readable prefix expected on the note string
72
+ * @returns Decoded ArkNote
73
+ * @throws Error if the prefix or base58 payload is invalid
74
+ * @see toString
75
+ */
42
76
  static fromString(noteStr: string, hrp?: string): ArkNote;
77
+ /**
78
+ * Encode the note to its human-readable base58 string form.
79
+ *
80
+ * @returns Base58-encoded note string
81
+ * @see fromString
82
+ */
43
83
  toString(): string;
44
84
  }
@@ -8,7 +8,7 @@ import type { Identity } from "../identity";
8
8
  *
9
9
  * Reuses the same toSpend/toSign transaction construction as Intent proofs,
10
10
  * but with the standard BIP-322 tagged hash ("BIP0322-signed-message")
11
- * instead of the Ark-specific tag.
11
+ * instead of the Arkade-specific tag.
12
12
  *
13
13
  * @see https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
14
14
  *
@@ -5,7 +5,7 @@ import { Contract } from "./types";
5
5
  * Format: arkcontract={type}&{key1}={value1}&{key2}={value2}...
6
6
  *
7
7
  * This format is compatible with NArk and allows contracts to be
8
- * shared/imported across different Ark implementations.
8
+ * shared/imported across different Arkade SDKs.
9
9
  *
10
10
  * @example
11
11
  * ```typescript
@@ -4,45 +4,6 @@ import { Contract, ContractEventCallback, ContractState, ContractWithVtxos, GetC
4
4
  import { ContractWatcherConfig } from "./contractWatcher";
5
5
  import { VirtualCoin } from "../wallet";
6
6
  import { ContractRepository } from "../repositories";
7
- /**
8
- * Contract lifecycle and VTXO orchestration API.
9
- *
10
- * Responsibilities:
11
- * - Create and persist contracts
12
- * - Query stored contracts (optionally with their VTXOs)
13
- * - Provide spendable path selection for a contract
14
- * - Emit contract-related events (VTXO received/spent, expiry, connection reset)
15
- *
16
- * Notes:
17
- * - Implementations typically start watching automatically during initialization
18
- * (so `onContractEvent()` is just for subscribing).
19
- *
20
- * @example
21
- * ```typescript
22
- * const manager = await ContractManager.create({
23
- * indexerProvider,
24
- * contractRepository,
25
- * walletRepository,
26
- * getDefaultAddress,
27
- * });
28
- *
29
- * const unsubscribe = manager.onContractEvent((event) => {
30
- * console.log(event.type, event.timestamp);
31
- * });
32
- *
33
- * const contract = await manager.createContract({
34
- * label: "Lightning Receive",
35
- * type: "vhtlc",
36
- * params: { sender: "ab12...", receiver: "cd34..." },
37
- * script: "5120...",
38
- * address: "tark1...",
39
- * });
40
- *
41
- * // Later:
42
- * unsubscribe();
43
- * manager.dispose();
44
- * ```
45
- */
46
7
  export type RefreshVtxosOptions = {
47
8
  scripts?: string[];
48
9
  after?: number;
@@ -70,9 +31,9 @@ export interface IContractManager extends Disposable {
70
31
  */
71
32
  getContracts(filter?: GetContractsFilter): Promise<Contract[]>;
72
33
  /**
73
- * List contracts and include their current VTXOs.
34
+ * List contracts and their current virtual outputs.
74
35
  *
75
- * If no filter is provided, returns all contracts with their VTXOs.
36
+ * If no filter is provided, returns all contracts with their virtual outputs.
76
37
  */
77
38
  getContractsWithVtxos(filter?: GetContractsFilter): Promise<ContractWithVtxos[]>;
78
39
  /**
@@ -108,7 +69,7 @@ export interface IContractManager extends Disposable {
108
69
  */
109
70
  onContractEvent(callback: ContractEventCallback): () => void;
110
71
  /**
111
- * Force a VTXO refresh from the indexer.
72
+ * Force a virtual output refresh from the indexer.
112
73
  *
113
74
  * Without options, refreshes all contracts from scratch.
114
75
  * With options, narrows the refresh to specific scripts and/or a time window.
@@ -129,7 +90,7 @@ export interface IContractManager extends Disposable {
129
90
  export type GetSpendablePathsOptions = {
130
91
  /** The contract script */
131
92
  contractScript: string;
132
- /** The specific VTXO being evaluated */
93
+ /** The specific virtual output being evaluated */
133
94
  vtxo: VirtualCoin;
134
95
  /** Whether collaborative spending is available (default: true) */
135
96
  collaborative?: boolean;
@@ -155,9 +116,9 @@ export interface ContractManagerConfig {
155
116
  indexerProvider: IndexerProvider;
156
117
  /** The contract repository for persistence */
157
118
  contractRepository: ContractRepository;
158
- /** The wallet repository for VTXO storage (single source of truth) */
119
+ /** The wallet repository for virtual output storage (single source of truth) */
159
120
  walletRepository: WalletRepository;
160
- /** Function to get the wallet's default Ark address */
121
+ /** Function to get the wallet's default Arkade address */
161
122
  getDefaultAddress: () => Promise<string>;
162
123
  /** Watcher configuration */
163
124
  watcherConfig?: Partial<ContractWatcherConfig>;
@@ -172,38 +133,50 @@ export type CreateContractParams = Omit<Contract, "createdAt" | "state"> & {
172
133
  /**
173
134
  * Central manager for contract lifecycle and operations.
174
135
  *
175
- * The ContractManager orchestrates:
176
- * - Contract registration and persistence
177
- * - Multi-contract watching via ContractWatcher
178
- * - VTXO queries across contracts
136
+ * Responsibilities:
137
+ * - Create and persist contracts
138
+ * - Query stored contracts (optionally with their virtual outputs)
139
+ * - Provide spendable path selection for a contract
140
+ * - Emit contract-related events (virtual output received/spent/expired, connection reset)
141
+ *
142
+ * Notes:
143
+ * - Implementations typically start watching automatically during initialization
144
+ * (so `onContractEvent()` is just for subscribing).
179
145
  *
180
146
  * @example
181
147
  * ```typescript
182
- * const manager = new ContractManager({
148
+ * const manager = await ContractManager.create({
183
149
  * indexerProvider: wallet.indexerProvider,
184
150
  * contractRepository: wallet.contractRepository,
151
+ * walletRepository: wallet.walletRepository,
185
152
  * getDefaultAddress: () => wallet.getAddress(),
186
153
  * });
187
154
  *
188
- * // Initialize (loads persisted contracts)
189
- * await manager.initialize();
190
- *
191
155
  * // Create a new VHTLC contract
192
156
  * const contract = await manager.createContract({
193
157
  * label: "Lightning Receive",
194
158
  * type: "vhtlc",
195
- * params: { sender: "ab12...", receiver: "cd34...", ... },
159
+ * params: { sender: "ark1q...", receiver: "ark1q...", ... },
196
160
  * script: "5120...",
197
- * address: "tark1...",
161
+ * address: "ark1q...",
198
162
  * });
199
163
  *
200
164
  * // Start watching for events
201
- * const stop = await manager.startWatching((event) => {
165
+ * const unsubscribe = manager.onContractEvent((event) => {
202
166
  * console.log(`${event.type} on ${event.contractScript}`);
203
167
  * });
204
168
  *
169
+ * // Query contracts together with their current virtual outputs
170
+ * const contractsWithVtxos = await manager.getContractsWithVtxos();
171
+ *
205
172
  * // Get balance across all contracts
206
- * const balances = await manager.getAllBalances();
173
+ * const balances = contractsWithVtxos.flatMap(({vtxos}) => vtxos).reduce((acc, vtxo) => acc + vtxo.value, 0)
174
+ *
175
+ * // Later: unsubscribe from events
176
+ * unsubscribe();
177
+ *
178
+ * // Clean up
179
+ * manager.dispose();
207
180
  * ```
208
181
  */
209
182
  export declare class ContractManager implements IContractManager {
@@ -218,7 +191,7 @@ export declare class ContractManager implements IContractManager {
218
191
  * Initialize the manager by loading persisted contracts and starting to watch.
219
192
  *
220
193
  * After initialization, the manager automatically watches all active contracts
221
- * and contracts with VTXOs. Use `onContractEvent()` to register event callbacks.
194
+ * and contracts with virtual outputs. Use `onContractEvent()` to register event callbacks.
222
195
  *
223
196
  * @param config ContractManagerConfig
224
197
  */
@@ -279,10 +252,14 @@ export declare class ContractManager implements IContractManager {
279
252
  /**
280
253
  * Get currently spendable paths for a contract.
281
254
  *
282
- * @param contractScript - The contract script
283
255
  * @param options - Options for getting spendable paths
284
256
  */
285
257
  getSpendablePaths(options: GetSpendablePathsOptions): Promise<PathSelection[]>;
258
+ /**
259
+ * Get every currently valid spending path for a contract.
260
+ *
261
+ * @param options - Options for getting spending paths
262
+ */
286
263
  getAllSpendingPaths(options: GetAllSpendingPathsOptions): Promise<PathSelection[]>;
287
264
  /**
288
265
  * Register a callback for contract events.
@@ -305,7 +282,7 @@ export declare class ContractManager implements IContractManager {
305
282
  */
306
283
  onContractEvent(callback: ContractEventCallback): () => void;
307
284
  /**
308
- * Force a VTXO refresh from the indexer.
285
+ * Force refresh virtual outputs from the indexer.
309
286
  *
310
287
  * Without options, clears all sync cursors and re-fetches every contract.
311
288
  * With options, narrows the refresh to specific scripts and/or a time window.
@@ -325,14 +302,14 @@ export declare class ContractManager implements IContractManager {
325
302
  private handleContractEvent;
326
303
  private getVtxosForContracts;
327
304
  /**
328
- * Incrementally sync VTXOs for the given contracts.
305
+ * Incrementally sync virtual outputs for the given contracts.
329
306
  * Uses per-script cursors to fetch only what changed since the last sync.
330
307
  * Scripts without a cursor are bootstrapped with a full fetch.
331
308
  */
332
309
  private deltaSyncContracts;
333
310
  /**
334
- * Fetch all pending (not-yet-finalized) VTXOs and upsert them into the
335
- * repository. This catches VTXOs whose state changed outside the delta
311
+ * Fetch all pending (unfinalized) virtual outputs and upsert them into the
312
+ * repository. This catches virtual outputs whose state changed outside the delta
336
313
  * window (e.g. a spend that hasn't settled yet).
337
314
  */
338
315
  private reconcilePendingFrontier;
@@ -3,33 +3,47 @@ import { WalletRepository } from "../repositories/walletRepository";
3
3
  import { Contract, ContractEventCallback } from "./types";
4
4
  /**
5
5
  * Configuration for the ContractWatcher.
6
+ *
7
+ * @see ContractWatcher
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const watcher = new ContractWatcher({
12
+ * indexerProvider,
13
+ * walletRepository,
14
+ * })
15
+ * ```
6
16
  */
7
17
  export interface ContractWatcherConfig {
8
- /** The indexer provider to use for subscriptions and queries */
18
+ /** Indexer provider used for subscriptions and queries. */
9
19
  indexerProvider: IndexerProvider;
10
- /** The wallet repository for VTXO persistence (optional) */
20
+ /** Wallet repository used to store virtual output state between watcher updates. */
11
21
  walletRepository: WalletRepository;
12
22
  /**
13
23
  * Interval for failsafe polling (ms).
14
24
  * Polls even when subscription is active to catch missed events.
15
- * Default: 60000 (1 minute)
25
+ *
26
+ * @defaultValue `60_000` (1 minute)
16
27
  */
17
28
  failsafePollIntervalMs?: number;
18
29
  /**
19
30
  * Initial reconnection delay (ms).
20
31
  * Uses exponential backoff on repeated failures.
21
- * Default: 1000 (1 second)
32
+ *
33
+ * @defaultValue `1_000` (1 second)
22
34
  */
23
35
  reconnectDelayMs?: number;
24
36
  /**
25
37
  * Maximum reconnection delay (ms).
26
- * Default: 30000 (30 seconds)
38
+ *
39
+ * @defaultValue `30_000` (30 seconds)
27
40
  */
28
41
  maxReconnectDelayMs?: number;
29
42
  /**
30
43
  * Maximum reconnection attempts before giving up.
31
44
  * Set to 0 for unlimited attempts.
32
- * Default: 0 (unlimited)
45
+ *
46
+ * @defaultValue `0` (unlimited)
33
47
  */
34
48
  maxReconnectAttempts?: number;
35
49
  }
@@ -38,7 +52,7 @@ export interface ContractWatcherConfig {
38
52
  */
39
53
  type ConnectionState = "disconnected" | "connecting" | "connected" | "reconnecting";
40
54
  /**
41
- * Watches multiple contracts for VTXO changes with resilient connection handling.
55
+ * Watches multiple contracts for virtual output state changes with resilient connection handling.
42
56
  *
43
57
  * Features:
44
58
  * - Automatic reconnection with exponential backoff
@@ -78,13 +92,20 @@ export declare class ContractWatcher {
78
92
  private reconnectAttempts;
79
93
  private reconnectTimeoutId?;
80
94
  private failsafePollIntervalId?;
95
+ /**
96
+ * Create a contract watcher with the given providers and polling settings.
97
+ *
98
+ * @param config - Contract watcher configuration
99
+ * @see ContractWatcherConfig
100
+ */
81
101
  constructor(config: ContractWatcherConfig);
82
102
  /**
83
103
  * Add a contract to be watched.
84
104
  *
85
- * Active contracts are immediately subscribed. All contracts are polled
86
- * to discover any existing VTXOs (which may cause them to be watched
87
- * even if inactive).
105
+ * Active contracts are immediately subscribed.
106
+ *
107
+ * All contracts are polled to discover any existing virtual outputs
108
+ * (which may cause them to be watched even if inactive).
88
109
  */
89
110
  addContract(contract: Contract): Promise<void>;
90
111
  /**
@@ -108,19 +129,19 @@ export declare class ContractWatcher {
108
129
  *
109
130
  * Returns scripts for:
110
131
  * - All active contracts
111
- * - All contracts with known VTXOs (regardless of state)
132
+ * - All contracts with known virtual outputs (regardless of state)
112
133
  *
113
134
  * This ensures we continue monitoring contracts even after they're
114
- * deactivated, as long as they have unspent VTXOs.
135
+ * deactivated, as long as they have unspent virtual outputs.
115
136
  */
116
137
  private getScriptsToWatch;
117
138
  /**
118
- * Get VTXOs for contracts, grouped by contract script.
119
- * Uses Repository.
139
+ * Get virtual outputs for contracts, grouped by contract script.
140
+ * @see WalletRepository for `repo`
120
141
  */
121
142
  private getContractVtxos;
122
143
  /**
123
- * Start watching for VTXO events across all active contracts.
144
+ * Start watching for virtual output events across all active contracts.
124
145
  */
125
146
  startWatching(callback: ContractEventCallback): Promise<() => void>;
126
147
  /**
@@ -168,7 +189,7 @@ export declare class ContractWatcher {
168
189
  /**
169
190
  * Update the subscription with scripts that should be watched.
170
191
  *
171
- * Watches both active contracts and contracts with VTXOs.
192
+ * Watches both active contracts and contracts with virtual outputs.
172
193
  */
173
194
  private updateSubscription;
174
195
  /**
@@ -180,12 +201,12 @@ export declare class ContractWatcher {
180
201
  */
181
202
  private handleSubscriptionUpdate;
182
203
  /**
183
- * Process VTXOs from subscription and route to correct contracts.
204
+ * Process virtual outputs from subscription and route to correct contracts.
184
205
  * Uses the scripts from the subscription response to determine contract ownership.
185
206
  */
186
207
  private processSubscriptionVtxos;
187
208
  /**
188
- * Emit a VTXO event for a contract.
209
+ * Emit a virtual output event for a contract.
189
210
  */
190
211
  private emitVtxoEvent;
191
212
  }
@@ -10,7 +10,7 @@ export interface DefaultContractParams {
10
10
  csvTimelock: RelativeTimelock;
11
11
  }
12
12
  /**
13
- * Handler for default wallet VTXOs.
13
+ * Handler for default wallet virtual outputs.
14
14
  *
15
15
  * Default contracts use the standard forfeit + exit tapscript:
16
16
  * - forfeit: (Alice + Server) multisig for collaborative spending
@@ -11,7 +11,7 @@ export interface DelegateContractParams {
11
11
  csvTimelock: RelativeTimelock;
12
12
  }
13
13
  /**
14
- * Handler for delegate wallet VTXOs.
14
+ * Handler for delegate wallet virtual outputs.
15
15
  *
16
16
  * Delegate contracts extend the default tapscript with an additional delegate path:
17
17
  * - forfeit: (Alice + Server) multisig for collaborative spending
@@ -13,6 +13,16 @@ export declare function sequenceToTimelock(sequence: number): RelativeTimelock;
13
13
  */
14
14
  export declare function resolveRole(contract: Contract, context: PathContext): "sender" | "receiver" | undefined;
15
15
  /**
16
- * Check if a CSV timelock is currently satisfied for the given context/VTXO.
16
+ * Check if an absolute (CLTV) locktime is currently satisfied.
17
+ *
18
+ * Following the BIP65 convention:
19
+ * - locktime < 500_000_000 → interpreted as a block height; compared against `context.blockHeight`
20
+ * - locktime >= 500_000_000 → interpreted as a Unix timestamp (seconds); compared against `context.currentTime`
21
+ *
22
+ * Returns false if the relevant context field is missing.
23
+ */
24
+ export declare function isCltvSatisfied(context: PathContext, locktime: bigint): boolean;
25
+ /**
26
+ * Check if a CSV timelock is currently satisfied for the given context/virtual output.
17
27
  */
18
28
  export declare function isCsvSpendable(context: PathContext, sequence?: number): boolean;