@johnhenry/browsermesh-core 0.10.0 → 0.11.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/README.md +16 -1
- package/package.json +1 -1
- package/src/acl.mjs +3 -3
- package/src/capabilities.mjs +3 -3
- package/src/compat.mjs +4 -3
- package/src/group-keys.mjs +2 -2
- package/src/handshake.mjs +7 -7
- package/src/hardening.mjs +8 -8
- package/src/identity-base.mjs +1 -1
- package/src/identity-tools.mjs +3 -3
- package/src/identity-wallet.mjs +2 -2
- package/src/identity.mjs +5 -5
- package/src/keyring.mjs +133 -21
- package/src/peer-tools.mjs +2 -2
- package/src/peer.mjs +2 -2
- package/src/silent-catch.mjs +21 -9
- package/src/trust.mjs +2 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ Identity, crypto, peer management, and trust primitives for BrowserMesh.
|
|
|
17
17
|
|
|
18
18
|
## Provenance
|
|
19
19
|
|
|
20
|
-
Extracted from
|
|
20
|
+
Extracted from a private monorepo (previously `packages/browsermesh-core`), where it was manually published to npm, unscoped, as `browsermesh-core@0.1.0` (2026-07-17) with no CI ever automating that publish. This is its first release as part of the `@johnhenry/browsermesh` monorepo; the version restarts at `0.0.0` per family convention.
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
## Modules
|
|
@@ -64,6 +64,21 @@ import { MeshIdentityManager, MeshKeyring, TrustGraph } from '@johnhenry/browser
|
|
|
64
64
|
- Revoke an edge with `SignedKeyUnlink.create(parentIdentity, childId)` and
|
|
65
65
|
`keyring.applyUnlink(unlink, parentPub)`. Unlinks serialise, can be relayed
|
|
66
66
|
to peers, and cut off every descendant of the child. `unlink()` is local only.
|
|
67
|
+
- A `SignedKeyUnlink` REQUIRES a signed `expires` (ms epoch, like
|
|
68
|
+
`SignedKeyLink`): `SignedKeyUnlink.create(p, childId, { expires })` throws
|
|
69
|
+
without one, or use `SignedKeyUnlink.forLink(parentIdentity, link)`, which
|
|
70
|
+
copies the link's expiry and namespace (pass `{ expires }` for a link that
|
|
71
|
+
never expires). It signs `"browsermesh/keyunlink/v2\n"` + canonical JSON.
|
|
72
|
+
**v1 unlinks (no `expires`) are no longer accepted**: `verify` is false,
|
|
73
|
+
`applyUnlink` throws, and `MeshKeyring.fromJSON` drops them (listed with a
|
|
74
|
+
reason in `keyring.droppedRevocations`). Once an unlink expires the keyring
|
|
75
|
+
stops counting it: `listRevocations({ now })`, `toJSON()` and `fromJSON()`
|
|
76
|
+
drop it, `pruneRevocations(now)` drops them explicitly and returns the
|
|
77
|
+
count, and `applyUnlink` records nothing for an already-expired one. Rule:
|
|
78
|
+
an unlink should expire no earlier than the link it revokes (what `forLink`
|
|
79
|
+
does). If it expires sooner, the revocation lapses and a stale copy of the
|
|
80
|
+
link is accepted again, but only while the link itself is unexpired;
|
|
81
|
+
`verifyCryptoChain` always refuses an expired link.
|
|
67
82
|
- `executeSuccession(primary, { links, getPublicKey })` with a `transfer`
|
|
68
83
|
policy needs successor-signed replacement links (`{ localOnly: true }` keeps
|
|
69
84
|
the old unsigned behaviour).
|
package/package.json
CHANGED
package/src/acl.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
// STATUS: INTEGRATED — wired into
|
|
3
|
-
*
|
|
2
|
+
// STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
|
|
3
|
+
* acl.mjs -- Remote access control for BrowserMesh.
|
|
4
4
|
*
|
|
5
5
|
* ScopeTemplate bundles, roster management, invitation tokens, and
|
|
6
6
|
* access checking. Wraps mesh-primitives ACLEngine with higher-level
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* No browser-only imports at module level.
|
|
10
10
|
*
|
|
11
11
|
* Run tests:
|
|
12
|
-
* node --import ./
|
|
12
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/acl.test.mjs
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {
|
package/src/capabilities.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
// STATUS: INTEGRATED — wired into
|
|
3
|
-
*
|
|
2
|
+
// STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
|
|
3
|
+
* capabilities.mjs -- Capability Attenuation & WASM Sandbox.
|
|
4
4
|
*
|
|
5
5
|
* Implements the object-capability (ocap) model for BrowserMesh:
|
|
6
6
|
*
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* No browser-only imports at module level.
|
|
15
15
|
*
|
|
16
16
|
* Run tests:
|
|
17
|
-
* node --import ./
|
|
17
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/capabilities.test.mjs
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { encodeBase64url, decodeBase64url } from '@johnhenry/browsermesh-primitives';
|
package/src/compat.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* compat.mjs -- BrowserTool shim for standalone use.
|
|
3
3
|
*
|
|
4
|
-
* In
|
|
4
|
+
* In the host application, BrowserTool is the base class for
|
|
5
|
+
* AI-agent-callable tools.
|
|
5
6
|
* Subclasses override name/description/parameters/permission as GETTERS
|
|
6
|
-
* (not constructor-assigned properties) — this shim mirrors that exactly
|
|
7
|
-
*
|
|
7
|
+
* (not constructor-assigned properties) — this shim mirrors that exactly.
|
|
8
|
+
* An earlier version of this shim tried to
|
|
8
9
|
* assign `this.name = ...` in the constructor, which threw
|
|
9
10
|
* "Cannot set property name of #<Tool> which has only a getter" for
|
|
10
11
|
* every real subclass, since none of them define a setter.
|
package/src/group-keys.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* group-keys.mjs -- Symmetric group encryption for multi-party sessions.
|
|
3
3
|
*
|
|
4
4
|
* Epoch-based key rotation with AES-GCM-256. Forward secrecy on member removal
|
|
5
5
|
* by generating a new epoch key and distributing it only to remaining members.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* No browser-only imports at module level.
|
|
11
11
|
*
|
|
12
12
|
* Run tests:
|
|
13
|
-
* node --import ./
|
|
13
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/group-keys.test.mjs
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { padTo, unpad } from '@johnhenry/browsermesh-primitives'
|
package/src/handshake.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { silentCatch } from './silent-catch.mjs'
|
|
2
2
|
/**
|
|
3
|
-
// STATUS: INTEGRATED — wired into
|
|
4
|
-
*
|
|
3
|
+
// STATUS: INTEGRATED — wired into Pod (@johnhenry/browsermesh-pod) lifecycle, proven via E2E testing
|
|
4
|
+
* handshake.mjs -- Connection Handshake Protocol.
|
|
5
5
|
*
|
|
6
6
|
* Coordinates signaling, direct input exchange (QR + clipboard), and
|
|
7
7
|
* session establishment between two mesh peers.
|
|
@@ -22,7 +22,7 @@ import { silentCatch } from './silent-catch.mjs'
|
|
|
22
22
|
* via constructor.
|
|
23
23
|
*
|
|
24
24
|
* Run tests:
|
|
25
|
-
* node --import ./
|
|
25
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/handshake.test.mjs
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
// ---------------------------------------------------------------------------
|
|
@@ -240,7 +240,7 @@ export class SignalingClient {
|
|
|
240
240
|
this.#ws.removeEventListener('message', this.#handleMessage)
|
|
241
241
|
this.#ws.removeEventListener('close', this.#handleClose)
|
|
242
242
|
this.#ws.close()
|
|
243
|
-
} catch (e) { silentCatch('
|
|
243
|
+
} catch (e) { silentCatch('handshake', 'ignore-close-errors', e) }
|
|
244
244
|
this.#ws = null
|
|
245
245
|
this.#onLog(2, 'SignalingClient disconnected')
|
|
246
246
|
}
|
|
@@ -370,7 +370,7 @@ export class SignalingClient {
|
|
|
370
370
|
const data = typeof ev.data === 'string' ? JSON.parse(ev.data) : ev.data
|
|
371
371
|
if (!data || !data.type) return
|
|
372
372
|
this.#fire(data.type, data)
|
|
373
|
-
} catch (e) { silentCatch('
|
|
373
|
+
} catch (e) { silentCatch('handshake', 'ignore-malformed-messages', e) }
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
/** @type {() => void} */
|
|
@@ -398,7 +398,7 @@ export class SignalingClient {
|
|
|
398
398
|
// direct server messages (e.g. `registered`) that have no `source`.
|
|
399
399
|
const fromPodId = data.source ?? data.from
|
|
400
400
|
for (const cb of set) {
|
|
401
|
-
try { cb(data, fromPodId) } catch (e) { silentCatch('
|
|
401
|
+
try { cb(data, fromPodId) } catch (e) { silentCatch('handshake', 'swallow-listener-errors', e) }
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
}
|
|
@@ -1256,7 +1256,7 @@ export class HandshakeCoordinator {
|
|
|
1256
1256
|
const set = this.#listeners.get(event)
|
|
1257
1257
|
if (!set) return
|
|
1258
1258
|
for (const cb of set) {
|
|
1259
|
-
try { cb(data) } catch (e) { silentCatch('
|
|
1259
|
+
try { cb(data) } catch (e) { silentCatch('handshake', 'swallow-listener-errors', e) }
|
|
1260
1260
|
}
|
|
1261
1261
|
}
|
|
1262
1262
|
}
|
package/src/hardening.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { silentCatch } from './silent-catch.mjs'
|
|
2
2
|
/**
|
|
3
3
|
// STATUS: EXPERIMENTAL — production hardening for BrowserMesh transports
|
|
4
|
-
*
|
|
4
|
+
* hardening.mjs -- Production Hardening Layer.
|
|
5
5
|
*
|
|
6
6
|
* Additive hardening primitives that compose with existing MeshTransport
|
|
7
7
|
* and MeshTransportNegotiator without breaking backward compatibility.
|
|
@@ -14,7 +14,7 @@ import { silentCatch } from './silent-catch.mjs'
|
|
|
14
14
|
* 5. TransportFailover — graceful degradation across transport types
|
|
15
15
|
*
|
|
16
16
|
* Run tests:
|
|
17
|
-
* node --import ./
|
|
17
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/hardening.test.mjs
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
// ---------------------------------------------------------------------------
|
|
@@ -463,7 +463,7 @@ export class TransportHealthCheck {
|
|
|
463
463
|
const set = this.#listeners.get(event);
|
|
464
464
|
if (!set) return;
|
|
465
465
|
for (const cb of [...set]) {
|
|
466
|
-
try { cb(data); } catch (e) { silentCatch('
|
|
466
|
+
try { cb(data); } catch (e) { silentCatch('hardening', 'swallow', e) }
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
}
|
|
@@ -563,7 +563,7 @@ export class ConnectionPool {
|
|
|
563
563
|
|
|
564
564
|
const evicted = entries.splice(idleIdx, 1)[0];
|
|
565
565
|
if (typeof evicted.transport.close === 'function') {
|
|
566
|
-
try { evicted.transport.close(); } catch (e) { silentCatch('
|
|
566
|
+
try { evicted.transport.close(); } catch (e) { silentCatch('hardening', 'evicted.transport.close', e) }
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
|
|
@@ -713,7 +713,7 @@ export class ConnectionPool {
|
|
|
713
713
|
const entry = entries[i];
|
|
714
714
|
if (!entry.acquired && (now - entry.lastUsed) > this.#idleTimeoutMs) {
|
|
715
715
|
if (typeof entry.transport.close === 'function') {
|
|
716
|
-
try { entry.transport.close(); } catch (e) { silentCatch('
|
|
716
|
+
try { entry.transport.close(); } catch (e) { silentCatch('hardening', 'entry.transport.close', e) }
|
|
717
717
|
}
|
|
718
718
|
entries.splice(i, 1);
|
|
719
719
|
evicted++;
|
|
@@ -734,7 +734,7 @@ export class ConnectionPool {
|
|
|
734
734
|
for (const [, entries] of this.#pools) {
|
|
735
735
|
for (const entry of entries) {
|
|
736
736
|
if (typeof entry.transport.close === 'function') {
|
|
737
|
-
try { entry.transport.close(); } catch (e) { silentCatch('
|
|
737
|
+
try { entry.transport.close(); } catch (e) { silentCatch('hardening', 'entry.transport.close', e) }
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
}
|
|
@@ -1119,7 +1119,7 @@ export class TransportFailover {
|
|
|
1119
1119
|
}
|
|
1120
1120
|
// Close the old transport
|
|
1121
1121
|
if (typeof this.#activeTransport.close === 'function') {
|
|
1122
|
-
try { this.#activeTransport.close(); } catch (e) { silentCatch('
|
|
1122
|
+
try { this.#activeTransport.close(); } catch (e) { silentCatch('hardening', 'this', e) }
|
|
1123
1123
|
}
|
|
1124
1124
|
this.#activeTransport = null;
|
|
1125
1125
|
}
|
|
@@ -1207,7 +1207,7 @@ export class TransportFailover {
|
|
|
1207
1207
|
const set = this.#listeners.get(event);
|
|
1208
1208
|
if (!set) return;
|
|
1209
1209
|
for (const cb of [...set]) {
|
|
1210
|
-
try { cb(data); } catch (e) { silentCatch('
|
|
1210
|
+
try { cb(data); } catch (e) { silentCatch('hardening', 'swallow', e) }
|
|
1211
1211
|
}
|
|
1212
1212
|
}
|
|
1213
1213
|
}
|
package/src/identity-base.mjs
CHANGED
package/src/identity-tools.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* identity-tools.mjs -- Identity BrowserTools for mesh.
|
|
3
3
|
*
|
|
4
4
|
* 8 BrowserTool subclasses for managing mesh identities via the agent.
|
|
5
|
-
* Follows the pattern in
|
|
5
|
+
* Follows the pattern in peer-tools.mjs.
|
|
6
6
|
*
|
|
7
7
|
* Run tests:
|
|
8
|
-
* node --import ./
|
|
8
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/identity-tools.test.mjs
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { BrowserTool } from './compat.mjs';
|
package/src/identity-wallet.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* identity-wallet.mjs -- High-level multi-identity wallet.
|
|
3
3
|
*
|
|
4
4
|
* Wraps MeshIdentityManager and IdentitySelector to provide a unified
|
|
5
5
|
* API for identity lifecycle, contact management, and access grants.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* No browser-only imports at module level.
|
|
8
8
|
*
|
|
9
9
|
* Run tests:
|
|
10
|
-
* node --import ./
|
|
10
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/identity-wallet.test.mjs
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
// ---------------------------------------------------------------------------
|
package/src/identity.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* identity.mjs -- Mesh identity management.
|
|
3
3
|
*
|
|
4
4
|
* Manages multiple Ed25519 cryptographic identities with vault-encrypted
|
|
5
5
|
* storage. Imports primitives from mesh-primitives; adds persistence,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Storage adapter pattern allows OPFS in browser, in-memory in tests.
|
|
10
10
|
*
|
|
11
11
|
* Run tests:
|
|
12
|
-
* node --import ./
|
|
12
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/identity.test.mjs
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { silentCatch } from './silent-catch.mjs'
|
|
@@ -1000,7 +1000,7 @@ export class VaultIdentityStorage {
|
|
|
1000
1000
|
encryptedPrivateKey: await encryptWithPassphrase(plaintext, passphrase, VAULT_TYPE),
|
|
1001
1001
|
});
|
|
1002
1002
|
} catch (err) {
|
|
1003
|
-
silentCatch('
|
|
1003
|
+
silentCatch('identity', 'vault-upgrade', err);
|
|
1004
1004
|
}
|
|
1005
1005
|
}
|
|
1006
1006
|
}
|
|
@@ -1145,7 +1145,7 @@ export class IdentitySyncCoordinator {
|
|
|
1145
1145
|
|
|
1146
1146
|
if (msg.type === 'created' || msg.type === 'deleted') {
|
|
1147
1147
|
for (const cb of this.#changeListeners) {
|
|
1148
|
-
try { cb(msg); } catch (e) { silentCatch('
|
|
1148
|
+
try { cb(msg); } catch (e) { silentCatch('identity', 'swallow', e) }
|
|
1149
1149
|
}
|
|
1150
1150
|
}
|
|
1151
1151
|
}
|
|
@@ -1257,7 +1257,7 @@ export class AutoIdentityManager {
|
|
|
1257
1257
|
this.#identityManager.setDefault(podId);
|
|
1258
1258
|
|
|
1259
1259
|
for (const cb of this.#switchListeners) {
|
|
1260
|
-
try { cb({ oldId, newId: podId }); } catch (e) { silentCatch('
|
|
1260
|
+
try { cb({ oldId, newId: podId }); } catch (e) { silentCatch('identity', 'swallow', e) }
|
|
1261
1261
|
}
|
|
1262
1262
|
}
|
|
1263
1263
|
|
package/src/keyring.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* keyring.mjs -- Key hierarchy and linking.
|
|
3
3
|
*
|
|
4
4
|
* Manages parent-child relationships between mesh identities
|
|
5
5
|
* (device, delegate, org, alias, recovery). Provides chain
|
|
@@ -35,7 +35,7 @@ export const VALID_RELATIONS = Object.freeze([
|
|
|
35
35
|
export const KEYLINK_DOMAIN = 'browsermesh/keylink/v3\n';
|
|
36
36
|
|
|
37
37
|
/** Domain prefix of the bytes a {@link SignedKeyUnlink} signs. */
|
|
38
|
-
export const KEYUNLINK_DOMAIN = 'browsermesh/keyunlink/
|
|
38
|
+
export const KEYUNLINK_DOMAIN = 'browsermesh/keyunlink/v2\n';
|
|
39
39
|
|
|
40
40
|
// ---------------------------------------------------------------------------
|
|
41
41
|
// KeyLink
|
|
@@ -348,8 +348,11 @@ export class SignedKeyLink extends KeyLink {
|
|
|
348
348
|
/**
|
|
349
349
|
* A signed, transferable revocation of the `parent -> child` edge.
|
|
350
350
|
*
|
|
351
|
-
* The parent signs `"browsermesh/keyunlink/
|
|
352
|
-
* `parent`, `child`, `namespace`, `created` and `
|
|
351
|
+
* The parent signs `"browsermesh/keyunlink/v2\n" ‖ canonical(body)` over
|
|
352
|
+
* `parent`, `child`, `namespace`, `created`, `reason` and `expires`.
|
|
353
|
+
* `expires` is REQUIRED (ms epoch): a revocation that cannot lapse is not
|
|
354
|
+
* supported, and v1 unlinks (no `expires`, domain `keyunlink/v1`) are no
|
|
355
|
+
* longer accepted anywhere. It revokes every
|
|
353
356
|
* link on that edge (in that namespace) created at or before `created`, so
|
|
354
357
|
* a re-link signed later by both parties is not affected, but replaying the
|
|
355
358
|
* old link is. Because authority flows down the chain, every descendant of
|
|
@@ -366,10 +369,17 @@ export class SignedKeyUnlink {
|
|
|
366
369
|
* @param {string|null} [opts.namespace]
|
|
367
370
|
* @param {number} [opts.created]
|
|
368
371
|
* @param {string|null} [opts.reason]
|
|
372
|
+
* @param {number|null} [opts.expires] - Optional expiry (ms epoch, same
|
|
373
|
+
* convention as `KeyLink#expires`), covered by the signature. After it
|
|
374
|
+
* the revocation is dropped by the keyring.
|
|
369
375
|
* @param {Uint8Array|null} [opts.signature]
|
|
370
376
|
*/
|
|
371
|
-
constructor({ parent, child, namespace, created, reason, signature }) {
|
|
377
|
+
constructor({ parent, child, namespace, created, reason, expires, signature }) {
|
|
372
378
|
if (!parent || !child) throw new Error('parent and child are required');
|
|
379
|
+
if (expires != null && !Number.isFinite(expires)) {
|
|
380
|
+
throw new TypeError('expires must be a finite number (ms epoch)');
|
|
381
|
+
}
|
|
382
|
+
this.expires = expires ?? null;
|
|
373
383
|
this.parent = parent;
|
|
374
384
|
this.child = child;
|
|
375
385
|
this.namespace = namespace ?? null;
|
|
@@ -378,7 +388,13 @@ export class SignedKeyUnlink {
|
|
|
378
388
|
this.signature = signature || null;
|
|
379
389
|
}
|
|
380
390
|
|
|
381
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* Signed bytes: the `keyunlink/v2` domain plus canonical JSON of every
|
|
393
|
+
* field including `expires`. The v2 domain means a v1 signature can never
|
|
394
|
+
* validate here, and a v2 signature is not a valid v1 message.
|
|
395
|
+
*
|
|
396
|
+
* @returns {Uint8Array}
|
|
397
|
+
*/
|
|
382
398
|
get signedPayload() {
|
|
383
399
|
return domainPayload(KEYUNLINK_DOMAIN, {
|
|
384
400
|
parent: this.parent,
|
|
@@ -386,39 +402,85 @@ export class SignedKeyUnlink {
|
|
|
386
402
|
namespace: this.namespace,
|
|
387
403
|
created: this.created,
|
|
388
404
|
reason: this.reason,
|
|
405
|
+
expires: this.expires,
|
|
389
406
|
});
|
|
390
407
|
}
|
|
391
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Whether this unlink's expiry has passed (`now >= expires`, as for links).
|
|
411
|
+
* @param {number} [now=Date.now()]
|
|
412
|
+
* @returns {boolean}
|
|
413
|
+
*/
|
|
414
|
+
isExpired(now = Date.now()) {
|
|
415
|
+
return this.expires !== null && now >= this.expires;
|
|
416
|
+
}
|
|
417
|
+
|
|
392
418
|
/**
|
|
393
419
|
* Create an unlink signed by the parent.
|
|
394
420
|
*
|
|
395
421
|
* @param {import('./identity.mjs').PodIdentity} parentIdentity
|
|
396
422
|
* @param {string} childId
|
|
397
|
-
* @param {{ namespace?: string, reason?: string, created?: number }} [opts]
|
|
423
|
+
* @param {{ namespace?: string, reason?: string, created?: number, expires?: number }} [opts]
|
|
398
424
|
* @returns {Promise<SignedKeyUnlink>}
|
|
399
425
|
*/
|
|
400
426
|
static async create(parentIdentity, childId, opts = {}) {
|
|
427
|
+
if (!Number.isFinite(opts.expires)) {
|
|
428
|
+
throw new TypeError('SignedKeyUnlink requires a signed expires (ms epoch)');
|
|
429
|
+
}
|
|
401
430
|
const unlink = new SignedKeyUnlink({
|
|
402
431
|
parent: parentIdentity.podId,
|
|
403
432
|
child: childId,
|
|
404
433
|
namespace: opts.namespace,
|
|
405
434
|
created: opts.created ?? Date.now(),
|
|
406
435
|
reason: opts.reason,
|
|
436
|
+
expires: opts.expires,
|
|
407
437
|
});
|
|
408
438
|
unlink.signature = await parentIdentity.sign(unlink.signedPayload);
|
|
409
439
|
return unlink;
|
|
410
440
|
}
|
|
411
441
|
|
|
442
|
+
/**
|
|
443
|
+
* Create an unlink for a known link: same child and namespace, and
|
|
444
|
+
* `expires` set to the link's expiry, so the revocation lives exactly as
|
|
445
|
+
* long as the link it revokes. A link that never expires needs an explicit
|
|
446
|
+
* `opts.expires` (throws otherwise). `opts` may also override `reason` and
|
|
447
|
+
* `created`.
|
|
448
|
+
*
|
|
449
|
+
* @param {import('./identity.mjs').PodIdentity} parentIdentity
|
|
450
|
+
* @param {KeyLink} link
|
|
451
|
+
* @param {{ reason?: string, created?: number, expires?: number }} [opts]
|
|
452
|
+
* @returns {Promise<SignedKeyUnlink>}
|
|
453
|
+
*/
|
|
454
|
+
static async forLink(parentIdentity, link, opts = {}) {
|
|
455
|
+
if (link.parent !== parentIdentity.podId) {
|
|
456
|
+
throw new Error('Link was not issued by this parent');
|
|
457
|
+
}
|
|
458
|
+
return SignedKeyUnlink.create(parentIdentity, link.child, {
|
|
459
|
+
namespace: link.namespace ?? undefined,
|
|
460
|
+
reason: opts.reason,
|
|
461
|
+
created: Math.max(opts.created ?? Date.now(), link.created),
|
|
462
|
+
expires: opts.expires ?? link.expires ?? undefined,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
|
|
412
466
|
/**
|
|
413
467
|
* Verify the parent's signature.
|
|
414
468
|
* @param {CryptoKey} parentPub
|
|
415
469
|
* @returns {Promise<boolean>}
|
|
416
470
|
*/
|
|
417
471
|
async verify(parentPub) {
|
|
418
|
-
if (!this.signature) return false;
|
|
472
|
+
if (!this.signature || !Number.isFinite(this.expires)) return false;
|
|
419
473
|
return crypto.subtle.verify('Ed25519', parentPub, this.signature, this.signedPayload);
|
|
420
474
|
}
|
|
421
475
|
|
|
476
|
+
/**
|
|
477
|
+
* Why this unlink cannot be used, or null if it is well formed.
|
|
478
|
+
* @returns {string|null}
|
|
479
|
+
*/
|
|
480
|
+
get defect() {
|
|
481
|
+
return Number.isFinite(this.expires) ? null : 'missing signed expires (v1 unlink)';
|
|
482
|
+
}
|
|
483
|
+
|
|
422
484
|
/**
|
|
423
485
|
* Whether this unlink revokes `link` (same edge and namespace, and the
|
|
424
486
|
* link was created at or before the unlink).
|
|
@@ -441,6 +503,7 @@ export class SignedKeyUnlink {
|
|
|
441
503
|
namespace: this.namespace,
|
|
442
504
|
created: this.created,
|
|
443
505
|
reason: this.reason,
|
|
506
|
+
expires: this.expires,
|
|
444
507
|
signature: this.signature ? encodeBase64url(this.signature) : null,
|
|
445
508
|
};
|
|
446
509
|
}
|
|
@@ -576,6 +639,8 @@ export class MeshKeyring {
|
|
|
576
639
|
|
|
577
640
|
/** @type {SignedKeyUnlink[]} */
|
|
578
641
|
#revocations = [];
|
|
642
|
+
/** @type {{ data: object, reason: string }[]} */
|
|
643
|
+
#dropped = [];
|
|
579
644
|
|
|
580
645
|
/** @type {*} */
|
|
581
646
|
#storage;
|
|
@@ -679,13 +744,40 @@ export class MeshKeyring {
|
|
|
679
744
|
// -- Revocation ---------------------------------------------------------
|
|
680
745
|
|
|
681
746
|
/**
|
|
682
|
-
* Whether a recorded {@link SignedKeyUnlink} revokes `link`.
|
|
747
|
+
* Whether a recorded, unexpired {@link SignedKeyUnlink} revokes `link`.
|
|
748
|
+
* An expired revocation no longer counts. If it expires before the link
|
|
749
|
+
* does, the link is live again; give the unlink an `expires` at least as
|
|
750
|
+
* late as the link's ({@link SignedKeyUnlink.forLink}). A link that is
|
|
751
|
+
* itself expired stays unusable regardless (`verifyCryptoChain` checks it).
|
|
683
752
|
*
|
|
684
753
|
* @param {KeyLink} link
|
|
754
|
+
* @param {number} [now=Date.now()]
|
|
685
755
|
* @returns {boolean}
|
|
686
756
|
*/
|
|
687
|
-
isRevoked(link) {
|
|
688
|
-
return this.#revocations.some((r) => r.revokes(link));
|
|
757
|
+
isRevoked(link, now = Date.now()) {
|
|
758
|
+
return this.#revocations.some((r) => !r.isExpired(now) && r.revokes(link));
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Revocations `fromJSON` refused to restore (v1 / expiry-less or
|
|
763
|
+
* malformed), with the reason, so callers can log or re-request them.
|
|
764
|
+
*
|
|
765
|
+
* @returns {{ data: object, reason: string }[]}
|
|
766
|
+
*/
|
|
767
|
+
get droppedRevocations() {
|
|
768
|
+
return [...this.#dropped];
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Drop recorded revocations that have expired.
|
|
773
|
+
*
|
|
774
|
+
* @param {number} [now=Date.now()]
|
|
775
|
+
* @returns {number} How many were dropped
|
|
776
|
+
*/
|
|
777
|
+
pruneRevocations(now = Date.now()) {
|
|
778
|
+
const before = this.#revocations.length;
|
|
779
|
+
this.#revocations = this.#revocations.filter((r) => !r.isExpired(now));
|
|
780
|
+
return before - this.#revocations.length;
|
|
689
781
|
}
|
|
690
782
|
|
|
691
783
|
/**
|
|
@@ -711,6 +803,7 @@ export class MeshKeyring {
|
|
|
711
803
|
`Namespace mismatch: unlink is for ${JSON.stringify(unlink.namespace)}, keyring is ${JSON.stringify(this.#namespace)}`
|
|
712
804
|
);
|
|
713
805
|
}
|
|
806
|
+
if (unlink.defect) throw new Error(`Unlink refused: ${unlink.defect}`);
|
|
714
807
|
let ok = false;
|
|
715
808
|
try {
|
|
716
809
|
ok = await unlink.verify(parentPub);
|
|
@@ -719,12 +812,22 @@ export class MeshKeyring {
|
|
|
719
812
|
}
|
|
720
813
|
if (!ok) throw new Error('Signature verification failed');
|
|
721
814
|
|
|
815
|
+
// Already expired: it no longer counts, so record and relay nothing.
|
|
816
|
+
if (unlink.isExpired()) return { removed: false, descendants: [] };
|
|
817
|
+
|
|
722
818
|
const descendants = this.#descendantsOf(unlink.child);
|
|
723
819
|
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
);
|
|
727
|
-
if (
|
|
820
|
+
const same = (r) =>
|
|
821
|
+
r.parent === unlink.parent && r.child === unlink.child && r.created === unlink.created;
|
|
822
|
+
const idx = this.#revocations.findIndex(same);
|
|
823
|
+
if (idx < 0) {
|
|
824
|
+
this.#revocations.push(unlink);
|
|
825
|
+
} else {
|
|
826
|
+
// Same revocation, possibly with a different expiry: keep the longer-lived.
|
|
827
|
+
if (unlink.expires > this.#revocations[idx].expires) {
|
|
828
|
+
this.#revocations[idx] = unlink;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
728
831
|
|
|
729
832
|
const before = this.#links.length;
|
|
730
833
|
this.#links = this.#links.filter((l) => !unlink.revokes(l));
|
|
@@ -732,12 +835,15 @@ export class MeshKeyring {
|
|
|
732
835
|
}
|
|
733
836
|
|
|
734
837
|
/**
|
|
735
|
-
*
|
|
736
|
-
*
|
|
838
|
+
* Recorded signed revocations that have not expired (copies of the list,
|
|
839
|
+
* same objects); expired ones are dropped from the keyring first. Relay
|
|
840
|
+
* these to peers so they can {@link MeshKeyring#applyUnlink} them.
|
|
737
841
|
*
|
|
842
|
+
* @param {{ now?: number }} [opts]
|
|
738
843
|
* @returns {SignedKeyUnlink[]}
|
|
739
844
|
*/
|
|
740
|
-
listRevocations() {
|
|
845
|
+
listRevocations(opts = {}) {
|
|
846
|
+
this.pruneRevocations(opts.now ?? Date.now());
|
|
741
847
|
return [...this.#revocations];
|
|
742
848
|
}
|
|
743
849
|
|
|
@@ -940,7 +1046,7 @@ export class MeshKeyring {
|
|
|
940
1046
|
|
|
941
1047
|
for (const link of relevantChain) {
|
|
942
1048
|
if (link.isExpired(now)) return fail(link, 'expired');
|
|
943
|
-
if (this.isRevoked(link)) return fail(link, 'revoked');
|
|
1049
|
+
if (this.isRevoked(link, now)) return fail(link, 'revoked');
|
|
944
1050
|
if ((link.namespace ?? null) !== this.#namespace) return fail(link, 'namespace');
|
|
945
1051
|
|
|
946
1052
|
if (!(link instanceof SignedKeyLink)) {
|
|
@@ -1201,7 +1307,7 @@ export class MeshKeyring {
|
|
|
1201
1307
|
v: 3,
|
|
1202
1308
|
namespace: this.#namespace,
|
|
1203
1309
|
links: this.#links.map((l) => l.toJSON()),
|
|
1204
|
-
revocations: this
|
|
1310
|
+
revocations: this.listRevocations().map((r) => r.toJSON()),
|
|
1205
1311
|
};
|
|
1206
1312
|
}
|
|
1207
1313
|
|
|
@@ -1242,7 +1348,13 @@ export class MeshKeyring {
|
|
|
1242
1348
|
);
|
|
1243
1349
|
}
|
|
1244
1350
|
for (const r of revocations) {
|
|
1245
|
-
|
|
1351
|
+
let u;
|
|
1352
|
+
try { u = SignedKeyUnlink.fromJSON(r); } catch (e) {
|
|
1353
|
+
kr.#dropped.push({ data: r, reason: `malformed: ${e.message}` });
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
if (u.defect) kr.#dropped.push({ data: r, reason: u.defect });
|
|
1357
|
+
else if (!u.isExpired()) kr.#revocations.push(u);
|
|
1246
1358
|
}
|
|
1247
1359
|
return kr;
|
|
1248
1360
|
}
|
package/src/peer-tools.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* peer-tools.mjs — BrowserTool subclasses for mesh peer subsystems
|
|
3
3
|
*
|
|
4
4
|
* Exposes chat, compute, scheduling, health, escrow, routing, timestamp,
|
|
5
5
|
* stealth, delta-sync, gateway, torrent, IPFS, ACL, and capability tools
|
|
6
6
|
* to the AI agent.
|
|
7
7
|
*
|
|
8
|
-
* @module
|
|
8
|
+
* @module peer-tools
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { BrowserTool } from './compat.mjs'
|
package/src/peer.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
// STATUS: EXPERIMENTAL — complete implementation, not yet integrated into main application
|
|
3
|
-
*
|
|
3
|
+
* peer.mjs -- Peer Connection Manager.
|
|
4
4
|
*
|
|
5
5
|
* Discovers, connects to, and maintains connections with mesh peers.
|
|
6
6
|
* Does not handle the actual transport -- delegates to MeshTransportManager.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Peer status lifecycle: disconnected -> connecting -> connected -> authenticated
|
|
9
9
|
*
|
|
10
10
|
* Run tests:
|
|
11
|
-
* node --import ./
|
|
11
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/peer.test.mjs
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
// ---------------------------------------------------------------------------
|
package/src/silent-catch.mjs
CHANGED
|
@@ -2,31 +2,43 @@
|
|
|
2
2
|
* silent-catch.mjs — debug-gated structured logger for the
|
|
3
3
|
* `try { … } catch { /* ignore *\/ }` pattern.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* clawser-app imports) so this package doesn't need to reach into web/.
|
|
5
|
+
* Standalone module (no other imports) so this package is self-contained.
|
|
7
6
|
*
|
|
8
7
|
* Replaces silent catches with an opt-in inspectable record. Default
|
|
9
8
|
* behaviour is unchanged (silent), so this is a drop-in replacement.
|
|
10
9
|
* Users surface the events by enabling debug mode:
|
|
11
10
|
*
|
|
12
|
-
* localStorage.setItem('
|
|
13
|
-
* // or, in DevTools:
|
|
11
|
+
* localStorage.setItem('browsermesh_debug', 'true') // persistent
|
|
12
|
+
* // or, in DevTools: browsermeshDebug.enable()
|
|
13
|
+
*
|
|
14
|
+
* The old `clawser_debug` localStorage key and `clawserDebug` global are
|
|
15
|
+
* deprecated aliases, kept for compatibility.
|
|
14
16
|
*/
|
|
15
17
|
|
|
18
|
+
/** localStorage key that enables debug mode. */
|
|
19
|
+
const DEBUG_KEY = 'browsermesh_debug';
|
|
20
|
+
/** Deprecated alias for DEBUG_KEY, kept for compatibility. */
|
|
21
|
+
const LEGACY_DEBUG_KEY = 'clawser_debug';
|
|
22
|
+
|
|
23
|
+
function readDebugFlag() {
|
|
24
|
+
return localStorage.getItem(DEBUG_KEY) === 'true'
|
|
25
|
+
|| localStorage.getItem(LEGACY_DEBUG_KEY) === 'true';
|
|
26
|
+
}
|
|
27
|
+
|
|
16
28
|
let enabled = false;
|
|
17
29
|
try {
|
|
18
30
|
if (typeof localStorage !== 'undefined') {
|
|
19
|
-
enabled =
|
|
31
|
+
enabled = readDebugFlag();
|
|
20
32
|
}
|
|
21
33
|
} catch {
|
|
22
34
|
// localStorage may throw in privacy / sandbox contexts — treat as disabled
|
|
23
35
|
}
|
|
24
36
|
|
|
25
|
-
/** Re-check the localStorage flag; called by
|
|
37
|
+
/** Re-check the localStorage flag; called by browsermeshDebug.enable/disable. */
|
|
26
38
|
export function refreshSilentCatchState() {
|
|
27
39
|
try {
|
|
28
40
|
if (typeof localStorage !== 'undefined') {
|
|
29
|
-
enabled =
|
|
41
|
+
enabled = readDebugFlag();
|
|
30
42
|
}
|
|
31
43
|
} catch {
|
|
32
44
|
enabled = false;
|
|
@@ -36,7 +48,7 @@ export function refreshSilentCatchState() {
|
|
|
36
48
|
/**
|
|
37
49
|
* Log a silent-catch event. No-op unless debug mode is enabled.
|
|
38
50
|
*
|
|
39
|
-
* @param {string} module — file/component (e.g. '
|
|
51
|
+
* @param {string} module — file/component (e.g. 'pod')
|
|
40
52
|
* @param {string} operation — what was attempted (e.g. 'relay-disconnect')
|
|
41
53
|
* @param {*} error — the caught value
|
|
42
54
|
* @param {object} [context] — extra structured fields
|
|
@@ -51,5 +63,5 @@ export function silentCatch(module, operation, error, context) {
|
|
|
51
63
|
}
|
|
52
64
|
const entry = { module, operation, error: error?.message || String(error) };
|
|
53
65
|
if (context) Object.assign(entry, context);
|
|
54
|
-
console.warn('[
|
|
66
|
+
console.warn('[browsermesh:silent-catch]', entry);
|
|
55
67
|
}
|
package/src/trust.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* trust.mjs -- Trust graph management.
|
|
3
3
|
*
|
|
4
4
|
* Float [0.0, 1.0] trust with multiplicative transitive decay,
|
|
5
5
|
* scope intersection, and reputation aggregation.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* No browser-only imports at module level.
|
|
12
12
|
*
|
|
13
13
|
* Run tests:
|
|
14
|
-
* node --import ./
|
|
14
|
+
* cd packages/browsermesh-core && node --import ./test/_setup-globals.mjs --test test/trust.test.mjs
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {
|