@dvmkit/dvm-cli 0.0.0 → 0.1.4

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 (53) hide show
  1. package/LICENSE +67 -0
  2. package/NOTICE +2 -0
  3. package/README.md +28 -3
  4. package/dist/_esm-M2HUAA3B.js +883 -0
  5. package/dist/_esm-NRGECLJ7.js +35 -0
  6. package/dist/accounts-S747UW3A.js +73 -0
  7. package/dist/ccip-XZ5F5J6R.js +18 -0
  8. package/dist/chains-PINFXYUE.js +1460 -0
  9. package/dist/channel-store-GOV7TEDN.js +62 -0
  10. package/dist/chunk-3PPOU55E.js +312 -0
  11. package/dist/chunk-3TBULV3F.js +551 -0
  12. package/dist/chunk-4AQ4G7L5.js +1447 -0
  13. package/dist/chunk-5BUV73FO.js +2351 -0
  14. package/dist/chunk-6AJ7H2VX.js +4387 -0
  15. package/dist/chunk-6UGZAFIR.js +1485 -0
  16. package/dist/chunk-7UPZZGC5.js +30063 -0
  17. package/dist/chunk-ACNNU5RY.js +5485 -0
  18. package/dist/chunk-BZNZWRBB.js +189 -0
  19. package/dist/chunk-EY5K4BM3.js +1780 -0
  20. package/dist/chunk-G3RLVJF5.js +19 -0
  21. package/dist/chunk-GIDSTROG.js +16614 -0
  22. package/dist/chunk-HPRIQEJS.js +258 -0
  23. package/dist/chunk-IC6OXFYW.js +6484 -0
  24. package/dist/chunk-IYHTITNZ.js +45 -0
  25. package/dist/chunk-KC4UPK44.js +113 -0
  26. package/dist/chunk-MMJR6N3J.js +2426 -0
  27. package/dist/chunk-MTBCEXJ6.js +4602 -0
  28. package/dist/chunk-ONQMRWY3.js +83 -0
  29. package/dist/chunk-PHZHPRQE.js +1181 -0
  30. package/dist/chunk-RA24J4QM.js +3717 -0
  31. package/dist/chunk-RWBYCM47.js +339 -0
  32. package/dist/chunk-SLDVIXCS.js +21369 -0
  33. package/dist/chunk-TO47XRK7.js +24890 -0
  34. package/dist/chunk-U5TNSUYW.js +1757 -0
  35. package/dist/chunk-UU6QMSTQ.js +171 -0
  36. package/dist/chunk-UXQCP26E.js +2691 -0
  37. package/dist/chunk-XGABM4H5.js +3339 -0
  38. package/dist/chunk-YZUBKHHA.js +15436 -0
  39. package/dist/chunk-ZELLQI7F.js +248 -0
  40. package/dist/chunk-ZGXCK43G.js +9868 -0
  41. package/dist/client-D3XFLWOK.js +52 -0
  42. package/dist/dist-7MMV3EZA.js +46 -0
  43. package/dist/dvm.js +33650 -0
  44. package/dist/lifecycle-5RLM5JMN.js +29 -0
  45. package/dist/mine.wasm-DNBKYCTQ.js +12 -0
  46. package/dist/pocket-refill-GDYSTECR.js +133 -0
  47. package/dist/secp256k1-4YWQEMGF.js +19 -0
  48. package/dist/tempo-lifecycle-DHZPQTSB.js +31 -0
  49. package/dist/tempo-wallet-5FEOI4CF.js +35 -0
  50. package/dist/wallet-G3VOUCL4.js +30 -0
  51. package/dist/x402-VNFA3DBY.js +91 -0
  52. package/package.json +71 -6
  53. package/skills/dvm/SKILL.md +71 -0
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __dvmCreateRequire } from "node:module";
3
+ const require = __dvmCreateRequire(import.meta.url);
4
+ import {
5
+ findSigningIdentityByPubkey,
6
+ listTempoChannelAssociations,
7
+ loadTempoChannelController,
8
+ reconcileTempoChannelOnChain,
9
+ shellQuoteArg,
10
+ tempoChannelControlledBy
11
+ } from "./chunk-ACNNU5RY.js";
12
+ import {
13
+ connectedTempoAccount
14
+ } from "./chunk-BZNZWRBB.js";
15
+ import {
16
+ formatUsdcMicrounits
17
+ } from "./chunk-ZELLQI7F.js";
18
+ import {
19
+ DvmError
20
+ } from "./chunk-U5TNSUYW.js";
21
+
22
+ // src/lib/payment-rails/tempo-lifecycle.ts
23
+ async function assertTempoWalletIdle(intent) {
24
+ const connected = await connectedTempoAccount();
25
+ if (!connected) return;
26
+ const records = await ownedTempoChannelRecords(connected.address);
27
+ const verdicts = await Promise.all(
28
+ records.map(async (association) => ({
29
+ association,
30
+ chain: await reconcileTempoChannelOnChain({ association })
31
+ }))
32
+ );
33
+ let blocker;
34
+ for (const status of BLOCKING_ORDER) {
35
+ blocker = verdicts.find((verdict) => verdict.chain.status === status);
36
+ if (blocker) break;
37
+ }
38
+ if (!blocker) return;
39
+ const blocking = verdicts.filter((verdict) => verdict.chain.status !== "closed").length;
40
+ 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);
41
+ }
42
+ async function ownedTempoChannelRecords(address) {
43
+ const records = listTempoChannelAssociations();
44
+ const controlled = await Promise.all(
45
+ records.map(
46
+ async (association) => tempoChannelControlledBy(
47
+ await loadTempoChannelController(association).catch(() => void 0),
48
+ address
49
+ )
50
+ )
51
+ );
52
+ return records.filter((_, index) => controlled[index]);
53
+ }
54
+ var BLOCKING_ORDER = ["open", "closing", "unconfirmed", "unreadable"];
55
+ function liveChannelError(association, chain, intent, blocking) {
56
+ const depositMicro = chain.status === "unconfirmed" ? Number(association.deposit) : chain.depositMicro;
57
+ const amount = `$${formatUsdcMicrounits(BigInt(depositMicro))}`;
58
+ 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.`;
59
+ const caller = findSigningIdentityByPubkey(association.callerPubkey);
60
+ if (!caller) {
61
+ return new DvmError(
62
+ "tempo_channels_active",
63
+ message,
64
+ `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)}`,
65
+ channelData(association, chain, depositMicro, blocking)
66
+ );
67
+ }
68
+ const identityName = caller.source.kind === "env" ? void 0 : caller.source.name;
69
+ const selectors = { creditId: association.creditId, identityName };
70
+ const exit = tempoExitCommand(association.endpoint, selectors);
71
+ const abandon = tempoExitCommand(association.endpoint, selectors, true);
72
+ const fund = creditCommand("fund", association.endpoint, selectors);
73
+ const remedy = chain.status === "open" ? (
74
+ // The endpoint can hold several credits and caller identities. Both
75
+ // selectors keep every remedy pointed at the channel just named.
76
+ `Empty the channel first \u2014 '${creditCommand("drain", association.endpoint, selectors)}' for the cooperative exit, or '${exit}' if the DVM is unavailable`
77
+ ) : 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`;
78
+ return new DvmError(
79
+ "tempo_channels_active",
80
+ message,
81
+ `Only this key can close that channel. ${remedy} \u2014 and ${intentClause(intent)}.${remainingClause(blocking)}`,
82
+ channelData(association, chain, depositMicro, blocking)
83
+ );
84
+ }
85
+ function tempoExitCommand(endpoint, selectors, abandon = false) {
86
+ const parts = [
87
+ "dvm wallet tempo-exit",
88
+ shellQuoteArg(endpoint),
89
+ "--credit-id",
90
+ shellQuoteArg(selectors.creditId)
91
+ ];
92
+ if (selectors.identityName !== void 0) {
93
+ parts.push("--as", shellQuoteArg(selectors.identityName));
94
+ }
95
+ if (abandon) parts.push("--abandon");
96
+ return parts.join(" ");
97
+ }
98
+ function creditCommand(verb, endpoint, selectors) {
99
+ const parts = [
100
+ `dvm credit ${verb}`,
101
+ shellQuoteArg(endpoint),
102
+ "--credit-id",
103
+ shellQuoteArg(selectors.creditId)
104
+ ];
105
+ if (selectors.identityName !== void 0) {
106
+ parts.push("--as", shellQuoteArg(selectors.identityName));
107
+ }
108
+ return parts.join(" ");
109
+ }
110
+ function unreadableChainError(association, chain, intent, blocking) {
111
+ const cause = chain.error;
112
+ return new DvmError(
113
+ cause?.code ?? "tempo_chain_read_failed",
114
+ `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"}`,
115
+ `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)}`,
116
+ channelData(association, chain, Number(association.deposit), blocking)
117
+ );
118
+ }
119
+ function descriptorlessChannelError(association, chain, intent, blocking) {
120
+ 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.`;
121
+ const data = {
122
+ ...channelData(association, chain, Number(association.deposit), blocking),
123
+ anchor: "tempo_channel_descriptor_missing"
124
+ };
125
+ const caller = findSigningIdentityByPubkey(association.callerPubkey);
126
+ if (!caller) {
127
+ return new DvmError(
128
+ "tempo_channel_not_found",
129
+ message,
130
+ `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)}`,
131
+ data
132
+ );
133
+ }
134
+ const identityName = caller.source.kind === "env" ? void 0 : caller.source.name;
135
+ const abandon = tempoExitCommand(
136
+ association.endpoint,
137
+ { creditId: association.creditId, identityName },
138
+ true
139
+ );
140
+ return new DvmError(
141
+ "tempo_channel_not_found",
142
+ message,
143
+ `Run '${abandon}' to retire this unusable local record without broadcasting anything, then ${intentClause(intent)}.${remainingClause(blocking)}`,
144
+ data
145
+ );
146
+ }
147
+ function channelData(association, chain, depositMicro, blocking) {
148
+ return {
149
+ anchor: "tempo_channel_live",
150
+ endpoint: association.endpoint,
151
+ credit_id: association.creditId,
152
+ channel_id: association.channelId,
153
+ chain_id: association.chainId,
154
+ chain_status: chain.status,
155
+ deposit_micro: depositMicro,
156
+ ...chain.status === "unreadable" ? {} : { settled_micro: chain.settledMicro },
157
+ // How many records are still in the way, so an agent knows whether clearing
158
+ // the one named above is the whole job.
159
+ blocking_channels: blocking
160
+ };
161
+ }
162
+ function remainingClause(blocking) {
163
+ 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.` : "";
164
+ }
165
+ function intentClause(intent) {
166
+ return intent === "replace" ? "retry the replacement" : "retry 'dvm wallet tempo-disconnect'";
167
+ }
168
+
169
+ export {
170
+ assertTempoWalletIdle
171
+ };