@arkade-os/sdk 0.5.7 → 0.5.9
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 +24 -6
- package/dist/adapters/expo.cjs +7 -7
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +4 -4
- package/dist/{asyncStorageTaskQueue-B9byr6ij.d.cts → asyncStorageTaskQueue-B6rFkXzW.d.cts} +1 -1
- package/dist/{asyncStorageTaskQueue-XP4CCdRY.d.ts → asyncStorageTaskQueue-C0irgPwJ.d.ts} +1 -1
- package/dist/{chunk-MWEDDWFU.js → chunk-2657D67V.js} +9 -7
- package/dist/chunk-2657D67V.js.map +1 -0
- package/dist/{chunk-MWMO2ZQP.js → chunk-3KNSMZWD.js} +24 -13
- package/dist/chunk-3KNSMZWD.js.map +1 -0
- package/dist/{chunk-DNFTHG73.js → chunk-4DUTRRXF.js} +8 -6
- package/dist/chunk-4DUTRRXF.js.map +1 -0
- package/dist/{chunk-MQUATTIM.cjs → chunk-4PSM6ZUC.cjs} +55 -57
- package/dist/chunk-4PSM6ZUC.cjs.map +1 -0
- package/dist/{chunk-FDJ734CH.js → chunk-DPFD5KBK.js} +5 -2
- package/dist/chunk-DPFD5KBK.js.map +1 -0
- package/dist/{chunk-OMPDPBT5.cjs → chunk-DY24A73N.cjs} +296 -240
- package/dist/chunk-DY24A73N.cjs.map +1 -0
- package/dist/{chunk-VMVFRTF4.js → chunk-FUCKDTH7.js} +285 -234
- package/dist/chunk-FUCKDTH7.js.map +1 -0
- package/dist/{chunk-4AJRIM44.js → chunk-GUK33TNC.js} +9 -13
- package/dist/chunk-GUK33TNC.js.map +1 -0
- package/dist/{chunk-RLD7DRSZ.js → chunk-HT35HPXR.js} +19365 -18395
- package/dist/chunk-HT35HPXR.js.map +1 -0
- package/dist/{chunk-3NALVGMJ.cjs → chunk-ODLSVJRU.cjs} +38 -27
- package/dist/chunk-ODLSVJRU.cjs.map +1 -0
- package/dist/{chunk-X6ZI53DZ.cjs → chunk-OMZZQTDM.cjs} +28 -35
- package/dist/chunk-OMZZQTDM.cjs.map +1 -0
- package/dist/{chunk-V3ZLL5VY.js → chunk-PXEFYEKL.js} +22 -29
- package/dist/chunk-PXEFYEKL.js.map +1 -0
- package/dist/{chunk-JFJNB7ZH.cjs → chunk-UPIQZRNJ.cjs} +16 -14
- package/dist/chunk-UPIQZRNJ.cjs.map +1 -0
- package/dist/{chunk-V5WRO3P6.cjs → chunk-UPV4W423.cjs} +14 -18
- package/dist/chunk-UPV4W423.cjs.map +1 -0
- package/dist/{chunk-URGVQ5TQ.cjs → chunk-V2EU5QWF.cjs} +4583 -3610
- package/dist/chunk-V2EU5QWF.cjs.map +1 -0
- package/dist/{chunk-FLPWNMX3.cjs → chunk-WIZCF5IX.cjs} +5 -2
- package/dist/chunk-WIZCF5IX.cjs.map +1 -0
- package/dist/{chunk-MXCB6EVM.cjs → chunk-WZJJZGBT.cjs} +22 -20
- package/dist/chunk-WZJJZGBT.cjs.map +1 -0
- package/dist/{chunk-V2DDN4MV.js → chunk-Z6WDOZZI.js} +10 -12
- package/dist/chunk-Z6WDOZZI.js.map +1 -0
- package/dist/compiler.cjs +4 -4
- package/dist/compiler.d.cts +1 -1
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +3 -3
- package/dist/contracts/handlers/index.cjs +11 -11
- package/dist/contracts/handlers/index.d.cts +3 -4
- package/dist/contracts/handlers/index.d.ts +3 -4
- package/dist/contracts/handlers/index.js +4 -4
- package/dist/{index-18cDMayF.d.ts → index-Bq349_ly.d.cts} +2334 -101
- package/dist/{index-Ccfhdfvj.d.cts → index-D4ahI0W6.d.cts} +2 -3
- package/dist/{index-DDJFHfba.d.cts → index-Mn2POBPj.d.ts} +2334 -101
- package/dist/{index-B_kcptF8.d.ts → index-Yh5y9G4E.d.ts} +2 -3
- package/dist/index.cjs +362 -346
- package/dist/index.d.cts +1505 -1374
- package/dist/index.d.ts +1505 -1374
- package/dist/index.js +7 -7
- package/dist/{program-BARSNg3X.d.ts → program-38A2Twvj.d.ts} +4 -2
- package/dist/{program-znrWkxE4.d.cts → program-DPzf5qsk.d.cts} +4 -2
- package/dist/repositories/realm/index.cjs +40 -40
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/realm/index.js +8 -8
- package/dist/repositories/sqlite/index.cjs +38 -38
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.js +8 -8
- package/dist/{taskRunner-DUafWu0o.d.ts → taskRunner-BYxEgwM5.d.ts} +1 -1
- package/dist/{taskRunner-JYHaLPne.d.cts → taskRunner-Z3LnHfgs.d.cts} +1 -1
- package/dist/wallet/expo/background.cjs +17 -17
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +9 -9
- package/dist/wallet/expo/index.cjs +18 -18
- package/dist/wallet/expo/index.d.cts +3 -5
- package/dist/wallet/expo/index.d.ts +3 -5
- package/dist/wallet/expo/index.js +8 -8
- package/dist/worker/expo/index.cjs +12 -12
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +8 -8
- package/package.json +1 -1
- package/dist/chunk-3NALVGMJ.cjs.map +0 -1
- package/dist/chunk-4AJRIM44.js.map +0 -1
- package/dist/chunk-DNFTHG73.js.map +0 -1
- package/dist/chunk-FDJ734CH.js.map +0 -1
- package/dist/chunk-FLPWNMX3.cjs.map +0 -1
- package/dist/chunk-JFJNB7ZH.cjs.map +0 -1
- package/dist/chunk-MQUATTIM.cjs.map +0 -1
- package/dist/chunk-MWEDDWFU.js.map +0 -1
- package/dist/chunk-MWMO2ZQP.js.map +0 -1
- package/dist/chunk-MXCB6EVM.cjs.map +0 -1
- package/dist/chunk-OMPDPBT5.cjs.map +0 -1
- package/dist/chunk-RLD7DRSZ.js.map +0 -1
- package/dist/chunk-URGVQ5TQ.cjs.map +0 -1
- package/dist/chunk-V2DDN4MV.js.map +0 -1
- package/dist/chunk-V3ZLL5VY.js.map +0 -1
- package/dist/chunk-V5WRO3P6.cjs.map +0 -1
- package/dist/chunk-VMVFRTF4.js.map +0 -1
- package/dist/chunk-X6ZI53DZ.cjs.map +0 -1
- package/dist/delegate-gGkUnYpi.d.cts +0 -92
- package/dist/delegate-iyDum4fw.d.ts +0 -92
- package/dist/keyringDescriptorProvider-DL-jAiRO.d.ts +0 -2082
- package/dist/keyringDescriptorProvider-Dtv0JWrT.d.cts +0 -2082
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkWIZCF5IX_cjs = require('./chunk-WIZCF5IX.cjs');
|
|
4
4
|
var btcSigner = require('@scure/btc-signer');
|
|
5
5
|
var psbt_js = require('@scure/btc-signer/psbt.js');
|
|
6
6
|
var utils_js = require('@scure/btc-signer/utils.js');
|
|
@@ -70,13 +70,13 @@ function legacyTapTreeToBIP371(value) {
|
|
|
70
70
|
}
|
|
71
71
|
let leaves;
|
|
72
72
|
try {
|
|
73
|
-
leaves =
|
|
73
|
+
leaves = chunkWIZCF5IX_cjs.TapTreeCoder.decode(value);
|
|
74
74
|
} catch {
|
|
75
75
|
return void 0;
|
|
76
76
|
}
|
|
77
77
|
if (leaves.length === 0 || leaves.some((leaf) => leaf.depth !== 1)) return void 0;
|
|
78
78
|
try {
|
|
79
|
-
return
|
|
79
|
+
return chunkWIZCF5IX_cjs.TapTreeCoder.encode(chunkWIZCF5IX_cjs.toBIP371TapTree(value));
|
|
80
80
|
} catch {
|
|
81
81
|
return void 0;
|
|
82
82
|
}
|
|
@@ -277,7 +277,7 @@ var VtxoTreeExpiry = {
|
|
|
277
277
|
if (!checkKeyMatch(unknown[0], "expiry" /* VtxoTreeExpiry */)) return null;
|
|
278
278
|
const v = btcSigner.ScriptNum(6, true).decode(unknown[1]);
|
|
279
279
|
if (!v) return null;
|
|
280
|
-
return
|
|
280
|
+
return chunkWIZCF5IX_cjs.sequenceToTimelock(Number(v));
|
|
281
281
|
})
|
|
282
282
|
};
|
|
283
283
|
var encodedPsbtFieldKey = Object.fromEntries(
|
|
@@ -302,11 +302,17 @@ function checkKeyMatch(key, arkPsbtFieldKey, prefixOnly = false) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
// package.json
|
|
305
|
-
var version = "0.5.
|
|
305
|
+
var version = "0.5.9";
|
|
306
|
+
|
|
307
|
+
// src/utils/sdkVersionHeaders.ts
|
|
308
|
+
var sdkVersion = `ts-sdk/${version}`;
|
|
309
|
+
function sdkVersionHeaders() {
|
|
310
|
+
const origin = globalThis.location?.origin;
|
|
311
|
+
return typeof origin === "string" ? {} : { "X-SDK-VERSION": sdkVersion };
|
|
312
|
+
}
|
|
306
313
|
|
|
307
314
|
// src/utils/fetch.ts
|
|
308
315
|
var buildVersion = "0.9.9";
|
|
309
|
-
var sdkVersion = `ts-sdk/${version}`;
|
|
310
316
|
var ARKADE_VERSION_HEADERS = {
|
|
311
317
|
"X-Build-Version": buildVersion,
|
|
312
318
|
"X-SDK-VERSION": sdkVersion
|
|
@@ -368,102 +374,140 @@ function describeRequest(input, init) {
|
|
|
368
374
|
return { url, method };
|
|
369
375
|
}
|
|
370
376
|
|
|
371
|
-
// src/providers/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
// src/providers/rateGate.ts
|
|
378
|
+
var DEFAULT_MAX_CONCURRENT = 6;
|
|
379
|
+
var DEFAULT_COOLDOWN_MS = 5e3;
|
|
380
|
+
var MAX_COOLDOWN_MS = 6e4;
|
|
381
|
+
var DEFAULT_JITTER_MS = 500;
|
|
382
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, Math.min(ms, MAX_TIMER_MS)));
|
|
383
|
+
function parseRetryAfterMs(header) {
|
|
384
|
+
if (header === null || header === void 0) return void 0;
|
|
385
|
+
const trimmed = header.trim();
|
|
386
|
+
if (trimmed === "") return void 0;
|
|
387
|
+
const seconds = Number(trimmed);
|
|
388
|
+
if (Number.isFinite(seconds)) return seconds < 0 ? void 0 : seconds * 1e3;
|
|
389
|
+
const at = Date.parse(trimmed);
|
|
390
|
+
if (!Number.isNaN(at)) return Math.max(0, at - Date.now());
|
|
391
|
+
return void 0;
|
|
392
|
+
}
|
|
393
|
+
function requestOrigin(input) {
|
|
394
|
+
let url;
|
|
395
|
+
if (typeof input === "string") {
|
|
396
|
+
url = input;
|
|
397
|
+
} else if (input instanceof URL) {
|
|
398
|
+
url = input.href;
|
|
399
|
+
} else {
|
|
400
|
+
url = input.url;
|
|
401
|
+
}
|
|
379
402
|
try {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const text = decoder.decode(chunk, { stream: true });
|
|
384
|
-
if (!text) continue;
|
|
385
|
-
const skipLF = pendingCR && text.startsWith("\n");
|
|
386
|
-
pendingCR = text.endsWith("\r");
|
|
387
|
-
buffer += (skipLF ? text.slice(1) : text).replace(/\r\n?/g, "\n");
|
|
388
|
-
const lines = buffer.split("\n");
|
|
389
|
-
buffer = lines.pop() ?? "";
|
|
390
|
-
for (const line of lines) {
|
|
391
|
-
if (line === "") {
|
|
392
|
-
const joined = data.join("\n");
|
|
393
|
-
if (joined) yield { event: event || "message", data: joined };
|
|
394
|
-
event = "";
|
|
395
|
-
data = [];
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
const colon = line.indexOf(":");
|
|
399
|
-
const field = colon === -1 ? line : line.slice(0, colon);
|
|
400
|
-
const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
401
|
-
if (field === "event") event = value;
|
|
402
|
-
else if (field === "data") data.push(value);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
} finally {
|
|
406
|
-
await reader.cancel().catch(() => {
|
|
407
|
-
});
|
|
403
|
+
return new URL(url).origin;
|
|
404
|
+
} catch {
|
|
405
|
+
return url;
|
|
408
406
|
}
|
|
409
407
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
408
|
+
var OriginRateGate = class {
|
|
409
|
+
states = /* @__PURE__ */ new Map();
|
|
410
|
+
maxConcurrent;
|
|
411
|
+
defaultCooldownMs;
|
|
412
|
+
maxCooldownMs;
|
|
413
|
+
jitterMs;
|
|
414
|
+
constructor(options) {
|
|
415
|
+
assertNonNegativeMs("defaultCooldownMs", options?.defaultCooldownMs);
|
|
416
|
+
assertNonNegativeMs("maxCooldownMs", options?.maxCooldownMs);
|
|
417
|
+
assertNonNegativeMs("jitterMs", options?.jitterMs);
|
|
418
|
+
this.maxConcurrent = options?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
|
|
419
|
+
this.defaultCooldownMs = options?.defaultCooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
420
|
+
this.maxCooldownMs = options?.maxCooldownMs ?? MAX_COOLDOWN_MS;
|
|
421
|
+
this.jitterMs = options?.jitterMs ?? DEFAULT_JITTER_MS;
|
|
417
422
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
423
|
+
/**
|
|
424
|
+
* Run `fn` under the origin's concurrency cap and behind any active
|
|
425
|
+
* cooldown. Put only the request in `fn`: the slot is released as soon as
|
|
426
|
+
* it settles, so body parsing doesn't hold one.
|
|
427
|
+
*/
|
|
428
|
+
async run(input, fn) {
|
|
429
|
+
const state = this.stateFor(requestOrigin(input));
|
|
430
|
+
await this.acquire(state);
|
|
431
|
+
try {
|
|
432
|
+
for (; ; ) {
|
|
433
|
+
const remaining = state.blockedUntil - Date.now();
|
|
434
|
+
if (remaining <= 0) break;
|
|
435
|
+
await sleep(remaining + Math.random() * this.jitterMs);
|
|
436
|
+
}
|
|
437
|
+
return await fn();
|
|
438
|
+
} finally {
|
|
439
|
+
this.release(state);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* {@link run} for a request whose response the gate should inspect: a `429`
|
|
444
|
+
* is recorded *before* the slot is released. Reporting after `run()` resolves
|
|
445
|
+
* is too late — `release()` hands the slot to the next queued waiter, which
|
|
446
|
+
* resumes, sees no cooldown, and sends into the limiter that just refused us.
|
|
447
|
+
*
|
|
448
|
+
* Prefer this over `run` for anything returning a `Response`.
|
|
449
|
+
*/
|
|
450
|
+
runHttp(input, fn) {
|
|
451
|
+
return this.run(input, async () => {
|
|
452
|
+
const response = await fn();
|
|
453
|
+
if (response.status === 429) {
|
|
454
|
+
this.reportRateLimited(input, response.headers?.get("retry-after"));
|
|
455
|
+
}
|
|
456
|
+
return response;
|
|
440
457
|
});
|
|
441
458
|
}
|
|
442
|
-
|
|
443
|
-
|
|
459
|
+
/**
|
|
460
|
+
* Record an observed `429`, pausing every gated request to that origin.
|
|
461
|
+
* Monotonic: a shorter cooldown never shortens one already in effect.
|
|
462
|
+
*/
|
|
463
|
+
reportRateLimited(input, retryAfterHeader) {
|
|
464
|
+
const cooldown = Math.min(
|
|
465
|
+
parseRetryAfterMs(retryAfterHeader) ?? this.defaultCooldownMs,
|
|
466
|
+
this.maxCooldownMs
|
|
467
|
+
);
|
|
468
|
+
const state = this.stateFor(requestOrigin(input));
|
|
469
|
+
state.blockedUntil = Math.max(state.blockedUntil, Date.now() + cooldown);
|
|
444
470
|
}
|
|
445
|
-
|
|
446
|
-
|
|
471
|
+
/** Milliseconds left on `input` origin's cooldown; `0` when not cooling down. */
|
|
472
|
+
cooldownRemainingMs(input) {
|
|
473
|
+
const state = this.states.get(requestOrigin(input));
|
|
474
|
+
if (!state) return 0;
|
|
475
|
+
return Math.max(0, state.blockedUntil - Date.now());
|
|
447
476
|
}
|
|
448
|
-
|
|
449
|
-
|
|
477
|
+
/**
|
|
478
|
+
* Drop all per-origin state, so test suites don't inherit each other's
|
|
479
|
+
* cooldowns. Waiters queued on the discarded state still drain normally.
|
|
480
|
+
*/
|
|
481
|
+
reset() {
|
|
482
|
+
this.states.clear();
|
|
450
483
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const type = response.headers.get("Content-Type") ?? "";
|
|
457
|
-
if (response.status !== 200 || !response.body || !/^text\/event-stream\s*(;|$)/i.test(type)) {
|
|
458
|
-
await response.body?.cancel();
|
|
459
|
-
throw new Error(`SSE response ${response.status} ${type}`);
|
|
484
|
+
stateFor(origin) {
|
|
485
|
+
let state = this.states.get(origin);
|
|
486
|
+
if (!state) {
|
|
487
|
+
state = { blockedUntil: 0, active: 0, queue: [] };
|
|
488
|
+
this.states.set(origin, state);
|
|
460
489
|
}
|
|
461
|
-
|
|
462
|
-
|
|
490
|
+
return state;
|
|
491
|
+
}
|
|
492
|
+
acquire(state) {
|
|
493
|
+
if (state.active < this.maxConcurrent) {
|
|
494
|
+
state.active += 1;
|
|
495
|
+
return Promise.resolve();
|
|
463
496
|
}
|
|
464
|
-
|
|
497
|
+
return new Promise((resolve) => {
|
|
498
|
+
state.queue.push(() => {
|
|
499
|
+
state.active += 1;
|
|
500
|
+
resolve();
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
release(state) {
|
|
505
|
+
state.active -= 1;
|
|
506
|
+
const next = state.queue.shift();
|
|
507
|
+
if (next) next();
|
|
465
508
|
}
|
|
466
509
|
};
|
|
510
|
+
var rateGate = new OriginRateGate();
|
|
467
511
|
|
|
468
512
|
// src/providers/errors.ts
|
|
469
513
|
var ArkError = class extends Error {
|
|
@@ -505,6 +549,28 @@ var ProviderUnavailableError = class extends Error {
|
|
|
505
549
|
this.name = "ProviderUnavailableError";
|
|
506
550
|
}
|
|
507
551
|
};
|
|
552
|
+
var HttpResponseError = class extends Error {
|
|
553
|
+
status;
|
|
554
|
+
retryAfterMs;
|
|
555
|
+
/** @param detail - Replaces `statusText`, for a route that reads the body instead. */
|
|
556
|
+
constructor(prefix, response, detail) {
|
|
557
|
+
const status = response.status;
|
|
558
|
+
const described = [
|
|
559
|
+
(detail ?? response.statusText)?.trim(),
|
|
560
|
+
typeof status === "number" && `(${status})`
|
|
561
|
+
].filter(Boolean).join(" ");
|
|
562
|
+
super(described ? `${prefix}: ${described}` : prefix);
|
|
563
|
+
this.name = "HttpResponseError";
|
|
564
|
+
this.status = status;
|
|
565
|
+
this.retryAfterMs = parseRetryAfterMs(response.headers?.get("retry-after"));
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
function retryAfterMsFromError(error) {
|
|
569
|
+
if (!(error instanceof Error)) return void 0;
|
|
570
|
+
const { status, retryAfterMs } = error;
|
|
571
|
+
if (status !== 429 && status !== 503) return void 0;
|
|
572
|
+
return typeof retryAfterMs === "number" && retryAfterMs > 0 ? retryAfterMs : void 0;
|
|
573
|
+
}
|
|
508
574
|
var ServerResponseMismatchError = class extends Error {
|
|
509
575
|
retryable = false;
|
|
510
576
|
constructor(message, options) {
|
|
@@ -560,6 +626,112 @@ function maybeArkError(error) {
|
|
|
560
626
|
function isMetadata(value) {
|
|
561
627
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
562
628
|
}
|
|
629
|
+
|
|
630
|
+
// src/providers/sseFrames.ts
|
|
631
|
+
async function* readSseFrames(body) {
|
|
632
|
+
const reader = body.getReader();
|
|
633
|
+
const decoder = new TextDecoder();
|
|
634
|
+
let buffer = "";
|
|
635
|
+
let pendingCR = false;
|
|
636
|
+
let event = "";
|
|
637
|
+
let data = [];
|
|
638
|
+
try {
|
|
639
|
+
for (; ; ) {
|
|
640
|
+
const { done, value: chunk } = await reader.read();
|
|
641
|
+
if (done) return;
|
|
642
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
643
|
+
if (!text) continue;
|
|
644
|
+
const skipLF = pendingCR && text.startsWith("\n");
|
|
645
|
+
pendingCR = text.endsWith("\r");
|
|
646
|
+
buffer += (skipLF ? text.slice(1) : text).replace(/\r\n?/g, "\n");
|
|
647
|
+
const lines = buffer.split("\n");
|
|
648
|
+
buffer = lines.pop() ?? "";
|
|
649
|
+
for (const line of lines) {
|
|
650
|
+
if (line === "") {
|
|
651
|
+
const joined = data.join("\n");
|
|
652
|
+
if (joined) yield { event: event || "message", data: joined };
|
|
653
|
+
event = "";
|
|
654
|
+
data = [];
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
657
|
+
const colon = line.indexOf(":");
|
|
658
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
659
|
+
const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
|
|
660
|
+
if (field === "event") event = value;
|
|
661
|
+
else if (field === "data") data.push(value);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
} finally {
|
|
665
|
+
await reader.cancel().catch(() => {
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/providers/eventSource.ts
|
|
671
|
+
var GUIDANCE = "Pass one with configureEventSource(url => new EventSource(url)) \u2014 in Node, from the `eventsource` package or by running with --experimental-eventsource. In React Native, use ExpoOperatorProvider / ExpoIndexerProvider instead.";
|
|
672
|
+
var EventSourceUnavailableError = class extends Error {
|
|
673
|
+
constructor() {
|
|
674
|
+
super(`no EventSource is available, so server-sent events cannot be opened. ${GUIDANCE}`);
|
|
675
|
+
this.name = "EventSourceUnavailableError";
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
function isEventSourceUnavailableError(error) {
|
|
679
|
+
return error instanceof EventSourceUnavailableError || error instanceof Error && error.name === "EventSourceUnavailableError";
|
|
680
|
+
}
|
|
681
|
+
var configured;
|
|
682
|
+
function configureEventSource(factory) {
|
|
683
|
+
configured = factory;
|
|
684
|
+
}
|
|
685
|
+
function getConfiguredEventSource() {
|
|
686
|
+
return configured;
|
|
687
|
+
}
|
|
688
|
+
function resolveEventSource(override) {
|
|
689
|
+
const factory = override ?? configured ?? (typeof globalThis.fetch === "function" && typeof ReadableStream !== "undefined" ? (url, headers) => new FetchEventSource(url, headers) : void 0) ?? (typeof EventSource === "undefined" ? void 0 : (url) => new EventSource(url));
|
|
690
|
+
if (!factory) throw new EventSourceUnavailableError();
|
|
691
|
+
return factory;
|
|
692
|
+
}
|
|
693
|
+
function errorEvent(error) {
|
|
694
|
+
const event = new Event("error");
|
|
695
|
+
if (error instanceof HttpResponseError) {
|
|
696
|
+
event.status = error.status;
|
|
697
|
+
event.retryAfterMs = error.retryAfterMs;
|
|
698
|
+
}
|
|
699
|
+
return event;
|
|
700
|
+
}
|
|
701
|
+
var FetchEventSource = class {
|
|
702
|
+
events = new EventTarget();
|
|
703
|
+
controller = new AbortController();
|
|
704
|
+
constructor(url, headers = {}) {
|
|
705
|
+
this.read(url, headers).catch((error) => {
|
|
706
|
+
if (!this.controller.signal.aborted) this.events.dispatchEvent(errorEvent(error));
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
addEventListener(type, listener) {
|
|
710
|
+
this.events.addEventListener(type, listener);
|
|
711
|
+
}
|
|
712
|
+
removeEventListener(type, listener) {
|
|
713
|
+
this.events.removeEventListener(type, listener);
|
|
714
|
+
}
|
|
715
|
+
close() {
|
|
716
|
+
this.controller.abort();
|
|
717
|
+
}
|
|
718
|
+
async read(url, headers) {
|
|
719
|
+
const response = await baseFetch(url, {
|
|
720
|
+
headers: { Accept: "text/event-stream", ...headers },
|
|
721
|
+
signal: this.controller.signal
|
|
722
|
+
});
|
|
723
|
+
const type = response.headers.get("Content-Type") ?? "";
|
|
724
|
+
if (response.status !== 200 || !response.body || !/^text\/event-stream\s*(;|$)/i.test(type)) {
|
|
725
|
+
await response.body?.cancel().catch(() => {
|
|
726
|
+
});
|
|
727
|
+
throw new HttpResponseError("SSE response", response, type);
|
|
728
|
+
}
|
|
729
|
+
for await (const { event, data } of readSseFrames(response.body)) {
|
|
730
|
+
this.events.dispatchEvent(new MessageEvent(event, { data }));
|
|
731
|
+
}
|
|
732
|
+
throw new Error("SSE stream ended");
|
|
733
|
+
}
|
|
734
|
+
};
|
|
563
735
|
exports.Proof = void 0;
|
|
564
736
|
((Proof2) => {
|
|
565
737
|
function create(message, ins, outputs = []) {
|
|
@@ -714,8 +886,8 @@ function prepareProofInput(coin) {
|
|
|
714
886
|
if (!("tapTree" in coin)) {
|
|
715
887
|
return coin;
|
|
716
888
|
}
|
|
717
|
-
const vtxoScript =
|
|
718
|
-
const sequence =
|
|
889
|
+
const vtxoScript = chunkWIZCF5IX_cjs.VtxoScript.decode(coin.tapTree);
|
|
890
|
+
const sequence = chunkWIZCF5IX_cjs.getSequence(chunkWIZCF5IX_cjs.proofTapLeafScriptOf(coin));
|
|
719
891
|
const unknown = [VtxoTaprootTree.encode(coin.tapTree)];
|
|
720
892
|
if (coin.extraWitness) {
|
|
721
893
|
unknown.push(ConditionWitness.encode(coin.extraWitness));
|
|
@@ -731,7 +903,7 @@ function prepareProofInput(coin) {
|
|
|
731
903
|
script: vtxoScript.pkScript
|
|
732
904
|
},
|
|
733
905
|
sequence,
|
|
734
|
-
tapLeafScript: [
|
|
906
|
+
tapLeafScript: [chunkWIZCF5IX_cjs.proofTapLeafScriptOf(coin)],
|
|
735
907
|
unknown
|
|
736
908
|
};
|
|
737
909
|
}
|
|
@@ -792,7 +964,7 @@ function eventSourceIterator(eventSource) {
|
|
|
792
964
|
errorQueue.push(error);
|
|
793
965
|
}
|
|
794
966
|
};
|
|
795
|
-
const errorHandler = () => rejectWith(eventSourceError("EventSource error"));
|
|
967
|
+
const errorHandler = (event) => rejectWith(eventSourceError("EventSource error", event));
|
|
796
968
|
const failureHandler = (event) => rejectWith(streamFailureError(event.data));
|
|
797
969
|
eventSource.addEventListener("message", messageHandler);
|
|
798
970
|
eventSource.addEventListener("error", errorHandler);
|
|
@@ -834,9 +1006,14 @@ function eventSourceIterator(eventSource) {
|
|
|
834
1006
|
};
|
|
835
1007
|
return managed;
|
|
836
1008
|
}
|
|
837
|
-
function eventSourceError(message) {
|
|
838
|
-
const
|
|
1009
|
+
function eventSourceError(message, refusal) {
|
|
1010
|
+
const { status, retryAfterMs } = refusal ?? {};
|
|
1011
|
+
const error = new Error(status ? `${message} (${status})` : message);
|
|
839
1012
|
error.name = "EventSourceError";
|
|
1013
|
+
if (status !== void 0) {
|
|
1014
|
+
error.status = status;
|
|
1015
|
+
error.retryAfterMs = retryAfterMs;
|
|
1016
|
+
}
|
|
840
1017
|
return error;
|
|
841
1018
|
}
|
|
842
1019
|
function streamFailureError(data) {
|
|
@@ -852,141 +1029,6 @@ function isEventSourceError(error) {
|
|
|
852
1029
|
return error instanceof Error && error.name === "EventSourceError";
|
|
853
1030
|
}
|
|
854
1031
|
|
|
855
|
-
// src/providers/rateGate.ts
|
|
856
|
-
var DEFAULT_MAX_CONCURRENT = 6;
|
|
857
|
-
var DEFAULT_COOLDOWN_MS = 5e3;
|
|
858
|
-
var MAX_COOLDOWN_MS = 6e4;
|
|
859
|
-
var DEFAULT_JITTER_MS = 500;
|
|
860
|
-
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, Math.min(ms, MAX_TIMER_MS)));
|
|
861
|
-
function parseRetryAfterMs(header) {
|
|
862
|
-
if (header === null || header === void 0) return void 0;
|
|
863
|
-
const trimmed = header.trim();
|
|
864
|
-
if (trimmed === "") return void 0;
|
|
865
|
-
const seconds = Number(trimmed);
|
|
866
|
-
if (Number.isFinite(seconds)) return seconds < 0 ? void 0 : seconds * 1e3;
|
|
867
|
-
const at = Date.parse(trimmed);
|
|
868
|
-
if (!Number.isNaN(at)) return Math.max(0, at - Date.now());
|
|
869
|
-
return void 0;
|
|
870
|
-
}
|
|
871
|
-
function requestOrigin(input) {
|
|
872
|
-
let url;
|
|
873
|
-
if (typeof input === "string") {
|
|
874
|
-
url = input;
|
|
875
|
-
} else if (input instanceof URL) {
|
|
876
|
-
url = input.href;
|
|
877
|
-
} else {
|
|
878
|
-
url = input.url;
|
|
879
|
-
}
|
|
880
|
-
try {
|
|
881
|
-
return new URL(url).origin;
|
|
882
|
-
} catch {
|
|
883
|
-
return url;
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
var OriginRateGate = class {
|
|
887
|
-
states = /* @__PURE__ */ new Map();
|
|
888
|
-
maxConcurrent;
|
|
889
|
-
defaultCooldownMs;
|
|
890
|
-
maxCooldownMs;
|
|
891
|
-
jitterMs;
|
|
892
|
-
constructor(options) {
|
|
893
|
-
assertNonNegativeMs("defaultCooldownMs", options?.defaultCooldownMs);
|
|
894
|
-
assertNonNegativeMs("maxCooldownMs", options?.maxCooldownMs);
|
|
895
|
-
assertNonNegativeMs("jitterMs", options?.jitterMs);
|
|
896
|
-
this.maxConcurrent = options?.maxConcurrent ?? DEFAULT_MAX_CONCURRENT;
|
|
897
|
-
this.defaultCooldownMs = options?.defaultCooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
898
|
-
this.maxCooldownMs = options?.maxCooldownMs ?? MAX_COOLDOWN_MS;
|
|
899
|
-
this.jitterMs = options?.jitterMs ?? DEFAULT_JITTER_MS;
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Run `fn` under the origin's concurrency cap and behind any active
|
|
903
|
-
* cooldown. Put only the request in `fn`: the slot is released as soon as
|
|
904
|
-
* it settles, so body parsing doesn't hold one.
|
|
905
|
-
*/
|
|
906
|
-
async run(input, fn) {
|
|
907
|
-
const state = this.stateFor(requestOrigin(input));
|
|
908
|
-
await this.acquire(state);
|
|
909
|
-
try {
|
|
910
|
-
for (; ; ) {
|
|
911
|
-
const remaining = state.blockedUntil - Date.now();
|
|
912
|
-
if (remaining <= 0) break;
|
|
913
|
-
await sleep(remaining + Math.random() * this.jitterMs);
|
|
914
|
-
}
|
|
915
|
-
return await fn();
|
|
916
|
-
} finally {
|
|
917
|
-
this.release(state);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* {@link run} for a request whose response the gate should inspect: a `429`
|
|
922
|
-
* is recorded *before* the slot is released. Reporting after `run()` resolves
|
|
923
|
-
* is too late — `release()` hands the slot to the next queued waiter, which
|
|
924
|
-
* resumes, sees no cooldown, and sends into the limiter that just refused us.
|
|
925
|
-
*
|
|
926
|
-
* Prefer this over `run` for anything returning a `Response`.
|
|
927
|
-
*/
|
|
928
|
-
runHttp(input, fn) {
|
|
929
|
-
return this.run(input, async () => {
|
|
930
|
-
const response = await fn();
|
|
931
|
-
if (response.status === 429) {
|
|
932
|
-
this.reportRateLimited(input, response.headers?.get("retry-after"));
|
|
933
|
-
}
|
|
934
|
-
return response;
|
|
935
|
-
});
|
|
936
|
-
}
|
|
937
|
-
/**
|
|
938
|
-
* Record an observed `429`, pausing every gated request to that origin.
|
|
939
|
-
* Monotonic: a shorter cooldown never shortens one already in effect.
|
|
940
|
-
*/
|
|
941
|
-
reportRateLimited(input, retryAfterHeader) {
|
|
942
|
-
const cooldown = Math.min(
|
|
943
|
-
parseRetryAfterMs(retryAfterHeader) ?? this.defaultCooldownMs,
|
|
944
|
-
this.maxCooldownMs
|
|
945
|
-
);
|
|
946
|
-
const state = this.stateFor(requestOrigin(input));
|
|
947
|
-
state.blockedUntil = Math.max(state.blockedUntil, Date.now() + cooldown);
|
|
948
|
-
}
|
|
949
|
-
/** Milliseconds left on `input` origin's cooldown; `0` when not cooling down. */
|
|
950
|
-
cooldownRemainingMs(input) {
|
|
951
|
-
const state = this.states.get(requestOrigin(input));
|
|
952
|
-
if (!state) return 0;
|
|
953
|
-
return Math.max(0, state.blockedUntil - Date.now());
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Drop all per-origin state, so test suites don't inherit each other's
|
|
957
|
-
* cooldowns. Waiters queued on the discarded state still drain normally.
|
|
958
|
-
*/
|
|
959
|
-
reset() {
|
|
960
|
-
this.states.clear();
|
|
961
|
-
}
|
|
962
|
-
stateFor(origin) {
|
|
963
|
-
let state = this.states.get(origin);
|
|
964
|
-
if (!state) {
|
|
965
|
-
state = { blockedUntil: 0, active: 0, queue: [] };
|
|
966
|
-
this.states.set(origin, state);
|
|
967
|
-
}
|
|
968
|
-
return state;
|
|
969
|
-
}
|
|
970
|
-
acquire(state) {
|
|
971
|
-
if (state.active < this.maxConcurrent) {
|
|
972
|
-
state.active += 1;
|
|
973
|
-
return Promise.resolve();
|
|
974
|
-
}
|
|
975
|
-
return new Promise((resolve) => {
|
|
976
|
-
state.queue.push(() => {
|
|
977
|
-
state.active += 1;
|
|
978
|
-
resolve();
|
|
979
|
-
});
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
release(state) {
|
|
983
|
-
state.active -= 1;
|
|
984
|
-
const next = state.queue.shift();
|
|
985
|
-
if (next) next();
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
var rateGate = new OriginRateGate();
|
|
989
|
-
|
|
990
1032
|
// src/providers/ark.ts
|
|
991
1033
|
var DigestMismatchError = class extends Error {
|
|
992
1034
|
constructor(message) {
|
|
@@ -1041,7 +1083,7 @@ function advertisedLimit(fromServer) {
|
|
|
1041
1083
|
return limit > 0n ? limit : void 0;
|
|
1042
1084
|
}
|
|
1043
1085
|
var RestOperatorProvider = class {
|
|
1044
|
-
constructor(serverUrl =
|
|
1086
|
+
constructor(serverUrl = chunkWIZCF5IX_cjs.DEFAULT_ARKADE_SERVER_URL, options = {}) {
|
|
1045
1087
|
this.serverUrl = serverUrl;
|
|
1046
1088
|
this.eventSource = options.eventSource;
|
|
1047
1089
|
}
|
|
@@ -1745,6 +1787,18 @@ async function getNormalizedVtxos(provider, opts) {
|
|
|
1745
1787
|
const { vtxos, page } = await provider.getVtxos(opts);
|
|
1746
1788
|
return { vtxos: vtxos.map(normalizeVtxo), page };
|
|
1747
1789
|
}
|
|
1790
|
+
var MAX_INDEXER_PAGES = 1e3;
|
|
1791
|
+
async function* indexerPages(read) {
|
|
1792
|
+
let pageIndex = 0;
|
|
1793
|
+
for (let pages = 1; ; pages++) {
|
|
1794
|
+
const res = await read(pageIndex);
|
|
1795
|
+
yield res;
|
|
1796
|
+
const { page } = res;
|
|
1797
|
+
if (!page || !(page.current < page.total) || !(page.next > pageIndex)) return;
|
|
1798
|
+
if (pages >= MAX_INDEXER_PAGES) throw new Error("indexer paging does not end");
|
|
1799
|
+
pageIndex = page.next;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1748
1802
|
var SCRIPT_CHUNK_CONCURRENCY = 4;
|
|
1749
1803
|
async function getAllNormalizedVtxos(provider, scripts, opts = {}) {
|
|
1750
1804
|
const { pageSize = DEFAULT_PAGE_SIZE, ...filters } = opts;
|
|
@@ -1755,19 +1809,16 @@ async function getAllNormalizedVtxos(provider, scripts, opts = {}) {
|
|
|
1755
1809
|
}
|
|
1756
1810
|
const fetchChunk = async (chunk) => {
|
|
1757
1811
|
const result = [];
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
const { vtxos, page } = await getNormalizedVtxos(provider, {
|
|
1812
|
+
for await (const { vtxos } of indexerPages(async (pageIndex) => {
|
|
1813
|
+
if (pageIndex > 0) await new Promise((r) => setTimeout(r, 500));
|
|
1814
|
+
return getNormalizedVtxos(provider, {
|
|
1762
1815
|
...filters,
|
|
1763
1816
|
scripts: chunk,
|
|
1764
1817
|
pageIndex,
|
|
1765
1818
|
pageSize
|
|
1766
1819
|
});
|
|
1820
|
+
})) {
|
|
1767
1821
|
result.push(...vtxos);
|
|
1768
|
-
hasMore = page ? vtxos.length === pageSize : false;
|
|
1769
|
-
pageIndex++;
|
|
1770
|
-
if (hasMore) await new Promise((r) => setTimeout(r, 500));
|
|
1771
1822
|
}
|
|
1772
1823
|
return result;
|
|
1773
1824
|
};
|
|
@@ -1848,8 +1899,10 @@ exports.DigestMismatchError = DigestMismatchError;
|
|
|
1848
1899
|
exports.EXPIRY_MIN_PLAUSIBLE_MS = EXPIRY_MIN_PLAUSIBLE_MS;
|
|
1849
1900
|
exports.EventSourceUnavailableError = EventSourceUnavailableError;
|
|
1850
1901
|
exports.FetchError = FetchError;
|
|
1902
|
+
exports.HttpResponseError = HttpResponseError;
|
|
1851
1903
|
exports.INFO_FETCH_TIMEOUT_MS = INFO_FETCH_TIMEOUT_MS;
|
|
1852
1904
|
exports.Intent = Intent;
|
|
1905
|
+
exports.MAX_COOLDOWN_MS = MAX_COOLDOWN_MS;
|
|
1853
1906
|
exports.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX = ONCHAIN_COSIGN_AMBIGUOUS_PREFIX;
|
|
1854
1907
|
exports.ONCHAIN_COSIGN_REJECTED_PREFIX = ONCHAIN_COSIGN_REJECTED_PREFIX;
|
|
1855
1908
|
exports.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX = ONCHAIN_COSIGN_UNSUPPORTED_PREFIX;
|
|
@@ -1888,6 +1941,7 @@ exports.getAllNormalizedVtxos = getAllNormalizedVtxos;
|
|
|
1888
1941
|
exports.getArkPsbtFields = getArkPsbtFields;
|
|
1889
1942
|
exports.getConfiguredEventSource = getConfiguredEventSource;
|
|
1890
1943
|
exports.getNormalizedVtxos = getNormalizedVtxos;
|
|
1944
|
+
exports.indexerPages = indexerPages;
|
|
1891
1945
|
exports.isArkError = isArkError;
|
|
1892
1946
|
exports.isEventSourceError = isEventSourceError;
|
|
1893
1947
|
exports.isEventSourceUnavailableError = isEventSourceUnavailableError;
|
|
@@ -1903,11 +1957,13 @@ exports.readSseFrames = readSseFrames;
|
|
|
1903
1957
|
exports.requiresForfeit = requiresForfeit;
|
|
1904
1958
|
exports.resolveEventSource = resolveEventSource;
|
|
1905
1959
|
exports.resolveTimeHeight = resolveTimeHeight;
|
|
1960
|
+
exports.retryAfterMsFromError = retryAfterMsFromError;
|
|
1906
1961
|
exports.sdkVersion = sdkVersion;
|
|
1962
|
+
exports.sdkVersionHeaders = sdkVersionHeaders;
|
|
1907
1963
|
exports.setArkPsbtField = setArkPsbtField;
|
|
1908
1964
|
exports.streamFailureError = streamFailureError;
|
|
1909
1965
|
exports.throwIfHttpUnavailable = throwIfHttpUnavailable;
|
|
1910
1966
|
exports.toOffchainInputFeeParams = toOffchainInputFeeParams;
|
|
1911
1967
|
exports.toProviderUnavailable = toProviderUnavailable;
|
|
1912
|
-
//# sourceMappingURL=chunk-
|
|
1913
|
-
//# sourceMappingURL=chunk-
|
|
1968
|
+
//# sourceMappingURL=chunk-DY24A73N.cjs.map
|
|
1969
|
+
//# sourceMappingURL=chunk-DY24A73N.cjs.map
|