@arkade-os/sdk 0.4.15 → 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 (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 +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 +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 +125 -67
  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 +40 -24
  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 +125 -67
  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 +40 -63
  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
@@ -2,15 +2,34 @@ import { hex } from "@scure/base";
2
2
  import { TX_HASH_SIZE, ASSET_ID_SIZE } from './types.js';
3
3
  import { BufferReader, BufferWriter, isZeroBytes } from './utils.js';
4
4
  /**
5
- * AssetId represents the id of an asset.
6
- * @param txid - the genesis transaction id (decoded from hex)
7
- * @param groupIndex - the asset group index in the genesis transaction
5
+ * AssetId identifies a specific asset.
6
+ *
7
+ * @remarks
8
+ * Asset ids are derived from the genesis transaction id plus the asset group index.
9
+ *
10
+ * @see AssetRef
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const assetId = AssetId.create('00'.repeat(32), 0)
15
+ * const encoded = assetId.toString()
16
+ * const decoded = AssetId.fromString(encoded)
17
+ * ```
8
18
  */
9
19
  export class AssetId {
10
20
  constructor(txid, groupIndex) {
11
21
  this.txid = txid;
12
22
  this.groupIndex = groupIndex;
13
23
  }
24
+ /**
25
+ * Create an asset id from a genesis transaction id and group index.
26
+ *
27
+ * @param txid - Hex-encoded genesis transaction id
28
+ * @param groupIndex - Asset group index within the genesis transaction
29
+ * @returns A validated asset id
30
+ * @throws Error if the txid is missing, malformed, or not 32 bytes long
31
+ * @see fromString
32
+ */
14
33
  static create(txid, groupIndex) {
15
34
  if (!txid) {
16
35
  throw new Error("missing txid");
@@ -29,6 +48,14 @@ export class AssetId {
29
48
  assetId.validate();
30
49
  return assetId;
31
50
  }
51
+ /**
52
+ * Decode an asset id from its hex string representation.
53
+ *
54
+ * @param s - Hex-encoded asset id
55
+ * @returns Decoded asset id
56
+ * @throws Error if the string is not valid hex or does not encode a valid asset id
57
+ * @see toString
58
+ */
32
59
  static fromString(s) {
33
60
  let buf;
34
61
  try {
@@ -39,6 +66,13 @@ export class AssetId {
39
66
  }
40
67
  return AssetId.fromBytes(buf);
41
68
  }
69
+ /**
70
+ * Decode an asset id from its serialized bytes.
71
+ *
72
+ * @param buf - Serialized asset id bytes
73
+ * @returns Decoded asset id
74
+ * @throws Error if the buffer length is invalid
75
+ */
42
76
  static fromBytes(buf) {
43
77
  if (!buf || buf.length === 0) {
44
78
  throw new Error("missing asset id");
@@ -49,14 +83,31 @@ export class AssetId {
49
83
  const reader = new BufferReader(buf);
50
84
  return AssetId.fromReader(reader);
51
85
  }
86
+ /**
87
+ * Serialize the asset id to raw bytes.
88
+ *
89
+ * @returns Serialized asset id bytes
90
+ * @see fromBytes
91
+ */
52
92
  serialize() {
53
93
  const writer = new BufferWriter();
54
94
  this.serializeTo(writer);
55
95
  return writer.toBytes();
56
96
  }
97
+ /**
98
+ * Encode the asset id to a hex string.
99
+ *
100
+ * @returns Hex-encoded asset id
101
+ * @see fromString
102
+ */
57
103
  toString() {
58
104
  return hex.encode(this.serialize());
59
105
  }
106
+ /**
107
+ * Validate the asset id fields.
108
+ *
109
+ * @throws Error if the txid is empty or the group index is out of range
110
+ */
60
111
  validate() {
61
112
  if (isZeroBytes(this.txid)) {
62
113
  throw new Error("empty txid");
@@ -67,6 +118,13 @@ export class AssetId {
67
118
  throw new Error(`invalid group index: ${this.groupIndex}, must be in range [0, 65535]`);
68
119
  }
69
120
  }
121
+ /**
122
+ * Decode an asset id from a binary reader.
123
+ *
124
+ * @param reader - Reader positioned at an asset id
125
+ * @returns Decoded asset id
126
+ * @throws Error if the reader does not contain enough bytes
127
+ */
70
128
  static fromReader(reader) {
71
129
  if (reader.remaining() < ASSET_ID_SIZE) {
72
130
  throw new Error(`invalid asset id length: got ${reader.remaining()}, want ${ASSET_ID_SIZE}`);
@@ -77,6 +135,12 @@ export class AssetId {
77
135
  assetId.validate();
78
136
  return assetId;
79
137
  }
138
+ /**
139
+ * Serialize the asset id into an existing binary writer.
140
+ *
141
+ * @param writer - Writer to append the asset id to
142
+ * @see serialize
143
+ */
80
144
  serializeTo(writer) {
81
145
  writer.write(this.txid);
82
146
  writer.writeUint16LE(this.groupIndex);
@@ -10,12 +10,15 @@ export class AssetInput {
10
10
  constructor(input) {
11
11
  this.input = input;
12
12
  }
13
+ /** Gets the transaction input index for an asset input, e.g. 0 */
13
14
  get vin() {
14
15
  return this.input.vin;
15
16
  }
17
+ /** Gets the amount for an input (in most cases, 330 sats) */
16
18
  get amount() {
17
19
  return this.input.amount;
18
20
  }
21
+ /** Create a local asset input that points at a transaction input index. */
19
22
  static create(vin, amount) {
20
23
  const input = new AssetInput({
21
24
  type: AssetInputType.Local,
@@ -25,6 +28,7 @@ export class AssetInput {
25
28
  input.validate();
26
29
  return input;
27
30
  }
31
+ /** Create an intent-backed asset input referencing an external intent transaction. */
28
32
  static createIntent(txid, vin, amount) {
29
33
  if (!txid || txid.length === 0) {
30
34
  throw new Error("missing input intent txid");
@@ -48,6 +52,7 @@ export class AssetInput {
48
52
  input.validate();
49
53
  return input;
50
54
  }
55
+ /** Decode an asset input from its hex string form. */
51
56
  static fromString(s) {
52
57
  let buf;
53
58
  try {
@@ -58,18 +63,22 @@ export class AssetInput {
58
63
  }
59
64
  return AssetInput.fromBytes(buf);
60
65
  }
66
+ /** Decode an asset input from its serialized bytes. */
61
67
  static fromBytes(buf) {
62
68
  const reader = new BufferReader(buf);
63
69
  return AssetInput.fromReader(reader);
64
70
  }
71
+ /** Serialize the asset input to raw bytes. */
65
72
  serialize() {
66
73
  const writer = new BufferWriter();
67
74
  this.serializeTo(writer);
68
75
  return writer.toBytes();
69
76
  }
77
+ /** Encode the asset input to a hex string. */
70
78
  toString() {
71
79
  return hex.encode(this.serialize());
72
80
  }
81
+ /** Validate the asset input fields. */
73
82
  validate() {
74
83
  switch (this.input.type) {
75
84
  case AssetInputType.Local:
@@ -81,6 +90,7 @@ export class AssetInput {
81
90
  break;
82
91
  }
83
92
  }
93
+ /** Decode an asset input from a buffer reader. */
84
94
  static fromReader(reader) {
85
95
  const type = reader.readByte();
86
96
  let input;
@@ -118,6 +128,7 @@ export class AssetInput {
118
128
  input.validate();
119
129
  return input;
120
130
  }
131
+ /** Serialize the asset input into an existing buffer writer. */
121
132
  serializeTo(writer) {
122
133
  writer.writeByte(this.input.type);
123
134
  if (this.input.type === AssetInputType.Intent) {
@@ -134,11 +145,13 @@ export class AssetInputs {
134
145
  constructor(inputs) {
135
146
  this.inputs = inputs;
136
147
  }
148
+ /** Create a validated list of asset inputs. */
137
149
  static create(inputs) {
138
150
  const list = new AssetInputs(inputs);
139
151
  list.validate();
140
152
  return list;
141
153
  }
154
+ /** Decode an asset input list from its hex string form. */
142
155
  static fromString(s) {
143
156
  if (!s || s.length === 0) {
144
157
  throw new Error("missing asset inputs");
@@ -153,14 +166,17 @@ export class AssetInputs {
153
166
  const reader = new BufferReader(buf);
154
167
  return AssetInputs.fromReader(reader);
155
168
  }
169
+ /** Serialize the asset input list to raw bytes. */
156
170
  serialize() {
157
171
  const writer = new BufferWriter();
158
172
  this.serializeTo(writer);
159
173
  return writer.toBytes();
160
174
  }
175
+ /** Encode the asset input list to a hex string. */
161
176
  toString() {
162
177
  return hex.encode(this.serialize());
163
178
  }
179
+ /** Validate the asset input list. */
164
180
  validate() {
165
181
  const seen = new Set();
166
182
  let listType = AssetInputType.Unspecified;
@@ -182,6 +198,7 @@ export class AssetInputs {
182
198
  }
183
199
  }
184
200
  }
201
+ /** Decode an asset input list from a buffer reader. */
185
202
  static fromReader(reader) {
186
203
  const count = Number(reader.readVarUint());
187
204
  const inputs = [];
@@ -190,6 +207,7 @@ export class AssetInputs {
190
207
  }
191
208
  return AssetInputs.create(inputs);
192
209
  }
210
+ /** Serialize the asset input list into an existing buffer writer. */
193
211
  serializeTo(writer) {
194
212
  writer.writeVarUint(this.inputs.length);
195
213
  for (const input of this.inputs) {
@@ -12,11 +12,13 @@ export class AssetOutput {
12
12
  this.vout = vout;
13
13
  this.amount = amount;
14
14
  }
15
+ /** Create a local asset output referencing a transaction output index. */
15
16
  static create(vout, amount) {
16
17
  const output = new AssetOutput(vout, typeof amount === "number" ? BigInt(amount) : amount);
17
18
  output.validate();
18
19
  return output;
19
20
  }
21
+ /** Decode an asset output from its hex string form. */
20
22
  static fromString(s) {
21
23
  let buf;
22
24
  try {
@@ -27,6 +29,7 @@ export class AssetOutput {
27
29
  }
28
30
  return AssetOutput.fromBytes(buf);
29
31
  }
32
+ /** Decode an asset output from its serialized bytes. */
30
33
  static fromBytes(buf) {
31
34
  if (!buf || buf.length === 0) {
32
35
  throw new Error("missing asset output");
@@ -36,14 +39,17 @@ export class AssetOutput {
36
39
  output.validate();
37
40
  return output;
38
41
  }
42
+ /** Serialize the asset output to raw bytes. */
39
43
  serialize() {
40
44
  const writer = new BufferWriter();
41
45
  this.serializeTo(writer);
42
46
  return writer.toBytes();
43
47
  }
48
+ /** Encode the asset output to a hex string. */
44
49
  toString() {
45
50
  return hex.encode(this.serialize());
46
51
  }
52
+ /** Validate the asset output fields. */
47
53
  validate() {
48
54
  if (!Number.isInteger(this.vout) ||
49
55
  this.vout < 0 ||
@@ -54,6 +60,7 @@ export class AssetOutput {
54
60
  throw new Error("asset output amount must be greater than 0");
55
61
  }
56
62
  }
63
+ /** Decode an asset output from a buffer reader. */
57
64
  static fromReader(reader) {
58
65
  if (reader.remaining() < 2) {
59
66
  throw new Error("invalid asset output vout length");
@@ -75,6 +82,7 @@ export class AssetOutput {
75
82
  const amount = reader.readVarUint();
76
83
  return new AssetOutput(vout, amount);
77
84
  }
85
+ /** Serialize the asset output into an existing buffer writer. */
78
86
  serializeTo(writer) {
79
87
  writer.writeByte(0x01);
80
88
  writer.writeUint16LE(this.vout);
@@ -94,11 +102,13 @@ export class AssetOutputs {
94
102
  constructor(outputs) {
95
103
  this.outputs = outputs;
96
104
  }
105
+ /** Create a validated list of asset outputs. */
97
106
  static create(outputs) {
98
107
  const list = new AssetOutputs(outputs);
99
108
  list.validate();
100
109
  return list;
101
110
  }
111
+ /** Decode an asset output list from its hex string form. */
102
112
  static fromString(s) {
103
113
  if (!s || s.length === 0) {
104
114
  throw new Error("missing asset outputs");
@@ -113,14 +123,17 @@ export class AssetOutputs {
113
123
  const reader = new BufferReader(buf);
114
124
  return AssetOutputs.fromReader(reader);
115
125
  }
126
+ /** Serialize the asset output list to raw bytes. */
116
127
  serialize() {
117
128
  const writer = new BufferWriter();
118
129
  this.serializeTo(writer);
119
130
  return writer.toBytes();
120
131
  }
132
+ /** Encode the asset output list to a hex string. */
121
133
  toString() {
122
134
  return hex.encode(this.serialize());
123
135
  }
136
+ /** Validate the asset output list. */
124
137
  validate() {
125
138
  const seen = new Set();
126
139
  for (const output of this.outputs) {
@@ -131,6 +144,7 @@ export class AssetOutputs {
131
144
  seen.add(output.vout);
132
145
  }
133
146
  }
147
+ /** Decode an asset output list from a buffer reader. */
134
148
  static fromReader(reader) {
135
149
  const count = Number(reader.readVarUint());
136
150
  if (count === 0) {
@@ -144,6 +158,7 @@ export class AssetOutputs {
144
158
  result.validate();
145
159
  return result;
146
160
  }
161
+ /** Serialize the asset output list into an existing buffer writer. */
147
162
  serializeTo(writer) {
148
163
  this.validate();
149
164
  writer.writeVarUint(this.outputs.length);
@@ -2,19 +2,53 @@ import { hex } from "@scure/base";
2
2
  import { AssetRefType } from './types.js';
3
3
  import { AssetId } from './assetId.js';
4
4
  import { BufferReader, BufferWriter } from './utils.js';
5
+ /**
6
+ * Reference to either an explicit asset id or another asset group in the same packet.
7
+ *
8
+ * @see AssetId
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const refById = AssetRef.fromId(assetId)
13
+ * const refByGroup = AssetRef.fromGroupIndex(0)
14
+ * ```
15
+ */
5
16
  export class AssetRef {
6
17
  constructor(ref) {
7
18
  this.ref = ref;
8
19
  }
20
+ /** Reference type discriminator. */
9
21
  get type() {
10
22
  return this.ref.type;
11
23
  }
24
+ /**
25
+ * Create an asset reference that points to a specific asset id.
26
+ *
27
+ * @param assetId - Asset id referenced by this pointer
28
+ * @returns Asset reference by id
29
+ * @see fromGroupIndex
30
+ */
12
31
  static fromId(assetId) {
13
32
  return new AssetRef({ type: AssetRefType.ByID, assetId });
14
33
  }
34
+ /**
35
+ * Create an asset reference that points to another asset group by index.
36
+ *
37
+ * @param groupIndex - Zero-based asset group index in the packet
38
+ * @returns Asset reference by group index
39
+ * @see fromId
40
+ */
15
41
  static fromGroupIndex(groupIndex) {
16
42
  return new AssetRef({ type: AssetRefType.ByGroup, groupIndex });
17
43
  }
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) {
19
53
  let buf;
20
54
  try {
@@ -25,6 +59,13 @@ export class AssetRef {
25
59
  }
26
60
  return AssetRef.fromBytes(buf);
27
61
  }
62
+ /**
63
+ * Decode an asset reference from its serialized bytes.
64
+ *
65
+ * @param buf - Serialized asset reference bytes
66
+ * @returns Decoded asset reference
67
+ * @throws Error if the buffer is empty or malformed
68
+ */
28
69
  static fromBytes(buf) {
29
70
  if (!buf || buf.length === 0) {
30
71
  throw new Error("missing asset ref");
@@ -32,14 +73,33 @@ export class AssetRef {
32
73
  const reader = new BufferReader(buf);
33
74
  return AssetRef.fromReader(reader);
34
75
  }
76
+ /**
77
+ * Serialize the asset reference to raw bytes.
78
+ *
79
+ * @returns Serialized asset reference bytes
80
+ * @see fromBytes
81
+ */
35
82
  serialize() {
36
83
  const writer = new BufferWriter();
37
84
  this.serializeTo(writer);
38
85
  return writer.toBytes();
39
86
  }
87
+ /**
88
+ * Encode the asset reference to a hex string.
89
+ *
90
+ * @returns Hex-encoded asset reference
91
+ * @see fromString
92
+ */
40
93
  toString() {
41
94
  return hex.encode(this.serialize());
42
95
  }
96
+ /**
97
+ * Decode an asset reference from a binary reader.
98
+ *
99
+ * @param reader - Reader positioned at an asset reference
100
+ * @returns Decoded asset reference
101
+ * @throws Error if the type is unknown or the reader does not contain enough bytes
102
+ */
43
103
  static fromReader(reader) {
44
104
  const type = reader.readByte();
45
105
  let ref;
@@ -64,6 +124,12 @@ export class AssetRef {
64
124
  }
65
125
  return ref;
66
126
  }
127
+ /**
128
+ * Serialize the asset reference into an existing binary writer.
129
+ *
130
+ * @param writer - Writer to append the asset reference to
131
+ * @see serialize
132
+ */
67
133
  serializeTo(writer) {
68
134
  writer.writeByte(this.ref.type);
69
135
  switch (this.ref.type) {
@@ -12,11 +12,13 @@ export class Metadata {
12
12
  this.key = key;
13
13
  this.value = value;
14
14
  }
15
+ /** Create a metadata entry from raw key and value bytes. */
15
16
  static create(key, value) {
16
17
  const md = new Metadata(key, value);
17
18
  md.validate();
18
19
  return md;
19
20
  }
21
+ /** Decode metadata from its hex string form. */
20
22
  static fromString(s) {
21
23
  let buf;
22
24
  try {
@@ -27,6 +29,7 @@ export class Metadata {
27
29
  }
28
30
  return Metadata.fromBytes(buf);
29
31
  }
32
+ /** Decode metadata from its serialized bytes. */
30
33
  static fromBytes(buf) {
31
34
  if (!buf || buf.length === 0) {
32
35
  throw new Error("missing metadata");
@@ -34,11 +37,13 @@ export class Metadata {
34
37
  const reader = new BufferReader(buf);
35
38
  return Metadata.fromReader(reader);
36
39
  }
40
+ /** Serialize metadata to raw bytes. */
37
41
  serialize() {
38
42
  const writer = new BufferWriter();
39
43
  this.serializeTo(writer);
40
44
  return writer.toBytes();
41
45
  }
46
+ /** Encode metadata to a hex string. */
42
47
  toString() {
43
48
  return hex.encode(this.serialize());
44
49
  }
@@ -48,6 +53,7 @@ export class Metadata {
48
53
  get valueString() {
49
54
  return new TextDecoder().decode(this.value);
50
55
  }
56
+ /** Validate the metadata key and value. */
51
57
  validate() {
52
58
  if (this.key.length === 0) {
53
59
  throw new Error("missing metadata key");
@@ -56,6 +62,7 @@ export class Metadata {
56
62
  throw new Error("missing metadata value");
57
63
  }
58
64
  }
65
+ /** Decode metadata from a buffer reader. */
59
66
  static fromReader(reader) {
60
67
  let key;
61
68
  let value;
@@ -75,6 +82,7 @@ export class Metadata {
75
82
  md.validate();
76
83
  return md;
77
84
  }
85
+ /** Serialize metadata into an existing buffer writer. */
78
86
  serializeTo(writer) {
79
87
  writer.writeVarSlice(this.key);
80
88
  writer.writeVarSlice(this.value);
@@ -84,6 +92,7 @@ export class MetadataList {
84
92
  constructor(items) {
85
93
  this.items = items;
86
94
  }
95
+ /** Create a metadata list from its hex string form. */
87
96
  static fromString(s) {
88
97
  let buf;
89
98
  try {
@@ -94,6 +103,7 @@ export class MetadataList {
94
103
  }
95
104
  return MetadataList.fromBytes(buf);
96
105
  }
106
+ /** Decode a metadata list from its serialized bytes. */
97
107
  static fromBytes(buf) {
98
108
  if (!buf || buf.length === 0) {
99
109
  throw new Error("missing metadata list");
@@ -101,28 +111,33 @@ export class MetadataList {
101
111
  const reader = new BufferReader(buf);
102
112
  return MetadataList.fromReader(reader);
103
113
  }
114
+ /** Decode a metadata list from a buffer reader. */
104
115
  static fromReader(reader) {
105
116
  const count = Number(reader.readVarUint());
106
117
  const items = Array.from({ length: count }, () => Metadata.fromReader(reader));
107
118
  return new MetadataList(items);
108
119
  }
120
+ /** Serialize the metadata list into an existing buffer writer. */
109
121
  serializeTo(writer) {
110
122
  writer.writeVarUint(this.items.length);
111
123
  for (const item of this) {
112
124
  item.serializeTo(writer);
113
125
  }
114
126
  }
127
+ /** Serialize the metadata list to raw bytes. */
115
128
  serialize() {
116
129
  const writer = new BufferWriter();
117
130
  this.serializeTo(writer);
118
131
  return writer.toBytes();
119
132
  }
133
+ /** Iterate through metadata entries in insertion order. */
120
134
  [Symbol.iterator]() {
121
135
  return this.items[Symbol.iterator]();
122
136
  }
123
137
  get length() {
124
138
  return this.items.length;
125
139
  }
140
+ /** Compute the tagged Merkle root for the metadata list. */
126
141
  hash() {
127
142
  if (this.items.length === 0)
128
143
  throw new Error("missing metadata list");
@@ -10,6 +10,7 @@ export class Packet {
10
10
  constructor(groups) {
11
11
  this.groups = groups;
12
12
  }
13
+ /** Create a validated asset packet from a list of asset groups. */
13
14
  static create(groups) {
14
15
  const p = new Packet(groups);
15
16
  p.validate();
@@ -43,13 +44,14 @@ export class Packet {
43
44
  type() {
44
45
  return Packet.PACKET_TYPE;
45
46
  }
47
+ /** Convert the packet into the batch-leaf form for a specific intent transaction id. */
46
48
  leafTxPacket(intentTxid) {
47
49
  const leafGroups = this.groups.map((group) => group.toBatchLeafAssetGroup(intentTxid));
48
50
  return new Packet(leafGroups);
49
51
  }
50
52
  /**
51
53
  * serialize encodes the packet as raw bytes (varint group count + group data).
52
- * Does NOT include OP_RETURN, ARK magic, or TLV type/length those are
54
+ * Does NOT include OP_RETURN, Arkade magic bytes (`ARK`), or TLV type/length; those are
53
55
  * added by the Extension module.
54
56
  */
55
57
  serialize() {
@@ -69,6 +71,7 @@ export class Packet {
69
71
  toString() {
70
72
  return hex.encode(this.serialize());
71
73
  }
74
+ /** Validate packet structure and cross-group references. */
72
75
  validate() {
73
76
  if (this.groups.length === 0) {
74
77
  throw new Error("missing assets");
@@ -7,7 +7,7 @@ import { UnknownPacket } from './packet.js';
7
7
  export { UnknownPacket } from './packet.js';
8
8
  /**
9
9
  * ArkadeMagic is the 3-byte magic prefix ("ARK") that identifies an OP_RETURN
10
- * output as an ark extension blob.
10
+ * output as an Arkade extension blob.
11
11
  */
12
12
  export const ARKADE_MAGIC = new Uint8Array([0x41, 0x52, 0x4b]); // "ARK"
13
13
  /**
@@ -1,5 +1,12 @@
1
1
  import { Transaction } from './utils/transaction.js';
2
2
  import { P2A } from './utils/anchor.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 function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
4
11
  let amount = 0n;
5
12
  for (const input of inputs) {
@@ -13,6 +20,13 @@ export function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
13
20
  amount,
14
21
  }, txLocktime);
15
22
  }
23
+ /**
24
+ * Build a forfeit transaction using an explicit output descriptor (used for delegated renewals)
25
+ *
26
+ * @param inputs - Inputs to include in the forfeit transaction
27
+ * @param output - Primary transaction output
28
+ * @param txLocktime - Optional locktime to apply to the transaction
29
+ */
16
30
  export function buildForfeitTxWithOutput(inputs, output, txLocktime) {
17
31
  const tx = new Transaction({
18
32
  version: 3,
@@ -41,7 +41,7 @@ function buildDescriptor(seed, isMainnet) {
41
41
  * format is HD-ready, allowing future support for multiple addresses
42
42
  * and change derivation.
43
43
  *
44
- * Prefer this (or {@link MnemonicIdentity}) over `SingleKey` for new
44
+ * Prefer this (or @see MnemonicIdentity) over `SingleKey` for new
45
45
  * integrations — `SingleKey` exists for backward compatibility with
46
46
  * raw nsec-style keys.
47
47
  *
@@ -157,7 +157,7 @@ export class SeedIdentity {
157
157
  *
158
158
  * This is the most user-friendly identity type — recommended for wallet
159
159
  * applications where users manage their own backup phrase. Extends
160
- * {@link SeedIdentity} with mnemonic validation and optional passphrase
160
+ * @see SeedIdentity with mnemonic validation and optional passphrase
161
161
  * support.
162
162
  *
163
163
  * @example
@@ -26,12 +26,15 @@ export class SingleKey {
26
26
  constructor(key) {
27
27
  this.key = key || randomPrivateKeyBytes();
28
28
  }
29
+ /** Create a signing identity from raw private key bytes. */
29
30
  static fromPrivateKey(privateKey) {
30
31
  return new SingleKey(privateKey);
31
32
  }
33
+ /** Create a signing identity from a hex-encoded private key. */
32
34
  static fromHex(privateKeyHex) {
33
35
  return new SingleKey(hex.decode(privateKeyHex));
34
36
  }
37
+ /** Create a signing identity with a freshly generated random private key. */
35
38
  static fromRandomBytes() {
36
39
  return new SingleKey(randomPrivateKeyBytes());
37
40
  }
@@ -88,6 +91,7 @@ export class SingleKey {
88
91
  }
89
92
  }
90
93
  export class ReadonlySingleKey {
94
+ /** Create a readonly identity from a compressed public key. */
91
95
  constructor(publicKey) {
92
96
  this.publicKey = publicKey;
93
97
  if (publicKey.length !== 33) {
package/dist/esm/index.js CHANGED
@@ -55,7 +55,7 @@ TxType, IndexerTxType, ChainTxType, SettlementEventType,
55
55
  setupServiceWorker, MessageBus, WalletMessageHandler, WalletNotInitializedError, ReadonlyWalletError, DelegatorNotConfiguredError, MESSAGE_BUS_NOT_INITIALIZED, MessageBusNotInitializedError, ServiceWorkerTimeoutError, ServiceWorkerWallet, ServiceWorkerReadonlyWallet, DEFAULT_MESSAGE_TIMEOUTS,
56
56
  // Tapscript
57
57
  decodeTapscript, MultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, CLTVMultisigTapscript, TapTreeCoder,
58
- // Ark PSBT fields
58
+ // Arkade PSBT fields
59
59
  ArkPsbtFieldKey, ArkPsbtFieldKeyType, setArkPsbtField, getArkPsbtFields, CosignerPublicKey, VtxoTreeExpiry, VtxoTaprootTree, ConditionWitness,
60
60
  // Utils
61
61
  buildOffchainTx, verifyTapscriptSignatures, waitForIncomingFunds, hasBoardingTxExpired, combineTapscriptSigs, isVtxoExpiringSoon, isValidArkAddress,