@needmoretruth/nmts-cli 0.44.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 (248) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +73 -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 +14 -0
  9. package/dist/args.js +11 -2
  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/get.d.ts +2 -0
  15. package/dist/commands/get.js +13 -1
  16. package/dist/commands/handover.d.ts +13 -0
  17. package/dist/commands/handover.js +328 -0
  18. package/dist/commands/heavy-run.d.ts +59 -0
  19. package/dist/commands/heavy-run.js +247 -0
  20. package/dist/commands/heavy.d.ts +7 -0
  21. package/dist/commands/heavy.js +123 -0
  22. package/dist/commands/ls.d.ts +7 -0
  23. package/dist/commands/ls.js +27 -6
  24. package/dist/commands/public-code.d.ts +6 -0
  25. package/dist/commands/public-code.js +46 -0
  26. package/dist/commands/push-heavy.d.ts +6 -0
  27. package/dist/commands/push-heavy.js +128 -0
  28. package/dist/commands/push-tree.d.ts +24 -0
  29. package/dist/commands/push-tree.js +91 -0
  30. package/dist/commands/push.d.ts +4 -13
  31. package/dist/commands/push.js +7 -77
  32. package/dist/commands/put-heavy.d.ts +9 -0
  33. package/dist/commands/put-heavy.js +120 -0
  34. package/dist/commands/put-payer.d.ts +21 -0
  35. package/dist/commands/put-payer.js +24 -0
  36. package/dist/commands/put-thumbnail.d.ts +4 -0
  37. package/dist/commands/put-thumbnail.js +119 -0
  38. package/dist/commands/put-wallet.d.ts +2 -0
  39. package/dist/commands/put-wallet.js +3 -2
  40. package/dist/commands/put.d.ts +10 -2
  41. package/dist/commands/put.js +13 -7
  42. package/dist/commands/receive.js +3 -3
  43. package/dist/commands/s3.js +44 -10
  44. package/dist/crypto-surface.d.ts +8 -0
  45. package/dist/crypto-surface.js +3 -0
  46. package/dist/crypto.d.ts +3 -0
  47. package/dist/crypto.js +3 -0
  48. package/dist/download-part.d.ts +32 -1
  49. package/dist/download-part.js +95 -6
  50. package/dist/download-range.d.ts +19 -0
  51. package/dist/download-range.js +108 -0
  52. package/dist/download-sink.d.ts +15 -0
  53. package/dist/download.d.ts +14 -0
  54. package/dist/download.js +19 -4
  55. package/dist/drive-edit/trash.js +5 -3
  56. package/dist/drive-edit/tree.d.ts +6 -0
  57. package/dist/drive-edit/tree.js +10 -0
  58. package/dist/drive-erase.js +2 -2
  59. package/dist/drive-paths.d.ts +2 -2
  60. package/dist/drive-paths.js +2 -2
  61. package/dist/handover.d.ts +44 -0
  62. package/dist/handover.js +199 -0
  63. package/dist/heavy-api.d.ts +36 -0
  64. package/dist/heavy-api.js +107 -0
  65. package/dist/heavy-copy.d.ts +72 -0
  66. package/dist/heavy-copy.js +108 -0
  67. package/dist/heavy-evm.d.ts +20 -0
  68. package/dist/heavy-evm.js +106 -0
  69. package/dist/heavy-self-pay.d.ts +92 -0
  70. package/dist/heavy-self-pay.js +167 -0
  71. package/dist/heavy-upload.d.ts +87 -0
  72. package/dist/heavy-upload.js +154 -0
  73. package/dist/heavy-wallet-pay.d.ts +39 -0
  74. package/dist/heavy-wallet-pay.js +73 -0
  75. package/dist/help-options.js +8 -2
  76. package/dist/help.js +16 -3
  77. package/dist/list-tier.d.ts +7 -0
  78. package/dist/list-tier.js +47 -0
  79. package/dist/main.js +14 -9
  80. package/dist/manifest-write.d.ts +4 -3
  81. package/dist/mcp-tools/files.js +21 -2
  82. package/dist/mcp-tools/reads.js +9 -1
  83. package/dist/platform-sign.d.ts +4 -4
  84. package/dist/platform-sign.js +3 -3
  85. package/dist/portable.d.ts +17 -1
  86. package/dist/portable.js +13 -1
  87. package/dist/product.d.ts +1 -1
  88. package/dist/product.js +1 -1
  89. package/dist/recovery-build.js +16 -0
  90. package/dist/recovery-map-part.d.ts +82 -0
  91. package/dist/recovery-map-part.js +83 -0
  92. package/dist/recovery-map.d.ts +5 -40
  93. package/dist/recovery-map.js +18 -1
  94. package/dist/recovery-source.d.ts +3 -0
  95. package/dist/recovery-source.js +9 -0
  96. package/dist/risk.d.ts +30 -0
  97. package/dist/risk.js +23 -2
  98. package/dist/run-log.d.ts +1 -1
  99. package/dist/run-log.js +7 -1
  100. package/dist/s3/address.d.ts +20 -0
  101. package/dist/s3/address.js +97 -0
  102. package/dist/s3/answer.d.ts +48 -0
  103. package/dist/s3/answer.js +330 -0
  104. package/dist/s3/body-deframe.d.ts +49 -0
  105. package/dist/s3/body-deframe.js +264 -0
  106. package/dist/s3/body-measure.d.ts +13 -0
  107. package/dist/s3/body-measure.js +48 -0
  108. package/dist/s3/body-plan.d.ts +31 -0
  109. package/dist/s3/body-plan.js +159 -0
  110. package/dist/s3/body.d.ts +46 -0
  111. package/dist/s3/body.js +117 -0
  112. package/dist/s3/call.d.ts +36 -0
  113. package/dist/s3/call.js +42 -0
  114. package/dist/s3/checksum.d.ts +26 -0
  115. package/dist/s3/checksum.js +176 -0
  116. package/dist/s3/content-type.d.ts +3 -0
  117. package/dist/s3/content-type.js +49 -0
  118. package/dist/s3/contract.d.ts +91 -14
  119. package/dist/s3/drive-conditions.d.ts +47 -0
  120. package/dist/s3/drive-conditions.js +134 -0
  121. package/dist/s3/drive-key.d.ts +11 -0
  122. package/dist/s3/drive-key.js +58 -0
  123. package/dist/s3/drive-limits.d.ts +33 -0
  124. package/dist/s3/drive-limits.js +53 -0
  125. package/dist/s3/drive-lock.d.ts +11 -0
  126. package/dist/s3/drive-lock.js +47 -0
  127. package/dist/s3/drive-trashed-name.d.ts +13 -0
  128. package/dist/s3/drive-trashed-name.js +59 -0
  129. package/dist/s3/drive-write.d.ts +38 -0
  130. package/dist/s3/drive-write.js +258 -0
  131. package/dist/s3/drive.d.ts +59 -25
  132. package/dist/s3/drive.js +46 -77
  133. package/dist/s3/listing.d.ts +27 -1
  134. package/dist/s3/listing.js +62 -20
  135. package/dist/s3/long-answer.d.ts +12 -0
  136. package/dist/s3/long-answer.js +104 -0
  137. package/dist/s3/multipart-assemble.d.ts +17 -0
  138. package/dist/s3/multipart-assemble.js +68 -0
  139. package/dist/s3/multipart-sweep.d.ts +15 -0
  140. package/dist/s3/multipart-sweep.js +87 -0
  141. package/dist/s3/multipart-view.d.ts +45 -0
  142. package/dist/s3/multipart-view.js +232 -0
  143. package/dist/s3/multipart.d.ts +26 -19
  144. package/dist/s3/multipart.js +193 -78
  145. package/dist/s3/object-read.d.ts +17 -0
  146. package/dist/s3/object-read.js +127 -0
  147. package/dist/s3/object-write.d.ts +35 -0
  148. package/dist/s3/object-write.js +198 -0
  149. package/dist/s3/range.d.ts +14 -0
  150. package/dist/s3/range.js +80 -0
  151. package/dist/s3/response-sink.d.ts +12 -2
  152. package/dist/s3/response-sink.js +71 -7
  153. package/dist/s3/routes.d.ts +0 -1
  154. package/dist/s3/routes.js +242 -217
  155. package/dist/s3/same-file.d.ts +4 -1
  156. package/dist/s3/same-file.js +12 -3
  157. package/dist/s3/server.d.ts +54 -4
  158. package/dist/s3/server.js +174 -14
  159. package/dist/s3/sigv4-canonical.d.ts +91 -0
  160. package/dist/s3/sigv4-canonical.js +148 -0
  161. package/dist/s3/sigv4-presigned.d.ts +13 -0
  162. package/dist/s3/sigv4-presigned.js +82 -0
  163. package/dist/s3/sigv4.d.ts +26 -27
  164. package/dist/s3/sigv4.js +137 -102
  165. package/dist/s3/spool.d.ts +37 -0
  166. package/dist/s3/spool.js +104 -0
  167. package/dist/s3/staging.d.ts +90 -7
  168. package/dist/s3/staging.js +97 -66
  169. package/dist/s3/xml-multipart.d.ts +38 -0
  170. package/dist/s3/xml-multipart.js +47 -0
  171. package/dist/s3/xml-read.d.ts +28 -0
  172. package/dist/s3/xml-read.js +235 -0
  173. package/dist/s3/xml.d.ts +45 -2
  174. package/dist/s3/xml.js +72 -13
  175. package/dist/s3-gateway.d.ts +11 -5
  176. package/dist/s3-gateway.js +5 -2
  177. package/dist/seal.d.ts +1 -1
  178. package/dist/share.d.ts +5 -0
  179. package/dist/share.js +1 -1
  180. package/dist/shared/lib/api/types-heavy.d.ts +167 -0
  181. package/dist/shared/lib/api/types-heavy.js +60 -0
  182. package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
  183. package/dist/shared/lib/drive/manifest-codec.js +15 -23
  184. package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
  185. package/dist/shared/lib/drive/manifest-index.js +30 -8
  186. package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
  187. package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
  188. package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
  189. package/dist/shared/lib/drive/preview-classify.js +96 -0
  190. package/dist/shared/lib/drive/rebuild-verify.js +1 -0
  191. package/dist/shared/lib/filecoin/providers.d.ts +25 -0
  192. package/dist/shared/lib/filecoin/providers.js +58 -0
  193. package/dist/shared/lib/heavy/download.d.ts +48 -0
  194. package/dist/shared/lib/heavy/download.js +116 -0
  195. package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
  196. package/dist/shared/lib/heavy/order-plan.js +83 -0
  197. package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
  198. package/dist/shared/lib/heavy/order-runner.js +300 -0
  199. package/dist/shared/lib/heavy/order-types.d.ts +90 -0
  200. package/dist/shared/lib/heavy/order-types.js +6 -0
  201. package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
  202. package/dist/shared/lib/heavy/order-wire.js +113 -0
  203. package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
  204. package/dist/shared/lib/heavy/piece-cid.js +55 -0
  205. package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
  206. package/dist/shared/lib/heavy/sp-upload.js +112 -0
  207. package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
  208. package/dist/shared/lib/heavy/synapse-piece.js +8 -0
  209. package/dist/shared/lib/share/handover-format.d.ts +129 -0
  210. package/dist/shared/lib/share/handover-format.js +323 -0
  211. package/dist/shared/lib/share/shared-file-info.js +1 -0
  212. package/dist/shared/lib/storage-network.d.ts +4 -4
  213. package/dist/shared/lib/storage-network.js +7 -7
  214. package/dist/shared/lib/storage-tier.d.ts +28 -0
  215. package/dist/shared/lib/storage-tier.js +63 -0
  216. package/dist/shared/lib/wallet/send-rules.js +1 -0
  217. package/dist/upload-file.d.ts +8 -0
  218. package/dist/upload-file.js +57 -25
  219. package/dist/upload-price-node.d.ts +3 -0
  220. package/dist/upload-price-node.js +3 -6
  221. package/dist/upload-price.d.ts +10 -0
  222. package/dist/upload-price.js +13 -1
  223. package/dist/upload-run.d.ts +80 -0
  224. package/dist/upload-run.js +173 -0
  225. package/dist/upload-steps.js +15 -4
  226. package/dist/upload-store.d.ts +15 -6
  227. package/dist/upload-store.js +6 -0
  228. package/dist/upload-wallet-put.d.ts +11 -4
  229. package/dist/upload-wallet-put.js +17 -6
  230. package/dist/upload-wallet.js +4 -0
  231. package/dist/upload-wire.d.ts +25 -0
  232. package/dist/upload-wire.js +20 -1
  233. package/dist/upload.js +28 -13
  234. package/dist/wallet-sign.js +2 -2
  235. package/docs/commands/get.md +3 -0
  236. package/docs/commands/handover.md +38 -0
  237. package/docs/commands/heavy.md +35 -0
  238. package/docs/commands/ls.md +5 -0
  239. package/docs/commands/public-code.md +7 -0
  240. package/docs/commands/push.md +4 -1
  241. package/docs/commands/put.md +23 -1
  242. package/docs/commands/share.md +3 -1
  243. package/package.json +5 -2
  244. package/server.json +2 -2
  245. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
  246. package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
  247. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  248. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
