@needmoretruth/nmts-cli 0.58.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 +15 -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-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 +3 -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 +4 -1
- package/dist/help.js +3 -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 +1 -1
- package/dist/portable.js +1 -1
- 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/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.d.ts +4 -2
- package/dist/storage-control.js +4 -2
- package/docs/commands/wallet.md +13 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/portable.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type { Manifest, ManifestEntry } from "./shared/lib/drive/manifest-codec.
|
|
|
37
37
|
export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.ts";
|
|
38
38
|
export type { FindOptions, ManifestIndex } from "./drive-paths.ts";
|
|
39
39
|
export { setTrashed } from "./item-trash.ts";
|
|
40
|
-
export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.ts";
|
|
40
|
+
export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, readDelegation, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.ts";
|
|
41
41
|
export type { BusinessKeyPair, BusinessRequest, DelegationRequest, ScopeName } from "./platform-sign.ts";
|
|
42
42
|
export { newAccountCode, registrationProofOf } from "./registration.ts";
|
|
43
43
|
export type { RegistrationProof } from "./registration.ts";
|
package/dist/portable.js
CHANGED
|
@@ -62,7 +62,7 @@ export { setTrashed } from "./item-trash.js";
|
|
|
62
62
|
// token it mints for one of its users. Making either needs no host and no server — a business
|
|
63
63
|
// signs on its own machine, and a device that was handed a token presents it from a page — so
|
|
64
64
|
// they belong on this side of the line rather than behind the Node entry.
|
|
65
|
-
export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.js";
|
|
65
|
+
export { businessPublicKey, businessSigningInput, BUSINESS_CONTEXT, BUSINESS_PREFIX, delegationSigningInput, DELEGATION_CONTEXT, DELEGATION_MAX_TTL_SECS, DELEGATION_PREFIX, generateBusinessKeys, mintDelegation, NONCE_LEN, PUBKEY_LEN, readDelegation, rotationProof, rotationSigningInput, ROTATE_CONTEXT, SCOPE_ALL, SCOPE_BITS, scopeMask, signatureHolds, signBusinessRequest, SIGNATURE_LEN, } from "./platform-sign.js";
|
|
66
66
|
// What a brand-new account is registered with, derived from its NMTS key and from nothing else.
|
|
67
67
|
// ⚠ Here because a business registering a user makes the same pair the account door has always
|
|
68
68
|
// taken — a second derivation for the Platform would be a second answer to one question.
|
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.59.0";
|
|
13
13
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
14
14
|
export declare const HOME_URL = "https://nmts.me";
|
|
15
15
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/product.js
CHANGED
|
@@ -18,7 +18,7 @@ export const BINARY_NAME = "nmts";
|
|
|
18
18
|
* beside it. Here rather than in `main.ts` because the MCP server has to say it too, and a
|
|
19
19
|
* command importing the entry point is a cycle waiting to bite.
|
|
20
20
|
*/
|
|
21
|
-
export const VERSION = "0.
|
|
21
|
+
export const VERSION = "0.59.0";
|
|
22
22
|
/** Where the product lives, for messages that need to send somebody somewhere real. */
|
|
23
23
|
export const HOME_URL = "https://nmts.me";
|
|
24
24
|
/** The source, so a person holding only the built program can find what it was built from. */
|
package/dist/public-codes.d.ts
CHANGED
|
@@ -23,18 +23,29 @@ export interface PublicCodeList {
|
|
|
23
23
|
}
|
|
24
24
|
/** How many numbers in a row publishing walks past before it stops. */
|
|
25
25
|
export declare const PUBLISH_TRIES = 64;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* `GET /v1/account/public-codes`, read field by field. Codes come back in number order.
|
|
28
|
+
* `accountProof` goes with it when given: a delegation token reads its account's list only with it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function readPublicCodes(server: string, token: string, accountProof?: string): Promise<PublicCodeList>;
|
|
28
31
|
/** The live codes, lowest number first. */
|
|
29
32
|
export declare function liveCodes(list: PublicCodeList): PublicCodeRow[];
|
|
30
33
|
/** The code this account shows and sends from unless told otherwise: its lowest-numbered live one. */
|
|
31
34
|
export declare function defaultCode(list: PublicCodeList): PublicCodeRow | null;
|
|
32
35
|
/** The number a new code gets: one past the highest ever published, or 0 for an account with none. */
|
|
33
36
|
export declare function nextCodeIndex(list: PublicCodeList): number;
|
|
34
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* Where a request goes and what it carries.
|
|
39
|
+
*
|
|
40
|
+
* ⛔ `accountProof` IS FOR A DELEGATION TOKEN. A token is its business's permission, so the three
|
|
41
|
+
* code doors also ask it for the code's proof — the key holder's own act, sent from wherever the
|
|
42
|
+
* key is straight to the server. An API key or a session needs none and sends none.
|
|
43
|
+
*/
|
|
35
44
|
export interface CodeDoor {
|
|
36
45
|
server: string;
|
|
37
46
|
token: string;
|
|
47
|
+
/** base64url of the code's proof. Absent: not sent. */
|
|
48
|
+
accountProof?: string | undefined;
|
|
38
49
|
}
|
|
39
50
|
/** What publishing answers: the number it landed on and the code a person reads. */
|
|
40
51
|
export interface PublishedCode {
|
package/dist/public-codes.js
CHANGED
|
@@ -42,9 +42,12 @@ function readRow(value) {
|
|
|
42
42
|
support: whole(value["support"] ?? 0),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
/**
|
|
46
|
+
* `GET /v1/account/public-codes`, read field by field. Codes come back in number order.
|
|
47
|
+
* `accountProof` goes with it when given: a delegation token reads its account's list only with it.
|
|
48
|
+
*/
|
|
49
|
+
export async function readPublicCodes(server, token, accountProof) {
|
|
50
|
+
const answer = await request(server, "/v1/account/public-codes", { token, ...proofOf(accountProof) });
|
|
48
51
|
if (!isRecord(answer) || !Array.isArray(answer["codes"]))
|
|
49
52
|
throw unreadable();
|
|
50
53
|
const codes = answer["codes"].map(readRow).sort((a, b) => a.index - b.index);
|
|
@@ -74,6 +77,10 @@ export function defaultCode(list) {
|
|
|
74
77
|
export function nextCodeIndex(list) {
|
|
75
78
|
return list.codes.reduce((top, c) => Math.max(top, c.index + 1), 0);
|
|
76
79
|
}
|
|
80
|
+
/** The proof header's option for `request`, or nothing. */
|
|
81
|
+
function proofOf(accountProof) {
|
|
82
|
+
return accountProof === undefined ? {} : { accountProof };
|
|
83
|
+
}
|
|
77
84
|
/**
|
|
78
85
|
* Publish this key's code at `from` (default: the next number), revoking `replace` in the same
|
|
79
86
|
* request when it is given. Walks past numbers the server says were revoked, up to `PUBLISH_TRIES`.
|
|
@@ -93,6 +100,7 @@ export async function publishCode(crypt, code, door, from, replace) {
|
|
|
93
100
|
const address = toBase64Url(keys.address);
|
|
94
101
|
await request(door.server, "/v1/account/public-codes", {
|
|
95
102
|
token: door.token,
|
|
103
|
+
...proofOf(door.accountProof),
|
|
96
104
|
method: "POST",
|
|
97
105
|
body: {
|
|
98
106
|
index,
|
|
@@ -136,12 +144,12 @@ export async function publishCode(crypt, code, door, from, replace) {
|
|
|
136
144
|
* first share does before anything else. Answers the list as it now stands, and whether it wrote.
|
|
137
145
|
*/
|
|
138
146
|
export async function ensureLiveCode(crypt, code, door, onPublish) {
|
|
139
|
-
const list = await readPublicCodes(door.server, door.token);
|
|
147
|
+
const list = await readPublicCodes(door.server, door.token, door.accountProof);
|
|
140
148
|
if (defaultCode(list) !== null)
|
|
141
149
|
return { list, published: null };
|
|
142
150
|
onPublish?.();
|
|
143
151
|
const published = await publishCode(crypt, code, door, nextCodeIndex(list));
|
|
144
|
-
return { list: await readPublicCodes(door.server, door.token), published };
|
|
152
|
+
return { list: await readPublicCodes(door.server, door.token, door.accountProof), published };
|
|
145
153
|
}
|
|
146
154
|
/**
|
|
147
155
|
* Whether the code at `address` is on the server's revoked list — or null when the list could not
|
|
@@ -177,6 +185,7 @@ export async function revokedOnServer(server, address, buckets = new Map()) {
|
|
|
177
185
|
export async function revokeCode(door, index) {
|
|
178
186
|
await request(door.server, `/v1/account/public-codes/${requireCodeIndex(index)}/revoke`, {
|
|
179
187
|
token: door.token,
|
|
188
|
+
...proofOf(door.accountProof),
|
|
180
189
|
method: "POST",
|
|
181
190
|
});
|
|
182
191
|
}
|
package/dist/rebuild.js
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
// passed over in silence.
|
|
37
37
|
import { request } from "./api.js";
|
|
38
38
|
import { NmtsError } from "./errors.js";
|
|
39
|
+
import { serverObjects } from "./server-objects.js";
|
|
39
40
|
import { KIND_FILE } from "./shared/lib/drive/manifest-index.js";
|
|
40
41
|
import { mayCarryKey, verifyKeyPairings, } from "./shared/lib/drive/rebuild-verify.js";
|
|
41
42
|
import { uniqueFileName } from "./shared/lib/drive/unique-name.js";
|
|
@@ -177,32 +178,16 @@ async function readListing(base, apiKey, trash, onProgress) {
|
|
|
177
178
|
* unavailable, which is reported as unknown rather than as zero.
|
|
178
179
|
*/
|
|
179
180
|
async function serverRowIds(base, apiKey) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
return null;
|
|
188
|
-
const raw = Reflect.get(answer, "objects");
|
|
189
|
-
if (!Array.isArray(raw))
|
|
181
|
+
try {
|
|
182
|
+
const { rows, complete } = await serverObjects(base, apiKey);
|
|
183
|
+
return complete ? new Set(rows.map((row) => row.id)) : null;
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
// An unreadable listing makes the cross-check unavailable — unknown, never zero.
|
|
187
|
+
if (error instanceof NmtsError)
|
|
190
188
|
return null;
|
|
191
|
-
|
|
192
|
-
for (const row of rows) {
|
|
193
|
-
if (typeof row !== "object" || row === null)
|
|
194
|
-
return null;
|
|
195
|
-
const id = Reflect.get(row, "id");
|
|
196
|
-
if (typeof id !== "string")
|
|
197
|
-
return null;
|
|
198
|
-
ids.add(id);
|
|
199
|
-
}
|
|
200
|
-
const next = Reflect.get(answer, "next_cursor");
|
|
201
|
-
if (typeof next !== "string" || next === "")
|
|
202
|
-
return ids;
|
|
203
|
-
cursor = next;
|
|
189
|
+
throw error;
|
|
204
190
|
}
|
|
205
|
-
return null;
|
|
206
191
|
}
|
|
207
192
|
/**
|
|
208
193
|
* Turn the server's rows into entries.
|
package/dist/risk.d.ts
CHANGED
|
@@ -462,6 +462,18 @@ export declare const ACTS: {
|
|
|
462
462
|
readonly what: "Hand a storage resource to another address — signed, and not undoable.";
|
|
463
463
|
readonly asksItself: true;
|
|
464
464
|
};
|
|
465
|
+
readonly "wallet.storage.buy": {
|
|
466
|
+
readonly tier: "high";
|
|
467
|
+
readonly lock: "wallet";
|
|
468
|
+
readonly what: "Buy a storage resource with WAL from the wallet — signed, and not undoable.";
|
|
469
|
+
readonly asksItself: true;
|
|
470
|
+
};
|
|
471
|
+
readonly "wallet.storage.extend": {
|
|
472
|
+
readonly tier: "high";
|
|
473
|
+
readonly lock: "wallet";
|
|
474
|
+
readonly what: "Extend a user's files with WAL from the wallet — signed, and not undoable.";
|
|
475
|
+
readonly asksItself: true;
|
|
476
|
+
};
|
|
465
477
|
};
|
|
466
478
|
export type ActId = keyof typeof ACTS;
|
|
467
479
|
export declare const ACT_IDS: ActId[];
|
package/dist/risk.js
CHANGED
|
@@ -209,6 +209,10 @@ export const ACTS = {
|
|
|
209
209
|
"wallet.hall.set": { tier: "medium", what: "Publish this name beside your wallet's address in the gift hall of fame." },
|
|
210
210
|
"wallet.storage.reshape": { tier: "high", lock: "wallet", what: "Cut or join a storage resource the wallet holds — a signed transaction.", asksItself: true },
|
|
211
211
|
"wallet.storage.give": { tier: "high", lock: "wallet", what: "Hand a storage resource to another address — signed, and not undoable.", asksItself: true },
|
|
212
|
+
// ⛔ BOTH SPEND WAL. Until 2026-11-11 `buy` fell through to the bare `wallet` read, tier none, so
|
|
213
|
+
// an auto mode ran a WAL purchase without the gate knowing a payment was coming.
|
|
214
|
+
"wallet.storage.buy": { tier: "high", lock: "wallet", what: "Buy a storage resource with WAL from the wallet — signed, and not undoable.", asksItself: true },
|
|
215
|
+
"wallet.storage.extend": { tier: "high", lock: "wallet", what: "Extend a user's files with WAL from the wallet — signed, and not undoable.", asksItself: true },
|
|
212
216
|
};
|
|
213
217
|
export const ACT_IDS = Object.keys(ACTS);
|
|
214
218
|
/**
|
|
@@ -230,6 +234,10 @@ export function actOf(args) {
|
|
|
230
234
|
case "wallet":
|
|
231
235
|
if (sub === "storage") {
|
|
232
236
|
const what = args.operands[1] ?? "";
|
|
237
|
+
if (what === "buy")
|
|
238
|
+
return "wallet.storage.buy";
|
|
239
|
+
if (what === "extend")
|
|
240
|
+
return "wallet.storage.extend";
|
|
233
241
|
return what === "transfer" ? "wallet.storage.give" : what === "split" || what === "merge" ? "wallet.storage.reshape" : "wallet";
|
|
234
242
|
}
|
|
235
243
|
// ⛔ `hall` READS UNTIL A NAME IS NAMED. `--name` and `--remove` both write the listing, so
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** How many pages one walk follows. At the server's page size that is far past any real account. */
|
|
2
|
+
export declare const MAX_OBJECT_PAGES = 200;
|
|
3
|
+
/** One row the server holds. */
|
|
4
|
+
export interface ServerObject {
|
|
5
|
+
id: string;
|
|
6
|
+
/** True for a file in the trash: still held, on its way out. */
|
|
7
|
+
trashed: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Every row, and whether the walk reached the end of the listing. */
|
|
10
|
+
export interface ServerObjects {
|
|
11
|
+
rows: ServerObject[];
|
|
12
|
+
/** False when the walk stopped at `MAX_OBJECT_PAGES`. ⛔ A cut walk is never "that was all". */
|
|
13
|
+
complete: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Every row the server holds for the account `token` speaks for.
|
|
17
|
+
*
|
|
18
|
+
* ⛔ A ROW THIS CANNOT READ IS A REFUSAL. Skipping one would shrink the set of things the server is
|
|
19
|
+
* known to hold, which each caller then acts on as if it were whole.
|
|
20
|
+
*/
|
|
21
|
+
export declare function serverObjects(base: string, token: string): Promise<ServerObjects>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Every row the NMTS server holds for an account, live or trashed — read with nothing but the
|
|
2
|
+
// account's credential.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ `/v1/objects` AND NOT `/v1/items?deleted=true`. The trash listing stops at the retention window,
|
|
5
|
+
// so a row that is past thirty days and not yet erased is missing from it. `/v1/objects` is the
|
|
6
|
+
// reconciliation view: every row of the account, with no window on it, and no name — the layer a
|
|
7
|
+
// caller without the NMTS key can use (`api/src/routes/items.rs`, `list_objects`).
|
|
8
|
+
//
|
|
9
|
+
// ⛔ ONE PAGER FOR EVERY CALLER. `nmts sweep`, `rebuild` and an operator keeping a user's files alive
|
|
10
|
+
// all walk this listing; three copies of the cursor loop were three places to disagree about what
|
|
11
|
+
// an unreadable row means.
|
|
12
|
+
//
|
|
13
|
+
// ⚠ The two calls are written out rather than built from a variable so that the gate comparing this
|
|
14
|
+
// tool's addresses against the server's routes (`check:cli-routes`) can see them both. It reads
|
|
15
|
+
// literal strings.
|
|
16
|
+
import { request } from "./api.js";
|
|
17
|
+
import { NmtsError } from "./errors.js";
|
|
18
|
+
/** How many pages one walk follows. At the server's page size that is far past any real account. */
|
|
19
|
+
export const MAX_OBJECT_PAGES = 200;
|
|
20
|
+
/**
|
|
21
|
+
* Every row the server holds for the account `token` speaks for.
|
|
22
|
+
*
|
|
23
|
+
* ⛔ A ROW THIS CANNOT READ IS A REFUSAL. Skipping one would shrink the set of things the server is
|
|
24
|
+
* known to hold, which each caller then acts on as if it were whole.
|
|
25
|
+
*/
|
|
26
|
+
export async function serverObjects(base, token) {
|
|
27
|
+
const rows = [];
|
|
28
|
+
let cursor = null;
|
|
29
|
+
for (let page = 0; page < MAX_OBJECT_PAGES; page += 1) {
|
|
30
|
+
const answer = cursor === null
|
|
31
|
+
? await request(base, "/v1/objects", { token })
|
|
32
|
+
: await request(base, `/v1/objects?after=${encodeURIComponent(cursor)}`, { token });
|
|
33
|
+
const read = asObjectsAnswer(answer);
|
|
34
|
+
rows.push(...read.rows);
|
|
35
|
+
if (read.next === null)
|
|
36
|
+
return { rows, complete: true };
|
|
37
|
+
cursor = read.next;
|
|
38
|
+
}
|
|
39
|
+
return { rows, complete: false };
|
|
40
|
+
}
|
|
41
|
+
/** What `GET /v1/objects` answers, narrowed rather than trusted. */
|
|
42
|
+
function asObjectsAnswer(value) {
|
|
43
|
+
const unreadable = () => {
|
|
44
|
+
throw new NmtsError("The server answered with an item listing this version cannot read.", {
|
|
45
|
+
nextStep: "Nothing was changed. Update this tool.",
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
if (typeof value !== "object" || value === null)
|
|
49
|
+
return unreadable();
|
|
50
|
+
const raw = Reflect.get(value, "objects");
|
|
51
|
+
if (!Array.isArray(raw))
|
|
52
|
+
return unreadable();
|
|
53
|
+
const objects = raw;
|
|
54
|
+
const rows = [];
|
|
55
|
+
for (const object of objects) {
|
|
56
|
+
if (typeof object !== "object" || object === null)
|
|
57
|
+
return unreadable();
|
|
58
|
+
const id = Reflect.get(object, "id");
|
|
59
|
+
if (typeof id !== "string")
|
|
60
|
+
return unreadable();
|
|
61
|
+
const deleted = Reflect.get(object, "deleted_at");
|
|
62
|
+
rows.push({ id, trashed: typeof deleted === "string" && deleted !== "" });
|
|
63
|
+
}
|
|
64
|
+
const next = Reflect.get(value, "next_cursor");
|
|
65
|
+
if (next !== null && next !== undefined && typeof next !== "string")
|
|
66
|
+
return unreadable();
|
|
67
|
+
return { rows, next: typeof next === "string" && next !== "" ? next : null };
|
|
68
|
+
}
|
package/dist/sharing.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface ShareAccount {
|
|
|
11
11
|
readonly accountId: string;
|
|
12
12
|
/** The chain the stored parts are on, as `resolveNetwork` answers it. */
|
|
13
13
|
readonly network: string;
|
|
14
|
-
/** ⛔ base64url of the code's proof, for the
|
|
14
|
+
/** ⛔ base64url of the code's proof, for the sending and code doors only. Absent: not sent. */
|
|
15
15
|
readonly accountProof?: string | undefined;
|
|
16
16
|
}
|
|
17
17
|
/** One file of the account's list that a share can carry, and its full path. */
|
package/dist/sharing.js
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
// byte — the sealing itself is `share.ts`, untouched, and its order is load-bearing.
|
|
9
9
|
//
|
|
10
10
|
// ⛔ THE SAME FOR EVERY KEY HOLDER. `ShareAccount.bearer` is an API key or a delegation token. A
|
|
11
|
-
// token reaches the
|
|
12
|
-
// (`accountProof`), so the proof is sent on those
|
|
13
|
-
// asked for a live human check there instead, and the proof is simply not needed.
|
|
11
|
+
// token reaches the sending doors and the account's own code doors only with its `share` bit AND
|
|
12
|
+
// the code's proof (`accountProof`), so the proof is sent on those requests and on no other. An
|
|
13
|
+
// API key is asked for a live human check there instead, and the proof is simply not needed.
|
|
14
14
|
//
|
|
15
15
|
// ⛔ RECEIVING IS `sharing-inbox.ts`, re-exported here so `./share` is one entry.
|
|
16
16
|
//
|
|
17
17
|
// ⛔ NO `node:`, NO `Buffer`, NO `process.` — `test/portable-closure.test.ts` walks this file.
|
|
18
|
-
import { request
|
|
18
|
+
import { request } from "./api.js";
|
|
19
19
|
import { fromBase64Url, toBase64Url, utf8 } from "./bytes.js";
|
|
20
20
|
import { AAD, DERIVED, loadCrypto } from "./crypto.js";
|
|
21
21
|
import { buildIndex, entryAt, fullPathOf, KIND_FILE, normalisePath } from "./drive-paths.js";
|
|
@@ -23,9 +23,9 @@ import { NmtsError } from "./errors.js";
|
|
|
23
23
|
import { readFileList } from "./manifest.js";
|
|
24
24
|
import { BINARY_NAME } from "./product.js";
|
|
25
25
|
import { differentCode, notLiveCode, publicCodeRefusal } from "./public-code-refusals.js";
|
|
26
|
-
import { ensureLiveCode, liveCodes
|
|
26
|
+
import { ensureLiveCode, liveCodes } from "./public-codes.js";
|
|
27
27
|
import { identityMatches, sealShare } from "./share.js";
|
|
28
|
-
import {
|
|
28
|
+
import { shareKeysAt } from "./share-codes.js";
|
|
29
29
|
export { addressFromTyped } from "./share.js";
|
|
30
30
|
export { receivedShares, receiveShare } from "./sharing-inbox.js";
|
|
31
31
|
/** The file at `target`, checked for the key and the hash a share carries. */
|
|
@@ -58,21 +58,19 @@ export async function shareableFileAt(account, target) {
|
|
|
58
58
|
* Which live code sends: `as` when named, else the lowest-numbered live one — published first when
|
|
59
59
|
* the account has none, as a first share does.
|
|
60
60
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
61
|
+
* ⛔ THE SAME ON EVERY ROOT. A delegation token reads the code list and publishes the
|
|
62
|
+
* first code with its `share` bit and the code's proof, the proof this account already carries
|
|
63
|
+
* for the sending door. Until 2026-11-11 a token could not, and a device whose business held no
|
|
64
|
+
* key had no road to a code of its own.
|
|
65
65
|
*/
|
|
66
66
|
async function senderKeys(crypt, account, as, onFirstCode) {
|
|
67
|
-
const door = { server: account.server, token: account.bearer };
|
|
67
|
+
const door = { server: account.server, token: account.bearer, accountProof: account.accountProof };
|
|
68
68
|
let codes;
|
|
69
69
|
try {
|
|
70
70
|
({ list: codes } = await ensureLiveCode(crypt, account.code, door, onFirstCode));
|
|
71
71
|
}
|
|
72
72
|
catch (error) {
|
|
73
|
-
|
|
74
|
-
throw publicCodeRefusal(error);
|
|
75
|
-
return as === undefined ? await walkToLiveCode(crypt, account) : shareKeysAt(crypt, account.code, as);
|
|
73
|
+
throw publicCodeRefusal(error);
|
|
76
74
|
}
|
|
77
75
|
const live = liveCodes(codes);
|
|
78
76
|
const sender = as === undefined ? live[0] : live.find((c) => c.index === as);
|
|
@@ -85,32 +83,6 @@ async function senderKeys(crypt, account, as, onFirstCode) {
|
|
|
85
83
|
}
|
|
86
84
|
return keys;
|
|
87
85
|
}
|
|
88
|
-
async function walkToLiveCode(crypt, account) {
|
|
89
|
-
const ring = shareKeyRing(crypt, account.code);
|
|
90
|
-
try {
|
|
91
|
-
for (let index = 0; index < PUBLISH_TRIES; index += 1) {
|
|
92
|
-
const address = toBase64Url(ring.at(index).address);
|
|
93
|
-
try {
|
|
94
|
-
await request(account.server, `/v1/share-recipients/${encodeURIComponent(address)}`, { token: account.bearer });
|
|
95
|
-
return shareKeysAt(crypt, account.code, index);
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
if (error instanceof ServerError && error.status === 410)
|
|
99
|
-
continue;
|
|
100
|
-
if (error instanceof ServerError && error.status === 404)
|
|
101
|
-
break;
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
ring.wipe();
|
|
108
|
-
}
|
|
109
|
-
throw new NmtsError("This account has no public code yet, so nothing can be shared from it.", {
|
|
110
|
-
exitCode: 4,
|
|
111
|
-
nextStep: "Nothing was shared. The business that issued this token publishes one with setPublicCodes; then share again.",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
86
|
/**
|
|
115
87
|
* Seal one file for one public code and send it.
|
|
116
88
|
*
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type ExtendReads } from "../extend-plan.ts";
|
|
2
|
+
import type { StorageHints } from "./hints.ts";
|
|
3
|
+
/** Where to talk and with what. ⛔ No NMTS key: the user's is not here and none is needed. */
|
|
4
|
+
export interface ExtendForInput {
|
|
5
|
+
server: string;
|
|
6
|
+
network: string;
|
|
7
|
+
/** The user's delegation token. It must carry `files_read` and `storage_spend`. */
|
|
8
|
+
token: string;
|
|
9
|
+
/** The address that holds the storage and pays. Every blob must be held by it. */
|
|
10
|
+
payer: string;
|
|
11
|
+
}
|
|
12
|
+
/** What to extend and how. */
|
|
13
|
+
export interface ExtendForAsk {
|
|
14
|
+
/** Item ids. Absent = every file the user's account holds that is not in the trash. */
|
|
15
|
+
items?: readonly string[] | undefined;
|
|
16
|
+
/** Epochs to add to each file. Default `DEFAULT_EXTEND_EPOCHS`. */
|
|
17
|
+
epochs?: string | number | undefined;
|
|
18
|
+
/** Extend files that are not near their end yet too. Without it they are skipped as not due. */
|
|
19
|
+
force?: boolean | undefined;
|
|
20
|
+
/** Price every file and sign nothing. */
|
|
21
|
+
dryRun?: boolean | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** The chain and the signature. ⚠ Seams, not options. */
|
|
24
|
+
export interface ExtendForSeams {
|
|
25
|
+
readChain?: ((network: string) => Promise<ExtendReads> | ExtendReads) | undefined;
|
|
26
|
+
/** Signs one file's extension from the paying wallet and answers the transaction digest. */
|
|
27
|
+
sign?: ((input: {
|
|
28
|
+
objectIds: readonly string[];
|
|
29
|
+
epochs: number;
|
|
30
|
+
}) => Promise<string>) | undefined;
|
|
31
|
+
/** Told the instant a file's signature exists, before the server is asked to write it down. */
|
|
32
|
+
onSigned?: ((itemId: string, digest: string) => void) | undefined;
|
|
33
|
+
now: number;
|
|
34
|
+
hints?: StorageHints | undefined;
|
|
35
|
+
}
|
|
36
|
+
/** What happened to one file. */
|
|
37
|
+
export interface ExtendForFile {
|
|
38
|
+
itemId: string;
|
|
39
|
+
/** `extended` = signed and paid; `priced` = a dry run's price; `skipped` = nothing signed. */
|
|
40
|
+
outcome: "extended" | "priced" | "skipped";
|
|
41
|
+
/** Why it was skipped, as a code a program can match (`EXTEND_NOT_DUE`, `EXTEND_NOT_OWNED`, …). */
|
|
42
|
+
code: string | null;
|
|
43
|
+
/** Why, in words. Null when nothing needs saying. */
|
|
44
|
+
reason: string | null;
|
|
45
|
+
epochs: number | null;
|
|
46
|
+
/** The blobs' sizes added up — what a ledger that sells size × time charges by. */
|
|
47
|
+
bytes: number | null;
|
|
48
|
+
/** The chain's end of the soonest blob before, and after this extension. */
|
|
49
|
+
endEpoch: number | null;
|
|
50
|
+
newEndEpoch: number | null;
|
|
51
|
+
/** Price in FROST and the fee measured in MIST, as strings. */
|
|
52
|
+
wal: string | null;
|
|
53
|
+
sui: string | null;
|
|
54
|
+
digest: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** The whole run. */
|
|
57
|
+
export interface ExtendForResult {
|
|
58
|
+
dryRun: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The paying wallet as the first plan read it, in FROST and MIST as decimal strings — the units of
|
|
61
|
+
* every amount here. ⛔ NULL IS NOT ZERO: the chain would not say, or no file was priced.
|
|
62
|
+
*/
|
|
63
|
+
wallet: {
|
|
64
|
+
address: string;
|
|
65
|
+
wal: string | null;
|
|
66
|
+
sui: string | null;
|
|
67
|
+
};
|
|
68
|
+
files: ExtendForFile[];
|
|
69
|
+
/** What the extended (or, on a dry run, priced) files cost together, in FROST and MIST. */
|
|
70
|
+
wal: string;
|
|
71
|
+
sui: string;
|
|
72
|
+
/** Why the run stopped before the end, or null when it reached every file. */
|
|
73
|
+
stopped: {
|
|
74
|
+
code: string;
|
|
75
|
+
reason: string;
|
|
76
|
+
} | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extend a user's files from the paying wallet. Files not due, held by another wallet, already at the
|
|
80
|
+
* network's ceiling or past their end are skipped and said so; the rest are bought one by one.
|
|
81
|
+
*
|
|
82
|
+
* ⛔ THIS SIGNS unless `dryRun` is set, and nothing it buys comes back.
|
|
83
|
+
*/
|
|
84
|
+
export declare function extendFor(input: ExtendForInput, ask: ExtendForAsk, seams: ExtendForSeams): Promise<ExtendForResult>;
|