@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.
Files changed (70) hide show
  1. package/README.md +4 -0
  2. package/dist/{chunk-S3OY533W.js → chunk-26W6GPCD.js} +48 -6
  3. package/dist/{chunk-FWGWLPXF.js → chunk-2OM2QPBE.js} +2 -2
  4. package/dist/{chunk-GY66THYI.js → chunk-3UK3CDOT.js} +186 -90
  5. package/dist/{chunk-CXCQLOOK.js → chunk-62FI3NJF.js} +42 -107
  6. package/dist/{chunk-VHNPVGSA.js → chunk-6STC5TCP.js} +3 -3
  7. package/dist/{chunk-N5RZ5HVB.js → chunk-72V5DTEC.js} +2 -2
  8. package/dist/chunk-A262WVYX.js +6 -0
  9. package/dist/{chunk-QR2EF2NI.js → chunk-AQ7OX5NX.js} +2 -2
  10. package/dist/{chunk-BYCEKO65.js → chunk-CLIAFTUR.js} +102 -13
  11. package/dist/{chunk-GAOAYHZA.js → chunk-DNG4KGSC.js} +3 -3
  12. package/dist/{chunk-Z4ZT5LNT.js → chunk-GSLS4464.js} +3 -3
  13. package/dist/{chunk-RA2WIX7G.js → chunk-H5FVVEEN.js} +18 -7
  14. package/dist/{chunk-IXR5RFK7.js → chunk-HCE4MPZ5.js} +1 -1
  15. package/dist/{chunk-OML32F6I.js → chunk-I555L2WK.js} +1 -1
  16. package/dist/{chunk-EQLA4FFY.js → chunk-IIZQNDQU.js} +3 -3
  17. package/dist/{chunk-FUJ36YDV.js → chunk-KXWROQGK.js} +24 -1
  18. package/dist/{chunk-ETXDTUJO.js → chunk-LAKP6FUI.js} +55 -0
  19. package/dist/{chunk-X7EZ5CLI.js → chunk-MON76YBJ.js} +3 -3
  20. package/dist/chunk-OFSOLHRX.js +120 -0
  21. package/dist/{chunk-IV6Q7NRW.js → chunk-RAGX6VG7.js} +2 -2
  22. package/dist/{chunk-KA6VN5FK.js → chunk-RXPHMS4C.js} +3 -3
  23. package/dist/{chunk-6XF3RVVX.js → chunk-SPYEJXI7.js} +5 -5
  24. package/dist/{chunk-P6QON7ER.js → chunk-TRNMTTPX.js} +1 -1
  25. package/dist/{chunk-RCM3P2HE.js → chunk-UKD3R2KU.js} +55 -4
  26. package/dist/chunk-USL7ZEXN.js +17 -0
  27. package/dist/{chunk-KMED3H3A.js → chunk-VB5OLOZH.js} +395 -231
  28. package/dist/{content-retention-DHyLdA6b.d.ts → content-retention-ChFSSVO0.d.ts} +1 -1
  29. package/dist/{credit-ledger-MCUXYKSJ.js → credit-ledger-7Z7LOCTN.js} +4 -4
  30. package/dist/{credit-menu-DjnkeEUU.d.ts → credit-menu-fy0DDigm.d.ts} +6 -6
  31. package/dist/{fx-zMWFzfrU.d.ts → fx-DM0_NYiE.d.ts} +1 -1
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +236 -16
  34. package/dist/internal/caller.d.ts +4968 -8286
  35. package/dist/internal/caller.js +4291 -8084
  36. package/dist/internal/index.js +1 -1
  37. package/dist/internal/server.d.ts +7 -7
  38. package/dist/internal/server.js +27 -30
  39. package/dist/{job-store-DdLXBpol.d.ts → job-store-DkfNE9sv.d.ts} +1 -1
  40. package/dist/{lightning-backend-Bw-qtAbt.d.ts → lightning-backend-C3Gf1XpP.d.ts} +2 -2
  41. package/dist/{memory-credit-ledger-SBSMGMDX.js → memory-credit-ledger-3WOS74UH.js} +5 -5
  42. package/dist/{mpp-setup-RF5FXGGV.js → mpp-setup-XB4KATMU.js} +2 -2
  43. package/dist/{payout-reporter-3Y2U55ZX.js → payout-reporter-WT7XYW42.js} +2 -2
  44. package/dist/{postgres-consumed-credential-store-BUVCAPLS.js → postgres-consumed-credential-store-W7UP33AH.js} +3 -3
  45. package/dist/{postgres-job-store-VHLQBJZC.js → postgres-job-store-3KGUGFRD.js} +2 -2
  46. package/dist/{postgres-replay-store-ARZSQ45X.js → postgres-replay-store-CVNJJOQG.js} +2 -2
  47. package/dist/{pricing-XT2IAPNE.js → pricing-QAVZUTZR.js} +12 -12
  48. package/dist/{revenue-reporter-MAERPYGK.js → revenue-reporter-7UR3W2SD.js} +2 -2
  49. package/dist/server/index.d.ts +10 -10
  50. package/dist/server/index.js +44 -48
  51. package/dist/{step-cache-2MkvenJn.d.ts → step-cache-DDTwd4SK.d.ts} +6 -2
  52. package/dist/{tempo-charge-store-Q3D7KYMH.js → tempo-charge-store-GA6CED6O.js} +2 -2
  53. package/dist/{tempo-session-store-ZRNCOX7P.js → tempo-session-store-WZWQRITB.js} +3 -3
  54. package/dist/testing/index.d.ts +3 -3
  55. package/dist/testing/index.js +6 -7
  56. package/dist/{usd-DI3d3gTK.d.ts → usd-DkRy9nfU.d.ts} +1 -1
  57. package/dist/{x402-FT4S4JS4.js → x402-ZU4GML7Z.js} +8 -27
  58. package/package.json +1 -1
  59. package/dist/chunk-66HGCPBU.js +0 -25
  60. package/dist/chunk-AT6V3SY7.js +0 -102
  61. package/dist/chunk-EZXAJ6EI.js +0 -1082
  62. package/dist/chunk-HCLVYZUZ.js +0 -244
  63. package/dist/chunk-JEVLNAO3.js +0 -1668
  64. package/dist/chunk-NFMOPYBA.js +0 -357
  65. package/dist/chunk-O2OTZ5GP.js +0 -1869
  66. package/dist/chunk-OFVV37XC.js +0 -57
  67. package/dist/chunk-SZVXOQ75.js +0 -211
  68. package/dist/chunk-WBOKPC37.js +0 -795
  69. package/dist/tempo-lifecycle-GJ77YKVY.js +0 -15
  70. package/dist/tempo-wallet-X2GGAZ6X.js +0 -40
