@needmoretruth/nmts-cli 0.45.0 → 0.46.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 (224) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +61 -0
  3. package/README.ko.md +6 -3
  4. package/README.md +15 -3
  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 +8 -0
  9. package/dist/args.js +7 -1
  10. package/dist/artifact-about.d.ts +1 -1
  11. package/dist/collision.d.ts +20 -3
  12. package/dist/collision.js +21 -3
  13. package/dist/commands/erase.js +1 -0
  14. package/dist/commands/handover.d.ts +13 -0
  15. package/dist/commands/handover.js +328 -0
  16. package/dist/commands/heavy-run.d.ts +59 -0
  17. package/dist/commands/heavy-run.js +247 -0
  18. package/dist/commands/heavy.d.ts +7 -0
  19. package/dist/commands/heavy.js +123 -0
  20. package/dist/commands/ls.d.ts +5 -0
  21. package/dist/commands/ls.js +9 -1
  22. package/dist/commands/public-code.d.ts +6 -0
  23. package/dist/commands/public-code.js +46 -0
  24. package/dist/commands/push-heavy.d.ts +6 -0
  25. package/dist/commands/push-heavy.js +128 -0
  26. package/dist/commands/push-tree.d.ts +24 -0
  27. package/dist/commands/push-tree.js +91 -0
  28. package/dist/commands/push.d.ts +4 -13
  29. package/dist/commands/push.js +7 -77
  30. package/dist/commands/put-heavy.d.ts +9 -0
  31. package/dist/commands/put-heavy.js +120 -0
  32. package/dist/commands/put-payer.d.ts +21 -0
  33. package/dist/commands/put-payer.js +24 -0
  34. package/dist/commands/put.d.ts +2 -2
  35. package/dist/commands/put.js +8 -7
  36. package/dist/commands/receive.js +3 -3
  37. package/dist/commands/s3.js +44 -10
  38. package/dist/crypto-surface.d.ts +8 -0
  39. package/dist/crypto-surface.js +3 -0
  40. package/dist/crypto.d.ts +3 -0
  41. package/dist/crypto.js +3 -0
  42. package/dist/download-part.d.ts +32 -1
  43. package/dist/download-part.js +95 -6
  44. package/dist/download-range.d.ts +19 -0
  45. package/dist/download-range.js +108 -0
  46. package/dist/download-sink.d.ts +15 -0
  47. package/dist/download.d.ts +14 -0
  48. package/dist/download.js +19 -4
  49. package/dist/handover.d.ts +44 -0
  50. package/dist/handover.js +199 -0
  51. package/dist/heavy-api.d.ts +36 -0
  52. package/dist/heavy-api.js +107 -0
  53. package/dist/heavy-copy.d.ts +72 -0
  54. package/dist/heavy-copy.js +108 -0
  55. package/dist/heavy-evm.d.ts +20 -0
  56. package/dist/heavy-evm.js +106 -0
  57. package/dist/heavy-self-pay.d.ts +92 -0
  58. package/dist/heavy-self-pay.js +167 -0
  59. package/dist/heavy-upload.d.ts +87 -0
  60. package/dist/heavy-upload.js +154 -0
  61. package/dist/heavy-wallet-pay.d.ts +39 -0
  62. package/dist/heavy-wallet-pay.js +73 -0
  63. package/dist/help-options.js +4 -2
  64. package/dist/help.js +16 -3
  65. package/dist/list-tier.d.ts +7 -0
  66. package/dist/list-tier.js +47 -0
  67. package/dist/main.js +12 -10
  68. package/dist/manifest-write.d.ts +4 -3
  69. package/dist/platform-sign.d.ts +4 -4
  70. package/dist/platform-sign.js +3 -3
  71. package/dist/portable.d.ts +15 -0
  72. package/dist/portable.js +11 -0
  73. package/dist/product.d.ts +1 -1
  74. package/dist/product.js +1 -1
  75. package/dist/recovery-build.js +16 -0
  76. package/dist/recovery-map-part.d.ts +82 -0
  77. package/dist/recovery-map-part.js +83 -0
  78. package/dist/recovery-map.d.ts +5 -40
  79. package/dist/recovery-map.js +18 -1
  80. package/dist/recovery-source.d.ts +3 -0
  81. package/dist/recovery-source.js +9 -0
  82. package/dist/risk.d.ts +30 -0
  83. package/dist/risk.js +23 -2
  84. package/dist/run-log.d.ts +1 -1
  85. package/dist/run-log.js +7 -1
  86. package/dist/s3/address.d.ts +20 -0
  87. package/dist/s3/address.js +97 -0
  88. package/dist/s3/answer.d.ts +48 -0
  89. package/dist/s3/answer.js +330 -0
  90. package/dist/s3/body-deframe.d.ts +49 -0
  91. package/dist/s3/body-deframe.js +264 -0
  92. package/dist/s3/body-measure.d.ts +13 -0
  93. package/dist/s3/body-measure.js +48 -0
  94. package/dist/s3/body-plan.d.ts +31 -0
  95. package/dist/s3/body-plan.js +159 -0
  96. package/dist/s3/body.d.ts +46 -0
  97. package/dist/s3/body.js +117 -0
  98. package/dist/s3/call.d.ts +36 -0
  99. package/dist/s3/call.js +42 -0
  100. package/dist/s3/checksum.d.ts +26 -0
  101. package/dist/s3/checksum.js +176 -0
  102. package/dist/s3/content-type.d.ts +3 -0
  103. package/dist/s3/content-type.js +49 -0
  104. package/dist/s3/contract.d.ts +91 -14
  105. package/dist/s3/drive-conditions.d.ts +47 -0
  106. package/dist/s3/drive-conditions.js +134 -0
  107. package/dist/s3/drive-key.d.ts +11 -0
  108. package/dist/s3/drive-key.js +58 -0
  109. package/dist/s3/drive-limits.d.ts +33 -0
  110. package/dist/s3/drive-limits.js +53 -0
  111. package/dist/s3/drive-lock.d.ts +11 -0
  112. package/dist/s3/drive-lock.js +47 -0
  113. package/dist/s3/drive-trashed-name.d.ts +13 -0
  114. package/dist/s3/drive-trashed-name.js +59 -0
  115. package/dist/s3/drive-write.d.ts +38 -0
  116. package/dist/s3/drive-write.js +258 -0
  117. package/dist/s3/drive.d.ts +59 -25
  118. package/dist/s3/drive.js +46 -77
  119. package/dist/s3/listing.d.ts +27 -1
  120. package/dist/s3/listing.js +62 -20
  121. package/dist/s3/long-answer.d.ts +12 -0
  122. package/dist/s3/long-answer.js +104 -0
  123. package/dist/s3/multipart-assemble.d.ts +17 -0
  124. package/dist/s3/multipart-assemble.js +68 -0
  125. package/dist/s3/multipart-sweep.d.ts +15 -0
  126. package/dist/s3/multipart-sweep.js +87 -0
  127. package/dist/s3/multipart-view.d.ts +45 -0
  128. package/dist/s3/multipart-view.js +232 -0
  129. package/dist/s3/multipart.d.ts +26 -19
  130. package/dist/s3/multipart.js +193 -78
  131. package/dist/s3/object-read.d.ts +17 -0
  132. package/dist/s3/object-read.js +127 -0
  133. package/dist/s3/object-write.d.ts +35 -0
  134. package/dist/s3/object-write.js +198 -0
  135. package/dist/s3/range.d.ts +14 -0
  136. package/dist/s3/range.js +80 -0
  137. package/dist/s3/response-sink.d.ts +12 -2
  138. package/dist/s3/response-sink.js +71 -7
  139. package/dist/s3/routes.d.ts +0 -1
  140. package/dist/s3/routes.js +242 -217
  141. package/dist/s3/same-file.d.ts +4 -1
  142. package/dist/s3/same-file.js +12 -3
  143. package/dist/s3/server.d.ts +54 -4
  144. package/dist/s3/server.js +174 -14
  145. package/dist/s3/sigv4-canonical.d.ts +91 -0
  146. package/dist/s3/sigv4-canonical.js +148 -0
  147. package/dist/s3/sigv4-presigned.d.ts +13 -0
  148. package/dist/s3/sigv4-presigned.js +82 -0
  149. package/dist/s3/sigv4.d.ts +26 -27
  150. package/dist/s3/sigv4.js +137 -102
  151. package/dist/s3/spool.d.ts +37 -0
  152. package/dist/s3/spool.js +104 -0
  153. package/dist/s3/staging.d.ts +90 -7
  154. package/dist/s3/staging.js +97 -66
  155. package/dist/s3/xml-multipart.d.ts +38 -0
  156. package/dist/s3/xml-multipart.js +47 -0
  157. package/dist/s3/xml-read.d.ts +28 -0
  158. package/dist/s3/xml-read.js +235 -0
  159. package/dist/s3/xml.d.ts +45 -2
  160. package/dist/s3/xml.js +72 -13
  161. package/dist/s3-gateway.d.ts +11 -5
  162. package/dist/s3-gateway.js +5 -2
  163. package/dist/seal.d.ts +1 -1
  164. package/dist/share.d.ts +5 -0
  165. package/dist/share.js +1 -1
  166. package/dist/shared/lib/api/types-heavy.d.ts +167 -0
  167. package/dist/shared/lib/api/types-heavy.js +60 -0
  168. package/dist/shared/lib/drive/rebuild-verify.js +1 -0
  169. package/dist/shared/lib/filecoin/providers.d.ts +25 -0
  170. package/dist/shared/lib/filecoin/providers.js +58 -0
  171. package/dist/shared/lib/heavy/download.d.ts +48 -0
  172. package/dist/shared/lib/heavy/download.js +116 -0
  173. package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
  174. package/dist/shared/lib/heavy/order-plan.js +83 -0
  175. package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
  176. package/dist/shared/lib/heavy/order-runner.js +300 -0
  177. package/dist/shared/lib/heavy/order-types.d.ts +90 -0
  178. package/dist/shared/lib/heavy/order-types.js +6 -0
  179. package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
  180. package/dist/shared/lib/heavy/order-wire.js +113 -0
  181. package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
  182. package/dist/shared/lib/heavy/piece-cid.js +55 -0
  183. package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
  184. package/dist/shared/lib/heavy/sp-upload.js +112 -0
  185. package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
  186. package/dist/shared/lib/heavy/synapse-piece.js +8 -0
  187. package/dist/shared/lib/share/handover-format.d.ts +129 -0
  188. package/dist/shared/lib/share/handover-format.js +323 -0
  189. package/dist/shared/lib/share/shared-file-info.js +1 -0
  190. package/dist/shared/lib/storage-network.d.ts +4 -4
  191. package/dist/shared/lib/storage-network.js +7 -7
  192. package/dist/shared/lib/storage-tier.d.ts +28 -0
  193. package/dist/shared/lib/storage-tier.js +63 -0
  194. package/dist/shared/lib/wallet/send-rules.js +1 -0
  195. package/dist/upload-file.d.ts +8 -0
  196. package/dist/upload-file.js +57 -25
  197. package/dist/upload-price-node.d.ts +3 -0
  198. package/dist/upload-price-node.js +3 -6
  199. package/dist/upload-price.d.ts +10 -0
  200. package/dist/upload-price.js +13 -1
  201. package/dist/upload-run.d.ts +80 -0
  202. package/dist/upload-run.js +173 -0
  203. package/dist/upload-steps.js +15 -4
  204. package/dist/upload-store.d.ts +15 -6
  205. package/dist/upload-store.js +6 -0
  206. package/dist/upload-wallet-put.d.ts +9 -4
  207. package/dist/upload-wallet-put.js +16 -6
  208. package/dist/upload-wallet.js +4 -0
  209. package/dist/upload-wire.d.ts +25 -0
  210. package/dist/upload-wire.js +20 -1
  211. package/dist/upload.js +28 -13
  212. package/dist/wallet-sign.js +2 -2
  213. package/docs/commands/handover.md +38 -0
  214. package/docs/commands/heavy.md +35 -0
  215. package/docs/commands/public-code.md +7 -0
  216. package/docs/commands/push.md +4 -1
  217. package/docs/commands/put.md +15 -1
  218. package/docs/commands/share.md +3 -1
  219. package/package.json +5 -2
  220. package/server.json +2 -2
  221. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
  222. package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
  223. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  224. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
