@kumiai/hub-tunnel 0.3.0 → 0.4.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.
@@ -63,6 +63,22 @@ function wrapHub({ hub, encryptor, groupID, onEvent, onEncryptError }) {
63
63
  }
64
64
  throw error;
65
65
  }
66
+ // WHY: the envelope states its group in the clear and we stamp ours on publish, so a
67
+ // frame addressed to another group is dropped before we ever hand it to the cipher.
68
+ // Honestly: against a working AEAD this catches little — a foreign group's frame is
69
+ // encrypted under a key we do not hold and would fail to decrypt anyway. What it does
70
+ // catch is the same-key case the cipher cannot see: a misroute or a configuration
71
+ // error that puts two groups on one key or one topic, where the bytes authenticate
72
+ // perfectly and are still not ours. It is one string compare, before any crypto, so
73
+ // the cost of keeping it is nil and the cost of trusting the cipher alone for a
74
+ // property the envelope states outright is a silent cross-group delivery.
75
+ if (envelope.groupID !== groupID) {
76
+ onEvent?.({
77
+ type: 'frame-dropped',
78
+ reason: 'group-mismatch'
79
+ });
80
+ continue;
81
+ }
66
82
  let plaintext;
67
83
  try {
68
84
  plaintext = await encryptor.decrypt(fromB64(envelope.ciphertext));
@@ -84,7 +100,13 @@ function wrapHub({ hub, encryptor, groupID, onEvent, onEncryptError }) {
84
100
  sequenceID: message.sequenceID,
85
101
  senderDID: message.senderDID,
86
102
  topicID: message.topicID,
87
- payload: plaintext
103
+ payload: plaintext,
104
+ // Carried through: this wrapper re-writes the payload and nothing else, and dropping
105
+ // the log position here would silently strip it from every lane behind an encrypting
106
+ // hub — leaving a reader unable to advance a log cursor over a frame it was pushed.
107
+ ...message.logPosition != null ? {
108
+ logPosition: message.logPosition
109
+ } : {}
88
110
  };
89
111
  return {
90
112
  value: decrypted,
package/lib/events.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DecryptError, EnvelopeDecodeError } from './errors.js';
2
- export type FrameDroppedReason = 'envelope-decode' | 'decrypt' | 'topic-mismatch' | 'session-mismatch' | 'dedup';
2
+ export type FrameDroppedReason = 'envelope-decode' | 'decrypt' | 'group-mismatch' | 'topic-mismatch' | 'session-mismatch' | 'dedup';
3
3
  export type ObservabilityEvent = {
4
4
  type: 'decrypt-failed';
5
5
  error: DecryptError;
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/hub-tunnel",
3
- "version": "0.3.0",
4
- "license": "MIT",
3
+ "version": "0.4.1",
5
4
  "description": "Peer-to-peer Enkaku transport tunneled through a hub relay",
6
5
  "keywords": [
7
6
  "enkaku",
@@ -15,36 +14,38 @@
15
14
  "url": "https://github.com/TairuFramework/kumiai",
16
15
  "directory": "packages/hub-tunnel"
17
16
  },
17
+ "license": "MIT",
18
+ "sideEffects": false,
18
19
  "type": "module",
19
- "main": "lib/index.js",
20
- "types": "lib/index.d.ts",
21
20
  "exports": {
22
21
  ".": "./lib/index.js"
23
22
  },
23
+ "main": "lib/index.js",
24
+ "types": "lib/index.d.ts",
24
25
  "files": [
25
26
  "lib/*"
26
27
  ],
27
- "sideEffects": false,
28
28
  "dependencies": {
29
+ "@enkaku/transport": "^0.20.0",
29
30
  "@sozai/async": "^0.2.1",
30
31
  "@sozai/codec": "^0.2.0",
31
32
  "@sozai/schema": "^0.1.1",
32
- "@enkaku/transport": "^0.19.1",
33
- "@kumiai/hub-protocol": "^0.3.0"
33
+ "@kumiai/hub-protocol": "^0.4.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@enkaku/client": "^0.19.0",
37
- "@enkaku/protocol": "^0.19.0",
38
- "@enkaku/server": "^0.19.0",
39
- "@kokuin/token": "^0.2.0"
36
+ "@enkaku/client": "^0.20.0",
37
+ "@enkaku/protocol": "^0.20.0",
38
+ "@enkaku/server": "^0.20.0",
39
+ "@kokuin/token": "^0.3.0",
40
+ "@kumiai/hub-conformance": "^0.4.1"
40
41
  },
41
42
  "scripts": {
43
+ "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
42
44
  "build:clean": "del lib",
43
45
  "build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
44
46
  "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
45
- "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
47
+ "test": "pnpm run test:types && pnpm run test:unit",
46
48
  "test:types": "tsc --noEmit -p tsconfig.test.json",
47
- "test:unit": "vitest run",
48
- "test": "pnpm run test:types && pnpm run test:unit"
49
+ "test:unit": "vitest run"
49
50
  }
50
51
  }