@needmoretruth/nmts-cli 0.45.0 → 0.47.0

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 (252) hide show
  1. package/AGENTS.md +8 -8
  2. package/CHANGELOG.md +78 -0
  3. package/README.ko.md +6 -3
  4. package/README.md +31 -11
  5. package/dist/api-advice.js +17 -2
  6. package/dist/api.d.ts +22 -0
  7. package/dist/api.js +49 -1
  8. package/dist/arg-options.d.ts +19 -1
  9. package/dist/args.js +14 -2
  10. package/dist/artifact-about.d.ts +1 -1
  11. package/dist/autonomy.js +3 -3
  12. package/dist/collision.d.ts +20 -3
  13. package/dist/collision.js +21 -3
  14. package/dist/commands/erase.js +1 -0
  15. package/dist/commands/handover.d.ts +15 -0
  16. package/dist/commands/handover.js +376 -0
  17. package/dist/commands/heavy-run.d.ts +59 -0
  18. package/dist/commands/heavy-run.js +247 -0
  19. package/dist/commands/heavy.d.ts +7 -0
  20. package/dist/commands/heavy.js +123 -0
  21. package/dist/commands/link.d.ts +12 -0
  22. package/dist/commands/link.js +121 -0
  23. package/dist/commands/ls.d.ts +5 -0
  24. package/dist/commands/ls.js +9 -1
  25. package/dist/commands/public-code-manage.d.ts +24 -0
  26. package/dist/commands/public-code-manage.js +217 -0
  27. package/dist/commands/public-code.d.ts +12 -1
  28. package/dist/commands/public-code.js +140 -45
  29. package/dist/commands/push-heavy.d.ts +6 -0
  30. package/dist/commands/push-heavy.js +128 -0
  31. package/dist/commands/push-tree.d.ts +24 -0
  32. package/dist/commands/push-tree.js +91 -0
  33. package/dist/commands/push.d.ts +4 -13
  34. package/dist/commands/push.js +7 -77
  35. package/dist/commands/put-heavy.d.ts +9 -0
  36. package/dist/commands/put-heavy.js +120 -0
  37. package/dist/commands/put-payer.d.ts +21 -0
  38. package/dist/commands/put-payer.js +24 -0
  39. package/dist/commands/put.d.ts +2 -2
  40. package/dist/commands/put.js +8 -7
  41. package/dist/commands/receive.js +14 -8
  42. package/dist/commands/s3.js +44 -10
  43. package/dist/commands/share-dispatch.js +14 -1
  44. package/dist/commands/share.d.ts +2 -0
  45. package/dist/commands/share.js +45 -35
  46. package/dist/commands/shares-sent.js +8 -3
  47. package/dist/crypto-surface.d.ts +35 -0
  48. package/dist/crypto-surface.js +13 -0
  49. package/dist/crypto.d.ts +8 -0
  50. package/dist/crypto.js +8 -0
  51. package/dist/download-part.d.ts +32 -1
  52. package/dist/download-part.js +95 -6
  53. package/dist/download-range.d.ts +19 -0
  54. package/dist/download-range.js +108 -0
  55. package/dist/download-sink.d.ts +15 -0
  56. package/dist/download.d.ts +14 -0
  57. package/dist/download.js +19 -4
  58. package/dist/handover-codes.d.ts +25 -0
  59. package/dist/handover-codes.js +106 -0
  60. package/dist/handover.d.ts +62 -0
  61. package/dist/handover.js +217 -0
  62. package/dist/heavy-api.d.ts +36 -0
  63. package/dist/heavy-api.js +107 -0
  64. package/dist/heavy-copy.d.ts +72 -0
  65. package/dist/heavy-copy.js +108 -0
  66. package/dist/heavy-evm.d.ts +20 -0
  67. package/dist/heavy-evm.js +106 -0
  68. package/dist/heavy-self-pay.d.ts +92 -0
  69. package/dist/heavy-self-pay.js +167 -0
  70. package/dist/heavy-upload.d.ts +87 -0
  71. package/dist/heavy-upload.js +154 -0
  72. package/dist/heavy-wallet-pay.d.ts +39 -0
  73. package/dist/heavy-wallet-pay.js +73 -0
  74. package/dist/help-options.js +13 -4
  75. package/dist/help.js +24 -3
  76. package/dist/links.d.ts +58 -0
  77. package/dist/links.js +206 -0
  78. package/dist/list-tier.d.ts +7 -0
  79. package/dist/list-tier.js +47 -0
  80. package/dist/main.js +13 -10
  81. package/dist/manifest-write.d.ts +4 -3
  82. package/dist/mcp-tools/reads.js +20 -6
  83. package/dist/mcp-tools/share.js +47 -1
  84. package/dist/mcp-tools/tiers.js +16 -1
  85. package/dist/platform-sign.d.ts +4 -4
  86. package/dist/platform-sign.js +3 -3
  87. package/dist/portable.d.ts +23 -0
  88. package/dist/portable.js +19 -0
  89. package/dist/product.d.ts +1 -1
  90. package/dist/product.js +1 -1
  91. package/dist/public-code-activity.d.ts +35 -0
  92. package/dist/public-code-activity.js +88 -0
  93. package/dist/public-code-refusals.d.ts +25 -0
  94. package/dist/public-code-refusals.js +87 -0
  95. package/dist/public-codes.d.ts +76 -0
  96. package/dist/public-codes.js +182 -0
  97. package/dist/recovery-build.js +16 -0
  98. package/dist/recovery-map-part.d.ts +82 -0
  99. package/dist/recovery-map-part.js +83 -0
  100. package/dist/recovery-map.d.ts +5 -40
  101. package/dist/recovery-map.js +18 -1
  102. package/dist/recovery-source.d.ts +3 -0
  103. package/dist/recovery-source.js +9 -0
  104. package/dist/risk.d.ts +55 -1
  105. package/dist/risk.js +55 -3
  106. package/dist/run-log.d.ts +1 -1
  107. package/dist/run-log.js +7 -1
  108. package/dist/s3/address.d.ts +20 -0
  109. package/dist/s3/address.js +97 -0
  110. package/dist/s3/answer.d.ts +48 -0
  111. package/dist/s3/answer.js +330 -0
  112. package/dist/s3/body-deframe.d.ts +49 -0
  113. package/dist/s3/body-deframe.js +264 -0
  114. package/dist/s3/body-measure.d.ts +13 -0
  115. package/dist/s3/body-measure.js +48 -0
  116. package/dist/s3/body-plan.d.ts +31 -0
  117. package/dist/s3/body-plan.js +159 -0
  118. package/dist/s3/body.d.ts +46 -0
  119. package/dist/s3/body.js +117 -0
  120. package/dist/s3/call.d.ts +36 -0
  121. package/dist/s3/call.js +42 -0
  122. package/dist/s3/checksum.d.ts +26 -0
  123. package/dist/s3/checksum.js +176 -0
  124. package/dist/s3/content-type.d.ts +3 -0
  125. package/dist/s3/content-type.js +49 -0
  126. package/dist/s3/contract.d.ts +91 -14
  127. package/dist/s3/drive-conditions.d.ts +47 -0
  128. package/dist/s3/drive-conditions.js +134 -0
  129. package/dist/s3/drive-key.d.ts +11 -0
  130. package/dist/s3/drive-key.js +58 -0
  131. package/dist/s3/drive-limits.d.ts +33 -0
  132. package/dist/s3/drive-limits.js +53 -0
  133. package/dist/s3/drive-lock.d.ts +11 -0
  134. package/dist/s3/drive-lock.js +47 -0
  135. package/dist/s3/drive-trashed-name.d.ts +13 -0
  136. package/dist/s3/drive-trashed-name.js +59 -0
  137. package/dist/s3/drive-write.d.ts +38 -0
  138. package/dist/s3/drive-write.js +258 -0
  139. package/dist/s3/drive.d.ts +59 -25
  140. package/dist/s3/drive.js +46 -77
  141. package/dist/s3/listing.d.ts +27 -1
  142. package/dist/s3/listing.js +62 -20
  143. package/dist/s3/long-answer.d.ts +12 -0
  144. package/dist/s3/long-answer.js +104 -0
  145. package/dist/s3/multipart-assemble.d.ts +17 -0
  146. package/dist/s3/multipart-assemble.js +68 -0
  147. package/dist/s3/multipart-sweep.d.ts +15 -0
  148. package/dist/s3/multipart-sweep.js +87 -0
  149. package/dist/s3/multipart-view.d.ts +45 -0
  150. package/dist/s3/multipart-view.js +232 -0
  151. package/dist/s3/multipart.d.ts +26 -19
  152. package/dist/s3/multipart.js +193 -78
  153. package/dist/s3/object-read.d.ts +17 -0
  154. package/dist/s3/object-read.js +127 -0
  155. package/dist/s3/object-write.d.ts +35 -0
  156. package/dist/s3/object-write.js +198 -0
  157. package/dist/s3/range.d.ts +14 -0
  158. package/dist/s3/range.js +80 -0
  159. package/dist/s3/response-sink.d.ts +12 -2
  160. package/dist/s3/response-sink.js +71 -7
  161. package/dist/s3/routes.d.ts +0 -1
  162. package/dist/s3/routes.js +242 -217
  163. package/dist/s3/same-file.d.ts +4 -1
  164. package/dist/s3/same-file.js +12 -3
  165. package/dist/s3/server.d.ts +54 -4
  166. package/dist/s3/server.js +174 -14
  167. package/dist/s3/sigv4-canonical.d.ts +91 -0
  168. package/dist/s3/sigv4-canonical.js +148 -0
  169. package/dist/s3/sigv4-presigned.d.ts +13 -0
  170. package/dist/s3/sigv4-presigned.js +82 -0
  171. package/dist/s3/sigv4.d.ts +26 -27
  172. package/dist/s3/sigv4.js +137 -102
  173. package/dist/s3/spool.d.ts +37 -0
  174. package/dist/s3/spool.js +104 -0
  175. package/dist/s3/staging.d.ts +90 -7
  176. package/dist/s3/staging.js +97 -66
  177. package/dist/s3/xml-multipart.d.ts +38 -0
  178. package/dist/s3/xml-multipart.js +47 -0
  179. package/dist/s3/xml-read.d.ts +28 -0
  180. package/dist/s3/xml-read.js +235 -0
  181. package/dist/s3/xml.d.ts +45 -2
  182. package/dist/s3/xml.js +72 -13
  183. package/dist/s3-gateway.d.ts +11 -5
  184. package/dist/s3-gateway.js +5 -2
  185. package/dist/seal.d.ts +1 -1
  186. package/dist/share-codes.d.ts +40 -0
  187. package/dist/share-codes.js +151 -0
  188. package/dist/share.d.ts +39 -0
  189. package/dist/share.js +54 -13
  190. package/dist/shared/lib/api/types-heavy.d.ts +167 -0
  191. package/dist/shared/lib/api/types-heavy.js +60 -0
  192. package/dist/shared/lib/drive/rebuild-verify.js +1 -0
  193. package/dist/shared/lib/filecoin/providers.d.ts +25 -0
  194. package/dist/shared/lib/filecoin/providers.js +58 -0
  195. package/dist/shared/lib/heavy/download.d.ts +48 -0
  196. package/dist/shared/lib/heavy/download.js +116 -0
  197. package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
  198. package/dist/shared/lib/heavy/order-plan.js +83 -0
  199. package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
  200. package/dist/shared/lib/heavy/order-runner.js +300 -0
  201. package/dist/shared/lib/heavy/order-types.d.ts +90 -0
  202. package/dist/shared/lib/heavy/order-types.js +6 -0
  203. package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
  204. package/dist/shared/lib/heavy/order-wire.js +113 -0
  205. package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
  206. package/dist/shared/lib/heavy/piece-cid.js +55 -0
  207. package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
  208. package/dist/shared/lib/heavy/sp-upload.js +112 -0
  209. package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
  210. package/dist/shared/lib/heavy/synapse-piece.js +8 -0
  211. package/dist/shared/lib/share/handover-format.d.ts +129 -0
  212. package/dist/shared/lib/share/handover-format.js +323 -0
  213. package/dist/shared/lib/share/public-link.d.ts +41 -0
  214. package/dist/shared/lib/share/public-link.js +107 -0
  215. package/dist/shared/lib/share/shared-file-info.js +1 -0
  216. package/dist/shared/lib/storage-network.d.ts +4 -4
  217. package/dist/shared/lib/storage-network.js +7 -7
  218. package/dist/shared/lib/storage-tier.d.ts +28 -0
  219. package/dist/shared/lib/storage-tier.js +63 -0
  220. package/dist/shared/lib/wallet/send-rules.js +1 -0
  221. package/dist/upload-file.d.ts +8 -0
  222. package/dist/upload-file.js +57 -25
  223. package/dist/upload-price-node.d.ts +3 -0
  224. package/dist/upload-price-node.js +3 -6
  225. package/dist/upload-price.d.ts +10 -0
  226. package/dist/upload-price.js +13 -1
  227. package/dist/upload-run.d.ts +80 -0
  228. package/dist/upload-run.js +173 -0
  229. package/dist/upload-steps.js +15 -4
  230. package/dist/upload-store.d.ts +15 -6
  231. package/dist/upload-store.js +6 -0
  232. package/dist/upload-wallet-put.d.ts +9 -4
  233. package/dist/upload-wallet-put.js +16 -6
  234. package/dist/upload-wallet.js +4 -0
  235. package/dist/upload-wire.d.ts +25 -0
  236. package/dist/upload-wire.js +20 -1
  237. package/dist/upload.js +28 -13
  238. package/dist/wallet-sign.js +2 -2
  239. package/docs/commands/handover.md +54 -0
  240. package/docs/commands/heavy.md +35 -0
  241. package/docs/commands/link.md +27 -0
  242. package/docs/commands/mcp.md +2 -1
  243. package/docs/commands/public-code.md +25 -6
  244. package/docs/commands/push.md +4 -1
  245. package/docs/commands/put.md +15 -1
  246. package/docs/commands/share.md +8 -3
  247. package/package.json +5 -2
  248. package/server.json +2 -2
  249. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +106 -4
  250. package/vendor/nmts-crypto/nmts_crypto_wasm.js +286 -3
  251. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  252. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +12 -1
