@johnhenry/browsermesh-core 0.7.0 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-core",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Identity, crypto, peer management, and trust primitives for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "directory": "packages/browsermesh-core"
21
21
  },
22
22
  "peerDependencies": {
23
- "@johnhenry/browsermesh-primitives": ">=0.2.0 <1.0.0",
23
+ "@johnhenry/browsermesh-primitives": ">=0.3.0 <1.0.0",
24
24
  "@johnhenry/browsermesh-apps": ">=0.4.0 <1.0.0"
25
25
  },
26
26
  "peerDependenciesMeta": {
@@ -13,17 +13,7 @@
13
13
  * node --import ./web/test/_setup-globals.mjs --test web/test/clawser-mesh-group-keys.test.mjs
14
14
  */
15
15
 
16
- // Namespace import, not `import { padTo, unpad }`: padding needs primitives >= 0.3.0,
17
- // but this package's peer range still admits 0.2.x, and a missing named export
18
- // would fail to link (breaking all of core) instead of only breaking `padding`.
19
- import * as primitives from '@johnhenry/browsermesh-primitives'
20
-
21
- function paddingFns() {
22
- if (typeof primitives.padTo !== 'function' || typeof primitives.unpad !== 'function') {
23
- throw new Error('padding requires @johnhenry/browsermesh-primitives >= 0.3.0')
24
- }
25
- return primitives
26
- }
16
+ import { padTo, unpad } from '@johnhenry/browsermesh-primitives'
27
17
 
28
18
  // ---------------------------------------------------------------------------
29
19
  // Wire constants
@@ -545,7 +535,7 @@ export class GroupKeyManager {
545
535
  if (!state || !state.key) throw new Error('No active group key')
546
536
 
547
537
  const pad = padding === undefined ? this.#padding : normalizePadding(padding)
548
- const sealed = pad ? paddingFns().padTo(plaintext, pad) : plaintext
538
+ const sealed = pad ? padTo(plaintext, pad) : plaintext
549
539
 
550
540
  const iv = crypto.getRandomValues(new Uint8Array(12))
551
541
  const ciphertext = new Uint8Array(
@@ -584,7 +574,7 @@ export class GroupKeyManager {
584
574
  )
585
575
 
586
576
  const pad = padding === undefined ? this.#padding : normalizePadding(padding)
587
- return pad ? paddingFns().unpad(plaintext) : plaintext
577
+ return pad ? unpad(plaintext) : plaintext
588
578
  }
589
579
 
590
580
  /**
package/src/handshake.mjs CHANGED
@@ -282,25 +282,28 @@ export class SignalingClient {
282
282
  /**
283
283
  * Register callback for incoming SDP offers.
284
284
  * @param {Function} cb - Receives (offer, fromPodId)
285
+ * @returns {() => void} Unsubscribe
285
286
  */
286
287
  onOffer(cb) {
287
- this.on('offer', cb)
288
+ return this.on('offer', cb)
288
289
  }
289
290
 
290
291
  /**
291
292
  * Register callback for incoming SDP answers.
292
293
  * @param {Function} cb - Receives (answer, fromPodId)
294
+ * @returns {() => void} Unsubscribe
293
295
  */
294
296
  onAnswer(cb) {
295
- this.on('answer', cb)
297
+ return this.on('answer', cb)
296
298
  }
297
299
 
298
300
  /**
299
301
  * Register callback for incoming ICE candidates.
300
302
  * @param {Function} cb - Receives (candidate, fromPodId)
303
+ * @returns {() => void} Unsubscribe
301
304
  */
302
305
  onIceCandidate(cb) {
303
- this.on('ice-candidate', cb)
306
+ return this.on('ice-candidate', cb)
304
307
  }
305
308
 
306
309
  // -- Generic send / event system ------------------------------------------
@@ -339,12 +342,14 @@ export class SignalingClient {
339
342
  * Register a listener for a given event type.
340
343
  * @param {string} event
341
344
  * @param {Function} cb
345
+ * @returns {() => void} Unsubscribe (same as `off(event, cb)`)
342
346
  */
343
347
  on(event, cb) {
344
348
  if (!this.#listeners.has(event)) {
345
349
  this.#listeners.set(event, new Set())
346
350
  }
347
351
  this.#listeners.get(event).add(cb)
352
+ return () => this.off(event, cb)
348
353
  }
349
354
 
350
355
  /**