@dvmkit/dvm-cli 0.5.0 → 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.
Files changed (54) hide show
  1. package/README.md +10 -0
  2. package/dist/{_esm-MN4BUYV6.js → _esm-KJAA4KAJ.js} +7 -7
  3. package/dist/{actions-LR65XILR.js → actions-J7VGYDBF.js} +4 -4
  4. package/dist/{ccip-JXYJSXTW.js → ccip-CJFG4PLA.js} +1 -1
  5. package/dist/{chains-LJ7XK6H3.js → chains-J6VIUNUB.js} +4 -4
  6. package/dist/{chunk-QICJRKB7.js → chunk-32AOWN2U.js} +11032 -12469
  7. package/dist/chunk-3E4LW5R5.js +77 -0
  8. package/dist/chunk-5RVUW52C.js +122 -0
  9. package/dist/{chunk-MJ4X4BEW.js → chunk-6LP4EGKA.js} +61 -61
  10. package/dist/chunk-6PVFVHS5.js +5460 -0
  11. package/dist/{chunk-BECPI5H5.js → chunk-B4WHUMZM.js} +36 -36
  12. package/dist/{chunk-CJTE5TS3.js → chunk-ESOJUXVY.js} +5 -5
  13. package/dist/{chunk-F55NNH2F.js → chunk-FOWQ7R7S.js} +16 -16
  14. package/dist/{chunk-ID5G54HJ.js → chunk-FPWP4S5S.js} +5 -3
  15. package/dist/{chunk-EE2MREOM.js → chunk-IQV4KG63.js} +5 -3
  16. package/dist/{chunk-R55XNXAR.js → chunk-IUTVV6N5.js} +3 -3
  17. package/dist/{chunk-Z4CZUMUT.js → chunk-JBU7RKQ3.js} +15 -15
  18. package/dist/{chunk-SHZMNEXE.js → chunk-JTMBSEZO.js} +2770 -926
  19. package/dist/{chunk-ERJFRCJO.js → chunk-KDNFUDOG.js} +5 -5
  20. package/dist/chunk-MWWZX7OQ.js +262 -0
  21. package/dist/chunk-PATIATFK.js +765 -0
  22. package/dist/{chunk-WTM2EICO.js → chunk-PUOXBKY2.js} +3 -3
  23. package/dist/{chunk-GZWKCIYN.js → chunk-QXMKABL7.js} +3 -3
  24. package/dist/chunk-R2DSAZBO.js +87 -0
  25. package/dist/chunk-SNSJAOR3.js +43 -0
  26. package/dist/{chunk-FL2ICZW5.js → chunk-SYFKO6BA.js} +3 -3
  27. package/dist/{chunk-LH3QPVN6.js → chunk-TAZWRWM4.js} +8060 -8058
  28. package/dist/chunk-VIRAAIDU.js +409 -0
  29. package/dist/{chunk-TZWZTS37.js → chunk-WN5R367B.js} +57 -83
  30. package/dist/{chunk-EZHT2RLJ.js → chunk-X7SEGALJ.js} +3 -3
  31. package/dist/{chunk-XHOFQ3OS.js → chunk-Y3SQD37C.js} +9 -9
  32. package/dist/{client-RYDA62DU.js → client-6IHIUB6J.js} +10 -10
  33. package/dist/client-VHGN7ZFZ.js +36 -0
  34. package/dist/{dist-GKCEIY2A.js → dist-23E7OOCA.js} +9 -9
  35. package/dist/dvm.js +2844 -623
  36. package/dist/{internal-INUTGTXQ.js → internal-7RZYJLLG.js} +325 -508
  37. package/dist/lifecycle-Z7YUOTR5.js +36 -0
  38. package/dist/{payout-reporter-3Y2U55ZX-CMKACKA3.js → payout-reporter-WT7XYW42-U2QPDIYC.js} +3 -2
  39. package/dist/{pocket-refill-K5T4LZF6.js → pocket-refill-CCWF3G4N.js} +33 -30
  40. package/dist/{revenue-reporter-MAERPYGK-CCPZXGFA.js → revenue-reporter-7UR3W2SD-C5OMRGK3.js} +3 -2
  41. package/dist/{tempo-AXTE4ZEA.js → tempo-ORFVGUKP.js} +10 -10
  42. package/dist/tempo-lifecycle-OT75TYVA.js +38 -0
  43. package/dist/tempo-wallet-SGYOEWVY.js +43 -0
  44. package/dist/wallet-BRXTQ4BB.js +45 -0
  45. package/dist/{x402-R6HPBY5D-VMSW7Z32.js → x402-ZU4GML7Z-RYEACIIT.js} +4 -19
  46. package/package.json +4 -2
  47. package/skills/dvm/credit.md +4 -0
  48. package/skills/dvm/wallets.md +4 -0
  49. package/dist/chunk-3YE43JJR.js +0 -215
  50. package/dist/chunk-4KINCBHL.js +0 -5153
  51. package/dist/chunk-FSYEZERJ.js +0 -1667
  52. package/dist/chunk-VOO5IAK7.js +0 -2318
  53. package/dist/tempo-lifecycle-ZBBLFBMH-HWI4PLYP.js +0 -32
  54. package/dist/tempo-wallet-B5XXV3YH-SRQBMYFV.js +0 -41
