@needmoretruth/nmts-cli 0.56.0 → 0.58.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 +21 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/receive.js +30 -87
- package/dist/commands/share.d.ts +7 -0
- package/dist/commands/share.js +58 -180
- package/dist/commands/shares-sent.js +4 -29
- package/dist/commands/wallet-storage-buy.d.ts +22 -0
- package/dist/commands/wallet-storage-buy.js +111 -0
- package/dist/commands/wallet.js +3 -1
- package/dist/help-options.js +4 -2
- package/dist/help.js +2 -0
- package/dist/links.d.ts +5 -0
- package/dist/links.js +6 -1
- package/dist/platform-sign.d.ts +7 -1
- package/dist/platform-sign.js +12 -1
- package/dist/portable.d.ts +8 -1
- package/dist/portable.js +8 -1
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/sharing-inbox.d.ts +52 -0
- package/dist/sharing-inbox.js +146 -0
- package/dist/sharing.d.ts +52 -0
- package/dist/sharing.js +218 -0
- 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-chain.d.ts +7 -0
- package/dist/storage-control-chain.js +19 -1
- package/dist/storage-control.d.ts +2 -0
- package/dist/storage-control.js +1 -0
- 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/package.json +5 -1
- package/server.json +2 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ExtendWindow } from "../extend-plan.ts";
|
|
2
|
+
import type { Network } from "../network.ts";
|
|
3
|
+
import type { DryRunVerdict, StorageOpShape } from "../storage-control-chain.ts";
|
|
4
|
+
import { type WalletBalances } from "../wallet.ts";
|
|
5
|
+
import type { SignStorageOp } from "../wallet-sign-seams.ts";
|
|
6
|
+
import type { ReshapeContext } from "./reshape.ts";
|
|
7
|
+
/** One purchase, in the values it is made of. */
|
|
8
|
+
export interface BuyAsk {
|
|
9
|
+
/** The resource's size: encoded bytes, as a listing shows them. */
|
|
10
|
+
sizeBytes: number;
|
|
11
|
+
/** Storage-network epochs from the current one. Default 2, the term `put` buys. */
|
|
12
|
+
epochs?: number | undefined;
|
|
13
|
+
}
|
|
14
|
+
/** What one purchase would be, priced, before anything is signed. */
|
|
15
|
+
export interface BuyReview {
|
|
16
|
+
network: Network;
|
|
17
|
+
/** The wallet that pays and receives the resource. */
|
|
18
|
+
address: string;
|
|
19
|
+
sizeBytes: number;
|
|
20
|
+
epochs: number;
|
|
21
|
+
startEpoch: number;
|
|
22
|
+
endEpoch: number;
|
|
23
|
+
/** WAL it costs, in FROST — storage only; a resource carries no write cost until a blob is written into it. */
|
|
24
|
+
priceFrost: bigint;
|
|
25
|
+
/** The chain fee the dry run measured, in MIST. ⛔ NULL WHEN UNMEASURED, never zero. */
|
|
26
|
+
feeMist: bigint | null;
|
|
27
|
+
/** What the wallet holds. ⛔ NULL IS "NOT READ", never zero. */
|
|
28
|
+
walFrost: bigint | null;
|
|
29
|
+
suiMist: bigint | null;
|
|
30
|
+
/** Set when the wallet is known to be short: both numbers. A real call throws instead of signing. */
|
|
31
|
+
shortfall: string | null;
|
|
32
|
+
}
|
|
33
|
+
export type BuyOutcome = {
|
|
34
|
+
kind: "review";
|
|
35
|
+
review: BuyReview;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "done";
|
|
38
|
+
review: BuyReview;
|
|
39
|
+
digest: string;
|
|
40
|
+
objectId: string | null;
|
|
41
|
+
};
|
|
42
|
+
/** The chain, as a purchase reads it. ⚠ A seam — a test hands in a table. */
|
|
43
|
+
export interface BuyReads {
|
|
44
|
+
readWindow(): Promise<ExtendWindow | null>;
|
|
45
|
+
/** The storage price of a resource of `sizeBytes` encoded bytes for `epochs`, in FROST. */
|
|
46
|
+
price(sizeBytes: number, epochs: number): Promise<bigint>;
|
|
47
|
+
readWallet(address: string): Promise<WalletBalances>;
|
|
48
|
+
walrusPackageId(): Promise<string>;
|
|
49
|
+
walType(): string;
|
|
50
|
+
systemObjectId(): string;
|
|
51
|
+
dryRun(shape: StorageOpShape, sender: string): Promise<DryRunVerdict>;
|
|
52
|
+
/** The storage resource a signed purchase created, or null when the chain did not name one. */
|
|
53
|
+
createdResource(digest: string): Promise<string | null>;
|
|
54
|
+
}
|
|
55
|
+
/** The chain, the signature and the gate. ⚠ Seams, not options. */
|
|
56
|
+
export interface BuySeams {
|
|
57
|
+
reads?: ((network: Network) => BuyReads | Promise<BuyReads>) | undefined;
|
|
58
|
+
sign?: SignStorageOp | undefined;
|
|
59
|
+
onReview?: ((review: BuyReview) => void) | undefined;
|
|
60
|
+
/** ⛔ THE GATE. Throwing here stops the run with nothing signed. */
|
|
61
|
+
agree?: ((review: BuyReview) => void) | undefined;
|
|
62
|
+
dryRun?: boolean | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Read, judge, price and — unless somebody stops it — sign one purchase of a storage resource. */
|
|
65
|
+
export declare function buyStorage(context: ReshapeContext, ask: BuyAsk, seams?: BuySeams): Promise<BuyOutcome>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Buying a storage resource on its own — a size and a term, with no file — decided, priced, signed
|
|
2
|
+
// and handed back rather than printed.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ WHY (spec 2026-09-20 Deponejo · gap B2 · plan 2026-11-10 §1.2). NMTS bought storage only inside
|
|
5
|
+
// an upload. A business that keeps one large resource and cuts a piece off it for each customer
|
|
6
|
+
// (`split` → `transfer`) had to buy that resource with the Walrus client — a reason to use Walrus
|
|
7
|
+
// directly. This sits beside split, merge and transfer, with the same two callers: `nmts wallet
|
|
8
|
+
// storage buy` and the SDK's `buyStorage`.
|
|
9
|
+
//
|
|
10
|
+
// ⛔ THE ORDER IS THE SAFETY, the one `reshape.ts` keeps: ① the term is judged against what the
|
|
11
|
+
// network sells ② the price is read fresh ③ both balances are read and a wallet known to be short
|
|
12
|
+
// is refused with both numbers ④ the exact transaction is dry-run, and a refusal there ends the
|
|
13
|
+
// run ⑤ the review is handed out ⑥ `dryRun` stops here ⑦ `agree` is the gate ⑧ only then the
|
|
14
|
+
// signature, and the resource the chain created is read back by its type.
|
|
15
|
+
//
|
|
16
|
+
// ⚠ THE SIZE IS A RESOURCE'S SIZE — the encoded bytes a storage listing shows and `split` cuts by —
|
|
17
|
+
// not a file's. A file of N bytes needs more once encoded; an upload's dry run says how much.
|
|
18
|
+
//
|
|
19
|
+
// ⚠ NOTHING HERE WRITES TO A STREAM, ASKS ANYBODY ANYTHING OR REACHES FOR `node:`.
|
|
20
|
+
import { NmtsError } from "../errors.js";
|
|
21
|
+
import { chooseUploadEpochs } from "../upload-wallet-plan.js";
|
|
22
|
+
import { coinAmount } from "../wallet.js";
|
|
23
|
+
/** A size worth buying: a positive whole number of bytes. */
|
|
24
|
+
function requireSize(sizeBytes) {
|
|
25
|
+
if (!Number.isSafeInteger(sizeBytes) || sizeBytes <= 0) {
|
|
26
|
+
throw new NmtsError(`A storage resource's size is a positive whole number of bytes: ${String(sizeBytes)}.`, {
|
|
27
|
+
exitCode: 2,
|
|
28
|
+
nextStep: "Nothing was signed. The size is encoded bytes, the unit a storage listing shows.",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return sizeBytes;
|
|
32
|
+
}
|
|
33
|
+
/** Read, judge, price and — unless somebody stops it — sign one purchase of a storage resource. */
|
|
34
|
+
export async function buyStorage(context, ask, seams = {}) {
|
|
35
|
+
const sizeBytes = requireSize(ask.sizeBytes);
|
|
36
|
+
const reads = seams.reads === undefined ? await defaultBuyReads(context.network) : await seams.reads(context.network);
|
|
37
|
+
// ① The term.
|
|
38
|
+
const window = await reads.readWindow();
|
|
39
|
+
if (window === null) {
|
|
40
|
+
throw new NmtsError(`The ${context.network} storage network could not be read.`, {
|
|
41
|
+
exitCode: 1,
|
|
42
|
+
nextStep: "Nothing was signed. Which epoch it is and how far ahead the network sells are facts only the chain has.",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const epochs = chooseUploadEpochs(ask.epochs, window);
|
|
46
|
+
// ② The price, fresh. ③ The wallet.
|
|
47
|
+
const [priceFrost, purse, walrusPackageId] = await Promise.all([
|
|
48
|
+
reads.price(sizeBytes, epochs),
|
|
49
|
+
reads.readWallet(context.address),
|
|
50
|
+
reads.walrusPackageId(),
|
|
51
|
+
]);
|
|
52
|
+
const shape = {
|
|
53
|
+
kind: "buy",
|
|
54
|
+
sizeBytes,
|
|
55
|
+
epochs,
|
|
56
|
+
priceFrost,
|
|
57
|
+
walType: reads.walType(),
|
|
58
|
+
systemObjectId: reads.systemObjectId(),
|
|
59
|
+
};
|
|
60
|
+
const walFrost = purse.wal.read ? purse.wal.baseUnits : null;
|
|
61
|
+
const suiMist = purse.sui.read ? purse.sui.baseUnits : null;
|
|
62
|
+
// ④ The dry run — skipped when the wallet is known to hold too little WAL, since the chain would
|
|
63
|
+
// only say the same thing less clearly.
|
|
64
|
+
const short = walFrost !== null && walFrost < priceFrost;
|
|
65
|
+
const verdict = short ? { feeMist: null, refusal: null } : await reads.dryRun(shape, context.address);
|
|
66
|
+
if (verdict.refusal !== null) {
|
|
67
|
+
throw new NmtsError(`The chain would refuse this: ${verdict.refusal}`, {
|
|
68
|
+
exitCode: 4,
|
|
69
|
+
nextStep: "Nothing was signed and no fee was spent.",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
let shortfall = null;
|
|
73
|
+
if (short) {
|
|
74
|
+
shortfall = `The wallet holds ${coinAmount(walFrost)} WAL and this storage costs ${coinAmount(priceFrost)} WAL.`;
|
|
75
|
+
}
|
|
76
|
+
else if (suiMist !== null && verdict.feeMist !== null && suiMist < verdict.feeMist) {
|
|
77
|
+
shortfall = `The wallet holds ${coinAmount(suiMist)} SUI and the chain fee is about ${coinAmount(verdict.feeMist)} SUI.`;
|
|
78
|
+
}
|
|
79
|
+
// ⑤ The review.
|
|
80
|
+
const review = {
|
|
81
|
+
network: context.network,
|
|
82
|
+
address: context.address,
|
|
83
|
+
sizeBytes,
|
|
84
|
+
epochs,
|
|
85
|
+
startEpoch: window.clock.current,
|
|
86
|
+
endEpoch: window.clock.current + epochs,
|
|
87
|
+
priceFrost,
|
|
88
|
+
feeMist: verdict.feeMist,
|
|
89
|
+
walFrost,
|
|
90
|
+
suiMist,
|
|
91
|
+
shortfall,
|
|
92
|
+
};
|
|
93
|
+
seams.onReview?.(review);
|
|
94
|
+
// ⑥ Stopped here, with nothing signed.
|
|
95
|
+
if (seams.dryRun === true)
|
|
96
|
+
return { kind: "review", review };
|
|
97
|
+
if (shortfall !== null) {
|
|
98
|
+
throw new NmtsError(shortfall, {
|
|
99
|
+
exitCode: 4,
|
|
100
|
+
nextStep: `Nothing was signed and nothing was spent. Send what is missing to ${context.address} and ask again.`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// ⑦ The gate.
|
|
104
|
+
seams.agree?.(review);
|
|
105
|
+
// ⑧ The signature, and the resource it made.
|
|
106
|
+
const sign = seams.sign ?? (await import("../wallet-sign.js")).signStorageOp;
|
|
107
|
+
const digest = await sign({ network: context.network, code: context.code, wallet: context.wallet, shape, walrusPackageId });
|
|
108
|
+
const objectId = await reads.createdResource(digest).catch(() => null);
|
|
109
|
+
return { kind: "done", review, digest, objectId };
|
|
110
|
+
}
|
|
111
|
+
/** The live reads, loaded on first use so nothing here imports a chain client by itself. */
|
|
112
|
+
async function defaultBuyReads(network) {
|
|
113
|
+
const [chain, { walrusClient }, { freshWalrus }, { readBalances, walCoinType }, { chainReader }, { packageConfig }, execute] = await Promise.all([
|
|
114
|
+
import("../storage-control-chain.js"),
|
|
115
|
+
import("../extend-chain.js"),
|
|
116
|
+
import("../walrus-fresh.js"),
|
|
117
|
+
import("../wallet.js"),
|
|
118
|
+
import("../wallet-chain.js"),
|
|
119
|
+
import("../upload-wallet-chain.js"),
|
|
120
|
+
import("../sui-execute.js"),
|
|
121
|
+
]);
|
|
122
|
+
const client = walrusClient(network);
|
|
123
|
+
const ops = chain.storageOpsReads(network);
|
|
124
|
+
return {
|
|
125
|
+
readWindow: async () => (await import("../extend-chain.js")).extendReads(network).readWindow(),
|
|
126
|
+
async price(sizeBytes, epochs) {
|
|
127
|
+
// ⚠ THE PROTOCOL'S UNIT IS ONE MEBIBYTE OF ENCODED SIZE, rounded up, and reserving space
|
|
128
|
+
// charges storage alone. If this arithmetic ever drifted from the contract's, the dry run
|
|
129
|
+
// below aborts (`destroy_zero` or `split`) and nothing is signed.
|
|
130
|
+
const state = await freshWalrus(client).systemState();
|
|
131
|
+
const units = BigInt(Math.ceil(sizeBytes / 2 ** 20));
|
|
132
|
+
return units * BigInt(state.storage_price_per_unit_size) * BigInt(epochs);
|
|
133
|
+
},
|
|
134
|
+
readWallet: (address) => readBalances(chainReader(network, address), walCoinType(network)),
|
|
135
|
+
walrusPackageId: () => ops.walrusPackageId(),
|
|
136
|
+
walType: () => walCoinType(network),
|
|
137
|
+
systemObjectId: () => packageConfig(network).systemObjectId,
|
|
138
|
+
dryRun: (shape, sender) => ops.dryRun(shape, sender),
|
|
139
|
+
async createdResource(digest) {
|
|
140
|
+
const answer = await client.core.getTransaction({ digest, include: execute.EXECUTE_INCLUDE });
|
|
141
|
+
const found = execute.readAnswer(answer).created.find((o) => o.type?.endsWith("::storage_resource::Storage") === true);
|
|
142
|
+
return found?.objectId ?? null;
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -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) {
|
|
@@ -5,6 +5,8 @@ export { applyExtension, nothingToExtend, planExtension } from "./storage-contro
|
|
|
5
5
|
export type { ExtendApplySeams, ExtendFacts, ExtendInput, ExtendOutcome, ExtendPlan, ExtendPlanSeams, } from "./storage-control/extend.ts";
|
|
6
6
|
export { planStorageOp, reshapeStorage } from "./storage-control/reshape.ts";
|
|
7
7
|
export type { ReshapeContext, ReshapeOutcome, ReshapeSeams, StorageOp, StorageOpAsk, StorageOpPlan, StorageOpResult, StorageOpReview, StorageShape, } from "./storage-control/reshape.ts";
|
|
8
|
+
export { buyStorage } from "./storage-control/buy.ts";
|
|
9
|
+
export type { BuyAsk, BuyOutcome, BuyReads, BuyReview, BuySeams } from "./storage-control/buy.ts";
|
|
8
10
|
export type { StorageOpShape, StorageOpsReads } from "./storage-control-chain.ts";
|
|
9
11
|
export type { StorageResource } from "./shared/lib/storage-control/chain.ts";
|
|
10
12
|
export { DEFAULT_EXTEND_EPOCHS } from "./extend-plan.ts";
|
package/dist/storage-control.js
CHANGED
|
@@ -21,4 +21,5 @@
|
|
|
21
21
|
export { formatBytes, listStorage, readOrRefuse } from "./storage-control/list.js";
|
|
22
22
|
export { applyExtension, nothingToExtend, planExtension } from "./storage-control/extend.js";
|
|
23
23
|
export { planStorageOp, reshapeStorage } from "./storage-control/reshape.js";
|
|
24
|
+
export { buyStorage } from "./storage-control/buy.js";
|
|
24
25
|
export { DEFAULT_EXTEND_EPOCHS } 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needmoretruth/nmts-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.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": {
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"types": "./dist/recovery.d.ts",
|
|
50
50
|
"default": "./dist/recovery.js"
|
|
51
51
|
},
|
|
52
|
+
"./share": {
|
|
53
|
+
"types": "./dist/sharing.d.ts",
|
|
54
|
+
"default": "./dist/sharing.js"
|
|
55
|
+
},
|
|
52
56
|
"./host": {
|
|
53
57
|
"types": "./dist/host.d.ts",
|
|
54
58
|
"default": "./dist/host.js"
|
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.58.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.58.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|