@celljs/ta-relay 4.20.0 → 4.22.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/esm/common/index.d.ts +2 -0
- package/esm/common/index.js +2 -0
- package/esm/common/relay-account-client.d.ts +4 -0
- package/esm/common/relay-account-client.js +13 -3
- package/esm/common/relay-account.d.ts +17 -2
- package/esm/common/relay-account.js +15 -6
- package/esm/common/relay-accounts.d.ts +2 -0
- package/esm/common/relay-accounts.js +16 -2
- package/esm/common/relay-group-invites.d.ts +6 -2
- package/esm/common/relay-group-invites.js +6 -5
- package/esm/common/relay-hub-charter.d.ts +78 -0
- package/esm/common/relay-hub-charter.js +152 -0
- package/esm/common/relay-hub-epochs.d.ts +43 -0
- package/esm/common/relay-hub-epochs.js +92 -0
- package/esm/common/relay-hub-util.d.ts +39 -7
- package/esm/common/relay-hub-util.js +46 -15
- package/esm/common/relay-hub.d.ts +13 -0
- package/esm/common/relay-hub.js +81 -18
- package/esm/common/relay-hubs-admins.d.ts +27 -0
- package/esm/common/relay-hubs-admins.js +91 -0
- package/esm/common/relay-hubs-connection.d.ts +19 -63
- package/esm/common/relay-hubs-connection.js +100 -87
- package/esm/common/relay-hubs-identity.d.ts +7 -1
- package/esm/common/relay-hubs-identity.js +28 -1
- package/esm/common/relay-hubs-live.d.ts +58 -0
- package/esm/common/relay-hubs-live.js +27 -0
- package/esm/common/relay-hubs-protocol.d.ts +10 -0
- package/esm/common/relay-hubs-util.d.ts +9 -0
- package/esm/common/relay-hubs-util.js +23 -1
- package/esm/common/relay-hubs.d.ts +15 -15
- package/esm/common/relay-hubs.js +76 -57
- package/esm/common/relay-protocol.d.ts +14 -3
- package/esm/common/relay-protocol.js +1 -1
- package/esm/common/relay-room-app.d.ts +106 -0
- package/esm/common/relay-room-app.js +171 -0
- package/esm/common/relay-room-chat.d.ts +6 -1
- package/esm/common/relay-room-chat.js +1 -0
- package/esm/guest/guest-i18n.d.ts +3 -0
- package/esm/guest/guest-i18n.js +12 -0
- package/esm/guest/guest-style.d.ts +1 -1
- package/esm/guest/guest-style.js +11 -0
- package/esm/guest/guest.js +76 -6
- package/esm/node/relay-server-accounts.d.ts +1 -1
- package/esm/node/relay-server-accounts.js +1 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/relay-account-client.d.ts +4 -0
- package/lib/common/relay-account-client.js +13 -3
- package/lib/common/relay-account.d.ts +17 -2
- package/lib/common/relay-account.js +15 -6
- package/lib/common/relay-accounts.d.ts +2 -0
- package/lib/common/relay-accounts.js +16 -2
- package/lib/common/relay-group-invites.d.ts +6 -2
- package/lib/common/relay-group-invites.js +6 -5
- package/lib/common/relay-hub-charter.d.ts +79 -0
- package/lib/common/relay-hub-charter.js +155 -0
- package/lib/common/relay-hub-epochs.d.ts +44 -0
- package/lib/common/relay-hub-epochs.js +95 -0
- package/lib/common/relay-hub-util.d.ts +39 -7
- package/lib/common/relay-hub-util.js +46 -15
- package/lib/common/relay-hub.d.ts +13 -0
- package/lib/common/relay-hub.js +81 -18
- package/lib/common/relay-hubs-admins.d.ts +28 -0
- package/lib/common/relay-hubs-admins.js +95 -0
- package/lib/common/relay-hubs-connection.d.ts +19 -63
- package/lib/common/relay-hubs-connection.js +106 -94
- package/lib/common/relay-hubs-identity.d.ts +7 -1
- package/lib/common/relay-hubs-identity.js +28 -1
- package/lib/common/relay-hubs-live.d.ts +59 -0
- package/lib/common/relay-hubs-live.js +31 -0
- package/lib/common/relay-hubs-protocol.d.ts +10 -0
- package/lib/common/relay-hubs-util.d.ts +9 -0
- package/lib/common/relay-hubs-util.js +23 -1
- package/lib/common/relay-hubs.d.ts +15 -15
- package/lib/common/relay-hubs.js +82 -63
- package/lib/common/relay-protocol.d.ts +14 -3
- package/lib/common/relay-protocol.js +1 -1
- package/lib/common/relay-room-app.d.ts +107 -0
- package/lib/common/relay-room-app.js +176 -0
- package/lib/common/relay-room-chat.d.ts +6 -1
- package/lib/common/relay-room-chat.js +1 -0
- package/lib/guest/guest-i18n.d.ts +3 -0
- package/lib/guest/guest-i18n.js +12 -0
- package/lib/guest/guest-style.d.ts +1 -1
- package/lib/guest/guest-style.js +11 -0
- package/lib/guest/guest.js +76 -6
- package/lib/node/relay-server-accounts.d.ts +1 -1
- package/lib/node/relay-server-accounts.js +1 -1
- package/package.json +3 -3
- package/viewer/join.html +17 -6
- package/viewer/room.html +26 -15
package/esm/common/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './relay-friends.js';
|
|
|
14
14
|
export * from './relay-group-invites.js';
|
|
15
15
|
export * from './relay-host-calls.js';
|
|
16
16
|
export * from './relay-hub.js';
|
|
17
|
+
export * from './relay-hub-charter.js';
|
|
17
18
|
export * from './relay-hub-util.js';
|
|
18
19
|
export * from './relay-hubs.js';
|
|
19
20
|
export * from './relay-hubs-protocol.js';
|
|
@@ -23,6 +24,7 @@ export * from './relay-info.js';
|
|
|
23
24
|
export * from './relay-pairing.js';
|
|
24
25
|
export * from './relay-protocol.js';
|
|
25
26
|
export * from './relay-room.js';
|
|
27
|
+
export * from './relay-room-app.js';
|
|
26
28
|
export * from './relay-room-chat.js';
|
|
27
29
|
export * from './relay-share.js';
|
|
28
30
|
export * from './relay-socket.js';
|
package/esm/common/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from './relay-friends.js';
|
|
|
14
14
|
export * from './relay-group-invites.js';
|
|
15
15
|
export * from './relay-host-calls.js';
|
|
16
16
|
export * from './relay-hub.js';
|
|
17
|
+
export * from './relay-hub-charter.js';
|
|
17
18
|
export * from './relay-hub-util.js';
|
|
18
19
|
export * from './relay-hubs.js';
|
|
19
20
|
export * from './relay-hubs-protocol.js';
|
|
@@ -23,6 +24,7 @@ export * from './relay-info.js';
|
|
|
23
24
|
export * from './relay-pairing.js';
|
|
24
25
|
export * from './relay-protocol.js';
|
|
25
26
|
export * from './relay-room.js';
|
|
27
|
+
export * from './relay-room-app.js';
|
|
26
28
|
export * from './relay-room-chat.js';
|
|
27
29
|
export * from './relay-share.js';
|
|
28
30
|
export * from './relay-socket.js';
|
|
@@ -133,6 +133,10 @@ export declare class AccountAgent {
|
|
|
133
133
|
approve(id: string): Promise<AccountView>;
|
|
134
134
|
/** Removes a device (one waiting that is not the user's, or one lost): every device drops it. */
|
|
135
135
|
remove(id: string): Promise<AccountView>;
|
|
136
|
+
/** A token of the account for a device the user brings in by hand (a computer whose code they scanned). */
|
|
137
|
+
invite(): Promise<{
|
|
138
|
+
token: string;
|
|
139
|
+
}>;
|
|
136
140
|
/** Leaves the account: removed from it, its token dropped. */
|
|
137
141
|
signOut(): Promise<void>;
|
|
138
142
|
}
|
|
@@ -125,7 +125,7 @@ export class AccountAgent {
|
|
|
125
125
|
/** A new device of `account`: its own keys, trusting itself alone. */
|
|
126
126
|
static async create(service, token, account, kind, name) {
|
|
127
127
|
const self = await RelayIdentityUtil.create(name);
|
|
128
|
-
return { service: service.replace(/\/+$/, ''), token, account, kind, self, circle: AccountCircle.alone(self), pairings: {} };
|
|
128
|
+
return { service: service.replace(/\/+$/, ''), token, account, kind, self, circle: AccountCircle.alone(self, kind), pairings: {} };
|
|
129
129
|
}
|
|
130
130
|
get state() {
|
|
131
131
|
return this.kept;
|
|
@@ -209,12 +209,14 @@ export class AccountAgent {
|
|
|
209
209
|
if (this.hooks.pair && this.hooks.paired) {
|
|
210
210
|
const paired = new Set(this.hooks.paired());
|
|
211
211
|
for (const id of paired) {
|
|
212
|
-
|
|
212
|
+
const device = trusted.find(one => one.id === id);
|
|
213
|
+
if (!ids.has(id) || (device && AccountCircle.cloud(this.kept.circle, device))) {
|
|
213
214
|
await ((_b = (_a = this.hooks).unpair) === null || _b === void 0 ? void 0 : _b.call(_a, id));
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
for (const device of trusted) {
|
|
217
|
-
|
|
218
|
+
// A Ta in the cloud gets no way into a computer: devices open it, it does not reach them.
|
|
219
|
+
if (!paired.has(device.id) && !AccountCircle.cloud(this.kept.circle, device)) {
|
|
218
220
|
const link = await this.hooks.pair(device);
|
|
219
221
|
await this.calls.send(await AccountCircle.seal(this.kept.self, device, 'pairing', { link }));
|
|
220
222
|
}
|
|
@@ -308,6 +310,10 @@ export class AccountAgent {
|
|
|
308
310
|
/** Lets a waiting device in: signs it, and sends it whom this device trusts. */
|
|
309
311
|
async approve(id) {
|
|
310
312
|
return this.guard(async () => {
|
|
313
|
+
if (this.kept.kind === 'cloud') {
|
|
314
|
+
// Not 403: that would sign this device out (guard).
|
|
315
|
+
throw new AccountCallError(409, 'A Ta in the cloud lets no device in.');
|
|
316
|
+
}
|
|
311
317
|
const roster = await this.calls.roster(this.kept.self.id);
|
|
312
318
|
const device = roster.devices.find(one => one.id === id);
|
|
313
319
|
if (!device || !AccountCircle.waiting(device)) {
|
|
@@ -326,6 +332,10 @@ export class AccountAgent {
|
|
|
326
332
|
return this.sync();
|
|
327
333
|
});
|
|
328
334
|
}
|
|
335
|
+
/** A token of the account for a device the user brings in by hand (a computer whose code they scanned). */
|
|
336
|
+
invite() {
|
|
337
|
+
return this.guard(() => this.calls.invite());
|
|
338
|
+
}
|
|
329
339
|
/** Leaves the account: removed from it, its token dropped. */
|
|
330
340
|
async signOut() {
|
|
331
341
|
const { self, account } = this.kept;
|
|
@@ -5,7 +5,11 @@ export declare const RELAY_ACCOUNT_PATH = "/v1/account/";
|
|
|
5
5
|
export declare const RELAY_ACCOUNT_MAX_DEVICES = 20;
|
|
6
6
|
/** A device seen within this is online: computers say they are there every minute. */
|
|
7
7
|
export declare const RELAY_ACCOUNT_ONLINE_MS: number;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `cloud`: a Ta in the cloud, in a sandbox of the gateway (docs/design/ta-me.md 2). The devices of the account open it,
|
|
10
|
+
* but it lets no device in and gets no way into a computer: whoever runs the gateway runs it.
|
|
11
|
+
*/
|
|
12
|
+
export type AccountDeviceKind = 'computer' | 'phone' | 'browser' | 'cloud';
|
|
9
13
|
export interface AccountName {
|
|
10
14
|
/** `github:<id>`, `iam:<user>`: the provider and who the user is there. */
|
|
11
15
|
id: string;
|
|
@@ -73,6 +77,13 @@ export interface AccountCalls {
|
|
|
73
77
|
send(mail: Omit<AccountMail, 'at'>): Promise<void>;
|
|
74
78
|
mail(to: string): Promise<AccountMail[]>;
|
|
75
79
|
signOut(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* A token of the account for another device the user brings in by hand (a computer whose code they scanned): it
|
|
82
|
+
* joins with it and waits to be let in, as any device signing in.
|
|
83
|
+
*/
|
|
84
|
+
invite(): Promise<{
|
|
85
|
+
token: string;
|
|
86
|
+
}>;
|
|
76
87
|
}
|
|
77
88
|
export type AccountCallName = keyof AccountCalls;
|
|
78
89
|
export declare const ACCOUNT_CALLS: readonly AccountCallName[];
|
|
@@ -96,9 +107,11 @@ export type AccountSignInPoll = {
|
|
|
96
107
|
};
|
|
97
108
|
/** What a device keeps of the devices it trusts (docs/design/ta-account.md 5). */
|
|
98
109
|
export interface AccountCircleState {
|
|
110
|
+
/** `kind` as it was let in with (signed): a Ta in the cloud lets no one in. None from a device of before. */
|
|
99
111
|
trusted: Record<string, {
|
|
100
112
|
sign: string;
|
|
101
113
|
box: string;
|
|
114
|
+
kind?: AccountDeviceKind;
|
|
102
115
|
}>;
|
|
103
116
|
/** Removed once: never trusted again, whatever the service says later. */
|
|
104
117
|
removed: string[];
|
|
@@ -115,7 +128,9 @@ export declare namespace AccountCircle {
|
|
|
115
128
|
/** Waiting for a device of the account to let it in. */
|
|
116
129
|
function waiting(device: AccountDevice): boolean;
|
|
117
130
|
/** A device trusting itself alone: the first one, or one not let in yet. */
|
|
118
|
-
function alone(self: Pick<AccountDevice, 'id' | 'sign' | 'box'
|
|
131
|
+
function alone(self: Pick<AccountDevice, 'id' | 'sign' | 'box'>, kind?: AccountDeviceKind): AccountCircleState;
|
|
132
|
+
/** A Ta in the cloud, as trusted: its kind as it was let in with, else as the service says. */
|
|
133
|
+
function cloud(state: AccountCircleState, device: Pick<AccountDevice, 'id' | 'kind'>): boolean;
|
|
119
134
|
/**
|
|
120
135
|
* Who to trust now: those trusted before and not removed, and those a trusted device let in with a good signature,
|
|
121
136
|
* until no more. A device the service adds without a signature of one of them is never trusted.
|
|
@@ -6,7 +6,7 @@ export const RELAY_ACCOUNT_PATH = '/v1/account/';
|
|
|
6
6
|
export const RELAY_ACCOUNT_MAX_DEVICES = 20;
|
|
7
7
|
/** A device seen within this is online: computers say they are there every minute. */
|
|
8
8
|
export const RELAY_ACCOUNT_ONLINE_MS = 3 * 60000;
|
|
9
|
-
export const ACCOUNT_CALLS = ['roster', 'join', 'endorse', 'remove', 'send', 'mail', 'signOut'];
|
|
9
|
+
export const ACCOUNT_CALLS = ['roster', 'join', 'endorse', 'remove', 'send', 'mail', 'signOut', 'invite'];
|
|
10
10
|
/** The trust of the devices of an account, kept by each device: the service holds keys, never says who to trust. */
|
|
11
11
|
export var AccountCircle;
|
|
12
12
|
(function (AccountCircle) {
|
|
@@ -37,10 +37,17 @@ export var AccountCircle;
|
|
|
37
37
|
}
|
|
38
38
|
AccountCircle.waiting = waiting;
|
|
39
39
|
/** A device trusting itself alone: the first one, or one not let in yet. */
|
|
40
|
-
function alone(self) {
|
|
41
|
-
return { trusted: { [self.id]: { sign: self.sign, box: self.box } }, removed: [] };
|
|
40
|
+
function alone(self, kind) {
|
|
41
|
+
return { trusted: { [self.id]: { sign: self.sign, box: self.box, ...(kind ? { kind } : {}) } }, removed: [] };
|
|
42
42
|
}
|
|
43
43
|
AccountCircle.alone = alone;
|
|
44
|
+
/** A Ta in the cloud, as trusted: its kind as it was let in with, else as the service says. */
|
|
45
|
+
function cloud(state, device) {
|
|
46
|
+
var _a;
|
|
47
|
+
var _b;
|
|
48
|
+
return ((_b = (_a = state.trusted[device.id]) === null || _a === void 0 ? void 0 : _a.kind) !== null && _b !== void 0 ? _b : device.kind) === 'cloud';
|
|
49
|
+
}
|
|
50
|
+
AccountCircle.cloud = cloud;
|
|
44
51
|
/**
|
|
45
52
|
* Who to trust now: those trusted before and not removed, and those a trusted device let in with a good signature,
|
|
46
53
|
* until no more. A device the service adds without a signature of one of them is never trusted.
|
|
@@ -61,11 +68,13 @@ export var AccountCircle;
|
|
|
61
68
|
for (let added = true; added;) {
|
|
62
69
|
added = false;
|
|
63
70
|
for (const device of roster.devices) {
|
|
64
|
-
|
|
71
|
+
const by = device.endorsement ? trusted[device.endorsement.by] : undefined;
|
|
72
|
+
// A Ta in the cloud lets no one in: the gateway it runs on could otherwise add devices to the account.
|
|
73
|
+
if (trusted[device.id] || removed.has(device.id) || !live(device) || !device.endorsement || !by || by.kind === 'cloud') {
|
|
65
74
|
continue;
|
|
66
75
|
}
|
|
67
|
-
if (await RelayIdentityUtil.verify(
|
|
68
|
-
trusted[device.id] = { sign: device.sign, box: device.box };
|
|
76
|
+
if (await RelayIdentityUtil.verify(by.sign, text(roster.account.id, device), device.endorsement.signature)) {
|
|
77
|
+
trusted[device.id] = { sign: device.sign, box: device.box, kind: device.kind };
|
|
69
78
|
added = true;
|
|
70
79
|
}
|
|
71
80
|
}
|
|
@@ -73,6 +73,8 @@ export interface RelayAccountsOptions {
|
|
|
73
73
|
* a provider says who signed in.
|
|
74
74
|
*/
|
|
75
75
|
authenticate?(token: string): Promise<AccountName | undefined>;
|
|
76
|
+
/** A gateway: a new token of its own sign-in for the account, for a device the user brings in (AccountCalls.invite). */
|
|
77
|
+
issue?(account: AccountName): Promise<string>;
|
|
76
78
|
maxDevices?: number;
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
@@ -13,7 +13,7 @@ const MAIL_MAX = 16 * 1024;
|
|
|
13
13
|
const TOKENS_MAX = 50;
|
|
14
14
|
const REMOVED_MAX = 100;
|
|
15
15
|
const SEEN_EVERY_MS = 30000;
|
|
16
|
-
const KINDS = new Set(['computer', 'phone', 'browser']);
|
|
16
|
+
const KINDS = new Set(['computer', 'phone', 'browser', 'cloud']);
|
|
17
17
|
const MAIL_KINDS = new Set(['circle', 'pairing', 'package']);
|
|
18
18
|
const TOPIC = /^[@\w./:-]{1,120}$/;
|
|
19
19
|
/**
|
|
@@ -350,13 +350,27 @@ export class RelayAccounts {
|
|
|
350
350
|
if (!account) {
|
|
351
351
|
throw new RelayAccountError(401, 'Sign in again.');
|
|
352
352
|
}
|
|
353
|
+
if (request.op === 'invite') {
|
|
354
|
+
if (!this.options.issue) {
|
|
355
|
+
throw new RelayAccountError(404, 'This service brings in no device by hand.');
|
|
356
|
+
}
|
|
357
|
+
return { token: await this.options.issue(account) };
|
|
358
|
+
}
|
|
353
359
|
return this.options.book(account.id).handle({ ...request, account });
|
|
354
360
|
}
|
|
355
361
|
const account = RelayAccounts.accountOf(token);
|
|
356
362
|
if (!account) {
|
|
357
363
|
throw new RelayAccountError(401, 'Sign in first.');
|
|
358
364
|
}
|
|
359
|
-
|
|
365
|
+
const hash = await RelayKeys.hash(token);
|
|
366
|
+
if (request.op === 'invite') {
|
|
367
|
+
// The caller's token checked by the book, then a token of the account of its own, which signs out alone.
|
|
368
|
+
const { account: name } = (await this.options.book(account).handle({ op: 'roster', args: [], hash }));
|
|
369
|
+
const invited = RelayAccounts.token(account);
|
|
370
|
+
await this.options.book(account).handle({ op: 'issue', account: name, hash: await RelayKeys.hash(invited) });
|
|
371
|
+
return { token: invited };
|
|
372
|
+
}
|
|
373
|
+
return this.options.book(account).handle({ ...request, hash });
|
|
360
374
|
}
|
|
361
375
|
}
|
|
362
376
|
/** The books of a `ta relay` or a gateway, in one process: the requests of one account one after another. */
|
|
@@ -7,6 +7,8 @@ export interface RelayGroupInvite {
|
|
|
7
7
|
/** The id of the room. */
|
|
8
8
|
room: string;
|
|
9
9
|
title: string;
|
|
10
|
+
/** The kind of the room, when not a group chat of the page (a chat of two, ta-rooms' `ta-direct`). */
|
|
11
|
+
kind?: string;
|
|
10
12
|
by: {
|
|
11
13
|
id: string;
|
|
12
14
|
name: string;
|
|
@@ -20,6 +22,8 @@ export interface RelayGroupRooms {
|
|
|
20
22
|
identity(): Promise<RelayIdentity>;
|
|
21
23
|
list(): RelayRoomInfo[];
|
|
22
24
|
record(room: string): RelayRoomRecord | undefined;
|
|
25
|
+
/** This Ta lets in and invites: the owner, or an admin. */
|
|
26
|
+
manages(room: string): boolean;
|
|
23
27
|
save(): void;
|
|
24
28
|
friends(): (RelayFriend & RelayPublicIdentity)[];
|
|
25
29
|
friendRoom(): Promise<RelayRoomInfo>;
|
|
@@ -50,9 +54,9 @@ export declare class RelayGroupInvites {
|
|
|
50
54
|
protected readonly rooms: RelayGroupRooms;
|
|
51
55
|
protected readonly store: RelayHubsStore;
|
|
52
56
|
constructor(rooms: RelayGroupRooms, store: RelayHubsStore);
|
|
53
|
-
/** Invites friends into a group chat
|
|
57
|
+
/** Invites friends into a group chat the user owns or is an admin of: how many were. */
|
|
54
58
|
invite(roomId: string, friendIds: readonly string[]): Promise<number>;
|
|
55
|
-
/** Whether an ask
|
|
59
|
+
/** Whether an ask (by an invitation of this Ta's) is of a friend it invited: let in at once. */
|
|
56
60
|
admits(record: RelayRoomRecord, ask: RelayPublicIdentity & {
|
|
57
61
|
guest?: boolean;
|
|
58
62
|
}): boolean;
|
|
@@ -17,11 +17,11 @@ export class RelayGroupInvites {
|
|
|
17
17
|
this.rooms = rooms;
|
|
18
18
|
this.store = store;
|
|
19
19
|
}
|
|
20
|
-
/** Invites friends into a group chat
|
|
20
|
+
/** Invites friends into a group chat the user owns or is an admin of: how many were. */
|
|
21
21
|
async invite(roomId, friendIds) {
|
|
22
22
|
var _a;
|
|
23
23
|
const record = this.rooms.record(roomId);
|
|
24
|
-
if (!
|
|
24
|
+
if (!record || !this.rooms.manages(roomId) || record.status !== 'member' || record.unlisted || record.kind === RELAY_FRIENDS_KIND) {
|
|
25
25
|
throw new Error('Only a group chat of your own takes friends.');
|
|
26
26
|
}
|
|
27
27
|
const ids = new Set(friendIds);
|
|
@@ -41,17 +41,17 @@ export class RelayGroupInvites {
|
|
|
41
41
|
await this.prune(mine.id, now);
|
|
42
42
|
for (const friend of friends) {
|
|
43
43
|
const key = await RelayKeys.aesKey(await RelayIdentityUtil.agree(identity, friend.box, friend.id, INFO));
|
|
44
|
-
const opened = { link, title: record.title, at: now, expiresAt };
|
|
44
|
+
const opened = { link, title: record.title, kind: record.kind, at: now, expiresAt };
|
|
45
45
|
const sealed = { d: await RelayKeys.seal(key, JSON.stringify(opened)), expiresAt };
|
|
46
46
|
await this.rooms.setState(mine.id, await RelayGroupInvites.keyOf(roomId, friend.id), sealed);
|
|
47
47
|
}
|
|
48
48
|
return friends.length;
|
|
49
49
|
}
|
|
50
|
-
/** Whether an ask
|
|
50
|
+
/** Whether an ask (by an invitation of this Ta's) is of a friend it invited: let in at once. */
|
|
51
51
|
admits(record, ask) {
|
|
52
52
|
var _a;
|
|
53
53
|
var _b;
|
|
54
|
-
return
|
|
54
|
+
return !ask.guest && ((_b = (_a = record.invited) === null || _a === void 0 ? void 0 : _a[ask.id]) !== null && _b !== void 0 ? _b : 0) > Date.now();
|
|
55
55
|
}
|
|
56
56
|
/** One invited is in: its invitation goes. */
|
|
57
57
|
async admitted(record, id) {
|
|
@@ -150,6 +150,7 @@ export class RelayGroupInvites {
|
|
|
150
150
|
found.push({
|
|
151
151
|
room: link.room,
|
|
152
152
|
title: String(opened.title || link.title).slice(0, 80),
|
|
153
|
+
...(typeof opened.kind === 'string' && opened.kind ? { kind: opened.kind.slice(0, 64) } : {}),
|
|
153
154
|
by: { id: owner.id, name: owner.name, ...(owner.look ? { look: owner.look } : {}) },
|
|
154
155
|
at: Number(opened.at) || now,
|
|
155
156
|
expiresAt: opened.expiresAt,
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type RelayHubKeys, type RelayHubMember, type RelayHubRosterBody } from './relay-hub-util.js';
|
|
2
|
+
import { type RelayIdentity, type RelayPublicIdentity } from './relay-identity.js';
|
|
3
|
+
/** An admin of a room as its owner names it: its member id in the room and the identity it is. */
|
|
4
|
+
export interface RelayHubAdmin {
|
|
5
|
+
member: string;
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The rules of a room, its owner's for all (docs/design/ta-link.md 8): `approve`, friends invited ask as anyone else;
|
|
10
|
+
* `guests` (RELAY_GUESTS_RULE), those asking from a browser come in without asking; the others are the packages' that
|
|
11
|
+
* read them (ta-rooms: `agents`, `doubles`, `tasks`), each false to forbid.
|
|
12
|
+
*/
|
|
13
|
+
export type RelayHubRules = Record<string, boolean>;
|
|
14
|
+
/** The rule that lets those asking from a browser in without asking (they only chat), as many an hour at most. */
|
|
15
|
+
export declare const RELAY_GUESTS_RULE = "guests";
|
|
16
|
+
export declare const RELAY_GUESTS_PER_HOUR = 30;
|
|
17
|
+
/** What the owner of a room signs for all: who its admins are, its rules, how many it lets in. `v` grows with each change. */
|
|
18
|
+
export interface RelayHubCharterBody {
|
|
19
|
+
room: string;
|
|
20
|
+
v: number;
|
|
21
|
+
admins: RelayHubAdmin[];
|
|
22
|
+
rules: RelayHubRules;
|
|
23
|
+
capacity?: number;
|
|
24
|
+
}
|
|
25
|
+
/** The charter as the roster carries it: `p` its JSON, `s` the owner's signature of it. */
|
|
26
|
+
export interface RelayHubCharter {
|
|
27
|
+
p: string;
|
|
28
|
+
s: string;
|
|
29
|
+
}
|
|
30
|
+
/** A roster opened: who signed it (the owner, or an admin of its charter) and the charter it carries. */
|
|
31
|
+
export interface RelayHubRosterOpened {
|
|
32
|
+
signer: string;
|
|
33
|
+
byAdmin: boolean;
|
|
34
|
+
body: RelayHubRosterBody;
|
|
35
|
+
charter?: RelayHubCharterBody;
|
|
36
|
+
}
|
|
37
|
+
/** Admins of a room at most. */
|
|
38
|
+
export declare const RELAY_HUB_MAX_ADMINS = 8;
|
|
39
|
+
/**
|
|
40
|
+
* The charter of a room (docs/design/ta-link.md 8): the owner names admins and sets rules, signed, carried in the
|
|
41
|
+
* roster; an admin signs a roster that changes members alone, which every member checks against the charter.
|
|
42
|
+
*/
|
|
43
|
+
export declare namespace RelayHubCharterUtil {
|
|
44
|
+
/** Rules as kept: names of letters, booleans, a few. */
|
|
45
|
+
function rules(input: unknown): RelayHubRules;
|
|
46
|
+
function seal(owner: RelayIdentity, body: RelayHubCharterBody): Promise<RelayHubCharter>;
|
|
47
|
+
/** Undefined unless signed by the owner, and of this room. */
|
|
48
|
+
function open(ownerSign: string, room: string, charter: unknown): Promise<RelayHubCharterBody | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* A roster, once it checks: signed by the owner of `owner` (whose entry it has), or by an admin its charter names,
|
|
51
|
+
* the entry of that admin of the identity named. Whether an admin may make such a change is the reader's to judge.
|
|
52
|
+
*/
|
|
53
|
+
function openRoster(keys: RelayHubKeys, sealed: string, owner: {
|
|
54
|
+
id: string;
|
|
55
|
+
sign: string;
|
|
56
|
+
}, room: string): Promise<RelayHubRosterOpened | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Whether a roster an admin signed only changes what an admin may: the charter no older than the one before, the
|
|
59
|
+
* owner and every admin still in, those who were members still the same identities.
|
|
60
|
+
*/
|
|
61
|
+
function adminMay(next: RelayHubRosterOpened, before: {
|
|
62
|
+
members: RelayHubMember[];
|
|
63
|
+
charter?: RelayHubCharterBody;
|
|
64
|
+
} | undefined): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The answer of an admin to an ask: as the owner's (RelayHubUtil.sealAnswer), with the owner's public identity
|
|
67
|
+
* and the charter naming the admin, which the one who asked checks against the owner of its link.
|
|
68
|
+
*/
|
|
69
|
+
function answerProof(head: RelayPublicIdentity, charter: RelayHubCharter): {
|
|
70
|
+
head: RelayPublicIdentity;
|
|
71
|
+
charter: RelayHubCharter;
|
|
72
|
+
};
|
|
73
|
+
/** The one who answered may: the owner of the link, or an admin its charter names (its identity checked). */
|
|
74
|
+
function answeredBy(signer: RelayPublicIdentity, ownerId: string, room: string, proof: {
|
|
75
|
+
head?: RelayPublicIdentity;
|
|
76
|
+
charter?: RelayHubCharter;
|
|
77
|
+
}): Promise<RelayPublicIdentity | undefined>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { RelayHubUtil } from './relay-hub-util.js';
|
|
2
|
+
import { RelayIdentityUtil, RelayKeys } from './relay-identity.js';
|
|
3
|
+
/** The rule that lets those asking from a browser in without asking (they only chat), as many an hour at most. */
|
|
4
|
+
export const RELAY_GUESTS_RULE = 'guests';
|
|
5
|
+
export const RELAY_GUESTS_PER_HOUR = 30;
|
|
6
|
+
/** Admins of a room at most. */
|
|
7
|
+
export const RELAY_HUB_MAX_ADMINS = 8;
|
|
8
|
+
const MAX_RULES = 16;
|
|
9
|
+
/**
|
|
10
|
+
* The charter of a room (docs/design/ta-link.md 8): the owner names admins and sets rules, signed, carried in the
|
|
11
|
+
* roster; an admin signs a roster that changes members alone, which every member checks against the charter.
|
|
12
|
+
*/
|
|
13
|
+
export var RelayHubCharterUtil;
|
|
14
|
+
(function (RelayHubCharterUtil) {
|
|
15
|
+
/** Rules as kept: names of letters, booleans, a few. */
|
|
16
|
+
function rules(input) {
|
|
17
|
+
if (!input || typeof input !== 'object') {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return Object.fromEntries(Object.entries(input)
|
|
21
|
+
.filter(([name, value]) => /^[a-z][a-zA-Z]{0,30}$/.test(name) && typeof value === 'boolean')
|
|
22
|
+
.slice(0, MAX_RULES));
|
|
23
|
+
}
|
|
24
|
+
RelayHubCharterUtil.rules = rules;
|
|
25
|
+
async function seal(owner, body) {
|
|
26
|
+
const p = JSON.stringify(body);
|
|
27
|
+
return { p, s: await RelayIdentityUtil.sign(owner, p) };
|
|
28
|
+
}
|
|
29
|
+
RelayHubCharterUtil.seal = seal;
|
|
30
|
+
/** Undefined unless signed by the owner, and of this room. */
|
|
31
|
+
async function open(ownerSign, room, charter) {
|
|
32
|
+
try {
|
|
33
|
+
const { p, s } = charter;
|
|
34
|
+
if (typeof p !== 'string' || typeof s !== 'string' || !(await RelayIdentityUtil.verify(ownerSign, p, s))) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const body = JSON.parse(p);
|
|
38
|
+
if (body.room !== room || !(Number(body.v) > 0) || !Array.isArray(body.admins)) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const capacity = Math.round(Number(body.capacity));
|
|
42
|
+
return {
|
|
43
|
+
room,
|
|
44
|
+
v: Number(body.v),
|
|
45
|
+
admins: body.admins
|
|
46
|
+
.filter(admin => admin && typeof admin.member === 'string' && typeof admin.id === 'string')
|
|
47
|
+
.slice(0, RELAY_HUB_MAX_ADMINS)
|
|
48
|
+
.map(admin => ({ member: admin.member, id: admin.id })),
|
|
49
|
+
rules: rules(body.rules),
|
|
50
|
+
...(capacity >= 2 ? { capacity } : {}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
catch (_a) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
RelayHubCharterUtil.open = open;
|
|
58
|
+
/**
|
|
59
|
+
* A roster, once it checks: signed by the owner of `owner` (whose entry it has), or by an admin its charter names,
|
|
60
|
+
* the entry of that admin of the identity named. Whether an admin may make such a change is the reader's to judge.
|
|
61
|
+
*/
|
|
62
|
+
async function openRoster(keys, sealed, owner, room) {
|
|
63
|
+
try {
|
|
64
|
+
const found = RelayHubUtil.keyFor(keys, sealed);
|
|
65
|
+
if (!found) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const envelope = JSON.parse(await RelayKeys.open(found.key, found.sealed));
|
|
69
|
+
const signed = JSON.parse(envelope.p);
|
|
70
|
+
if (!(signed === null || signed === void 0 ? void 0 : signed.b) || !Array.isArray(signed.b.members) || typeof signed.m !== 'string') {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
const members = signed.b.members.filter((member) => !!member && typeof member.member === 'string');
|
|
74
|
+
const head = members.find(member => member.owner && member.id === owner.id);
|
|
75
|
+
if (!head) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const charter = signed.b.charter ? await open(owner.sign, room, signed.b.charter) : undefined;
|
|
79
|
+
let key;
|
|
80
|
+
let byAdmin = false;
|
|
81
|
+
if (signed.m === head.member) {
|
|
82
|
+
key = owner.sign;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const named = charter === null || charter === void 0 ? void 0 : charter.admins.find(admin => admin.member === signed.m);
|
|
86
|
+
const entry = named && members.find(member => member.member === named.member && member.id === named.id && !member.owner && !member.guest);
|
|
87
|
+
if (entry && (await RelayIdentityUtil.check(entry))) {
|
|
88
|
+
key = entry.sign;
|
|
89
|
+
byAdmin = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!key || !(await RelayIdentityUtil.verify(key, envelope.p, envelope.s))) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
signer: signed.m,
|
|
97
|
+
byAdmin,
|
|
98
|
+
body: { v: Number(signed.b.v), members, ...(signed.b.charter ? { charter: signed.b.charter } : {}) },
|
|
99
|
+
...(charter ? { charter } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (_a) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
RelayHubCharterUtil.openRoster = openRoster;
|
|
107
|
+
/**
|
|
108
|
+
* Whether a roster an admin signed only changes what an admin may: the charter no older than the one before, the
|
|
109
|
+
* owner and every admin still in, those who were members still the same identities.
|
|
110
|
+
*/
|
|
111
|
+
function adminMay(next, before) {
|
|
112
|
+
const charter = next.charter;
|
|
113
|
+
if (!charter || ((before === null || before === void 0 ? void 0 : before.charter) && charter.v < before.charter.v)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const has = (member) => next.body.members.some(each => each.member === member);
|
|
117
|
+
if (!charter.admins.every(admin => has(admin.member))) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const head = before === null || before === void 0 ? void 0 : before.members.find(member => member.owner);
|
|
121
|
+
if (head && !next.body.members.some(member => member.member === head.member && member.owner && member.id === head.id)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return next.body.members.every(member => {
|
|
125
|
+
const was = before === null || before === void 0 ? void 0 : before.members.find(each => each.member === member.member);
|
|
126
|
+
return !was || (was.id === member.id && !!was.owner === !!member.owner);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
RelayHubCharterUtil.adminMay = adminMay;
|
|
130
|
+
/**
|
|
131
|
+
* The answer of an admin to an ask: as the owner's (RelayHubUtil.sealAnswer), with the owner's public identity
|
|
132
|
+
* and the charter naming the admin, which the one who asked checks against the owner of its link.
|
|
133
|
+
*/
|
|
134
|
+
function answerProof(head, charter) {
|
|
135
|
+
return { head: RelayIdentityUtil.publicOf(head), charter };
|
|
136
|
+
}
|
|
137
|
+
RelayHubCharterUtil.answerProof = answerProof;
|
|
138
|
+
/** The one who answered may: the owner of the link, or an admin its charter names (its identity checked). */
|
|
139
|
+
async function answeredBy(signer, ownerId, room, proof) {
|
|
140
|
+
if (signer.id === ownerId) {
|
|
141
|
+
return (await RelayIdentityUtil.check(signer)) ? signer : undefined;
|
|
142
|
+
}
|
|
143
|
+
const head = proof.head;
|
|
144
|
+
if (!head || head.id !== ownerId || !(await RelayIdentityUtil.check(head)) || !(await RelayIdentityUtil.check(signer))) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const charter = await open(head.sign, room, proof.charter);
|
|
148
|
+
return (charter === null || charter === void 0 ? void 0 : charter.admins.some(admin => admin.id === signer.id)) ? head : undefined;
|
|
149
|
+
}
|
|
150
|
+
RelayHubCharterUtil.answeredBy = answeredBy;
|
|
151
|
+
})(RelayHubCharterUtil || (RelayHubCharterUtil = {}));
|
|
152
|
+
//# sourceMappingURL=relay-hub-charter.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RelayHubRosterOpened } from './relay-hub-charter.js';
|
|
2
|
+
import { type RelayHubMember } from './relay-hub-util.js';
|
|
3
|
+
import { type RelayIdentity } from './relay-identity.js';
|
|
4
|
+
/** The epochs a Ta keeps the keys of, the latest: what was sealed in one before them is no longer read. */
|
|
5
|
+
export declare const RELAY_HUB_KEEP_EPOCHS = 8;
|
|
6
|
+
/**
|
|
7
|
+
* A new key for a room once a member is taken out or leaves (docs/design/ta-link.md 8.7). The one who writes the roster
|
|
8
|
+
* makes it and seals the keys of the latest epochs for each member left, alone (ECDH of the two, salted by the room and
|
|
9
|
+
* the epoch): `roster.k` beside the roster sealed with the new key. The one gone holds the keys of before, never this.
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace RelayHubEpochs {
|
|
12
|
+
/** The epochs kept: the latest RELAY_HUB_KEEP_EPOCHS. */
|
|
13
|
+
function kept(epochs: Record<string, string>): Record<string, string>;
|
|
14
|
+
/** The epoch a text of RelayHubUtil.sealIn is of. */
|
|
15
|
+
function epochOf(sealed: string): number;
|
|
16
|
+
function latest(epochs: Record<string, string> | undefined): number;
|
|
17
|
+
/** The epochs with one more, its key new. */
|
|
18
|
+
function next(epochs: Record<string, string> | undefined): Record<string, string>;
|
|
19
|
+
/**
|
|
20
|
+
* What each of `members` reads the keys by, sealed by `identity` as `sealer` (its member id):
|
|
21
|
+
* `<sealer>.<its box>.<sealed>` by member id, the one who opens it checking the sealer against the roster. `cache` keeps those made for this epoch, so that writing the roster again does not agree keys again.
|
|
22
|
+
*/
|
|
23
|
+
function seal(identity: RelayIdentity, sealer: string, room: string, epochs: Record<string, string>, members: readonly Pick<RelayHubMember, 'member' | 'box'>[], cache: Map<string, string>): Promise<Record<string, string>>;
|
|
24
|
+
/**
|
|
25
|
+
* The keys sealed for this Ta (`self`) in `k`, with who sealed them (its member id and box), to be checked against
|
|
26
|
+
* the roster they come with (`sealedBy`); undefined when none is for it, or it does not open.
|
|
27
|
+
*/
|
|
28
|
+
function open(identity: RelayIdentity, self: string, room: string, epoch: number, k: Record<string, string> | undefined): Promise<{
|
|
29
|
+
epochs: Record<string, string>;
|
|
30
|
+
sealer: {
|
|
31
|
+
member: string;
|
|
32
|
+
box: string;
|
|
33
|
+
};
|
|
34
|
+
} | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the one who sealed the keys of a new epoch may: it signed the roster they came with (the owner, or an admin
|
|
37
|
+
* its charter names), with the box the roster gives it. Anyone else, the relay among them, gives no key.
|
|
38
|
+
*/
|
|
39
|
+
function sealedBy(sealer: {
|
|
40
|
+
member: string;
|
|
41
|
+
box: string;
|
|
42
|
+
}, roster: RelayHubRosterOpened): boolean;
|
|
43
|
+
}
|