@needmoretruth/nmts-cli 0.50.0 → 0.52.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/api.js +3 -0
  5. package/dist/artifact-about.d.ts +1 -1
  6. package/dist/client-id.d.ts +11 -0
  7. package/dist/client-id.js +30 -0
  8. package/dist/commands/mcp.js +3 -0
  9. package/dist/commands/wallet-activity.d.ts +10 -6
  10. package/dist/commands/wallet-activity.js +17 -6
  11. package/dist/env-vars.d.ts +1 -1
  12. package/dist/env-vars.js +1 -1
  13. package/dist/extend-chain.d.ts +4 -6
  14. package/dist/extend-chain.js +30 -28
  15. package/dist/net-retry.js +14 -0
  16. package/dist/portable.d.ts +2 -0
  17. package/dist/portable.js +2 -0
  18. package/dist/product.d.ts +1 -1
  19. package/dist/product.js +1 -1
  20. package/dist/reach.d.ts +1 -1
  21. package/dist/shared/lib/storage-control/chain.d.ts +30 -29
  22. package/dist/shared/lib/storage-control/chain.js +14 -20
  23. package/dist/shared/lib/wallet/activity.d.ts +42 -48
  24. package/dist/shared/lib/wallet/activity.js +51 -30
  25. package/dist/shared/lib/wallet/address-history.d.ts +42 -0
  26. package/dist/shared/lib/wallet/address-history.js +247 -0
  27. package/dist/shared/lib/wallet/chain-calls.d.ts +44 -0
  28. package/dist/shared/lib/wallet/chain-calls.js +59 -0
  29. package/dist/storage-control-chain.js +5 -4
  30. package/dist/sui-execute.d.ts +54 -0
  31. package/dist/sui-execute.js +43 -0
  32. package/dist/sui-rpc.d.ts +16 -9
  33. package/dist/sui-rpc.js +53 -19
  34. package/dist/upload-wallet-chain.d.ts +8 -3
  35. package/dist/upload-wallet-chain.js +33 -29
  36. package/dist/upload-wallet-plan.d.ts +1 -1
  37. package/dist/upload-wallet-put.js +1 -1
  38. package/dist/wallet-activity-chain.d.ts +2 -2
  39. package/dist/wallet-activity-chain.js +12 -27
  40. package/dist/wallet-chain.js +19 -13
  41. package/dist/wallet-list-chain.d.ts +1 -1
  42. package/dist/wallet-list-chain.js +13 -14
  43. package/dist/wallet-send-chain.js +4 -3
  44. package/dist/wallet-sign-external.d.ts +18 -25
  45. package/dist/wallet-sign-external.js +16 -19
  46. package/dist/wallet-sign.js +22 -70
  47. package/dist/wallet-storage-chain.js +2 -3
  48. package/dist/wallet-swap-chain.d.ts +3 -6
  49. package/dist/wallet-swap-chain.js +16 -16
  50. package/dist/wallet-swap-quote.js +16 -17
  51. package/dist/walrus-fresh.d.ts +8 -0
  52. package/dist/walrus-fresh.js +15 -0
  53. package/dist/walrus-write.js +6 -16
  54. package/dist/walrus.d.ts +13 -13
  55. package/dist/walrus.js +15 -15
  56. package/package.json +7 -4
  57. package/server.json +2 -2
  58. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +11 -11
  59. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  60. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +11 -11
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Run `transaction` without signing, checks off, and return what each command returned.
3
+ *
4
+ * `sender` is set only when the transaction has none — a devInspect needs one, and nothing is spent:
5
+ * with checks off and no gas payment the node simulates with a mocked gas coin.
6
+ *
7
+ * ⛔ A refusal the node REPORTS (the Move call aborted) comes back as `error`; a request the node
8
+ * could not run at all (no such object, malformed call) throws, as the old call's RPC errors did.
9
+ */
10
+ export async function inspect(client, transaction, sender) {
11
+ transaction.setSenderIfNotSet(sender);
12
+ const res = await client.core.simulateTransaction({
13
+ transaction,
14
+ checksEnabled: false,
15
+ include: { commandResults: true },
16
+ });
17
+ if (res.$kind === "FailedTransaction") {
18
+ return { error: res.FailedTransaction.status.error?.message ?? "the calls did not run", results: [] };
19
+ }
20
+ return {
21
+ error: null,
22
+ results: (res.commandResults ?? []).map((r) => ({ returnValues: r.returnValues.map((v) => v.bcs) })),
23
+ };
24
+ }
25
+ /**
26
+ * Simulate built transaction bytes exactly as they would be submitted (checks on, gas as built).
27
+ *
28
+ * Nothing is signed, nothing is broadcast. Throws when the node returns no effects, because a dry run
29
+ * without a gas figure is not an answer any caller can use.
30
+ */
31
+ export async function dryRun(client, bytes) {
32
+ const res = await client.core.simulateTransaction({ transaction: bytes, include: { effects: true } });
33
+ const tx = res.Transaction ?? res.FailedTransaction;
34
+ const effects = tx?.effects;
35
+ if (tx === undefined || effects === undefined || effects === null) {
36
+ throw new Error("The dry run came back without effects.");
37
+ }
38
+ return { status: tx.status, gasUsed: effects.gasUsed };
39
+ }
40
+ /** A u64 return value: exactly eight little-endian bytes, or a refusal to guess. */
41
+ export function u64FromLe(bytes) {
42
+ if (bytes === undefined || bytes.length !== 8) {
43
+ throw new Error("The chain answered a number in an unexpected shape.");
44
+ }
45
+ return bytes.reduceRight((acc, byte) => (acc << 8n) | BigInt(byte), 0n);
46
+ }
47
+ /**
48
+ * An object's Move fields as JSON, or `null` when the node rendered none. An object that does not
49
+ * exist (deleted, wrapped, or on another network) THROWS — the core API's `getObject` refuses rather
50
+ * than answering empty, and a caller that must tell "gone" from "unreadable" catches it.
51
+ *
52
+ * ⚠ The JSON form is the node's rendering of the struct; the SDK warns that its exact field shapes
53
+ * may differ between transports. Callers here read top-level primitive fields (a package id, a
54
+ * number) only, which every transport renders the same way.
55
+ */
56
+ export async function objectFields(client, objectId) {
57
+ const { object } = await client.core.getObject({ objectId, include: { json: true } });
58
+ return object.json ?? null;
59
+ }
@@ -16,6 +16,7 @@
16
16
  import { Transaction } from "@mysten/sui/transactions";
