@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,111 @@
|
|
|
1
|
+
// `nmts wallet storage buy --size <n> [--epochs <n>]` — buying a storage resource with no file.
|
|
2
|
+
// ⛔ IT SIGNS AND SPENDS WAL. The order, the price, the dry run and the signature are
|
|
3
|
+
// `storage-control/buy.ts`, which the SDK calls as well; this file is the terminal over it: the
|
|
4
|
+
// words typed, the review read, `--yes`, and the wallet unlock held against what the review measured.
|
|
5
|
+
//
|
|
6
|
+
// ⛔ WHY (spec 2026-09-20 Deponejo · gap B2). A resource bought here is cut and handed on with the
|
|
7
|
+
// three commands beside it (`split`, `merge`, `transfer`), in the same place and under the same
|
|
8
|
+
// unlock scope — buying is a change to the wallet's storage like those, only one that costs WAL.
|
|
9
|
+
import { requireAccountCode } from "../code-access.js";
|
|
10
|
+
import { readCredentialsFile } from "../credentials.js";
|
|
11
|
+
import { NmtsError } from "../errors.js";
|
|
12
|
+
import { resolveNetwork } from "../network.js";
|
|
13
|
+
import { BINARY_NAME } from "../product.js";
|
|
14
|
+
import { resolveServer } from "../server.js";
|
|
15
|
+
import { buyStorage } from "../storage-control.js";
|
|
16
|
+
import { explorerTxUrl } from "../shared/lib/wallet/activity.js";
|
|
17
|
+
import { coinAmount, walletAddress } from "../wallet.js";
|
|
18
|
+
import { payingWalletIndex } from "../wallet-pay-index.js";
|
|
19
|
+
import { recordWalletSpend, requireWalletGrant } from "../wallet-grant.js";
|
|
20
|
+
import { parseBytes } from "./wallet-storage-ops.js";
|
|
21
|
+
import { formatBytes } from "./wallet-storage.js";
|
|
22
|
+
export async function walletStorageBuy(options = {}) {
|
|
23
|
+
const say = options.write ?? ((line) => process.stdout.write(`${line}\n`));
|
|
24
|
+
if (options.size === undefined) {
|
|
25
|
+
throw new NmtsError(`\`${BINARY_NAME} wallet storage buy --size <bytes> [--epochs <n>]\``, { exitCode: 2 });
|
|
26
|
+
}
|
|
27
|
+
const sizeBytes = parseBytes(options.size);
|
|
28
|
+
const epochs = options.epochs === undefined ? undefined : Number(options.epochs);
|
|
29
|
+
const resolved = await requireAccountCode();
|
|
30
|
+
const wallet = await payingWalletIndex(options);
|
|
31
|
+
const address = await walletAddress(resolved.code, wallet);
|
|
32
|
+
const stored = resolved.source === "file" || resolved.source === "file-locked" ? readCredentialsFile() : null;
|
|
33
|
+
const server = resolveServer(options.server ?? stored?.server);
|
|
34
|
+
const network = resolveNetwork(server, options.network ?? stored?.network);
|
|
35
|
+
const command = `${BINARY_NAME} wallet storage buy --size ${options.size}${options.epochs === undefined ? "" : ` --epochs ${options.epochs}`}`;
|
|
36
|
+
// ⛔ WITHOUT `--yes` THE RUN STOPS AT THE REVIEW, exactly as `--dry-run` does.
|
|
37
|
+
const stopAtReview = options.dryRun === true || options.yes !== true;
|
|
38
|
+
const outcome = await buyStorage({ network, code: resolved.code, wallet, address }, { sizeBytes, epochs }, {
|
|
39
|
+
reads: options.buyReads,
|
|
40
|
+
sign: options.signStorage,
|
|
41
|
+
dryRun: stopAtReview,
|
|
42
|
+
onReview: (review) => {
|
|
43
|
+
if (!options.json)
|
|
44
|
+
describe(say, review, wallet);
|
|
45
|
+
},
|
|
46
|
+
// The unlock, held against the price and the fee. ⛔ Throwing here signs nothing.
|
|
47
|
+
agree: (review) => {
|
|
48
|
+
requireWalletGrant("reshape", spendOf(review), new Date(options.now ?? Date.now()));
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const { review } = outcome;
|
|
52
|
+
const facts = {
|
|
53
|
+
op: "buy",
|
|
54
|
+
network,
|
|
55
|
+
address,
|
|
56
|
+
sizeBytes: review.sizeBytes,
|
|
57
|
+
epochs: review.epochs,
|
|
58
|
+
endEpoch: review.endEpoch,
|
|
59
|
+
wal: coinAmount(review.priceFrost),
|
|
60
|
+
feeSui: review.feeMist === null ? null : coinAmount(review.feeMist),
|
|
61
|
+
shortfall: review.shortfall,
|
|
62
|
+
};
|
|
63
|
+
if (outcome.kind === "review") {
|
|
64
|
+
if (options.json) {
|
|
65
|
+
say(JSON.stringify({ ...facts, signed: false, dryRun: options.dryRun === true }));
|
|
66
|
+
return options.dryRun === true ? 0 : 4;
|
|
67
|
+
}
|
|
68
|
+
say(``);
|
|
69
|
+
if (options.dryRun === true) {
|
|
70
|
+
say(` Nothing was signed. Run the same command with --yes to buy it.`);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
throw new NmtsError(`Nothing was signed: this needs --yes.`, {
|
|
74
|
+
exitCode: 4,
|
|
75
|
+
nextStep: `Read the review above, then: \`${command} --yes\``,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
recordWalletSpend(spendOf(review));
|
|
79
|
+
const explorerUrl = explorerTxUrl(outcome.digest, network);
|
|
80
|
+
if (options.json) {
|
|
81
|
+
say(JSON.stringify({ ...facts, signed: true, digest: outcome.digest, id: outcome.objectId, explorerUrl }));
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
say(``);
|
|
85
|
+
say(` Bought. Transaction ${outcome.digest}`);
|
|
86
|
+
if (outcome.objectId !== null)
|
|
87
|
+
say(` Resource ${outcome.objectId}`);
|
|
88
|
+
say(` ${explorerUrl}`);
|
|
89
|
+
say(` \`${BINARY_NAME} wallet storage\` lists it; \`put --pay wallet --storage <id>\` uploads into it.`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
/** What a purchase costs this wallet: the price in WAL and the fee the dry run measured. */
|
|
93
|
+
function spendOf(review) {
|
|
94
|
+
return { walFrost: review.priceFrost, suiMist: review.feeMist ?? 0n };
|
|
95
|
+
}
|
|
96
|
+
/** The review a person reads, in the order somebody deciding needs it. */
|
|
97
|
+
function describe(say, review, wallet) {
|
|
98
|
+
say(`Would buy a storage resource of ${formatBytes(review.sizeBytes)} for ${review.epochs} epoch${review.epochs === 1 ? "" : "s"}, epoch ${review.startEpoch} to ${review.endEpoch}.`);
|
|
99
|
+
say(` paid by ${review.address} (wallet ${wallet}), which also receives it`);
|
|
100
|
+
say(` Storage ${coinAmount(review.priceFrost)} WAL. Writing a file into it later costs its own small WAL.`);
|
|
101
|
+
say(review.feeMist === null
|
|
102
|
+
? ` Chain fee (SUI): could not be measured just now; it is charged with the signature.`
|
|
103
|
+
: ` Chain fee about ${coinAmount(review.feeMist)} SUI, measured by a dry run just now.`);
|
|
104
|
+
const wal = review.walFrost === null ? "WAL not read" : `${coinAmount(review.walFrost)} WAL`;
|
|
105
|
+
const sui = review.suiMist === null ? "SUI not read" : `${coinAmount(review.suiMist)} SUI`;
|
|
106
|
+
say(` The wallet holds ${wal} and ${sui}.`);
|
|
107
|
+
if (review.shortfall !== null)
|
|
108
|
+
say(` ⛔ ${review.shortfall}`);
|
|
109
|
+
say(` The size is what the network holds once a file is encoded, the unit the listing shows.`);
|
|
110
|
+
say(` Nobody, NMTS included, can reverse it.`);
|
|
111
|
+
}
|
package/dist/commands/wallet.js
CHANGED
|
@@ -61,10 +61,12 @@ export async function wallet(what, options = {}) {
|
|
|
61
61
|
if (sub === "split" || sub === "merge" || sub === "transfer") {
|
|
62
62
|
return (await import("./wallet-storage-ops.js")).walletStorageOps(sub, more, options);
|
|
63
63
|
}
|
|
64
|
+
if (sub === "buy")
|
|
65
|
+
return (await import("./wallet-storage-buy.js")).walletStorageBuy(options);
|
|
64
66
|
if (sub !== undefined) {
|
|
65
67
|
throw new NmtsError(`\`${BINARY_NAME} wallet storage ${sub}\` is not something this command does.`, {
|
|
66
68
|
exitCode: 2,
|
|
67
|
-
nextStep: `\`${BINARY_NAME} wallet storage\` lists; \`split\`, \`merge\` and \`transfer\` sign — \`${BINARY_NAME} help wallet\`.`,
|
|
69
|
+
nextStep: `\`${BINARY_NAME} wallet storage\` lists; \`buy\`, \`split\`, \`merge\` and \`transfer\` sign — \`${BINARY_NAME} help wallet\`.`,
|
|
68
70
|
});
|
|
69
71
|
}
|
|
70
72
|
return (await import("./wallet-storage.js")).walletStorage(options);
|
package/dist/help-options.js
CHANGED
|
@@ -101,8 +101,10 @@ export function optionLines() {
|
|
|
101
101
|
` rollback, wallet send, wallet swap, wallet donate),`,
|
|
102
102
|
` or extend a file that is nowhere near its deadline (extend)`,
|
|
103
103
|
` --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
|
|
105
|
-
`
|
|
104
|
+
` (put, push --pay wallet, wallet storage buy; default 2), or to keep`,
|
|
105
|
+
` (wallet storage split)`,
|
|
106
|
+
` --size <bytes> What a cut resource keeps, or a bought one holds: bytes, or with`,
|
|
107
|
+
` KiB/MiB/GiB (wallet storage split, wallet storage buy)`,
|
|
106
108
|
` --pay credits|wallet Who pays for an upload's storage (put, push). Default credits.`,
|
|
107
109
|
` wallet = the wallet this NMTS key derives signs and pays the`,
|
|
108
110
|
` network directly, under a wallet agreement of scope storage`,
|
package/dist/help.js
CHANGED
|
@@ -75,6 +75,8 @@ 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`,
|
|
78
80
|
` wallet send <SUI|WAL> <amount|max> <address>`,
|
|
79
81
|
` Send coins to an address — **signs and spends from the wallet**.`,
|
|
80
82
|
` Prints the review; sends only with --yes`,
|
package/dist/links.d.ts
CHANGED
|
@@ -8,6 +8,11 @@ export interface LinkAccount {
|
|
|
8
8
|
readonly bearer: string;
|
|
9
9
|
/** The NMTS key, display form. Its dataKey opens the file key and seals the owner's copy of `S`. */
|
|
10
10
|
readonly code: string;
|
|
11
|
+
/**
|
|
12
|
+
* ⛔ base64url of the code's proof, sent on making a link and nowhere else. A delegation token
|
|
13
|
+
* reaches that door only with its `share` bit and this proof; an API key does not need it.
|
|
14
|
+
*/
|
|
15
|
+
readonly accountProof?: string | undefined;
|
|
11
16
|
}
|
|
12
17
|
export interface MadeLink {
|
|
13
18
|
/** The whole link, secret included. */
|
package/dist/links.js
CHANGED
|
@@ -67,7 +67,12 @@ export async function makeLink(account, entry, options) {
|
|
|
67
67
|
digest.fill(0);
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
-
const answer = await request(account.server, "/v1/share-links", {
|
|
70
|
+
const answer = await request(account.server, "/v1/share-links", {
|
|
71
|
+
method: "POST",
|
|
72
|
+
body,
|
|
73
|
+
token: account.bearer,
|
|
74
|
+
...(account.accountProof === undefined ? {} : { accountProof: account.accountProof }),
|
|
75
|
+
});
|
|
71
76
|
const id = isRecord(answer) ? text(answer["link_id"]) : null;
|
|
72
77
|
const createdAt = isRecord(answer) ? text(answer["created_at"]) : null;
|
|
73
78
|
if (id === null || createdAt === null) {
|
package/dist/platform-sign.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export declare const DELEGATION_MAX_TTL_SECS = 2592000;
|
|
|
32
32
|
* an app can upload cannot destroy — and it does not stand alone: both doors also ask for the
|
|
33
33
|
* account code's own proof on the same request, which is an act only whoever holds the code can
|
|
34
34
|
* perform. The token is the business's permission; the proof is the key holder's.
|
|
35
|
+
*
|
|
36
|
+
* ⛔ `share` IS THE SIXTH, AND IT IS BUILT THE SAME WAY (spec 2026-09-20 unit C). It opens what sends
|
|
37
|
+
* a file's key out of the account: sharing it with another account and making a public link,
|
|
38
|
+
* and the lookup of the identity a share is sealed to. Those two sending doors also ask for the
|
|
39
|
+
* code's proof. Listing, receiving and cutting stay on `files_read` and `files_write`.
|
|
35
40
|
*/
|
|
36
41
|
export declare const SCOPE_BITS: {
|
|
37
42
|
readonly files_read: 1;
|
|
@@ -39,8 +44,9 @@ export declare const SCOPE_BITS: {
|
|
|
39
44
|
readonly storage_spend: 4;
|
|
40
45
|
readonly register: 8;
|
|
41
46
|
readonly files_erase: 16;
|
|
47
|
+
readonly share: 32;
|
|
42
48
|
};
|
|
43
|
-
/** One of the
|
|
49
|
+
/** One of the six names above. */
|
|
44
50
|
export type ScopeName = keyof typeof SCOPE_BITS;
|
|
45
51
|
/** Every bit a token may carry. */
|
|
46
52
|
export declare const SCOPE_ALL: number;
|
package/dist/platform-sign.js
CHANGED
|
@@ -60,6 +60,11 @@ export const DELEGATION_MAX_TTL_SECS = 2_592_000;
|
|
|
60
60
|
* an app can upload cannot destroy — and it does not stand alone: both doors also ask for the
|
|
61
61
|
* account code's own proof on the same request, which is an act only whoever holds the code can
|
|
62
62
|
* perform. The token is the business's permission; the proof is the key holder's.
|
|
63
|
+
*
|
|
64
|
+
* ⛔ `share` IS THE SIXTH, AND IT IS BUILT THE SAME WAY (spec 2026-09-20 unit C). It opens what sends
|
|
65
|
+
* a file's key out of the account: sharing it with another account and making a public link,
|
|
66
|
+
* and the lookup of the identity a share is sealed to. Those two sending doors also ask for the
|
|
67
|
+
* code's proof. Listing, receiving and cutting stay on `files_read` and `files_write`.
|
|
63
68
|
*/
|
|
64
69
|
export const SCOPE_BITS = {
|
|
65
70
|
files_read: 1,
|
|
@@ -67,9 +72,15 @@ export const SCOPE_BITS = {
|
|
|
67
72
|
storage_spend: 4,
|
|
68
73
|
register: 8,
|
|
69
74
|
files_erase: 16,
|
|
75
|
+
share: 32,
|
|
70
76
|
};
|
|
71
77
|
/** Every bit a token may carry. */
|
|
72
|
-
export const SCOPE_ALL = SCOPE_BITS.files_read |
|
|
78
|
+
export const SCOPE_ALL = SCOPE_BITS.files_read |
|
|
79
|
+
SCOPE_BITS.files_write |
|
|
80
|
+
SCOPE_BITS.storage_spend |
|
|
81
|
+
SCOPE_BITS.register |
|
|
82
|
+
SCOPE_BITS.files_erase |
|
|
83
|
+
SCOPE_BITS.share;
|
|
73
84
|
/**
|
|
74
85
|
* A new key pair, from the runtime's own random source.
|
|
75
86
|
*
|
package/dist/portable.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export { readFileList } from "./manifest.ts";
|
|
|
29
29
|
export type { FileList } from "./manifest.ts";
|
|
30
30
|
export { makeRecoveryList, nextRecoverySeq, readRecoveryCopy, recordRecoveryList, setRecoveryCopy } from "./recovery.ts";
|
|
31
31
|
export type { MadeRecoveryList, RecoveryAccount, RecoveryCopyState } from "./recovery.ts";
|
|
32
|
+
export { addressFromTyped, receivedShares, receiveShare, removeShare, sendShare, sentShares, shareableFileAt } from "./sharing.ts";
|
|
33
|
+
export type { ReceivedFile, ReceivedShare, SentShare, ShareAccount, ShareableFile } from "./sharing.ts";
|
|
32
34
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
|
|
33
35
|
export type { AddEntryInput, AddEntryResult, ListEditInput, ListEditResult } from "./manifest-write.ts";
|
|
34
36
|
export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
|
@@ -66,8 +68,13 @@ export type { LinkAccount, ListedLink, MadeLink, OpenedLinkFile } from "./links.
|
|
|
66
68
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.ts";
|
|
67
69
|
export type { ChainReader, CoinBalance, WalletBalances } from "./wallet.ts";
|
|
68
70
|
export { chainReader } from "./wallet-chain.ts";
|
|
69
|
-
export { signerAddress, signExtension, signTransfer } from "./wallet-sign.ts";
|
|
71
|
+
export { signerAddress, signExtension, signSponsored, signTransfer } from "./wallet-sign.ts";
|
|
70
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";
|
|
71
78
|
export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/drive/manifest-settings.ts";
|
|
72
79
|
export { classify } from "./shared/lib/drive/preview-classify.ts";
|
|
73
80
|
export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.ts";
|
package/dist/portable.js
CHANGED
|
@@ -53,6 +53,8 @@ export { readFileList } from "./manifest.js";
|
|
|
53
53
|
// The recovery list (spec 2026-09-20 unit B): the file `nmts recovery-list` writes, and its
|
|
54
54
|
// storage-network copy's switch. Also its own entry, `./recovery`.
|
|
55
55
|
export { makeRecoveryList, nextRecoverySeq, readRecoveryCopy, recordRecoveryList, setRecoveryCopy } from "./recovery.js";
|
|
56
|
+
// Sharing one file with another account (spec 2026-09-20 unit C). Also its own entry, `./share`.
|
|
57
|
+
export { addressFromTyped, receivedShares, receiveShare, removeShare, sendShare, sentShares, shareableFileAt } from "./sharing.js";
|
|
56
58
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
|
|
57
59
|
export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
|
|
58
60
|
export { setTrashed } from "./item-trash.js";
|
|
@@ -91,7 +93,12 @@ export { listLinks, listLiveLinks, makeLink, openLink, revokeAllLinks, revokeLin
|
|
|
91
93
|
// The wallet the NMTS key derives: reading it, and signing with it.
|
|
92
94
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.js";
|
|
93
95
|
export { chainReader } from "./wallet-chain.js";
|
|
94
|
-
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";
|
|
95
102
|
// WHICH of this key's wallets, and which of them have been used. One key derives a wallet at every
|
|
96
103
|
// index (NCF-3 §1.3), so the account's own number is read out of the sealed list and the rest is a
|
|
97
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.
|
|
12
|
+
export declare const VERSION = "0.58.0";
|
|
13
13
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
14
14
|
export declare const HOME_URL = "https://nmts.me";
|
|
15
15
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/product.js
CHANGED
|
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
|
|
|
18
18
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
19
19
|
* command importing the entry point is a cycle waiting to bite.
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.
|
|
21
|
+
export const VERSION = "0.58.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. */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PlaintextSink } from "./download-sink.ts";
|
|
2
|
+
import type { ShareAccount } from "./sharing.ts";
|
|
3
|
+
import type { ReadOptions } from "./walrus.ts";
|
|
4
|
+
/** One received share, opened as far as it would open. Its key never leaves this module. */
|
|
5
|
+
export interface ReceivedShare {
|
|
6
|
+
id: string;
|
|
7
|
+
itemId: string;
|
|
8
|
+
/** The file's name and real length as the sender sealed them; null when the row would not open. */
|
|
9
|
+
name: string | null;
|
|
10
|
+
size: number | null;
|
|
11
|
+
/** The sender's public code — only ever set when the open SUCCEEDED. */
|
|
12
|
+
sender: string | null;
|
|
13
|
+
senderRevoked: boolean;
|
|
14
|
+
/** Which of this account's codes it came to, and that code readable. */
|
|
15
|
+
toIndex: number;
|
|
16
|
+
toCode: string;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
/** Why it did not open, for a row that is still listed. */
|
|
19
|
+
problem: string | null;
|
|
20
|
+
}
|
|
21
|
+
/** A received file, written to the sink and checked against the sender's hash. */
|
|
22
|
+
export interface ReceivedFile {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
bytes: number;
|
|
26
|
+
parts: number;
|
|
27
|
+
sender: string | null;
|
|
28
|
+
senderRevoked: boolean;
|
|
29
|
+
toIndex: number;
|
|
30
|
+
toCode: string;
|
|
31
|
+
/** False when the sink took the bytes but did not deliver them (it decides what that means). */
|
|
32
|
+
delivered: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Everything shared with this account, each row opened with the code it came to.
|
|
36
|
+
*
|
|
37
|
+
* ⛔ A ROW THAT WILL NOT OPEN IS STILL LISTED, with its reason and no sender. `total` can be larger
|
|
38
|
+
* than the list: the server's listing is bounded, and a caller that is not told cannot know.
|
|
39
|
+
*/
|
|
40
|
+
export declare function receivedShares(account: ShareAccount): Promise<{
|
|
41
|
+
shares: ReceivedShare[];
|
|
42
|
+
total: number;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Receive one share into a sink: find its row in the list, open it, check what it says, then fetch.
|
|
46
|
+
* `sinkFor` is asked once the name and real length are known — the command picks a path from the
|
|
47
|
+
* sender's name there, and a program its own destination.
|
|
48
|
+
*/
|
|
49
|
+
export declare function receiveShare(account: ShareAccount, id: string, sinkFor: (file: {
|
|
50
|
+
name: string;
|
|
51
|
+
size: number;
|
|
52
|
+
}) => PlaintextSink, read?: ReadOptions): Promise<ReceivedFile>;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// The inbox half of `sharing.ts`: what came in, and taking one of them. Its own file because
|
|
2
|
+
// `check:size` measures the sending half; `./share` re-exports both, so a caller sees one entry.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ RECEIVING FINDS THE ROW IN THE LIST, not by id: the list is what carries the sender's published
|
|
5
|
+
// identity, and without it the envelope cannot be authenticated. The length written is the one
|
|
6
|
+
// the sender sealed, never the server's stored size (`commands/receive.ts` says why).
|
|
7
|
+
//
|
|
8
|
+
// ⛔ NO `node:`, NO `Buffer`, NO `process.` — `test/portable-closure.test.ts` walks this file.
|
|
9
|
+
import { request } from "./api.js";
|
|
10
|
+
import { loadCrypto } from "./crypto.js";
|
|
11
|
+
import { fetchWithKey } from "./download.js";
|
|
12
|
+
import { NmtsError } from "./errors.js";
|
|
13
|
+
import { BINARY_NAME } from "./product.js";
|
|
14
|
+
import { openReceived, openSharedDigest, receivedIndex } from "./share.js";
|
|
15
|
+
import { shareKeyRing } from "./share-codes.js";
|
|
16
|
+
/** The raw rows of `GET /v1/shares/received`, read field by field. */
|
|
17
|
+
async function receivedRows(account) {
|
|
18
|
+
const value = await request(account.server, "/v1/shares/received", { token: account.bearer });
|
|
19
|
+
if (typeof value !== "object" || value === null)
|
|
20
|
+
throw new NmtsError("The server's answer was not an object.");
|
|
21
|
+
const rows = Reflect.get(value, "shares");
|
|
22
|
+
if (!Array.isArray(rows))
|
|
23
|
+
throw new NmtsError("The server did not list any shares.");
|
|
24
|
+
const total = Reflect.get(value, "total");
|
|
25
|
+
return { rows: rows.filter(isRow), total: typeof total === "number" ? total : rows.length };
|
|
26
|
+
}
|
|
27
|
+
function isRow(value) {
|
|
28
|
+
if (typeof value !== "object" || value === null)
|
|
29
|
+
return false;
|
|
30
|
+
for (const name of ["id", "item_id", "dek_share_ct", "name_share_ct", "content_hash_share_ct"]) {
|
|
31
|
+
if (typeof Reflect.get(value, name) !== "string")
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Everything shared with this account, each row opened with the code it came to.
|
|
38
|
+
*
|
|
39
|
+
* ⛔ A ROW THAT WILL NOT OPEN IS STILL LISTED, with its reason and no sender. `total` can be larger
|
|
40
|
+
* than the list: the server's listing is bounded, and a caller that is not told cannot know.
|
|
41
|
+
*/
|
|
42
|
+
export async function receivedShares(account) {
|
|
43
|
+
const crypt = await loadCrypto();
|
|
44
|
+
const ring = shareKeyRing(crypt, account.code);
|
|
45
|
+
try {
|
|
46
|
+
const received = await receivedRows(account);
|
|
47
|
+
const shares = received.rows.map((row) => {
|
|
48
|
+
const o = openReceived(crypt, ring.at(receivedIndex(row)), row);
|
|
49
|
+
o.dek?.fill(0);
|
|
50
|
+
return {
|
|
51
|
+
id: o.id,
|
|
52
|
+
itemId: o.itemId,
|
|
53
|
+
name: o.name,
|
|
54
|
+
size: o.size,
|
|
55
|
+
sender: o.sender,
|
|
56
|
+
senderRevoked: o.senderRevoked,
|
|
57
|
+
toIndex: o.toIndex,
|
|
58
|
+
toCode: ring.at(o.toIndex).display,
|
|
59
|
+
createdAt: o.createdAt,
|
|
60
|
+
problem: o.problem,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return { shares, total: received.total };
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
ring.wipe();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Receive one share into a sink: find its row in the list, open it, check what it says, then fetch.
|
|
71
|
+
* `sinkFor` is asked once the name and real length are known — the command picks a path from the
|
|
72
|
+
* sender's name there, and a program its own destination.
|
|
73
|
+
*/
|
|
74
|
+
export async function receiveShare(account, id, sinkFor, read) {
|
|
75
|
+
const crypt = await loadCrypto();
|
|
76
|
+
const ring = shareKeyRing(crypt, account.code);
|
|
77
|
+
try {
|
|
78
|
+
const answer = await request(account.server, "/v1/shares/received", { token: account.bearer });
|
|
79
|
+
const rows = typeof answer === "object" && answer !== null ? Reflect.get(answer, "shares") : null;
|
|
80
|
+
if (!Array.isArray(rows))
|
|
81
|
+
throw new NmtsError("The server did not list any shares.");
|
|
82
|
+
const row = rows.find((candidate) => typeof candidate === "object" && candidate !== null && Reflect.get(candidate, "id") === id);
|
|
83
|
+
if (row === undefined) {
|
|
84
|
+
throw new NmtsError(`Nothing shared with this account has the id "${id}".`, {
|
|
85
|
+
exitCode: 4,
|
|
86
|
+
nextStep: `Nothing was written. \`${BINARY_NAME} shares\` lists what is there.`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const opened = openReceived(crypt, ring.at(receivedIndex(row)), row);
|
|
90
|
+
if (opened.dek === null || opened.name === null) {
|
|
91
|
+
throw new NmtsError(`That share ${opened.problem ?? "did not open"}.`, {
|
|
92
|
+
exitCode: 1,
|
|
93
|
+
nextStep: "Nothing was written. The sender can withdraw it and share the file again.",
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (opened.size === null) {
|
|
97
|
+
opened.dek.fill(0);
|
|
98
|
+
throw new NmtsError("The sender did not record this file's real length.", {
|
|
99
|
+
exitCode: 1,
|
|
100
|
+
nextStep: "Nothing was written. It was shared by an older client; ask them to share it again from " +
|
|
101
|
+
"a current one, which seals the length beside the name.",
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const expected = openSharedDigest(crypt, opened.dek, opened.digestCt);
|
|
105
|
+
if (expected === null) {
|
|
106
|
+
opened.dek.fill(0);
|
|
107
|
+
throw new NmtsError("This share's content hash did not open with the file's own key.", {
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
nextStep: "Nothing was written. There would be nothing to check the bytes against.",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
let sink;
|
|
113
|
+
try {
|
|
114
|
+
sink = sinkFor({ name: opened.name, size: opened.size });
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
opened.dek.fill(0);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
const fetched = await fetchWithKey({
|
|
121
|
+
base: account.server,
|
|
122
|
+
apiKey: account.bearer,
|
|
123
|
+
descriptorPath: `/v1/shares/${encodeURIComponent(id)}/parts?for=download`,
|
|
124
|
+
size: opened.size,
|
|
125
|
+
dek: opened.dek,
|
|
126
|
+
expected,
|
|
127
|
+
chain: account.network,
|
|
128
|
+
...(read === undefined ? {} : { read }),
|
|
129
|
+
sink,
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
id,
|
|
133
|
+
name: opened.name,
|
|
134
|
+
bytes: fetched.byteCount,
|
|
135
|
+
parts: fetched.partCount,
|
|
136
|
+
sender: opened.sender,
|
|
137
|
+
senderRevoked: opened.senderRevoked,
|
|
138
|
+
toIndex: opened.toIndex,
|
|
139
|
+
toCode: ring.at(opened.toIndex).display,
|
|
140
|
+
delivered: fetched.delivered,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
ring.wipe();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ManifestEntry } from "./shared/lib/drive/manifest-codec.ts";
|
|
2
|
+
export { addressFromTyped } from "./share.ts";
|
|
3
|
+
export { receivedShares, receiveShare } from "./sharing-inbox.ts";
|
|
4
|
+
export type { ReceivedFile, ReceivedShare } from "./sharing-inbox.ts";
|
|
5
|
+
/** An account as the share doors take it. */
|
|
6
|
+
export interface ShareAccount {
|
|
7
|
+
readonly server: string;
|
|
8
|
+
/** What the one auth header carries: an API key or a delegation token. */
|
|
9
|
+
readonly bearer: string;
|
|
10
|
+
readonly code: string;
|
|
11
|
+
readonly accountId: string;
|
|
12
|
+
/** The chain the stored parts are on, as `resolveNetwork` answers it. */
|
|
13
|
+
readonly network: string;
|
|
14
|
+
/** ⛔ base64url of the code's proof, for the two sending doors only. Absent: not sent. */
|
|
15
|
+
readonly accountProof?: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** One file of the account's list that a share can carry, and its full path. */
|
|
18
|
+
export interface ShareableFile {
|
|
19
|
+
readonly entry: ManifestEntry & {
|
|
20
|
+
dekWrapped: string;
|
|
21
|
+
contentHashCt: string;
|
|
22
|
+
};
|
|
23
|
+
readonly path: string;
|
|
24
|
+
}
|
|
25
|
+
/** What a sent share is: its id, the file's name, who it went to and from which code. */
|
|
26
|
+
export interface SentShare {
|
|
27
|
+
id: string | null;
|
|
28
|
+
name: string;
|
|
29
|
+
/** The recipient's public code, readable form. */
|
|
30
|
+
recipient: string;
|
|
31
|
+
fromIndex: number;
|
|
32
|
+
}
|
|
33
|
+
/** The file at `target`, checked for the key and the hash a share carries. */
|
|
34
|
+
export declare function shareableFileAt(account: ShareAccount, target: string): Promise<ShareableFile>;
|
|
35
|
+
/**
|
|
36
|
+
* Seal one file for one public code and send it.
|
|
37
|
+
*
|
|
38
|
+
* ⛔ THE CALLER HAS ALREADY DECIDED. The command asks its person between `shareableFileAt` and this
|
|
39
|
+
* call; a program decides by calling. Nothing here asks anybody anything.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sendShare(account: ShareAccount, file: ShareableFile, recipientAddress: Uint8Array, options?: {
|
|
42
|
+
as?: number | undefined;
|
|
43
|
+
onFirstCode?: () => void;
|
|
44
|
+
}): Promise<SentShare>;
|
|
45
|
+
/** Who one file was shared with: the server's rows, unchanged, beside the file's path and id. */
|
|
46
|
+
export declare function sentShares(account: ShareAccount, target: string): Promise<{
|
|
47
|
+
path: string;
|
|
48
|
+
itemId: string;
|
|
49
|
+
rows: unknown[];
|
|
50
|
+
}>;
|
|
51
|
+
/** Withdraw a share this account sent, or remove one it was sent. A copy already taken stays taken. */
|
|
52
|
+
export declare function removeShare(account: ShareAccount, id: string): Promise<void>;
|