@celljs/ta-relay 4.13.1 → 4.14.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.
Files changed (58) hide show
  1. package/README.en.md +9 -1
  2. package/README.md +9 -1
  3. package/esm/common/index.d.ts +3 -0
  4. package/esm/common/index.js +3 -0
  5. package/esm/common/relay-friends.js +29 -4
  6. package/esm/common/relay-host-calls.d.ts +34 -0
  7. package/esm/common/relay-host-calls.js +126 -0
  8. package/esm/common/relay-hubs-connection.d.ts +9 -1
  9. package/esm/common/relay-hubs-connection.js +33 -1
  10. package/esm/common/relay-hubs-protocol.d.ts +9 -1
  11. package/esm/common/relay-hubs.d.ts +7 -0
  12. package/esm/common/relay-hubs.js +20 -3
  13. package/esm/common/relay-identity.d.ts +11 -0
  14. package/esm/common/relay-identity.js +12 -1
  15. package/esm/common/relay-protocol.d.ts +1 -1
  16. package/esm/common/relay-protocol.js +2 -1
  17. package/esm/common/relay-team.d.ts +144 -0
  18. package/esm/common/relay-team.js +200 -0
  19. package/esm/common/relay-web.d.ts +13 -0
  20. package/esm/common/relay-web.js +61 -0
  21. package/esm/join/join-i18n.d.ts +53 -0
  22. package/esm/join/join-i18n.js +103 -0
  23. package/esm/join/join.d.ts +1 -0
  24. package/esm/join/join.js +364 -0
  25. package/esm/node/relay-server.d.ts +7 -0
  26. package/esm/node/relay-server.js +28 -3
  27. package/esm/node/relay-viewer.d.ts +2 -0
  28. package/esm/node/relay-viewer.js +9 -4
  29. package/lib/common/index.d.ts +3 -0
  30. package/lib/common/index.js +3 -0
  31. package/lib/common/relay-friends.js +29 -4
  32. package/lib/common/relay-host-calls.d.ts +35 -0
  33. package/lib/common/relay-host-calls.js +130 -0
  34. package/lib/common/relay-hubs-connection.d.ts +9 -1
  35. package/lib/common/relay-hubs-connection.js +33 -1
  36. package/lib/common/relay-hubs-protocol.d.ts +9 -1
  37. package/lib/common/relay-hubs.d.ts +7 -0
  38. package/lib/common/relay-hubs.js +20 -3
  39. package/lib/common/relay-identity.d.ts +11 -0
  40. package/lib/common/relay-identity.js +12 -1
  41. package/lib/common/relay-protocol.d.ts +1 -1
  42. package/lib/common/relay-protocol.js +2 -1
  43. package/lib/common/relay-team.d.ts +145 -0
  44. package/lib/common/relay-team.js +204 -0
  45. package/lib/common/relay-web.d.ts +14 -0
  46. package/lib/common/relay-web.js +64 -0
  47. package/lib/join/join-i18n.d.ts +54 -0
  48. package/lib/join/join-i18n.js +106 -0
  49. package/lib/join/join.d.ts +2 -0
  50. package/lib/join/join.js +366 -0
  51. package/lib/node/relay-server.d.ts +7 -0
  52. package/lib/node/relay-server.js +27 -2
  53. package/lib/node/relay-viewer.d.ts +2 -0
  54. package/lib/node/relay-viewer.js +6 -1
  55. package/package.json +4 -4
  56. package/viewer/join.html +92 -0
  57. package/viewer/page.html +9 -9
  58. package/viewer/room.html +10 -10
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayHostCalls = void 0;
4
+ const relay_pairing_1 = require("./relay-pairing");
5
+ const relay_socket_1 = require("./relay-socket");
6
+ /** How long a call to another Ta waits for its answer. */
7
+ const CALL_MS = 30000;
8
+ /** Tries to reach it, a while apart: a Ta that just made the link may be on its way to the relay. */
9
+ const OPEN_TRIES = 6;
10
+ const OPEN_PAUSE_MS = 700;
11
+ /**
12
+ * Calls of the host of a package on another Ta, through the relay with a device of it (end to end): asking to come in
13
+ * with the device of a link (RelayTeamJoining), or reading what is shared with the user there from their own Ta. The
14
+ * other Ta checks every call as it does those of its pages.
15
+ */
16
+ class RelayHostCalls {
17
+ constructor(pairing,
18
+ /** The package whose host is called. */
19
+ name) {
20
+ this.pairing = pairing;
21
+ this.name = name;
22
+ this.next = 1;
23
+ this.calls = new Map();
24
+ this.closed = false;
25
+ }
26
+ /** From the pairing link of a device. */
27
+ static of(link, name) {
28
+ return new RelayHostCalls(relay_pairing_1.RelayPairingUtil.parse(link), name);
29
+ }
30
+ open() {
31
+ var _a;
32
+ (_a = this.opening) !== null && _a !== void 0 ? _a : (this.opening = this.tryOpen(OPEN_TRIES));
33
+ return this.opening;
34
+ }
35
+ /** Opens, again after a pause when the connection drops before it opened (not when the other Ta refused the device). */
36
+ async tryOpen(tries) {
37
+ for (let left = tries;; left--) {
38
+ try {
39
+ await this.openOnce();
40
+ return;
41
+ }
42
+ catch (error) {
43
+ if (left <= 1 || this.closed || error.refused) {
44
+ this.opening = undefined;
45
+ throw error;
46
+ }
47
+ await new Promise(resolve => setTimeout(resolve, OPEN_PAUSE_MS));
48
+ }
49
+ }
50
+ }
51
+ openOnce() {
52
+ return new Promise((resolve, reject) => {
53
+ let opened = false;
54
+ const socket = new relay_socket_1.RelaySocket(this.pairing);
55
+ this.socket = socket;
56
+ socket.onopen = () => {
57
+ opened = true;
58
+ resolve();
59
+ };
60
+ socket.onerror = () => {
61
+ if (!opened) {
62
+ reject(new Error('The other Ta did not answer: is it running?'));
63
+ }
64
+ };
65
+ socket.onclose = event => {
66
+ const refused = event.code === relay_socket_1.RelaySocket.REFUSED;
67
+ const error = Object.assign(new Error(refused ? 'The other Ta no longer knows this device.' : 'The connection to the other Ta was lost.'), {
68
+ refused,
69
+ });
70
+ if (!opened) {
71
+ reject(error);
72
+ return;
73
+ }
74
+ this.failAll(error);
75
+ this.opening = undefined;
76
+ };
77
+ socket.onmessage = message => this.receive(message.data);
78
+ });
79
+ }
80
+ async callHost(method, ...params) {
81
+ await this.open();
82
+ const id = this.next++;
83
+ return new Promise((resolve, reject) => {
84
+ var _a;
85
+ const timer = setTimeout(() => {
86
+ this.calls.delete(id);
87
+ reject(new Error('The other Ta did not answer in time.'));
88
+ }, CALL_MS);
89
+ this.calls.set(id, { resolve, reject, timer });
90
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ jsonrpc: '2.0', id, method: 'TaPackageServer/callPackageHost', params: [this.name, method, params] }));
91
+ });
92
+ }
93
+ close() {
94
+ var _a;
95
+ this.closed = true;
96
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
97
+ this.failAll(new Error('Stopped.'));
98
+ }
99
+ failAll(error) {
100
+ for (const call of this.calls.values()) {
101
+ clearTimeout(call.timer);
102
+ call.reject(error);
103
+ }
104
+ this.calls.clear();
105
+ }
106
+ receive(data) {
107
+ var _a;
108
+ let message;
109
+ try {
110
+ message = JSON.parse(data);
111
+ }
112
+ catch (_b) {
113
+ return;
114
+ }
115
+ const call = typeof message.id === 'number' ? this.calls.get(message.id) : undefined;
116
+ if (!call) {
117
+ return;
118
+ }
119
+ this.calls.delete(message.id);
120
+ clearTimeout(call.timer);
121
+ if (message.error) {
122
+ call.reject(new Error((_a = message.error.message) !== null && _a !== void 0 ? _a : 'Failed.'));
123
+ }
124
+ else {
125
+ call.resolve(message.result);
126
+ }
127
+ }
128
+ }
129
+ exports.RelayHostCalls = RelayHostCalls;
130
+ //# sourceMappingURL=relay-host-calls.js.map
@@ -5,8 +5,9 @@ import { type RelayHubEntry, type RelayHubFailure, type RelayHubRequest } from '
5
5
  /** What a member sends in a message, signed and sealed: data of an extension, or a word of Ta itself. */
