@dvmkit/sdk 0.7.0-rc.1 → 0.7.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/dist/{chunk-S3OY533W.js → chunk-2NUFE2PG.js} +47 -5
- package/dist/{chunk-RA2WIX7G.js → chunk-3E4C6W7W.js} +17 -6
- package/dist/{chunk-GY66THYI.js → chunk-53SNRGQQ.js} +372 -153
- package/dist/{chunk-CXCQLOOK.js → chunk-62FI3NJF.js} +42 -107
- package/dist/chunk-6HJEVCVI.js +17 -0
- package/dist/chunk-A262WVYX.js +6 -0
- package/dist/{chunk-IV6Q7NRW.js → chunk-C5RIQWG4.js} +1 -1
- package/dist/{chunk-GAOAYHZA.js → chunk-FBQVOOYF.js} +37 -6
- package/dist/{chunk-Z4ZT5LNT.js → chunk-GEI4MAXE.js} +3 -3
- package/dist/{chunk-OML32F6I.js → chunk-GLIAR7RN.js} +1 -1
- package/dist/{chunk-X7EZ5CLI.js → chunk-HCATFJDD.js} +3 -3
- package/dist/{chunk-BYCEKO65.js → chunk-HPCXF3DV.js} +220 -32
- package/dist/{chunk-6XF3RVVX.js → chunk-IRXIH775.js} +5 -5
- package/dist/{chunk-QR2EF2NI.js → chunk-KCQDXIJU.js} +1 -42
- package/dist/chunk-MDW7ZR7V.js +47 -0
- package/dist/{chunk-KA6VN5FK.js → chunk-MQYM4T66.js} +3 -3
- package/dist/{chunk-P6QON7ER.js → chunk-NV7Z7377.js} +1 -1
- package/dist/{chunk-KMED3H3A.js → chunk-OBBVDKLE.js} +476 -230
- package/dist/{chunk-EQLA4FFY.js → chunk-OHUXCAOM.js} +17 -6
- package/dist/{chunk-FWGWLPXF.js → chunk-PZ5IAWFD.js} +1 -1
- package/dist/{chunk-IXR5RFK7.js → chunk-R3TQSXWT.js} +191 -5
- package/dist/{chunk-VHNPVGSA.js → chunk-T5DIXOLR.js} +3 -3
- package/dist/{chunk-RCM3P2HE.js → chunk-UKD3R2KU.js} +55 -4
- package/dist/chunk-WMGXJQI3.js +120 -0
- package/dist/{chunk-N5RZ5HVB.js → chunk-X6S2CHFM.js} +2 -2
- package/dist/{chunk-ETXDTUJO.js → chunk-ZCNPIILZ.js} +112 -1
- package/dist/{content-retention-DHyLdA6b.d.ts → content-retention-D2K4MKNO.d.ts} +1 -1
- package/dist/{credit-ledger-MCUXYKSJ.js → credit-ledger-MFIIOSZH.js} +4 -4
- package/dist/{credit-menu-DjnkeEUU.d.ts → credit-menu-D2t1-Tf6.d.ts} +13 -6
- package/dist/{fx-zMWFzfrU.d.ts → fx-Ql4nvdbh.d.ts} +10 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +248 -16
- package/dist/internal/caller.d.ts +5032 -8272
- package/dist/internal/caller.js +4302 -8084
- package/dist/internal/index.js +1 -1
- package/dist/internal/server.d.ts +7 -7
- package/dist/internal/server.js +30 -31
- package/dist/{job-store-DdLXBpol.d.ts → job-store-DCvJQUX0.d.ts} +1 -1
- package/dist/{lightning-backend-Bw-qtAbt.d.ts → lightning-backend-CY5ML3km.d.ts} +2 -2
- package/dist/{memory-credit-ledger-SBSMGMDX.js → memory-credit-ledger-44NE4PZC.js} +5 -5
- package/dist/{mpp-setup-RF5FXGGV.js → mpp-setup-HRWUBULX.js} +4 -2
- package/dist/{payout-reporter-3Y2U55ZX.js → payout-reporter-7P66T77I.js} +6 -4
- package/dist/{postgres-consumed-credential-store-BUVCAPLS.js → postgres-consumed-credential-store-IDGPFKIL.js} +3 -3
- package/dist/{postgres-job-store-VHLQBJZC.js → postgres-job-store-UKNJ2F6Z.js} +2 -2
- package/dist/{postgres-replay-store-ARZSQ45X.js → postgres-replay-store-PMA4ADXN.js} +2 -2
- package/dist/{pricing-XT2IAPNE.js → pricing-52XJHJ6K.js} +12 -12
- package/dist/{revenue-reporter-MAERPYGK.js → revenue-reporter-HV7RMS54.js} +2 -2
- package/dist/server/index.d.ts +12 -11
- package/dist/server/index.js +47 -48
- package/dist/{step-cache-2MkvenJn.d.ts → step-cache-BOWAn_BH.d.ts} +84 -7
- package/dist/{tempo-charge-store-Q3D7KYMH.js → tempo-charge-store-P2Z4RMU7.js} +2 -2
- package/dist/{tempo-session-store-ZRNCOX7P.js → tempo-session-store-VSP7KLBS.js} +3 -3
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +7 -6
- package/dist/{usd-DI3d3gTK.d.ts → usd-MAtMp3DB.d.ts} +1 -1
- package/dist/{x402-FT4S4JS4.js → x402-3IQ3HXSG.js} +8 -26
- package/package.json +1 -1
- package/dist/chunk-AT6V3SY7.js +0 -102
- package/dist/chunk-EZXAJ6EI.js +0 -1082
- package/dist/chunk-HCLVYZUZ.js +0 -244
- package/dist/chunk-JEVLNAO3.js +0 -1668
- package/dist/chunk-NFMOPYBA.js +0 -357
- package/dist/chunk-O2OTZ5GP.js +0 -1869
- package/dist/chunk-OFVV37XC.js +0 -57
- package/dist/chunk-SZVXOQ75.js +0 -211
- package/dist/chunk-WBOKPC37.js +0 -795
- package/dist/tempo-lifecycle-GJ77YKVY.js +0 -15
- package/dist/tempo-wallet-X2GGAZ6X.js +0 -40
package/dist/chunk-OFVV37XC.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/chunk-SZVXOQ75.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isValidEvmPrivateKey,
|
|
3
|
-
loadConfig,
|
|
4
|
-
tempoAccountFromConfig,
|
|
5
|
-
updateConfig
|
|
6
|
-
} from "./chunk-WBOKPC37.js";
|
|
7
|
-
import {
|
|
8
|
-
resolveRpcHttpTransportOptions,
|
|
9
|
-
resolveRpcOverride
|
|
10
|
-
} from "./chunk-CXCQLOOK.js";
|
|
11
|
-
import {
|
|
12
|
-
redactUrl,
|
|
13
|
-
redactUrlsInText
|
|
14
|
-
} from "./chunk-FUJ36YDV.js";
|
|
15
|
-
import {
|
|
16
|
-
DvmError
|
|
17
|
-
} from "./chunk-BPYMEMQX.js";
|
|
18
|
-
|
|
19
|
-
// src/lib/payment-rails/tempo-wallet.ts
|
|
20
|
-
var TEMPO_USDC_MAINNET = "0x20C000000000000000000000b9537d11c60E8b50";
|
|
21
|
-
var TEMPO_CHAIN_ID = 4217;
|
|
22
|
-
var TEMPO_MODERATO_CHAIN_ID = 42431;
|
|
23
|
-
var TEMPO_PATH_USD_MODERATO = "0x20c0000000000000000000000000000000000000";
|
|
24
|
-
var TEMPO_MODERATO_RPC = "https://rpc.moderato.tempo.xyz";
|
|
25
|
-
function resolveTempoNetwork(network = "mainnet") {
|
|
26
|
-
return network === "moderato" ? {
|
|
27
|
-
network,
|
|
28
|
-
chainId: TEMPO_MODERATO_CHAIN_ID,
|
|
29
|
-
rpcUrl: TEMPO_MODERATO_RPC,
|
|
30
|
-
defaultToken: TEMPO_PATH_USD_MODERATO
|
|
31
|
-
} : {
|
|
32
|
-
network,
|
|
33
|
-
chainId: TEMPO_CHAIN_ID,
|
|
34
|
-
rpcUrl: "https://rpc.tempo.xyz",
|
|
35
|
-
defaultToken: TEMPO_USDC_MAINNET
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function resolveTempoAsset(env = process.env, network = "mainnet") {
|
|
39
|
-
const address = env.DVM_TEMPO_CURRENCY ?? resolveTempoNetwork(network).defaultToken;
|
|
40
|
-
if (!HEX_ADDRESS_RE.test(address)) {
|
|
41
|
-
throw new DvmError(
|
|
42
|
-
"tempo_config_invalid",
|
|
43
|
-
`DVM_TEMPO_CURRENCY must be a 0x-prefixed 40-char hex address; got '${address}'.`,
|
|
44
|
-
"Unset DVM_TEMPO_CURRENCY to fall back to the bundled USDC.e mainnet default."
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
const symbol = tempoTokenSymbol(address);
|
|
48
|
-
return {
|
|
49
|
-
address,
|
|
50
|
-
symbol,
|
|
51
|
-
label: tempoTokenLabel(address),
|
|
52
|
-
unit: symbol ?? "tokens"
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function tempoTokenLabel(address) {
|
|
56
|
-
return tempoTokenSymbol(address) ?? `the token at ${shortAddress(address)}`;
|
|
57
|
-
}
|
|
58
|
-
function tempoTokenReference(address) {
|
|
59
|
-
const symbol = tempoTokenSymbol(address);
|
|
60
|
-
return symbol ? `${symbol} (${address})` : address;
|
|
61
|
-
}
|
|
62
|
-
function tempoBalanceCheckHint(token) {
|
|
63
|
-
const configured = tryResolveTempoAsset();
|
|
64
|
-
if (configured?.address.toLowerCase() === token.toLowerCase()) {
|
|
65
|
-
return "This channel's token is the rail's configured settlement asset, so 'dvm wallet balance' reads it.";
|
|
66
|
-
}
|
|
67
|
-
return `'dvm wallet balance' reads the rail's configured settlement asset (${configured?.address ?? "unresolvable in this environment"}) rather than this channel's token (${token}), so query that contract directly for the balance that matters here.`;
|
|
68
|
-
}
|
|
69
|
-
function tryResolveTempoAsset(env = process.env) {
|
|
70
|
-
try {
|
|
71
|
-
return resolveTempoAsset(env);
|
|
72
|
-
} catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function tempoWrongAssetHint(asset) {
|
|
77
|
-
return `This rail settles only in ${asset.label} (${asset.address}) on Tempo. Another Tempo dollar \u2014 USDT0 or any other stablecoin \u2014 is a different contract and will never show up here, however much of it your wallet says you hold. If you funded with the wrong one, swap it to ${asset.label} on Tempo (an on-chain swap, fees are sub-cent) or send ${asset.label} to this address.`;
|
|
78
|
-
}
|
|
79
|
-
function tempoTokenSymbol(address) {
|
|
80
|
-
if (address.toLowerCase() === TEMPO_USDC_MAINNET.toLowerCase()) return "USDC.e";
|
|
81
|
-
if (address.toLowerCase() === TEMPO_PATH_USD_MODERATO.toLowerCase()) return "pathUSD";
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
var HEX_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
85
|
-
async function connectedTempoAccount() {
|
|
86
|
-
const config = loadConfig();
|
|
87
|
-
return tempoAccountFromConfig(config);
|
|
88
|
-
}
|
|
89
|
-
async function generateTempoKey(opts = {}) {
|
|
90
|
-
const config = loadConfig();
|
|
91
|
-
if (!config) {
|
|
92
|
-
throw new DvmError(
|
|
93
|
-
"no_config",
|
|
94
|
-
"No config found.",
|
|
95
|
-
"Run `dvm init` before generating a Tempo wallet."
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
const existing = await tempoAccountFromConfig(config);
|
|
99
|
-
if (existing && !opts.force) {
|
|
100
|
-
throw new DvmError(
|
|
101
|
-
"tempo_wallet_exists",
|
|
102
|
-
`Tempo wallet already configured (address ${existing.address}).`,
|
|
103
|
-
"Pass `--force` to replace, or run `dvm wallet tempo-disconnect` to clear it first."
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
if (existing && opts.force) {
|
|
107
|
-
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-GJ77YKVY.js");
|
|
108
|
-
await assertTempoWalletIdle("replace");
|
|
109
|
-
}
|
|
110
|
-
const { privateKeyToAccount, generatePrivateKey } = await import("viem/accounts");
|
|
111
|
-
const privateKey = generatePrivateKey();
|
|
112
|
-
const account = privateKeyToAccount(privateKey);
|
|
113
|
-
const generated = {
|
|
114
|
-
privateKey,
|
|
115
|
-
address: account.address.toLowerCase(),
|
|
116
|
-
network: opts.network ?? "mainnet"
|
|
117
|
-
};
|
|
118
|
-
await opts.beforePersist?.(generated);
|
|
119
|
-
await updateConfig({
|
|
120
|
-
reason: "tempo_wallet_generate",
|
|
121
|
-
patch: () => ({
|
|
122
|
-
set: {
|
|
123
|
-
tempo: { method: "tempo", apiKey: privateKey, network: generated.network }
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
});
|
|
127
|
-
return generated;
|
|
128
|
-
}
|
|
129
|
-
async function getTempoUsdcBalance(account) {
|
|
130
|
-
const accountNetwork = account.network ?? "mainnet";
|
|
131
|
-
const network = resolveTempoNetwork(accountNetwork);
|
|
132
|
-
const tokenAddress = resolveTempoAsset(process.env, accountNetwork).address;
|
|
133
|
-
const { createPublicClient, http, erc20Abi } = await import("viem");
|
|
134
|
-
const { tempo, tempoModerato } = await import("viem/chains");
|
|
135
|
-
const chain = accountNetwork === "moderato" ? tempoModerato : tempo;
|
|
136
|
-
const { url: rpcUrl, source: rpcSource } = resolveRpcOverride(
|
|
137
|
-
process.env.DVM_TEMPO_RPC_URL,
|
|
138
|
-
network.rpcUrl
|
|
139
|
-
);
|
|
140
|
-
try {
|
|
141
|
-
const transportOptions = resolveRpcHttpTransportOptions(
|
|
142
|
-
rpcSource,
|
|
143
|
-
process.env.DVM_TEMPO_RPC_HEADERS_JSON
|
|
144
|
-
);
|
|
145
|
-
const client = createPublicClient({
|
|
146
|
-
chain,
|
|
147
|
-
transport: transportOptions ? http(rpcUrl, transportOptions) : http(rpcUrl)
|
|
148
|
-
});
|
|
149
|
-
const raw = await client.readContract({
|
|
150
|
-
address: tokenAddress,
|
|
151
|
-
abi: erc20Abi,
|
|
152
|
-
functionName: "balanceOf",
|
|
153
|
-
args: [account.address]
|
|
154
|
-
});
|
|
155
|
-
return {
|
|
156
|
-
address: account.address,
|
|
157
|
-
rawBaseUnits: raw,
|
|
158
|
-
usdc: Number(raw) / 1e6,
|
|
159
|
-
tokenAddress,
|
|
160
|
-
chainId: network.chainId,
|
|
161
|
-
// redacted here rather than at a display surface, so the clear
|
|
162
|
-
// endpoint never leaves this function on the success path either.
|
|
163
|
-
rpcUrlRedacted: redactUrl(rpcUrl),
|
|
164
|
-
rpcSource,
|
|
165
|
-
fetchedAtMs: Date.now()
|
|
166
|
-
};
|
|
167
|
-
} catch (err) {
|
|
168
|
-
const cause = redactUrlsInText(err instanceof Error ? err.message : String(err));
|
|
169
|
-
throw new DvmError(
|
|
170
|
-
"tempo_rpc_error",
|
|
171
|
-
`Tempo USDC balance lookup failed: ${cause}`,
|
|
172
|
-
// A caller who set the override doesn't need to be told to set it. Which
|
|
173
|
-
// knob is theirs to turn depends on whose endpoint this was.
|
|
174
|
-
rpcSource === "override" ? `DVM_TEMPO_RPC_URL sent this read to ${redactUrl(rpcUrl)}. Correct it, or unset it to fall back to Tempo's bundled endpoint.` : `Verify connectivity to Tempo's bundled endpoint (${redactUrl(rpcUrl)}), or send the read somewhere else with DVM_TEMPO_RPC_URL.`
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
async function deriveTempoAddress(privateKey) {
|
|
179
|
-
if (!isValidEvmPrivateKey(privateKey)) throw invalidTempoPrivateKey();
|
|
180
|
-
const { privateKeyToAccount } = await import("viem/accounts");
|
|
181
|
-
return privateKeyToAccount(privateKey).address.toLowerCase();
|
|
182
|
-
}
|
|
183
|
-
function shortAddress(addr) {
|
|
184
|
-
return `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
|
|
185
|
-
}
|
|
186
|
-
function invalidTempoPrivateKey() {
|
|
187
|
-
return new DvmError(
|
|
188
|
-
"invalid_api_key",
|
|
189
|
-
"A Tempo private key must be a valid 0x-prefixed 32-byte hex secp256k1 private key.",
|
|
190
|
-
"Generate one with `cast wallet new` or `openssl rand -hex 32` (and prepend 0x)."
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export {
|
|
195
|
-
TEMPO_USDC_MAINNET,
|
|
196
|
-
TEMPO_CHAIN_ID,
|
|
197
|
-
TEMPO_MODERATO_CHAIN_ID,
|
|
198
|
-
TEMPO_PATH_USD_MODERATO,
|
|
199
|
-
TEMPO_MODERATO_RPC,
|
|
200
|
-
resolveTempoNetwork,
|
|
201
|
-
resolveTempoAsset,
|
|
202
|
-
tempoTokenLabel,
|
|
203
|
-
tempoTokenReference,
|
|
204
|
-
tempoBalanceCheckHint,
|
|
205
|
-
tryResolveTempoAsset,
|
|
206
|
-
tempoWrongAssetHint,
|
|
207
|
-
connectedTempoAccount,
|
|
208
|
-
generateTempoKey,
|
|
209
|
-
getTempoUsdcBalance,
|
|
210
|
-
deriveTempoAddress
|
|
211
|
-
};
|