package/dist/s3/xml.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // The XML the S3 protocol answers in.
2
2
  //
3
- // ⛔ WRITTEN BY HAND, ON PURPOSE. Pulling in an XML builder to emit five fixed shapes would add a
3
+ // ⛔ WRITTEN BY HAND, ON PURPOSE. Pulling in an XML builder to emit a few fixed shapes would add a
4
4
  // dependency to a tool whose whole dependency list is auditable in one screen, and this is the
5
5
  // one place where the output is dictated by somebody else's specification -- there is nothing to
6
6
  // design, only to match.
@@ -8,20 +8,47 @@
8
8
  // ⚠ EVERY VALUE THAT CAME FROM A FILE NAME IS ESCAPED. Names in this drive are whatever a person
9
9
  // typed, including `&` and `<`, and an unescaped one produces XML the client cannot parse -- a
10
10
  // listing that fails for one badly-named file and works for everything else.
11
- /** The five characters XML cannot carry raw. */
11
+ /**
12
+ * What XML 1.0 cannot carry at all, not even as a character reference: the C0 controls other than
13
+ * tab, line feed and carriage return; U+FFFE and U+FFFF; and half of a surrogate pair.
14
+ */
15
+ const UNCARRIABLE = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]|\p{Cs}/gu;
16
+ /** What stands in for a character XML cannot carry. */
17
+ const REPLACEMENT = "\uFFFD";
18
+ /** `value` with every character no document may contain replaced by U+FFFD. */
19
+ function carriable(value) {
20
+ return value.replace(UNCARRIABLE, REPLACEMENT);
21
+ }
22
+ /**
23
+ * The five characters XML cannot carry raw, escaped -- and what it cannot carry at all, replaced.
24
+ *
25
+ * ⛔ A NAME WITH A CONTROL CHARACTER IN IT MUST NOT BREAK THE DOCUMENT IT IS LISTED IN. `&#1;` is no
26
+ * way out: XML 1.0 forbids the reference as it forbids the character, and a parser that meets
27
+ * either refuses the whole listing -- every other file in it along with the one badly named.
28
+ * Such a name is answered with U+FFFD in its place, which the client can at least see; the exact
29
+ * name is what `encoding-type=url` is for, and that path percent-encodes it before it gets here.
30
+ * ⚠ A CARRIAGE RETURN IS LEGAL BUT DOES NOT SURVIVE PARSING: a parser turns it into a line feed,
31
+ * and the client reads a different name from the one stored. As a reference it arrives intact.
32
+ */
12
33
  export function escapeXml(value) {
13
- return value
34
+ return carriable(value)
14
35
  .replace(/&/g, "&amp;")
15
36
  .replace(/</g, "&lt;")
16
37
  .replace(/>/g, "&gt;")
17
38
  .replace(/"/g, "&quot;")
18
- .replace(/'/g, "&apos;");
39
+ .replace(/'/g, "&apos;")
40
+ .replace(/\r/g, "&#xD;");
19
41
  }
20
- const HEAD = `<?xml version="1.0" encoding="UTF-8"?>`;
21
- const NS = `http://s3.amazonaws.com/doc/2006-03-01/`;
22
- export function errorXml(code, message, resource) {
42
+ export const HEAD = `<?xml version="1.0" encoding="UTF-8"?>`;
43
+ export const NS = `http://s3.amazonaws.com/doc/2006-03-01/`;
44
+ /** Who owns and began everything here, as far as a client can be told. */
45
+ export const OWNER = `<ID>nmts</ID><DisplayName>nmts</DisplayName>`;
46
+ /** S3's error document. `requestId` names the answer it belongs to, when there is one to name. */
47
+ export function errorXml(code, message, resource, requestId) {
23
48
  return (`${HEAD}<Error><Code>${escapeXml(code)}</Code><Message>${escapeXml(message)}</Message>` +
24
- `<Resource>${escapeXml(resource)}</Resource></Error>`);
49
+ `<Resource>${escapeXml(resource)}</Resource>` +
50
+ (requestId === undefined ? "" : `<RequestId>${escapeXml(requestId)}</RequestId>`) +
51
+ `</Error>`);
25
52
  }
26
53
  /**
27
54
  * The answer to `ListBuckets`.
@@ -35,8 +62,8 @@ export function listBucketsXml(buckets, createdAt) {
35
62
  .map((bucket) => `<Bucket><Name>${escapeXml(bucket)}</Name>` +
36
63
  `<CreationDate>${escapeXml(createdAt)}</CreationDate></Bucket>`)
37
64
  .join("");
38
- return (`${HEAD}<ListAllMyBucketsResult xmlns="${NS}"><Owner><ID>nmts</ID>` +
39
- `<DisplayName>nmts</DisplayName></Owner><Buckets>${rows}</Buckets></ListAllMyBucketsResult>`);
65
+ return (`${HEAD}<ListAllMyBucketsResult xmlns="${NS}"><Owner>${OWNER}</Owner>` +
66
+ `<Buckets>${rows}</Buckets></ListAllMyBucketsResult>`);
40
67
  }
41
68
  export function initiateUploadXml(bucket, key, uploadId) {
42
69
  return (`${HEAD}<InitiateMultipartUploadResult xmlns="${NS}">` +
@@ -49,9 +76,15 @@ export function completeUploadXml(bucket, key, etag) {
49
76
  `<Bucket>${escapeXml(bucket)}</Bucket><Key>${escapeXml(key)}</Key>` +
50
77
  `<ETag>${escapeXml(etag)}</ETag></CompleteMultipartUploadResult>`);
51
78
  }
52
- /** `encoding-type=url` means every name in the answer comes back percent-encoded. */
53
- function out(value, encodingType) {
54
- return escapeXml(encodingType === "url" ? encodeURIComponent(value) : value);
79
+ /**
80
+ * `encoding-type=url` means every name in the answer comes back percent-encoded -- control
81
+ * characters included, which is how a client gets such a name exactly.
82
+ *
83
+ * ⚠ HALF A SURROGATE PAIR HAS NO UTF-8 FORM TO PERCENT-ENCODE, and `encodeURIComponent` throws on
84
+ * one; it is replaced first, as `escapeXml` would replace it.
85
+ */
86
+ export function out(value, encodingType) {
87
+ return escapeXml(encodingType === "url" ? encodeURIComponent(value.replace(/\p{Cs}/gu, REPLACEMENT)) : value);
55
88
  }
56
89
  export function listObjectsXml(listing) {
57
90
  const enc = listing.encodingType;
@@ -87,3 +120,29 @@ export function listObjectsXml(listing) {
87
120
  parts.push(`</ListBucketResult>`);
88
121
  return parts.join("");
89
122
  }
123
+ /**
124
+ * Where the bucket lives: nowhere a region names.
125
+ *
126
+ * ⚠ EMPTY IS S3'S OWN WAY OF SAYING `us-east-1`, which is what a client that asks should sign
127
+ * with — and this gateway accepts a signature in any region anyway.
128
+ */
129
+ export function locationXml() {
130
+ return `${HEAD}<LocationConstraint xmlns="${NS}"/>`;
131
+ }
132
+ /** Versioning was never turned on, which S3 answers with an empty configuration. */
133
+ export function versioningXml() {
134
+ return `${HEAD}<VersioningConfiguration xmlns="${NS}"/>`;
135
+ }
136
+ export function copyObjectXml(etag, lastModified) {
137
+ return (`${HEAD}<CopyObjectResult xmlns="${NS}"><LastModified>${escapeXml(lastModified)}</LastModified>` +
138
+ `<ETag>${escapeXml(etag)}</ETag></CopyObjectResult>`);
139
+ }
140
+ /** The answer to `DeleteObjects`. In quiet mode the caller passes no `deleted`, as S3 does. */
141
+ export function deleteResultXml(outcome) {
142
+ const deleted = outcome.deleted.map((key) => `<Deleted><Key>${escapeXml(key)}</Key></Deleted>`).join("");
143
+ const errors = outcome.errors
144
+ .map((e) => `<Error><Key>${escapeXml(e.key)}</Key><Code>${escapeXml(e.code)}</Code>` +
145
+ `<Message>${escapeXml(e.message)}</Message></Error>`)
146
+ .join("");
147
+ return `${HEAD}<DeleteResult xmlns="${NS}">${deleted}${errors}</DeleteResult>`;
148
+ }
@@ -1,8 +1,14 @@
1
- export { createGateway, gatewayHandler } from "./s3/server.ts";
2
- export type { DriveSource, DriveWriter, GatewayHandler, GatewayOptions } from "./s3/server.ts";
1
+ export { BODY_IDLE_MS, checkContinueHandler, createGateway, failureReasonOf, GATEWAY_SERVER_OPTIONS, gatewayHandler, refusalBeforeBody, watchBodyIdle, } from "./s3/server.ts";
2
+ export type { EarlyRefusal, CopySource, DriveSource, DriveWriter, GatewayHandler, GatewayOptions, StoreOutcome, WriteMeta, } from "./s3/server.ts";
3
3
  export { createDriveSource, fetchObject, placeOf, LIST_CACHE_MS } from "./s3/drive.ts";
4
- export type { DriveAccount, DriveSourceOptions, ObjectReader } from "./s3/drive.ts";
5
- export { createStaging } from "./s3/staging.ts";
6
- export type { Staging, StoreFile } from "./s3/staging.ts";
4
+ export type { DriveAccount, DriveSourceOptions, ObjectReader, StoredFile } from "./s3/drive.ts";
5
+ export { createKeyLocks } from "./s3/drive-lock.ts";
6
+ export type { KeyLocks } from "./s3/drive-lock.ts";
7
+ export { freeTrashedName } from "./s3/drive-trashed-name.ts";
8
+ export { MAX_CONCURRENT_WRITES, MAX_UPLOADS_PER_BUCKET } from "./s3/drive-limits.ts";
9
+ export type { WriteCondition } from "./s3/drive-conditions.ts";
10
+ export type { RemoveOutcome } from "./s3/contract.ts";
11
+ export { createStaging, createStagingStore, SWEEP_EVERY_MS, UPLOAD_LIFETIME_MS } from "./s3/staging.ts";
12
+ export type { CompleteOptions, ObjectChecksum, PartChoice, StagedPart, StagedUpload, Staging, StagingOptions, StagingStore, StoreFile, UploadAccount, } from "./s3/staging.ts";
7
13
  export type { GatewayCredential } from "./s3/sigv4.ts";
8
14
  export type { DriveObject } from "./s3/listing.ts";
@@ -8,6 +8,9 @@
8
8
  //
9
9
  // ⚠ WHAT IS NOT HERE: the bucket name `nmts s3` uses, the address it binds, and the pair it prints
10
10
  // when it starts. Those are that command's answers to questions a business answers for itself.
11
- export { createGateway, gatewayHandler } from "./s3/server.js";
11
+ export { BODY_IDLE_MS, checkContinueHandler, createGateway, failureReasonOf, GATEWAY_SERVER_OPTIONS, gatewayHandler, refusalBeforeBody, watchBodyIdle, } from "./s3/server.js";
12
12
  export { createDriveSource, fetchObject, placeOf, LIST_CACHE_MS } from "./s3/drive.js";
13
- export { createStaging } from "./s3/staging.js";
13
+ export { createKeyLocks } from "./s3/drive-lock.js";
14
+ export { freeTrashedName } from "./s3/drive-trashed-name.js";
15
+ export { MAX_CONCURRENT_WRITES, MAX_UPLOADS_PER_BUCKET } from "./s3/drive-limits.js";
16
+ export { createStaging, createStagingStore, SWEEP_EVERY_MS, UPLOAD_LIFETIME_MS } from "./s3/staging.js";
package/dist/seal.d.ts CHANGED
@@ -109,7 +109,7 @@ export declare function sealPart(crypt: CryptoGlue, dek: Uint8Array, chunks: Asy
109
109
  index: number;
110
110
  total: number;
111
111
  plaintextLen: number;
112
- }): Promise<Uint8Array>;
112
+ }): Promise<Uint8Array<ArrayBuffer>>;
113
113
  /**
114
114
  * Seal a whole file held in memory, as one part.
115
115
  *
package/dist/share.d.ts CHANGED
@@ -51,6 +51,11 @@ export declare function sealShare(crypt: CryptoGlue, input: {
51
51
  size: number;
52
52
  /** The file's whole-plaintext digest, opened from the account's own sealed copy. */
53
53
  digest: Uint8Array;
54
+ /**
55
+ * The name document to seal in place of the share's own — a handover's, which also binds its
56
+ * parts list and network (NCF-3 §5.6). A built-in share never passes one.
57
+ */
58
+ nameDocument?: string;
54
59
  }): SharePayload;
