@needmoretruth/nmts-cli 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +73 -0
- package/README.ko.md +6 -3
- package/README.md +15 -3
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +14 -0
- package/dist/args.js +11 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/get.d.ts +2 -0
- package/dist/commands/get.js +13 -1
- package/dist/commands/handover.d.ts +13 -0
- package/dist/commands/handover.js +328 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/ls.d.ts +7 -0
- package/dist/commands/ls.js +27 -6
- package/dist/commands/public-code.d.ts +6 -0
- package/dist/commands/public-code.js +46 -0
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put-thumbnail.d.ts +4 -0
- package/dist/commands/put-thumbnail.js +119 -0
- package/dist/commands/put-wallet.d.ts +2 -0
- package/dist/commands/put-wallet.js +3 -2
- package/dist/commands/put.d.ts +10 -2
- package/dist/commands/put.js +13 -7
- package/dist/commands/receive.js +3 -3
- package/dist/commands/s3.js +44 -10
- package/dist/crypto-surface.d.ts +8 -0
- package/dist/crypto-surface.js +3 -0
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.js +3 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/drive-edit/trash.js +5 -3
- package/dist/drive-edit/tree.d.ts +6 -0
- package/dist/drive-edit/tree.js +10 -0
- package/dist/drive-erase.js +2 -2
- package/dist/drive-paths.d.ts +2 -2
- package/dist/drive-paths.js +2 -2
- package/dist/handover.d.ts +44 -0
- package/dist/handover.js +199 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +8 -2
- package/dist/help.js +16 -3
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +14 -9
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/files.js +21 -2
- package/dist/mcp-tools/reads.js +9 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +17 -1
- package/dist/portable.js +13 -1
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +30 -0
- package/dist/risk.js +23 -2
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share.d.ts +5 -0
- package/dist/share.js +1 -1
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
- package/dist/shared/lib/drive/manifest-codec.js +15 -23
- package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
- package/dist/shared/lib/drive/manifest-index.js +30 -8
- package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
- package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
- package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
- package/dist/shared/lib/drive/preview-classify.js +96 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +11 -4
- package/dist/upload-wallet-put.js +17 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/get.md +3 -0
- package/docs/commands/handover.md +38 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/ls.md +5 -0
- package/docs/commands/public-code.md +7 -0
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +23 -1
- package/docs/commands/share.md +3 -1
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { HeavyPay, HeavyPrice, HeavySlotRequest } from "../api/types-heavy.ts";
|
|
2
|
+
/**
|
|
3
|
+
* How much plaintext one Heavy part carries at most: 512 MiB.
|
|
4
|
+
*
|
|
5
|
+
* WHY THIS NUMBER. A storage company takes at most 1,065,353,216 bytes in one piece. A 512 MiB part
|
|
6
|
+
* seals to 512 MiB plus about 2 KiB (a 72-byte header and a 16-byte tag per 4 MiB chunk), and size
|
|
7
|
+
* padding never grows a part past its own power of two, so a full part stays near half the limit
|
|
8
|
+
* whatever padding is chosen. It is also what a browser tab can hold comfortably while it hashes the
|
|
9
|
+
* part and sends it.
|
|
10
|
+
*/
|
|
11
|
+
export declare const HEAVY_PART_SIZE_BYTES: number;
|
|
12
|
+
/** A sealed part may be no smaller than this (a Filecoin piece's minimum)… */
|
|
13
|
+
export declare const HEAVY_PIECE_MIN_BYTES = 127;
|
|
14
|
+
/** …and no larger than this (the storage companies' limit per piece). */
|
|
15
|
+
export declare const HEAVY_PIECE_MAX_BYTES = 1065353216;
|
|
16
|
+
/**
|
|
17
|
+
* The least plaintext that seals to a legal piece: 127 − the 72-byte header − one 16-byte tag. A
|
|
18
|
+
* part shorter than this is padded (the same size padding the format already has) before sealing.
|
|
19
|
+
*/
|
|
20
|
+
export declare const HEAVY_MIN_SEAL_FROM_BYTES: number;
|
|
21
|
+
/** Slots one order may hold. */
|
|
22
|
+
export declare const HEAVY_MAX_SLOTS = 256;
|
|
23
|
+
/** One part of one file, before sealing. */
|
|
24
|
+
export interface HeavyRunPart {
|
|
25
|
+
/** Its position in its file (0-based). */
|
|
26
|
+
partIndex: number;
|
|
27
|
+
/** The exact size it will seal to — the order is opened with this before anything is sealed. */
|
|
28
|
+
sealedLen: number;
|
|
29
|
+
}
|
|
30
|
+
/** One file of the upload. */
|
|
31
|
+
export interface HeavyRunFile {
|
|
32
|
+
/** The caller's own name for the file; it comes back on the result unchanged. */
|
|
33
|
+
key: string;
|
|
34
|
+
parts: readonly HeavyRunPart[];
|
|
35
|
+
}
|
|
36
|
+
/** How the upload is paid. */
|
|
37
|
+
export type HeavyPayment = {
|
|
38
|
+
pay: "credits";
|
|
39
|
+
} | {
|
|
40
|
+
pay: "wallet";
|
|
41
|
+
/** `0x` + 64 hex — the Sui address that will send the WAL. */
|
|
42
|
+
payer: string;
|
|
43
|
+
/** 1..=365 days. */
|
|
44
|
+
termDays: number;
|
|
45
|
+
/** Send `price.wal_frost` FROST to `price.treasury`; resolve with the Sui transaction digest. */
|
|
46
|
+
payWallet: (price: HeavyPrice, orderId: string) => Promise<string>;
|
|
47
|
+
};
|
|
48
|
+
/** One slot of the order: which part of which file it carries. */
|
|
49
|
+
export interface SlotPlan {
|
|
50
|
+
slot: number;
|
|
51
|
+
fileIndex: number;
|
|
52
|
+
fileKey: string;
|
|
53
|
+
partIndex: number;
|
|
54
|
+
sealedLen: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Number the slots across the files (file by file, part by part), and refuse any part an order
|
|
58
|
+
* could never take — before anything is opened, sealed or charged.
|
|
59
|
+
*/
|
|
60
|
+
export declare function planSlots(files: readonly HeavyRunFile[]): SlotPlan[];
|
|
61
|
+
/** The `POST /v1/heavy/orders` body for an upload — exactly what `runHeavyOrder` sends. */
|
|
62
|
+
export interface HeavyOrderRequestBody {
|
|
63
|
+
idempotency_key: string;
|
|
64
|
+
slots: HeavySlotRequest[];
|
|
65
|
+
pay: HeavyPay;
|
|
66
|
+
term_days?: number;
|
|
67
|
+
payer?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build the order request for an upload.
|
|
71
|
+
*
|
|
72
|
+
* Exposed so a screen can open the order early — a wallet order's answer carries the price to show
|
|
73
|
+
* — and then run the upload under the SAME idempotency key, which reaches the same order again.
|
|
74
|
+
* ⚠ A different body under the same key is refused (`idempotency_conflict`): if the person changes
|
|
75
|
+
* the term, make a new key.
|
|
76
|
+
*/
|
|
77
|
+
export declare function heavyOrderRequest(files: readonly HeavyRunFile[], payment: HeavyPayment, idempotencyKey: string): HeavyOrderRequestBody;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// The sizes an NMTS Heavy part may have, and how an upload's parts become one order's slots.
|
|
2
|
+
//
|
|
3
|
+
// ⚠ THIS FILE IS PUBLISHED. It is copied byte-for-byte into the `nmts` command-line package.
|
|
4
|
+
// Keep the comments self-contained English, with no pointer only we can follow.
|
|
5
|
+
import { HeavyOrderError } from "./order-wire.js";
|
|
6
|
+
/**
|
|
7
|
+
* How much plaintext one Heavy part carries at most: 512 MiB.
|
|
8
|
+
*
|
|
9
|
+
* WHY THIS NUMBER. A storage company takes at most 1,065,353,216 bytes in one piece. A 512 MiB part
|
|
10
|
+
* seals to 512 MiB plus about 2 KiB (a 72-byte header and a 16-byte tag per 4 MiB chunk), and size
|
|
11
|
+
* padding never grows a part past its own power of two, so a full part stays near half the limit
|
|
12
|
+
* whatever padding is chosen. It is also what a browser tab can hold comfortably while it hashes the
|
|
13
|
+
* part and sends it.
|
|
14
|
+
*/
|
|
15
|
+
export const HEAVY_PART_SIZE_BYTES = 512 * 1024 * 1024;
|
|
16
|
+
/** A sealed part may be no smaller than this (a Filecoin piece's minimum)… */
|
|
17
|
+
export const HEAVY_PIECE_MIN_BYTES = 127;
|
|
18
|
+
/** …and no larger than this (the storage companies' limit per piece). */
|
|
19
|
+
export const HEAVY_PIECE_MAX_BYTES = 1_065_353_216;
|
|
20
|
+
/**
|
|
21
|
+
* The least plaintext that seals to a legal piece: 127 − the 72-byte header − one 16-byte tag. A
|
|
22
|
+
* part shorter than this is padded (the same size padding the format already has) before sealing.
|
|
23
|
+
*/
|
|
24
|
+
export const HEAVY_MIN_SEAL_FROM_BYTES = HEAVY_PIECE_MIN_BYTES - 72 - 16;
|
|
25
|
+
/** Slots one order may hold. */
|
|
26
|
+
export const HEAVY_MAX_SLOTS = 256;
|
|
27
|
+
/**
|
|
28
|
+
* Number the slots across the files (file by file, part by part), and refuse any part an order
|
|
29
|
+
* could never take — before anything is opened, sealed or charged.
|
|
30
|
+
*/
|
|
31
|
+
export function planSlots(files) {
|
|
32
|
+
const plans = [];
|
|
33
|
+
files.forEach((file, fileIndex) => {
|
|
34
|
+
const parts = [...file.parts].sort((a, b) => a.partIndex - b.partIndex);
|
|
35
|
+
if (parts.length === 0) {
|
|
36
|
+
throw new HeavyOrderError("slot_count", `File "${file.key}" has no parts.`);
|
|
37
|
+
}
|
|
38
|
+
parts.forEach((part, position) => {
|
|
39
|
+
if (part.partIndex !== position) {
|
|
40
|
+
throw new HeavyOrderError("slot_count", `File "${file.key}" has no part ${position}; its parts must be numbered 0..n-1.`);
|
|
41
|
+
}
|
|
42
|
+
if (!Number.isSafeInteger(part.sealedLen) || part.sealedLen < HEAVY_PIECE_MIN_BYTES) {
|
|
43
|
+
throw new HeavyOrderError("piece_too_small", `Part ${part.partIndex} of "${file.key}" seals to ${part.sealedLen} bytes; a piece needs ` +
|
|
44
|
+
`${HEAVY_PIECE_MIN_BYTES}. Pad it to at least ${HEAVY_MIN_SEAL_FROM_BYTES} bytes of plaintext.`);
|
|
45
|
+
}
|
|
46
|
+
if (part.sealedLen > HEAVY_PIECE_MAX_BYTES) {
|
|
47
|
+
throw new HeavyOrderError("piece_too_large", `Part ${part.partIndex} of "${file.key}" seals to ${part.sealedLen} bytes; a piece holds ` +
|
|
48
|
+
`at most ${HEAVY_PIECE_MAX_BYTES}.`);
|
|
49
|
+
}
|
|
50
|
+
plans.push({
|
|
51
|
+
slot: plans.length,
|
|
52
|
+
fileIndex,
|
|
53
|
+
fileKey: file.key,
|
|
54
|
+
partIndex: part.partIndex,
|
|
55
|
+
sealedLen: part.sealedLen,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
if (plans.length === 0 || plans.length > HEAVY_MAX_SLOTS) {
|
|
60
|
+
throw new HeavyOrderError("slot_count", `An order holds 1..${HEAVY_MAX_SLOTS} parts; this upload has ${plans.length}.`);
|
|
61
|
+
}
|
|
62
|
+
return plans;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build the order request for an upload.
|
|
66
|
+
*
|
|
67
|
+
* Exposed so a screen can open the order early — a wallet order's answer carries the price to show
|
|
68
|
+
* — and then run the upload under the SAME idempotency key, which reaches the same order again.
|
|
69
|
+
* ⚠ A different body under the same key is refused (`idempotency_conflict`): if the person changes
|
|
70
|
+
* the term, make a new key.
|
|
71
|
+
*/
|
|
72
|
+
export function heavyOrderRequest(files, payment, idempotencyKey) {
|
|
73
|
+
const slots = planSlots(files).map((p) => ({ slot: p.slot, sealed_len: p.sealedLen }));
|
|
74
|
+
return payment.pay === "credits"
|
|
75
|
+
? { idempotency_key: idempotencyKey, slots, pay: "credits" }
|
|
76
|
+
: {
|
|
77
|
+
idempotency_key: idempotencyKey,
|
|
78
|
+
slots,
|
|
79
|
+
pay: "wallet",
|
|
80
|
+
term_days: payment.termDays,
|
|
81
|
+
payer: payment.payer,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HeavyRunDeps, HeavyRunOptions, HeavyRunResult } from "./order-types.ts";
|
|
2
|
+
export { HEAVY_MAX_SLOTS, HEAVY_MIN_SEAL_FROM_BYTES, HEAVY_PART_SIZE_BYTES, HEAVY_PIECE_MAX_BYTES, HEAVY_PIECE_MIN_BYTES, heavyOrderRequest, type HeavyOrderRequestBody, type HeavyPayment, type HeavyRunFile, type HeavyRunPart, } from "./order-plan.ts";
|
|
3
|
+
export { HeavyOrderError, type HeavyFailure } from "./order-wire.ts";
|
|
4
|
+
export type { HeavyProgress, HeavyRunDeps, HeavyRunOptions, HeavyRunResult, HeavySealJob, SealedBytes, } from "./order-types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Run one Heavy upload to the end. Resolves with the parts to commit; rejects with a
|
|
7
|
+
* `HeavyOrderError`, or with an AbortError when `options.signal` aborts.
|
|
8
|
+
*/
|
|
9
|
+
export declare function runHeavyOrder(options: HeavyRunOptions, deps: HeavyRunDeps): Promise<HeavyRunResult>;
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// Drive one NMTS Heavy upload from start to finish: open the order, place and upload every sealed
|
|
2
|
+
// part, wait until each is stored, pay if the wallet pays, and hand back the parts to commit.
|
|
3
|
+
//
|
|
4
|
+
// ⚠ THIS FILE IS PUBLISHED. It is copied byte-for-byte into the `nmts` command-line package.
|
|
5
|
+
// Keep the comments self-contained English, with no pointer only we can follow.
|
|
6
|
+
//
|
|
7
|
+
// EVERY EDGE IS INJECTED — the order routes, the sealer, the PieceCID, the upload, the clock and the
|
|
8
|
+
// wait. The browser and the command line plug in their own; a test plugs in fakes. Nothing in here
|
|
9
|
+
// touches the network or a key on its own.
|
|
10
|
+
//
|
|
11
|
+
// THE ORDER OF THINGS (one upload = one order, however many files):
|
|
12
|
+
// 1. open `createOrder` with one slot per sealed part, numbered across the files in order.
|
|
13
|
+
// Retried under the SAME idempotency key when the answer is lost, so it is charged once.
|
|
14
|
+
// 2. per slot, a few at a time (default 2):
|
|
15
|
+
// seal → check the sealed size is the one the order was opened with → PieceCID →
|
|
16
|
+
// `targetSlot` (where to upload) → upload to that company → `slotUploaded` →
|
|
17
|
+
// read the order until the slot is `stored` (bounded, with backoff) or `failed`.
|
|
18
|
+
// 3. pay wallet orders only, after EVERY slot is stored: the injected `payWallet` sends the WAL
|
|
19
|
+
// and returns the Sui transaction digest, which is reported with `markPaid`.
|
|
20
|
+
// 4. return per file, the parts to commit (`network` 1, `blob_id` = PieceCID, the order and slot,
|
|
21
|
+
// the copies, and the Filecoin epoch they are kept until).
|
|
22
|
+
//
|
|
23
|
+
// ⛔ A FAILURE STOPS EVERYTHING AND SAYS WHY IN A WORD (`HeavyOrderError.reason`). Nothing is cleaned
|
|
24
|
+
// up from here: the server removes whatever an order stored if no file is committed from it within
|
|
25
|
+
// a day, and gives back the credits for slots that were never stored.
|
|
26
|
+
import { heavyRefusalOf } from "../api/types-heavy.js";
|
|
27
|
+
import { heavyOrderRequest, planSlots } from "./order-plan.js";
|
|
28
|
+
import { abortError, codeOf, defaultSleep, HeavyOrderError, isAbort, isHttpsUrl, isTransient, readCopies, } from "./order-wire.js";
|
|
29
|
+
export { HEAVY_MAX_SLOTS, HEAVY_MIN_SEAL_FROM_BYTES, HEAVY_PART_SIZE_BYTES, HEAVY_PIECE_MAX_BYTES, HEAVY_PIECE_MIN_BYTES, heavyOrderRequest, } from "./order-plan.js";
|
|
30
|
+
export { HeavyOrderError } from "./order-wire.js";
|
|
31
|
+
function sizeOf(bytes) {
|
|
32
|
+
return bytes instanceof Uint8Array ? bytes.byteLength : bytes.size;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Run one Heavy upload to the end. Resolves with the parts to commit; rejects with a
|
|
36
|
+
* `HeavyOrderError`, or with an AbortError when `options.signal` aborts.
|
|
37
|
+
*/
|
|
38
|
+
export async function runHeavyOrder(options, deps) {
|
|
39
|
+
const plans = planSlots(options.files);
|
|
40
|
+
const { api } = deps;
|
|
41
|
+
const sleep = deps.sleep ?? defaultSleep;
|
|
42
|
+
const now = deps.now ?? (() => Date.now());
|
|
43
|
+
const concurrency = Math.max(1, options.concurrency ?? 2);
|
|
44
|
+
const pollStart = options.pollIntervalMs ?? 3_000;
|
|
45
|
+
const pollMax = options.pollMaxIntervalMs ?? 30_000;
|
|
46
|
+
const storeTimeout = options.storeTimeoutMs ?? 60 * 60 * 1000;
|
|
47
|
+
const uploadAttempts = Math.max(1, options.uploadAttempts ?? 3);
|
|
48
|
+
const idempotencyKey = options.idempotencyKey ?? deps.newIdempotencyKey?.() ?? globalThis.crypto.randomUUID();
|
|
49
|
+
const emit = (event) => options.onProgress?.(event);
|
|
50
|
+
// One controller for the run: the caller's abort, or the first slot that fails, stops the rest.
|
|
51
|
+
if (options.signal?.aborted)
|
|
52
|
+
throw abortError();
|
|
53
|
+
const run = new AbortController();
|
|
54
|
+
const onOuterAbort = () => run.abort();
|
|
55
|
+
options.signal?.addEventListener("abort", onOuterAbort, { once: true });
|
|
56
|
+
const signal = run.signal;
|
|
57
|
+
let orderId = null;
|
|
58
|
+
/** One api call, made again after 1, 2, 4… s when it failed for a reason unrelated to the request. */
|
|
59
|
+
async function call(what, fn, slot) {
|
|
60
|
+
const attempts = 5;
|
|
61
|
+
for (let attempt = 1;; attempt += 1) {
|
|
62
|
+
if (signal.aborted)
|
|
63
|
+
throw abortError();
|
|
64
|
+
try {
|
|
65
|
+
return await fn();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
if (isAbort(err))
|
|
69
|
+
throw err;
|
|
70
|
+
const code = codeOf(err);
|
|
71
|
+
if (!isTransient(err)) {
|
|
72
|
+
throw new HeavyOrderError("refused", `${what} was refused (${code ?? "no code"}).`, {
|
|
73
|
+
refusal: code === null ? null : heavyRefusalOf(code),
|
|
74
|
+
orderId,
|
|
75
|
+
slot,
|
|
76
|
+
cause: err,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (attempt >= attempts) {
|
|
80
|
+
throw new HeavyOrderError("unreachable", `${what} failed ${attempts} times.`, {
|
|
81
|
+
orderId,
|
|
82
|
+
slot,
|
|
83
|
+
cause: err,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
await sleep(1000 * 2 ** (attempt - 1), signal);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const readOrder = (id, slot) => call("Reading the order", () => api.getOrder(id, { signal }), slot);
|
|
91
|
+
/**
|
|
92
|
+
* Report the payment. A just-sent transaction may not be readable yet where the server looks, so
|
|
93
|
+
* "not found" is asked again a few times; "already used" means an earlier report landed and its
|
|
94
|
+
* answer was lost, which the order's own state confirms.
|
|
95
|
+
*/
|
|
96
|
+
async function reportPayment(id, digest) {
|
|
97
|
+
for (let attempt = 1;; attempt += 1) {
|
|
98
|
+
try {
|
|
99
|
+
await call("Reporting the payment", () => api.markPaid(id, { tx_digest: digest }, { signal }), null);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
const refusal = err instanceof HeavyOrderError ? err.refusal : null;
|
|
104
|
+
if (refusal === "payment_not_found" && attempt < 6) {
|
|
105
|
+
await sleep(5000 * attempt, signal);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (refusal === "digest_used") {
|
|
109
|
+
const view = await readOrder(id, null);
|
|
110
|
+
if (view.state === "paid" || view.state === "bound")
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (err instanceof HeavyOrderError && err.reason === "refused") {
|
|
114
|
+
throw new HeavyOrderError("payment_refused", `The payment ${digest} was not accepted.`, {
|
|
115
|
+
refusal,
|
|
116
|
+
orderId: id,
|
|
117
|
+
cause: err,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
// 1. Open (or reach again) the order.
|
|
126
|
+
const request = heavyOrderRequest(options.files, options.payment, idempotencyKey);
|
|
127
|
+
const created = await call("Opening the order", () => api.createOrder(request, { signal }), null);
|
|
128
|
+
if (typeof created.order_id !== "string" || created.slots?.length !== plans.length) {
|
|
129
|
+
throw new HeavyOrderError("bad_answer", "The order came back without the slots it was opened with.");
|
|
130
|
+
}
|
|
131
|
+
const id = created.order_id;
|
|
132
|
+
orderId = id;
|
|
133
|
+
if (options.payment.pay === "wallet" && created.price === undefined) {
|
|
134
|
+
throw new HeavyOrderError("bad_answer", "A wallet order came back without a price.", { orderId: id });
|
|
135
|
+
}
|
|
136
|
+
emit({ phase: "opened", orderId: id, order: created });
|
|
137
|
+
// What the order already holds: a run that reaches an existing order does not redo stored slots.
|
|
138
|
+
const before = await readOrder(id, null);
|
|
139
|
+
let latest = before;
|
|
140
|
+
const results = new Map();
|
|
141
|
+
/** Read the order until this slot is stored; fail on a failed slot, a failed order or the deadline. */
|
|
142
|
+
async function waitStored(plan, cid) {
|
|
143
|
+
const deadline = now() + storeTimeout;
|
|
144
|
+
const where = { orderId: id, slot: plan.slot };
|
|
145
|
+
for (let interval = pollStart;; interval = Math.min(pollMax, Math.round(interval * 1.5))) {
|
|
146
|
+
const view = await readOrder(id, plan.slot);
|
|
147
|
+
latest = view;
|
|
148
|
+
if (view.state === "failed" || view.state === "expired") {
|
|
149
|
+
throw new HeavyOrderError("order_failed", `The order is ${view.state}.`, where);
|
|
150
|
+
}
|
|
151
|
+
const slot = view.slots?.find((s) => s.slot === plan.slot);
|
|
152
|
+
if (slot?.state === "failed" || slot?.state === "removed") {
|
|
153
|
+
const why = slot.error ? `: ${slot.error}` : "";
|
|
154
|
+
throw new HeavyOrderError("slot_failed", `Part ${plan.partIndex} of "${plan.fileKey}" was not stored (${slot.state}${why}).`, where);
|
|
155
|
+
}
|
|
156
|
+
if (slot?.state === "stored") {
|
|
157
|
+
const copies = readCopies(slot.copies);
|
|
158
|
+
const stored = slot.piece_cid ?? cid;
|
|
159
|
+
if (copies === null || typeof stored !== "string" || (cid !== null && stored !== cid)) {
|
|
160
|
+
throw new HeavyOrderError("bad_answer", `Slot ${plan.slot} is stored, but its copies or piece id do not add up.`, where);
|
|
161
|
+
}
|
|
162
|
+
return { cid: stored, copies };
|
|
163
|
+
}
|
|
164
|
+
if (now() >= deadline) {
|
|
165
|
+
const minutes = Math.round(storeTimeout / 60_000);
|
|
166
|
+
throw new HeavyOrderError("store_timeout", `Part ${plan.partIndex} of "${plan.fileKey}" was not stored within ${minutes} minutes.`, where);
|
|
167
|
+
}
|
|
168
|
+
await sleep(interval, signal);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async function processSlot(plan) {
|
|
172
|
+
const at = { slot: plan.slot, fileKey: plan.fileKey, partIndex: plan.partIndex };
|
|
173
|
+
const where = { orderId: id, slot: plan.slot };
|
|
174
|
+
const known = before.slots?.find((s) => s.slot === plan.slot);
|
|
175
|
+
if (known?.state === "stored" || known?.state === "committing") {
|
|
176
|
+
results.set(plan.slot, await waitStored(plan, known.piece_cid ?? null));
|
|
177
|
+
emit({ phase: "stored", ...at });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
emit({ phase: "sealing", ...at });
|
|
181
|
+
const job = { fileKey: plan.fileKey, partIndex: plan.partIndex, slot: plan.slot, sealedLen: plan.sealedLen };
|
|
182
|
+
const bytes = await deps.seal(job, signal);
|
|
183
|
+
if (signal.aborted)
|
|
184
|
+
throw abortError();
|
|
185
|
+
if (sizeOf(bytes) !== plan.sealedLen) {
|
|
186
|
+
throw new HeavyOrderError("sealed_len_mismatch", `Part ${plan.partIndex} of "${plan.fileKey}" sealed to ${sizeOf(bytes)} bytes, ` +
|
|
187
|
+
`not the ${plan.sealedLen} the order was opened for.`, where);
|
|
188
|
+
}
|
|
189
|
+
emit({ phase: "hashing", ...at });
|
|
190
|
+
const cid = await deps.pieceCid(bytes);
|
|
191
|
+
emit({ phase: "placing", ...at });
|
|
192
|
+
const target = await call("Placing the part", () => api.targetSlot(id, plan.slot, { piece_cid: cid }, { signal }), plan.slot);
|
|
193
|
+
if (!isHttpsUrl(target.service_url)) {
|
|
194
|
+
throw new HeavyOrderError("bad_answer", "The server named no https storage service for this part.", where);
|
|
195
|
+
}
|
|
196
|
+
for (let attempt = 1;; attempt += 1) {
|
|
197
|
+
try {
|
|
198
|
+
await deps.upload({
|
|
199
|
+
serviceUrl: target.service_url,
|
|
200
|
+
bytes,
|
|
201
|
+
pieceCid: cid,
|
|
202
|
+
signal,
|
|
203
|
+
onProgress: (sentBytes, totalBytes) => emit({ phase: "uploading", ...at, sentBytes, totalBytes }),
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
catch (err) {
|
|
208
|
+
if (isAbort(err) || signal.aborted)
|
|
209
|
+
throw err;
|
|
210
|
+
if (attempt >= uploadAttempts) {
|
|
211
|
+
throw new HeavyOrderError("upload_failed", `Uploading part ${plan.partIndex} of "${plan.fileKey}" failed ${uploadAttempts} times.`, { ...where, cause: err });
|
|
212
|
+
}
|
|
213
|
+
await sleep(2000 * 2 ** (attempt - 1), signal);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
emit({ phase: "committing", ...at });
|
|
217
|
+
await call("Reporting the upload", () => api.slotUploaded(id, plan.slot, { signal }), plan.slot);
|
|
218
|
+
results.set(plan.slot, await waitStored(plan, cid));
|
|
219
|
+
emit({ phase: "stored", ...at });
|
|
220
|
+
}
|
|
221
|
+
// 2. The slots, a few at a time. The first failure aborts the others and is the one reported.
|
|
222
|
+
let firstFailure = null;
|
|
223
|
+
let next = 0;
|
|
224
|
+
const worker = async () => {
|
|
225
|
+
for (let plan = plans[next]; firstFailure === null && plan !== undefined; plan = plans[next]) {
|
|
226
|
+
next += 1;
|
|
227
|
+
try {
|
|
228
|
+
await processSlot(plan);
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
if (firstFailure === null)
|
|
232
|
+
firstFailure = err;
|
|
233
|
+
run.abort();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, plans.length) }, worker));
|
|
239
|
+
if (firstFailure !== null) {
|
|
240
|
+
// When the caller aborted, every slot reports an abort; say so rather than the first of them.
|
|
241
|
+
if (options.signal?.aborted)
|
|
242
|
+
throw abortError();
|
|
243
|
+
throw firstFailure;
|
|
244
|
+
}
|
|
245
|
+
// The epoch the copies are kept until is set once every slot is stored: the last read has it,
|
|
246
|
+
// or a read or two later does.
|
|
247
|
+
let view = latest;
|
|
248
|
+
for (let tries = 0; typeof view.expiry_epoch !== "number" && tries < 5; tries += 1) {
|
|
249
|
+
await sleep(pollStart, signal);
|
|
250
|
+
view = await readOrder(id, null);
|
|
251
|
+
}
|
|
252
|
+
const expiryEpoch = view.expiry_epoch;
|
|
253
|
+
if (typeof expiryEpoch !== "number") {
|
|
254
|
+
throw new HeavyOrderError("bad_answer", "Every part is stored but the order names no end epoch.", {
|
|
255
|
+
orderId: id,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// 3. Pay, when the wallet pays — once, after everything is stored, and not again on a rerun.
|
|
259
|
+
let txDigest;
|
|
260
|
+
const price = created.price;
|
|
261
|
+
if (options.payment.pay === "wallet" && price && view.state !== "paid" && view.state !== "bound") {
|
|
262
|
+
emit({ phase: "paying", orderId: id, price });
|
|
263
|
+
txDigest = await options.payment.payWallet(price, id);
|
|
264
|
+
await reportPayment(id, txDigest);
|
|
265
|
+
emit({ phase: "paid", orderId: id, txDigest });
|
|
266
|
+
}
|
|
267
|
+
// 4. The parts to commit, per file.
|
|
268
|
+
const files = options.files.map((file) => ({ key: file.key, parts: [] }));
|
|
269
|
+
for (const plan of plans) {
|
|
270
|
+
const done = results.get(plan.slot);
|
|
271
|
+
const file = files[plan.fileIndex];
|
|
272
|
+
if (done === undefined || file === undefined) {
|
|
273
|
+
throw new HeavyOrderError("bad_answer", `Slot ${plan.slot} finished without a result.`, { orderId: id });
|
|
274
|
+
}
|
|
275
|
+
file.parts.push({
|
|
276
|
+
part_index: plan.partIndex,
|
|
277
|
+
storage_kind: 0,
|
|
278
|
+
network: 1,
|
|
279
|
+
blob_id: done.cid,
|
|
280
|
+
sealed_len: plan.sealedLen,
|
|
281
|
+
owner_kind: 1,
|
|
282
|
+
expiry_epoch: expiryEpoch,
|
|
283
|
+
heavy_order_id: id,
|
|
284
|
+
heavy_slot: plan.slot,
|
|
285
|
+
copies: done.copies,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
orderId: id,
|
|
290
|
+
idempotencyKey,
|
|
291
|
+
expiryEpoch,
|
|
292
|
+
...(created.credits === undefined ? {} : { credits: created.credits }),
|
|
293
|
+
...(txDigest === undefined ? {} : { txDigest }),
|
|
294
|
+
files,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
options.signal?.removeEventListener("abort", onOuterAbort);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { HeavyOrderApi, HeavyOrderCreated, HeavyPartCommit, HeavyPrice } from "../api/types-heavy.ts";
|
|
2
|
+
import type { HeavyPayment, HeavyRunFile } from "./order-plan.ts";
|
|
3
|
+
/** A sealed part as the sealer returns it: a Blob (may be disk-backed) or bytes in memory. */
|
|
4
|
+
export type SealedBytes = Blob | Uint8Array<ArrayBuffer>;
|
|
5
|
+
/** What the sealer is asked to seal. */
|
|
6
|
+
export interface HeavySealJob {
|
|
7
|
+
fileKey: string;
|
|
8
|
+
partIndex: number;
|
|
9
|
+
slot: number;
|
|
10
|
+
sealedLen: number;
|
|
11
|
+
}
|
|
12
|
+
/** The moments a caller can show. */
|
|
13
|
+
export type HeavyProgress = {
|
|
14
|
+
phase: "opened";
|
|
15
|
+
orderId: string;
|
|
16
|
+
order: HeavyOrderCreated;
|
|
17
|
+
} | {
|
|
18
|
+
phase: "sealing" | "hashing" | "placing" | "committing" | "stored";
|
|
19
|
+
slot: number;
|
|
20
|
+
fileKey: string;
|
|
21
|
+
partIndex: number;
|
|
22
|
+
} | {
|
|
23
|
+
phase: "uploading";
|
|
24
|
+
slot: number;
|
|
25
|
+
fileKey: string;
|
|
26
|
+
partIndex: number;
|
|
27
|
+
sentBytes: number;
|
|
28
|
+
totalBytes: number;
|
|
29
|
+
} | {
|
|
30
|
+
phase: "paying";
|
|
31
|
+
orderId: string;
|
|
32
|
+
price: HeavyPrice;
|
|
33
|
+
} | {
|
|
34
|
+
phase: "paid";
|
|
35
|
+
orderId: string;
|
|
36
|
+
txDigest: string;
|
|
37
|
+
};
|
|
38
|
+
export interface HeavyRunDeps {
|
|
39
|
+
api: HeavyOrderApi;
|
|
40
|
+
seal: (job: HeavySealJob, signal?: AbortSignal) => Promise<SealedBytes>;
|
|
41
|
+
/** The part's FRC-0069 PieceCID (`bafkzcib…`), e.g. `calculate` from `@filoz/synapse-core/piece`. */
|
|
42
|
+
pieceCid: (bytes: SealedBytes) => Promise<string>;
|
|
43
|
+
/** Upload to the company — `uploadPieceToProvider` in `sp-upload.ts`, with the caller's transport. */
|
|
44
|
+
upload: (input: {
|
|
45
|
+
serviceUrl: string;
|
|
46
|
+
bytes: SealedBytes;
|
|
47
|
+
pieceCid: string;
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
onProgress?: (sentBytes: number, totalBytes: number) => void;
|
|
50
|
+
}) => Promise<void>;
|
|
51
|
+
/** Wait `ms`, rejecting with an AbortError when `signal` aborts. Default: a timer. */
|
|
52
|
+
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
53
|
+
/** Milliseconds since some fixed point. Default: `Date.now`. */
|
|
54
|
+
now?: () => number;
|
|
55
|
+
/** A fresh idempotency key (16..64 of `[A-Za-z0-9_-]`). Default: a random UUID. */
|
|
56
|
+
newIdempotencyKey?: () => string;
|
|
57
|
+
}
|
|
58
|
+
export interface HeavyRunOptions {
|
|
59
|
+
files: readonly HeavyRunFile[];
|
|
60
|
+
payment: HeavyPayment;
|
|
61
|
+
/** Pass the key of an earlier run to reach the same order again; otherwise a new one is made. */
|
|
62
|
+
idempotencyKey?: string;
|
|
63
|
+
/** Slots worked on at once. Default 2. */
|
|
64
|
+
concurrency?: number;
|
|
65
|
+
/** First wait between order reads while a slot commits. Default 3 s; it grows by half each time. */
|
|
66
|
+
pollIntervalMs?: number;
|
|
67
|
+
/** Longest wait between order reads. Default 30 s. */
|
|
68
|
+
pollMaxIntervalMs?: number;
|
|
69
|
+
/** How long one slot may take from `uploaded` to `stored`. Default 60 minutes. */
|
|
70
|
+
storeTimeoutMs?: number;
|
|
71
|
+
/** Upload attempts per slot before giving up. Default 3. */
|
|
72
|
+
uploadAttempts?: number;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
onProgress?: (event: HeavyProgress) => void;
|
|
75
|
+
}
|
|
76
|
+
export interface HeavyRunResult {
|
|
77
|
+
orderId: string;
|
|
78
|
+
idempotencyKey: string;
|
|
79
|
+
/** The Filecoin epoch every copy is kept until. */
|
|
80
|
+
expiryEpoch: number;
|
|
81
|
+
/** Credit orders: what was taken. */
|
|
82
|
+
credits?: number;
|
|
83
|
+
/** Wallet orders: the payment's Sui transaction digest. */
|
|
84
|
+
txDigest?: string;
|
|
85
|
+
/** Per file, in the order given: the parts to put in that file's `POST /v1/items`. */
|
|
86
|
+
files: {
|
|
87
|
+
key: string;
|
|
88
|
+
parts: HeavyPartCommit[];
|
|
89
|
+
}[];
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The shapes an NMTS Heavy upload is described in: what the caller hands the orchestrator, what it
|
|
2
|
+
// injects, what it hears along the way and what it gets back (`order-runner.ts` runs it).
|
|
3
|
+
//
|
|
4
|
+
// ⚠ THIS FILE IS PUBLISHED. It is copied byte-for-byte into the `nmts` command-line package.
|
|
5
|
+
// Keep the comments self-contained English, with no pointer only we can follow.
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type HeavyCopy, type HeavyRefusal } from "../api/types-heavy.ts";
|
|
2
|
+
/** Why a Heavy upload stopped, as a machine-readable word. */
|
|
3
|
+
export type HeavyFailure =
|
|
4
|
+
/** A sealed part is under 127 bytes. The caller pads the plaintext and tries again. */
|
|
5
|
+
"piece_too_small"
|
|
6
|
+
/** A sealed part is over the per-piece limit. The caller cuts smaller parts. */
|
|
7
|
+
| "piece_too_large"
|
|
8
|
+
/** More parts than one order may hold, none at all, or parts not numbered 0..n-1. */
|
|
9
|
+
| "slot_count"
|
|
10
|
+
/** The sealer produced a different number of bytes than the order was opened for. */
|
|
11
|
+
| "sealed_len_mismatch"
|
|
12
|
+
/** The server refused a call; `refusal` names which refusal when it is one of the contract's. */
|
|
13
|
+
| "refused"
|
|
14
|
+
/** The server's answer did not have the shape the contract gives it. */
|
|
15
|
+
| "bad_answer"
|
|
16
|
+
/** Every upload attempt to the storage company failed. */
|
|
17
|
+
| "upload_failed"
|
|
18
|
+
/** The server reports the slot failed (or was removed) instead of stored. */
|
|
19
|
+
| "slot_failed"
|
|
20
|
+
/** The whole order failed or expired. */
|
|
21
|
+
| "order_failed"
|
|
22
|
+
/** The slot was not stored within the time allowed. */
|
|
23
|
+
| "store_timeout"
|
|
24
|
+
/** The server could not be reached, repeatedly. */
|
|
25
|
+
| "unreachable"
|
|
26
|
+
/** The wallet payment was sent but the server would not accept it. */
|
|
27
|
+
| "payment_refused";
|
|
28
|
+
export declare class HeavyOrderError extends Error {
|
|
29
|
+
readonly reason: HeavyFailure;
|
|
30
|
+
/** The contract refusal behind `refused` or `payment_refused`, when there was one. */
|
|
31
|
+
readonly refusal: HeavyRefusal | null;
|
|
32
|
+
readonly orderId: string | null;
|
|
33
|
+
readonly slot: number | null;
|
|
34
|
+
constructor(reason: HeavyFailure, message: string, details?: {
|
|
35
|
+
refusal?: HeavyRefusal | null;
|
|
36
|
+
orderId?: string | null;
|
|
37
|
+
slot?: number | null;
|
|
38
|
+
cause?: unknown;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export declare function abortError(): DOMException;
|
|
42
|
+
export declare function isAbort(err: unknown): boolean;
|
|
43
|
+
/** The error's string `code`, if it has one. */
|
|
44
|
+
export declare function codeOf(err: unknown): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* A failure that says nothing about the request itself — the line dropped, the server had a bad
|
|
47
|
+
* moment, or a limiter answered without a named reason — so the same call may simply be made again.
|
|
48
|
+
* A named refusal never is: asking again gets the same answer.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isTransient(err: unknown): boolean;
|
|
51
|
+
/** Wait `ms`, rejecting with an AbortError as soon as `signal` aborts. */
|
|
52
|
+
export declare function defaultSleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
53
|
+
export declare function isHttpsUrl(value: unknown): value is string;
|
|
54
|
+
/** A stored slot's copies, checked field by field; `null` when the answer is not usable. */
|
|
55
|
+
export declare function readCopies(raw: unknown): HeavyCopy[] | null;
|