@needmoretruth/nmts-cli 0.54.2 → 0.56.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/CHANGELOG.md +22 -0
- package/README.ko.md +9 -1
- package/README.md +9 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/push.js +1 -1
- package/dist/commands/put-wallet.js +12 -12
- package/dist/commands/put.js +1 -1
- package/dist/commands/recovery-list.js +3 -2
- package/dist/crypto-surface.d.ts +2 -0
- package/dist/crypto-surface.js +4 -7
- package/dist/manifest.js +3 -0
- package/dist/node-read.d.ts +2 -0
- package/dist/node-read.js +24 -0
- package/dist/portable.d.ts +2 -0
- package/dist/portable.js +3 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/read-race.d.ts +35 -0
- package/dist/read-race.js +91 -0
- package/dist/recovery-assemble.d.ts +4 -11
- package/dist/recovery-assemble.js +25 -106
- package/dist/recovery-build.d.ts +7 -1
- package/dist/recovery-build.js +15 -11
- package/dist/recovery-seq.d.ts +2 -2
- package/dist/recovery-seq.js +30 -23
- package/dist/recovery.d.ts +92 -0
- package/dist/recovery.js +202 -0
- package/dist/road-hosts.generated.d.ts +4 -0
- package/dist/road-hosts.generated.js +284 -0
- package/dist/shared/lib/upload/wallet-storage-estimate.d.ts +16 -0
- package/dist/shared/lib/upload/wallet-storage-estimate.js +44 -0
- package/dist/shared/lib/wallet/graphql-history.d.ts +7 -2
- package/dist/shared/lib/wallet/graphql-history.js +7 -2
- package/dist/shared/lib/walrus/credit-tip.d.ts +24 -0
- package/dist/shared/lib/walrus/credit-tip.js +61 -0
- package/dist/shared/lib/walrus/node-certificate.d.ts +18 -0
- package/dist/shared/lib/walrus/node-certificate.js +77 -0
- package/dist/shared/lib/walrus/node-quorum.d.ts +17 -0
- package/dist/shared/lib/walrus/node-quorum.js +103 -0
- package/dist/shared/lib/walrus/tip-config.d.ts +33 -0
- package/dist/shared/lib/walrus/tip-config.js +68 -0
- package/dist/upload-file.d.ts +2 -0
- package/dist/upload-file.js +6 -0
- package/dist/upload-recovery-patch.d.ts +65 -0
- package/dist/upload-recovery-patch.js +250 -0
- package/dist/upload-road.d.ts +26 -4
- package/dist/upload-road.js +79 -17
- package/dist/upload-steps.js +5 -1
- package/dist/upload-wallet-chain.d.ts +1 -1
- package/dist/upload-wallet-chain.js +11 -4
- package/dist/upload-wallet-plan.d.ts +4 -0
- package/dist/upload-wallet-plan.js +18 -8
- package/dist/upload-wallet-put.d.ts +6 -2
- package/dist/upload-wallet-put.js +30 -17
- package/dist/upload-wallet.d.ts +4 -1
- package/dist/upload-wallet.js +12 -3
- package/dist/upload-wire.d.ts +27 -0
- package/dist/upload-wire.js +2 -0
- package/dist/upload.js +3 -3
- package/dist/walrus-write.js +80 -3
- package/dist/walrus.d.ts +20 -4
- package/dist/walrus.js +115 -36
- package/docs/commands/put.md +5 -1
- package/package.json +5 -1
- package/server.json +2 -2
package/dist/upload-road.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The roads an upload from this tool can take (D50 · D51, 2026-11-09).
|
|
3
|
+
*
|
|
4
|
+
* ⭐ ORDER (owner, 2026-11-09). Mysten Labs' relay; when it does not answer, the Walrus storage
|
|
5
|
+
* nodes straight from this machine (`NODE_ROAD`, no relay, no tip); NMTS's own relay last, only
|
|
6
|
+
* for a part the direct write could not carry. The own relay is a server the owner pays for and
|
|
7
|
+
* shares with the site, so it is the road taken when nothing else carried the bytes.
|
|
8
|
+
* Between them, the other company relays of `RELAY_HOSTS` (Studio Mirai since 2026-11-10, found by
|
|
9
|
+
* a live probe; the registry lists no relays). On a wallet upload the person pays that relay's tip
|
|
10
|
+
* and sees it before signing. On a credit upload the treasury pays it only while its tip fits the
|
|
11
|
+
* credit ceiling at every size (`credit-tip.ts`, three times Mysten's formula; the chain service
|
|
12
|
+
* refuses above it), because this road is chosen before the size is known.
|
|
13
|
+
*
|
|
14
|
+
* ⭐ THE TWO LAST ROADS COST THE SAME AND CUT THE SAME. Neither takes a tip, and both send 64 MiB
|
|
15
|
+
* parts, so the price shown before the first signature holds whichever of them carries a part,
|
|
16
|
+
* and the registration a part was bought with serves either.
|
|
3
17
|
*
|
|
4
18
|
* ⛔ WHY. Every upload reached Walrus through Mysten Labs' relay alone; the day it stops answering,
|
|
5
19
|
* nobody can upload. NMTS runs the same relay software (Mysten's image, no tip) behind its own
|
|
@@ -17,51 +31,99 @@
|
|
|
17
31
|
*/
|
|
18
32
|
import { reachFetch } from "./reach.js";
|
|
19
33
|
import { RELAY_HOSTS, relayHost } from "./walrus.js";
|
|
34
|
+
import { creditTipFitsEverySize, tipLine } from "./shared/lib/walrus/credit-tip.js";
|
|
35
|
+
import { parseTipConfig } from "./shared/lib/walrus/tip-config.js";
|
|
20
36
|
/** Where the own relay answers, after the NMTS server's address. */
|
|
21
37
|
export const OWN_RELAY_PATH = "/v1/relay";
|
|
22
38
|
/** The part size on the own road: an existing preset, the size whose relay peak fits the server. */
|
|
23
39
|
export const OWN_RELAY_PART_BYTES = 64 * 2 ** 20;
|
|
24
40
|
/** How long Mysten's relay gets to answer before this run takes the own road. */
|
|
25
41
|
export const ROAD_PROBE_TIMEOUT_MS = 10_000;
|
|
42
|
+
/**
|
|
43
|
+
* The "relay address" of the direct road: no host, the storage nodes themselves (D51). The same
|
|
44
|
+
* value as the browser's (`web/src/lib/walrus/node-road.ts`), and it is what a resumable upload's
|
|
45
|
+
* record keeps, so a resumed part goes back to the nodes.
|
|
46
|
+
*/
|
|
47
|
+
export const NODE_ROAD = "walrus:storage-nodes";
|
|
48
|
+
/** True for the direct road. */
|
|
49
|
+
export function isNodeRoad(relayUrl) {
|
|
50
|
+
return relayUrl === NODE_ROAD;
|
|
51
|
+
}
|
|
52
|
+
/** True for a road that takes no tip: the own relay and the storage nodes. */
|
|
53
|
+
export function isTipFree(relayUrl) {
|
|
54
|
+
return isNodeRoad(relayUrl) || isOwnRelay(relayUrl);
|
|
55
|
+
}
|
|
26
56
|
let chosen = null;
|
|
57
|
+
/** A company relay after Mysten's, taken when Mysten's did not answer (D51). */
|
|
58
|
+
let companyRelay = null;
|
|
27
59
|
/** True for the own relay's address on any NMTS server. */
|
|
28
60
|
export function isOwnRelay(relayUrl) {
|
|
29
61
|
return relayUrl.replace(/\/+$/, "").endsWith(OWN_RELAY_PATH);
|
|
30
62
|
}
|
|
31
63
|
/**
|
|
32
|
-
* Decide this run's road, once, before anything is priced. True when
|
|
64
|
+
* Decide this run's road, once, before anything is priced. True when a small road (the storage
|
|
65
|
+
* nodes, or the own relay) was taken.
|
|
33
66
|
*
|
|
34
|
-
* `probe` is the request that asks Mysten's relay (tests pass a fake one).
|
|
67
|
+
* `probe` is the request that asks Mysten's relay (tests pass a fake one). `nodeRoad: false` is a
|
|
68
|
+
* machine that cannot write to the storage nodes itself; it goes to the own relay, as before D51.
|
|
35
69
|
*/
|
|
36
70
|
export async function chooseUploadRoad(input) {
|
|
37
71
|
chosen = null;
|
|
38
|
-
|
|
72
|
+
companyRelay = null;
|
|
73
|
+
const relays = RELAY_HOSTS[input.network] ?? [];
|
|
74
|
+
const known = relays[0];
|
|
39
75
|
// A caller or an environment that named a relay chose it; nothing is asked.
|
|
40
76
|
if (known === undefined || relayHost(input.network) !== known)
|
|
41
77
|
return false;
|
|
42
78
|
const probe = input.probe ?? reachFetch;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
79
|
+
const answers = async (relay) => {
|
|
80
|
+
try {
|
|
81
|
+
const res = await probe(`${relay}/v1/tip-config`, {
|
|
82
|
+
signal: AbortSignal.timeout(input.timeoutMs ?? ROAD_PROBE_TIMEOUT_MS),
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok)
|
|
85
|
+
return false;
|
|
86
|
+
// Mysten's own price is the reference; another company's must fit the credit ceiling.
|
|
87
|
+
if (input.credit !== true || relay === known)
|
|
88
|
+
return true;
|
|
89
|
+
const line = tipLine(parseTipConfig(await res.json()));
|
|
90
|
+
return line !== null && creditTipFitsEverySize(line);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
48
93
|
return false;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// Asked together, so a dead relay costs one timeout, not one each; Mysten's answer wins.
|
|
97
|
+
const others = input.otherCompanies === true || input.credit === true ? relays.slice(1) : [];
|
|
98
|
+
const answered = await Promise.all([known, ...others].map(answers));
|
|
99
|
+
if (answered[0])
|
|
100
|
+
return false;
|
|
101
|
+
const other = others.find((_, i) => answered[i + 1]);
|
|
102
|
+
if (other !== undefined) {
|
|
103
|
+
companyRelay = other;
|
|
104
|
+
return false;
|
|
49
105
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
chosen = { relayUrl: `${input.server.replace(/\/+$/, "")}${OWN_RELAY_PATH}`, apiKey: input.apiKey };
|
|
106
|
+
const ownUrl = `${input.server.replace(/\/+$/, "")}${OWN_RELAY_PATH}`;
|
|
107
|
+
chosen = { relayUrl: input.nodeRoad === false ? ownUrl : NODE_ROAD, apiKey: input.apiKey, ownUrl };
|
|
54
108
|
return true;
|
|
55
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* The own relay to try when a direct write failed, with the fetch that carries this account's key,
|
|
112
|
+
* or null when this run did not choose the small roads (a named relay, or Mysten's).
|
|
113
|
+
*/
|
|
114
|
+
export function ownRelayFallback() {
|
|
115
|
+
return chosen === null || chosen.relayUrl === chosen.ownUrl ? null : chosen.ownUrl;
|
|
116
|
+
}
|
|
56
117
|
/** Forget the choice (tests; a library caller between runs). */
|
|
57
118
|
export function resetUploadRoad() {
|
|
58
119
|
chosen = null;
|
|
120
|
+
companyRelay = null;
|
|
59
121
|
}
|
|
60
|
-
/** The
|
|
122
|
+
/** The road this run writes through: the storage nodes or the own relay when chosen, else the usual relay. */
|
|
61
123
|
export function uploadRelay(network) {
|
|
62
|
-
return chosen?.relayUrl ?? relayHost(network);
|
|
124
|
+
return chosen?.relayUrl ?? companyRelay ?? relayHost(network);
|
|
63
125
|
}
|
|
64
|
-
/** The part size a fresh upload uses: unchanged on Mysten's road, at most 64 MiB on
|
|
126
|
+
/** The part size a fresh upload uses: unchanged on Mysten's road, at most 64 MiB on the small roads. */
|
|
65
127
|
export function partSizeForRoad(partSize) {
|
|
66
128
|
return chosen === null ? partSize : Math.min(partSize, OWN_RELAY_PART_BYTES);
|
|
67
129
|
}
|
|
@@ -76,7 +138,7 @@ const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
|
76
138
|
});
|
|
77
139
|
export function relayFetch(relayUrl, inner, sleep = wait) {
|
|
78
140
|
const road = chosen;
|
|
79
|
-
if (road === null || road.
|
|
141
|
+
if (road === null || road.ownUrl !== relayUrl)
|
|
80
142
|
return inner;
|
|
81
143
|
return async (input, init) => {
|
|
82
144
|
const headers = new Headers(init?.headers);
|
package/dist/upload-steps.js
CHANGED
|
@@ -8,6 +8,8 @@ import { readItemRecord, writeItemRecord } from "./upload-store.js";
|
|
|
8
8
|
import { UploadError, } from "./upload-wire.js";
|
|
9
9
|
/** ITEM PARTS: the storage shape this tool writes — one blob per part, the file its own set. */
|
|
10
10
|
const STORAGE_KIND_DEDICATED_BLOB = 0;
|
|
11
|
+
/** A wallet upload that carried the recovery list is one patch of a quilt (`upload-recovery-patch.ts`). */
|
|
12
|
+
const STORAGE_KIND_QUILT_PATCH = 1;
|
|
11
13
|
/** Walrus. The only network with an upload path. */
|
|
12
14
|
const NETWORK_WALRUS = 0;
|
|
13
15
|
/** Only this account can read it. Sharing is a separate act, made in a browser. */
|
|
@@ -28,6 +30,7 @@ export async function pushPart(input, step) {
|
|
|
28
30
|
nonce: step.nonce,
|
|
29
31
|
registerTxDigest: step.registerTxDigest,
|
|
30
32
|
blobObjectId: step.blobObjectId,
|
|
33
|
+
relayUrl: step.relayUrl,
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
catch (error) {
|
|
@@ -125,9 +128,10 @@ export async function commitItem(input, fileKey, parts) {
|
|
|
125
128
|
function describePart(part, expiryEpoch) {
|
|
126
129
|
const common = {
|
|
127
130
|
part_index: part.partIndex,
|
|
128
|
-
storage_kind: STORAGE_KIND_DEDICATED_BLOB,
|
|
131
|
+
storage_kind: part.patchId === undefined ? STORAGE_KIND_DEDICATED_BLOB : STORAGE_KIND_QUILT_PATCH,
|
|
129
132
|
network: NETWORK_WALRUS,
|
|
130
133
|
blob_id: part.blobId,
|
|
134
|
+
...(part.patchId === undefined ? {} : { patch_id: part.patchId }),
|
|
131
135
|
sealed_len: part.sealedLen,
|
|
132
136
|
};
|
|
133
137
|
if (part.ledgerId !== null) {
|
|
@@ -16,7 +16,7 @@ export declare const RELAY_TIP_CEILING_MIST: Readonly<Record<Network, number>>;
|
|
|
16
16
|
export declare function packageConfig(network: Network): {
|
|
17
17
|
systemObjectId: string;
|
|
18
18
|
};
|
|
19
|
-
declare function build(network: Network,
|
|
19
|
+
declare function build(network: Network, given: string): import("@mysten/sui/client").ClientWithExtensions<{
|
|
20
20
|
walrus: import("@mysten/walrus").WalrusClient;
|
|
21
21
|
}, import("@mysten/sui/grpc").SuiGrpcClient>;
|
|
22
22
|
export type PayingClient = ReturnType<typeof build>;
|
|
@@ -26,7 +26,7 @@ import { reachFetch } from "./reach.js";
|
|
|
26
26
|
import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
|
|
27
27
|
import { registerIntoStorage, splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
28
28
|
import { dryRun, inspect, u64FromLe } from "./shared/lib/wallet/chain-calls.js";
|
|
29
|
-
import { isOwnRelay, relayFetch } from "./upload-road.js";
|
|
29
|
+
import { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch } from "./upload-road.js";
|
|
30
30
|
import { storageNodesThrough } from "./walrus.js";
|
|
31
31
|
import { freshWalrus } from "./walrus-fresh.js";
|
|
32
32
|
import { suiClient } from "./sui-rpc.js";
|
|
@@ -40,15 +40,22 @@ import { chainReader } from "./wallet-chain.js";
|
|
|
40
40
|
* tip configuration sets the amount, which the review prints — and a relay asking for more than
|
|
41
41
|
* this is refused by the SDK before anything is signed.
|
|
42
42
|
*/
|
|
43
|
+
// ⛔ Raised in D51 (2026-11-10) with the browser's, for Studio Mirai's relay: 3,000,000 MIST plus 60
|
|
44
|
+
// per encoded KiB, about 0.022 SUI for a 64 MiB part and 0.289 SUI for a 1 GiB one.
|
|
43
45
|
export const RELAY_TIP_CEILING_MIST = {
|
|
44
|
-
testnet:
|
|
45
|
-
mainnet:
|
|
46
|
+
testnet: 50_000_000,
|
|
47
|
+
mainnet: 400_000_000,
|
|
46
48
|
};
|
|
47
49
|
/** The Walrus package addresses of one network. Exported from the SDK; the system object survives upgrades. */
|
|
48
50
|
export function packageConfig(network) {
|
|
49
51
|
return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
|
|
50
52
|
}
|
|
51
|
-
function build(network,
|
|
53
|
+
function build(network, given) {
|
|
54
|
+
// The direct road (D51) has no relay to tip; the client is the own relay's (no tip either), which
|
|
55
|
+
// also carries a part the nodes did not take. Without that fallback, a relay-free client.
|
|
56
|
+
const relayUrl = isNodeRoad(given) ? (ownRelayFallback() ?? given) : given;
|
|
57
|
+
if (isNodeRoad(relayUrl))
|
|
58
|
+
return suiClient(network).$extend(walrus({ ...storageNodesThrough() }));
|
|
52
59
|
return suiClient(network).$extend(walrus({
|
|
53
60
|
...storageNodesThrough(),
|
|
54
61
|
uploadRelay: {
|
|
@@ -117,6 +117,8 @@ export declare function uploadShortfallNextStep(b: UploadBudget): string;
|
|
|
117
117
|
export declare function describeUploadReview(say: (line: string) => void, facts: {
|
|
118
118
|
name: string;
|
|
119
119
|
bytes: number;
|
|
120
|
+
/** What the storage network would hold, sealing and padding included. */
|
|
121
|
+
sealedBytes: number;
|
|
120
122
|
parts: number;
|
|
121
123
|
epochs: number;
|
|
122
124
|
days: string;
|
|
@@ -133,4 +135,6 @@ export declare function describeUploadReview(say: (line: string) => void, facts:
|
|
|
133
135
|
* off buys silence.
|
|
134
136
|
*/
|
|
135
137
|
networkCopy: boolean | null;
|
|
138
|
+
/** The list rides in this upload's quilt, and the WAL above is the quilt's price. */
|
|
139
|
+
carriesRecoveryList: boolean;
|
|
136
140
|
}, budget: UploadBudget): void;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// costs the most: a zero would refuse an upload the wallet can afford.
|
|
14
14
|
import { NmtsError } from "./errors.js";
|
|
15
15
|
import { BINARY_NAME } from "./product.js";
|
|
16
|
+
import { RIDE_CEILING_BYTES } from "./upload-wire.js";
|
|
16
17
|
import { fits, leftoverBytes, statusOf, usableFirst } from "./shared/lib/storage-control/plan.js";
|
|
17
18
|
import { coinAmount } from "./wallet.js";
|
|
18
19
|
/** The browser's default rung, and the term one credit buys. A number of EPOCHS, not days. */
|
|
@@ -179,15 +180,24 @@ export function describeUploadReview(say, facts, budget) {
|
|
|
179
180
|
say(` This is paid in WAL and SUI from the wallet this NMTS key derives — not from credits, which`);
|
|
180
181
|
say(` is what \`${BINARY_NAME} put\` spends without --pay wallet. Nobody, NMTS included, can reverse it.`);
|
|
181
182
|
say(` The storage is the wallet's own: NMTS records the file and does not hold it.`);
|
|
182
|
-
// ⛔ SAID WHERE IT CHANGES WHAT SOMEBODY GETS, AND NOWHERE ELSE.
|
|
183
|
-
// the recovery list's copy
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
// ⛔ SAID WHERE IT CHANGES WHAT SOMEBODY GETS, AND NOWHERE ELSE. An account that never asked for
|
|
184
|
+
// the recovery list's copy has nothing to be told (`GET /v1/account/summary` `network_copy`).
|
|
185
|
+
// Since spec 2026-09-20 unit B a one-part upload onto new storage carries it, as the browser's
|
|
186
|
+
// small uploads do (`upload-recovery-patch.ts`); anything else still does not, and says so.
|
|
187
|
+
// Whether it rides was decided before the price, so the sentence says what happens, not "if".
|
|
188
|
+
const on = facts.carriesRecoveryList || facts.networkCopy === true;
|
|
189
|
+
if (on || facts.networkCopy === null) {
|
|
190
|
+
say(on
|
|
188
191
|
? ` This account asks for the recovery list to be copied to the storage network with its uploads.`
|
|
189
192
|
: ` Whether this account asks for the recovery list's storage-network copy could not be read.`);
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
const fits = facts.parts === 1 && facts.storage.kind === "buy" && facts.sealedBytes <= RIDE_CEILING_BYTES;
|
|
194
|
+
if (facts.carriesRecoveryList)
|
|
195
|
+
say(` The newest recovery list goes up with this file, and the WAL above includes it.`);
|
|
196
|
+
else if (fits)
|
|
197
|
+
say(` This upload does not include it. \`${BINARY_NAME} recovery-list\` saves the list as a file.`);
|
|
198
|
+
else {
|
|
199
|
+
say(` Only a one-part upload under 64 MiB onto new storage includes it, so this one does not.`);
|
|
200
|
+
say(` \`${BINARY_NAME} recovery-list\` saves the list as a file.`);
|
|
201
|
+
}
|
|
192
202
|
}
|
|
193
203
|
}
|
|
@@ -92,14 +92,16 @@ export interface WalletPutSeams {
|
|
|
92
92
|
agree?: ((review: WalletPutReview) => void) | undefined;
|
|
93
93
|
/** Told what left the wallet, after each signature. */
|
|
94
94
|
onSpend?: ((spend: Spend) => void) | undefined;
|
|
95
|
+
/** Told why the recovery list did not ride along, when it was switched on and did not. */
|
|
96
|
+
onRecoveryProblem?: ((message: string) => void) | undefined;
|
|
95
97
|
}
|
|
96
98
|
/** What this upload would buy, in the order somebody deciding needs it. Base units throughout. */
|
|
97
99
|
export interface WalletPutReview {
|
|
98
100
|
name: string;
|
|
99
|
-
/** Plaintext bytes. */
|
|
100
101
|
bytes: number;
|
|
101
|
-
/** Bytes the storage network holds,
|
|
102
|
+
/** Bytes the storage network holds, sealing and padding included — the quilt, when the list rides. */
|
|
102
103
|
sealedBytes: number;
|
|
104
|
+
carriesRecoveryList: boolean;
|
|
103
105
|
parts: number;
|
|
104
106
|
epochs: number;
|
|
105
107
|
/** The term in days, read from the network's own clock. */
|
|
@@ -131,6 +133,8 @@ export type WalletPutOutcome = {
|
|
|
131
133
|
fileListVersion: number;
|
|
132
134
|
/** True when every part was already signed for by an earlier run: this call spent nothing. */
|
|
133
135
|
resumed: boolean;
|
|
136
|
+
/** The number of the recovery list that rode in this upload's quilt; null when none did. */
|
|
137
|
+
recoveryList: number | null;
|
|
134
138
|
};
|
|
135
139
|
/**
|
|
136
140
|
* Price, agree, sign, upload and record ONE file, paid from the wallet the NMTS key derives.
|
|
@@ -41,6 +41,7 @@ import { createUploadApi } from "./upload-api.js";
|
|
|
41
41
|
import { uploadFile } from "./upload-file.js";
|
|
42
42
|
import { CREDIT_BYTES, planAndPrice } from "./upload-price.js";
|
|
43
43
|
import { forgetUpload } from "./upload-run.js";
|
|
44
|
+
import { planWalletRide } from "./upload-recovery-patch.js";
|
|
44
45
|
import { walletRail } from "./upload-wallet.js";
|
|
45
46
|
import { chooseUploadEpochs, daysOf, parseStorageAsk, pickResource, uploadBudget, uploadShortfallNextStep, } from "./upload-wallet-plan.js";
|
|
46
47
|
import { UploadError } from "./upload-wire.js";
|
|
@@ -75,7 +76,15 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
75
76
|
}
|
|
76
77
|
const epochs = chooseUploadEpochs(seams.epochs, window);
|
|
77
78
|
const endEpoch = window.clock.current + epochs;
|
|
78
|
-
|
|
79
|
+
// ⛔ THE RIDE IS PLANNED BEFORE THE PRICE: a riding list makes the quilt what is registered, so
|
|
80
|
+
// the quilt is quoted, reviewed, checked and told to the ledger (`upload-recovery-patch.ts`).
|
|
81
|
+
// The file is quoted too: a list that cannot ride after all sends it, for less than agreed.
|
|
82
|
+
const range = plan[0];
|
|
83
|
+
const riding = storageAsk === null && range !== undefined && plan.length === 1
|
|
84
|
+
? await planWalletRide(ctx, protocol, seams.onRecoveryProblem, { ...file, streamPlaintextLen: sealFor(range), sealedLen: sealedBytes }) : null;
|
|
85
|
+
const quiltLen = riding?.quiltLen ?? null, lens = quiltLen === null ? sealedLens : [quiltLen];
|
|
86
|
+
const quoted = await reads.quoteParts(quiltLen === null ? sealedLens : [quiltLen, ...sealedLens], epochs);
|
|
87
|
+
const quotes = quoted.slice(0, lens.length);
|
|
79
88
|
// ⛔ THE ADDRESS THAT IS PRICED IS THE ADDRESS THAT SIGNS — the same wallet the rail carries,
|
|
80
89
|
// whether that is a number this key derives or a wallet the caller holds the key to.
|
|
81
90
|
const address = ctx.payer?.address ?? (await walletAddress(ctx.code, ctx.wallet));
|
|
@@ -108,7 +117,7 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
108
117
|
reads.readWallet(address),
|
|
109
118
|
reads.estimateRegisterGas({
|
|
110
119
|
sender: address,
|
|
111
|
-
sealedLen: Math.max(...
|
|
120
|
+
sealedLen: Math.max(...lens),
|
|
112
121
|
epochs,
|
|
113
122
|
storage: storage.kind === "buy"
|
|
114
123
|
? storage
|
|
@@ -119,7 +128,8 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
119
128
|
const review = {
|
|
120
129
|
name: file.name,
|
|
121
130
|
bytes: file.source.size,
|
|
122
|
-
sealedBytes,
|
|
131
|
+
sealedBytes: lens.reduce((sum, len) => sum + len, 0),
|
|
132
|
+
carriesRecoveryList: quiltLen !== null,
|
|
123
133
|
parts: plan.length,
|
|
124
134
|
epochs,
|
|
125
135
|
days: daysOf(window, epochs),
|
|
@@ -148,6 +158,20 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
148
158
|
seams.agree?.(review);
|
|
149
159
|
const sign = seams.sign ?? (await signers());
|
|
150
160
|
const onSpend = seams.onSpend ?? (() => undefined);
|
|
161
|
+
const rail = walletRail({
|
|
162
|
+
network: ctx.network,
|
|
163
|
+
code: ctx.code,
|
|
164
|
+
wallet: ctx.wallet,
|
|
165
|
+
...(ctx.payer === undefined ? {} : { payer: ctx.payer }),
|
|
166
|
+
relayUrl: protocol.relayUrl,
|
|
167
|
+
epochs,
|
|
168
|
+
storage,
|
|
169
|
+
quotes: quoted,
|
|
170
|
+
feeMist,
|
|
171
|
+
signRegister: sign.register,
|
|
172
|
+
signCertify: sign.certify,
|
|
173
|
+
onSpend,
|
|
174
|
+
});
|
|
151
175
|
const derived = ctx.crypt.kdf_derive(ctx.crypt.account_code_parse(ctx.code));
|
|
152
176
|
const dataKey = derived.slice(DERIVED.dataKey[0], DERIVED.dataKey[1]);
|
|
153
177
|
derived.fill(0);
|
|
@@ -168,20 +192,7 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
168
192
|
partSize: ctx.partSize,
|
|
169
193
|
padding: { rule: ctx.rule, unitBytes: CREDIT_BYTES },
|
|
170
194
|
...(seams.onStep === undefined ? {} : { onStep: seams.onStep }),
|
|
171
|
-
buy:
|
|
172
|
-
network: ctx.network,
|
|
173
|
-
code: ctx.code,
|
|
174
|
-
wallet: ctx.wallet,
|
|
175
|
-
...(ctx.payer === undefined ? {} : { payer: ctx.payer }),
|
|
176
|
-
relayUrl: protocol.relayUrl,
|
|
177
|
-
epochs,
|
|
178
|
-
storage,
|
|
179
|
-
quotes,
|
|
180
|
-
feeMist,
|
|
181
|
-
signRegister: sign.register,
|
|
182
|
-
signCertify: sign.certify,
|
|
183
|
-
onSpend,
|
|
184
|
-
}),
|
|
195
|
+
buy: riding === null ? rail : riding.ride.wrap(rail),
|
|
185
196
|
});
|
|
186
197
|
}
|
|
187
198
|
finally {
|
|
@@ -223,6 +234,8 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
223
234
|
replaced: added.replaced?.id ?? null,
|
|
224
235
|
fileListVersion: added.seq,
|
|
225
236
|
resumed: result.resumed,
|
|
237
|
+
// After the list names the file, so the account screen and the next list agree.
|
|
238
|
+
recoveryList: riding === null ? null : await riding.ride.record(),
|
|
226
239
|
};
|
|
227
240
|
}
|
|
228
241
|
async function defaultReads(network, relayUrl) {
|
package/dist/upload-wallet.d.ts
CHANGED
|
@@ -25,7 +25,10 @@ export interface WalletRailContext {
|
|
|
25
25
|
epochs: number;
|
|
26
26
|
/** Where the storage comes from. A held resource serves one blob, so it applies to a one-part file. */
|
|
27
27
|
storage: StorageChoice;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* What was quoted, by sealed length — what the grant ledger is told after each signature. Bytes of
|
|
30
|
+
* a length not here are refused before anything is signed.
|
|
31
|
+
*/
|
|
29
32
|
quotes: readonly PartQuote[];
|
|
30
33
|
/** The measured register fee, added to the ledger with the tip; null adds the tip alone. */
|
|
31
34
|
feeMist: bigint | null;
|
package/dist/upload-wallet.js
CHANGED
|
@@ -80,6 +80,17 @@ async function buyAndPushPartWithWallet(ctx, input) {
|
|
|
80
80
|
return paidPart((await readReservationRecord(key)) ?? existing, true);
|
|
81
81
|
}
|
|
82
82
|
// ── fresh, or interrupted before the signature ──
|
|
83
|
+
// ⛔ ONLY BYTES WHOSE PRICE WAS AGREED ARE REGISTERED. Storage is bought for the length the
|
|
84
|
+
// signature names, and a length nobody quoted would spend what nobody reviewed.
|
|
85
|
+
const quote = ctx.quotes.find((q) => q.sealedLen === sealed.length);
|
|
86
|
+
if (quote === undefined) {
|
|
87
|
+
throw new UploadError({
|
|
88
|
+
phase: "reserve",
|
|
89
|
+
message: `These ${sealed.length} bytes are not the ones this upload was priced for.`,
|
|
90
|
+
paid: false,
|
|
91
|
+
nextStep: "Nothing was signed. Running the same command again prices them first.",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
83
94
|
onStep?.({ step: "encoding", bytes: sealed.length });
|
|
84
95
|
let meta;
|
|
85
96
|
try {
|
|
@@ -119,9 +130,6 @@ async function buyAndPushPartWithWallet(ctx, input) {
|
|
|
119
130
|
// ⛔ BEFORE THE SIGNATURE. See the module header.
|
|
120
131
|
await writeReservation(key, record, sealed);
|
|
121
132
|
onStep?.({ step: "reserving" });
|
|
122
|
-
const quote = ctx.quotes[input.part.index];
|
|
123
|
-
if (quote === undefined)
|
|
124
|
-
throw new NmtsError("unreachable: a part with no quote");
|
|
125
133
|
let registered;
|
|
126
134
|
try {
|
|
127
135
|
registered = await ctx.signRegister({
|
|
@@ -171,6 +179,7 @@ async function push(input, record, registerTxDigest, blobObjectId, sealed) {
|
|
|
171
179
|
nonce: fromBase64Url(record.nonceB64),
|
|
172
180
|
registerTxDigest,
|
|
173
181
|
blobObjectId,
|
|
182
|
+
relayUrl: record.relayUrl,
|
|
174
183
|
});
|
|
175
184
|
}
|
|
176
185
|
catch (error) {
|
package/dist/upload-wire.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface Certificate {
|
|
|
16
16
|
serialized_message_b64: string;
|
|
17
17
|
signature_b64: string;
|
|
18
18
|
}
|
|
19
|
+
/** The largest sealed file a recovery list rides with — the browser's quilt line (`upload-recovery-patch.ts`). */
|
|
20
|
+
export declare const RIDE_CEILING_BYTES: number;
|
|
19
21
|
/** The Walrus protocol seam. The real one is in `walrus-write.ts`; the tests supply a fake. */
|
|
20
22
|
export interface BlobProtocol {
|
|
21
23
|
computeMetadata(input: {
|
|
@@ -28,7 +30,27 @@ export interface BlobProtocol {
|
|
|
28
30
|
nonce: Uint8Array;
|
|
29
31
|
registerTxDigest: string;
|
|
30
32
|
blobObjectId: string;
|
|
33
|
+
/**
|
|
34
|
+
* The road the registration was made for, from the record (D51). A part registered with no tip
|
|
35
|
+
* for the storage nodes must not go to a relay that checks for one on a resume.
|
|
36
|
+
*/
|
|
37
|
+
relayUrl?: string;
|
|
31
38
|
}): Promise<Certificate>;
|
|
39
|
+
/**
|
|
40
|
+
* Lay several byte runs out as one quilt, with each patch's place in it. Optional: a protocol
|
|
41
|
+
* without it uploads files as their own blobs, and no recovery list rides along.
|
|
42
|
+
*/
|
|
43
|
+
encodeQuilt?(blobs: readonly {
|
|
44
|
+
contents: Uint8Array;
|
|
45
|
+
identifier: string;
|
|
46
|
+
}[]): Promise<{
|
|
47
|
+
quilt: Uint8Array;
|
|
48
|
+
patches: readonly {
|
|
49
|
+
identifier: string;
|
|
50
|
+
startIndex: number;
|
|
51
|
+
endIndex: number;
|
|
52
|
+
}[];
|
|
53
|
+
}>;
|
|
32
54
|
}
|
|
33
55
|
/** The reservation as the server describes it. */
|
|
34
56
|
export interface ReserveReply {
|
|
@@ -233,6 +255,11 @@ export interface PaidPart {
|
|
|
233
255
|
suiObjectId?: string;
|
|
234
256
|
/** Wallet rail only: the epoch the bought storage ends at, read from the blob object. */
|
|
235
257
|
endEpoch?: number;
|
|
258
|
+
/**
|
|
259
|
+
* Set when the part is one patch of a quilt — `blobId` is then the quilt and `sealedLen` this
|
|
260
|
+
* part's own stream, not the quilt's length.
|
|
261
|
+
*/
|
|
262
|
+
patchId?: string;
|
|
236
263
|
}
|
|
237
264
|
/** What finished. The caller writes the file list, THEN clears the records. */
|
|
238
265
|
export interface UploadResult {
|
package/dist/upload-wire.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// and means the file that DOES spend stays short enough to read in one sitting.
|
|
7
7
|
import { HttpError, ServerError } from "./api.js";
|
|
8
8
|
import { NmtsError } from "./errors.js";
|
|
9
|
+
/** The largest sealed file a recovery list rides with — the browser's quilt line (`upload-recovery-patch.ts`). */
|
|
10
|
+
export const RIDE_CEILING_BYTES = 64 * 1024 * 1024;
|
|
9
11
|
/**
|
|
10
12
|
* A failure that names its phase — and, crucially, whether the account has already paid.
|
|
11
13
|
*
|
package/dist/upload.js
CHANGED
|
@@ -32,7 +32,7 @@ import { ServerError } from "./api.js";
|
|
|
32
32
|
import { readReservationBytes, readReservationRecord, writeReservation, } from "./upload-store.js";
|
|
33
33
|
import { refuseOtherSealing, runIdField } from "./upload-run.js";
|
|
34
34
|
import { pushPart } from "./upload-steps.js";
|
|
35
|
-
import {
|
|
35
|
+
import { isTipFree } from "./upload-road.js";
|
|
36
36
|
import { UploadError, } from "./upload-wire.js";
|
|
37
37
|
export * from "./upload-wire.js";
|
|
38
38
|
/** A reservation state that can still become storage. Anything else is dead. */
|
|
@@ -202,8 +202,8 @@ export async function buyAndPushPart(input) {
|
|
|
202
202
|
size: sealed.length,
|
|
203
203
|
epochs: input.epochs,
|
|
204
204
|
deposit_credits: input.depositCredits,
|
|
205
|
-
// The own relay (D50)
|
|
206
|
-
relay:
|
|
205
|
+
// The own relay (D50) and the storage nodes (D51) take no tip, so the treasury registers without one.
|
|
206
|
+
relay: isTipFree(input.relayUrl)
|
|
207
207
|
? null
|
|
208
208
|
: { host: input.relayUrl, blob_digest_b64: toBase64Url(meta.blobDigest), nonce_b64: nonceB64 },
|
|
209
209
|
});
|
package/dist/walrus-write.js
CHANGED
|
@@ -17,9 +17,11 @@ import { epochStartedMs as readEpochStart } from "./shared/lib/extend/epochs.js"
|
|
|
17
17
|
import { NmtsError } from "./errors.js";
|
|
18
18
|
import { countingFetch } from "./progress.js";
|
|
19
19
|
import { reachFetch } from "./reach.js";
|
|
20
|
-
import { isOwnRelay, relayFetch, uploadRelay } from "./upload-road.js";
|
|
20
|
+
import { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch, uploadRelay } from "./upload-road.js";
|
|
21
21
|
import { storageNodesThrough } from "./walrus.js";
|
|
22
22
|
import { suiClient } from "./sui-rpc.js";
|
|
23
|
+
import { stopAtQuorum } from "./shared/lib/walrus/node-quorum.js";
|
|
24
|
+
import { certifyByShardWeight } from "./shared/lib/walrus/node-certificate.js";
|
|
23
25
|
/**
|
|
24
26
|
* How long the relay gets for one blob PUT, sized to the body.
|
|
25
27
|
*
|
|
@@ -43,6 +45,29 @@ export function relayTimeoutMs(bodyBytes) {
|
|
|
43
45
|
* two level: the browser's number bounds a real payment made by a real wallet.
|
|
44
46
|
*/
|
|
45
47
|
const TIP_CEILING_UNUSED_MIST = 1;
|
|
48
|
+
/** What the storage nodes receive for one blob, about five times the blob (the erasure code). */
|
|
49
|
+
const NODE_WRITE_EXPANSION = 5;
|
|
50
|
+
/**
|
|
51
|
+
* A client with no relay, writing to the storage nodes itself (D51). Progress is the bodies the
|
|
52
|
+
* nodes accepted, counted in the blob's own bytes, and it stops just short of the end until the
|
|
53
|
+
* certificate is in.
|
|
54
|
+
*/
|
|
55
|
+
function direct(network, bodyBytes, onSent) {
|
|
56
|
+
let sent = 0;
|
|
57
|
+
const counted = async (input, init) => {
|
|
58
|
+
const res = await reachFetch(input, init);
|
|
59
|
+
const body = init?.body;
|
|
60
|
+
if (onSent && res.ok && body instanceof Uint8Array) {
|
|
61
|
+
sent += body.length;
|
|
62
|
+
onSent(Math.min(Math.floor(sent / NODE_WRITE_EXPANSION), Math.floor(bodyBytes * 0.99)), bodyBytes);
|
|
63
|
+
}
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
// The SDK would wait for every node; `stopAtQuorum` stops a little after a quorum confirmed (D51).
|
|
67
|
+
const client = suiClient(network === "mainnet" ? "mainnet" : "testnet").$extend(walrus({ storageNodeClientOptions: { fetch: counted, timeout: relayTimeoutMs(bodyBytes) } }));
|
|
68
|
+
certifyByShardWeight(stopAtQuorum(client.walrus));
|
|
69
|
+
return client;
|
|
70
|
+
}
|
|
46
71
|
function extend(network, relayUrl, bodyBytes, onSent) {
|
|
47
72
|
// ⛔ The network name reaches the SDK as well as the URL. A node pointed at the wrong chain
|
|
48
73
|
// would otherwise be discovered as a blob the storage nodes refuse, after the money moved.
|
|
@@ -76,7 +101,9 @@ function fail(what, error) {
|
|
|
76
101
|
*/
|
|
77
102
|
export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
78
103
|
const relayUrl = uploadRelay(network);
|
|
79
|
-
|
|
104
|
+
// On the direct road this relay-shaped client computes the id, and carries a part to the own
|
|
105
|
+
// relay when the nodes did not take it; the bytes go to the nodes first.
|
|
106
|
+
const client = extend(network, isNodeRoad(relayUrl) ? (ownRelayFallback() ?? relayUrl) : relayUrl, bodyBytes, onSent);
|
|
80
107
|
return {
|
|
81
108
|
relayUrl,
|
|
82
109
|
async computeMetadata({ bytes, nonce }) {
|
|
@@ -101,7 +128,17 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
101
128
|
blobDigest: await meta.blobDigest(),
|
|
102
129
|
};
|
|
103
130
|
},
|
|
104
|
-
async uploadToRelay({ blobId, bytes, nonce, registerTxDigest, blobObjectId }) {
|
|
131
|
+
async uploadToRelay({ blobId, bytes, nonce, registerTxDigest, blobObjectId, relayUrl: registeredFor }) {
|
|
132
|
+
if (isNodeRoad(registeredFor ?? relayUrl)) {
|
|
133
|
+
try {
|
|
134
|
+
return await writeToNodes(direct(network, bodyBytes, onSent), blobId, bytes, blobObjectId);
|
|
135
|
+
}
|
|
136
|
+
catch (nodeError) {
|
|
137
|
+
// The registration is road-free (no tip on either), so the same part can go to the own relay.
|
|
138
|
+
if (ownRelayFallback() === null || !isNodeRoad(relayUrl))
|
|
139
|
+
fail("The storage nodes did not take the bytes", nodeError);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
105
142
|
const { certificate } = await client.walrus
|
|
106
143
|
.writeBlobToUploadRelay({
|
|
107
144
|
blobId,
|
|
@@ -120,6 +157,46 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
120
157
|
signature_b64: toBase64Url(certificate.signature),
|
|
121
158
|
};
|
|
122
159
|
},
|
|
160
|
+
async encodeQuilt(blobs) {
|
|
161
|
+
// ⛔ THE SDK'S OWN LAYOUT, the one the browser's `writeFilesFlow` uses — patches sorted by
|
|
162
|
+
// identifier, the shard count read from the chain — so an aggregator reads a patch of this
|
|
163
|
+
// quilt by name exactly as it reads one the browser wrote (spec 2026-09-20 unit B).
|
|
164
|
+
const { quilt, index } = await client.walrus
|
|
165
|
+
.encodeQuilt({ blobs: blobs.map((b) => ({ contents: b.contents, identifier: b.identifier })) })
|
|
166
|
+
.catch((error) => fail("The storage network's encoder could not build the quilt", error));
|
|
167
|
+
return {
|
|
168
|
+
quilt,
|
|
169
|
+
patches: index.patches.map((p) => ({ identifier: p.identifier, startIndex: p.startIndex, endIndex: p.endIndex })),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Write one registered blob to the storage nodes and gather their signatures into the certificate
|
|
176
|
+
* the certify step needs: the same shape a relay hands back.
|
|
177
|
+
*/
|
|
178
|
+
async function writeToNodes(client, blobId, bytes, blobObjectId) {
|
|
179
|
+
const encoded = await client.walrus.encodeBlob(bytes);
|
|
180
|
+
// The id was computed and registered before; bytes that encode to another id would be refused.
|
|
181
|
+
if (encoded.blobId !== blobId)
|
|
182
|
+
throw new Error(`the bytes encode to ${encoded.blobId}, not the registered ${blobId}`);
|
|
183
|
+
const confirmations = await client.walrus.writeEncodedBlobToNodes({
|
|
184
|
+
blobId,
|
|
185
|
+
objectId: blobObjectId,
|
|
186
|
+
metadata: encoded.metadata,
|
|
187
|
+
sliversByNode: encoded.sliversByNode,
|
|
188
|
+
deletable: true,
|
|
189
|
+
});
|
|
190
|
+
const certificate = await client.walrus.certificateFromConfirmations({
|
|
191
|
+
confirmations,
|
|
192
|
+
blobId,
|
|
193
|
+
blobObjectId,
|
|
194
|
+
deletable: true,
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
signers: certificate.signers,
|
|
198
|
+
serialized_message_b64: toBase64Url(certificate.serializedMessage),
|
|
199
|
+
signature_b64: toBase64Url(certificate.signature),
|
|
123
200
|
};
|
|
124
201
|
}
|
|
125
202
|
/**
|