@celljs/ta-relay 4.13.1 → 4.15.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/README.en.md +9 -1
- package/README.md +9 -1
- package/esm/common/index.d.ts +3 -0
- package/esm/common/index.js +3 -0
- package/esm/common/page-language.d.ts +14 -0
- package/esm/common/page-language.js +27 -0
- package/esm/common/relay-friends.js +29 -4
- package/esm/common/relay-host-calls.d.ts +34 -0
- package/esm/common/relay-host-calls.js +126 -0
- package/esm/common/relay-hubs-connection.d.ts +9 -1
- package/esm/common/relay-hubs-connection.js +33 -1
- package/esm/common/relay-hubs-protocol.d.ts +9 -1
- package/esm/common/relay-hubs.d.ts +7 -0
- package/esm/common/relay-hubs.js +20 -3
- package/esm/common/relay-identity.d.ts +11 -0
- package/esm/common/relay-identity.js +12 -1
- package/esm/common/relay-protocol.d.ts +1 -1
- package/esm/common/relay-protocol.js +2 -1
- package/esm/common/relay-team.d.ts +169 -0
- package/esm/common/relay-team.js +248 -0
- package/esm/common/relay-web.d.ts +13 -0
- package/esm/common/relay-web.js +61 -0
- package/esm/guest/guest-i18n.d.ts +6 -1
- package/esm/guest/guest-i18n.js +98 -5
- package/esm/guest/guest.js +1 -1
- package/esm/join/join-i18n.d.ts +65 -0
- package/esm/join/join-i18n.js +233 -0
- package/esm/join/join.d.ts +1 -0
- package/esm/join/join.js +433 -0
- package/esm/node/relay-server.d.ts +7 -0
- package/esm/node/relay-server.js +28 -3
- package/esm/node/relay-viewer.d.ts +2 -0
- package/esm/node/relay-viewer.js +9 -4
- package/esm/viewer/viewer-i18n.d.ts +6 -1
- package/esm/viewer/viewer-i18n.js +107 -3
- package/lib/common/index.d.ts +3 -0
- package/lib/common/index.js +3 -0
- package/lib/common/page-language.d.ts +15 -0
- package/lib/common/page-language.js +31 -0
- package/lib/common/relay-friends.js +29 -4
- package/lib/common/relay-host-calls.d.ts +35 -0
- package/lib/common/relay-host-calls.js +130 -0
- package/lib/common/relay-hubs-connection.d.ts +9 -1
- package/lib/common/relay-hubs-connection.js +33 -1
- package/lib/common/relay-hubs-protocol.d.ts +9 -1
- package/lib/common/relay-hubs.d.ts +7 -0
- package/lib/common/relay-hubs.js +20 -3
- package/lib/common/relay-identity.d.ts +11 -0
- package/lib/common/relay-identity.js +12 -1
- package/lib/common/relay-protocol.d.ts +1 -1
- package/lib/common/relay-protocol.js +2 -1
- package/lib/common/relay-team.d.ts +170 -0
- package/lib/common/relay-team.js +252 -0
- package/lib/common/relay-web.d.ts +14 -0
- package/lib/common/relay-web.js +64 -0
- package/lib/guest/guest-i18n.d.ts +6 -1
- package/lib/guest/guest-i18n.js +99 -6
- package/lib/guest/guest.js +1 -1
- package/lib/join/join-i18n.d.ts +66 -0
- package/lib/join/join-i18n.js +236 -0
- package/lib/join/join.d.ts +2 -0
- package/lib/join/join.js +435 -0
- package/lib/node/relay-server.d.ts +7 -0
- package/lib/node/relay-server.js +27 -2
- package/lib/node/relay-viewer.d.ts +2 -0
- package/lib/node/relay-viewer.js +6 -1
- package/lib/viewer/viewer-i18n.d.ts +6 -1
- package/lib/viewer/viewer-i18n.js +108 -4
- package/package.json +4 -4
- package/viewer/join.html +93 -0
- package/viewer/page.html +9 -9
- package/viewer/room.html +10 -10
|
@@ -7,6 +7,11 @@ export interface RelayPublicIdentity {
|
|
|
7
7
|
sign: string;
|
|
8
8
|
/** ECDH P-256: what keys for it are agreed with. */
|
|
9
9
|
box: string;
|
|
10
|
+
/**
|
|
11
|
+
* The kind of dinosaur its double is (a species of Ta's page, `trex`): others draw this Ta as that double. None from a
|
|
12
|
+
* Ta of before, or a browser.
|
|
13
|
+
*/
|
|
14
|
+
look?: string;
|
|
10
15
|
}
|
|
11
16
|
/** A Ta's own identity, its private keys as JWK; in `identity.json` of the agent directory. */
|
|
12
17
|
export interface RelayIdentity extends RelayPublicIdentity {
|
|
@@ -37,6 +42,12 @@ export declare namespace RelayIdentityUtil {
|
|
|
37
42
|
/** Whether the keys are what the id says, and well formed. */
|
|
38
43
|
function check(identity: RelayPublicIdentity): Promise<boolean>;
|
|
39
44
|
function publicOf(identity: RelayPublicIdentity): RelayPublicIdentity;
|
|
45
|
+
/** Whether it is a look as a Ta gives it: a short word of letters, digits and dashes. */
|
|
46
|
+
function isLook(look: unknown): look is string;
|
|
47
|
+
/** `value` with `look`, or without any for one that is none. */
|
|
48
|
+
function withLook<T extends {
|
|
49
|
+
look?: string;
|
|
50
|
+
}>(value: T, look: unknown): T;
|
|
40
51
|
function sign(identity: RelayIdentity, text: string): Promise<string>;
|
|
41
52
|
/** False for a signature that is not of this text by this key, or not a signature at all. */
|
|
42
53
|
function verify(signPublic: string, text: string, signature: string): Promise<boolean>;
|
|
@@ -91,9 +91,20 @@ var RelayIdentityUtil;
|
|
|
91
91
|
}
|
|
92
92
|
RelayIdentityUtil.check = check;
|
|
93
93
|
function publicOf(identity) {
|
|
94
|
-
return { id: identity.id, name: identity.name, sign: identity.sign, box: identity.box };
|
|
94
|
+
return withLook({ id: identity.id, name: identity.name, sign: identity.sign, box: identity.box }, identity.look);
|
|
95
95
|
}
|
|
96
96
|
RelayIdentityUtil.publicOf = publicOf;
|
|
97
|
+
/** Whether it is a look as a Ta gives it: a short word of letters, digits and dashes. */
|
|
98
|
+
function isLook(look) {
|
|
99
|
+
return typeof look === 'string' && /^[a-z][a-z0-9-]{0,31}$/.test(look);
|
|
100
|
+
}
|
|
101
|
+
RelayIdentityUtil.isLook = isLook;
|
|
102
|
+
/** `value` with `look`, or without any for one that is none. */
|
|
103
|
+
function withLook(value, look) {
|
|
104
|
+
const { look: _, ...rest } = value;
|
|
105
|
+
return (isLook(look) ? { ...rest, look } : rest);
|
|
106
|
+
}
|
|
107
|
+
RelayIdentityUtil.withLook = withLook;
|
|
97
108
|
async function sign(identity, text) {
|
|
98
109
|
const key = await subtle().importKey('jwk', identity.signKey, SIGN, false, ['sign']);
|
|
99
110
|
return relay_bytes_1.RelayBytes.toBase64(new Uint8Array(await subtle().sign(SIGNATURE, key, encoder.encode(text))));
|
|
@@ -28,7 +28,7 @@ export declare const RELAY_FRAME_HEADER_CSP = "default-src 'none'; script-src 'u
|
|
|
28
28
|
/** Headers of the viewer and its frame: never framed elsewhere, never a referrer (the key is in the address). */
|
|
29
29
|
export declare const RELAY_VIEWER_HEADERS: {
|
|
30
30
|
readonly 'content-type': 'text/html; charset=utf-8';
|
|
31
|
-
readonly 'cache-control': 'no-cache';
|
|
31
|
+
readonly 'cache-control': 'no-cache, no-transform';
|
|
32
32
|
readonly 'referrer-policy': 'no-referrer';
|
|
33
33
|
readonly 'x-content-type-options': 'nosniff';
|
|
34
34
|
};
|
|
@@ -31,7 +31,8 @@ exports.RELAY_FRAME_HEADER_CSP = `${exports.RELAY_FRAME_CSP}; frame-ancestors 's
|
|
|
31
31
|
/** Headers of the viewer and its frame: never framed elsewhere, never a referrer (the key is in the address). */
|
|
32
32
|
exports.RELAY_VIEWER_HEADERS = {
|
|
33
33
|
'content-type': 'text/html; charset=utf-8',
|
|
34
|
-
|
|
34
|
+
// no-transform: a CDN in front (Cloudflare's analytics) puts no script of its own into a page that keeps keys.
|
|
35
|
+
'cache-control': 'no-cache, no-transform',
|
|
35
36
|
'referrer-policy': 'no-referrer',
|
|
36
37
|
'x-content-type-options': 'nosniff',
|
|
37
38
|
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { RelayHostCalls } from './relay-host-calls';
|
|
2
|
+
import { type RelayIdentity } from './relay-identity';
|
|
3
|
+
/** The path of a link that invites into a Ta, on its relay: `<relay>/j#…`; opened in a browser, the page that asks to come in. */
|
|
4
|
+
export declare const RELAY_JOIN_PATH = "/j";
|
|
5
|
+
/** Where the relay serves Ta's web page, for one let in from a browser (docs/design/ta-team.md 8.3): `/w/#pair=<pairing link>`. */
|
|
6
|
+
export declare const RELAY_WEB_PATH = "/w/";
|
|
7
|
+
/** The package that lets people into a Ta: its host answers `ask` and `wait` of a link. */
|
|
8
|
+
export declare const RELAY_TEAM_PACKAGE = "@celljs/ta-team";
|
|
9
|
+
/** A link that invites into a Ta: its device (on the relay), whose Ta, the name of the role it gives. */
|
|
10
|
+
export interface RelayTeamLink {
|
|
11
|
+
relay: string;
|
|
12
|
+
host: string;
|
|
13
|
+
device: string;
|
|
14
|
+
key: string;
|
|
15
|
+
owner: string;
|
|
16
|
+
role: string;
|
|
17
|
+
/** It shares something on its own: the name shown (`设计师`). */
|
|
18
|
+
what?: string;
|
|
19
|
+
/** The language of who made it (`zh-CN`): the page of the link speaks it, unless the browser asks Chinese or Japanese. */
|
|
20
|
+
language?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Where one asking from a browser comes from: the page of the relay (RELAY_JOIN_PATH), not the Ta app. */
|
|
23
|
+
export type RelayTeamVia = 'web';
|
|
24
|
+
/** The answer to asking to come in. */
|
|
25
|
+
export interface RelayTeamAnswer {
|
|
26
|
+
status: 'waiting' | 'accepted' | 'refused' | 'gone';
|
|
27
|
+
answer?: {
|
|
28
|
+
box: string;
|
|
29
|
+
sealed: string;
|
|
30
|
+
};
|
|
31
|
+
request?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Refused at once: `app`, the role is one taken in the Ta app alone (it manages members, and the Ta has no provider to
|
|
34
|
+
* sign in with); `account`, sign in with an account first (from a browser, for a role that manages members).
|
|
35
|
+
*/
|
|
36
|
+
reason?: 'app' | 'account';
|
|
37
|
+
}
|
|
38
|
+
/** How one asking by a link may say who they are (docs/design/ta-team.md 17). */
|
|
39
|
+
export interface RelayTeamWays {
|
|
40
|
+
/** The providers the Ta signs in with: GitHub, Google, WeChat, the operator's; `device`, by a code typed at it. */
|
|
41
|
+
providers: {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
device?: true;
|
|
45
|
+
}[];
|
|
46
|
+
/** They sign in first: the role manages members and they ask from a browser; otherwise signing in is theirs to choose. */
|
|
47
|
+
required: boolean;
|
|
48
|
+
/** The role manages members. */
|
|
49
|
+
manages?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A sign-in started: `url`, where the browser goes, to come back to the page of the link; `device`, a code to type at
|
|
53
|
+
* the provider's `uri` (GitHub's device flow), the Ta asking it whether it was ({@link RelayTeamJoining.typed}).
|
|
54
|
+
*/
|
|
55
|
+
export interface RelayTeamSignInStart {
|
|
56
|
+
state: string;
|
|
57
|
+
url?: string;
|
|
58
|
+
device?: {
|
|
59
|
+
code: string;
|
|
60
|
+
uri: string;
|
|
61
|
+
expiresAt: number;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Signed in with a provider: as it came back to the page of the link (the code goes to the Ta, which alone can use it),
|
|
66
|
+
* or in a browser for the Ta app, by the handoff id the app gave it (RelayTeamLinkUtil.signInFor), or by a code typed,
|
|
67
|
+
* by the state of its sign-in as the handoff.
|
|
68
|
+
*/
|
|
69
|
+
export type RelayTeamSignIn = {
|
|
70
|
+
state: string;
|
|
71
|
+
code: string;
|
|
72
|
+
} | {
|
|
73
|
+
handoff: string;
|
|
74
|
+
};
|
|
75
|
+
/** A sign-in the page of the link does in a browser for the Ta app (the fragment's `p` and `x`). */
|
|
76
|
+
export interface RelayTeamHandoff {
|
|
77
|
+
provider: string;
|
|
78
|
+
handoff: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* What lets one asking by a link in, sealed for them alone (docs/design/ta-team.md 8.1): the link's key is shared by all
|
|
82
|
+
* who have the link, so the device of the one let in is sealed with ECDH between a key of the moment of each side.
|
|
83
|
+
*/
|
|
84
|
+
export declare namespace RelayTeamSeal {
|
|
85
|
+
/** A pair of keys for one request: its public part goes with it. */
|
|
86
|
+
function keys(name: string): Promise<RelayIdentity>;
|
|
87
|
+
function seal(box: string, salt: string, text: string): Promise<{
|
|
88
|
+
box: string;
|
|
89
|
+
sealed: string;
|
|
90
|
+
}>;
|
|
91
|
+
/** Throws when it was not sealed for these keys. */
|
|
92
|
+
function open(keys: RelayIdentity, answer: {
|
|
93
|
+
box: string;
|
|
94
|
+
sealed: string;
|
|
95
|
+
}, salt: string): Promise<string>;
|
|
96
|
+
/** Whether a public key is one: what a request carries is checked before anything is sealed for it. */
|
|
97
|
+
function isKey(box: unknown): box is string;
|
|
98
|
+
}
|
|
99
|
+
/** A link that invites into a Ta: `<relay>/j#v=1&h=…&d=…&k=…&o=…&r=…`; all but the relay in the fragment, which is not sent to it. */
|
|
100
|
+
export declare namespace RelayTeamLinkUtil {
|
|
101
|
+
function format(link: RelayTeamLink): string;
|
|
102
|
+
/** Undefined for text that is not such a link. */
|
|
103
|
+
function parse(text: string): RelayTeamLink | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The page of a link that signs in with `provider` for the Ta app, in a browser (docs/design/ta-team.md 17): the app
|
|
106
|
+
* waits for the account under `handoff`, an id of its own; all of it in the fragment.
|
|
107
|
+
*/
|
|
108
|
+
function signInFor(link: RelayTeamLink, provider: string, handoff: string): string;
|
|
109
|
+
/** The sign-in for the Ta app a link of {@link signInFor} asks, if it does. */
|
|
110
|
+
function handoffOf(text: string): RelayTeamHandoff | undefined;
|
|
111
|
+
/** Ta's web page of the relay, signing in with a pairing link (in the fragment, which the relay is not sent). */
|
|
112
|
+
function web(relay: string, pairing: string): string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Asking to come into another Ta by its link (docs/design/ta-team.md 8.2, 8.3): a connection to it through the relay with
|
|
116
|
+
* the device of the link, which may only ask and wait for the answer; the device for the one let in comes sealed for a
|
|
117
|
+
* key of this request alone, then the page connects with it. The keys of a request may be kept (`keys`) to wait again
|
|
118
|
+
* after the page was opened again (`resume`).
|
|
119
|
+
*/
|
|
120
|
+
export declare class RelayTeamJoining {
|
|
121
|
+
protected readonly calls: RelayHostCalls;
|
|
122
|
+
protected own?: RelayIdentity;
|
|
123
|
+
protected closed: boolean;
|
|
124
|
+
constructor(link: RelayTeamLink);
|
|
125
|
+
/** The keys of the request asked. */
|
|
126
|
+
get keys(): RelayIdentity | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed.
|
|
129
|
+
* A Ta that cannot be reached throws, so that the page says so rather than hide the ways to sign in.
|
|
130
|
+
*/
|
|
131
|
+
ways(via?: RelayTeamVia): Promise<RelayTeamWays>;
|
|
132
|
+
/** A call the relay or the Ta did not answer: the Ta is off, or the connection was lost. */
|
|
133
|
+
static unreachable(failure: unknown): boolean;
|
|
134
|
+
/** Where the browser goes to sign in with a provider, and the state it comes back with to the page of the link; for the app, its handoff. */
|
|
135
|
+
signIn(provider: string, handoff?: string): Promise<RelayTeamSignInStart>;
|
|
136
|
+
/** The browser came back signed in for the Ta app: the Ta verifies the account and keeps it for the app. */
|
|
137
|
+
signedIn(state: string, code: string): Promise<{
|
|
138
|
+
account: {
|
|
139
|
+
id: string;
|
|
140
|
+
name?: string;
|
|
141
|
+
};
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Waits for the code of a sign-in (`device` of {@link signIn}) to be typed at the provider, asking again till it was
|
|
145
|
+
* (the account, kept by the Ta under the handoff of the sign-in, or its state), this stops or `until` passes. A call
|
|
146
|
+
* the relay or the Ta did not answer (a phone away while the code was typed) is asked again; one refused throws.
|
|
147
|
+
*/
|
|
148
|
+
typed(state: string, until?: number): Promise<{
|
|
149
|
+
id: string;
|
|
150
|
+
name?: string;
|
|
151
|
+
} | undefined>;
|
|
152
|
+
/**
|
|
153
|
+
* Waits for the browser to sign in for the app, asking again till it did (the account), this stops or `until`
|
|
154
|
+
* passes; a call that fails (the app was away while the browser was in front) is asked again.
|
|
155
|
+
*/
|
|
156
|
+
handedOff(handoff: string, until?: number): Promise<{
|
|
157
|
+
id: string;
|
|
158
|
+
name?: string;
|
|
159
|
+
} | undefined>;
|
|
160
|
+
/** Asks with a name (`via` a browser, maybe signed in): the answer, or that it waits. */
|
|
161
|
+
ask(name: string, via?: RelayTeamVia, signIn?: RelayTeamSignIn): Promise<RelayTeamAnswer>;
|
|
162
|
+
/** Goes on with a request asked before, with its keys. */
|
|
163
|
+
resume(keys: RelayIdentity): void;
|
|
164
|
+
/** Waits for the answer to a request, asking again till it comes or this stops. */
|
|
165
|
+
wait(request: string): Promise<RelayTeamAnswer>;
|
|
166
|
+
/** The pairing link of the device sealed in an answer. */
|
|
167
|
+
pairing(request: string, answer: NonNullable<RelayTeamAnswer['answer']>): Promise<string>;
|
|
168
|
+
close(): void;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=relay-team.d.ts.map
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayTeamJoining = exports.RelayTeamLinkUtil = exports.RelayTeamSeal = exports.RELAY_TEAM_PACKAGE = exports.RELAY_WEB_PATH = exports.RELAY_JOIN_PATH = void 0;
|
|
4
|
+
const relay_bytes_1 = require("./relay-bytes");
|
|
5
|
+
const relay_host_calls_1 = require("./relay-host-calls");
|
|
6
|
+
const relay_identity_1 = require("./relay-identity");
|
|
7
|
+
const relay_pairing_1 = require("./relay-pairing");
|
|
8
|
+
/** The path of a link that invites into a Ta, on its relay: `<relay>/j#…`; opened in a browser, the page that asks to come in. */
|
|
9
|
+
exports.RELAY_JOIN_PATH = '/j';
|
|
10
|
+
/** Where the relay serves Ta's web page, for one let in from a browser (docs/design/ta-team.md 8.3): `/w/#pair=<pairing link>`. */
|
|
11
|
+
exports.RELAY_WEB_PATH = '/w/';
|
|
12
|
+
/** The package that lets people into a Ta: its host answers `ask` and `wait` of a link. */
|
|
13
|
+
exports.RELAY_TEAM_PACKAGE = '@celljs/ta-team';
|
|
14
|
+
const SEAL_INFO = 'ta-team/1 device';
|
|
15
|
+
/**
|
|
16
|
+
* What lets one asking by a link in, sealed for them alone (docs/design/ta-team.md 8.1): the link's key is shared by all
|
|
17
|
+
* who have the link, so the device of the one let in is sealed with ECDH between a key of the moment of each side.
|
|
18
|
+
*/
|
|
19
|
+
var RelayTeamSeal;
|
|
20
|
+
(function (RelayTeamSeal) {
|
|
21
|
+
/** A pair of keys for one request: its public part goes with it. */
|
|
22
|
+
function keys(name) {
|
|
23
|
+
return relay_identity_1.RelayIdentityUtil.create(name);
|
|
24
|
+
}
|
|
25
|
+
RelayTeamSeal.keys = keys;
|
|
26
|
+
async function seal(box, salt, text) {
|
|
27
|
+
const own = await relay_identity_1.RelayIdentityUtil.create('ta');
|
|
28
|
+
const key = await relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayIdentityUtil.agree(own, box, salt, SEAL_INFO));
|
|
29
|
+
return { box: own.box, sealed: await relay_identity_1.RelayKeys.seal(key, text) };
|
|
30
|
+
}
|
|
31
|
+
RelayTeamSeal.seal = seal;
|
|
32
|
+
/** Throws when it was not sealed for these keys. */
|
|
33
|
+
async function open(keys, answer, salt) {
|
|
34
|
+
const key = await relay_identity_1.RelayKeys.aesKey(await relay_identity_1.RelayIdentityUtil.agree(keys, answer.box, salt, SEAL_INFO));
|
|
35
|
+
return relay_identity_1.RelayKeys.open(key, answer.sealed);
|
|
36
|
+
}
|
|
37
|
+
RelayTeamSeal.open = open;
|
|
38
|
+
/** Whether a public key is one: what a request carries is checked before anything is sealed for it. */
|
|
39
|
+
function isKey(box) {
|
|
40
|
+
return typeof box === 'string' && /^[A-Za-z0-9_-]{80,100}$/.test(box) && relay_bytes_1.RelayBytes.fromBase64(box).length === 65;
|
|
41
|
+
}
|
|
42
|
+
RelayTeamSeal.isKey = isKey;
|
|
43
|
+
})(RelayTeamSeal || (exports.RelayTeamSeal = RelayTeamSeal = {}));
|
|
44
|
+
/** A link that invites into a Ta: `<relay>/j#v=1&h=…&d=…&k=…&o=…&r=…`; all but the relay in the fragment, which is not sent to it. */
|
|
45
|
+
var RelayTeamLinkUtil;
|
|
46
|
+
(function (RelayTeamLinkUtil) {
|
|
47
|
+
const ID = /^[A-Za-z0-9_-]{16,64}$/;
|
|
48
|
+
function format(link) {
|
|
49
|
+
const fragment = new URLSearchParams({ v: '1', h: link.host, d: link.device, k: link.key, o: link.owner, r: link.role });
|
|
50
|
+
if (link.what) {
|
|
51
|
+
fragment.set('w', link.what);
|
|
52
|
+
}
|
|
53
|
+
if (link.language) {
|
|
54
|
+
fragment.set('l', link.language);
|
|
55
|
+
}
|
|
56
|
+
return `${link.relay.replace(/\/+$/, '')}${exports.RELAY_JOIN_PATH}#${fragment}`;
|
|
57
|
+
}
|
|
58
|
+
RelayTeamLinkUtil.format = format;
|
|
59
|
+
/** Undefined for text that is not such a link. */
|
|
60
|
+
function parse(text) {
|
|
61
|
+
var _a;
|
|
62
|
+
var _b, _c, _d;
|
|
63
|
+
let url;
|
|
64
|
+
try {
|
|
65
|
+
url = new URL(text.trim());
|
|
66
|
+
}
|
|
67
|
+
catch (_e) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
71
|
+
const [host, device, key] = ['h', 'd', 'k'].map(name => { var _a; return (_a = fragment.get(name)) !== null && _a !== void 0 ? _a : ''; });
|
|
72
|
+
if (!/^https?:$/.test(url.protocol) ||
|
|
73
|
+
url.pathname !== exports.RELAY_JOIN_PATH ||
|
|
74
|
+
fragment.get('v') !== '1' ||
|
|
75
|
+
!ID.test(host) ||
|
|
76
|
+
!ID.test(device) ||
|
|
77
|
+
!/^[A-Za-z0-9_-]{43}$/.test(key)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const what = (_a = fragment.get('w')) === null || _a === void 0 ? void 0 : _a.slice(0, 80);
|
|
81
|
+
const language = (_b = fragment.get('l')) !== null && _b !== void 0 ? _b : '';
|
|
82
|
+
return {
|
|
83
|
+
relay: url.origin,
|
|
84
|
+
host,
|
|
85
|
+
device,
|
|
86
|
+
key,
|
|
87
|
+
owner: (_c = fragment.get('o')) !== null && _c !== void 0 ? _c : '',
|
|
88
|
+
role: (_d = fragment.get('r')) !== null && _d !== void 0 ? _d : '',
|
|
89
|
+
...(what ? { what } : {}),
|
|
90
|
+
...(/^[a-z]{2}(-[A-Za-z]{2,4})?$/.test(language) ? { language } : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
RelayTeamLinkUtil.parse = parse;
|
|
94
|
+
/**
|
|
95
|
+
* The page of a link that signs in with `provider` for the Ta app, in a browser (docs/design/ta-team.md 17): the app
|
|
96
|
+
* waits for the account under `handoff`, an id of its own; all of it in the fragment.
|
|
97
|
+
*/
|
|
98
|
+
function signInFor(link, provider, handoff) {
|
|
99
|
+
return `${format(link)}&${new URLSearchParams({ p: provider, x: handoff })}`;
|
|
100
|
+
}
|
|
101
|
+
RelayTeamLinkUtil.signInFor = signInFor;
|
|
102
|
+
/** The sign-in for the Ta app a link of {@link signInFor} asks, if it does. */
|
|
103
|
+
function handoffOf(text) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
let url;
|
|
106
|
+
try {
|
|
107
|
+
url = new URL(text.trim());
|
|
108
|
+
}
|
|
109
|
+
catch (_c) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const fragment = new URLSearchParams(url.hash.slice(1));
|
|
113
|
+
const provider = (_a = fragment.get('p')) !== null && _a !== void 0 ? _a : '';
|
|
114
|
+
const handoff = (_b = fragment.get('x')) !== null && _b !== void 0 ? _b : '';
|
|
115
|
+
return /^[a-z0-9_-]{1,32}$/.test(provider) && /^[A-Za-z0-9_-]{16,64}$/.test(handoff) ? { provider, handoff } : undefined;
|
|
116
|
+
}
|
|
117
|
+
RelayTeamLinkUtil.handoffOf = handoffOf;
|
|
118
|
+
/** Ta's web page of the relay, signing in with a pairing link (in the fragment, which the relay is not sent). */
|
|
119
|
+
function web(relay, pairing) {
|
|
120
|
+
return `${relay.replace(/\/+$/, '')}${exports.RELAY_WEB_PATH}#${new URLSearchParams({ pair: pairing })}`;
|
|
121
|
+
}
|
|
122
|
+
RelayTeamLinkUtil.web = web;
|
|
123
|
+
})(RelayTeamLinkUtil || (exports.RelayTeamLinkUtil = RelayTeamLinkUtil = {}));
|
|
124
|
+
/**
|
|
125
|
+
* Asking to come into another Ta by its link (docs/design/ta-team.md 8.2, 8.3): a connection to it through the relay with
|
|
126
|
+
* the device of the link, which may only ask and wait for the answer; the device for the one let in comes sealed for a
|
|
127
|
+
* key of this request alone, then the page connects with it. The keys of a request may be kept (`keys`) to wait again
|
|
128
|
+
* after the page was opened again (`resume`).
|
|
129
|
+
*/
|
|
130
|
+
class RelayTeamJoining {
|
|
131
|
+
constructor(link) {
|
|
132
|
+
this.closed = false;
|
|
133
|
+
this.calls = new relay_host_calls_1.RelayHostCalls({ relay: link.relay, host: link.host, device: link.device, key: link.key, name: link.owner }, exports.RELAY_TEAM_PACKAGE);
|
|
134
|
+
}
|
|
135
|
+
/** The keys of the request asked. */
|
|
136
|
+
get keys() {
|
|
137
|
+
return this.own;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed.
|
|
141
|
+
* A Ta that cannot be reached throws, so that the page says so rather than hide the ways to sign in.
|
|
142
|
+
*/
|
|
143
|
+
async ways(via) {
|
|
144
|
+
try {
|
|
145
|
+
return (await this.calls.callHost('ways', via ? { via } : {}));
|
|
146
|
+
}
|
|
147
|
+
catch (failure) {
|
|
148
|
+
if (RelayTeamJoining.unreachable(failure)) {
|
|
149
|
+
throw failure;
|
|
150
|
+
}
|
|
151
|
+
return { providers: [], required: false };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** A call the relay or the Ta did not answer: the Ta is off, or the connection was lost. */
|
|
155
|
+
static unreachable(failure) {
|
|
156
|
+
return /did not answer|was lost/i.test(failure instanceof Error ? failure.message : String(failure));
|
|
157
|
+
}
|
|
158
|
+
/** Where the browser goes to sign in with a provider, and the state it comes back with to the page of the link; for the app, its handoff. */
|
|
159
|
+
async signIn(provider, handoff) {
|
|
160
|
+
return (await this.calls.callHost('signIn', { provider, ...(handoff ? { handoff } : {}) }));
|
|
161
|
+
}
|
|
162
|
+
/** The browser came back signed in for the Ta app: the Ta verifies the account and keeps it for the app. */
|
|
163
|
+
async signedIn(state, code) {
|
|
164
|
+
const answer = (await this.calls.callHost('signedIn', { state, code }));
|
|
165
|
+
return { account: answer.account };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Waits for the code of a sign-in (`device` of {@link signIn}) to be typed at the provider, asking again till it was
|
|
169
|
+
* (the account, kept by the Ta under the handoff of the sign-in, or its state), this stops or `until` passes. A call
|
|
170
|
+
* the relay or the Ta did not answer (a phone away while the code was typed) is asked again; one refused throws.
|
|
171
|
+
*/
|
|
172
|
+
async typed(state, until = Date.now() + 15 * 60000) {
|
|
173
|
+
while (!this.closed && Date.now() < until) {
|
|
174
|
+
let answer;
|
|
175
|
+
try {
|
|
176
|
+
answer = (await this.calls.callHost('signedIn', { state }));
|
|
177
|
+
}
|
|
178
|
+
catch (failure) {
|
|
179
|
+
if (this.closed) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (!RelayTeamJoining.unreachable(failure)) {
|
|
183
|
+
throw failure;
|
|
184
|
+
}
|
|
185
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (answer.status === 'done' && answer.account) {
|
|
189
|
+
return answer.account;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Waits for the browser to sign in for the app, asking again till it did (the account), this stops or `until`
|
|
196
|
+
* passes; a call that fails (the app was away while the browser was in front) is asked again.
|
|
197
|
+
*/
|
|
198
|
+
async handedOff(handoff, until = Date.now() + 10 * 60000) {
|
|
199
|
+
while (!this.closed && Date.now() < until) {
|
|
200
|
+
try {
|
|
201
|
+
const answer = (await this.calls.callHost('handedOff', handoff));
|
|
202
|
+
if (answer.status === 'done' && answer.account) {
|
|
203
|
+
return answer.account;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (_a) {
|
|
207
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
/** Asks with a name (`via` a browser, maybe signed in): the answer, or that it waits. */
|
|
213
|
+
async ask(name, via, signIn) {
|
|
214
|
+
const own = await RelayTeamSeal.keys(name || 'ta');
|
|
215
|
+
const answer = (await this.calls.callHost('ask', { name, box: own.box, ...(via ? { via } : {}), ...(signIn ? { signIn } : {}) }));
|
|
216
|
+
// The keys of a request asked: one refused, or that failed, leaves those of a request asked before.
|
|
217
|
+
if (answer.status !== 'refused') {
|
|
218
|
+
this.own = own;
|
|
219
|
+
}
|
|
220
|
+
return answer;
|
|
221
|
+
}
|
|
222
|
+
/** Goes on with a request asked before, with its keys. */
|
|
223
|
+
resume(keys) {
|
|
224
|
+
this.own = keys;
|
|
225
|
+
}
|
|
226
|
+
/** Waits for the answer to a request, asking again till it comes or this stops. */
|
|
227
|
+
async wait(request) {
|
|
228
|
+
for (;;) {
|
|
229
|
+
if (this.closed) {
|
|
230
|
+
return { status: 'gone' };
|
|
231
|
+
}
|
|
232
|
+
const answer = (await this.calls.callHost('wait', request));
|
|
233
|
+
if (answer.status !== 'waiting') {
|
|
234
|
+
return answer;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** The pairing link of the device sealed in an answer. */
|
|
239
|
+
async pairing(request, answer) {
|
|
240
|
+
if (!this.own) {
|
|
241
|
+
throw new Error('Ask first.');
|
|
242
|
+
}
|
|
243
|
+
const device = JSON.parse(await RelayTeamSeal.open(this.own, answer, request));
|
|
244
|
+
return relay_pairing_1.RelayPairingUtil.link(relay_pairing_1.RelayPairingUtil.parse(relay_pairing_1.RelayPairingUtil.link(device)));
|
|
245
|
+
}
|
|
246
|
+
close() {
|
|
247
|
+
this.closed = true;
|
|
248
|
+
this.calls.close();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.RelayTeamJoining = RelayTeamJoining;
|
|
252
|
+
//# sourceMappingURL=relay-team.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ta's web page as the relay serves it under RELAY_WEB_PATH (docs/design/ta-team.md 8.3): the files of the page of
|
|
3
|
+
* `ta serve` (`apps/ta/dist/public`), its base made that path, for one let in from a browser; it signs in with the
|
|
4
|
+
* pairing link of its fragment and reaches the Ta through the relay, end to end, as the Ta app does.
|
|
5
|
+
*/
|
|
6
|
+
export declare namespace RelayWebUtil {
|
|
7
|
+
/** The page, its base the path it is served at. */
|
|
8
|
+
function index(html: string): string;
|
|
9
|
+
/** The file of the page a path asks for, relative to its directory; undefined for none (outside it, or not a plain path). */
|
|
10
|
+
function file(path: string): string | undefined;
|
|
11
|
+
/** How a file of the page is answered: the page never framed nor cached old, the files with hashed names kept long. */
|
|
12
|
+
function headers(file: string): Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=relay-web.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RelayWebUtil = void 0;
|
|
4
|
+
const relay_team_1 = require("./relay-team");
|
|
5
|
+
const TYPES = {
|
|
6
|
+
html: 'text/html; charset=utf-8',
|
|
7
|
+
js: 'text/javascript; charset=utf-8',
|
|
8
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
9
|
+
css: 'text/css; charset=utf-8',
|
|
10
|
+
json: 'application/json',
|
|
11
|
+
webmanifest: 'application/manifest+json',
|
|
12
|
+
svg: 'image/svg+xml',
|
|
13
|
+
png: 'image/png',
|
|
14
|
+
jpg: 'image/jpeg',
|
|
15
|
+
webp: 'image/webp',
|
|
16
|
+
ico: 'image/x-icon',
|
|
17
|
+
woff2: 'font/woff2',
|
|
18
|
+
woff: 'font/woff',
|
|
19
|
+
ttf: 'font/ttf',
|
|
20
|
+
wasm: 'application/wasm',
|
|
21
|
+
txt: 'text/plain; charset=utf-8',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Ta's web page as the relay serves it under RELAY_WEB_PATH (docs/design/ta-team.md 8.3): the files of the page of
|
|
25
|
+
* `ta serve` (`apps/ta/dist/public`), its base made that path, for one let in from a browser; it signs in with the
|
|
26
|
+
* pairing link of its fragment and reaches the Ta through the relay, end to end, as the Ta app does.
|
|
27
|
+
*/
|
|
28
|
+
var RelayWebUtil;
|
|
29
|
+
(function (RelayWebUtil) {
|
|
30
|
+
/** The page, its base the path it is served at. */
|
|
31
|
+
function index(html) {
|
|
32
|
+
return html.replace(/<base href="\/">/, `<base href="${relay_team_1.RELAY_WEB_PATH}">`);
|
|
33
|
+
}
|
|
34
|
+
RelayWebUtil.index = index;
|
|
35
|
+
/** The file of the page a path asks for, relative to its directory; undefined for none (outside it, or not a plain path). */
|
|
36
|
+
function file(path) {
|
|
37
|
+
if (!path.startsWith(relay_team_1.RELAY_WEB_PATH)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const rest = path.slice(relay_team_1.RELAY_WEB_PATH.length) || 'index.html';
|
|
41
|
+
const parts = rest.split('/');
|
|
42
|
+
if (parts.some(part => !part || part === '.' || part === '..' || !/^[\w.@-]+$/.test(part))) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return rest;
|
|
46
|
+
}
|
|
47
|
+
RelayWebUtil.file = file;
|
|
48
|
+
/** How a file of the page is answered: the page never framed nor cached old, the files with hashed names kept long. */
|
|
49
|
+
function headers(file) {
|
|
50
|
+
var _a;
|
|
51
|
+
const type = (_a = TYPES[file.slice(file.lastIndexOf('.') + 1).toLowerCase()]) !== null && _a !== void 0 ? _a : 'application/octet-stream';
|
|
52
|
+
const page = file === 'index.html';
|
|
53
|
+
return {
|
|
54
|
+
'content-type': type,
|
|
55
|
+
// no-transform: a CDN in front (Cloudflare's analytics) puts no script of its own into the page, which keeps keys.
|
|
56
|
+
'cache-control': file.startsWith('assets/') ? 'public, max-age=31536000, immutable, no-transform' : 'no-cache, no-transform',
|
|
57
|
+
'x-content-type-options': 'nosniff',
|
|
58
|
+
'referrer-policy': 'no-referrer',
|
|
59
|
+
...(page ? { 'x-frame-options': 'DENY' } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
RelayWebUtil.headers = headers;
|
|
63
|
+
})(RelayWebUtil || (exports.RelayWebUtil = RelayWebUtil = {}));
|
|
64
|
+
//# sourceMappingURL=relay-web.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PageLanguage } from '../common/page-language';
|
|
1
2
|
declare const zh: {
|
|
2
3
|
title: string;
|
|
3
4
|
invalid: string;
|
|
@@ -43,8 +44,12 @@ declare const zh: {
|
|
|
43
44
|
close: string;
|
|
44
45
|
};
|
|
45
46
|
export type GuestText = keyof typeof zh;
|
|
47
|
+
/** The words of each language of Ta, checked by scripts/check-i18n.ts. */
|
|
48
|
+
export declare const GUEST_WORDS: Readonly<Record<PageLanguage, typeof zh>>;
|
|
46
49
|
export declare namespace GuestI18n {
|
|
47
|
-
const
|
|
50
|
+
const language: PageLanguage;
|
|
51
|
+
/** Chinese or Japanese: Latin among the words has a space on each side. */
|
|
52
|
+
const cjk: boolean;
|
|
48
53
|
function t(id: GuestText, values?: Record<string, string | number>): string;
|
|
49
54
|
/** The time of a line: when today, else the day too. */
|
|
50
55
|
function time(at: number): string;
|