@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
package/dist/drive-edit/tree.js
CHANGED
|
@@ -27,6 +27,16 @@ export function hasNamedAncestor(entries, entry, named) {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* `files` and the preview pictures of the videos among them. A video's
|
|
32
|
+
* picture is a file of its own, hidden from every listing while the video is there, so it goes
|
|
33
|
+
* wherever the video goes — left behind, it would be charged for and then show up on its own.
|
|
34
|
+
*/
|
|
35
|
+
export function withPreviews(entries, files) {
|
|
36
|
+
const index = buildIndex(entries);
|
|
37
|
+
const pictures = files.flatMap((f) => (index.previews.get(f.id) ?? []).flatMap((id) => index.byId.get(id) ?? []));
|
|
38
|
+
return uniqueById([...files, ...pictures]);
|
|
39
|
+
}
|
|
30
40
|
/** One entry per id, keeping the first. Two named folders can hold the same file only once. */
|
|
31
41
|
export function uniqueById(files) {
|
|
32
42
|
const byId = new Map();
|
package/dist/drive-erase.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// from each other. This is a sibling of that family rather than an outside caller.
|
|
31
31
|
import { request, ServerError } from "./api.js";
|
|
32
32
|
import { DriveEditError, resolving } from "./drive-edit/errors.js";
|
|
33
|
-
import { filesUnder, foldersUnder, uniqueById } from "./drive-edit/tree.js";
|
|
33
|
+
import { filesUnder, foldersUnder, uniqueById, withPreviews } from "./drive-edit/tree.js";
|
|
34
34
|
import { buildIndex, fullPathOf, KIND_FILE } from "./drive-paths.js";
|
|
35
35
|
import { NmtsError } from "./errors.js";
|
|
36
36
|
import { readFileList } from "./manifest.js";
|
|
@@ -53,7 +53,7 @@ export async function planErase(input, paths) {
|
|
|
53
53
|
const entries = list.manifest?.entries ?? [];
|
|
54
54
|
const index = buildIndex(entries);
|
|
55
55
|
const targets = resolving(() => batchTargets(entries, paths, { includeTrashed: true, nothingHappened: "Nothing was erased." }));
|
|
56
|
-
const files =
|
|
56
|
+
const files = withPreviews(entries, targets.flatMap((t) => (t.kind === KIND_FILE ? [t] : filesUnder(entries, t.id))));
|
|
57
57
|
// ⛔ AND THE FOLDERS UNDER A NAMED FOLDER, which `targets + files` left behind. A sub-folder
|
|
58
58
|
// holding no file was in neither set, so it stayed in the sealed list with its parent gone —
|
|
59
59
|
// a folder the drive still showed, sitting under nothing, that no command could reach
|
package/dist/drive-paths.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
|
2
|
-
import { buildIndex, isLive, type ManifestIndex, trashedAt } from "./shared/lib/drive/manifest-index.ts";
|
|
2
|
+
import { buildIndex, isLive, type ManifestIndex, shown, trashedAt } from "./shared/lib/drive/manifest-index.ts";
|
|
3
3
|
/** Folder. The same numeric codes the items API uses. */
|
|
4
4
|
export declare const KIND_FOLDER = 0;
|
|
5
5
|
/** File. */
|
|
6
6
|
export declare const KIND_FILE = 1;
|
|
7
|
-
export { buildIndex, isLive, trashedAt };
|
|
7
|
+
export { buildIndex, isLive, shown, trashedAt };
|
|
8
8
|
export type { ManifestIndex };
|
|
9
9
|
/**
|
|
10
10
|
* The full path of one entry, marked when the walk could not reach the root.
|
package/dist/drive-paths.js
CHANGED
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
// the third walk silently resolved the orphan to the same string. **The path that is printed
|
|
24
24
|
// must be the path that matches**, so there is one function and everybody calls it.
|
|
25
25
|
import { NmtsError } from "./errors.js";
|
|
26
|
-
import { buildIndex, isLive, KIND_FILE as SHARED_KIND_FILE, KIND_FOLDER as SHARED_KIND_FOLDER, trashedAt, } from "./shared/lib/drive/manifest-index.js";
|
|
26
|
+
import { buildIndex, isLive, KIND_FILE as SHARED_KIND_FILE, KIND_FOLDER as SHARED_KIND_FOLDER, shown, trashedAt, } from "./shared/lib/drive/manifest-index.js";
|
|
27
27
|
/** Folder. The same numeric codes the items API uses. */
|
|
28
28
|
export const KIND_FOLDER = SHARED_KIND_FOLDER;
|
|
29
29
|
/** File. */
|
|
30
30
|
export const KIND_FILE = SHARED_KIND_FILE;
|
|
31
|
-
export { buildIndex, isLive, trashedAt };
|
|
31
|
+
export { buildIndex, isLive, shown, trashedAt };
|
|
32
32
|
/**
|
|
33
33
|
* What a broken parent chain is drawn as.
|
|
34
34
|
*
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CryptoGlue } from "./crypto.ts";
|
|
2
|
+
import { type ShareKeys } from "./share.ts";
|
|
3
|
+
import { type HandoverNetwork, type HandoverPart } from "./shared/lib/share/handover-format.ts";
|
|
4
|
+
export declare function isHandoverNetwork(value: string): value is HandoverNetwork;
|
|
5
|
+
/** Refuse a name the handover file cannot carry, before any work is done. */
|
|
6
|
+
export declare function checkHandoverName(name: string, size: number, network: HandoverNetwork): void;
|
|
7
|
+
/** Build a handover file's text. The caller holds the file key and the digest, and wipes them. */
|
|
8
|
+
export declare function makeHandoverText(crypt: CryptoGlue, input: {
|
|
9
|
+
keys: ShareKeys;
|
|
10
|
+
recipientIdentity: Uint8Array;
|
|
11
|
+
recipientAddress: Uint8Array;
|
|
12
|
+
dek: Uint8Array;
|
|
13
|
+
itemId: string;
|
|
14
|
+
name: string;
|
|
15
|
+
size: number;
|
|
16
|
+
digest: Uint8Array;
|
|
17
|
+
parts: readonly HandoverPart[];
|
|
18
|
+
network: HandoverNetwork;
|
|
19
|
+
}): string;
|
|
20
|
+
/** What an opened handover file says. `dek` and `digest` are the caller's to wipe. */
|
|
21
|
+
export interface OpenedHandover {
|
|
22
|
+
name: string;
|
|
23
|
+
size: number;
|
|
24
|
+
/** The sender's public code, readable form — set only because the envelope opened. */
|
|
25
|
+
sender: string;
|
|
26
|
+
parts: HandoverPart[];
|
|
27
|
+
/** Earliest end epoch recorded when the file was made (exclusive); 0 when unknown. A hint. */
|
|
28
|
+
expiryEpoch: number;
|
|
29
|
+
dek: Uint8Array;
|
|
30
|
+
digest: Uint8Array;
|
|
31
|
+
}
|
|
32
|
+
/** Open a handover file's text with this account's keys. */
|
|
33
|
+
export declare function openHandoverText(crypt: CryptoGlue, keys: ShareKeys, text: string, network: HandoverNetwork): OpenedHandover;
|
|
34
|
+
/** This account's public code file. */
|
|
35
|
+
export declare function publicCodeFileText(keys: ShareKeys): string;
|
|
36
|
+
/**
|
|
37
|
+
* Read a recipient's public code file. Returns only when the identity inside really fingerprints to
|
|
38
|
+
* the code the file names, so what is sealed to is what the person was told.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readPublicCodeFileText(crypt: CryptoGlue, text: string): {
|
|
41
|
+
identity: Uint8Array;
|
|
42
|
+
address: Uint8Array;
|
|
43
|
+
display: string;
|
|
44
|
+
};
|
package/dist/handover.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Handing one file to one account OUTSIDE NMTS: a share that travels as a file instead of a server
|
|
2
|
+
// row (NCF-3 §5.6), and the public code file that lets a sender make one without asking the server
|
|
3
|
+
// for the recipient's identity (§5.7).
|
|
4
|
+
//
|
|
5
|
+
// ⛔ NOTHING NEW IS BUILT HERE. The envelope and the sealed digest come from `sealShare` — the same
|
|
6
|
+
// bytes a built-in share posts. The name document is the share's, extended by two values, and the
|
|
7
|
+
// only extra sealed value is the list of stored pieces, under the file's own key with its own
|
|
8
|
+
// label. The text around them is the shared format module, byte for byte the one the browser
|
|
9
|
+
// uses, so both programs accept and refuse the same files.
|
|
10
|
+
//
|
|
11
|
+
// ⛔ THE PARTS LIST AND THE NETWORK ARE BOUND THROUGH THE NAME. The parts are sealed first, and
|
|
12
|
+
// their SHA-256 and the network go into the name document, which the envelope covers. A reader
|
|
13
|
+
// compares both after opening the name; without that, anyone holding the file key could hand the
|
|
14
|
+
// recipient a list of their own choosing under the real sender's name.
|
|
15
|
+
//
|
|
16
|
+
// ⛔ OPENING ONE ASKS THE NMTS SERVER NOTHING. Everything the recipient needs is in the file; the
|
|
17
|
+
// pieces come from Walrus aggregators.
|
|
18
|
+
//
|
|
19
|
+
// ⛔ THE SENDER IS NAMED ONLY AFTER THE ENVELOPE OPENED, as for a received share: the file names
|
|
20
|
+
// its sender twice (the identity it carries and the envelope's first 16 bytes), the two must
|
|
21
|
+
// agree, and the unwrap then proves that sender made it.
|
|
22
|
+
import { createHash } from "node:crypto";
|
|
23
|
+
import { AAD } from "./crypto.js";
|
|
24
|
+
import { NmtsError } from "./errors.js";
|
|
25
|
+
import { addressFromTyped, identityMatches, sealShare } from "./share.js";
|
|
26
|
+
import { decodeHandover, decodeHandoverName, decodePartsList, decodePublicCodeFile, earliestExpiry, encodeHandover, encodeHandoverName, encodePartsList, encodePublicCodeFile, handoverNameFits, HandoverFormatError, } from "./shared/lib/share/handover-format.js";
|
|
27
|
+
const encoder = new TextEncoder();
|
|
28
|
+
const b64 = (bytes) => Buffer.from(bytes).toString("base64url");
|
|
29
|
+
const bytesOf = (text) => new Uint8Array(Buffer.from(text, "base64url"));
|
|
30
|
+
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("base64url");
|
|
31
|
+
/** A stand-in digest of the right length, to ask whether a name fits before anything is sealed. */
|
|
32
|
+
const DIGEST_PLACEHOLDER = "A".repeat(43);
|
|
33
|
+
export function isHandoverNetwork(value) {
|
|
34
|
+
return value === "mainnet" || value === "testnet";
|
|
35
|
+
}
|
|
36
|
+
/** Refuse a name the handover file cannot carry, before any work is done. */
|
|
37
|
+
export function checkHandoverName(name, size, network) {
|
|
38
|
+
let fits = false;
|
|
39
|
+
try {
|
|
40
|
+
fits = handoverNameFits(encodeHandoverName({ name, size, network, partsSha256: DIGEST_PLACEHOLDER }));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
fits = false;
|
|
44
|
+
}
|
|
45
|
+
if (!fits) {
|
|
46
|
+
throw new NmtsError("This file's name is too long to hand over.", {
|
|
47
|
+
exitCode: 2,
|
|
48
|
+
nextStep: "Nothing was written. Rename it with `nmts mv`, then try again.",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Build a handover file's text. The caller holds the file key and the digest, and wipes them. */
|
|
53
|
+
export function makeHandoverText(crypt, input) {
|
|
54
|
+
checkHandoverName(input.name, input.size, input.network);
|
|
55
|
+
try {
|
|
56
|
+
// The engine lowercases the id before binding it; the file carries that same spelling.
|
|
57
|
+
const item = input.itemId.toLowerCase();
|
|
58
|
+
// ⚠ ORDER: parts first — their digest goes into the name, and the name into the envelope.
|
|
59
|
+
const parts = crypt.envelope_seal(input.dek, encoder.encode(AAD.handoverParts), encoder.encode(encodePartsList(input.parts)));
|
|
60
|
+
const nameDocument = encodeHandoverName({
|
|
61
|
+
name: input.name,
|
|
62
|
+
size: input.size,
|
|
63
|
+
network: input.network,
|
|
64
|
+
partsSha256: sha256(parts),
|
|
65
|
+
});
|
|
66
|
+
const sealed = sealShare(crypt, { ...input, itemId: item, nameDocument });
|
|
67
|
+
return encodeHandover({
|
|
68
|
+
network: input.network,
|
|
69
|
+
item,
|
|
70
|
+
sender: b64(input.keys.identity),
|
|
71
|
+
envelope: sealed.dek_share_ct,
|
|
72
|
+
name: sealed.name_share_ct,
|
|
73
|
+
hash: sealed.content_hash_share_ct,
|
|
74
|
+
parts: b64(parts),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof NmtsError)
|
|
79
|
+
throw error;
|
|
80
|
+
const field = error instanceof HandoverFormatError && error.field !== null ? ` (${error.field})` : "";
|
|
81
|
+
throw new NmtsError(`Could not make the handover file${field}.`, {
|
|
82
|
+
exitCode: 1,
|
|
83
|
+
nextStep: "Nothing was written. The file's stored pieces are not in a form a handover can carry.",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Open a handover file's text with this account's keys. */
|
|
88
|
+
export function openHandoverText(crypt, keys, text, network) {
|
|
89
|
+
let file;
|
|
90
|
+
try {
|
|
91
|
+
file = decodeHandover(text, network);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw readRefusal(error, network);
|
|
95
|
+
}
|
|
96
|
+
const damaged = new NmtsError("This handover file is damaged: its fields do not hold together.", {
|
|
97
|
+
exitCode: 1,
|
|
98
|
+
nextStep: "Nothing was written. Ask the sender to send it again.",
|
|
99
|
+
});
|
|
100
|
+
const senderIdentity = bytesOf(file.sender);
|
|
101
|
+
const envelope = bytesOf(file.envelope);
|
|
102
|
+
let claimed;
|
|
103
|
+
try {
|
|
104
|
+
claimed = crypt.share_claimed_sender(envelope);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
throw damaged;
|
|
108
|
+
}
|
|
109
|
+
if (!identityMatches(crypt, senderIdentity, claimed))
|
|
110
|
+
throw damaged;
|
|
111
|
+
const nameCt = bytesOf(file.name);
|
|
112
|
+
const digestCt = bytesOf(file.hash);
|
|
113
|
+
const partsCt = bytesOf(file.parts);
|
|
114
|
+
let dek;
|
|
115
|
+
try {
|
|
116
|
+
dek = crypt.share_unwrap_dek(keys.kemSeed, keys.authSecret, keys.sigSeed, senderIdentity, envelope, file.item, nameCt, digestCt);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw new NmtsError("This file does not open with your NMTS key.", {
|
|
120
|
+
exitCode: 4,
|
|
121
|
+
nextStep: "Nothing was written. It was made for another key, or it was changed after it was made.",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const named = decodeHandoverName(new TextDecoder().decode(crypt.envelope_open(dek, encoder.encode(AAD.shareName), nameCt)));
|
|
126
|
+
if (named.network !== file.network || named.partsSha256 !== sha256(partsCt))
|
|
127
|
+
throw damaged;
|
|
128
|
+
const parts = decodePartsList(new TextDecoder().decode(crypt.envelope_open(dek, encoder.encode(AAD.handoverParts), partsCt)));
|
|
129
|
+
const digest = crypt.envelope_open(dek, encoder.encode(AAD.shareContentHash), digestCt);
|
|
130
|
+
return {
|
|
131
|
+
name: named.name,
|
|
132
|
+
size: named.size,
|
|
133
|
+
sender: crypt.share_address_display(claimed),
|
|
134
|
+
parts,
|
|
135
|
+
expiryEpoch: earliestExpiry(parts),
|
|
136
|
+
dek,
|
|
137
|
+
digest,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
dek.fill(0);
|
|
142
|
+
throw damaged;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** This account's public code file. */
|
|
146
|
+
export function publicCodeFileText(keys) {
|
|
147
|
+
return encodePublicCodeFile({ code: keys.display, identity: b64(keys.identity) });
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Read a recipient's public code file. Returns only when the identity inside really fingerprints to
|
|
151
|
+
* the code the file names, so what is sealed to is what the person was told.
|
|
152
|
+
*/
|
|
153
|
+
export function readPublicCodeFileText(crypt, text) {
|
|
154
|
+
let file;
|
|
155
|
+
try {
|
|
156
|
+
file = decodePublicCodeFile(text);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error instanceof HandoverFormatError && error.problem === "unknown-version") {
|
|
160
|
+
throw new NmtsError("This public code file is from a newer version of NMTS.", {
|
|
161
|
+
exitCode: 4,
|
|
162
|
+
nextStep: "Nothing was written. Update this tool and try again.",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
throw new NmtsError("This is not a valid public code file.", { exitCode: 2, nextStep: "Nothing was written." });
|
|
166
|
+
}
|
|
167
|
+
const address = addressFromTyped(crypt, file.code);
|
|
168
|
+
const identity = bytesOf(file.identity);
|
|
169
|
+
if (!identityMatches(crypt, identity, address)) {
|
|
170
|
+
throw new NmtsError("The identity in this public code file does not belong to the public code it names.", {
|
|
171
|
+
exitCode: 1,
|
|
172
|
+
nextStep: "Nothing was written. Sealing to it would hand the file to somebody else; ask the recipient for their file again.",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return { identity, address, display: crypt.share_address_display(address) };
|
|
176
|
+
}
|
|
177
|
+
/** A handover file the format module refused, said the way §5.6 sorts it. */
|
|
178
|
+
function readRefusal(error, network) {
|
|
179
|
+
const problem = error instanceof HandoverFormatError ? error.problem : "not-json";
|
|
180
|
+
switch (problem) {
|
|
181
|
+
case "unknown-version":
|
|
182
|
+
return new NmtsError("This handover file is from a newer version of NMTS.", {
|
|
183
|
+
exitCode: 4,
|
|
184
|
+
nextStep: "Nothing was written. Update this tool and try again.",
|
|
185
|
+
});
|
|
186
|
+
case "other-network":
|
|
187
|
+
return new NmtsError(`This handover file was made on the other network; this tool is on ${network}.`, {
|
|
188
|
+
exitCode: 4,
|
|
189
|
+
nextStep: "Nothing was written. Open it with --network set to the network it was made on.",
|
|
190
|
+
});
|
|
191
|
+
case "bad-field":
|
|
192
|
+
return new NmtsError("This handover file is damaged: a field was cut or changed.", {
|
|
193
|
+
exitCode: 1,
|
|
194
|
+
nextStep: "Nothing was written. Ask the sender to send it again.",
|
|
195
|
+
});
|
|
196
|
+
default:
|
|
197
|
+
return new NmtsError("This is not a handover file.", { exitCode: 2, nextStep: "Nothing was written." });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NmtsError } from "./errors.ts";
|
|
2
|
+
import type { HeavyCopy, HeavyOrderApi, HeavyPartCommit } from "./shared/lib/api/types-heavy.ts";
|
|
3
|
+
/** A line that dropped, in the shape the order runner retries. */
|
|
4
|
+
export declare class HeavyTransportError extends NmtsError {
|
|
5
|
+
readonly code = "NETWORK";
|
|
6
|
+
constructor(cause: NmtsError);
|
|
7
|
+
}
|
|
8
|
+
/** The order routes, bound to one server and one credential. */
|
|
9
|
+
export declare function createHeavyApi(server: string, bearer: string): HeavyOrderApi;
|
|
10
|
+
/** A self-paid Heavy part: no order, the person's own EVM wallet paid (`owner_kind` 0). */
|
|
11
|
+
export interface HeavySelfPaidPart {
|
|
12
|
+
part_index: number;
|
|
13
|
+
storage_kind: 0;
|
|
14
|
+
network: 1;
|
|
15
|
+
blob_id: string;
|
|
16
|
+
sealed_len: number;
|
|
17
|
+
owner_kind: 0;
|
|
18
|
+
expiry_epoch: number;
|
|
19
|
+
copies: HeavyCopy[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `POST /v1/items` for one Heavy file.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ SAFE TO ASK AGAIN: the idempotency key names this file of this upload, so a commit whose answer
|
|
25
|
+
* was lost is recognised rather than making a second file out of the same stored pieces.
|
|
26
|
+
*/
|
|
27
|
+
export declare function commitHeavyItem(input: {
|
|
28
|
+
server: string;
|
|
29
|
+
bearer: string;
|
|
30
|
+
idempotencyKey: string;
|
|
31
|
+
dekWrapped: string;
|
|
32
|
+
contentHashCt: string;
|
|
33
|
+
parts: readonly (HeavyPartCommit | HeavySelfPaidPart)[];
|
|
34
|
+
/** Self-paid only: the `0x` EVM address that paid. */
|
|
35
|
+
paidBy?: string | undefined;
|
|
36
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// NMTS Heavy's order routes over this package's one request function — the `HeavyOrderApi` the
|
|
2
|
+
// shared order runner (`shared/lib/heavy/order-runner.ts`) drives — and the commit of a finished
|
|
3
|
+
// Heavy file.
|
|
4
|
+
//
|
|
5
|
+
// ⛔ THE RUNNER READS ERRORS BY SHAPE: a string `code` and a number `status`. A server refusal
|
|
6
|
+
// already carries both (`ServerError`). A line that dropped does not — `request` throws a plain
|
|
7
|
+
// `NmtsError` for it — so it is handed on here with the transport word `NETWORK`, which is the
|
|
8
|
+
// one the runner asks again on. Everything else passes through untouched, so a refusal the
|
|
9
|
+
// server explained still prints the way every other refusal does.
|
|
10
|
+
//
|
|
11
|
+
// ⛔ NO `node:` IMPORT. The SDK's browser entry reaches this file through `portable.ts`.
|
|
12
|
+
import { HttpError, request, ServerError } from "./api.js";
|
|
13
|
+
import { NmtsError } from "./errors.js";
|
|
14
|
+
import { isRecord } from "./guards.js";
|
|
15
|
+
import { HEAVY_COPY } from "./heavy-copy.js";
|
|
16
|
+
/** How long a route that reaches the chain service gets. The same as the credit rail's. */
|
|
17
|
+
const CHAIN_TIMEOUT_MS = 120_000;
|
|
18
|
+
/** A line that dropped, in the shape the order runner retries. */
|
|
19
|
+
export class HeavyTransportError extends NmtsError {
|
|
20
|
+
code = "NETWORK";
|
|
21
|
+
constructor(cause) {
|
|
22
|
+
super(cause.message, { exitCode: cause.exitCode, nextStep: cause.nextStep });
|
|
23
|
+
this.name = "HeavyTransportError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function call(fn, read) {
|
|
27
|
+
let value;
|
|
28
|
+
try {
|
|
29
|
+
value = await fn();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof ServerError || error instanceof HttpError || !(error instanceof NmtsError))
|
|
33
|
+
throw error;
|
|
34
|
+
throw new HeavyTransportError(error);
|
|
35
|
+
}
|
|
36
|
+
return read(value);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The answer as the contract types it.
|
|
40
|
+
*
|
|
41
|
+
* ⚠ CHECKED FOR BEING AN OBJECT AND NOTHING MORE HERE: the runner checks every field it acts on
|
|
42
|
+
* (the slots it opened, the https address it uploads to, each copy) before it acts on it, and
|
|
43
|
+
* says `bad_answer` when one is missing. Two checks of one answer would be two answers to what a
|
|
44
|
+
* well-formed one is.
|
|
45
|
+
*/
|
|
46
|
+
function answer(value) {
|
|
47
|
+
if (!isRecord(value))
|
|
48
|
+
throw new NmtsError("The server's answer about the Heavy order was not an object.");
|
|
49
|
+
// ⚠ The one assertion in this file, for the reason above: the runner reads each field by shape.
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/** The order routes, bound to one server and one credential. */
|
|
53
|
+
export function createHeavyApi(server, bearer) {
|
|
54
|
+
const order = (id) => encodeURIComponent(id);
|
|
55
|
+
return {
|
|
56
|
+
createOrder: (body, options) => call(() => request(server, "/v1/heavy/orders", { method: "POST", token: bearer, body, timeoutMs: CHAIN_TIMEOUT_MS, signal: options?.signal }), (answer)),
|
|
57
|
+
getOrder: (id, options) => call(() => request(server, `/v1/heavy/orders/${order(id)}`, { token: bearer, signal: options?.signal }), (answer)),
|
|
58
|
+
targetSlot: (id, slot, body, options) => call(() => request(server, `/v1/heavy/orders/${order(id)}/slots/${slot}/target`, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
token: bearer,
|
|
61
|
+
body,
|
|
62
|
+
timeoutMs: CHAIN_TIMEOUT_MS,
|
|
63
|
+
signal: options?.signal,
|
|
64
|
+
}), (answer)),
|
|
65
|
+
slotUploaded: (id, slot, options) => call(() => request(server, `/v1/heavy/orders/${order(id)}/slots/${slot}/uploaded`, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
token: bearer,
|
|
68
|
+
body: {},
|
|
69
|
+
timeoutMs: CHAIN_TIMEOUT_MS,
|
|
70
|
+
signal: options?.signal,
|
|
71
|
+
}), (answer)),
|
|
72
|
+
markPaid: (id, body, options) => call(() => request(server, `/v1/heavy/orders/${order(id)}/paid`, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
token: bearer,
|
|
75
|
+
body,
|
|
76
|
+
timeoutMs: CHAIN_TIMEOUT_MS,
|
|
77
|
+
signal: options?.signal,
|
|
78
|
+
}), (answer)),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* `POST /v1/items` for one Heavy file.
|
|
83
|
+
*
|
|
84
|
+
* ⛔ SAFE TO ASK AGAIN: the idempotency key names this file of this upload, so a commit whose answer
|
|
85
|
+
* was lost is recognised rather than making a second file out of the same stored pieces.
|
|
86
|
+
*/
|
|
87
|
+
export async function commitHeavyItem(input) {
|
|
88
|
+
const reply = await request(input.server, "/v1/items", {
|
|
89
|
+
method: "POST",
|
|
90
|
+
token: input.bearer,
|
|
91
|
+
idempotencyKey: input.idempotencyKey,
|
|
92
|
+
timeoutMs: CHAIN_TIMEOUT_MS,
|
|
93
|
+
body: {
|
|
94
|
+
size: input.parts.reduce((sum, part) => sum + part.sealed_len, 0),
|
|
95
|
+
dek_wrapped: input.dekWrapped,
|
|
96
|
+
content_hash_ct: input.contentHashCt,
|
|
97
|
+
visibility: 0,
|
|
98
|
+
parts: input.parts,
|
|
99
|
+
...(input.paidBy === undefined ? {} : { paid_by: input.paidBy }),
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const id = isRecord(reply) ? reply["id"] : undefined;
|
|
103
|
+
if (typeof id !== "string" || id === "") {
|
|
104
|
+
throw new NmtsError(HEAVY_COPY.commitNoId, { nextStep: HEAVY_COPY.commitNoIdNext });
|
|
105
|
+
}
|
|
106
|
+
return id;
|
|
107
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export declare const HEAVY_COPY: {
|
|
2
|
+
/** `put --tier heavy`: the line before the upload starts (credits). */
|
|
3
|
+
readonly creditsPlan: (name: string, bytes: number, credits: number) => string;
|
|
4
|
+
/** `put --tier heavy --pay wallet`: the review line with the order's WAL price and term. */
|
|
5
|
+
readonly walletPlan: (name: string, bytes: number, wal: string, days: number, from: string, to: string) => string;
|
|
6
|
+
/** `put --tier heavy --pay evm`: the review line (copies, paying 0x address). */
|
|
7
|
+
readonly evmPlan: (name: string, bytes: number, copies: number, address: string) => string;
|
|
8
|
+
/** `--dry-run --tier heavy --pay wallet`: the plan line before any order opens (no price yet). */
|
|
9
|
+
readonly walletDryPlan: (name: string, bytes: number, days: number, from: string) => string;
|
|
10
|
+
/** `--dry-run` with `--tier heavy`: the closing line (nothing sent; a wallet price is quoted only when an order opens). */
|
|
11
|
+
readonly dryRunEnd: " Nothing was sent and nothing was charged. The WAL or USDFC price is set when the upload runs; run the same command without --dry-run to see it before anything is paid.";
|
|
12
|
+
/** Progress, one line per phase of one part. */
|
|
13
|
+
readonly progress: (phase: string, where: string) => string;
|
|
14
|
+
/** Finished: the Filecoin epoch it is kept until. */
|
|
15
|
+
readonly stored: (expiryEpoch: number) => string;
|
|
16
|
+
/** A Heavy upload stopped (`HeavyOrderError`): the reason word and the runner's detail. */
|
|
17
|
+
readonly failed: (reason: string, detail: string) => string;
|
|
18
|
+
readonly failedNext: (reason: string) => string;
|
|
19
|
+
/** POST /v1/items answered without an id (the pieces are stored; a rerun opens a NEW order). */
|
|
20
|
+
readonly commitNoId: "The file was stored, but the server did not say which file it became.";
|
|
21
|
+
readonly commitNoIdNext: "Run `nmts ls` to look for it before trying again: running the same command again is a new upload and is paid again.";
|
|
22
|
+
/** Server refusal advice (`api-advice.ts`): Heavy paid from the wallet is off on this server. */
|
|
23
|
+
readonly adviceWalletPayOff: "Paying for NMTS Heavy from the wallet is switched off on this server. Pay with credits: leave out --pay wallet.";
|
|
24
|
+
/** Server refusal advice: Heavy storage is unavailable right now (chain service down or at its day limit). */
|
|
25
|
+
readonly adviceUnavailable: "NMTS Heavy cannot take uploads on this server right now. Nothing was charged. Try again later, or upload with --tier standard.";
|
|
26
|
+
/** Server refusal advice: the wallet price cannot be set right now (the WAL quotes disagree or are stale). */
|
|
27
|
+
readonly advicePriceUnavailable: "NMTS Heavy cannot set a WAL price right now, so nothing was charged. Pay with credits (leave out --pay wallet), or try again in a few minutes.";
|
|
28
|
+
/** Server refusal advice: this account's unpaid wallet orders reached the day's ceiling (UTC day). */
|
|
29
|
+
readonly adviceUnpaidCap: "Today's limit of unpaid NMTS Heavy wallet uploads is reached, so nothing was charged. Pay with credits (leave out --pay wallet), or upload again after midnight UTC.";
|
|
30
|
+
/** `--tier heavy --pay evm` where no storage company is listed, refused before anything is spent. */
|
|
31
|
+
readonly evmNoProviders: (chain: string) => string;
|
|
32
|
+
/** A flag that only means something with `--pay evm` was given without it. */
|
|
33
|
+
readonly evmOnlyFlag: (flag: string) => string;
|
|
34
|
+
/** `--pay evm` without `--tier heavy`. */
|
|
35
|
+
readonly evmNeedsHeavy: "--pay evm pays Filecoin, so it needs --tier heavy.";
|
|
36
|
+
/** A Standard-only option (`--epochs`, `--storage`, `--from`, `--deposit`, `--part-size`) given with `--tier heavy`. */
|
|
37
|
+
readonly standardOnlyFlag: (flag: string) => string;
|
|
38
|
+
/** A Heavy-only option (`--copies`, `--providers`, `--evm-wallet`, `--days`) given without `--tier heavy`. */
|
|
39
|
+
readonly heavyOnlyFlag: (flag: string) => string;
|
|
40
|
+
/** `--days` given with a Heavy payer other than the wallet (credits keep 28 days; evm lasts as long as the deposit). */
|
|
41
|
+
readonly walletOnlyDays: "--days only applies with --tier heavy --pay wallet: credits keep a file 28 days, and --pay evm keeps it as long as the deposit lasts.";
|
|
42
|
+
/** `--days` out of 1..365. */
|
|
43
|
+
readonly badDays: (raw: string) => string;
|
|
44
|
+
/** The wallet holds less WAL (or SUI for the fee) than the order's price — refused before anything is sealed. */
|
|
45
|
+
readonly walletShort: (needWal: string, haveWal: string, needSui: string, haveSui: string) => string;
|
|
46
|
+
/** `--copies` out of 1..12, or `--providers` not a list of ids. */
|
|
47
|
+
readonly badCopies: (raw: string) => string;
|
|
48
|
+
readonly badProviders: (raw: string) => string;
|
|
49
|
+
/** A self-paid upload stored no copy at all (the SDK answered no copies). */
|
|
50
|
+
readonly evmNoCopy: (detail: string) => string;
|
|
51
|
+
/** `heavy wallet` output labels. */
|
|
52
|
+
readonly walletAddress: "address";
|
|
53
|
+
readonly walletFil: "FIL";
|
|
54
|
+
readonly walletUsdfc: "USDFC";
|
|
55
|
+
readonly walletDeposit: "deposit (available)";
|
|
56
|
+
readonly walletRunway: "lasts to epoch";
|
|
57
|
+
/** `heavy fund`: the review before signing, the `--yes` refusal, and the done line. */
|
|
58
|
+
readonly fundReview: (usdfc: string, address: string) => string;
|
|
59
|
+
readonly fundNeedsYes: "Nothing was signed. Depositing spends from the wallet: run it again with --yes.";
|
|
60
|
+
readonly fundNothing: "The deposit already covers this amount. Nothing was signed.";
|
|
61
|
+
readonly fundDone: (hash: string) => string;
|
|
62
|
+
readonly fundBadAmount: (raw: string) => string;
|
|
63
|
+
/** The SDK's `put(…, { tier })`: an option given on the tier or payer it means nothing to. */
|
|
64
|
+
readonly sdkHeavyOnly: (option: string) => string;
|
|
65
|
+
readonly sdkNotHeavy: (option: string) => string;
|
|
66
|
+
readonly sdkPayerOnly: (option: string, pay: string) => string;
|
|
67
|
+
/** The SDK: `pay: { signer }` on Heavy is an EVM account; on Standard it is a Sui wallet. */
|
|
68
|
+
readonly sdkEvmSigner: "On tier: \"heavy\", pay: { signer } is an EVM account, such as viem's privateKeyToAccount().";
|
|
69
|
+
readonly sdkSuiSigner: "An EVM account pays only with tier: \"heavy\". On tier: \"standard\", pay: { signer } is a Sui wallet.";
|
|
70
|
+
/** `heavy` with no or an unknown verb. */
|
|
71
|
+
readonly heavyVerb: "Use `nmts heavy wallet` or `nmts heavy fund <USDFC>`.";
|
|
72
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Every sentence NMTS Heavy adds to this tool that a person or an agent reads — in one table.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ Code never builds a Heavy sentence anywhere else; a new sentence is a new row here.
|
|
4
|
+
//
|
|
5
|
+
// ⭐ TWO REGISTERS, ON PURPOSE. What `--tier heavy` says with credits or the wallet uses the drive's
|
|
6
|
+
// words — the file is kept whole in two separate places — and names no network, company or token:
|
|
7
|
+
// a person choosing Heavy never has to learn one. The self-paid road (`--pay evm`, `heavy wallet`,
|
|
8
|
+
// `heavy fund`) is the developer's handle on Filecoin itself (what Filecoin allows directly must
|
|
9
|
+
// work here too), so it says Filecoin, USDFC and FIL plainly.
|
|
10
|
+
//
|
|
11
|
+
// ⚠ Values that take numbers are functions, so the wording can put the number where it reads best.
|
|
12
|
+
/** What each runner phase is called on the progress lines. An unknown phase prints as itself. */
|
|
13
|
+
const PHASE = {
|
|
14
|
+
opened: "order opened",
|
|
15
|
+
sealing: "encrypting",
|
|
16
|
+
hashing: "computing the piece id",
|
|
17
|
+
placing: "choosing where it is kept",
|
|
18
|
+
uploading: "uploading",
|
|
19
|
+
committing: "waiting for both places to confirm",
|
|
20
|
+
stored: "stored",
|
|
21
|
+
paying: "paying from the wallet",
|
|
22
|
+
paid: "paid",
|
|
23
|
+
};
|
|
24
|
+
/** What a stopped Heavy upload means for the money, by the runner's reason word. */
|
|
25
|
+
function failedNextFor(reason) {
|
|
26
|
+
if (reason === "payment_refused") {
|
|
27
|
+
return ("The file was stored, but the server did not accept the payment. Look at `nmts wallet activity`: " +
|
|
28
|
+
"if the WAL left the wallet, write to us with `nmts support` and the transaction. Unpaid pieces " +
|
|
29
|
+
"are removed after an hour.");
|
|
30
|
+
}
|
|
31
|
+
if (reason === "piece_too_small" || reason === "piece_too_large" || reason === "slot_count" || reason === "sealed_len_mismatch") {
|
|
32
|
+
return "Nothing was stored. This is a fault in this tool, not in the file — please write to us with `nmts support`.";
|
|
33
|
+
}
|
|
34
|
+
return ("Credits for anything that was not stored come back within a day, and a wallet pays nothing until " +
|
|
35
|
+
"every part is stored. Running the same command again starts a new upload.");
|
|
36
|
+
}
|
|
37
|
+
export const HEAVY_COPY = {
|
|
38
|
+
/** `put --tier heavy`: the line before the upload starts (credits). */
|
|
39
|
+
creditsPlan: (name, bytes, credits) => `${name} ${bytes} bytes → ${credits} credit${credits === 1 ? "" : "s"} · NMTS Heavy: kept whole in two separate places for 28 days`,
|
|
40
|
+
/** `put --tier heavy --pay wallet`: the review line with the order's WAL price and term. */
|
|
41
|
+
walletPlan: (name, bytes, wal, days, from, to) => `${name} ${bytes} bytes → ${wal} WAL for ${days} day${days === 1 ? "" : "s"}, paid once it is stored, from ${from} to ${to} · NMTS Heavy`,
|
|
42
|
+
/** `put --tier heavy --pay evm`: the review line (copies, paying 0x address). */
|
|
43
|
+
evmPlan: (name, bytes, copies, address) => `${name} ${bytes} bytes → ${copies} cop${copies === 1 ? "y" : "ies"} on Filecoin, paid in USDFC by ${address}`,
|
|
44
|
+
/** `--dry-run --tier heavy --pay wallet`: the plan line before any order opens (no price yet). */
|
|
45
|
+
walletDryPlan: (name, bytes, days, from) => `${name} ${bytes} bytes → NMTS Heavy for ${days} day${days === 1 ? "" : "s"}, paid from ${from} once it is stored`,
|
|
46
|
+
/** `--dry-run` with `--tier heavy`: the closing line (nothing sent; a wallet price is quoted only when an order opens). */
|
|
47
|
+
dryRunEnd: " Nothing was sent and nothing was charged. The WAL or USDFC price is set when the upload runs; run the same command without --dry-run to see it before anything is paid.",
|
|
48
|
+
/** Progress, one line per phase of one part. */
|
|
49
|
+
progress: (phase, where) => ` ${PHASE[phase] ?? phase}${where}`,
|
|
50
|
+
/** Finished: the Filecoin epoch it is kept until. */
|
|
51
|
+
stored: (expiryEpoch) => ` kept until Filecoin epoch ${expiryEpoch}`,
|
|
52
|
+
/** A Heavy upload stopped (`HeavyOrderError`): the reason word and the runner's detail. */
|
|
53
|
+
failed: (reason, detail) => `The NMTS Heavy upload stopped (${reason}): ${detail}`,
|
|
54
|
+
failedNext: (reason) => failedNextFor(reason),
|
|
55
|
+
/** POST /v1/items answered without an id (the pieces are stored; a rerun opens a NEW order). */
|
|
56
|
+
commitNoId: "The file was stored, but the server did not say which file it became.",
|
|
57
|
+
commitNoIdNext: "Run `nmts ls` to look for it before trying again: running the same command again is a new upload and is paid again.",
|
|
58
|
+
/** Server refusal advice (`api-advice.ts`): Heavy paid from the wallet is off on this server. */
|
|
59
|
+
adviceWalletPayOff: "Paying for NMTS Heavy from the wallet is switched off on this server. Pay with credits: leave out --pay wallet.",
|
|
60
|
+
/** Server refusal advice: Heavy storage is unavailable right now (chain service down or at its day limit). */
|
|
61
|
+
adviceUnavailable: "NMTS Heavy cannot take uploads on this server right now. Nothing was charged. Try again later, or upload with --tier standard.",
|
|
62
|
+
/** Server refusal advice: the wallet price cannot be set right now (the WAL quotes disagree or are stale). */
|
|
63
|
+
advicePriceUnavailable: "NMTS Heavy cannot set a WAL price right now, so nothing was charged. Pay with credits (leave out --pay wallet), or try again in a few minutes.",
|
|
64
|
+
/** Server refusal advice: this account's unpaid wallet orders reached the day's ceiling (UTC day). */
|
|
65
|
+
adviceUnpaidCap: "Today's limit of unpaid NMTS Heavy wallet uploads is reached, so nothing was charged. Pay with credits (leave out --pay wallet), or upload again after midnight UTC.",
|
|
66
|
+
/** `--tier heavy --pay evm` where no storage company is listed, refused before anything is spent. */
|
|
67
|
+
evmNoProviders: (chain) => `Paying Filecoin yourself is not available on ${chain} in this version. Nothing was spent.`,
|
|
68
|
+
/** A flag that only means something with `--pay evm` was given without it. */
|
|
69
|
+
evmOnlyFlag: (flag) => `${flag} only applies with --tier heavy --pay evm: it chooses where your own payment stores the file.`,
|
|
70
|
+
/** `--pay evm` without `--tier heavy`. */
|
|
71
|
+
evmNeedsHeavy: "--pay evm pays Filecoin, so it needs --tier heavy.",
|
|
72
|
+
/** A Standard-only option (`--epochs`, `--storage`, `--from`, `--deposit`, `--part-size`) given with `--tier heavy`. */
|
|
73
|
+
standardOnlyFlag: (flag) => `${flag} does not apply to --tier heavy.`,
|
|
74
|
+
/** A Heavy-only option (`--copies`, `--providers`, `--evm-wallet`, `--days`) given without `--tier heavy`. */
|
|
75
|
+
heavyOnlyFlag: (flag) => `${flag} only applies with --tier heavy.`,
|
|
76
|
+
/** `--days` given with a Heavy payer other than the wallet (credits keep 28 days; evm lasts as long as the deposit). */
|
|
77
|
+
walletOnlyDays: "--days only applies with --tier heavy --pay wallet: credits keep a file 28 days, and --pay evm keeps it as long as the deposit lasts.",
|
|
78
|
+
/** `--days` out of 1..365. */
|
|
79
|
+
badDays: (raw) => `--days takes a whole number from 1 to 365, not "${raw}".`,
|
|
80
|
+
/** The wallet holds less WAL (or SUI for the fee) than the order's price — refused before anything is sealed. */
|
|
81
|
+
walletShort: (needWal, haveWal, needSui, haveSui) => `The wallet is short: this upload needs ${needWal} WAL and about ${needSui} SUI for the fee, and the wallet holds ${haveWal} WAL and ${haveSui} SUI. Nothing was stored or paid.`,
|
|
82
|
+
/** `--copies` out of 1..12, or `--providers` not a list of ids. */
|
|
83
|
+
badCopies: (raw) => `--copies takes a whole number from 1 to 12, not "${raw}".`,
|
|
84
|
+
badProviders: (raw) => `--providers takes storage provider ids separated by commas, such as 4,9 — not "${raw}".`,
|
|
85
|
+
/** A self-paid upload stored no copy at all (the SDK answered no copies). */
|
|
86
|
+
evmNoCopy: (detail) => `No storage provider kept the piece: ${detail}`,
|
|
87
|
+
/** `heavy wallet` output labels. */
|
|
88
|
+
walletAddress: "address",
|
|
89
|
+
walletFil: "FIL",
|
|
90
|
+
walletUsdfc: "USDFC",
|
|
91
|
+
walletDeposit: "deposit (available)",
|
|
92
|
+
walletRunway: "lasts to epoch",
|
|
93
|
+
/** `heavy fund`: the review before signing, the `--yes` refusal, and the done line. */
|
|
94
|
+
fundReview: (usdfc, address) => `Deposit ${usdfc} USDFC from ${address} into Filecoin Pay, for --pay evm uploads.`,
|
|
95
|
+
fundNeedsYes: "Nothing was signed. Depositing spends from the wallet: run it again with --yes.",
|
|
96
|
+
fundNothing: "The deposit already covers this amount. Nothing was signed.",
|
|
97
|
+
fundDone: (hash) => ` deposited — transaction ${hash}`,
|
|
98
|
+
fundBadAmount: (raw) => `heavy fund takes an amount of USDFC above zero, such as 5 or 2.5 — not "${raw}".`,
|
|
99
|
+
/** The SDK's `put(…, { tier })`: an option given on the tier or payer it means nothing to. */
|
|
100
|
+
sdkHeavyOnly: (option) => `\`${option}\` only applies with tier: "heavy".`,
|
|
101
|
+
sdkNotHeavy: (option) => `\`${option}\` does not apply to tier: "heavy".`,
|
|
102
|
+
sdkPayerOnly: (option, pay) => `\`${option}\` only applies with tier: "heavy" and pay: ${pay}.`,
|
|
103
|
+
/** The SDK: `pay: { signer }` on Heavy is an EVM account; on Standard it is a Sui wallet. */
|
|
104
|
+
sdkEvmSigner: `On tier: "heavy", pay: { signer } is an EVM account, such as viem's privateKeyToAccount().`,
|
|
105
|
+
sdkSuiSigner: `An EVM account pays only with tier: "heavy". On tier: "standard", pay: { signer } is a Sui wallet.`,
|
|
106
|
+
/** `heavy` with no or an unknown verb. */
|
|
107
|
+
heavyVerb: "Use `nmts heavy wallet` or `nmts heavy fund <USDFC>`.",
|
|
108
|
+
};
|