@dvmkit/sdk 0.4.0-rc.1 → 0.5.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-TXX4GOUB.js → chunk-7ZUKL4IV.js} +1 -1
- package/dist/{chunk-KXZUCCEY.js → chunk-A4YFWZ7R.js} +4 -55
- package/dist/{chunk-2VGWYG4P.js → chunk-B2IROPQF.js} +446 -81
- package/dist/{chunk-K2YX2VRA.js → chunk-EYTHFFFU.js} +14 -12
- package/dist/{chunk-74PUEZJ4.js → chunk-GFY5FRX3.js} +1 -1
- package/dist/{chunk-W2EQGDF5.js → chunk-LE74UEV7.js} +49 -8
- package/dist/chunk-OFVV37XC.js +57 -0
- package/dist/{chunk-3MHE725Z.js → chunk-PAIM66YA.js} +90 -1
- package/dist/{chunk-5LR6P7WN.js → chunk-TUA7PYH7.js} +23 -103
- package/dist/{chunk-O3QDFPKM.js → chunk-TZ2WKCDD.js} +1 -1
- package/dist/{chunk-R4DQZFAL.js → chunk-UOCZXO2Z.js} +3 -3
- package/dist/{chunk-CE7XEHYC.js → chunk-Z4KLECAC.js} +1 -1
- package/dist/{credit-menu-B8_p_vUz.d.ts → credit-menu-CAfqe8IY.d.ts} +4 -4
- package/dist/{fx-DuaYHvVn.d.ts → fx-D9nsN3n4.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -3
- package/dist/internal/caller.d.ts +80 -13
- package/dist/internal/caller.js +36 -38
- package/dist/internal/index.js +1 -1
- package/dist/internal/server.d.ts +8 -8
- package/dist/internal/server.js +7 -6
- package/dist/{job-store-D6Rjj5Oi.d.ts → job-store-Bx-VFRjg.d.ts} +1 -1
- package/dist/{lightning-backend-BaeCPmx7.d.ts → lightning-backend-BAx2Y8pP.d.ts} +1 -1
- package/dist/server/index.d.ts +8 -8
- package/dist/server/index.js +6 -5
- package/dist/{step-cache-Bi43A0JN.d.ts → step-cache-QG_h5-3G.d.ts} +1 -1
- package/dist/{tempo-lifecycle-OTHV757Y.js → tempo-lifecycle-ZBBLFBMH.js} +5 -4
- package/dist/{tempo-wallet-32JWQZKQ.js → tempo-wallet-B5XXV3YH.js} +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/{usd-AZPVq4eU.d.ts → usd-EwRqCPF-.d.ts} +1 -1
- package/dist/{x402-CEDHGZDI.js → x402-R6HPBY5D.js} +5 -4
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
humanizeZodIssues,
|
|
26
26
|
signedRequestInput,
|
|
27
27
|
zodIssuesOf
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-Z4KLECAC.js";
|
|
29
29
|
import {
|
|
30
30
|
JobCancelledError,
|
|
31
31
|
MemoryJobStore,
|
|
@@ -52,7 +52,6 @@ import {
|
|
|
52
52
|
attestedDvmIdentity,
|
|
53
53
|
buildAdminChallenge,
|
|
54
54
|
checkMintHealth,
|
|
55
|
-
computeResultHash,
|
|
56
55
|
createMonotonicClock,
|
|
57
56
|
getWallet,
|
|
58
57
|
isPublicRequestId,
|
|
@@ -61,13 +60,10 @@ import {
|
|
|
61
60
|
normaliseMintUrl,
|
|
62
61
|
parseTraceparent,
|
|
63
62
|
receiptPubkeyFromSecret,
|
|
64
|
-
signDrainReceipt,
|
|
65
|
-
signFundingReceipt,
|
|
66
|
-
signReceipt,
|
|
67
63
|
toLockPubkey,
|
|
68
64
|
verifyCashuToken,
|
|
69
65
|
verifyChallenge
|
|
70
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-TUA7PYH7.js";
|
|
71
67
|
import {
|
|
72
68
|
X402_BATCH_SETTLEMENT_SCHEME,
|
|
73
69
|
X402_DEFAULT_FACILITATOR,
|
|
@@ -85,20 +81,26 @@ import {
|
|
|
85
81
|
} from "./chunk-IWQHUSMO.js";
|
|
86
82
|
import {
|
|
87
83
|
IMPLICIT_CREDIT_TTL_MS,
|
|
84
|
+
computeResultHash,
|
|
88
85
|
formatStaleness,
|
|
89
86
|
msatsToUsd,
|
|
90
87
|
msatsToUsdc,
|
|
88
|
+
signDrainReceipt,
|
|
89
|
+
signFundingReceipt,
|
|
90
|
+
signReceipt,
|
|
91
91
|
usdcToMsats
|
|
92
|
-
} from "./chunk-
|
|
92
|
+
} from "./chunk-PAIM66YA.js";
|
|
93
93
|
import {
|
|
94
94
|
resolveRpcOverride
|
|
95
95
|
} from "./chunk-CZULM42S.js";
|
|
96
96
|
import {
|
|
97
97
|
RAIL_REFUNDABLE,
|
|
98
98
|
canonicalRequestPath,
|
|
99
|
-
canonicalize,
|
|
100
99
|
isZodSchema
|
|
101
|
-
} from "./chunk-
|
|
100
|
+
} from "./chunk-A4YFWZ7R.js";
|
|
101
|
+
import {
|
|
102
|
+
canonicalize
|
|
103
|
+
} from "./chunk-OFVV37XC.js";
|
|
102
104
|
import {
|
|
103
105
|
StepCache,
|
|
104
106
|
createConsoleLogger,
|
|
@@ -3777,7 +3779,7 @@ async function verifyUpfrontPayment(opts) {
|
|
|
3777
3779
|
x402Requirements
|
|
3778
3780
|
});
|
|
3779
3781
|
}
|
|
3780
|
-
const { verifyX402Payment } = await import("./x402-
|
|
3782
|
+
const { verifyX402Payment } = await import("./x402-R6HPBY5D.js");
|
|
3781
3783
|
const receipt = await verifyX402Payment(
|
|
3782
3784
|
x402Payment,
|
|
3783
3785
|
x402Config,
|
|
@@ -4752,7 +4754,7 @@ async function verifyIncomingPayment(body, opts, snapshot) {
|
|
|
4752
4754
|
snapshot
|
|
4753
4755
|
});
|
|
4754
4756
|
}
|
|
4755
|
-
const { verifyX402Payment } = await import("./x402-
|
|
4757
|
+
const { verifyX402Payment } = await import("./x402-R6HPBY5D.js");
|
|
4756
4758
|
const receipt = await verifyX402Payment(
|
|
4757
4759
|
body.content.x402_payment,
|
|
4758
4760
|
opts.x402Config,
|
|
@@ -5177,7 +5179,7 @@ async function processIncomingPayment(job, body, opts) {
|
|
|
5177
5179
|
try {
|
|
5178
5180
|
const requiredMsats = job.pendingPaymentMsats ?? 0;
|
|
5179
5181
|
const requiredUsdcMicro = job.pendingX402AmountUsdcMicro !== void 0 ? BigInt(job.pendingX402AmountUsdcMicro) : BigInt(msatsToUsdc(requiredMsats, rate));
|
|
5180
|
-
const { verifyX402Payment } = await import("./x402-
|
|
5182
|
+
const { verifyX402Payment } = await import("./x402-R6HPBY5D.js");
|
|
5181
5183
|
const receipt = await verifyX402Payment(
|
|
5182
5184
|
body.content.x402_payment,
|
|
5183
5185
|
opts.x402Config,
|
|
@@ -103,7 +103,7 @@ async function generateTempoKey(opts = {}) {
|
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
if (existing && opts.force) {
|
|
106
|
-
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-
|
|
106
|
+
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-ZBBLFBMH.js");
|
|
107
107
|
await assertTempoWalletIdle("replace");
|
|
108
108
|
}
|
|
109
109
|
const { privateKeyToAccount, generatePrivateKey } = await import("viem/accounts");
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fundingReachableAt,
|
|
3
|
-
info,
|
|
4
3
|
listCredits,
|
|
5
4
|
maxAdvertisedMicro,
|
|
6
5
|
withinAdvertisedTolerance
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-B2IROPQF.js";
|
|
8
7
|
import {
|
|
9
8
|
authorizeProtectedRemoval,
|
|
10
9
|
isValidEvmPrivateKey,
|
|
@@ -31,7 +30,7 @@ import {
|
|
|
31
30
|
getLastKnownBtcRate,
|
|
32
31
|
msatsToUsdc,
|
|
33
32
|
usdcToMsats
|
|
34
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-PAIM66YA.js";
|
|
35
34
|
import {
|
|
36
35
|
X402_CHANNELS_FILE,
|
|
37
36
|
ensureConfigDir,
|
|
@@ -72,6 +71,42 @@ function x402WrongAssetHint(asset) {
|
|
|
72
71
|
return `This rail reads only ${asset.label} (${asset.address}) on ${asset.networkLabel}. ${wrongToken} USDC on a different chain is invisible here too \u2014 this wallet reads ${asset.networkLabel} alone. If you funded the wrong one, swap it to ${asset.label} on ${asset.networkLabel}, or bridge the funds across to ${asset.networkLabel}; either way they land where this rail can spend them.`;
|
|
73
72
|
}
|
|
74
73
|
|
|
74
|
+
// src/lib/output.ts
|
|
75
|
+
import { writeSync } from "fs";
|
|
76
|
+
var _traceId = null;
|
|
77
|
+
function setOutputTraceId(id) {
|
|
78
|
+
_traceId = id;
|
|
79
|
+
}
|
|
80
|
+
function getOutputTraceId() {
|
|
81
|
+
return _traceId;
|
|
82
|
+
}
|
|
83
|
+
function json(data) {
|
|
84
|
+
const out = _traceId !== null && typeof data === "object" && data !== null && !Array.isArray(data) && !("trace_id" in data) ? { trace_id: _traceId, ...data } : data;
|
|
85
|
+
writeAllSync(1, JSON.stringify(out) + "\n");
|
|
86
|
+
}
|
|
87
|
+
function info(msg) {
|
|
88
|
+
writeAllSync(2, msg + "\n");
|
|
89
|
+
}
|
|
90
|
+
function raw(msg) {
|
|
91
|
+
writeAllSync(1, msg + "\n");
|
|
92
|
+
}
|
|
93
|
+
function progress(event) {
|
|
94
|
+
writeAllSync(2, JSON.stringify(event) + "\n");
|
|
95
|
+
}
|
|
96
|
+
function writeAllSync(fd, text) {
|
|
97
|
+
const buf = Buffer.from(text, "utf8");
|
|
98
|
+
let offset = 0;
|
|
99
|
+
while (offset < buf.length) {
|
|
100
|
+
try {
|
|
101
|
+
offset += writeSync(fd, buf, offset, buf.length - offset);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
const code = err.code;
|
|
104
|
+
if (code === "EAGAIN" || code === "EINTR") continue;
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
75
110
|
// src/lib/btc-rate.ts
|
|
76
111
|
async function resolveBtcUsdRate(purpose) {
|
|
77
112
|
try {
|
|
@@ -600,18 +635,18 @@ function ensureX402ChannelFile() {
|
|
|
600
635
|
function loadFile() {
|
|
601
636
|
if (!existsSync(X402_CHANNELS_FILE)) return { ...EMPTY, channels: {}, pending: [], exact: [] };
|
|
602
637
|
try {
|
|
603
|
-
const
|
|
604
|
-
if (
|
|
638
|
+
const raw2 = JSON.parse(readFileSync(X402_CHANNELS_FILE, "utf8"));
|
|
639
|
+
if (raw2.version !== 1 || !raw2.channels || typeof raw2.channels !== "object" || Array.isArray(raw2.channels) || !Array.isArray(raw2.pending)) {
|
|
605
640
|
throw new Error("unsupported x402 channel store shape");
|
|
606
641
|
}
|
|
607
642
|
return {
|
|
608
643
|
version: 1,
|
|
609
|
-
channels:
|
|
610
|
-
pending:
|
|
644
|
+
channels: raw2.channels,
|
|
645
|
+
pending: raw2.pending,
|
|
611
646
|
// Tolerated rather than required, unlike its two siblings: every file
|
|
612
647
|
// written before lacks the key, and failing closed on it would
|
|
613
648
|
// read as a corrupt journal on a store that is perfectly intact.
|
|
614
|
-
exact: Array.isArray(
|
|
649
|
+
exact: Array.isArray(raw2.exact) ? raw2.exact : []
|
|
615
650
|
};
|
|
616
651
|
} catch (cause) {
|
|
617
652
|
throw new DvmError(
|
|
@@ -986,6 +1021,12 @@ async function priceableRate(btcRate) {
|
|
|
986
1021
|
export {
|
|
987
1022
|
resolveX402Asset,
|
|
988
1023
|
x402WrongAssetHint,
|
|
1024
|
+
setOutputTraceId,
|
|
1025
|
+
getOutputTraceId,
|
|
1026
|
+
json,
|
|
1027
|
+
info,
|
|
1028
|
+
raw,
|
|
1029
|
+
progress,
|
|
989
1030
|
resolveBtcUsdRate,
|
|
990
1031
|
tryResolveBtcUsdRate,
|
|
991
1032
|
staleRateNotice,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/lib/cast-auth/canonical-json.ts
|
|
2
|
+
function canonicalize(value) {
|
|
3
|
+
return JSON.stringify(sortDeep(value));
|
|
4
|
+
}
|
|
5
|
+
function canonicaliseForSigning(value) {
|
|
6
|
+
return new TextEncoder().encode(canonicalize(value));
|
|
7
|
+
}
|
|
8
|
+
function sortDeep(value) {
|
|
9
|
+
if (value === null) return null;
|
|
10
|
+
if (typeof value === "string" || typeof value === "boolean") return value;
|
|
11
|
+
if (typeof value === "number") {
|
|
12
|
+
if (!Number.isFinite(value)) {
|
|
13
|
+
throw new TypeError(`canonicalize: non-finite number is not JSON-serialisable`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(value)) return value.map(sortDeep);
|
|
18
|
+
if (typeof value === "object") {
|
|
19
|
+
const sorted = {};
|
|
20
|
+
for (const key of Object.keys(value).sort()) {
|
|
21
|
+
const v = value[key];
|
|
22
|
+
if (v === void 0) continue;
|
|
23
|
+
sorted[key] = sortDeep(v);
|
|
24
|
+
}
|
|
25
|
+
return sorted;
|
|
26
|
+
}
|
|
27
|
+
throw new TypeError(`canonicalize: unsupported value of type ${typeof value}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/lib/cast-auth/verify.ts
|
|
31
|
+
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
32
|
+
function verifyCanonicalSignedRequest(payload, signatureHex, pubkeyHex) {
|
|
33
|
+
if (!/^[0-9a-f]{64}$/i.test(pubkeyHex) || !/^[0-9a-f]{128}$/i.test(signatureHex)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const data = canonicaliseForSigning(payload);
|
|
37
|
+
const signature = hexToBytes(signatureHex);
|
|
38
|
+
const pubkey = hexToBytes(pubkeyHex);
|
|
39
|
+
try {
|
|
40
|
+
return schnorr.verify(signature, data, pubkey);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function hexToBytes(hex) {
|
|
46
|
+
const out = new Uint8Array(hex.length / 2);
|
|
47
|
+
for (let i = 0; i < out.length; i++) {
|
|
48
|
+
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
canonicalize,
|
|
55
|
+
canonicaliseForSigning,
|
|
56
|
+
verifyCanonicalSignedRequest
|
|
57
|
+
};
|
|
@@ -2,6 +2,9 @@ import {
|
|
|
2
2
|
BTC_RATE_FILE,
|
|
3
3
|
ensureConfigSubdir
|
|
4
4
|
} from "./chunk-CZULM42S.js";
|
|
5
|
+
import {
|
|
6
|
+
canonicaliseForSigning
|
|
7
|
+
} from "./chunk-OFVV37XC.js";
|
|
5
8
|
import {
|
|
6
9
|
formatFiat
|
|
7
10
|
} from "./chunk-AT6V3SY7.js";
|
|
@@ -232,6 +235,82 @@ async function fetchFromApi() {
|
|
|
232
235
|
return rate;
|
|
233
236
|
}
|
|
234
237
|
|
|
238
|
+
// src/lib/receipt.ts
|
|
239
|
+
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
240
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
241
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
242
|
+
function computeResultHash(summary, artifactContents) {
|
|
243
|
+
const artifactHashes = artifactContents.map(
|
|
244
|
+
(content) => bytesToHex(sha256(canonicaliseForSigning(content)))
|
|
245
|
+
);
|
|
246
|
+
return bytesToHex(
|
|
247
|
+
sha256(
|
|
248
|
+
canonicaliseForSigning({
|
|
249
|
+
summary: summary ?? null,
|
|
250
|
+
artifact_hashes: artifactHashes
|
|
251
|
+
})
|
|
252
|
+
)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
function signReceipt(unsigned, secretHex) {
|
|
256
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
257
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
258
|
+
return { ...unsigned, signature };
|
|
259
|
+
}
|
|
260
|
+
function verifyReceipt(receipt) {
|
|
261
|
+
try {
|
|
262
|
+
const { signature, ...unsigned } = receipt;
|
|
263
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
264
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
265
|
+
} catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function isSignedJobReceipt(value) {
|
|
270
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
271
|
+
const r = value;
|
|
272
|
+
const paid = r.paid;
|
|
273
|
+
return r.v === 1 && typeof r.job_id === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.capability === "string" && (r.outcome === "completed" || r.outcome === "failed" || r.outcome === "cancelled") && typeof r.seq === "number" && typeof r.issued_at === "number" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string" && !!paid && typeof paid === "object" && !Array.isArray(paid) && typeof paid.msats === "number";
|
|
274
|
+
}
|
|
275
|
+
function signDrainReceipt(unsigned, secretHex) {
|
|
276
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
277
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
278
|
+
return { ...unsigned, signature };
|
|
279
|
+
}
|
|
280
|
+
function signFundingReceipt(unsigned, secretHex) {
|
|
281
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
282
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
283
|
+
return { ...unsigned, signature };
|
|
284
|
+
}
|
|
285
|
+
function isFundingReceipt(value) {
|
|
286
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
287
|
+
const r = value;
|
|
288
|
+
return r.v === 1 && r.kind === "credit_funding" && typeof r.credit_id === "string" && typeof r.fund_id === "string" && typeof r.funded_micro === "number" && typeof r.balance_after_micro === "number" && typeof r.ledger_seq === "number" && typeof r.issued_at === "number" && typeof r.caller_pubkey === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string";
|
|
289
|
+
}
|
|
290
|
+
function verifyFundingReceipt(receipt) {
|
|
291
|
+
try {
|
|
292
|
+
const { signature, ...unsigned } = receipt;
|
|
293
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
294
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
295
|
+
} catch {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function isDrainReceipt(value) {
|
|
300
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
301
|
+
const r = value;
|
|
302
|
+
return r.v === 1 && r.kind === "credit_drain" && typeof r.credit_id === "string" && typeof r.drain_id === "string" && (r.event === "requested" || r.event === "parked" || r.event === "picked_up" || r.event === "sent" || r.event === "released") && typeof r.method === "string" && typeof r.amount_micro === "number" && typeof r.issued_at === "number" && typeof r.caller_pubkey === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string";
|
|
303
|
+
}
|
|
304
|
+
function verifyDrainReceipt(receipt) {
|
|
305
|
+
try {
|
|
306
|
+
const { signature, ...unsigned } = receipt;
|
|
307
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
308
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
309
|
+
} catch {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
235
314
|
export {
|
|
236
315
|
IMPLICIT_CREDIT_TTL_MS,
|
|
237
316
|
COINGECKO_SIMPLE_PRICE_URL,
|
|
@@ -254,5 +333,15 @@ export {
|
|
|
254
333
|
fetchBtcUsdRate,
|
|
255
334
|
getLastKnownBtcRate,
|
|
256
335
|
formatStaleness,
|
|
257
|
-
formatAmountBestEffort
|
|
336
|
+
formatAmountBestEffort,
|
|
337
|
+
computeResultHash,
|
|
338
|
+
signReceipt,
|
|
339
|
+
verifyReceipt,
|
|
340
|
+
isSignedJobReceipt,
|
|
341
|
+
signDrainReceipt,
|
|
342
|
+
signFundingReceipt,
|
|
343
|
+
isFundingReceipt,
|
|
344
|
+
verifyFundingReceipt,
|
|
345
|
+
isDrainReceipt,
|
|
346
|
+
verifyDrainReceipt
|
|
258
347
|
};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
computeResultHash,
|
|
2
3
|
costAnchor,
|
|
3
4
|
formatUsd,
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
isDrainReceipt,
|
|
6
|
+
isFundingReceipt,
|
|
7
|
+
msatsToUsd,
|
|
8
|
+
verifyDrainReceipt,
|
|
9
|
+
verifyFundingReceipt,
|
|
10
|
+
verifyReceipt
|
|
11
|
+
} from "./chunk-PAIM66YA.js";
|
|
6
12
|
import {
|
|
7
13
|
AGENT_MNEMONIC_FILE,
|
|
8
14
|
BUILDER_CONFIG_DIR,
|
|
@@ -13,7 +19,7 @@ import {
|
|
|
13
19
|
} from "./chunk-CZULM42S.js";
|
|
14
20
|
import {
|
|
15
21
|
canonicaliseForSigning
|
|
16
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-OFVV37XC.js";
|
|
17
23
|
import {
|
|
18
24
|
callerLoggers
|
|
19
25
|
} from "./chunk-66HGCPBU.js";
|
|
@@ -1167,82 +1173,6 @@ function hexToBytes2(hex) {
|
|
|
1167
1173
|
return out;
|
|
1168
1174
|
}
|
|
1169
1175
|
|
|
1170
|
-
// src/lib/receipt.ts
|
|
1171
|
-
import { schnorr as schnorr3 } from "@noble/curves/secp256k1.js";
|
|
1172
|
-
import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
|
|
1173
|
-
import { bytesToHex as bytesToHex3, hexToBytes as hexToBytes3 } from "@noble/hashes/utils.js";
|
|
1174
|
-
function computeResultHash(summary, artifactContents) {
|
|
1175
|
-
const artifactHashes = artifactContents.map(
|
|
1176
|
-
(content) => bytesToHex3(sha2563(canonicaliseForSigning(content)))
|
|
1177
|
-
);
|
|
1178
|
-
return bytesToHex3(
|
|
1179
|
-
sha2563(
|
|
1180
|
-
canonicaliseForSigning({
|
|
1181
|
-
summary: summary ?? null,
|
|
1182
|
-
artifact_hashes: artifactHashes
|
|
1183
|
-
})
|
|
1184
|
-
)
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
function signReceipt(unsigned, secretHex) {
|
|
1188
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1189
|
-
const signature = bytesToHex3(schnorr3.sign(bytes, hexToBytes3(secretHex)));
|
|
1190
|
-
return { ...unsigned, signature };
|
|
1191
|
-
}
|
|
1192
|
-
function verifyReceipt(receipt) {
|
|
1193
|
-
try {
|
|
1194
|
-
const { signature, ...unsigned } = receipt;
|
|
1195
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1196
|
-
return schnorr3.verify(hexToBytes3(signature), bytes, hexToBytes3(receipt.receipt_pubkey));
|
|
1197
|
-
} catch {
|
|
1198
|
-
return false;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
function isSignedJobReceipt(value) {
|
|
1202
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1203
|
-
const r = value;
|
|
1204
|
-
const paid = r.paid;
|
|
1205
|
-
return r.v === 1 && typeof r.job_id === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.capability === "string" && (r.outcome === "completed" || r.outcome === "failed" || r.outcome === "cancelled") && typeof r.seq === "number" && typeof r.issued_at === "number" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string" && !!paid && typeof paid === "object" && !Array.isArray(paid) && typeof paid.msats === "number";
|
|
1206
|
-
}
|
|
1207
|
-
function signDrainReceipt(unsigned, secretHex) {
|
|
1208
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1209
|
-
const signature = bytesToHex3(schnorr3.sign(bytes, hexToBytes3(secretHex)));
|
|
1210
|
-
return { ...unsigned, signature };
|
|
1211
|
-
}
|
|
1212
|
-
function signFundingReceipt(unsigned, secretHex) {
|
|
1213
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1214
|
-
const signature = bytesToHex3(schnorr3.sign(bytes, hexToBytes3(secretHex)));
|
|
1215
|
-
return { ...unsigned, signature };
|
|
1216
|
-
}
|
|
1217
|
-
function isFundingReceipt(value) {
|
|
1218
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1219
|
-
const r = value;
|
|
1220
|
-
return r.v === 1 && r.kind === "credit_funding" && typeof r.credit_id === "string" && typeof r.fund_id === "string" && typeof r.funded_micro === "number" && typeof r.balance_after_micro === "number" && typeof r.ledger_seq === "number" && typeof r.issued_at === "number" && typeof r.caller_pubkey === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string";
|
|
1221
|
-
}
|
|
1222
|
-
function verifyFundingReceipt(receipt) {
|
|
1223
|
-
try {
|
|
1224
|
-
const { signature, ...unsigned } = receipt;
|
|
1225
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1226
|
-
return schnorr3.verify(hexToBytes3(signature), bytes, hexToBytes3(receipt.receipt_pubkey));
|
|
1227
|
-
} catch {
|
|
1228
|
-
return false;
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
function isDrainReceipt(value) {
|
|
1232
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1233
|
-
const r = value;
|
|
1234
|
-
return r.v === 1 && r.kind === "credit_drain" && typeof r.credit_id === "string" && typeof r.drain_id === "string" && (r.event === "requested" || r.event === "parked" || r.event === "picked_up" || r.event === "sent" || r.event === "released") && typeof r.method === "string" && typeof r.amount_micro === "number" && typeof r.issued_at === "number" && typeof r.caller_pubkey === "string" && typeof r.dvm_id === "string" && typeof r.dvm === "string" && typeof r.receipt_pubkey === "string" && typeof r.signature === "string";
|
|
1235
|
-
}
|
|
1236
|
-
function verifyDrainReceipt(receipt) {
|
|
1237
|
-
try {
|
|
1238
|
-
const { signature, ...unsigned } = receipt;
|
|
1239
|
-
const bytes = canonicaliseForSigning(unsigned);
|
|
1240
|
-
return schnorr3.verify(hexToBytes3(signature), bytes, hexToBytes3(receipt.receipt_pubkey));
|
|
1241
|
-
} catch {
|
|
1242
|
-
return false;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
1176
|
// src/lib/receipt-verify.ts
|
|
1247
1177
|
function attestedDvmIdentity(builder) {
|
|
1248
1178
|
const builderPubkey = authenticatedBuilderPubkey(builder);
|
|
@@ -1543,7 +1473,7 @@ function derivePubkeyFromPrivkey(privkey) {
|
|
|
1543
1473
|
"Provide a valid secp256k1 private key as a 64-char hex string."
|
|
1544
1474
|
);
|
|
1545
1475
|
}
|
|
1546
|
-
const bytes =
|
|
1476
|
+
const bytes = hexToBytes3(privkey);
|
|
1547
1477
|
if (!secp256k12.utils.isValidSecretKey(bytes)) {
|
|
1548
1478
|
throw new DvmError(
|
|
1549
1479
|
"invalid_privkey",
|
|
@@ -1552,17 +1482,17 @@ function derivePubkeyFromPrivkey(privkey) {
|
|
|
1552
1482
|
);
|
|
1553
1483
|
}
|
|
1554
1484
|
const pub = secp256k12.getPublicKey(bytes);
|
|
1555
|
-
return
|
|
1485
|
+
return bytesToHex3(pub);
|
|
1556
1486
|
}
|
|
1557
|
-
function
|
|
1487
|
+
function bytesToHex3(bytes) {
|
|
1558
1488
|
return Buffer.from(bytes).toString("hex");
|
|
1559
1489
|
}
|
|
1560
|
-
function
|
|
1490
|
+
function hexToBytes3(hex) {
|
|
1561
1491
|
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
1562
1492
|
}
|
|
1563
1493
|
|
|
1564
1494
|
// src/lib/wallet-agent/sign.ts
|
|
1565
|
-
import { schnorr as
|
|
1495
|
+
import { schnorr as schnorr3 } from "@noble/curves/secp256k1.js";
|
|
1566
1496
|
var PUBKEY_COMPRESSED_HEX_RE = /^0[23][0-9a-f]{64}$/i;
|
|
1567
1497
|
var PUBKEY_XONLY_HEX_RE = /^[0-9a-f]{64}$/i;
|
|
1568
1498
|
var SIG_HEX_RE = /^[0-9a-f]{128}$/i;
|
|
@@ -1581,42 +1511,42 @@ function signChallenge(privkeyHex, challenge) {
|
|
|
1581
1511
|
"Pass the SHA-256 digest output (32 bytes)."
|
|
1582
1512
|
);
|
|
1583
1513
|
}
|
|
1584
|
-
const sig =
|
|
1585
|
-
return
|
|
1514
|
+
const sig = schnorr3.sign(challenge, hexToBytes4(privkeyHex));
|
|
1515
|
+
return bytesToHex4(sig);
|
|
1586
1516
|
}
|
|
1587
1517
|
function verifyChallenge(pubkeyHex, challenge, sigHex) {
|
|
1588
1518
|
if (!SIG_HEX_RE.test(sigHex)) return false;
|
|
1589
1519
|
if (challenge.length !== 32) return false;
|
|
1590
1520
|
let xonly;
|
|
1591
1521
|
if (PUBKEY_COMPRESSED_HEX_RE.test(pubkeyHex)) {
|
|
1592
|
-
xonly =
|
|
1522
|
+
xonly = hexToBytes4(pubkeyHex.slice(2));
|
|
1593
1523
|
} else if (PUBKEY_XONLY_HEX_RE.test(pubkeyHex)) {
|
|
1594
|
-
xonly =
|
|
1524
|
+
xonly = hexToBytes4(pubkeyHex);
|
|
1595
1525
|
} else {
|
|
1596
1526
|
return false;
|
|
1597
1527
|
}
|
|
1598
1528
|
try {
|
|
1599
|
-
return
|
|
1529
|
+
return schnorr3.verify(hexToBytes4(sigHex), challenge, xonly);
|
|
1600
1530
|
} catch {
|
|
1601
1531
|
return false;
|
|
1602
1532
|
}
|
|
1603
1533
|
}
|
|
1604
|
-
function
|
|
1534
|
+
function hexToBytes4(hex) {
|
|
1605
1535
|
return Uint8Array.from(Buffer.from(hex, "hex"));
|
|
1606
1536
|
}
|
|
1607
|
-
function
|
|
1537
|
+
function bytesToHex4(bytes) {
|
|
1608
1538
|
return Buffer.from(bytes).toString("hex");
|
|
1609
1539
|
}
|
|
1610
1540
|
|
|
1611
1541
|
// src/lib/cashu/admin-auth.ts
|
|
1612
1542
|
import { randomBytes } from "crypto";
|
|
1613
|
-
import { sha256 as
|
|
1543
|
+
import { sha256 as sha2563 } from "@noble/hashes/sha2.js";
|
|
1614
1544
|
var ADMIN_AUTH_NONCE_TTL_SECONDS = 300;
|
|
1615
1545
|
var ADMIN_AUTH_CLOCK_SKEW_SECONDS = 30;
|
|
1616
1546
|
var ADMIN_STATE_UNAVAILABLE = "admin_state_unavailable";
|
|
1617
1547
|
function buildAdminChallenge(args) {
|
|
1618
1548
|
const msg = `dvmkit-admin:${args.method}:${args.path}:${args.dvmId}:${args.nonceHex}:${args.unixSeconds}`;
|
|
1619
|
-
return
|
|
1549
|
+
return sha2563(new TextEncoder().encode(msg));
|
|
1620
1550
|
}
|
|
1621
1551
|
function buildAdminAuthHeader(args) {
|
|
1622
1552
|
const nowMs = args.now ? args.now() : Date.now();
|
|
@@ -1739,16 +1669,6 @@ export {
|
|
|
1739
1669
|
buildAttestation,
|
|
1740
1670
|
signAttestation,
|
|
1741
1671
|
verifyAttestation,
|
|
1742
|
-
computeResultHash,
|
|
1743
|
-
signReceipt,
|
|
1744
|
-
verifyReceipt,
|
|
1745
|
-
isSignedJobReceipt,
|
|
1746
|
-
signDrainReceipt,
|
|
1747
|
-
signFundingReceipt,
|
|
1748
|
-
isFundingReceipt,
|
|
1749
|
-
verifyFundingReceipt,
|
|
1750
|
-
isDrainReceipt,
|
|
1751
|
-
verifyDrainReceipt,
|
|
1752
1672
|
attestedDvmIdentity,
|
|
1753
1673
|
authenticatedBuilderPubkey,
|
|
1754
1674
|
verifyJobReceipt,
|
|
@@ -2,19 +2,19 @@ import {
|
|
|
2
2
|
connectedTempoAccount,
|
|
3
3
|
tempoBalanceCheckHint,
|
|
4
4
|
tempoTokenReference
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GFY5FRX3.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-B2IROPQF.js";
|
|
13
13
|
import {
|
|
14
14
|
costAnchor,
|
|
15
15
|
formatUsd,
|
|
16
16
|
formatUsdcMicrounits
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-PAIM66YA.js";
|
|
18
18
|
import {
|
|
19
19
|
IDENTITIES_FILE,
|
|
20
20
|
TEMPO_CHANNELS_FILE,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { cf as HostingCleanupFence, cV as HostedIntent, ah as FundingMethod, o as PaymentMethod, bN as CreditLedgerLike, a1 as Message, X as FundingReceipt, bP as CreditSnapshot, Y as JobReceipt, S as SDKJobContext, aw as StepCache, u as ResponseContent, P as PaymentContent, a2 as MessageType, bj as X402Receipt, aE as X402Config, bi as X402ExactVersionSupport, cW as X402SettlementIntent, aq as PaymentRequirementsV2, cX as HostedFundingReservation, c2 as CreditLedgerQuerier, cY as X402SettlementCursor, bR as X402SettlementStatus, cZ as X402SettlementWriteOff, bO as X402RefundSettlementGate, c_ as X402FacilitatorAuth, c$ as X402BatchSettlementConfig, cB as PostgresX402ChannelStorage, d0 as X402PayoutObserver, bL as HostedSettlementReportObligations, br as MppxServer,
|
|
1
|
+
import { cf as HostingCleanupFence, cV as HostedIntent, ah as FundingMethod, o as PaymentMethod, bN as CreditLedgerLike, a1 as Message, X as FundingReceipt, bP as CreditSnapshot, Y as JobReceipt, S as SDKJobContext, aw as StepCache, u as ResponseContent, P as PaymentContent, a2 as MessageType, bj as X402Receipt, aE as X402Config, bi as X402ExactVersionSupport, cW as X402SettlementIntent, aq as PaymentRequirementsV2, cX as HostedFundingReservation, c2 as CreditLedgerQuerier, cY as X402SettlementCursor, bR as X402SettlementStatus, cZ as X402SettlementWriteOff, bO as X402RefundSettlementGate, c_ as X402FacilitatorAuth, c$ as X402BatchSettlementConfig, cB as PostgresX402ChannelStorage, d0 as X402PayoutObserver, bL as HostedSettlementReportObligations, br as MppxServer, ac as CashuMode, d1 as CreditDepositEnqueue, d2 as X402SettlementReconciliationReason, ao as PaymentRequirements, a0 as MppxCredential, bm as CreditDepositPayload, bQ as DrawResult, cp as CreditLedgerError, a7 as ReceiptCredit, ae as DrainReceiptEvent, a6 as DrainReceipt, K as KVStore, y as SignedRequestAudience, d3 as CreditDrawReleaseEnqueue, cz as JobCostReportPayload, cA as JobTerminalReportPayload, cD as RevenueSkippedNoRailPayload, Z as ZodLike, a as DVMDescriptor, bW as CreditInvoiceRecord, bX as InvoiceSettlement, cj as ClientCompatibilityGate, ch as ClientCompatibility, bv as PostgresTempoSessionStore, bu as PayoutReporter, R as ResolvedCreditConfig, g as CreditView } from './step-cache-QG_h5-3G.js';
|
|
2
2
|
import { ProofLike, SerializedDLEQ, Proof } from '@cashu/cashu-ts';
|
|
3
3
|
import { Hono, Context } from 'hono';
|
|
4
4
|
import { Pool } from 'pg';
|
|
5
|
-
import { b as FxRateSnapshot, F as FxFetcher } from './fx-
|
|
5
|
+
import { b as FxRateSnapshot, F as FxFetcher } from './fx-D9nsN3n4.js';
|
|
6
6
|
import { Store, Challenge } from 'mppx';
|
|
7
|
-
import { g as LockPubkey, f as CheckMintHealthOptions, b as LightningBackend, A as AttestationPayload } from './lightning-backend-
|
|
8
|
-
import { T as TopUpCapUnenforcedReason, A as AppendOutgoingOptions, J as JobRecord, b as JobStore } from './job-store-
|
|
7
|
+
import { g as LockPubkey, f as CheckMintHealthOptions, b as LightningBackend, A as AttestationPayload } from './lightning-backend-BAx2Y8pP.js';
|
|
8
|
+
import { T as TopUpCapUnenforcedReason, A as AppendOutgoingOptions, J as JobRecord, b as JobStore } from './job-store-Bx-VFRjg.js';
|
|
9
9
|
import { SettleResponse, SupportedResponse } from '@x402/core/types';
|
|
10
10
|
import { Channel, AutoSettlementConfig } from '@x402/evm/batch-settlement/server';
|
|
11
11
|
import { FacilitatorClient } from '@x402/core/server';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Currency, Z as ZodLike, D as DVMConfig, a as DVMDescriptor } from './step-cache-
|
|
2
|
-
export { A as ApprovalContent, b as ArtifactContent, c as CancelContent, d as CanonicalEnvelope, e as CreateSignedRequestVerifierOpts, f as CreditConfig, g as CreditView, h as DEFAULT_CREDIT_MAX, i as DEFAULT_CREDIT_MIN, j as DEFAULT_CREDIT_TTL_SECONDS, k as DEFAULT_JOB_RETENTION_DAYS, l as DVMRouteContext, I as IncomingMessage, m as InputType, n as InvalidCurrencyError, J as JobCost, K as KVStore, L as Logger, P as PaymentContent, o as PaymentMethod, p as PriceValue, q as ProgressContent, r as PromptOpts, Q as QuoteConfig, s as QuoteContext, t as QuoteResult, R as ResolvedCreditConfig, u as ResponseContent, S as SDKJobContext, v as SDKPaymentRequestOpts, w as SIGNED_REQUEST_AUTH_ID, x as SIGNED_REQUEST_STATEMENT_VERSION, y as SignedRequestAudience, z as SignedRequestDomain, B as SignedRequestError, E as SignedRequestFailure, F as SignedRequestReplayStore, G as SignedRequestSignOpts, H as SignedRequestStatementHeader, M as SignedRequestVerifier, U as UnsupportedCurrencyError, N as createSignedRequestVerifier, O as isZodSchema, T as signedRequestStatementHeader, V as validateCurrency } from './step-cache-
|
|
3
|
-
export { C as CreateFxFetcherOpts, D as DEFAULT_FX_CURRENCIES, a as DEFAULT_FX_RATE_SOURCE, F as FxFetcher, b as FxRateSnapshot, c as FxRateUnavailableError, P as PlatformFxSource, d as createFxFetcher, f as fxRateFor, r as resolveFxSourceFromEnv } from './fx-
|
|
4
|
-
export { I as InvalidFxRateError, f as fiatToSatsCeil, a as formatFiat, b as formatUsd, r as roundUsd, s as satsToFiat } from './usd-
|
|
5
|
-
export { J as JobRecord, a as JobStatus, b as JobStore } from './job-store-
|
|
1
|
+
import { C as Currency, Z as ZodLike, D as DVMConfig, a as DVMDescriptor } from './step-cache-QG_h5-3G.js';
|
|
2
|
+
export { A as ApprovalContent, b as ArtifactContent, c as CancelContent, d as CanonicalEnvelope, e as CreateSignedRequestVerifierOpts, f as CreditConfig, g as CreditView, h as DEFAULT_CREDIT_MAX, i as DEFAULT_CREDIT_MIN, j as DEFAULT_CREDIT_TTL_SECONDS, k as DEFAULT_JOB_RETENTION_DAYS, l as DVMRouteContext, I as IncomingMessage, m as InputType, n as InvalidCurrencyError, J as JobCost, K as KVStore, L as Logger, P as PaymentContent, o as PaymentMethod, p as PriceValue, q as ProgressContent, r as PromptOpts, Q as QuoteConfig, s as QuoteContext, t as QuoteResult, R as ResolvedCreditConfig, u as ResponseContent, S as SDKJobContext, v as SDKPaymentRequestOpts, w as SIGNED_REQUEST_AUTH_ID, x as SIGNED_REQUEST_STATEMENT_VERSION, y as SignedRequestAudience, z as SignedRequestDomain, B as SignedRequestError, E as SignedRequestFailure, F as SignedRequestReplayStore, G as SignedRequestSignOpts, H as SignedRequestStatementHeader, M as SignedRequestVerifier, U as UnsupportedCurrencyError, N as createSignedRequestVerifier, O as isZodSchema, T as signedRequestStatementHeader, V as validateCurrency } from './step-cache-QG_h5-3G.js';
|
|
3
|
+
export { C as CreateFxFetcherOpts, D as DEFAULT_FX_CURRENCIES, a as DEFAULT_FX_RATE_SOURCE, F as FxFetcher, b as FxRateSnapshot, c as FxRateUnavailableError, P as PlatformFxSource, d as createFxFetcher, f as fxRateFor, r as resolveFxSourceFromEnv } from './fx-D9nsN3n4.js';
|
|
4
|
+
export { I as InvalidFxRateError, f as fiatToSatsCeil, a as formatFiat, b as formatUsd, r as roundUsd, s as satsToFiat } from './usd-EwRqCPF-.js';
|
|
5
|
+
export { J as JobRecord, a as JobStatus, b as JobStore } from './job-store-Bx-VFRjg.js';
|
|
6
6
|
export { P as PinnedFetch, S as SSRFError, a as SSRFGuardOpts, b as SSRFReason, c as SSRFResolver, d as assertSafeUrl, e as createPinnedFetch } from './ssrf-dMooihtY.js';
|
|
7
7
|
export { z } from 'zod';
|
|
8
8
|
import 'hono';
|