@rotifer/playground 0.34.0 → 0.36.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 +33 -0
- package/README.md +4 -2
- package/README.zh.md +2 -2
- package/dist/cloud/auth.d.ts +7 -0
- package/dist/cloud/auth.d.ts.map +1 -1
- package/dist/cloud/auth.js +35 -35
- package/dist/cloud/auth.js.map +1 -1
- package/dist/cloud/callback-page.d.ts +2 -0
- package/dist/cloud/callback-page.d.ts.map +1 -0
- package/dist/cloud/callback-page.js +45 -0
- package/dist/cloud/callback-page.js.map +1 -0
- package/dist/cloud/gene-availability.d.ts +31 -0
- package/dist/cloud/gene-availability.d.ts.map +1 -0
- package/dist/cloud/gene-availability.js +75 -0
- package/dist/cloud/gene-availability.js.map +1 -0
- package/dist/commands/agent-run.d.ts +9 -0
- package/dist/commands/agent-run.d.ts.map +1 -1
- package/dist/commands/agent-run.js +5 -4
- package/dist/commands/agent-run.js.map +1 -1
- package/dist/commands/arena-submit.d.ts.map +1 -1
- package/dist/commands/arena-submit.js +2 -1
- package/dist/commands/arena-submit.js.map +1 -1
- package/dist/commands/hello.d.ts +27 -0
- package/dist/commands/hello.d.ts.map +1 -1
- package/dist/commands/hello.js +286 -59
- package/dist/commands/hello.js.map +1 -1
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +3 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +29 -32
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/network-attest.d.ts +55 -0
- package/dist/commands/network-attest.d.ts.map +1 -0
- package/dist/commands/network-attest.js +266 -0
- package/dist/commands/network-attest.js.map +1 -0
- package/dist/commands/network.d.ts.map +1 -1
- package/dist/commands/network.js +11 -0
- package/dist/commands/network.js.map +1 -1
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +2 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +4 -3
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/test.js +6 -6
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/wrap.d.ts +4 -0
- package/dist/commands/wrap.d.ts.map +1 -1
- package/dist/commands/wrap.js +86 -11
- package/dist/commands/wrap.js.map +1 -1
- package/dist/testsuite/generate.d.ts.map +1 -1
- package/dist/testsuite/generate.js +23 -0
- package/dist/testsuite/generate.js.map +1 -1
- package/dist/utils/binding.d.ts +9 -0
- package/dist/utils/binding.d.ts.map +1 -1
- package/dist/utils/binding.js.map +1 -1
- package/dist/utils/l0-gate.d.ts +9 -0
- package/dist/utils/l0-gate.d.ts.map +1 -1
- package/dist/utils/l0-gate.js +27 -0
- package/dist/utils/l0-gate.js.map +1 -1
- package/dist/utils/open-browser.d.ts +9 -2
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js +39 -5
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/p2p-daemon.d.ts +9 -0
- package/dist/utils/p2p-daemon.d.ts.map +1 -1
- package/dist/utils/p2p-daemon.js +26 -0
- package/dist/utils/p2p-daemon.js.map +1 -1
- package/dist/utils/por-client.d.ts +86 -0
- package/dist/utils/por-client.d.ts.map +1 -0
- package/dist/utils/por-client.js +245 -0
- package/dist/utils/por-client.js.map +1 -0
- package/dist/utils/por-keeper.d.ts +82 -0
- package/dist/utils/por-keeper.d.ts.map +1 -0
- package/dist/utils/por-keeper.js +237 -0
- package/dist/utils/por-keeper.js.map +1 -0
- package/dist/utils/zip-safety.d.ts +18 -0
- package/dist/utils/zip-safety.d.ts.map +1 -0
- package/dist/utils/zip-safety.js +102 -0
- package/dist/utils/zip-safety.js.map +1 -0
- package/package.json +5 -5
package/dist/utils/p2p-daemon.js
CHANGED
|
@@ -24,6 +24,8 @@ const node_crypto_1 = require("node:crypto");
|
|
|
24
24
|
const private_fs_js_1 = require("./private-fs.js");
|
|
25
25
|
const binding_js_1 = require("./binding.js");
|
|
26
26
|
const announce_table_js_1 = require("./announce-table.js");
|
|
27
|
+
const por_client_js_1 = require("./por-client.js");
|
|
28
|
+
const por_keeper_js_1 = require("./por-keeper.js");
|
|
27
29
|
const ROTIFER_HOME = (0, node_path_1.join)(process.env.HOME || process.env.USERPROFILE || "/tmp", ".rotifer");
|
|
28
30
|
const DAEMON_STATE = (0, node_path_1.join)(ROTIFER_HOME, "daemon.json");
|
|
29
31
|
const TOKEN_HEADER = "x-rotifer-token";
|
|
@@ -125,6 +127,7 @@ async function runDaemon(listenHost, listenPort, bootstrapPeers, shouldUseMdns)
|
|
|
125
127
|
}
|
|
126
128
|
const node = maybeNode; // non-null below (incl. inside the control-server closure)
|
|
127
129
|
node.start();
|
|
130
|
+
const { colocationStats } = node;
|
|
128
131
|
const token = (0, node_crypto_1.randomBytes)(24).toString("hex");
|
|
129
132
|
const startedAt = Date.now();
|
|
130
133
|
let isShuttingDown = false;
|
|
@@ -140,6 +143,16 @@ async function runDaemon(listenHost, listenPort, bootstrapPeers, shouldUseMdns)
|
|
|
140
143
|
})
|
|
141
144
|
: null;
|
|
142
145
|
republisher?.restore();
|
|
146
|
+
// Certificates need an addon that can answer a challenge (T-170).
|
|
147
|
+
const keeper = (0, por_client_js_1.isPorCapable)(node)
|
|
148
|
+
? new por_keeper_js_1.PorKeeper({
|
|
149
|
+
path: (0, por_keeper_js_1.porStatePath)(ROTIFER_HOME),
|
|
150
|
+
node,
|
|
151
|
+
obtain: (n) => (0, por_client_js_1.obtainCertificate)(n),
|
|
152
|
+
log: (line) => process.stderr.write(`${line}\n`),
|
|
153
|
+
})
|
|
154
|
+
: null;
|
|
155
|
+
keeper?.start();
|
|
143
156
|
const server = (0, node_http_1.createServer)((req, res) => {
|
|
144
157
|
const send = (code, obj) => {
|
|
145
158
|
res.writeHead(code, { "content-type": "application/json" });
|
|
@@ -158,6 +171,10 @@ async function runDaemon(listenHost, listenPort, bootstrapPeers, shouldUseMdns)
|
|
|
158
171
|
// An older native addon lacks these; leave them out rather than fail.
|
|
159
172
|
...(node.dhtPeers ? { dhtPeers: node.dhtPeers().length } : {}),
|
|
160
173
|
...(node.connectedPeers ? { connectedPeers: node.connectedPeers().length } : {}),
|
|
174
|
+
// Cumulative same-IP counters (A6 design v3 §3.4); absent before A6.
|
|
175
|
+
...(colocationStats ? { colocation: colocationStats.call(node) } : {}),
|
|
176
|
+
// Absent when this addon cannot hold a certificate.
|
|
177
|
+
...(keeper ? { attestation: keeper.view() } : {}),
|
|
161
178
|
startedAt,
|
|
162
179
|
});
|
|
163
180
|
return;
|
|
@@ -263,6 +280,14 @@ async function runDaemon(listenHost, listenPort, bootstrapPeers, shouldUseMdns)
|
|
|
263
280
|
});
|
|
264
281
|
return;
|
|
265
282
|
}
|
|
283
|
+
if (req.method === "POST" && url.pathname === "/attestation/reload") {
|
|
284
|
+
if (!keeper) {
|
|
285
|
+
send(501, { error: "this native addon cannot hold a certificate; update the CLI" });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
send(200, { ok: true, attestation: keeper.reload() });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
266
291
|
if (req.method === "POST" && url.pathname === "/stop") {
|
|
267
292
|
send(200, { ok: true });
|
|
268
293
|
shutdown();
|
|
@@ -275,6 +300,7 @@ async function runDaemon(listenHost, listenPort, bootstrapPeers, shouldUseMdns)
|
|
|
275
300
|
return;
|
|
276
301
|
isShuttingDown = true;
|
|
277
302
|
republisher?.stop();
|
|
303
|
+
keeper?.stop();
|
|
278
304
|
try {
|
|
279
305
|
node.stop();
|
|
280
306
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p2p-daemon.js","sourceRoot":"","sources":["../../src/utils/p2p-daemon.ts"],"names":[],"mappings":";;AAuCA,0CAOC;AAQD,4CAMC;AAqBD,wCAkDC;AAGD,0CAGC;AAOD,8BAgMC;AAhVD;;;;;;;;;;;GAWG;AACH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C,CAAC,CAAC;QACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,iFAAiF;AACnF,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { PorChallengeSignature } from "./binding.js";
|
|
2
|
+
export declare const POR_LIFETIME_S: number;
|
|
3
|
+
/** ADR-300, the wording fixed by the 2026-11-02 ruling. */
|
|
4
|
+
export declare const CONSENT_NOTICE: string;
|
|
5
|
+
/** What a certificate commits the user to, shown alongside the consent notice. */
|
|
6
|
+
export declare const LIFETIME_NOTICE: string;
|
|
7
|
+
export declare const CONSENT_FLAG = "--accept-public-pseudonym";
|
|
8
|
+
/** por.rs `MAX_JWKS_CACHE_SECS` is the 24 hours; ADR-300 D4 revision is the 7 days. */
|
|
9
|
+
export declare const BAN_NOTICE: string;
|
|
10
|
+
export declare const KEY_CHANGE_NOTICE: string;
|
|
11
|
+
declare const FAILURES: {
|
|
12
|
+
readonly POR_NOT_LOGGED_IN: readonly ["You are not signed in.", "Run 'rotifer login', then run this command again."];
|
|
13
|
+
readonly POR_SESSION_EXPIRED: readonly ["Your sign-in has expired.", "Run 'rotifer login', then run this command again."];
|
|
14
|
+
readonly POR_CONSENT_REQUIRED: readonly ["Nothing was enabled: enabling certificates needs your explicit agreement.", "Pass --accept-public-pseudonym to agree that this node is publicly linked to an account pseudonym."];
|
|
15
|
+
readonly POR_CONSENT_DECLINED: readonly ["Nothing was enabled: you did not agree.", "Run this command again if you change your mind."];
|
|
16
|
+
readonly POR_NOT_ENABLED: readonly ["Certificates are not enabled on this node.", "Run 'rotifer network attest enable' first."];
|
|
17
|
+
readonly POR_KEY_CHANGED: readonly ["This node's key changed, so its certificate no longer applies.", string];
|
|
18
|
+
readonly POR_CLIENT_NEEDS_UPGRADE: readonly ["This CLI's native node cannot request certificates.", "Update the CLI (rotifer self-update), then try again."];
|
|
19
|
+
readonly POR_SERVICE_NOT_OPEN: readonly ["The certificate service is not open yet.", "Nothing to fix on your side: the node keeps running without a certificate. Try again later."];
|
|
20
|
+
readonly POR_UNREACHABLE: readonly ["The certificate service could not be reached.", "Check your connection and try again."];
|
|
21
|
+
readonly POR_BAD_CLOUD_ENDPOINT: readonly ["The Cloud endpoint is not usable for certificates: your session would be sent to it unprotected.", "Set ROTIFER_CLOUD_ENDPOINT (or endpoint in ~/.rotifer/cloud.json) to an https address, or plain http to this machine."];
|
|
22
|
+
readonly POR_AUD_MISMATCH: readonly ["The certificate service answered for a different address than the one called, so nothing was signed.", "If you changed ROTIFER_CLOUD_ENDPOINT or ~/.rotifer/cloud.json, it must match the address the service is set up for. Otherwise update the CLI."];
|
|
23
|
+
readonly POR_BAD_RESPONSE: readonly ["The certificate service sent an answer this CLI cannot use.", "Update the CLI (rotifer self-update), then try again."];
|
|
24
|
+
readonly POR_SERVICE_ERROR: readonly ["The certificate service could not complete the request.", "Try again later."];
|
|
25
|
+
readonly POR_CLIENT_ERROR: readonly ["The certificate request could not be completed on this machine.", "Try again later."];
|
|
26
|
+
readonly POR_QUOTA_EXCEEDED: readonly ["This account already has certificates for 3 nodes.", string];
|
|
27
|
+
readonly POR_RENEWAL_TOO_EARLY: readonly ["This node got a certificate in the last 24 hours and it still has more than 48 hours left.", "Nothing to do if the node still has it: it renews on its own. If this machine lost its copy, try again 24 hours after that certificate was issued."];
|
|
28
|
+
readonly POR_CHALLENGE_INVALID: readonly ["The sign-in challenge was not accepted.", "Run this command again."];
|
|
29
|
+
readonly POR_CHALLENGE_EXPIRED: readonly ["The sign-in challenge expired before it was answered.", "Run this command again."];
|
|
30
|
+
readonly POR_BAD_SIGNATURE: readonly ["The service did not accept this node's signature.", "Update the CLI (rotifer self-update), then try again."];
|
|
31
|
+
readonly POR_UNSUPPORTED_KEY: readonly ["The service does not support this node's key type.", "To go on with a new identity, delete ~/.rotifer/identity.pem, restart the node and run 'rotifer network attest enable'."];
|
|
32
|
+
readonly POR_BAD_REQUEST: readonly ["The service did not understand the request.", "Update the CLI (rotifer self-update), then try again."];
|
|
33
|
+
readonly POR_ACCOUNT_CLOSED: readonly ["This account can no longer get certificates.", "Sign in with an account in good standing: rotifer login."];
|
|
34
|
+
readonly POR_PEER_BOUND_ELSEWHERE: readonly ["This node's identity is already registered to another account.", "Sign in with that account. To go on with a new identity, delete ~/.rotifer/identity.pem, restart the node and run 'rotifer network attest enable'."];
|
|
35
|
+
readonly POR_PEER_REVOKED: readonly ["This node's identity has been revoked.", "To go on with a new identity, delete ~/.rotifer/identity.pem, restart the node and run 'rotifer network attest enable'."];
|
|
36
|
+
readonly POR_TOO_MANY_CHALLENGES: readonly ["Too many certificate requests from this account.", "Try again later."];
|
|
37
|
+
readonly POR_RATE_LIMITED: readonly ["Too many certificate requests from this account.", "Try again later."];
|
|
38
|
+
};
|
|
39
|
+
export type PorErrorCode = keyof typeof FAILURES;
|
|
40
|
+
export declare class PorError extends Error {
|
|
41
|
+
readonly code: PorErrorCode;
|
|
42
|
+
readonly fix: string;
|
|
43
|
+
/** `detail` is added to the fixed text; it must hold nothing secret. */
|
|
44
|
+
constructor(code: PorErrorCode, detail?: string);
|
|
45
|
+
}
|
|
46
|
+
/** Any failure as a PorError; an unexpected one loses its text, which could hold anything. */
|
|
47
|
+
export declare function asPorError(err: unknown): PorError;
|
|
48
|
+
/** What a refusal means. `code` comes off the network: only known ones are used. */
|
|
49
|
+
export declare function errorFromResponse(status: number, code: unknown): PorError;
|
|
50
|
+
/** The function to call under a Cloud endpoint. The session token goes here. */
|
|
51
|
+
export declare function porFunctionUrl(endpoint: string): string;
|
|
52
|
+
export interface PorSession {
|
|
53
|
+
jwt: string;
|
|
54
|
+
userId: string;
|
|
55
|
+
}
|
|
56
|
+
/** The signed-in account, refreshing an expired session when it can. */
|
|
57
|
+
export declare function currentSession(): Promise<PorSession>;
|
|
58
|
+
/** The two native calls a certificate needs; older addons lack them. */
|
|
59
|
+
export interface PorCapableNode {
|
|
60
|
+
peerId(): string;
|
|
61
|
+
signPorChallenge(aud: string, userId: string, nonce: string, challengeExp: number): PorChallengeSignature;
|
|
62
|
+
setAttestation(token: string | null): void;
|
|
63
|
+
}
|
|
64
|
+
export declare function isPorCapable<T extends {
|
|
65
|
+
peerId(): string;
|
|
66
|
+
}>(node: T | null | undefined): node is T & PorCapableNode;
|
|
67
|
+
export interface PorClientDeps {
|
|
68
|
+
fetch: typeof fetch;
|
|
69
|
+
session: () => Promise<PorSession>;
|
|
70
|
+
functionUrl: () => string;
|
|
71
|
+
}
|
|
72
|
+
export declare const defaultPorClientDeps: PorClientDeps;
|
|
73
|
+
export interface PorCertificate {
|
|
74
|
+
token: string;
|
|
75
|
+
peerId: string;
|
|
76
|
+
iat: number;
|
|
77
|
+
exp: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* One full challenge round for this node. Refuses a challenge issued for any
|
|
81
|
+
* address other than the one called, so a signature made here can only be
|
|
82
|
+
* spent at that address. The caller decides what to do with the certificate.
|
|
83
|
+
*/
|
|
84
|
+
export declare function obtainCertificate(node: PorCapableNode, deps?: PorClientDeps): Promise<PorCertificate>;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=por-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"por-client.d.ts","sourceRoot":"","sources":["../../src/utils/por-client.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAU1D,eAAO,MAAM,cAAc,QAAgB,CAAC;AAG5C,2DAA2D;AAC3D,eAAO,MAAM,cAAc,QAEgF,CAAC;AAC5G,kFAAkF;AAClF,eAAO,MAAM,eAAe,QAEoF,CAAC;AACjH,eAAO,MAAM,YAAY,8BAA8B,CAAC;AAExD,uFAAuF;AACvF,eAAO,MAAM,UAAU,QAE4G,CAAC;AACpI,eAAO,MAAM,iBAAiB,QAGoG,CAAC;AAQnI,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;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UAAU,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,oBAAoB,EAAE,aAIlC,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAmCD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,cAAc,EACpB,IAAI,GAAE,aAAoC,GACzC,OAAO,CAAC,cAAc,CAAC,CAsCzB"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultPorClientDeps = exports.PorError = exports.KEY_CHANGE_NOTICE = exports.BAN_NOTICE = exports.CONSENT_FLAG = exports.LIFETIME_NOTICE = exports.CONSENT_NOTICE = exports.POR_LIFETIME_S = void 0;
|
|
4
|
+
exports.asPorError = asPorError;
|
|
5
|
+
exports.errorFromResponse = errorFromResponse;
|
|
6
|
+
exports.porFunctionUrl = porFunctionUrl;
|
|
7
|
+
exports.currentSession = currentSession;
|
|
8
|
+
exports.isPorCapable = isPorCapable;
|
|
9
|
+
exports.obtainCertificate = obtainCertificate;
|
|
10
|
+
/**
|
|
11
|
+
* Client for the node-attestation issuing function (ADR-300 revision 2).
|
|
12
|
+
*
|
|
13
|
+
* Gets a proof-of-registration certificate for this node: ask for a challenge,
|
|
14
|
+
* have the native node answer it with its key, trade the answer for a token.
|
|
15
|
+
* Enabling and renewing share `obtainCertificate`.
|
|
16
|
+
*
|
|
17
|
+
* Nothing here may put a session token, a certificate or the account pseudonym
|
|
18
|
+
* in an error: every failure is a `PorError` built from fixed text.
|
|
19
|
+
*/
|
|
20
|
+
const node_fs_1 = require("node:fs");
|
|
21
|
+
const node_path_1 = require("node:path");
|
|
22
|
+
const auth_js_1 = require("../cloud/auth.js");
|
|
23
|
+
const client_js_1 = require("../cloud/client.js");
|
|
24
|
+
const types_js_1 = require("../cloud/types.js");
|
|
25
|
+
/**
|
|
26
|
+
* Where the function lives under the Cloud endpoint. The whole address is also
|
|
27
|
+
* the `aud` it signs challenges for (ADR-300), so production's
|
|
28
|
+
* NODE_ATTESTATION_AUD must be this, byte for byte, under the default endpoint:
|
|
29
|
+
* https://cloud.rotifer.dev/functions/v1/node-attestation
|
|
30
|
+
*/
|
|
31
|
+
const POR_FUNCTION_PATH = "/functions/v1/node-attestation";
|
|
32
|
+
exports.POR_LIFETIME_S = 7 * 24 * 3600;
|
|
33
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
34
|
+
/** ADR-300, the wording fixed by the 2026-11-02 ruling. */
|
|
35
|
+
exports.CONSENT_NOTICE = "你的节点会和一个账号假名关联公开,Cloud 能反查。 " +
|
|
36
|
+
"Your node will be publicly linked to an account pseudonym, and Cloud can trace it back to your account.";
|
|
37
|
+
/** What a certificate commits the user to, shown alongside the consent notice. */
|
|
38
|
+
exports.LIFETIME_NOTICE = "证书 7 天内失效;节点在线时会在剩余不足 48 小时时自动续签。 " +
|
|
39
|
+
"The certificate expires within 7 days; while the node is online it renews itself when under 48 hours remain.";
|
|
40
|
+
exports.CONSENT_FLAG = "--accept-public-pseudonym";
|
|
41
|
+
/** por.rs `MAX_JWKS_CACHE_SECS` is the 24 hours; ADR-300 D4 revision is the 7 days. */
|
|
42
|
+
exports.BAN_NOTICE = "If your account is banned or a certificate is revoked, other nodes stop accepting it within about 24 hours " +
|
|
43
|
+
"of the revocation being published. Without a published revocation it stops working when it expires, at most 7 days after issue.";
|
|
44
|
+
exports.KEY_CHANGE_NOTICE = "This node's key changed, so it is a new node to the network and needs its own certificate: run 'rotifer network attest enable'. " +
|
|
45
|
+
"The old certificate is not voided: it stays valid for the old identity until it expires (at most 7 days), " +
|
|
46
|
+
"and anyone holding the old key can keep using it. If the old key may have leaked, ask the Rotifer team to revoke the old node.";
|
|
47
|
+
const SIGN_IN = "Run 'rotifer login', then run this command again.";
|
|
48
|
+
const LATER = "Try again later.";
|
|
49
|
+
const UPDATE_CLI = "Update the CLI (rotifer self-update), then try again.";
|
|
50
|
+
const NEW_IDENTITY = "To go on with a new identity, delete ~/.rotifer/identity.pem, restart the node and run 'rotifer network attest enable'.";
|
|
51
|
+
const FAILURES = {
|
|
52
|
+
POR_NOT_LOGGED_IN: ["You are not signed in.", SIGN_IN],
|
|
53
|
+
POR_SESSION_EXPIRED: ["Your sign-in has expired.", SIGN_IN],
|
|
54
|
+
POR_CONSENT_REQUIRED: [
|
|
55
|
+
"Nothing was enabled: enabling certificates needs your explicit agreement.",
|
|
56
|
+
`Pass ${exports.CONSENT_FLAG} to agree that this node is publicly linked to an account pseudonym.`,
|
|
57
|
+
],
|
|
58
|
+
POR_CONSENT_DECLINED: ["Nothing was enabled: you did not agree.", "Run this command again if you change your mind."],
|
|
59
|
+
POR_NOT_ENABLED: ["Certificates are not enabled on this node.", "Run 'rotifer network attest enable' first."],
|
|
60
|
+
POR_KEY_CHANGED: ["This node's key changed, so its certificate no longer applies.", exports.KEY_CHANGE_NOTICE],
|
|
61
|
+
POR_CLIENT_NEEDS_UPGRADE: ["This CLI's native node cannot request certificates.", UPDATE_CLI],
|
|
62
|
+
POR_SERVICE_NOT_OPEN: [
|
|
63
|
+
"The certificate service is not open yet.",
|
|
64
|
+
"Nothing to fix on your side: the node keeps running without a certificate. Try again later.",
|
|
65
|
+
],
|
|
66
|
+
POR_UNREACHABLE: ["The certificate service could not be reached.", "Check your connection and try again."],
|
|
67
|
+
POR_BAD_CLOUD_ENDPOINT: [
|
|
68
|
+
"The Cloud endpoint is not usable for certificates: your session would be sent to it unprotected.",
|
|
69
|
+
"Set ROTIFER_CLOUD_ENDPOINT (or endpoint in ~/.rotifer/cloud.json) to an https address, or plain http to this machine.",
|
|
70
|
+
],
|
|
71
|
+
POR_AUD_MISMATCH: [
|
|
72
|
+
"The certificate service answered for a different address than the one called, so nothing was signed.",
|
|
73
|
+
"If you changed ROTIFER_CLOUD_ENDPOINT or ~/.rotifer/cloud.json, it must match the address the service is set up for. Otherwise update the CLI.",
|
|
74
|
+
],
|
|
75
|
+
POR_BAD_RESPONSE: ["The certificate service sent an answer this CLI cannot use.", UPDATE_CLI],
|
|
76
|
+
POR_SERVICE_ERROR: ["The certificate service could not complete the request.", LATER],
|
|
77
|
+
POR_CLIENT_ERROR: ["The certificate request could not be completed on this machine.", LATER],
|
|
78
|
+
// The function's own codes (supabase/functions/node-attestation/README.md).
|
|
79
|
+
POR_QUOTA_EXCEEDED: [
|
|
80
|
+
"This account already has certificates for 3 nodes.",
|
|
81
|
+
"A slot frees up when that node's certificate expires, at most 7 days after its last renewal. " +
|
|
82
|
+
"Run 'rotifer network attest disable' on a node you no longer use, then try again once its certificate has expired.",
|
|
83
|
+
],
|
|
84
|
+
POR_RENEWAL_TOO_EARLY: [
|
|
85
|
+
"This node got a certificate in the last 24 hours and it still has more than 48 hours left.",
|
|
86
|
+
"Nothing to do if the node still has it: it renews on its own. If this machine lost its copy, try again 24 hours after that certificate was issued.",
|
|
87
|
+
],
|
|
88
|
+
POR_CHALLENGE_INVALID: ["The sign-in challenge was not accepted.", "Run this command again."],
|
|
89
|
+
POR_CHALLENGE_EXPIRED: ["The sign-in challenge expired before it was answered.", "Run this command again."],
|
|
90
|
+
POR_BAD_SIGNATURE: ["The service did not accept this node's signature.", UPDATE_CLI],
|
|
91
|
+
POR_UNSUPPORTED_KEY: ["The service does not support this node's key type.", NEW_IDENTITY],
|
|
92
|
+
POR_BAD_REQUEST: ["The service did not understand the request.", UPDATE_CLI],
|
|
93
|
+
POR_ACCOUNT_CLOSED: ["This account can no longer get certificates.", "Sign in with an account in good standing: rotifer login."],
|
|
94
|
+
POR_PEER_BOUND_ELSEWHERE: [
|
|
95
|
+
"This node's identity is already registered to another account.",
|
|
96
|
+
`Sign in with that account. ${NEW_IDENTITY}`,
|
|
97
|
+
],
|
|
98
|
+
POR_PEER_REVOKED: ["This node's identity has been revoked.", NEW_IDENTITY],
|
|
99
|
+
POR_TOO_MANY_CHALLENGES: ["Too many certificate requests from this account.", LATER],
|
|
100
|
+
POR_RATE_LIMITED: ["Too many certificate requests from this account.", LATER],
|
|
101
|
+
};
|
|
102
|
+
class PorError extends Error {
|
|
103
|
+
code;
|
|
104
|
+
fix;
|
|
105
|
+
/** `detail` is added to the fixed text; it must hold nothing secret. */
|
|
106
|
+
constructor(code, detail) {
|
|
107
|
+
super(detail ? `${FAILURES[code][0]} ${detail}` : FAILURES[code][0]);
|
|
108
|
+
this.name = "PorError";
|
|
109
|
+
this.code = code;
|
|
110
|
+
this.fix = FAILURES[code][1];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.PorError = PorError;
|
|
114
|
+
/** Any failure as a PorError; an unexpected one loses its text, which could hold anything. */
|
|
115
|
+
function asPorError(err) {
|
|
116
|
+
return err instanceof PorError ? err : new PorError("POR_CLIENT_ERROR");
|
|
117
|
+
}
|
|
118
|
+
/** What a refusal means. `code` comes off the network: only known ones are used. */
|
|
119
|
+
function errorFromResponse(status, code) {
|
|
120
|
+
if (typeof code === "string") {
|
|
121
|
+
// The function is deployed but has no keys yet: to a user, not open.
|
|
122
|
+
if (code === "POR_NOT_CONFIGURED")
|
|
123
|
+
return new PorError("POR_SERVICE_NOT_OPEN");
|
|
124
|
+
if (code.startsWith("POR_") && Object.hasOwn(FAILURES, code))
|
|
125
|
+
return new PorError(code);
|
|
126
|
+
}
|
|
127
|
+
// Not the function's own answer: its gateway or a proxy spoke.
|
|
128
|
+
if (status === 404)
|
|
129
|
+
return new PorError("POR_SERVICE_NOT_OPEN");
|
|
130
|
+
if (status === 401)
|
|
131
|
+
return new PorError("POR_SESSION_EXPIRED");
|
|
132
|
+
return new PorError("POR_SERVICE_ERROR");
|
|
133
|
+
}
|
|
134
|
+
function isLoopback(host) {
|
|
135
|
+
return host === "localhost" || host === "[::1]" || /^127(\.\d{1,3}){3}$/.test(host);
|
|
136
|
+
}
|
|
137
|
+
/** The function to call under a Cloud endpoint. The session token goes here. */
|
|
138
|
+
function porFunctionUrl(endpoint) {
|
|
139
|
+
let url;
|
|
140
|
+
try {
|
|
141
|
+
url = new URL(endpoint);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
throw new PorError("POR_BAD_CLOUD_ENDPOINT");
|
|
145
|
+
}
|
|
146
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && isLoopback(url.hostname))) {
|
|
147
|
+
throw new PorError("POR_BAD_CLOUD_ENDPOINT");
|
|
148
|
+
}
|
|
149
|
+
return `${endpoint.replace(/\/+$/, "")}${POR_FUNCTION_PATH}`;
|
|
150
|
+
}
|
|
151
|
+
/** Text from the network, made safe to print on one line. */
|
|
152
|
+
function printable(text) {
|
|
153
|
+
return JSON.stringify(text.slice(0, 200));
|
|
154
|
+
}
|
|
155
|
+
function credentialsPath() {
|
|
156
|
+
return (0, node_path_1.join)(process.env.HOME || process.env.USERPROFILE || "/tmp", ".rotifer", types_js_1.CREDENTIALS_FILE);
|
|
157
|
+
}
|
|
158
|
+
/** The signed-in account, refreshing an expired session when it can. */
|
|
159
|
+
async function currentSession() {
|
|
160
|
+
await (0, auth_js_1.refreshTokenIfNeeded)();
|
|
161
|
+
const creds = (0, auth_js_1.loadCredentials)();
|
|
162
|
+
if (creds?.access_token && creds.user?.id)
|
|
163
|
+
return { jwt: creds.access_token, userId: creds.user.id };
|
|
164
|
+
throw new PorError((0, node_fs_1.existsSync)(credentialsPath()) ? "POR_SESSION_EXPIRED" : "POR_NOT_LOGGED_IN");
|
|
165
|
+
}
|
|
166
|
+
function isPorCapable(node) {
|
|
167
|
+
const n = node;
|
|
168
|
+
return typeof n?.signPorChallenge === "function" && typeof n?.setAttestation === "function";
|
|
169
|
+
}
|
|
170
|
+
exports.defaultPorClientDeps = {
|
|
171
|
+
fetch: (input, init) => fetch(input, init),
|
|
172
|
+
session: currentSession,
|
|
173
|
+
functionUrl: () => porFunctionUrl((0, client_js_1.loadCloudConfig)().endpoint),
|
|
174
|
+
};
|
|
175
|
+
async function callFunction(deps, url, op, jwt, body) {
|
|
176
|
+
let res;
|
|
177
|
+
let text;
|
|
178
|
+
try {
|
|
179
|
+
res = await deps.fetch(`${url}/${op}`, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${jwt}` },
|
|
182
|
+
body: JSON.stringify(body),
|
|
183
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
184
|
+
});
|
|
185
|
+
text = await res.text();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
throw new PorError("POR_UNREACHABLE");
|
|
189
|
+
}
|
|
190
|
+
let parsed = null;
|
|
191
|
+
try {
|
|
192
|
+
parsed = JSON.parse(text);
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Handled below: a gateway's HTML page and a broken answer look alike.
|
|
196
|
+
}
|
|
197
|
+
if (!res.ok)
|
|
198
|
+
throw errorFromResponse(res.status, parsed?.error?.code);
|
|
199
|
+
if (parsed === null || typeof parsed !== "object")
|
|
200
|
+
throw new PorError("POR_BAD_RESPONSE");
|
|
201
|
+
return parsed;
|
|
202
|
+
}
|
|
203
|
+
const isWholeNumber = (v) => typeof v === "number" && Number.isSafeInteger(v) && v > 0;
|
|
204
|
+
/**
|
|
205
|
+
* One full challenge round for this node. Refuses a challenge issued for any
|
|
206
|
+
* address other than the one called, so a signature made here can only be
|
|
207
|
+
* spent at that address. The caller decides what to do with the certificate.
|
|
208
|
+
*/
|
|
209
|
+
async function obtainCertificate(node, deps = exports.defaultPorClientDeps) {
|
|
210
|
+
const url = deps.functionUrl();
|
|
211
|
+
const { jwt, userId } = await deps.session();
|
|
212
|
+
const challenge = await callFunction(deps, url, "challenge", jwt, {});
|
|
213
|
+
const { aud, nonce, challengeExp } = challenge;
|
|
214
|
+
if (typeof aud !== "string" || typeof nonce !== "string" || !isWholeNumber(challengeExp)) {
|
|
215
|
+
throw new PorError("POR_BAD_RESPONSE");
|
|
216
|
+
}
|
|
217
|
+
if (aud !== url)
|
|
218
|
+
throw new PorError("POR_AUD_MISMATCH", `Expected aud: ${printable(url)}. Actual aud: ${printable(aud)}.`);
|
|
219
|
+
let answer;
|
|
220
|
+
try {
|
|
221
|
+
answer = node.signPorChallenge(aud, userId, nonce, challengeExp);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
// The native side refused the fields, and only the service supplied those
|
|
225
|
+
// or, for the user id, the sign-in. Its message is not shown.
|
|
226
|
+
throw new PorError("POR_BAD_RESPONSE");
|
|
227
|
+
}
|
|
228
|
+
const issued = await callFunction(deps, url, "issue", jwt, {
|
|
229
|
+
publicKey: answer.publicKey,
|
|
230
|
+
signature: answer.signature,
|
|
231
|
+
nonce,
|
|
232
|
+
challengeExp,
|
|
233
|
+
});
|
|
234
|
+
const { token, peerId, iat, exp } = issued;
|
|
235
|
+
if (typeof token !== "string" ||
|
|
236
|
+
peerId !== node.peerId() ||
|
|
237
|
+
!isWholeNumber(iat) ||
|
|
238
|
+
!isWholeNumber(exp) ||
|
|
239
|
+
exp <= iat ||
|
|
240
|
+
exp - iat > exports.POR_LIFETIME_S) {
|
|
241
|
+
throw new PorError("POR_BAD_RESPONSE");
|
|
242
|
+
}
|
|
243
|
+
return { token, peerId, iat, exp };
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=por-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"por-client.js","sourceRoot":"","sources":["../../src/utils/por-client.ts"],"names":[],"mappings":";;;AAyHA,gCAEC;AAGD,8CAUC;AAOD,wCAWC;AAiBD,wCAKC;AASD,oCAGC;AA2DD,8CAyCC;AAhSD;;;;;;;;;GASG;AACH,qCAAqC;AACrC,yCAAiC;AACjC,8CAAyE;AACzE,kDAAqD;AACrD,gDAAqD;AAGrD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,gCAAgC,CAA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AC,CAAC;IACnE,CAAC;IAAC,MAAM,CAAC;QACP,0EAA0E;QAC1E,8DAA8D;QAC9D,MAAM,IAAI,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE;QACzD,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK;QACL,YAAY;KACb,CAAC,CAAC;IACH,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAC3C,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE;QACxB,CAAC,aAAa,CAAC,GAAG,CAAC;QACnB,CAAC,aAAa,CAAC,GAAG,CAAC;QACnB,GAAG,IAAI,GAAG;QACV,GAAG,GAAG,GAAG,GAAG,sBAAc,EAC1B,CAAC;QACD,MAAM,IAAI,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type PorCapableNode, type PorCertificate, type PorErrorCode } from "./por-client.js";
|
|
2
|
+
export declare const RENEW_WHEN_REMAINING_S: number;
|
|
3
|
+
/** How often the daemon looks at the certificate. */
|
|
4
|
+
export declare const RENEW_CHECK_MS: number;
|
|
5
|
+
/** How long the daemon waits after a failed renewal; at most 48 tries before expiry. */
|
|
6
|
+
export declare const RENEW_RETRY_MS: number;
|
|
7
|
+
/** The one judgement of when a certificate should be renewed. */
|
|
8
|
+
export declare function isRenewalDue(expS: number, nowS: number): boolean;
|
|
9
|
+
export interface PorFailure {
|
|
10
|
+
code: PorErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
fix: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PorState {
|
|
15
|
+
peerId: string;
|
|
16
|
+
token: string;
|
|
17
|
+
iat: number;
|
|
18
|
+
exp: number;
|
|
19
|
+
lastRenewalAttemptAt: number | null;
|
|
20
|
+
lastRenewedAt: number | null;
|
|
21
|
+
lastFailure: PorFailure | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function porStatePath(rotiferHome: string): string;
|
|
24
|
+
export declare function readPorState(path: string): PorState | null;
|
|
25
|
+
export declare function writePorState(path: string, state: PorState): void;
|
|
26
|
+
export declare function removePorState(path: string): void;
|
|
27
|
+
/** State for a fresh certificate, recording when it was obtained. */
|
|
28
|
+
export declare function stateFor(cert: PorCertificate, nowMs: number): PorState;
|
|
29
|
+
/** `active`, `expired`, `key_changed` or `off`; each name means only that. */
|
|
30
|
+
export type PorStateName = "off" | "active" | "expired" | "key_changed";
|
|
31
|
+
/** What is safe to show or print: never the token. */
|
|
32
|
+
export interface PorView {
|
|
33
|
+
state: PorStateName;
|
|
34
|
+
/** The PeerId the certificate is for. */
|
|
35
|
+
peerId: string | null;
|
|
36
|
+
issuedAt: number | null;
|
|
37
|
+
expiresAt: number | null;
|
|
38
|
+
/** Seconds left; 0 once expired; null without a certificate. */
|
|
39
|
+
expiresInSeconds: number | null;
|
|
40
|
+
/** Whether a running daemon will renew this certificate. */
|
|
41
|
+
autoRenew: boolean;
|
|
42
|
+
lastRenewalAttemptAt: number | null;
|
|
43
|
+
lastRenewedAt: number | null;
|
|
44
|
+
lastFailure: PorFailure | null;
|
|
45
|
+
}
|
|
46
|
+
/** `nodePeerId` is null when no native node is at hand to compare with. */
|
|
47
|
+
export declare function viewOf(state: PorState | null, nodePeerId: string | null, nowS: number): PorView;
|
|
48
|
+
export interface PorKeeperDeps {
|
|
49
|
+
path: string;
|
|
50
|
+
node: PorCapableNode;
|
|
51
|
+
/** One full challenge round: the same one enabling uses. */
|
|
52
|
+
obtain: (node: PorCapableNode) => Promise<PorCertificate>;
|
|
53
|
+
/** Milliseconds since the epoch. */
|
|
54
|
+
now?: () => number;
|
|
55
|
+
log?: (line: string) => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Keeps a running node's certificate loaded and fresh. A failure is recorded
|
|
59
|
+
* where `status` shows it and tried again later; nothing it does can stop the
|
|
60
|
+
* node, and a failed renewal leaves the current certificate in use.
|
|
61
|
+
*/
|
|
62
|
+
export declare class PorKeeper {
|
|
63
|
+
private readonly deps;
|
|
64
|
+
private readonly now;
|
|
65
|
+
private readonly log;
|
|
66
|
+
private timer;
|
|
67
|
+
private isTicking;
|
|
68
|
+
private retryAfterMs;
|
|
69
|
+
private hasWarnedKeyChange;
|
|
70
|
+
constructor(deps: PorKeeperDeps);
|
|
71
|
+
start(): void;
|
|
72
|
+
stop(): void;
|
|
73
|
+
private nowS;
|
|
74
|
+
private setToken;
|
|
75
|
+
/** Apply what is on disk: after `start`, and when `attest` changed it. */
|
|
76
|
+
reload(): PorView;
|
|
77
|
+
view(): PorView;
|
|
78
|
+
/** Stop carrying a lapsed certificate, and renew one that is due. */
|
|
79
|
+
tick(): Promise<void>;
|
|
80
|
+
private renewIfDue;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=por-keeper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"por-keeper.d.ts","sourceRoot":"","sources":["../../src/utils/por-keeper.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAEzB,eAAO,MAAM,sBAAsB,QAAY,CAAC;AAChD,qDAAqD;AACrD,eAAO,MAAM,cAAc,QAAiB,CAAC;AAC7C,wFAAwF;AACxF,eAAO,MAAM,cAAc,QAAiB,CAAC;AAE7C,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO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