@dvmkit/sdk 0.6.0-rc.1 → 0.7.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JH3SX3LY.js → chunk-6XF3RVVX.js} +1 -1
- package/dist/{chunk-RLTSCKRI.js → chunk-BPYMEMQX.js} +50 -3
- package/dist/{chunk-IWQHUSMO.js → chunk-CXCQLOOK.js} +143 -2
- package/dist/{chunk-LE74UEV7.js → chunk-EZXAJ6EI.js} +64 -53
- package/dist/{chunk-FI4CST2D.js → chunk-FWGWLPXF.js} +4 -6
- package/dist/{chunk-HHBDBMEO.js → chunk-GY66THYI.js} +21 -23
- package/dist/{chunk-UOCZXO2Z.js → chunk-JEVLNAO3.js} +10 -5
- package/dist/{chunk-OQA7IHI4.js → chunk-KMED3H3A.js} +10 -6
- package/dist/{chunk-PAIM66YA.js → chunk-NFMOPYBA.js} +47 -37
- package/dist/{chunk-B2IROPQF.js → chunk-O2OTZ5GP.js} +40 -15
- package/dist/{chunk-FYRR2UEZ.js → chunk-OML32F6I.js} +1 -1
- package/dist/{chunk-7ZUKL4IV.js → chunk-RA2WIX7G.js} +5 -5
- package/dist/{chunk-PLG4XER6.js → chunk-S3OY533W.js} +1 -1
- package/dist/{chunk-GFY5FRX3.js → chunk-SZVXOQ75.js} +5 -12
- package/dist/{chunk-MZRJR2CW.js → chunk-WBOKPC37.js} +22 -3
- package/dist/{content-retention-BTGSQRfP.d.ts → content-retention-DHyLdA6b.d.ts} +1 -1
- package/dist/{credit-ledger-MI2H7NEC.js → credit-ledger-MCUXYKSJ.js} +2 -3
- package/dist/{credit-menu-BAsrRu3z.d.ts → credit-menu-DjnkeEUU.d.ts} +4 -4
- package/dist/{fx-BgDmyTdd.d.ts → fx-zMWFzfrU.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/internal/caller.d.ts +1359 -851
- package/dist/internal/caller.js +1000 -914
- package/dist/internal/index.js +1 -1
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +9 -11
- package/dist/{job-store-BVeF5_Jq.d.ts → job-store-DdLXBpol.d.ts} +1 -1
- package/dist/{lightning-backend-40fIzz1W.d.ts → lightning-backend-Bw-qtAbt.d.ts} +4 -2
- package/dist/{memory-credit-ledger-W2BAUYJP.js → memory-credit-ledger-SBSMGMDX.js} +3 -4
- package/dist/server/index.d.ts +10 -10
- package/dist/server/index.js +14 -17
- package/dist/{step-cache-CPdH1hei.d.ts → step-cache-2MkvenJn.d.ts} +1 -1
- package/dist/tempo-lifecycle-GJ77YKVY.js +15 -0
- package/dist/{tempo-wallet-B5XXV3YH.js → tempo-wallet-X2GGAZ6X.js} +4 -4
- package/dist/testing/index.d.ts +3 -3
- package/dist/{usd-AWlrwlM5.d.ts → usd-DI3d3gTK.d.ts} +1 -1
- package/dist/{x402-R6HPBY5D.js → x402-FT4S4JS4.js} +8 -10
- package/package.json +3 -2
- package/dist/chunk-CZULM42S.js +0 -143
- package/dist/chunk-LIRAHP7B.js +0 -53
- package/dist/tempo-lifecycle-ZBBLFBMH.js +0 -15
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/lib/errors.ts
|
|
2
|
+
var DvmError = class extends Error {
|
|
3
|
+
constructor(code, message, hint, data, display, proseSources) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.hint = hint;
|
|
7
|
+
this.data = data;
|
|
8
|
+
this.display = display;
|
|
9
|
+
this.proseSources = proseSources;
|
|
10
|
+
this.name = "DvmError";
|
|
11
|
+
}
|
|
12
|
+
code;
|
|
13
|
+
hint;
|
|
14
|
+
data;
|
|
15
|
+
display;
|
|
16
|
+
proseSources;
|
|
17
|
+
};
|
|
18
|
+
function providerProseSources(...sources) {
|
|
19
|
+
const provenance = {};
|
|
20
|
+
for (const source of sources) {
|
|
21
|
+
if (!source) continue;
|
|
22
|
+
for (const field of ["message", "hint", "display"]) {
|
|
23
|
+
if (typeof source[field] === "string") provenance[field] = "provider";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Object.keys(provenance).length > 0 ? provenance : void 0;
|
|
27
|
+
}
|
|
28
|
+
function isAbortError(err) {
|
|
29
|
+
return err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
30
|
+
}
|
|
31
|
+
function transportErrorCode(err) {
|
|
32
|
+
let current = err;
|
|
33
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34
|
+
for (let depth = 0; depth < 5 && isErrorLike(current) && !seen.has(current); depth++) {
|
|
35
|
+
seen.add(current);
|
|
36
|
+
const code = current.code;
|
|
37
|
+
if (typeof code === "string" && /^(?:E[A-Z0-9_]{1,63}|UND_ERR_[A-Z0-9_]{1,63})$/.test(code)) {
|
|
38
|
+
return code;
|
|
39
|
+
}
|
|
40
|
+
current = current.cause;
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
function isErrorLike(value) {
|
|
45
|
+
return (typeof value === "object" || typeof value === "function") && value !== null;
|
|
46
|
+
}
|
|
4
47
|
|
|
5
48
|
// src/lib/x402/networks.ts
|
|
6
49
|
var X402_NETWORKS = [
|
|
@@ -99,6 +142,10 @@ var BY_CAIP2 = new Map(X402_NETWORKS.map((n) => [n.caip2, n]));
|
|
|
99
142
|
var BY_SLUG = new Map(X402_NETWORKS.map((n) => [n.slug, n]));
|
|
100
143
|
|
|
101
144
|
export {
|
|
145
|
+
DvmError,
|
|
146
|
+
providerProseSources,
|
|
147
|
+
isAbortError,
|
|
148
|
+
transportErrorCode,
|
|
102
149
|
X402_NETWORKS,
|
|
103
150
|
x402NetworkByCaip2,
|
|
104
151
|
x402NetworkBySlug,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
x402NetworkByCaip2,
|
|
3
3
|
x402NetworkBySlug
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-BPYMEMQX.js";
|
|
5
5
|
|
|
6
6
|
// src/lib/x402/constants.ts
|
|
7
7
|
var X402_DEFAULT_FACILITATOR = "https://x402.org/facilitator";
|
|
@@ -204,6 +204,118 @@ function isOptionalRecord(value) {
|
|
|
204
204
|
return value === void 0 || value === null || isRecord(value);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
// src/defaults.ts
|
|
208
|
+
import { homedir } from "os";
|
|
209
|
+
import { join } from "path";
|
|
210
|
+
var CONFIG_DIR = process.env.DVM_CONFIG_DIR ?? join(homedir(), ".dvm");
|
|
211
|
+
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
212
|
+
var CONFIG_BACKUP_FILE = join(CONFIG_DIR, "config.json.bak");
|
|
213
|
+
var CONFIG_AUDIT_FILE = join(CONFIG_DIR, "config-audit.jsonl");
|
|
214
|
+
var CONFIG_PINNED_FILE = join(CONFIG_DIR, "config.json.pinned");
|
|
215
|
+
var JOBS_FILE = join(CONFIG_DIR, "jobs.json");
|
|
216
|
+
var REQUEST_INTENTS_DIR = join(CONFIG_DIR, "request-intents");
|
|
217
|
+
var FAVORITES_FILE = join(CONFIG_DIR, "favorites.json");
|
|
218
|
+
var MESSAGES_DIR = join(CONFIG_DIR, "messages");
|
|
219
|
+
var RECEIPTS_FILE = join(CONFIG_DIR, "receipts.jsonl");
|
|
220
|
+
var CREDITS_FILE = join(CONFIG_DIR, "credits.json");
|
|
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 };
|
|
267
|
+
}
|
|
268
|
+
if ((mode & 63) === 0) {
|
|
269
|
+
return { ...base, exists: true, modeOctal: toOctal(mode) };
|
|
270
|
+
}
|
|
271
|
+
try {
|
|
272
|
+
chmodSync(CONFIG_DIR, CONFIG_DIR_MODE);
|
|
273
|
+
} catch (err) {
|
|
274
|
+
return {
|
|
275
|
+
...base,
|
|
276
|
+
exists: true,
|
|
277
|
+
modeOctal: toOctal(mode),
|
|
278
|
+
error: err instanceof Error ? err.message : String(err)
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
...base,
|
|
283
|
+
exists: true,
|
|
284
|
+
modeOctal: toOctal(CONFIG_DIR_MODE),
|
|
285
|
+
previousModeOctal: toOctal(mode),
|
|
286
|
+
repaired: true
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function toOctal(mode) {
|
|
290
|
+
return "0" + mode.toString(8).padStart(3, "0");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/lib/payment-rails/rpc.ts
|
|
294
|
+
function resolveRpcOverride(envValue, bundled) {
|
|
295
|
+
const override = envValue?.trim() ?? "";
|
|
296
|
+
return override.length > 0 ? { url: override, source: "override" } : { url: bundled, source: "bundled" };
|
|
297
|
+
}
|
|
298
|
+
function resolveRpcHttpTransportOptions(source, envValue) {
|
|
299
|
+
if (source !== "override" || !envValue?.trim()) return void 0;
|
|
300
|
+
let parsed;
|
|
301
|
+
try {
|
|
302
|
+
parsed = JSON.parse(envValue);
|
|
303
|
+
} catch {
|
|
304
|
+
throw new Error("RPC headers must be a JSON object of non-empty string values.");
|
|
305
|
+
}
|
|
306
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
307
|
+
throw new Error("RPC headers must be a JSON object of non-empty string values.");
|
|
308
|
+
const headers = {};
|
|
309
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
310
|
+
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name) || typeof value !== "string" || value.length === 0 || /[\r\n]/.test(value))
|
|
311
|
+
throw new Error("RPC headers must be a JSON object of non-empty string values.");
|
|
312
|
+
headers[name] = value;
|
|
313
|
+
}
|
|
314
|
+
if (Object.keys(headers).length === 0)
|
|
315
|
+
throw new Error("RPC headers must be a JSON object of non-empty string values.");
|
|
316
|
+
return { fetchOptions: { headers } };
|
|
317
|
+
}
|
|
318
|
+
|
|
207
319
|
export {
|
|
208
320
|
X402_DEFAULT_FACILITATOR,
|
|
209
321
|
X402_VERSION,
|
|
@@ -226,5 +338,34 @@ export {
|
|
|
226
338
|
encodePaymentRequiredHeader,
|
|
227
339
|
decodePaymentRequiredHeader,
|
|
228
340
|
exactEvmAuthorization,
|
|
229
|
-
encodeSettleResponseHeader
|
|
341
|
+
encodeSettleResponseHeader,
|
|
342
|
+
CONFIG_DIR,
|
|
343
|
+
CONFIG_FILE,
|
|
344
|
+
CONFIG_BACKUP_FILE,
|
|
345
|
+
CONFIG_AUDIT_FILE,
|
|
346
|
+
CONFIG_PINNED_FILE,
|
|
347
|
+
JOBS_FILE,
|
|
348
|
+
REQUEST_INTENTS_DIR,
|
|
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,
|
|
369
|
+
resolveRpcOverride,
|
|
370
|
+
resolveRpcHttpTransportOptions
|
|
230
371
|
};
|
|
@@ -3,25 +3,14 @@ import {
|
|
|
3
3
|
listCredits,
|
|
4
4
|
maxAdvertisedMicro,
|
|
5
5
|
withinAdvertisedTolerance
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-O2OTZ5GP.js";
|
|
7
7
|
import {
|
|
8
8
|
authorizeProtectedRemoval,
|
|
9
9
|
isValidEvmPrivateKey,
|
|
10
10
|
loadConfig,
|
|
11
|
-
updateConfig
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
X402_DEFAULT_NETWORK,
|
|
15
|
-
X402_V1_VERSION,
|
|
16
|
-
X402_VERSION,
|
|
17
|
-
buildPaymentRequirements,
|
|
18
|
-
chainIdFromCaip2,
|
|
19
|
-
encodePayment,
|
|
20
|
-
usdcContractFor,
|
|
21
|
-
usdcDomainNameFor,
|
|
22
|
-
usdcDomainVersionFor,
|
|
23
|
-
x402NetworkToCaip2
|
|
24
|
-
} from "./chunk-IWQHUSMO.js";
|
|
11
|
+
updateConfig,
|
|
12
|
+
x402WalletFromConfig
|
|
13
|
+
} from "./chunk-WBOKPC37.js";
|
|
25
14
|
import {
|
|
26
15
|
costAnchor,
|
|
27
16
|
fetchBtcUsdRate,
|
|
@@ -30,25 +19,33 @@ import {
|
|
|
30
19
|
getLastKnownBtcRate,
|
|
31
20
|
msatsToUsdc,
|
|
32
21
|
usdcToMsats
|
|
33
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-NFMOPYBA.js";
|
|
34
23
|
import {
|
|
35
24
|
X402_CHANNELS_FILE,
|
|
25
|
+
X402_DEFAULT_NETWORK,
|
|
26
|
+
X402_V1_VERSION,
|
|
27
|
+
X402_VERSION,
|
|
28
|
+
buildPaymentRequirements,
|
|
29
|
+
chainIdFromCaip2,
|
|
30
|
+
encodePayment,
|
|
36
31
|
ensureConfigDir,
|
|
37
32
|
resolveRpcHttpTransportOptions,
|
|
38
|
-
resolveRpcOverride
|
|
39
|
-
|
|
33
|
+
resolveRpcOverride,
|
|
34
|
+
usdcContractFor,
|
|
35
|
+
usdcDomainNameFor,
|
|
36
|
+
usdcDomainVersionFor,
|
|
37
|
+
x402NetworkToCaip2
|
|
38
|
+
} from "./chunk-CXCQLOOK.js";
|
|
40
39
|
import {
|
|
41
40
|
redactUrl,
|
|
42
41
|
redactUrlsInText
|
|
43
42
|
} from "./chunk-FUJ36YDV.js";
|
|
44
43
|
import {
|
|
44
|
+
DvmError,
|
|
45
45
|
assertSupportedX402Network,
|
|
46
46
|
x402NetworkByCaip2,
|
|
47
47
|
x402SupportedNetworksHint
|
|
48
|
-
} from "./chunk-
|
|
49
|
-
import {
|
|
50
|
-
DvmError
|
|
51
|
-
} from "./chunk-LIRAHP7B.js";
|
|
48
|
+
} from "./chunk-BPYMEMQX.js";
|
|
52
49
|
|
|
53
50
|
// src/lib/x402/asset.ts
|
|
54
51
|
function resolveX402Asset(network = X402_DEFAULT_NETWORK) {
|
|
@@ -166,6 +163,43 @@ function rateUnavailable(purpose) {
|
|
|
166
163
|
var X402_EXACT_AUTHORIZATION_TTL_SECONDS = 600;
|
|
167
164
|
var X402_REFUSAL_TRANSACTION_DISCOVERY_WINDOW_MS = 15 * 6e4;
|
|
168
165
|
|
|
166
|
+
// src/lib/x402/voucher-pending.ts
|
|
167
|
+
var X402_PENDING_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
168
|
+
function x402PendingStale(pending, now = Date.now()) {
|
|
169
|
+
return now - pending.requestedAt >= X402_PENDING_STALE_MS;
|
|
170
|
+
}
|
|
171
|
+
function x402PendingRetired(pending) {
|
|
172
|
+
return pending.refusedAt !== void 0 || pending.supersededAt !== void 0;
|
|
173
|
+
}
|
|
174
|
+
function x402PendingBlockExpiresAt(pending) {
|
|
175
|
+
return x402PendingDepositExpiresAt(pending) ?? pending.requestedAt + X402_PENDING_STALE_MS;
|
|
176
|
+
}
|
|
177
|
+
function x402PendingDepositExpiresAt(pending) {
|
|
178
|
+
const seconds = pending.authorizationValidBefore ? Number(pending.authorizationValidBefore) : NaN;
|
|
179
|
+
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
180
|
+
}
|
|
181
|
+
function x402PendingUnsettled(pending, now = Date.now()) {
|
|
182
|
+
return !x402PendingRetired(pending) || now <= x402PendingBlockExpiresAt(pending);
|
|
183
|
+
}
|
|
184
|
+
function x402VoucherPendingState(blocking) {
|
|
185
|
+
const depositExpiresAt = x402PendingDepositExpiresAt(blocking);
|
|
186
|
+
return {
|
|
187
|
+
code: "x402_voucher_pending",
|
|
188
|
+
creditId: blocking.creditId,
|
|
189
|
+
fundId: blocking.fundId,
|
|
190
|
+
channelId: blocking.channelId,
|
|
191
|
+
endpoint: blocking.endpoint,
|
|
192
|
+
retired: x402PendingRetired(blocking),
|
|
193
|
+
blockedUntil: x402PendingBlockExpiresAt(blocking),
|
|
194
|
+
...depositExpiresAt === void 0 ? {} : { depositExpiresAt }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function assertNoRivalX402Voucher(channelId, creditId, pending, now) {
|
|
198
|
+
const blocking = pending.filter((entry) => x402PendingUnsettled(entry, now));
|
|
199
|
+
const rival = blocking.find((entry) => entry.creditId !== creditId && !x402PendingRetired(entry)) ?? blocking.find((entry) => entry.creditId !== creditId || x402PendingRetired(entry));
|
|
200
|
+
if (rival) throw { ...x402VoucherPendingState(rival), channelId };
|
|
201
|
+
}
|
|
202
|
+
|
|
169
203
|
// src/lib/x402/channel-store.ts
|
|
170
204
|
import { AsyncLocalStorage } from "async_hooks";
|
|
171
205
|
import { existsSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
@@ -203,23 +237,6 @@ function clearPendingX402ExactFunding(pending) {
|
|
|
203
237
|
);
|
|
204
238
|
saveFile(file);
|
|
205
239
|
}
|
|
206
|
-
var X402_PENDING_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
207
|
-
function x402PendingStale(pending, now = Date.now()) {
|
|
208
|
-
return now - pending.requestedAt >= X402_PENDING_STALE_MS;
|
|
209
|
-
}
|
|
210
|
-
function x402PendingRetired(pending) {
|
|
211
|
-
return pending.refusedAt !== void 0 || pending.supersededAt !== void 0;
|
|
212
|
-
}
|
|
213
|
-
function x402PendingBlockExpiresAt(pending) {
|
|
214
|
-
return x402PendingDepositExpiresAt(pending) ?? pending.requestedAt + X402_PENDING_STALE_MS;
|
|
215
|
-
}
|
|
216
|
-
function x402PendingDepositExpiresAt(pending) {
|
|
217
|
-
const seconds = pending.authorizationValidBefore ? Number(pending.authorizationValidBefore) : NaN;
|
|
218
|
-
return Number.isFinite(seconds) ? seconds * 1e3 : void 0;
|
|
219
|
-
}
|
|
220
|
-
function x402PendingUnsettled(pending, now = Date.now()) {
|
|
221
|
-
return !x402PendingRetired(pending) || now <= x402PendingBlockExpiresAt(pending);
|
|
222
|
-
}
|
|
223
240
|
function x402PendingFundingJson(entry) {
|
|
224
241
|
return {
|
|
225
242
|
credit_id: entry.creditId,
|
|
@@ -667,15 +684,7 @@ function saveFile(file) {
|
|
|
667
684
|
|
|
668
685
|
// src/lib/x402/wallet.ts
|
|
669
686
|
function loadX402Wallet() {
|
|
670
|
-
|
|
671
|
-
const x402 = config?.x402;
|
|
672
|
-
const privateKey = x402?.privateKey;
|
|
673
|
-
if (!privateKey || !isValidEvmPrivateKey(privateKey)) return null;
|
|
674
|
-
return {
|
|
675
|
-
privateKey,
|
|
676
|
-
address: "",
|
|
677
|
-
network: x402.network ?? X402_DEFAULT_NETWORK
|
|
678
|
-
};
|
|
687
|
+
return x402WalletFromConfig(loadConfig());
|
|
679
688
|
}
|
|
680
689
|
async function ensureAddress(wallet) {
|
|
681
690
|
if (!isValidEvmPrivateKey(wallet.privateKey)) throw invalidX402PrivateKey();
|
|
@@ -1032,17 +1041,19 @@ export {
|
|
|
1032
1041
|
staleRateNotice,
|
|
1033
1042
|
X402_EXACT_AUTHORIZATION_TTL_SECONDS,
|
|
1034
1043
|
X402_REFUSAL_TRANSACTION_DISCOVERY_WINDOW_MS,
|
|
1035
|
-
x402ExactFundingDead,
|
|
1036
|
-
recordPendingX402ExactFunding,
|
|
1037
|
-
loadResumableX402ExactFunding,
|
|
1038
|
-
listResumableX402ExactFundings,
|
|
1039
|
-
clearPendingX402ExactFunding,
|
|
1040
1044
|
X402_PENDING_STALE_MS,
|
|
1041
1045
|
x402PendingStale,
|
|
1042
1046
|
x402PendingRetired,
|
|
1043
1047
|
x402PendingBlockExpiresAt,
|
|
1044
1048
|
x402PendingDepositExpiresAt,
|
|
1045
1049
|
x402PendingUnsettled,
|
|
1050
|
+
x402VoucherPendingState,
|
|
1051
|
+
assertNoRivalX402Voucher,
|
|
1052
|
+
x402ExactFundingDead,
|
|
1053
|
+
recordPendingX402ExactFunding,
|
|
1054
|
+
loadResumableX402ExactFunding,
|
|
1055
|
+
listResumableX402ExactFundings,
|
|
1056
|
+
clearPendingX402ExactFunding,
|
|
1046
1057
|
x402PendingFundingJson,
|
|
1047
1058
|
withX402ChannelLock,
|
|
1048
1059
|
DvmX402ChannelStorage,
|
|
@@ -388,12 +388,6 @@ var HttpTransport = class {
|
|
|
388
388
|
}
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
-
// src/lib/nwc.ts
|
|
392
|
-
import { decrypt, encrypt } from "nostr-tools/nip04";
|
|
393
|
-
import { SimplePool, useWebSocketImplementation } from "nostr-tools/pool";
|
|
394
|
-
import { finalizeEvent, getPublicKey } from "nostr-tools/pure";
|
|
395
|
-
import WebSocket from "ws";
|
|
396
|
-
|
|
397
391
|
// src/lib/hash.ts
|
|
398
392
|
import { createHash } from "crypto";
|
|
399
393
|
function sha256hex(input) {
|
|
@@ -401,6 +395,10 @@ function sha256hex(input) {
|
|
|
401
395
|
}
|
|
402
396
|
|
|
403
397
|
// src/lib/nwc.ts
|
|
398
|
+
import { decrypt, encrypt } from "nostr-tools/nip04";
|
|
399
|
+
import { SimplePool, useWebSocketImplementation } from "nostr-tools/pool";
|
|
400
|
+
import { finalizeEvent, getPublicKey } from "nostr-tools/pure";
|
|
401
|
+
import WebSocket from "ws";
|
|
404
402
|
var webSocketImplementationConfigured = false;
|
|
405
403
|
function ensureWebSocketImplementation() {
|
|
406
404
|
if (webSocketImplementationConfigured) return;
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
createX402FacilitatorClient,
|
|
9
9
|
settleWithFacilitator,
|
|
10
10
|
verifyWithFacilitator
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-S3OY533W.js";
|
|
12
12
|
import {
|
|
13
13
|
MemoryCreditLedger
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-OML32F6I.js";
|
|
15
15
|
import {
|
|
16
16
|
PostgresJobStore
|
|
17
17
|
} from "./chunk-EQLA4FFY.js";
|
|
@@ -69,7 +69,18 @@ import {
|
|
|
69
69
|
toLockPubkey,
|
|
70
70
|
verifyCashuToken,
|
|
71
71
|
verifyChallenge
|
|
72
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-KMED3H3A.js";
|
|
73
|
+
import {
|
|
74
|
+
IMPLICIT_CREDIT_TTL_MS,
|
|
75
|
+
computeResultHash,
|
|
76
|
+
formatStaleness,
|
|
77
|
+
msatsToUsd,
|
|
78
|
+
msatsToUsdc,
|
|
79
|
+
signDrainReceipt,
|
|
80
|
+
signFundingReceipt,
|
|
81
|
+
signReceipt,
|
|
82
|
+
usdcToMsats
|
|
83
|
+
} from "./chunk-NFMOPYBA.js";
|
|
73
84
|
import {
|
|
74
85
|
X402_BATCH_SETTLEMENT_SCHEME,
|
|
75
86
|
X402_DEFAULT_FACILITATOR,
|
|
@@ -83,22 +94,9 @@ import {
|
|
|
83
94
|
encodeSettleResponseHeader,
|
|
84
95
|
exactEvmAuthorization,
|
|
85
96
|
paymentRequiredV2FromV1,
|
|
97
|
+
resolveRpcOverride,
|
|
86
98
|
x402NetworkToCaip2
|
|
87
|
-
} from "./chunk-
|
|
88
|
-
import {
|
|
89
|
-
IMPLICIT_CREDIT_TTL_MS,
|
|
90
|
-
computeResultHash,
|
|
91
|
-
formatStaleness,
|
|
92
|
-
msatsToUsd,
|
|
93
|
-
msatsToUsdc,
|
|
94
|
-
signDrainReceipt,
|
|
95
|
-
signFundingReceipt,
|
|
96
|
-
signReceipt,
|
|
97
|
-
usdcToMsats
|
|
98
|
-
} from "./chunk-PAIM66YA.js";
|
|
99
|
-
import {
|
|
100
|
-
resolveRpcOverride
|
|
101
|
-
} from "./chunk-CZULM42S.js";
|
|
99
|
+
} from "./chunk-CXCQLOOK.js";
|
|
102
100
|
import {
|
|
103
101
|
RAIL_REFUNDABLE,
|
|
104
102
|
canonicalRequestPath,
|
|
@@ -147,7 +145,7 @@ import {
|
|
|
147
145
|
isNonChannelBitcoinRail,
|
|
148
146
|
netOwedSats,
|
|
149
147
|
x402SettlementPending
|
|
150
|
-
} from "./chunk-
|
|
148
|
+
} from "./chunk-6XF3RVVX.js";
|
|
151
149
|
import {
|
|
152
150
|
withSdkInitLock
|
|
153
151
|
} from "./chunk-COYKJRMM.js";
|
|
@@ -156,7 +154,7 @@ import {
|
|
|
156
154
|
} from "./chunk-P6QON7ER.js";
|
|
157
155
|
import {
|
|
158
156
|
x402NetworkByCaip2
|
|
159
|
-
} from "./chunk-
|
|
157
|
+
} from "./chunk-BPYMEMQX.js";
|
|
160
158
|
import {
|
|
161
159
|
TEMPO_MODERATO_CHAIN_ID,
|
|
162
160
|
TEMPO_MODERATO_RPC,
|
|
@@ -3796,7 +3794,7 @@ async function verifyUpfrontPayment(opts) {
|
|
|
3796
3794
|
x402Requirements
|
|
3797
3795
|
});
|
|
3798
3796
|
}
|
|
3799
|
-
const { verifyX402Payment } = await import("./x402-
|
|
3797
|
+
const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
|
|
3800
3798
|
const receipt = await verifyX402Payment(
|
|
3801
3799
|
x402Payment,
|
|
3802
3800
|
x402Config,
|
|
@@ -4771,7 +4769,7 @@ async function verifyIncomingPayment(body, opts, snapshot) {
|
|
|
4771
4769
|
snapshot
|
|
4772
4770
|
});
|
|
4773
4771
|
}
|
|
4774
|
-
const { verifyX402Payment } = await import("./x402-
|
|
4772
|
+
const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
|
|
4775
4773
|
const receipt = await verifyX402Payment(
|
|
4776
4774
|
body.content.x402_payment,
|
|
4777
4775
|
opts.x402Config,
|
|
@@ -5196,7 +5194,7 @@ async function processIncomingPayment(job, body, opts) {
|
|
|
5196
5194
|
try {
|
|
5197
5195
|
const requiredMsats = job.pendingPaymentMsats ?? 0;
|
|
5198
5196
|
const requiredUsdcMicro = job.pendingX402AmountUsdcMicro !== void 0 ? BigInt(job.pendingX402AmountUsdcMicro) : BigInt(msatsToUsdc(requiredMsats, rate));
|
|
5199
|
-
const { verifyX402Payment } = await import("./x402-
|
|
5197
|
+
const { verifyX402Payment } = await import("./x402-FT4S4JS4.js");
|
|
5200
5198
|
const receipt = await verifyX402Payment(
|
|
5201
5199
|
body.content.x402_payment,
|
|
5202
5200
|
opts.x402Config,
|
|
@@ -2,33 +2,33 @@ import {
|
|
|
2
2
|
connectedTempoAccount,
|
|
3
3
|
tempoBalanceCheckHint,
|
|
4
4
|
tempoTokenReference
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-SZVXOQ75.js";
|
|
6
6
|
import {
|
|
7
7
|
fundingReachableAt,
|
|
8
8
|
listCredits,
|
|
9
9
|
maxAdvertisedMicro,
|
|
10
10
|
normalizeCreditEndpoint,
|
|
11
11
|
withinAdvertisedTolerance
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-O2OTZ5GP.js";
|
|
13
13
|
import {
|
|
14
14
|
costAnchor,
|
|
15
15
|
formatUsd,
|
|
16
16
|
formatUsdcMicrounits
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-NFMOPYBA.js";
|
|
18
18
|
import {
|
|
19
19
|
IDENTITIES_FILE,
|
|
20
20
|
TEMPO_CHANNELS_FILE,
|
|
21
21
|
ensureConfigDir,
|
|
22
22
|
resolveRpcHttpTransportOptions,
|
|
23
23
|
resolveRpcOverride
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-CXCQLOOK.js";
|
|
25
25
|
import {
|
|
26
26
|
redactUrl,
|
|
27
27
|
redactUrlsInText
|
|
28
28
|
} from "./chunk-FUJ36YDV.js";
|
|
29
29
|
import {
|
|
30
30
|
DvmError
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-BPYMEMQX.js";
|
|
32
32
|
|
|
33
33
|
// src/lib/cli-identity-store.ts
|
|
34
34
|
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
@@ -1606,11 +1606,16 @@ function intentClause(intent) {
|
|
|
1606
1606
|
export {
|
|
1607
1607
|
TEMPO_CHARGE_PENDING_STALE_MS,
|
|
1608
1608
|
withTempoChannelLock,
|
|
1609
|
+
createTempoChannelStore,
|
|
1609
1610
|
listTempoChannelAssociations,
|
|
1610
1611
|
loadTempoChannelAssociation,
|
|
1612
|
+
loadTempoChannelAssociationByKey,
|
|
1611
1613
|
loadTempoChannelEntry,
|
|
1612
1614
|
loadTempoChannelController,
|
|
1615
|
+
tempoDescriptorController,
|
|
1613
1616
|
tempoChannelControlledBy,
|
|
1617
|
+
retireTempoChannel,
|
|
1618
|
+
retireTempoChannelScope,
|
|
1614
1619
|
tempoChargeCredentialSettleable,
|
|
1615
1620
|
recordPendingTempoChargeFunding,
|
|
1616
1621
|
loadResumableTempoChargeFunding,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
verifyDrainReceipt,
|
|
9
9
|
verifyFundingReceipt,
|
|
10
10
|
verifyReceipt
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-NFMOPYBA.js";
|
|
12
12
|
import {
|
|
13
13
|
AGENT_MNEMONIC_FILE,
|
|
14
14
|
BUILDER_CONFIG_DIR,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
BUILDER_KEY_FILE,
|
|
17
17
|
WALLET_FILE,
|
|
18
18
|
ensureConfigDir
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-CXCQLOOK.js";
|
|
20
20
|
import {
|
|
21
21
|
canonicaliseForSigning
|
|
22
22
|
} from "./chunk-OFVV37XC.js";
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from "./chunk-66HGCPBU.js";
|
|
26
26
|
import {
|
|
27
27
|
DvmError
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-BPYMEMQX.js";
|
|
29
29
|
import {
|
|
30
30
|
diagnosticConsole
|
|
31
31
|
} from "./chunk-ETXDTUJO.js";
|
|
@@ -40,6 +40,9 @@ function isX402SettlementReconciliationReason(value) {
|
|
|
40
40
|
return value === "settlement_not_on_chain" || value === "chain_unreachable" || value === "settlement_unbookmarked" || value === "facilitator_channel_state_unavailable";
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// src/lib/payment-rails/tempo-wire.ts
|
|
44
|
+
var TEMPO_SESSION_UPDATED_REASON = "Tempo session updated; attach the next voucher to fund this credit.";
|
|
45
|
+
|
|
43
46
|
// src/lib/mints.ts
|
|
44
47
|
var RECOMMENDED_MINTS = [
|
|
45
48
|
{
|
|
@@ -204,6 +207,9 @@ var DEFAULT_LOCK_RETRY_INTERVAL_MS = 1e3;
|
|
|
204
207
|
var WALLET_VERSION = 9;
|
|
205
208
|
var RECENT_SPENDS_CAP = 10;
|
|
206
209
|
var DEFAULT_AGENT_MINT_URL = "https://mint.coinos.io";
|
|
210
|
+
function loadWalletConfiguredMints() {
|
|
211
|
+
return loadAgentWallet()?.mints ?? [];
|
|
212
|
+
}
|
|
207
213
|
function loadAgentWallet() {
|
|
208
214
|
if (!existsSync3(WALLET_FILE)) return null;
|
|
209
215
|
const raw = readFileSync3(WALLET_FILE, "utf-8");
|
|
@@ -1620,9 +1626,6 @@ function normaliseMintUrl(url) {
|
|
|
1620
1626
|
}
|
|
1621
1627
|
}
|
|
1622
1628
|
|
|
1623
|
-
// src/lib/payment-rails/tempo-wire.ts
|
|
1624
|
-
var TEMPO_SESSION_UPDATED_REASON = "Tempo session updated; attach the next voucher to fund this credit.";
|
|
1625
|
-
|
|
1626
1629
|
export {
|
|
1627
1630
|
toLockPubkey,
|
|
1628
1631
|
isX402SettlementReconciliationReason,
|
|
@@ -1644,6 +1647,7 @@ export {
|
|
|
1644
1647
|
WALLET_VERSION,
|
|
1645
1648
|
RECENT_SPENDS_CAP,
|
|
1646
1649
|
DEFAULT_AGENT_MINT_URL,
|
|
1650
|
+
loadWalletConfiguredMints,
|
|
1647
1651
|
loadAgentWallet,
|
|
1648
1652
|
saveAgentWallet,
|
|
1649
1653
|
walletExists,
|