@needmoretruth/nmts-cli 0.41.0 → 0.42.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 +7 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/api.js +2 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/extend-chain.js +2 -1
- package/dist/portable.d.ts +3 -0
- package/dist/portable.js +8 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/progress.d.ts +4 -0
- package/dist/progress.js +7 -2
- package/dist/reach.d.ts +40 -0
- package/dist/reach.js +52 -0
- package/dist/sui-rpc.js +2 -1
- package/dist/upload-wallet-chain.js +6 -1
- package/dist/walrus-write.js +9 -4
- package/dist/walrus.d.ts +33 -6
- package/dist/walrus.js +48 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
Each version's entry is what changed for the person or the program using `nmts`. The product's own
|
|
4
4
|
update history, which covers the site and the server too, is at https://nmts.me/updates.
|
|
5
5
|
|
|
6
|
+
## 0.42.0 — 2026-09-20
|
|
7
|
+
|
|
8
|
+
- Nothing changes for the `nmts` command. The library surface gains one seam for programs built on
|
|
9
|
+
it: a caller can name the upload relay, the Sui nodes and the aggregators, and hand over the
|
|
10
|
+
`fetch` function every request goes through (`@needmoretruth/nmts-cli/portable`: `useReach`). The
|
|
11
|
+
command reads its addresses from the environment as before and sets none of it.
|
|
12
|
+
|
|
6
13
|
## 0.41.0 — 2026-09-20
|
|
7
14
|
|
|
8
15
|
- **Wallet login.** `nmts login --wallet --sui-key-file <file>` signs in with a Sui wallet, and
|
package/README.ko.md
CHANGED
|
@@ -50,7 +50,7 @@ nmts --help
|
|
|
50
50
|
|
|
51
51
|
```sh
|
|
52
52
|
npm install -g github:needmoretruth/nmts-cli # 기본 브랜치
|
|
53
|
-
npm install -g github:needmoretruth/nmts-cli#v0.
|
|
53
|
+
npm install -g github:needmoretruth/nmts-cli#v0.42.0 # 버전을 고정할 때
|
|
54
54
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
55
55
|
```
|
|
56
56
|
|
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ default branch, from a pinned version, or from the tarball attached to the
|
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
53
|
npm install -g github:needmoretruth/nmts-cli # the default branch
|
|
54
|
-
npm install -g github:needmoretruth/nmts-cli#v0.
|
|
54
|
+
npm install -g github:needmoretruth/nmts-cli#v0.42.0 # a pinned version
|
|
55
55
|
npm install -g https://github.com/needmoretruth/nmts-cli/releases/latest/download/nmts.tgz
|
|
56
56
|
```
|
|
57
57
|
|
package/dist/api.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { adviseFor } from "./api-advice.js";
|
|
14
14
|
import { NmtsError } from "./errors.js";
|
|
15
15
|
import { isTransient, keepTrying } from "./net-retry.js";
|
|
16
|
+
import { reachFetch } from "./reach.js";
|
|
16
17
|
import { noteRequest } from "./run-log.js";
|
|
17
18
|
/** Default deadline for a request that is not moving file bytes. */
|
|
18
19
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -109,7 +110,7 @@ async function once(base, path, options) {
|
|
|
109
110
|
const init = { method, headers, signal: controller.signal };
|
|
110
111
|
if (body !== undefined)
|
|
111
112
|
init.body = JSON.stringify(body);
|
|
112
|
-
response = await
|
|
113
|
+
response = await reachFetch(`${base}${path}`, init);
|
|
113
114
|
}
|
|
114
115
|
catch (error) {
|
|
115
116
|
// ⛔ The cause is named, not swallowed: "fetch failed" alone sends an agent looking at its own
|
package/dist/artifact-about.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const CRYPTO_SPEC_URL = "https://github.com/needmoretruth/nmts-re
|
|
|
11
11
|
* is the field's own contract — what the writer says about itself — and a person holding two
|
|
12
12
|
* copies of one account's artefacts can then tell which program made each.
|
|
13
13
|
*/
|
|
14
|
-
export declare const WRITTEN_BY = "nmts-cli 0.
|
|
14
|
+
export declare const WRITTEN_BY = "nmts-cli 0.42.0";
|
|
15
15
|
/** Which of the three artefacts a wrapper is. A reader holding several can sort them. */
|
|
16
16
|
export type ArtifactKind = "recovery-list" | "file-list" | "recovery-kit";
|
|
17
17
|
/**
|
package/dist/extend-chain.js
CHANGED
|
@@ -21,6 +21,7 @@ import { NmtsError } from "./errors.js";
|
|
|
21
21
|
import { epochClock } from "./expiry.js";
|
|
22
22
|
import { isRecord } from "./guards.js";
|
|
23
23
|
import { epochStartedMs } from "./walrus-write.js";
|
|
24
|
+
import { storageNodesThrough } from "./walrus.js";
|
|
24
25
|
import { suiRpcTransport } from "./sui-rpc.js";
|
|
25
26
|
import { readBalances, walCoinType } from "./wallet.js";
|
|
26
27
|
import { chainReader } from "./wallet-chain.js";
|
|
@@ -41,7 +42,7 @@ function build(network) {
|
|
|
41
42
|
return new SuiJsonRpcClient({
|
|
42
43
|
network: network === "mainnet" ? "mainnet" : "testnet",
|
|
43
44
|
transport: suiRpcTransport(network),
|
|
44
|
-
}).$extend(walrus(
|
|
45
|
+
}).$extend(walrus(storageNodesThrough()));
|
|
45
46
|
}
|
|
46
47
|
/** A number off the wire, whether it arrived as a number or as one of Sui's 64-bit strings. */
|
|
47
48
|
function numberOf(value) {
|
package/dist/portable.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { forgetHost, host, hostIsRegistered, registerHost } from "./host.ts";
|
|
2
2
|
export type { EngineHost, Host, HostName, StateHost, ZstdHost } from "./host.ts";
|
|
3
3
|
export { hostContract } from "./host-contract.ts";
|
|
4
|
+
export { forgetReach, reach, reachFetch, useReach } from "./reach.ts";
|
|
5
|
+
export type { Reach } from "./reach.ts";
|
|
4
6
|
export { concat, fromBase64Url, fromUtf8, toBase64Url, utf8 } from "./bytes.ts";
|
|
5
7
|
export { setZstdCodec, zstdCodec, zstdContentSize } from "./shared/lib/drive/zstd.ts";
|
|
6
8
|
export type { ZstdCodec } from "./shared/lib/drive/zstd.ts";
|
|
@@ -46,6 +48,7 @@ export { fetchFile, fetchWithKey } from "./download.ts";
|
|
|
46
48
|
export type { FetchedFile, FetchInput } from "./download.ts";
|
|
47
49
|
export type { PlaintextSink } from "./download-sink.ts";
|
|
48
50
|
export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./walrus.ts";
|
|
51
|
+
export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.ts";
|
|
49
52
|
export type { ReadOptions } from "./walrus.ts";
|
|
50
53
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.ts";
|
|
51
54
|
export type { ChainReader, CoinBalance, WalletBalances } from "./wallet.ts";
|
package/dist/portable.js
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
// The host every module below reaches for. A program that imported this entry point registers one.
|
|
20
20
|
export { forgetHost, host, hostIsRegistered, registerHost } from "./host.js";
|
|
21
21
|
export { hostContract } from "./host-contract.js";
|
|
22
|
+
// Where a caller says this client talks, and what it talks through — the addresses the
|
|
23
|
+
// command-line tool takes from its environment, and the one `fetch` every request here goes
|
|
24
|
+
// through. A library's caller has no environment to write, so this is how it says the same things.
|
|
25
|
+
export { forgetReach, reach, reachFetch, useReach } from "./reach.js";
|
|
22
26
|
// Bytes to text and back, in the two spellings the format uses.
|
|
23
27
|
export { concat, fromBase64Url, fromUtf8, toBase64Url, utf8 } from "./bytes.js";
|
|
24
28
|
// The file-list codec's zstd register (NCF-3 §6.3.4). A host fills it with the encoder its runtime
|
|
@@ -66,6 +70,10 @@ export { DEFAULT_UPLOAD_EPOCHS } from "./upload-wallet-plan.js";
|
|
|
66
70
|
// Downloading: fetching sealed parts from the storage network and opening them here.
|
|
67
71
|
export { fetchFile, fetchWithKey } from "./download.js";
|
|
68
72
|
export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./walrus.js";
|
|
73
|
+
// ⛔ THE THREE ADDRESS ANSWERS, so that a caller — and a test — can ask what this client WILL talk
|
|
74
|
+
// to rather than finding out from a request that went somewhere else. Each reads what the
|
|
75
|
+
// caller said first, then the environment, then the network's own.
|
|
76
|
+
export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.js";
|
|
69
77
|
// The wallet the NMTS key derives: reading it, and signing with it.
|
|
70
78
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.js";
|
|
71
79
|
export { chainReader } from "./wallet-chain.js";
|
package/dist/product.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const BINARY_NAME = "nmts";
|
|
|
9
9
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
10
10
|
* command importing the entry point is a cycle waiting to bite.
|
|
11
11
|
*/
|
|
12
|
-
export declare const VERSION = "0.
|
|
12
|
+
export declare const VERSION = "0.42.0";
|
|
13
13
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
14
14
|
export declare const HOME_URL = "https://nmts.me";
|
|
15
15
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/product.js
CHANGED
|
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
|
|
|
18
18
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
19
19
|
* command importing the entry point is a cycle waiting to bite.
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.
|
|
21
|
+
export const VERSION = "0.42.0";
|
|
22
22
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
23
23
|
export const HOME_URL = "https://nmts.me";
|
|
24
24
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/progress.d.ts
CHANGED
|
@@ -32,5 +32,9 @@ export declare class Progress {
|
|
|
32
32
|
*
|
|
33
33
|
* ⚠ `duplex: "half"` is required by the fetch specification for a streaming body and Node enforces
|
|
34
34
|
* it. Without it the request throws before a single byte is sent.
|
|
35
|
+
*
|
|
36
|
+
* ⛔ IT WRAPS `reachFetch`, NOT THE GLOBAL. Counting the bytes must not be a way around the
|
|
37
|
+
* function a caller asked every request to go through — this is the one request in an upload
|
|
38
|
+
* that carries the file.
|
|
35
39
|
*/
|
|
36
40
|
export declare function countingFetch(onSent: (sent: number, total: number) => void, chunkBytes?: number): (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
package/dist/progress.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// ⛔ THE TERMINAL SINK IS NOT HERE. Writing to a real stderr is Node's, so it is in
|
|
12
12
|
// `progress-node.ts`; what is left runs in a page, where the same reporter drives a caller's
|
|
13
13
|
// own `onProgress`.
|
|
14
|
+
import { reachFetch } from "./reach.js";
|
|
14
15
|
/** A reporter that says nothing. What `--json` gets, and what a test gets by default. */
|
|
15
16
|
export function silentSink() {
|
|
16
17
|
return { write: () => { }, interactive: false };
|
|
@@ -71,12 +72,16 @@ export class Progress {
|
|
|
71
72
|
*
|
|
72
73
|
* ⚠ `duplex: "half"` is required by the fetch specification for a streaming body and Node enforces
|
|
73
74
|
* it. Without it the request throws before a single byte is sent.
|
|
75
|
+
*
|
|
76
|
+
* ⛔ IT WRAPS `reachFetch`, NOT THE GLOBAL. Counting the bytes must not be a way around the
|
|
77
|
+
* function a caller asked every request to go through — this is the one request in an upload
|
|
78
|
+
* that carries the file.
|
|
74
79
|
*/
|
|
75
80
|
export function countingFetch(onSent, chunkBytes = 256 * 1024) {
|
|
76
81
|
return async (url, init) => {
|
|
77
82
|
const body = init?.body;
|
|
78
83
|
if (!(body instanceof Uint8Array))
|
|
79
|
-
return
|
|
84
|
+
return reachFetch(url, init);
|
|
80
85
|
const total = body.length;
|
|
81
86
|
let sent = 0;
|
|
82
87
|
const stream = new ReadableStream({
|
|
@@ -101,6 +106,6 @@ export function countingFetch(onSent, chunkBytes = 256 * 1024) {
|
|
|
101
106
|
if (!headers.has("content-length"))
|
|
102
107
|
headers.set("content-length", String(total));
|
|
103
108
|
next.headers = headers;
|
|
104
|
-
return
|
|
109
|
+
return reachFetch(url, next);
|
|
105
110
|
};
|
|
106
111
|
}
|
package/dist/reach.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** What a caller may say about where this client talks, and what it talks through. */
|
|
2
|
+
export interface Reach {
|
|
3
|
+
/**
|
|
4
|
+
* The storage network's upload relay to write through, instead of the network's own.
|
|
5
|
+
*
|
|
6
|
+
* ⚠ ONE host, not a list: the relay is named inside the transaction that pays its tip, so a
|
|
7
|
+
* write picks its host before the storage is bought and never moves.
|
|
8
|
+
*/
|
|
9
|
+
relay?: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The Sui JSON-RPC endpoints to ask, in order, instead of the network's own.
|
|
12
|
+
*
|
|
13
|
+
* ⛔ IT REPLACES THE LIST rather than adding to it — somebody who names a node is saying *those*,
|
|
14
|
+
* and quietly reaching a public mirror as well would send their traffic somewhere they did
|
|
15
|
+
* not choose.
|
|
16
|
+
*/
|
|
17
|
+
suiRpc?: readonly string[] | undefined;
|
|
18
|
+
/** Hosts to read stored bytes from, instead of the public aggregators for the network. */
|
|
19
|
+
aggregators?: readonly string[] | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The function every request this package makes goes through. Absent, the runtime's own.
|
|
22
|
+
*
|
|
23
|
+
* It is where a proxy goes: an agent, a SOCKS tunnel, a recorder, a counter. Nothing about a
|
|
24
|
+
* proxy is built into this package, because one function is the whole of what it would need.
|
|
25
|
+
*/
|
|
26
|
+
fetch?: typeof fetch | undefined;
|
|
27
|
+
}
|
|
28
|
+
/** What the caller has said. */
|
|
29
|
+
export declare function reach(): Reach;
|
|
30
|
+
/** Tell this package what the caller chose. Fields that are absent leave what was there. */
|
|
31
|
+
export declare function useReach(next: Reach): void;
|
|
32
|
+
/** Start again with nothing — the runtime's own addresses and its own `fetch`. For tests. */
|
|
33
|
+
export declare function forgetReach(): void;
|
|
34
|
+
/**
|
|
35
|
+
* The one function every request in this package goes through.
|
|
36
|
+
*
|
|
37
|
+
* With nothing injected it is the runtime's `fetch`, called as the runtime's own — which is what
|
|
38
|
+
* the command-line tool has always done, byte for byte.
|
|
39
|
+
*/
|
|
40
|
+
export declare const reachFetch: typeof fetch;
|
package/dist/reach.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Where this program talks, and what it talks through — the caller's answer, not the runtime's.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ WHY THIS IS NOT THE HOST. `host.ts` holds what a RUNTIME provides: an engine, a store, an
|
|
4
|
+
// environment, somewhere for progress to go, a zstd encoder. What is here is what a CALLER
|
|
5
|
+
// chose: a relay, a set of Sui nodes, a set of aggregators, and the function every request goes
|
|
6
|
+
// through. The command-line tool sets none of it and reads its addresses out of the environment
|
|
7
|
+
// exactly as it always has; a library's caller has no environment to write, and until this file
|
|
8
|
+
// existed the options it passed for two of those addresses were read only by the browser host —
|
|
9
|
+
// silently ignored on Node, which is the defect this fixes.
|
|
10
|
+
//
|
|
11
|
+
// ⛔ AN OPTION THAT WAS PASSED IS HONOURED ON EVERY HOST, or refused by name. Nothing in this
|
|
12
|
+
// package may quietly reach an address the caller did not choose: for somebody routing their
|
|
13
|
+
// traffic through a proxy, one leak makes the proxy a lie rather than a weaker promise.
|
|
14
|
+
//
|
|
15
|
+
// ⛔ IT IS READ AT THE MOMENT OF THE REQUEST, not copied when a client is made. `reachFetch` looks
|
|
16
|
+
// the function up on every call, so a caller that set one after building its client is not
|
|
17
|
+
// holding a stale copy.
|
|
18
|
+
//
|
|
19
|
+
// ⚠ ONE PER PROCESS, AND THE LAST WRITER WINS THE FIELDS IT NAMES. This is the same arrangement
|
|
20
|
+
// the SDK's `host-options.ts` already describes for a page: two clients pointed at different
|
|
21
|
+
// relays would be two answers to a question with one answer. On a server that means two clients
|
|
22
|
+
// with two different proxies share whichever was set last — said here rather than discovered.
|
|
23
|
+
//
|
|
24
|
+
// ⛔ NO `node:` IMPORT, EVER. This file is reachable from `portable.ts`, which promises that.
|
|
25
|
+
let current = {};
|
|
26
|
+
/** What the caller has said. */
|
|
27
|
+
export function reach() {
|
|
28
|
+
return current;
|
|
29
|
+
}
|
|
30
|
+
/** Tell this package what the caller chose. Fields that are absent leave what was there. */
|
|
31
|
+
export function useReach(next) {
|
|
32
|
+
const merged = { ...current };
|
|
33
|
+
for (const key of Object.keys(next)) {
|
|
34
|
+
if (next[key] !== undefined)
|
|
35
|
+
Reflect.set(merged, key, next[key]);
|
|
36
|
+
}
|
|
37
|
+
current = merged;
|
|
38
|
+
}
|
|
39
|
+
/** Start again with nothing — the runtime's own addresses and its own `fetch`. For tests. */
|
|
40
|
+
export function forgetReach() {
|
|
41
|
+
current = {};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The one function every request in this package goes through.
|
|
45
|
+
*
|
|
46
|
+
* With nothing injected it is the runtime's `fetch`, called as the runtime's own — which is what
|
|
47
|
+
* the command-line tool has always done, byte for byte.
|
|
48
|
+
*/
|
|
49
|
+
export const reachFetch = (input, init) => {
|
|
50
|
+
const given = current.fetch;
|
|
51
|
+
return given === undefined ? globalThis.fetch(input, init) : given(input, init);
|
|
52
|
+
};
|
package/dist/sui-rpc.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// ⛔ NOT A RETRIER. Each host is asked once. Anything other than "no answer" — any 4xx that is not
|
|
10
10
|
// 429 — is an answer, and asking a different node the same question gets the same one.
|
|
11
11
|
import { JsonRpcHTTPTransport } from "@mysten/sui/jsonRpc";
|
|
12
|
+
import { reachFetch } from "./reach.js";
|
|
12
13
|
import { suiRpcHosts } from "./walrus.js";
|
|
13
14
|
/** HTTP statuses that mean "no answer came", the only ones worth asking a second node about. */
|
|
14
15
|
function worthAnotherHost(status) {
|
|
@@ -39,7 +40,7 @@ export function suiRpcTransport(network) {
|
|
|
39
40
|
if (host === undefined)
|
|
40
41
|
continue;
|
|
41
42
|
try {
|
|
42
|
-
const res = await
|
|
43
|
+
const res = await reachFetch(new URL(asked.pathname + asked.search, host), init);
|
|
43
44
|
if (worthAnotherHost(res.status) && step < hosts.length - 1) {
|
|
44
45
|
lastError = new Error(`${host} answered ${res.status}`);
|
|
45
46
|
continue;
|
|
@@ -24,8 +24,10 @@ import { blobIdFromInt, blobIdToInt, MAINNET_WALRUS_PACKAGE_CONFIG, TESTNET_WALR
|
|
|
24
24
|
import { fromBase64Url } from "./bytes.js";
|
|
25
25
|
import { NmtsError } from "./errors.js";
|
|
26
26
|
import { extendReads, netGasFee, readBlobLease } from "./extend-chain.js";
|
|
27
|
+
import { reachFetch } from "./reach.js";
|
|
27
28
|
import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
|
|
28
29
|
import { registerIntoStorage, splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
30
|
+
import { storageNodesThrough } from "./walrus.js";
|
|
29
31
|
import { suiRpcTransport } from "./sui-rpc.js";
|
|
30
32
|
import { readBalances, walCoinType } from "./wallet.js";
|
|
31
33
|
import { chainReader } from "./wallet-chain.js";
|
|
@@ -46,7 +48,10 @@ export function packageConfig(network) {
|
|
|
46
48
|
return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
|
|
47
49
|
}
|
|
48
50
|
function build(network, relayUrl) {
|
|
49
|
-
return new SuiJsonRpcClient({ network, transport: suiRpcTransport(network) }).$extend(walrus({
|
|
51
|
+
return new SuiJsonRpcClient({ network, transport: suiRpcTransport(network) }).$extend(walrus({
|
|
52
|
+
...storageNodesThrough(),
|
|
53
|
+
uploadRelay: { host: relayUrl, sendTip: { max: RELAY_TIP_CEILING_MIST[network] }, fetch: reachFetch },
|
|
54
|
+
}));
|
|
50
55
|
}
|
|
51
56
|
/** A Walrus client bound to ONE relay, able to pay that relay's tip. */
|
|
52
57
|
export function payingClient(network, relayUrl) {
|
package/dist/walrus-write.js
CHANGED
|
@@ -17,7 +17,8 @@ import { epochClock } from "./expiry.js";
|
|
|
17
17
|
import { epochStartedMs as readEpochStart } from "./shared/lib/extend/epochs.js";
|
|
18
18
|
import { NmtsError } from "./errors.js";
|
|
19
19
|
import { countingFetch } from "./progress.js";
|
|
20
|
-
import {
|
|
20
|
+
import { reachFetch } from "./reach.js";
|
|
21
|
+
import { relayHost, storageNodesThrough } from "./walrus.js";
|
|
21
22
|
import { suiRpcTransport } from "./sui-rpc.js";
|
|
22
23
|
/**
|
|
23
24
|
* How long the relay gets for one blob PUT, sized to the body.
|
|
@@ -50,6 +51,7 @@ function extend(network, relayUrl, bodyBytes, onSent) {
|
|
|
50
51
|
transport: suiRpcTransport(network),
|
|
51
52
|
});
|
|
52
53
|
return base.$extend(walrus({
|
|
54
|
+
...storageNodesThrough(),
|
|
53
55
|
uploadRelay: {
|
|
54
56
|
host: relayUrl,
|
|
55
57
|
sendTip: { max: TIP_CEILING_UNUSED_MIST },
|
|
@@ -58,7 +60,10 @@ function extend(network, relayUrl, bodyBytes, onSent) {
|
|
|
58
60
|
// PUT is the one step of an upload that takes real time — a person watching a large
|
|
59
61
|
// file with no feedback cannot tell a slow upload from a hung one, and neither can an
|
|
60
62
|
// agent deciding whether to give up.
|
|
61
|
-
|
|
63
|
+
//
|
|
64
|
+
// ⛔ AND EITHER WAY IT IS THE CALLER'S `fetch`: the counting wrapper goes through it too,
|
|
65
|
+
// so the request that carries the file cannot be the one that misses a proxy.
|
|
66
|
+
fetch: onSent ? countingFetch(onSent) : reachFetch,
|
|
62
67
|
},
|
|
63
68
|
}));
|
|
64
69
|
}
|
|
@@ -131,7 +136,7 @@ export async function readCurrentEpoch(network) {
|
|
|
131
136
|
const base = new SuiJsonRpcClient({
|
|
132
137
|
network: network === "mainnet" ? "mainnet" : "testnet",
|
|
133
138
|
transport: suiRpcTransport(network),
|
|
134
|
-
}).$extend(walrus(
|
|
139
|
+
}).$extend(walrus(storageNodesThrough()));
|
|
135
140
|
// The epoch lives on the COMMITTEE, not beside it: the system state describes capacity and
|
|
136
141
|
// the deny lists as well, and only the committee is stamped with which epoch it serves.
|
|
137
142
|
const state = await base.walrus.systemState();
|
|
@@ -162,7 +167,7 @@ export async function readEpochWindow(network) {
|
|
|
162
167
|
const base = new SuiJsonRpcClient({
|
|
163
168
|
network: network === "mainnet" ? "mainnet" : "testnet",
|
|
164
169
|
transport: suiRpcTransport(network),
|
|
165
|
-
}).$extend(walrus(
|
|
170
|
+
}).$extend(walrus(storageNodesThrough()));
|
|
166
171
|
const [system, staking] = await Promise.all([base.walrus.systemState(), base.walrus.stakingState()]);
|
|
167
172
|
// Both numbers can arrive as strings — Sui reports 64-bit values that way — so they are
|
|
168
173
|
// converted here and the constructor below refuses whatever did not survive it.
|
package/dist/walrus.d.ts
CHANGED
|
@@ -29,19 +29,46 @@ export declare const SUI_RPC_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
|
29
29
|
/** How long one host gets before the next is tried. A read that stalls is a read that failed. */
|
|
30
30
|
export declare const READ_TIMEOUT_MS = 60000;
|
|
31
31
|
export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.ts";
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* The relay this run writes through: the caller's if it named one, then the environment's, then
|
|
34
|
+
* the network's.
|
|
35
|
+
*
|
|
36
|
+
* ⛔ THE CALLER COMES FIRST AND IS READ ON EVERY HOST. A library's caller has no environment to
|
|
37
|
+
* write, and until this order existed the `relay` option was answered by the browser host alone
|
|
38
|
+
* — so a program on a server named a relay and its bytes went to the public one, silently.
|
|
39
|
+
*/
|
|
33
40
|
export declare function relayHost(network: string): string;
|
|
34
41
|
/**
|
|
35
|
-
* Every Sui JSON-RPC node this run may ask, in order
|
|
42
|
+
* Every Sui JSON-RPC node this run may ask, in order: the caller's list if it named one, then the
|
|
43
|
+
* environment's, then the network's.
|
|
36
44
|
*
|
|
37
|
-
* ⛔ Naming
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
45
|
+
* ⛔ Naming nodes REPLACES the list rather than adding to it — the same rule the aggregator
|
|
46
|
+
* override follows, and for the same reason: somebody who names a node is saying *those*, and
|
|
47
|
+
* quietly reaching a public mirror instead would send their traffic somewhere they did not
|
|
48
|
+
* choose.
|
|
49
|
+
*
|
|
50
|
+
* ⚠ THE CALLER MAY NAME SEVERAL AND A VARIABLE MAY NAME ONE. The failover below is the same
|
|
51
|
+
* either way; a single name is a list of one.
|
|
41
52
|
*/
|
|
42
53
|
export declare function suiRpcHosts(network: string): readonly string[];
|
|
43
54
|
/** The node whose address gets RECORDED — the first one, since that is the one normally asked. */
|
|
44
55
|
export declare function suiRpcHost(network: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* What a storage-network client talks to the storage nodes through, spread into its options.
|
|
58
|
+
*
|
|
59
|
+
* ⚠ THIS TOOL DOES NOT NORMALLY REACH A STORAGE NODE — it writes through an upload relay and reads
|
|
60
|
+
* through an aggregator. The option is filled anyway, because the one path that fell back to a
|
|
61
|
+
* node directly would be a request going round whatever the caller asked every request to go
|
|
62
|
+
* through, and the whole worth of that option is that there is no exception to it.
|
|
63
|
+
*
|
|
64
|
+
* ⛔ HERE RATHER THAN IN EACH CLIENT. Five of them are built in this package; five copies of the
|
|
65
|
+
* same line is five places for the sixth to be forgotten.
|
|
66
|
+
*/
|
|
67
|
+
export declare function storageNodesThrough(): {
|
|
68
|
+
storageNodeClientOptions: {
|
|
69
|
+
fetch: typeof fetch;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
45
72
|
export interface ReadOptions {
|
|
46
73
|
/** Override the host list — for a development stack, or an aggregator somebody runs themselves. */
|
|
47
74
|
hosts?: readonly string[];
|
package/dist/walrus.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.js";
|
|
14
14
|
import { NmtsError } from "./errors.js";
|
|
15
15
|
import { host as runtime } from "./host.js";
|
|
16
|
+
import { reach, reachFetch } from "./reach.js";
|
|
16
17
|
/** Curated Walrus aggregator (read) endpoints per network, preference order. */
|
|
17
18
|
export const AGGREGATOR_HOSTS = {
|
|
18
19
|
testnet: ["https://aggregator.walrus-testnet.walrus.space"],
|
|
@@ -55,9 +56,16 @@ export const READ_TIMEOUT_MS = 60_000;
|
|
|
55
56
|
// Re-exported so every caller still finds them here; the names themselves live in a module with no
|
|
56
57
|
// imports, because `nmts --help` prints them (`env-vars.ts`).
|
|
57
58
|
export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.js";
|
|
58
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The relay this run writes through: the caller's if it named one, then the environment's, then
|
|
61
|
+
* the network's.
|
|
62
|
+
*
|
|
63
|
+
* ⛔ THE CALLER COMES FIRST AND IS READ ON EVERY HOST. A library's caller has no environment to
|
|
64
|
+
* write, and until this order existed the `relay` option was answered by the browser host alone
|
|
65
|
+
* — so a program on a server named a relay and its bytes went to the public one, silently.
|
|
66
|
+
*/
|
|
59
67
|
export function relayHost(network) {
|
|
60
|
-
const named = runtime().env(RELAY_ENV_VAR)?.trim();
|
|
68
|
+
const named = reach().relay?.trim() || runtime().env(RELAY_ENV_VAR)?.trim();
|
|
61
69
|
if (named)
|
|
62
70
|
return named;
|
|
63
71
|
const known = RELAY_HOSTS[network]?.[0];
|
|
@@ -69,14 +77,21 @@ export function relayHost(network) {
|
|
|
69
77
|
return known;
|
|
70
78
|
}
|
|
71
79
|
/**
|
|
72
|
-
* Every Sui JSON-RPC node this run may ask, in order
|
|
80
|
+
* Every Sui JSON-RPC node this run may ask, in order: the caller's list if it named one, then the
|
|
81
|
+
* environment's, then the network's.
|
|
73
82
|
*
|
|
74
|
-
* ⛔ Naming
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
83
|
+
* ⛔ Naming nodes REPLACES the list rather than adding to it — the same rule the aggregator
|
|
84
|
+
* override follows, and for the same reason: somebody who names a node is saying *those*, and
|
|
85
|
+
* quietly reaching a public mirror instead would send their traffic somewhere they did not
|
|
86
|
+
* choose.
|
|
87
|
+
*
|
|
88
|
+
* ⚠ THE CALLER MAY NAME SEVERAL AND A VARIABLE MAY NAME ONE. The failover below is the same
|
|
89
|
+
* either way; a single name is a list of one.
|
|
78
90
|
*/
|
|
79
91
|
export function suiRpcHosts(network) {
|
|
92
|
+
const asked = reach().suiRpc?.map((h) => h.trim()).filter((h) => h !== "");
|
|
93
|
+
if (asked !== undefined && asked.length > 0)
|
|
94
|
+
return asked;
|
|
80
95
|
const named = runtime().env(SUI_RPC_ENV_VAR)?.trim();
|
|
81
96
|
if (named)
|
|
82
97
|
return [named];
|
|
@@ -92,6 +107,20 @@ export function suiRpcHosts(network) {
|
|
|
92
107
|
export function suiRpcHost(network) {
|
|
93
108
|
return suiRpcHosts(network)[0] ?? "";
|
|
94
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* What a storage-network client talks to the storage nodes through, spread into its options.
|
|
112
|
+
*
|
|
113
|
+
* ⚠ THIS TOOL DOES NOT NORMALLY REACH A STORAGE NODE — it writes through an upload relay and reads
|
|
114
|
+
* through an aggregator. The option is filled anyway, because the one path that fell back to a
|
|
115
|
+
* node directly would be a request going round whatever the caller asked every request to go
|
|
116
|
+
* through, and the whole worth of that option is that there is no exception to it.
|
|
117
|
+
*
|
|
118
|
+
* ⛔ HERE RATHER THAN IN EACH CLIENT. Five of them are built in this package; five copies of the
|
|
119
|
+
* same line is five places for the sixth to be forgotten.
|
|
120
|
+
*/
|
|
121
|
+
export function storageNodesThrough() {
|
|
122
|
+
return { storageNodeClientOptions: { fetch: reachFetch } };
|
|
123
|
+
}
|
|
95
124
|
function fromEnvironment() {
|
|
96
125
|
const raw = runtime().env(AGGREGATOR_ENV_VAR);
|
|
97
126
|
if (raw === undefined)
|
|
@@ -99,9 +128,20 @@ function fromEnvironment() {
|
|
|
99
128
|
const hosts = raw.split(",").map((h) => h.trim()).filter((h) => h !== "");
|
|
100
129
|
return hosts.length > 0 ? hosts : null;
|
|
101
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Which aggregators this read may ask, in order: the ones this call named, then the ones the
|
|
133
|
+
* caller named for the client, then the environment's, then the network's.
|
|
134
|
+
*
|
|
135
|
+
* ⚠ THE CLIENT'S CHOICE IS NEW HERE. A caller that named aggregators used to be honoured only on
|
|
136
|
+
* the reads that carry a host list down as an argument; the rest of the package quietly went to
|
|
137
|
+
* the public ones, which is the same defect `relay` had.
|
|
138
|
+
*/
|
|
102
139
|
function hostsFor(network, options) {
|
|
103
140
|
if (options.hosts !== undefined && options.hosts.length > 0)
|
|
104
141
|
return options.hosts;
|
|
142
|
+
const asked = reach().aggregators;
|
|
143
|
+
if (asked !== undefined && asked.length > 0)
|
|
144
|
+
return asked;
|
|
105
145
|
const chosen = fromEnvironment();
|
|
106
146
|
if (chosen !== null)
|
|
107
147
|
return chosen;
|
|
@@ -129,7 +169,7 @@ async function readFrom(network, pathOf, what, options) {
|
|
|
129
169
|
const timer = AbortSignal.timeout(options.timeoutMs ?? READ_TIMEOUT_MS);
|
|
130
170
|
const signal = options.signal === undefined ? timer : AbortSignal.any([timer, options.signal]);
|
|
131
171
|
try {
|
|
132
|
-
const response = await
|
|
172
|
+
const response = await reachFetch(url, { signal, redirect: "follow", ...headersFor(options) });
|
|
133
173
|
if (!response.ok) {
|
|
134
174
|
tried.push(`${host} → ${response.status}`);
|
|
135
175
|
continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needmoretruth/nmts-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Command-line and MCP access to NMTS (NeedMoreTruthStorage, https://nmts.me): open-source, end-to-end encrypted storage on the Walrus network. No fee to NMTS; you pay the network from your own wallet. For people and for their agents.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|