@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.
- package/CHANGELOG.md +26 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/arg-options.d.ts +2 -0
- package/dist/args.js +2 -0
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/expiring.js +2 -2
- package/dist/commands/sweep.js +6 -64
- package/dist/commands/wallet-storage-buy.d.ts +22 -0
- package/dist/commands/wallet-storage-buy.js +111 -0
- package/dist/commands/wallet-storage-extend.d.ts +23 -0
- package/dist/commands/wallet-storage-extend.js +137 -0
- package/dist/commands/wallet.d.ts +3 -0
- package/dist/commands/wallet.js +5 -1
- package/dist/extend-chain.js +19 -3
- package/dist/extend-plan.d.ts +38 -0
- package/dist/extend-plan.js +61 -0
- package/dist/help-options.js +8 -3
- package/dist/help.js +5 -0
- package/dist/main.js +1 -1
- package/dist/platform-sign.d.ts +12 -0
- package/dist/platform-sign.js +29 -1
- package/dist/portable.d.ts +7 -2
- package/dist/portable.js +7 -2
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-codes.d.ts +14 -3
- package/dist/public-codes.js +14 -5
- package/dist/rebuild.js +9 -24
- package/dist/risk.d.ts +12 -0
- package/dist/risk.js +8 -0
- package/dist/server-objects.d.ts +21 -0
- package/dist/server-objects.js +68 -0
- package/dist/sharing.d.ts +1 -1
- package/dist/sharing.js +12 -40
- package/dist/sponsor-check.d.ts +56 -0
- package/dist/sponsor-check.js +270 -0
- package/dist/sponsor-facts.d.ts +10 -0
- package/dist/sponsor-facts.js +75 -0
- package/dist/storage-control/buy.d.ts +65 -0
- package/dist/storage-control/buy.js +145 -0
- package/dist/storage-control/extend-for.d.ts +84 -0
- package/dist/storage-control/extend-for.js +204 -0
- package/dist/storage-control/extend.d.ts +57 -12
- package/dist/storage-control/extend.js +51 -45
- package/dist/storage-control-chain.d.ts +7 -0
- package/dist/storage-control-chain.js +19 -1
- package/dist/storage-control.d.ts +6 -2
- package/dist/storage-control.js +5 -2
- package/dist/upload-quote.d.ts +93 -0
- package/dist/upload-quote.js +135 -0
- package/dist/wallet-sign.d.ts +24 -0
- package/dist/wallet-sign.js +31 -1
- package/docs/commands/wallet.md +13 -1
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -24,7 +24,7 @@ import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "../dr
|
|
|
24
24
|
import { NmtsError } from "../errors.js";
|
|
25
25
|
import { budgetFacts, readBudget } from "../extend-budget.js";
|
|
26
26
|
import { daysLeftUntilEpoch, stageOf } from "../expiry.js";
|
|
27
|
-
import { asExtendPreview, chooseEpochs, headroom, soonestEnd, } from "../extend-plan.js";
|
|
27
|
+
import { asExtendPreview, chooseEpochs, headroom, nothingToExtend, readWindowOrRefuse, soonestEnd, refuseUnheld, } from "../extend-plan.js";
|
|
28
28
|
import { isRecord } from "../guards.js";
|
|
29
29
|
import { readFileList } from "../manifest.js";
|
|
30
30
|
import { activeWalletOf } from "../shared/lib/drive/manifest-settings.js";
|
|
@@ -53,28 +53,44 @@ export async function planExtension(input, target, seams) {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
const path = fullPathOf(buildIndex(entries), entry);
|
|
56
|
+
// ⛔ WHICH WALLET PAYS comes out of the list this run already read, before the price is measured
|
|
57
|
+
// against a balance: the address below is the one that will sign.
|
|
58
|
+
const wallet = seams.wallet ?? activeWalletOf(settings);
|
|
59
|
+
const address = seams.payer?.address ?? (await walletAddress(input.code, wallet));
|
|
60
|
+
const reads = await (seams.readChain ?? defaultReads)(input.network);
|
|
61
|
+
const item = await planItemExtension(input, { id: entry.id, label: path }, {
|
|
62
|
+
reads,
|
|
63
|
+
window: await readWindowOrRefuse(reads, input.network),
|
|
64
|
+
address,
|
|
65
|
+
epochs: seams.epochs,
|
|
66
|
+
now: seams.now,
|
|
67
|
+
hints: seams.hints,
|
|
68
|
+
});
|
|
69
|
+
return { ...item, path, wallet, settings };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Plan one file's extension from its id. The NMTS server says which blobs, the chain says how long
|
|
73
|
+
* each runs and who holds it, and the paying wallet's balances are read against the price.
|
|
74
|
+
*
|
|
75
|
+
* ⛔ NO NMTS KEY. This is what lets a business's server keep a user's files alive with the user's
|
|
76
|
+
* delegation token and its own wallet, while the key that opens the files stays on the user's
|
|
77
|
+
* device. The file is named by `item.label`: its path when a key opened the list, its id when
|
|
78
|
+
* nothing could.
|
|
79
|
+
*/
|
|
80
|
+
export async function planItemExtension(where, item, seams) {
|
|
81
|
+
const path = item.label;
|
|
56
82
|
// ⛔ THE SERVER SAYS WHICH BLOBS, AND NOTHING ELSE. Its `expiry_epoch` is client-reported and
|
|
57
83
|
// advisory; anything that spends money reads the chain's own answer below.
|
|
58
|
-
const preview = asExtendPreview(await request(
|
|
59
|
-
token:
|
|
84
|
+
const preview = asExtendPreview(await request(where.server, `/v1/items/${encodeURIComponent(item.id)}/extend-preview`, {
|
|
85
|
+
token: where.apiKey,
|
|
60
86
|
}));
|
|
61
87
|
if (preview.targets.length === 0) {
|
|
62
|
-
throw new NmtsError(`
|
|
88
|
+
throw new NmtsError(`EXTEND_NOTHING: nothing on "${path}" can be extended from here.`, {
|
|
63
89
|
exitCode: 4,
|
|
64
90
|
nextStep: nothingToExtend(preview),
|
|
65
91
|
});
|
|
66
92
|
}
|
|
67
|
-
const reads =
|
|
68
|
-
const window = await reads.readWindow();
|
|
69
|
-
if (window === null) {
|
|
70
|
-
// ⛔ Not "nothing needs extending". The two look identical from outside and mean opposite things.
|
|
71
|
-
throw new NmtsError(`The ${input.network} storage network could not be read.`, {
|
|
72
|
-
exitCode: 1,
|
|
73
|
-
nextStep: `Nothing was signed and nothing was charged. Which epoch the network is in, and how far ` +
|
|
74
|
-
`ahead it will sell, are facts only the chain has — this will not spend against a ` +
|
|
75
|
-
`guess. Try again, or name a different Sui node in NMTS_SUI_RPC.`,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
93
|
+
const { reads, window } = seams;
|
|
78
94
|
const clock = window.clock;
|
|
79
95
|
const objectIds = preview.targets.map((t) => t.objectId);
|
|
80
96
|
const leases = await reads.readLeases(objectIds);
|
|
@@ -87,7 +103,7 @@ export async function planExtension(input, target, seams) {
|
|
|
87
103
|
}
|
|
88
104
|
const stage = stageOf(clock, endEpoch, seams.now);
|
|
89
105
|
if (stage === "lapsed") {
|
|
90
|
-
throw new NmtsError(`
|
|
106
|
+
throw new NmtsError(`EXTEND_LAPSED: the storage term for "${path}" has already ended.`, {
|
|
91
107
|
exitCode: 4,
|
|
92
108
|
nextStep: seams.hints?.lapsed ??
|
|
93
109
|
`Nothing was signed and nothing was charged. A lease is extended before it ends — once it ` +
|
|
@@ -95,6 +111,9 @@ export async function planExtension(input, target, seams) {
|
|
|
95
111
|
`Fetching the file is what says whether they can still be read.`,
|
|
96
112
|
});
|
|
97
113
|
}
|
|
114
|
+
// ⛔ BEFORE THE PRICE AND BEFORE ANY SIGNATURE: a blob this wallet does not hold cannot be
|
|
115
|
+
// extended by it, and the chain would only say so after somebody had been asked to sign.
|
|
116
|
+
refuseUnheld(leases, seams.address, path);
|
|
98
117
|
const epochs = chooseEpochs(seams.epochs, headroom(leases, clock.current, window.maxAhead));
|
|
99
118
|
const newEndEpoch = endEpoch + epochs;
|
|
100
119
|
const before = daysLeftUntilEpoch(clock, endEpoch, seams.now);
|
|
@@ -104,16 +123,12 @@ export async function planExtension(input, target, seams) {
|
|
|
104
123
|
const frost = await reads.quote(leases, epochs);
|
|
105
124
|
const cohort = Math.max(0, ...preview.targets.map((t) => t.sharedItems));
|
|
106
125
|
const unreachable = preview.treasuryParts + preview.untrackedParts;
|
|
107
|
-
|
|
108
|
-
// against a balance: the address below is the one that will sign.
|
|
109
|
-
const wallet = seams.wallet ?? activeWalletOf(settings);
|
|
110
|
-
const address = seams.payer?.address ?? (await walletAddress(input.code, wallet));
|
|
111
|
-
const budget = await readBudget(reads, { address, objectIds, epochs, priceFrost: frost });
|
|
126
|
+
const budget = await readBudget(reads, { address: seams.address, objectIds, epochs, priceFrost: frost });
|
|
112
127
|
return {
|
|
113
128
|
facts: {
|
|
114
129
|
file: path,
|
|
115
|
-
itemId:
|
|
116
|
-
network:
|
|
130
|
+
itemId: item.id,
|
|
131
|
+
network: where.network,
|
|
117
132
|
epoch: clock.current,
|
|
118
133
|
endEpoch,
|
|
119
134
|
epochs,
|
|
@@ -128,14 +143,12 @@ export async function planExtension(input, target, seams) {
|
|
|
128
143
|
partsThatCannotBeExtended: unreachable,
|
|
129
144
|
...budgetFacts(budget),
|
|
130
145
|
},
|
|
131
|
-
itemId:
|
|
132
|
-
path,
|
|
146
|
+
itemId: item.id,
|
|
133
147
|
objectIds,
|
|
148
|
+
bytes: leases.reduce((sum, lease) => sum + lease.size, 0),
|
|
134
149
|
epochs,
|
|
135
|
-
wallet,
|
|
136
150
|
stage,
|
|
137
151
|
budget,
|
|
138
|
-
settings,
|
|
139
152
|
};
|
|
140
153
|
}
|
|
141
154
|
/**
|
|
@@ -154,10 +167,17 @@ export async function applyExtension(input, plan, seams = {}) {
|
|
|
154
167
|
epochs: plan.epochs,
|
|
155
168
|
});
|
|
156
169
|
seams.onSigned?.(digest);
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
return recordExtension(input, plan, digest);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Tell the NMTS server about an extension that is already signed and paid for.
|
|
174
|
+
*
|
|
175
|
+
* From here the storage IS extended. Recording it is bookkeeping, and a failure to record must
|
|
176
|
+
* never be reported as a failure to extend — that reading invites a second run, which pays again.
|
|
177
|
+
*/
|
|
178
|
+
export async function recordExtension(where, plan, digest) {
|
|
159
179
|
try {
|
|
160
|
-
const recorded = await request(
|
|
180
|
+
const recorded = await request(where.server, `/v1/items/${encodeURIComponent(plan.itemId)}/extended`, { method: "POST", token: where.apiKey, body: { epochs: plan.epochs, tx_digest: digest } });
|
|
161
181
|
return { digest, recorded: true, replay: isRecord(recorded) && recorded["replay"] === true, notRecorded: null };
|
|
162
182
|
}
|
|
163
183
|
catch (error) {
|
|
@@ -169,21 +189,7 @@ export async function applyExtension(input, plan, seams = {}) {
|
|
|
169
189
|
};
|
|
170
190
|
}
|
|
171
191
|
}
|
|
172
|
-
/** Why a file has nothing to extend, said as the two different things it can be. */
|
|
173
|
-
export function nothingToExtend(preview) {
|
|
174
|
-
const parts = [];
|
|
175
|
-
if (preview.treasuryParts > 0) {
|
|
176
|
-
parts.push(`${preview.treasuryParts} part${preview.treasuryParts === 1 ? " is" : "s are"} on storage NMTS ` +
|
|
177
|
-
`paid for, which this account cannot extend`);
|
|
178
|
-
}
|
|
179
|
-
if (preview.untrackedParts > 0) {
|
|
180
|
-
parts.push(`${preview.untrackedParts} part${preview.untrackedParts === 1 ? " has" : "s have"} no ` +
|
|
181
|
-
`recorded storage object, so there is nothing to name on the chain`);
|
|
182
|
-
}
|
|
183
|
-
const why = parts.length === 0 ? "The server lists no storage object for it." : `${parts.join(", and ")}.`;
|
|
184
|
-
return `Nothing was signed and nothing was charged. ${why} Opening the account in a browser shows what it is stored on.`;
|
|
185
|
-
}
|
|
186
192
|
/** The real chain reads. Imported only when no seam was supplied — it loads the storage SDK. */
|
|
187
|
-
async function defaultReads(network) {
|
|
193
|
+
export async function defaultReads(network) {
|
|
188
194
|
return (await import("../extend-chain.js")).extendReads(network);
|
|
189
195
|
}
|
|
@@ -18,6 +18,13 @@ export type StorageOpShape = {
|
|
|
18
18
|
kind: "transfer";
|
|
19
19
|
objectId: string;
|
|
20
20
|
to: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "buy";
|
|
23
|
+
sizeBytes: number;
|
|
24
|
+
epochs: number;
|
|
25
|
+
priceFrost: bigint;
|
|
26
|
+
walType: string;
|
|
27
|
+
systemObjectId: string;
|
|
21
28
|
};
|
|
22
29
|
/** The transaction one shape is, for `sender`. */
|
|
23
30
|
export declare function storageOpTransaction(shape: StorageOpShape, input: {
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
// · `fuse_periods(&mut Storage, Storage)` same size, adjacent periods; the second is consumed
|
|
14
14
|
// ⛔ A returned resource must be transferred or the transaction is refused at assembly for an
|
|
15
15
|
// unused value; a consumed one needs nothing. The dry run is the final judge of every rule.
|
|
16
|
-
|
|
16
|
+
//
|
|
17
|
+
// ⛔ BUYING IS THE FIFTH SHAPE (2026-11-10 · Deponejo gap B2): `system::reserve_space(&mut System,
|
|
18
|
+
// u64 storage_amount, u32 epochs_ahead, &mut Coin<WAL>) → Storage`, paid from a WAL coin of
|
|
19
|
+
// exactly the price the review read, the zero coin destroyed and the resource sent to the sender.
|
|
20
|
+
// The amount is the RESOURCE's size, the encoded size a listing shows, not a file's size. The
|
|
21
|
+
// price travels in the shape, so the coin the fee was measured with is the coin that is signed.
|
|
22
|
+
import { coinWithBalance, Transaction } from "@mysten/sui/transactions";
|
|
17
23
|
import { walrusClient, netGasFee } from "./extend-chain.js";
|
|
18
24
|
import { splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
19
25
|
import { dryRun } from "./shared/lib/wallet/chain-calls.js";
|
|
@@ -45,6 +51,18 @@ export function storageOpTransaction(shape, input) {
|
|
|
45
51
|
case "transfer":
|
|
46
52
|
tx.transferObjects([tx.object(shape.objectId)], shape.to);
|
|
47
53
|
return tx;
|
|
54
|
+
case "buy": {
|
|
55
|
+
const payment = tx.add(coinWithBalance({ balance: shape.priceFrost, type: shape.walType }));
|
|
56
|
+
const storage = tx.moveCall({
|
|
57
|
+
package: input.walrusPackageId,
|
|
58
|
+
module: "system",
|
|
59
|
+
function: "reserve_space",
|
|
60
|
+
arguments: [tx.object(shape.systemObjectId), tx.pure.u64(shape.sizeBytes), tx.pure.u32(shape.epochs), payment],
|
|
61
|
+
});
|
|
62
|
+
tx.moveCall({ target: "0x2::coin::destroy_zero", typeArguments: [shape.walType], arguments: [payment] });
|
|
63
|
+
tx.transferObjects([storage], input.sender);
|
|
64
|
+
return tx;
|
|
65
|
+
}
|
|
48
66
|
}
|
|
49
67
|
}
|
|
50
68
|
export function storageOpsReads(network) {
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export type { StorageHints } from "./storage-control/hints.ts";
|
|
2
2
|
export { formatBytes, listStorage, readOrRefuse } from "./storage-control/list.ts";
|
|
3
3
|
export type { ReadWalletStorage, StorageItem, StorageListing, StorageRead, StorageStatus, } from "./storage-control/list.ts";
|
|
4
|
-
export { applyExtension,
|
|
4
|
+
export { applyExtension, planExtension } from "./storage-control/extend.ts";
|
|
5
5
|
export type { ExtendApplySeams, ExtendFacts, ExtendInput, ExtendOutcome, ExtendPlan, ExtendPlanSeams, } from "./storage-control/extend.ts";
|
|
6
|
+
export { extendFor } from "./storage-control/extend-for.ts";
|
|
7
|
+
export type { ExtendForAsk, ExtendForFile, ExtendForInput, ExtendForResult, ExtendForSeams, } from "./storage-control/extend-for.ts";
|
|
6
8
|
export { planStorageOp, reshapeStorage } from "./storage-control/reshape.ts";
|
|
7
9
|
export type { ReshapeContext, ReshapeOutcome, ReshapeSeams, StorageOp, StorageOpAsk, StorageOpPlan, StorageOpResult, StorageOpReview, StorageShape, } from "./storage-control/reshape.ts";
|
|
10
|
+
export { buyStorage } from "./storage-control/buy.ts";
|
|
11
|
+
export type { BuyAsk, BuyOutcome, BuyReads, BuyReview, BuySeams } from "./storage-control/buy.ts";
|
|
8
12
|
export type { StorageOpShape, StorageOpsReads } from "./storage-control-chain.ts";
|
|
9
13
|
export type { StorageResource } from "./shared/lib/storage-control/chain.ts";
|
|
10
|
-
export { DEFAULT_EXTEND_EPOCHS } from "./extend-plan.ts";
|
|
14
|
+
export { DEFAULT_EXTEND_EPOCHS, nothingToExtend } from "./extend-plan.ts";
|
|
11
15
|
export type { ExtendReads, SignExtension } from "./extend-plan.ts";
|
|
12
16
|
export type { Budget } from "./extend-budget.ts";
|
|
13
17
|
export type { SignStorageOp } from "./wallet-sign-seams.ts";
|
package/dist/storage-control.js
CHANGED
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
// entry bundles what this exports, and the chain and the signer are loaded only when no seam was
|
|
20
20
|
// supplied.
|
|
21
21
|
export { formatBytes, listStorage, readOrRefuse } from "./storage-control/list.js";
|
|
22
|
-
export { applyExtension,
|
|
22
|
+
export { applyExtension, planExtension } from "./storage-control/extend.js";
|
|
23
|
+
// A business extending a user's files from its own wallet, with the user's token and no user key.
|
|
24
|
+
export { extendFor } from "./storage-control/extend-for.js";
|
|
23
25
|
export { planStorageOp, reshapeStorage } from "./storage-control/reshape.js";
|
|
24
|
-
export {
|
|
26
|
+
export { buyStorage } from "./storage-control/buy.js";
|
|
27
|
+
export { DEFAULT_EXTEND_EPOCHS, nothingToExtend } from "./extend-plan.js";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ExtendWindow } from "./extend-plan.ts";
|
|
2
|
+
import type { Network } from "./network.ts";
|
|
3
|
+
import type { PaddingRule } from "./shared/lib/crypto/size-padding.ts";
|
|
4
|
+
import { type PartQuote } from "./upload-wallet-plan.ts";
|
|
5
|
+
/**
|
|
6
|
+
* The gas one part's two transactions used, measured on testnet (2026-11-10, this unit's runs).
|
|
7
|
+
*
|
|
8
|
+
* ⛔ COMPUTATION IS IN GAS UNITS, STORAGE IN MIST. Sui charges computation as units × the reference
|
|
9
|
+
* gas price, which each network sets per epoch, and storage at a fixed price per byte; the
|
|
10
|
+
* rebate is what deleting the objects later gives back. Keeping the units lets the estimate
|
|
11
|
+
* follow the network's price instead of freezing testnet's.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MEASURED_GAS: {
|
|
14
|
+
readonly source: string;
|
|
15
|
+
readonly register: {
|
|
16
|
+
readonly computationUnits: 1000n;
|
|
17
|
+
readonly storageMist: 115732800n;
|
|
18
|
+
readonly rebateMist: 112757523n;
|
|
19
|
+
};
|
|
20
|
+
readonly certify: {
|
|
21
|
+
readonly computationUnits: 1000n;
|
|
22
|
+
readonly storageMist: 2006400n;
|
|
23
|
+
readonly rebateMist: 1975802n;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** What the quote asks for. */
|
|
27
|
+
export interface UploadQuoteAsk {
|
|
28
|
+
/** The file's size in bytes, before sealing. */
|
|
29
|
+
bytes: number;
|
|
30
|
+
/** Storage-network epochs. Default 2, the term `put` buys. */
|
|
31
|
+
epochs?: number | undefined;
|
|
32
|
+
/** How the last part is padded. Default `padme`, a new account's rule. */
|
|
33
|
+
padding?: PaddingRule | undefined;
|
|
34
|
+
/** Bytes of the file per part. Default 64 MiB, `put`'s. */
|
|
35
|
+
partSize?: number | undefined;
|
|
36
|
+
}
|
|
37
|
+
/** One part, priced. Base units throughout, as decimal strings so JSON carries them whole. */
|
|
38
|
+
export interface QuotedPart {
|
|
39
|
+
/** Bytes the storage network holds for this part, sealing and padding included. */
|
|
40
|
+
sealedBytes: number;
|
|
41
|
+
/**
|
|
42
|
+
* What the part occupies once the network has encoded it — the size a storage resource must
|
|
43
|
+
* have to hold it (`buyStorage({ sizeBytes })`, `put(…, { storage: id })`). ⚠ Far above
|
|
44
|
+
* `sealedBytes` for a small part: the encoding carries metadata for every shard.
|
|
45
|
+
*/
|
|
46
|
+
encodedBytes: number;
|
|
47
|
+
storageFrost: string;
|
|
48
|
+
writeFrost: string;
|
|
49
|
+
tipMist: string;
|
|
50
|
+
}
|
|
51
|
+
/** The answer. */
|
|
52
|
+
export interface UploadQuote {
|
|
53
|
+
network: Network;
|
|
54
|
+
bytes: number;
|
|
55
|
+
epochs: number;
|
|
56
|
+
/** The epoch the storage would end at if it were bought now. */
|
|
57
|
+
endEpoch: number;
|
|
58
|
+
parts: QuotedPart[];
|
|
59
|
+
sealedBytes: number;
|
|
60
|
+
/** The parts' encoded sizes added up: what one resource holding the whole upload must have. */
|
|
61
|
+
encodedBytes: number;
|
|
62
|
+
/** WAL for the storage and the write, in FROST. */
|
|
63
|
+
walFrost: string;
|
|
64
|
+
/** SUI for the relay's tip, in MIST. */
|
|
65
|
+
tipMist: string;
|
|
66
|
+
/** SUI for the chain fees of every part's two transactions, in MIST. ⚠ An estimate — see `gasSource`. */
|
|
67
|
+
gasEstimateMist: string;
|
|
68
|
+
/** Where `gasEstimateMist` came from. */
|
|
69
|
+
gasSource: string;
|
|
70
|
+
/** The relay the tip is for. Another relay charges its own tip; the storage nodes charge none. */
|
|
71
|
+
relay: string;
|
|
72
|
+
/**
|
|
73
|
+
* What the same upload costs on the credit rail. ⛔ NULL WHEN `epochs` IS NOT THE CREDIT TERM:
|
|
74
|
+
* a credit buys one mebibyte for exactly 2 epochs, and the credit rail sells no other term.
|
|
75
|
+
*/
|
|
76
|
+
credits: number | null;
|
|
77
|
+
}
|
|
78
|
+
/** The chain, as the quote reads it. ⚠ A seam — a test hands in a table. */
|
|
79
|
+
export interface UploadQuoteReads {
|
|
80
|
+
readWindow(): Promise<ExtendWindow | null>;
|
|
81
|
+
quoteParts(sealedLens: readonly number[], epochs: number): Promise<PartQuote[]>;
|
|
82
|
+
/** The network's reference gas price now, in MIST per unit, or null when it could not be read. */
|
|
83
|
+
referenceGasPrice(): Promise<bigint | null>;
|
|
84
|
+
/** What `sealedLen` bytes occupy once encoded — the chain's own function, asked with no sender. */
|
|
85
|
+
encodedLength(sealedLen: number): Promise<number>;
|
|
86
|
+
}
|
|
87
|
+
/** The measured gas of `parts` parts at `price` MIST per unit. */
|
|
88
|
+
export declare function gasEstimate(parts: number, price: bigint): bigint;
|
|
89
|
+
/** The price of an upload of `ask.bytes` for `ask.epochs`, with nothing opened and nothing signed. */
|
|
90
|
+
export declare function quoteUpload(network: Network, ask: UploadQuoteAsk, seams?: {
|
|
91
|
+
reads?: UploadQuoteReads;
|
|
92
|
+
relay?: string;
|
|
93
|
+
}): Promise<UploadQuote>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// What an upload of N bytes for E epochs costs, asked with no file, no account and no wallet.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ WHY (spec 2026-09-20 Deponejo · gap C · plan 2026-11-10 §1.1). A business pricing an invoice
|
|
4
|
+
// has to say "N bytes for E epochs is this much WAL, this much SUI, this many credits" before
|
|
5
|
+
// its customer has a funded wallet — often before the customer has an account at all. Until now
|
|
6
|
+
// the price came back only from `put(…, { dryRun: true })`, which needs the file and an opened
|
|
7
|
+
// account. A business that had to call Walrus directly to price an invoice had a reason to build
|
|
8
|
+
// on Walrus rather than on NMTS.
|
|
9
|
+
//
|
|
10
|
+
// ⛔ THE SAME ARITHMETIC AS THE UPLOAD, NOT A COPY. The part plan, the padding of the last part and
|
|
11
|
+
// the sealed length come from `planAndPrice` — the function `put` prices with — and the WAL and
|
|
12
|
+
// the relay's tip from `walletUploadReads().quoteParts`, the read `walletPut` makes. So the WAL
|
|
13
|
+
// this answers for a sealed size is the WAL the upload's review answers for the same size.
|
|
14
|
+
//
|
|
15
|
+
// ⚠ THE GAS IS AN ESTIMATE AND SAYS SO. An upload measures its register fee by dry-running the exact
|
|
16
|
+
// transaction with the payer's coins; with no payer there are no coins to dry-run with. The
|
|
17
|
+
// estimate is the gas the two transactions used on testnet (`MEASURED_GAS` below, with the
|
|
18
|
+
// digests it came from), its computation part scaled by the network's reference gas price read
|
|
19
|
+
// now. The field is named `gasEstimateMist` and `gasSource` says where the number came from.
|
|
20
|
+
//
|
|
21
|
+
// ⚠ NOTHING HERE WRITES TO A STREAM OR REACHES FOR `node:`: the SDK's browser entry runs it.
|
|
22
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
23
|
+
import { NmtsError } from "./errors.js";
|
|
24
|
+
import { DEFAULT_PART_BYTES, sealedLenFor } from "./seal.js";
|
|
25
|
+
import { creditsFor, planAndPrice, UPLOAD_EPOCHS } from "./upload-price.js";
|
|
26
|
+
import { chooseUploadEpochs } from "./upload-wallet-plan.js";
|
|
27
|
+
/**
|
|
28
|
+
* The gas one part's two transactions used, measured on testnet (2026-11-10, this unit's runs).
|
|
29
|
+
*
|
|
30
|
+
* ⛔ COMPUTATION IS IN GAS UNITS, STORAGE IN MIST. Sui charges computation as units × the reference
|
|
31
|
+
* gas price, which each network sets per epoch, and storage at a fixed price per byte; the
|
|
32
|
+
* rebate is what deleting the objects later gives back. Keeping the units lets the estimate
|
|
33
|
+
* follow the network's price instead of freezing testnet's.
|
|
34
|
+
*/
|
|
35
|
+
export const MEASURED_GAS = {
|
|
36
|
+
source: "measured on testnet 2026-11-10 from one sponsored upload of a 1 MiB file (register " +
|
|
37
|
+
"8XLr5kR7n9pypv5PznrqhUtFc7QAK9k7HbHBts5aF3ds, certify E9JtBWV6ntyWQuaucrkGLrZDrF4JiQV2knFnwJzvLbAN); " +
|
|
38
|
+
"computation scaled by the reference gas price read now",
|
|
39
|
+
// Most of register's storage charge is the shared system object being rewritten, and most of it
|
|
40
|
+
// comes back as the rebate in the same transaction: the net is about 3 million MIST.
|
|
41
|
+
register: { computationUnits: 1000n, storageMist: 115732800n, rebateMist: 112757523n },
|
|
42
|
+
certify: { computationUnits: 1000n, storageMist: 2006400n, rebateMist: 1975802n },
|
|
43
|
+
};
|
|
44
|
+
/** The relay a quote is for and the reads behind it, for one network. */
|
|
45
|
+
async function defaultReads(network) {
|
|
46
|
+
const [{ relayHost }, { walletUploadReads }, { suiClient }] = await Promise.all([
|
|
47
|
+
import("./walrus.js"),
|
|
48
|
+
import("./upload-wallet-chain.js"),
|
|
49
|
+
import("./sui-rpc.js"),
|
|
50
|
+
]);
|
|
51
|
+
const relay = relayHost(network);
|
|
52
|
+
const upload = walletUploadReads(network, relay);
|
|
53
|
+
return {
|
|
54
|
+
relay,
|
|
55
|
+
reads: {
|
|
56
|
+
readWindow: () => upload.readWindow(),
|
|
57
|
+
quoteParts: (lens, epochs) => upload.quoteParts(lens, epochs),
|
|
58
|
+
// ⚠ A READ WITH NO WALLET: the simulation runs with its checks off, so any sender will do.
|
|
59
|
+
encodedLength: (sealedLen) => upload.encodedLength(normalizeSuiAddress("0x0"), sealedLen),
|
|
60
|
+
async referenceGasPrice() {
|
|
61
|
+
try {
|
|
62
|
+
const { referenceGasPrice } = await suiClient(network).core.getReferenceGasPrice();
|
|
63
|
+
return BigInt(referenceGasPrice);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** The measured gas of `parts` parts at `price` MIST per unit. */
|
|
73
|
+
export function gasEstimate(parts, price) {
|
|
74
|
+
const one = (g) => g.computationUnits * price + g.storageMist - g.rebateMist;
|
|
75
|
+
return BigInt(parts) * (one(MEASURED_GAS.register) + one(MEASURED_GAS.certify));
|
|
76
|
+
}
|
|
77
|
+
/** The price of an upload of `ask.bytes` for `ask.epochs`, with nothing opened and nothing signed. */
|
|
78
|
+
export async function quoteUpload(network, ask, seams = {}) {
|
|
79
|
+
if (!Number.isSafeInteger(ask.bytes) || ask.bytes < 0) {
|
|
80
|
+
throw new NmtsError(`A size is a whole number of bytes, 0 or more: ${String(ask.bytes)}.`, {
|
|
81
|
+
exitCode: 2,
|
|
82
|
+
nextStep: "Nothing was read from the chain. Pass the file's size in bytes.",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const partSize = ask.partSize ?? DEFAULT_PART_BYTES;
|
|
86
|
+
if (!Number.isSafeInteger(partSize) || partSize <= 0) {
|
|
87
|
+
throw new NmtsError(`A part size is a positive whole number of bytes: ${String(ask.partSize)}.`, { exitCode: 2 });
|
|
88
|
+
}
|
|
89
|
+
const { plan, sealFor } = planAndPrice(ask.bytes, partSize, ask.padding ?? "padme");
|
|
90
|
+
const sealedLens = plan.map((range) => sealedLenFor(sealFor(range)));
|
|
91
|
+
const found = seams.reads === undefined ? await defaultReads(network) : { relay: seams.relay ?? "", reads: seams.reads };
|
|
92
|
+
const window = await found.reads.readWindow();
|
|
93
|
+
if (window === null) {
|
|
94
|
+
throw new NmtsError(`The ${network} storage network could not be read.`, {
|
|
95
|
+
exitCode: 1,
|
|
96
|
+
nextStep: "Nothing was spent. Which epoch it is and how far ahead the network sells are facts only the chain has; ask again.",
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// ⛔ THE SAME REFUSAL AS THE UPLOAD: a term the network will not sell is refused, never clamped.
|
|
100
|
+
const epochs = chooseUploadEpochs(ask.epochs, window);
|
|
101
|
+
const [quotes, price, encoded] = await Promise.all([
|
|
102
|
+
found.reads.quoteParts(sealedLens, epochs),
|
|
103
|
+
found.reads.referenceGasPrice(),
|
|
104
|
+
Promise.all(sealedLens.map((len) => found.reads.encodedLength(len))),
|
|
105
|
+
]);
|
|
106
|
+
if (price === null) {
|
|
107
|
+
throw new NmtsError(`The ${network} reference gas price could not be read.`, {
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
nextStep: "Nothing was spent. The fee estimate scales with that price, so it is not guessed; ask again.",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const sum = (pick) => quotes.reduce((total, q) => total + pick(q), 0n);
|
|
113
|
+
const sealedBytes = sealedLens.reduce((total, len) => total + len, 0);
|
|
114
|
+
return {
|
|
115
|
+
network,
|
|
116
|
+
bytes: ask.bytes,
|
|
117
|
+
epochs,
|
|
118
|
+
endEpoch: window.clock.current + epochs,
|
|
119
|
+
parts: quotes.map((q, i) => ({
|
|
120
|
+
sealedBytes: q.sealedLen,
|
|
121
|
+
encodedBytes: encoded[i] ?? 0,
|
|
122
|
+
storageFrost: q.storageFrost.toString(),
|
|
123
|
+
writeFrost: q.writeFrost.toString(),
|
|
124
|
+
tipMist: q.tipMist.toString(),
|
|
125
|
+
})),
|
|
126
|
+
sealedBytes,
|
|
127
|
+
encodedBytes: encoded.reduce((total, n) => total + n, 0),
|
|
128
|
+
walFrost: sum((q) => q.storageFrost + q.writeFrost).toString(),
|
|
129
|
+
tipMist: sum((q) => q.tipMist).toString(),
|
|
130
|
+
gasEstimateMist: gasEstimate(quotes.length, price).toString(),
|
|
131
|
+
gasSource: MEASURED_GAS.source,
|
|
132
|
+
relay: found.relay,
|
|
133
|
+
credits: epochs === UPLOAD_EPOCHS ? sealedLens.reduce((total, len) => total + creditsFor(len), 0) : null,
|
|
134
|
+
};
|
|
135
|
+
}
|
package/dist/wallet-sign.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { SignExtension } from "./extend-plan.ts";
|
|
2
|
+
import type { Network } from "./network.ts";
|
|
3
|
+
import type { SponsorFacts, SponsorPolicy, SponsorSpend } from "./sponsor-check.ts";
|
|
2
4
|
import type { SignBlobCertify, SignBlobRegister, SignMessage, SignStorageOp, SignSwap, SignTransfer } from "./wallet-sign-seams.ts";
|
|
3
5
|
export type { SignBlobCertify, SignBlobRegister, SignMessage, SignStorageOp, SignSwap, SignTransfer, } from "./wallet-sign-seams.ts";
|
|
4
6
|
/**
|
|
@@ -81,3 +83,25 @@ export declare const signBlobCertify: SignBlobCertify;
|
|
|
81
83
|
* spent its gas, so the status is read and a failure is said as one.
|
|
82
84
|
*/
|
|
83
85
|
export declare const signStorageOp: SignStorageOp;
|
|
86
|
+
/**
|
|
87
|
+
* Sign a transaction somebody else's device built, as the operator that pays for it — only after
|
|
88
|
+
* `sponsor-check.ts` has passed it against the operator's policy.
|
|
89
|
+
*
|
|
90
|
+
* ⛔ CHECK, THEN SIGN, IN ONE DOOR. There is no way to reach the signature without the check: the
|
|
91
|
+
* bytes are judged here, by the same function an operator can call on its own, and a refusal
|
|
92
|
+
* throws before the keypair is even built. The policy's operator must be this wallet's address.
|
|
93
|
+
* ⛔ IT DOES NOT SUBMIT. The device that built the transaction submits it with this signature, the
|
|
94
|
+
* way any wallet's `signTransaction` answers.
|
|
95
|
+
*/
|
|
96
|
+
export declare function signSponsored(input: {
|
|
97
|
+
network: Network;
|
|
98
|
+
code: string;
|
|
99
|
+
wallet: number;
|
|
100
|
+
bytes: Uint8Array;
|
|
101
|
+
policy: SponsorPolicy;
|
|
102
|
+
facts?: SponsorFacts | undefined;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
bytes: string;
|
|
105
|
+
signature: string;
|
|
106
|
+
spends: SponsorSpend;
|
|
107
|
+
}>;
|
package/dist/wallet-sign.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
// the other on a venue (`signSwap`), and the two halves of a wallet-paid upload — registering one
|
|
7
7
|
// part's blob (`signBlobRegister`, which buys the storage or binds a held resource and pays the
|
|
8
8
|
// relay's tip) and certifying it (`signBlobCertify`, gas only). Another transaction shape is a
|
|
9
|
-
// decision made here, in the open — the test pins the export list.
|
|
9
|
+
// decision made here, in the open — the test pins the export list. `signStorageOp` signs the
|
|
10
|
+
// storage-resource changes (buy, cut, join, hand over), and `signSponsored` signs a transaction
|
|
11
|
+
// another device built, only after `sponsor-check.ts` has passed it against the operator's policy.
|
|
10
12
|
//
|
|
11
13
|
// ⛔ AND ONE THING THAT IS NOT A TRANSACTION. `signMessage` signs a short text under the
|
|
12
14
|
// personal-message intent: it moves nothing, it cannot be replayed as a transaction, and it
|
|
@@ -31,6 +33,7 @@
|
|
|
31
33
|
// surfaces is a transaction signed by a wallet the person has never funded.
|
|
32
34
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
33
35
|
import { Transaction } from "@mysten/sui/transactions";
|
|
36
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
34
37
|
import { assertUsableCode } from "./account.js";
|
|
35
38
|
import { DERIVED, loadCrypto } from "./crypto.js";
|
|
36
39
|
import { NmtsError } from "./errors.js";
|
|
@@ -273,3 +276,30 @@ export const signStorageOp = async ({ network, code, wallet, shape, walrusPackag
|
|
|
273
276
|
}
|
|
274
277
|
return result.digest;
|
|
275
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Sign a transaction somebody else's device built, as the operator that pays for it — only after
|
|
281
|
+
* `sponsor-check.ts` has passed it against the operator's policy.
|
|
282
|
+
*
|
|
283
|
+
* ⛔ CHECK, THEN SIGN, IN ONE DOOR. There is no way to reach the signature without the check: the
|
|
284
|
+
* bytes are judged here, by the same function an operator can call on its own, and a refusal
|
|
285
|
+
* throws before the keypair is even built. The policy's operator must be this wallet's address.
|
|
286
|
+
* ⛔ IT DOES NOT SUBMIT. The device that built the transaction submits it with this signature, the
|
|
287
|
+
* way any wallet's `signTransaction` answers.
|
|
288
|
+
*/
|
|
289
|
+
export async function signSponsored(input) {
|
|
290
|
+
const { judgeSponsored } = await import("./sponsor-check.js");
|
|
291
|
+
const facts = input.facts ?? (await (await import("./sponsor-facts.js")).sponsorFacts(input.network, input.policy.operator));
|
|
292
|
+
const verdict = await judgeSponsored(input.bytes, { ...input.policy, network: input.network }, facts);
|
|
293
|
+
if (!verdict.ok) {
|
|
294
|
+
throw new NmtsError(`SPONSOR_REFUSED: ${verdict.code}: ${verdict.reason}.`, {
|
|
295
|
+
exitCode: 4,
|
|
296
|
+
nextStep: "Nothing was signed. The transaction asks for something the operator's policy does not pay for.",
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const keypair = await keypairFor(input.code, input.wallet);
|
|
300
|
+
if (keypair.toSuiAddress() !== normalizeSuiAddress(input.policy.operator)) {
|
|
301
|
+
throw new NmtsError(`SPONSOR_REFUSED: SPONSOR_SENDER: the policy names ${input.policy.operator}, and this wallet is ${keypair.toSuiAddress()}.`, { exitCode: 4, nextStep: "Nothing was signed. The operator in the policy is the wallet that signs." });
|
|
302
|
+
}
|
|
303
|
+
const signed = await keypair.signTransaction(input.bytes);
|
|
304
|
+
return { bytes: signed.bytes, signature: signed.signature, spends: verdict.spends };
|
|
305
|
+
}
|
package/docs/commands/wallet.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# nmts wallet — the wallet your NMTS key derives
|
|
2
2
|
|
|
3
3
|
Commands: wallet
|
|
4
|
-
Tiers: wallet=none · wallet.use=low · wallet.send=high(wallet) · wallet.swap=high(wallet) · wallet.donate=high(donate) · wallet.storage.reshape=high(wallet) · wallet.storage.give=high(wallet) · wallet.hall=none · wallet.hall.set=medium
|
|
4
|
+
Tiers: wallet=none · wallet.use=low · wallet.send=high(wallet) · wallet.swap=high(wallet) · wallet.donate=high(donate) · wallet.storage.reshape=high(wallet) · wallet.storage.give=high(wallet) · wallet.storage.buy=high(wallet) · wallet.storage.extend=high(wallet) · wallet.hall=none · wallet.hall.set=medium
|
|
5
5
|
|
|
6
6
|
`wallet` shows the address and its SUI and WAL balances; `wallet address` derives the address
|
|
7
7
|
offline (`--qr` draws it, `--index N` derives another of this key's wallets); `wallet activity`
|
|
@@ -52,6 +52,18 @@ resources are the person's, in their wallet, and every step is their signature):
|
|
|
52
52
|
— what goes is size and remaining time; files stay sealed with this account's keys. Not undoable,
|
|
53
53
|
and NMTS cannot recall it. Scope `all`.
|
|
54
54
|
|
|
55
|
+
Two more spend WAL from the wallet, under the wallet unlock, and sign only with `--yes`:
|
|
56
|
+
|
|
57
|
+
- `wallet storage buy --size <bytes> [--epochs <n>]` buys a storage resource with no file in it,
|
|
58
|
+
for 2 epochs unless `--epochs` says otherwise.
|
|
59
|
+
- `wallet storage extend [<item-id>...] --delegation-file <file>` is for a business that paid for
|
|
60
|
+
its users' uploads. The storage of those files is held by the business's wallet, so that wallet
|
|
61
|
+
extends it. The file holds a delegation token for the user's account with `files_read` and
|
|
62
|
+
`storage_spend`; the user's key is not needed. Without item ids it takes every file of that user
|
|
63
|
+
that runs out soon; `--force` takes files not due yet. A file whose storage another wallet holds
|
|
64
|
+
is named and left as it is before anything is signed. Each file is one transaction, and the new
|
|
65
|
+
end is written into the user's account.
|
|
66
|
+
|
|
55
67
|
Each prints the review with the chain fee measured by a dry run, and a refusal the chain would
|
|
56
68
|
give ends the run there; nothing is signed without `--yes` on that run. Sizes are what a resource
|
|
57
69
|
holds after the network's encoding, as the listing prints them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needmoretruth/nmts-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.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": {
|
package/server.json
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/needmoretruth/nmts-cli",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.59.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
14
14
|
"identifier": "@needmoretruth/nmts-cli",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.59.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|