@arkade-os/sdk 0.5.0-rc.2 → 0.5.0-rc.21

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 (126) hide show
  1. package/README.md +90 -83
  2. package/dist/adapters/expo.cjs +5 -6
  3. package/dist/adapters/expo.d.cts +4 -4
  4. package/dist/adapters/expo.d.ts +4 -4
  5. package/dist/adapters/expo.js +3 -4
  6. package/dist/{asyncStorageTaskQueue-C5rBYlru.d.ts → asyncStorageTaskQueue-aL7K14e4.d.ts} +2 -2
  7. package/dist/{asyncStorageTaskQueue-BuDvgWh6.d.cts → asyncStorageTaskQueue-x8ok3tJy.d.cts} +2 -2
  8. package/dist/{chunk-ISO4TI5J.js → chunk-4FDNOLBO.js} +566 -459
  9. package/dist/chunk-4FDNOLBO.js.map +1 -0
  10. package/dist/{chunk-JZWLXNHV.cjs → chunk-5XBH5SAL.cjs} +574 -464
  11. package/dist/chunk-5XBH5SAL.cjs.map +1 -0
  12. package/dist/{chunk-3R476TDV.js → chunk-CXHJGED6.js} +293 -1071
  13. package/dist/chunk-CXHJGED6.js.map +1 -0
  14. package/dist/{chunk-ZRNQV6HV.js → chunk-EXFU6MTA.js} +4578 -4396
  15. package/dist/chunk-EXFU6MTA.js.map +1 -0
  16. package/dist/{chunk-43FKNLX4.cjs → chunk-GVF4OCTL.cjs} +357 -1114
  17. package/dist/chunk-GVF4OCTL.cjs.map +1 -0
  18. package/dist/{chunk-HLCGYOIH.cjs → chunk-HIZNPHB2.cjs} +37 -36
  19. package/dist/chunk-HIZNPHB2.cjs.map +1 -0
  20. package/dist/{chunk-4PKLULWT.js → chunk-JZAEFOE4.js} +109 -246
  21. package/dist/chunk-JZAEFOE4.js.map +1 -0
  22. package/dist/{chunk-ZOTXDOS5.js → chunk-LNJPVLIC.js} +30 -29
  23. package/dist/chunk-LNJPVLIC.js.map +1 -0
  24. package/dist/{chunk-NVZJSKZS.cjs → chunk-Q7PC3NHX.cjs} +121 -257
  25. package/dist/chunk-Q7PC3NHX.cjs.map +1 -0
  26. package/dist/{chunk-GMZZQXV5.cjs → chunk-R5OFJ23O.cjs} +4961 -4767
  27. package/dist/chunk-R5OFJ23O.cjs.map +1 -0
  28. package/dist/{chunk-6DNR46C7.js → chunk-S2WWOVFC.js} +7 -5
  29. package/dist/chunk-S2WWOVFC.js.map +1 -0
  30. package/dist/{chunk-D25O4EGY.cjs → chunk-VZMLADXQ.cjs} +12 -10
  31. package/dist/chunk-VZMLADXQ.cjs.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -10
  33. package/dist/contracts/handlers/index.d.cts +5 -5
  34. package/dist/contracts/handlers/index.d.ts +5 -5
  35. package/dist/contracts/handlers/index.js +2 -3
  36. package/dist/{delegate-BAX5QftB.d.ts → delegate-BT5iON1T.d.ts} +1 -1
  37. package/dist/{delegate-1yp1HyP7.d.cts → delegate-u6kXTtWY.d.cts} +1 -1
  38. package/dist/index-BCnhItOQ.d.cts +639 -0
  39. package/dist/{index-DUxufw76.d.cts → index-CK5QbTmZ.d.cts} +1387 -2404
  40. package/dist/{index-DUxufw76.d.ts → index-CK5QbTmZ.d.ts} +1387 -2404
  41. package/dist/index-D1D4cR-G.d.ts +639 -0
  42. package/dist/index.cjs +375 -340
  43. package/dist/index.d.cts +784 -1197
  44. package/dist/index.d.ts +784 -1197
  45. package/dist/index.js +4 -5
  46. package/dist/repositories/realm/index.cjs +201 -106
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +28 -16
  49. package/dist/repositories/realm/index.d.ts +28 -16
  50. package/dist/repositories/realm/index.js +190 -95
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +301 -189
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +32 -21
  55. package/dist/repositories/sqlite/index.d.ts +32 -21
  56. package/dist/repositories/sqlite/index.js +294 -182
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-D_iPiZIi.d.ts → taskRunner-BeYR6NpQ.d.ts} +2 -2
  59. package/dist/{taskRunner-Dr3NStc0.d.cts → taskRunner-Csey3EYJ.d.cts} +2 -2
  60. package/dist/wallet/expo/background.cjs +14 -15
  61. package/dist/wallet/expo/background.cjs.map +1 -1
  62. package/dist/wallet/expo/background.d.cts +10 -16
  63. package/dist/wallet/expo/background.d.ts +10 -16
  64. package/dist/wallet/expo/background.js +6 -7
  65. package/dist/wallet/expo/background.js.map +1 -1
  66. package/dist/wallet/expo/index.cjs +16 -23
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +6 -9
  69. package/dist/wallet/expo/index.d.ts +6 -9
  70. package/dist/wallet/expo/index.js +8 -15
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-DG3Qmbmt.d.cts +1848 -0
  73. package/dist/wallet-DzSLMxBZ.d.ts +1848 -0
  74. package/dist/worker/expo/index.cjs +9 -10
  75. package/dist/worker/expo/index.cjs.map +1 -1
  76. package/dist/worker/expo/index.d.cts +6 -6
  77. package/dist/worker/expo/index.d.ts +6 -6
  78. package/dist/worker/expo/index.js +5 -6
  79. package/dist/worker/expo/index.js.map +1 -1
  80. package/package.json +12 -51
  81. package/dist/adapters/asyncStorage.cjs +0 -48
  82. package/dist/adapters/asyncStorage.cjs.map +0 -1
  83. package/dist/adapters/asyncStorage.d.cts +0 -16
  84. package/dist/adapters/asyncStorage.d.ts +0 -16
  85. package/dist/adapters/asyncStorage.js +0 -46
  86. package/dist/adapters/asyncStorage.js.map +0 -1
  87. package/dist/adapters/fileSystem.cjs +0 -116
  88. package/dist/adapters/fileSystem.cjs.map +0 -1
  89. package/dist/adapters/fileSystem.d.cts +0 -17
  90. package/dist/adapters/fileSystem.d.ts +0 -17
  91. package/dist/adapters/fileSystem.js +0 -93
  92. package/dist/adapters/fileSystem.js.map +0 -1
  93. package/dist/adapters/indexedDB.cjs +0 -103
  94. package/dist/adapters/indexedDB.cjs.map +0 -1
  95. package/dist/adapters/indexedDB.d.cts +0 -18
  96. package/dist/adapters/indexedDB.d.ts +0 -18
  97. package/dist/adapters/indexedDB.js +0 -101
  98. package/dist/adapters/indexedDB.js.map +0 -1
  99. package/dist/adapters/localStorage.cjs +0 -50
  100. package/dist/adapters/localStorage.cjs.map +0 -1
  101. package/dist/adapters/localStorage.d.cts +0 -14
  102. package/dist/adapters/localStorage.d.ts +0 -14
  103. package/dist/adapters/localStorage.js +0 -48
  104. package/dist/adapters/localStorage.js.map +0 -1
  105. package/dist/chunk-3R476TDV.js.map +0 -1
  106. package/dist/chunk-43FKNLX4.cjs.map +0 -1
  107. package/dist/chunk-4PKLULWT.js.map +0 -1
  108. package/dist/chunk-5BLDMQED.cjs +0 -18
  109. package/dist/chunk-5BLDMQED.cjs.map +0 -1
  110. package/dist/chunk-6DNR46C7.js.map +0 -1
  111. package/dist/chunk-D25O4EGY.cjs.map +0 -1
  112. package/dist/chunk-GMZZQXV5.cjs.map +0 -1
  113. package/dist/chunk-HLCGYOIH.cjs.map +0 -1
  114. package/dist/chunk-ISO4TI5J.js.map +0 -1
  115. package/dist/chunk-JZWLXNHV.cjs.map +0 -1
  116. package/dist/chunk-NSBPE2FW.js +0 -15
  117. package/dist/chunk-NSBPE2FW.js.map +0 -1
  118. package/dist/chunk-NVZJSKZS.cjs.map +0 -1
  119. package/dist/chunk-ZOTXDOS5.js.map +0 -1
  120. package/dist/chunk-ZRNQV6HV.js.map +0 -1
  121. package/dist/hdWalletCapable-CmEU0NP1.d.ts +0 -2232
  122. package/dist/hdWalletCapable-eJgaT-ec.d.cts +0 -2232
  123. package/dist/index-Bem5vKzX.d.ts +0 -850
  124. package/dist/index-C0IanN1m.d.cts +0 -11
  125. package/dist/index-C0IanN1m.d.ts +0 -11
  126. package/dist/index-W_oMcOmG.d.cts +0 -850
