@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/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
+ }
@@ -98,6 +98,7 @@ async function attempt(open, row) {
98
98
  return await open(row);
99
99
  }
100
100
  catch {
101
+ // Every way the reader throws means the bytes did not arrive, which is `unreadable`.
101
102
  return { ok: false, reason: "unreadable" };
102
103
  }
103
104
  }
@@ -0,0 +1,25 @@
1
+ /** A Filecoin chain NMTS Heavy can run on. */
2
+ export type FilecoinChain = "calibration" | "mainnet";
3
+ /** One storage company NMTS may place a copy with. */
4
+ export interface FilecoinProvider {
5
+ /** The company's id in the chain's service-provider registry. */
6
+ readonly id: bigint;
7
+ /** The host of its storage service (`https://<host>`); uploads and reads go here. */
8
+ readonly host: string;
9
+ /** Who runs it. Two copies of one file never go to the same operator when another exists. */
10
+ readonly operator: string;
11
+ /** Whether the chain's endorsement list names it. The first copy always goes to an endorsed one. */
12
+ readonly endorsed: boolean;
13
+ }
14
+ /** The allowlist, per chain, in preference order. */
15
+ export declare const FILECOIN_PROVIDERS: Readonly<Record<FilecoinChain, readonly FilecoinProvider[]>>;
16
+ /**
17
+ * Which Filecoin chain goes with which NMTS network: test data stays on test networks.
18
+ *
19
+ * Keyed by the NMTS network name ("testnet" | "mainnet") so that this file needs no import.
20
+ */
21
+ export declare const FILECOIN_CHAIN_FOR_NETWORK: Readonly<Record<"testnet" | "mainnet", FilecoinChain>>;
22
+ /** The `https://<host>` origins of one chain's list, in order. */
23
+ export declare function filecoinProviderOrigins(chain: FilecoinChain): string[];
24
+ /** The allowlisted company serving `host` on `chain`, or `null` when the host is not on the list. */
25
+ export declare function providerForHost(chain: FilecoinChain, host: string): FilecoinProvider | null;
@@ -0,0 +1,58 @@
1
+ // The Filecoin storage companies NMTS Heavy may place a file with, per Filecoin chain.
2
+ //
3
+ // ⚠ THIS FILE IS PUBLISHED. It is copied byte-for-byte into the `nmts` command-line package, so
4
+ // its comments stay self-contained English and it imports nothing.
5
+ //
6
+ // WHY A FIXED LIST AND NOT "EVERY APPROVED COMPANY ON CHAIN". A browser may only talk to hosts its
7
+ // Content-Security-Policy names, and the policy is written at build time. Accepting whatever the
8
+ // chain approves at the moment of an upload would mean opening the policy to any host at all. So
9
+ // the candidates are this list; adding one is a code change and a release. The chain's own
10
+ // approved set still applies on top: a company here that the chain no longer approves is skipped.
11
+ //
12
+ // HOW A PAIR IS CHOSEN (the server does it, from this same list): the first copy goes to an
13
+ // endorsed company, the second to a company run by a DIFFERENT operator, so that one operator
14
+ // failing never takes both copies. `operator` exists only to make that comparison.
15
+ //
16
+ // ⛔ THE SERVER KEEPS AN IDENTICAL TABLE. Both sides must agree on every row, or the server places a
17
+ // copy with a company the browser is not allowed to read from. A test compares the two files.
18
+ //
19
+ // Recorded 2026-09-23 on Filecoin Calibration: approved providers 2, 4 and 9; endorsed 4 and 9;
20
+ // 2 and 9 are run by the same operator.
21
+ // Recorded 2026-09-26 on Filecoin mainnet: approved providers 1, 5, 7, 32, 36 and 37; endorsed 1, 5,
22
+ // 7 and 32; 1 and 32 are run by one operator, 36 and 37 by another. Every one answers the browser's
23
+ // cross-origin upload and read requests. A company that stops answering is skipped when a pair is
24
+ // chosen, not removed from this list.
25
+ /** The allowlist, per chain, in preference order. */
26
+ export const FILECOIN_PROVIDERS = {
27
+ calibration: [
28
+ { id: 4n, host: "caliberation-pdp.infrafolio.com", operator: "infrafolio", endorsed: true },
29
+ { id: 9n, host: "calib.ezpdpz.net", operator: "ezpdpz", endorsed: true },
30
+ { id: 2n, host: "calib2.ezpdpz.net", operator: "ezpdpz", endorsed: false },
31
+ ],
32
+ mainnet: [
33
+ { id: 1n, host: "main.ezpdpz.net", operator: "ezpdpz", endorsed: true },
34
+ { id: 5n, host: "pdp.lotus.dedyn.io", operator: "mongo2stor", endorsed: true },
35
+ { id: 7n, host: "mainnet-pdp.infrafolio.com", operator: "infrafolio", endorsed: true },
36
+ { id: 32n, host: "main2.ezpdpz.net", operator: "ezpdpz", endorsed: true },
37
+ { id: 36n, host: "cello.fidl.tech", operator: "fidl", endorsed: false },
38
+ { id: 37n, host: "bass.fidl.tech", operator: "fidl", endorsed: false },
39
+ ],
40
+ };
41
+ /**
42
+ * Which Filecoin chain goes with which NMTS network: test data stays on test networks.
43
+ *
44
+ * Keyed by the NMTS network name ("testnet" | "mainnet") so that this file needs no import.
45
+ */
46
+ export const FILECOIN_CHAIN_FOR_NETWORK = {
47
+ testnet: "calibration",
48
+ mainnet: "mainnet",
49
+ };
50
+ /** The `https://<host>` origins of one chain's list, in order. */
51
+ export function filecoinProviderOrigins(chain) {
52
+ return FILECOIN_PROVIDERS[chain].map((p) => `https://${p.host}`);
53
+ }
54
+ /** The allowlisted company serving `host` on `chain`, or `null` when the host is not on the list. */
55
+ export function providerForHost(chain, host) {
56
+ const wanted = host.toLowerCase();
57
+ return FILECOIN_PROVIDERS[chain].find((p) => p.host === wanted) ?? null;
58
+ }
@@ -0,0 +1,48 @@
1
+ import type { HeavyCopy } from "../api/types-heavy.ts";
2
+ import { type FilecoinChain } from "../filecoin/providers.ts";
3
+ /** Inclusive start, exclusive end — the same shape the Walrus reads use. */
4
+ export interface HeavyByteRange {
5
+ start: number;
6
+ end?: number;
7
+ }
8
+ /** Why one copy was not used. */
9
+ export type HeavyCopySkip = "not_https" | "host_not_allowed" | "not_found" | "http_error" | "network_error";
10
+ export interface HeavyCopyAttempt {
11
+ providerId: string;
12
+ reason: HeavyCopySkip;
13
+ /** The HTTP status, when an answer was the reason. */
14
+ status?: number;
15
+ }
16
+ /**
17
+ * Every copy failed. `notFound` is true only when every company actually asked answered 404 — one
18
+ * that was down or erred may still hold the piece, which is the same rule the Walrus reads keep.
19
+ */
20
+ export declare class HeavyDownloadError extends Error {
21
+ readonly pieceCid: string;
22
+ readonly attempts: readonly HeavyCopyAttempt[];
23
+ readonly notFound: boolean;
24
+ constructor(pieceCid: string, attempts: readonly HeavyCopyAttempt[]);
25
+ }
26
+ export interface FetchHeavyPartInput {
27
+ /** The part's PieceCID — its `blob_id`. Used in messages only; each copy's address already names it. */
28
+ pieceCid: string;
29
+ /** The copies, in the order to try them. */
30
+ copies: readonly HeavyCopy[];
31
+ /** Which chain's allowlist the companies must be on. */
32
+ chain: FilecoinChain;
33
+ range?: HeavyByteRange;
34
+ signal?: AbortSignal;
35
+ /** Ask https companies outside the allowlist too (a program with no browser security policy). */
36
+ allowUnlisted?: boolean;
37
+ /** Default: the global `fetch`. */
38
+ fetchImpl?: (input: string, init?: RequestInit) => Promise<Response>;
39
+ }
40
+ /**
41
+ * Open a streaming read of one Heavy part from the first copy that serves it.
42
+ *
43
+ * Resolves with the response (status 200, or 206 for a range) whose body is the sealed part;
44
+ * rejects with `HeavyDownloadError` when no copy serves it, or with the AbortError of `signal`.
45
+ * A company that ignores `Range` and answers 200 with the whole part is accepted — the caller reads
46
+ * only what it needs and cancels the rest.
47
+ */
48
+ export declare function fetchHeavyPart(input: FetchHeavyPartInput): Promise<Response>;