@@ -0,0 +1,120 @@
1
+ import {
2
+ X402_DEFAULT_NETWORK,
3
+ resolveRpcHttpTransportOptions,
4
+ resolveRpcOverride
5
+ } from "./chunk-62FI3NJF.js";
6
+ import {
7
+ redactUrl,
8
+ redactUrlsInText
9
+ } from "./chunk-KXWROQGK.js";
10
+ import {
11
+ DvmError,
12
+ x402NetworkByCaip2,
13
+ x402SupportedNetworksHint
14
+ } from "./chunk-BPYMEMQX.js";
15
+
16
+ // src/lib/x402/asset.ts
17
+ function resolveX402Asset(network = X402_DEFAULT_NETWORK) {
18
+ const spec = x402NetworkByCaip2(network);
19
+ if (!spec) return null;
20
+ return {
21
+ address: spec.usdc,
22
+ symbol: "USDC",
23
+ // "native" is the load-bearing word: every contract in the table is
24
+ // Circle's own USDC, and the dollars that read as zero here are the
25
+ // bridged ones.
26
+ label: "native USDC",
27
+ unit: "USDC",
28
+ networkLabel: spec.label,
29
+ confusable: spec.confusable
30
+ };
31
+ }
32
+
33
+ // src/lib/evm-private-key.ts
34
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
35
+ import { hexToBytes } from "@noble/hashes/utils.js";
36
+ var EVM_PRIVATE_KEY_RE = /^0x[0-9a-fA-F]{64}$/;
37
+ function isValidEvmPrivateKey(value) {
38
+ return EVM_PRIVATE_KEY_RE.test(value) && secp256k1.utils.isValidSecretKey(hexToBytes(value.slice(2)));
39
+ }
40
+
41
+ // src/lib/x402/wallet.ts
42
+ async function ensureAddress(wallet) {
43
+ if (!isValidEvmPrivateKey(wallet.privateKey)) throw invalidX402PrivateKey();
44
+ if (wallet.address) return wallet;
45
+ const { privateKeyToAccount } = await import("viem/accounts");
46
+ const account = privateKeyToAccount(wallet.privateKey);
47
+ return { ...wallet, address: account.address };
48
+ }
49
+ async function generateX402PrivateKey() {
50
+ const { generatePrivateKey } = await import("viem/accounts");
51
+ return generatePrivateKey();
52
+ }
53
+ function invalidX402PrivateKey() {
54
+ return new DvmError(
55
+ "invalid_key",
56
+ "Invalid secp256k1 private key.",
57
+ "Reconnect with `dvm wallet x402-connect --key-file <path>`, set DVM_X402_KEY, or pipe a valid 0x-prefixed 32-byte secp256k1 private key through stdin."
58
+ );
59
+ }
60
+ async function getX402Balance(wallet) {
61
+ const w = await ensureAddress(wallet);
62
+ const spec = x402NetworkByCaip2(w.network);
63
+ if (!spec) {
64
+ throw new DvmError(
65
+ "x402_unsupported_network",
66
+ `The x402 wallet is configured for ${w.network}, a chain this rail can't settle on.`,
67
+ `${x402SupportedNetworksHint()} Re-pin the connected wallet without handling its key: 'dvm wallet x402-network ${X402_DEFAULT_NETWORK}'.`
68
+ );
69
+ }
70
+ const chains = await import("viem/chains");
71
+ const { createPublicClient, http, erc20Abi } = await import("viem");
72
+ const chain = chains[spec.viemChain];
73
+ const { url: rpcUrl, source: rpcSource } = resolveRpcOverride(
74
+ process.env.DVM_X402_RPC_URL,
75
+ chain?.rpcUrls.default.http[0]
76
+ );
77
+ try {
78
+ const transportOptions = resolveRpcHttpTransportOptions(
79
+ rpcSource,
80
+ process.env.DVM_X402_RPC_HEADERS_JSON
81
+ );
82
+ const client = createPublicClient({
83
+ chain,
84
+ transport: transportOptions ? http(rpcUrl, transportOptions) : http(rpcUrl)
85
+ });
86
+ const balance = await client.readContract({
87
+ address: spec.usdc,
88
+ abi: erc20Abi,
89
+ functionName: "balanceOf",
90
+ args: [w.address]
91
+ });
92
+ return {
93
+ address: w.address,
94
+ usdc: Number(balance) / 1e6,
95
+ network: w.network,
96
+ tokenAddress: spec.usdc,
97
+ // redacted here rather than at a display surface, so the clear
98
+ // endpoint never leaves this function on the success path either.
99
+ rpcUrlRedacted: rpcUrl ? redactUrl(rpcUrl) : void 0,
100
+ rpcSource
101
+ };
102
+ } catch (err) {
103
+ const cause = redactUrlsInText(err instanceof Error ? err.message : String(err));
104
+ throw new DvmError(
105
+ "x402_rpc_error",
106
+ `x402 USDC balance lookup on ${spec.label} failed: ${cause}`,
107
+ // A caller who set the override doesn't need to be told to set it. Which
108
+ // knob is theirs to turn depends on whose endpoint this was.
109
+ rpcSource === "override" ? `DVM_X402_RPC_URL sent this read to ${redactUrl(rpcUrl)}. Correct it, or unset it to fall back to ${spec.label}'s bundled endpoint.` : `Verify connectivity to ${spec.label}'s bundled endpoint${rpcUrl ? ` (${redactUrl(rpcUrl)})` : ""}, or send the read somewhere else with DVM_X402_RPC_URL.`
110
+ );
111
+ }
112
+ }
113
+
114
+ export {
115
+ resolveX402Asset,
116
+ isValidEvmPrivateKey,
117
+ ensureAddress,
118
+ generateX402PrivateKey,
119
+ getX402Balance
120
+ };
@@ -5,10 +5,10 @@ import {
5
5
  } from "./chunk-AFV77S4C.js";
