@dvmkit/sdk 0.7.0-rc.1 → 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/README.md +4 -0
- package/dist/{chunk-S3OY533W.js → chunk-26W6GPCD.js} +48 -6
- package/dist/{chunk-FWGWLPXF.js → chunk-2OM2QPBE.js} +2 -2
- package/dist/{chunk-GY66THYI.js → chunk-3UK3CDOT.js} +186 -90
- package/dist/{chunk-CXCQLOOK.js → chunk-62FI3NJF.js} +42 -107
- package/dist/{chunk-VHNPVGSA.js → chunk-6STC5TCP.js} +3 -3
- package/dist/{chunk-N5RZ5HVB.js → chunk-72V5DTEC.js} +2 -2
- package/dist/chunk-A262WVYX.js +6 -0
- package/dist/{chunk-QR2EF2NI.js → chunk-AQ7OX5NX.js} +2 -2
- package/dist/{chunk-BYCEKO65.js → chunk-CLIAFTUR.js} +102 -13
- package/dist/{chunk-GAOAYHZA.js → chunk-DNG4KGSC.js} +3 -3
- package/dist/{chunk-Z4ZT5LNT.js → chunk-GSLS4464.js} +3 -3
- package/dist/{chunk-RA2WIX7G.js → chunk-H5FVVEEN.js} +18 -7
- package/dist/{chunk-IXR5RFK7.js → chunk-HCE4MPZ5.js} +1 -1
- package/dist/{chunk-OML32F6I.js → chunk-I555L2WK.js} +1 -1
- package/dist/{chunk-EQLA4FFY.js → chunk-IIZQNDQU.js} +3 -3
- package/dist/{chunk-FUJ36YDV.js → chunk-KXWROQGK.js} +24 -1
- package/dist/{chunk-ETXDTUJO.js → chunk-LAKP6FUI.js} +55 -0
- package/dist/{chunk-X7EZ5CLI.js → chunk-MON76YBJ.js} +3 -3
- package/dist/chunk-OFSOLHRX.js +120 -0
- package/dist/{chunk-IV6Q7NRW.js → chunk-RAGX6VG7.js} +2 -2
- package/dist/{chunk-KA6VN5FK.js → chunk-RXPHMS4C.js} +3 -3
- package/dist/{chunk-6XF3RVVX.js → chunk-SPYEJXI7.js} +5 -5
- package/dist/{chunk-P6QON7ER.js → chunk-TRNMTTPX.js} +1 -1
- package/dist/{chunk-RCM3P2HE.js → chunk-UKD3R2KU.js} +55 -4
- package/dist/chunk-USL7ZEXN.js +17 -0
- package/dist/{chunk-KMED3H3A.js → chunk-VB5OLOZH.js} +395 -231
- package/dist/{content-retention-DHyLdA6b.d.ts → content-retention-ChFSSVO0.d.ts} +1 -1
- package/dist/{credit-ledger-MCUXYKSJ.js → credit-ledger-7Z7LOCTN.js} +4 -4
- package/dist/{credit-menu-DjnkeEUU.d.ts → credit-menu-fy0DDigm.d.ts} +6 -6
- package/dist/{fx-zMWFzfrU.d.ts → fx-DM0_NYiE.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +236 -16
- package/dist/internal/caller.d.ts +4968 -8286
- package/dist/internal/caller.js +4291 -8084
- package/dist/internal/index.js +1 -1
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +27 -30
- package/dist/{job-store-DdLXBpol.d.ts → job-store-DkfNE9sv.d.ts} +1 -1
- package/dist/{lightning-backend-Bw-qtAbt.d.ts → lightning-backend-C3Gf1XpP.d.ts} +2 -2
- package/dist/{memory-credit-ledger-SBSMGMDX.js → memory-credit-ledger-3WOS74UH.js} +5 -5
- package/dist/{mpp-setup-RF5FXGGV.js → mpp-setup-XB4KATMU.js} +2 -2
- package/dist/{payout-reporter-3Y2U55ZX.js → payout-reporter-WT7XYW42.js} +2 -2
- package/dist/{postgres-consumed-credential-store-BUVCAPLS.js → postgres-consumed-credential-store-W7UP33AH.js} +3 -3
- package/dist/{postgres-job-store-VHLQBJZC.js → postgres-job-store-3KGUGFRD.js} +2 -2
- package/dist/{postgres-replay-store-ARZSQ45X.js → postgres-replay-store-CVNJJOQG.js} +2 -2
- package/dist/{pricing-XT2IAPNE.js → pricing-QAVZUTZR.js} +12 -12
- package/dist/{revenue-reporter-MAERPYGK.js → revenue-reporter-7UR3W2SD.js} +2 -2
- package/dist/server/index.d.ts +10 -10
- package/dist/server/index.js +44 -48
- package/dist/{step-cache-2MkvenJn.d.ts → step-cache-DDTwd4SK.d.ts} +6 -2
- package/dist/{tempo-charge-store-Q3D7KYMH.js → tempo-charge-store-GA6CED6O.js} +2 -2
- package/dist/{tempo-session-store-ZRNCOX7P.js → tempo-session-store-WZWQRITB.js} +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +6 -7
- package/dist/{usd-DI3d3gTK.d.ts → usd-DkRy9nfU.d.ts} +1 -1
- package/dist/{x402-FT4S4JS4.js → x402-ZU4GML7Z.js} +8 -27
- package/package.json +1 -1
- package/dist/chunk-66HGCPBU.js +0 -25
- package/dist/chunk-AT6V3SY7.js +0 -102
- package/dist/chunk-EZXAJ6EI.js +0 -1082
- package/dist/chunk-HCLVYZUZ.js +0 -244
- package/dist/chunk-JEVLNAO3.js +0 -1668
- package/dist/chunk-NFMOPYBA.js +0 -357
- package/dist/chunk-O2OTZ5GP.js +0 -1869
- package/dist/chunk-OFVV37XC.js +0 -57
- package/dist/chunk-SZVXOQ75.js +0 -211
- package/dist/chunk-WBOKPC37.js +0 -795
- package/dist/tempo-lifecycle-GJ77YKVY.js +0 -15
- package/dist/tempo-wallet-X2GGAZ6X.js +0 -40
|
@@ -204,90 +204,45 @@ function isOptionalRecord(value) {
|
|
|
204
204
|
return value === void 0 || value === null || isRecord(value);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
// src/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
var X402_CHANNELS_FILE = join(CONFIG_DIR, "x402-channels.json");
|
|
222
|
-
var TEMPO_CHANNELS_FILE = join(CONFIG_DIR, "tempo-channels.json");
|
|
223
|
-
var FEEDBACK_NUDGES_FILE = join(CONFIG_DIR, "feedback-nudges.json");
|
|
224
|
-
var RECOVERY_MNEMONIC_FILE = join(CONFIG_DIR, "recovery.mnemonic");
|
|
225
|
-
var WALLET_FILE = join(CONFIG_DIR, "wallet.json");
|
|
226
|
-
var AGENT_MNEMONIC_FILE = join(CONFIG_DIR, "wallet.mnemonic");
|
|
227
|
-
var IDENTITIES_FILE = join(CONFIG_DIR, "identities.json");
|
|
228
|
-
var PAIRINGS_DIR = join(CONFIG_DIR, "pairings");
|
|
229
|
-
var BUDGET_FILE = join(CONFIG_DIR, "budget.json");
|
|
230
|
-
var BTC_RATE_FILE = join(CONFIG_DIR, "btc-rate.json");
|
|
231
|
-
var ADMIN_DIR = join(CONFIG_DIR, "admin");
|
|
232
|
-
var PROXY_STATE_FILE = join(ADMIN_DIR, "proxy.json");
|
|
233
|
-
var BUILDER_CONFIG_DIR = process.env.DVMKIT_CONFIG_DIR ?? join(homedir(), ".dvmkit");
|
|
234
|
-
var BUILDER_FILE = join(BUILDER_CONFIG_DIR, "builder.json");
|
|
235
|
-
var BUILDER_MNEMONIC_FILE = join(BUILDER_CONFIG_DIR, "recovery.mnemonic");
|
|
236
|
-
var BUILDER_KEY_FILE = join(BUILDER_CONFIG_DIR, "builder.key");
|
|
237
|
-
var MELT_PENDING_LOG_FILE = join(BUILDER_CONFIG_DIR, "melt-pending.log");
|
|
238
|
-
var DRAIN_PARK_LOG_FILE = join(BUILDER_CONFIG_DIR, "drain-park.log");
|
|
239
|
-
var DRAIN_HOLD_STATE_FILE = join(BUILDER_CONFIG_DIR, "drain-hold.json");
|
|
240
|
-
var MELT_SUCCESS_FILE = join(BUILDER_CONFIG_DIR, "melt-success.json");
|
|
241
|
-
|
|
242
|
-
// src/lib/config-dir.ts
|
|
243
|
-
import { chmodSync, mkdirSync, statSync } from "fs";
|
|
244
|
-
var CONFIG_DIR_MODE = 448;
|
|
245
|
-
function ensureConfigDir() {
|
|
246
|
-
ensureConfigSubdir(CONFIG_DIR);
|
|
247
|
-
}
|
|
248
|
-
function ensureConfigSubdir(path) {
|
|
249
|
-
mkdirSync(path, { recursive: true, mode: CONFIG_DIR_MODE });
|
|
250
|
-
}
|
|
251
|
-
function repairConfigDirMode() {
|
|
252
|
-
const base = {
|
|
253
|
-
path: CONFIG_DIR,
|
|
254
|
-
exists: false,
|
|
255
|
-
modeOctal: null,
|
|
256
|
-
repaired: false,
|
|
257
|
-
skippedNonPosix: process.platform === "win32"
|
|
258
|
-
};
|
|
259
|
-
if (base.skippedNonPosix) return base;
|
|
260
|
-
let mode;
|
|
261
|
-
try {
|
|
262
|
-
mode = statSync(CONFIG_DIR).mode & 511;
|
|
263
|
-
} catch (err) {
|
|
264
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
265
|
-
const missing = err.code === "ENOENT";
|
|
266
|
-
return missing ? base : { ...base, error: message };
|
|
207
|
+
// src/lib/payment-amounts.ts
|
|
208
|
+
function msatsToUsd(msats, rate) {
|
|
209
|
+
return msats / 1e11 * rate;
|
|
210
|
+
}
|
|
211
|
+
function usdToMsats(usd, rate) {
|
|
212
|
+
return Math.round(usd / rate * 1e11);
|
|
213
|
+
}
|
|
214
|
+
function msatsToUsdCents(msats, btcPriceUsd) {
|
|
215
|
+
const usd = msatsToUsd(msats, btcPriceUsd);
|
|
216
|
+
return Math.round(usd * 100);
|
|
217
|
+
}
|
|
218
|
+
function msatsToUsdc(msats, btcUsdRate) {
|
|
219
|
+
if (!Number.isSafeInteger(msats) || msats < 0) {
|
|
220
|
+
throw new RangeError("msats must be a non-negative safe integer");
|
|
267
221
|
}
|
|
268
|
-
if ((
|
|
269
|
-
|
|
222
|
+
if (!Number.isFinite(btcUsdRate) || btcUsdRate <= 0) {
|
|
223
|
+
throw new RangeError("BTC/USD rate must be finite and positive");
|
|
270
224
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
225
|
+
const [mantissa, exponent = "0"] = btcUsdRate.toString().split("e");
|
|
226
|
+
const decimalPlaces = mantissa.split(".")[1]?.length ?? 0;
|
|
227
|
+
const shift = Number(exponent) - decimalPlaces;
|
|
228
|
+
let numerator = BigInt(msats) * BigInt(mantissa.replace(".", ""));
|
|
229
|
+
let denominator = 100000n;
|
|
230
|
+
if (shift > 0) numerator *= 10n ** BigInt(shift);
|
|
231
|
+
else if (shift < 0) denominator *= 10n ** BigInt(-shift);
|
|
232
|
+
const micro = (numerator + denominator - 1n) / denominator;
|
|
233
|
+
if (micro > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
234
|
+
throw new RangeError("USDC micro-unit amount exceeds the safe integer range");
|
|
280
235
|
}
|
|
281
|
-
return
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
236
|
+
return Number(micro);
|
|
237
|
+
}
|
|
238
|
+
function usdcToMsats(usdc, btcUsdRate) {
|
|
239
|
+
return usdToMsats(usdc, btcUsdRate);
|
|
240
|
+
}
|
|
241
|
+
function msatsToMicro(msats, btcRate) {
|
|
242
|
+
return Math.round(msatsToUsd(msats, btcRate) * 1e6);
|
|
288
243
|
}
|
|
289
|
-
function
|
|
290
|
-
return
|
|
244
|
+
function microToSats(micro, btcRate) {
|
|
245
|
+
return Math.ceil(usdToMsats(micro / 1e6, btcRate) / 1e3);
|
|
291
246
|
}
|
|
292
247
|
|
|
293
248
|
// src/lib/payment-rails/rpc.ts
|
|
@@ -339,33 +294,13 @@ export {
|
|
|
339
294
|
decodePaymentRequiredHeader,
|
|
340
295
|
exactEvmAuthorization,
|
|
341
296
|
encodeSettleResponseHeader,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
FAVORITES_FILE,
|
|
350
|
-
MESSAGES_DIR,
|
|
351
|
-
RECEIPTS_FILE,
|
|
352
|
-
CREDITS_FILE,
|
|
353
|
-
X402_CHANNELS_FILE,
|
|
354
|
-
TEMPO_CHANNELS_FILE,
|
|
355
|
-
FEEDBACK_NUDGES_FILE,
|
|
356
|
-
RECOVERY_MNEMONIC_FILE,
|
|
357
|
-
WALLET_FILE,
|
|
358
|
-
AGENT_MNEMONIC_FILE,
|
|
359
|
-
IDENTITIES_FILE,
|
|
360
|
-
PAIRINGS_DIR,
|
|
361
|
-
BUDGET_FILE,
|
|
362
|
-
BTC_RATE_FILE,
|
|
363
|
-
BUILDER_CONFIG_DIR,
|
|
364
|
-
BUILDER_FILE,
|
|
365
|
-
BUILDER_KEY_FILE,
|
|
366
|
-
ensureConfigDir,
|
|
367
|
-
ensureConfigSubdir,
|
|
368
|
-
repairConfigDirMode,
|
|
297
|
+
msatsToUsd,
|
|
298
|
+
usdToMsats,
|
|
299
|
+
msatsToUsdCents,
|
|
300
|
+
msatsToUsdc,
|
|
301
|
+
usdcToMsats,
|
|
302
|
+
msatsToMicro,
|
|
303
|
+
microToSats,
|
|
369
304
|
resolveRpcOverride,
|
|
370
305
|
resolveRpcHttpTransportOptions
|
|
371
306
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticConsole
|
|
3
|
+
} from "./chunk-LAKP6FUI.js";
|
|
1
4
|
import {
|
|
2
5
|
withSdkInitLock
|
|
3
6
|
} from "./chunk-COYKJRMM.js";
|
|
4
|
-
import {
|
|
5
|
-
diagnosticConsole
|
|
6
|
-
} from "./chunk-ETXDTUJO.js";
|
|
7
7
|
|
|
8
8
|
// src/sdk/server/postgres-replay-store.ts
|
|
9
9
|
var DEFAULT_TABLE_NAME = "signed_request_replays";
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
signedRequestHeaderMatchesDomain,
|
|
5
5
|
signedRequestStatementHeader,
|
|
6
6
|
testOnlySignedRequestDomain
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-UKD3R2KU.js";
|
|
8
8
|
import {
|
|
9
9
|
diagnosticConsole
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-LAKP6FUI.js";
|
|
11
11
|
|
|
12
12
|
// src/sdk/server/zod-error.ts
|
|
13
13
|
function humanizeZodError(err, opts) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
initCallerLoggers
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXWROQGK.js";
|
|
4
4
|
import {
|
|
5
5
|
bindDiagnosticCapabilityAuthority,
|
|
6
6
|
bindDiagnosticIdentityAuthority,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
extendDiagnosticIdentityAuthority,
|
|
9
9
|
projectDiagnosticFields,
|
|
10
10
|
projectSpanRow
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-LAKP6FUI.js";
|
|
12
12
|
|
|
13
13
|
// src/sdk/logger.ts
|
|
14
14
|
function createConsoleLogger(_jobId) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
diagnosticConsole
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LAKP6FUI.js";
|
|
4
4
|
|
|
5
5
|
// src/sdk/pricing/currency.ts
|
|
6
6
|
var InvalidCurrencyError = class extends Error {
|
|
@@ -35,6 +35,98 @@ function validateCurrency(raw) {
|
|
|
35
35
|
return raw;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// src/sdk/pricing/usd.ts
|
|
39
|
+
var InvalidFxRateError = class extends Error {
|
|
40
|
+
code = "invalid_fx_rate";
|
|
41
|
+
ratePerBtc;
|
|
42
|
+
constructor(ratePerBtc) {
|
|
43
|
+
super(
|
|
44
|
+
`invalid fx rate ${String(ratePerBtc)} \u2014 expected a finite positive number of fiat per BTC`
|
|
45
|
+
);
|
|
46
|
+
this.ratePerBtc = ratePerBtc;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function fiatToSatsCeil(amount, ratePerBtc) {
|
|
50
|
+
if (!Number.isFinite(ratePerBtc) || ratePerBtc <= 0) {
|
|
51
|
+
throw new InvalidFxRateError(ratePerBtc);
|
|
52
|
+
}
|
|
53
|
+
if (!Number.isFinite(amount) || amount < 0) return 0;
|
|
54
|
+
return Math.ceil(amount * 1e8 / ratePerBtc);
|
|
55
|
+
}
|
|
56
|
+
function satsToFiat(sats, ratePerBtc) {
|
|
57
|
+
if (!Number.isFinite(ratePerBtc) || ratePerBtc <= 0) {
|
|
58
|
+
throw new InvalidFxRateError(ratePerBtc);
|
|
59
|
+
}
|
|
60
|
+
return sats / 1e8 * ratePerBtc;
|
|
61
|
+
}
|
|
62
|
+
var InvalidUsdPriceError = class extends Error {
|
|
63
|
+
constructor(field, value, detail) {
|
|
64
|
+
super(`${field}: ${detail}`);
|
|
65
|
+
this.field = field;
|
|
66
|
+
this.value = value;
|
|
67
|
+
this.name = "InvalidUsdPriceError";
|
|
68
|
+
}
|
|
69
|
+
field;
|
|
70
|
+
value;
|
|
71
|
+
code = "invalid_usd_price";
|
|
72
|
+
};
|
|
73
|
+
function parseUsdPrice(value, field) {
|
|
74
|
+
if (!USD_PRICE_RE.test(value)) {
|
|
75
|
+
throw new InvalidUsdPriceError(
|
|
76
|
+
field,
|
|
77
|
+
value,
|
|
78
|
+
`${JSON.stringify(value)} is not a USD price literal. Use a "$X.XX" string, e.g. "$0.05".`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const usd = parseFloat(value.slice(1));
|
|
82
|
+
if (!Number.isFinite(usd) || usd < MIN_USD_PRICE) {
|
|
83
|
+
throw new InvalidUsdPriceError(
|
|
84
|
+
field,
|
|
85
|
+
value,
|
|
86
|
+
`${JSON.stringify(value)} is below ${MIN_USD_PRICE_LITERAL}, the smallest price the wire can carry \u2014 every price surface rounds to four decimals, so this would advertise as $0 and then charge anyway. Charge at least ${MIN_USD_PRICE_LITERAL}, or omit the price for a free capability.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (roundUsd(usd) !== usd) {
|
|
90
|
+
throw new InvalidUsdPriceError(
|
|
91
|
+
field,
|
|
92
|
+
value,
|
|
93
|
+
`${JSON.stringify(value)} carries more than four decimal places. Every price surface rounds to four, so this would advertise ${formatUsd(roundUsd(usd))} and charge something else. Use at most four decimals.`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
if (!Number.isSafeInteger(Math.round(usd * 1e6))) {
|
|
97
|
+
throw new InvalidUsdPriceError(
|
|
98
|
+
field,
|
|
99
|
+
value,
|
|
100
|
+
`${JSON.stringify(value)} is too large to denominate. Use an amount under $9,007,199,254.`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return usd;
|
|
104
|
+
}
|
|
105
|
+
function roundUsd(usd) {
|
|
106
|
+
return Math.round(usd * 1e4) / 1e4;
|
|
107
|
+
}
|
|
108
|
+
function formatUsd(usd) {
|
|
109
|
+
if (usd === 0) return "$0.00";
|
|
110
|
+
if (usd >= 0.01) return `$${usd.toFixed(2)}`;
|
|
111
|
+
return `$${usd.toFixed(4)}`;
|
|
112
|
+
}
|
|
113
|
+
function formatFiat(amount, currency) {
|
|
114
|
+
const code = currency.toUpperCase();
|
|
115
|
+
const symbol = FIAT_SYMBOLS[currency] ?? "";
|
|
116
|
+
const digits = currency === "jpy" ? 0 : amount >= 0.01 || amount === 0 ? 2 : 4;
|
|
117
|
+
const body = `${amount.toFixed(digits)} ${code}`;
|
|
118
|
+
return symbol ? `${symbol}${body}` : body;
|
|
119
|
+
}
|
|
120
|
+
var USD_PRICE_RE = /^\$\d+(\.\d+)?$/;
|
|
121
|
+
var MIN_USD_PRICE = 1e-4;
|
|
122
|
+
var MIN_USD_PRICE_LITERAL = '"$0.0001"';
|
|
123
|
+
var FIAT_SYMBOLS = {
|
|
124
|
+
usd: "$",
|
|
125
|
+
eur: "\u20AC",
|
|
126
|
+
gbp: "\xA3",
|
|
127
|
+
jpy: "\xA5"
|
|
128
|
+
};
|
|
129
|
+
|
|
38
130
|
// src/sdk/pricing/fx.ts
|
|
39
131
|
var DEFAULT_FX_CURRENCIES = ["usd", "eur", "gbp", "jpy"];
|
|
40
132
|
var DEFAULT_FX_RATE_SOURCE = `https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=${DEFAULT_FX_CURRENCIES.join(",")}`;
|
|
@@ -268,20 +360,18 @@ function resolveFxSourceFromEnv(env) {
|
|
|
268
360
|
return raw;
|
|
269
361
|
}
|
|
270
362
|
|
|
271
|
-
// src/sdk/pricing/upfront.ts
|
|
272
|
-
function buildUpfront(input) {
|
|
273
|
-
const currency = validateCurrency(input.currency);
|
|
274
|
-
const amount = input.amount;
|
|
275
|
-
if (!Number.isFinite(amount) || amount < 0) {
|
|
276
|
-
throw new Error(`invalid upfront amount: ${String(amount)} (must be a non-negative number)`);
|
|
277
|
-
}
|
|
278
|
-
return { amount, currency };
|
|
279
|
-
}
|
|
280
|
-
|
|
281
363
|
export {
|
|
282
364
|
InvalidCurrencyError,
|
|
283
365
|
UnsupportedCurrencyError,
|
|
284
366
|
validateCurrency,
|
|
367
|
+
InvalidFxRateError,
|
|
368
|
+
fiatToSatsCeil,
|
|
369
|
+
satsToFiat,
|
|
370
|
+
InvalidUsdPriceError,
|
|
371
|
+
parseUsdPrice,
|
|
372
|
+
roundUsd,
|
|
373
|
+
formatUsd,
|
|
374
|
+
formatFiat,
|
|
285
375
|
DEFAULT_FX_CURRENCIES,
|
|
286
376
|
DEFAULT_FX_RATE_SOURCE,
|
|
287
377
|
FX_CACHE_TTL_MS,
|
|
@@ -290,6 +380,5 @@ export {
|
|
|
290
380
|
createFxFetcher,
|
|
291
381
|
warmFxSnapshot,
|
|
292
382
|
fxRateFor,
|
|
293
|
-
resolveFxSourceFromEnv
|
|
294
|
-
buildUpfront
|
|
383
|
+
resolveFxSourceFromEnv
|
|
295
384
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticConsole
|
|
3
|
+
} from "./chunk-LAKP6FUI.js";
|
|
1
4
|
import {
|
|
2
5
|
withSdkInitLock
|
|
3
6
|
} from "./chunk-COYKJRMM.js";
|
|
4
|
-
import {
|
|
5
|
-
diagnosticConsole
|
|
6
|
-
} from "./chunk-ETXDTUJO.js";
|
|
7
7
|
|
|
8
8
|
// src/sdk/server/payout-reporter.ts
|
|
9
9
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticConsole
|
|
3
|
+
} from "./chunk-LAKP6FUI.js";
|
|
1
4
|
import {
|
|
2
5
|
withSdkInitLock
|
|
3
6
|
} from "./chunk-COYKJRMM.js";
|
|
4
|
-
import {
|
|
5
|
-
diagnosticConsole
|
|
6
|
-
} from "./chunk-ETXDTUJO.js";
|
|
7
7
|
|
|
8
8
|
// src/sdk/server/revenue-reporter.ts
|
|
9
9
|
import { randomUUID } from "crypto";
|
|
@@ -2,19 +2,20 @@ import {
|
|
|
2
2
|
createX402FacilitatorAuthHeaders,
|
|
3
3
|
settleWithFacilitator,
|
|
4
4
|
verifyWithFacilitator
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import {
|
|
7
|
-
usdcToMsats
|
|
8
|
-
} from "./chunk-NFMOPYBA.js";
|
|
5
|
+
} from "./chunk-26W6GPCD.js";
|
|
9
6
|
import {
|
|
10
7
|
buildPaymentRequirements,
|
|
11
8
|
decodePayment,
|
|
12
9
|
encodeSettleResponseHeader,
|
|
13
|
-
exactEvmAuthorization
|
|
14
|
-
|
|
10
|
+
exactEvmAuthorization,
|
|
11
|
+
usdcToMsats
|
|
12
|
+
} from "./chunk-62FI3NJF.js";
|
|
15
13
|
import {
|
|
16
14
|
callerLoggers
|
|
17
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KXWROQGK.js";
|
|
16
|
+
import {
|
|
17
|
+
diagnosticConsole
|
|
18
|
+
} from "./chunk-LAKP6FUI.js";
|
|
18
19
|
|
|
19
20
|
// src/lib/x402/verify.ts
|
|
20
21
|
async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resource, btcUsdRate, exactVersions = { v1: true, v2: true }) {
|
|
@@ -30,9 +31,11 @@ async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resou
|
|
|
30
31
|
try {
|
|
31
32
|
payload = decodePayment(paymentHeader);
|
|
32
33
|
} catch {
|
|
34
|
+
logRejected("malformed_credential", "verifier");
|
|
33
35
|
return { verified: false, amountMsats: 0, invalidReason: "decode_failed" };
|
|
34
36
|
}
|
|
35
37
|
if (payload.x402Version === 1 && !exactVersions.v1 || payload.x402Version === 2 && !exactVersions.v2) {
|
|
38
|
+
logRejected("unsupported_version", "verifier");
|
|
36
39
|
return { verified: false, amountMsats: 0, invalidReason: "unsupported_version" };
|
|
37
40
|
}
|
|
38
41
|
const requirementOpts = { x402Config: config, requiredUsdcMicro, resource };
|
|
@@ -81,6 +84,14 @@ async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resou
|
|
|
81
84
|
}
|
|
82
85
|
);
|
|
83
86
|
}
|
|
87
|
+
function logRejected(category, stage) {
|
|
88
|
+
diagnosticConsole.warn({
|
|
89
|
+
event: "x402_credential_rejected",
|
|
90
|
+
rail: "x402",
|
|
91
|
+
failure_category: category,
|
|
92
|
+
failure_stage: stage
|
|
93
|
+
});
|
|
94
|
+
}
|
|
84
95
|
|
|
85
96
|
export {
|
|
86
97
|
verifyX402Payment
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
ContentHoldError,
|
|
3
3
|
applyContentHoldMutation
|
|
4
4
|
} from "./chunk-AFV77S4C.js";
|
|
5
|
+
import {
|
|
6
|
+
diagnosticConsole
|
|
7
|
+
} from "./chunk-LAKP6FUI.js";
|
|
5
8
|
import {
|
|
6
9
|
withSdkInitLock
|
|
7
10
|
} from "./chunk-COYKJRMM.js";
|
|
8
|
-
import {
|
|
9
|
-
diagnosticConsole
|
|
10
|
-
} from "./chunk-ETXDTUJO.js";
|
|
11
11
|
|
|
12
12
|
// src/sdk/server/postgres-job-store.ts
|
|
13
13
|
import { createHash } from "crypto";
|
|
@@ -45,7 +45,30 @@ function isOpaqueToken(segment) {
|
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// src/lib/caller-loggers.ts
|
|
49
|
+
var callerLoggers = buildNoopLoggers();
|
|
50
|
+
function initCallerLoggers(nextLoggers) {
|
|
51
|
+
callerLoggers = nextLoggers;
|
|
52
|
+
}
|
|
53
|
+
function buildNoopLoggers() {
|
|
54
|
+
const noopLogger = {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function -- standalone caller has no exporter
|
|
56
|
+
info() {
|
|
57
|
+
},
|
|
58
|
+
async span(_name, _attrs, fn) {
|
|
59
|
+
return fn();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
cashu: noopLogger,
|
|
64
|
+
lightning: noopLogger,
|
|
65
|
+
x402: noopLogger
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
48
69
|
export {
|
|
49
70
|
redactUrl,
|
|
50
|
-
redactUrlsInText
|
|
71
|
+
redactUrlsInText,
|
|
72
|
+
callerLoggers,
|
|
73
|
+
initCallerLoggers
|
|
51
74
|
};
|
|
@@ -998,11 +998,63 @@ var diagnostic_catalogue_v1_default = {
|
|
|
998
998
|
],
|
|
999
999
|
clientVersionFields: [
|
|
1000
1000
|
"client.version"
|
|
1001
|
+
],
|
|
1002
|
+
paymentSkipReasons: [
|
|
1003
|
+
"credit_or_draw_missing",
|
|
1004
|
+
"draw_not_pending",
|
|
1005
|
+
"draw_job_mismatch",
|
|
1006
|
+
"rail_mismatch",
|
|
1007
|
+
"channel_binding_mismatch",
|
|
1008
|
+
"denomination_unavailable",
|
|
1009
|
+
"topup_cap_unavailable",
|
|
1010
|
+
"topup_cap_currency_mismatch",
|
|
1011
|
+
"unknown"
|
|
1012
|
+
],
|
|
1013
|
+
denominationCauses: [
|
|
1014
|
+
"no_msats",
|
|
1015
|
+
"sub_micro",
|
|
1016
|
+
"unsupported_currency",
|
|
1017
|
+
"rate_unavailable",
|
|
1018
|
+
"rate_stale_refused",
|
|
1019
|
+
"unknown"
|
|
1020
|
+
],
|
|
1021
|
+
paymentFailureCategories: [
|
|
1022
|
+
"invalid_challenge",
|
|
1023
|
+
"malformed_credential",
|
|
1024
|
+
"payment_expired",
|
|
1025
|
+
"verification_failed",
|
|
1026
|
+
"insufficient_funds",
|
|
1027
|
+
"invalid_signature",
|
|
1028
|
+
"unsupported_method",
|
|
1029
|
+
"replay_detected",
|
|
1030
|
+
"ledger_refused",
|
|
1031
|
+
"settlement_failed",
|
|
1032
|
+
"unsupported_version",
|
|
1033
|
+
"unknown"
|
|
1034
|
+
],
|
|
1035
|
+
paymentFailureStages: [
|
|
1036
|
+
"verifier",
|
|
1037
|
+
"broadcast",
|
|
1038
|
+
"verifier_broadcast",
|
|
1039
|
+
"replay_store",
|
|
1040
|
+
"funding_ledger",
|
|
1041
|
+
"unknown"
|
|
1042
|
+
],
|
|
1043
|
+
paymentPhases: [
|
|
1044
|
+
"upfront",
|
|
1045
|
+
"mid-job"
|
|
1001
1046
|
]
|
|
1002
1047
|
};
|
|
1003
1048
|
|
|
1004
1049
|
// src/observability/projection.ts
|
|
1005
1050
|
var DIAGNOSTIC_CATALOGUE_VERSION = diagnostic_catalogue_v1_default.version;
|
|
1051
|
+
var PAYMENT_ENUMS = {
|
|
1052
|
+
reason: new Set(diagnostic_catalogue_v1_default.paymentSkipReasons),
|
|
1053
|
+
cause: new Set(diagnostic_catalogue_v1_default.denominationCauses),
|
|
1054
|
+
failure_category: new Set(diagnostic_catalogue_v1_default.paymentFailureCategories),
|
|
1055
|
+
failure_stage: new Set(diagnostic_catalogue_v1_default.paymentFailureStages),
|
|
1056
|
+
phase: new Set(diagnostic_catalogue_v1_default.paymentPhases)
|
|
1057
|
+
};
|
|
1006
1058
|
var EVENTS = new Set(diagnostic_catalogue_v1_default.events);
|
|
1007
1059
|
var ROUTE_TEMPLATES = [...diagnostic_catalogue_v1_default.routeTemplates].sort(
|
|
1008
1060
|
compareRouteTemplates
|
|
@@ -1202,6 +1254,9 @@ function projectFields(input, dataset, authority, identityAuthority) {
|
|
|
1202
1254
|
return output;
|
|
1203
1255
|
}
|
|
1204
1256
|
function projectField(key, value, dataset, authority, identityAuthority) {
|
|
1257
|
+
const paymentEnum = Object.hasOwn(PAYMENT_ENUMS, key) ? PAYMENT_ENUMS[key] : void 0;
|
|
1258
|
+
if (paymentEnum)
|
|
1259
|
+
return typeof value === "string" && paymentEnum.has(value) ? value : void 0;
|
|
1205
1260
|
if (BOOLEAN_FIELDS.has(key))
|
|
1206
1261
|
return typeof value === "boolean" ? value : void 0;
|
|
1207
1262
|
if (INTEGER_FIELDS.has(key))
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
parseStoreValue,
|
|
3
3
|
stringifyStoreValue
|
|
4
4
|
} from "./chunk-YG7G4DPZ.js";
|
|
5
|
+
import {
|
|
6
|
+
withPostgresTransactionRecovery
|
|
7
|
+
} from "./chunk-TRNMTTPX.js";
|
|
5
8
|
import {
|
|
6
9
|
withSdkInitLock
|
|
7
10
|
} from "./chunk-COYKJRMM.js";
|
|
8
|
-
import {
|
|
9
|
-
withPostgresTransactionRecovery
|
|
10
|
-
} from "./chunk-P6QON7ER.js";
|
|
11
11
|
|
|
12
12
|
// src/sdk/server/tempo-session-store.ts
|
|
13
13
|
import { AsyncLocalStorage } from "async_hooks";
|