@@ -1,14 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkJZWLXNHV_cjs = require('./chunk-JZWLXNHV.cjs');
4
- var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
3
+ var chunk5XBH5SAL_cjs = require('./chunk-5XBH5SAL.cjs');
5
4
  var base = require('@scure/base');
6
5
  var secp256k1_js = require('@noble/curves/secp256k1.js');
7
6
  var utils_js = require('@scure/btc-signer/utils.js');
8
7
 
9
8
  // src/extension/asset/index.ts
10
9
  var asset_exports = {};
11
- chunk5BLDMQED_cjs.__export(asset_exports, {
10
+ chunk5XBH5SAL_cjs.__export(asset_exports, {
12
11
  ASSET_ID_VECTORS: () => ASSET_ID_VECTORS,
13
12
  AssetGroup: () => AssetGroup,
14
13
  AssetId: () => AssetId,
@@ -42,8 +41,13 @@ var AssetRefType = /* @__PURE__ */ ((AssetRefType2) => {
42
41
  var MASK_ASSET_ID = 1;
43
42
  var MASK_CONTROL_ASSET = 2;
44
43
  var MASK_METADATA = 4;
45
-
46
- // src/extension/utils.ts
44
+ function hexOrThrow(s, message) {
45
+ try {
46
+ return base.hex.decode(s);
47
+ } catch {
48
+ throw new Error(message);
49
+ }
50
+ }
47
51
  var BufferWriter = class {
48
52
  buffer = [];
49
53
  write(data) {
@@ -186,11 +190,10 @@ var AssetId = class _AssetId {
186
190
  txid;
187
191
  groupIndex;
188
192
  /**
189
- * Create an asset id from a genesis transaction id and group index.
193
+ * Create a validated asset id from a genesis transaction id and group index.
190
194
  *
191
195
  * @param txid - Hex-encoded genesis transaction id
192
196
  * @param groupIndex - Asset group index within the genesis transaction
193
- * @returns A validated asset id
194
197
  * @throws Error if the txid is missing, malformed, or not 32 bytes long
195
198
  * @see fromString
196
199
  */
@@ -198,12 +201,7 @@ var AssetId = class _AssetId {
198
201
  if (!txid) {
199
202
  throw new Error("missing txid");
200
203
  }
201
- let buf;
202
- try {
203
- buf = base.hex.decode(txid);
204
- } catch {
205
- throw new Error("invalid txid format, must be hex");
206
- }
204
+ const buf = hexOrThrow(txid, "invalid txid format, must be hex");
207
205
  if (buf.length !== TX_HASH_SIZE) {
208
206
  throw new Error(
209
207
  `invalid txid length: got ${buf.length} bytes, want ${TX_HASH_SIZE} bytes`
@@ -216,25 +214,15 @@ var AssetId = class _AssetId {
216
214
  /**
217
215
  * Decode an asset id from its hex string representation.
218
216
  *
219
- * @param s - Hex-encoded asset id
220
- * @returns Decoded asset id
221
217
  * @throws Error if the string is not valid hex or does not encode a valid asset id
222
218
  * @see toString
223
219
  */
224
220
  static fromString(s) {
225
- let buf;
226
- try {
227
- buf = base.hex.decode(s);
228
- } catch {
229
- throw new Error("invalid asset id format, must be hex");
230
- }
231
- return _AssetId.fromBytes(buf);
221
+ return _AssetId.fromBytes(hexOrThrow(s, "invalid asset id format, must be hex"));
232
222
  }
233
223
  /**
234
224
  * Decode an asset id from its serialized bytes.
235
225
  *
236
- * @param buf - Serialized asset id bytes
237
- * @returns Decoded asset id
238
226
  * @throws Error if the buffer length is invalid
239
227
  */
240
228
  static fromBytes(buf) {
@@ -252,7 +240,6 @@ var AssetId = class _AssetId {
252
240
  /**
253
241
  * Serialize the asset id to raw bytes.
254
242
  *
255
- * @returns Serialized asset id bytes
256
243
  * @see fromBytes
257
244
  */
258
245
  serialize() {
@@ -263,7 +250,6 @@ var AssetId = class _AssetId {
263
250
  /**
264
251
  * Encode the asset id to a hex string.
265
252
  *
266
- * @returns Hex-encoded asset id
267
253
  * @see fromString
268
254
  */
269
255
  toString() {
@@ -283,10 +269,8 @@ var AssetId = class _AssetId {
283
269
  }
284
270
  }
285
271
  /**
286
- * Decode an asset id from a binary reader.
272
+ * Decode an asset id from a binary reader positioned at one.
287
273
  *
288
- * @param reader - Reader positioned at an asset id
289
- * @returns Decoded asset id
290
274
  * @throws Error if the reader does not contain enough bytes
291
275
  */
292
276
  static fromReader(reader) {
@@ -304,7 +288,6 @@ var AssetId = class _AssetId {
304
288
  /**
305
289
  * Serialize the asset id into an existing binary writer.
306
290
  *
307
- * @param writer - Writer to append the asset id to
308
291
  * @see serialize
309
292
  */
310
293
  serializeTo(writer) {
@@ -321,48 +304,31 @@ var AssetRef = class _AssetRef {
321
304
  get type() {
322
305
  return this.ref.type;
323
306
  }
324
- /**
325
- * Create an asset reference that points to a specific asset id.
326
- *
327
- * @param assetId - Asset id referenced by this pointer
328
- * @returns Asset reference by id
329
- * @see fromGroupIndex
330
- */
307
+ /** Reference a specific asset id. @see fromGroupIndex */
331
308
  static fromId(assetId) {
332
309
  return new _AssetRef({ type: 1 /* ByID */, assetId });
333
310
  }
334
311
  /**
335
- * Create an asset reference that points to another asset group by index.
312
+ * Reference another asset group in the packet.
336
313
  *
337
314
  * @param groupIndex - Zero-based asset group index in the packet
338
- * @returns Asset reference by group index
339
315
  * @see fromId
340
316
  */
341
317
  static fromGroupIndex(groupIndex) {
342
318
  return new _AssetRef({ type: 2 /* ByGroup */, groupIndex });
343
319
  }
344
320
  /**
345
- * Decode an asset reference from its hex string form.
321
+ * Decode an asset reference from hex.
346
322
  *
347
- * @param s - Hex-encoded asset reference
348
- * @returns Decoded asset reference
349
323
  * @throws Error if the string is not valid hex or does not encode a valid asset reference
350
324
  * @see toString
351
325
  */
352
326
  static fromString(s) {
353
- let buf;
354
- try {
355
- buf = base.hex.decode(s);
356
- } catch {
357
- throw new Error("invalid asset ref format, must be hex");
358
- }
359
- return _AssetRef.fromBytes(buf);
327
+ return _AssetRef.fromBytes(hexOrThrow(s, "invalid asset ref format, must be hex"));
360
328
  }
361
329
  /**
362
330
  * Decode an asset reference from its serialized bytes.
363
331
  *
364
- * @param buf - Serialized asset reference bytes
365
- * @returns Decoded asset reference
366
332
  * @throws Error if the buffer is empty or malformed
367
333
  */
368
334
  static fromBytes(buf) {
@@ -372,31 +338,19 @@ var AssetRef = class _AssetRef {
372
338
  const reader = new BufferReader(buf);
373
339
  return _AssetRef.fromReader(reader);
374
340
  }
375
- /**
376
- * Serialize the asset reference to raw bytes.
377
- *
378
- * @returns Serialized asset reference bytes
379
- * @see fromBytes
380
- */
341
+ /** Serialize to raw bytes. @see fromBytes */
381
342
  serialize() {
382
343
  const writer = new BufferWriter();
383
344
  this.serializeTo(writer);
384
345
  return writer.toBytes();
385
346
  }
386
- /**
387
- * Encode the asset reference to a hex string.
388
- *
389
- * @returns Hex-encoded asset reference
390
- * @see fromString
391
- */
347
+ /** Encode to hex. @see fromString */
392
348
  toString() {
393
349
  return base.hex.encode(this.serialize());
394
350
  }
395
351
  /**
396
- * Decode an asset reference from a binary reader.
352
+ * Decode an asset reference from a reader positioned at one.
397
353
  *
398
- * @param reader - Reader positioned at an asset reference
399
- * @returns Decoded asset reference
400
354
  * @throws Error if the type is unknown or the reader does not contain enough bytes
401
355
  */
402
356
  static fromReader(reader) {
@@ -423,12 +377,7 @@ var AssetRef = class _AssetRef {
423
377
  }
424
378
  return ref;
425
379
  }
426
- /**
427
- * Serialize the asset reference into an existing binary writer.
428
- *
429
- * @param writer - Writer to append the asset reference to
430
- * @see serialize
431
- */
380
+ /** Append the serialized reference to `writer`. @see serialize */
432
381
  serializeTo(writer) {
433
382
  writer.writeByte(this.ref.type);
434
383
  switch (this.ref.type) {
@@ -469,12 +418,7 @@ var AssetInput = class _AssetInput {
469
418
  if (!txid || txid.length === 0) {
470
419
  throw new Error("missing input intent txid");
471
420
  }
472
- let buf;
473
- try {
474
- buf = base.hex.decode(txid);
475
- } catch {
476
- throw new Error("invalid input intent txid format, must be hex");
477
- }
421
+ const buf = hexOrThrow(txid, "invalid input intent txid format, must be hex");
478
422
  if (buf.length !== TX_HASH_SIZE) {
479
423
  throw new Error("invalid input intent txid length");
480
424
  }
@@ -489,13 +433,7 @@ var AssetInput = class _AssetInput {
489
433
  }
490
434
  /** Decode an asset input from its hex string form. */
491
435
  static fromString(s) {
492
- let buf;
493
- try {
494
- buf = base.hex.decode(s);
495
- } catch {
496
- throw new Error("invalid format, must be hex");
497
- }
498
- return _AssetInput.fromBytes(buf);
436
+ return _AssetInput.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
499
437
  }
500
438
  /** Decode an asset input from its serialized bytes. */
501
439
  static fromBytes(buf) {
@@ -588,13 +526,7 @@ var AssetInputs = class _AssetInputs {
588
526
  if (!s || s.length === 0) {
589
527
  throw new Error("missing asset inputs");
590
528
  }
591
- let buf;
592
- try {
593
- buf = base.hex.decode(s);
594
- } catch {
595
- throw new Error("invalid asset inputs format, must be hex");
596
- }
597
- const reader = new BufferReader(buf);
529
+ const reader = new BufferReader(hexOrThrow(s, "invalid asset inputs format, must be hex"));
598
530
  return _AssetInputs.fromReader(reader);
599
531
  }
600
532
  /** Serialize the asset input list to raw bytes. */
@@ -662,13 +594,7 @@ var AssetOutput = class _AssetOutput {
662
594
  }
663
595
  /** Decode an asset output from its hex string form. */
664
596
  static fromString(s) {
665
- let buf;
666
- try {
667
- buf = base.hex.decode(s);
668
- } catch {
669
- throw new Error("invalid asset output format, must be hex");
670
- }
671
- return _AssetOutput.fromBytes(buf);
597
+ return _AssetOutput.fromBytes(hexOrThrow(s, "invalid asset output format, must be hex"));
672
598
  }
673
599
  /** Decode an asset output from its serialized bytes. */
674
600
  static fromBytes(buf) {
@@ -743,13 +669,7 @@ var AssetOutputs = class _AssetOutputs {
743
669
  if (!s || s.length === 0) {
744
670
  throw new Error("missing asset outputs");
745
671
  }
746
- let buf;
747
- try {
748
- buf = base.hex.decode(s);
749
- } catch {
750
- throw new Error("invalid asset outputs format, must be hex");
751
- }
752
- const reader = new BufferReader(buf);
672
+ const reader = new BufferReader(hexOrThrow(s, "invalid asset outputs format, must be hex"));
753
673
  return _AssetOutputs.fromReader(reader);
754
674
  }
755
675
  /** Serialize the asset output list to raw bytes. */
@@ -811,13 +731,7 @@ var Metadata = class _Metadata {
811
731
  }
812
732
  /** Decode metadata from its hex string form. */
813
733
  static fromString(s) {
814
- let buf;
815
- try {
816
- buf = base.hex.decode(s);
817
- } catch {
818
- throw new Error("invalid metadata format, must be hex");
819
- }
820
- return _Metadata.fromBytes(buf);
734
+ return _Metadata.fromBytes(hexOrThrow(s, "invalid metadata format, must be hex"));
821
735
  }
822
736
  /** Decode metadata from its serialized bytes. */
823
737
  static fromBytes(buf) {
@@ -886,13 +800,7 @@ var MetadataList = class _MetadataList {
886
800
  static ARK_LEAF_VERSION = 0;
887
801
  /** Create a metadata list from its hex string form. */
888
802
  static fromString(s) {
889
- let buf;
890
- try {
891
- buf = base.hex.decode(s);
892
- } catch {
893
- throw new Error("invalid metadata list format");
894
- }
895
- return _MetadataList.fromBytes(buf);
803
+ return _MetadataList.fromBytes(hexOrThrow(s, "invalid metadata list format"));
896
804
  }
897
805
  /** Decode a metadata list from its serialized bytes. */
898
806
  static fromBytes(buf) {
@@ -1005,13 +913,7 @@ var AssetGroup = class _AssetGroup {
1005
913
  * @see toString
1006
914
  */
1007
915
  static fromString(s) {
1008
- let buf;
1009
- try {
1010
- buf = base.hex.decode(s);
1011
- } catch {
1012
- throw new Error("invalid format, must be hex");
1013
- }
1014
- return _AssetGroup.fromBytes(buf);
916
+ return _AssetGroup.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
1015
917
  }
1016
918
  /**
1017
919
  * Decode an asset group from its serialized bytes.
@@ -1196,13 +1098,7 @@ var Packet = class _Packet {
1196
1098
  if (!s) {
1197
1099
  throw new Error("missing packet data");
1198
1100
  }
1199
- let buf;
1200
- try {
1201
- buf = base.hex.decode(s);
1202
- } catch {
1203
- throw new Error("invalid packet format, must be hex");
1204
- }
1205
- return _Packet.fromBytes(buf);
1101
+ return _Packet.fromBytes(hexOrThrow(s, "invalid packet format, must be hex"));
1206
1102
  }
1207
1103
  /**
1208
1104
  * type returns the TLV packet type tag. Implements ExtensionPacket interface.
@@ -1420,10 +1316,10 @@ async function indexerFetch(input, init) {
1420
1316
  const lastAttempt = attempt >= maxAttempts;
1421
1317
  let res;
1422
1318
  try {
1423
- res = await chunkJZWLXNHV_cjs.rateGate.runHttp(input, () => chunkJZWLXNHV_cjs.baseFetch(input, init));
1319
+ res = await chunk5XBH5SAL_cjs.rateGate.runHttp(input, () => chunk5XBH5SAL_cjs.baseFetch(input, init));
1424
1320
  } catch (err) {
1425
- const mapped = chunkJZWLXNHV_cjs.toProviderUnavailable(err, "indexer");
1426
- if (lastAttempt || !(mapped instanceof chunkJZWLXNHV_cjs.ProviderUnavailableError)) throw mapped;
1321
+ const mapped = chunk5XBH5SAL_cjs.toProviderUnavailable(err, "indexer");
1322
+ if (lastAttempt || !(mapped instanceof chunk5XBH5SAL_cjs.ProviderUnavailableError)) throw mapped;
1427
1323
  await sleep(retryDelayMs(attempt));
1428
1324
  continue;
1429
1325
  }
@@ -1435,7 +1331,7 @@ async function indexerFetch(input, init) {
1435
1331
  body = void 0;
1436
1332
  }
1437
1333
  try {
1438
- chunkJZWLXNHV_cjs.throwIfHttpUnavailable(res, "indexer", body);
1334
+ chunk5XBH5SAL_cjs.throwIfHttpUnavailable(res, "indexer", body);
1439
1335
  } catch (err) {
1440
1336
  if (lastAttempt) throw err;
1441
1337
  await sleep(retryDelayMs(attempt));
@@ -1464,24 +1360,20 @@ var ChainTxType = /* @__PURE__ */ ((ChainTxType2) => {
1464
1360
  return ChainTxType2;
1465
1361
  })(ChainTxType || {});
1466
1362
  var RestIndexerProvider = class {
1467
- constructor(serverUrl = chunkJZWLXNHV_cjs.DEFAULT_ARKADE_SERVER_URL, options = {}) {
1363
+ constructor(serverUrl = chunk5XBH5SAL_cjs.DEFAULT_ARKADE_SERVER_URL, options = {}) {
1468
1364
  this.serverUrl = serverUrl;
1469
1365
  this.eventSource = options.eventSource;
1470
1366
  }
1471
1367
  serverUrl;
1472
1368
  /** Overrides {@link configureEventSource} for this provider's subscription. */
1473
1369
  eventSource;
1370
+ /** @see fetchVtxosJson */
1371
+ inFlightVtxoReads = /* @__PURE__ */ new Map();
1474
1372
  async getVtxoTree(batchOutpoint, opts) {
1475
- let url = `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree`;
1476
- const params = new URLSearchParams();
1477
- if (opts) {
1478
- if (opts.pageIndex !== void 0)
1479
- params.append("page.index", opts.pageIndex.toString());
1480
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1481
- }
1482
- if (params.toString()) {
1483
- url += "?" + params.toString();
1484
- }
1373
+ const url = withPage(
1374
+ `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree`,
1375
+ opts
1376
+ );
1485
1377
  const res = await indexerFetch(url);
1486
1378
  if (!res.ok) {
1487
1379
  throw new Error(`Failed to fetch vtxo tree: ${res.statusText}`);
@@ -1490,24 +1382,14 @@ var RestIndexerProvider = class {
1490
1382
  if (!Response.isVtxoTreeResponse(data)) {
1491
1383
  throw new Error("Invalid vtxo tree data received");
1492
1384
  }
1493
- data.vtxoTree.forEach((tx) => {
1494
- tx.children = Object.fromEntries(
1495
- Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1496
- );
1497
- });
1385
+ numberChildKeys(data.vtxoTree);
1498
1386
  return data;
1499
1387
  }
1500
1388
  async getVtxoTreeLeaves(batchOutpoint, opts) {
1501
- let url = `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree/leaves`;
1502
- const params = new URLSearchParams();
1503
- if (opts) {
1504
- if (opts.pageIndex !== void 0)
1505
- params.append("page.index", opts.pageIndex.toString());
1506
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1507
- }
1508
- if (params.toString()) {
1509
- url += "?" + params.toString();
1510
- }
1389
+ const url = withPage(
1390
+ `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree/leaves`,
1391
+ opts
1392
+ );
1511
1393
  const res = await indexerFetch(url);
1512
1394
  if (!res.ok) {
1513
1395
  throw new Error(`Failed to fetch vtxo tree leaves: ${res.statusText}`);
@@ -1543,16 +1425,7 @@ var RestIndexerProvider = class {
1543
1425
  return data;
1544
1426
  }
1545
1427
  async getCommitmentTxConnectors(txid, opts) {
1546
- let url = `${this.serverUrl}/v1/indexer/commitmentTx/${txid}/connectors`;
1547
- const params = new URLSearchParams();
1548
- if (opts) {
1549
- if (opts.pageIndex !== void 0)
1550
- params.append("page.index", opts.pageIndex.toString());
1551
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1552
- }
1553
- if (params.toString()) {
1554
- url += "?" + params.toString();
1555
- }
1428
+ const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/connectors`, opts);
1556
1429
  const res = await indexerFetch(url);
1557
1430
  if (!res.ok) {
1558
1431
  throw new Error(`Failed to fetch commitment tx connectors: ${res.statusText}`);
@@ -1561,24 +1434,11 @@ var RestIndexerProvider = class {
1561
1434
  if (!Response.isConnectorsResponse(data)) {
1562
1435
  throw new Error("Invalid commitment tx connectors data received");
1563
1436
  }
1564
- data.connectors.forEach((tx) => {
1565
- tx.children = Object.fromEntries(
1566
- Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1567
- );
1568
- });
1437
+ numberChildKeys(data.connectors);
1569
1438
  return data;
1570
1439
  }
1571
1440
  async getCommitmentTxForfeitTxs(txid, opts) {
1572
- let url = `${this.serverUrl}/v1/indexer/commitmentTx/${txid}/forfeitTxs`;
1573
- const params = new URLSearchParams();
1574
- if (opts) {
1575
- if (opts.pageIndex !== void 0)
1576
- params.append("page.index", opts.pageIndex.toString());
1577
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1578
- }
1579
- if (params.toString()) {
1580
- url += "?" + params.toString();
1581
- }
1441
+ const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/forfeitTxs`, opts);
1582
1442
  const res = await indexerFetch(url);
1583
1443
  if (!res.ok) {
1584
1444
  throw new Error(`Failed to fetch commitment tx forfeitTxs: ${res.statusText}`);
@@ -1600,8 +1460,8 @@ var RestIndexerProvider = class {
1600
1460
  try {
1601
1461
  while (!abortSignal?.aborted) {
1602
1462
  try {
1603
- const currentIterator = chunkJZWLXNHV_cjs.eventSourceIterator(
1604
- chunkJZWLXNHV_cjs.resolveEventSource(override)(url)
1463
+ const currentIterator = chunk5XBH5SAL_cjs.eventSourceIterator(
1464
+ chunk5XBH5SAL_cjs.resolveEventSource(override)(url)
1605
1465
  );
1606
1466
  iterator = currentIterator;
1607
1467
  for await (const event of currentIterator) {
@@ -1609,15 +1469,7 @@ var RestIndexerProvider = class {
1609
1469
  try {
1610
1470
  const data = JSON.parse(event.data);
1611
1471
  if (data.event) {
1612
- yield {
1613
- txid: data.event.txid,
1614
- scripts: data.event.scripts || [],
1615
- newVtxos: (data.event.newVtxos || []).map(chunkJZWLXNHV_cjs.convertVtxo),
1616
- spentVtxos: (data.event.spentVtxos || []).map(chunkJZWLXNHV_cjs.convertVtxo),
1617
- sweptVtxos: (data.event.sweptVtxos || []).map(chunkJZWLXNHV_cjs.convertVtxo),
1618
- tx: data.event.tx,
1619
- checkpointTxs: data.event.checkpointTxs
1620
- };
1472
+ yield toSubscriptionResponse(data.event);
1621
1473
  }
1622
1474
  } catch (err) {
1623
1475
  console.error("Failed to parse subscription event:", err);
@@ -1628,14 +1480,14 @@ var RestIndexerProvider = class {
1628
1480
  if (abortSignal?.aborted || error instanceof Error && error.name === "AbortError") {
1629
1481
  break;
1630
1482
  }
1631
- if (chunkJZWLXNHV_cjs.isFetchTimeoutError(error)) {
1483
+ if (chunk5XBH5SAL_cjs.isFetchTimeoutError(error)) {
1632
1484
  console.debug("Timeout error ignored");
1633
1485
  continue;
1634
1486
  }
1635
- if (chunkJZWLXNHV_cjs.isEventSourceError(error)) {
1487
+ if (chunk5XBH5SAL_cjs.isEventSourceError(error)) {
1636
1488
  throw error;
1637
1489
  }
1638
- if (chunkJZWLXNHV_cjs.isEventSourceUnavailableError(error)) throw error;
1490
+ if (chunk5XBH5SAL_cjs.isEventSourceUnavailableError(error)) throw error;
1639
1491
  console.error("Subscription error:", error);
1640
1492
  throw error;
1641
1493
  } finally {
@@ -1656,16 +1508,7 @@ var RestIndexerProvider = class {
1656
1508
  return gen;
1657
1509
  }
1658
1510
  async getVirtualTxs(txids, opts) {
1659
- let url = `${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`;
1660
- const params = new URLSearchParams();
1661
- if (opts) {
1662
- if (opts.pageIndex !== void 0)
1663
- params.append("page.index", opts.pageIndex.toString());
1664
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1665
- }
1666
- if (params.toString()) {
1667
- url += "?" + params.toString();
1668
- }
1511
+ const url = withPage(`${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`, opts);
1669
1512
  const res = await indexerFetch(url);
1670
1513
  if (!res.ok) {
1671
1514
  throw new Error(`Failed to fetch virtual txs: ${res.statusText}`);
@@ -1677,16 +1520,10 @@ var RestIndexerProvider = class {
1677
1520
  return data;
1678
1521
  }
1679
1522
  async getVtxoChain(vtxoOutpoint, opts) {
1680
- let url = `${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`;
1681
- const params = new URLSearchParams();
1682
- if (opts) {
1683
- if (opts.pageIndex !== void 0)
1684
- params.append("page.index", opts.pageIndex.toString());
1685
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1686
- }
1687
- if (params.toString()) {
1688
- url += "?" + params.toString();
1689
- }
1523
+ const url = withPage(
1524
+ `${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`,
1525
+ opts
1526
+ );
1690
1527
  const res = await indexerFetch(url);
1691
1528
  if (!res.ok) {
1692
1529
  throw new Error(`Failed to fetch vtxo chain: ${res.statusText}`);
@@ -1777,19 +1614,43 @@ var RestIndexerProvider = class {
1777
1614
  if (params.toString()) {
1778
1615
  url += "?" + params.toString();
1779
1616
  }
1780
- const res = await indexerFetch(url);
1781
- if (!res.ok) {
1782
- throw new Error(`Failed to fetch vtxos: ${res.statusText}`);
1783
- }
1784
- const data = await res.json();
1785
- if (!Response.isVtxosResponse(data)) {
1786
- throw new Error("Invalid vtxos data received");
1787
- }
1617
+ const data = await this.fetchVtxosJson(url);
1788
1618
  return {
1789
- vtxos: data.vtxos.map(chunkJZWLXNHV_cjs.convertVtxo),
1619
+ vtxos: data.vtxos.map(chunk5XBH5SAL_cjs.convertVtxo),
1790
1620
  page: data.page
1791
1621
  };
1792
1622
  }
1623
+ /**
1624
+ * The wire read behind {@link fetchVtxosPage}, with an identical read
1625
+ * already in flight served from that one request instead of repeated.
1626
+ *
1627
+ * Two callers can want the same page at the same instant without either
1628
+ * being redundant, so there is no single call site to remove: a send that
1629
+ * leaves change makes the indexer emit `vtxo_spent` and `vtxo_received` for
1630
+ * the wallet's own contract milliseconds apart, and `handleContractEvent`
1631
+ * delta-syncs that contract on both arms.
1632
+ */
1633
+ async fetchVtxosJson(url) {
1634
+ const joined = this.inFlightVtxoReads.get(url);
1635
+ if (joined) return joined;
1636
+ const shared = (async () => {
1637
+ const res = await indexerFetch(url);
1638
+ if (!res.ok) {
1639
+ throw new Error(`Failed to fetch vtxos: ${res.statusText}`);
1640
+ }
1641
+ const data = await res.json();
1642
+ if (!Response.isVtxosResponse(data)) {
1643
+ throw new Error("Invalid vtxos data received");
1644
+ }
1645
+ return data;
1646
+ })();
1647
+ this.inFlightVtxoReads.set(url, shared);
1648
+ try {
1649
+ return await shared;
1650
+ } finally {
1651
+ if (this.inFlightVtxoReads.get(url) === shared) this.inFlightVtxoReads.delete(url);
1652
+ }
1653
+ }
1793
1654
  async getAssetDetails(assetId) {
1794
1655
  const url = `${this.serverUrl}/v1/indexer/asset/${encodeURIComponent(assetId)}`;
1795
1656
  const res = await indexerFetch(url);
@@ -1840,6 +1701,31 @@ var RestIndexerProvider = class {
1840
1701
  }
1841
1702
  }
1842
1703
  };
1704
+ function withPage(url, opts) {
1705
+ const params = new URLSearchParams();
1706
+ if (opts?.pageIndex !== void 0) params.append("page.index", opts.pageIndex.toString());
1707
+ if (opts?.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1708
+ const query = params.toString();
1709
+ return query ? `${url}?${query}` : url;
1710
+ }
1711
+ function numberChildKeys(txs) {
1712
+ txs.forEach((tx) => {
1713
+ tx.children = Object.fromEntries(
1714
+ Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1715
+ );
1716
+ });
1717
+ }
1718
+ function toSubscriptionResponse(event) {
1719
+ return {
1720
+ txid: event.txid,
1721
+ scripts: event.scripts || [],
1722
+ newVtxos: (event.newVtxos || []).map(chunk5XBH5SAL_cjs.convertVtxo),
1723
+ spentVtxos: (event.spentVtxos || []).map(chunk5XBH5SAL_cjs.convertVtxo),
1724
+ sweptVtxos: (event.sweptVtxos || []).map(chunk5XBH5SAL_cjs.convertVtxo),
1725
+ tx: event.tx,
1726
+ checkpointTxs: event.checkpointTxs
1727
+ };
1728
+ }
1843
1729
  function parseAssetMetadata(metadata) {
1844
1730
  const metadataList = MetadataList.fromString(metadata);
1845
1731
  const out = {};
@@ -1879,31 +1765,12 @@ var Response;
1879
1765
  return typeof data === "object" && typeof data.txid === "string" && typeof data.vout === "number";
1880
1766
  }
1881
1767
  Response2.isOutpoint = isOutpoint;
1882
- function isOutpointArray(data) {
1883
- return Array.isArray(data) && data.every(isOutpoint);
1884
- }
1885
- Response2.isOutpointArray = isOutpointArray;
1886
1768
  function isTx(data) {
1887
1769
  return typeof data === "object" && typeof data.txid === "string" && typeof data.children === "object" && Object.values(data.children).every(isTxid) && Object.keys(data.children).every((k) => Number.isInteger(Number(k)));
1888
1770
  }
1889
- function isTxsArray(data) {
1890
- return Array.isArray(data) && data.every(isTx);
1891
- }
1892
- Response2.isTxsArray = isTxsArray;
1893
- function isTxHistoryRecord(data) {
1894
- return typeof data === "object" && typeof data.amount === "string" && typeof data.createdAt === "string" && typeof data.isSettled === "boolean" && typeof data.settledBy === "string" && Object.values(IndexerTxType).includes(data.type) && (!data.commitmentTxid && typeof data.virtualTxid === "string" || typeof data.commitmentTxid === "string" && !data.virtualTxid);
1895
- }
1896
- function isTxHistoryRecordArray(data) {
1897
- return Array.isArray(data) && data.every(isTxHistoryRecord);
1898
- }
1899
- Response2.isTxHistoryRecordArray = isTxHistoryRecordArray;
1900
1771
  function isTxid(data) {
1901
1772
  return typeof data === "string" && data.length === 64;
1902
1773
  }
1903
- function isTxidArray(data) {
1904
- return Array.isArray(data) && data.every(isTxid);
1905
- }
1906
- Response2.isTxidArray = isTxidArray;
1907
1774
  function isVtxoAsset(data) {
1908
1775
  return typeof data === "object" && data !== null && typeof data.assetId === "string" && typeof data.amount === "string";
1909
1776
  }
@@ -1929,10 +1796,6 @@ var Response;
1929
1796
  return typeof data === "object" && Array.isArray(data.txids) && data.txids.every(isTxid) && (!data.page || isPageResponse(data.page));
1930
1797
  }
1931
1798
  Response2.isForfeitTxsResponse = isForfeitTxsResponse;
1932
- function isSweptCommitmentTxResponse(data) {
1933
- return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
1934
- }
1935
- Response2.isSweptCommitmentTxResponse = isSweptCommitmentTxResponse;
1936
1799
  function isBatchSweepTransactionsResponse(data) {
1937
1800
  return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
1938
1801
  }
@@ -1969,5 +1832,6 @@ exports.Metadata = Metadata;
1969
1832
  exports.Packet = Packet;
1970
1833
  exports.RestIndexerProvider = RestIndexerProvider;
1971
1834
  exports.asset_exports = asset_exports;
1972
- //# sourceMappingURL=chunk-NVZJSKZS.cjs.map
1973
- //# sourceMappingURL=chunk-NVZJSKZS.cjs.map
1835
+ exports.toSubscriptionResponse = toSubscriptionResponse;
1836
+ //# sourceMappingURL=chunk-Q7PC3NHX.cjs.map
1837
+ //# sourceMappingURL=chunk-Q7PC3NHX.cjs.map