17
17
  import { walrusClient, netGasFee } from "./extend-chain.js";
18
18
  import { splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
19
+ import { dryRun } from "./shared/lib/wallet/chain-calls.js";
19
20
  /** The transaction one shape is, for `sender`. */
20
21
  export function storageOpTransaction(shape, input) {
21
22
  const tx = new Transaction();
@@ -59,11 +60,11 @@ export function storageOpsReads(network) {
59
60
  try {
60
61
  const walrusPackageId = await this.walrusPackageId();
61
62
  const bytes = await storageOpTransaction(shape, { walrusPackageId, sender }).build({ client });
62
- const { effects } = await client.dryRunTransactionBlock({ transactionBlock: bytes });
63
- if (effects.status.status !== "success") {
64
- return { feeMist: null, refusal: effects.status.error ?? "the chain gave no reason" };
63
+ const { status, gasUsed } = await dryRun(client, bytes);
64
+ if (!status.success) {
65
+ return { feeMist: null, refusal: status.error?.message || "the chain gave no reason" };
65
66
  }
66
- return { feeMist: netGasFee(effects.gasUsed), refusal: null };
67
+ return { feeMist: netGasFee(gasUsed), refusal: null };
67
68
  }
68
69
  catch (error) {
69
70
  // ⚠ A refusal at ASSEMBLY (a wrong argument, an object that is not this wallet's) is an
@@ -0,0 +1,54 @@
1
+ import type { ClientWithCoreApi } from "@mysten/sui/client";
2
+ import type { Signer } from "@mysten/sui/cryptography";
3
+ import type { Transaction } from "@mysten/sui/transactions";
4
+ /** What every execution asks the node to include: the effects (status, objects) and the objects' types. */
5
+ export declare const EXECUTE_INCLUDE: {
6
+ readonly effects: true;
7
+ readonly objectTypes: true;
8
+ };
9
+ /** The parts of one transaction in the node's answer this tool reads. The SDK's shape fits it. */
10
+ export interface AnsweredTransaction {
11
+ digest: string;
12
+ status: {
13
+ success: boolean;
14
+ error?: {
15
+ message: string;
16
+ } | null;
17
+ };
18
+ effects?: {
19
+ changedObjects: readonly {
20
+ objectId: string;
21
+ idOperation: string;
22
+ }[];
23
+ } | null;
24
+ objectTypes?: Readonly<Record<string, string>> | null;
25
+ }
26
+ /** The node's answer: the transaction under the name that says how it ended. */
27
+ export interface ChainAnswer {
28
+ Transaction?: AnsweredTransaction;
29
+ FailedTransaction?: AnsweredTransaction;
30
+ }
31
+ export interface Executed {
32
+ digest: string;
33
+ /** The chain's reason when the transaction executed and FAILED; `null` when it went through. */
34
+ refused: string | null;
35
+ /** Every object it created, with its Move type when the node named one. */
36
+ created: readonly {
37
+ objectId: string;
38
+ type: string | null;
39
+ }[];
40
+ }
41
+ /** Read one answer. Throws when it carries no transaction at all — that is not an answer to judge. */
42
+ export declare function readAnswer(answer: ChainAnswer): Executed;
43
+ /**
44
+ * Sign `transaction` with `signer`, execute it once, and read the answer.
45
+ *
46
+ * ⛔ THE WAIT AFTER A SUCCESS is for what happens NEXT — the server told the digest, `nmts wallet`
47
+ * run, the browser's activity list opened — because a node that has not indexed the transaction
48
+ * yet answers those as if nothing happened. A wait that times out changes nothing about what was
49
+ * signed, so it is not an error of the transaction.
50
+ *
51
+ * ⚠ A THROW HERE IS NOT PROOF THAT NOTHING HAPPENED: a timeout or a dropped connection after the
52
+ * bytes went out says nothing about whether the transaction executed.
53
+ */
54
+ export declare function signAndRun(client: ClientWithCoreApi, transaction: Transaction, signer: Signer): Promise<Executed>;
@@ -0,0 +1,43 @@
1
+ // What the chain says about one executed transaction — read ONE way for every signer in this tool.
2
+ //
3
+ // ⛔ WHY ONE READER (2026-10-21). Sui retired JSON-RPC, whose execute answer carried the status as a
4
+ // word (`effects.status.status === "failure"`) and the created objects as `objectChanges`. The gRPC
5
+ // answer carries `status.success` and `effects.changedObjects` plus a separate `objectTypes` map.
6
+ // Six signers in `wallet-sign.ts` and two in `wallet-sign-external.ts` each read the old shape by
7
+ // hand; one translation here is what keeps "executed and FAILED" from being misread in one of them.
8
+ //
9
+ // ⛔ A DIGEST IS NOT A SUCCESS. A transaction that executed and failed still has a digest, and its
10
+ // gas is gone. `refused` is the chain's reason in that case and `null` only when it went through.
11
+ /** What every execution asks the node to include: the effects (status, objects) and the objects' types. */
12
+ export const EXECUTE_INCLUDE = { effects: true, objectTypes: true };
13
+ /** Read one answer. Throws when it carries no transaction at all — that is not an answer to judge. */
14
+ export function readAnswer(answer) {
15
+ const tx = answer.Transaction ?? answer.FailedTransaction;
16
+ if (tx === undefined)
17
+ throw new Error("The chain answered without the transaction it was asked about.");
18
+ const reason = tx.status.error?.message;
19
+ const refused = tx.status.success ? null : reason !== undefined && reason !== "" ? reason : "no reason was given";
20
+ const created = (tx.effects?.changedObjects ?? [])
21
+ .filter((change) => change.idOperation === "Created")
22
+ .map((change) => ({ objectId: change.objectId, type: tx.objectTypes?.[change.objectId] ?? null }));
23
+ return { digest: tx.digest, refused, created };
24
+ }
25
+ /**
26
+ * Sign `transaction` with `signer`, execute it once, and read the answer.
27
+ *
28
+ * ⛔ THE WAIT AFTER A SUCCESS is for what happens NEXT — the server told the digest, `nmts wallet`
29
+ * run, the browser's activity list opened — because a node that has not indexed the transaction
30
+ * yet answers those as if nothing happened. A wait that times out changes nothing about what was
31
+ * signed, so it is not an error of the transaction.
32
+ *
33
+ * ⚠ A THROW HERE IS NOT PROOF THAT NOTHING HAPPENED: a timeout or a dropped connection after the
34
+ * bytes went out says nothing about whether the transaction executed.
35
+ */
36
+ export async function signAndRun(client, transaction, signer) {
37
+ const answer = await client.core.signAndExecuteTransaction({ transaction, signer, include: EXECUTE_INCLUDE });
38
+ const executed = readAnswer(answer);
39
+ if (executed.refused === null) {
40
+ await client.core.waitForTransaction({ digest: executed.digest }).catch(() => undefined);
41
+ }
42
+ return executed;
43
+ }
package/dist/sui-rpc.d.ts CHANGED
@@ -1,15 +1,22 @@
1
- import { JsonRpcHTTPTransport } from "@mysten/sui/jsonRpc";
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
+ import { type DeeperHistory } from "./shared/lib/wallet/address-history.ts";
2
3
  /**
3
- * A Sui transport that asks the network's hosts in order.
4
+ * A Sui client for `network` that asks the network's hosts in order.
4
5
  *
5
- * ⭐ 2026-09-01. There used to be one host per network, and on that morning
6
- * the testnet one was measured dead — `rpc-testnet.suiscan.xyz` completes the TCP handshake in
7
- * 31 ms and then sends nothing for twelve seconds, three times running. It had been that way for
8
- * eleven days, so every command that needed the shard count on testnet had simply stopped.
9
- *
10
- * ⚠ One transport per client on purpose: the host that answered becomes the one asked first, and
6
+ * ⚠ One failover per client on purpose: the host that answered becomes the one asked first, and
11
7
  * sharing that state across clients would let one command's bad luck redirect every other. The
12
8
  * flip side is that a recovered first host is not noticed until the process restarts — that is
13
9
  * the price of not probing a node nobody asked us to talk to.
10
+ *
11
+ * `format: "binary"` — protobuf bytes as they are; every host in the tables answers binary
12
+ * (measured 2026-10-21), and the default text form base64s every message.
13
+ */
14
+ export declare function suiClient(network: "testnet" | "mainnet"): SuiGrpcClient;
15
+ /**
16
+ * Where a wallet's history OLDER than a gRPC node's few-week window is read — Sui's GraphQL service
17
+ * (`shared/lib/wallet/address-history.ts` holds why and the measurements) — or `null` when this run
18
+ * named its own Sui node: somebody who names a node is saying *that one*, and quietly asking a public
19
+ * service as well would send their addresses somewhere they did not choose. The history answer then
20
+ * says it is partial instead.
14
21
  */
15
- export declare function suiRpcTransport(network: string): JsonRpcHTTPTransport;
22
+ export declare function deeperHistory(network: "testnet" | "mainnet"): DeeperHistory | null;
package/dist/sui-rpc.js CHANGED
@@ -1,4 +1,5 @@
1
- // The chain transport: which Sui node a command talks to, and what happens when it does not answer.
1
+ // The chain client: which Sui node a command talks to, over what, and what happens when it does not
2
+ // answer.
2
3
  //
3
4
  // ⛔ WHY THIS IS ITS OWN FILE AND NOT PART OF walrus.ts. `walrus.ts` holds the host tables, and it
4
5
  // is loaded by EVERY invocation including `nmts --help`. Importing the Sui SDK there pulled 150
@@ -6,32 +7,35 @@
6
7
  // and failed the build, which is exactly what that gate is for. The SDK is imported here, and
7
8
  // only the commands that actually reach the chain import this.
8
9
  //
10
+ // ⛔ gRPC-WEB, SINCE 2026-10-21. Sui removed JSON-RPC from its node software in October 2026, and every
11
+ // host this tool used to ask answered only JSON-RPC. The SDK's `SuiGrpcClient` speaks gRPC-web over
12
+ // `fetch`, so the failover below wraps the same `fetch` it always did — the path
13
+ // (`/sui.rpc.v2.<Service>/<Method>`) is kept and only the host changes.
14
+ //
9
15
  // ⛔ NOT A RETRIER. Each host is asked once. Anything other than "no answer" — any 4xx that is not
10
- // 429 — is an answer, and asking a different node the same question gets the same one.
11
- import { JsonRpcHTTPTransport } from "@mysten/sui/jsonRpc";
16
+ // 429, and every gRPC status the node sends back — is an answer, and asking a different node the
17
+ // same question gets the same one.
18
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
12
19
  import { reachFetch } from "./reach.js";
13
- import { suiRpcHosts } from "./walrus.js";
20
+ import { graphqlHistory, SUI_GRAPHQL_URLS } from "./shared/lib/wallet/address-history.js";
21
+ import { SUI_RPC_HOSTS, suiRpcHosts } from "./walrus.js";
14
22
  /** HTTP statuses that mean "no answer came", the only ones worth asking a second node about. */
15
23
  function worthAnotherHost(status) {
16
24
  return status >= 500 || status === 429;
17
25
  }
18
26
  /**
19
- * A Sui transport that asks the network's hosts in order.
27
+ * A `fetch` that asks the network's hosts in order.
20
28
  *
21
- * ⭐ 2026-09-01. There used to be one host per network, and on that morning
22
- * the testnet one was measured dead — `rpc-testnet.suiscan.xyz` completes the TCP handshake in
23
- * 31 ms and then sends nothing for twelve seconds, three times running. It had been that way for
24
- * eleven days, so every command that needed the shard count on testnet had simply stopped.
29
+ * ⭐ 2026-09-01. There used to be one host per network, and on that morning the testnet one was
30
+ * measured dead for eleven days — every command that needed the chain on testnet had simply stopped.
25
31
  *
26
- * ⚠ One transport per client on purpose: the host that answered becomes the one asked first, and
27
- * sharing that state across clients would let one command's bad luck redirect every other. The
28
- * flip side is that a recovered first host is not noticed until the process restarts — that is
29
- * the price of not probing a node nobody asked us to talk to.
32
+ * ⚠ THE LAST HOST'S 5xx/429 IS THROWN, with its number in the sentence (2026-10-21). The gRPC-web
33
+ * transport turns a returned 500 or 502 into a bare `UNKNOWN`, and then "the server failed" and
34
+ * "the node said no" look the same to whoever decides whether to wait and ask again.
30
35
  */
31
- export function suiRpcTransport(network) {
32
- const hosts = suiRpcHosts(network);
36
+ function failoverFetch(hosts) {
33
37
  let preferred = 0;
34
- const fetchWithFailover = async (input, init) => {
38
+ return async (input, init) => {
35
39
  const asked = new URL(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
36
40
  let lastError = null;
37
41
  for (let step = 0; step < hosts.length; step += 1) {
@@ -41,8 +45,8 @@ export function suiRpcTransport(network) {
41
45
  continue;
42
46
  try {
43
47
  const res = await reachFetch(new URL(asked.pathname + asked.search, host), init);
44
- if (worthAnotherHost(res.status) && step < hosts.length - 1) {
45
- lastError = new Error(`${host} answered ${res.status}`);
48
+ if (worthAnotherHost(res.status)) {
49
+ lastError = new Error(`${host} → HTTP ${res.status}`);
46
50
  continue;
47
51
  }
48
52
  preferred = index;
@@ -56,5 +60,35 @@ export function suiRpcTransport(network) {
56
60
  ? lastError
57
61
  : new Error(`no Sui node answered (${hosts.length} tried)`);
58
62
  };
59
- return new JsonRpcHTTPTransport({ url: hosts[0] ?? "", fetch: fetchWithFailover });
63
+ }
64
+ /**
65
+ * A Sui client for `network` that asks the network's hosts in order.
66
+ *
67
+ * ⚠ One failover per client on purpose: the host that answered becomes the one asked first, and
68
+ * sharing that state across clients would let one command's bad luck redirect every other. The
69
+ * flip side is that a recovered first host is not noticed until the process restarts — that is
70
+ * the price of not probing a node nobody asked us to talk to.
71
+ *
72
+ * `format: "binary"` — protobuf bytes as they are; every host in the tables answers binary
73
+ * (measured 2026-10-21), and the default text form base64s every message.
74
+ */
75
+ export function suiClient(network) {
76
+ const hosts = suiRpcHosts(network);
77
+ return new SuiGrpcClient({
78
+ network,
79
+ baseUrl: hosts[0] ?? "",
80
+ format: "binary",
81
+ fetch: failoverFetch(hosts),
82
+ });
83
+ }
84
+ /**
85
+ * Where a wallet's history OLDER than a gRPC node's few-week window is read — Sui's GraphQL service
86
+ * (`shared/lib/wallet/address-history.ts` holds why and the measurements) — or `null` when this run
87
+ * named its own Sui node: somebody who names a node is saying *that one*, and quietly asking a public
88
+ * service as well would send their addresses somewhere they did not choose. The history answer then
89
+ * says it is partial instead.
90
+ */
91
+ export function deeperHistory(network) {
92
+ const named = suiRpcHosts(network).join(" ") !== (SUI_RPC_HOSTS[network] ?? []).join(" ");
93
+ return named ? null : graphqlHistory(SUI_GRAPHQL_URLS[network], (input, init) => reachFetch(input, init));
60
94
  }
@@ -1,6 +1,6 @@
1
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
2
1
  import { Transaction } from "@mysten/sui/transactions";
3
2
  import type { Network } from "./network.ts";
3
+ import type { Executed } from "./sui-execute.ts";
4
4
  import type { RegisterShape, WalletUploadReads } from "./upload-wallet-plan.ts";
5
5
  import type { Certificate } from "./upload-wire.ts";
6
6
  /**
@@ -18,7 +18,7 @@ export declare function packageConfig(network: Network): {
18
18
  };
19
19
  declare function build(network: Network, relayUrl: string): import("@mysten/sui/client").ClientWithExtensions<{
20
20
  walrus: import("@mysten/walrus").WalrusClient;
21
- }, SuiJsonRpcClient>;
21
+ }, import("@mysten/sui/grpc").SuiGrpcClient>;
22
22
  export type PayingClient = ReturnType<typeof build>;
23
23
  /** A Walrus client bound to ONE relay, able to pay that relay's tip. */
24
24
  export declare function payingClient(network: Network, relayUrl: string): PayingClient;
@@ -27,6 +27,11 @@ export declare function payingClient(network: Network, relayUrl: string): Paying
27
27
  *
28
28
  * ⛔ SENDER FIRST. `coinWithBalance` and the SDK's own coin selection pick WAL and SUI from the
29
29
  * sender's address when the fragments resolve; without it the build fails late.
30
+ *
31
+ * ⛔ EVERY PRICE IS READ HERE, ON FRESH STATE — the held resource's write cost included. It used to
32
+ * arrive from the review's quote, and the register transaction pays EXACTLY what it is given:
33
+ * a price vote landing between the review and the signature (a long seal, a resumed upload) made
34
+ * the chain abort the registration in `destroy_zero` or `split` instead of charging the new price.
30
35
  */
31
36
  export declare function registerTransaction(client: PayingClient, network: Network, input: RegisterShape & {
32
37
  sender: string;
@@ -43,7 +48,7 @@ export declare function certifyTransaction(client: PayingClient, input: {
43
48
  * ⛔ THE OBJECT IS FOUND BY ITS TYPE, not by position: the transaction also creates the leftover
44
49
  * resource on a cut, and on a purchase the storage object is created and consumed inside it.
45
50
  */
46
- export declare function createdBlob(client: PayingClient, objectChanges: unknown): Promise<{
51
+ export declare function createdBlob(client: PayingClient, created: Executed["created"]): Promise<{
47
52
  blobObjectId: string;
48
53
  endEpoch: number;
49
54
  }>;
@@ -14,11 +14,9 @@
14
14
  // ⛔ THE ENCODED SIZE IS THE CHAIN'S ARITHMETIC, NOT A COPY. Registration checks
15
15
  // `encoded_size <= storage_size` with `walrus::encoding::encoded_blob_length`, and the SDK keeps
16
16
  // its own copy unexported. Cutting a held resource to fit needs that exact number, so it is
17
- // asked of the chain itself, in a dev-inspect that costs nothing — a copy kept here would be
17
+ // asked of the chain itself, in a simulation that costs nothing — a copy kept here would be
18
18
  // wrong the day the protocol changed it, and the way that surfaces is a refused registration
19
19
  // after the split was signed.
20
- import { bcs } from "@mysten/sui/bcs";
21
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
22
20
  import { Transaction } from "@mysten/sui/transactions";
23
21
  import { blobIdFromInt, blobIdToInt, MAINNET_WALRUS_PACKAGE_CONFIG, TESTNET_WALRUS_PACKAGE_CONFIG, walrus, } from "@mysten/walrus";
24
22
  import { fromBase64Url } from "./bytes.js";
@@ -27,8 +25,10 @@ import { extendReads, netGasFee, readBlobLease } from "./extend-chain.js";
27
25
  import { reachFetch } from "./reach.js";
28
26
  import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
29
27
  import { registerIntoStorage, splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
28
+ import { dryRun, inspect, u64FromLe } from "./shared/lib/wallet/chain-calls.js";
30
29
  import { storageNodesThrough } from "./walrus.js";
31
- import { suiRpcTransport } from "./sui-rpc.js";
30
+ import { freshWalrus } from "./walrus-fresh.js";
31
+ import { suiClient } from "./sui-rpc.js";
32
32
  import { readBalances, walCoinType } from "./wallet.js";
33
33
  import { chainReader } from "./wallet-chain.js";
34
34
  /**
@@ -48,7 +48,7 @@ export function packageConfig(network) {
48
48
  return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
49
49
  }
50
50
  function build(network, relayUrl) {
51
- return new SuiJsonRpcClient({ network, transport: suiRpcTransport(network) }).$extend(walrus({
51
+ return suiClient(network).$extend(walrus({
52
52
  ...storageNodesThrough(),
53
53
  uploadRelay: { host: relayUrl, sendTip: { max: RELAY_TIP_CEILING_MIST[network] }, fetch: reachFetch },
54
54
  }));
@@ -62,14 +62,20 @@ export function payingClient(network, relayUrl) {
62
62
  *
63
63
  * ⛔ SENDER FIRST. `coinWithBalance` and the SDK's own coin selection pick WAL and SUI from the
64
64
  * sender's address when the fragments resolve; without it the build fails late.
65
+ *
66
+ * ⛔ EVERY PRICE IS READ HERE, ON FRESH STATE — the held resource's write cost included. It used to
67
+ * arrive from the review's quote, and the register transaction pays EXACTLY what it is given:
68
+ * a price vote landing between the review and the signature (a long seal, a resumed upload) made
69
+ * the chain abort the registration in `destroy_zero` or `split` instead of charging the new price.
65
70
  */
66
71
  export async function registerTransaction(client, network, input) {
67
72
  const tx = new Transaction();
68
73
  tx.setSender(input.sender);
69
74
  const { part } = input;
70
- tx.add(client.walrus.sendUploadRelayTip({ size: part.sealedLen, blobDigest: part.blobDigest, nonce: part.nonce }));
75
+ const fresh = freshWalrus(client);
76
+ tx.add(fresh.sendUploadRelayTip({ size: part.sealedLen, blobDigest: part.blobDigest, nonce: part.nonce }));
71
77
  if (input.storage.kind === "buy") {
72
- const blob = tx.add(client.walrus.registerBlob({
78
+ const blob = tx.add(fresh.registerBlob({
73
79
  size: part.sealedLen,
74
80
  epochs: input.epochs,
75
81
  blobId: part.blobId,
@@ -79,7 +85,11 @@ export async function registerTransaction(client, network, input) {
79
85
  tx.transferObjects([blob], input.sender);
80
86
  return tx;
81
87
  }
82
- const walrusPackageId = (await client.walrus.systemObject()).package_id;
88
+ const [system, { writeCost }] = await Promise.all([
89
+ fresh.systemObject(),
90
+ fresh.storageCost(part.sealedLen, input.epochs),
91
+ ]);
92
+ const walrusPackageId = system.package_id;
83
93
  if (input.storage.cutToBytes !== null) {
84
94
  splitStorageToFit({
85
95
  walrusPackageId,
@@ -96,7 +106,7 @@ export async function registerTransaction(client, network, input) {
96
106
  blobIdAsInt: blobIdToInt(part.blobId),
97
107
  rootHash: part.rootHash,
98
108
  rawBytes: part.sealedLen,
99
- writeCost: input.storage.writeFrost,
109
+ writeCost,
100
110
  deletable: true,
101
111
  owner: input.sender,
102
112
  }, tx);
@@ -104,7 +114,7 @@ export async function registerTransaction(client, network, input) {
104
114
  }
105
115
  /** The certify transaction of ONE part, from the certificate the relay handed back. */
106
116
  export function certifyTransaction(client, input) {
107
- return client.walrus.certifyBlobTransaction({
117
+ return freshWalrus(client).certifyBlobTransaction({
108
118
  blobId: input.blobId,
109
119
  blobObjectId: input.blobObjectId,
110
120
  deletable: true,
@@ -121,16 +131,9 @@ export function certifyTransaction(client, input) {
121
131
  * ⛔ THE OBJECT IS FOUND BY ITS TYPE, not by position: the transaction also creates the leftover
122
132
  * resource on a cut, and on a purchase the storage object is created and consumed inside it.
123
133
  */
124
- export async function createdBlob(client, objectChanges) {
125
- const created = Array.isArray(objectChanges)
126
- ? objectChanges.find((change) => typeof change === "object" &&
127
- change !== null &&
128
- Reflect.get(change, "type") === "created" &&
129
- typeof Reflect.get(change, "objectType") === "string" &&
130
- String(Reflect.get(change, "objectType")).endsWith("::blob::Blob"))
131
- : undefined;
132
- const id = created === undefined ? undefined : Reflect.get(created, "objectId");
133
- if (typeof id !== "string") {
134
+ export async function createdBlob(client, created) {
135
+ const id = created.find((object) => object.type?.endsWith("::blob::Blob") === true)?.objectId;
136
+ if (id === undefined) {
134
137
  throw new NmtsError("The registration executed but the chain did not list the blob object it created.", {
135
138
  exitCode: 1,
136
139
  nextStep: "The storage is bought. Running the same command again does not pay again: it reads the record and continues.",
@@ -150,15 +153,15 @@ export async function encodedLength(client, sender, sealedLen) {
150
153
  // 1 = RS2, the encoding every registration in this tool names (`reuse.ts`).
151
154
  arguments: [tx.pure.u64(sealedLen), tx.pure.u8(1), tx.pure.u16(state.committee.n_shards)],
152
155
  });
153
- const result = await client.devInspectTransactionBlock({ sender, transactionBlock: tx });
154
- const value = result.results?.[0]?.returnValues?.[0]?.[0];
155
- if (value === undefined) {
156
+ const result = await inspect(client, tx, sender);
157
+ const value = result.error === null ? result.results[0]?.returnValues[0] : undefined;
158
+ if (value === undefined || value.length !== 8) {
156
159
  throw new NmtsError("The chain did not say how large this part is once encoded.", {
157
160
  exitCode: 1,
158
161
  nextStep: "Nothing was signed. A held resource cannot be cut to fit without that number; buy new storage instead, or try again.",
159
162
  });
160
163
  }
161
- return Number(bcs.u64().parse(Uint8Array.from(value)));
164
+ return Number(u64FromLe(value));
162
165
  }
163
166
  /** A part shaped like a real one, for measuring the fee of a registration before anything is sealed. */
164
167
  function placeholderPart(sealedLen) {
@@ -176,10 +179,11 @@ export function walletUploadReads(network, relayUrl) {
176
179
  return {
177
180
  readWindow: () => extendReads(network).readWindow(),
178
181
  async quoteParts(sealedLens, epochs) {
182
+ const fresh = freshWalrus(client);
179
183
  return Promise.all(sealedLens.map(async (sealedLen) => {
180
184
  const [cost, tip] = await Promise.all([
181
- client.walrus.storageCost(sealedLen, epochs),
182
- client.walrus.calculateUploadRelayTip({ size: sealedLen }),
185
+ fresh.storageCost(sealedLen, epochs),
186
+ fresh.calculateUploadRelayTip({ size: sealedLen }),
183
187
  ]);
184
188
  return { sealedLen, storageFrost: cost.storageCost, writeFrost: cost.writeCost, tipMist: BigInt(tip) };
185
189
  }));
@@ -191,10 +195,10 @@ export function walletUploadReads(network, relayUrl) {
191
195
  try {
192
196
  const tx = await registerTransaction(client, network, { sender, epochs, storage, part: placeholderPart(sealedLen) });
193
197
  const bytes = await tx.build({ client });
194
- const { effects } = await client.dryRunTransactionBlock({ transactionBlock: bytes });
195
- if (effects.status.status !== "success")
198
+ const { status, gasUsed } = await dryRun(client, bytes);
199
+ if (!status.success)
196
200
  return null;
197
- return netGasFee(effects.gasUsed);
201
+ return netGasFee(gasUsed);
198
202
  }
199
203
  catch {
200
204
  return null;
@@ -30,13 +30,13 @@ export type StorageChoice = {
30
30
  /** One part as the register transaction needs it. */
31
31
  export interface RegisterShape {
32
32
  epochs: number;
33
+ /** ⚠ No write cost here: the register transaction reads it at signing (`registerTransaction`). */
33
34
  storage: {
34
35
  kind: "buy";
35
36
  } | {
36
37
  kind: "reuse";
37
38
  objectId: string;
38
39
  cutToBytes: number | null;
39
- writeFrost: bigint;
40
40
  };
41
41
  part: {
42
42
  sealedLen: number;
@@ -112,7 +112,7 @@ export async function walletPut(ctx, file, seams = {}) {
112
112
  epochs,
113
113
  storage: storage.kind === "buy"
114
114
  ? storage
115
- : { kind: "reuse", objectId: storage.objectId, cutToBytes: storage.cutToBytes, writeFrost: storage.writeFrost },
115
+ : { kind: "reuse", objectId: storage.objectId, cutToBytes: storage.cutToBytes },
116
116
  }),
117
117
  ]);
118
118
  const budget = uploadBudget({ address, purse, feeMist, quotes, storage });
@@ -1,5 +1,5 @@
1
- import type { ActivityFetch } from "./commands/wallet-activity.ts";
1
+ import { type ActivityFetch } from "./commands/wallet-activity.ts";
2
2
  import type { Network } from "./network.ts";
3
- /** How long the two questions get together. A read that stalls is a read that failed. */
3
+ /** How long the question gets. A read that stalls is a read that failed. */
4
4
  export declare const ACTIVITY_TIMEOUT_MS = 20000;
5
5
  export declare function queryActivity(network: Network, address: string): Promise<ActivityFetch>;
@@ -1,31 +1,16 @@
1
- // The live read behind `nmts wallet activity`: the chain's two lists for one address.
1
+ // The live read behind `nmts wallet activity`: the chain's list for one address.
2
2
  //
3
- // ⛔ READ ONLY. The same JSON-RPC client `wallet-chain.ts` reads balances with; nothing here builds
4
- // or signs a transaction. Imported lazily, only when no seam was supplied.
5
- import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
6
- import { FETCH_PER_DIRECTION } from "./commands/wallet-activity.js";
7
- import { suiRpcTransport } from "./sui-rpc.js";
8
- /** How long the two questions get together. A read that stalls is a read that failed. */
3
+ // ⛔ READ ONLY. The same gRPC client `wallet-chain.ts` reads balances with, and the browser's own
4
+ // question (`shared/lib/wallet/address-history.ts`); nothing here builds or signs a transaction.
5
+ // Imported lazily, only when no seam was supplied.
6
+ import { FETCH } from "./commands/wallet-activity.js";
7
+ import { addressTransactions } from "./shared/lib/wallet/address-history.js";
8
+ import { deeperHistory, suiClient } from "./sui-rpc.js";
9
+ /** How long the question gets. A read that stalls is a read that failed. */
9
10
  export const ACTIVITY_TIMEOUT_MS = 20_000;
10
11
  export async function queryActivity(network, address) {
11
- const client = new SuiJsonRpcClient({ network, transport: suiRpcTransport(network) });
12
- const options = { showBalanceChanges: true, showInput: true, showEffects: true };
13
- const signal = AbortSignal.timeout(ACTIVITY_TIMEOUT_MS);
14
- const [sent, received] = await Promise.all([
15
- client.queryTransactionBlocks({
16
- filter: { FromAddress: address },
17
- options,
18
- limit: FETCH_PER_DIRECTION,
19
- order: "descending",
20
- signal,
21
- }),
22
- client.queryTransactionBlocks({
23
- filter: { ToAddress: address },
24
- options,
25
- limit: FETCH_PER_DIRECTION,
26
- order: "descending",
27
- signal,
28
- }),
29
- ]);
30
- return { sent: sent.data, received: received.data };
12
+ const { transactions, complete } = await addressTransactions(suiClient(network), address, FETCH, AbortSignal.timeout(ACTIVITY_TIMEOUT_MS),
13
+ // Past the node's few-week window, the older rows come from Sui's GraphQL service.
14
+ deeperHistory(network));
15
+ return { transactions, complete };
31
16
  }