@arkade-os/sdk 0.5.0-rc.9 → 0.5.1
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.
- package/README.md +232 -51
- package/dist/adapters/expo.cjs +5 -5
- package/dist/adapters/expo.d.cts +5 -5
- package/dist/adapters/expo.d.ts +5 -5
- package/dist/adapters/expo.js +3 -3
- package/dist/{asyncStorageTaskQueue-DZYrAWN8.d.ts → asyncStorageTaskQueue-CdWheMqT.d.ts} +1 -1
- package/dist/{asyncStorageTaskQueue-ChKX-D51.d.cts → asyncStorageTaskQueue-DFt5LgW5.d.cts} +1 -1
- package/dist/{chunk-R4KRWX7R.js → chunk-3M22PJVB.js} +427 -1078
- package/dist/chunk-3M22PJVB.js.map +1 -0
- package/dist/{chunk-J2K7WWMJ.js → chunk-6MIGYYWB.js} +112 -243
- package/dist/chunk-6MIGYYWB.js.map +1 -0
- package/dist/{chunk-FQCMEAWN.js → chunk-FXVEOEYB.js} +32 -39
- package/dist/chunk-FXVEOEYB.js.map +1 -0
- package/dist/{chunk-7OL2P5TV.cjs → chunk-GQUFPTN7.cjs} +39 -46
- package/dist/chunk-GQUFPTN7.cjs.map +1 -0
- package/dist/{chunk-VMVHRKXM.cjs → chunk-GW42FS2X.cjs} +494 -1122
- package/dist/chunk-GW42FS2X.cjs.map +1 -0
- package/dist/{chunk-V4JZOFYT.cjs → chunk-HQNQ3CLQ.cjs} +124 -254
- package/dist/chunk-HQNQ3CLQ.cjs.map +1 -0
- package/dist/{chunk-PO2ZDZZC.cjs → chunk-JJ6QKTFZ.cjs} +12 -10
- package/dist/chunk-JJ6QKTFZ.cjs.map +1 -0
- package/dist/{chunk-3TCWQPAC.js → chunk-NKKJEA3Z.js} +5842 -4284
- package/dist/chunk-NKKJEA3Z.js.map +1 -0
- package/dist/{chunk-JFZBKPSV.js → chunk-QFB55EOZ.js} +541 -400
- package/dist/chunk-QFB55EOZ.js.map +1 -0
- package/dist/{chunk-PKD5VPYX.cjs → chunk-QKNSMVBW.cjs} +6143 -4565
- package/dist/chunk-QKNSMVBW.cjs.map +1 -0
- package/dist/{chunk-VTXMC4N7.cjs → chunk-XLHUGP3G.cjs} +548 -399
- package/dist/chunk-XLHUGP3G.cjs.map +1 -0
- package/dist/{chunk-Z3QM5XFY.js → chunk-XQRIY5K5.js} +7 -5
- package/dist/chunk-XQRIY5K5.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +9 -9
- package/dist/contracts/handlers/index.d.cts +5 -5
- package/dist/contracts/handlers/index.d.ts +5 -5
- package/dist/contracts/handlers/index.js +2 -2
- package/dist/{delegate-CyBnNY9v.d.ts → delegate-BSbGQabI.d.ts} +1 -1
- package/dist/{delegate-Cyv2suFd.d.cts → delegate-CFCfrReG.d.cts} +1 -1
- package/dist/{index-BIL9boGL.d.ts → index-B3fRWO5i.d.cts} +1652 -2291
- package/dist/{index-BIL9boGL.d.cts → index-B3fRWO5i.d.ts} +1652 -2291
- package/dist/index-CzUVvIxA.d.ts +645 -0
- package/dist/index-Fpf4mQZr.d.cts +645 -0
- package/dist/index.cjs +399 -311
- package/dist/index.d.cts +957 -1124
- package/dist/index.d.ts +957 -1124
- package/dist/index.js +4 -4
- package/dist/repositories/realm/index.cjs +165 -103
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +18 -14
- package/dist/repositories/realm/index.d.ts +18 -14
- package/dist/repositories/realm/index.js +153 -91
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +226 -184
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +22 -21
- package/dist/repositories/sqlite/index.d.ts +22 -21
- package/dist/repositories/sqlite/index.js +218 -176
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-Cu4uO1to.d.ts → taskRunner-CdfoCMaw.d.ts} +1 -1
- package/dist/{taskRunner-DxpSuKmh.d.cts → taskRunner-Dk6oDAtd.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +14 -14
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +10 -16
- package/dist/wallet/expo/background.d.ts +10 -16
- package/dist/wallet/expo/background.js +6 -6
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +19 -14
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +8 -6
- package/dist/wallet/expo/index.d.ts +8 -6
- package/dist/wallet/expo/index.js +10 -5
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/wallet-BQHNgc_v.d.ts +1874 -0
- package/dist/wallet-D9dvXu-K.d.cts +1874 -0
- package/dist/worker/expo/index.cjs +9 -9
- package/dist/worker/expo/index.d.cts +6 -6
- package/dist/worker/expo/index.d.ts +6 -6
- package/dist/worker/expo/index.js +5 -5
- package/package.json +10 -11
- package/dist/chunk-3TCWQPAC.js.map +0 -1
- package/dist/chunk-7OL2P5TV.cjs.map +0 -1
- package/dist/chunk-FQCMEAWN.js.map +0 -1
- package/dist/chunk-J2K7WWMJ.js.map +0 -1
- package/dist/chunk-JFZBKPSV.js.map +0 -1
- package/dist/chunk-PKD5VPYX.cjs.map +0 -1
- package/dist/chunk-PO2ZDZZC.cjs.map +0 -1
- package/dist/chunk-R4KRWX7R.js.map +0 -1
- package/dist/chunk-V4JZOFYT.cjs.map +0 -1
- package/dist/chunk-VMVHRKXM.cjs.map +0 -1
- package/dist/chunk-VTXMC4N7.cjs.map +0 -1
- package/dist/chunk-Z3QM5XFY.js.map +0 -1
- package/dist/hdWalletCapable-D1ImQqlu.d.cts +0 -2214
- package/dist/hdWalletCapable-DvumVrKW.d.ts +0 -2214
- package/dist/index-DleNQcz5.d.cts +0 -850
- package/dist/index-QVhQgYvU.d.ts +0 -850
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __export, DEFAULT_ARKADE_SERVER_URL, eventSourceIterator, resolveEventSource,
|
|
1
|
+
import { __export, DEFAULT_ARKADE_SERVER_URL, eventSourceIterator, resolveEventSource, isFetchTimeoutError, isEventSourceError, isEventSourceUnavailableError, convertVtxo, rateGate, baseFetch, toProviderUnavailable, ProviderUnavailableError, throwIfHttpUnavailable } from './chunk-QFB55EOZ.js';
|
|
2
2
|
import { hex } from '@scure/base';
|
|
3
3
|
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
4
4
|
import { compareBytes } from '@scure/btc-signer/utils.js';
|
|
@@ -39,8 +39,13 @@ var AssetRefType = /* @__PURE__ */ ((AssetRefType2) => {
|
|
|
39
39
|
var MASK_ASSET_ID = 1;
|
|
40
40
|
var MASK_CONTROL_ASSET = 2;
|
|
41
41
|
var MASK_METADATA = 4;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
function hexOrThrow(s, message) {
|
|
43
|
+
try {
|
|
44
|
+
return hex.decode(s);
|
|
45
|
+
} catch {
|
|
46
|
+
throw new Error(message);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
44
49
|
var BufferWriter = class {
|
|
45
50
|
buffer = [];
|
|
46
51
|
write(data) {
|
|
@@ -183,11 +188,10 @@ var AssetId = class _AssetId {
|
|
|
183
188
|
txid;
|
|
184
189
|
groupIndex;
|
|
185
190
|
/**
|
|
186
|
-
* Create
|
|
191
|
+
* Create a validated asset id from a genesis transaction id and group index.
|
|
187
192
|
*
|
|
188
193
|
* @param txid - Hex-encoded genesis transaction id
|
|
189
194
|
* @param groupIndex - Asset group index within the genesis transaction
|
|
190
|
-
* @returns A validated asset id
|
|
191
195
|
* @throws Error if the txid is missing, malformed, or not 32 bytes long
|
|
192
196
|
* @see fromString
|
|
193
197
|
*/
|
|
@@ -195,12 +199,7 @@ var AssetId = class _AssetId {
|
|
|
195
199
|
if (!txid) {
|
|
196
200
|
throw new Error("missing txid");
|
|
197
201
|
}
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
buf = hex.decode(txid);
|
|
201
|
-
} catch {
|
|
202
|
-
throw new Error("invalid txid format, must be hex");
|
|
203
|
-
}
|
|
202
|
+
const buf = hexOrThrow(txid, "invalid txid format, must be hex");
|
|
204
203
|
if (buf.length !== TX_HASH_SIZE) {
|
|
205
204
|
throw new Error(
|
|
206
205
|
`invalid txid length: got ${buf.length} bytes, want ${TX_HASH_SIZE} bytes`
|
|
@@ -213,25 +212,15 @@ var AssetId = class _AssetId {
|
|
|
213
212
|
/**
|
|
214
213
|
* Decode an asset id from its hex string representation.
|
|
215
214
|
*
|
|
216
|
-
* @param s - Hex-encoded asset id
|
|
217
|
-
* @returns Decoded asset id
|
|
218
215
|
* @throws Error if the string is not valid hex or does not encode a valid asset id
|
|
219
216
|
* @see toString
|
|
220
217
|
*/
|
|
221
218
|
static fromString(s) {
|
|
222
|
-
|
|
223
|
-
try {
|
|
224
|
-
buf = hex.decode(s);
|
|
225
|
-
} catch {
|
|
226
|
-
throw new Error("invalid asset id format, must be hex");
|
|
227
|
-
}
|
|
228
|
-
return _AssetId.fromBytes(buf);
|
|
219
|
+
return _AssetId.fromBytes(hexOrThrow(s, "invalid asset id format, must be hex"));
|
|
229
220
|
}
|
|
230
221
|
/**
|
|
231
222
|
* Decode an asset id from its serialized bytes.
|
|
232
223
|
*
|
|
233
|
-
* @param buf - Serialized asset id bytes
|
|
234
|
-
* @returns Decoded asset id
|
|
235
224
|
* @throws Error if the buffer length is invalid
|
|
236
225
|
*/
|
|
237
226
|
static fromBytes(buf) {
|
|
@@ -249,7 +238,6 @@ var AssetId = class _AssetId {
|
|
|
249
238
|
/**
|
|
250
239
|
* Serialize the asset id to raw bytes.
|
|
251
240
|
*
|
|
252
|
-
* @returns Serialized asset id bytes
|
|
253
241
|
* @see fromBytes
|
|
254
242
|
*/
|
|
255
243
|
serialize() {
|
|
@@ -260,7 +248,6 @@ var AssetId = class _AssetId {
|
|
|
260
248
|
/**
|
|
261
249
|
* Encode the asset id to a hex string.
|
|
262
250
|
*
|
|
263
|
-
* @returns Hex-encoded asset id
|
|
264
251
|
* @see fromString
|
|
265
252
|
*/
|
|
266
253
|
toString() {
|
|
@@ -280,10 +267,8 @@ var AssetId = class _AssetId {
|
|
|
280
267
|
}
|
|
281
268
|
}
|
|
282
269
|
/**
|
|
283
|
-
* Decode an asset id from a binary reader.
|
|
270
|
+
* Decode an asset id from a binary reader positioned at one.
|
|
284
271
|
*
|
|
285
|
-
* @param reader - Reader positioned at an asset id
|
|
286
|
-
* @returns Decoded asset id
|
|
287
272
|
* @throws Error if the reader does not contain enough bytes
|
|
288
273
|
*/
|
|
289
274
|
static fromReader(reader) {
|
|
@@ -301,7 +286,6 @@ var AssetId = class _AssetId {
|
|
|
301
286
|
/**
|
|
302
287
|
* Serialize the asset id into an existing binary writer.
|
|
303
288
|
*
|
|
304
|
-
* @param writer - Writer to append the asset id to
|
|
305
289
|
* @see serialize
|
|
306
290
|
*/
|
|
307
291
|
serializeTo(writer) {
|
|
@@ -318,48 +302,31 @@ var AssetRef = class _AssetRef {
|
|
|
318
302
|
get type() {
|
|
319
303
|
return this.ref.type;
|
|
320
304
|
}
|
|
321
|
-
/**
|
|
322
|
-
* Create an asset reference that points to a specific asset id.
|
|
323
|
-
*
|
|
324
|
-
* @param assetId - Asset id referenced by this pointer
|
|
325
|
-
* @returns Asset reference by id
|
|
326
|
-
* @see fromGroupIndex
|
|
327
|
-
*/
|
|
305
|
+
/** Reference a specific asset id. @see fromGroupIndex */
|
|
328
306
|
static fromId(assetId) {
|
|
329
307
|
return new _AssetRef({ type: 1 /* ByID */, assetId });
|
|
330
308
|
}
|
|
331
309
|
/**
|
|
332
|
-
*
|
|
310
|
+
* Reference another asset group in the packet.
|
|
333
311
|
*
|
|
334
312
|
* @param groupIndex - Zero-based asset group index in the packet
|
|
335
|
-
* @returns Asset reference by group index
|
|
336
313
|
* @see fromId
|
|
337
314
|
*/
|
|
338
315
|
static fromGroupIndex(groupIndex) {
|
|
339
316
|
return new _AssetRef({ type: 2 /* ByGroup */, groupIndex });
|
|
340
317
|
}
|
|
341
318
|
/**
|
|
342
|
-
* Decode an asset reference from
|
|
319
|
+
* Decode an asset reference from hex.
|
|
343
320
|
*
|
|
344
|
-
* @param s - Hex-encoded asset reference
|
|
345
|
-
* @returns Decoded asset reference
|
|
346
321
|
* @throws Error if the string is not valid hex or does not encode a valid asset reference
|
|
347
322
|
* @see toString
|
|
348
323
|
*/
|
|
349
324
|
static fromString(s) {
|
|
350
|
-
|
|
351
|
-
try {
|
|
352
|
-
buf = hex.decode(s);
|
|
353
|
-
} catch {
|
|
354
|
-
throw new Error("invalid asset ref format, must be hex");
|
|
355
|
-
}
|
|
356
|
-
return _AssetRef.fromBytes(buf);
|
|
325
|
+
return _AssetRef.fromBytes(hexOrThrow(s, "invalid asset ref format, must be hex"));
|
|
357
326
|
}
|
|
358
327
|
/**
|
|
359
328
|
* Decode an asset reference from its serialized bytes.
|
|
360
329
|
*
|
|
361
|
-
* @param buf - Serialized asset reference bytes
|
|
362
|
-
* @returns Decoded asset reference
|
|
363
330
|
* @throws Error if the buffer is empty or malformed
|
|
364
331
|
*/
|
|
365
332
|
static fromBytes(buf) {
|
|
@@ -369,31 +336,19 @@ var AssetRef = class _AssetRef {
|
|
|
369
336
|
const reader = new BufferReader(buf);
|
|
370
337
|
return _AssetRef.fromReader(reader);
|
|
371
338
|
}
|
|
372
|
-
/**
|
|
373
|
-
* Serialize the asset reference to raw bytes.
|
|
374
|
-
*
|
|
375
|
-
* @returns Serialized asset reference bytes
|
|
376
|
-
* @see fromBytes
|
|
377
|
-
*/
|
|
339
|
+
/** Serialize to raw bytes. @see fromBytes */
|
|
378
340
|
serialize() {
|
|
379
341
|
const writer = new BufferWriter();
|
|
380
342
|
this.serializeTo(writer);
|
|
381
343
|
return writer.toBytes();
|
|
382
344
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Encode the asset reference to a hex string.
|
|
385
|
-
*
|
|
386
|
-
* @returns Hex-encoded asset reference
|
|
387
|
-
* @see fromString
|
|
388
|
-
*/
|
|
345
|
+
/** Encode to hex. @see fromString */
|
|
389
346
|
toString() {
|
|
390
347
|
return hex.encode(this.serialize());
|
|
391
348
|
}
|
|
392
349
|
/**
|
|
393
|
-
* Decode an asset reference from a
|
|
350
|
+
* Decode an asset reference from a reader positioned at one.
|
|
394
351
|
*
|
|
395
|
-
* @param reader - Reader positioned at an asset reference
|
|
396
|
-
* @returns Decoded asset reference
|
|
397
352
|
* @throws Error if the type is unknown or the reader does not contain enough bytes
|
|
398
353
|
*/
|
|
399
354
|
static fromReader(reader) {
|
|
@@ -420,12 +375,7 @@ var AssetRef = class _AssetRef {
|
|
|
420
375
|
}
|
|
421
376
|
return ref;
|
|
422
377
|
}
|
|
423
|
-
/**
|
|
424
|
-
* Serialize the asset reference into an existing binary writer.
|
|
425
|
-
*
|
|
426
|
-
* @param writer - Writer to append the asset reference to
|
|
427
|
-
* @see serialize
|
|
428
|
-
*/
|
|
378
|
+
/** Append the serialized reference to `writer`. @see serialize */
|
|
429
379
|
serializeTo(writer) {
|
|
430
380
|
writer.writeByte(this.ref.type);
|
|
431
381
|
switch (this.ref.type) {
|
|
@@ -466,12 +416,7 @@ var AssetInput = class _AssetInput {
|
|
|
466
416
|
if (!txid || txid.length === 0) {
|
|
467
417
|
throw new Error("missing input intent txid");
|
|
468
418
|
}
|
|
469
|
-
|
|
470
|
-
try {
|
|
471
|
-
buf = hex.decode(txid);
|
|
472
|
-
} catch {
|
|
473
|
-
throw new Error("invalid input intent txid format, must be hex");
|
|
474
|
-
}
|
|
419
|
+
const buf = hexOrThrow(txid, "invalid input intent txid format, must be hex");
|
|
475
420
|
if (buf.length !== TX_HASH_SIZE) {
|
|
476
421
|
throw new Error("invalid input intent txid length");
|
|
477
422
|
}
|
|
@@ -486,13 +431,7 @@ var AssetInput = class _AssetInput {
|
|
|
486
431
|
}
|
|
487
432
|
/** Decode an asset input from its hex string form. */
|
|
488
433
|
static fromString(s) {
|
|
489
|
-
|
|
490
|
-
try {
|
|
491
|
-
buf = hex.decode(s);
|
|
492
|
-
} catch {
|
|
493
|
-
throw new Error("invalid format, must be hex");
|
|
494
|
-
}
|
|
495
|
-
return _AssetInput.fromBytes(buf);
|
|
434
|
+
return _AssetInput.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
|
|
496
435
|
}
|
|
497
436
|
/** Decode an asset input from its serialized bytes. */
|
|
498
437
|
static fromBytes(buf) {
|
|
@@ -585,13 +524,7 @@ var AssetInputs = class _AssetInputs {
|
|
|
585
524
|
if (!s || s.length === 0) {
|
|
586
525
|
throw new Error("missing asset inputs");
|
|
587
526
|
}
|
|
588
|
-
|
|
589
|
-
try {
|
|
590
|
-
buf = hex.decode(s);
|
|
591
|
-
} catch {
|
|
592
|
-
throw new Error("invalid asset inputs format, must be hex");
|
|
593
|
-
}
|
|
594
|
-
const reader = new BufferReader(buf);
|
|
527
|
+
const reader = new BufferReader(hexOrThrow(s, "invalid asset inputs format, must be hex"));
|
|
595
528
|
return _AssetInputs.fromReader(reader);
|
|
596
529
|
}
|
|
597
530
|
/** Serialize the asset input list to raw bytes. */
|
|
@@ -659,13 +592,7 @@ var AssetOutput = class _AssetOutput {
|
|
|
659
592
|
}
|
|
660
593
|
/** Decode an asset output from its hex string form. */
|
|
661
594
|
static fromString(s) {
|
|
662
|
-
|
|
663
|
-
try {
|
|
664
|
-
buf = hex.decode(s);
|
|
665
|
-
} catch {
|
|
666
|
-
throw new Error("invalid asset output format, must be hex");
|
|
667
|
-
}
|
|
668
|
-
return _AssetOutput.fromBytes(buf);
|
|
595
|
+
return _AssetOutput.fromBytes(hexOrThrow(s, "invalid asset output format, must be hex"));
|
|
669
596
|
}
|
|
670
597
|
/** Decode an asset output from its serialized bytes. */
|
|
671
598
|
static fromBytes(buf) {
|
|
@@ -740,13 +667,7 @@ var AssetOutputs = class _AssetOutputs {
|
|
|
740
667
|
if (!s || s.length === 0) {
|
|
741
668
|
throw new Error("missing asset outputs");
|
|
742
669
|
}
|
|
743
|
-
|
|
744
|
-
try {
|
|
745
|
-
buf = hex.decode(s);
|
|
746
|
-
} catch {
|
|
747
|
-
throw new Error("invalid asset outputs format, must be hex");
|
|
748
|
-
}
|
|
749
|
-
const reader = new BufferReader(buf);
|
|
670
|
+
const reader = new BufferReader(hexOrThrow(s, "invalid asset outputs format, must be hex"));
|
|
750
671
|
return _AssetOutputs.fromReader(reader);
|
|
751
672
|
}
|
|
752
673
|
/** Serialize the asset output list to raw bytes. */
|
|
@@ -808,13 +729,7 @@ var Metadata = class _Metadata {
|
|
|
808
729
|
}
|
|
809
730
|
/** Decode metadata from its hex string form. */
|
|
810
731
|
static fromString(s) {
|
|
811
|
-
|
|
812
|
-
try {
|
|
813
|
-
buf = hex.decode(s);
|
|
814
|
-
} catch {
|
|
815
|
-
throw new Error("invalid metadata format, must be hex");
|
|
816
|
-
}
|
|
817
|
-
return _Metadata.fromBytes(buf);
|
|
732
|
+
return _Metadata.fromBytes(hexOrThrow(s, "invalid metadata format, must be hex"));
|
|
818
733
|
}
|
|
819
734
|
/** Decode metadata from its serialized bytes. */
|
|
820
735
|
static fromBytes(buf) {
|
|
@@ -883,13 +798,7 @@ var MetadataList = class _MetadataList {
|
|
|
883
798
|
static ARK_LEAF_VERSION = 0;
|
|
884
799
|
/** Create a metadata list from its hex string form. */
|
|
885
800
|
static fromString(s) {
|
|
886
|
-
|
|
887
|
-
try {
|
|
888
|
-
buf = hex.decode(s);
|
|
889
|
-
} catch {
|
|
890
|
-
throw new Error("invalid metadata list format");
|
|
891
|
-
}
|
|
892
|
-
return _MetadataList.fromBytes(buf);
|
|
801
|
+
return _MetadataList.fromBytes(hexOrThrow(s, "invalid metadata list format"));
|
|
893
802
|
}
|
|
894
803
|
/** Decode a metadata list from its serialized bytes. */
|
|
895
804
|
static fromBytes(buf) {
|
|
@@ -1002,13 +911,7 @@ var AssetGroup = class _AssetGroup {
|
|
|
1002
911
|
* @see toString
|
|
1003
912
|
*/
|
|
1004
913
|
static fromString(s) {
|
|
1005
|
-
|
|
1006
|
-
try {
|
|
1007
|
-
buf = hex.decode(s);
|
|
1008
|
-
} catch {
|
|
1009
|
-
throw new Error("invalid format, must be hex");
|
|
1010
|
-
}
|
|
1011
|
-
return _AssetGroup.fromBytes(buf);
|
|
914
|
+
return _AssetGroup.fromBytes(hexOrThrow(s, "invalid format, must be hex"));
|
|
1012
915
|
}
|
|
1013
916
|
/**
|
|
1014
917
|
* Decode an asset group from its serialized bytes.
|
|
@@ -1193,13 +1096,7 @@ var Packet = class _Packet {
|
|
|
1193
1096
|
if (!s) {
|
|
1194
1097
|
throw new Error("missing packet data");
|
|
1195
1098
|
}
|
|
1196
|
-
|
|
1197
|
-
try {
|
|
1198
|
-
buf = hex.decode(s);
|
|
1199
|
-
} catch {
|
|
1200
|
-
throw new Error("invalid packet format, must be hex");
|
|
1201
|
-
}
|
|
1202
|
-
return _Packet.fromBytes(buf);
|
|
1099
|
+
return _Packet.fromBytes(hexOrThrow(s, "invalid packet format, must be hex"));
|
|
1203
1100
|
}
|
|
1204
1101
|
/**
|
|
1205
1102
|
* type returns the TLV packet type tag. Implements ExtensionPacket interface.
|
|
@@ -1471,16 +1368,10 @@ var RestIndexerProvider = class {
|
|
|
1471
1368
|
/** @see fetchVtxosJson */
|
|
1472
1369
|
inFlightVtxoReads = /* @__PURE__ */ new Map();
|
|
1473
1370
|
async getVtxoTree(batchOutpoint, opts) {
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1479
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1480
|
-
}
|
|
1481
|
-
if (params.toString()) {
|
|
1482
|
-
url += "?" + params.toString();
|
|
1483
|
-
}
|
|
1371
|
+
const url = withPage(
|
|
1372
|
+
`${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree`,
|
|
1373
|
+
opts
|
|
1374
|
+
);
|
|
1484
1375
|
const res = await indexerFetch(url);
|
|
1485
1376
|
if (!res.ok) {
|
|
1486
1377
|
throw new Error(`Failed to fetch vtxo tree: ${res.statusText}`);
|
|
@@ -1489,24 +1380,14 @@ var RestIndexerProvider = class {
|
|
|
1489
1380
|
if (!Response.isVtxoTreeResponse(data)) {
|
|
1490
1381
|
throw new Error("Invalid vtxo tree data received");
|
|
1491
1382
|
}
|
|
1492
|
-
data.vtxoTree
|
|
1493
|
-
tx.children = Object.fromEntries(
|
|
1494
|
-
Object.entries(tx.children).map(([key, value]) => [Number(key), value])
|
|
1495
|
-
);
|
|
1496
|
-
});
|
|
1383
|
+
numberChildKeys(data.vtxoTree);
|
|
1497
1384
|
return data;
|
|
1498
1385
|
}
|
|
1499
1386
|
async getVtxoTreeLeaves(batchOutpoint, opts) {
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1505
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1506
|
-
}
|
|
1507
|
-
if (params.toString()) {
|
|
1508
|
-
url += "?" + params.toString();
|
|
1509
|
-
}
|
|
1387
|
+
const url = withPage(
|
|
1388
|
+
`${this.serverUrl}/v1/indexer/batch/${batchOutpoint.txid}/${batchOutpoint.vout}/tree/leaves`,
|
|
1389
|
+
opts
|
|
1390
|
+
);
|
|
1510
1391
|
const res = await indexerFetch(url);
|
|
1511
1392
|
if (!res.ok) {
|
|
1512
1393
|
throw new Error(`Failed to fetch vtxo tree leaves: ${res.statusText}`);
|
|
@@ -1542,16 +1423,7 @@ var RestIndexerProvider = class {
|
|
|
1542
1423
|
return data;
|
|
1543
1424
|
}
|
|
1544
1425
|
async getCommitmentTxConnectors(txid, opts) {
|
|
1545
|
-
|
|
1546
|
-
const params = new URLSearchParams();
|
|
1547
|
-
if (opts) {
|
|
1548
|
-
if (opts.pageIndex !== void 0)
|
|
1549
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1550
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1551
|
-
}
|
|
1552
|
-
if (params.toString()) {
|
|
1553
|
-
url += "?" + params.toString();
|
|
1554
|
-
}
|
|
1426
|
+
const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/connectors`, opts);
|
|
1555
1427
|
const res = await indexerFetch(url);
|
|
1556
1428
|
if (!res.ok) {
|
|
1557
1429
|
throw new Error(`Failed to fetch commitment tx connectors: ${res.statusText}`);
|
|
@@ -1560,24 +1432,11 @@ var RestIndexerProvider = class {
|
|
|
1560
1432
|
if (!Response.isConnectorsResponse(data)) {
|
|
1561
1433
|
throw new Error("Invalid commitment tx connectors data received");
|
|
1562
1434
|
}
|
|
1563
|
-
data.connectors
|
|
1564
|
-
tx.children = Object.fromEntries(
|
|
1565
|
-
Object.entries(tx.children).map(([key, value]) => [Number(key), value])
|
|
1566
|
-
);
|
|
1567
|
-
});
|
|
1435
|
+
numberChildKeys(data.connectors);
|
|
1568
1436
|
return data;
|
|
1569
1437
|
}
|
|
1570
1438
|
async getCommitmentTxForfeitTxs(txid, opts) {
|
|
1571
|
-
|
|
1572
|
-
const params = new URLSearchParams();
|
|
1573
|
-
if (opts) {
|
|
1574
|
-
if (opts.pageIndex !== void 0)
|
|
1575
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1576
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1577
|
-
}
|
|
1578
|
-
if (params.toString()) {
|
|
1579
|
-
url += "?" + params.toString();
|
|
1580
|
-
}
|
|
1439
|
+
const url = withPage(`${this.serverUrl}/v1/indexer/commitmentTx/${txid}/forfeitTxs`, opts);
|
|
1581
1440
|
const res = await indexerFetch(url);
|
|
1582
1441
|
if (!res.ok) {
|
|
1583
1442
|
throw new Error(`Failed to fetch commitment tx forfeitTxs: ${res.statusText}`);
|
|
@@ -1589,7 +1448,34 @@ var RestIndexerProvider = class {
|
|
|
1589
1448
|
return data;
|
|
1590
1449
|
}
|
|
1591
1450
|
getSubscription(subscriptionId, abortSignal) {
|
|
1592
|
-
const
|
|
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) {
|
|
1593
1479
|
const override = this.eventSource;
|
|
1594
1480
|
let iterator = null;
|
|
1595
1481
|
const closeIterator = () => iterator?.close();
|
|
@@ -1606,18 +1492,8 @@ var RestIndexerProvider = class {
|
|
|
1606
1492
|
for await (const event of currentIterator) {
|
|
1607
1493
|
if (abortSignal?.aborted) break;
|
|
1608
1494
|
try {
|
|
1609
|
-
const
|
|
1610
|
-
if (
|
|
1611
|
-
yield {
|
|
1612
|
-
txid: data.event.txid,
|
|
1613
|
-
scripts: data.event.scripts || [],
|
|
1614
|
-
newVtxos: (data.event.newVtxos || []).map(convertVtxo),
|
|
1615
|
-
spentVtxos: (data.event.spentVtxos || []).map(convertVtxo),
|
|
1616
|
-
sweptVtxos: (data.event.sweptVtxos || []).map(convertVtxo),
|
|
1617
|
-
tx: data.event.tx,
|
|
1618
|
-
checkpointTxs: data.event.checkpointTxs
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1495
|
+
const message = toSubscriptionMessage(JSON.parse(event.data));
|
|
1496
|
+
if (message) yield message;
|
|
1621
1497
|
} catch (err) {
|
|
1622
1498
|
console.error("Failed to parse subscription event:", err);
|
|
1623
1499
|
throw err;
|
|
@@ -1655,16 +1531,7 @@ var RestIndexerProvider = class {
|
|
|
1655
1531
|
return gen;
|
|
1656
1532
|
}
|
|
1657
1533
|
async getVirtualTxs(txids, opts) {
|
|
1658
|
-
|
|
1659
|
-
const params = new URLSearchParams();
|
|
1660
|
-
if (opts) {
|
|
1661
|
-
if (opts.pageIndex !== void 0)
|
|
1662
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1663
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1664
|
-
}
|
|
1665
|
-
if (params.toString()) {
|
|
1666
|
-
url += "?" + params.toString();
|
|
1667
|
-
}
|
|
1534
|
+
const url = withPage(`${this.serverUrl}/v1/indexer/virtualTx/${txids.join(",")}`, opts);
|
|
1668
1535
|
const res = await indexerFetch(url);
|
|
1669
1536
|
if (!res.ok) {
|
|
1670
1537
|
throw new Error(`Failed to fetch virtual txs: ${res.statusText}`);
|
|
@@ -1676,16 +1543,10 @@ var RestIndexerProvider = class {
|
|
|
1676
1543
|
return data;
|
|
1677
1544
|
}
|
|
1678
1545
|
async getVtxoChain(vtxoOutpoint, opts) {
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
params.append("page.index", opts.pageIndex.toString());
|
|
1684
|
-
if (opts.pageSize !== void 0) params.append("page.size", opts.pageSize.toString());
|
|
1685
|
-
}
|
|
1686
|
-
if (params.toString()) {
|
|
1687
|
-
url += "?" + params.toString();
|
|
1688
|
-
}
|
|
1546
|
+
const url = withPage(
|
|
1547
|
+
`${this.serverUrl}/v1/indexer/vtxo/${vtxoOutpoint.txid}/${vtxoOutpoint.vout}/chain`,
|
|
1548
|
+
opts
|
|
1549
|
+
);
|
|
1689
1550
|
const res = await indexerFetch(url);
|
|
1690
1551
|
if (!res.ok) {
|
|
1691
1552
|
throw new Error(`Failed to fetch vtxo chain: ${res.statusText}`);
|
|
@@ -1831,14 +1692,15 @@ var RestIndexerProvider = class {
|
|
|
1831
1692
|
controlAssetId: data.controlAsset || void 0
|
|
1832
1693
|
};
|
|
1833
1694
|
}
|
|
1834
|
-
async subscribeForScripts(scripts, subscriptionId) {
|
|
1695
|
+
async subscribeForScripts(scripts, subscriptionId, signal) {
|
|
1835
1696
|
const url = `${this.serverUrl}/v1/indexer/script/subscribe`;
|
|
1836
1697
|
const res = await indexerFetch(url, {
|
|
1837
1698
|
headers: {
|
|
1838
1699
|
"Content-Type": "application/json"
|
|
1839
1700
|
},
|
|
1840
1701
|
method: "POST",
|
|
1841
|
-
body: JSON.stringify({ scripts, subscriptionId })
|
|
1702
|
+
body: JSON.stringify({ scripts, subscriptionId }),
|
|
1703
|
+
signal
|
|
1842
1704
|
});
|
|
1843
1705
|
if (!res.ok) {
|
|
1844
1706
|
const errorText = await res.text();
|
|
@@ -1863,6 +1725,36 @@ var RestIndexerProvider = class {
|
|
|
1863
1725
|
}
|
|
1864
1726
|
}
|
|
1865
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
|
+
}
|
|
1866
1758
|
function parseAssetMetadata(metadata) {
|
|
1867
1759
|
const metadataList = MetadataList.fromString(metadata);
|
|
1868
1760
|
const out = {};
|
|
@@ -1902,31 +1794,12 @@ var Response;
|
|
|
1902
1794
|
return typeof data === "object" && typeof data.txid === "string" && typeof data.vout === "number";
|
|
1903
1795
|
}
|
|
1904
1796
|
Response2.isOutpoint = isOutpoint;
|
|
1905
|
-
function isOutpointArray(data) {
|
|
1906
|
-
return Array.isArray(data) && data.every(isOutpoint);
|
|
1907
|
-
}
|
|
1908
|
-
Response2.isOutpointArray = isOutpointArray;
|
|
1909
1797
|
function isTx(data) {
|
|
1910
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)));
|
|
1911
1799
|
}
|
|
1912
|
-
function isTxsArray(data) {
|
|
1913
|
-
return Array.isArray(data) && data.every(isTx);
|
|
1914
|
-
}
|
|
1915
|
-
Response2.isTxsArray = isTxsArray;
|
|
1916
|
-
function isTxHistoryRecord(data) {
|
|
1917
|
-
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);
|
|
1918
|
-
}
|
|
1919
|
-
function isTxHistoryRecordArray(data) {
|
|
1920
|
-
return Array.isArray(data) && data.every(isTxHistoryRecord);
|
|
1921
|
-
}
|
|
1922
|
-
Response2.isTxHistoryRecordArray = isTxHistoryRecordArray;
|
|
1923
1800
|
function isTxid(data) {
|
|
1924
1801
|
return typeof data === "string" && data.length === 64;
|
|
1925
1802
|
}
|
|
1926
|
-
function isTxidArray(data) {
|
|
1927
|
-
return Array.isArray(data) && data.every(isTxid);
|
|
1928
|
-
}
|
|
1929
|
-
Response2.isTxidArray = isTxidArray;
|
|
1930
1803
|
function isVtxoAsset(data) {
|
|
1931
1804
|
return typeof data === "object" && data !== null && typeof data.assetId === "string" && typeof data.amount === "string";
|
|
1932
1805
|
}
|
|
@@ -1952,10 +1825,6 @@ var Response;
|
|
|
1952
1825
|
return typeof data === "object" && Array.isArray(data.txids) && data.txids.every(isTxid) && (!data.page || isPageResponse(data.page));
|
|
1953
1826
|
}
|
|
1954
1827
|
Response2.isForfeitTxsResponse = isForfeitTxsResponse;
|
|
1955
|
-
function isSweptCommitmentTxResponse(data) {
|
|
1956
|
-
return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
|
|
1957
|
-
}
|
|
1958
|
-
Response2.isSweptCommitmentTxResponse = isSweptCommitmentTxResponse;
|
|
1959
1828
|
function isBatchSweepTransactionsResponse(data) {
|
|
1960
1829
|
return typeof data === "object" && Array.isArray(data.sweptBy) && data.sweptBy.every(isTxid);
|
|
1961
1830
|
}
|
|
@@ -1978,6 +1847,6 @@ var Response;
|
|
|
1978
1847
|
Response2.isGetAssetResponse = isGetAssetResponse;
|
|
1979
1848
|
})(Response || (Response = {}));
|
|
1980
1849
|
|
|
1981
|
-
export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports };
|
|
1982
|
-
//# sourceMappingURL=chunk-
|
|
1983
|
-
//# sourceMappingURL=chunk-
|
|
1850
|
+
export { AssetGroup, AssetId, AssetInput, AssetOutput, AssetRef, BufferReader, BufferWriter, ChainTxType, DEFAULT_VTXO_PAGE_SIZE, IndexerTxType, Metadata, Packet, RestIndexerProvider, asset_exports, toSubscriptionMessage };
|
|
1851
|
+
//# sourceMappingURL=chunk-6MIGYYWB.js.map
|
|
1852
|
+
//# sourceMappingURL=chunk-6MIGYYWB.js.map
|