@@ -0,0 +1,247 @@
1
+ // The terminal around an NMTS Heavy upload — shared by `put --tier heavy` and `push --tier heavy`:
2
+ // which money pays, the review a person reads before anything is spent, the wallet agreement, the
3
+ // progress lines, and what a failure says.
4
+ //
5
+ // ⛔ THE THREE PAYERS AND THEIR STOPS.
6
+ // credits one order, credits taken when it opens — the same tier as a Standard credit upload.
7
+ // wallet the order opens first so its WAL price can be printed; the balances are read and a
8
+ // known shortfall stops the run BEFORE anything is sealed; the wallet agreement is held
9
+ // against the price; the WAL is sent only once every part is stored — the same act,
10
+ // lock and review as `put --pay wallet`.
11
+ // evm developer mode: the key's own EVM wallet pays Filecoin through the Synapse SDK. The
12
+ // same wallet lock; refused before anything is spent where no company is listed.
13
+ //
14
+ // ⛔ A SERVER REFUSAL IS PRINTED AS ONE. The shared runner wraps whatever stopped it; when that was
15
+ // the server explaining itself, the explanation is what goes out, with the same advice table
16
+ // (`api-advice.ts`) every other refusal uses.
17
+ import { ServerError } from "../api.js";
18
+ import { DERIVED } from "../crypto.js";
19
+ import { NmtsError } from "../errors.js";
20
+ import { HEAVY_COPY } from "../heavy-copy.js";
21
+ import { evmAccountFor, evmIndexOf } from "../heavy-evm.js";
22
+ import { copiesOf, heavySelfPut, providersOf, selfPayChain } from "../heavy-self-pay.js";
23
+ import { heavyCredits, heavyOrderPut, planHeavyFile } from "../heavy-upload.js";
24
+ import { heavyWalletPut } from "../heavy-wallet-pay.js";
25
+ import { addEntry } from "../manifest-write.js";
26
+ import { setTrashed } from "../item-trash.js";
27
+ import { activeWalletOf } from "../shared/lib/drive/manifest-settings.js";
28
+ import { HeavyOrderError } from "../shared/lib/heavy/order-runner.js";
29
+ import { coinAmount } from "../wallet.js";
30
+ import { recordWalletSpend, requireWalletGrant } from "../wallet-grant.js";
31
+ import { payingWalletIndex } from "../wallet-pay-index.js";
32
+ import { payerOf, refuseWalletOnlyOptions } from "./put-payer.js";
33
+ export function heavyPayerOf(pay) {
34
+ return pay === "evm" ? "evm" : payerOf(pay);
35
+ }
36
+ /** Every option that means nothing on this payer, refused before a file is measured. */
37
+ export function refuseHeavyClashes(options, payer) {
38
+ const standardOnly = [
39
+ ["--epochs", options.epochs],
40
+ ["--storage", options.storage],
41
+ ["--from", options.from],
42
+ ["--deposit", options.deposit],
43
+ ["--part-size", options.partSize],
44
+ ["--trust-server-tip-address", options.trustServerTipAddress === true ? true : undefined],
45
+ ["--thumbnail", options.thumbnail === true ? true : undefined],
46
+ ["--thumbnail-file", options.thumbnailFile],
47
+ ];
48
+ for (const [flag, value] of standardOnly) {
49
+ if (value !== undefined)
50
+ throw new NmtsError(HEAVY_COPY.standardOnlyFlag(flag), { exitCode: 2 });
51
+ }
52
+ if (payer !== "evm") {
53
+ for (const [flag, value] of [["--copies", options.copies], ["--providers", options.providers], ["--evm-wallet", options.evmWallet]]) {
54
+ if (value !== undefined)
55
+ throw new NmtsError(HEAVY_COPY.evmOnlyFlag(flag), { exitCode: 2 });
56
+ }
57
+ }
58
+ if (payer !== "wallet") {
59
+ if (options.wallet !== undefined && options.wallet !== "")
60
+ refuseWalletOnlyOptions({ wallet: options.wallet });
61
+ if (options.days !== undefined)
62
+ throw new NmtsError(HEAVY_COPY.walletOnlyDays, { exitCode: 2 });
63
+ }
64
+ // Judged now, not after the files are read: a typo must not surface after the money.
65
+ if (payer === "evm") {
66
+ copiesOf(options.copies);
67
+ providersOf(options.providers);
68
+ evmIndexOf(options.evmWallet);
69
+ }
70
+ if (payer === "wallet")
71
+ termDaysOf(options.days);
72
+ }
73
+ /** `--days`: 1..365, default 28 — the term a credit buys. */
74
+ export function termDaysOf(raw) {
75
+ if (raw === undefined || raw === "")
76
+ return 28;
77
+ const value = Number(raw.trim());
78
+ if (!/^[0-9]+$/u.test(raw.trim()) || value < 1 || value > 365)
79
+ throw new NmtsError(HEAVY_COPY.badDays(raw), { exitCode: 2 });
80
+ return value;
81
+ }
82
+ /** The dry run: what is known without opening an order or touching a chain. */
83
+ export function heavyDryRun(files, rule, payer) {
84
+ const plans = files.map((f) => planHeavyFile(f.source.size, rule));
85
+ return {
86
+ dryRun: true,
87
+ tier: "heavy",
88
+ paidFrom: payer,
89
+ bytes: files.reduce((sum, f) => sum + f.source.size, 0),
90
+ sealedBytes: plans.flat().reduce((sum, p) => sum + p.sealedLen, 0),
91
+ parts: plans.reduce((sum, p) => sum + p.length, 0),
92
+ ...(payer === "credits" ? { credits: plans.reduce((sum, p) => sum + heavyCredits(p), 0) } : {}),
93
+ };
94
+ }
95
+ function label(files) {
96
+ return files.length === 1 ? (files[0]?.name ?? "") : `${files.length} files`;
97
+ }
98
+ /** Upload these files to NMTS Heavy on this payer, and commit them. The caller writes the list. */
99
+ export async function runHeavy(ctx, files, payer, options) {
100
+ const { session, crypt } = ctx;
101
+ const bytes = files.reduce((sum, f) => sum + f.source.size, 0);
102
+ const now = new Date(options.now ?? Date.now());
103
+ const derived = crypt.kdf_derive(crypt.account_code_parse(session.code));
104
+ const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
105
+ derived.fill(0);
106
+ try {
107
+ if (payer === "evm")
108
+ return await runSelfPaid(ctx, files, options, dataKey, now, bytes);
109
+ const onProgress = (event) => tellOrder(ctx, files, event);
110
+ const base = { server: session.server, bearer: session.apiKey, crypt, dataKey, rule: ctx.rule, onProgress };
111
+ if (payer === "credits") {
112
+ const credits = files.reduce((sum, f) => sum + heavyCredits(planHeavyFile(f.source.size, ctx.rule)), 0);
113
+ if (!ctx.json)
114
+ ctx.say(HEAVY_COPY.creditsPlan(label(files), bytes, credits));
115
+ const { run, files: done } = await heavyOrderPut(base, files, { pay: "credits" });
116
+ return { files: done, facts: { tier: "heavy", paidFrom: "credits", orderId: run.orderId, credits: run.credits ?? credits, expiryEpoch: run.expiryEpoch } };
117
+ }
118
+ return await runWalletPaid(ctx, files, options, base, now, bytes);
119
+ }
120
+ catch (error) {
121
+ throw heavyFailure(error);
122
+ }
123
+ finally {
124
+ dataKey.fill(0);
125
+ ctx.progress.done();
126
+ }
127
+ }
128
+ /** The wallet payer: open, review, check, agree — then run the same order. */
129
+ async function runWalletPaid(ctx, files, options, base, now, bytes) {
130
+ const { session, network } = ctx;
131
+ const wallet = await payingWalletIndex({ wallet: options.wallet, readActiveWallet: async () => activeWalletOf(ctx.settings) });
132
+ // ⛔ THE AGREEMENT IS ASKED BEFORE AN ORDER OPENS — an unpaid order counts against the day's three.
133
+ requireWalletGrant("seal", { walFrost: 0n, suiMist: 0n }, now);
134
+ const termDays = termDaysOf(options.days);
135
+ const { run, files: done, quote } = await heavyWalletPut(base, files, {
136
+ code: session.code,
137
+ network,
138
+ wallet,
139
+ termDays,
140
+ onQuote: (q) => {
141
+ if (!ctx.json)
142
+ ctx.say(HEAVY_COPY.walletPlan(label(files), bytes, coinAmount(q.walFrost), termDays, q.address, q.treasury));
143
+ },
144
+ approve: (q) => requireWalletGrant("seal", { walFrost: q.walFrost, suiMist: q.feeMist ?? 0n }, now),
145
+ onPaid: recordWalletSpend,
146
+ });
147
+ return {
148
+ files: done,
149
+ facts: {
150
+ tier: "heavy",
151
+ paidFrom: "wallet",
152
+ orderId: run.orderId,
153
+ priceFrost: quote.walFrost.toString(),
154
+ priceWal: coinAmount(quote.walFrost),
155
+ termDays,
156
+ wallet: quote.address,
157
+ txDigest: run.txDigest ?? null,
158
+ expiryEpoch: run.expiryEpoch,
159
+ },
160
+ };
161
+ }
162
+ /** The evm payer: this key's own EVM wallet, through the Synapse SDK. */
163
+ async function runSelfPaid(ctx, files, options, dataKey, now, bytes) {
164
+ selfPayChain(ctx.network);
165
+ const copies = copiesOf(options.copies);
166
+ const providers = providersOf(options.providers);
167
+ requireWalletGrant("seal", { walFrost: 0n, suiMist: 0n }, now);
168
+ const account = await evmAccountFor(ctx.session.code, evmIndexOf(options.evmWallet));
169
+ if (!ctx.json)
170
+ ctx.say(HEAVY_COPY.evmPlan(label(files), bytes, copies, account.address));
171
+ const done = await heavySelfPut({
172
+ server: ctx.session.server,
173
+ bearer: ctx.session.apiKey,
174
+ crypt: ctx.crypt,
175
+ dataKey,
176
+ rule: ctx.rule,
177
+ network: ctx.network,
178
+ account,
179
+ copies,
180
+ providers,
181
+ onProgress: (event) => tellSelf(ctx, files, event),
182
+ }, files);
183
+ return {
184
+ files: done.files,
185
+ facts: { tier: "heavy", paidFrom: "evm", paidBy: done.paidBy, copies: done.copies, expiryEpoch: done.expiryEpoch, ...(providers === undefined ? {} : { providers: providers.map(String) }) },
186
+ };
187
+ }
188
+ function where(files, fileIndex, partIndex, parts) {
189
+ const name = files.length > 1 ? ` ${files[fileIndex]?.name ?? ""}` : "";
190
+ return `${name}${parts > 1 ? ` [${partIndex + 1}/${parts}]` : ""}`;
191
+ }
192
+ function tellOrder(ctx, files, event) {
193
+ if (ctx.json)
194
+ return;
195
+ if (event.phase === "uploading")
196
+ return ctx.progress.update(event.sentBytes, event.totalBytes);
197
+ if ("fileKey" in event) {
198
+ const fileIndex = Number(event.fileKey.slice(1));
199
+ const parts = planHeavyFile(files[fileIndex]?.source.size ?? 1, ctx.rule).length;
200
+ if (event.phase === "committing")
201
+ ctx.progress.done();
202
+ return ctx.say(HEAVY_COPY.progress(event.phase, where(files, fileIndex, event.partIndex, parts)));
203
+ }
204
+ ctx.say(HEAVY_COPY.progress(event.phase, ""));
205
+ }
206
+ function tellSelf(ctx, files, event) {
207
+ if (ctx.json)
208
+ return;
209
+ if (event.phase === "sent")
210
+ return ctx.progress.update(event.sentBytes, event.totalBytes);
211
+ if (event.phase === "stored")
212
+ ctx.progress.done();
213
+ ctx.say(HEAVY_COPY.progress(event.phase, where(files, event.fileIndex, event.partIndex, event.parts)));
214
+ }
215
+ /** A server refusal as itself; any other stop of the runner in the Heavy words. */
216
+ export function heavyFailure(error) {
217
+ if (!(error instanceof HeavyOrderError))
218
+ return error;
219
+ if (error.cause instanceof ServerError)
220
+ return error.cause;
221
+ return new NmtsError(HEAVY_COPY.failed(error.reason, error.message), { exitCode: 1, nextStep: HEAVY_COPY.failedNext(error.reason) });
222
+ }
223
+ /** Write each committed file into the sealed list; a displaced one goes to the server's trash last. */
224
+ export async function recordHeavy(session, done, onCollision) {
225
+ const now = Date.now();
226
+ const added = await addEntry({
227
+ server: session.server,
228
+ apiKey: session.apiKey,
229
+ code: session.code,
230
+ accountId: session.accountId,
231
+ ...(onCollision !== undefined ? { onCollision } : {}),
232
+ entry: {
233
+ id: done.itemId,
234
+ parentId: done.parentId,
235
+ kind: 1,
236
+ name: done.name,
237
+ size: done.plaintextLen,
238
+ createdAt: now,
239
+ updatedAt: now,
240
+ dekWrapped: done.dekWrapped,
241
+ contentHashCt: done.contentHashCt,
242
+ },
243
+ });
244
+ if (added.replaced)
245
+ await setTrashed(session.server, session.apiKey, added.replaced.id, true);
246
+ return { name: added.name, replaced: added.replaced?.id ?? null, seq: added.seq };
247
+ }
@@ -0,0 +1,7 @@
1
+ import type { ParsedArgs } from "../args.ts";
2
+ interface HeavyIo {
3
+ write?: ((line: string) => void) | undefined;
4
+ now?: number;
5
+ }
6
+ export declare function heavy(verb: string | undefined, args: ParsedArgs, io?: HeavyIo): Promise<number>;
7
+ export {};
@@ -0,0 +1,123 @@
1
+ // `nmts heavy wallet` and `nmts heavy fund <USDFC>` — the EVM wallet this NMTS key derives for NMTS
2
+ // Heavy's self-paid road (developer mode): what it holds, and filling its Filecoin Pay deposit.
3
+ //
4
+ // ⛔ `wallet` READS AND NEVER SIGNS. The address is computed offline from the key (`heavy-evm.ts`);
5
+ // the balances are read from the chain with the address alone, so no key is even derived.
6
+ //
7
+ // ⛔ `fund` SIGNS AND SPENDS, with `wallet send`'s rules: the review first, nothing without `--yes`,
8
+ // the wallet agreement at scope `all`, and Calibration only — refused before anything is read
9
+ // where no storage company is listed. The deposit and the operator approval are one call of the
10
+ // Synapse SDK (`payments.fundSync`, which is what `storage.prepare(…).transaction.execute` runs),
11
+ // given the amount that was typed instead of one it works out from piece sizes.
12
+ import { requireAccountCode } from "../code-access.js";
13
+ import { readCredentialsFile } from "../credentials.js";
14
+ import { NmtsError } from "../errors.js";
15
+ import { HEAVY_COPY } from "../heavy-copy.js";
16
+ import { evmAddressFor, evmIndexOf, evmKeyOf, hexKey } from "../heavy-evm.js";
17
+ import { selfPayChain, synapseFor } from "../heavy-self-pay.js";
18
+ import { resolveNetwork } from "../network.js";
19
+ import { resolveServer } from "../server.js";
20
+ import { FILECOIN_CHAIN_FOR_NETWORK } from "../shared/lib/filecoin/providers.js";
21
+ import { requireWalletGrant } from "../wallet-grant.js";
22
+ /** USDFC and FIL both count in 18 decimals. */
23
+ const DECIMALS = 18;
24
+ export async function heavy(verb, args, io = {}) {
25
+ if (verb === "wallet")
26
+ return heavyWallet(args, io);
27
+ if (verb === "fund")
28
+ return heavyFund(args.operands[1], args, io);
29
+ throw new NmtsError(HEAVY_COPY.heavyVerb, { exitCode: 2 });
30
+ }
31
+ async function where(args) {
32
+ const resolved = await requireAccountCode();
33
+ const stored = resolved.source === "file" || resolved.source === "file-locked" ? readCredentialsFile() : null;
34
+ const server = resolveServer(args.server ?? stored?.server);
35
+ const network = resolveNetwork(server, args.network ?? stored?.network);
36
+ return { code: resolved.code, chain: FILECOIN_CHAIN_FOR_NETWORK[network], network };
37
+ }
38
+ async function readPurse(address, chain) {
39
+ const synapse = await synapseFor(address, chain);
40
+ const [fil, usdfc, summary] = await Promise.all([
41
+ synapse.payments.walletBalance(),
42
+ synapse.payments.walletBalance({ token: "USDFC" }),
43
+ synapse.payments.accountSummary(),
44
+ ]);
45
+ return { fil, usdfc, summary };
46
+ }
47
+ async function heavyWallet(args, io) {
48
+ const say = io.write ?? ((line) => process.stdout.write(`${line}\n`));
49
+ const index = evmIndexOf(args.index);
50
+ const { code, chain } = await where(args);
51
+ const address = await evmAddressFor(code, index);
52
+ const { formatUnits } = await import("viem");
53
+ const purse = await readPurse(address, chain);
54
+ const coins = (value) => formatUnits(value, DECIMALS);
55
+ const facts = {
56
+ index,
57
+ address,
58
+ chain,
59
+ fil: coins(purse.fil),
60
+ usdfc: coins(purse.usdfc),
61
+ deposit: coins(purse.summary.funds),
62
+ available: coins(purse.summary.availableFunds),
63
+ lockupPerEpoch: coins(purse.summary.lockupRatePerEpoch),
64
+ epoch: purse.summary.epoch.toString(),
65
+ runwayEpochs: purse.summary.runwayInEpochs.toString(),
66
+ };
67
+ if (args.json) {
68
+ say(JSON.stringify(facts));
69
+ return 0;
70
+ }
71
+ say(`${HEAVY_COPY.walletAddress} ${address}`);
72
+ say(`${HEAVY_COPY.walletFil} ${facts.fil}`);
73
+ say(`${HEAVY_COPY.walletUsdfc} ${facts.usdfc}`);
74
+ say(`${HEAVY_COPY.walletDeposit} ${facts.deposit} (${facts.available})`);
75
+ say(`${HEAVY_COPY.walletRunway} ${facts.epoch} + ${facts.runwayEpochs}`);
76
+ return 0;
77
+ }
78
+ async function heavyFund(amountRaw, args, io) {
79
+ const say = io.write ?? ((line) => process.stdout.write(`${line}\n`));
80
+ const index = evmIndexOf(args.index);
81
+ const { code, network } = await where(args);
82
+ // ⛔ BEFORE ANYTHING IS READ: no listed company on this chain means nothing to fund for.
83
+ const chain = selfPayChain(network);
84
+ const { formatUnits, parseUnits } = await import("viem");
85
+ let amount;
86
+ try {
87
+ amount = parseUnits((amountRaw ?? "").trim(), DECIMALS);
88
+ }
89
+ catch {
90
+ // viem refuses what is not a decimal number; the words are this tool's.
91
+ amount = 0n;
92
+ }
93
+ if (amountRaw === undefined || amount <= 0n)
94
+ throw new NmtsError(HEAVY_COPY.fundBadAmount(amountRaw ?? ""), { exitCode: 2 });
95
+ const address = await evmAddressFor(code, index);
96
+ const purse = await readPurse(address, chain);
97
+ const facts = { index, address, chain, amount: formatUnits(amount, DECIMALS), usdfc: formatUnits(purse.usdfc, DECIMALS), deposit: formatUnits(purse.summary.funds, DECIMALS) };
98
+ if (!args.json) {
99
+ say(HEAVY_COPY.fundReview(facts.amount, address));
100
+ say(`${HEAVY_COPY.walletUsdfc} ${facts.usdfc}`);
101
+ say(`${HEAVY_COPY.walletDeposit} ${facts.deposit}`);
102
+ }
103
+ if (args.dryRun || !args.yes) {
104
+ if (args.json)
105
+ say(JSON.stringify({ ...facts, signed: false, dryRun: args.dryRun }));
106
+ if (args.dryRun)
107
+ return 0;
108
+ throw new NmtsError(HEAVY_COPY.fundNeedsYes, { exitCode: 4 });
109
+ }
110
+ requireWalletGrant("send", { walFrost: 0n, suiMist: 0n }, new Date(io.now ?? Date.now()));
111
+ const key = await evmKeyOf(code, index);
112
+ const { privateKeyToAccount } = await import("viem/accounts");
113
+ const account = privateKeyToAccount(hexKey(key));
114
+ key.fill(0);
115
+ const synapse = await synapseFor(account, chain);
116
+ const done = await synapse.payments.fundSync({ amount });
117
+ if (args.json) {
118
+ say(JSON.stringify({ ...facts, signed: true, hash: done.hash }));
119
+ return 0;
120
+ }
121
+ say(HEAVY_COPY.fundDone(done.hash));
122
+ return 0;
123
+ }
@@ -0,0 +1,12 @@
1
+ export interface LinkOptions {
2
+ server?: string | undefined;
3
+ network?: string | undefined;
4
+ hideName?: boolean;
5
+ /** `<n>d`. */
6
+ expires?: string | undefined;
7
+ out?: string | undefined;
8
+ force?: boolean;
9
+ json?: boolean;
10
+ write?: (line: string) => void;
11
+ }
12
+ export declare function link(sub: string | undefined, operand: string | undefined, options?: LinkOptions): Promise<number>;
@@ -0,0 +1,121 @@
1
+ // `nmts link make|list|revoke|open` — public links (NCF-3 §5.8). The work is in
2
+ // `../links.ts`, which the SDK calls too; this file is the terminal around it.
3
+ //
4
+ // ⛔ `open` NEEDS NO LOGIN. It reads the link, asks the server for the token only, and writes one file
5
+ // here — the name the owner showed (its last segment), or `nmts-link-<token>` when it was hidden.
6
+ //
7
+ // ⛔ `make` sits behind the `share` unlock (`risk.ts`), because it gives the file to whoever holds the
8
+ // link. The gate asks for the yes; the trade-off line is what it shows.
9
+ //
10
+ import { resolve } from "node:path";
11
+ import { fileSink } from "../download-sink-node.js";
12
+ import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../drive-paths.js";
13
+ import { NmtsError } from "../errors.js";
14
+ import { listLinks, makeLink, openLink, revokeLink } from "../links.js";
15
+ import { readFileList } from "../manifest.js";
16
+ import { resolveNetwork } from "../network.js";
17
+ import { BINARY_NAME } from "../product.js";
18
+ import { readCredentialsFile } from "../credentials.js";
19
+ import { destinationFor } from "../safe-path.js";
20
+ import { resolveServer } from "../server.js";
21
+ import { openSession } from "../session.js";
22
+ import { linkExpiryDays } from "../shared/lib/share/public-link.js";
23
+ const USAGE = `\`${BINARY_NAME} link make <path> [--hide-name] [--expires <n>d]\` · \`${BINARY_NAME} link list <path>\` · ` +
24
+ `\`${BINARY_NAME} link revoke <id>\` · \`${BINARY_NAME} link open <link> [--out <path>]\``;
25
+ export async function link(sub, operand, options = {}) {
26
+ const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
27
+ if (sub !== "make" && sub !== "list" && sub !== "revoke" && sub !== "open") {
28
+ throw new NmtsError("Say `make`, `list`, `revoke` or `open`.", { exitCode: 2, nextStep: USAGE });
29
+ }
30
+ if (operand === undefined || operand === "") {
31
+ throw new NmtsError(`Say which ${sub === "revoke" ? "link id" : sub === "open" ? "link" : "file"}.`, {
32
+ exitCode: 2,
33
+ nextStep: USAGE,
34
+ });
35
+ }
36
+ if (sub === "open")
37
+ return await open(operand, options, say);
38
+ if (sub === "revoke") {
39
+ const session = await openSession({ server: options.server, network: options.network });
40
+ await revokeLink(accountOf(session), operand);
41
+ say(options.json === true ? JSON.stringify({ id: operand, cut: true }) : `${operand} cut`);
42
+ return 0;
43
+ }
44
+ const session = await openSession({ server: options.server, network: options.network });
45
+ const entry = await fileAt(session, operand);
46
+ if (sub === "list") {
47
+ const links = await listLinks(accountOf(session), entry.id);
48
+ if (options.json === true) {
49
+ say(JSON.stringify({ path: operand, links }));
50
+ return 0;
51
+ }
52
+ for (const row of links) {
53
+ const state = row.cutAt === null ? `downloads ${row.downloads}` : `cut ${row.cutAt} by ${row.cutBy ?? "?"}`;
54
+ say(`${row.id} made ${row.createdAt} ${state}`);
55
+ if (row.link !== null)
56
+ say(` ${row.link}`);
57
+ }
58
+ return 0;
59
+ }
60
+ const days = expiryOf(options.expires);
61
+ const made = await makeLink(accountOf(session), entry, { showName: options.hideName !== true, expiresDays: days });
62
+ if (options.json === true) {
63
+ say(JSON.stringify(made));
64
+ return 0;
65
+ }
66
+ say(made.link);
67
+ say(` id ${made.id}${made.expiresAt === null ? "" : ` expires ${made.expiresAt}`}`);
68
+ return 0;
69
+ }
70
+ /** `30d` → 30. Absent → never. */
71
+ function expiryOf(value) {
72
+ if (value === undefined)
73
+ return null;
74
+ const match = /^([0-9]+)d$/u.exec(value.trim());
75
+ const days = match?.[1] === undefined ? null : linkExpiryDays(Number(match[1]));
76
+ if (days === null) {
77
+ throw new NmtsError(`--expires takes a number of days, like 30d, from 1d to 3650d.`, { exitCode: 2, nextStep: USAGE });
78
+ }
79
+ return days;
80
+ }
81
+ function accountOf(session) {
82
+ return { server: session.server, bearer: session.apiKey, code: session.code };
83
+ }
84
+ async function fileAt(session, target) {
85
+ const list = await readFileList(session.server, session.apiKey, session.code, session.accountId);
86
+ if (list.manifest === null) {
87
+ throw new NmtsError("This account has no file list, so there is nothing to link.", { exitCode: 4 });
88
+ }
89
+ const entry = entryAt(list.manifest.entries, normalisePath(target), { nothingHappened: "Nothing was changed." });
90
+ if (entry.kind !== KIND_FILE) {
91
+ throw new NmtsError(`No file at "${fullPathOf(buildIndex(list.manifest.entries), entry)}".`, {
92
+ exitCode: 4,
93
+ nextStep: "That is a folder, and a link is to one file.",
94
+ });
95
+ }
96
+ return entry;
97
+ }
98
+ async function open(text, options, say) {
99
+ // ⛔ No session: a link is opened by whoever holds it. Only where to ask and which network to read.
100
+ const stored = readCredentialsFile();
101
+ const server = resolveServer(options.server ?? stored?.server);
102
+ const chain = resolveNetwork(server, options.network ?? stored?.network);
103
+ let destination = "";
104
+ const opened = await openLink({
105
+ link: text,
106
+ server,
107
+ chain,
108
+ sink: (name) => {
109
+ const token = /\/l\/([A-Za-z0-9_-]{22})/u.exec(text)?.[1] ?? "file";
110
+ destination = options.out !== undefined ? resolve(options.out) : destinationFor(".", name ?? `nmts-link-${token}`);
111
+ return fileSink(destination, { force: options.force === true });
112
+ },
113
+ });
114
+ if (options.json === true) {
115
+ say(JSON.stringify({ name: opened.name, bytes: opened.bytes, out: destination }));
116
+ return 0;
117
+ }
118
+ say(`${opened.name ?? "(name hidden)"} ${opened.bytes} bytes`);
119
+ say(` saved to ${destination}, checked against the hash the owner sealed with it`);
120
+ return 0;
121
+ }
@@ -1,3 +1,4 @@
1
+ import type { StorageTier } from "../shared/lib/storage-tier.ts";
1
2
  export interface LsOptions {
2
3
  server?: string | undefined;
3
4
  network?: string | undefined;
@@ -18,6 +19,10 @@ export interface LsOptions {
18
19
  sort?: string | undefined;
19
20
  /** Reverse whichever order is in effect. */
20
21
  desc?: boolean;
22
+ /** Add the tier each file is stored on — one more read of the server per file (`list-tier.ts`). */
23
+ long?: boolean;
24
+ /** ⚠ A SEAM, NOT AN OPTION: where the tiers are read from. */
25
+ readTiers?: (ids: readonly string[]) => Promise<Map<string, StorageTier | null>>;
21
26
  write?: (line: string) => void;
22
27
  /** The instant the trash countdown is measured against. Passed in so one listing means one moment. */
23
28
  now?: number;
@@ -27,6 +27,7 @@ import { readFileList } from "../manifest.js";
27
27
  import { openSession } from "../session.js";
28
28
  import { daysLeftInTrash, TRASH_RETENTION_DAYS } from "../trash-sweep.js";
29
29
  import { humanSize } from "../units.js";
30
+ import { tierLabel, tiersOf } from "../list-tier.js";
30
31
  /**
31
32
  * How much of a trashed entry's thirty days is left, in the words beside its row.
32
33
  *
@@ -119,6 +120,11 @@ export async function ls(options = {}) {
119
120
  ...(e.pinned === true ? { pinned: true } : {}),
120
121
  }));
121
122
  const rows = sort === null ? byPath(mapped, dir) : orderRows(mapped, sort, dir);
123
+ const fileIds = options.long === true ? rows.filter((r) => r.kind !== KIND_FOLDER).map((r) => r.id) : [];
124
+ const tiers = options.long === true
125
+ ? await (options.readTiers ?? ((ids) => tiersOf(session.server, session.apiKey, ids)))(fileIds)
126
+ : null;
127
+ const tierOfRow = (row) => (row.kind === KIND_FOLDER ? "" : tierLabel(tiers?.get(row.id) ?? null));
122
128
  if (options.json) {
123
129
  say(JSON.stringify({
124
130
  state: "present",
@@ -141,6 +147,7 @@ export async function ls(options = {}) {
141
147
  trashed: row.trashed,
142
148
  trashedAt: row.trashedAt,
143
149
  marks: row.marks,
150
+ ...(tiers === null ? {} : { tier: row.kind === KIND_FOLDER ? null : (tiers.get(row.id) ?? null) }),
144
151
  })),
145
152
  }));
146
153
  return 0;
@@ -162,7 +169,8 @@ export async function ls(options = {}) {
162
169
  const mark = row.trashed
163
170
  ? ` [trash${row.trashedAt === null ? "" : `, ${trashWindow(row.trashedAt, now)}`}]`
164
171
  : "";
165
- say(`${row.path.padEnd(width)} ${size.padStart(9)}${mark}${markSuffix(row.marks)}`);
172
+ const tier = tiers === null ? "" : ` ${tierOfRow(row).padEnd(8)}`;
173
+ say(`${row.path.padEnd(width)} ${size.padStart(9)}${tier}${mark}${markSuffix(row.marks)}`);
166
174
  }
167
175
  say(``);
168
176
  const files = rows.filter((r) => r.kind !== KIND_FOLDER).length;
@@ -0,0 +1,24 @@
1
+ import { type CryptoGlue } from "../crypto.ts";
2
+ import { type PublicCodeRow } from "../public-codes.ts";
3
+ export interface PublicCodeManageOptions {
4
+ server?: string | undefined;
5
+ network?: string | undefined;
6
+ json?: boolean;
7
+ /** The person's yes to a revoke, or the one the tier gate already took. */
8
+ yes?: boolean;
9
+ /** `list`: each code's shares as well as its counts. */
10
+ activity?: boolean;
11
+ /** `new`: the number of the live code the new one replaces. */
12
+ replace?: string | undefined;
13
+ write?: (line: string) => void;
14
+ /** Injected in tests: answers the revoke question. */
15
+ readLine?: ((question: string) => Promise<string>) | undefined;
16
+ }
17
+ /** The code this key derives at `row`'s number, as a person reads it — or `differentCode` when the server's differs. */
18
+ export declare function checkedDisplay(crypt: CryptoGlue, code: string, row: PublicCodeRow): string;
19
+ /** `nmts public-code list [--activity]` — every code, live ones first, and the two ceilings. */
20
+ export declare function listCodes(options?: PublicCodeManageOptions): Promise<number>;
21
+ /** `nmts public-code new [--replace <n>]` — the next number, published; with --replace, that code revoked in the same request. */
22
+ export declare function newCode(options?: PublicCodeManageOptions): Promise<number>;
23
+ /** `nmts public-code revoke <n>` — one way, and never the last live code. */
24
+ export declare function revokeCodeCommand(operand: string | undefined, options?: PublicCodeManageOptions): Promise<number>;