@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/dist/crypto.js ADDED
@@ -0,0 +1,158 @@
1
+ import { namespaceHash } from './signaling.js';
2
+ const encoder = new TextEncoder();
3
+ const decoder = new TextDecoder();
4
+ export const replayWindowMs = 60_000;
5
+ export const midTtlMs = replayWindowMs * 2;
6
+ export const maxMidLength = 64;
7
+ export const maxSeenMids = 2048;
8
+ export const errorCooldownMs = 15_000;
9
+ export const minBoxBytes = 28;
10
+ export const minBoxChars = 38;
11
+ export const maxBoxChars = 96 * 1024;
12
+ const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
13
+ function bytesToHex(bytes) {
14
+ let out = '';
15
+ for (let i = 0; i < bytes.length; i++) {
16
+ out += bytes[i].toString(16).padStart(2, '0');
17
+ }
18
+ return out;
19
+ }
20
+ /**
21
+ * Derive an AES-256-GCM signaling key and a domain-separated 128-bit hex `privateId`
22
+ * from a shared password using a single 256-bit PBKDF2-HMAC-SHA256 pass (100,000 iterations)
23
+ * followed by RFC 5869 HKDF-SHA256 expansion.
24
+ */
25
+ export async function deriveSignalingKeys(password, baseScope, insecureMessage = 'Password encryption requires a secure context (crypto.subtle)') {
26
+ const subtle = globalThis.crypto?.subtle;
27
+ if (!subtle)
28
+ throw new Error(insecureMessage);
29
+ const salt = encoder.encode('meshpost/1/' + namespaceHash(baseScope));
30
+ const pbkdf2Key = await subtle.importKey('raw', encoder.encode(password), 'PBKDF2', false, [
31
+ 'deriveBits'
32
+ ]);
33
+ const masterBits = await subtle.deriveBits({ name: 'PBKDF2', salt, iterations: 100_000, hash: 'SHA-256' }, pbkdf2Key, 256);
34
+ const hkdfKey = await subtle.importKey('raw', masterBits, 'HKDF', false, [
35
+ 'deriveKey',
36
+ 'deriveBits'
37
+ ]);
38
+ const emptySalt = new Uint8Array(0);
39
+ const [aeadKey, topicBits] = await Promise.all([
40
+ subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: emptySalt, info: encoder.encode('meshpost/1/aead') }, hkdfKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']),
41
+ subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: emptySalt, info: encoder.encode('meshpost/1/topic') }, hkdfKey, 128)
42
+ ]);
43
+ return {
44
+ aeadKey,
45
+ privateId: bytesToHex(new Uint8Array(topicBits))
46
+ };
47
+ }
48
+ export async function sealPayload(key, plain, aad) {
49
+ const iv = crypto.getRandomValues(new Uint8Array(12));
50
+ const cipher = new Uint8Array(await crypto.subtle.encrypt({ name: 'AES-GCM', iv, additionalData: encoder.encode(aad) }, key, plain.buffer instanceof ArrayBuffer
51
+ ? new Uint8Array(plain.buffer, plain.byteOffset, plain.byteLength)
52
+ : Uint8Array.from(plain)));
53
+ const out = new Uint8Array(12 + cipher.byteLength);
54
+ out.set(iv, 0);
55
+ out.set(cipher, 12);
56
+ return out;
57
+ }
58
+ export async function openPayload(key, boxed, aad) {
59
+ if (boxed.byteLength < minBoxBytes)
60
+ return null;
61
+ try {
62
+ const iv = Uint8Array.from(boxed.subarray(0, 12));
63
+ const cipher = Uint8Array.from(boxed.subarray(12));
64
+ return new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv, additionalData: encoder.encode(aad) }, key, cipher));
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ }
70
+ export async function sealEnvelope(key, envelope, aad) {
71
+ return sealPayload(key, encoder.encode(JSON.stringify(envelope)), aad);
72
+ }
73
+ export async function openEnvelope(key, boxed, aad) {
74
+ const plain = await openPayload(key, boxed, aad);
75
+ if (!plain)
76
+ return null;
77
+ try {
78
+ const parsed = JSON.parse(decoder.decode(plain));
79
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
80
+ ? parsed
81
+ : null;
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ }
87
+ export function toBase64Url(bytes) {
88
+ const chunkSize = 0x8000;
89
+ let binary = '';
90
+ for (let i = 0; i < bytes.length; i += chunkSize) {
91
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunkSize));
92
+ }
93
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
94
+ }
95
+ export function fromBase64Url(value, maxChars = maxBoxChars) {
96
+ if (typeof value !== 'string' ||
97
+ value.length < minBoxChars ||
98
+ value.length > maxChars ||
99
+ value.length % 4 === 1 ||
100
+ !base64UrlPattern.test(value)) {
101
+ return null;
102
+ }
103
+ try {
104
+ const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
105
+ const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
106
+ const binary = atob(padded);
107
+ if (binary.length < minBoxBytes)
108
+ return null;
109
+ const out = new Uint8Array(binary.length);
110
+ for (let i = 0; i < binary.length; i++)
111
+ out[i] = binary.charCodeAt(i);
112
+ return out;
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ }
118
+ export function createReplayGuard() {
119
+ const seenMids = new Map();
120
+ const recordMid = (scopedMid, now = Date.now()) => {
121
+ const prev = seenMids.get(scopedMid);
122
+ if (prev !== undefined && now - prev < midTtlMs)
123
+ return false;
124
+ if (seenMids.size >= maxSeenMids) {
125
+ for (const [key, at] of seenMids) {
126
+ if (now - at >= midTtlMs || seenMids.size >= maxSeenMids) {
127
+ seenMids.delete(key);
128
+ if (seenMids.size < maxSeenMids)
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ seenMids.delete(scopedMid);
134
+ seenMids.set(scopedMid, now);
135
+ return true;
136
+ };
137
+ return {
138
+ recordMid,
139
+ checkAuthenticated(from, data, now = Date.now()) {
140
+ if (typeof data.mid !== 'string' ||
141
+ data.mid.length === 0 ||
142
+ data.mid.length > maxMidLength ||
143
+ typeof data.ts !== 'number' ||
144
+ !Number.isFinite(data.ts)) {
145
+ return 'invalid';
146
+ }
147
+ if (Math.abs(now - data.ts) > replayWindowMs)
148
+ return 'clock-skew';
149
+ return recordMid(from + ':' + data.mid, now) ? 'ok' : 'replay';
150
+ },
151
+ prune(now = Date.now()) {
152
+ for (const [mid, at] of seenMids) {
153
+ if (now - at >= midTtlMs)
154
+ seenMids.delete(mid);
155
+ }
156
+ }
157
+ };
158
+ }
@@ -0,0 +1,45 @@
1
+ export interface CreateIdentityOptions {
2
+ /**
3
+ * Whether the private ECDSA key can be exported via `exportIdentity()`.
4
+ * Pass `false` when using non-extractable session or process identities.
5
+ * @default true
6
+ */
7
+ extractable?: boolean;
8
+ }
9
+ export interface PeerIdentity {
10
+ /**
11
+ * Deterministic 22-character base64url identifier (`[A-Za-z0-9_-]{22}`):
12
+ * the first 128 bits (16 bytes) of `SHA-256("meshpost/1/userid:" || rawUncompressedPublicKey65B)`.
13
+ */
14
+ readonly userId: string;
15
+ /**
16
+ * Base64url-encoded 65-byte uncompressed P-256 public key (`0x04 || X(32B) || Y(32B)`, 87 chars).
17
+ */
18
+ readonly publicKey: string;
19
+ }
20
+ export interface SerializedIdentity {
21
+ readonly v: 1;
22
+ readonly crv: 'P-256';
23
+ /** 32-byte canonical base64url X coordinate (43 chars). */
24
+ readonly x: string;
25
+ /** 32-byte canonical base64url Y coordinate (43 chars). */
26
+ readonly y: string;
27
+ /** 32-byte canonical base64url private scalar (43 chars). */
28
+ readonly d: string;
29
+ }
30
+ /**
31
+ * Generate a fresh WebCrypto `ECDSA P-256` peer identity with a deterministic 128-bit `userId`.
32
+ */
33
+ export declare function createIdentity(options?: CreateIdentityOptions): Promise<PeerIdentity>;
34
+ /**
35
+ * Serialize an extractable `PeerIdentity` to a compact, JSON-safe object suitable for `localStorage`.
36
+ */
37
+ export declare function exportIdentity(identity: PeerIdentity): Promise<SerializedIdentity>;
38
+ /**
39
+ * Type guard checking whether an unknown JSON value has the canonical `SerializedIdentity` shape.
40
+ */
41
+ export declare function isSerializedIdentity(value: unknown): value is SerializedIdentity;
42
+ /**
43
+ * Import and cryptographically self-verify a `SerializedIdentity` (`(x, y)` verified against `d`).
44
+ */
45
+ export declare function importIdentity(data: unknown, options?: CreateIdentityOptions): Promise<PeerIdentity>;
@@ -0,0 +1,264 @@
1
+ import { toBase64Url } from './crypto.js';
2
+ const encoder = new TextEncoder();
3
+ const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
4
+ const userIdDomainPrefix = encoder.encode('meshpost/1/userid:');
5
+ const dtlsFingerprintLinePattern = /^a=fingerprint:(sha-256|sha-384|sha-512)\s+([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2})+)\s*$/i;
6
+ const expectedFingerprintHexLength = {
7
+ 'sha-256': 32 * 3 - 1,
8
+ 'sha-384': 48 * 3 - 1,
9
+ 'sha-512': 64 * 3 - 1
10
+ };
11
+ const identityInternals = new WeakMap();
12
+ /** @internal */
13
+ export function decodeCanonicalBase64Url(value, expectedChars, expectedBytes) {
14
+ if (typeof value !== 'string' ||
15
+ value.length !== expectedChars ||
16
+ !base64UrlPattern.test(value)) {
17
+ return null;
18
+ }
19
+ try {
20
+ const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
21
+ const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
22
+ const binary = atob(padded);
23
+ if (binary.length !== expectedBytes)
24
+ return null;
25
+ const out = new Uint8Array(expectedBytes);
26
+ for (let i = 0; i < expectedBytes; i++)
27
+ out[i] = binary.charCodeAt(i);
28
+ return toBase64Url(out) === value ? out : null;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ async function deriveUserIdFromRawPublicKey(subtle, rawPub) {
35
+ const input = new Uint8Array(userIdDomainPrefix.byteLength + rawPub.byteLength);
36
+ input.set(userIdDomainPrefix, 0);
37
+ input.set(rawPub, userIdDomainPrefix.byteLength);
38
+ const digest = new Uint8Array(await subtle.digest('SHA-256', input));
39
+ return toBase64Url(digest.subarray(0, 16));
40
+ }
41
+ function parseExtractableOption(options) {
42
+ if (options === undefined)
43
+ return true;
44
+ if (!options || typeof options !== 'object' || Array.isArray(options)) {
45
+ throw new TypeError('Invalid identity options');
46
+ }
47
+ const { extractable } = options;
48
+ if (extractable !== undefined && typeof extractable !== 'boolean') {
49
+ throw new TypeError('Invalid extractable option');
50
+ }
51
+ return extractable ?? true;
52
+ }
53
+ function requireSubtleCrypto() {
54
+ const subtle = globalThis.crypto?.subtle;
55
+ if (!subtle) {
56
+ throw new Error('Peer identity requires a secure context (crypto.subtle)');
57
+ }
58
+ return subtle;
59
+ }
60
+ /**
61
+ * Generate a fresh WebCrypto `ECDSA P-256` peer identity with a deterministic 128-bit `userId`.
62
+ */
63
+ export async function createIdentity(options) {
64
+ const extractable = parseExtractableOption(options);
65
+ const subtle = requireSubtleCrypto();
66
+ const pair = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, extractable, [
67
+ 'sign',
68
+ 'verify'
69
+ ]);
70
+ const rawPub = new Uint8Array(await subtle.exportKey('raw', pair.publicKey));
71
+ const userId = await deriveUserIdFromRawPublicKey(subtle, rawPub);
72
+ const identity = Object.freeze({
73
+ userId,
74
+ publicKey: toBase64Url(rawPub)
75
+ });
76
+ identityInternals.set(identity, { privateKey: pair.privateKey, extractable });
77
+ return identity;
78
+ }
79
+ /**
80
+ * Serialize an extractable `PeerIdentity` to a compact, JSON-safe object suitable for `localStorage`.
81
+ */
82
+ export async function exportIdentity(identity) {
83
+ const internals = typeof identity === 'object' && identity !== null ? identityInternals.get(identity) : undefined;
84
+ if (!internals)
85
+ throw new TypeError('Expected a valid PeerIdentity');
86
+ if (!internals.extractable)
87
+ throw new Error('Identity is not extractable');
88
+ const subtle = requireSubtleCrypto();
89
+ const jwk = await subtle.exportKey('jwk', internals.privateKey);
90
+ if (typeof jwk.x !== 'string' ||
91
+ typeof jwk.y !== 'string' ||
92
+ typeof jwk.d !== 'string' ||
93
+ decodeCanonicalBase64Url(jwk.x, 43, 32) === null ||
94
+ decodeCanonicalBase64Url(jwk.y, 43, 32) === null ||
95
+ decodeCanonicalBase64Url(jwk.d, 43, 32) === null) {
96
+ throw new Error('Failed to export valid P-256 key material');
97
+ }
98
+ return Object.freeze({
99
+ v: 1,
100
+ crv: 'P-256',
101
+ x: jwk.x,
102
+ y: jwk.y,
103
+ d: jwk.d
104
+ });
105
+ }
106
+ /**
107
+ * Type guard checking whether an unknown JSON value has the canonical `SerializedIdentity` shape.
108
+ */
109
+ export function isSerializedIdentity(value) {
110
+ if (!value || typeof value !== 'object' || Array.isArray(value))
111
+ return false;
112
+ const rec = value;
113
+ return (rec.v === 1 &&
114
+ rec.crv === 'P-256' &&
115
+ decodeCanonicalBase64Url(rec.x, 43, 32) !== null &&
116
+ decodeCanonicalBase64Url(rec.y, 43, 32) !== null &&
117
+ decodeCanonicalBase64Url(rec.d, 43, 32) !== null);
118
+ }
119
+ /**
120
+ * Import and cryptographically self-verify a `SerializedIdentity` (`(x, y)` verified against `d`).
121
+ */
122
+ export async function importIdentity(data, options) {
123
+ const extractable = parseExtractableOption(options);
124
+ if (!isSerializedIdentity(data)) {
125
+ throw new TypeError('Invalid serialized identity');
126
+ }
127
+ const subtle = requireSubtleCrypto();
128
+ const xBytes = decodeCanonicalBase64Url(data.x, 43, 32);
129
+ const yBytes = decodeCanonicalBase64Url(data.y, 43, 32);
130
+ if (!xBytes || !yBytes) {
131
+ throw new TypeError('Invalid serialized identity');
132
+ }
133
+ const rawCandidate = new Uint8Array(65);
134
+ rawCandidate[0] = 0x04;
135
+ rawCandidate.set(xBytes, 1);
136
+ rawCandidate.set(yBytes, 33);
137
+ try {
138
+ const [privateKey, publicKey] = await Promise.all([
139
+ subtle.importKey('jwk', {
140
+ kty: 'EC',
141
+ crv: 'P-256',
142
+ x: data.x,
143
+ y: data.y,
144
+ d: data.d,
145
+ key_ops: ['sign'],
146
+ ext: extractable
147
+ }, { name: 'ECDSA', namedCurve: 'P-256' }, extractable, ['sign']),
148
+ subtle.importKey('raw', rawCandidate, { name: 'ECDSA', namedCurve: 'P-256' }, true, [
149
+ 'verify'
150
+ ])
151
+ ]);
152
+ const challenge = crypto.getRandomValues(new Uint8Array(16));
153
+ const sig = await subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, privateKey, challenge);
154
+ const consistent = await subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, publicKey, sig, challenge);
155
+ if (!consistent)
156
+ throw new Error('Invalid identity keypair');
157
+ const rawPub = new Uint8Array(await subtle.exportKey('raw', publicKey));
158
+ const userId = await deriveUserIdFromRawPublicKey(subtle, rawPub);
159
+ const identity = Object.freeze({
160
+ userId,
161
+ publicKey: toBase64Url(rawPub)
162
+ });
163
+ identityInternals.set(identity, { privateKey, extractable });
164
+ return identity;
165
+ }
166
+ catch {
167
+ throw new Error('Invalid identity keypair');
168
+ }
169
+ }
170
+ /** @internal */
171
+ export function isValidPeerIdentity(value) {
172
+ return typeof value === 'object' && value !== null && identityInternals.has(value);
173
+ }
174
+ /**
175
+ * Extract the single canonical DTLS certificate fingerprint from an SDP description.
176
+ * Rejects weak hashes (`sha-1`, `md5`), malformed `a=fingerprint:` lines, and RFC 8122 §5
177
+ * multi-fingerprint MitM injections (`unique.size !== 1`).
178
+ * @internal
179
+ */
180
+ export function extractUniqueDtlsFingerprint(sdp) {
181
+ if (typeof sdp !== 'string' || sdp.length === 0)
182
+ return null;
183
+ const unique = new Set();
184
+ const lines = sdp.split(/\r?\n/);
185
+ for (const line of lines) {
186
+ if (!line.startsWith('a=fingerprint:'))
187
+ continue;
188
+ const match = dtlsFingerprintLinePattern.exec(line);
189
+ if (!match)
190
+ return null;
191
+ const algo = match[1].toLowerCase();
192
+ const hex = match[2].toUpperCase();
193
+ if (hex.length !== expectedFingerprintHexLength[algo])
194
+ return null;
195
+ unique.add(`${algo} ${hex}`);
196
+ }
197
+ return unique.size === 1 ? [...unique][0] : null;
198
+ }
199
+ function buildIdentityTranscript(params) {
200
+ const fields = [
201
+ params.appId,
202
+ params.room,
203
+ params.signerId,
204
+ params.verifierId,
205
+ params.signerFp,
206
+ params.verifierFp
207
+ ];
208
+ let text = 'meshpost/1/id-sig\0';
209
+ for (const field of fields) {
210
+ text += `${field.length}:${field}\n`;
211
+ }
212
+ return encoder.encode(text);
213
+ }
214
+ /** @internal */
215
+ export async function signIdentityProof(identity, params) {
216
+ const internals = identityInternals.get(identity);
217
+ if (!internals)
218
+ throw new TypeError('Expected a valid PeerIdentity');
219
+ const subtle = requireSubtleCrypto();
220
+ const transcript = buildIdentityTranscript(params);
221
+ const sig = new Uint8Array(await subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, internals.privateKey, transcript.buffer instanceof ArrayBuffer
222
+ ? new Uint8Array(transcript.buffer, transcript.byteOffset, transcript.byteLength)
223
+ : Uint8Array.from(transcript)));
224
+ return {
225
+ pub: identity.publicKey,
226
+ sig: toBase64Url(sig)
227
+ };
228
+ }
229
+ /** @internal */
230
+ export async function verifyIdentityProof(proof, params) {
231
+ const subtle = globalThis.crypto?.subtle;
232
+ if (!subtle)
233
+ return null;
234
+ const rawPub = decodeCanonicalBase64Url(proof.pub, 87, 65);
235
+ if (!rawPub || rawPub[0] !== 0x04)
236
+ return null;
237
+ const rawSig = decodeCanonicalBase64Url(proof.sig, 86, 64);
238
+ if (!rawSig)
239
+ return null;
240
+ try {
241
+ const publicKey = await subtle.importKey('raw', Uint8Array.from(rawPub), { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify']);
242
+ const transcript = buildIdentityTranscript(params);
243
+ const ok = await subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, publicKey, Uint8Array.from(rawSig), Uint8Array.from(transcript));
244
+ if (!ok)
245
+ return null;
246
+ return await deriveUserIdFromRawPublicKey(subtle, rawPub);
247
+ }
248
+ catch {
249
+ return null;
250
+ }
251
+ }
252
+ /** @internal */
253
+ export async function sha256Base64Url(input) {
254
+ const subtle = globalThis.crypto?.subtle;
255
+ if (!subtle)
256
+ return null;
257
+ try {
258
+ const digest = await subtle.digest('SHA-256', encoder.encode(input));
259
+ return toBase64Url(new Uint8Array(digest));
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ }
package/dist/index.d.ts CHANGED
@@ -1,16 +1,28 @@
1
1
  export { defaultIceServers, joinRoom } from './room.js';
2
- export type { Delivery, ListenOptions, PeerRoute, PeerStats, Room, RoomError, RoomErrorCode, RoomOptions, SendOptions, SendResult } from './room.js';
3
- export { createChannel } from './channel.js';
4
- export type { Channel, ChannelOptions, ChannelSendOptions } from './channel.js';
2
+ export { createIdentity, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
3
+ export type { CreateIdentityOptions, PeerIdentity, SerializedIdentity } from './identity.js';
4
+ export type { AddStreamOptions, Delivery, ListenOptions, PeerRoute, PeerStats, PeerStreamMeta, RemoveStreamOptions, Room, RoomError, RoomErrorCode, RoomOptions, RTCPeerConnectionConstructor, SendOptions, SendResult } from './room.js';
5
+ export { binaryCodec, createChannel, createCodecChannel, jsonCodec, textCodec } from './channel.js';
6
+ export type { Channel, ChannelOptions, ChannelSendOptions, Codec, CodecChannel } from './channel.js';
7
+ export { createRpc, RpcError } from './rpc.js';
8
+ export type { RpcCallOptions, RpcEndpoint, RpcErrorCode, RpcOptions } from './rpc.js';
9
+ export { createPeerState } from './state.js';
10
+ export type { PeerState, PeerStateOptions } from './state.js';
5
11
  export { createBlobChannel } from './blob.js';
6
12
  export type { BlobChannel, BlobChannelOptions, BlobProgress, BlobSendOptions, BlobSendStatus } from './blob.js';
13
+ export { createVoice } from './voice.js';
14
+ export type { MicError, MicErrorCode, MicStatus, Voice, VoiceOptions, VoiceSnapshot } from './voice.js';
15
+ export { fetchTurnCredentials } from './turn.js';
16
+ export type { FetchTurnOptions } from './turn.js';
7
17
  export { tabSignaling } from './tabs.js';
8
18
  export { manualSignaling } from './manual.js';
9
19
  export type { ManualSignaling } from './manual.js';
10
20
  export { defaultMqttRelays, mqttSignaling } from './mqtt.js';
11
21
  export type { MqttSignalingOptions } from './mqtt.js';
22
+ export { defaultNostrRelays, nostrSignaling } from './nostr.js';
23
+ export type { NostrSignalingOptions } from './nostr.js';
12
24
  export { wsSignaling } from './ws.js';
13
25
  export type { WsSignalingOptions } from './ws.js';
14
- export { combineSignaling } from './combine.js';
26
+ export { combineSignaling, withLocalTabs } from './combine.js';
15
27
  export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
16
- export type { Discovery, IceCandidatePayload, Signal, Signaling, SignalingErrorCode, SignalingSession, SignalingState } from './signaling.js';
28
+ export type { Discovery, IceCandidatePayload, Signal, Signaling, SignalingErrorCode, SignalingSession, SignalingState, WebSocketConstructor } from './signaling.js';
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  export { defaultIceServers, joinRoom } from './room.js';
2
- export { createChannel } from './channel.js';
2
+ export { createIdentity, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
3
+ export { binaryCodec, createChannel, createCodecChannel, jsonCodec, textCodec } from './channel.js';
4
+ export { createRpc, RpcError } from './rpc.js';
5
+ export { createPeerState } from './state.js';
3
6
  export { createBlobChannel } from './blob.js';
7
+ export { createVoice } from './voice.js';
8
+ export { fetchTurnCredentials } from './turn.js';
4
9
  export { tabSignaling } from './tabs.js';
5
10
  export { manualSignaling } from './manual.js';
6
11
  export { defaultMqttRelays, mqttSignaling } from './mqtt.js';
12
+ export { defaultNostrRelays, nostrSignaling } from './nostr.js';
7
13
  export { wsSignaling } from './ws.js';
8
- export { combineSignaling } from './combine.js';
14
+ export { combineSignaling, withLocalTabs } from './combine.js';
9
15
  export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
package/dist/mqtt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Signaling } from './signaling.js';
1
+ import { type Signaling, type WebSocketConstructor } from './signaling.js';
2
2
  /** Built-in public MQTT-over-WebSocket relay URLs used by default. */
3
3
  export declare const defaultMqttRelays: readonly string[];
4
4
  export interface MqttSignalingOptions {
@@ -8,8 +8,16 @@ export interface MqttSignalingOptions {
8
8
  appId?: string;
9
9
  /** Optional shared password to encrypt signaling payloads with AES-256-GCM (requires secure context). */
10
10
  password?: string;
11
+ /**
12
+ * Derive the MQTT room topic cryptographically from `password` so room activity is hidden from outsiders
13
+ * (disables `'decrypt-failed'` detection when a peer enters the wrong password).
14
+ * @default false
15
+ */
16
+ privateTopic?: boolean;
11
17
  /** Maximum time in milliseconds to wait for CONNECT -> CONNACK -> SUBACK per broker. @default 10000 */
12
18
  handshakeTimeoutMs?: number;
19
+ /** Optional custom `WebSocket` constructor for headless runtimes or custom transports. */
20
+ WebSocket?: WebSocketConstructor;
13
21
  }
14
22
  /**
15
23
  * Zero-backend signaling over public (or custom) MQTT-over-WebSocket brokers.