package/dist/portable.js CHANGED
@@ -59,6 +59,7 @@ export { partKeysOf, uploadFile } from "./upload-file.js";
59
59
  export { createUploadApi } from "./upload-api.js";
60
60
  export { CREDIT_BYTES, creditsFor, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "./upload-price.js";
61
61
  export { clearItemRecord, clearReservation } from "./upload-store.js";
62
+ export { forgetUpload } from "./upload-run.js";
62
63
  export { UploadError } from "./upload-wire.js";
63
64
  export { DEFAULT_PART_BYTES } from "./seal.js";
64
65
  export { createBlobProtocol, readCurrentEpoch } from "./walrus-write.js";
@@ -87,5 +88,15 @@ export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/
87
88
  export { classify } from "./shared/lib/drive/preview-classify.js";
88
89
  export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.js";
89
90
  export { hasHistory } from "./wallet-list-chain.js";
91
+ // NMTS Heavy: the tier word every interface reads, an upload paid through an order (credits, or WAL
92
+ // once stored), and developer mode's self-paid road from the key's own EVM wallet (NCF-3 §1.9).
93
+ // ⚠ The Synapse SDK behind the self-paid road is loaded only when that road runs.
94
+ export { DEFAULT_STORAGE_TIER, isStorageTier, networkForTier, parseStorageTier, STORAGE_TIERS, tierForNetwork } from "./shared/lib/storage-tier.js";
95
+ export { heavyCredits, heavyOrderPut, planHeavyFile } from "./heavy-upload.js";
96
+ export { copiesOf, heavySelfPut, providersOf, selfPayChain, SELF_PAY_DEFAULT_COPIES, SELF_PAY_MAX_COPIES } from "./heavy-self-pay.js";
97
+ export { heavyWalletPut } from "./heavy-wallet-pay.js";
98
+ export { evmAccountFor, evmAddressFor, evmAddressOf, evmIndexOf, evmKeyOf, hexKey } from "./heavy-evm.js";
99
+ export { HeavyOrderError } from "./shared/lib/heavy/order-runner.js";
100
+ export { HEAVY_COPY } from "./heavy-copy.js";
90
101
  // What this package is.
91
102
  export { HOME_URL, PRODUCT_NAME, SOURCE_URL, SUPPORT_EMAIL, VERSION } from "./product.js";
package/dist/product.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare const BINARY_NAME = "nmts";
9
9
  * beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
10
10
  * command importing the entry point is a cycle waiting to bite.
11
11
  */
12
- export declare const VERSION = "0.45.0";
12
+ export declare const VERSION = "0.46.0";
13
13
  /** Where the product lives, for messages that need to send somebody somewhere real. */
14
14
  export declare const HOME_URL = "https://nmts.me";
15
15
  /** The source, so a person holding only the built program can find what it was built from. */
package/dist/product.js CHANGED
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
18
18
  * beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
19
19
  * command importing the entry point is a cycle waiting to bite.
20
20
  */
21
- export const VERSION = "0.45.0";
21
+ export const VERSION = "0.46.0";
22
22
  /** Where the product lives, for messages that need to send somebody somewhere real. */
23
23
  export const HOME_URL = "https://nmts.me";
24
24
  /** The source, so a person holding only the built program can find what it was built from. */
@@ -29,6 +29,12 @@ import { NCF3_SHAPE } from "./seal.js";
29
29
  import { freeCeiling, keepLengths, padmeLen, pow2Len, } from "./shared/lib/crypto/size-padding.js";
30
30
  import { buildIndex, KIND_FOLDER, pathOf } from "./shared/lib/drive/manifest-index.js";
31
31
  import { NETWORK_WHEN_UNRECORDED, networkName, } from "./shared/lib/storage-network.js";
32
+ import { NETWORK_FILECOIN } from "./shared/lib/storage-network.js";
33
+ import { FILECOIN_CHAIN_FOR_NETWORK } from "./shared/lib/filecoin/providers.js";
34
+ /** The Filecoin chain that goes with this list's chain; null for one this build does not pair. */
35
+ function filecoinChainOf(chain) {
36
+ return chain === "testnet" || chain === "mainnet" ? FILECOIN_CHAIN_FOR_NETWORK[chain] : null;
37
+ }
32
38
  import { CREDIT_BYTES } from "./upload-price.js";
33
39
  const utf8 = new TextEncoder();
34
40
  /** Path of the account root. Every file sits at this or below it. */
@@ -169,6 +175,16 @@ export function buildRecoveryList(input) {
169
175
  part.padded_len = p.streamPlaintextLen;
170
176
  if (p.sui_object_id !== undefined)
171
177
  part.sui_object_id = p.sui_object_id;
178
+ // NRM-5: a Heavy part also names its Filecoin chain — this build's, as for every other network
179
+ // fact in the list — and the companies keeping it, in the order the server stored them. The
180
+ // encoder refuses the part if either is not something a reader accepts.
181
+ if (p.network === NETWORK_FILECOIN) {
182
+ const chain = filecoinChainOf(input.meta.storage.chain);
183
+ if (chain !== null)
184
+ part.chain = chain;
185
+ if (p.copies !== undefined)
186
+ part.copies = p.copies;
187
+ }
172
188
  return part;
173
189
  });
