@needmoretruth/nmts-cli 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +61 -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 +8 -0
- package/dist/args.js +7 -1
- 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/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 +5 -0
- package/dist/commands/ls.js +9 -1
- 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.d.ts +2 -2
- package/dist/commands/put.js +8 -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/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 +4 -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 +12 -10
- package/dist/manifest-write.d.ts +4 -3
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +15 -0
- package/dist/portable.js +11 -0
- 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/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 +9 -4
- package/dist/upload-wallet-put.js +16 -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/handover.md +38 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/public-code.md +7 -0
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +15 -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,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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PrivateKeyAccount } from "viem/accounts";
|
|
2
|
+
/** An EVM wallet number as a person typed it. Refused, never rounded. */
|
|
3
|
+
export declare function evmIndexOf(raw: string | undefined): number;
|
|
4
|
+
/** The EIP-55 address of a 32-byte secp256k1 private key. */
|
|
5
|
+
export declare function evmAddressOf(privateKey: Uint8Array): `0x${string}`;
|
|
6
|
+
/**
|
|
7
|
+
* EVM wallet `index`'s private key, from an NMTS key.
|
|
8
|
+
*
|
|
9
|
+
* ⛔ THE CALLER WIPES WHAT COMES BACK — it moves money on Filecoin.
|
|
10
|
+
*/
|
|
11
|
+
export declare function evmKeyOf(code: string, index: number): Promise<Uint8Array>;
|
|
12
|
+
/** EVM wallet `index`'s address, from an NMTS key. Nothing is signed; the key is wiped here. */
|
|
13
|
+
export declare function evmAddressFor(code: string, index: number): Promise<`0x${string}`>;
|
|
14
|
+
/**
|
|
15
|
+
* EVM wallet `index` as a viem account that signs. The key bytes are wiped once the account holds
|
|
16
|
+
* them; the account itself keeps the key for as long as the caller keeps the account.
|
|
17
|
+
*/
|
|
18
|
+
export declare function evmAccountFor(code: string, index: number): Promise<PrivateKeyAccount>;
|
|
19
|
+
/** `0x…` for viem, from key bytes. ⚠ The string cannot be wiped; keep it only as long as the call. */
|
|
20
|
+
export declare function hexKey(key: Uint8Array): `0x${string}`;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// The EVM wallets an NMTS key derives (NCF-3 §1.9) — the key the engine hands out, and the address
|
|
2
|
+
// computed from it here.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ THE KEY COMES FROM THE ENGINE, NEVER FROM HERE. `evm_key_for` is the same WebAssembly the
|
|
5
|
+
// browser and the recovery tool run, so one NMTS key names one Filecoin address everywhere.
|
|
6
|
+
// Only the step from a private key to its address is written in TypeScript, because it is the
|
|
7
|
+
// textbook one (secp256k1 public key → Keccak-256 → last 20 bytes, EIP-55 case) and a test holds
|
|
8
|
+
// it to the frozen vectors in `crypto/tests/vectors/ncf3-evm.json`.
|
|
9
|
+
//
|
|
10
|
+
// ⛔ EVERY KEY IS WIPED BY WHOEVER ASKED FOR IT. The derivation output holds every key in the
|
|
11
|
+
// account; it and the wallet root sliced out of it are zeroed here on every path out.
|
|
12
|
+
//
|
|
13
|
+
// ⚠ NO `t410`/`f410` FORM. Neither viem nor the Synapse packages carry a helper for Filecoin's
|
|
14
|
+
// delegated address spelling, and it is not written by hand here — the 0x address is the one the
|
|
15
|
+
// Filecoin EVM, the Synapse SDK and every EVM wallet read.
|
|
16
|
+
import { secp256k1 } from "@noble/curves/secp256k1.js";
|
|
17
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
18
|
+
import { assertUsableCode } from "./account.js";
|
|
19
|
+
import { DERIVED, loadCrypto } from "./crypto.js";
|
|
20
|
+
import { NmtsError } from "./errors.js";
|
|
21
|
+
import { BINARY_NAME } from "./product.js";
|
|
22
|
+
/** The highest EVM wallet number accepted — the same range the Sui wallets use. */
|
|
23
|
+
const EVM_INDEX_LIMIT = 2 ** 31;
|
|
24
|
+
/** An EVM wallet number as a person typed it. Refused, never rounded. */
|
|
25
|
+
export function evmIndexOf(raw) {
|
|
26
|
+
if (raw === undefined || raw === "")
|
|
27
|
+
return 0;
|
|
28
|
+
const text = raw.trim();
|
|
29
|
+
const value = Number(text);
|
|
30
|
+
if (!/^[0-9]+$/u.test(text) || !Number.isSafeInteger(value) || value >= EVM_INDEX_LIMIT) {
|
|
31
|
+
throw new NmtsError(`An EVM wallet number is a whole number from 0 to ${EVM_INDEX_LIMIT - 1}, not "${raw}".`, {
|
|
32
|
+
exitCode: 2,
|
|
33
|
+
nextStep: `Nothing was signed. \`${BINARY_NAME} heavy wallet\` shows wallet 0.`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/** `0x` + 40 hex, in EIP-55 mixed case. */
|
|
39
|
+
function checksummed(addressHex) {
|
|
40
|
+
const lower = addressHex.toLowerCase();
|
|
41
|
+
const hash = keccak_256(new TextEncoder().encode(lower));
|
|
42
|
+
let out = "0x";
|
|
43
|
+
for (let i = 0; i < lower.length; i += 1) {
|
|
44
|
+
const char = lower.charAt(i);
|
|
45
|
+
const byte = hash[i >> 1] ?? 0;
|
|
46
|
+
const nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;
|
|
47
|
+
out = `${out}${nibble >= 8 ? char.toUpperCase() : char}`;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/** The EIP-55 address of a 32-byte secp256k1 private key. */
|
|
52
|
+
export function evmAddressOf(privateKey) {
|
|
53
|
+
const publicKey = secp256k1.getPublicKey(privateKey, false);
|
|
54
|
+
const digest = keccak_256(publicKey.subarray(1));
|
|
55
|
+
const hex = Array.from(digest.subarray(12), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
56
|
+
return checksummed(hex);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* EVM wallet `index`'s private key, from an NMTS key.
|
|
60
|
+
*
|
|
61
|
+
* ⛔ THE CALLER WIPES WHAT COMES BACK — it moves money on Filecoin.
|
|
62
|
+
*/
|
|
63
|
+
export async function evmKeyOf(code, index) {
|
|
64
|
+
await assertUsableCode(code);
|
|
65
|
+
const glue = await loadCrypto();
|
|
66
|
+
const bytes = glue.account_code_parse(code);
|
|
67
|
+
const derived = glue.kdf_derive(bytes);
|
|
68
|
+
const [from, to] = DERIVED.walletRoot;
|
|
69
|
+
const root = derived.slice(from, to);
|
|
70
|
+
try {
|
|
71
|
+
return glue.evm_key_for(root, index);
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
root.fill(0);
|
|
75
|
+
derived.fill(0);
|
|
76
|
+
bytes.fill(0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** EVM wallet `index`'s address, from an NMTS key. Nothing is signed; the key is wiped here. */
|
|
80
|
+
export async function evmAddressFor(code, index) {
|
|
81
|
+
const key = await evmKeyOf(code, index);
|
|
82
|
+
try {
|
|
83
|
+
return evmAddressOf(key);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
key.fill(0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* EVM wallet `index` as a viem account that signs. The key bytes are wiped once the account holds
|
|
91
|
+
* them; the account itself keeps the key for as long as the caller keeps the account.
|
|
92
|
+
*/
|
|
93
|
+
export async function evmAccountFor(code, index) {
|
|
94
|
+
const key = await evmKeyOf(code, index);
|
|
95
|
+
try {
|
|
96
|
+
const { privateKeyToAccount } = await import("viem/accounts");
|
|
97
|
+
return privateKeyToAccount(hexKey(key));
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
key.fill(0);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** `0x…` for viem, from key bytes. ⚠ The string cannot be wiped; keep it only as long as the call. */
|
|
104
|
+
export function hexKey(key) {
|
|
105
|
+
return `0x${Array.from(key, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
106
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Account } from "viem";
|
|
2
|
+
import type { CryptoGlue } from "./crypto.ts";
|
|
3
|
+
import { commitHeavyItem } from "./heavy-api.ts";
|
|
4
|
+
import { type HeavyCommitted, type HeavyFile } from "./heavy-upload.ts";
|
|
5
|
+
import type { Network } from "./network.ts";
|
|
6
|
+
import type { PaddingRule } from "./shared/lib/crypto/size-padding.ts";
|
|
7
|
+
import { type FilecoinChain } from "./shared/lib/filecoin/providers.ts";
|
|
8
|
+
/** Copies one self-paid part may ask for, and the default. */
|
|
9
|
+
export declare const SELF_PAY_MAX_COPIES = 12;
|
|
10
|
+
export declare const SELF_PAY_DEFAULT_COPIES = 2;
|
|
11
|
+
/** `--copies` as typed. Absent = 2. Refused, never clamped. */
|
|
12
|
+
export declare function copiesOf(raw: string | number | undefined): number;
|
|
13
|
+
/** `--providers 4,9` as registry ids. Absent = the SDK chooses. */
|
|
14
|
+
export declare function providersOf(raw: string | readonly (number | bigint)[] | undefined): bigint[] | undefined;
|
|
15
|
+
/** Which Filecoin chain this NMTS network pays on — refused where no company is listed. */
|
|
16
|
+
export declare function selfPayChain(network: Network): FilecoinChain;
|
|
17
|
+
/** The Synapse client for one account on one chain. `account` may be a bare address for reads. */
|
|
18
|
+
export declare function synapseFor(account: Account | `0x${string}`, chain: FilecoinChain): Promise<import("@filoz/synapse-sdk").Synapse>;
|
|
19
|
+
/** The phases a caller can show, per part. */
|
|
20
|
+
export type SelfPayProgress = {
|
|
21
|
+
phase: "sealing" | "uploading" | "stored";
|
|
22
|
+
fileIndex: number;
|
|
23
|
+
partIndex: number;
|
|
24
|
+
parts: number;
|
|
25
|
+
} | {
|
|
26
|
+
phase: "sent";
|
|
27
|
+
fileIndex: number;
|
|
28
|
+
partIndex: number;
|
|
29
|
+
parts: number;
|
|
30
|
+
sentBytes: number;
|
|
31
|
+
totalBytes: number;
|
|
32
|
+
};
|
|
33
|
+
export interface SelfPayContext {
|
|
34
|
+
server: string;
|
|
35
|
+
bearer: string;
|
|
36
|
+
crypt: CryptoGlue;
|
|
37
|
+
/** Borrowed — the caller wipes it. */
|
|
38
|
+
dataKey: Uint8Array;
|
|
39
|
+
rule: PaddingRule;
|
|
40
|
+
network: Network;
|
|
41
|
+
/** The EVM account that pays and signs: this key's own (`evm_key_for`), or a business's. */
|
|
42
|
+
account: Account;
|
|
43
|
+
copies: number;
|
|
44
|
+
providers?: readonly bigint[] | undefined;
|
|
45
|
+
signal?: AbortSignal | undefined;
|
|
46
|
+
onProgress?: ((event: SelfPayProgress) => void) | undefined;
|
|
47
|
+
/** ⚠ Seams, not options: the storage client and the commit, for tests. */
|
|
48
|
+
synapse?: SelfPaySynapse | undefined;
|
|
49
|
+
commit?: typeof commitHeavyItem | undefined;
|
|
50
|
+
}
|
|
51
|
+
/** The two things this path asks of the Synapse SDK. */
|
|
52
|
+
export interface SelfPaySynapse {
|
|
53
|
+
upload(bytes: Uint8Array, options: {
|
|
54
|
+
copies: number;
|
|
55
|
+
providerIds?: bigint[];
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
onProgress?: (sent: number) => void;
|
|
58
|
+
}): Promise<{
|
|
59
|
+
pieceCid: string;
|
|
60
|
+
copies: {
|
|
61
|
+
providerId: bigint;
|
|
62
|
+
dataSetId: bigint;
|
|
63
|
+
pieceId: bigint;
|
|
64
|
+
retrievalUrl: string;
|
|
65
|
+
}[];
|
|
66
|
+
}>;
|
|
67
|
+
/** The Filecoin epoch now, and how many more the deposit lasts at its current rate. */
|
|
68
|
+
runway(): Promise<{
|
|
69
|
+
epoch: bigint;
|
|
70
|
+
runwayInEpochs: bigint;
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/** The real one: the Synapse SDK, over this account on this chain. */
|
|
74
|
+
export declare function synapseSelfPay(account: Account, chain: FilecoinChain): Promise<SelfPaySynapse>;
|
|
75
|
+
/**
|
|
76
|
+
* The epoch the deposit reaches at the rate the account pays after this upload.
|
|
77
|
+
*
|
|
78
|
+
* ⚠ A RATE OF ZERO HAS NO END (the SDK answers the largest uint256). That only happens when no
|
|
79
|
+
* piece is being paid for, which after a successful upload it is; the 30-day lockup is written
|
|
80
|
+
* then, because it is what the storage company is owed whatever the deposit does.
|
|
81
|
+
*/
|
|
82
|
+
export declare function expiryFrom(runway: {
|
|
83
|
+
epoch: bigint;
|
|
84
|
+
runwayInEpochs: bigint;
|
|
85
|
+
}): number;
|
|
86
|
+
/** Upload these files from the key's own EVM wallet and commit each one. The caller writes the list. */
|
|
87
|
+
export declare function heavySelfPut(ctx: SelfPayContext, files: readonly HeavyFile[]): Promise<{
|
|
88
|
+
files: HeavyCommitted[];
|
|
89
|
+
expiryEpoch: number;
|
|
90
|
+
paidBy: string;
|
|
91
|
+
copies: number[];
|
|
92
|
+
}>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// NMTS Heavy paid by the key's OWN EVM wallet — developer mode. Anything a developer could do with
|
|
2
|
+
// the Synapse SDK directly (how many copies, which storage companies, their own deposit) is done
|
|
3
|
+
// here through it, and the result is filed in the account like any other file.
|
|
4
|
+
//
|
|
5
|
+
// ⛔ NO ORDER AND NO TREASURY. The wallet's own Filecoin Pay deposit pays the storage companies;
|
|
6
|
+
// the server only records where the copies are (`paid_by` = the 0x address, `owner_kind` 0) and
|
|
7
|
+
// checks nothing about the payment, as it does for a Walrus wallet upload.
|
|
8
|
+
//
|
|
9
|
+
// ⛔ REFUSED BEFORE ANYTHING IS SPENT ON A CHAIN WITH NO LISTED COMPANY. Today that is mainnet:
|
|
10
|
+
// `shared/lib/filecoin/providers.ts` has no mainnet rows, so self-paid Heavy is Calibration only.
|
|
11
|
+
//
|
|
12
|
+
// ⛔ THE SDK IS LOADED ONLY WHEN THIS RUNS (it pulls in viem, seconds in Node), never at start-up.
|
|
13
|
+
//
|
|
14
|
+
// ⚠ ITS REQUESTS DO NOT GO THROUGH `reachFetch`. The Synapse SDK makes its own RPC and storage
|
|
15
|
+
// company calls; a proxy set on this package is not applied to them.
|
|
16
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
17
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
18
|
+
import { NmtsError } from "./errors.js";
|
|
19
|
+
import { commitHeavyItem } from "./heavy-api.js";
|
|
20
|
+
import { HEAVY_COPY } from "./heavy-copy.js";
|
|
21
|
+
import { prepareHeavyFiles, sealHeavyPart, wipe } from "./heavy-upload.js";
|
|
22
|
+
import { FILECOIN_CHAIN_FOR_NETWORK, FILECOIN_PROVIDERS } from "./shared/lib/filecoin/providers.js";
|
|
23
|
+
/** Copies one self-paid part may ask for, and the default. */
|
|
24
|
+
export const SELF_PAY_MAX_COPIES = 12;
|
|
25
|
+
export const SELF_PAY_DEFAULT_COPIES = 2;
|
|
26
|
+
/** `--copies` as typed. Absent = 2. Refused, never clamped. */
|
|
27
|
+
export function copiesOf(raw) {
|
|
28
|
+
if (raw === undefined || raw === "")
|
|
29
|
+
return SELF_PAY_DEFAULT_COPIES;
|
|
30
|
+
const value = typeof raw === "number" ? raw : Number(raw.trim());
|
|
31
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > SELF_PAY_MAX_COPIES) {
|
|
32
|
+
throw new NmtsError(HEAVY_COPY.badCopies(String(raw)), { exitCode: 2 });
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
/** `--providers 4,9` as registry ids. Absent = the SDK chooses. */
|
|
37
|
+
export function providersOf(raw) {
|
|
38
|
+
if (raw === undefined || raw === "")
|
|
39
|
+
return undefined;
|
|
40
|
+
const parts = typeof raw === "string" ? raw.split(",").map((p) => p.trim()) : raw.map(String);
|
|
41
|
+
if (parts.length === 0 || parts.some((p) => !/^[0-9]+$/u.test(p))) {
|
|
42
|
+
throw new NmtsError(HEAVY_COPY.badProviders(String(raw)), { exitCode: 2 });
|
|
43
|
+
}
|
|
44
|
+
return parts.map((p) => BigInt(p));
|
|
45
|
+
}
|
|
46
|
+
/** Which Filecoin chain this NMTS network pays on — refused where no company is listed. */
|
|
47
|
+
export function selfPayChain(network) {
|
|
48
|
+
const chain = FILECOIN_CHAIN_FOR_NETWORK[network];
|
|
49
|
+
if (FILECOIN_PROVIDERS[chain].length === 0) {
|
|
50
|
+
throw new NmtsError(HEAVY_COPY.evmNoProviders(chain), { exitCode: 4 });
|
|
51
|
+
}
|
|
52
|
+
return chain;
|
|
53
|
+
}
|
|
54
|
+
/** The Synapse client for one account on one chain. `account` may be a bare address for reads. */
|
|
55
|
+
export async function synapseFor(account, chain) {
|
|
56
|
+
const sdk = await import("@filoz/synapse-sdk");
|
|
57
|
+
return sdk.Synapse.create({ account, source: "nmts", chain: chain === "mainnet" ? sdk.mainnet : sdk.calibration });
|
|
58
|
+
}
|
|
59
|
+
/** The real one: the Synapse SDK, over this account on this chain. */
|
|
60
|
+
export async function synapseSelfPay(account, chain) {
|
|
61
|
+
const synapse = await synapseFor(account, chain);
|
|
62
|
+
return {
|
|
63
|
+
async upload(bytes, options) {
|
|
64
|
+
const result = await synapse.storage.upload(bytes, {
|
|
65
|
+
copies: options.copies,
|
|
66
|
+
...(options.providerIds === undefined ? {} : { providerIds: options.providerIds }),
|
|
67
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
68
|
+
...(options.onProgress === undefined ? {} : { callbacks: { onProgress: options.onProgress } }),
|
|
69
|
+
});
|
|
70
|
+
return { pieceCid: result.pieceCid.toString(), copies: result.copies };
|
|
71
|
+
},
|
|
72
|
+
async runway() {
|
|
73
|
+
const summary = await synapse.payments.accountSummary();
|
|
74
|
+
return { epoch: summary.epoch, runwayInEpochs: summary.runwayInEpochs };
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** Filecoin epochs in 30 days — the lockup a storage company is always owed. */
|
|
79
|
+
const EPOCHS_PER_MONTH = 86400n;
|
|
80
|
+
/**
|
|
81
|
+
* The epoch the deposit reaches at the rate the account pays after this upload.
|
|
82
|
+
*
|
|
83
|
+
* ⚠ A RATE OF ZERO HAS NO END (the SDK answers the largest uint256). That only happens when no
|
|
84
|
+
* piece is being paid for, which after a successful upload it is; the 30-day lockup is written
|
|
85
|
+
* then, because it is what the storage company is owed whatever the deposit does.
|
|
86
|
+
*/
|
|
87
|
+
export function expiryFrom(runway) {
|
|
88
|
+
const end = runway.runwayInEpochs > 2n ** 40n ? runway.epoch + EPOCHS_PER_MONTH : runway.epoch + runway.runwayInEpochs;
|
|
89
|
+
return Number(end);
|
|
90
|
+
}
|
|
91
|
+
/** Upload these files from the key's own EVM wallet and commit each one. The caller writes the list. */
|
|
92
|
+
export async function heavySelfPut(ctx, files) {
|
|
93
|
+
const chain = selfPayChain(ctx.network);
|
|
94
|
+
const synapse = ctx.synapse ?? (await synapseSelfPay(ctx.account, chain));
|
|
95
|
+
const prepared = await prepareHeavyFiles(ctx.crypt, ctx.dataKey, ctx.rule, files);
|
|
96
|
+
try {
|
|
97
|
+
const partsPerFile = [];
|
|
98
|
+
const copyCounts = [];
|
|
99
|
+
for (const [fileIndex, one] of prepared.entries()) {
|
|
100
|
+
const parts = [];
|
|
101
|
+
for (const part of one.plan) {
|
|
102
|
+
const at = { fileIndex, partIndex: part.partIndex, parts: one.plan.length };
|
|
103
|
+
ctx.onProgress?.({ phase: "sealing", ...at });
|
|
104
|
+
const bytes = await sealHeavyPart(ctx.crypt, one, part);
|
|
105
|
+
ctx.onProgress?.({ phase: "uploading", ...at });
|
|
106
|
+
const stored = await synapse.upload(bytes, {
|
|
107
|
+
copies: ctx.copies,
|
|
108
|
+
...(ctx.providers === undefined ? {} : { providerIds: [...ctx.providers] }),
|
|
109
|
+
...(ctx.signal === undefined ? {} : { signal: ctx.signal }),
|
|
110
|
+
onProgress: (sent) => ctx.onProgress?.({ phase: "sent", ...at, sentBytes: sent, totalBytes: bytes.byteLength }),
|
|
111
|
+
});
|
|
112
|
+
if (stored.copies.length === 0)
|
|
113
|
+
throw new NmtsError(HEAVY_COPY.evmNoCopy(stored.pieceCid), { exitCode: 1 });
|
|
114
|
+
copyCounts.push(stored.copies.length);
|
|
115
|
+
parts.push({
|
|
116
|
+
part_index: part.partIndex,
|
|
117
|
+
storage_kind: 0,
|
|
118
|
+
network: 1,
|
|
119
|
+
blob_id: stored.pieceCid,
|
|
120
|
+
sealed_len: part.sealedLen,
|
|
121
|
+
owner_kind: 0,
|
|
122
|
+
expiry_epoch: 0,
|
|
123
|
+
copies: stored.copies.map((c) => ({
|
|
124
|
+
provider_id: c.providerId.toString(),
|
|
125
|
+
data_set_id: c.dataSetId.toString(),
|
|
126
|
+
piece_id: c.pieceId.toString(),
|
|
127
|
+
retrieval_url: c.retrievalUrl,
|
|
128
|
+
})),
|
|
129
|
+
});
|
|
130
|
+
ctx.onProgress?.({ phase: "stored", ...at });
|
|
131
|
+
}
|
|
132
|
+
partsPerFile.push(parts);
|
|
133
|
+
}
|
|
134
|
+
// ⛔ READ AFTER EVERY PART IS IN: the new pieces raise the rate, and the rate sets the end.
|
|
135
|
+
const expiryEpoch = expiryFrom(await synapse.runway());
|
|
136
|
+
const commit = ctx.commit ?? commitHeavyItem;
|
|
137
|
+
const committed = [];
|
|
138
|
+
for (const [index, one] of prepared.entries()) {
|
|
139
|
+
const parts = (partsPerFile[index] ?? []).map((p) => ({ ...p, expiry_epoch: expiryEpoch }));
|
|
140
|
+
const itemId = await commit({
|
|
141
|
+
server: ctx.server,
|
|
142
|
+
bearer: ctx.bearer,
|
|
143
|
+
// The pieces name the file: the same pieces committed again are the same file.
|
|
144
|
+
idempotencyKey: `nmts-heavy-self-${bytesToHex(sha256(new TextEncoder().encode(parts.map((p) => p.blob_id).join(",")))).slice(0, 40)}`,
|
|
145
|
+
dekWrapped: one.secrets.dekWrapped,
|
|
146
|
+
contentHashCt: one.secrets.contentHashCt,
|
|
147
|
+
parts,
|
|
148
|
+
paidBy: ctx.account.address,
|
|
149
|
+
});
|
|
150
|
+
committed.push({
|
|
151
|
+
itemId,
|
|
152
|
+
name: one.file.name,
|
|
153
|
+
parentId: one.file.parentId,
|
|
154
|
+
destination: one.file.destination,
|
|
155
|
+
plaintextLen: one.file.source.size,
|
|
156
|
+
dekWrapped: one.secrets.dekWrapped,
|
|
157
|
+
contentHashCt: one.secrets.contentHashCt,
|
|
158
|
+
sealedBytes: one.plan.reduce((sum, p) => sum + p.sealedLen, 0),
|
|
159
|
+
parts: one.plan.length,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return { files: committed, expiryEpoch, paidBy: ctx.account.address, copies: copyCounts };
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
wipe(prepared);
|
|
166
|
+
}
|
|
167
|
+
}
|