@getpaseo/relay 0.2.3 → 0.2.4

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.
@@ -35,6 +35,8 @@ interface EncryptedChannelOptions {
35
35
  daemonKeyPair?: KeyPair;
36
36
  binaryCiphertext?: boolean;
37
37
  }
38
+ export declare function base64EncryptedWireByteLength(plaintextBytes: number): number;
39
+ export declare function maxBase64EncryptedPlaintextByteLength(wireBytes: number): number;
38
40
  /**
39
41
  * Creates an encrypted channel as the initiator (client).
40
42
  *
@@ -47,6 +47,13 @@ function buildInvalidHelloError(rawText, parsed) {
47
47
  const HANDSHAKE_RETRY_MS = 1000;
48
48
  const MAX_PENDING_SENDS = 200;
49
49
  const REHANDSHAKE_KEY_MISMATCH_CLOSE_CODE = 1008;
50
+ const ENCRYPTED_PAYLOAD_OVERHEAD_BYTES = 40;
51
+ export function base64EncryptedWireByteLength(plaintextBytes) {
52
+ return 4 * Math.ceil((plaintextBytes + ENCRYPTED_PAYLOAD_OVERHEAD_BYTES) / 3);
53
+ }
54
+ export function maxBase64EncryptedPlaintextByteLength(wireBytes) {
55
+ return Math.floor(wireBytes / 4) * 3 - ENCRYPTED_PAYLOAD_OVERHEAD_BYTES;
56
+ }
50
57
  const REHANDSHAKE_KEY_MISMATCH_CLOSE_REASON = "E2EE re-handshake key mismatch";
51
58
  function hasUnref(timeout) {
52
59
  return (typeof timeout === "object" &&
@@ -356,11 +363,12 @@ export class EncryptedChannel {
356
363
  await this.transport.send(arrayBufferToBase64(ciphertext));
357
364
  }
358
365
  outboundWireByteLength(data) {
359
- const encryptedBytes = utf8ByteLength(data) + 40;
366
+ const plaintextBytes = utf8ByteLength(data);
367
+ const encryptedBytes = plaintextBytes + ENCRYPTED_PAYLOAD_OVERHEAD_BYTES;
360
368
  if (this.options.binaryCiphertext && data instanceof ArrayBuffer) {
361
369
  return encryptedBytes;
362
370
  }
363
- return 4 * Math.ceil(encryptedBytes / 3);
371
+ return base64EncryptedWireByteLength(plaintextBytes);
364
372
  }
365
373
  async flushPendingSends() {
366
374
  if (this.state !== "open")
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { ConnectionRole, RelaySessionAttachment } from "./types.js";
2
2
  export { generateKeyPair, exportPublicKey, importPublicKey, deriveSharedKey, encrypt, decrypt, } from "./crypto.js";
3
- export { createClientChannel, createDaemonChannel, EncryptedChannel } from "./encrypted-channel.js";
3
+ export { base64EncryptedWireByteLength, createClientChannel, createDaemonChannel, EncryptedChannel, maxBase64EncryptedPlaintextByteLength, } from "./encrypted-channel.js";
4
4
  export type { Transport, EncryptedChannelEvents } from "./encrypted-channel.js";
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { generateKeyPair, exportPublicKey, importPublicKey, deriveSharedKey, encrypt, decrypt, } from "./crypto.js";
2
- export { createClientChannel, createDaemonChannel, EncryptedChannel } from "./encrypted-channel.js";
2
+ export { base64EncryptedWireByteLength, createClientChannel, createDaemonChannel, EncryptedChannel, maxBase64EncryptedPlaintextByteLength, } from "./encrypted-channel.js";
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpaseo/relay",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Paseo relay for bridging daemon and client connections",
5
5
  "files": [
6
6
  "dist",