@needmoretruth/nmts-cli 0.57.0 → 0.59.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 (56) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.ko.md +1 -1
  3. package/README.md +1 -1
  4. package/dist/arg-options.d.ts +2 -0
  5. package/dist/args.js +2 -0
  6. package/dist/artifact-about.d.ts +1 -1
  7. package/dist/commands/expiring.js +2 -2
  8. package/dist/commands/sweep.js +6 -64
  9. package/dist/commands/wallet-storage-buy.d.ts +22 -0
  10. package/dist/commands/wallet-storage-buy.js +111 -0
  11. package/dist/commands/wallet-storage-extend.d.ts +23 -0
  12. package/dist/commands/wallet-storage-extend.js +137 -0
  13. package/dist/commands/wallet.d.ts +3 -0
  14. package/dist/commands/wallet.js +5 -1
  15. package/dist/extend-chain.js +19 -3
  16. package/dist/extend-plan.d.ts +38 -0
  17. package/dist/extend-plan.js +61 -0
  18. package/dist/help-options.js +8 -3
  19. package/dist/help.js +5 -0
  20. package/dist/main.js +1 -1
  21. package/dist/platform-sign.d.ts +12 -0
  22. package/dist/platform-sign.js +29 -1
  23. package/dist/portable.d.ts +7 -2
  24. package/dist/portable.js +7 -2
  25. package/dist/product.d.ts +1 -1
  26. package/dist/product.js +1 -1
  27. package/dist/public-codes.d.ts +14 -3
  28. package/dist/public-codes.js +14 -5
  29. package/dist/rebuild.js +9 -24
  30. package/dist/risk.d.ts +12 -0
  31. package/dist/risk.js +8 -0
  32. package/dist/server-objects.d.ts +21 -0
  33. package/dist/server-objects.js +68 -0
  34. package/dist/sharing.d.ts +1 -1
  35. package/dist/sharing.js +12 -40
  36. package/dist/sponsor-check.d.ts +56 -0
  37. package/dist/sponsor-check.js +270 -0
  38. package/dist/sponsor-facts.d.ts +10 -0
  39. package/dist/sponsor-facts.js +75 -0
  40. package/dist/storage-control/buy.d.ts +65 -0
  41. package/dist/storage-control/buy.js +145 -0
  42. package/dist/storage-control/extend-for.d.ts +84 -0
  43. package/dist/storage-control/extend-for.js +204 -0
  44. package/dist/storage-control/extend.d.ts +57 -12
  45. package/dist/storage-control/extend.js +51 -45
  46. package/dist/storage-control-chain.d.ts +7 -0
  47. package/dist/storage-control-chain.js +19 -1
  48. package/dist/storage-control.d.ts +6 -2
  49. package/dist/storage-control.js +5 -2
  50. package/dist/upload-quote.d.ts +93 -0
  51. package/dist/upload-quote.js +135 -0
  52. package/dist/wallet-sign.d.ts +24 -0
  53. package/dist/wallet-sign.js +31 -1
  54. package/docs/commands/wallet.md +13 -1
  55. package/package.json +1 -1
  56. package/server.json +2 -2
@@ -75,6 +75,37 @@ export function asExtendPreview(value) {
75
75
  return unreadable();
76
76
  return { targets, treasuryParts: treasury, untrackedParts: untracked };
77
77
  }
