@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,5 +1,4 @@
1
- import { DEFAULT_ARKADE_SERVER_URL, eventSourceIterator, resolveEventSource, convertVtxo, isFetchTimeoutError, isEventSourceError, isEventSourceUnavailableError, rateGate, baseFetch, toProviderUnavailable, ProviderUnavailableError, throwIfHttpUnavailable } from './chunk-ISO4TI5J.js';
2
- import { __export } from './chunk-NSBPE2FW.js';
1
+ import { __export, DEFAULT_ARKADE_SERVER_URL, eventSourceIterator, resolveEventSource, isFetchTimeoutError, isEventSourceError, isEventSourceUnavailableError, convertVtxo, rateGate, baseFetch, toProviderUnavailable, ProviderUnavailableError, throwIfHttpUnavailable } from './chunk-4FDNOLBO.js';
3
2
  import { hex } from '@scure/base';
4
3
  import { schnorr } from '@noble/curves/secp256k1.js';
5
4
  import { compareBytes } from '@scure/btc-signer/utils.js';
@@ -40,8 +39,13 @@ var AssetRefType = /* @__PURE__ */ ((AssetRefType2) => {
40
39
  var MASK_ASSET_ID = 1;
41
40
  var MASK_CONTROL_ASSET = 2;
42
41
  var MASK_METADATA = 4;
43
-
44
- // src/extension/utils.ts
42
+ function hexOrThrow(s, message) {
43
+ try {
44
+ return hex.decode(s);
45
+ } catch {
46
+ throw new Error(message);
47
+ }
48
+ }
45
49
  var BufferWriter = class {
46
50
  buffer = [];
47
51
  write(data) {
@@ -184,11 +188,10 @@ var AssetId = class _AssetId {
184
188
  txid;
185
189
  groupIndex;
186
190
  /**
187
- * Create an asset id from a genesis transaction id and group index.
191
+ * Create a validated asset id from a genesis transaction id and group index.
188
192
  *
189
193
  * @param txid - Hex-encoded genesis transaction id
190
194
  * @param groupIndex - Asset group index within the genesis transaction
191
- * @returns A validated asset id
192
195
  * @throws Error if the txid is missing, malformed, or not 32 bytes long
193
196
  * @see fromString
194
197
  */
@@ -196,12 +199,7 @@ var AssetId = class _AssetId {
196
199
  if (!txid) {
197
200
  throw new Error("missing txid");
198
201
  }
199
- let buf;
200
- try {
201
- buf = hex.decode(txid);
202
- } catch {
203
- throw new Error("invalid txid format, must be hex");
204
- }
202
+ const buf = hexOrThrow(txid, "invalid txid format, must be hex");
205
203
  if (buf.length !== TX_HASH_SIZE) {
206
204
  throw new Error(
207
205
  `invalid txid length: got ${buf.length} bytes, want ${TX_HASH_SIZE} bytes`
@@ -214,25 +212,15 @@ var AssetId = class _AssetId {
214
212
  /**
215
213
  * Decode an asset id from its hex string representation.
216
214
  *
217
- * @param s - Hex-encoded asset id
218
- * @returns Decoded asset id
219
215
  * @throws Error if the string is not valid hex or does not encode a valid asset id
220
216
  * @see toString
221
217
  */
222
218
  static fromString(s) {
223
- let buf;
224
- try {
225
- buf = hex.decode(s);
226
- } catch {
227
- throw new Error("invalid asset id format, must be hex");
228
- }
229
- return _AssetId.fromBytes(buf);
219
+ return _AssetId.fromBytes(hexOrThrow(s, "invalid asset id format, must be hex"));
230
220
  }
231
221
  /**
232
222
  * Decode an asset id from its serialized bytes.
233
223
  *
234
- * @param buf - Serialized asset id bytes
235
- * @returns Decoded asset id
236
224
  * @throws Error if the buffer length is invalid
237
225
  */
238
226
  static fromBytes(buf) {
@@ -250,7 +238,6 @@ var AssetId = class _AssetId {
250
238
  /**
251
239
  * Serialize the asset id to raw bytes.
252
240
  *
253
- * @returns Serialized asset id bytes
254
241
  * @see fromBytes
255
242
  */
256
243
  serialize() {
@@ -261,7 +248,6 @@ var AssetId = class _AssetId {
261
248
  /**
262
249
  * Encode the asset id to a hex string.
263
250
  *
264
- * @returns Hex-encoded asset id
265
251
  * @see fromString
266
252
  */
267
253
  toString() {
@@ -281,10 +267,8 @@ var AssetId = class _AssetId {
281
267
  }
282
268
  }
283
269
  /**
284
- * Decode an asset id from a binary reader.
270
+ * Decode an asset id from a binary reader positioned at one.
285
271
  *
286
- * @param reader - Reader positioned at an asset id
287
- * @returns Decoded asset id
288
272
  * @throws Error if the reader does not contain enough bytes
289
273
  */
290
274
  static fromReader(reader) {
@@ -302,7 +286,6 @@ var AssetId = class _AssetId {
302
286
  /**
303
287
  * Serialize the asset id into an existing binary writer.
304
288
  *
305
- * @param writer - Writer to append the asset id to
306
289
  * @see serialize
307
290
  */
308
291
  serializeTo(writer) {
@@ -319,48 +302,31 @@ var AssetRef = class _AssetRef {
319
302
  get type() {
320
303
  return this.ref.type;
321
304
  }
322
- /**
323
- * Create an asset reference that points to a specific asset id.
324
- *
325
- * @param assetId - Asset id referenced by this pointer
326
- * @returns Asset reference by id
327
- * @see fromGroupIndex
328
- */
305
+ /** Reference a specific asset id. @see fromGroupIndex */
329
306
  static fromId(assetId) {
330
307
  return new _AssetRef({ type: 1 /* ByID */, assetId });
331
308
  }
332
309
  /**
333
- * Create an asset reference that points to another asset group by index.
310
+ * Reference another asset group in the packet.
334
311
  *
335
312
  * @param groupIndex - Zero-based asset group index in the packet
336
- * @returns Asset reference by group index
337
313
  * @see fromId
338
314
  */
339
315
  static fromGroupIndex(groupIndex) {
340
316
  return new _AssetRef({ type: 2 /* ByGroup */, groupIndex });
341
317
  }
342
318
  /**
343
- * Decode an asset reference from its hex string form.
319
+ * Decode an asset reference from hex.
344
320
  *
345
- * @param s - Hex-encoded asset reference
346
- * @returns Decoded asset reference
347
321
  * @throws Error if the string is not valid hex or does not encode a valid asset reference
348
322
  * @see toString
349
323
  */
350
324
  static fromString(s) {
351
- let buf;
352
- try {
353
- buf = hex.decode(s);
354
- } catch {
355
- throw new Error("invalid asset ref format, must be hex");
356
- }
357
- return _AssetRef.fromBytes(buf);
325
+ return _AssetRef.fromBytes(hexOrThrow(s, "invalid asset ref format, must be hex"));
358
326
  }
359
327
  /**
360
328
  * Decode an asset reference from its serialized bytes.
361
329
  *
362
- * @param buf - Serialized asset reference bytes
363
- * @returns Decoded asset reference
364
330
  * @throws Error if the buffer is empty or malformed
365
331
  */
366
332
  static fromBytes(buf) {
@@ -370,31 +336,19 @@ var AssetRef = class _AssetRef {
370
336
  const reader = new BufferReader(buf);
371
337
  return _AssetRef.fromReader(reader);
372
338
  }
373
- /**
374
- * Serialize the asset reference to raw bytes.
375
- *
376
- * @returns Serialized asset reference bytes
377
- * @see fromBytes
378
- */
339
+ /** Serialize to raw bytes. @see fromBytes */
379
340
  serialize() {
380
341
  const writer = new BufferWriter();
381
342
  this.serializeTo(writer);
382
343
  return writer.toBytes();
383
344
  }
384
- /**
385
- * Encode the asset reference to a hex string.
386
- *
387
- * @returns Hex-encoded asset reference
388
- * @see fromString
389
- */
345
+ /** Encode to hex. @see fromString */
390
346
  toString() {
391
347
  return hex.encode(this.serialize());
392
348
  }
393
349
  /**
394
- * Decode an asset reference from a binary reader.
350
+ * Decode an asset reference from a reader positioned at one.
395
351
  *
396
- * @param reader - Reader positioned at an asset reference
397
- * @returns Decoded asset reference
398
352
  * @throws Error if the type is unknown or the reader does not contain enough bytes
399
353
  */
400
354
  static fromReader(reader) {
@@ -421,12 +375,7 @@ var AssetRef = class _AssetRef {
421
375
  }
422
376
  return ref;
423
377
  }
424
- /**
425
- * Serialize the asset reference into an existing binary writer.
426
- *
427
- * @param writer - Writer to append the asset reference to
428
- * @see serialize
429
- */
378
+ /** Append the serialized reference to `writer`. @see serialize */
430
379
  serializeTo(writer) {
431
380
  writer.writeByte(this.ref.type);
432
381
  switch (this.ref.type) {
@@ -467,12 +416,7 @@ var AssetInput = class _AssetInput {
467
416
  if (!txid || txid.length === 0) {
468
417
  throw new Error("missing input intent txid");
469
418
  }
470
- let buf;
471
- try {
472
- buf = hex.decode(txid);
473
- } catch {
474
- throw new Error("invalid input intent txid format, must be hex");
475
- }
419
+ const buf = hexOrThrow(txid, "invalid input intent txid format, must be hex");
476
420
  if (buf.length !== TX_HASH_SIZE) {
477
421
  throw new Error("invalid input intent txid length");
478
422
  }
@@ -487,13 +431,7 @@ var AssetInput = class _AssetInput {
487
431
  }
488
432
  /** Decode an asset input from its hex string form. */
489
433
  static fromString(s) {
490
- let buf;
491
- try {
492
- buf = hex.decode(s);
493
- } catch {
494
- throw new Error("invalid format, must be hex");
495
- }
496
- return _AssetInput.fromBytes(buf);
434
+ return _AssetInput.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
497
435
  }
498
436
  /** Decode an asset input from its serialized bytes. */
499
437
  static fromBytes(buf) {
@@ -586,13 +524,7 @@ var AssetInputs = class _AssetInputs {
586
524
  if (!s || s.length === 0) {
587
525
  throw new Error("missing asset inputs");
588
526
  }
589
- let buf;
590
- try {
591
- buf = hex.decode(s);
592
- } catch {
593
- throw new Error("invalid asset inputs format, must be hex");
594
- }
595
- const reader = new BufferReader(buf);
527
+ const reader = new BufferReader(hexOrThrow(s, "invalid asset inputs format, must be hex"));
596
528
  return _AssetInputs.fromReader(reader);
597
529
  }
598
530
  /** Serialize the asset input list to raw bytes. */
@@ -660,13 +592,7 @@ var AssetOutput = class _AssetOutput {
660
592
  }
661
593
  /** Decode an asset output from its hex string form. */
662
594
  static fromString(s) {
663
- let buf;
664
- try {
665
- buf = hex.decode(s);
666
- } catch {
667
- throw new Error("invalid asset output format, must be hex");
668
- }
669
- return _AssetOutput.fromBytes(buf);
595
+ return _AssetOutput.fromBytes(hexOrThrow(s, "invalid asset output format, must be hex"));
670
596
  }
671
597
  /** Decode an asset output from its serialized bytes. */
672
598
  static fromBytes(buf) {
@@ -741,13 +667,7 @@ var AssetOutputs = class _AssetOutputs {
741
667
  if (!s || s.length === 0) {
742
668
  throw new Error("missing asset outputs");
743
669
  }
744
- let buf;
745
- try {
746
- buf = hex.decode(s);
747
- } catch {
748
- throw new Error("invalid asset outputs format, must be hex");
749
- }
750
- const reader = new BufferReader(buf);
670
+ const reader = new BufferReader(hexOrThrow(s, "invalid asset outputs format, must be hex"));
751
671
  return _AssetOutputs.fromReader(reader);
752
672
  }
753
673
  /** Serialize the asset output list to raw bytes. */
@@ -809,13 +729,7 @@ var Metadata = class _Metadata {
809
729
  }
810
730
  /** Decode metadata from its hex string form. */
811
731
  static fromString(s) {
812
- let buf;
813
- try {
814
- buf = hex.decode(s);
815
- } catch {
816
- throw new Error("invalid metadata format, must be hex");
817
- }
818
- return _Metadata.fromBytes(buf);
732
+ return _Metadata.fromBytes(hexOrThrow(s, "invalid metadata format, must be hex"));
819
733
  }
820
734
  /** Decode metadata from its serialized bytes. */
821
735
  static fromBytes(buf) {
@@ -884,13 +798,7 @@ var MetadataList = class _MetadataList {
884
798
  static ARK_LEAF_VERSION = 0;
885
799
  /** Create a metadata list from its hex string form. */
886
800
  static fromString(s) {
887
- let buf;
888
- try {
889
- buf = hex.decode(s);
890
- } catch {
891
- throw new Error("invalid metadata list format");
892
- }
893
- return _MetadataList.fromBytes(buf);
801
+ return _MetadataList.fromBytes(hexOrThrow(s, "invalid metadata list format"));
894
802
  }
895
803
  /** Decode a metadata list from its serialized bytes. */
896
804
  static fromBytes(buf) {
@@ -1003,13 +911,7 @@ var AssetGroup = class _AssetGroup {
1003
911
  * @see toString
1004
912
  */
1005
913
  static fromString(s) {
1006
- let buf;
1007
- try {
1008
- buf = hex.decode(s);
1009
- } catch {
1010
- throw new Error("invalid format, must be hex");
1011
- }
1012
- return _AssetGroup.fromBytes(buf);
914
+ return _AssetGroup.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
1013
915
  }
1014
916
  /**
1015
917
  * Decode an asset group from its serialized bytes.
@@ -1194,13 +1096,7 @@ var Packet = class _Packet {
1194
1096
  if (!s) {
1195
1097
  throw new Error("missing packet data");
1196
1098
  }
1197
- let buf;
1198
- try {
1199
- buf = hex.decode(s);
1200
- } catch {
1201
- throw new Error("invalid packet format, must be hex");
1202
- }
1203
- return _Packet.fromBytes(buf);
1099
+ return _Packet.fromBytes(hexOrThrow(s, "invalid packet format, must be hex"));
1204
1100
  }
1205
1101
  /**
1206
1102
  * type returns the TLV packet type tag. Implements ExtensionPacket interface.
@@ -1469,17 +1365,13 @@ var RestIndexerProvider = class {
1469
1365
  serverUrl;
1470
1366
  /** Overrides {@link configureEventSource} for this provider's subscription. */
1471
1367
  eventSource;
1368
+ /** @see fetchVtxosJson */
1369
+ inFlightVtxoReads = /* @__PURE__ */ new Map();
1472
1370
  async getVtxoTree(batchOutpoint, opts) {
1473
- let url = `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree`;
1474
- const params = new URLSearchParams();
1475
- if (opts) {
1476
- if (opts.pageIndex !== void 0)
1477
- params.append("page.index", opts.pageIndex.toString());
1478
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1479
- }
1480
- if (params.toString()) {
1481
- url += "?" + params.toString();
1482
- }
1371
+ const url = withPage(
1372
+ `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree`,
1373
+ opts
1374
+ );
1483
1375
  const res = await indexerFetch(url);
1484
1376
  if (!res.ok) {
1485
1377
  throw new Error(`Failed to fetch vtxo tree: ${res.statusText}`);
@@ -1488,24 +1380,14 @@ var RestIndexerProvider = class {
1488
1380
  if (!Response.isVtxoTreeResponse(data)) {
1489
1381
  throw new Error("Invalid vtxo tree data received");
1490
1382
  }
1491
- data.vtxoTree.forEach((tx) => {
1492
- tx.children = Object.fromEntries(
1493
- Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1494
- );
1495
- });
1383
+ numberChildKeys(data.vtxoTree);
1496
1384
  return data;
1497
1385
  }
1498
1386
  async getVtxoTreeLeaves(batchOutpoint, opts) {
1499
- let url = `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree/leaves`;
1500
- const params = new URLSearchParams();
1501
- if (opts) {
1502
- if (opts.pageIndex !== void 0)
1503
- params.append("page.index", opts.pageIndex.toString());
1504
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1505
- }
1506
- if (params.toString()) {
1507
- url += "?" + params.toString();
1508
- }
1387
+ const url = withPage(
1388
+ `${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree/leaves`,
1389
+ opts
1390
+ );
1509
1391
  const res = await indexerFetch(url);
1510
1392
  if (!res.ok) {
1511
1393
  throw new Error(`Failed to fetch vtxo tree leaves: ${res.statusText}`);
@@ -1541,16 +1423,7 @@ var RestIndexerProvider = class {
1541
1423
  return data;
1542
1424
  }
1543
1425
  async getCommitmentTxConnectors(txid, opts) {
1544
- let url = `${this.serverUrl}/v1/indexer/commitmentTx/${txid}/connectors`;
1545
- const params = new URLSearchParams();
1546
- if (opts) {
1547
- if (opts.pageIndex !== void 0)
1548
- params.append("page.index", opts.pageIndex.toString());
1549
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1550
- }
1551
- if (params.toString()) {
1552
- url += "?" + params.toString();
1553
- }
1426
+ const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/connectors`, opts);
1554
1427
  const res = await indexerFetch(url);
1555
1428
  if (!res.ok) {
1556
1429
  throw new Error(`Failed to fetch commitment tx connectors: ${res.statusText}`);
@@ -1559,24 +1432,11 @@ var RestIndexerProvider = class {
1559
1432
  if (!Response.isConnectorsResponse(data)) {
1560
1433
  throw new Error("Invalid commitment tx connectors data received");
1561
1434
  }
1562
- data.connectors.forEach((tx) => {
1563
- tx.children = Object.fromEntries(
1564
- Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1565
- );
1566
- });
1435
+ numberChildKeys(data.connectors);
1567
1436
  return data;
1568
1437
  }
1569
1438
  async getCommitmentTxForfeitTxs(txid, opts) {
1570
- let url = `${this.serverUrl}/v1/indexer/commitmentTx/${txid}/forfeitTxs`;
1571
- const params = new URLSearchParams();
1572
- if (opts) {
1573
- if (opts.pageIndex !== void 0)
1574
- params.append("page.index", opts.pageIndex.toString());
1575
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1576
- }
1577
- if (params.toString()) {
1578
- url += "?" + params.toString();
1579
- }
1439
+ const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/forfeitTxs`, opts);
1580
1440
  const res = await indexerFetch(url);
1581
1441
  if (!res.ok) {
1582
1442
  throw new Error(`Failed to fetch commitment tx forfeitTxs: ${res.statusText}`);
@@ -1607,15 +1467,7 @@ var RestIndexerProvider = class {
1607
1467
  try {
1608
1468
  const data = JSON.parse(event.data);
1609
1469
  if (data.event) {
1610
- yield {
1611
- txid: data.event.txid,
1612
- scripts: data.event.scripts || [],
1613
- newVtxos: (data.event.newVtxos || []).map(convertVtxo),
1614
- spentVtxos: (data.event.spentVtxos || []).map(convertVtxo),
1615
- sweptVtxos: (data.event.sweptVtxos || []).map(convertVtxo),
1616
- tx: data.event.tx,
1617
- checkpointTxs: data.event.checkpointTxs
1618
- };
1470
+ yield toSubscriptionResponse(data.event);
1619
1471
  }
1620
1472
  } catch (err) {
1621
1473
  console.error("Failed to parse subscription event:", err);
@@ -1654,16 +1506,7 @@ var RestIndexerProvider = class {
1654
1506
  return gen;
1655
1507
  }
1656
1508
  async getVirtualTxs(txids, opts) {
1657
- let url = `${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`;
1658
- const params = new URLSearchParams();
1659
- if (opts) {
1660
- if (opts.pageIndex !== void 0)
1661
- params.append("page.index", opts.pageIndex.toString());
1662
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1663
- }
1664
- if (params.toString()) {
1665
- url += "?" + params.toString();
1666
- }
1509
+ const url = withPage(`${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`, opts);
1667
1510
  const res = await indexerFetch(url);
1668
1511
  if (!res.ok) {
1669
1512
  throw new Error(`Failed to fetch virtual txs: ${res.statusText}`);
@@ -1675,16 +1518,10 @@ var RestIndexerProvider = class {
1675
1518
  return data;
1676
1519
  }
1677
1520
  async getVtxoChain(vtxoOutpoint, opts) {
1678
- let url = `${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`;
1679
- const params = new URLSearchParams();
1680
- if (opts) {
1681
- if (opts.pageIndex !== void 0)
1682
- params.append("page.index", opts.pageIndex.toString());
1683
- if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1684
- }
1685
- if (params.toString()) {
1686
- url += "?" + params.toString();
1687
- }
1521
+ const url = withPage(
1522
+ `${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`,
1523
+ opts
1524
+ );
1688
1525
  const res = await indexerFetch(url);
1689
1526
  if (!res.ok) {
1690
1527
  throw new Error(`Failed to fetch vtxo chain: ${res.statusText}`);
@@ -1775,19 +1612,43 @@ var RestIndexerProvider = class {
1775
1612
  if (params.toString()) {
1776
1613
  url += "?" + params.toString();
1777
1614
  }
1778
- const res = await indexerFetch(url);
1779
- if (!res.ok) {
1780
- throw new Error(`Failed to fetch vtxos: ${res.statusText}`);
1781
- }
1782
- const data = await res.json();
1783
- if (!Response.isVtxosResponse(data)) {
1784
- throw new Error("Invalid vtxos data received");
1785
- }
1615
+ const data = await this.fetchVtxosJson(url);
1786
1616
  return {
1787
1617
  vtxos: data.vtxos.map(convertVtxo),
1788
1618
  page: data.page
1789
1619
  };
1790
1620
  }
1621
+ /**
1622
+ * The wire read behind {@link fetchVtxosPage}, with an identical read
1623
+ * already in flight served from that one request instead of repeated.
1624
+ *
1625
+ * Two callers can want the same page at the same instant without either
1626
+ * being redundant, so there is no single call site to remove: a send that
1627
+ * leaves change makes the indexer emit `vtxo_spent` and `vtxo_received` for
1628
+ * the wallet's own contract milliseconds apart, and `handleContractEvent`
1629
+ * delta-syncs that contract on both arms.
1630
+ */
1631
+ async fetchVtxosJson(url) {
1632
+ const joined = this.inFlightVtxoReads.get(url);
1633
+ if (joined) return joined;
1634
+ const shared = (async () => {
1635
+ const res = await indexerFetch(url);
1636
+ if (!res.ok) {
1637
+ throw new Error(`Failed to fetch vtxos: ${res.statusText}`);
1638
+ }
1639
+ const data = await res.json();
1640
+ if (!Response.isVtxosResponse(data)) {
1641
+ throw new Error("Invalid vtxos data received");
1642
+ }
1643
+ return data;
1644
+ })();
1645
+ this.inFlightVtxoReads.set(url, shared);
1646
+ try {
1647
+ return await shared;
1648
+ } finally {
1649
+ if (this.inFlightVtxoReads.get(url) === shared) this.inFlightVtxoReads.delete(url);
1650
+ }
1651
+ }
1791
1652
  async getAssetDetails(assetId) {
1792
1653
  const url = `${this.serverUrl}/v1/indexer/asset/${encodeURIComponent(assetId)}`;
1793
1654
  const res = await indexerFetch(url);
@@ -1838,6 +1699,31 @@ var RestIndexerProvider = class {
1838
1699
  }
1839
1700
  }
1840
1701
  };
1702
+ function withPage(url, opts) {
1703
+ const params = new URLSearchParams();
1704
+ if (opts?.pageIndex !== void 0) params.append("page.index", opts.pageIndex.toString());
1705
+ if (opts?.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1706
+ const query = params.toString();
1707
+ return query ? `${url}?${query}` : url;
1708
+ }
1709
+ function numberChildKeys(txs) {
1710
+ txs.forEach((tx) => {
1711
+ tx.children = Object.fromEntries(
1712
+ Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1713
+ );
1714
+ });
1715
+ }
1716
+ function toSubscriptionResponse(event) {
1717
+ return {
1718
+ txid: event.txid,
1719
+ scripts: event.scripts || [],
1720
+ newVtxos: (event.newVtxos || []).map(convertVtxo),
1721
+ spentVtxos: (event.spentVtxos || []).map(convertVtxo),
1722
+ sweptVtxos: (event.sweptVtxos || []).map(convertVtxo),
1723
+ tx: event.tx,
1724
+ checkpointTxs: event.checkpointTxs
1725
+ };
1726
+ }
1841
1727
  function parseAssetMetadata(metadata) {
1842
1728
  const metadataList = MetadataList.fromString(metadata);
1843
1729
  const out = {};
@@ -1877,31 +1763,12 @@ var Response;
1877
1763
  return typeof data === "object" && typeof data.txid === "string" && typeof data.vout === "number";
1878
1764
  }
1879
1765
  Response2.isOutpoint = isOutpoint;
1880
- function isOutpointArray(data) {
1881
- return Array.isArray(data) && data.every(isOutpoint);
1882
- }
1883
- Response2.isOutpointArray = isOutpointArray;
1884
1766
  function isTx(data) {
1885
1767
  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)));
1886
1768
  }
1887
- function isTxsArray(data) {
1888
- return Array.isArray(data) && data.every(isTx);
1889
- }
1890
- Response2.isTxsArray = isTxsArray;
1891
- function isTxHistoryRecord(data) {
1892
- 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);
1893
- }
1894
- function isTxHistoryRecordArray(data) {
1895
- return Array.isArray(data) && data.every(isTxHistoryRecord);
1896
- }
1897
- Response2.isTxHistoryRecordArray = isTxHistoryRecordArray;
1898
1769
  function isTxid(data) {
1899
1770
  return typeof data === "string" && data.length === 64;
1900
1771
  }
1901
- function isTxidArray(data) {
1902
- return Array.isArray(data) && data.every(isTxid);
1903
- }
1904
- Response2.isTxidArray = isTxidArray;
1905
1772
  function isVtxoAsset(data) {
1906
1773
  return typeof data === "object" && data !== null && typeof data.assetId === "string" && typeof data.amount === "string";
1907
1774
  }
@@ -1927,10 +1794,6 @@ var Response;
1927
1794
  return typeof data === "object" && Array.isArray(data.txids) && data.txids.every(isTxid) && (!data.page || isPageResponse(data.page));
1928
1795
  }
1929
1796
  Response2.isForfeitTxsResponse = isForfeitTxsResponse;
1930
- function isSweptCommitmentTxResponse(data) {
1931
- return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
1932
- }
1933
- Response2.isSweptCommitmentTxResponse = isSweptCommitmentTxResponse;
1934
1797
  function isBatchSweepTransactionsResponse(data) {
1935
1798
  return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
1936
1799
  }
@@ -1953,6 +1816,6 @@ var Response;
1953
1816
  Response2.isGetAssetResponse = isGetAssetResponse;
1954
1817
  })(Response || (Response = {}));
1955
1818
 
1956
- export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports };
1957
- //# sourceMappingURL=chunk-4PKLULWT.js.map
1958
- //# sourceMappingURL=chunk-4PKLULWT.js.map
1819
+ export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports, toSubscriptionResponse };
1820
+ //# sourceMappingURL=chunk-JZAEFOE4.js.map
1821
+ //# sourceMappingURL=chunk-JZAEFOE4.js.map