ftown-bridge 0.30.84 → 0.30.86
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/dist/direct-transport/loopback-server.d.ts +26 -4
- package/dist/direct-transport/loopback-server.js +112 -38
- package/dist/direct-transport/loopback-server.js.map +1 -1
- package/dist/ftown-cli.js +4 -1
- package/dist/ftown-cli.js.map +1 -1
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -1
- package/dist/local-api-server.d.ts +10 -0
- package/dist/local-api-server.js +73 -25
- package/dist/local-api-server.js.map +1 -1
- package/dist/workspace/authority.d.ts +21 -230
- package/dist/workspace/authority.js +86 -239
- package/dist/workspace/authority.js.map +1 -1
- package/dist/workspace/browser-application.d.ts +26 -0
- package/dist/workspace/browser-application.js +10 -0
- package/dist/workspace/browser-application.js.map +1 -0
- package/dist/workspace/browser-authority.d.ts +2 -0
- package/dist/workspace/browser-authority.js +49 -0
- package/dist/workspace/browser-authority.js.map +1 -0
- package/dist/workspace/browser-relay.d.ts +17 -0
- package/dist/workspace/browser-relay.js +222 -0
- package/dist/workspace/browser-relay.js.map +1 -0
- package/dist/workspace/browser-rtc.d.ts +29 -0
- package/dist/workspace/browser-rtc.js +247 -0
- package/dist/workspace/browser-rtc.js.map +1 -0
- package/dist/workspace/browser-session.d.ts +109 -0
- package/dist/workspace/browser-session.js +781 -0
- package/dist/workspace/browser-session.js.map +1 -0
- package/dist/workspace/cli.js +136 -9
- package/dist/workspace/cli.js.map +1 -1
- package/dist/workspace/cutover.d.ts +1 -0
- package/dist/workspace/cutover.js +4 -0
- package/dist/workspace/cutover.js.map +1 -1
- package/dist/workspace/device.d.ts +9 -4
- package/dist/workspace/device.js +46 -1
- package/dist/workspace/device.js.map +1 -1
- package/dist/workspace/enrollment.d.ts +25 -2
- package/dist/workspace/enrollment.js +144 -26
- package/dist/workspace/enrollment.js.map +1 -1
- package/dist/workspace/listener.d.ts +1 -1
- package/dist/workspace/listener.js +13 -5
- package/dist/workspace/listener.js.map +1 -1
- package/dist/workspace/local-dashboard-cli.d.ts +1 -0
- package/dist/workspace/local-dashboard-cli.js +109 -0
- package/dist/workspace/local-dashboard-cli.js.map +1 -0
- package/dist/workspace/native-client-bridge.js +8 -1
- package/dist/workspace/native-client-bridge.js.map +1 -1
- package/dist/workspace/native-client-cli.d.ts +3 -0
- package/dist/workspace/native-client-cli.js +15 -12
- package/dist/workspace/native-client-cli.js.map +1 -1
- package/dist/workspace/pq/bytes.d.ts +15 -0
- package/dist/workspace/pq/bytes.js +80 -0
- package/dist/workspace/pq/bytes.js.map +1 -0
- package/dist/workspace/pq/carrier.d.ts +24 -0
- package/dist/workspace/pq/carrier.js +70 -0
- package/dist/workspace/pq/carrier.js.map +1 -0
- package/dist/workspace/pq/ledger-core.d.ts +597 -0
- package/dist/workspace/pq/ledger-core.js +524 -0
- package/dist/workspace/pq/ledger-core.js.map +1 -0
- package/dist/workspace/pq/pairing-link.d.ts +15 -0
- package/dist/workspace/pq/pairing-link.js +88 -0
- package/dist/workspace/pq/pairing-link.js.map +1 -0
- package/dist/workspace/pq/relay-client.d.ts +76 -0
- package/dist/workspace/pq/relay-client.js +307 -0
- package/dist/workspace/pq/relay-client.js.map +1 -0
- package/dist/workspace/pq/relay-identity.d.ts +7 -0
- package/dist/workspace/pq/relay-identity.js +6 -0
- package/dist/workspace/pq/relay-identity.js.map +1 -0
- package/dist/workspace/pq/relay-stream.d.ts +89 -0
- package/dist/workspace/pq/relay-stream.js +318 -0
- package/dist/workspace/pq/relay-stream.js.map +1 -0
- package/dist/workspace/pq/session-client.d.ts +103 -0
- package/dist/workspace/pq/session-client.js +607 -0
- package/dist/workspace/pq/session-client.js.map +1 -0
- package/dist/workspace/pq/session-protocol.d.ts +226 -0
- package/dist/workspace/pq/session-protocol.js +301 -0
- package/dist/workspace/pq/session-protocol.js.map +1 -0
- package/dist/workspace/rendezvous-client.js +1 -1
- package/dist/workspace/rendezvous-client.js.map +1 -1
- package/dist/workspace/rendezvous-wire.d.ts +33 -4
- package/dist/workspace/rendezvous-wire.js +77 -2
- package/dist/workspace/rendezvous-wire.js.map +1 -1
- package/dist/workspace/rendezvous.js +2 -1
- package/dist/workspace/rendezvous.js.map +1 -1
- package/dist/workspace/runtime.d.ts +4 -0
- package/dist/workspace/runtime.js +11 -1
- package/dist/workspace/runtime.js.map +1 -1
- package/dist/workspace/writer-only.d.ts +3 -1
- package/dist/workspace/writer-only.js +23 -0
- package/dist/workspace/writer-only.js.map +1 -1
- package/package.json +2 -2
- package/skills/ftown/SKILL.md +1 -1
|
@@ -1,233 +1,9 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { type PeerLanAddress } from '../peer-lan-address.js';
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
browser: "browser";
|
|
8
|
-
client: "client";
|
|
9
|
-
}>;
|
|
10
|
-
declare const policy: z.ZodEnum<{
|
|
11
|
-
strict: "strict";
|
|
12
|
-
standard: "standard";
|
|
13
|
-
}>;
|
|
14
|
-
export declare const workspaceMember: z.ZodObject<{
|
|
15
|
-
id: z.ZodString;
|
|
16
|
-
role: z.ZodEnum<{
|
|
17
|
-
bridge: "bridge";
|
|
18
|
-
browser: "browser";
|
|
19
|
-
client: "client";
|
|
20
|
-
}>;
|
|
21
|
-
approvedAt: z.ZodOptional<z.ZodNumber>;
|
|
22
|
-
label: z.ZodString;
|
|
23
|
-
publicKey: z.ZodString;
|
|
24
|
-
endpoint: z.ZodObject<{
|
|
25
|
-
version: z.ZodLiteral<1>;
|
|
26
|
-
id: z.ZodString;
|
|
27
|
-
ownerId: z.ZodString;
|
|
28
|
-
kind: z.ZodEnum<{
|
|
29
|
-
bridge: "bridge";
|
|
30
|
-
browser: "browser";
|
|
31
|
-
"local-cli": "local-cli";
|
|
32
|
-
}>;
|
|
33
|
-
publicKey: z.ZodString;
|
|
34
|
-
}, z.core.$strict>;
|
|
35
|
-
authPublicKey: z.ZodString;
|
|
36
|
-
bridgeId: z.ZodOptional<z.ZodString>;
|
|
37
|
-
certFingerprint: z.ZodOptional<z.ZodString>;
|
|
38
|
-
lan: z.ZodOptional<z.ZodObject<{
|
|
39
|
-
host: z.ZodString;
|
|
40
|
-
port: z.ZodNumber;
|
|
41
|
-
}, z.core.$strict>>;
|
|
42
|
-
browserGatewayOrigin: z.ZodOptional<z.ZodString>;
|
|
43
|
-
rendezvousEncryptionKey: z.ZodOptional<z.ZodString>;
|
|
44
|
-
rendezvousGrantDigest: z.ZodOptional<z.ZodString>;
|
|
45
|
-
credentialId: z.ZodOptional<z.ZodString>;
|
|
46
|
-
origin: z.ZodOptional<z.ZodString>;
|
|
47
|
-
rpId: z.ZodOptional<z.ZodString>;
|
|
48
|
-
}, z.core.$strict>;
|
|
49
|
-
export type WorkspaceMember = z.infer<typeof workspaceMember>;
|
|
50
|
-
export type WorkspacePolicy = z.infer<typeof policy>;
|
|
51
|
-
declare const operation: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
52
|
-
type: z.ZodLiteral<"add">;
|
|
53
|
-
member: z.ZodObject<{
|
|
54
|
-
id: z.ZodString;
|
|
55
|
-
role: z.ZodEnum<{
|
|
56
|
-
bridge: "bridge";
|
|
57
|
-
browser: "browser";
|
|
58
|
-
client: "client";
|
|
59
|
-
}>;
|
|
60
|
-
approvedAt: z.ZodOptional<z.ZodNumber>;
|
|
61
|
-
label: z.ZodString;
|
|
62
|
-
publicKey: z.ZodString;
|
|
63
|
-
endpoint: z.ZodObject<{
|
|
64
|
-
version: z.ZodLiteral<1>;
|
|
65
|
-
id: z.ZodString;
|
|
66
|
-
ownerId: z.ZodString;
|
|
67
|
-
kind: z.ZodEnum<{
|
|
68
|
-
bridge: "bridge";
|
|
69
|
-
browser: "browser";
|
|
70
|
-
"local-cli": "local-cli";
|
|
71
|
-
}>;
|
|
72
|
-
publicKey: z.ZodString;
|
|
73
|
-
}, z.core.$strict>;
|
|
74
|
-
authPublicKey: z.ZodString;
|
|
75
|
-
bridgeId: z.ZodOptional<z.ZodString>;
|
|
76
|
-
certFingerprint: z.ZodOptional<z.ZodString>;
|
|
77
|
-
lan: z.ZodOptional<z.ZodObject<{
|
|
78
|
-
host: z.ZodString;
|
|
79
|
-
port: z.ZodNumber;
|
|
80
|
-
}, z.core.$strict>>;
|
|
81
|
-
browserGatewayOrigin: z.ZodOptional<z.ZodString>;
|
|
82
|
-
rendezvousEncryptionKey: z.ZodOptional<z.ZodString>;
|
|
83
|
-
rendezvousGrantDigest: z.ZodOptional<z.ZodString>;
|
|
84
|
-
credentialId: z.ZodOptional<z.ZodString>;
|
|
85
|
-
origin: z.ZodOptional<z.ZodString>;
|
|
86
|
-
rpId: z.ZodOptional<z.ZodString>;
|
|
87
|
-
}, z.core.$strict>;
|
|
88
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
89
|
-
type: z.ZodLiteral<"revoke">;
|
|
90
|
-
id: z.ZodString;
|
|
91
|
-
}, z.core.$strict>], "type">;
|
|
92
|
-
declare const bundleSchema: z.ZodObject<{
|
|
93
|
-
rootPublicKey: z.ZodString;
|
|
94
|
-
delegation: z.ZodObject<{
|
|
95
|
-
body: z.ZodObject<{
|
|
96
|
-
version: z.ZodLiteral<3>;
|
|
97
|
-
type: z.ZodLiteral<"writer">;
|
|
98
|
-
workspaceId: z.ZodString;
|
|
99
|
-
generation: z.ZodNumber;
|
|
100
|
-
writerId: z.ZodString;
|
|
101
|
-
writerPublicKey: z.ZodString;
|
|
102
|
-
policy: z.ZodEnum<{
|
|
103
|
-
strict: "strict";
|
|
104
|
-
standard: "standard";
|
|
105
|
-
}>;
|
|
106
|
-
members: z.ZodArray<z.ZodObject<{
|
|
107
|
-
id: z.ZodString;
|
|
108
|
-
role: z.ZodEnum<{
|
|
109
|
-
bridge: "bridge";
|
|
110
|
-
browser: "browser";
|
|
111
|
-
client: "client";
|
|
112
|
-
}>;
|
|
113
|
-
approvedAt: z.ZodOptional<z.ZodNumber>;
|
|
114
|
-
label: z.ZodString;
|
|
115
|
-
publicKey: z.ZodString;
|
|
116
|
-
endpoint: z.ZodObject<{
|
|
117
|
-
version: z.ZodLiteral<1>;
|
|
118
|
-
id: z.ZodString;
|
|
119
|
-
ownerId: z.ZodString;
|
|
120
|
-
kind: z.ZodEnum<{
|
|
121
|
-
bridge: "bridge";
|
|
122
|
-
browser: "browser";
|
|
123
|
-
"local-cli": "local-cli";
|
|
124
|
-
}>;
|
|
125
|
-
publicKey: z.ZodString;
|
|
126
|
-
}, z.core.$strict>;
|
|
127
|
-
authPublicKey: z.ZodString;
|
|
128
|
-
bridgeId: z.ZodOptional<z.ZodString>;
|
|
129
|
-
certFingerprint: z.ZodOptional<z.ZodString>;
|
|
130
|
-
lan: z.ZodOptional<z.ZodObject<{
|
|
131
|
-
host: z.ZodString;
|
|
132
|
-
port: z.ZodNumber;
|
|
133
|
-
}, z.core.$strict>>;
|
|
134
|
-
browserGatewayOrigin: z.ZodOptional<z.ZodString>;
|
|
135
|
-
rendezvousEncryptionKey: z.ZodOptional<z.ZodString>;
|
|
136
|
-
rendezvousGrantDigest: z.ZodOptional<z.ZodString>;
|
|
137
|
-
credentialId: z.ZodOptional<z.ZodString>;
|
|
138
|
-
origin: z.ZodOptional<z.ZodString>;
|
|
139
|
-
rpId: z.ZodOptional<z.ZodString>;
|
|
140
|
-
}, z.core.$strict>>;
|
|
141
|
-
revoked: z.ZodArray<z.ZodString>;
|
|
142
|
-
previous: z.ZodNullable<z.ZodObject<{
|
|
143
|
-
generation: z.ZodNumber;
|
|
144
|
-
revision: z.ZodNumber;
|
|
145
|
-
head: z.ZodString;
|
|
146
|
-
}, z.core.$strict>>;
|
|
147
|
-
rendezvousNamespace: z.ZodOptional<z.ZodString>;
|
|
148
|
-
}, z.core.$strict>;
|
|
149
|
-
signature: z.ZodString;
|
|
150
|
-
}, z.core.$strict>;
|
|
151
|
-
records: z.ZodArray<z.ZodObject<{
|
|
152
|
-
body: z.ZodObject<{
|
|
153
|
-
type: z.ZodLiteral<"membership">;
|
|
154
|
-
workspaceId: z.ZodString;
|
|
155
|
-
generation: z.ZodNumber;
|
|
156
|
-
revision: z.ZodNumber;
|
|
157
|
-
previous: z.ZodString;
|
|
158
|
-
op: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
159
|
-
type: z.ZodLiteral<"add">;
|
|
160
|
-
member: z.ZodObject<{
|
|
161
|
-
id: z.ZodString;
|
|
162
|
-
role: z.ZodEnum<{
|
|
163
|
-
bridge: "bridge";
|
|
164
|
-
browser: "browser";
|
|
165
|
-
client: "client";
|
|
166
|
-
}>;
|
|
167
|
-
approvedAt: z.ZodOptional<z.ZodNumber>;
|
|
168
|
-
label: z.ZodString;
|
|
169
|
-
publicKey: z.ZodString;
|
|
170
|
-
endpoint: z.ZodObject<{
|
|
171
|
-
version: z.ZodLiteral<1>;
|
|
172
|
-
id: z.ZodString;
|
|
173
|
-
ownerId: z.ZodString;
|
|
174
|
-
kind: z.ZodEnum<{
|
|
175
|
-
bridge: "bridge";
|
|
176
|
-
browser: "browser";
|
|
177
|
-
"local-cli": "local-cli";
|
|
178
|
-
}>;
|
|
179
|
-
publicKey: z.ZodString;
|
|
180
|
-
}, z.core.$strict>;
|
|
181
|
-
authPublicKey: z.ZodString;
|
|
182
|
-
bridgeId: z.ZodOptional<z.ZodString>;
|
|
183
|
-
certFingerprint: z.ZodOptional<z.ZodString>;
|
|
184
|
-
lan: z.ZodOptional<z.ZodObject<{
|
|
185
|
-
host: z.ZodString;
|
|
186
|
-
port: z.ZodNumber;
|
|
187
|
-
}, z.core.$strict>>;
|
|
188
|
-
browserGatewayOrigin: z.ZodOptional<z.ZodString>;
|
|
189
|
-
rendezvousEncryptionKey: z.ZodOptional<z.ZodString>;
|
|
190
|
-
rendezvousGrantDigest: z.ZodOptional<z.ZodString>;
|
|
191
|
-
credentialId: z.ZodOptional<z.ZodString>;
|
|
192
|
-
origin: z.ZodOptional<z.ZodString>;
|
|
193
|
-
rpId: z.ZodOptional<z.ZodString>;
|
|
194
|
-
}, z.core.$strict>;
|
|
195
|
-
}, z.core.$strict>, z.ZodObject<{
|
|
196
|
-
type: z.ZodLiteral<"revoke">;
|
|
197
|
-
id: z.ZodString;
|
|
198
|
-
}, z.core.$strict>], "type">;
|
|
199
|
-
}, z.core.$strict>;
|
|
200
|
-
signature: z.ZodString;
|
|
201
|
-
}, z.core.$strict>>;
|
|
202
|
-
lease: z.ZodObject<{
|
|
203
|
-
body: z.ZodObject<{
|
|
204
|
-
type: z.ZodLiteral<"lease">;
|
|
205
|
-
workspaceId: z.ZodString;
|
|
206
|
-
generation: z.ZodNumber;
|
|
207
|
-
revision: z.ZodNumber;
|
|
208
|
-
head: z.ZodString;
|
|
209
|
-
issuedAt: z.ZodNumber;
|
|
210
|
-
expiresAt: z.ZodNumber;
|
|
211
|
-
order: z.ZodOptional<z.ZodNumber>;
|
|
212
|
-
}, z.core.$strict>;
|
|
213
|
-
signature: z.ZodString;
|
|
214
|
-
}, z.core.$strict>;
|
|
215
|
-
}, z.core.$strict>;
|
|
216
|
-
export type WorkspaceBundle = z.infer<typeof bundleSchema>;
|
|
217
|
-
export interface WorkspaceSnapshot {
|
|
218
|
-
workspaceId: string;
|
|
219
|
-
generation: number;
|
|
220
|
-
revision: number;
|
|
221
|
-
head: string;
|
|
222
|
-
policy: WorkspacePolicy;
|
|
223
|
-
writerId: string;
|
|
224
|
-
leaseUntil: number;
|
|
225
|
-
leaseOrder?: number;
|
|
226
|
-
rendezvousNamespace?: string;
|
|
227
|
-
members: WorkspaceMember[];
|
|
228
|
-
revoked: string[];
|
|
229
|
-
}
|
|
230
|
-
export declare function canonical(value: unknown): string;
|
|
4
|
+
import { MAX_ROSTER_BYTES, canonical, operation, workspaceMember, workspaceRole, type AccountCredential, type BrowserDevices, type LedgerHooks, type WorkspaceBundle, type WorkspaceMember, type WorkspacePolicy, type WorkspaceSnapshot } from './pq/ledger-core.js';
|
|
5
|
+
export { MAX_ROSTER_BYTES, canonical, workspaceMember, workspaceRole };
|
|
6
|
+
export type { WorkspaceBundle, WorkspaceMember, WorkspacePolicy, WorkspaceSnapshot };
|
|
231
7
|
export declare function digest(bytes: Buffer | string): string;
|
|
232
8
|
export declare function challenge(domain: string, value: unknown): Buffer;
|
|
233
9
|
export declare function createSigningKey(): {
|
|
@@ -236,7 +12,9 @@ export declare function createSigningKey(): {
|
|
|
236
12
|
};
|
|
237
13
|
export declare function signPq(privatePem: string, bytes: Buffer): string;
|
|
238
14
|
export declare function verifyPq(publicKey: string, bytes: Buffer, signature: string): boolean;
|
|
239
|
-
|
|
15
|
+
/** OpenSSL parses every key and verifies every signature before a ledger rule can accept it. */
|
|
16
|
+
export declare const ledgerHooks: LedgerHooks;
|
|
17
|
+
export declare function validateMember(input: unknown, workspaceId: string, mode: WorkspacePolicy, browserDevices?: boolean): WorkspaceMember;
|
|
240
18
|
export declare function verifyWorkspaceState(value: unknown, expectedWorkspaceId: string): WorkspaceSnapshot;
|
|
241
19
|
export declare function leaseOrdering(state: {
|
|
242
20
|
leaseOrder?: number;
|
|
@@ -253,11 +31,25 @@ export declare function readWorkspace(dir: string): WorkspaceSnapshot | null;
|
|
|
253
31
|
export declare function requireWorkspaceMember(dir: string, id: string): WorkspaceMember;
|
|
254
32
|
export declare function append(db: DatabaseSync, op: z.infer<typeof operation>, expectedHead: string): WorkspaceSnapshot;
|
|
255
33
|
export declare function revokeWorkspaceMember(dir: string, id: string, expectedHead: string): WorkspaceSnapshot;
|
|
34
|
+
export declare function addAccountCredential(dir: string, account: string, credential: AccountCredential, expectedHead: string): WorkspaceSnapshot;
|
|
35
|
+
export declare function revokeAccountCredential(dir: string, account: string, credentialId: string, expectedHead: string): WorkspaceSnapshot;
|
|
36
|
+
/** The highest delegation version this build verifies. */
|
|
37
|
+
export declare const LEDGER_VERSION = 4;
|
|
38
|
+
export interface PeerLedgerVersion {
|
|
39
|
+
version: number;
|
|
40
|
+
at: number;
|
|
41
|
+
}
|
|
42
|
+
/** A local, unsigned observation of the ledger version an authenticated replica reported. */
|
|
43
|
+
export declare function recordPeerLedgerVersion(dir: string, memberId: string, version: unknown): void;
|
|
44
|
+
export declare function peerLedgerVersions(dir: string): Record<string, PeerLedgerVersion>;
|
|
256
45
|
export declare function importWorkspaceState(dir: string, value: unknown, expectedWorkspaceId?: string): WorkspaceSnapshot;
|
|
257
46
|
export declare function installWriter(dir: string, root: {
|
|
258
47
|
publicKey: string;
|
|
259
48
|
privateKey: string;
|
|
260
|
-
}, member: WorkspaceMember, mode: WorkspacePolicy, previous?: WorkspaceBundle, handoff?: WriterHandoff
|
|
49
|
+
}, member: WorkspaceMember, mode: WorkspacePolicy, previous?: WorkspaceBundle, handoff?: WriterHandoff, options?: {
|
|
50
|
+
browserDevices?: BrowserDevices;
|
|
51
|
+
reissue?: boolean;
|
|
52
|
+
}): WorkspaceSnapshot;
|
|
261
53
|
export interface WriterHandoff {
|
|
262
54
|
workspaceId: string;
|
|
263
55
|
generation: number;
|
|
@@ -271,4 +63,3 @@ export declare function prepareWorkspaceHandoff(dir: string, successor: string):
|
|
|
271
63
|
export declare function workspaceForkEvidence(dir: string, generation?: number): WorkspaceBundle[];
|
|
272
64
|
/** The enrollment connection supplies the reachable host; its port is from the signed member grant. */
|
|
273
65
|
export declare function workspacePeerBootstrap(dir: string, member: WorkspaceMember): PeerLanAddress | undefined;
|
|
274
|
-
export {};
|
|
@@ -7,117 +7,12 @@ import { join } from 'node:path';
|
|
|
7
7
|
import { DatabaseSync } from 'node:sqlite';
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { lanAddress } from '../peer-lan-address.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { rendezvousAuthority, rendezvousNamespace, signalId } from './rendezvous-wire.js';
|
|
10
|
+
import { rendezvousAuthority, rendezvousNamespace } from './rendezvous-wire.js';
|
|
11
|
+
import { MAX_ROSTER_BYTES, bundleSchema, canonical, omitsKnownRevocation, validateMember as validateLedgerMember, verifyWorkspaceState as verifyLedgerState, workspaceMember, workspaceRole, } from './pq/ledger-core.js';
|
|
13
12
|
const id = z.string().regex(/^[\w-]{43}$/);
|
|
14
|
-
const point = z.string().regex(/^[\w-]{87}$/);
|
|
15
|
-
const key = z
|
|
16
|
-
.string()
|
|
17
|
-
.min(80)
|
|
18
|
-
.max(6000)
|
|
19
|
-
.regex(/^[\w-]+$/);
|
|
20
|
-
const stamp = z.number().int().nonnegative().safe();
|
|
21
|
-
// The largest wire envelope is a signed writer handoff with one checkpoint.
|
|
22
|
-
export const MAX_ROSTER_BYTES = 32 * 1024 * 1024;
|
|
23
13
|
const MAX_CHECKPOINT_BYTES = MAX_ROSTER_BYTES - 64 * 1024;
|
|
24
|
-
export
|
|
25
|
-
const policy = z.enum(['strict', 'standard']);
|
|
26
|
-
export const workspaceMember = z.strictObject({
|
|
27
|
-
id,
|
|
28
|
-
role: workspaceRole,
|
|
29
|
-
approvedAt: stamp.max(8_640_000_000_000_000).optional(),
|
|
30
|
-
label: z.string().trim().min(1).max(120),
|
|
31
|
-
publicKey: key,
|
|
32
|
-
endpoint: endpointSchema,
|
|
33
|
-
authPublicKey: point,
|
|
34
|
-
bridgeId: z
|
|
35
|
-
.string()
|
|
36
|
-
.regex(/^[\w-]{1,200}$/)
|
|
37
|
-
.optional(),
|
|
38
|
-
certFingerprint: z
|
|
39
|
-
.string()
|
|
40
|
-
.regex(/^(?:[A-F0-9]{2}:){31}[A-F0-9]{2}$/)
|
|
41
|
-
.optional(),
|
|
42
|
-
lan: z
|
|
43
|
-
.strictObject({ host: z.string().min(1).max(253), port: z.number().int().min(1).max(65535) })
|
|
44
|
-
.optional(),
|
|
45
|
-
browserGatewayOrigin: z.string().refine(isWorkspaceGatewayOrigin).optional(),
|
|
46
|
-
rendezvousEncryptionKey: key.optional(),
|
|
47
|
-
rendezvousGrantDigest: id.optional(),
|
|
48
|
-
credentialId: z
|
|
49
|
-
.string()
|
|
50
|
-
.min(1)
|
|
51
|
-
.max(2048)
|
|
52
|
-
.regex(/^[\w-]+$/)
|
|
53
|
-
.optional(),
|
|
54
|
-
origin: z.string().max(500).optional(),
|
|
55
|
-
rpId: z.string().max(253).optional(),
|
|
56
|
-
});
|
|
57
|
-
const delegation = z.strictObject({
|
|
58
|
-
version: z.literal(3),
|
|
59
|
-
type: z.literal('writer'),
|
|
60
|
-
workspaceId: id,
|
|
61
|
-
generation: stamp,
|
|
62
|
-
writerId: id,
|
|
63
|
-
writerPublicKey: key,
|
|
64
|
-
policy,
|
|
65
|
-
members: z.array(workspaceMember).min(1).max(512),
|
|
66
|
-
revoked: z.array(id).max(10000),
|
|
67
|
-
previous: z.strictObject({ generation: stamp, revision: stamp, head: id }).nullable(),
|
|
68
|
-
rendezvousNamespace: id.optional(),
|
|
69
|
-
});
|
|
70
|
-
const operation = z.discriminatedUnion('type', [
|
|
71
|
-
z.strictObject({ type: z.literal('add'), member: workspaceMember }),
|
|
72
|
-
z.strictObject({ type: z.literal('revoke'), id }),
|
|
73
|
-
]);
|
|
74
|
-
const transition = z.strictObject({
|
|
75
|
-
type: z.literal('membership'),
|
|
76
|
-
workspaceId: id,
|
|
77
|
-
generation: stamp,
|
|
78
|
-
revision: stamp,
|
|
79
|
-
previous: id,
|
|
80
|
-
op: operation,
|
|
81
|
-
});
|
|
82
|
-
const lease = z.strictObject({
|
|
83
|
-
type: z.literal('lease'),
|
|
84
|
-
workspaceId: id,
|
|
85
|
-
generation: stamp,
|
|
86
|
-
revision: stamp,
|
|
87
|
-
head: id,
|
|
88
|
-
issuedAt: stamp,
|
|
89
|
-
expiresAt: stamp,
|
|
90
|
-
order: stamp.min(1).optional(),
|
|
91
|
-
});
|
|
92
|
-
const signed = (body) => z.strictObject({
|
|
93
|
-
body,
|
|
94
|
-
signature: z
|
|
95
|
-
.string()
|
|
96
|
-
.min(100)
|
|
97
|
-
.max(8200)
|
|
98
|
-
.regex(/^[\w-]+$/),
|
|
99
|
-
});
|
|
100
|
-
const bundleSchema = z.strictObject({
|
|
101
|
-
rootPublicKey: key,
|
|
102
|
-
delegation: signed(delegation),
|
|
103
|
-
records: z.array(signed(transition)).max(4096),
|
|
104
|
-
lease: signed(lease),
|
|
105
|
-
});
|
|
14
|
+
export { MAX_ROSTER_BYTES, canonical, workspaceMember, workspaceRole };
|
|
106
15
|
const DAY = 86_400_000;
|
|
107
|
-
export function canonical(value) {
|
|
108
|
-
if (value === null || typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean')
|
|
109
|
-
return JSON.stringify(value);
|
|
110
|
-
if (Array.isArray(value))
|
|
111
|
-
return '[' + value.map(canonical).join(',') + ']';
|
|
112
|
-
if (!value || typeof value !== 'object')
|
|
113
|
-
throw new Error('Invalid workspace record');
|
|
114
|
-
return ('{' +
|
|
115
|
-
Object.entries(value)
|
|
116
|
-
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
117
|
-
.map(([k, v]) => JSON.stringify(k) + ':' + canonical(v))
|
|
118
|
-
.join(',') +
|
|
119
|
-
'}');
|
|
120
|
-
}
|
|
121
16
|
export function digest(bytes) {
|
|
122
17
|
return createHash('sha256').update(bytes).digest('base64url');
|
|
123
18
|
}
|
|
@@ -187,133 +82,32 @@ export function verifyPq(publicKey, bytes, signature) {
|
|
|
187
82
|
function signedRecord(body, pem) {
|
|
188
83
|
return { body, signature: signPq(pem, challenge('record', body)) };
|
|
189
84
|
}
|
|
190
|
-
function
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
!point.safeParse(m.publicKey).success ||
|
|
214
|
-
m.authPublicKey !== m.publicKey ||
|
|
215
|
-
m.certFingerprint ||
|
|
216
|
-
m.bridgeId ||
|
|
217
|
-
m.lan ||
|
|
218
|
-
m.rendezvousEncryptionKey ||
|
|
219
|
-
m.rendezvousGrantDigest)
|
|
220
|
-
throw new Error('Standard browser credential required');
|
|
221
|
-
const origin = new URL(m.origin);
|
|
222
|
-
if (origin.origin !== m.origin || origin.protocol !== 'https:' || origin.hostname !== m.rpId)
|
|
223
|
-
throw new Error('Invalid WebAuthn relying party');
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
publicPq(m.publicKey);
|
|
227
|
-
if (m.rendezvousGrantDigest &&
|
|
228
|
-
(m.role !== 'bridge' || !m.rendezvousEncryptionKey || !signalId(m.rendezvousGrantDigest)))
|
|
229
|
-
throw new Error('Invalid workspace rendezvous grant');
|
|
230
|
-
if (m.rendezvousEncryptionKey) {
|
|
231
|
-
const kem = createPublicKey({
|
|
232
|
-
key: Buffer.from(m.rendezvousEncryptionKey, 'base64url'),
|
|
233
|
-
format: 'der',
|
|
234
|
-
type: 'spki',
|
|
235
|
-
});
|
|
236
|
-
const der = kem.export({ format: 'der', type: 'spki' });
|
|
237
|
-
if (der.length !== 1590 ||
|
|
238
|
-
der.subarray(0, 22).toString('hex') !== '30820632300b06096086480165030404030382062100' ||
|
|
239
|
-
der.toString('base64url') !== m.rendezvousEncryptionKey)
|
|
240
|
-
throw new Error('Invalid workspace rendezvous key');
|
|
241
|
-
}
|
|
242
|
-
if (!m.certFingerprint || (m.role === 'bridge') !== !!m.bridgeId || m.origin || m.credentialId || m.rpId)
|
|
243
|
-
throw new Error('Invalid native member');
|
|
244
|
-
}
|
|
245
|
-
return m;
|
|
246
|
-
}
|
|
247
|
-
function add(members, revoked, member) {
|
|
248
|
-
if (members.length >= 512 ||
|
|
249
|
-
revoked.includes(member.id) ||
|
|
250
|
-
members.some((m) => m.id === member.id ||
|
|
251
|
-
m.publicKey === member.publicKey ||
|
|
252
|
-
m.authPublicKey === member.authPublicKey ||
|
|
253
|
-
(!!m.bridgeId && m.bridgeId === member.bridgeId) ||
|
|
254
|
-
(!!m.certFingerprint && m.certFingerprint === member.certFingerprint)))
|
|
255
|
-
throw new Error('Workspace member already used or revoked');
|
|
256
|
-
members.push(member);
|
|
85
|
+
function kemPublicKey(value) {
|
|
86
|
+
const kem = createPublicKey({ key: Buffer.from(value, 'base64url'), format: 'der', type: 'spki' });
|
|
87
|
+
const der = kem.export({ format: 'der', type: 'spki' });
|
|
88
|
+
if (der.length !== 1590 ||
|
|
89
|
+
der.subarray(0, 22).toString('hex') !== '30820632300b06096086480165030404030382062100' ||
|
|
90
|
+
der.toString('base64url') !== value)
|
|
91
|
+
throw new Error('Invalid workspace rendezvous key');
|
|
92
|
+
}
|
|
93
|
+
/** OpenSSL parses every key and verifies every signature before a ledger rule can accept it. */
|
|
94
|
+
export const ledgerHooks = {
|
|
95
|
+
sha256: (bytes) => createHash('sha256').update(bytes).digest(),
|
|
96
|
+
signingKey: (spki) => {
|
|
97
|
+
publicPq(spki);
|
|
98
|
+
},
|
|
99
|
+
kemKey: kemPublicKey,
|
|
100
|
+
verify: (publicKey, message, signature) => {
|
|
101
|
+
if (!verifyPq(publicKey, Buffer.from(message), signature))
|
|
102
|
+
throw new Error('Invalid workspace signature');
|
|
103
|
+
},
|
|
104
|
+
now: () => Date.now(),
|
|
105
|
+
};
|
|
106
|
+
export function validateMember(input, workspaceId, mode, browserDevices = false) {
|
|
107
|
+
return validateLedgerMember(input, workspaceId, mode, ledgerHooks, { browserDevices });
|
|
257
108
|
}
|
|
258
109
|
export function verifyWorkspaceState(value, expectedWorkspaceId) {
|
|
259
|
-
|
|
260
|
-
const d = authenticate(b.delegation, b.rootPublicKey);
|
|
261
|
-
if (d.workspaceId !== expectedWorkspaceId ||
|
|
262
|
-
digest(Buffer.from(b.rootPublicKey, 'base64url')) !== expectedWorkspaceId ||
|
|
263
|
-
d.generation < 1 ||
|
|
264
|
-
(d.generation === 1) !== (d.previous === null) ||
|
|
265
|
-
(d.previous && d.previous.generation + 1 !== d.generation))
|
|
266
|
-
throw new Error('Invalid workspace trust anchor or generation');
|
|
267
|
-
publicPq(d.writerPublicKey);
|
|
268
|
-
const members = [];
|
|
269
|
-
const revoked = [...d.revoked];
|
|
270
|
-
for (const m of d.members)
|
|
271
|
-
add(members, revoked, validateMember(m, d.workspaceId, d.policy));
|
|
272
|
-
if (!members.some((m) => m.id === d.writerId && m.role === 'bridge'))
|
|
273
|
-
throw new Error('Unknown enrollment bridge');
|
|
274
|
-
let head = digest(canonical(d));
|
|
275
|
-
let revision = 0;
|
|
276
|
-
for (const record of b.records) {
|
|
277
|
-
const r = authenticate(record, d.writerPublicKey);
|
|
278
|
-
if (r.workspaceId !== d.workspaceId ||
|
|
279
|
-
r.generation !== d.generation ||
|
|
280
|
-
r.previous !== head ||
|
|
281
|
-
r.revision !== ++revision)
|
|
282
|
-
throw new Error('Invalid workspace ledger ancestry');
|
|
283
|
-
if (r.op.type === 'add')
|
|
284
|
-
add(members, revoked, validateMember(r.op.member, d.workspaceId, d.policy));
|
|
285
|
-
else {
|
|
286
|
-
const removed = r.op.id;
|
|
287
|
-
const index = members.findIndex((m) => m.id === removed);
|
|
288
|
-
if (index < 0 || removed === d.writerId)
|
|
289
|
-
throw new Error('Invalid workspace revocation');
|
|
290
|
-
members.splice(index, 1);
|
|
291
|
-
revoked.push(removed);
|
|
292
|
-
}
|
|
293
|
-
head = digest(canonical(r));
|
|
294
|
-
}
|
|
295
|
-
const l = authenticate(b.lease, d.writerPublicKey);
|
|
296
|
-
if (l.workspaceId !== d.workspaceId ||
|
|
297
|
-
l.generation !== d.generation ||
|
|
298
|
-
l.head !== head ||
|
|
299
|
-
l.revision !== revision ||
|
|
300
|
-
l.issuedAt > Date.now() + 30_000 ||
|
|
301
|
-
l.expiresAt <= l.issuedAt ||
|
|
302
|
-
l.expiresAt - l.issuedAt > DAY)
|
|
303
|
-
throw new Error('Invalid workspace lease');
|
|
304
|
-
return {
|
|
305
|
-
workspaceId: d.workspaceId,
|
|
306
|
-
generation: d.generation,
|
|
307
|
-
revision,
|
|
308
|
-
head,
|
|
309
|
-
policy: d.policy,
|
|
310
|
-
writerId: d.writerId,
|
|
311
|
-
members,
|
|
312
|
-
revoked,
|
|
313
|
-
leaseUntil: l.expiresAt,
|
|
314
|
-
...(l.order !== undefined ? { leaseOrder: l.order } : {}),
|
|
315
|
-
...(d.rendezvousNamespace ? { rendezvousNamespace: d.rendezvousNamespace } : {}),
|
|
316
|
-
};
|
|
110
|
+
return verifyLedgerState(value, expectedWorkspaceId, ledgerHooks);
|
|
317
111
|
}
|
|
318
112
|
// Older checkpoints use the signed expiry as their broker revision. Start new counters
|
|
319
113
|
// above all legacy millisecond timestamps and keep the actual authorization deadline independent.
|
|
@@ -538,6 +332,34 @@ export function revokeWorkspaceMember(dir, id, expectedHead) {
|
|
|
538
332
|
return snapshot;
|
|
539
333
|
});
|
|
540
334
|
}
|
|
335
|
+
export function addAccountCredential(dir, account, credential, expectedHead) {
|
|
336
|
+
return transaction(dir, (db) => append(db, { type: 'account-credential', account, credential }, expectedHead));
|
|
337
|
+
}
|
|
338
|
+
export function revokeAccountCredential(dir, account, credentialId, expectedHead) {
|
|
339
|
+
return transaction(dir, (db) => append(db, { type: 'account-credential-revoke', account, credentialId }, expectedHead));
|
|
340
|
+
}
|
|
341
|
+
/** The highest delegation version this build verifies. */
|
|
342
|
+
export const LEDGER_VERSION = 4;
|
|
343
|
+
const HOUR = 3_600_000;
|
|
344
|
+
/** A local, unsigned observation of the ledger version an authenticated replica reported. */
|
|
345
|
+
export function recordPeerLedgerVersion(dir, memberId, version) {
|
|
346
|
+
if (!id.safeParse(memberId).success || !Number.isSafeInteger(version) || version < 1)
|
|
347
|
+
return;
|
|
348
|
+
transaction(dir, (db) => {
|
|
349
|
+
const versions = get(db, 'peerLedger') ?? {};
|
|
350
|
+
const prior = versions[memberId];
|
|
351
|
+
const now = Date.now();
|
|
352
|
+
if (prior && prior.version === version && prior.at > now - HOUR)
|
|
353
|
+
return;
|
|
354
|
+
versions[memberId] = { version: version, at: now };
|
|
355
|
+
put(db, 'peerLedger', versions);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
export function peerLedgerVersions(dir) {
|
|
359
|
+
if (!existsSync(dbPath(dir)))
|
|
360
|
+
return {};
|
|
361
|
+
return transaction(dir, (db) => get(db, 'peerLedger') ?? {});
|
|
362
|
+
}
|
|
541
363
|
export function importWorkspaceState(dir, value, expectedWorkspaceId) {
|
|
542
364
|
const b = bundleSchema.parse(value);
|
|
543
365
|
const outcome = transaction(dir, (db) => {
|
|
@@ -572,7 +394,7 @@ export function importWorkspaceState(dir, value, expectedWorkspaceId) {
|
|
|
572
394
|
}
|
|
573
395
|
}
|
|
574
396
|
else {
|
|
575
|
-
if (old
|
|
397
|
+
if (omitsKnownRevocation(old, next))
|
|
576
398
|
throw new Error('Recovery omitted known revocation');
|
|
577
399
|
put(db, 'writer', null);
|
|
578
400
|
put(db, 'quarantine', false);
|
|
@@ -587,7 +409,12 @@ export function importWorkspaceState(dir, value, expectedWorkspaceId) {
|
|
|
587
409
|
throw new Error('Conflicting workspace history quarantined');
|
|
588
410
|
return outcome;
|
|
589
411
|
}
|
|
590
|
-
export function installWriter(dir, root, member, mode, previous, handoff) {
|
|
412
|
+
export function installWriter(dir, root, member, mode, previous, handoff, options = {}) {
|
|
413
|
+
const { reissue = false } = options;
|
|
414
|
+
if (reissue && (!previous || handoff || !options.browserDevices))
|
|
415
|
+
throw new Error('Reissuing the writer delegation requires the current checkpoint');
|
|
416
|
+
if (previous && !reissue && options.browserDevices)
|
|
417
|
+
throw new Error('Authorize browser devices by reissuing the current writer delegation');
|
|
591
418
|
const writer = createSigningKey();
|
|
592
419
|
const workspaceId = digest(Buffer.from(root.publicKey, 'base64url'));
|
|
593
420
|
const old = previous ? verifyWorkspaceState(previous, workspaceId) : null;
|
|
@@ -616,6 +443,16 @@ export function installWriter(dir, root, member, mode, previous, handoff) {
|
|
|
616
443
|
(known.revision === old.revision && known.head !== old.head) ||
|
|
617
444
|
known.revoked.some((id) => !old.revoked.includes(id))))
|
|
618
445
|
throw new Error('Recovery checkpoint is stale or inconsistent');
|
|
446
|
+
const prior = previous?.delegation.body;
|
|
447
|
+
if (reissue) {
|
|
448
|
+
activeWriter(db);
|
|
449
|
+
if (!old || !known || !prior || known.revision !== old.revision || member.id !== old.writerId)
|
|
450
|
+
throw new Error('Only the current writer can reissue its delegation from the current checkpoint');
|
|
451
|
+
if (prior.version === 4 &&
|
|
452
|
+
(prior.browserDevices.origin !== options.browserDevices?.origin ||
|
|
453
|
+
prior.browserDevices.rpId !== options.browserDevices?.rpId))
|
|
454
|
+
throw new Error('Browser devices are already authorized for a different origin');
|
|
455
|
+
}
|
|
619
456
|
if (handoff) {
|
|
620
457
|
if (!old ||
|
|
621
458
|
!previous ||
|
|
@@ -631,7 +468,7 @@ export function installWriter(dir, root, member, mode, previous, handoff) {
|
|
|
631
468
|
if (old?.revoked.includes(member.id))
|
|
632
469
|
throw new Error('Cannot promote a revoked endpoint');
|
|
633
470
|
const checkpointRevocations = readGuard(db)?.revoked ?? [];
|
|
634
|
-
const revoked = handoff && old
|
|
471
|
+
const revoked = (handoff || reissue) && old
|
|
635
472
|
? [...new Set([...old.revoked, ...checkpointRevocations])]
|
|
636
473
|
: old
|
|
637
474
|
? [
|
|
@@ -642,7 +479,9 @@ export function installWriter(dir, root, member, mode, previous, handoff) {
|
|
|
642
479
|
]),
|
|
643
480
|
]
|
|
644
481
|
: [];
|
|
645
|
-
const
|
|
482
|
+
const inherited = prior?.version === 4 ? prior.browserDevices : undefined;
|
|
483
|
+
const browserDevices = reissue || !prior ? options.browserDevices : inherited;
|
|
484
|
+
const body = {
|
|
646
485
|
type: 'writer',
|
|
647
486
|
version: 3,
|
|
648
487
|
workspaceId,
|
|
@@ -651,10 +490,18 @@ export function installWriter(dir, root, member, mode, previous, handoff) {
|
|
|
651
490
|
writerPublicKey: writer.publicKey,
|
|
652
491
|
rendezvousNamespace: rendezvousNamespace(rendezvousAuthority(writer.privateKey, workspaceId)),
|
|
653
492
|
policy: mode,
|
|
654
|
-
members: handoff && old ? old.members : [{ ...member, approvedAt: Date.now() }],
|
|
493
|
+
members: (handoff || reissue) && old ? old.members : [{ ...member, approvedAt: Date.now() }],
|
|
655
494
|
revoked,
|
|
656
495
|
previous: old ? { generation: old.generation, revision: old.revision, head: old.head } : null,
|
|
657
|
-
}
|
|
496
|
+
};
|
|
497
|
+
const d = signedRecord(browserDevices
|
|
498
|
+
? {
|
|
499
|
+
...body,
|
|
500
|
+
version: 4,
|
|
501
|
+
browserDevices: { version: 1, origin: browserDevices.origin, rpId: browserDevices.rpId },
|
|
502
|
+
accounts: old?.accounts ?? [],
|
|
503
|
+
}
|
|
504
|
+
: body, root.privateKey);
|
|
658
505
|
const b = {
|
|
659
506
|
rootPublicKey: root.publicKey,
|
|
660
507
|
delegation: d,
|