78
+ /**
79
+ * Refuse, before anything is signed, a blob the paying wallet does not hold.
80
+ *
81
+ * ⛔ WHAT A WALLET PAID FOR, ONLY THAT WALLET EXTENDS (`pay.ts` in the SDK says the same). The chain
82
+ * enforces it — but only after a signature was asked for, and for a remote signer (an operator's
83
+ * server signing for a customer) that is a request to sign a transaction that cannot run. Named
84
+ * here, each blob and who holds it, so the caller knows which wallet to pay from instead.
85
+ */
86
+ export function refuseUnheld(leases, payer, file) {
87
+ const mine = normaliseAddress(payer);
88
+ const unheld = leases.flatMap((lease) => {
89
+ const holder = lease.holder;
90
+ if (holder === undefined || holder.kind === "shared")
91
+ return [];
92
+ if (holder.kind === "address" && normaliseAddress(holder.address) === mine)
93
+ return [];
94
+ return [`${lease.objectId} is held by ${holder.kind === "address" ? holder.address : holder.what}`];
95
+ });
96
+ if (unheld.length === 0)
97
+ return;
98
+ throw new NmtsError(`EXTEND_NOT_OWNED: the wallet ${payer} does not hold the storage of "${file}": ${unheld.join("; ")}.`, {
99
+ exitCode: 4,
100
+ nextStep: "Nothing was signed and nothing was charged. Only the wallet that holds a blob can extend it — " +
101
+ "pay from that wallet, or leave this file to whoever holds it.",
102
+ });
103
+ }
104
+ /** `0x` and 64 lower-case hex digits, whatever the spelling it arrived in. */
105
+ function normaliseAddress(address) {
106
+ const hex = address.toLowerCase().replace(/^0x/, "");
107
+ return `0x${hex.padStart(64, "0")}`;
108
+ }
78
109
  /**
79
110
  * When the file actually runs out: the SOONEST end epoch across the blobs it rides on.
80
111
  *
@@ -147,3 +178,33 @@ function parseEpochs(asked) {
147
178
  }
148
179
  return epochs;
149
180
  }
181
+ /**
182
+ * The network's clock and how far ahead it sells, or the refusal for a network that would not say.
183
+ *
184
+ * ⛔ Not "nothing needs extending". The two look identical from outside and mean opposite things.
185
+ */
186
+ export async function readWindowOrRefuse(reads, network) {
187
+ const window = await reads.readWindow();
188
+ if (window !== null)
189
+ return window;
190
+ throw new NmtsError(`The ${network} storage network could not be read.`, {
191
+ exitCode: 1,
192
+ nextStep: `Nothing was signed and nothing was charged. Which epoch the network is in, and how far ` +
193
+ `ahead it will sell, are facts only the chain has — this will not spend against a ` +
194
+ `guess. Try again, or name a different Sui node in NMTS_SUI_RPC.`,
195
+ });
196
+ }
197
+ /** Why a file has nothing to extend, said as the two different things it can be. */
198
+ export function nothingToExtend(preview) {
199
+ const parts = [];
200
+ if (preview.treasuryParts > 0) {
201
+ parts.push(`${preview.treasuryParts} part${preview.treasuryParts === 1 ? " is" : "s are"} on storage NMTS ` +
202
+ `paid for, which this account cannot extend`);
203
+ }
204
+ if (preview.untrackedParts > 0) {
205
+ parts.push(`${preview.untrackedParts} part${preview.untrackedParts === 1 ? " has" : "s have"} no ` +
206
+ `recorded storage object, so there is nothing to name on the chain`);
207
+ }
208
+ const why = parts.length === 0 ? "The server lists no storage object for it." : `${parts.join(", and ")}.`;
209
+ return `Nothing was signed and nothing was charged. ${why} Opening the account in a browser shows what it is stored on.`;
210
+ }
@@ -75,7 +75,8 @@ export function optionLines() {
75
75
  ` public code file`,
76
76
  ` --force Replace a file that is already there (get, pull, listfile,`,
77
77
  ` recovery, recovery-list, kit), or rebuild an account this machine`,
78
- ` has seen a list for (rebuild). \`create\` never replaces a file`,
78
+ ` has seen a list for (rebuild), or extend files not due yet (wallet`,
79
+ ` storage extend). \`create\` never replaces a file`,
79
80
  ` --name <name> The name the uploaded file gets in the drive (put), or the name to`,
80
81
  ` be listed under in the gift hall of fame (wallet hall)`,
81
82
  ` --to <folder> Destination folder, as \`${BINARY_NAME} ls\` prints it (put, push).`,
@@ -101,8 +102,10 @@ export function optionLines() {
101
102
  ` rollback, wallet send, wallet swap, wallet donate),`,
102
103
  ` or extend a file that is nowhere near its deadline (extend)`,
103
104
  ` --epochs <n> How many of the storage network's epochs to add (extend), to buy`,
104
- ` (put, push --pay wallet; default 2), or to keep (wallet storage split)`,
105
- ` --size <bytes> What a cut resource keeps: bytes, or with KiB/MiB/GiB (wallet storage split)`,
105
+ ` (put, push --pay wallet, wallet storage buy; default 2), or to keep`,
106
+ ` (wallet storage split)`,
107
+ ` --size <bytes> What a cut resource keeps, or a bought one holds: bytes, or with`,
108
+ ` KiB/MiB/GiB (wallet storage split, wallet storage buy)`,
106
109
  ` --pay credits|wallet Who pays for an upload's storage (put, push). Default credits.`,
107
110
  ` wallet = the wallet this NMTS key derives signs and pays the`,
108
111
  ` network directly, under a wallet agreement of scope storage`,
@@ -149,6 +152,8 @@ export function optionLines() {
149
152
  ` --wallet The NMTS key comes from a wallet's signature (login, create)`,
150
153
  ` --sui-key-file <p> File holding the wallet's \`suiprivkey1…\` line. Never the key itself.`,
151
154
  ` With put --pay wallet, that wallet pays for the upload`,
155
+ ` --delegation-file <p> File holding a user's delegation token (wallet storage extend).`,
156
+ ` Never the token itself`,
152
157
  ` --account <n> Which of that wallet's accounts. Default 1; it is inside what is signed`,
153
158
  ` --app <name> Scope the signature to one product. Without it, one account everywhere`,
154
159
  ` --version Print the version and exit`,
package/dist/help.js CHANGED
@@ -75,6 +75,11 @@ export function helpText(version) {
75
75
  ` wallet storage The storage resources (size × time) the wallet holds, unbound`,
76
76
  ` wallet storage split <id> --size <n>|--epochs <n> · merge <id> <id> · transfer <id> <address>`,
77
77
  ` Cut, join or hand over a resource — **signs**, under the wallet unlock`,
78
+ ` wallet storage buy --size <n> [--epochs <n>]`,
79
+ ` Buy a resource with no file — **signs and spends WAL**, under the unlock`,
80
+ ` wallet storage extend [<item-id>...] --delegation-file <file>`,
81
+ ` A business extends a user's files from its own wallet, with the user's`,
82
+ ` token and no key of theirs — **signs and spends WAL**, under the unlock`,
78
83
  ` wallet send <SUI|WAL> <amount|max> <address>`,
79
84
  ` Send coins to an address — **signs and spends from the wallet**.`,
80
85
  ` Prints the review; sends only with --yes`,
package/dist/main.js CHANGED
@@ -122,7 +122,7 @@ export async function run(argv) {
122
122
  return await wallet(args.operands[0], {
123
123
  server: args.server, network: args.network, json: args.json, qr: args.qr,
124
124
  rest: args.operands.slice(1), yes: args.yes, dryRun: args.dryRun, feeCap: args.feeCap,
125
- to: args.to, venue: args.venue, slippageBps: args.slippageBps, acceptExtremes: args.acceptExtremes, size: args.size, epochs: args.epochs, name: args.name, remove: args.remove, index: args.index, wallet: args.wallet,
125
+ to: args.to, venue: args.venue, slippageBps: args.slippageBps, acceptExtremes: args.acceptExtremes, size: args.size, epochs: args.epochs, name: args.name, remove: args.remove, index: args.index, wallet: args.wallet, delegationFile: args.delegationFile, force: args.force,
126
126
  });
127
127
  }
128
128
  case "expiring": {
@@ -151,6 +151,18 @@ export declare function mintDelegation(request: DelegationRequest): string;
151
151
  * halves in one hand.
152
152
  */
153
153
  export declare function rotationProof(oldPublicKey: string, newPrivateKey: string): string;
154
+ /**
155
+ * What a delegation token was minted FOR — the account it names and its scope — or null for a string
156
+ * that is not one this can read.
157
+ *
158
+ * ⚠ IT IS NOT A CHECK THAT THE TOKEN IS VALID. Whether the signature holds and whether it has run
159
+ * out are the server's judgement and stay there; what is read here is what a caller can act on
160
+ * BEFORE spending — a token minted without `storage_spend` would be refused after the WAL had gone.
161
+ */
162
+ export declare function readDelegation(token: string): {
163
+ user: string;
164
+ scope: number;
165
+ } | null;
154
166
  /** The bitmask these scope names make. */
155
167
  export declare function scopeMask(scopes: readonly ScopeName[]): number;
156
168
  /** Does this signature hold over these bytes? Here so a caller can check its own work offline. */
@@ -24,7 +24,7 @@
24
24
  import { ed25519 } from "@noble/curves/ed25519.js";
25
25
  import { sha256 } from "@noble/hashes/sha2.js";
26
26
  import { bytesToHex, randomBytes } from "@noble/hashes/utils.js";
27
- import { concat, fromBase64Url, toBase64Url, utf8 } from "./bytes.js";
27
+ import { concat, fromBase64Url, fromUtf8, toBase64Url, utf8 } from "./bytes.js";
28
28
  import { NmtsError } from "./errors.js";
29
29
  /** The fixed prefix of a business signature. `1` is the format version, so a later shape is `bs2_`. */
30
30
  export const BUSINESS_PREFIX = "nmts_bs1_";
@@ -179,6 +179,34 @@ export function mintDelegation(request) {
179
179
  export function rotationProof(oldPublicKey, newPrivateKey) {
180
180
  return toBase64Url(ed25519.sign(rotationSigningInput(oldPublicKey), secretBytes(newPrivateKey)));
181
181
  }
182
+ /**
183
+ * What a delegation token was minted FOR — the account it names and its scope — or null for a string
184
+ * that is not one this can read.
185
+ *
186
+ * ⚠ IT IS NOT A CHECK THAT THE TOKEN IS VALID. Whether the signature holds and whether it has run
187
+ * out are the server's judgement and stay there; what is read here is what a caller can act on
188
+ * BEFORE spending — a token minted without `storage_spend` would be refused after the WAL had gone.
189
+ */
190
+ export function readDelegation(token) {
191
+ if (!token.startsWith(DELEGATION_PREFIX))
192
+ return null;
193
+ const payload = token.slice(DELEGATION_PREFIX.length).split(".")[0];
194
+ if (payload === undefined || payload === "")
195
+ return null;
196
+ try {
197
+ const parsed = JSON.parse(fromUtf8(fromBase64Url(payload)));
198
+ if (typeof parsed !== "object" || parsed === null)
199
+ return null;
200
+ const scope = Reflect.get(parsed, "s");
201
+ const user = Reflect.get(parsed, "u");
202
+ if (typeof scope !== "number" || !Number.isSafeInteger(scope) || typeof user !== "string")
203
+ return null;
204
+ return { user, scope };
205
+ }
206
+ catch {
207
+ return null;
208
+ }
209
+ }
182
210
  /** The bitmask these scope names make. */
183
211
  export function scopeMask(scopes) {
184
212
  let mask = 0;
@@ -37,7 +37,7 @@ export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.
37
37
  export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.ts";
38
38
  export type { FindOptions, ManifestIndex } from "./drive-paths.ts";
39
39
  export { setTrashed } from "./item-trash.ts";
40
- export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.ts";
40
+ export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, readDelegation, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.ts";
41
41
  export type { BusinessKeyPair, BusinessRequest, DelegationRequest, ScopeName } from "./platform-sign.ts";
42
42
  export { newAccountCode, registrationProofOf } from "./registration.ts";
43
43
  export type { RegistrationProof } from "./registration.ts";
@@ -68,8 +68,13 @@ export type { LinkAccount, ListedLink, MadeLink, OpenedLinkFile } from "./links.
68
68
  export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.ts";
69
69
  export type { ChainReader, CoinBalance, WalletBalances } from "./wallet.ts";
70
70
  export { chainReader } from "./wallet-chain.ts";
71
- export { signerAddress, signExtension, signTransfer } from "./wallet-sign.ts";
71
+ export { signerAddress, signExtension, signSponsored, signTransfer } from "./wallet-sign.ts";
72
72
  export type { SignTransfer } from "./wallet-sign.ts";
73
+ export { gasEstimate, MEASURED_GAS, quoteUpload } from "./upload-quote.ts";
74
+ export type { QuotedPart, UploadQuote, UploadQuoteAsk, UploadQuoteReads } from "./upload-quote.ts";
75
+ export { judgeSponsored } from "./sponsor-check.ts";
76
+ export type { SponsorFacts, SponsorPolicy, SponsorRefusal, SponsorSpend, SponsorVerdict } from "./sponsor-check.ts";
77
+ export { readRelayTipAddresses, sponsorFacts } from "./sponsor-facts.ts";
73
78
  export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/drive/manifest-settings.ts";
74
79
  export { classify } from "./shared/lib/drive/preview-classify.ts";
75
80
  export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.ts";
package/dist/portable.js CHANGED
@@ -62,7 +62,7 @@ export { setTrashed } from "./item-trash.js";
62
62
  // token it mints for one of its users. Making either needs no host and no server — a business
63
63
  // signs on its own machine, and a device that was handed a token presents it from a page — so
64
64
  // they belong on this side of the line rather than behind the Node entry.
65
- export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.js";
65
+ export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, readDelegation, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.js";
66
66
  // What a brand-new account is registered with, derived from its NMTS key and from nothing else.
67
67
  // ⚠ Here because a business registering a user makes the same pair the account door has always
68
68
  // taken — a second derivation for the Platform would be a second answer to one question.
@@ -93,7 +93,12 @@ export { listLinks, listLiveLinks, makeLink, openLink, revokeAllLinks, revokeLin
93
93
  // The wallet the NMTS key derives: reading it, and signing with it.
94
94
  export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.js";
95
95
  export { chainReader } from "./wallet-chain.js";
96
- export { signerAddress, signExtension, signTransfer } from "./wallet-sign.js";
96
+ export { signerAddress, signExtension, signSponsored, signTransfer } from "./wallet-sign.js";
97
+ // Money paths with no account (plan 2026-11-10): an upload's price asked with nothing opened, and
98
+ // the check an operator's server runs on a transaction another device built, before signing it.
99
+ export { gasEstimate, MEASURED_GAS, quoteUpload } from "./upload-quote.js";
100
+ export { judgeSponsored } from "./sponsor-check.js";
101
+ export { readRelayTipAddresses, sponsorFacts } from "./sponsor-facts.js";
97
102
  // WHICH of this key's wallets, and which of them have been used. One key derives a wallet at every
98
103
  // index (NCF-3 §1.3), so the account's own number is read out of the sealed list and the rest is a
99
104
  // walk. Both are here so that a library built on this package finds the SAME wallets under the same
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.57.0";
12
+ export declare const VERSION = "0.59.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.57.0";
21
+ export const VERSION = "0.59.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. */
@@ -23,18 +23,29 @@ export interface PublicCodeList {
23
23
  }
24
24
  /** How many numbers in a row publishing walks past before it stops. */
25
25
  export declare const PUBLISH_TRIES = 64;
26
- /** `GET /v1/account/public-codes`, read field by field. Codes come back in number order. */
27
- export declare function readPublicCodes(server: string, token: string): Promise<PublicCodeList>;
26
+ /**
27
+ * `GET /v1/account/public-codes`, read field by field. Codes come back in number order.
28
+ * `accountProof` goes with it when given: a delegation token reads its account's list only with it.
29
+ */
30
+ export declare function readPublicCodes(server: string, token: string, accountProof?: string): Promise<PublicCodeList>;
28
31
  /** The live codes, lowest number first. */
29
32
  export declare function liveCodes(list: PublicCodeList): PublicCodeRow[];
30
33
  /** The code this account shows and sends from unless told otherwise: its lowest-numbered live one. */
31
34
  export declare function defaultCode(list: PublicCodeList): PublicCodeRow | null;
32
35
  /** The number a new code gets: one past the highest ever published, or 0 for an account with none. */
33
36
  export declare function nextCodeIndex(list: PublicCodeList): number;
34
- /** Where a request goes and what it carries. */
37
+ /**
38
+ * Where a request goes and what it carries.
39
+ *
40
+ * ⛔ `accountProof` IS FOR A DELEGATION TOKEN. A token is its business's permission, so the three
41
+ * code doors also ask it for the code's proof — the key holder's own act, sent from wherever the
42
+ * key is straight to the server. An API key or a session needs none and sends none.
43
+ */
35
44
  export interface CodeDoor {
36
45
  server: string;
37
46
  token: string;
47
+ /** base64url of the code's proof. Absent: not sent. */
48
+ accountProof?: string | undefined;
38
49
  }
39
50
  /** What publishing answers: the number it landed on and the code a person reads. */
40
51
  export interface PublishedCode {
@@ -42,9 +42,12 @@ function readRow(value) {
42
42
  support: whole(value["support"] ?? 0),
43
43
  };
44
44
  }
45
- /** `GET /v1/account/public-codes`, read field by field. Codes come back in number order. */
46
- export async function readPublicCodes(server, token) {
47
- const answer = await request(server, "/v1/account/public-codes", { token });
45
+ /**
46
+ * `GET /v1/account/public-codes`, read field by field. Codes come back in number order.
47
+ * `accountProof` goes with it when given: a delegation token reads its account's list only with it.
48
+ */
49
+ export async function readPublicCodes(server, token, accountProof) {
50
+ const answer = await request(server, "/v1/account/public-codes", { token, ...proofOf(accountProof) });
48
51
  if (!isRecord(answer) || !Array.isArray(answer["codes"]))
49
52
  throw unreadable();
50
53
  const codes = answer["codes"].map(readRow).sort((a, b) => a.index - b.index);
@@ -74,6 +77,10 @@ export function defaultCode(list) {
74
77
  export function nextCodeIndex(list) {
75
78
  return list.codes.reduce((top, c) => Math.max(top, c.index + 1), 0);
76
79
  }
80
+ /** The proof header's option for `request`, or nothing. */
81
+ function proofOf(accountProof) {
82
+ return accountProof === undefined ? {} : { accountProof };
83
+ }
77
84
  /**
78
85
  * Publish this key's code at `from` (default: the next number), revoking `replace` in the same
79
86
  * request when it is given. Walks past numbers the server says were revoked, up to `PUBLISH_TRIES`.
@@ -93,6 +100,7 @@ export async function publishCode(crypt, code, door, from, replace) {
93
100
  const address = toBase64Url(keys.address);
94
101
  await request(door.server, "/v1/account/public-codes", {
95
102
  token: door.token,
103
+ ...proofOf(door.accountProof),
96
104
  method: "POST",
97
105
  body: {
98
106
  index,
@@ -136,12 +144,12 @@ export async function publishCode(crypt, code, door, from, replace) {
136
144
  * first share does before anything else. Answers the list as it now stands, and whether it wrote.
137
145
  */
138
146
  export async function ensureLiveCode(crypt, code, door, onPublish) {
139
- const list = await readPublicCodes(door.server, door.token);
147
+ const list = await readPublicCodes(door.server, door.token, door.accountProof);
140
148
  if (defaultCode(list) !== null)
141
149
  return { list, published: null };
142
150
  onPublish?.();
143
151
  const published = await publishCode(crypt, code, door, nextCodeIndex(list));
144
- return { list: await readPublicCodes(door.server, door.token), published };
152
+ return { list: await readPublicCodes(door.server, door.token, door.accountProof), published };
145
153
  }
146
154
  /**
147
155
  * Whether the code at `address` is on the server's revoked list — or null when the list could not
@@ -177,6 +185,7 @@ export async function revokedOnServer(server, address, buckets = new Map()) {
177
185
  export async function revokeCode(door, index) {
178
186
  await request(door.server, `/v1/account/public-codes/${requireCodeIndex(index)}/revoke`, {
179
187
  token: door.token,
188
+ ...proofOf(door.accountProof),
180
189
  method: "POST",
181
190
  });
182
191
  }
package/dist/rebuild.js CHANGED
@@ -36,6 +36,7 @@
36
36
  // passed over in silence.
37
37
  import { request } from "./api.js";
38
38
  import { NmtsError } from "./errors.js";
39
+ import { serverObjects } from "./server-objects.js";
39
40
  import { KIND_FILE } from "./shared/lib/drive/manifest-index.js";
40
41
  import { mayCarryKey, verifyKeyPairings, } from "./shared/lib/drive/rebuild-verify.js";
41
42
  import { uniqueFileName } from "./shared/lib/drive/unique-name.js";
@@ -177,32 +178,16 @@ async function readListing(base, apiKey, trash, onProgress) {
177
178
  * unavailable, which is reported as unknown rather than as zero.
178
179
  */
179
180
  async function serverRowIds(base, apiKey) {
180
- const ids = new Set();
181
- let cursor = null;
182
- for (let page = 0; page < MAX_PAGES; page += 1) {
183
- const answer = cursor === null
184
- ? await request(base, "/v1/objects", { token: apiKey })
185
- : await request(base, `/v1/objects?after=${encodeURIComponent(cursor)}`, { token: apiKey });
186
- if (typeof answer !== "object" || answer === null)
187
- return null;
188
- const raw = Reflect.get(answer, "objects");
189
- if (!Array.isArray(raw))
181
+ try {
182
+ const { rows, complete } = await serverObjects(base, apiKey);
183
+ return complete ? new Set(rows.map((row) => row.id)) : null;
184
+ }
185
+ catch (error) {
186
+ // An unreadable listing makes the cross-check unavailable — unknown, never zero.
187
+ if (error instanceof NmtsError)
190
188
  return null;
191
- const rows = raw;
192
- for (const row of rows) {
193
- if (typeof row !== "object" || row === null)
194
- return null;
195
- const id = Reflect.get(row, "id");
196
- if (typeof id !== "string")
197
- return null;
198
- ids.add(id);
199
- }
200
- const next = Reflect.get(answer, "next_cursor");
201
- if (typeof next !== "string" || next === "")
202
- return ids;
203
- cursor = next;
189
+ throw error;
204
190
  }
205
- return null;
206
191
  }
207
192
  /**
208
193
  * Turn the server's rows into entries.
package/dist/risk.d.ts CHANGED
@@ -462,6 +462,18 @@ export declare const ACTS: {
462
462
  readonly what: "Hand a storage resource to another address — signed, and not undoable.";
463
463
  readonly asksItself: true;
464
464
  };
465
+ readonly "wallet.storage.buy": {
466
+ readonly tier: "high";
467
+ readonly lock: "wallet";
468
+ readonly what: "Buy a storage resource with WAL from the wallet — signed, and not undoable.";
469
+ readonly asksItself: true;
470
+ };
471
+ readonly "wallet.storage.extend": {
472
+ readonly tier: "high";
473
+ readonly lock: "wallet";
474
+ readonly what: "Extend a user's files with WAL from the wallet — signed, and not undoable.";
475
+ readonly asksItself: true;
476
+ };
465
477
  };
466
478
  export type ActId = keyof typeof ACTS;
467
479
  export declare const ACT_IDS: ActId[];
package/dist/risk.js CHANGED
@@ -209,6 +209,10 @@ export const ACTS = {
209
209
  "wallet.hall.set": { tier: "medium", what: "Publish this name beside your wallet's address in the gift hall of fame." },
210
210
  "wallet.storage.reshape": { tier: "high", lock: "wallet", what: "Cut or join a storage resource the wallet holds — a signed transaction.", asksItself: true },
211
211
  "wallet.storage.give": { tier: "high", lock: "wallet", what: "Hand a storage resource to another address — signed, and not undoable.", asksItself: true },
212
+ // ⛔ BOTH SPEND WAL. Until 2026-11-11 `buy` fell through to the bare `wallet` read, tier none, so
213
+ // an auto mode ran a WAL purchase without the gate knowing a payment was coming.
214
+ "wallet.storage.buy": { tier: "high", lock: "wallet", what: "Buy a storage resource with WAL from the wallet — signed, and not undoable.", asksItself: true },
215
+ "wallet.storage.extend": { tier: "high", lock: "wallet", what: "Extend a user's files with WAL from the wallet — signed, and not undoable.", asksItself: true },
212
216
  };
213
217
  export const ACT_IDS = Object.keys(ACTS);
214
218
  /**
@@ -230,6 +234,10 @@ export function actOf(args) {
230
234
  case "wallet":
231
235
  if (sub === "storage") {
232
236
  const what = args.operands[1] ?? "";
237
+ if (what === "buy")
238
+ return "wallet.storage.buy";
239
+ if (what === "extend")
240
+ return "wallet.storage.extend";
233
241
  return what === "transfer" ? "wallet.storage.give" : what === "split" || what === "merge" ? "wallet.storage.reshape" : "wallet";
234
242
  }
235
243
  // ⛔ `hall` READS UNTIL A NAME IS NAMED. `--name` and `--remove` both write the listing, so
@@ -0,0 +1,21 @@
1
+ /** How many pages one walk follows. At the server's page size that is far past any real account. */
2
+ export declare const MAX_OBJECT_PAGES = 200;
3
+ /** One row the server holds. */
4
+ export interface ServerObject {
5
+ id: string;
6
+ /** True for a file in the trash: still held, on its way out. */
7
+ trashed: boolean;
8
+ }
9
+ /** Every row, and whether the walk reached the end of the listing. */
10
+ export interface ServerObjects {
11
+ rows: ServerObject[];
12
+ /** False when the walk stopped at `MAX_OBJECT_PAGES`. ⛔ A cut walk is never "that was all". */
13
+ complete: boolean;
14
+ }
15
+ /**
16
+ * Every row the server holds for the account `token` speaks for.
17
+ *
18
+ * ⛔ A ROW THIS CANNOT READ IS A REFUSAL. Skipping one would shrink the set of things the server is
19
+ * known to hold, which each caller then acts on as if it were whole.
20
+ */
21
+ export declare function serverObjects(base: string, token: string): Promise<ServerObjects>;
@@ -0,0 +1,68 @@
1
+ // Every row the NMTS server holds for an account, live or trashed — read with nothing but the
2
+ // account's credential.
3
+ //
4
+ // ⛔ `/v1/objects` AND NOT `/v1/items?deleted=true`. The trash listing stops at the retention window,
5
+ // so a row that is past thirty days and not yet erased is missing from it. `/v1/objects` is the
6
+ // reconciliation view: every row of the account, with no window on it, and no name — the layer a
7
+ // caller without the NMTS key can use (`api/src/routes/items.rs`, `list_objects`).
8
+ //
9
+ // ⛔ ONE PAGER FOR EVERY CALLER. `nmts sweep`, `rebuild` and an operator keeping a user's files alive
10
+ // all walk this listing; three copies of the cursor loop were three places to disagree about what
11
+ // an unreadable row means.
12
+ //
13
+ // ⚠ The two calls are written out rather than built from a variable so that the gate comparing this
14
+ // tool's addresses against the server's routes (`check:cli-routes`) can see them both. It reads
15
+ // literal strings.
16
+ import { request } from "./api.js";
17
+ import { NmtsError } from "./errors.js";
18
+ /** How many pages one walk follows. At the server's page size that is far past any real account. */
19
+ export const MAX_OBJECT_PAGES = 200;
20
+ /**
21
+ * Every row the server holds for the account `token` speaks for.
22
+ *
23
+ * ⛔ A ROW THIS CANNOT READ IS A REFUSAL. Skipping one would shrink the set of things the server is
24
+ * known to hold, which each caller then acts on as if it were whole.
25
+ */
26
+ export async function serverObjects(base, token) {
27
+ const rows = [];
28
+ let cursor = null;
29
+ for (let page = 0; page < MAX_OBJECT_PAGES; page += 1) {
30
+ const answer = cursor === null
31
+ ? await request(base, "/v1/objects", { token })
32
+ : await request(base, `/v1/objects?after=${encodeURIComponent(cursor)}`, { token });
33
+ const read = asObjectsAnswer(answer);
34
+ rows.push(...read.rows);
35
+ if (read.next === null)
36
+ return { rows, complete: true };
37
+ cursor = read.next;
38
+ }
39
+ return { rows, complete: false };
40
+ }
41
+ /** What `GET /v1/objects` answers, narrowed rather than trusted. */
42
+ function asObjectsAnswer(value) {
43
+ const unreadable = () => {
44
+ throw new NmtsError("The server answered with an item listing this version cannot read.", {
45
+ nextStep: "Nothing was changed. Update this tool.",
46
+ });
47
+ };
48
+ if (typeof value !== "object" || value === null)
49
+ return unreadable();
50
+ const raw = Reflect.get(value, "objects");
51
+ if (!Array.isArray(raw))
52
+ return unreadable();
53
+ const objects = raw;
54
+ const rows = [];
55
+ for (const object of objects) {
56
+ if (typeof object !== "object" || object === null)
57
+ return unreadable();
58
+ const id = Reflect.get(object, "id");
59
+ if (typeof id !== "string")
60
+ return unreadable();
61
+ const deleted = Reflect.get(object, "deleted_at");
62
+ rows.push({ id, trashed: typeof deleted === "string" && deleted !== "" });
63
+ }
64
+ const next = Reflect.get(value, "next_cursor");
65
+ if (next !== null && next !== undefined && typeof next !== "string")
66
+ return unreadable();
67
+ return { rows, next: typeof next === "string" && next !== "" ? next : null };
68
+ }
package/dist/sharing.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface ShareAccount {
11
11
  readonly accountId: string;
12
12
  /** The chain the stored parts are on, as `resolveNetwork` answers it. */
13
13
  readonly network: string;
14
- /** ⛔ base64url of the code's proof, for the two sending doors only. Absent: not sent. */
14
+ /** ⛔ base64url of the code's proof, for the sending and code doors only. Absent: not sent. */
15
15
  readonly accountProof?: string | undefined;
16
16
  }
17
17
  /** One file of the account's list that a share can carry, and its full path. */