@needmoretruth/nmts-cli 0.45.0 → 0.47.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/AGENTS.md +8 -8
- package/CHANGELOG.md +78 -0
- package/README.ko.md +6 -3
- package/README.md +31 -11
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +19 -1
- package/dist/args.js +14 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/autonomy.js +3 -3
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/handover.d.ts +15 -0
- package/dist/commands/handover.js +376 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/link.d.ts +12 -0
- package/dist/commands/link.js +121 -0
- package/dist/commands/ls.d.ts +5 -0
- package/dist/commands/ls.js +9 -1
- package/dist/commands/public-code-manage.d.ts +24 -0
- package/dist/commands/public-code-manage.js +217 -0
- package/dist/commands/public-code.d.ts +12 -1
- package/dist/commands/public-code.js +140 -45
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put.d.ts +2 -2
- package/dist/commands/put.js +8 -7
- package/dist/commands/receive.js +14 -8
- package/dist/commands/s3.js +44 -10
- package/dist/commands/share-dispatch.js +14 -1
- package/dist/commands/share.d.ts +2 -0
- package/dist/commands/share.js +45 -35
- package/dist/commands/shares-sent.js +8 -3
- package/dist/crypto-surface.d.ts +35 -0
- package/dist/crypto-surface.js +13 -0
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +8 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/handover-codes.d.ts +25 -0
- package/dist/handover-codes.js +106 -0
- package/dist/handover.d.ts +62 -0
- package/dist/handover.js +217 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +13 -4
- package/dist/help.js +24 -3
- package/dist/links.d.ts +58 -0
- package/dist/links.js +206 -0
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +13 -10
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/reads.js +20 -6
- package/dist/mcp-tools/share.js +47 -1
- package/dist/mcp-tools/tiers.js +16 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +23 -0
- package/dist/portable.js +19 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-code-activity.d.ts +35 -0
- package/dist/public-code-activity.js +88 -0
- package/dist/public-code-refusals.d.ts +25 -0
- package/dist/public-code-refusals.js +87 -0
- package/dist/public-codes.d.ts +76 -0
- package/dist/public-codes.js +182 -0
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +55 -1
- package/dist/risk.js +55 -3
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share-codes.d.ts +40 -0
- package/dist/share-codes.js +151 -0
- package/dist/share.d.ts +39 -0
- package/dist/share.js +54 -13
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/public-link.d.ts +41 -0
- package/dist/shared/lib/share/public-link.js +107 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +9 -4
- package/dist/upload-wallet-put.js +16 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/handover.md +54 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/link.md +27 -0
- package/docs/commands/mcp.md +2 -1
- package/docs/commands/public-code.md +25 -6
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +15 -1
- package/docs/commands/share.md +8 -3
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +106 -4
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +286 -3
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +12 -1
package/dist/mcp-tools/share.js
CHANGED
|
@@ -31,10 +31,51 @@
|
|
|
31
31
|
// ⛔ THE RECIPIENT'S PUBLIC CODE IS NOT CHECKED AGAINST A PERSON. A share sent to a well-formed
|
|
32
32
|
// code that belongs to somebody else is sent, and is not recallable. Confirm it with whoever
|
|
33
33
|
// gave it to you, out of band, before calling this.
|
|
34
|
+
import { newCode, revokeCodeCommand } from "../commands/public-code-manage.js";
|
|
34
35
|
import { share, unshare } from "../commands/share.js";
|
|
35
36
|
import { common, needString, say } from "./context.js";
|
|
37
|
+
/** A code's number from a tool call, as the command takes it. The schema already said it is an integer. */
|
|
38
|
+
function numberArg(args, name) {
|
|
39
|
+
const value = args[name];
|
|
40
|
+
return typeof value === "number" ? String(value) : undefined;
|
|
41
|
+
}
|
|
36
42
|
export function shareTools(ctx) {
|
|
37
43
|
return [
|
|
44
|
+
{
|
|
45
|
+
name: "nmts_public_code_new",
|
|
46
|
+
description: "Make a new public code for this account — the next number from the same NMTS key — and " +
|
|
47
|
+
"publish it, so other accounts can send files to it. `replace` names a live code to revoke " +
|
|
48
|
+
"in the same step: nobody can send to that one again and nobody can bring it back. The " +
|
|
49
|
+
"server caps how many codes are live at once and how many are made per UTC day; the reply " +
|
|
50
|
+
"of nmts_public_code says both.",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
replace: {
|
|
55
|
+
type: "integer",
|
|
56
|
+
description: "The number of a live code to revoke in the same step, from nmts_public_code.",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
run: (args) => say((write) => newCode({ ...common(ctx), json: true, yes: true, replace: numberArg(args, "replace"), write })),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "nmts_public_code_revoke",
|
|
65
|
+
description: "Revoke one of this account's public codes, by its number from nmts_public_code. Nobody can " +
|
|
66
|
+
"send to it again and nobody can bring it back; files already received with it stay and " +
|
|
67
|
+
"still open. The account's last live code cannot be revoked — make a new one with " +
|
|
68
|
+
"nmts_public_code_new and `replace` instead.",
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: "object",
|
|
71
|
+
properties: {
|
|
72
|
+
index: { type: "integer", description: "The code's number, from nmts_public_code." },
|
|
73
|
+
},
|
|
74
|
+
required: ["index"],
|
|
75
|
+
additionalProperties: false,
|
|
76
|
+
},
|
|
77
|
+
run: (args) => say((write) => revokeCodeCommand(numberArg(args, "index"), { ...common(ctx), json: true, yes: true, write })),
|
|
78
|
+
},
|
|
38
79
|
{
|
|
39
80
|
name: "nmts_share",
|
|
40
81
|
description: "Give another NMTS account the key to one file in this account. ⛔ IT CANNOT BE TAKEN " +
|
|
@@ -53,6 +94,11 @@ export function shareTools(ctx) {
|
|
|
53
94
|
type: "string",
|
|
54
95
|
description: "The recipient's PUBLIC CODE, given to you by them. Not their NMTS key.",
|
|
55
96
|
},
|
|
97
|
+
as: {
|
|
98
|
+
type: "integer",
|
|
99
|
+
description: "Which of this account's live public codes sends it, by number from nmts_public_code. " +
|
|
100
|
+
"Absent: the lowest-numbered live one.",
|
|
101
|
+
},
|
|
56
102
|
},
|
|
57
103
|
required: ["path", "public_code"],
|
|
58
104
|
additionalProperties: false,
|
|
@@ -60,7 +106,7 @@ export function shareTools(ctx) {
|
|
|
60
106
|
run: async (args) => {
|
|
61
107
|
const path = needString(args, "path");
|
|
62
108
|
const code = needString(args, "public_code");
|
|
63
|
-
return say((write) => share(path, code, { ...common(ctx), json: true, write }));
|
|
109
|
+
return say((write) => share(path, code, { ...common(ctx), json: true, as: numberArg(args, "as"), write }));
|
|
64
110
|
},
|
|
65
111
|
},
|
|
66
112
|
{
|
package/dist/mcp-tools/tiers.js
CHANGED
|
@@ -12,6 +12,11 @@ import { unlocked } from "../gate.js";
|
|
|
12
12
|
import { BINARY_NAME } from "../product.js";
|
|
13
13
|
import { ACTS } from "../risk.js";
|
|
14
14
|
const READ = { act: "ls", readOnly: true };
|
|
15
|
+
/** The revoke question, naming the code by its number — the same words `nmts public-code revoke` asks. */
|
|
16
|
+
function revokeQuestion(index) {
|
|
17
|
+
return (`Revoke public code #${String(index)}? Nobody can send to it again, and nobody can bring it back. ` +
|
|
18
|
+
"Files already received with it stay.");
|
|
19
|
+
}
|
|
15
20
|
export const TOOL_TIERS = {
|
|
16
21
|
nmts_whoami: { act: "whoami", readOnly: true },
|
|
17
22
|
nmts_list: READ,
|
|
@@ -24,6 +29,15 @@ export const TOOL_TIERS = {
|
|
|
24
29
|
nmts_wallet_storage: { act: "wallet", readOnly: true },
|
|
25
30
|
nmts_devices: { act: "devices", readOnly: true },
|
|
26
31
|
nmts_public_code: { act: "public-code", readOnly: true },
|
|
32
|
+
// ⛔ A REPLACEMENT IS A REVOKE, and is asked as one — the act follows the arguments.
|
|
33
|
+
nmts_public_code_new: {
|
|
34
|
+
act: (args) => (typeof args["replace"] === "number" ? "public-code.revoke" : "public-code.new"),
|
|
35
|
+
question: (args) => typeof args["replace"] === "number"
|
|
36
|
+
? `Make a new public code for this account and revoke public code #${String(args["replace"])}? ` +
|
|
37
|
+
"Nobody can send to that one again, and nobody can bring it back. Files already received with it stay."
|
|
38
|
+
: "Make a new public code for this account. Go ahead?",
|
|
39
|
+
},
|
|
40
|
+
nmts_public_code_revoke: { act: "public-code.revoke", question: (args) => revokeQuestion(args["index"]) },
|
|
27
41
|
nmts_shares: { act: "shares", readOnly: true },
|
|
28
42
|
nmts_shares_sent: { act: "shares", readOnly: true },
|
|
29
43
|
nmts_notices: { act: "notices", readOnly: true },
|
|
@@ -54,7 +68,8 @@ export const TOOL_TIERS = {
|
|
|
54
68
|
nmts_restore: { act: "restore" },
|
|
55
69
|
nmts_share: {
|
|
56
70
|
act: "share",
|
|
57
|
-
question: (args) => `Share "${String(args["path"])}" with the NMTS account whose public code is ${String(args["public_code"])}
|
|
71
|
+
question: (args) => `Share "${String(args["path"])}" with the NMTS account whose public code is ${String(args["public_code"])}` +
|
|
72
|
+
`${typeof args["as"] === "number" ? `, from this account's public code #${String(args["as"])}` : ""}?\n\n` +
|
|
58
73
|
"Whoever holds that code can then download the file. Withdrawing the share afterwards stops " +
|
|
59
74
|
"further downloads and cannot reach a copy already fetched. The code is not checked against " +
|
|
60
75
|
"a person — if it is the wrong one, the file goes to whoever holds it.",
|
package/dist/platform-sign.d.ts
CHANGED
|
@@ -64,9 +64,9 @@ export declare function businessPublicKey(privateKey: string): string;
|
|
|
64
64
|
/**
|
|
65
65
|
* The bytes a business signature covers.
|
|
66
66
|
*
|
|
67
|
-
* `path` is the request
|
|
68
|
-
*
|
|
69
|
-
* the request.
|
|
67
|
+
* `path` is the request target exactly as it is sent — the path AND its query string,
|
|
68
|
+
* `/p1/users?after=…&limit=…`, neither dropped nor put in order. A signature that did not cover a
|
|
69
|
+
* parameter the server then read would be a signature over half the request.
|
|
70
70
|
*
|
|
71
71
|
* ⚠ THE NONCE IS SIGNED AS THE TEXT THAT TRAVELS, base64url, on its own line after the moment —
|
|
72
72
|
* so the sender and the receiver agree about the field without either re-encoding it.
|
|
@@ -82,7 +82,7 @@ export interface BusinessRequest {
|
|
|
82
82
|
accountId: string;
|
|
83
83
|
privateKey: string;
|
|
84
84
|
method: string;
|
|
85
|
-
/** The path as
|
|
85
|
+
/** The path and query string as they will be sent, `/p1/business` or `/p1/users?limit=50`. */
|
|
86
86
|
path: string;
|
|
87
87
|
/** The request body exactly as it will be sent. Empty for a GET. */
|
|
88
88
|
body?: Uint8Array | undefined;
|
package/dist/platform-sign.js
CHANGED
|
@@ -88,9 +88,9 @@ export function businessPublicKey(privateKey) {
|
|
|
88
88
|
/**
|
|
89
89
|
* The bytes a business signature covers.
|
|
90
90
|
*
|
|
91
|
-
* `path` is the request
|
|
92
|
-
*
|
|
93
|
-
* the request.
|
|
91
|
+
* `path` is the request target exactly as it is sent — the path AND its query string,
|
|
92
|
+
* `/p1/users?after=…&limit=…`, neither dropped nor put in order. A signature that did not cover a
|
|
93
|
+
* parameter the server then read would be a signature over half the request.
|
|
94
94
|
*
|
|
95
95
|
* ⚠ THE NONCE IS SIGNED AS THE TEXT THAT TRAVELS, base64url, on its own line after the moment —
|
|
96
96
|
* so the sender and the receiver agree about the field without either re-encoding it.
|
package/dist/portable.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export type { AccountIdentity } from "./account.ts";
|
|
|
17
17
|
export { AAD, DERIVED, loadCrypto } from "./crypto.ts";
|
|
18
18
|
export type { CryptoGlue } from "./crypto.ts";
|
|
19
19
|
export { isCryptoGlue, missingExports } from "./crypto-surface.ts";
|
|
20
|
+
export { CODE_INDEX_MAX, openShareAnyCode, openShareWithRing, requireCodeIndex, shareKeyRing, shareKeysAt, type ShareKeyRing, } from "./share-codes.ts";
|
|
21
|
+
export type { ShareKeys, ShareSealed } from "./share.ts";
|
|
22
|
+
export { defaultCode, ensureLiveCode, liveCodes, nextCodeIndex, publishCode, PUBLISH_TRIES, readPublicCodes, revokeCode, } from "./public-codes.ts";
|
|
23
|
+
export type { CodeDoor, PublicCodeList, PublicCodeRow, PublishedCode } from "./public-codes.ts";
|
|
24
|
+
export { codeActivity } from "./public-code-activity.ts";
|
|
25
|
+
export type { ActivityDoor, CodeActivity, ReceivedThrough, SentThrough } from "./public-code-activity.ts";
|
|
20
26
|
export { readFileList } from "./manifest.ts";
|
|
21
27
|
export type { FileList } from "./manifest.ts";
|
|
22
28
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.ts";
|
|
@@ -34,6 +40,7 @@ export type { FileUploadInput, FileUploadStep, PlaintextSource } from "./upload-
|
|
|
34
40
|
export { createUploadApi } from "./upload-api.ts";
|
|
35
41
|
export { CREDIT_BYTES, creditsFor, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "./upload-price.ts";
|
|
36
42
|
export { clearItemRecord, clearReservation } from "./upload-store.ts";
|
|
43
|
+
export { forgetUpload } from "./upload-run.ts";
|
|
37
44
|
export { UploadError } from "./upload-wire.ts";
|
|
38
45
|
export type { BlobProtocol, UploadApi, UploadResult, UploadStep } from "./upload-wire.ts";
|
|
39
46
|
export type { PaddingRule } from "./shared/lib/crypto/size-padding.ts";
|
|
@@ -50,6 +57,8 @@ export type { PlaintextSink } from "./download-sink.ts";
|
|
|
50
57
|
export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./walrus.ts";
|
|
51
58
|
export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.ts";
|
|
52
59
|
export type { ReadOptions } from "./walrus.ts";
|
|
60
|
+
export { listLinks, makeLink, openLink, revokeLink } from "./links.ts";
|
|
61
|
+
export type { LinkAccount, ListedLink, MadeLink, OpenedLinkFile } from "./links.ts";
|
|
53
62
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.ts";
|
|
54
63
|
export type { ChainReader, CoinBalance, WalletBalances } from "./wallet.ts";
|
|
55
64
|
export { chainReader } from "./wallet-chain.ts";
|
|
@@ -60,4 +69,18 @@ export { classify } from "./shared/lib/drive/preview-classify.ts";
|
|
|
60
69
|
export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.ts";
|
|
61
70
|
export type { WalletProbe, WalletScan } from "./shared/lib/wallet/discover.ts";
|
|
62
71
|
export { hasHistory } from "./wallet-list-chain.ts";
|
|
72
|
+
export { DEFAULT_STORAGE_TIER, isStorageTier, networkForTier, parseStorageTier, STORAGE_TIERS, tierForNetwork } from "./shared/lib/storage-tier.ts";
|
|
73
|
+
export type { StorageTier } from "./shared/lib/storage-tier.ts";
|
|
74
|
+
export { heavyCredits, heavyOrderPut, planHeavyFile } from "./heavy-upload.ts";
|
|
75
|
+
export type { HeavyCommitted, HeavyFile, HeavyOrderContext, HeavyOrderOutcome, HeavyPlanPart } from "./heavy-upload.ts";
|
|
76
|
+
export { copiesOf, heavySelfPut, providersOf, selfPayChain, SELF_PAY_DEFAULT_COPIES, SELF_PAY_MAX_COPIES } from "./heavy-self-pay.ts";
|
|
77
|
+
export type { SelfPayContext, SelfPayProgress, SelfPaySynapse } from "./heavy-self-pay.ts";
|
|
78
|
+
export { heavyWalletPut } from "./heavy-wallet-pay.ts";
|
|
79
|
+
export type { HeavyWalletInput, HeavyWalletQuote } from "./heavy-wallet-pay.ts";
|
|
80
|
+
export { evmAccountFor, evmAddressFor, evmAddressOf, evmIndexOf, evmKeyOf, hexKey } from "./heavy-evm.ts";
|
|
81
|
+
/** The EVM account a caller holds, for Heavy paid from its own Filecoin wallet. */
|
|
82
|
+
export type { LocalAccount as EvmAccount } from "viem";
|
|
83
|
+
export { HeavyOrderError } from "./shared/lib/heavy/order-runner.ts";
|
|
84
|
+
export type { HeavyPayment, HeavyProgress } from "./shared/lib/heavy/order-runner.ts";
|
|
85
|
+
export { HEAVY_COPY } from "./heavy-copy.ts";
|
|
63
86
|
export { HOME_URL, PRODUCT_NAME, SOURCE_URL, SUPPORT_EMAIL, VERSION } from "./product.ts";
|
package/dist/portable.js
CHANGED
|
@@ -41,6 +41,12 @@ export { AAD, DERIVED, loadCrypto } from "./crypto.js";
|
|
|
41
41
|
// runs its answer through this rather than trusting it.
|
|
42
42
|
export { isCryptoGlue, missingExports } from "./crypto-surface.js";
|
|
43
43
|
// The sealed file list: reading it, editing it, and walking it by path.
|
|
44
|
+
// Public codes (spec 2026-09-23): the numbered codes one key derives, the account's list of them on
|
|
45
|
+
// the server, and what each one was used for. `openShareAnyCode` is what opens a share whose code is
|
|
46
|
+
// not named — it tries the numbers it is given.
|
|
47
|
+
export { CODE_INDEX_MAX, openShareAnyCode, openShareWithRing, requireCodeIndex, shareKeyRing, shareKeysAt, } from "./share-codes.js";
|
|
48
|
+
export { defaultCode, ensureLiveCode, liveCodes, nextCodeIndex, publishCode, PUBLISH_TRIES, readPublicCodes, revokeCode, } from "./public-codes.js";
|
|
49
|
+
export { codeActivity } from "./public-code-activity.js";
|
|
44
50
|
export { readFileList } from "./manifest.js";
|
|
45
51
|
export { addEntry, applyManyToList, applyToList, planAddition } from "./manifest-write.js";
|
|
46
52
|
export { buildIndex, entryAt, folderIdFor, fullPathOf, isLive, KIND_FILE, KIND_FOLDER, namesIn, normalisePath, shown, trashedAt, } from "./drive-paths.js";
|
|
@@ -59,6 +65,7 @@ export { partKeysOf, uploadFile } from "./upload-file.js";
|
|
|
59
65
|
export { createUploadApi } from "./upload-api.js";
|
|
60
66
|
export { CREDIT_BYTES, creditsFor, partSizeFor, planAndPrice, UPLOAD_EPOCHS } from "./upload-price.js";
|
|
61
67
|
export { clearItemRecord, clearReservation } from "./upload-store.js";
|
|
68
|
+
export { forgetUpload } from "./upload-run.js";
|
|
62
69
|
export { UploadError } from "./upload-wire.js";
|
|
63
70
|
export { DEFAULT_PART_BYTES } from "./seal.js";
|
|
64
71
|
export { createBlobProtocol, readCurrentEpoch } from "./walrus-write.js";
|
|
@@ -74,6 +81,8 @@ export { AGGREGATOR_ENV_VAR, readBlob, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./
|
|
|
74
81
|
// to rather than finding out from a request that went somewhere else. Each reads what the
|
|
75
82
|
// caller said first, then the environment, then the network's own.
|
|
76
83
|
export { relayHost, storageNodesThrough, suiRpcHosts } from "./walrus.js";
|
|
84
|
+
// Public links (NCF-3 §5.8): make, list, cut, and open without an account — `nmts link`'s four.
|
|
85
|
+
export { listLinks, makeLink, openLink, revokeLink } from "./links.js";
|
|
77
86
|
// The wallet the NMTS key derives: reading it, and signing with it.
|
|
78
87
|
export { coinAmount, readBalances, walCoinType, walletAddress } from "./wallet.js";
|
|
79
88
|
export { chainReader } from "./wallet-chain.js";
|
|
@@ -87,5 +96,15 @@ export { activeWalletOf, walletCountOf, WALLET_INDEX_LIMIT } from "./shared/lib/
|
|
|
87
96
|
export { classify } from "./shared/lib/drive/preview-classify.js";
|
|
88
97
|
export { discoverWallets, WALLET_SCAN_GAP } from "./shared/lib/wallet/discover.js";
|
|
89
98
|
export { hasHistory } from "./wallet-list-chain.js";
|
|
99
|
+
// NMTS Heavy: the tier word every interface reads, an upload paid through an order (credits, or WAL
|
|
100
|
+
// once stored), and developer mode's self-paid road from the key's own EVM wallet (NCF-3 §1.9).
|
|
101
|
+
// ⚠ The Synapse SDK behind the self-paid road is loaded only when that road runs.
|
|
102
|
+
export { DEFAULT_STORAGE_TIER, isStorageTier, networkForTier, parseStorageTier, STORAGE_TIERS, tierForNetwork } from "./shared/lib/storage-tier.js";
|
|
103
|
+
export { heavyCredits, heavyOrderPut, planHeavyFile } from "./heavy-upload.js";
|
|
104
|
+
export { copiesOf, heavySelfPut, providersOf, selfPayChain, SELF_PAY_DEFAULT_COPIES, SELF_PAY_MAX_COPIES } from "./heavy-self-pay.js";
|
|
105
|
+
export { heavyWalletPut } from "./heavy-wallet-pay.js";
|
|
106
|
+
export { evmAccountFor, evmAddressFor, evmAddressOf, evmIndexOf, evmKeyOf, hexKey } from "./heavy-evm.js";
|
|
107
|
+
export { HeavyOrderError } from "./shared/lib/heavy/order-runner.js";
|
|
108
|
+
export { HEAVY_COPY } from "./heavy-copy.js";
|
|
90
109
|
// What this package is.
|
|
91
110
|
export { HOME_URL, PRODUCT_NAME, SOURCE_URL, SUPPORT_EMAIL, VERSION } from "./product.js";
|
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.47.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.47.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,35 @@
|
|
|
1
|
+
import type { CryptoGlue } from "./crypto.ts";
|
|
2
|
+
import type { PublicCodeList } from "./public-codes.ts";
|
|
3
|
+
/** One share sent from a code. */
|
|
4
|
+
export interface SentThrough {
|
|
5
|
+
id: string;
|
|
6
|
+
itemId: string;
|
|
7
|
+
/** Where the file sits in this account, or null when the list no longer holds it. */
|
|
8
|
+
path: string | null;
|
|
9
|
+
/** The recipient's code in the form a person reads, or as the server sent it if it will not parse. */
|
|
10
|
+
recipient: string;
|
|
11
|
+
recipientRevoked: boolean;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
}
|
|
14
|
+
/** One share received with a code. */
|
|
15
|
+
export interface ReceivedThrough {
|
|
16
|
+
id: string;
|
|
17
|
+
/** The name its sender sealed, or null when it would not open — `problem` says why. */
|
|
18
|
+
name: string | null;
|
|
19
|
+
sender: string | null;
|
|
20
|
+
senderRevoked: boolean;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
problem: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface CodeActivity {
|
|
25
|
+
sent: SentThrough[];
|
|
26
|
+
received: ReceivedThrough[];
|
|
27
|
+
}
|
|
28
|
+
/** Where to ask and as whom — the account the code opens, on its server. */
|
|
29
|
+
export interface ActivityDoor {
|
|
30
|
+
server: string;
|
|
31
|
+
token: string;
|
|
32
|
+
accountId: string;
|
|
33
|
+
}
|
|
34
|
+
/** Every code's shares, by number. A code with none has two empty lists. */
|
|
35
|
+
export declare function codeActivity(crypt: CryptoGlue, code: string, door: ActivityDoor, list: PublicCodeList): Promise<Map<number, CodeActivity>>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// What each of an account's public codes has been used for: the shares sent from it and the shares
|
|
2
|
+
// received with it — `nmts public-code list --activity` and the library's `publicCodes.list`.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ THE NAMES ARE OPENED HERE, NOT READ FROM THE SERVER. The server knows which code a share went
|
|
5
|
+
// through and nothing about what it holds: a received file's name is sealed by its sender and
|
|
6
|
+
// opens with the code it came to, and a sent file's name is this account's own, in its sealed list.
|
|
7
|
+
//
|
|
8
|
+
// ⚠ A ROW THAT WILL NOT OPEN IS STILL LISTED, with the reason and no name — the rule `openReceived`
|
|
9
|
+
// keeps for the inbox, for the same reason: leaving it out would say less was received than was.
|
|
10
|
+
import { request } from "./api.js";
|
|
11
|
+
import { fromBase64Url } from "./bytes.js";
|
|
12
|
+
import { buildIndex, fullPathOf } from "./drive-paths.js";
|
|
13
|
+
import { isRecord } from "./guards.js";
|
|
14
|
+
import { readFileList } from "./manifest.js";
|
|
15
|
+
import { openReceived, receivedIndex } from "./share.js";
|
|
16
|
+
import { shareKeyRing } from "./share-codes.js";
|
|
17
|
+
function readable(crypt, wire) {
|
|
18
|
+
try {
|
|
19
|
+
return crypt.share_address_display(fromBase64Url(wire));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return wire;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function rowsOf(answer) {
|
|
26
|
+
return isRecord(answer) && Array.isArray(answer["shares"]) ? answer["shares"] : [];
|
|
27
|
+
}
|
|
28
|
+
function isReceived(value) {
|
|
29
|
+
if (!isRecord(value))
|
|
30
|
+
return false;
|
|
31
|
+
return ["id", "item_id", "dek_share_ct", "name_share_ct", "content_hash_share_ct"].every((name) => typeof value[name] === "string");
|
|
32
|
+
}
|
|
33
|
+
/** Every code's shares, by number. A code with none has two empty lists. */
|
|
34
|
+
export async function codeActivity(crypt, code, door, list) {
|
|
35
|
+
const out = new Map();
|
|
36
|
+
for (const c of list.codes)
|
|
37
|
+
out.set(c.index, { sent: [], received: [] });
|
|
38
|
+
const slot = (index) => {
|
|
39
|
+
const had = out.get(index);
|
|
40
|
+
if (had !== undefined)
|
|
41
|
+
return had;
|
|
42
|
+
const made = { sent: [], received: [] };
|
|
43
|
+
out.set(index, made);
|
|
44
|
+
return made;
|
|
45
|
+
};
|
|
46
|
+
const files = await readFileList(door.server, door.token, code, door.accountId);
|
|
47
|
+
const entries = files.manifest?.entries ?? [];
|
|
48
|
+
const index = buildIndex(entries);
|
|
49
|
+
const pathOf = new Map(entries.map((e) => [e.id, fullPathOf(index, e)]));
|
|
50
|
+
for (const c of list.codes) {
|
|
51
|
+
const answer = await request(door.server, `/v1/shares/sent?from_index=${c.index}`, { token: door.token });
|
|
52
|
+
for (const row of rowsOf(answer)) {
|
|
53
|
+
if (!isRecord(row))
|
|
54
|
+
continue;
|
|
55
|
+
const { id, item_id: itemId, recipient_address: to, created_at: at } = row;
|
|
56
|
+
if (typeof id !== "string" || typeof itemId !== "string" || typeof to !== "string" || typeof at !== "string")
|
|
57
|
+
continue;
|
|
58
|
+
slot(c.index).sent.push({
|
|
59
|
+
id,
|
|
60
|
+
itemId,
|
|
61
|
+
path: pathOf.get(itemId) ?? null,
|
|
62
|
+
recipient: readable(crypt, to),
|
|
63
|
+
recipientRevoked: row["recipient_code_revoked"] === true,
|
|
64
|
+
createdAt: at,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const ring = shareKeyRing(crypt, code);
|
|
69
|
+
try {
|
|
70
|
+
const answer = await request(door.server, "/v1/shares/received", { token: door.token });
|
|
71
|
+
for (const row of rowsOf(answer).filter(isReceived)) {
|
|
72
|
+
const opened = openReceived(crypt, ring.at(receivedIndex(row)), row);
|
|
73
|
+
opened.dek?.fill(0);
|
|
74
|
+
slot(opened.toIndex).received.push({
|
|
75
|
+
id: opened.id,
|
|
76
|
+
name: opened.name,
|
|
77
|
+
sender: opened.sender,
|
|
78
|
+
senderRevoked: opened.senderRevoked,
|
|
79
|
+
createdAt: opened.createdAt,
|
|
80
|
+
problem: opened.problem,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
ring.wipe();
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NmtsError } from "./errors.ts";
|
|
2
|
+
/** What the texts below fill in. Each is optional; a missing one falls back to a sentence without it. */
|
|
3
|
+
export interface RefusalFacts {
|
|
4
|
+
/** How many live codes the account may hold. */
|
|
5
|
+
liveMax?: number | undefined;
|
|
6
|
+
/** How many new codes it may make per UTC day. */
|
|
7
|
+
dayCap?: number | undefined;
|
|
8
|
+
/** The number of the code a replacement would revoke — the account's default. */
|
|
9
|
+
replace?: number | undefined;
|
|
10
|
+
}
|
|
11
|
+
/** The refusal a person reads for `error`, or `error` itself when it is not one of the table's. */
|
|
12
|
+
export declare function publicCodeRefusal(error: unknown, facts?: RefusalFacts): unknown;
|
|
13
|
+
/** Revoking `index` would leave the account with no live code. */
|
|
14
|
+
export declare function lastLiveCode(index: number | undefined): NmtsError;
|
|
15
|
+
/** A number that is not one of this account's live codes. */
|
|
16
|
+
export declare function notLiveCode(index: number): NmtsError;
|
|
17
|
+
/**
|
|
18
|
+
* The server holds a code this key does not derive at that number.
|
|
19
|
+
*
|
|
20
|
+
* ⛔ THE BIGGER FACT, NOT "THE WRITE FAILED". Codes come from the NMTS key, so a different one means
|
|
21
|
+
* this machine holds a different account's key than the credential beside it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function differentCode(): NmtsError;
|
|
24
|
+
/** A public code's number as a person typed it after `flag`. */
|
|
25
|
+
export declare function codeNumber(text: string | undefined, flag: string): number;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// What a person is told when a public-code door refuses — one table, read by `nmts public-code …`
|
|
2
|
+
// and by `nmts share`.
|
|
3
|
+
//
|
|
4
|
+
// ⛔ IT TRANSLATES ONLY WHAT IT KNOWS. A refusal whose code is not in this table is handed on as
|
|
5
|
+
// the server sent it (`ServerError`, with the server's own advice), not reworded into a guess.
|
|
6
|
+
//
|
|
7
|
+
// ⚠ THE NUMBERS COME FROM THE REFUSAL WHEN IT CARRIES THEM (`details.cap`) and from the account's
|
|
8
|
+
// list otherwise — the server's ceiling, not a copy of it kept here.
|
|
9
|
+
import { ServerError } from "./api.js";
|
|
10
|
+
import { NmtsError } from "./errors.js";
|
|
11
|
+
import { BINARY_NAME } from "./product.js";
|
|
12
|
+
function capOf(error, fallback) {
|
|
13
|
+
const cap = error.details["cap"];
|
|
14
|
+
return typeof cap === "number" ? cap : fallback;
|
|
15
|
+
}
|
|
16
|
+
/** The refusal a person reads for `error`, or `error` itself when it is not one of the table's. */
|
|
17
|
+
export function publicCodeRefusal(error, facts = {}) {
|
|
18
|
+
if (!(error instanceof ServerError))
|
|
19
|
+
return error;
|
|
20
|
+
switch (error.code) {
|
|
21
|
+
case "TOO_MANY_LIVE_CODES": {
|
|
22
|
+
const cap = capOf(error, facts.liveMax);
|
|
23
|
+
const said = cap === undefined ? "as many live public codes as you may" : `${cap} live public codes`;
|
|
24
|
+
return new NmtsError(`You already hold ${said}.`, {
|
|
25
|
+
exitCode: 4,
|
|
26
|
+
nextStep: "Revoke one first, or make the new one with --replace <number>.",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
case "PUBLIC_CODE_DAY_CAP": {
|
|
30
|
+
const cap = capOf(error, facts.dayCap);
|
|
31
|
+
const said = cap === undefined ? "as many public codes today as you may" : `${cap} public codes today`;
|
|
32
|
+
return new NmtsError(`You have made ${said}.`, { exitCode: 4, nextStep: "Try again after 00:00 UTC." });
|
|
33
|
+
}
|
|
34
|
+
case "LAST_LIVE_CODE":
|
|
35
|
+
return lastLiveCode(facts.replace);
|
|
36
|
+
case "PLATFORM_REPLACE_ONLY":
|
|
37
|
+
return new NmtsError("This account holds one public code, so a new one replaces it.", {
|
|
38
|
+
exitCode: 4,
|
|
39
|
+
nextStep: `Use --replace ${facts.replace ?? "<number>"}.`,
|
|
40
|
+
});
|
|
41
|
+
case "PUBLIC_CODE_REVOKED":
|
|
42
|
+
return new NmtsError("Its owner has revoked that public code.", {
|
|
43
|
+
exitCode: 4,
|
|
44
|
+
nextStep: "Ask them for the code they use now.",
|
|
45
|
+
});
|
|
46
|
+
default:
|
|
47
|
+
return error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Revoking `index` would leave the account with no live code. */
|
|
51
|
+
export function lastLiveCode(index) {
|
|
52
|
+
return new NmtsError("That is your last live public code.", {
|
|
53
|
+
exitCode: 4,
|
|
54
|
+
nextStep: `Make a new one first: ${BINARY_NAME} public-code new --replace ${index ?? "<number>"}`,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** A number that is not one of this account's live codes. */
|
|
58
|
+
export function notLiveCode(index) {
|
|
59
|
+
return new NmtsError(`Public code #${index} is not a live code of this account.`, {
|
|
60
|
+
exitCode: 4,
|
|
61
|
+
nextStep: `\`${BINARY_NAME} public-code list\` shows which are.`,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The server holds a code this key does not derive at that number.
|
|
66
|
+
*
|
|
67
|
+
* ⛔ THE BIGGER FACT, NOT "THE WRITE FAILED". Codes come from the NMTS key, so a different one means
|
|
68
|
+
* this machine holds a different account's key than the credential beside it.
|
|
69
|
+
*/
|
|
70
|
+
export function differentCode() {
|
|
71
|
+
return new NmtsError("This account already publishes a different public code.", {
|
|
72
|
+
exitCode: 4,
|
|
73
|
+
nextStep: "The public code is derived from the NMTS key, so a different one means this machine " +
|
|
74
|
+
"is holding a different account's code than the key beside it. Check which account you meant.",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/** A public code's number as a person typed it after `flag`. */
|
|
78
|
+
export function codeNumber(text, flag) {
|
|
79
|
+
const trimmed = (text ?? "").trim();
|
|
80
|
+
const n = /^[0-9]{1,10}$/.test(trimmed) ? Number(trimmed) : Number.NaN;
|
|
81
|
+
if (!Number.isSafeInteger(n) || n > 2 ** 31 - 2) {
|
|
82
|
+
throw new NmtsError(`${flag} takes a public code's number, as \`${BINARY_NAME} public-code list\` prints it.`, {
|
|
83
|
+
exitCode: 2,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return n;
|
|
87
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { CryptoGlue } from "./crypto.ts";
|
|
2
|
+
/** One code as `GET /v1/account/public-codes` lists it. */
|
|
3
|
+
export interface PublicCodeRow {
|
|
4
|
+
index: number;
|
|
5
|
+
/** The 16-byte address, base64url, as the wire carries it. */
|
|
6
|
+
address: string;
|
|
7
|
+
createdAt: string;
|
|
8
|
+
/** When it was revoked, or null while it is live. */
|
|
9
|
+
revokedAt: string | null;
|
|
10
|
+
/** Shares sent from it, shares received with it, support threads that carry it. */
|
|
11
|
+
sent: number;
|
|
12
|
+
received: number;
|
|
13
|
+
support: number;
|
|
14
|
+
}
|
|
15
|
+
/** The whole answer: every code this account ever published, and the two ceilings on making more. */
|
|
16
|
+
export interface PublicCodeList {
|
|
17
|
+
codes: PublicCodeRow[];
|
|
18
|
+
/** How many may be live at once — 3, or 1 for a Platform user. */
|
|
19
|
+
liveMax: number;
|
|
20
|
+
/** How many new ones this account may make per UTC day, and how many it has made today. */
|
|
21
|
+
dayCap: number;
|
|
22
|
+
madeToday: number;
|
|
23
|
+
}
|
|
24
|
+
/** How many numbers in a row publishing walks past before it stops. */
|
|
25
|
+
export declare const PUBLISH_TRIES = 64;
|
|
26
|
+
/** `GET /v1/account/public-codes`, read field by field. Codes come back in number order. */
|
|
27
|
+
export declare function readPublicCodes(server: string, token: string): Promise<PublicCodeList>;
|
|
28
|
+
/** The live codes, lowest number first. */
|
|
29
|
+
export declare function liveCodes(list: PublicCodeList): PublicCodeRow[];
|
|
30
|
+
/** The code this account shows and sends from unless told otherwise: its lowest-numbered live one. */
|
|
31
|
+
export declare function defaultCode(list: PublicCodeList): PublicCodeRow | null;
|
|
32
|
+
/** The number a new code gets: one past the highest ever published, or 0 for an account with none. */
|
|
33
|
+
export declare function nextCodeIndex(list: PublicCodeList): number;
|
|
34
|
+
/** Where a request goes and what it carries. */
|
|
35
|
+
export interface CodeDoor {
|
|
36
|
+
server: string;
|
|
37
|
+
token: string;
|
|
38
|
+
}
|
|
39
|
+
/** What publishing answers: the number it landed on and the code a person reads. */
|
|
40
|
+
export interface PublishedCode {
|
|
41
|
+
index: number;
|
|
42
|
+
/** The grouped form a person reads and types. */
|
|
43
|
+
code: string;
|
|
44
|
+
/** The 16 bytes, base64url. */
|
|
45
|
+
address: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Publish this key's code at `from` (default: the next number), revoking `replace` in the same
|
|
49
|
+
* request when it is given. Walks past numbers the server says were revoked, up to `PUBLISH_TRIES`.
|
|
50
|
+
*
|
|
51
|
+
* ⛔ THE IDENTITY IS DERIVED HERE AND NOWHERE ELSE. There is no form of this that takes an identity
|
|
52
|
+
* from a caller: what goes to the server is what this key makes at that number.
|
|
53
|
+
*/
|
|
54
|
+
export declare function publishCode(crypt: CryptoGlue, code: string, door: CodeDoor, from: number, replace?: number): Promise<PublishedCode>;
|
|
55
|
+
/**
|
|
56
|
+
* Make sure the account has a live code, publishing the next number when it has none — what a
|
|
57
|
+
* first share does before anything else. Answers the list as it now stands, and whether it wrote.
|
|
58
|
+
*/
|
|
59
|
+
export declare function ensureLiveCode(crypt: CryptoGlue, code: string, door: CodeDoor, onPublish?: () => void): Promise<{
|
|
60
|
+
list: PublicCodeList;
|
|
61
|
+
published: PublishedCode | null;
|
|
62
|
+
}>;
|
|
63
|
+
/** One bucket of the server's revoked list, fetched once per lookup that shares it. */
|
|
64
|
+
export type RevokedBuckets = Map<string, Promise<Uint8Array[]>>;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the code at `address` is on the server's revoked list — or null when the list could not
|
|
67
|
+
* be read (offline, rate-limited, an older server), which is "unknown", not "live".
|
|
68
|
+
*
|
|
69
|
+
* ⛔ ASKED BY BUCKET, NEVER BY CODE. The server keeps SHA-256 of each revoked address; this fetches
|
|
70
|
+
* every mark whose hex starts with the same digit as this address's mark (one of sixteen) and
|
|
71
|
+
* compares here. A question about one code would tell the server who is dealing with whom — the
|
|
72
|
+
* thing a handover exists not to tell it. Needs no credential.
|
|
73
|
+
*/
|
|
74
|
+
export declare function revokedOnServer(server: string, address: Uint8Array, buckets?: RevokedBuckets): Promise<boolean | null>;
|
|
75
|
+
/** `POST /v1/account/public-codes/{index}/revoke`. One way: nothing brings a code back. */
|
|
76
|
+
export declare function revokeCode(door: CodeDoor, index: number): Promise<void>;
|