@@ -24,7 +24,7 @@ import {
24
24
  networkOf,
25
25
  paymentMethod as paymentMethod2,
26
26
  toSource
27
- } from "./chunk-FL2ICZW5.js";
27
+ } from "./chunk-SYFKO6BA.js";
28
28
  import {
29
29
  ExactEip3009PayloadSchema,
30
30
  ExactPayloadSchema,
@@ -52,16 +52,16 @@ import {
52
52
  syntheticChallengeIdPrefix,
53
53
  toPaymentRequirements,
54
54
  versions
55
- } from "./chunk-WTM2EICO.js";
55
+ } from "./chunk-PUOXBKY2.js";
56
56
  import {
57
57
  Base64_exports
58
- } from "./chunk-EZHT2RLJ.js";
58
+ } from "./chunk-X7SEGALJ.js";
59
59
  import {
60
60
  Hash_exports
61
- } from "./chunk-LH3QPVN6.js";
61
+ } from "./chunk-TAZWRWM4.js";
62
62
  import {
63
63
  Bytes_exports
64
- } from "./chunk-F55NNH2F.js";
64
+ } from "./chunk-FOWQ7R7S.js";
65
65
  import {
66
66
  __export
67
67
  } from "./chunk-IYHTITNZ.js";
@@ -0,0 +1,262 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __dvmCreateRequire } from "node:module";
3
+ const require = __dvmCreateRequire(import.meta.url);
4
+ import {
5
+ connectedTempoAccount
6
+ } from "./chunk-3E4LW5R5.js";
7
+ import {
8
+ deriveIdentityFromPrivkey,
9
+ formatUsdcMicrounits,
10
+ listTempoChannelAssociations,
11
+ loadIdentities,
12
+ loadTempoChannelController,
13
+ reconcileTempoChannelOnChain,
14
+ shellQuoteArg,
15
+ tempoChannelControlledBy
16
+ } from "./chunk-32AOWN2U.js";
17
+ import {
18
+ DvmError
19
+ } from "./chunk-JTMBSEZO.js";
20
+
21
+ // src/lib/cli-identity-resolve.ts
22
+ function resolveSigningIdentity(opts) {
23
+ if (opts.as !== void 0) {
24
+ const file2 = loadIdentities();
25
+ const entry = file2?.identities[opts.as];
26
+ if (!entry) {
27
+ throw new DvmError(
28
+ "auth_required",
29
+ `No identity named '${opts.as}' is configured.`,
30
+ availableHint(file2?.identities, "create one with 'dvm identity create <name>'.")
31
+ );
32
+ }
33
+ return {
34
+ privkey: entry.privkey,
35
+ pubkey: entry.pubkey,
36
+ source: { kind: "flag", name: opts.as }
37
+ };
38
+ }
39
+ const envKey = process.env.DVM_IDENTITY_KEY;
40
+ if (envKey) {
41
+ const derived = deriveIdentityFromPrivkey(envKey.toLowerCase());
42
+ return { privkey: derived.privkey, pubkey: derived.pubkey, source: { kind: "env" } };
43
+ }
44
+ const file = loadIdentities();
45
+ const identities = file?.identities ?? {};
46
+ const names = Object.keys(identities);
47
+ const configuredDefault = opts.config?.defaultIdentity;
48
+ if (configuredDefault !== void 0) {
49
+ if (!Object.hasOwn(identities, configuredDefault)) {
50
+ throw new DvmError(
51
+ "auth_required",
52
+ `Configured default identity '${configuredDefault}' no longer exists.`,
53
+ availableHint(identities, "set a new default with 'dvm identity use <name>'.")
54
+ );
55
+ }
56
+ const entry = identities[configuredDefault];
57
+ return {
58
+ privkey: entry.privkey,
59
+ pubkey: entry.pubkey,
60
+ source: { kind: "default", name: configuredDefault }
61
+ };
62
+ }
63
+ if (names.length === 1) {
64
+ const onlyName = names[0];
65
+ const entry = identities[onlyName];
66
+ return {
67
+ privkey: entry.privkey,
68
+ pubkey: entry.pubkey,
69
+ source: { kind: "sole", name: onlyName }
70
+ };
71
+ }
72
+ if (names.length === 0) {
73
+ throw new DvmError(
74
+ "auth_required",
75
+ "This DVM requires a signed request but no caller identity is configured.",
76
+ "Run 'dvm identity create <name>' (or 'dvm init') to generate one, or pass DVM_IDENTITY_KEY=<hex>."
77
+ );
78
+ }
79
+ throw new DvmError(
80
+ "auth_required",
81
+ "Multiple identities are configured but none is selected.",
82
+ `Pass --as <name>, set a default with 'dvm identity use <name>', or export DVM_IDENTITY_KEY=<hex>. Available: ${names.join(", ")}.`
83
+ );
84
+ }
85
+ function findSigningIdentityByPubkey(pubkey) {
86
+ const wanted = pubkey.toLowerCase();
87
+ const envKey = process.env.DVM_IDENTITY_KEY;
88
+ if (envKey) {
89
+ try {
90
+ const derived = deriveIdentityFromPrivkey(envKey.toLowerCase());
91
+ if (derived.pubkey === wanted) {
92
+ return { privkey: derived.privkey, pubkey: derived.pubkey, source: { kind: "env" } };
93
+ }
94
+ } catch {
95
+ }
96
+ }
97
+ const identities = loadIdentities()?.identities ?? {};
98
+ for (const [name, entry] of Object.entries(identities)) {
99
+ if (entry.pubkey.toLowerCase() === wanted) {
100
+ return { privkey: entry.privkey, pubkey: entry.pubkey, source: { kind: "pubkey", name } };
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ function availableHint(identities, suffix) {
106
+ const names = identities ? Object.keys(identities) : [];
107
+ if (names.length === 0) return `No identities are configured \u2014 ${suffix}`;
108
+ return `Available identities: ${names.join(", ")}. ${suffix}`;
109
+ }
110
+
111
+ // src/lib/payment-rails/tempo-lifecycle.ts
112
+ async function assertTempoWalletIdle(intent) {
113
+ const connected = await connectedTempoAccount();
114
+ if (!connected) return;
115
+ const records = await ownedTempoChannelRecords(connected.address);
116
+ const verdicts = await Promise.all(
117
+ records.map(async (association) => ({
118
+ association,
119
+ chain: await reconcileTempoChannelOnChain({ association })
120
+ }))
121
+ );
122
+ let blocker;
123
+ for (const status of BLOCKING_ORDER) {
124
+ blocker = verdicts.find((verdict) => verdict.chain.status === status);
125
+ if (blocker) break;
126
+ }
127
+ if (!blocker) return;
128
+ const blocking = verdicts.filter((verdict) => verdict.chain.status !== "closed").length;
129
+ throw blocker.chain.status === "unreadable" ? blocker.chain.error?.code === "tempo_channel_not_found" ? descriptorlessChannelError(blocker.association, blocker.chain, intent, blocking) : unreadableChainError(blocker.association, blocker.chain, intent, blocking) : liveChannelError(blocker.association, blocker.chain, intent, blocking);
130
+ }
131
+ async function ownedTempoChannelRecords(address) {
132
+ const records = listTempoChannelAssociations();
133
+ const controlled = await Promise.all(
134
+ records.map(
135
+ async (association) => tempoChannelControlledBy(
136
+ await loadTempoChannelController(association).catch(() => void 0),
137
+ address
138
+ )
139
+ )
140
+ );
141
+ return records.filter((_, index) => controlled[index]);
142
+ }
143
+ var BLOCKING_ORDER = ["open", "closing", "unconfirmed", "unreadable"];
144
+ function liveChannelError(association, chain, intent, blocking) {
145
+ const depositMicro = chain.status === "unconfirmed" ? Number(association.deposit) : chain.depositMicro;
146
+ const amount = `$${formatUsdcMicrounits(BigInt(depositMicro))}`;
147
+ const message = chain.status === "open" ? `The connected Tempo key still holds ${amount} of collateral in an open channel with ${association.endpoint}.` : chain.status === "closing" ? `The connected Tempo key has ${amount} still escrowed on its channel with ${association.endpoint}, where a close has been requested on-chain and is in its 15-minute grace period.` : `The connected Tempo key signed an open committing ${amount} to a channel with ${association.endpoint} that the escrow has no record of, so that collateral may or may not be locked.`;
148
+ const caller = findSigningIdentityByPubkey(association.callerPubkey);
149
+ if (!caller) {
150
+ return new DvmError(
151
+ "tempo_channels_active",
152
+ message,
153
+ `Only this key can close that channel, but its caller identity (${association.callerPubkey}) is no longer configured. Restore that identity first, then retry the wallet ${intent === "replace" ? "replacement" : "disconnect"}; the key and channel record were left untouched.${remainingClause(blocking)}`,
154
+ channelData(association, chain, depositMicro, blocking)
155
+ );
156
+ }
157
+ const identityName = caller.source.kind === "env" ? void 0 : caller.source.name;
158
+ const selectors = { creditId: association.creditId, identityName };
159
+ const exit = tempoExitCommand(association.endpoint, selectors);
160
+ const abandon = tempoExitCommand(association.endpoint, selectors, true);
161
+ const fund = creditCommand("fund", association.endpoint, selectors);
162
+ const remedy = chain.status === "open" ? (
163
+ // The endpoint can hold several credits and caller identities. Both
164
+ // selectors keep every remedy pointed at the channel just named.
165
+ `Empty the channel first \u2014 '${creditCommand("drain", association.endpoint, selectors)}' for the cooperative exit, or '${exit}' if the DVM is unavailable`
166
+ ) : chain.status === "closing" ? `'${exit}' withdraws what remains once the grace period ends` : `'${exit}' reads the chain and says which it is, and '${fund}' resumes a funding still pending for it. Once that open is known never to have landed, '${abandon}' retires the record`;
167
+ return new DvmError(
168
+ "tempo_channels_active",
169
+ message,
170
+ `Only this key can close that channel. ${remedy} \u2014 and ${intentClause(intent)}.${remainingClause(blocking)}`,
171
+ channelData(association, chain, depositMicro, blocking)
172
+ );
173
+ }
174
+ function tempoExitCommand(endpoint, selectors, abandon = false) {
175
+ const parts = [
176
+ "dvm wallet tempo-exit",
177
+ shellQuoteArg(endpoint),
178
+ "--credit-id",
179
+ shellQuoteArg(selectors.creditId)
180
+ ];
181
+ if (selectors.identityName !== void 0) {
182
+ parts.push("--as", shellQuoteArg(selectors.identityName));
183
+ }
184
+ if (abandon) parts.push("--abandon");
185
+ return parts.join(" ");
186
+ }
187
+ function creditCommand(verb, endpoint, selectors) {
188
+ const parts = [
189
+ `dvm credit ${verb}`,
190
+ shellQuoteArg(endpoint),
191
+ "--credit-id",
192
+ shellQuoteArg(selectors.creditId)
193
+ ];
194
+ if (selectors.identityName !== void 0) {
195
+ parts.push("--as", shellQuoteArg(selectors.identityName));
196
+ }
197
+ return parts.join(" ");
198
+ }
199
+ function unreadableChainError(association, chain, intent, blocking) {
200
+ const cause = chain.error;
201
+ return new DvmError(
202
+ cause?.code ?? "tempo_chain_read_failed",
203
+ `The Tempo channel with ${association.endpoint} could not be read, so there is no way to show it is empty: ${cause?.message ?? "the chain read failed"}`,
204
+ `The Tempo key is untouched, and the local channel record was kept \u2014 it is the only route back to any collateral the escrow does hold. ${cause?.hint ? `${cause.hint} Then ${intentClause(intent)}.` : `Restore the chain read, then ${intentClause(intent)}.`}${remainingClause(blocking)}`,
205
+ channelData(association, chain, Number(association.deposit), blocking)
206
+ );
207
+ }
208
+ function descriptorlessChannelError(association, chain, intent, blocking) {
209
+ const message = `The saved Tempo channel with ${association.endpoint} has no stored descriptor, so its escrow state cannot be read or closed from this machine.`;
210
+ const data = {
211
+ ...channelData(association, chain, Number(association.deposit), blocking),
212
+ anchor: "tempo_channel_descriptor_missing"
213
+ };
214
+ const caller = findSigningIdentityByPubkey(association.callerPubkey);
215
+ if (!caller) {
216
+ return new DvmError(
217
+ "tempo_channel_not_found",
218
+ message,
219
+ `The caller identity that owns this record (${association.callerPubkey}) is no longer configured. Restore that identity first, then retire the descriptor-less record; the Tempo key and record were left untouched.${remainingClause(blocking)}`,
220
+ data
221
+ );
222
+ }
223
+ const identityName = caller.source.kind === "env" ? void 0 : caller.source.name;
224
+ const abandon = tempoExitCommand(
225
+ association.endpoint,
226
+ { creditId: association.creditId, identityName },
227
+ true
228
+ );
229
+ return new DvmError(
230
+ "tempo_channel_not_found",
231
+ message,
232
+ `Run '${abandon}' to retire this unusable local record without broadcasting anything, then ${intentClause(intent)}.${remainingClause(blocking)}`,
233
+ data
234
+ );
235
+ }
236
+ function channelData(association, chain, depositMicro, blocking) {
237
+ return {
238
+ anchor: "tempo_channel_live",
239
+ endpoint: association.endpoint,
240
+ credit_id: association.creditId,
241
+ channel_id: association.channelId,
242
+ chain_id: association.chainId,
243
+ chain_status: chain.status,
244
+ deposit_micro: depositMicro,
245
+ ...chain.status === "unreadable" ? {} : { settled_micro: chain.settledMicro },
246
+ // How many records are still in the way, so an agent knows whether clearing
247
+ // the one named above is the whole job.
248
+ blocking_channels: blocking
249
+ };
250
+ }
251
+ function remainingClause(blocking) {
252
+ return blocking > 1 ? ` ${blocking - 1} other recorded channel${blocking > 2 ? "s" : ""} still ${blocking > 2 ? "block" : "blocks"} this too \u2014 'dvm wallet balance' lists them all with what the escrow says about each.` : "";
253
+ }
254
+ function intentClause(intent) {
255
+ return intent === "replace" ? "retry the replacement" : "retry 'dvm wallet tempo-disconnect'";
256
+ }
257
+
258
+ export {
259
+ resolveSigningIdentity,
260
+ findSigningIdentityByPubkey,
261
+ assertTempoWalletIdle
262
+ };