55
60
  /** One row of what somebody shared with this account, as the server describes it. */
56
61
  export interface ReceivedRow {
package/dist/share.js CHANGED
@@ -70,7 +70,7 @@ export function sealShare(crypt, input) {
70
70
  });
71
71
  }
72
72
  // ⛔ SEALED FIRST, AND THESE EXACT BYTES ARE WHAT GETS SENT. See the module note.
73
- const nameCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareName), encoder.encode(encodeSharedFileInfo({ name: input.name, size: input.size })));
73
+ const nameCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareName), encoder.encode(input.nameDocument ?? encodeSharedFileInfo({ name: input.name, size: input.size })));
74
74
  const digestCt = crypt.envelope_seal(input.dek, encoder.encode(AAD.shareContentHash), input.digest);
75
75
  if (digestCt.length !== DIGEST_ENVELOPE_LEN) {
76
76
  throw new NmtsError(`A sealed content hash came out ${digestCt.length} bytes.`);
@@ -0,0 +1,167 @@
1
+ /** One stored copy of a Heavy part: which company holds it, where on chain, and where to read it. */
2
+ export interface HeavyCopy {
3
+ /** The storage company's registry id. */
4
+ provider_id: string;
5
+ /** The on-chain data set the piece was added to. */
6
+ data_set_id: string;
7
+ /** The piece's id inside that data set. */
8
+ piece_id: string;
9
+ /** `https://<company>/piece/<PieceCID>` — public, no credentials, byte ranges allowed. */
10
+ retrieval_url: string;
11
+ }
12
+ /** The field a Filecoin (network 1) part carries on every read and on commit. */
13
+ export interface HeavyPartCopies {
14
+ /** Where the part's copies are kept. Present on network-1 parts only; absent means Walrus. */
15
+ copies?: HeavyCopy[];
16
+ }
17
+ /** The fields that tie a committed part to the order and slot that paid for it. */
18
+ export interface HeavyOrderBinding {
19
+ /** The order that paid for this part. Omitted on the self-paid path, which has no order. */
20
+ heavy_order_id?: string;
21
+ /** Which slot of that order this part is. */
22
+ heavy_slot?: number;
23
+ }
24
+ /** How an order is paid. */
25
+ export type HeavyPay = "credits" | "wallet";
26
+ /** One slot asked for when an order opens: its number and the exact sealed size it will upload. */
27
+ export interface HeavySlotRequest {
28
+ /** 0..n-1, one per sealed part across every file of the upload. */
29
+ slot: number;
30
+ /** Bytes of the sealed part, 127..=1_065_353_216 — known before sealing. */
31
+ sealed_len: number;
32
+ }
33
+ /** `POST /v1/heavy/orders` body. */
34
+ export interface HeavyCreateOrderRequest {
35
+ /** 16..64 of `[A-Za-z0-9_-]`. The same key and body answer the same order; nothing is charged twice. */
36
+ idempotency_key: string;
37
+ /** 1..=256 slots. */
38
+ slots: HeavySlotRequest[];
39
+ pay: HeavyPay;
40
+ /** Wallet orders only: 1..=365 days. Credit orders are always 28. */
41
+ term_days?: number;
42
+ /** Wallet orders only: the `0x` + 64-hex Sui address that will pay. */
43
+ payer?: string;
44
+ }
45
+ /** What a wallet order costs, and where the payment goes. */
46
+ export interface HeavyPrice {
47
+ /** The price in FROST (1 WAL = 10^9 FROST), as a decimal string. */
48
+ wal_frost: string;
49
+ /** The `0x` + 64-hex Sui address the WAL is sent to. */
50
+ treasury: string;
51
+ /** How long after every slot is stored the payment may arrive before the copies are removed. */
52
+ pay_within_secs: number;
53
+ }
54
+ export type HeavyOrderState = "open" | "stored" | "paid" | "bound" | "expired" | "failed";
55
+ export type HeavySlotState = "open" | "targeted" | "committing" | "stored" | "failed" | "removed";
56
+ /** `POST /v1/heavy/orders` 200. */
57
+ export interface HeavyOrderCreated {
58
+ order_id: string;
59
+ state: "open";
60
+ pay: HeavyPay;
61
+ term_days: number;
62
+ /** Credit orders: what was taken. */
63
+ credits?: number;
64
+ /** Wallet orders: what will be owed once everything is stored. */
65
+ price?: HeavyPrice;
66
+ slots: {
67
+ slot: number;
68
+ state: "open";
69
+ }[];
70
+ }
71
+ /** One slot as `GET /v1/heavy/orders/{id}` reports it. */
72
+ export interface HeavySlotView {
73
+ slot: number;
74
+ state: HeavySlotState;
75
+ piece_cid?: string;
76
+ /** Present once the slot is stored. */
77
+ copies?: HeavyCopy[];
78
+ /** Why a failed slot failed, as the server words it for a log. */
79
+ error?: string;
80
+ }
81
+ /** `GET /v1/heavy/orders/{id}` 200. */
82
+ export interface HeavyOrderView {
83
+ order_id: string;
84
+ state: HeavyOrderState;
85
+ pay: HeavyPay;
86
+ term_days: number;
87
+ price?: HeavyPrice;
88
+ /** The Filecoin epoch (30 s) the copies are kept until; set once every slot is stored. */
89
+ expiry_epoch?: number;
90
+ slots: HeavySlotView[];
91
+ }
92
+ /** `POST …/slots/{slot}/target` body. */
93
+ export interface HeavyTargetRequest {
94
+ /** The part's FRC-0069 PieceCID (`bafkzcib…`); its raw size must equal the slot's `sealed_len`. */
95
+ piece_cid: string;
96
+ }
97
+ /** `POST …/slots/{slot}/target` 200 — where to upload this slot's bytes. */
98
+ export interface HeavySlotTarget {
99
+ provider_id: string;
100
+ /** The company's service origin; the upload goes to `<service_url>/pdp/piece/uploads`. */
101
+ service_url: string;
102
+ }
103
+ /** `POST …/slots/{slot}/uploaded` 202. */
104
+ export interface HeavyUploadedReply {
105
+ state: "committing";
106
+ }
107
+ /** `POST …/paid` body — the Sui transaction that sent the WAL. */
108
+ export interface HeavyPaidRequest {
109
+ tx_digest: string;
110
+ }
111
+ /** `POST …/paid` 200. */
112
+ export interface HeavyPaidReply {
113
+ state: "paid";
114
+ }
115
+ /** Per-call options every order route accepts. */
116
+ export interface HeavyCallOptions {
117
+ signal?: AbortSignal;
118
+ }
119
+ /**
120
+ * The order routes as one object. The browser builds it over its api client; the command line
121
+ * builds it over its own. The upload orchestrator depends on nothing but this.
122
+ */
123
+ export interface HeavyOrderApi {
124
+ createOrder(body: HeavyCreateOrderRequest, options?: HeavyCallOptions): Promise<HeavyOrderCreated>;
125
+ getOrder(orderId: string, options?: HeavyCallOptions): Promise<HeavyOrderView>;
126
+ targetSlot(orderId: string, slot: number, body: HeavyTargetRequest, options?: HeavyCallOptions): Promise<HeavySlotTarget>;
127
+ slotUploaded(orderId: string, slot: number, options?: HeavyCallOptions): Promise<HeavyUploadedReply>;
128
+ markPaid(orderId: string, body: HeavyPaidRequest, options?: HeavyCallOptions): Promise<HeavyPaidReply>;
129
+ }
130
+ /**
131
+ * A finished Heavy part, ready to go into `POST /v1/items` as one of a file's parts.
132
+ *
133
+ * Structurally one of that route's part inputs: the treasury owns order-paid storage (`owner_kind`
134
+ * 1), the part is a whole piece rather than a quilt patch (`storage_kind` 0), and `blob_id` holds
135
+ * the PieceCID — the id the Filecoin network knows the bytes by.
136
+ */
137
+ export interface HeavyPartCommit {
138
+ part_index: number;
139
+ storage_kind: 0;
140
+ network: 1;
141
+ blob_id: string;
142
+ sealed_len: number;
143
+ owner_kind: 1;
144
+ /** A Filecoin epoch, not a Walrus one: the unit is the network's own. */
145
+ expiry_epoch: number;
146
+ heavy_order_id: string;
147
+ heavy_slot: number;
148
+ copies: HeavyCopy[];
149
+ }
150
+ /**
151
+ * Every refusal the order routes can answer, by the name the contract gives it.
152
+ *
153
+ * credits_insufficient · idempotency_conflict · file_credits_cap · day_credits_cap ·
154
+ * heavy_wallet_pay_off · heavy_price_unavailable · unpaid_orders_cap ·
155
+ * heavy_unavailable (opening an order)
156
+ * piece_cid_invalid · piece_size_mismatch · slot_state (placing a slot)
157
+ * not_stored · payment_not_found · payment_mismatch · digest_used (reporting a payment)
158
+ */
159
+ export declare const HEAVY_REFUSALS: readonly ["credits_insufficient", "idempotency_conflict", "file_credits_cap", "day_credits_cap", "heavy_wallet_pay_off", "heavy_price_unavailable", "unpaid_orders_cap", "heavy_unavailable", "piece_cid_invalid", "piece_size_mismatch", "slot_state", "not_stored", "payment_not_found", "payment_mismatch", "digest_used"];
160
+ export type HeavyRefusal = (typeof HEAVY_REFUSALS)[number];
161
+ /**
162
+ * The Heavy refusal an error code names, or `null` when it names none.
163
+ *
164
+ * Letter case is ignored: servers spell error codes in capitals (`CREDITS_INSUFFICIENT`) and the
165
+ * contract writes them in lower case, and both mean one thing.
166
+ */
167
+ export declare function heavyRefusalOf(code: string): HeavyRefusal | null;
@@ -0,0 +1,60 @@
1
+ // The wire shapes of NMTS Heavy's order routes, and the refusals they answer with.
2
+ //
3
+ // ⚠ THIS FILE IS PUBLISHED. It is copied byte-for-byte into the `nmts` command-line package, so it
4
+ // imports nothing and its comments stay self-contained English.
5
+ //
6
+ // WHAT AN ORDER IS. One upload (one file or fifty) opens ONE order. The order has a slot per sealed
7
+ // part; each slot is placed with a Filecoin storage company, the client uploads the bytes to that
8
+ // company directly, and the server has the copies committed on chain and reports when they are
9
+ // stored. Payment is either credits (taken when the order opens) or the person's wallet (paid once,
10
+ // after every slot is stored). The finished parts are then committed to a file like any other part,
11
+ // naming the order and slot that paid for them.
12
+ //
13
+ // ⛔ IDS ARE DECIMAL STRINGS, NOT NUMBERS. Data-set and piece ids are uint256 on chain and can exceed
14
+ // what a JSON number carries exactly, so every id travels as a string and is never parsed.
15
+ /**
16
+ * Every refusal the order routes can answer, by the name the contract gives it.
17
+ *
18
+ * credits_insufficient · idempotency_conflict · file_credits_cap · day_credits_cap ·
19
+ * heavy_wallet_pay_off · heavy_price_unavailable · unpaid_orders_cap ·
20
+ * heavy_unavailable (opening an order)
21
+ * piece_cid_invalid · piece_size_mismatch · slot_state (placing a slot)
22
+ * not_stored · payment_not_found · payment_mismatch · digest_used (reporting a payment)
23
+ */
24
+ export const HEAVY_REFUSALS = [
25
+ "credits_insufficient",
26
+ "idempotency_conflict",
27
+ "file_credits_cap",
28
+ "day_credits_cap",
29
+ "heavy_wallet_pay_off",
30
+ "heavy_price_unavailable",
31
+ "unpaid_orders_cap",
32
+ "heavy_unavailable",
33
+ "piece_cid_invalid",
34
+ "piece_size_mismatch",
35
+ "slot_state",
36
+ "not_stored",
37
+ "payment_not_found",
38
+ "payment_mismatch",
39
+ "digest_used",
40
+ ];
41
+ /**
42
+ * The credit refusals Standard already has, which the order route may answer with instead of a new
43
+ * code of its own. They mean the same thing to the person, so they read as the same refusal here.
44
+ */
45
+ const SAME_AS = {
46
+ credits_short: "credits_insufficient",
47
+ credit_file_cap: "file_credits_cap",
48
+ credit_daily_cap: "day_credits_cap",
49
+ };
50
+ /**
51
+ * The Heavy refusal an error code names, or `null` when it names none.
52
+ *
53
+ * Letter case is ignored: servers spell error codes in capitals (`CREDITS_INSUFFICIENT`) and the
54
+ * contract writes them in lower case, and both mean one thing.
55
+ */
56
+ export function heavyRefusalOf(code) {
57
+ const lower = code.toLowerCase();
58
+ const direct = HEAVY_REFUSALS.find((r) => r === lower);
59
+ return direct ?? SAME_AS[lower] ?? null;
60
+ }
@@ -1,27 +1,7 @@
1
1
  import { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT, type AccountSettings } from "./manifest-settings.ts";
2
+ import { type ShareReceipt, type WireShareReceipt } from "./manifest-wire-extras.ts";
2
3
  export { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT };
3
- export type { AccountSettings };
4
- /**
5
- * One share this device made, kept where the server cannot reach it (`ManifestEntry.shares`).
6
- *
7
- * A receipt is written only AFTER the server's created row was checked to carry the very address
8
- * the sender typed — so what is stored is the address she asked for, never one the server chose.
9
- */
10
- export interface ShareReceipt {
11
- /** Recipient address in WIRE form: exactly what the create call was checked against. */
12
- address: string;
13
- /** When this device wrote the receipt, ms since the Unix epoch. This browser's clock. */
14
- at: number;
15
- /**
16
- * A revoke was sent for this receipt and the listing has not yet come back without the row.
17
- *
18
- * The receipt outlives the revoke ON PURPOSE: a revoke this side cannot verify is exactly the
19
- * case worth keeping, and a listing that still carries the address is the only evidence the
20
- * removal did not happen. Dropped once a listing no longer names it (`sharePrune`), which is
21
- * what keeps this array from growing forever.
22
- */
23
- revoked?: true;
24
- }
4
+ export type { AccountSettings, ShareReceipt };
25
5
  /** One entry — a file or a folder — as the rest of the app sees it. */
26
6
  export interface ManifestEntry {
27
7
  /** Item id. Files: the id the server assigned at commit. Folders: client-generated. */
@@ -100,6 +80,14 @@ export interface ManifestEntry {
100
80
  * log in the clear — the server is never handed a per-account value it could use as a handle.
101
81
  */
102
82
  labels?: string[];
83
+ /**
84
+ * This file is the preview picture of the video with this id: an
85
+ * ordinary file in every other way. Hidden wherever that video is in the list; shown once it is
86
+ * not, so a picture someone paid for never becomes an invisible orphan.
87
+ */
88
+ thumbOf?: string;
89
+ /** Wire keys this build does not know, written back verbatim (`manifest-wire-extras.ts`). */
90
+ carried?: Readonly<Record<string, unknown>>;
103
91
  }
104
92
  /**
105
93
  * Account-level settings that live INSIDE the sealed list.
@@ -174,15 +162,7 @@ export interface WireEntry {
174
162
  l?: string[];
175
163
  sn?: number;
176
164
  sh?: WireShareReceipt[];
177
- }
178
- /** One share receipt on the wire. Same short-key reason as the entry above it. */
179
- interface WireShareReceipt {
180
- /** address. */
181
- a: string;
182
- /** at. */
183
- t: number;
184
- /** revoked. */
185
- r?: 1;
165
+ to?: string;
186
166
  }
187
167
  export declare function toWire(e: ManifestEntry): WireEntry;
188
168
  export declare function fromWire(w: WireEntry): ManifestEntry;
@@ -17,6 +17,7 @@
17
17
  // codec round-trip suite and resolves no path aliases.
18
18
  import { NETWORK_WHEN_UNRECORDED } from "../storage-network.js";
19
19
  import { settingsFromWire, settingsToWire, TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT, } from "./manifest-settings.js";
20
+ import { carriedFromWire, sharesFromWire, sharesToWire, withCarried, } from "./manifest-wire-extras.js";
20
21
  export { TEXT_SCALE_DEFAULT_PCT, TEXT_SCALE_MAX_PCT, TEXT_SCALE_MIN_PCT };
21
22
  /**
22
23
  * Current format version this build writes.
@@ -70,10 +71,11 @@ export function toWire(e) {
70
71
  // spelling it out would cost bytes on every file of every save to say nothing new.
71
72
  if (e.network !== undefined && e.network !== NETWORK_WHEN_UNRECORDED)
72
73
  w.sn = e.network;
73
- if (e.shares && e.shares.length > 0) {
74
- w.sh = e.shares.map((r) => (r.revoked ? { a: r.address, t: r.at, r: 1 } : { a: r.address, t: r.at }));
75
- }
76
- return w;
74
+ if (e.shares && e.shares.length > 0)
75
+ w.sh = sharesToWire(e.shares);
76
+ if (e.thumbOf !== undefined)
77
+ w.to = e.thumbOf;
78
+ return withCarried(w, e.carried);
77
79
  }
78
80
  export function fromWire(w) {
79
81
  const e = {
@@ -108,25 +110,15 @@ export function fromWire(w) {
108
110
  // "stored on Walrus" — a claim about someone else's bytes that nothing would ever correct.
109
111
  if (typeof w.sn === "number")
110
112
  e.network = w.sn;
111
- // Defensive in the same way labels are, and for a sharper reason: a receipt with a blank address
112
- // or a broken instant would be compared against the server's rows and could produce a warning
113
- // about a share nobody ever made. Anything unusable is dropped — a receipt that cannot be
114
- // checked says nothing, and saying nothing is the honest outcome.
115
- if (Array.isArray(w.sh)) {
116
- const clean = [];
117
- for (const raw of w.sh) {
118
- if (!raw || typeof raw !== "object")
119
- continue;
120
- const { a, t, r } = raw;
121
- if (typeof a !== "string" || a === "")
122
- continue;
123
- if (typeof t !== "number" || !Number.isFinite(t))
124
- continue;
125
- clean.push(r === 1 ? { address: a, at: t, revoked: true } : { address: a, at: t });
126
- }
127
- if (clean.length > 0)
128
- e.shares = clean;
129
- }
113
+ // Checked receipt by receipt — see `sharesFromWire` for why a broken one says nothing.
114
+ const shares = sharesFromWire(w.sh);
115
+ if (shares)
116
+ e.shares = shares;
117
+ if (typeof w.to === "string" && w.to !== "")
118
+ e.thumbOf = w.to;
119
+ const carried = carriedFromWire(w);
120
+ if (carried)
121
+ e.carried = carried;
130
122
  return e;
131
123
  }
132
124
  /** Thrown when the plaintext is not a manifest this build can read. */
@@ -8,9 +8,15 @@ export interface ManifestIndex {
8
8
  readonly byId: ReadonlyMap<string, ManifestEntry>;
9
9
  /** Direct children by parent id (root under its own key). Values keep list order. */
10
10
  readonly childrenByParent: ReadonlyMap<string, readonly ManifestEntry[]>;
11
+ /** Preview pictures whose video is in the list — no view below shows these. */
12
+ readonly hidden: ReadonlySet<string>;
13
+ /** Video id → its hidden preview pictures, so every act on a video can take them along. */
14
+ readonly previews: ReadonlyMap<string, readonly string[]>;
11
15
  }
12
16
  /** Build the lookup structures for one version of the list. Cost is linear; do it once. */
13
17
  export declare function buildIndex(entries: readonly ManifestEntry[]): ManifestIndex;
18
+ /** Would a view show this entry at all? False only for a preview picture whose video is listed. */
19
+ export declare function shown(index: ManifestIndex, entry: ManifestEntry): boolean;
14
20
  /**
15
21
  * The instant this item became trash — its own, or the nearest trashed ancestor's.
16
22
  * `null` means live. A parent chain that is broken or looping counts as live at the point it
@@ -94,5 +100,8 @@ export interface DriveTotals {
94
100
  /** Bytes held by trashed files — the figure that explains "deleting did not free space yet". */
95
101
  trashedBytes: number;
96
102
  }
97
- /** Whole-drive counts. Exact, because the list is complete by construction. */
103
+ /**
104
+ * Whole-drive counts. Exact, because the list is complete by construction.
105
+ * ⚠ A hidden preview picture is not counted: the totals describe what the lists show.
106
+ */
98
107
  export declare function totalsOf(index: ManifestIndex): DriveTotals;