@dvmkit/sdk 0.10.1 → 0.12.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-STJBBVNL.js → chunk-2VGMZ7VF.js} +487 -71
- package/dist/{chunk-3Q6FTZDB.js → chunk-3YFFZLW7.js} +2 -2
- package/dist/{chunk-VMHYGKWT.js → chunk-566CFXGU.js} +9 -1
- package/dist/chunk-5H7P3ORL.js +92 -0
- package/dist/{chunk-3R7NQA3Z.js → chunk-7KQLPVV7.js} +1 -1
- package/dist/{chunk-JNECYURT.js → chunk-D4FFS3IS.js} +1 -1
- package/dist/{chunk-VTHYQCDB.js → chunk-E7ZBCT5U.js} +1 -1
- package/dist/{chunk-MMGSYMIC.js → chunk-EP7OVWI5.js} +1 -1
- package/dist/{chunk-LDIPVPKI.js → chunk-FFRTAQUW.js} +1 -1
- package/dist/chunk-H3GGFEE5.js +57 -0
- package/dist/{chunk-M3T5JYDJ.js → chunk-HNXMWHLU.js} +1 -1
- package/dist/{chunk-UKD3R2KU.js → chunk-HW2UCOOC.js} +4 -55
- package/dist/{chunk-FFXXGCVG.js → chunk-ITRSITFP.js} +1 -1
- package/dist/{chunk-MU3IE434.js → chunk-JLT2YIBS.js} +267 -52
- package/dist/{chunk-KFCEXCZM.js → chunk-KJZVTWMX.js} +1 -1
- package/dist/{chunk-W3VGCNG6.js → chunk-LDKV4UHI.js} +1 -1
- package/dist/{chunk-AJ6UHXUA.js → chunk-M4NFYEEY.js} +1 -1
- package/dist/{chunk-MB6R4XPZ.js → chunk-NS2OMIU7.js} +15 -3
- package/dist/{chunk-YOSZIWC3.js → chunk-POYUX2NN.js} +149 -11
- package/dist/{chunk-VUGEEMLT.js → chunk-RPUFWIT4.js} +11 -89
- package/dist/{chunk-SYBFMHXQ.js → chunk-S7PIFHE4.js} +590 -67
- package/dist/{chunk-2OGBZPPJ.js → chunk-TWKQFIOW.js} +21 -3
- package/dist/{chunk-EWZFANHJ.js → chunk-VWIMQ5H5.js} +1 -1
- package/dist/{chunk-2XQLL6N6.js → chunk-WFCVS6QB.js} +2 -2
- package/dist/{chunk-QGNXYVBO.js → chunk-Z4FOPROB.js} +17 -0
- package/dist/{content-retention-CrILCNxk.d.ts → content-retention-a1yRdmhI.d.ts} +1 -1
- package/dist/{credit-ledger-4PZNAMDT.js → credit-ledger-MF23UKRJ.js} +6 -3
- package/dist/{credit-menu-BWsVqMh-.d.ts → credit-menu-B2T-O9oY.d.ts} +11 -4
- package/dist/{fx-BM5h4o5S.d.ts → fx-DLhscRUh.d.ts} +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -5
- package/dist/internal/caller.d.ts +8 -6
- package/dist/internal/caller.js +27 -22
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +24 -22
- package/dist/{job-store-92v8e1LQ.d.ts → job-store-B8Ijr5V6.d.ts} +3 -1
- package/dist/{lightning-backend-9oky_wJi.d.ts → lightning-backend-DmwMSgaM.d.ts} +1 -1
- package/dist/memory-credit-ledger-ERD764PS.js +14 -0
- package/dist/{mpp-setup-FURD45LI.js → mpp-setup-JU3MT7QX.js} +3 -3
- package/dist/{payout-reporter-HVJ6WUF3.js → payout-reporter-NXWQVKXW.js} +2 -2
- package/dist/{postgres-consumed-credential-store-WO6OCFXZ.js → postgres-consumed-credential-store-WXJLM6J7.js} +1 -1
- package/dist/{postgres-job-store-H45PRBLA.js → postgres-job-store-ZVMAN6L2.js} +2 -2
- package/dist/{postgres-replay-store-XXJSA457.js → postgres-replay-store-QJ4FG6AR.js} +2 -2
- package/dist/{pricing-X4XU5HXY.js → pricing-KCLENT2C.js} +3 -3
- package/dist/{revenue-reporter-EV3K5L6B.js → revenue-reporter-HD4GMXGD.js} +2 -2
- package/dist/server/index.d.ts +30 -12
- package/dist/server/index.js +32 -30
- package/dist/{step-cache--7yA5Ihr.d.ts → step-cache-DQqpwXa8.d.ts} +206 -47
- package/dist/{tempo-charge-store-5JOIYUIH.js → tempo-charge-store-7LTUAQHQ.js} +2 -2
- package/dist/{tempo-session-store-S6QMLQUA.js → tempo-session-store-LYAIDR2B.js} +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +6 -6
- package/dist/{usd-C7lvLvLk.d.ts → usd-D5kk2nIT.d.ts} +1 -1
- package/dist/{x402-EN5LSOVM.js → x402-RUJ4LUKF.js} +3 -3
- package/package.json +1 -1
- package/recipes/postgres/financial-export-v1.sql +19 -5
- package/dist/memory-credit-ledger-RP7DT5IY.js +0 -11
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
createX402FacilitatorAuthHeaders,
|
|
3
3
|
settleWithFacilitator,
|
|
4
4
|
verifyWithFacilitator
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-E7ZBCT5U.js";
|
|
6
6
|
import {
|
|
7
7
|
buildPaymentRequirements,
|
|
8
8
|
decodePayment,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./chunk-66HGCPBU.js";
|
|
16
16
|
import {
|
|
17
17
|
diagnosticConsole
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-Z4FOPROB.js";
|
|
19
19
|
|
|
20
20
|
// src/lib/x402/verify.ts
|
|
21
21
|
async function verifyX402Payment(paymentHeader, config, requiredUsdcMicro, resource, btcUsdRate, exactVersions = { v1: true, v2: true }) {
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-COYKJRMM.js";
|
|
4
4
|
import {
|
|
5
5
|
diagnosticConsole
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-Z4FOPROB.js";
|
|
7
7
|
|
|
8
8
|
// src/sdk/server/revenue-reporter.ts
|
|
9
9
|
import { randomUUID } from "crypto";
|
|
@@ -13,6 +13,7 @@ var ENDPOINTS = {
|
|
|
13
13
|
cost: "/_internal/job-cost",
|
|
14
14
|
deposit: "/_internal/credit-deposit",
|
|
15
15
|
release: "/_internal/credit-draw-release",
|
|
16
|
+
refund: "/_internal/credit-draw-refund",
|
|
16
17
|
drain: "/_internal/credit-drain",
|
|
17
18
|
payout: "/_internal/payout",
|
|
18
19
|
expiry_release: "/_internal/credit-expiry-release"
|
|
@@ -166,6 +167,10 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
166
167
|
async enqueueDeposit(tx, payload) {
|
|
167
168
|
await this.insertPending(tx, "deposit", payload);
|
|
168
169
|
}
|
|
170
|
+
/** Persist without network delivery before the refund accounting transaction commits. */
|
|
171
|
+
async enqueueCreditDrawRefund(tx, payload) {
|
|
172
|
+
await this.insertPending(tx, "refund", payload);
|
|
173
|
+
}
|
|
169
174
|
/** Join a released draw to the transaction that made the hold terminal. */
|
|
170
175
|
async enqueueCreditDrawRelease(tx, payload) {
|
|
171
176
|
await this.insertPending(tx, "release", payload);
|
|
@@ -620,6 +625,9 @@ var RevenueReporter = class _RevenueReporter {
|
|
|
620
625
|
diagnosticConsole.log(`[revenue-reporter] reported ${kind} ${label}`);
|
|
621
626
|
return;
|
|
622
627
|
}
|
|
628
|
+
if (kind === "refund" && res.status === 409) {
|
|
629
|
+
throw new Error("Original draw revenue has not arrived yet");
|
|
630
|
+
}
|
|
623
631
|
if (res.status === 401) {
|
|
624
632
|
await this.markStale(id, "token_rotated");
|
|
625
633
|
diagnosticConsole.warn(
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicaliseForSigning
|
|
3
|
+
} from "./chunk-H3GGFEE5.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/receipt.ts
|
|
6
|
+
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
7
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
8
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
9
|
+
function computeResultHash(summary, artifactContents) {
|
|
10
|
+
const artifactHashes = artifactContents.map(
|
|
11
|
+
(content) => bytesToHex(sha256(canonicaliseForSigning(content)))
|
|
12
|
+
);
|
|
13
|
+
return bytesToHex(
|
|
14
|
+
sha256(
|
|
15
|
+
canonicaliseForSigning({
|
|
16
|
+
summary: summary ?? null,
|
|
17
|
+
artifact_hashes: artifactHashes
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function signReceipt(unsigned, secretHex) {
|
|
23
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
24
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
25
|
+
return { ...unsigned, signature };
|
|
26
|
+
}
|
|
27
|
+
function verifyReceipt(receipt) {
|
|
28
|
+
try {
|
|
29
|
+
const { signature, ...unsigned } = receipt;
|
|
30
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
31
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function isSignedJobReceipt(value) {
|
|
37
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
38
|
+
const r = value;
|
|
39
|
+
const paid = r.paid;
|
|
40
|
+
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";
|
|
41
|
+
}
|
|
42
|
+
function signDrainReceipt(unsigned, secretHex) {
|
|
43
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
44
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
45
|
+
return { ...unsigned, signature };
|
|
46
|
+
}
|
|
47
|
+
function signFundingReceipt(unsigned, secretHex) {
|
|
48
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
49
|
+
const signature = bytesToHex(schnorr.sign(bytes, hexToBytes(secretHex)));
|
|
50
|
+
return { ...unsigned, signature };
|
|
51
|
+
}
|
|
52
|
+
function isFundingReceipt(value) {
|
|
53
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
54
|
+
const r = value;
|
|
55
|
+
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";
|
|
56
|
+
}
|
|
57
|
+
function verifyFundingReceipt(receipt) {
|
|
58
|
+
try {
|
|
59
|
+
const { signature, ...unsigned } = receipt;
|
|
60
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
61
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function isDrainReceipt(value) {
|
|
67
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
68
|
+
const r = value;
|
|
69
|
+
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";
|
|
70
|
+
}
|
|
71
|
+
function verifyDrainReceipt(receipt) {
|
|
72
|
+
try {
|
|
73
|
+
const { signature, ...unsigned } = receipt;
|
|
74
|
+
const bytes = canonicaliseForSigning(unsigned);
|
|
75
|
+
return schnorr.verify(hexToBytes(signature), bytes, hexToBytes(receipt.receipt_pubkey));
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
computeResultHash,
|
|
83
|
+
signReceipt,
|
|
84
|
+
verifyReceipt,
|
|
85
|
+
isSignedJobReceipt,
|
|
86
|
+
signDrainReceipt,
|
|
87
|
+
signFundingReceipt,
|
|
88
|
+
isFundingReceipt,
|
|
89
|
+
verifyFundingReceipt,
|
|
90
|
+
isDrainReceipt,
|
|
91
|
+
verifyDrainReceipt
|
|
92
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
canonicaliseForSigning
|
|
3
|
+
} from "./chunk-H3GGFEE5.js";
|
|
4
|
+
|
|
1
5
|
// src/sdk/types.ts
|
|
2
6
|
function isZodSchema(value) {
|
|
3
7
|
return typeof value === "object" && value !== null && "_zod" in value && "parse" in value && "safeParse" in value;
|
|
@@ -12,58 +16,6 @@ var DEFAULT_CREDIT_MAX = "$5.00";
|
|
|
12
16
|
var DEFAULT_CREDIT_TTL_SECONDS = 30 * 24 * 60 * 60;
|
|
13
17
|
var DEFAULT_JOB_RETENTION_DAYS = 730;
|
|
14
18
|
|
|
15
|
-
// src/lib/cast-auth/canonical-json.ts
|
|
16
|
-
function canonicalize(value) {
|
|
17
|
-
return JSON.stringify(sortDeep(value));
|
|
18
|
-
}
|
|
19
|
-
function canonicaliseForSigning(value) {
|
|
20
|
-
return new TextEncoder().encode(canonicalize(value));
|
|
21
|
-
}
|
|
22
|
-
function sortDeep(value) {
|
|
23
|
-
if (value === null) return null;
|
|
24
|
-
if (typeof value === "string" || typeof value === "boolean") return value;
|
|
25
|
-
if (typeof value === "number") {
|
|
26
|
-
if (!Number.isFinite(value)) {
|
|
27
|
-
throw new TypeError(`canonicalize: non-finite number is not JSON-serialisable`);
|
|
28
|
-
}
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
if (Array.isArray(value)) return value.map(sortDeep);
|
|
32
|
-
if (typeof value === "object") {
|
|
33
|
-
const sorted = {};
|
|
34
|
-
for (const key of Object.keys(value).sort()) {
|
|
35
|
-
const v = value[key];
|
|
36
|
-
if (v === void 0) continue;
|
|
37
|
-
sorted[key] = sortDeep(v);
|
|
38
|
-
}
|
|
39
|
-
return sorted;
|
|
40
|
-
}
|
|
41
|
-
throw new TypeError(`canonicalize: unsupported value of type ${typeof value}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// src/lib/cast-auth/verify.ts
|
|
45
|
-
import { schnorr } from "@noble/curves/secp256k1.js";
|
|
46
|
-
function verifyCanonicalSignedRequest(payload, signatureHex, pubkeyHex) {
|
|
47
|
-
if (!/^[0-9a-f]{64}$/i.test(pubkeyHex) || !/^[0-9a-f]{128}$/i.test(signatureHex)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
const data = canonicaliseForSigning(payload);
|
|
51
|
-
const signature = hexToBytes(signatureHex);
|
|
52
|
-
const pubkey = hexToBytes(pubkeyHex);
|
|
53
|
-
try {
|
|
54
|
-
return schnorr.verify(signature, data, pubkey);
|
|
55
|
-
} catch {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function hexToBytes(hex) {
|
|
60
|
-
const out = new Uint8Array(hex.length / 2);
|
|
61
|
-
for (let i = 0; i < out.length; i++) {
|
|
62
|
-
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
63
|
-
}
|
|
64
|
-
return out;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
19
|
// src/lib/signed-request-statement.ts
|
|
68
20
|
var SIGNED_REQUEST_AUTH_ID = "secp256k1-schnorr-v2";
|
|
69
21
|
var SIGNED_REQUEST_STATEMENT_VERSION = 2;
|
|
@@ -129,9 +81,6 @@ export {
|
|
|
129
81
|
DEFAULT_CREDIT_MAX,
|
|
130
82
|
DEFAULT_CREDIT_TTL_SECONDS,
|
|
131
83
|
DEFAULT_JOB_RETENTION_DAYS,
|
|
132
|
-
canonicalize,
|
|
133
|
-
canonicaliseForSigning,
|
|
134
|
-
verifyCanonicalSignedRequest,
|
|
135
84
|
SIGNED_REQUEST_AUTH_ID,
|
|
136
85
|
SIGNED_REQUEST_STATEMENT_VERSION,
|
|
137
86
|
signedRequestStatementHeader,
|