@dimchansky/meshpost 0.2.0 → 0.4.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.
- package/README.md +330 -96
- package/dist/channel.d.ts +37 -2
- package/dist/channel.js +226 -12
- package/dist/combine.d.ts +12 -1
- package/dist/combine.js +304 -213
- package/dist/crypto.d.ts +34 -0
- package/dist/crypto.js +158 -0
- package/dist/identity.d.ts +45 -0
- package/dist/identity.js +264 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.js +8 -2
- package/dist/mqtt.d.ts +9 -1
- package/dist/mqtt.js +95 -87
- package/dist/nostr.d.ts +27 -0
- package/dist/nostr.js +1008 -0
- package/dist/room.d.ts +37 -7
- package/dist/room.js +656 -65
- package/dist/rpc.d.ts +48 -0
- package/dist/rpc.js +382 -0
- package/dist/signaling.d.ts +9 -8
- package/dist/signaling.js +10 -2
- package/dist/state.d.ts +56 -0
- package/dist/state.js +305 -0
- package/dist/tabs.js +8 -1
- package/dist/turn.d.ts +13 -0
- package/dist/turn.js +213 -0
- package/dist/voice.d.ts +108 -0
- package/dist/voice.js +1160 -0
- package/dist/ws.d.ts +17 -2
- package/dist/ws.js +248 -33
- package/docs/behavior.md +107 -54
- package/package.json +67 -2
package/dist/combine.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tabSignaling } from './tabs.js';
|
|
1
2
|
const maxSeenIcePeers = 256;
|
|
2
3
|
const maxSeenIceAttemptsPerPeer = 4;
|
|
3
4
|
const maxSeenIceKeysPerAttempt = 64;
|
|
@@ -13,237 +14,327 @@ function setsEqual(a, b) {
|
|
|
13
14
|
}
|
|
14
15
|
return true;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export function combineSignaling(...adapters) {
|
|
22
|
-
if (adapters.length === 0)
|
|
23
|
-
throw new RangeError('At least one signaling adapter is required');
|
|
24
|
-
for (const adapter of adapters) {
|
|
25
|
-
if (typeof adapter !== 'function') {
|
|
26
|
-
throw new TypeError('All signaling adapters must be functions');
|
|
27
|
-
}
|
|
17
|
+
function childCanReach(child, peerId) {
|
|
18
|
+
if (!child.peers.has(peerId) || !child.session)
|
|
19
|
+
return false;
|
|
20
|
+
if (typeof child.session.canReach === 'function') {
|
|
21
|
+
return child.session.canReach(peerId);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
23
|
+
return child.state === 'online';
|
|
24
|
+
}
|
|
25
|
+
function createCompositeSession(discovery, list, primaryIndex) {
|
|
26
|
+
const children = list.map(() => ({
|
|
27
|
+
state: 'connecting',
|
|
28
|
+
peers: new Set()
|
|
29
|
+
}));
|
|
30
|
+
const buffered = [];
|
|
31
|
+
const seenIce = new Map();
|
|
32
|
+
let initializing = true;
|
|
33
|
+
let closed = false;
|
|
34
|
+
let aggState = 'connecting';
|
|
35
|
+
let lastReason;
|
|
36
|
+
let publishedRoster = new Set();
|
|
37
|
+
let rosterDirty = false;
|
|
38
|
+
const computeAggregateState = () => {
|
|
39
|
+
if (primaryIndex !== null) {
|
|
40
|
+
return children[primaryIndex].state;
|
|
41
|
+
}
|
|
42
|
+
let hasConnecting = false;
|
|
43
|
+
let hasOffline = false;
|
|
44
|
+
for (const child of children) {
|
|
45
|
+
if (child.state === 'online')
|
|
46
|
+
return 'online';
|
|
47
|
+
if (child.state === 'connecting')
|
|
48
|
+
hasConnecting = true;
|
|
49
|
+
else if (child.state === 'offline')
|
|
50
|
+
hasOffline = true;
|
|
51
|
+
}
|
|
52
|
+
if (hasConnecting)
|
|
53
|
+
return 'connecting';
|
|
54
|
+
if (hasOffline)
|
|
55
|
+
return 'offline';
|
|
56
|
+
return 'closed';
|
|
57
|
+
};
|
|
58
|
+
const syncState = (reason) => {
|
|
59
|
+
if (closed)
|
|
60
|
+
return;
|
|
61
|
+
const next = computeAggregateState();
|
|
62
|
+
if (next === aggState)
|
|
63
|
+
return;
|
|
64
|
+
aggState = next;
|
|
65
|
+
lastReason = reason;
|
|
66
|
+
if (!initializing)
|
|
67
|
+
discovery.status(next, reason);
|
|
68
|
+
};
|
|
69
|
+
const computeUnion = () => {
|
|
70
|
+
const union = new Set();
|
|
71
|
+
for (const child of children) {
|
|
72
|
+
for (const id of child.peers) {
|
|
73
|
+
if (child.session ? childCanReach(child, id) : child.state === 'online') {
|
|
74
|
+
union.add(id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return union;
|
|
79
|
+
};
|
|
80
|
+
const syncRoster = () => {
|
|
81
|
+
if (closed)
|
|
82
|
+
return;
|
|
83
|
+
if (initializing) {
|
|
84
|
+
rosterDirty = true;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const union = computeUnion();
|
|
88
|
+
if (setsEqual(union, publishedRoster))
|
|
89
|
+
return;
|
|
90
|
+
publishedRoster = union;
|
|
91
|
+
discovery.roster([...union]);
|
|
92
|
+
};
|
|
93
|
+
const dedupeIceSignal = (from, signal) => {
|
|
94
|
+
if (signal.kind !== 'ice')
|
|
95
|
+
return signal;
|
|
96
|
+
let byAttempt = seenIce.get(from);
|
|
97
|
+
if (!byAttempt) {
|
|
98
|
+
if (seenIce.size >= maxSeenIcePeers) {
|
|
99
|
+
const oldestPeer = seenIce.keys().next().value;
|
|
100
|
+
if (oldestPeer !== undefined)
|
|
101
|
+
seenIce.delete(oldestPeer);
|
|
102
|
+
}
|
|
103
|
+
byAttempt = new Map();
|
|
104
|
+
}
|
|
105
|
+
seenIce.delete(from);
|
|
106
|
+
seenIce.set(from, byAttempt);
|
|
107
|
+
let keys = byAttempt.get(signal.attempt);
|
|
108
|
+
if (!keys) {
|
|
109
|
+
if (byAttempt.size >= maxSeenIceAttemptsPerPeer) {
|
|
110
|
+
const oldestAttempt = byAttempt.keys().next().value;
|
|
111
|
+
if (oldestAttempt !== undefined)
|
|
112
|
+
byAttempt.delete(oldestAttempt);
|
|
55
113
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
114
|
+
keys = new Set();
|
|
115
|
+
}
|
|
116
|
+
byAttempt.delete(signal.attempt);
|
|
117
|
+
byAttempt.set(signal.attempt, keys);
|
|
118
|
+
const fresh = [];
|
|
119
|
+
for (const item of signal.candidates) {
|
|
120
|
+
const key = iceCandidateKey(item);
|
|
121
|
+
if (keys.has(key))
|
|
122
|
+
continue;
|
|
123
|
+
if (keys.size < maxSeenIceKeysPerAttempt)
|
|
124
|
+
keys.add(key);
|
|
125
|
+
fresh.push(item);
|
|
126
|
+
}
|
|
127
|
+
return fresh.length > 0 ? { ...signal, candidates: fresh } : null;
|
|
128
|
+
};
|
|
129
|
+
const closeAll = () => {
|
|
130
|
+
seenIce.clear();
|
|
131
|
+
for (const child of children) {
|
|
132
|
+
try {
|
|
133
|
+
child.session?.close();
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Ensure one failing child close does not leak sibling sessions.
|
|
137
|
+
}
|
|
138
|
+
delete child.session;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const makeChildDiscovery = (index, child) => ({
|
|
142
|
+
appId: discovery.appId,
|
|
143
|
+
room: discovery.room,
|
|
144
|
+
self: discovery.self,
|
|
145
|
+
...(discovery.password !== undefined ? { password: discovery.password } : {}),
|
|
146
|
+
status(next, reason) {
|
|
147
|
+
if (closed || next === child.state)
|
|
148
|
+
return;
|
|
149
|
+
child.state = next;
|
|
150
|
+
if (next === 'closed') {
|
|
151
|
+
if (child.peers.size > 0) {
|
|
152
|
+
child.peers.clear();
|
|
153
|
+
syncRoster();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (next === 'offline') {
|
|
157
|
+
if (typeof child.session?.canReach === 'function') {
|
|
158
|
+
let removed = false;
|
|
159
|
+
for (const id of [...child.peers]) {
|
|
160
|
+
if (!child.session.canReach(id)) {
|
|
161
|
+
child.peers.delete(id);
|
|
162
|
+
removed = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (removed)
|
|
166
|
+
syncRoster();
|
|
167
|
+
}
|
|
168
|
+
else if (child.peers.size > 0) {
|
|
169
|
+
child.peers.clear();
|
|
170
|
+
syncRoster();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (next === 'online' && child.peers.size > 0) {
|
|
174
|
+
syncRoster();
|
|
175
|
+
}
|
|
176
|
+
if (primaryIndex === null || index === primaryIndex) {
|
|
177
|
+
syncState(reason);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
roster(ids) {
|
|
63
181
|
if (closed)
|
|
64
182
|
return;
|
|
65
|
-
|
|
66
|
-
|
|
183
|
+
child.peers = new Set(ids);
|
|
184
|
+
syncRoster();
|
|
185
|
+
},
|
|
186
|
+
receive(from, signal) {
|
|
187
|
+
if (closed)
|
|
67
188
|
return;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
discovery.status(next, reason);
|
|
72
|
-
};
|
|
73
|
-
const computeUnion = () => {
|
|
74
|
-
const union = new Set();
|
|
75
|
-
for (const child of children) {
|
|
76
|
-
for (const id of child.peers)
|
|
77
|
-
union.add(id);
|
|
189
|
+
if (!child.peers.has(from)) {
|
|
190
|
+
child.peers.add(from);
|
|
191
|
+
syncRoster();
|
|
78
192
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const syncRoster = () => {
|
|
82
|
-
if (closed)
|
|
193
|
+
const deduped = dedupeIceSignal(from, signal);
|
|
194
|
+
if (!deduped)
|
|
83
195
|
return;
|
|
84
196
|
if (initializing) {
|
|
85
|
-
|
|
197
|
+
buffered.push({ kind: 'receive', from, signal: deduped });
|
|
86
198
|
return;
|
|
87
199
|
}
|
|
88
|
-
|
|
89
|
-
|
|
200
|
+
discovery.receive(from, deduped);
|
|
201
|
+
},
|
|
202
|
+
error(code, message) {
|
|
203
|
+
if (closed)
|
|
204
|
+
return;
|
|
205
|
+
if (primaryIndex !== null && index !== primaryIndex)
|
|
206
|
+
return;
|
|
207
|
+
if (initializing) {
|
|
208
|
+
buffered.push({ kind: 'error', code, message });
|
|
90
209
|
return;
|
|
91
|
-
publishedRoster = union;
|
|
92
|
-
discovery.roster([...union]);
|
|
93
|
-
};
|
|
94
|
-
const dedupeIceSignal = (from, signal) => {
|
|
95
|
-
if (signal.kind !== 'ice')
|
|
96
|
-
return signal;
|
|
97
|
-
let byAttempt = seenIce.get(from);
|
|
98
|
-
if (!byAttempt) {
|
|
99
|
-
if (seenIce.size >= maxSeenIcePeers) {
|
|
100
|
-
const oldestPeer = seenIce.keys().next().value;
|
|
101
|
-
if (oldestPeer !== undefined)
|
|
102
|
-
seenIce.delete(oldestPeer);
|
|
103
|
-
}
|
|
104
|
-
byAttempt = new Map();
|
|
105
210
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
211
|
+
discovery.error?.(code, message);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
try {
|
|
215
|
+
for (let i = 0; i < list.length; i++) {
|
|
216
|
+
const child = children[i];
|
|
217
|
+
const adapter = list[i];
|
|
218
|
+
child.session = adapter(makeChildDiscovery(i, child));
|
|
219
|
+
if (child.peers.size > 0)
|
|
220
|
+
rosterDirty = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
closed = true;
|
|
225
|
+
closeAll();
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
initializing = false;
|
|
229
|
+
if (!closed) {
|
|
230
|
+
const nextState = computeAggregateState();
|
|
231
|
+
aggState = nextState;
|
|
232
|
+
if (nextState !== 'connecting')
|
|
233
|
+
discovery.status(nextState, lastReason);
|
|
234
|
+
if (rosterDirty) {
|
|
235
|
+
rosterDirty = false;
|
|
236
|
+
const union = computeUnion();
|
|
237
|
+
if (union.size > 0) {
|
|
238
|
+
publishedRoster = union;
|
|
239
|
+
discovery.roster([...union]);
|
|
117
240
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
241
|
+
}
|
|
242
|
+
for (const ev of buffered) {
|
|
243
|
+
if (closed)
|
|
244
|
+
break;
|
|
245
|
+
if (ev.kind === 'receive')
|
|
246
|
+
discovery.receive(ev.from, ev.signal);
|
|
247
|
+
else
|
|
248
|
+
discovery.error?.(ev.code, ev.message);
|
|
249
|
+
}
|
|
250
|
+
buffered.length = 0;
|
|
251
|
+
}
|
|
252
|
+
const trickle = children.every((child) => child.session?.trickle === true);
|
|
253
|
+
return {
|
|
254
|
+
trickle,
|
|
255
|
+
canReach(peerId) {
|
|
256
|
+
if (closed)
|
|
257
|
+
return false;
|
|
258
|
+
for (const child of children) {
|
|
259
|
+
if (childCanReach(child, peerId))
|
|
260
|
+
return true;
|
|
129
261
|
}
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
262
|
+
return false;
|
|
263
|
+
},
|
|
264
|
+
send(to, signal) {
|
|
265
|
+
if (closed)
|
|
266
|
+
return false;
|
|
267
|
+
let accepted = false;
|
|
134
268
|
for (const child of children) {
|
|
135
|
-
|
|
136
|
-
child.session
|
|
137
|
-
|
|
138
|
-
catch {
|
|
139
|
-
// Ensure one failing child close does not leak sibling sessions.
|
|
269
|
+
if (childCanReach(child, to) && child.session) {
|
|
270
|
+
if (child.session.send(to, signal))
|
|
271
|
+
accepted = true;
|
|
140
272
|
}
|
|
141
|
-
delete child.session;
|
|
142
273
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
child.session = adapter({
|
|
149
|
-
appId: discovery.appId,
|
|
150
|
-
room: discovery.room,
|
|
151
|
-
self: discovery.self,
|
|
152
|
-
...(discovery.password !== undefined ? { password: discovery.password } : {}),
|
|
153
|
-
status(next, reason) {
|
|
154
|
-
if (closed || next === child.state)
|
|
155
|
-
return;
|
|
156
|
-
child.state = next;
|
|
157
|
-
if (next === 'offline' || next === 'closed') {
|
|
158
|
-
if (child.peers.size > 0) {
|
|
159
|
-
child.peers.clear();
|
|
160
|
-
syncRoster();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
syncState(reason);
|
|
164
|
-
},
|
|
165
|
-
roster(ids) {
|
|
166
|
-
if (closed)
|
|
167
|
-
return;
|
|
168
|
-
child.peers = new Set(ids);
|
|
169
|
-
syncRoster();
|
|
170
|
-
},
|
|
171
|
-
receive(from, signal) {
|
|
172
|
-
if (closed)
|
|
173
|
-
return;
|
|
174
|
-
if (!child.peers.has(from)) {
|
|
175
|
-
child.peers.add(from);
|
|
176
|
-
syncRoster();
|
|
177
|
-
}
|
|
178
|
-
const deduped = dedupeIceSignal(from, signal);
|
|
179
|
-
if (!deduped)
|
|
180
|
-
return;
|
|
181
|
-
if (initializing) {
|
|
182
|
-
buffered.push({ kind: 'receive', from, signal: deduped });
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
discovery.receive(from, deduped);
|
|
186
|
-
},
|
|
187
|
-
error(code, message) {
|
|
188
|
-
if (closed)
|
|
189
|
-
return;
|
|
190
|
-
if (initializing) {
|
|
191
|
-
buffered.push({ kind: 'error', code, message });
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
discovery.error?.(code, message);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
274
|
+
return accepted;
|
|
275
|
+
},
|
|
276
|
+
close() {
|
|
277
|
+
if (closed)
|
|
278
|
+
return;
|
|
200
279
|
closed = true;
|
|
201
280
|
closeAll();
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Combine multiple signaling adapters into one composite adapter.
|
|
286
|
+
* Merges peer rosters across all children, routes signals to reachable children that advertise the target peer,
|
|
287
|
+
* and stays `'online'` as long as at least one child adapter is `'online'`.
|
|
288
|
+
*/
|
|
289
|
+
export function combineSignaling(...adapters) {
|
|
290
|
+
if (adapters.length === 0)
|
|
291
|
+
throw new RangeError('At least one signaling adapter is required');
|
|
292
|
+
for (const adapter of adapters) {
|
|
293
|
+
if (typeof adapter !== 'function') {
|
|
294
|
+
throw new TypeError('All signaling adapters must be functions');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (adapters.length === 1)
|
|
298
|
+
return adapters[0];
|
|
299
|
+
const list = [...adapters];
|
|
300
|
+
return (discovery) => createCompositeSession(discovery, list, null);
|
|
301
|
+
}
|
|
302
|
+
function canUseLocalTabs() {
|
|
303
|
+
if (typeof BroadcastChannel !== 'function')
|
|
304
|
+
return false;
|
|
305
|
+
if (typeof location !== 'undefined') {
|
|
306
|
+
if (location.protocol === 'file:' || location.origin === 'null')
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Decorate a network signaling adapter (`mqttSignaling()`, `wsSignaling()`, etc.) with instant
|
|
313
|
+
* same-browser `BroadcastChannel` discovery (`tabSignaling()`).
|
|
314
|
+
*
|
|
315
|
+
* - Exposes `primary`'s `SignalingState` and errors for `room.signalingState` / `room.onSignalingChange`
|
|
316
|
+
* (avoiding a permanently `'online'` indicator when network connectivity is lost).
|
|
317
|
+
* - Still connects same-browser tabs locally even while `primary` is `'connecting'` or `'offline'`.
|
|
318
|
+
* - Safely falls back to `primary` alone when `BroadcastChannel` is unavailable, on `file:` / opaque
|
|
319
|
+
* origins, or if `new BroadcastChannel(...)` throws `SecurityError`.
|
|
320
|
+
*/
|
|
321
|
+
export function withLocalTabs(primary) {
|
|
322
|
+
if (typeof primary !== 'function') {
|
|
323
|
+
throw new TypeError('Expected a signaling adapter function');
|
|
324
|
+
}
|
|
325
|
+
return (discovery) => {
|
|
326
|
+
if (!canUseLocalTabs())
|
|
327
|
+
return primary(discovery);
|
|
328
|
+
// Probe BroadcastChannel construction before starting anything so a synchronous SecurityError
|
|
329
|
+
// falls back cleanly to `primary(discovery)` without creating duplicate sessions.
|
|
330
|
+
try {
|
|
331
|
+
const probe = new BroadcastChannel('meshpost/probe');
|
|
332
|
+
probe.close();
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
return primary(discovery);
|
|
336
|
+
}
|
|
337
|
+
const tabs = tabSignaling();
|
|
338
|
+
return createCompositeSession(discovery, [tabs, primary], 1);
|
|
248
339
|
};
|
|
249
340
|
}
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const replayWindowMs = 60000;
|
|
2
|
+
export declare const midTtlMs: number;
|
|
3
|
+
export declare const maxMidLength = 64;
|
|
4
|
+
export declare const maxSeenMids = 2048;
|
|
5
|
+
export declare const errorCooldownMs = 15000;
|
|
6
|
+
export declare const minBoxBytes = 28;
|
|
7
|
+
export declare const minBoxChars = 38;
|
|
8
|
+
export declare const maxBoxChars: number;
|
|
9
|
+
export interface DerivedSignalingKeys {
|
|
10
|
+
readonly aeadKey: CryptoKey;
|
|
11
|
+
readonly privateId: string;
|
|
12
|
+
}
|
|
13
|
+
export type ReplayCheckResult = 'ok' | 'clock-skew' | 'replay' | 'invalid';
|
|
14
|
+
export interface ReplayGuard {
|
|
15
|
+
recordMid(scopedMid: string, now?: number): boolean;
|
|
16
|
+
checkAuthenticated(from: string, data: {
|
|
17
|
+
readonly mid?: unknown;
|
|
18
|
+
readonly ts?: unknown;
|
|
19
|
+
}, now?: number): ReplayCheckResult;
|
|
20
|
+
prune(now?: number): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Derive an AES-256-GCM signaling key and a domain-separated 128-bit hex `privateId`
|
|
24
|
+
* from a shared password using a single 256-bit PBKDF2-HMAC-SHA256 pass (100,000 iterations)
|
|
25
|
+
* followed by RFC 5869 HKDF-SHA256 expansion.
|
|
26
|
+
*/
|
|
27
|
+
export declare function deriveSignalingKeys(password: string, baseScope: string, insecureMessage?: string): Promise<DerivedSignalingKeys>;
|
|
28
|
+
export declare function sealPayload(key: CryptoKey, plain: Uint8Array, aad: string): Promise<Uint8Array>;
|
|
29
|
+
export declare function openPayload(key: CryptoKey, boxed: Uint8Array, aad: string): Promise<Uint8Array | null>;
|
|
30
|
+
export declare function sealEnvelope(key: CryptoKey, envelope: object, aad: string): Promise<Uint8Array>;
|
|
31
|
+
export declare function openEnvelope(key: CryptoKey, boxed: Uint8Array, aad: string): Promise<Record<string, unknown> | null>;
|
|
32
|
+
export declare function toBase64Url(bytes: Uint8Array): string;
|
|
33
|
+
export declare function fromBase64Url(value: unknown, maxChars?: number): Uint8Array | null;
|
|
34
|
+
export declare function createReplayGuard(): ReplayGuard;
|