6
6
  export interface MessageBody {
7
7
  d?: unknown;
8
- /** A member's new name, for the owner to put in the roster. */
8
+ /** A member's new name, for the owner to put in the roster; with its look (RelayPublicIdentity.look), '' for none. */
9
9
  name?: string;
10
+ look?: string;
10
11
  /** Asks the one it is sent to to be friends: the link of the sender's room of friends (RelayFriends.offer). */
11
12
  friend?: string;
12
13
  }
@@ -43,6 +44,8 @@ export declare class Live {
43
44
  timer?: ReturnType<typeof setTimeout>;
44
45
  pingTimer?: ReturnType<typeof setInterval>;
45
46
  awaitingPong: boolean;
47
+ /** The look this Ta last sent the owner, for the roster to say: once, whatever the owner does with it. */
48
+ toldLook?: string;
46
49
  /** Events are handled one after another: opening them is async. */
47
50
  chain: Promise<void>;
48
51
  constructor(record: RelayRoomRecord);
@@ -94,6 +97,11 @@ export declare abstract class RelayHubsConnection {
94
97
  /** A member asks the user to be friends, by the link of its room of friends. */
95
98
  protected offered(_live: Live, _from: RelayPublicIdentity, _link: string): void;
96
99
  protected readRoster(live: Live, sealed: string): Promise<void>;
100
+ /**
101
+ * The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
102
+ * a member tells the owner, once a connection. A room joined with another identity keeps that one's.
103
+ */
104
+ protected keepLook(live: Live): Promise<void>;
97
105
  protected guestOf(live: Live, member: string): boolean;
98
106
  protected signOf(live: Live): (member: string) => string | undefined;
99
107
  protected readEntry(live: Live, entry: RelayHubEntry, tell: boolean): Promise<void>;
@@ -76,6 +76,7 @@ class RelayHubsConnection {
76
76
  ask: ask.member,
77
77
  id: ask.id,
78
78
  name: ask.name,
79
+ ...(relay_identity_1.RelayIdentityUtil.isLook(ask.look) ? { look: ask.look } : {}),
79
80
  friend: friends.has(ask.id),
80
81
  ...(ask.guest ? { guest: true } : {}),
81
82
  at: ask.at,
@@ -417,6 +418,35 @@ class RelayHubsConnection {
417
418
  this.heardMembers(members.filter(member => member.id !== own && !member.guest));
418
419
  if (!members.some(member => member.member === live.record.member) && !live.record.own && live.record.status === 'member') {
419
420
  this.setStatus(live, 'gone', 'removed');
421
+ return;
422
+ }
423
+ // Not awaited: what it sends waits for the room to be ready, which may wait for this event.
424
+ void this.keepLook(live);
425
+ }
426
+ /**
427
+ * The roster says this Ta as it is now: its look, set while the room was away or the owner offline. The owner writes it,
428
+ * a member tells the owner, once a connection. A room joined with another identity keeps that one's.
429
+ */
430
+ async keepLook(live) {
431
+ var _a, _b;
432
+ if (live.record.status !== 'member' || live.record.identity || !live.roster) {
433
+ return;
434
+ }
435
+ const identity = await this.identity();
436
+ const look = (_a = identity.look) !== null && _a !== void 0 ? _a : '';
437
+ const self = live.roster.members.find(member => member.member === live.record.member);
438
+ if (!self || ((_b = self.look) !== null && _b !== void 0 ? _b : '') === look) {
439
+ return;
440
+ }
441
+ if (live.record.own) {
442
+ await this.writeRoster(live, members => members.map(member => (member.member === self.member ? relay_identity_1.RelayIdentityUtil.withLook(member, look) : member))).catch(() => undefined);
443
+ return;
444
+ }
445
+ const owner = live.roster.members.find(member => member.owner);
446
+ if (owner && live.toldLook !== look) {
447
+ await this.sendBody(live, { name: identity.name, look }, owner.member).then(() => {
448
+ live.toldLook = look;
449
+ }, () => undefined);
420
450
  }
421
451
  }
422
452
  guestOf(live, member) {
@@ -473,7 +503,9 @@ class RelayHubsConnection {
473
503
  if (typeof signed.b.name === 'string') {
474
504
  if (live.record.own && sender) {
475
505
  const name = signed.b.name.trim().slice(0, 40);
476
- await this.writeRoster(live, members => members.map(member => (member.member === from ? { ...member, name } : member))).catch(() => undefined);
506
+ // A Ta of before tells its name alone: its look stays as it was.
507
+ const look = typeof signed.b.look === 'string' ? signed.b.look : sender.look;
508
+ await this.writeRoster(live, members => members.map(member => (member.member === from ? relay_identity_1.RelayIdentityUtil.withLook({ ...member, name }, look) : member))).catch(() => undefined);
477
509
  }
478
510
  return;
479
511
  }
@@ -56,6 +56,8 @@ export interface RelayRoomMember {
56
56
  /** The identity of its Ta. */
57
57
  id: string;
58
58
  name: string;
59
+ /** The look of its double (RelayPublicIdentity.look). */
60
+ look?: string;
59
61
  owner: boolean;
60
62
  online: boolean;
61
63
  self: boolean;
@@ -88,6 +90,8 @@ export interface RelayRoomRequest {
88
90
  /** Its identity, and the name it gives. */
89
91
  id: string;
90
92
  name: string;
93
+ /** The look of its double (RelayPublicIdentity.look). */
94
+ look?: string;
91
95
  /** Met before, in another room. */
92
96
  friend: boolean;
93
97
  /** Asks from a browser, without Ta: admitted, it only chats. */
@@ -98,7 +102,7 @@ export interface RelayRoomRequest {
98
102
  * One the user chose as a friend (docs/design/ta-link.md 3.1), in `friends.json`: its keys once known (from its link
99
103
  * only its id and name), when chosen and last heard of.
100
104
  */
101
- export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, Partial<Pick<RelayPublicIdentity, 'sign' | 'box'>> {
105
+ export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, Partial<Pick<RelayPublicIdentity, 'sign' | 'box' | 'look'>> {
102
106
  metAt: number;
103
107
  seenAt: number;
104
108
  }
@@ -106,6 +110,8 @@ export interface RelayFriend extends Pick<RelayPublicIdentity, 'id' | 'name'>, P
106
110
  export interface RelayFriendInfo {
107
111
  id: string;
108
112
  name: string;
113
+ /** The look of its double (RelayPublicIdentity.look). */
114
+ look?: string;
109
115
  status: 'friend' | 'adding';
110
116
  online: boolean;
111
117
  metAt: number;
@@ -115,6 +121,8 @@ export interface RelayFriendInfo {
115
121
  export interface RelayFriendRequest {
116
122
  id: string;
117
123
  name: string;
124
+ /** The look of its double (RelayPublicIdentity.look). */
125
+ look?: string;
118
126
  at: number;
119
127
  via: 'link' | 'room';
120
128
  room?: string;
@@ -17,6 +17,13 @@ export declare class RelayHubs extends RelayHubsConnection {
17
17
  onEvent(listener: (event: RelayRoomEvent) => void): () => void;
18
18
  /** The name others see; the owners of rooms this Ta is in hear it. */
19
19
  setName(name: string): Promise<RelayPublicIdentity>;
20
+ /**
21
+ * The kind of dinosaur the double of this Ta is (RelayPublicIdentity.look), which others draw it by; none for a
22
+ * look that is none. The owners of rooms this Ta is in hear it, as a name.
23
+ */
24
+ setLook(look: string | undefined): Promise<RelayPublicIdentity>;
25
+ /** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
26
+ protected changeSelf(identity: RelayIdentity): Promise<RelayPublicIdentity>;
20
27
  list(): RelayRoomInfo[];
21
28
  room(id: string): RelayRoomInfo | undefined;
22
29
  create(input: {
@@ -74,7 +74,20 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
74
74
  if (!trimmed) {
75
75
  throw new Error('A name is needed.');
76
76
  }
77
- const identity = { ...(await this.identity()), name: trimmed };
77
+ return this.changeSelf({ ...(await this.identity()), name: trimmed });
78
+ }
79
+ /**
80
+ * The kind of dinosaur the double of this Ta is (RelayPublicIdentity.look), which others draw it by; none for a
81
+ * look that is none. The owners of rooms this Ta is in hear it, as a name.
82
+ */
83
+ async setLook(look) {
84
+ const identity = await this.identity();
85
+ const next = relay_identity_1.RelayIdentityUtil.withLook(identity, look);
86
+ return next.look === identity.look ? relay_identity_1.RelayIdentityUtil.publicOf(identity) : this.changeSelf(next);
87
+ }
88
+ /** Keeps the identity with a new name or look, and tells the rooms this Ta is in. */
89
+ async changeSelf(identity) {
90
+ var _a;
78
91
  this.options.store.write('identity', identity);
79
92
  this.own = identity;
80
93
  for (const live of this.live.values()) {
@@ -83,12 +96,15 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
83
96
  continue;
84
97
  }
85
98
  if (live.record.own) {
86
- await this.writeRoster(live, members => members.map(member => (member.id === identity.id ? { ...member, name: trimmed } : member))).catch(() => undefined);
99
+ await this.writeRoster(live, members => members.map(member => (member.id === identity.id ? relay_identity_1.RelayIdentityUtil.withLook({ ...member, name: identity.name }, identity.look) : member))).catch(() => undefined);
87
100
  }
88
101
  else if (live.roster) {
89
102
  const owner = live.roster.members.find(member => member.owner);
90
103
  if (owner) {
91
- await this.sendBody(live, { name: trimmed }, owner.member).catch(() => undefined);
104
+ const look = (_a = identity.look) !== null && _a !== void 0 ? _a : '';
105
+ await this.sendBody(live, { name: identity.name, look }, owner.member).then(() => {
106
+ live.toldLook = look;
107
+ }, () => undefined);
92
108
  }
93
109
  }
94
110
  }
@@ -544,6 +560,7 @@ class RelayHubs extends relay_hubs_connection_1.RelayHubsConnection {
544
560
  member: member.member,
545
561
  id: member.id,
546
562
  name: member.name,
563
+ ...(relay_identity_1.RelayIdentityUtil.isLook(member.look) ? { look: member.look } : {}),
547
564
  owner: !!member.owner,
548
565
  online: member.member === record.member ? ((_a = live.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_hubs_connection_1.OPEN && live.synced : live.online.has(member.member),
549
566
  self: member.member === record.member,
@@ -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
- 'cache-control': 'no-cache',
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,145 @@
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
+ }
20
+ /** Where one asking from a browser comes from: the page of the relay (RELAY_JOIN_PATH), not the Ta app. */
21
+ export type RelayTeamVia = 'web';
22
+ /** The answer to asking to come in. */
23
+ export interface RelayTeamAnswer {
24
+ status: 'waiting' | 'accepted' | 'refused' | 'gone';
25
+ answer?: {
26
+ box: string;
27
+ sealed: string;
28
+ };
29
+ request?: string;
30
+ /**
31
+ * Refused at once: `app`, the role is one taken in the Ta app alone (it manages members, and the Ta has no provider to
32
+ * sign in with); `account`, sign in with an account first (from a browser, for a role that manages members).
33
+ */
34
+ reason?: 'app' | 'account';
35
+ }
36
+ /** How one asking by a link may say who they are (docs/design/ta-team.md 17). */
37
+ export interface RelayTeamWays {
38
+ /** The providers the Ta signs in with: GitHub, Google, WeChat, the operator's. */
39
+ providers: {
40
+ id: string;
41
+ name: string;
42
+ }[];
43
+ /** They sign in first: the role manages members and they ask from a browser; otherwise signing in is theirs to choose. */
44
+ required: boolean;
45
+ /** The role manages members. */
46
+ manages?: boolean;
47
+ }
48
+ /**
49
+ * 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),
50
+ * or in a browser for the Ta app, by the handoff id the app gave it (RelayTeamLinkUtil.signInFor).
51
+ */
52
+ export type RelayTeamSignIn = {
53
+ state: string;
54
+ code: string;
55
+ } | {
56
+ handoff: string;
57
+ };
58
+ /** A sign-in the page of the link does in a browser for the Ta app (the fragment's `p` and `x`). */
59
+ export interface RelayTeamHandoff {
60
+ provider: string;
61
+ handoff: string;
62
+ }
63
+ /**
64
+ * 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
65
+ * 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.
66
+ */
67
+ export declare namespace RelayTeamSeal {
68
+ /** A pair of keys for one request: its public part goes with it. */
69
+ function keys(name: string): Promise<RelayIdentity>;
70
+ function seal(box: string, salt: string, text: string): Promise<{
71
+ box: string;
72
+ sealed: string;
73
+ }>;
74
+ /** Throws when it was not sealed for these keys. */
75
+ function open(keys: RelayIdentity, answer: {
76
+ box: string;
77
+ sealed: string;
78
+ }, salt: string): Promise<string>;
79
+ /** Whether a public key is one: what a request carries is checked before anything is sealed for it. */
80
+ function isKey(box: unknown): box is string;
81
+ }
82
+ /** 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. */
83
+ export declare namespace RelayTeamLinkUtil {
84
+ function format(link: RelayTeamLink): string;
85
+ /** Undefined for text that is not such a link. */
86
+ function parse(text: string): RelayTeamLink | undefined;
87
+ /**
88
+ * 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
89
+ * waits for the account under `handoff`, an id of its own; all of it in the fragment.
90
+ */
91
+ function signInFor(link: RelayTeamLink, provider: string, handoff: string): string;
92
+ /** The sign-in for the Ta app a link of {@link signInFor} asks, if it does. */
93
+ function handoffOf(text: string): RelayTeamHandoff | undefined;
94
+ /** Ta's web page of the relay, signing in with a pairing link (in the fragment, which the relay is not sent). */
95
+ function web(relay: string, pairing: string): string;
96
+ }
97
+ /**
98
+ * 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
99
+ * 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
100
+ * key of this request alone, then the page connects with it. The keys of a request may be kept (`keys`) to wait again
101
+ * after the page was opened again (`resume`).
102
+ */
103
+ export declare class RelayTeamJoining {
104
+ protected readonly calls: RelayHostCalls;
105
+ protected own?: RelayIdentity;
106
+ protected closed: boolean;
107
+ constructor(link: RelayTeamLink);
108
+ /** The keys of the request asked. */
109
+ get keys(): RelayIdentity | undefined;
110
+ /**
111
+ * How to say who one is. A Ta of before has no accounts for those asking (its link may not call `ways`): none needed;
112
+ * a Ta that cannot be reached says so when asked.
113
+ */
114
+ ways(via?: RelayTeamVia): Promise<RelayTeamWays>;
115
+ /** 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. */
116
+ signIn(provider: string, handoff?: string): Promise<{
117
+ url: string;
118
+ state: string;
119
+ }>;
120
+ /** The browser came back signed in for the Ta app: the Ta verifies the account and keeps it for the app. */
121
+ signedIn(state: string, code: string): Promise<{
122
+ account: {
123
+ id: string;
124
+ name?: string;
125
+ };
126
+ }>;
127
+ /**
128
+ * Waits for the browser to sign in for the app, asking again till it did (the account), this stops or `until`
129
+ * passes; a call that fails (the app was away while the browser was in front) is asked again.
130
+ */
131
+ handedOff(handoff: string, until?: number): Promise<{
132
+ id: string;
133
+ name?: string;
134
+ } | undefined>;
135
+ /** Asks with a name (`via` a browser, maybe signed in): the answer, or that it waits. */
136
+ ask(name: string, via?: RelayTeamVia, signIn?: RelayTeamSignIn): Promise<RelayTeamAnswer>;
137
+ /** Goes on with a request asked before, with its keys. */
138
+ resume(keys: RelayIdentity): void;
139
+ /** Waits for the answer to a request, asking again till it comes or this stops. */
140
+ wait(request: string): Promise<RelayTeamAnswer>;
141
+ /** The pairing link of the device sealed in an answer. */
142
+ pairing(request: string, answer: NonNullable<RelayTeamAnswer['answer']>): Promise<string>;
143
+ close(): void;
144
+ }
145
+ //# sourceMappingURL=relay-team.d.ts.map