@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.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +73 -0
- package/README.ko.md +6 -3
- package/README.md +15 -3
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +14 -0
- package/dist/args.js +11 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/get.d.ts +2 -0
- package/dist/commands/get.js +13 -1
- package/dist/commands/handover.d.ts +13 -0
- package/dist/commands/handover.js +328 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/ls.d.ts +7 -0
- package/dist/commands/ls.js +27 -6
- package/dist/commands/public-code.d.ts +6 -0
- package/dist/commands/public-code.js +46 -0
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put-thumbnail.d.ts +4 -0
- package/dist/commands/put-thumbnail.js +119 -0
- package/dist/commands/put-wallet.d.ts +2 -0
- package/dist/commands/put-wallet.js +3 -2
- package/dist/commands/put.d.ts +10 -2
- package/dist/commands/put.js +13 -7
- package/dist/commands/receive.js +3 -3
- package/dist/commands/s3.js +44 -10
- package/dist/crypto-surface.d.ts +8 -0
- package/dist/crypto-surface.js +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +3 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/drive-edit/trash.js +5 -3
- package/dist/drive-edit/tree.d.ts +6 -0
- package/dist/drive-edit/tree.js +10 -0
- package/dist/drive-erase.js +2 -2
- package/dist/drive-paths.d.ts +2 -2
- package/dist/drive-paths.js +2 -2
- package/dist/handover.d.ts +44 -0
- package/dist/handover.js +199 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +8 -2
- package/dist/help.js +16 -3
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +14 -9
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/files.js +21 -2
- package/dist/mcp-tools/reads.js +9 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +17 -1
- package/dist/portable.js +13 -1
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +30 -0
- package/dist/risk.js +23 -2
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share.d.ts +5 -0
- package/dist/share.js +1 -1
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
- package/dist/shared/lib/drive/manifest-codec.js +15 -23
- package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
- package/dist/shared/lib/drive/manifest-index.js +30 -8
- package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
- package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
- package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
- package/dist/shared/lib/drive/preview-classify.js +96 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +11 -4
- package/dist/upload-wallet-put.js +17 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/get.md +3 -0
- package/docs/commands/handover.md +38 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/ls.md +5 -0
- package/docs/commands/public-code.md +7 -0
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +23 -1
- package/docs/commands/share.md +3 -1
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
|
@@ -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
|
+
}
|
package/dist/recovery-map.d.ts
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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;
|
package/dist/recovery-map.js
CHANGED
|
@@ -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 =
|
|
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
|
*
|
package/dist/recovery-source.js
CHANGED
|
@@ -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,
|
|
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,
|
|
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;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Which bucket and which key a request names, and whether it names something this gateway does.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ A SUB-RESOURCE IS NEVER AN OBJECT. `?acl`, `?tagging`, `?policy` and the rest ask about a
|
|
4
|
+
// bucket or a key rather than for its bytes. Falling through to the object branch answered
|
|
5
|
+
// `GET ?acl` with the file, stored the XML of `PUT ?tagging` as the file, and trashed the file
|
|
6
|
+
// on `DELETE ?tagging` — each a 200 for something that did not happen, or something that should
|
|
7
|
+
// not have. Every name below is classified first, and one this gateway does not do is 501.
|
|
8
|
+
//
|
|
9
|
+
// ⚠ THE PRESIGNED `X-Amz-*` PARAMETERS AND THE SDK'S `x-id` ARE NOT SUB-RESOURCES and are not
|
|
10
|
+
// listed; the signature has already consumed them by the time anything here looks.
|
|
11
|
+
import { S3Refusal } from "./answer.js";
|
|
12
|
+
/**
|
|
13
|
+
* Every query parameter S3 treats as naming a sub-resource.
|
|
14
|
+
*
|
|
15
|
+
* ⚠ `uploads`, `uploadId`, `delete`, `location` and `versioning` are answered; `versionId` is
|
|
16
|
+
* listed so that a request for one version is refused rather than answered with the only one.
|
|
17
|
+
*/
|
|
18
|
+
export const SUB_RESOURCES = [
|
|
19
|
+
"accelerate",
|
|
20
|
+
"acl",
|
|
21
|
+
"analytics",
|
|
22
|
+
"attributes",
|
|
23
|
+
"cors",
|
|
24
|
+
"delete",
|
|
25
|
+
"encryption",
|
|
26
|
+
"intelligent-tiering",
|
|
27
|
+
"inventory",
|
|
28
|
+
"legal-hold",
|
|
29
|
+
"lifecycle",
|
|
30
|
+
"location",
|
|
31
|
+
"logging",
|
|
32
|
+
"metrics",
|
|
33
|
+
"notification",
|
|
34
|
+
"object-lock",
|
|
35
|
+
"ownershipControls",
|
|
36
|
+
"policy",
|
|
37
|
+
"policyStatus",
|
|
38
|
+
"publicAccessBlock",
|
|
39
|
+
"replication",
|
|
40
|
+
"requestPayment",
|
|
41
|
+
"restore",
|
|
42
|
+
"retention",
|
|
43
|
+
"select",
|
|
44
|
+
"tagging",
|
|
45
|
+
"torrent",
|
|
46
|
+
"uploads",
|
|
47
|
+
"versioning",
|
|
48
|
+
"versionId",
|
|
49
|
+
"versions",
|
|
50
|
+
"website",
|
|
51
|
+
];
|
|
52
|
+
/** The sub-resource this query names, or null when it names none. */
|
|
53
|
+
export function subResourceOf(query) {
|
|
54
|
+
for (const name of query.keys()) {
|
|
55
|
+
if (SUB_RESOURCES.includes(name))
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
function decoded(part) {
|
|
61
|
+
try {
|
|
62
|
+
return decodeURIComponent(part);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new S3Refusal(400, "InvalidURI", "The request path is not valid percent-encoding.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** `Host` without its port, lower-cased. An IPv6 literal keeps its brackets. */
|
|
69
|
+
function hostOnly(host) {
|
|
70
|
+
const lower = host.trim().toLowerCase();
|
|
71
|
+
if (lower.startsWith("[")) {
|
|
72
|
+
const close = lower.indexOf("]");
|
|
73
|
+
return close < 0 ? lower : lower.slice(0, close + 1);
|
|
74
|
+
}
|
|
75
|
+
const colon = lower.lastIndexOf(":");
|
|
76
|
+
return colon >= 0 && /^\d*$/.test(lower.slice(colon + 1)) ? lower.slice(0, colon) : lower;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* `/drive/photos/a.jpg` → bucket `drive`, key `photos/a.jpg`; or, virtual-hosted, `Host:
|
|
80
|
+
* drive.s3.example.com` and `/photos/a.jpg` → the same two.
|
|
81
|
+
*/
|
|
82
|
+
export function addressOf(pathname, host, virtualHostBase) {
|
|
83
|
+
if (virtualHostBase !== undefined && host !== undefined) {
|
|
84
|
+
const base = hostOnly(virtualHostBase).replace(/^\.+/, "");
|
|
85
|
+
const named = hostOnly(host);
|
|
86
|
+
if (base !== "" && named.endsWith(`.${base}`)) {
|
|
87
|
+
const bucket = named.slice(0, named.length - base.length - 1);
|
|
88
|
+
if (bucket !== "")
|
|
89
|
+
return { bucket, key: decoded(pathname.replace(/^\//, "")) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const trimmed = pathname.replace(/^\//, "");
|
|
93
|
+
const at = trimmed.indexOf("/");
|
|
94
|
+
if (at < 0)
|
|
95
|
+
return { bucket: decoded(trimmed), key: "" };
|
|
96
|
+
return { bucket: decoded(trimmed.slice(0, at)), key: decoded(trimmed.slice(at + 1)) };
|
|
97
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ServerResponse } from "node:http";
|
|
2
|
+
/** A refusal this gateway decided on, carrying the S3 status and code it is answered with. */
|
|
3
|
+
export declare class S3Refusal extends Error {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly code: string;
|
|
6
|
+
constructor(status: number, code: string, message: string);
|
|
7
|
+
}
|
|
8
|
+
/** One failure, as the error document and headers an S3 client reads. */
|
|
9
|
+
export interface S3Answer {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
/** Seconds a client should wait before sending it again, when anything said. */
|
|
14
|
+
readonly retryAfter: number | null;
|
|
15
|
+
/**
|
|
16
|
+
* What the client was not told: the failure's own code or name and its own words, for whoever
|
|
17
|
+
* runs the gateway. Null when `message` already says everything there is.
|
|
18
|
+
*/
|
|
19
|
+
readonly reason: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* How long a client is asked to wait after the storage network did not take the bytes, when nothing
|
|
23
|
+
* named a wait. The storage is paid for and the bytes are kept, so the retry costs only the push.
|
|
24
|
+
*/
|
|
25
|
+
export declare const PUSH_RETRY_AFTER_SECONDS = 5;
|
|
26
|
+
/** What an S3 client should be told about a thrown value. */
|
|
27
|
+
export declare function answerFor(error: unknown): S3Answer;
|
|
28
|
+
/**
|
|
29
|
+
* Why this response failed, for whoever runs the gateway: undefined when it did not, or when its
|
|
30
|
+
* client was told everything there was.
|
|
31
|
+
*
|
|
32
|
+
* ⛔ NEVER A KEY. The request's path, and each of its segments, is taken out of the reason, since a
|
|
33
|
+
* failure's words may quote the file it was about and the log never names a file.
|
|
34
|
+
*/
|
|
35
|
+
export declare function failureReasonOf(res: ServerResponse): string | undefined;
|
|
36
|
+
/** Keep why this response failed, when its client was told less than that. */
|
|
37
|
+
export declare function noteFailure(res: ServerResponse, answer: S3Answer, resource: string): void;
|
|
38
|
+
/** Answer with an XML body, or with its headers alone for a HEAD. */
|
|
39
|
+
export declare function sendXml(res: ServerResponse, status: number, body: string, extra?: Record<string, string>): void;
|
|
40
|
+
/** Answer one refusal as the error document S3 sends. */
|
|
41
|
+
export declare function refuse(res: ServerResponse, status: number, code: string, message: string, resource: string, extra?: Record<string, string>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Answer whatever was thrown, if the response can still carry an answer.
|
|
44
|
+
*
|
|
45
|
+
* ⛔ A RESPONSE THAT HAS BEGUN IS DESTROYED, NOT ENDED. Its status and length went out already; a
|
|
46
|
+
* clean end after a short body is what every client files away as a whole file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function failWith(res: ServerResponse, error: unknown, resource: string): void;
|