@arkade-os/sdk 0.5.0-rc.3 → 0.5.0-rc.30

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 +223 -83
  2. package/dist/adapters/expo.cjs +5 -6
  3. package/dist/adapters/expo.d.cts +5 -5
  4. package/dist/adapters/expo.d.ts +5 -5
  5. package/dist/adapters/expo.js +3 -4
  6. package/dist/{asyncStorageTaskQueue-DAs_n1xr.d.ts → asyncStorageTaskQueue-DAVf4Fyy.d.ts} +2 -2
  7. package/dist/{asyncStorageTaskQueue-DqGRG66E.d.cts → asyncStorageTaskQueue-fkkUPrhz.d.cts} +2 -2
  8. package/dist/{chunk-FSF2PGTR.cjs → chunk-3SM7BMIE.cjs} +6736 -5189
  9. package/dist/chunk-3SM7BMIE.cjs.map +1 -0
  10. package/dist/{chunk-UCSTNXB4.cjs → chunk-4MCQZYH6.cjs} +501 -1153
  11. package/dist/chunk-4MCQZYH6.cjs.map +1 -0
  12. package/dist/{chunk-BCT7DT2J.cjs → chunk-6BTZ6KFI.cjs} +12 -10
  13. package/dist/chunk-6BTZ6KFI.cjs.map +1 -0
  14. package/dist/{chunk-L4HZK4KK.cjs → chunk-AICUNREA.cjs} +158 -263
  15. package/dist/chunk-AICUNREA.cjs.map +1 -0
  16. package/dist/{chunk-UJTYUYY4.cjs → chunk-ASKOHVGX.cjs} +596 -467
  17. package/dist/chunk-ASKOHVGX.cjs.map +1 -0
  18. package/dist/{chunk-43XGA362.cjs → chunk-DLHE4RCH.cjs} +40 -43
  19. package/dist/chunk-DLHE4RCH.cjs.map +1 -0
  20. package/dist/{chunk-7W6FHWYN.js → chunk-ESEHYZAY.js} +434 -1109
  21. package/dist/chunk-ESEHYZAY.js.map +1 -0
  22. package/dist/{chunk-HSG2GQTM.js → chunk-G6ZPX2GL.js} +586 -462
  23. package/dist/chunk-G6ZPX2GL.js.map +1 -0
  24. package/dist/{chunk-G4UPMCKW.js → chunk-KK6GXY4L.js} +33 -36
  25. package/dist/chunk-KK6GXY4L.js.map +1 -0
  26. package/dist/{chunk-ERUAQGYF.js → chunk-PY3YQNHP.js} +146 -252
  27. package/dist/chunk-PY3YQNHP.js.map +1 -0
  28. package/dist/{chunk-VQCDDGRW.js → chunk-XW72DWYO.js} +6350 -4816
  29. package/dist/chunk-XW72DWYO.js.map +1 -0
  30. package/dist/{chunk-ROD5H7RX.js → chunk-YML2N4SC.js} +7 -5
  31. package/dist/chunk-YML2N4SC.js.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-CZzIduW4.d.cts → delegate-BYoNu3lf.d.cts} +1 -1
  37. package/dist/{delegate-B9Bmrns7.d.ts → delegate-DsqzUVId.d.ts} +1 -1
  38. package/dist/index-CXNTURO_.d.cts +645 -0
  39. package/dist/{index-DnNIOqHS.d.ts → index-DhP68WBD.d.cts} +1698 -2402
  40. package/dist/{index-DnNIOqHS.d.cts → index-DhP68WBD.d.ts} +1698 -2402
  41. package/dist/index-pQr5y77P.d.ts +645 -0
  42. package/dist/index.cjs +407 -356
  43. package/dist/index.d.cts +1045 -1302
  44. package/dist/index.d.ts +1045 -1302
  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-BDb5Ee2J.d.cts → taskRunner-C8H3bSsk.d.cts} +2 -2
  59. package/dist/{taskRunner-F7wNJcF3.d.ts → taskRunner-DKtBy8Yo.d.ts} +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 +20 -23
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +8 -9
  69. package/dist/wallet/expo/index.d.ts +8 -9
  70. package/dist/wallet/expo/index.js +12 -15
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-BmAHDzK3.d.cts +1874 -0
  73. package/dist/wallet-C0W8EOnA.d.ts +1874 -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-43XGA362.cjs.map +0 -1
  106. package/dist/chunk-5BLDMQED.cjs +0 -18
  107. package/dist/chunk-5BLDMQED.cjs.map +0 -1
  108. package/dist/chunk-7W6FHWYN.js.map +0 -1
  109. package/dist/chunk-BCT7DT2J.cjs.map +0 -1
  110. package/dist/chunk-ERUAQGYF.js.map +0 -1
  111. package/dist/chunk-FSF2PGTR.cjs.map +0 -1
  112. package/dist/chunk-G4UPMCKW.js.map +0 -1
  113. package/dist/chunk-HSG2GQTM.js.map +0 -1
  114. package/dist/chunk-L4HZK4KK.cjs.map +0 -1
  115. package/dist/chunk-NSBPE2FW.js +0 -15
  116. package/dist/chunk-NSBPE2FW.js.map +0 -1
  117. package/dist/chunk-ROD5H7RX.js.map +0 -1
  118. package/dist/chunk-UCSTNXB4.cjs.map +0 -1
  119. package/dist/chunk-UJTYUYY4.cjs.map +0 -1
  120. package/dist/chunk-VQCDDGRW.js.map +0 -1
  121. package/dist/hdWalletCapable-BIl3yLVM.d.cts +0 -2232
  122. package/dist/hdWalletCapable-Cr5nGpK5.d.ts +0 -2232
  123. package/dist/index-C0IanN1m.d.cts +0 -11
  124. package/dist/index-C0IanN1m.d.ts +0 -11
  125. package/dist/index-Ci5MmNnK.d.cts +0 -850
  126. package/dist/index-DQ1Hb2w_.d.ts +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-HSG2GQTM.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-G6ZPX2GL.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}`);
@@ -1588,7 +1448,34 @@ var RestIndexerProvider = class {
1588
1448
  return data;
1589
1449
  }
1590
1450
  getSubscription(subscriptionId, abortSignal) {
1591
- const url = `${this.serverUrl}/v1/indexer/script/subscription/${subscriptionId}`;
1451
+ const stream = this.subscriptionStream(
1452
+ `${this.serverUrl}/v1/indexer/script/subscription/${subscriptionId}`,
1453
+ abortSignal
1454
+ );
1455
+ const gen = (async function* () {
1456
+ for await (const message of stream) if (message.type === "event") yield message;
1457
+ })();
1458
+ const origReturn = gen.return.bind(gen);
1459
+ gen.return = (value) => {
1460
+ stream.return?.();
1461
+ return origReturn(value);
1462
+ };
1463
+ return gen;
1464
+ }
1465
+ getFilteredSubscription(filter, abortSignal) {
1466
+ if (filter.expressions.length === 0) {
1467
+ throw new Error("A filtered subscription needs at least one expression");
1468
+ }
1469
+ const query = new URLSearchParams(
1470
+ filter.expressions.map((expression) => ["filter.expressions", expression])
1471
+ );
1472
+ return this.subscriptionStream(
1473
+ `${this.serverUrl}/v1/indexer/subscription?${query}`,
1474
+ abortSignal
1475
+ );
1476
+ }
1477
+ /** The SSE transport behind every subscription; `ExpoIndexerProvider` replaces only this. */
1478
+ subscriptionStream(url, abortSignal) {
1592
1479
  const override = this.eventSource;
1593
1480
  let iterator = null;
1594
1481
  const closeIterator = () => iterator?.close();
@@ -1605,18 +1492,8 @@ var RestIndexerProvider = class {
1605
1492
  for await (const event of currentIterator) {
1606
1493
  if (abortSignal?.aborted) break;
1607
1494
  try {
1608
- const data = JSON.parse(event.data);
1609
- 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
- };
1619
- }
1495
+ const message = toSubscriptionMessage(JSON.parse(event.data));
1496
+ if (message) yield message;
1620
1497
  } catch (err) {
1621
1498
  console.error("Failed to parse subscription event:", err);
1622
1499
  throw err;
@@ -1654,16 +1531,7 @@ var RestIndexerProvider = class {
1654
1531
  return gen;
1655
1532
  }
1656
1533
  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
- }
1534
+ const url = withPage(`${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`, opts);
1667
1535
  const res = await indexerFetch(url);
1668
1536
  if (!res.ok) {
1669
1537
  throw new Error(`Failed to fetch virtual txs: ${res.statusText}`);
@@ -1675,16 +1543,10 @@ var RestIndexerProvider = class {
1675
1543
  return data;
1676
1544
  }
1677
1545
  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
- }
1546
+ const url = withPage(
1547
+ `${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`,
1548
+ opts
1549
+ );
1688
1550
  const res = await indexerFetch(url);
1689
1551
  if (!res.ok) {
1690
1552
  throw new Error(`Failed to fetch vtxo chain: ${res.statusText}`);
@@ -1775,19 +1637,43 @@ var RestIndexerProvider = class {
1775
1637
  if (params.toString()) {
1776
1638
  url += "?" + params.toString();
1777
1639
  }
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
- }
1640
+ const data = await this.fetchVtxosJson(url);
1786
1641
  return {
1787
1642
  vtxos: data.vtxos.map(convertVtxo),
1788
1643
  page: data.page
1789
1644
  };
1790
1645
  }
1646
+ /**
1647
+ * The wire read behind {@link fetchVtxosPage}, with an identical read
1648
+ * already in flight served from that one request instead of repeated.
1649
+ *
1650
+ * Two callers can want the same page at the same instant without either
1651
+ * being redundant, so there is no single call site to remove: a send that
1652
+ * leaves change makes the indexer emit `vtxo_spent` and `vtxo_received` for
1653
+ * the wallet's own contract milliseconds apart, and `handleContractEvent`
1654
+ * delta-syncs that contract on both arms.
1655
+ */
1656
+ async fetchVtxosJson(url) {
1657
+ const joined = this.inFlightVtxoReads.get(url);
1658
+ if (joined) return joined;
1659
+ const shared = (async () => {
1660
+ const res = await indexerFetch(url);
1661
+ if (!res.ok) {
1662
+ throw new Error(`Failed to fetch vtxos: ${res.statusText}`);
1663
+ }
1664
+ const data = await res.json();
1665
+ if (!Response.isVtxosResponse(data)) {
1666
+ throw new Error("Invalid vtxos data received");
1667
+ }
1668
+ return data;
1669
+ })();
1670
+ this.inFlightVtxoReads.set(url, shared);
1671
+ try {
1672
+ return await shared;
1673
+ } finally {
1674
+ if (this.inFlightVtxoReads.get(url) === shared) this.inFlightVtxoReads.delete(url);
1675
+ }
1676
+ }
1791
1677
  async getAssetDetails(assetId) {
1792
1678
  const url = `${this.serverUrl}/v1/indexer/asset/${encodeURIComponent(assetId)}`;
1793
1679
  const res = await indexerFetch(url);
@@ -1806,14 +1692,15 @@ var RestIndexerProvider = class {
1806
1692
  controlAssetId: data.controlAsset || void 0
1807
1693
  };
1808
1694
  }
1809
- async subscribeForScripts(scripts, subscriptionId) {
1695
+ async subscribeForScripts(scripts, subscriptionId, signal) {
1810
1696
  const url = `${this.serverUrl}/v1/indexer/script/subscribe`;
1811
1697
  const res = await indexerFetch(url, {
1812
1698
  headers: {
1813
1699
  "Content-Type": "application/json"
1814
1700
  },
1815
1701
  method: "POST",
1816
- body: JSON.stringify({ scripts, subscriptionId })
1702
+ body: JSON.stringify({ scripts, subscriptionId }),
1703
+ signal
1817
1704
  });
1818
1705
  if (!res.ok) {
1819
1706
  const errorText = await res.text();
@@ -1838,6 +1725,36 @@ var RestIndexerProvider = class {
1838
1725
  }
1839
1726
  }
1840
1727
  };
1728
+ function withPage(url, opts) {
1729
+ const params = new URLSearchParams();
1730
+ if (opts?.pageIndex !== void 0) params.append("page.index", opts.pageIndex.toString());
1731
+ if (opts?.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
1732
+ const query = params.toString();
1733
+ return query ? `${url}?${query}` : url;
1734
+ }
1735
+ function numberChildKeys(txs) {
1736
+ txs.forEach((tx) => {
1737
+ tx.children = Object.fromEntries(
1738
+ Object.entries(tx.children).map(([key, value]) => [Number(key), value])
1739
+ );
1740
+ });
1741
+ }
1742
+ function toSubscriptionMessage(data) {
1743
+ if (data.event) return { type: "event", ...toSubscriptionResponse(data.event) };
1744
+ if (data.heartbeat !== void 0) return { type: "heartbeat" };
1745
+ return null;
1746
+ }
1747
+ function toSubscriptionResponse(event) {
1748
+ return {
1749
+ txid: event.txid,
1750
+ scripts: event.scripts || [],
1751
+ newVtxos: (event.newVtxos || []).map(convertVtxo),
1752
+ spentVtxos: (event.spentVtxos || []).map(convertVtxo),
1753
+ sweptVtxos: (event.sweptVtxos || []).map(convertVtxo),
1754
+ tx: event.tx,
1755
+ checkpointTxs: event.checkpointTxs
1756
+ };
1757
+ }
1841
1758
  function parseAssetMetadata(metadata) {
1842
1759
  const metadataList = MetadataList.fromString(metadata);
1843
1760
  const out = {};
@@ -1877,31 +1794,12 @@ var Response;
1877
1794
  return typeof data === "object" && typeof data.txid === "string" && typeof data.vout === "number";
1878
1795
  }
1879
1796
  Response2.isOutpoint = isOutpoint;
1880
- function isOutpointArray(data) {
1881
- return Array.isArray(data) && data.every(isOutpoint);
1882
- }
1883
- Response2.isOutpointArray = isOutpointArray;
1884
1797
  function isTx(data) {
1885
1798
  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
1799
  }
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
1800
  function isTxid(data) {
1899
1801
  return typeof data === "string" && data.length === 64;
1900
1802
  }
1901
- function isTxidArray(data) {
1902
- return Array.isArray(data) && data.every(isTxid);
1903
- }
1904
- Response2.isTxidArray = isTxidArray;
1905
1803
  function isVtxoAsset(data) {
1906
1804
  return typeof data === "object" && data !== null && typeof data.assetId === "string" && typeof data.amount === "string";
1907
1805
  }
@@ -1927,10 +1825,6 @@ var Response;
1927
1825
  return typeof data === "object" && Array.isArray(data.txids) && data.txids.every(isTxid) && (!data.page || isPageResponse(data.page));
1928
1826
  }
1929
1827
  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
1828
  function isBatchSweepTransactionsResponse(data) {
1935
1829
  return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
1936
1830
  }
@@ -1953,6 +1847,6 @@ var Response;
1953
1847
  Response2.isGetAssetResponse = isGetAssetResponse;
1954
1848
  })(Response || (Response = {}));
1955
1849
 
1956
- export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports };
1957
- //# sourceMappingURL=chunk-ERUAQGYF.js.map
1958
- //# sourceMappingURL=chunk-ERUAQGYF.js.map
1850
+ export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports, toSubscriptionMessage };
1851
+ //# sourceMappingURL=chunk-PY3YQNHP.js.map
1852
+ //# sourceMappingURL=chunk-PY3YQNHP.js.map