174
190
  // A quilted file is one patch inside one shared blob — by construction one part — so the
@@ -0,0 +1,82 @@
1
+ /** The network name a Filecoin part carries — the word the storage-network table registers. */
2
+ export declare const NETWORK_NAME_FILECOIN = "filecoin";
3
+ /** The Filecoin networks a part may name in `chain`. */
4
+ export type ManifestFilecoinChain = "calibration" | "mainnet";
5
+ /** The most copies one part may list; the reader refuses more. */
6
+ export declare const MAX_FILECOIN_COPIES = 12;
7
+ /**
8
+ * One storage company keeping a whole copy of a Filecoin part. The three numbers are decimal
9
+ * STRINGS because the contracts count them as `uint256`; `retrieval_url` is where the company served
10
+ * the piece when the list was written — a hint; the registry on `chain` has its current address.
11
+ */
12
+ export interface ManifestFilecoinCopy {
13
+ provider_id: string;
14
+ data_set_id: string;
15
+ piece_id: string;
16
+ retrieval_url: string;
17
+ }
18
+ /** One stored piece of a file, in order. */
19
+ export interface ManifestPart {
20
+ /**
21
+ * Where this part belongs: 0 for the first, and the position it must be concatenated at
22
+ * thereafter. Required from NRM-2.
23
+ *
24
+ * It is written down because array order alone cannot be CHECKED. A reader holds each fetched
25
+ * part's 72-byte NCF-3 header, which carries the index sealed under the file key, so with this
26
+ * field it can compare three things that must agree: the position it is writing at, what the
27
+ * list says belongs there, and what the bytes themselves say they are.
28
+ */
29
+ part_index: number;
30
+ /** Blob id holding this part's stream, in `network`'s own naming (a PieceCID on Filecoin). */
31
+ blob_id?: string;
32
+ /** The REAL bytes this part contributes to the file. */
33
+ plaintext_len: number;
34
+ /**
35
+ * What the stored stream's header DECLARES, when the part was padded and that is larger.
36
+ * Absent means it was not padded. New in NRM-4.
37
+ *
38
+ * ⛔ THE TWO NUMBERS STAY APART so that "the parts sum to exactly `size`" keeps its exact
39
+ * strength. Folded into one, the check softens to "at least", which accepts any size below
40
+ * the real one: the file comes back short and nothing says so.
41
+ */
42
+ padded_len?: number;
43
+ /** On-chain blob object, when the uploading client captured it. Omitted, never null. */
44
+ sui_object_id?: string;
45
+ /**
46
+ * Which storage network holds `blob_id` — a NAME (`"walrus"`, `"filecoin"`), not a code.
47
+ *
48
+ * A word rather than a number because whoever parses this may be doing so years from now with
49
+ * none of our code beside them, and a bare `1` is not something a stranger can look up.
50
+ */
51
+ network?: string;
52
+ /** The Filecoin network that issued `blob_id`. On a Filecoin part only, and required there (NRM-5). */
53
+ chain?: ManifestFilecoinChain;
54
+ /** The companies keeping a whole copy, in the order a reader tries them. Filecoin only, 1..=12. */
55
+ copies?: ManifestFilecoinCopy[];
56
+ }
57
+ /** As a writer hands one in: the position is the value, so `part_index` is filled by the encoder. */
58
+ export interface ManifestPartInput extends Omit<ManifestPart, "part_index" | "copies"> {
59
+ part_index?: number;
60
+ copies?: readonly ManifestFilecoinCopy[];
61
+ }
62
+ /** Whether a part uses an NRM-5 form — what makes a document need `v: 5`. */
63
+ export declare function usesFilecoin(part: Pick<ManifestPartInput, "network" | "chain" | "copies">): boolean;
64
+ /** A part's Filecoin form: nothing to write, the two fields to write, or why it cannot be written. */
65
+ export type FilecoinForm = {
66
+ readonly kind: "none";
67
+ } | {
68
+ readonly kind: "filecoin";
69
+ readonly chain: ManifestFilecoinChain;
70
+ readonly copies: ManifestFilecoinCopy[];
71
+ } | {
72
+ readonly kind: "refused";
73
+ readonly why: string;
74
+ };
75
+ /**
76
+ * Decide a part's Filecoin fields, or say why they cannot be written. `why` finishes a sentence
77
+ * that begins "the part …". The reader's rules, in its order: `chain` and `copies` only on a
78
+ * Filecoin part, no Filecoin part in a quilted item, a known chain, a PieceCIDv2 `blob_id`, 1..=12
79
+ * copies, three canonical decimal `uint256` numbers per copy, and a `retrieval_url` of
80
+ * `https://<host>…/piece/<blob_id>` with no query or fragment.
81
+ */
82
+ export declare function filecoinForm(part: Pick<ManifestPartInput, "network" | "chain" | "copies" | "blob_id">, inQuilt: boolean): FilecoinForm;
@@ -0,0 +1,83 @@
1
+ // One stored piece of a file in the recovery list — the wire shape of a part, and the rules its
2
+ // Filecoin form (NRM-5, NMTS Heavy) must meet to be written.
3
+ //
4
+ // ⚠ RESTATED FROM THE BROWSER'S WRITER (`web/src/lib/recovery/manifest-part.ts`), which this package
5
+ // cannot import, and held to the same shared sample the Rust reader and the browser are held to
6
+ // (`crypto/tests/vectors/nrm5-sample.json`). It moved out of `recovery-map.ts` because NRM-5 gave a
7
+ // part two more fields and that file was near its length ceiling; `recovery-map.ts` re-exports it.
8
+ //
9
+ // ⛔ THE READER REFUSES THE WHOLE DOCUMENT over one Filecoin part that breaks these rules, so a list
10
+ // a writer let one through would open nothing — on the day it is somebody's only copy. So the
11
+ // writer applies every rule the reader applies, in the reader's order, and refuses instead.
12
+ /** The network name a Filecoin part carries — the word the storage-network table registers. */
13
+ export const NETWORK_NAME_FILECOIN = "filecoin";
14
+ const FILECOIN_CHAINS = ["calibration", "mainnet"];
15
+ /** The most copies one part may list; the reader refuses more. */
16
+ export const MAX_FILECOIN_COPIES = 12;
17
+ /** 2²⁵⁶ − 1 in decimal: the largest number the provider contracts' `uint256` holds. */
18
+ const U256_MAX_DECIMAL = "115792089237316195423570985008687907853269984665640564039457584007913129639935";
19
+ /** A PieceCIDv2 string: `bafkzcib` then lowercase base32, at most 128 characters. */
20
+ const PIECE_CID = /^bafkzcib[a-z2-7]+$/;
21
+ const MAX_PIECE_CID_LEN = 128;
22
+ /** Whether a part uses an NRM-5 form — what makes a document need `v: 5`. */
23
+ export function usesFilecoin(part) {
24
+ return part.network === NETWORK_NAME_FILECOIN || part.chain !== undefined || part.copies !== undefined;
25
+ }
26
+ const COPY_NUMBERS = ["provider_id", "data_set_id", "piece_id"];
27
+ /**
28
+ * Decide a part's Filecoin fields, or say why they cannot be written. `why` finishes a sentence
29
+ * that begins "the part …". The reader's rules, in its order: `chain` and `copies` only on a
30
+ * Filecoin part, no Filecoin part in a quilted item, a known chain, a PieceCIDv2 `blob_id`, 1..=12
31
+ * copies, three canonical decimal `uint256` numbers per copy, and a `retrieval_url` of
32
+ * `https://<host>…/piece/<blob_id>` with no query or fragment.
33
+ */
34
+ export function filecoinForm(part, inQuilt) {
35
+ const { chain, copies } = part;
36
+ if (part.network !== NETWORK_NAME_FILECOIN) {
37
+ if (chain === undefined && copies === undefined)
38
+ return { kind: "none" };
39
+ return { kind: "refused", why: `carries chain or copies but is on ${part.network ?? "walrus"}, not filecoin` };
40
+ }
41
+ if (inQuilt)
42
+ return { kind: "refused", why: "is on filecoin but its item is placed in a quilt" };
43
+ if (chain === undefined || !FILECOIN_CHAINS.includes(chain)) {
44
+ return { kind: "refused", why: `is on filecoin and names no known chain (${String(chain)})` };
45
+ }
46
+ const cid = part.blob_id;
47
+ if (typeof cid !== "string" || cid.length > MAX_PIECE_CID_LEN || !PIECE_CID.test(cid)) {
48
+ return { kind: "refused", why: "is on filecoin and its blob_id is not a PieceCIDv2" };
49
+ }
50
+ if (copies === undefined || copies.length < 1 || copies.length > MAX_FILECOIN_COPIES) {
51
+ return { kind: "refused", why: `is on filecoin and lists ${copies?.length ?? 0} copies, outside 1..=${MAX_FILECOIN_COPIES}` };
52
+ }
53
+ for (const [n, copy] of copies.entries()) {
54
+ const bad = COPY_NUMBERS.find((field) => !isU256Decimal(copy[field]));
55
+ if (bad)
56
+ return { kind: "refused", why: `has a copy ${n} whose ${bad} is not a canonical decimal uint256` };
57
+ if (!isRetrievalUrl(copy.retrieval_url, cid)) {
58
+ return { kind: "refused", why: `has a copy ${n} whose retrieval_url is not https://…/piece/<blob_id>` };
59
+ }
60
+ }
61
+ // Rebuilt rather than passed through, so a copy handed in with an extra key cannot reach the
62
+ // byte output. The order is kept: it is the order a reader tries them in.
63
+ return {
64
+ kind: "filecoin",
65
+ chain,
66
+ copies: copies.map((c) => ({ provider_id: c.provider_id, data_set_id: c.data_set_id, piece_id: c.piece_id, retrieval_url: c.retrieval_url })),
67
+ };
68
+ }
69
+ /** Digits only, no leading zero (except `"0"`), at most 2²⁵⁶ − 1 — one spelling per number. */
70
+ function isU256Decimal(s) {
71
+ if (typeof s !== "string" || !/^(0|[1-9][0-9]*)$/.test(s))
72
+ return false;
73
+ return s.length < U256_MAX_DECIMAL.length || (s.length === U256_MAX_DECIMAL.length && s <= U256_MAX_DECIMAL);
74
+ }
75
+ /** `https://<host>…/piece/<cid>`: printable ASCII, no query or fragment — it must name this piece. */
76
+ function isRetrievalUrl(url, cid) {
77
+ if (typeof url !== "string" || !url.startsWith("https://"))
78
+ return false;
79
+ const rest = url.slice("https://".length);
80
+ const slash = rest.indexOf("/");
81
+ const hostEnds = slash < 0 ? rest.length : slash;
82
+ return hostEnds > 0 && rest.endsWith(`/piece/${cid}`) && /^[\x21-\x7e]+$/.test(url) && !/[?#]/.test(url);
83
+ }
@@ -1,54 +1,19 @@
1
1
  import type { ArtifactAbout } from "./artifact-about.ts";
2
2
  import { NmtsError } from "./errors.ts";
3
+ import { type ManifestPart, type ManifestPartInput } from "./recovery-map-part.ts";
3
4
  /** The newest NRM version this writer knows how to emit. */
4
- export declare const NRM_VERSION_LATEST = 4;
5
+ export declare const NRM_VERSION_LATEST = 5;
5
6
  /** The first NRM version in which every part carries `part_index`. */
6
7
  export declare const NRM_VERSION_WITH_PART_INDEX = 2;
7
8
  /** The first NRM version in which a quilt placement may be `{ identifier }` alone. */
8
9
  export declare const NRM_VERSION_WITH_OWN_QUILT = 3;
9
10
  /** The first NRM version in which a part may carry `padded_len`. */
10
11
  export declare const NRM_VERSION_WITH_PADDING = 4;
12
+ /** The first NRM version in which a part may be on Filecoin (`network`, `chain`, `copies`). */
13
+ export declare const NRM_VERSION_WITH_FILECOIN = 5;
11
14
  /** Practical ceiling from RECOVERY-MANIFEST.md §1 — beyond this the format needs chunk framing. */
12
15
  export declare const MANIFEST_ITEM_SOFT_CAP = 100000;
13
- /** One stored piece of a file, in order. */
14
- export interface ManifestPart {
15
- /**
16
- * Where this part belongs: 0 for the first, and the position it must be concatenated at
17
- * thereafter. Required from NRM-2.
18
- *
19
- * It is written down because array order alone cannot be CHECKED. A reader holds each fetched
20
- * part's 72-byte NCF-3 header, which carries the index sealed under the file key, so with this
21
- * field it can compare three things that must agree: the position it is writing at, what the
22
- * list says belongs there, and what the bytes themselves say they are.
23
- */
24
- part_index: number;
25
- /** Blob id holding this part's stream, in `network`'s own naming. */
26
- blob_id?: string;
27
- /** The REAL bytes this part contributes to the file. */
28
- plaintext_len: number;
29
- /**
30
- * What the stored stream's header DECLARES, when the part was padded and that is larger.
31
- * Absent means it was not padded. New in NRM-4.
32
- *
33
- * ⛔ THE TWO NUMBERS STAY APART so that "the parts sum to exactly `size`" keeps its exact
34
- * strength. Folded into one, the check softens to "at least", which accepts any size below
35
- * the real one: the file comes back short and nothing says so.
36
- */
37
- padded_len?: number;
38
- /** On-chain blob object, when the uploading client captured it. Omitted, never null. */
39
- sui_object_id?: string;
40
- /**
41
- * Which storage network holds `blob_id` — a NAME (`"walrus"`), not a code.
42
- *
43
- * A word rather than a number because whoever parses this may be doing so years from now with
44
- * none of our code beside them, and a bare `1` is not something a stranger can look up.
45
- */
46
- network?: string;
47
- }
48
- /** As a writer hands one in: the position is the value, so `part_index` is filled by the encoder. */
49
- export interface ManifestPartInput extends Omit<ManifestPart, "part_index"> {
50
- part_index?: number;
51
- }
16
+ export type { ManifestFilecoinCopy, ManifestPart, ManifestPartInput } from "./recovery-map-part.ts";
52
17
  /** Quilt placement naming a quilt anywhere on the network. */
53
18
  export interface ManifestQuiltAbsolute {
54
19
  quilt_blob_id: string;
@@ -17,14 +17,17 @@
17
17
  // real is not restated at all, because `shared/lib/crypto/size-padding.ts` is a byte-for-byte
18
18
  // copy of the browser's own file and a gate compares them.
19
19
  import { NmtsError } from "./errors.js";
20
+ import { filecoinForm, usesFilecoin } from "./recovery-map-part.js";
20
21
  /** The newest NRM version this writer knows how to emit. */
21
- export const NRM_VERSION_LATEST = 4;
22
+ export const NRM_VERSION_LATEST = 5;
22
23
  /** The first NRM version in which every part carries `part_index`. */
23
24
  export const NRM_VERSION_WITH_PART_INDEX = 2;
24
25
  /** The first NRM version in which a quilt placement may be `{ identifier }` alone. */
25
26
  export const NRM_VERSION_WITH_OWN_QUILT = 3;
26
27
  /** The first NRM version in which a part may carry `padded_len`. */
27
28
  export const NRM_VERSION_WITH_PADDING = 4;
29
+ /** The first NRM version in which a part may be on Filecoin (`network`, `chain`, `copies`). */
30
+ export const NRM_VERSION_WITH_FILECOIN = 5;
28
31
  /** Practical ceiling from RECOVERY-MANIFEST.md §1 — beyond this the format needs chunk framing. */
29
32
  export const MANIFEST_ITEM_SOFT_CAP = 100_000;
30
33
  /** Which form a placement is. One narrowing point, so "exactly one of the two" is decided here. */
@@ -62,6 +65,10 @@ export class RecoveryListProblem extends NmtsError {
62
65
  * understood every byte of it.
63
66
  */
64
67
  export function minimumVersion(items) {
68
+ // A list holding a Heavy (Filecoin) part is v5: a v4 reader would ask a Walrus aggregator for
69
+ // the piece and be told "not found", the same answer as an expired blob.
70
+ if (items.some((it) => it.parts.some(usesFilecoin)))
71
+ return NRM_VERSION_WITH_FILECOIN;
65
72
  if (items.some((it) => it.parts.some((p) => p.padded_len !== undefined))) {
66
73
  return NRM_VERSION_WITH_PADDING;
67
74
  }
@@ -144,6 +151,16 @@ export function buildRecoveryListDoc(input) {
144
151
  part.sui_object_id = p.sui_object_id;
145
152
  if (p.network)
146
153
  part.network = p.network;
154
+ // NRM-5: the reader refuses the WHOLE document over one bad Filecoin part, so the writer
155
+ // refuses to emit it instead of handing somebody a list that opens nothing.
156
+ const filecoin = filecoinForm(p, it.quilt !== undefined);
157
+ if (filecoin.kind === "refused") {
158
+ throw new RecoveryListProblem(`item ${it.id}: the part at position ${i} ${filecoin.why}`);
159
+ }
160
+ if (filecoin.kind === "filecoin") {
161
+ part.chain = filecoin.chain;
162
+ part.copies = filecoin.copies;
163
+ }
147
164
  return part;
148
165
  }),
149
166
  };
@@ -1,3 +1,4 @@
1
+ import type { HeavyCopy } from "./shared/lib/api/types-heavy.ts";
1
2
  /** `file_parts.storage_kind` for a quilt patch. 0 is a dedicated blob. */
2
3
  export declare const STORAGE_QUILT = 1;
3
4
  /** One stored piece of a file, as the server describes it. */
@@ -11,6 +12,8 @@ export interface SourcePart {
11
12
  /** What the part OCCUPIES: the sealed stream, header and tags included. */
12
13
  sealed_len: number;
13
14
  sui_object_id?: string;
15
+ /** Network 1 (NMTS Heavy): the companies keeping a whole copy, as the server recorded them. */
16
+ copies?: HeavyCopy[];
14
17
  /**
15
18
  * What this part's stored header DECLARES — the plaintext length behind `sealed_len`.
16
19
  *
@@ -21,6 +21,7 @@ import { request } from "./api.js";
21
21
  import { NmtsError } from "./errors.js";
22
22
  import { isRecord } from "./guards.js";
23
23
  import { plaintextLenFromSealed } from "./seal.js";
24
+ import { readCopies } from "./shared/lib/heavy/order-wire.js";
24
25
  /** `file_parts.storage_kind` for a quilt patch. 0 is a dedicated blob. */
25
26
  export const STORAGE_QUILT = 1;
26
27
  function unreadable(what) {
@@ -70,6 +71,14 @@ function partOf(value, itemId) {
70
71
  const object = optionalStr(value, "sui_object_id");
71
72
  if (object !== undefined)
72
73
  part.sui_object_id = object;
74
+ // ⛔ A LIST THAT DOES NOT READ IS A REFUSAL, NOT A SKIP: a Heavy part written without its copies
75
+ // would be refused by every reader, and one written with half of them is a file half-covered.
76
+ if (value["copies"] !== undefined) {
77
+ const copies = readCopies(value["copies"]);
78
+ if (copies === null)
79
+ throw unreadable(`the copies of a stored part of file ${itemId}`);
80
+ part.copies = copies;
81
+ }
73
82
  return part;
74
83
  }
75
84
  function itemOf(value) {
package/dist/risk.d.ts CHANGED
@@ -56,6 +56,9 @@ export declare const ACTS: {
56
56
  readonly "public-code": {
57
57
  readonly tier: "none";
58
58
  };
59
+ readonly handover: {
60
+ readonly tier: "none";
61
+ };
59
62
  readonly wallet: {
60
63
  readonly tier: "none";
61
64
  };
@@ -269,6 +272,12 @@ export declare const ACTS: {
269
272
  readonly what: "Give another account this file.";
270
273
  readonly asksItself: true;
271
274
  };
275
+ readonly "handover.make": {
276
+ readonly tier: "high";
277
+ readonly lock: "share";
278
+ readonly what: "Give another account this file in a handover file. It cannot be taken back.";
279
+ readonly asksItself: true;
280
+ };
272
281
  readonly "login.plain": {
273
282
  readonly tier: "high";
274
283
  readonly lock: "unsafe-code-storage";
@@ -299,6 +308,27 @@ export declare const ACTS: {
299
308
  readonly what: "Sign transactions that spend WAL and SUI from the wallet.";
300
309
  readonly standing: true;
301
310
  };
311
+ readonly "put.evm": {
312
+ readonly tier: "high";
313
+ readonly lock: "wallet";
314
+ readonly what: "Sign Filecoin storage payments in USDFC from the EVM wallet this key derives.";
315
+ readonly standing: true;
316
+ };
317
+ readonly "push.evm": {
318
+ readonly tier: "high";
319
+ readonly lock: "wallet";
320
+ readonly what: "Sign Filecoin storage payments in USDFC from the EVM wallet this key derives.";
321
+ readonly standing: true;
322
+ };
323
+ readonly heavy: {
324
+ readonly tier: "none";
325
+ };
326
+ readonly "heavy.fund": {
327
+ readonly tier: "high";
328
+ readonly lock: "wallet";
329
+ readonly what: "Deposit USDFC from the EVM wallet this key derives into Filecoin Pay.";
330
+ readonly asksItself: true;
331
+ };
302
332
  readonly "wallet.send": {
303
333
  readonly tier: "high";
304
334
  readonly lock: "wallet";
package/dist/risk.js CHANGED
@@ -39,6 +39,9 @@ export const ACTS = {
39
39
  // below, under the tiers they belong to.
40
40
  "ai-account": { tier: "none" },
41
41
  "public-code": { tier: "none" },
42
+ // Opening a handover file someone passed on: it reads the file, fetches from Walrus and writes
43
+ // one file here. `handover.make`, which gives a file away, is under `high` beside `share`.
44
+ handover: { tier: "none" },
42
45
  wallet: { tier: "none" },
43
46
  get: { tier: "none" },
44
47
  pull: { tier: "none" },
@@ -123,11 +126,25 @@ export const ACTS = {
123
126
  rebuild: { tier: "medium", what: "Build a file list from the server's rows and write it as this account's list." },
124
127
  // ── high: locked until a person unlocks, asked on every run ──
125
128
  share: { tier: "high", lock: "share", what: "Give another account this file.", asksItself: true },
129
+ // ⛔ THE SAME ACT AS `share`, behind the same unlock — it gives another account this file — and it
130
+ // cannot be taken back at all, because no row exists to delete.
131
+ "handover.make": {
132
+ tier: "high",
133
+ lock: "share",
134
+ what: "Give another account this file in a handover file. It cannot be taken back.",
135
+ asksItself: true,
136
+ },
126
137
  "login.plain": { tier: "high", lock: "unsafe-code-storage", what: "Store the NMTS key in the clear.", standing: true },
127
138
  "login.env": { tier: "high", lock: "plain-env", what: "Print the NMTS key for an environment variable.", standing: true },
128
139
  extend: { tier: "high", lock: "wallet", what: "Sign a transaction that spends WAL from the wallet.", standing: true },
129
140
  "put.wallet": { tier: "high", lock: "wallet", what: "Sign a transaction that spends WAL and SUI from the wallet.", standing: true },
130
141
  "push.wallet": { tier: "high", lock: "wallet", what: "Sign transactions that spend WAL and SUI from the wallet.", standing: true },
142
+ // ⛔ NMTS HEAVY'S SELF-PAID ROAD (developer mode) SITS BESIDE THE WALLET ROADS: it signs Filecoin
143
+ // transactions from this key's EVM wallet and spends that wallet's deposit, under the same lock.
144
+ "put.evm": { tier: "high", lock: "wallet", what: "Sign Filecoin storage payments in USDFC from the EVM wallet this key derives.", standing: true },
145
+ "push.evm": { tier: "high", lock: "wallet", what: "Sign Filecoin storage payments in USDFC from the EVM wallet this key derives.", standing: true },
146
+ heavy: { tier: "none" },
147
+ "heavy.fund": { tier: "high", lock: "wallet", what: "Deposit USDFC from the EVM wallet this key derives into Filecoin Pay.", asksItself: true },
131
148
  "wallet.send": { tier: "high", lock: "wallet", what: "Send coins out of the wallet.", asksItself: true },
132
149
  "wallet.swap": { tier: "high", lock: "wallet", what: "Swap one coin for the other on a public venue.", asksItself: true },
133
150
  "devices.sign-out": { tier: "high", lock: "sign-out", what: "Sign a device out of this account.", asksItself: true },
@@ -199,9 +216,11 @@ export function actOf(args) {
199
216
  return "wallet.use";
200
217
  return sub === "send" ? "wallet.send" : sub === "swap" ? "wallet.swap" : sub === "donate" ? "wallet.donate" : "wallet";
201
218
  case "put":
202
- return args.pay === "wallet" ? "put.wallet" : "put";
219
+ return args.pay === "wallet" ? "put.wallet" : args.pay === "evm" ? "put.evm" : "put";
203
220
  case "push":
204
- return args.pay === "wallet" ? "push.wallet" : "push";
221
+ return args.pay === "wallet" ? "push.wallet" : args.pay === "evm" ? "push.evm" : "push";
222
+ case "heavy":
223
+ return sub === "fund" ? "heavy.fund" : "heavy";
205
224
  case "key":
206
225
  return sub === "new" ? "key.new" : sub === "revoke" ? "key.revoke" : "key";
207
226
  case "ai-account":
@@ -216,6 +235,8 @@ export function actOf(args) {
216
235
  return args.dismiss !== undefined ? "losses.dismiss" : "losses";
217
236
  case "public-code":
218
237
  return args.publish ? "public-code.publish" : "public-code";
238
+ case "handover":
239
+ return sub === "make" ? "handover.make" : "handover";
219
240
  case "support":
220
241
  return sub === "send" || sub === "reply" ? "support.send" : "support";
221
242
  case "platform":
package/dist/run-log.d.ts CHANGED
@@ -47,7 +47,7 @@ export declare function runLogIsOff(): boolean;
47
47
  * ⚠ The path is recorded as it was requested, query string and all. Anything secret in it is a
48
48
  * label by the time it lands: `redact` runs over the whole record before it is written.
49
49
  */
50
- export declare function noteRequest(method: string, path: string, status: number, error?: string): void;
50
+ export declare function noteRequest(method: string, requested: string, status: number, error?: string): void;
51
51
  /** This run failed, with this sentence. Called from the entry point's own catch. */
52
52
  export declare function noteFailure(message: string): void;
53
53
  /** Throw away what has been collected. For tests, and for a second run inside one process. */
package/dist/run-log.js CHANGED
@@ -53,8 +53,12 @@ export const MAX_ATTACHED_RUNS = 20;
53
53
  * ⛔ `--code`, `--passphrase` AND `--api-key` DO NOT EXIST TODAY, and they are here anyway. The
54
54
  * rule in `args.ts` is that no option carries a secret; this table is what makes the log safe
55
55
  * on the day somebody argues for an exception to it.
56
+ *
57
+ * ⛔ `--to` IS WHOM. A handover exists so that nobody but the two people knows who gave a file to
58
+ * whom; a record on this disk — and a support attachment made from it — must not say it either.
56
59
  */
57
60
  const HIDDEN_VALUES = {
61
+ "--to": "[recipient]",
58
62
  "--message": "[message]",
59
63
  "--omit": "[omitted]",
60
64
  "--code": "[account-code]",
@@ -87,7 +91,9 @@ function remember(event) {
87
91
  * ⚠ The path is recorded as it was requested, query string and all. Anything secret in it is a
88
92
  * label by the time it lands: `redact` runs over the whole record before it is written.
89
93
  */
90
- export function noteRequest(method, path, status, error) {
94
+ export function noteRequest(method, requested, status, error) {
95
+ // ⛔ A recipient lookup names whom a file is about to go to; the address is not written down.
96
+ const path = requested.replace(/^\/v1\/share-recipients\/[^/?]+/, "/v1/share-recipients/[recipient]");
91
97
  remember(error === undefined ? { kind: "http", method, path, status } : { kind: "http", method, path, status, error });
92
98
  }
93
99
  /** This run failed, with this sentence. Called from the entry point's own catch. */
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Every query parameter S3 treats as naming a sub-resource.
3
+ *
4
+ * ⚠ `uploads`, `uploadId`, `delete`, `location` and `versioning` are answered; `versionId` is
5
+ * listed so that a request for one version is refused rather than answered with the only one.
6
+ */
7
+ export declare const SUB_RESOURCES: readonly string[];
8
+ /** The sub-resource this query names, or null when it names none. */
9
+ export declare function subResourceOf(query: URLSearchParams): string | null;
10
+ export interface Address {
11
+ /** Empty for the service itself: `ListBuckets`. */
12
+ readonly bucket: string;
13
+ /** Empty for the bucket itself. */
14
+ readonly key: string;
15
+ }
16
+ /**
17
+ * `/drive/photos/a.jpg` → bucket `drive`, key `photos/a.jpg`; or, virtual-hosted, `Host:
18
+ * drive.s3.example.com` and `/photos/a.jpg` → the same two.
19
+ */
20
+ export declare function addressOf(pathname: string, host: string | undefined, virtualHostBase: string | undefined): Address;