@kumiai/hub-tunnel 0.11.0 → 0.12.1

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.
@@ -1,6 +1,6 @@
1
1
  import { fromB64, toB64 } from '@sozai/codec';
2
2
  import { decodeEnvelope, encodeEnvelope } from './envelope.js';
3
- import { DecryptError, EncryptError, EnvelopeDecodeError } from './errors.js';
3
+ import { DecryptError, DuplicateFrameError, EncryptError, EnvelopeDecodeError } from './errors.js';
4
4
  import { createHubTunnelTransport } from './transport.js';
5
5
  function wrapHub({ hub, encryptor, groupID, onEvent, onEncryptError, drainTimeoutMs, drains }) {
6
6
  const wrapped = {
@@ -132,6 +132,16 @@ function wrapHub({ hub, encryptor, groupID, onEvent, onEncryptError, drainTimeou
132
132
  try {
133
133
  plaintext = await decryptWork;
134
134
  } catch (cause) {
135
+ if (cause instanceof DuplicateFrameError) {
136
+ // Opened once already: the redelivery of a frame whose ack was lost. Acked so the
137
+ // hub stops redelivering it.
138
+ onEvent?.({
139
+ type: 'frame-dropped',
140
+ reason: 'dedup'
141
+ });
142
+ ackHandled(message.sequenceID);
143
+ continue;
144
+ }
135
145
  const err = new DecryptError('decrypt failed', {
136
146
  cause
137
147
  });
@@ -1,4 +1,5 @@
1
1
  export type Encryptor = {
2
2
  encrypt(plaintext: Uint8Array): Promise<Uint8Array>;
3
+ /** Rejects with `DuplicateFrameError` for a ciphertext this reader has already opened. */
3
4
  decrypt(ciphertext: Uint8Array): Promise<Uint8Array>;
4
5
  };
package/lib/errors.d.ts CHANGED
@@ -7,6 +7,14 @@ export declare class EnvelopeDecodeError extends Error {
7
7
  export declare class DecryptError extends Error {
8
8
  name: string;
9
9
  }
10
+ /**
11
+ * Thrown by an `Encryptor.decrypt` for a ciphertext this reader has already opened. A hub
12
+ * redelivers a frame whose ack was lost, and a ratcheting cipher cannot open it twice: that is a
13
+ * duplicate, not a lost frame.
14
+ */
15
+ export declare class DuplicateFrameError extends Error {
16
+ name: string;
17
+ }
10
18
  export declare class EncryptError extends Error {
11
19
  name: string;
12
20
  }
package/lib/errors.js CHANGED
@@ -7,6 +7,13 @@ export class EnvelopeDecodeError extends Error {
7
7
  export class DecryptError extends Error {
8
8
  name = 'DecryptError';
9
9
  }
10
+ /**
11
+ * Thrown by an `Encryptor.decrypt` for a ciphertext this reader has already opened. A hub
12
+ * redelivers a frame whose ack was lost, and a ratcheting cipher cannot open it twice: that is a
13
+ * duplicate, not a lost frame.
14
+ */ export class DuplicateFrameError extends Error {
15
+ name = 'DuplicateFrameError';
16
+ }
10
17
  export class EncryptError extends Error {
11
18
  name = 'EncryptError';
12
19
  }
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createEncryptedHubTunnelTransport, type EncryptedHubTunnelTransportParams, } from './encrypted-transport.js';
2
2
  export type { Encryptor } from './encryptor.js';
3
3
  export { decodeEnvelope, encodeEnvelope, TUNNEL_ENVELOPE_VERSION, type TunnelEnvelope, tunnelEnvelopeSchema, } from './envelope.js';
4
- export { BackpressureError, DecryptError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError, } from './errors.js';
4
+ export { BackpressureError, DecryptError, DuplicateFrameError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError, } from './errors.js';
5
5
  export type { FrameDroppedReason, ObservabilityEvent, ObservabilityEventListener, } from './events.js';
6
6
  export { decodeFrame, encodeFrame, HUB_FRAME_VERSION, type HubFrame, type HubFrameMessageBody, hubFrameSchema, } from './frame.js';
7
7
  export { createHubTunnelTransport, type HubBase, type HubFetchTopicParams, type HubFetchTopicResult, type HubPublishParams, type HubReceiveOptions, type HubReceiveSubscription, type HubSubscribeOptions, type HubTunnelSessionID, type HubTunnelTransportParams, type LogHub, type MailboxHub, type MailboxHubEvent, type MailboxHubEvents, type MailboxPublishParams, } from './transport.js';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @kumiai/hub-tunnel — peer-to-peer Enkaku transport over the hub relay
2
2
  export { createEncryptedHubTunnelTransport } from './encrypted-transport.js';
3
3
  export { decodeEnvelope, encodeEnvelope, TUNNEL_ENVELOPE_VERSION, tunnelEnvelopeSchema } from './envelope.js';
4
- export { BackpressureError, DecryptError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError } from './errors.js';
4
+ export { BackpressureError, DecryptError, DuplicateFrameError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError } from './errors.js';
5
5
  export { decodeFrame, encodeFrame, HUB_FRAME_VERSION, hubFrameSchema } from './frame.js';
6
6
  export { createHubTunnelTransport } from './transport.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/hub-tunnel",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "description": "Peer-to-peer Enkaku transport tunneled through a hub relay",
5
5
  "keywords": [
6
6
  "enkaku",
@@ -26,19 +26,19 @@
26
26
  "lib/*"
27
27
  ],
28
28
  "dependencies": {
29
- "@enkaku/transport": "^0.22.1",
30
- "@kumiai/hub-protocol": "^0.11.0",
31
- "@sozai/async": "^0.4.1",
29
+ "@enkaku/transport": "^0.22.3",
30
+ "@kumiai/hub-protocol": "^0.12.0",
31
+ "@sozai/async": "^0.4.3",
32
32
  "@sozai/codec": "^0.4.3",
33
33
  "@sozai/event": "^0.1.6",
34
34
  "@sozai/schema": "^0.1.6"
35
35
  },
36
36
  "devDependencies": {
37
- "@enkaku/client": "^0.22.1",
38
- "@enkaku/protocol": "^0.22.1",
39
- "@enkaku/server": "^0.22.1",
40
- "@kokuin/token": "^0.6.1",
41
- "@kumiai/hub-conformance": "^0.11.0"
37
+ "@enkaku/client": "^0.22.3",
38
+ "@enkaku/protocol": "^0.22.3",
39
+ "@enkaku/server": "^0.22.3",
40
+ "@kokuin/token": "^0.6.4",
41
+ "@kumiai/hub-conformance": "^0.12.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"