6
6
  import {
7
7
  loggers
8
- } from "./chunk-QR2EF2NI.js";
8
+ } from "./chunk-AQ7OX5NX.js";
9
9
  import {
10
10
  redactUrl
11
- } from "./chunk-FUJ36YDV.js";
11
+ } from "./chunk-KXWROQGK.js";
12
12
 
13
13
  // src/sdk/server/job-store.ts
14
14
  function accumulateAskedTopUp(prior, ask) {
@@ -2,12 +2,12 @@ import {
2
2
  parseStoreValue,
3
3
  stringifyStoreValue
4
4
  } from "./chunk-YG7G4DPZ.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/tempo-charge-store.ts
13
13
  import { Credential } from "mppx";
@@ -1,15 +1,15 @@
1
- import {
2
- withSdkInitLock
3
- } from "./chunk-COYKJRMM.js";
4
1
  import {
5
2
  applyRetryToPool
6
- } from "./chunk-P6QON7ER.js";
3
+ } from "./chunk-TRNMTTPX.js";
7
4
  import {
8
5
  x402NetworkByCaip2
9
6
  } from "./chunk-BPYMEMQX.js";
10
7
  import {
11
8
  diagnosticConsole
12
- } from "./chunk-ETXDTUJO.js";
9
+ } from "./chunk-LAKP6FUI.js";
10
+ import {
11
+ withSdkInitLock
12
+ } from "./chunk-COYKJRMM.js";
13
13
 
