@dvmkit/dvm-cli 0.7.0-rc.2 → 0.7.0-rc.3
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/dist/{chunk-6QHVPJNX.js → chunk-2I5XAIQ4.js} +3 -3
- package/dist/{chunk-RQYMWLX4.js → chunk-3PV36227.js} +2 -2
- package/dist/{chunk-7UAQTHNP.js → chunk-5QO3MGMH.js} +4 -4
- package/dist/{chunk-PG7MEKJI.js → chunk-5VOAE2CL.js} +2 -2
- package/dist/{chunk-JTMBSEZO.js → chunk-6JP6ZBWW.js} +4 -4
- package/dist/{chunk-ZXVOMXT4.js → chunk-7OA2XUM4.js} +2 -2
- package/dist/{chunk-VLZ2K7JL.js → chunk-BHJLMVO2.js} +27 -6
- package/dist/{chunk-FPWP4S5S.js → chunk-C5XIOTRP.js} +36 -5
- package/dist/{chunk-IQV4KG63.js → chunk-EQXNDN5I.js} +2 -2
- package/dist/{chunk-U3YRNLZ5.js → chunk-IERBEO4C.js} +3 -3
- package/dist/{chunk-VIYUB3XT.js → chunk-LIITTIEN.js} +347 -85
- package/dist/{chunk-WN5R367B.js → chunk-ZM5QFHEY.js} +30 -2
- package/dist/{client-IDO4IAXG.js → client-PGOH2ION.js} +6 -6
- package/dist/dvm.js +1779 -620
- package/dist/{internal-7FXJTFBU.js → internal-VIAWW5ED.js} +13 -5
- package/dist/{lifecycle-LRS3IBQL.js → lifecycle-VHGTNHHE.js} +6 -6
- package/dist/{payout-reporter-WT7XYW42-U2QPDIYC.js → payout-reporter-3UVWPGMO-WWZWXWCG.js} +6 -4
- package/dist/{pocket-refill-J5OWRBXH.js → pocket-refill-BHNKMENF.js} +10 -10
- package/dist/{revenue-reporter-7UR3W2SD-C5OMRGK3.js → revenue-reporter-E56J3NZK-NZ5H27ZI.js} +2 -2
- package/dist/{tempo-lifecycle-HS2NIFKT.js → tempo-lifecycle-NDBO3V3A.js} +8 -8
- package/dist/{tempo-wallet-BA2LKR45.js → tempo-wallet-BAU7ASWF.js} +7 -7
- package/dist/{wallet-RPPUCQUR.js → wallet-RB2RPWIN.js} +7 -7
- package/dist/{x402-ZU4GML7Z-RYEACIIT.js → x402-BN26TQZ6-4MWLNZGT.js} +2 -2
- package/package.json +2 -2
|
@@ -322,7 +322,10 @@ import {
|
|
|
322
322
|
x402ResourceServer,
|
|
323
323
|
x402SupportedNetworksHint,
|
|
324
324
|
x402Version
|
|
325
|
-
} from "./chunk-
|
|
325
|
+
} from "./chunk-6JP6ZBWW.js";
|
|
326
|
+
import {
|
|
327
|
+
x402EarnedCeiling
|
|
328
|
+
} from "./chunk-C5XIOTRP.js";
|
|
326
329
|
import {
|
|
327
330
|
withSdkInitLock
|
|
328
331
|
} from "./chunk-R2DSAZBO.js";
|
|
@@ -335,7 +338,7 @@ import {
|
|
|
335
338
|
extendDiagnosticIdentityAuthority,
|
|
336
339
|
projectDiagnosticFields,
|
|
337
340
|
projectSpanRow
|
|
338
|
-
} from "./chunk-
|
|
341
|
+
} from "./chunk-ZM5QFHEY.js";
|
|
339
342
|
import {
|
|
340
343
|
privateKeyToAccount
|
|
341
344
|
} from "./chunk-EVQERRCP.js";
|
|
@@ -1984,7 +1987,7 @@ var require_proper_lockfile = __commonJS({
|
|
|
1984
1987
|
// node_modules/@dvmkit/sdk/dist/chunk-A262WVYX.js
|
|
1985
1988
|
var CAPABILITY_NAME_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
1986
1989
|
|
|
1987
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
1990
|
+
// node_modules/@dvmkit/sdk/dist/chunk-BDHJVTWA.js
|
|
1988
1991
|
import { createHash } from "crypto";
|
|
1989
1992
|
|
|
1990
1993
|
// node_modules/@noble/ciphers/utils.js
|
|
@@ -3927,7 +3930,7 @@ var getPublicKey2 = i2.getPublicKey;
|
|
|
3927
3930
|
var finalizeEvent2 = i2.finalizeEvent;
|
|
3928
3931
|
var verifyEvent2 = i2.verifyEvent;
|
|
3929
3932
|
|
|
3930
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
3933
|
+
// node_modules/@dvmkit/sdk/dist/chunk-BDHJVTWA.js
|
|
3931
3934
|
var X402_SELF_RELAY_KEY = "DVMKIT_X402_SELF_RELAY_KEY";
|
|
3932
3935
|
var X402_RECEIVER_AUTHORIZER_KEY = "DVMKIT_X402_RECEIVER_AUTHORIZER_KEY";
|
|
3933
3936
|
var X402_BATCH_SETTLEMENT_KEY = "DVMKIT_X402_BATCH_SETTLEMENT";
|
|
@@ -4966,7 +4969,7 @@ function canonicalRequestPath(pathOrUrl) {
|
|
|
4966
4969
|
return parsed.pathname.startsWith("/") ? parsed.pathname : `/${parsed.pathname}`;
|
|
4967
4970
|
}
|
|
4968
4971
|
|
|
4969
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
4972
|
+
// node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
|
|
4970
4973
|
import { homedir } from "os";
|
|
4971
4974
|
import { join as join3 } from "path";
|
|
4972
4975
|
import { chmodSync, mkdirSync, statSync } from "fs";
|
|
@@ -10209,7 +10212,7 @@ zero
|
|
|
10209
10212
|
zone
|
|
10210
10213
|
zoo`.split("\n");
|
|
10211
10214
|
|
|
10212
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
10215
|
+
// node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
|
|
10213
10216
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
10214
10217
|
import { existsSync as existsSync4, readFileSync as readFileSync4, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
10215
10218
|
|
|
@@ -20183,7 +20186,7 @@ function expand(hash4, prk, info, length = 32) {
|
|
|
20183
20186
|
}
|
|
20184
20187
|
var hkdf = (hash4, ikm, salt, info, length) => expand(hash4, extract(hash4, ikm, salt), info, length);
|
|
20185
20188
|
|
|
20186
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
20189
|
+
// node_modules/@dvmkit/sdk/dist/chunk-XO5EUHCW.js
|
|
20187
20190
|
import { randomBytes as randomBytes6 } from "crypto";
|
|
20188
20191
|
import {
|
|
20189
20192
|
chmodSync as chmodSync4,
|
|
@@ -20542,10 +20545,20 @@ var DEFAULT_LOCK_RETRY_INTERVAL_MS = 1e3;
|
|
|
20542
20545
|
var WALLET_VERSION = 9;
|
|
20543
20546
|
var RECENT_SPENDS_CAP = 10;
|
|
20544
20547
|
var DEFAULT_AGENT_MINT_URL = "https://mint.coinos.io";
|
|
20548
|
+
var MAX_STORABLE_JOB_ID_LENGTH = 512;
|
|
20549
|
+
function isStorableJobId(value) {
|
|
20550
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_STORABLE_JOB_ID_LENGTH && // eslint-disable-next-line no-control-regex -- control characters are what this rejects
|
|
20551
|
+
!/[\u0000-\u001f\u007f-\u009f]/u.test(value);
|
|
20552
|
+
}
|
|
20545
20553
|
function loadWalletConfiguredMints() {
|
|
20546
20554
|
return loadAgentWallet()?.mints ?? [];
|
|
20547
20555
|
}
|
|
20548
20556
|
function loadAgentWallet() {
|
|
20557
|
+
const wallet = parseAgentWallet();
|
|
20558
|
+
if (wallet) normalizeAcceptedUnresolved(wallet);
|
|
20559
|
+
return wallet;
|
|
20560
|
+
}
|
|
20561
|
+
function parseAgentWallet() {
|
|
20549
20562
|
if (!existsSync4(WALLET_FILE)) return null;
|
|
20550
20563
|
const raw2 = readFileSync4(WALLET_FILE, "utf-8");
|
|
20551
20564
|
let parsed;
|
|
@@ -20626,6 +20639,7 @@ function loadAgentWallet() {
|
|
|
20626
20639
|
return parsed;
|
|
20627
20640
|
}
|
|
20628
20641
|
function saveAgentWallet(wallet) {
|
|
20642
|
+
assertAcceptedUnresolvedStorable(wallet);
|
|
20629
20643
|
ensureConfigDir();
|
|
20630
20644
|
const tmp = `${WALLET_FILE}.tmp`;
|
|
20631
20645
|
const data = JSON.stringify(wallet, null, 2) + "\n";
|
|
@@ -20794,6 +20808,62 @@ function migrateV8ToV9(parsed) {
|
|
|
20794
20808
|
created_at: typeof parsed.created_at === "string" ? parsed.created_at : (/* @__PURE__ */ new Date()).toISOString()
|
|
20795
20809
|
};
|
|
20796
20810
|
}
|
|
20811
|
+
var ACCEPTED_UNRESOLVED_KINDS = /* @__PURE__ */ new Set([
|
|
20812
|
+
"identity_mismatch",
|
|
20813
|
+
"body_unreadable",
|
|
20814
|
+
"router_identity_conflict"
|
|
20815
|
+
]);
|
|
20816
|
+
var OBSERVED_JOB_ID_FIELDS = ["header_job_id", "body_job_id", "accepted_job_id"];
|
|
20817
|
+
var PLACEHOLDER_KIND = "body_unreadable";
|
|
20818
|
+
var PLACEHOLDER_OBSERVED_AT = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
20819
|
+
function assertAcceptedUnresolvedStorable(wallet) {
|
|
20820
|
+
const entries = wallet.pending_submissions;
|
|
20821
|
+
if (!Array.isArray(entries)) return;
|
|
20822
|
+
for (const entry of entries) {
|
|
20823
|
+
const record2 = entry?.accepted_unresolved;
|
|
20824
|
+
if (record2 === void 0 || isStorableAcceptedUnresolved(record2)) continue;
|
|
20825
|
+
throw new DvmError(
|
|
20826
|
+
"accepted_unresolved_invalid",
|
|
20827
|
+
`Refusing to save pending submission ${String(entry?.request_id)}: its accepted_unresolved record is outside the stored contract.`,
|
|
20828
|
+
"Use one of the three kinds, an ISO-8601 observed_at, and job IDs and ambiguity_id that pass isStorableJobId; omit an observed ID that does not. The wallet file was not changed."
|
|
20829
|
+
);
|
|
20830
|
+
}
|
|
20831
|
+
}
|
|
20832
|
+
function isStorableAcceptedUnresolved(value) {
|
|
20833
|
+
if (!isPlainRecord(value)) return false;
|
|
20834
|
+
return ACCEPTED_UNRESOLVED_KINDS.has(value.kind) && isIsoTimestamp(value.observed_at) && isStorableJobId(value.ambiguity_id) && OBSERVED_JOB_ID_FIELDS.every((field) => value[field] === void 0 || isStorableJobId(value[field]));
|
|
20835
|
+
}
|
|
20836
|
+
function normalizeAcceptedUnresolved(wallet) {
|
|
20837
|
+
const entries = wallet.pending_submissions;
|
|
20838
|
+
if (!Array.isArray(entries)) return;
|
|
20839
|
+
for (const entry of entries) {
|
|
20840
|
+
if (!entry || entry.accepted_unresolved === void 0) continue;
|
|
20841
|
+
const stored = entry.accepted_unresolved;
|
|
20842
|
+
if (isStorableAcceptedUnresolved(stored)) continue;
|
|
20843
|
+
const record2 = isPlainRecord(stored) ? { ...stored } : {};
|
|
20844
|
+
if (!ACCEPTED_UNRESOLVED_KINDS.has(record2.kind)) record2.kind = PLACEHOLDER_KIND;
|
|
20845
|
+
if (!isIsoTimestamp(record2.observed_at)) record2.observed_at = PLACEHOLDER_OBSERVED_AT;
|
|
20846
|
+
if (!isStorableJobId(record2.ambiguity_id)) {
|
|
20847
|
+
record2.ambiguity_id = isStorableJobId(entry.request_id) ? entry.request_id : "missing-ambiguity";
|
|
20848
|
+
}
|
|
20849
|
+
for (const field of OBSERVED_JOB_ID_FIELDS) {
|
|
20850
|
+
if (record2[field] !== void 0 && !isStorableJobId(record2[field])) delete record2[field];
|
|
20851
|
+
}
|
|
20852
|
+
entry.accepted_unresolved = record2;
|
|
20853
|
+
}
|
|
20854
|
+
}
|
|
20855
|
+
function isPlainRecord(value) {
|
|
20856
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20857
|
+
}
|
|
20858
|
+
var ISO_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,9})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;
|
|
20859
|
+
function isIsoTimestamp(value) {
|
|
20860
|
+
if (typeof value !== "string") return false;
|
|
20861
|
+
const match2 = ISO_TIMESTAMP.exec(value);
|
|
20862
|
+
if (!match2) return false;
|
|
20863
|
+
const [year, month, day] = [Number(match2[1]), Number(match2[2]), Number(match2[3])];
|
|
20864
|
+
const date4 = new Date(Date.UTC(year, month - 1, day));
|
|
20865
|
+
return date4.getUTCFullYear() === year && date4.getUTCMonth() === month - 1 && date4.getUTCDate() === day;
|
|
20866
|
+
}
|
|
20797
20867
|
function isCounterMap(value) {
|
|
20798
20868
|
if (typeof value !== "object" || value === null) return false;
|
|
20799
20869
|
for (const inner of Object.values(value)) {
|
|
@@ -21373,6 +21443,15 @@ function buildAdminAuthHeader(args) {
|
|
|
21373
21443
|
unixSeconds
|
|
21374
21444
|
};
|
|
21375
21445
|
}
|
|
21446
|
+
var JOB_IDENTITY_HEADER = "dvm-job-identity-v1";
|
|
21447
|
+
var JOB_IDENTITY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
21448
|
+
function isJobIdentityValue(value) {
|
|
21449
|
+
return typeof value === "string" && JOB_IDENTITY_PATTERN.test(value);
|
|
21450
|
+
}
|
|
21451
|
+
function parseJobIdentityHeader(value) {
|
|
21452
|
+
if (value === null) return { kind: "absent" };
|
|
21453
|
+
return isJobIdentityValue(value) ? { kind: "valid", jobId: value } : { kind: "invalid" };
|
|
21454
|
+
}
|
|
21376
21455
|
var CURRENT_VERSION = 2;
|
|
21377
21456
|
function loadBuilderStore() {
|
|
21378
21457
|
if (!existsSync5(BUILDER_FILE)) {
|
|
@@ -21836,7 +21915,7 @@ function createMonotonicClock() {
|
|
|
21836
21915
|
};
|
|
21837
21916
|
}
|
|
21838
21917
|
|
|
21839
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
21918
|
+
// node_modules/@dvmkit/sdk/dist/chunk-SX4WCPW7.js
|
|
21840
21919
|
import { AsyncLocalStorage } from "async_hooks";
|
|
21841
21920
|
import { randomBytes as randomBytes7, randomUUID } from "crypto";
|
|
21842
21921
|
import { hostname } from "os";
|
|
@@ -22298,7 +22377,7 @@ var StepCache = class _StepCache {
|
|
|
22298
22377
|
}
|
|
22299
22378
|
};
|
|
22300
22379
|
|
|
22301
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
22380
|
+
// node_modules/@dvmkit/sdk/dist/chunk-LQQ6H4UB.js
|
|
22302
22381
|
var InvalidCurrencyError = class extends Error {
|
|
22303
22382
|
code = "invalid_currency";
|
|
22304
22383
|
raw;
|
|
@@ -22436,14 +22515,53 @@ var FxRateUnavailableError = class extends Error {
|
|
|
22436
22515
|
* the last-known rate without it. See {@link FxKnownStale}.
|
|
22437
22516
|
*/
|
|
22438
22517
|
knownStale;
|
|
22439
|
-
|
|
22518
|
+
sourceFailure;
|
|
22519
|
+
constructor(message, copy, knownStale, sourceFailure) {
|
|
22440
22520
|
super(message);
|
|
22441
22521
|
this.name = "FxRateUnavailableError";
|
|
22442
22522
|
this.display = copy?.display ?? "Couldn't fetch the BTC reference rate to lock pricing";
|
|
22443
22523
|
this.hint = copy?.hint ?? "transient \u2014 try the quote again in a few seconds";
|
|
22444
22524
|
this.knownStale = knownStale;
|
|
22525
|
+
this.sourceFailure = normalizeFxSourceFailure(sourceFailure);
|
|
22445
22526
|
}
|
|
22446
22527
|
};
|
|
22528
|
+
var FX_SOURCE_FAILURE_CATEGORIES = /* @__PURE__ */ new Set([
|
|
22529
|
+
"network_error",
|
|
22530
|
+
"http_error",
|
|
22531
|
+
"invalid_body",
|
|
22532
|
+
"no_usable_rate",
|
|
22533
|
+
"missing_currency",
|
|
22534
|
+
"unknown"
|
|
22535
|
+
]);
|
|
22536
|
+
function normalizeFxSourceFailure(input) {
|
|
22537
|
+
if (input === void 0) return void 0;
|
|
22538
|
+
try {
|
|
22539
|
+
if (typeof input !== "object" || input === null) return { category: "unknown" };
|
|
22540
|
+
const categoryDescriptor = Object.getOwnPropertyDescriptor(input, "category");
|
|
22541
|
+
const category = categoryDescriptor && "value" in categoryDescriptor ? categoryDescriptor.value : void 0;
|
|
22542
|
+
if (typeof category !== "string" || !FX_SOURCE_FAILURE_CATEGORIES.has(category)) {
|
|
22543
|
+
return { category: "unknown" };
|
|
22544
|
+
}
|
|
22545
|
+
const statusDescriptor = Object.getOwnPropertyDescriptor(input, "httpStatus");
|
|
22546
|
+
const status = statusDescriptor && "value" in statusDescriptor ? statusDescriptor.value : void 0;
|
|
22547
|
+
return {
|
|
22548
|
+
category,
|
|
22549
|
+
...category === "http_error" && typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599 && { httpStatus: status }
|
|
22550
|
+
};
|
|
22551
|
+
} catch {
|
|
22552
|
+
return { category: "unknown" };
|
|
22553
|
+
}
|
|
22554
|
+
}
|
|
22555
|
+
function readFxSourceFailure(error) {
|
|
22556
|
+
try {
|
|
22557
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, "sourceFailure");
|
|
22558
|
+
if (!descriptor) return void 0;
|
|
22559
|
+
if (!("value" in descriptor)) return { category: "unknown" };
|
|
22560
|
+
return normalizeFxSourceFailure(descriptor.value);
|
|
22561
|
+
} catch {
|
|
22562
|
+
return { category: "unknown" };
|
|
22563
|
+
}
|
|
22564
|
+
}
|
|
22447
22565
|
function createFxFetcher(opts) {
|
|
22448
22566
|
const currencies = opts?.currencies ?? DEFAULT_FX_CURRENCIES;
|
|
22449
22567
|
const source = opts?.source ?? DEFAULT_FX_RATE_SOURCE;
|
|
@@ -22484,7 +22602,10 @@ function createFxFetcher(opts) {
|
|
|
22484
22602
|
}
|
|
22485
22603
|
}
|
|
22486
22604
|
throw new FxRateUnavailableError(
|
|
22487
|
-
lastErr instanceof Error ? lastErr.message : String(lastErr)
|
|
22605
|
+
lastErr instanceof Error ? lastErr.message : String(lastErr),
|
|
22606
|
+
void 0,
|
|
22607
|
+
void 0,
|
|
22608
|
+
lastErr instanceof FxRateUnavailableError ? readFxSourceFailure(lastErr) : { category: "unknown" }
|
|
22488
22609
|
);
|
|
22489
22610
|
})();
|
|
22490
22611
|
inFlight = promise2;
|
|
@@ -22511,7 +22632,9 @@ function fxRateFor(snapshot, currency) {
|
|
|
22511
22632
|
{
|
|
22512
22633
|
display: `The ${currency.toUpperCase()} reference rate is unavailable right now.`,
|
|
22513
22634
|
hint: `The rate source stopped carrying ${currency.toUpperCase()}. Retry in a minute; if it persists the source needs to be reconfigured.`
|
|
22514
|
-
}
|
|
22635
|
+
},
|
|
22636
|
+
void 0,
|
|
22637
|
+
{ category: "missing_currency" }
|
|
22515
22638
|
);
|
|
22516
22639
|
}
|
|
22517
22640
|
throw new UnsupportedCurrencyError(currency, Object.keys(snapshot.rates));
|
|
@@ -22523,19 +22646,32 @@ async function fetchOnce(source, currencies, fetchFn) {
|
|
|
22523
22646
|
return fetchPlatformShape(source, currencies, fetchFn);
|
|
22524
22647
|
}
|
|
22525
22648
|
async function fetchCoinGeckoShape(source, currencies, fetchFn) {
|
|
22526
|
-
const res = await fetchFn
|
|
22649
|
+
const res = await fetchSource(fetchFn, source);
|
|
22527
22650
|
if (!res.ok) {
|
|
22528
|
-
throw new
|
|
22651
|
+
throw new FxRateUnavailableError(
|
|
22652
|
+
`fx source ${source} returned ${res.status.toString()}`,
|
|
22653
|
+
void 0,
|
|
22654
|
+
void 0,
|
|
22655
|
+
{ category: "http_error", httpStatus: res.status }
|
|
22656
|
+
);
|
|
22529
22657
|
}
|
|
22530
|
-
const body = await res
|
|
22531
|
-
const bitcoin = body
|
|
22532
|
-
if (!bitcoin || typeof bitcoin !== "object") {
|
|
22533
|
-
throw new
|
|
22658
|
+
const body = await parseRateBody(res);
|
|
22659
|
+
const bitcoin = body?.bitcoin;
|
|
22660
|
+
if (!bitcoin || typeof bitcoin !== "object" || Array.isArray(bitcoin)) {
|
|
22661
|
+
throw new FxRateUnavailableError(
|
|
22662
|
+
`fx source ${source} returned an unparsable rate body`,
|
|
22663
|
+
void 0,
|
|
22664
|
+
void 0,
|
|
22665
|
+
{ category: "invalid_body" }
|
|
22666
|
+
);
|
|
22534
22667
|
}
|
|
22535
|
-
return {
|
|
22668
|
+
return {
|
|
22669
|
+
rates: collectRates(source, bitcoin, currencies),
|
|
22670
|
+
as_of: (/* @__PURE__ */ new Date()).toISOString()
|
|
22671
|
+
};
|
|
22536
22672
|
}
|
|
22537
22673
|
async function fetchPlatformShape(source, currencies, fetchFn) {
|
|
22538
|
-
const res = await fetchFn
|
|
22674
|
+
const res = await fetchSource(fetchFn, source.url, {
|
|
22539
22675
|
headers: { Authorization: `Bearer ${source.token}`, Accept: "application/json" }
|
|
22540
22676
|
});
|
|
22541
22677
|
if (!res.ok) {
|
|
@@ -22544,20 +22680,57 @@ async function fetchPlatformShape(source, currencies, fetchFn) {
|
|
|
22544
22680
|
throw new FxRateUnavailableError(
|
|
22545
22681
|
`fx source ${source.url} refused: rate ${knownStale.staleDays.toString()}d stale` + (knownStale.thresholdDays !== void 0 ? ` (threshold ${knownStale.thresholdDays.toString()}d)` : ""),
|
|
22546
22682
|
void 0,
|
|
22547
|
-
knownStale
|
|
22683
|
+
knownStale,
|
|
22684
|
+
{ category: "http_error", httpStatus: res.status }
|
|
22548
22685
|
);
|
|
22549
22686
|
}
|
|
22550
|
-
throw new
|
|
22687
|
+
throw new FxRateUnavailableError(
|
|
22688
|
+
`fx source ${source.url} returned ${res.status.toString()}`,
|
|
22689
|
+
void 0,
|
|
22690
|
+
void 0,
|
|
22691
|
+
{ category: "http_error", httpStatus: res.status }
|
|
22692
|
+
);
|
|
22551
22693
|
}
|
|
22552
|
-
const body = await res
|
|
22553
|
-
const raw2 = body
|
|
22554
|
-
if (!raw2 || typeof raw2 !== "object") {
|
|
22555
|
-
throw new
|
|
22694
|
+
const body = await parseRateBody(res);
|
|
22695
|
+
const raw2 = body?.rates;
|
|
22696
|
+
if (!raw2 || typeof raw2 !== "object" || Array.isArray(raw2)) {
|
|
22697
|
+
throw new FxRateUnavailableError(
|
|
22698
|
+
`fx source ${source.url} returned an unparsable rate body`,
|
|
22699
|
+
void 0,
|
|
22700
|
+
void 0,
|
|
22701
|
+
{ category: "invalid_body" }
|
|
22702
|
+
);
|
|
22556
22703
|
}
|
|
22557
22704
|
const rates = collectRates(source.url, raw2, currencies);
|
|
22558
22705
|
const as_of = typeof body.as_of === "string" ? body.as_of : (/* @__PURE__ */ new Date()).toISOString();
|
|
22559
22706
|
return { rates, as_of };
|
|
22560
22707
|
}
|
|
22708
|
+
async function fetchSource(fetchFn, url2, init) {
|
|
22709
|
+
try {
|
|
22710
|
+
return await fetchFn(url2, init);
|
|
22711
|
+
} catch (err) {
|
|
22712
|
+
if (err instanceof FxRateUnavailableError) throw err;
|
|
22713
|
+
throw new FxRateUnavailableError(
|
|
22714
|
+
err instanceof Error ? err.message : String(err),
|
|
22715
|
+
void 0,
|
|
22716
|
+
void 0,
|
|
22717
|
+
{ category: "network_error" }
|
|
22718
|
+
);
|
|
22719
|
+
}
|
|
22720
|
+
}
|
|
22721
|
+
async function parseRateBody(res) {
|
|
22722
|
+
try {
|
|
22723
|
+
const body = await res.json();
|
|
22724
|
+
return typeof body === "object" && body !== null && !Array.isArray(body) ? body : null;
|
|
22725
|
+
} catch {
|
|
22726
|
+
throw new FxRateUnavailableError(
|
|
22727
|
+
"fx source returned an unparsable rate body",
|
|
22728
|
+
void 0,
|
|
22729
|
+
void 0,
|
|
22730
|
+
{ category: "invalid_body" }
|
|
22731
|
+
);
|
|
22732
|
+
}
|
|
22733
|
+
}
|
|
22561
22734
|
function collectRates(source, raw2, currencies) {
|
|
22562
22735
|
const rates = {};
|
|
22563
22736
|
for (const currency of currencies) {
|
|
@@ -22566,8 +22739,11 @@ function collectRates(source, raw2, currencies) {
|
|
|
22566
22739
|
rates[currency] = value;
|
|
22567
22740
|
}
|
|
22568
22741
|
if (Object.keys(rates).length === 0) {
|
|
22569
|
-
throw new
|
|
22570
|
-
`fx source ${source} returned no usable rate for any of [${currencies.join(", ")}]
|
|
22742
|
+
throw new FxRateUnavailableError(
|
|
22743
|
+
`fx source ${source} returned no usable rate for any of [${currencies.join(", ")}]`,
|
|
22744
|
+
void 0,
|
|
22745
|
+
void 0,
|
|
22746
|
+
{ category: "no_usable_rate" }
|
|
22571
22747
|
);
|
|
22572
22748
|
}
|
|
22573
22749
|
return rates;
|
|
@@ -22624,6 +22800,7 @@ async function parsePlatformStaleRefusal(res) {
|
|
|
22624
22800
|
} catch {
|
|
22625
22801
|
return null;
|
|
22626
22802
|
}
|
|
22803
|
+
if (typeof body !== "object" || body === null) return null;
|
|
22627
22804
|
const error = body.error;
|
|
22628
22805
|
if (!error || typeof error !== "object") return null;
|
|
22629
22806
|
const { code, detail } = error;
|
|
@@ -22652,7 +22829,7 @@ function resolveFxSourceFromEnv(env) {
|
|
|
22652
22829
|
return raw2;
|
|
22653
22830
|
}
|
|
22654
22831
|
|
|
22655
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
22832
|
+
// node_modules/@dvmkit/sdk/dist/chunk-6RYCZLCK.js
|
|
22656
22833
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
22657
22834
|
var postgresRecovery = new AsyncLocalStorage2();
|
|
22658
22835
|
function withPostgresRecoveryContext(context, operation) {
|
|
@@ -31084,7 +31261,7 @@ function parseStoreValue(value) {
|
|
|
31084
31261
|
return parsed;
|
|
31085
31262
|
}
|
|
31086
31263
|
|
|
31087
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
31264
|
+
// node_modules/@dvmkit/sdk/dist/chunk-GDCIHJAR.js
|
|
31088
31265
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "async_hooks";
|
|
31089
31266
|
var PostgresTempoSessionStore = class {
|
|
31090
31267
|
constructor(pool) {
|
|
@@ -31593,7 +31770,7 @@ function acceptanceVoucherAmount(acceptance, key, current, next) {
|
|
|
31593
31770
|
return authorized !== void 0 && authorized >= acceptance.cumulativeAmount ? acceptance.cumulativeAmount : void 0;
|
|
31594
31771
|
}
|
|
31595
31772
|
|
|
31596
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
31773
|
+
// node_modules/@dvmkit/sdk/dist/chunk-BQP3LU2O.js
|
|
31597
31774
|
import { createHash as createHash5 } from "crypto";
|
|
31598
31775
|
var DEFAULT_TABLE_NAME = "mpp_tempo_charge_replays";
|
|
31599
31776
|
var DEFAULT_RETENTION_MS = 60 * 60 * 1e3;
|
|
@@ -31822,7 +31999,7 @@ var PostgresTempoChargeStore = class {
|
|
|
31822
31999
|
}
|
|
31823
32000
|
};
|
|
31824
32001
|
|
|
31825
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
32002
|
+
// node_modules/@dvmkit/sdk/dist/chunk-KYCLHWKO.js
|
|
31826
32003
|
import { createHash as createHash6, randomUUID as randomUUID3 } from "crypto";
|
|
31827
32004
|
var TEMPO_SETTLEMENT_BALANCE_INTERVAL_MS = 5 * 60 * 1e3;
|
|
31828
32005
|
function isTempoInsufficientFundsError(error) {
|
|
@@ -32369,7 +32546,7 @@ var _testing = {
|
|
|
32369
32546
|
attachTempoSessionRuntime
|
|
32370
32547
|
};
|
|
32371
32548
|
|
|
32372
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
32549
|
+
// node_modules/@dvmkit/sdk/dist/chunk-WP7UX6RF.js
|
|
32373
32550
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
32374
32551
|
import { AsyncLocalStorage as AsyncLocalStorage5 } from "async_hooks";
|
|
32375
32552
|
import { isDeepStrictEqual } from "util";
|
|
@@ -36308,7 +36485,7 @@ function expiryReleaseReport(dvmId, row) {
|
|
|
36308
36485
|
};
|
|
36309
36486
|
}
|
|
36310
36487
|
|
|
36311
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
36488
|
+
// node_modules/@dvmkit/sdk/dist/chunk-FOJKZ4E7.js
|
|
36312
36489
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
36313
36490
|
var MemoryCreditLedger = class _MemoryCreditLedger {
|
|
36314
36491
|
/**
|
|
@@ -37822,7 +37999,7 @@ function applyContentHoldMutation(job, history, mutation) {
|
|
|
37822
37999
|
return result;
|
|
37823
38000
|
}
|
|
37824
38001
|
|
|
37825
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
38002
|
+
// node_modules/@dvmkit/sdk/dist/chunk-KB7MEWBE.js
|
|
37826
38003
|
import { createHash as createHash7 } from "crypto";
|
|
37827
38004
|
var DEFAULT_BACKOFF_MS = [1e3, 4e3, 15e3, 3e4];
|
|
37828
38005
|
var ListenChannel = class {
|
|
@@ -38095,10 +38272,20 @@ var PostgresJobStore = class {
|
|
|
38095
38272
|
CREATE INDEX IF NOT EXISTS idx_jobs_retention
|
|
38096
38273
|
ON jobs (last_activity_at, id)
|
|
38097
38274
|
WHERE redacted_at IS NULL AND status IN ('completed', 'failed', 'cancelled');
|
|
38098
|
-
|
|
38275
|
+
-- Terminal cost recovery runs at boot and every 30s on each machine.
|
|
38276
|
+
-- Indexing only rows whose latest revision is not yet enqueued keeps each
|
|
38277
|
+
-- pass proportional to that backlog; marking a row drops it from the
|
|
38278
|
+
-- index. listUnreportedTerminalCosts' WHERE clause must imply this
|
|
38279
|
+
-- predicate or the planner falls back to scanning terminal history.
|
|
38280
|
+
DROP INDEX IF EXISTS idx_jobs_pending_cost_report;
|
|
38281
|
+
CREATE INDEX IF NOT EXISTS idx_jobs_unreported_terminal_cost
|
|
38099
38282
|
ON jobs (dvm_id, id)
|
|
38100
38283
|
WHERE cost_revision IS NOT NULL
|
|
38101
|
-
AND
|
|
38284
|
+
AND (cost_reported_revision IS NULL OR cost_reported_revision < cost_revision)
|
|
38285
|
+
AND (
|
|
38286
|
+
status IN ('failed', 'cancelled')
|
|
38287
|
+
OR (status = 'completed' AND paid_msats = 0)
|
|
38288
|
+
);
|
|
38102
38289
|
-- the idempotent-replay lookup. payment_tx_hash carries the
|
|
38103
38290
|
-- caller's X-Cashu-Request-Id on the accumulator path, so a retried paid
|
|
38104
38291
|
-- submit finds the job its payment already created.
|
|
@@ -38498,7 +38685,8 @@ var PostgresJobStore = class {
|
|
|
38498
38685
|
}
|
|
38499
38686
|
/**
|
|
38500
38687
|
* Read terminal zero-revenue jobs whose latest declared-cost revision has
|
|
38501
|
-
* not yet reached the durable reporter outbox.
|
|
38688
|
+
* not yet reached the durable reporter outbox. Keep the filter in step with
|
|
38689
|
+
* `idx_jobs_unreported_terminal_cost`, which bounds each pass to the backlog.
|
|
38502
38690
|
*/
|
|
38503
38691
|
async listUnreportedTerminalCosts(args) {
|
|
38504
38692
|
const { rows: rows2 } = await this.pool.query(
|
|
@@ -39295,7 +39483,7 @@ function isTerminalStatus(status) {
|
|
|
39295
39483
|
return status === "completed" || status === "failed" || status === "cancelled";
|
|
39296
39484
|
}
|
|
39297
39485
|
|
|
39298
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
39486
|
+
// node_modules/@dvmkit/sdk/dist/chunk-X5RY2G3C.js
|
|
39299
39487
|
function humanizeZodError(err, opts) {
|
|
39300
39488
|
return humanizeZodIssues(err.issues, opts);
|
|
39301
39489
|
}
|
|
@@ -39448,7 +39636,7 @@ function createDefaultReplayStore() {
|
|
|
39448
39636
|
}
|
|
39449
39637
|
var SATURATION_WARN_INTERVAL_SECONDS = 60;
|
|
39450
39638
|
|
|
39451
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
39639
|
+
// node_modules/@dvmkit/sdk/dist/chunk-MYJOV4R4.js
|
|
39452
39640
|
function accumulateAskedTopUp(prior, ask) {
|
|
39453
39641
|
const poisoned = (reason) => ({
|
|
39454
39642
|
micro: UNCAPPABLE_ASK_TOTAL,
|
|
@@ -40101,7 +40289,7 @@ function isUniqueViolation2(err) {
|
|
|
40101
40289
|
return typeof err === "object" && err !== null && err.code === "23505";
|
|
40102
40290
|
}
|
|
40103
40291
|
|
|
40104
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
40292
|
+
// node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
|
|
40105
40293
|
import { createHash as createHash8, randomUUID as randomUUID7 } from "crypto";
|
|
40106
40294
|
import { createHash as createHash23 } from "crypto";
|
|
40107
40295
|
import { createHash as createHash33 } from "crypto";
|
|
@@ -43559,8 +43747,8 @@ var BatchSettlementEvmScheme3 = class {
|
|
|
43559
43747
|
}
|
|
43560
43748
|
};
|
|
43561
43749
|
|
|
43562
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
43563
|
-
import { randomBytes as randomBytes8, randomUUID as randomUUID22 } from "crypto";
|
|
43750
|
+
// node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
|
|
43751
|
+
import { createHash as createHash42, randomBytes as randomBytes8, randomUUID as randomUUID22 } from "crypto";
|
|
43564
43752
|
import { randomBytes as randomBytes22 } from "crypto";
|
|
43565
43753
|
|
|
43566
43754
|
// node_modules/zod/v4/classic/external.js
|
|
@@ -45930,18 +46118,18 @@ function date3(params) {
|
|
|
45930
46118
|
// node_modules/zod/v4/classic/external.js
|
|
45931
46119
|
config(en_default());
|
|
45932
46120
|
|
|
45933
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
45934
|
-
import { createHash as
|
|
46121
|
+
// node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
|
|
46122
|
+
import { createHash as createHash52 } from "crypto";
|
|
45935
46123
|
import { createHmac as createHmac2, randomUUID as randomUUID42, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
45936
|
-
import { createHash as
|
|
46124
|
+
import { createHash as createHash62, randomUUID as randomUUID32 } from "crypto";
|
|
45937
46125
|
import { isDeepStrictEqual as isDeepStrictEqual22 } from "util";
|
|
45938
|
-
import { createHash as
|
|
46126
|
+
import { createHash as createHash72 } from "crypto";
|
|
45939
46127
|
import { randomBytes as randomBytes42 } from "crypto";
|
|
45940
46128
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "async_hooks";
|
|
45941
46129
|
import { randomBytes as randomBytes32 } from "crypto";
|
|
45942
|
-
import { createHash as
|
|
46130
|
+
import { createHash as createHash82 } from "crypto";
|
|
45943
46131
|
import { randomUUID as randomUUID52 } from "crypto";
|
|
45944
|
-
import { createHash as
|
|
46132
|
+
import { createHash as createHash10, randomBytes as randomBytes52, randomUUID as randomUUID62 } from "crypto";
|
|
45945
46133
|
|
|
45946
46134
|
// node_modules/hono/dist/compose.js
|
|
45947
46135
|
var compose = (middleware, onError, onNotFound) => {
|
|
@@ -48322,8 +48510,8 @@ var streamSSE = (c, cb, onError) => {
|
|
|
48322
48510
|
return c.newResponse(stream2.responseReadable);
|
|
48323
48511
|
};
|
|
48324
48512
|
|
|
48325
|
-
// node_modules/@dvmkit/sdk/dist/chunk-
|
|
48326
|
-
import { createHash as
|
|
48513
|
+
// node_modules/@dvmkit/sdk/dist/chunk-Z6EJOVIU.js
|
|
48514
|
+
import { createHash as createHash9 } from "crypto";
|
|
48327
48515
|
async function initLockPubkeyTable(db) {
|
|
48328
48516
|
await withSdkInitLock(db, () => createLockPubkeyTable(db));
|
|
48329
48517
|
}
|
|
@@ -49138,7 +49326,8 @@ async function resolveFxSnapshot(fetcher) {
|
|
|
49138
49326
|
return {
|
|
49139
49327
|
ok: false,
|
|
49140
49328
|
reason: "rate_stale_refused",
|
|
49141
|
-
detail: `snapshot ${err.knownStale.staleDays.toString()}d stale
|
|
49329
|
+
detail: `snapshot ${err.knownStale.staleDays.toString()}d stale`,
|
|
49330
|
+
sourceFailure: readFxSourceFailure(err)
|
|
49142
49331
|
};
|
|
49143
49332
|
}
|
|
49144
49333
|
const cached = fetcher.lastKnown?.();
|
|
@@ -49148,7 +49337,8 @@ async function resolveFxSnapshot(fetcher) {
|
|
|
49148
49337
|
return {
|
|
49149
49338
|
ok: false,
|
|
49150
49339
|
reason: "rate_unavailable",
|
|
49151
|
-
detail: err instanceof Error ? err.message : String(err)
|
|
49340
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
49341
|
+
sourceFailure: err instanceof FxRateUnavailableError ? readFxSourceFailure(err) ?? { category: "unknown" } : { category: "unknown" }
|
|
49152
49342
|
};
|
|
49153
49343
|
}
|
|
49154
49344
|
}
|
|
@@ -49175,7 +49365,10 @@ async function msatsToFiatMicro(args) {
|
|
|
49175
49365
|
// A currency the snapshot never carried is the rate source narrowing, not
|
|
49176
49366
|
// a currency this DVM doesn't speak — `fxRateFor` separates the two.
|
|
49177
49367
|
reason: err instanceof FxRateUnavailableError ? "rate_unavailable" : "unsupported_currency",
|
|
49178
|
-
detail: err instanceof Error ? err.message : String(err)
|
|
49368
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
49369
|
+
...err instanceof FxRateUnavailableError && {
|
|
49370
|
+
sourceFailure: readFxSourceFailure(err) ?? { category: "unknown" }
|
|
49371
|
+
}
|
|
49179
49372
|
};
|
|
49180
49373
|
}
|
|
49181
49374
|
const amountMicro = Math.round(amount * 1e6);
|
|
@@ -50094,6 +50287,7 @@ async function createX402BatchSettlementServer(opts) {
|
|
|
50094
50287
|
payTo: opts.payTo,
|
|
50095
50288
|
network: opts.network,
|
|
50096
50289
|
storage: storage2,
|
|
50290
|
+
earnedNative: opts.earnedNative,
|
|
50097
50291
|
settleIntervalMs: (settlementConfig.settleIntervalSecs ?? X402_BATCH_AUTO_SETTLEMENT.settleIntervalSecs ?? 300) * 1e3,
|
|
50098
50292
|
...postgres ? { listWedgedRefunds: () => listWedgedRefunds(postgres) } : {}
|
|
50099
50293
|
});
|
|
@@ -50848,22 +51042,19 @@ function claimCeilingSelector(earnedNative) {
|
|
|
50848
51042
|
const charged = BigInt(channel.chargedCumulativeAmount);
|
|
50849
51043
|
const claimed = BigInt(channel.totalClaimed);
|
|
50850
51044
|
if (charged <= claimed) continue;
|
|
50851
|
-
|
|
50852
|
-
|
|
50853
|
-
earned = await earnedNative(channel.channelId.toLowerCase());
|
|
50854
|
-
} catch (error) {
|
|
51045
|
+
const resolved = await x402EarnedCeiling(channel, earnedNative);
|
|
51046
|
+
if (resolved.kind === "unresolved") {
|
|
50855
51047
|
loggers.x402.warn("x402_claim_ceiling_unresolved", {
|
|
50856
51048
|
"channel.id": channel.channelId,
|
|
50857
|
-
error: error instanceof Error ? error.message : String(error)
|
|
51049
|
+
error: resolved.error instanceof Error ? resolved.error.message : String(resolved.error)
|
|
50858
51050
|
});
|
|
50859
51051
|
continue;
|
|
50860
51052
|
}
|
|
50861
|
-
if (
|
|
51053
|
+
if (resolved.kind === "unbound") {
|
|
50862
51054
|
loggers.x402.warn("x402_claim_ceiling_unbound", { "channel.id": channel.channelId });
|
|
50863
51055
|
continue;
|
|
50864
51056
|
}
|
|
50865
|
-
const
|
|
50866
|
-
const ceiling = wanted < charged ? wanted : charged;
|
|
51057
|
+
const { ceiling } = resolved;
|
|
50867
51058
|
if (ceiling <= claimed) continue;
|
|
50868
51059
|
selected.push({ ...channel, chargedCumulativeAmount: ceiling.toString() });
|
|
50869
51060
|
}
|
|
@@ -51865,7 +52056,7 @@ async function verifyUpfrontPaymentInScope(opts) {
|
|
|
51865
52056
|
x402Requirements
|
|
51866
52057
|
});
|
|
51867
52058
|
}
|
|
51868
|
-
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-
|
|
52059
|
+
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
|
|
51869
52060
|
const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
|
|
51870
52061
|
x402Payment,
|
|
51871
52062
|
x402Config,
|
|
@@ -52853,7 +53044,7 @@ async function verifyIncomingPaymentInScope(body, opts, snapshot) {
|
|
|
52853
53044
|
snapshot
|
|
52854
53045
|
});
|
|
52855
53046
|
}
|
|
52856
|
-
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-
|
|
53047
|
+
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
|
|
52857
53048
|
const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
|
|
52858
53049
|
body.content.x402_payment,
|
|
52859
53050
|
opts.x402Config,
|
|
@@ -53284,7 +53475,7 @@ async function processIncomingPaymentInScope(job, body, opts) {
|
|
|
53284
53475
|
try {
|
|
53285
53476
|
const requiredMsats = job.pendingPaymentMsats ?? 0;
|
|
53286
53477
|
const requiredUsdcMicro = job.pendingX402AmountUsdcMicro !== void 0 ? BigInt(job.pendingX402AmountUsdcMicro) : BigInt(msatsToUsdc(requiredMsats, rate));
|
|
53287
|
-
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-
|
|
53478
|
+
const { verifyX402Payment: verifyX402Payment2 } = await import("./x402-BN26TQZ6-4MWLNZGT.js");
|
|
53288
53479
|
const receipt = await withPaymentStage("verifier_broadcast", () => verifyX402Payment2(
|
|
53289
53480
|
body.content.x402_payment,
|
|
53290
53481
|
opts.x402Config,
|
|
@@ -53672,7 +53863,10 @@ async function resolveTopUpLedgerContext(opts, snapshot, binding) {
|
|
|
53672
53863
|
job_id: opts.jobId,
|
|
53673
53864
|
credit_id: snapshot.creditId,
|
|
53674
53865
|
draw_id: snapshot.drawId,
|
|
53675
|
-
...extra
|
|
53866
|
+
...extra,
|
|
53867
|
+
...typeof opts.jobId === "string" && {
|
|
53868
|
+
job_id_hash: createHash42("sha256").update(opts.jobId, "utf8").digest("hex")
|
|
53869
|
+
}
|
|
53676
53870
|
}
|
|
53677
53871
|
);
|
|
53678
53872
|
};
|
|
@@ -53734,7 +53928,11 @@ async function resolveTopUpLedgerContext(opts, snapshot, binding) {
|
|
|
53734
53928
|
if (!denomination.ok) {
|
|
53735
53929
|
logSkip("denomination_unavailable", {
|
|
53736
53930
|
currency,
|
|
53737
|
-
cause: denomination.reason
|
|
53931
|
+
cause: denomination.reason,
|
|
53932
|
+
...denomination.sourceFailure && {
|
|
53933
|
+
source_failure: denomination.sourceFailure.category,
|
|
53934
|
+
source_status: denomination.sourceFailure.httpStatus
|
|
53935
|
+
}
|
|
53738
53936
|
});
|
|
53739
53937
|
return void 0;
|
|
53740
53938
|
}
|
|
@@ -53924,9 +54122,11 @@ async function fundAndDrawInScope(ctx, funding, tx) {
|
|
|
53924
54122
|
throw new Error("deposit outbox enqueue requires the rail's open transaction and a DVM id");
|
|
53925
54123
|
}
|
|
53926
54124
|
const commitDeposit = async (result, credit) => {
|
|
54125
|
+
const instrument = credit.rail ? storedCreditBinding(credit).instrument : void 0;
|
|
53927
54126
|
const report = {
|
|
53928
54127
|
...deposit,
|
|
53929
|
-
callerPubkey: credit.callerPubkey
|
|
54128
|
+
callerPubkey: credit.callerPubkey,
|
|
54129
|
+
...instrument && { instrument }
|
|
53930
54130
|
};
|
|
53931
54131
|
if (createsDepositLiability && enqueue && tx) {
|
|
53932
54132
|
await enqueue(tx, creditDepositPayload(ctx.dvmId, report));
|
|
@@ -54108,6 +54308,7 @@ function creditDepositPayload(dvmId, funding) {
|
|
|
54108
54308
|
creditCurrency: funding.currency,
|
|
54109
54309
|
fundedAt: funding.fundedAt,
|
|
54110
54310
|
expiryMs: funding.expiryMs,
|
|
54311
|
+
...funding.instrument && { instrument: funding.instrument },
|
|
54111
54312
|
// label a session-funded deposit as one, whether or not the chain
|
|
54112
54313
|
// binding below could be read. `rail: "tempo"` alone does not say — a
|
|
54113
54314
|
// `tempo/charge` one-shot funds a credit with no channel at all — so this is
|
|
@@ -57445,7 +57646,7 @@ function settlementMayHaveMoved(response) {
|
|
|
57445
57646
|
return reason.includes("authorization_already_used") || reason.includes("authorization already used") || /facilitator_status_5\d\d/.test(reason);
|
|
57446
57647
|
}
|
|
57447
57648
|
function hash3(parts) {
|
|
57448
|
-
return
|
|
57649
|
+
return createHash52("sha256").update(JSON.stringify(parts)).digest("hex");
|
|
57449
57650
|
}
|
|
57450
57651
|
function safeError(err) {
|
|
57451
57652
|
if (err instanceof Error) return err.name;
|
|
@@ -57669,7 +57870,7 @@ var TEMPO_CLOSED_EVENT = session_exports.Precompile.escrowAbi.find(
|
|
|
57669
57870
|
(item) => item.type === "event" && item.name === "ChannelClosed"
|
|
57670
57871
|
);
|
|
57671
57872
|
function hash22(value) {
|
|
57672
|
-
return
|
|
57873
|
+
return createHash62("sha256").update(JSON.stringify(value)).digest("hex");
|
|
57673
57874
|
}
|
|
57674
57875
|
function hex2(value, bytes) {
|
|
57675
57876
|
return typeof value === "string" && new RegExp(`^0x[0-9a-fA-F]{${bytes * 2}}$`).test(value);
|
|
@@ -58617,7 +58818,7 @@ async function readHostedChannelSnapshot(query) {
|
|
|
58617
58818
|
};
|
|
58618
58819
|
const x402HistoryComplete = await history(names[6]);
|
|
58619
58820
|
const tempoHistoryComplete = await history(names[7]);
|
|
58620
|
-
const digest =
|
|
58821
|
+
const digest = createHash72("sha256").update(JSON.stringify({
|
|
58621
58822
|
present: [...exists].sort(),
|
|
58622
58823
|
x402,
|
|
58623
58824
|
x402Tombstones,
|
|
@@ -59697,7 +59898,8 @@ var HostingControl = class {
|
|
|
59697
59898
|
pendingAdmissionCount: Number(pending.rows[0].pending),
|
|
59698
59899
|
pendingAdmissions: inFlight.rows.map((row) => ({ admissionId: row.id, workId: row.job_id })),
|
|
59699
59900
|
unresolvedAdmissionCount: Number(pending.rows[0].unresolved),
|
|
59700
|
-
unresolvedAdmissions: unresolved.rows.map((row) => ({ admissionId: row.id, jobId: row.job_id }))
|
|
59901
|
+
unresolvedAdmissions: unresolved.rows.map((row) => ({ admissionId: row.id, jobId: row.job_id })),
|
|
59902
|
+
jobIdentityHeader: "v1"
|
|
59701
59903
|
};
|
|
59702
59904
|
}
|
|
59703
59905
|
};
|
|
@@ -59749,7 +59951,7 @@ function isRecord22(value) {
|
|
|
59749
59951
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
59750
59952
|
}
|
|
59751
59953
|
function hashKey(key) {
|
|
59752
|
-
return
|
|
59954
|
+
return createHash82("sha256").update(key).digest("hex").slice(0, 16);
|
|
59753
59955
|
}
|
|
59754
59956
|
function instrumentKVStore(inner) {
|
|
59755
59957
|
return {
|
|
@@ -67123,7 +67325,7 @@ function requestFingerprint(req, opts) {
|
|
|
67123
67325
|
params: req.params ?? {},
|
|
67124
67326
|
data: opts.stripAuthEnvelope ? stripEnvelope(req.data) : req.data
|
|
67125
67327
|
});
|
|
67126
|
-
return
|
|
67328
|
+
return createHash9("sha256").update(canonical).digest("hex");
|
|
67127
67329
|
}
|
|
67128
67330
|
var ENVELOPE_KEYS = /* @__PURE__ */ new Set(["pubkey", "signature", "timestamp", "nonce", "auth_statement"]);
|
|
67129
67331
|
function stripEnvelope(data) {
|
|
@@ -67244,7 +67446,7 @@ async function createDVMServer(descriptor, opts) {
|
|
|
67244
67446
|
}
|
|
67245
67447
|
}
|
|
67246
67448
|
if (!opts.onJobCompleted && platformToken && platformUrl && dvmId && opts.db) {
|
|
67247
|
-
const { RevenueReporter: RevenueReporter2 } = await import("./revenue-reporter-
|
|
67449
|
+
const { RevenueReporter: RevenueReporter2 } = await import("./revenue-reporter-E56J3NZK-NZ5H27ZI.js");
|
|
67248
67450
|
const reporter = new RevenueReporter2(
|
|
67249
67451
|
opts.db,
|
|
67250
67452
|
platformUrl,
|
|
@@ -67254,7 +67456,7 @@ async function createDVMServer(descriptor, opts) {
|
|
|
67254
67456
|
revenueReporter = reporter;
|
|
67255
67457
|
await reporter.init();
|
|
67256
67458
|
reporter.startRetryLoop();
|
|
67257
|
-
const { MemoryX402BatchStore, PayoutReporter: PayoutReporter2 } = await import("./payout-reporter-
|
|
67459
|
+
const { MemoryX402BatchStore, PayoutReporter: PayoutReporter2 } = await import("./payout-reporter-3UVWPGMO-WWZWXWCG.js");
|
|
67258
67460
|
payoutReporter = new PayoutReporter2({
|
|
67259
67461
|
dvmId,
|
|
67260
67462
|
db: opts.db,
|
|
@@ -67539,6 +67741,7 @@ var DVMServer = class {
|
|
|
67539
67741
|
`createDVMServer: this DVM prices in ${JSON.stringify(this.pricingCurrency)} (DVMConfig.currency) but its fx fetcher only quotes [${fxCurrencies.join(", ")}]. Wire a fetcher that carries it \u2014 createFxFetcher({ currencies: [..., ${JSON.stringify(this.pricingCurrency)}] }) \u2014 or price in one of the above.`
|
|
67540
67742
|
);
|
|
67541
67743
|
}
|
|
67744
|
+
assertCapabilityRates(descriptor.capabilities);
|
|
67542
67745
|
if (opts.mintHealthTracker) {
|
|
67543
67746
|
this.mintHealthTracker = opts.mintHealthTracker;
|
|
67544
67747
|
this.ownsMintHealthTracker = false;
|
|
@@ -68119,7 +68322,7 @@ var DVMServer = class {
|
|
|
68119
68322
|
const dvmId = this.opts.dvmId ?? `dev:${this.descriptor.name}`;
|
|
68120
68323
|
return {
|
|
68121
68324
|
dvm_id: dvmId,
|
|
68122
|
-
builder_pubkey:
|
|
68325
|
+
builder_pubkey: createHash10("sha256").update(`dvmkit-dev:${dvmId}`).digest("hex")
|
|
68123
68326
|
};
|
|
68124
68327
|
}
|
|
68125
68328
|
throw new AuthAudienceError();
|
|
@@ -68467,7 +68670,7 @@ var DVMServer = class {
|
|
|
68467
68670
|
const paymentAuthorization = ctx.req.header("Authorization");
|
|
68468
68671
|
const mppArtifact = paymentAuthorization ? (await import("./dist-23E7OOCA.js")).Credential.extractPaymentScheme(paymentAuthorization) : void 0;
|
|
68469
68672
|
const attachedPayment = ctx.req.header("X-Cashu") ?? ctx.req.header("PAYMENT-SIGNATURE") ?? ctx.req.header("X-PAYMENT") ?? mppArtifact;
|
|
68470
|
-
const paymentArtifactHash = attachedPayment ?
|
|
68673
|
+
const paymentArtifactHash = attachedPayment ? createHash10("sha256").update(attachedPayment).digest("hex") : void 0;
|
|
68471
68674
|
hostingFundingArtifactHash = paymentArtifactHash;
|
|
68472
68675
|
if (!await control.admit(admissionId, workId, {
|
|
68473
68676
|
creditId,
|
|
@@ -68651,17 +68854,20 @@ var DVMServer = class {
|
|
|
68651
68854
|
entry.input_schema = toJSONSchema(cap.input, { io: "input" });
|
|
68652
68855
|
}
|
|
68653
68856
|
if (cap.example !== void 0) entry.example = cap.example;
|
|
68857
|
+
let pricing;
|
|
68654
68858
|
if (cap.onQuote?.schema) {
|
|
68655
68859
|
const qs = cap.onQuote.schema;
|
|
68656
|
-
|
|
68860
|
+
pricing = {
|
|
68657
68861
|
quote: {
|
|
68658
68862
|
schema: isZodSchema(qs) ? toJSONSchema(qs, { io: "input" }) : qs
|
|
68659
68863
|
}
|
|
68660
68864
|
};
|
|
68661
68865
|
} else {
|
|
68662
68866
|
const max = this.jobManager.currentPricingMax(name);
|
|
68663
|
-
if (max)
|
|
68867
|
+
if (max) pricing = { max };
|
|
68664
68868
|
}
|
|
68869
|
+
if (cap.rates) pricing = { ...pricing, rates: cap.rates };
|
|
68870
|
+
if (pricing) entry.pricing = pricing;
|
|
68665
68871
|
out[name] = entry;
|
|
68666
68872
|
}
|
|
68667
68873
|
return out;
|
|
@@ -69173,7 +69379,7 @@ var DVMServer = class {
|
|
|
69173
69379
|
const authorization = c.req.header("Authorization");
|
|
69174
69380
|
const mppArtifact = authorization ? (await import("./dist-23E7OOCA.js")).Credential.extractPaymentScheme(authorization) : void 0;
|
|
69175
69381
|
const attachedPayment = c.req.header("X-Cashu") ?? c.req.header("PAYMENT-SIGNATURE") ?? c.req.header("X-PAYMENT") ?? mppArtifact;
|
|
69176
|
-
const hostingPaymentArtifactHash = attachedPayment ?
|
|
69382
|
+
const hostingPaymentArtifactHash = attachedPayment ? createHash10("sha256").update(attachedPayment).digest("hex") : void 0;
|
|
69177
69383
|
if (!resumeOnly && this.opts.hostingControlInstance && hostingPaymentArtifactHash) {
|
|
69178
69384
|
const priorId = await this.opts.hostingControlInstance.acceptedJobByPaymentArtifactHash(
|
|
69179
69385
|
hostingPaymentArtifactHash
|
|
@@ -69471,7 +69677,7 @@ var DVMServer = class {
|
|
|
69471
69677
|
}
|
|
69472
69678
|
const isAnonymous = requesterId === "anonymous" || requesterId === "dev-anonymous";
|
|
69473
69679
|
const jobToken = isAnonymous ? randomBytes52(32).toString("hex") : void 0;
|
|
69474
|
-
const requesterTokenHash = jobToken ?
|
|
69680
|
+
const requesterTokenHash = jobToken ? createHash10("sha256").update(jobToken).digest("hex") : void 0;
|
|
69475
69681
|
const job = jm.createJob(
|
|
69476
69682
|
normalisedBody,
|
|
69477
69683
|
requesterId,
|
|
@@ -70183,7 +70389,7 @@ function isJobOwner(c, job) {
|
|
|
70183
70389
|
if (job.requesterTokenHash) {
|
|
70184
70390
|
const token = c.req.header("X-Job-Token");
|
|
70185
70391
|
if (!token) return false;
|
|
70186
|
-
const provided =
|
|
70392
|
+
const provided = createHash10("sha256").update(token).digest("hex");
|
|
70187
70393
|
return timingSafeEqualHex(provided, job.requesterTokenHash);
|
|
70188
70394
|
}
|
|
70189
70395
|
return c.get("requesterId") === job.requesterId;
|
|
@@ -70201,7 +70407,7 @@ function buildSubmitResponse(c, job, jobToken, contentFields) {
|
|
|
70201
70407
|
else if (job.status === "completed") res.status = "completed";
|
|
70202
70408
|
Object.assign(res, terminalResponseFields(job), contentFields);
|
|
70203
70409
|
removeUnavailableContent(res);
|
|
70204
|
-
return c.json(res, job.status === "completed" ? 200 : 202);
|
|
70410
|
+
return c.json(res, job.status === "completed" ? 200 : 202, jobIdentityHeaders(job.id));
|
|
70205
70411
|
}
|
|
70206
70412
|
function requestRecoveryStore(store) {
|
|
70207
70413
|
return store.findJobByRequestId && store.claimRequestId && store.resumeRequestId && store.releaseRequestIdClaim ? store : void 0;
|
|
@@ -70267,7 +70473,10 @@ function buildRequestResultResponse(c, requestId, job, contentFields) {
|
|
|
70267
70473
|
if (job.paymentTransactionHash) res.transaction_hash = job.paymentTransactionHash;
|
|
70268
70474
|
Object.assign(res, terminalResponseFields(job), contentFields);
|
|
70269
70475
|
removeUnavailableContent(res);
|
|
70270
|
-
return c.json(res, isTerminal(job.status) ? 200 : 202);
|
|
70476
|
+
return c.json(res, isTerminal(job.status) ? 200 : 202, jobIdentityHeaders(job.id));
|
|
70477
|
+
}
|
|
70478
|
+
function jobIdentityHeaders(jobId) {
|
|
70479
|
+
return isJobIdentityValue(jobId) ? { [JOB_IDENTITY_HEADER]: jobId } : {};
|
|
70271
70480
|
}
|
|
70272
70481
|
function requestResultNotFound(c, requestId) {
|
|
70273
70482
|
return c.json(
|
|
@@ -70458,6 +70667,55 @@ function validateMessageContent(type, content, devMode) {
|
|
|
70458
70667
|
}
|
|
70459
70668
|
return null;
|
|
70460
70669
|
}
|
|
70670
|
+
var MAX_RATES = 5;
|
|
70671
|
+
var MAX_RATE_AMOUNT_LENGTH = 12;
|
|
70672
|
+
var MAX_RATE_TEXT_LENGTH = 24;
|
|
70673
|
+
var RATE_AMOUNT_RE = /^\d+(\.\d+)?$/;
|
|
70674
|
+
var RATE_KEYS = /* @__PURE__ */ new Set(["label", "amount", "currency", "per"]);
|
|
70675
|
+
function assertCapabilityRates(capabilities) {
|
|
70676
|
+
for (const [name, cap] of Object.entries(capabilities)) {
|
|
70677
|
+
if (cap.rates === void 0) continue;
|
|
70678
|
+
const refuse = (detail) => {
|
|
70679
|
+
throw new Error(`createDVMServer: capability ${JSON.stringify(name)}: ${detail}`);
|
|
70680
|
+
};
|
|
70681
|
+
const rates = cap.rates;
|
|
70682
|
+
if (!Array.isArray(rates) || rates.length === 0 || rates.length > MAX_RATES) {
|
|
70683
|
+
refuse(`rates must be an array of 1 to ${MAX_RATES} entries`);
|
|
70684
|
+
}
|
|
70685
|
+
if (cap.price === void 0 && cap.onQuote === void 0) {
|
|
70686
|
+
refuse("rates is declared on a free capability; set `price` or `onQuote`, or remove `rates`");
|
|
70687
|
+
}
|
|
70688
|
+
rates.forEach((rate, i3) => {
|
|
70689
|
+
const at = `rates[${i3}]`;
|
|
70690
|
+
if (typeof rate !== "object" || rate === null || Array.isArray(rate)) {
|
|
70691
|
+
refuse(`${at} must be an object with amount, currency and per`);
|
|
70692
|
+
}
|
|
70693
|
+
const entry = rate;
|
|
70694
|
+
for (const key of Object.keys(entry)) {
|
|
70695
|
+
if (!RATE_KEYS.has(key)) refuse(`${at}.${key} is not a rate field (label, amount, currency, per)`);
|
|
70696
|
+
}
|
|
70697
|
+
const amount = entry.amount;
|
|
70698
|
+
if (typeof amount !== "string" || amount.length > MAX_RATE_AMOUNT_LENGTH || !RATE_AMOUNT_RE.test(amount) || // Above zero without parsing to a float: some digit is non-zero.
|
|
70699
|
+
!/[1-9]/.test(amount)) {
|
|
70700
|
+
refuse(
|
|
70701
|
+
`${at}.amount must be a decimal dollar string above zero of at most ${MAX_RATE_AMOUNT_LENGTH} characters, like "0.00015" (got ${JSON.stringify(amount)})`
|
|
70702
|
+
);
|
|
70703
|
+
}
|
|
70704
|
+
if (entry.currency !== "USD") {
|
|
70705
|
+
refuse(`${at}.currency must be "USD" (got ${JSON.stringify(entry.currency)})`);
|
|
70706
|
+
}
|
|
70707
|
+
assertRateText(entry.per, `${at}.per`, refuse);
|
|
70708
|
+
if (entry.label !== void 0) assertRateText(entry.label, `${at}.label`, refuse);
|
|
70709
|
+
});
|
|
70710
|
+
}
|
|
70711
|
+
}
|
|
70712
|
+
function assertRateText(value, field, refuse) {
|
|
70713
|
+
if (typeof value !== "string" || value.length === 0 || value.length > MAX_RATE_TEXT_LENGTH || value.trim() !== value) {
|
|
70714
|
+
refuse(
|
|
70715
|
+
`${field} must be a string of 1 to ${MAX_RATE_TEXT_LENGTH} characters with no leading or trailing whitespace (got ${JSON.stringify(value)})`
|
|
70716
|
+
);
|
|
70717
|
+
}
|
|
70718
|
+
}
|
|
70461
70719
|
var TEMPO_OBSERVER_HEALTH_REFRESH_TTL_MS = 60 * 1e3;
|
|
70462
70720
|
var TEMPO_OBSERVER_HEALTH_MAX_CURSOR_AGE_MS = 2 * 60 * 1e3;
|
|
70463
70721
|
var TEMPO_OBSERVER_HEALTH_MAX_STALENESS_MS = 5 * 60 * 1e3;
|
|
@@ -70568,6 +70826,7 @@ export {
|
|
|
70568
70826
|
WALLET_VERSION,
|
|
70569
70827
|
RECENT_SPENDS_CAP,
|
|
70570
70828
|
DEFAULT_AGENT_MINT_URL,
|
|
70829
|
+
isStorableJobId,
|
|
70571
70830
|
loadWalletConfiguredMints,
|
|
70572
70831
|
loadAgentWallet,
|
|
70573
70832
|
saveAgentWallet,
|
|
@@ -70593,6 +70852,9 @@ export {
|
|
|
70593
70852
|
ADMIN_STATE_UNAVAILABLE,
|
|
70594
70853
|
buildAdminChallenge,
|
|
70595
70854
|
buildAdminAuthHeader,
|
|
70855
|
+
JOB_IDENTITY_HEADER,
|
|
70856
|
+
isJobIdentityValue,
|
|
70857
|
+
parseJobIdentityHeader,
|
|
70596
70858
|
generateIdentity,
|
|
70597
70859
|
loadIdentitySecret,
|
|
70598
70860
|
writeIdentity,
|