@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
@@ -7,7 +7,7 @@ import { ContractFilter } from "../repositories";
7
7
  */
8
8
  export type ContractState = "active" | "inactive";
9
9
  /**
10
- * Represents a contract that can receive and manage VTXOs.
10
+ * Represents a contract that can receive and manage virtual outputs.
11
11
  *
12
12
  * A contract is defined by its type and parameters, which together
13
13
  * determine the VtxoScript (spending paths). The wallet's default
@@ -29,14 +29,14 @@ export type ContractState = "active" | "inactive";
29
29
  * // ... timelocks
30
30
  * },
31
31
  * script: "5120...",
32
- * address: "tark1...",
32
+ * address: "ark1q...",
33
33
  * state: "active",
34
34
  * createdAt: 1704067200000,
35
35
  * };
36
36
  * ```
37
37
  */
38
38
  export interface Contract {
39
- /** Human-readable label for display purposes */
39
+ /** Human-readable label for display purposes. */
40
40
  label?: string;
41
41
  /**
42
42
  * Contract type identifier.
@@ -50,15 +50,15 @@ export interface Contract {
50
50
  * The ContractHandler for this type knows how to interpret these.
51
51
  */
52
52
  params: Record<string, string>;
53
- /** The pkScript hex - unique identifier and primary key for contracts */
53
+ /** The pkScript hex, used as the unique identifier and primary key for contracts. */
54
54
  script: string;
55
- /** The address derived from the script */
55
+ /** Address derived from the contract script. */
56
56
  address: string;
57
- /** Current state of the contract */
57
+ /** Current state of the contract. */
58
58
  state: ContractState;
59
- /** Unix timestamp (ms) when this contract was created */
59
+ /** Unix timestamp in milliseconds when this contract was created. */
60
60
  createdAt: number;
61
- /** Unix timestamp (ms) when this contract expires (optional) */
61
+ /** Unix timestamp in milliseconds when this contract expires. */
62
62
  expiresAt?: number;
63
63
  /**
64
64
  * Optional metadata for external integrations.
@@ -66,50 +66,54 @@ export interface Contract {
66
66
  metadata?: Record<string, unknown>;
67
67
  }
68
68
  /**
69
- * A VTXO that has been associated with a specific contract.
69
+ * A virtual output that has been associated with a specific contract.
70
70
  */
71
71
  export interface ContractVtxo extends ExtendedVirtualCoin {
72
- /** The contract script this VTXO belongs to */
72
+ /** The contract script this virtual output belongs to. */
73
73
  contractScript: string;
74
74
  }
75
75
  /**
76
- * Result of path selection - which tapleaf to use and extra witness data.
76
+ * Result of path selection, including the tapleaf to use and any extra witness data.
77
77
  */
78
78
  export interface PathSelection {
79
- /** The tapleaf script to use for spending */
79
+ /** Tapleaf script to use for spending. */
80
80
  leaf: TapLeafScript;
81
- /** Additional witness elements (e.g., preimage for HTLC) */
81
+ /** Additional witness elements, for example a preimage for HTLC-like paths. */
82
82
  extraWitness?: Bytes[];
83
- /** Sequence number override (for CSV timelocks) */
83
+ /**
84
+ * nSequence for the spending input, BIP-68 encoded when the leaf
85
+ * uses CSV. Decode with `sequenceToTimelock`; do NOT use as an
86
+ * absolute `Transaction.lockTime`.
87
+ */
84
88
  sequence?: number;
85
89
  }
86
90
  /**
87
91
  * Context for path selection decisions.
88
92
  */
89
93
  export interface PathContext {
90
- /** Is collaborative spending available (server cooperation)? */
94
+ /** Whether collaborative spending is available through server cooperation. */
91
95
  collaborative: boolean;
92
- /** Current time in milliseconds */
96
+ /** Current time in milliseconds. */
93
97
  currentTime: number;
94
- /** Current block height (optional) */
98
+ /** Current block height, when known. */
95
99
  blockHeight?: number;
96
100
  /**
97
- * Wallet's public key (x-only, 32 bytes hex).
98
- * Used by handlers to determine wallet's role in multi-party contracts.
101
+ * Wallet public key encoded as 32-byte x-only hex.
102
+ * Used by handlers to determine the wallet's role in multi-party contracts.
99
103
  */
100
104
  walletPubKey?: string;
101
105
  /**
102
- * Explicit role override (for multi-party contracts like VHTLC).
103
- * If not provided, handler may derive role from walletPubKey.
106
+ * Explicit role override for multi-party contracts such as VHTLC.
107
+ * If not provided, the handler may derive the role from `walletPubKey`.
104
108
  */
105
109
  role?: string;
106
- /** The specific VTXO being evaluated */
110
+ /** The specific virtual output being evaluated. */
107
111
  vtxo?: VirtualCoin;
108
112
  }
109
113
  /**
110
114
  * Handler for a specific contract type.
111
115
  *
112
- * Each contract type (default, vhtlc, etc.) has a handler that knows how to:
116
+ * Each contract type (`default`, `vhtlc`, etc.) has a handler that knows how to:
113
117
  * 1. Create the VtxoScript from parameters
114
118
  * 2. Serialize/deserialize parameters for storage
115
119
  * 3. Select the appropriate spending path based on context
@@ -134,14 +138,20 @@ export interface PathContext {
134
138
  * ```
135
139
  */
136
140
  export interface ContractHandler<P = Record<string, unknown>, S extends VtxoScript = VtxoScript> {
137
- /** The contract type this handler manages */
141
+ /** Contract type managed by this handler. */
138
142
  readonly type: string;
139
143
  /**
140
144
  * Create the VtxoScript from serialized parameters.
145
+ *
146
+ * @param params - Serialized contract parameters
147
+ * @returns Contract script instance
141
148
  */
142
149
  createScript(params: Record<string, string>): S;
143
150
  /**
144
151
  * Serialize typed parameters to string key-value pairs.
152
+ *
153
+ * @param params - Typed contract parameters
154
+ * @returns Serialized key-value representation
145
155
  */
146
156
  serializeParams(params: P): Record<string, string>;
147
157
  /**
@@ -203,7 +213,7 @@ export type ContractEventCallback = (event: ContractEvent) => void;
203
213
  */
204
214
  export type GetContractsFilter = ContractFilter;
205
215
  /**
206
- * Contract with its VTXOs included.
216
+ * Contract with its virtual outputs included.
207
217
  */
208
218
  export type ContractWithVtxos = {
209
219
  contract: Contract;
@@ -217,6 +227,6 @@ export interface ContractBalance {
217
227
  total: number;
218
228
  /** Spendable balance in satoshis */
219
229
  spendable: number;
220
- /** Number of VTXOs in this contract */
230
+ /** Number of virtual outputs in this contract */
221
231
  vtxoCount: number;
222
232
  }
@@ -5,7 +5,22 @@ import { AssetOutput } from "./assetOutput";
5
5
  import { Metadata } from "./metadata";
6
6
  import { BufferReader, BufferWriter } from "./utils";
7
7
  /**
8
- * An asset group contains inputs/outputs and all data related to a given asset id.
8
+ * An asset group contains inputs, outputs, and all data related to a given asset id.
9
+ *
10
+ * @see Packet
11
+ * @see AssetId
12
+ * @see AssetRef
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const group = AssetGroup.create(
17
+ * null, // asset ID: null for new issuance
18
+ * null, // control asset ID: null when reissuance not needed
19
+ * [], // asset inputs: empty for new issuance
20
+ * [AssetOutput.create(0, 1000)], // asset outputs: 1000 units at vout index 0
21
+ * [] // metadata: can be empty
22
+ * )
23
+ * ```
9
24
  */
10
25
  export declare class AssetGroup {
11
26
  readonly assetId: AssetId | null;
@@ -13,16 +28,92 @@ export declare class AssetGroup {
13
28
  readonly inputs: AssetInput[];
14
29
  readonly outputs: AssetOutput[];
15
30
  private readonly metadataList;
31
+ /** @see create */
16
32
  constructor(assetId: AssetId | null, controlAsset: AssetRef | null, inputs: AssetInput[], outputs: AssetOutput[], metadata: Metadata[]);
33
+ /**
34
+ * Create and validate an asset group.
35
+ *
36
+ * @param assetId - Asset id for this group, or `null` for fresh issuance
37
+ * @param controlAsset - Optional control asset reference for (re) issuance
38
+ * @param inputs - Asset inputs in the group
39
+ * @param outputs - Asset outputs in the group
40
+ * @param metadata - Metadata entries associated with the group
41
+ * @returns A validated asset group
42
+ * @throws Error if the group fails validation
43
+ * @see validate
44
+ */
17
45
  static create(assetId: AssetId | null, controlAsset: AssetRef | null, inputs: AssetInput[], outputs: AssetOutput[], metadata: Metadata[]): AssetGroup;
46
+ /**
47
+ * Decode an asset group from its hex string form.
48
+ *
49
+ * @param s - Hex-encoded asset group
50
+ * @returns Decoded asset group
51
+ * @throws Error if the string is not valid hex or does not encode a valid asset group
52
+ * @see toString
53
+ */
18
54
  static fromString(s: string): AssetGroup;
55
+ /**
56
+ * Decode an asset group from its serialized bytes.
57
+ *
58
+ * @param buf - Serialized asset group bytes
59
+ * @returns Decoded asset group
60
+ * @throws Error if the buffer is empty or malformed
61
+ */
19
62
  static fromBytes(buf: Uint8Array): AssetGroup;
63
+ /**
64
+ * Return true when the group represents an issuance.
65
+ *
66
+ * @returns `true` when the group has no asset id
67
+ */
20
68
  isIssuance(): boolean;
69
+ /**
70
+ * Return true when the group represents a reissuance.
71
+ *
72
+ * @returns `true` when the group has an asset id and outputs exceed local inputs
73
+ * @remarks
74
+ * Only local inputs contribute to the comparison; intent-backed inputs contribute `0` here.
75
+ */
21
76
  isReissuance(): boolean;
77
+ /**
78
+ * Serialize the asset group to raw bytes.
79
+ *
80
+ * @returns Serialized asset group bytes
81
+ * @see fromBytes
82
+ */
22
83
  serialize(): Uint8Array;
84
+ /**
85
+ * Validate the asset group and its child structures.
86
+ *
87
+ * @throws Error if the group is empty or violates issuance invariants
88
+ */
23
89
  validate(): void;
90
+ /**
91
+ * Convert the group into its batch-leaf representation for the given intent txid.
92
+ *
93
+ * @param intentTxid - Intent transaction id used to build the leaf input reference
94
+ * @returns Batch-leaf asset group
95
+ * @see AssetInput.createIntent
96
+ */
24
97
  toBatchLeafAssetGroup(intentTxid: Uint8Array): AssetGroup;
98
+ /**
99
+ * Encode the asset group to a hex string.
100
+ *
101
+ * @returns Hex-encoded asset group
102
+ * @see fromString
103
+ */
25
104
  toString(): string;
105
+ /**
106
+ * Decode an asset group from a binary reader.
107
+ *
108
+ * @param reader - Reader positioned at an asset group
109
+ * @returns Decoded asset group
110
+ * @throws Error if the encoded group is malformed
111
+ */
26
112
  static fromReader(reader: BufferReader): AssetGroup;
113
+ /**
114
+ * Serialize the asset group into an existing binary writer.
115
+ *
116
+ * @param writer - Writer to append the asset group to
117
+ */
27
118
  serializeTo(writer: BufferWriter): void;
28
119
  }
@@ -1,19 +1,83 @@
1
1
  import { BufferReader, BufferWriter } from "./utils";
2
2
  /**
3
- * AssetId represents the id of an asset.
4
- * @param txid - the genesis transaction id (decoded from hex)
5
- * @param groupIndex - the asset group index in the genesis transaction
3
+ * AssetId identifies a specific asset.
4
+ *
5
+ * @remarks
6
+ * Asset ids are derived from the genesis transaction id plus the asset group index.
7
+ *
8
+ * @see AssetRef
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const assetId = AssetId.create('00'.repeat(32), 0)
13
+ * const encoded = assetId.toString()
14
+ * const decoded = AssetId.fromString(encoded)
15
+ * ```
6
16
  */
7
17
  export declare class AssetId {
8
18
  readonly txid: Uint8Array;
9
19
  readonly groupIndex: number;
10
20
  private constructor();
21
+ /**
22
+ * Create an asset id from a genesis transaction id and group index.
23
+ *
24
+ * @param txid - Hex-encoded genesis transaction id
25
+ * @param groupIndex - Asset group index within the genesis transaction
26
+ * @returns A validated asset id
27
+ * @throws Error if the txid is missing, malformed, or not 32 bytes long
28
+ * @see fromString
29
+ */
11
30
  static create(txid: string, groupIndex: number): AssetId;
31
+ /**
32
+ * Decode an asset id from its hex string representation.
33
+ *
34
+ * @param s - Hex-encoded asset id
35
+ * @returns Decoded asset id
36
+ * @throws Error if the string is not valid hex or does not encode a valid asset id
37
+ * @see toString
38
+ */
12
39
  static fromString(s: string): AssetId;
40
+ /**
41
+ * Decode an asset id from its serialized bytes.
42
+ *
43
+ * @param buf - Serialized asset id bytes
44
+ * @returns Decoded asset id
45
+ * @throws Error if the buffer length is invalid
46
+ */
13
47
  static fromBytes(buf: Uint8Array): AssetId;
48
+ /**
49
+ * Serialize the asset id to raw bytes.
50
+ *
51
+ * @returns Serialized asset id bytes
52
+ * @see fromBytes
53
+ */
14
54
  serialize(): Uint8Array;
55
+ /**
56
+ * Encode the asset id to a hex string.
57
+ *
58
+ * @returns Hex-encoded asset id
59
+ * @see fromString
60
+ */
15
61
  toString(): string;
62
+ /**
63
+ * Validate the asset id fields.
64
+ *
65
+ * @throws Error if the txid is empty or the group index is out of range
66
+ */
16
67
  validate(): void;
68
+ /**
69
+ * Decode an asset id from a binary reader.
70
+ *
71
+ * @param reader - Reader positioned at an asset id
72
+ * @returns Decoded asset id
73
+ * @throws Error if the reader does not contain enough bytes
74
+ */
17
75
  static fromReader(reader: BufferReader): AssetId;
76
+ /**
77
+ * Serialize the asset id into an existing binary writer.
78
+ *
79
+ * @param writer - Writer to append the asset id to
80
+ * @see serialize
81
+ */
18
82
  serializeTo(writer: BufferWriter): void;
19
83
  }
@@ -17,16 +17,27 @@ type AssetInputIntent = Pick<AssetInputLocal, "vin" | "amount"> & {
17
17
  export declare class AssetInput {
18
18
  readonly input: AssetInputLocal | AssetInputIntent;
19
19
  private constructor();
20
+ /** Gets the transaction input index for an asset input, e.g. 0 */
20
21
  get vin(): number;
22
+ /** Gets the amount for an input (in most cases, 330 sats) */
21
23
  get amount(): bigint;
24
+ /** Create a local asset input that points at a transaction input index. */
22
25
  static create(vin: number, amount: bigint | number): AssetInput;
26
+ /** Create an intent-backed asset input referencing an external intent transaction. */
23
27
  static createIntent(txid: string, vin: number, amount: bigint | number): AssetInput;
28
+ /** Decode an asset input from its hex string form. */
24
29
  static fromString(s: string): AssetInput;
30
+ /** Decode an asset input from its serialized bytes. */
25
31
  static fromBytes(buf: Uint8Array): AssetInput;
32
+ /** Serialize the asset input to raw bytes. */
26
33
  serialize(): Uint8Array;
34
+ /** Encode the asset input to a hex string. */
27
35
  toString(): string;
36
+ /** Validate the asset input fields. */
28
37
  validate(): void;
38
+ /** Decode an asset input from a buffer reader. */
29
39
  static fromReader(reader: BufferReader): AssetInput;
40
+ /** Serialize the asset input into an existing buffer writer. */
30
41
  serializeTo(writer: BufferWriter): void;
31
42
  }
32
43
  /**
@@ -35,12 +46,19 @@ export declare class AssetInput {
35
46
  export declare class AssetInputs {
36
47
  readonly inputs: AssetInput[];
37
48
  private constructor();
49
+ /** Create a validated list of asset inputs. */
38
50
  static create(inputs: AssetInput[]): AssetInputs;
51
+ /** Decode an asset input list from its hex string form. */
39
52
  static fromString(s: string): AssetInputs;
53
+ /** Serialize the asset input list to raw bytes. */
40
54
  serialize(): Uint8Array;
55
+ /** Encode the asset input list to a hex string. */
41
56
  toString(): string;
57
+ /** Validate the asset input list. */
42
58
  validate(): void;
59
+ /** Decode an asset input list from a buffer reader. */
43
60
  static fromReader(reader: BufferReader): AssetInputs;
61
+ /** Serialize the asset input list into an existing buffer writer. */
44
62
  serializeTo(writer: BufferWriter): void;
45
63
  }
46
64
  export {};
@@ -11,13 +11,21 @@ export declare class AssetOutput {
11
11
  readonly amount: bigint;
12
12
  static readonly TYPE_LOCAL = 1;
13
13
  private constructor();
14
+ /** Create a local asset output referencing a transaction output index. */
14
15
  static create(vout: number, amount: bigint | number): AssetOutput;
16
+ /** Decode an asset output from its hex string form. */
15
17
  static fromString(s: string): AssetOutput;
18
+ /** Decode an asset output from its serialized bytes. */
16
19
  static fromBytes(buf: Uint8Array): AssetOutput;
20
+ /** Serialize the asset output to raw bytes. */
17
21
  serialize(): Uint8Array;
22
+ /** Encode the asset output to a hex string. */
18
23
  toString(): string;
24
+ /** Validate the asset output fields. */
19
25
  validate(): void;
26
+ /** Decode an asset output from a buffer reader. */
20
27
  static fromReader(reader: BufferReader): AssetOutput;
28
+ /** Serialize the asset output into an existing buffer writer. */
21
29
  serializeTo(writer: BufferWriter): void;
22
30
  }
23
31
  /**
@@ -29,11 +37,18 @@ export declare class AssetOutput {
29
37
  export declare class AssetOutputs {
30
38
  readonly outputs: AssetOutput[];
31
39
  private constructor();
40
+ /** Create a validated list of asset outputs. */
32
41
  static create(outputs: AssetOutput[]): AssetOutputs;
42
+ /** Decode an asset output list from its hex string form. */
33
43
  static fromString(s: string): AssetOutputs;
44
+ /** Serialize the asset output list to raw bytes. */
34
45
  serialize(): Uint8Array;
46
+ /** Encode the asset output list to a hex string. */
35
47
  toString(): string;
48
+ /** Validate the asset output list. */
36
49
  validate(): void;
50
+ /** Decode an asset output list from a buffer reader. */
37
51
  static fromReader(reader: BufferReader): AssetOutputs;
52
+ /** Serialize the asset output list into an existing buffer writer. */
38
53
  serializeTo(writer: BufferWriter): void;
39
54
  }
@@ -9,17 +9,83 @@ type AssetRefByGroup = {
9
9
  type: AssetRefType.ByGroup;
10
10
  groupIndex: number;
11
11
  };
12
+ /**
13
+ * Reference to either an explicit asset id or another asset group in the same packet.
14
+ *
15
+ * @see AssetId
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const refById = AssetRef.fromId(assetId)
20
+ * const refByGroup = AssetRef.fromGroupIndex(0)
21
+ * ```
22
+ */
12
23
  export declare class AssetRef {
13
24
  readonly ref: AssetRefByID | AssetRefByGroup;
14
25
  private constructor();
26
+ /** Reference type discriminator. */
15
27
  get type(): AssetRefType;
28
+ /**
29
+ * Create an asset reference that points to a specific asset id.
30
+ *
31
+ * @param assetId - Asset id referenced by this pointer
32
+ * @returns Asset reference by id
33
+ * @see fromGroupIndex
34
+ */
16
35
  static fromId(assetId: AssetId): AssetRef;
36
+ /**
37
+ * Create an asset reference that points to another asset group by index.
38
+ *
39
+ * @param groupIndex - Zero-based asset group index in the packet
40
+ * @returns Asset reference by group index
41
+ * @see fromId
42
+ */
17
43
  static fromGroupIndex(groupIndex: number): AssetRef;
44
+ /**
45
+ * Decode an asset reference from its hex string form.
46
+ *
47
+ * @param s - Hex-encoded asset reference
48
+ * @returns Decoded asset reference
49
+ * @throws Error if the string is not valid hex or does not encode a valid asset reference
50
+ * @see toString
51
+ */
18
52
  static fromString(s: string): AssetRef;
53
+ /**
54
+ * Decode an asset reference from its serialized bytes.
55
+ *
56
+ * @param buf - Serialized asset reference bytes
57
+ * @returns Decoded asset reference
58
+ * @throws Error if the buffer is empty or malformed
59
+ */
19
60
  static fromBytes(buf: Uint8Array): AssetRef;
61
+ /**
62
+ * Serialize the asset reference to raw bytes.
63
+ *
64
+ * @returns Serialized asset reference bytes
65
+ * @see fromBytes
66
+ */
20
67
  serialize(): Uint8Array;
68
+ /**
69
+ * Encode the asset reference to a hex string.
70
+ *
71
+ * @returns Hex-encoded asset reference
72
+ * @see fromString
73
+ */
21
74
  toString(): string;
75
+ /**
76
+ * Decode an asset reference from a binary reader.
77
+ *
78
+ * @param reader - Reader positioned at an asset reference
79
+ * @returns Decoded asset reference
80
+ * @throws Error if the type is unknown or the reader does not contain enough bytes
81
+ */
22
82
  static fromReader(reader: BufferReader): AssetRef;
83
+ /**
84
+ * Serialize the asset reference into an existing binary writer.
85
+ *
86
+ * @param writer - Writer to append the asset reference to
87
+ * @see serialize
88
+ */
23
89
  serializeTo(writer: BufferWriter): void;
24
90
  }
25
91
  export {};
@@ -9,15 +9,23 @@ export declare class Metadata {
9
9
  readonly key: Uint8Array;
10
10
  readonly value: Uint8Array;
11
11
  private constructor();
12
+ /** Create a metadata entry from raw key and value bytes. */
12
13
  static create(key: Bytes, value: Bytes): Metadata;
14
+ /** Decode metadata from its hex string form. */
13
15
  static fromString(s: string): Metadata;
16
+ /** Decode metadata from its serialized bytes. */
14
17
  static fromBytes(buf: Uint8Array): Metadata;
18
+ /** Serialize metadata to raw bytes. */
15
19
  serialize(): Uint8Array;
20
+ /** Encode metadata to a hex string. */
16
21
  toString(): string;
17
22
  get keyString(): string;
18
23
  get valueString(): string;
24
+ /** Validate the metadata key and value. */
19
25
  validate(): void;
26
+ /** Decode metadata from a buffer reader. */
20
27
  static fromReader(reader: BufferReader): Metadata;
28
+ /** Serialize metadata into an existing buffer writer. */
21
29
  serializeTo(writer: BufferWriter): void;
22
30
  }
23
31
  export declare class MetadataList {
@@ -26,12 +34,19 @@ export declare class MetadataList {
26
34
  static readonly ARK_BRANCH_TAG = "ArkadeAssetBranch";
27
35
  static readonly ARK_LEAF_VERSION = 0;
28
36
  constructor(items: Metadata[]);
37
+ /** Create a metadata list from its hex string form. */
29
38
  static fromString(s: string): MetadataList;
39
+ /** Decode a metadata list from its serialized bytes. */
30
40
  static fromBytes(buf: Uint8Array): MetadataList;
41
+ /** Decode a metadata list from a buffer reader. */
31
42
  static fromReader(reader: BufferReader): MetadataList;
43
+ /** Serialize the metadata list into an existing buffer writer. */
32
44
  serializeTo(writer: BufferWriter): void;
45
+ /** Serialize the metadata list to raw bytes. */
33
46
  serialize(): Uint8Array;
47
+ /** Iterate through metadata entries in insertion order. */
34
48
  [Symbol.iterator](): Iterator<Metadata>;
35
49
  get length(): number;
50
+ /** Compute the tagged Merkle root for the metadata list. */
36
51
  hash(): Uint8Array;
37
52
  }
@@ -9,6 +9,7 @@ export declare class Packet implements ExtensionPacket {
9
9
  /** PACKET_TYPE is the 1-byte TLV type tag used in the Extension envelope. */
10
10
  static readonly PACKET_TYPE = 0;
11
11
  private constructor();
12
+ /** Create a validated asset packet from a list of asset groups. */
12
13
  static create(groups: AssetGroup[]): Packet;
13
14
  /**
14
15
  * fromBytes parses a Packet from raw bytes.
@@ -22,10 +23,11 @@ export declare class Packet implements ExtensionPacket {
22
23
  * type returns the TLV packet type tag. Implements ExtensionPacket interface.
23
24
  */
24
25
  type(): number;
26
+ /** Convert the packet into the batch-leaf form for a specific intent transaction id. */
25
27
  leafTxPacket(intentTxid: Uint8Array): Packet;
26
28
  /**
27
29
  * serialize encodes the packet as raw bytes (varint group count + group data).
28
- * Does NOT include OP_RETURN, ARK magic, or TLV type/length those are
30
+ * Does NOT include OP_RETURN, Arkade magic bytes (`ARK`), or TLV type/length; those are
29
31
  * added by the Extension module.
30
32
  */
31
33
  serialize(): Uint8Array;
@@ -33,6 +35,7 @@ export declare class Packet implements ExtensionPacket {
33
35
  * toString returns the hex-encoded raw packet bytes.
34
36
  */
35
37
  toString(): string;
38
+ /** Validate packet structure and cross-group references. */
36
39
  validate(): void;
37
40
  private static fromReader;
38
41
  }
@@ -6,7 +6,7 @@ export type { ExtensionPacket } from "./packet";
6
6
  export { UnknownPacket } from "./packet";
7
7
  /**
8
8
  * ArkadeMagic is the 3-byte magic prefix ("ARK") that identifies an OP_RETURN
9
- * output as an ark extension blob.
9
+ * output as an Arkade extension blob.
10
10
  */
11
11
  export declare const ARKADE_MAGIC: Uint8Array<ArrayBuffer>;
12
12
  /**
@@ -1,4 +1,18 @@
1
1
  import { Transaction } from "./utils/transaction";
2
2
  import { TransactionInputUpdate, TransactionOutput } from "@scure/btc-signer/psbt.js";
3
+ /**
4
+ * Build a forfeit transaction that spends the provided inputs to a single forfeit output.
5
+ *
6
+ * @param inputs - Inputs to include in the forfeit transaction
7
+ * @param forfeitPkScript - ScriptPubKey for the forfeit output
8
+ * @param txLocktime - Optional locktime to apply to the transaction
9
+ */
3
10
  export declare function buildForfeitTx(inputs: TransactionInputUpdate[], forfeitPkScript: Uint8Array, txLocktime?: number): Transaction;
11
+ /**
12
+ * Build a forfeit transaction using an explicit output descriptor (used for delegated renewals)
13
+ *
14
+ * @param inputs - Inputs to include in the forfeit transaction
15
+ * @param output - Primary transaction output
16
+ * @param txLocktime - Optional locktime to apply to the transaction
17
+ */
4
18
  export declare function buildForfeitTxWithOutput(inputs: TransactionInputUpdate[], output: TransactionOutput, txLocktime?: number): Transaction;