14
14
  // src/sdk/server/credit-ledger.ts
15
15
  import { randomUUID } from "crypto";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  diagnosticConsole
3
- } from "./chunk-ETXDTUJO.js";
3
+ } from "./chunk-LAKP6FUI.js";
4
4
 
5
5
  // src/lib/pg-retry.ts
6
6
  import { AsyncLocalStorage } from "async_hooks";
@@ -1,7 +1,3 @@
1
- import {
2
- canonicaliseForSigning
3
- } from "./chunk-OFVV37XC.js";
4
-
5
1
  // src/sdk/types.ts
6
2
  function isZodSchema(value) {
7
3
  return typeof value === "object" && value !== null && "_zod" in value && "parse" in value && "safeParse" in value;
@@ -16,6 +12,58 @@ var DEFAULT_CREDIT_MAX = "$5.00";
16
12
  var DEFAULT_CREDIT_TTL_SECONDS = 30 * 24 * 60 * 60;
17
13
  var DEFAULT_JOB_RETENTION_DAYS = 730;
18
14
 
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
+
19
67
  // src/lib/signed-request-statement.ts
20
68
  var SIGNED_REQUEST_AUTH_ID = "secp256k1-schnorr-v2";
21
69
  var SIGNED_REQUEST_STATEMENT_VERSION = 2;
@@ -81,6 +129,9 @@ export {
81
129
  DEFAULT_CREDIT_MAX,
82
130
  DEFAULT_CREDIT_TTL_SECONDS,
83
131
  DEFAULT_JOB_RETENTION_DAYS,
132
+ canonicalize,
133
+ canonicaliseForSigning,
134
+ verifyCanonicalSignedRequest,
84
135
  SIGNED_REQUEST_AUTH_ID,
85
136
  SIGNED_REQUEST_STATEMENT_VERSION,
86
137
  signedRequestStatementHeader,
@@ -0,0 +1,17 @@
1
+ import {
2
+ validateCurrency
3
+ } from "./chunk-CLIAFTUR.js";
4
+
5
+ // src/sdk/pricing/upfront.ts
6
+ function buildUpfront(input) {
7
+ const currency = validateCurrency(input.currency);
8
+ const amount = input.amount;
9
+ if (!Number.isFinite(amount) || amount < 0) {
10
+ throw new Error(`invalid upfront amount: ${String(amount)} (must be a non-negative number)`);
11
+ }
12
+ return { amount, currency };
13
+ }
14
+
15
+ export {
16
+ buildUpfront
17
+ };