@celljs/ta-relay 4.9.1 → 4.10.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.
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayFiles = exports.RelayFilesUtil = exports.RELAY_FILES_TIMEOUT_MS = exports.RELAY_FILES_MAX_PARALLEL = exports.RELAY_FILE_MAX_BYTES = exports.RELAY_FILE_CHUNK_BYTES = exports.RELAY_FILES_PREFIX = void 0;
4
+ const relay_bytes_1 = require("./relay-bytes");
5
+ const relay_socket_1 = require("./relay-socket");
6
+ /** The only paths of ta serve a device may ask for: the ones answered without its token. */
7
+ exports.RELAY_FILES_PREFIX = '/api/files/';
8
+ /** The bytes of a chunk, base64 in a sealed frame: well under the 1 MiB of a message of Cloudflare. */
9
+ exports.RELAY_FILE_CHUNK_BYTES = 192 * 1024;
10
+ /** The largest file a device reads this way: a video of a workspace is previewed by its first bytes, not all of it. */
11
+ exports.RELAY_FILE_MAX_BYTES = 128 * 1024 * 1024;
12
+ /** Files read at once on one channel; a page that loads its pictures asks for several. */
13
+ exports.RELAY_FILES_MAX_PARALLEL = 4;
14
+ /** For one file, all of it. */
15
+ exports.RELAY_FILES_TIMEOUT_MS = 30000;
16
+ var RelayFilesUtil;
17
+ (function (RelayFilesUtil) {
18
+ /** The frame that turns a channel into a channel of files. */
19
+ function hello() {
20
+ return { t: 'files', v: 1 };
21
+ }
22
+ RelayFilesUtil.hello = hello;
23
+ /** Whether a frame of a device asks for files, rather than for ta serve's socket (`{t:'files', v:1}`). */
24
+ function isHello(text) {
25
+ try {
26
+ const frame = JSON.parse(text);
27
+ return frame.t === 'files' && frame.v === 1;
28
+ }
29
+ catch (_a) {
30
+ return false;
31
+ }
32
+ }
33
+ RelayFilesUtil.isHello = isHello;
34
+ })(RelayFilesUtil || (exports.RelayFilesUtil = RelayFilesUtil = {}));
35
+ /**
36
+ * The files of the ta serve of a pairing, through the relay: a channel of its own, kept open for the page,
37
+ * sealed end to end as the connection of a device is. It behaves for the page as loading the URL does.
38
+ */
39
+ class RelayFiles {
40
+ constructor(pairing, options = {}) {
41
+ this.pairing = pairing;
42
+ this.options = options;
43
+ this.called = 1;
44
+ this.pending = new Map();
45
+ }
46
+ /** The bytes of a URL of {@link RELAY_FILES_PREFIX}, as ta serve answers them. */
47
+ async get(url) {
48
+ if (!url.startsWith(exports.RELAY_FILES_PREFIX)) {
49
+ throw new Error('Ta reads only the files it offers by URL.');
50
+ }
51
+ await this.connect();
52
+ const id = this.called++;
53
+ return new Promise((resolve, reject) => {
54
+ var _a;
55
+ const timeout = (_a = this.options.timeoutMs) !== null && _a !== void 0 ? _a : exports.RELAY_FILES_TIMEOUT_MS;
56
+ const timer = setTimeout(() => this.settle(id, new Error('The file took too long to come.')), timeout);
57
+ this.pending.set(id, { chunks: [], received: 0, resolve, reject, timer });
58
+ this.send({ t: 'get', id, url });
59
+ });
60
+ }
61
+ /** Whether the channel is open: the page may keep one for as long as it shows files. */
62
+ get open() {
63
+ var _a;
64
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_socket_1.RelaySocket.OPEN;
65
+ }
66
+ close() {
67
+ const socket = this.socket;
68
+ this.socket = undefined;
69
+ this.opening = undefined;
70
+ this.fail(new Error('The files are closed.'));
71
+ socket === null || socket === void 0 ? void 0 : socket.close();
72
+ }
73
+ send(frame) {
74
+ var _a;
75
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(frame));
76
+ }
77
+ /** Opens the channel, once: the first file asked for opens it. */
78
+ connect() {
79
+ var _a;
80
+ if (((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === relay_socket_1.RelaySocket.OPEN) {
81
+ return Promise.resolve();
82
+ }
83
+ if (!this.opening) {
84
+ const socket = new relay_socket_1.RelaySocket(this.pairing);
85
+ this.socket = socket;
86
+ this.opening = new Promise((resolve, reject) => {
87
+ socket.onmessage = ({ data }) => this.receive(data);
88
+ socket.onopen = () => {
89
+ this.send(RelayFilesUtil.hello());
90
+ resolve();
91
+ };
92
+ socket.onclose = ({ code }) => {
93
+ const error = new Error(code === relay_socket_1.RelaySocket.REFUSED
94
+ ? 'This device is no longer paired with the computer.'
95
+ : 'The computer is not running Ta, or cannot be reached.');
96
+ if (this.socket === socket) {
97
+ this.socket = undefined;
98
+ }
99
+ this.fail(error);
100
+ reject(error);
101
+ };
102
+ });
103
+ const clear = () => {
104
+ this.opening = undefined;
105
+ };
106
+ this.opening.then(clear, clear);
107
+ }
108
+ return this.opening;
109
+ }
110
+ receive(text) {
111
+ var _a, _b;
112
+ let frame;
113
+ try {
114
+ frame = JSON.parse(text);
115
+ }
116
+ catch (_c) {
117
+ this.close();
118
+ return;
119
+ }
120
+ if (!('id' in frame) || typeof frame.id !== 'number') {
121
+ return;
122
+ }
123
+ const pending = this.pending.get(frame.id);
124
+ if (!pending) {
125
+ return;
126
+ }
127
+ if (frame.t === 'head') {
128
+ pending.head = { type: (_a = frame.type) !== null && _a !== void 0 ? _a : 'application/octet-stream', size: (_b = frame.size) !== null && _b !== void 0 ? _b : 0 };
129
+ }
130
+ else if (frame.t === 'chunk') {
131
+ const bytes = relay_bytes_1.RelayBytes.fromBase64(frame.d);
132
+ pending.received += bytes.length;
133
+ if (pending.received > exports.RELAY_FILE_MAX_BYTES) {
134
+ this.settle(frame.id, new Error('The file is too large to show here.'));
135
+ return;
136
+ }
137
+ pending.chunks.push(bytes);
138
+ }
139
+ else if (frame.t === 'end') {
140
+ if (!pending.head) {
141
+ this.settle(frame.id, new Error('The file came without its head.'));
142
+ return;
143
+ }
144
+ this.finish(frame.id, { type: pending.head.type, size: pending.received, data: relay_bytes_1.RelayBytes.concat(...pending.chunks) });
145
+ }
146
+ else if (frame.t === 'error') {
147
+ this.settle(frame.id, new Error(frame.message));
148
+ }
149
+ }
150
+ settle(id, error) {
151
+ const pending = this.pending.get(id);
152
+ if (pending) {
153
+ this.pending.delete(id);
154
+ clearTimeout(pending.timer);
155
+ pending.reject(error);
156
+ }
157
+ }
158
+ finish(id, bytes) {
159
+ const pending = this.pending.get(id);
160
+ if (pending) {
161
+ this.pending.delete(id);
162
+ clearTimeout(pending.timer);
163
+ pending.resolve(bytes);
164
+ }
165
+ }
166
+ /** The channel went: what was asked for is not coming. */
167
+ fail(error) {
168
+ for (const [id] of [...this.pending]) {
169
+ this.settle(id, error);
170
+ }
171
+ }
172
+ }
173
+ exports.RelayFiles = RelayFiles;
174
+ //# sourceMappingURL=relay-files.js.map
@@ -84,12 +84,18 @@ export interface RelayHello {
84
84
  v: 1;
85
85
  device: string;
86
86
  nonce: string;
87
+ /** 1: the device inflates deflate-raw (RelayCipher.compress). A device of before says nothing. */
88
+ z?: 1;
87
89
  }
88
- /** The host's answer: its nonce, and a first sealed message that shows it has the device's key. */
90
+ /**
91
+ * The host's answer: its nonce, and a first sealed message that shows it has the device's key; `z` when
92
+ * both compress what they seal after the proof (the device offered it, and the host can).
93
+ */
89
94
  export type RelayWelcome = {
90
95
  t: 'ready';
91
96
  nonce: string;
92
97
  proof: string;
98
+ z?: 1;
93
99
  } | {
94
100
  t: 'refused';
95
101
  reason: string;
@@ -35,7 +35,13 @@ class RelaySocket {
35
35
  this.helloTimer = setTimeout(() => this.drop(relay_protocol_1.RelayCloseCode.TIMEOUT, 'The host did not answer.'), (_a = options.helloMs) !== null && _a !== void 0 ? _a : HELLO_MS);
36
36
  this.socket.onopen = () => {
37
37
  var _a;
38
- const hello = { t: 'hello', v: 1, device: pairing.device, nonce: relay_bytes_1.RelayBytes.toBase64(this.nonce) };
38
+ const hello = {
39
+ t: 'hello',
40
+ v: 1,
41
+ device: pairing.device,
42
+ nonce: relay_bytes_1.RelayBytes.toBase64(this.nonce),
43
+ ...(relay_cipher_1.RelayDeflate.supported() ? { z: 1 } : {}),
44
+ };
39
45
  this.socket.send(JSON.stringify(hello));
40
46
  this.pingTimer = setInterval(() => this.ping(), (_a = options.pingMs) !== null && _a !== void 0 ? _a : relay_protocol_1.RELAY_PING_MS);
41
47
  };
@@ -92,6 +98,8 @@ class RelaySocket {
92
98
  if ((await cipher.open(welcome.proof)) !== relay_protocol_1.RELAY_PROOF) {
93
99
  throw new Error('The host did not show the key.');
94
100
  }
101
+ // The messages after the proof, both ways.
102
+ cipher.compress = welcome.z === 1 && relay_cipher_1.RelayDeflate.supported();
95
103
  this.cipher = cipher;
96
104
  clearTimeout(this.helloTimer);
97
105
  this.state = OPEN;
@@ -1,4 +1,5 @@
1
1
  export * from '../common';
2
+ export * from './relay-files-host';
2
3
  export * from './relay-host';
3
4
  export * from './relay-server';
4
5
  export * from './relay-store';
package/lib/node/index.js CHANGED
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("../common"), exports);
18
+ __exportStar(require("./relay-files-host"), exports);
18
19
  __exportStar(require("./relay-host"), exports);
19
20
  __exportStar(require("./relay-server"), exports);
20
21
  __exportStar(require("./relay-store"), exports);
@@ -0,0 +1,28 @@
1
+ import { type RelayFilesFrame } from '../common/relay-files';
2
+ export interface RelayFilesHostOptions {
3
+ /** The address of ta serve, always at loopback: the one of its WebSocket (RelayHostOptions.localUrl). */
4
+ localUrl: string;
5
+ /** Sends a frame of the sealed channel of this device. */
6
+ send(frame: RelayFilesFrame): void;
7
+ }
8
+ /**
9
+ * The files of the workspace on a channel of a device (RelayFiles): asks them of the ta serve of this
10
+ * machine and sends them back sealed. It asks for nothing but a path of {@link RELAY_FILES_PREFIX}, with
11
+ * GET, at the loopback port of ta serve and never at another host: a device has the whole of ta serve
12
+ * already, and what a device cannot be trusted with is not this.
13
+ */
14
+ export declare class RelayFilesHost {
15
+ protected readonly options: RelayFilesHostOptions;
16
+ protected readonly base: string;
17
+ protected reading: number;
18
+ protected readonly running: Set<AbortController>;
19
+ constructor(options: RelayFilesHostOptions);
20
+ /** A frame of the device: a file to read, or something of a version it does not know. */
21
+ receive(text: string): Promise<void>;
22
+ /** The device went: what it asked for is not read to the end. */
23
+ close(): void;
24
+ /** What to fetch for what a device asked, or undefined: a path of {@link RELAY_FILES_PREFIX} of this ta serve alone. */
25
+ static target(base: string, url: string): string | undefined;
26
+ protected read(id: number, url: string): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=relay-files-host.d.ts.map
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelayFilesHost = void 0;
4
+ const relay_bytes_1 = require("../common/relay-bytes");
5
+ const relay_files_1 = require("../common/relay-files");
6
+ /**
7
+ * The files of the workspace on a channel of a device (RelayFiles): asks them of the ta serve of this
8
+ * machine and sends them back sealed. It asks for nothing but a path of {@link RELAY_FILES_PREFIX}, with
9
+ * GET, at the loopback port of ta serve and never at another host: a device has the whole of ta serve
10
+ * already, and what a device cannot be trusted with is not this.
11
+ */
12
+ class RelayFilesHost {
13
+ constructor(options) {
14
+ this.options = options;
15
+ this.reading = 0;
16
+ this.running = new Set();
17
+ // Only ever loopback, whatever the address of the socket says: what this reaches is one server.
18
+ this.base = `http://127.0.0.1:${new URL(options.localUrl).port}`;
19
+ }
20
+ /** A frame of the device: a file to read, or something of a version it does not know. */
21
+ async receive(text) {
22
+ let frame;
23
+ try {
24
+ frame = JSON.parse(text);
25
+ }
26
+ catch (_a) {
27
+ return;
28
+ }
29
+ if (!frame || typeof frame !== 'object' || frame.t !== 'get' || typeof frame.url !== 'string' || typeof frame.id !== 'number') {
30
+ return;
31
+ }
32
+ await this.read(frame.id, frame.url);
33
+ }
34
+ /** The device went: what it asked for is not read to the end. */
35
+ close() {
36
+ for (const controller of this.running) {
37
+ controller.abort();
38
+ }
39
+ this.running.clear();
40
+ }
41
+ /** What to fetch for what a device asked, or undefined: a path of {@link RELAY_FILES_PREFIX} of this ta serve alone. */
42
+ static target(base, url) {
43
+ let parsed;
44
+ try {
45
+ // Parsed, never taken as text: a device that sends another host or a path out of the prefix is refused.
46
+ parsed = new URL(url, base);
47
+ }
48
+ catch (_a) {
49
+ return undefined;
50
+ }
51
+ if (parsed.origin !== base || !parsed.pathname.startsWith(relay_files_1.RELAY_FILES_PREFIX)) {
52
+ return undefined;
53
+ }
54
+ return base + parsed.pathname + parsed.search;
55
+ }
56
+ async read(id, url) {
57
+ var _a, _b;
58
+ const target = RelayFilesHost.target(this.base, url);
59
+ if (!target) {
60
+ this.options.send({ t: 'error', id, message: 'Ta reads only the files it offers by URL.' });
61
+ return;
62
+ }
63
+ if (this.reading >= relay_files_1.RELAY_FILES_MAX_PARALLEL) {
64
+ this.options.send({ t: 'error', id, message: 'Too many files are loading at once.' });
65
+ return;
66
+ }
67
+ const controller = new AbortController();
68
+ this.running.add(controller);
69
+ this.reading++;
70
+ const timer = setTimeout(() => controller.abort(), relay_files_1.RELAY_FILES_TIMEOUT_MS);
71
+ try {
72
+ const response = await fetch(target, { signal: controller.signal, redirect: 'error', headers: { accept: '*/*' } });
73
+ if (!response.ok) {
74
+ this.options.send({ t: 'error', id, message: `The file is not there (${response.status}).` });
75
+ return;
76
+ }
77
+ const length = Number((_a = response.headers.get('content-length')) !== null && _a !== void 0 ? _a : 0);
78
+ if (length > relay_files_1.RELAY_FILE_MAX_BYTES) {
79
+ this.options.send({ t: 'error', id, message: 'The file is too large to show here.' });
80
+ return;
81
+ }
82
+ this.options.send({
83
+ t: 'head',
84
+ id,
85
+ status: response.status,
86
+ type: (_b = response.headers.get('content-type')) !== null && _b !== void 0 ? _b : 'application/octet-stream',
87
+ size: length || undefined,
88
+ });
89
+ if (!response.body) {
90
+ this.options.send({ t: 'end', id });
91
+ return;
92
+ }
93
+ let sent = 0;
94
+ let parts = [];
95
+ let held = 0;
96
+ const flush = () => {
97
+ if (held > 0) {
98
+ this.options.send({ t: 'chunk', id, d: relay_bytes_1.RelayBytes.toBase64(relay_bytes_1.RelayBytes.concat(...parts)) });
99
+ parts = [];
100
+ held = 0;
101
+ }
102
+ };
103
+ for await (const piece of response.body) {
104
+ const chunk = piece;
105
+ sent += chunk.length;
106
+ if (sent > relay_files_1.RELAY_FILE_MAX_BYTES) {
107
+ this.options.send({ t: 'error', id, message: 'The file is too large to show here.' });
108
+ return;
109
+ }
110
+ parts.push(chunk);
111
+ held += chunk.length;
112
+ if (held >= relay_files_1.RELAY_FILE_CHUNK_BYTES) {
113
+ flush();
114
+ }
115
+ }
116
+ flush();
117
+ this.options.send({ t: 'end', id });
118
+ }
119
+ catch (error) {
120
+ this.options.send({
121
+ t: 'error',
122
+ id,
123
+ message: controller.signal.aborted ? 'The file took too long to come.' : `The file could not be read: ${error.message}`,
124
+ });
125
+ }
126
+ finally {
127
+ clearTimeout(timer);
128
+ this.running.delete(controller);
129
+ this.reading--;
130
+ }
131
+ }
132
+ }
133
+ exports.RelayFilesHost = RelayFilesHost;
134
+ //# sourceMappingURL=relay-files-host.js.map
@@ -1,5 +1,7 @@
1
1
  import { RelayCipher } from '../common/relay-cipher';
2
+ import { type RelayFilesFrame } from '../common/relay-files';
2
3
  import { RELAY_PING, type RelayHostMessage, type RelayWelcome } from '../common/relay-protocol';
4
+ import { RelayFilesHost } from './relay-files-host';
3
5
  import type { RelayShare, RelayStore } from './relay-store';
4
6
  export interface RelayHostOptions {
5
7
  store: RelayStore;
@@ -12,19 +14,28 @@ export interface RelayHostOptions {
12
14
  /** The bytes of a package handed on (a share of the store), for one who has its link; without it, shares are refused. */
13
15
  sharePackage?(share: RelayShare): Promise<Uint8Array>;
14
16
  }
15
- /** A device on a channel: the handshake, then its connection to ta serve. */
17
+ /**
18
+ * A device on a channel: the handshake, then its connection to ta serve — or, for a channel that asked
19
+ * for files (RelayFiles, RelayFilesHost), the file it asks for. What a channel is, it says in its first
20
+ * sealed message; until then nothing of ta serve is opened for it.
21
+ */
16
22
  declare class RelayChannel {
17
23
  readonly id: string;
18
24
  protected readonly host: RelayHost;
19
25
  protected readonly options: RelayHostOptions;
20
26
  protected cipher?: RelayCipher;
21
27
  protected local?: WebSocket;
28
+ /** What this channel does, once its first sealed message said it. */
29
+ protected mode?: 'rpc' | 'files';
30
+ protected files?: RelayFilesHost;
22
31
  protected readonly early: string[];
23
32
  protected readonly timer: NodeJS.Timeout;
24
33
  constructor(id: string, host: RelayHost, options: RelayHostOptions);
25
34
  receive(text: string): Promise<void>;
26
35
  /** From the relay: the device is gone. */
27
36
  closed(): void;
37
+ /** A frame of the files of the workspace, sealed as the rest. */
38
+ protected sendFrame(frame: RelayFilesFrame): void;
28
39
  protected hello(text: string): Promise<void>;
29
40
  /** A package handed on: what it is, its bytes in chunks, the end; then the channel closes. It never reaches ta serve's socket. */
30
41
  protected sendShare(cipher: RelayCipher, share: RelayShare): Promise<void>;
@@ -3,11 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RelayHost = void 0;
4
4
  const relay_bytes_1 = require("../common/relay-bytes");
5
5
  const relay_cipher_1 = require("../common/relay-cipher");
6
+ const relay_files_1 = require("../common/relay-files");
6
7
  const relay_pairing_1 = require("../common/relay-pairing");
7
8
  const relay_protocol_1 = require("../common/relay-protocol");
9
+ const relay_files_host_1 = require("./relay-files-host");
8
10
  const MAX_RECONNECT_DELAY_MS = 30000;
9
11
  const HELLO_TIMEOUT_MS = 10000;
10
- /** A device on a channel: the handshake, then its connection to ta serve. */
12
+ /**
13
+ * A device on a channel: the handshake, then its connection to ta serve — or, for a channel that asked
14
+ * for files (RelayFiles, RelayFilesHost), the file it asks for. What a channel is, it says in its first
15
+ * sealed message; until then nothing of ta serve is opened for it.
16
+ */
11
17
  class RelayChannel {
12
18
  constructor(id, host, options) {
13
19
  this.id = id;
@@ -17,7 +23,7 @@ class RelayChannel {
17
23
  this.timer = setTimeout(() => this.close(), HELLO_TIMEOUT_MS);
18
24
  }
19
25
  async receive(text) {
20
- var _a;
26
+ var _a, _b;
21
27
  if (!this.cipher) {
22
28
  await this.hello(text);
23
29
  return;
@@ -26,11 +32,24 @@ class RelayChannel {
26
32
  try {
27
33
  data = await this.cipher.open(text);
28
34
  }
29
- catch (_b) {
35
+ catch (_c) {
30
36
  this.close();
31
37
  return;
32
38
  }
33
- if (((_a = this.local) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
39
+ if (!this.mode) {
40
+ this.mode = relay_files_1.RelayFilesUtil.isHello(data) ? 'files' : 'rpc';
41
+ if (this.mode === 'files') {
42
+ this.files = new relay_files_host_1.RelayFilesHost({ localUrl: this.options.localUrl, send: frame => this.sendFrame(frame) });
43
+ }
44
+ else {
45
+ this.connectLocal(this.cipher);
46
+ }
47
+ }
48
+ if (this.mode === 'files') {
49
+ await ((_a = this.files) === null || _a === void 0 ? void 0 : _a.receive(data));
50
+ return;
51
+ }
52
+ if (((_b = this.local) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.OPEN) {
34
53
  this.local.send(data);
35
54
  }
36
55
  else {
@@ -39,9 +58,15 @@ class RelayChannel {
39
58
  }
40
59
  /** From the relay: the device is gone. */
41
60
  closed() {
42
- var _a;
61
+ var _a, _b;
43
62
  clearTimeout(this.timer);
44
- (_a = this.local) === null || _a === void 0 ? void 0 : _a.close();
63
+ (_a = this.files) === null || _a === void 0 ? void 0 : _a.close();
64
+ (_b = this.local) === null || _b === void 0 ? void 0 : _b.close();
65
+ }
66
+ /** A frame of the files of the workspace, sealed as the rest. */
67
+ sendFrame(frame) {
68
+ var _a;
69
+ (_a = this.cipher) === null || _a === void 0 ? void 0 : _a.seal(JSON.stringify(frame)).then(sealed => this.host.send({ t: 'data', ch: this.id, d: sealed }));
45
70
  }
46
71
  async hello(text) {
47
72
  var _a;
@@ -66,13 +91,14 @@ class RelayChannel {
66
91
  const nonce = relay_bytes_1.RelayBytes.random(16);
67
92
  const cipher = await relay_cipher_1.RelayCipher.derive(relay_bytes_1.RelayBytes.fromBase64(key), relay_bytes_1.RelayBytes.fromBase64(hello.nonce), nonce, 'host');
68
93
  this.cipher = cipher;
69
- this.answer({ t: 'ready', nonce: relay_bytes_1.RelayBytes.toBase64(nonce), proof: await cipher.seal(relay_protocol_1.RELAY_PROOF) });
94
+ const compress = hello.z === 1 && relay_cipher_1.RelayDeflate.supported();
95
+ const proof = await cipher.seal(relay_protocol_1.RELAY_PROOF);
96
+ // The messages after the proof, both ways: the device sets it once it opened the proof.
97
+ cipher.compress = compress;
98
+ this.answer({ t: 'ready', nonce: relay_bytes_1.RelayBytes.toBase64(nonce), proof, ...(compress ? { z: 1 } : {}) });
70
99
  if (share) {
71
100
  await this.sendShare(cipher, share);
72
101
  }
73
- else {
74
- this.connectLocal(cipher);
75
- }
76
102
  }
77
103
  /** A package handed on: what it is, its bytes in chunks, the end; then the channel closes. It never reaches ta serve's socket. */
78
104
  async sendShare(cipher, share) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-relay",
3
- "version": "4.9.1",
3
+ "version": "4.10.0",
4
4
  "description": "Ta from anywhere: a relay that only forwards, and end-to-end encryption between a paired device and ta serve",
5
5
  "homepage": "https://github.com/cellbang/cell",
6
6
  "bugs": {
@@ -29,7 +29,7 @@
29
29
  "watch": "tsc -b -w --preserveWatchOutput"
30
30
  },
31
31
  "dependencies": {
32
- "@celljs/rpc": "4.9.1"
32
+ "@celljs/rpc": "4.10.0"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"