@kubun/plugin-p2p 0.11.0 → 0.12.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/lib/context/group.js +1073 -746
- package/lib/context/hub.js +2 -1
- package/lib/context/join.js +50 -15
- package/lib/context/peer.d.ts +92 -0
- package/lib/context/peer.js +1216 -0
- package/lib/context/require-admin.d.ts +57 -0
- package/lib/context/require-admin.js +57 -0
- package/lib/context/sync.d.ts +12 -0
- package/lib/context/sync.js +234 -1
- package/lib/context/types.d.ts +56 -20
- package/lib/context/types.js +23 -3
- package/lib/groups/access-default-token.d.ts +44 -0
- package/lib/groups/access-default-token.js +103 -0
- package/lib/groups/admin-roster.d.ts +42 -117
- package/lib/groups/admin-roster.js +53 -168
- package/lib/groups/anchor-store.d.ts +15 -0
- package/lib/groups/anchor-store.js +37 -0
- package/lib/groups/app-cursor-store.d.ts +17 -0
- package/lib/groups/app-cursor-store.js +34 -0
- package/lib/groups/broadcast.d.ts +199 -81
- package/lib/groups/broadcast.js +443 -368
- package/lib/groups/catalog-token.d.ts +50 -0
- package/lib/groups/catalog-token.js +96 -0
- package/lib/groups/circle-projection.d.ts +32 -64
- package/lib/groups/circle-projection.js +95 -181
- package/lib/groups/circle-reducers.d.ts +71 -110
- package/lib/groups/circle-reducers.js +57 -127
- package/lib/groups/commit-adoption.d.ts +77 -0
- package/lib/groups/commit-adoption.js +108 -0
- package/lib/groups/commit-journal.d.ts +14 -0
- package/lib/groups/commit-journal.js +65 -0
- package/lib/groups/control-request.d.ts +66 -0
- package/lib/groups/control-request.js +101 -0
- package/lib/groups/events.d.ts +14 -1
- package/lib/groups/group-anchor.d.ts +18 -57
- package/lib/groups/group-anchor.js +15 -100
- package/lib/groups/group-crypto.d.ts +36 -13
- package/lib/groups/group-crypto.js +124 -50
- package/lib/groups/group-handle-registry.d.ts +106 -36
- package/lib/groups/group-handle-registry.js +351 -61
- package/lib/groups/group-handlers.d.ts +5 -4
- package/lib/groups/group-handlers.js +155 -29
- package/lib/groups/group-health-monitor.d.ts +1 -1
- package/lib/groups/group-health-monitor.js +1 -1
- package/lib/groups/group-mls.d.ts +35 -4
- package/lib/groups/group-mls.js +594 -62
- package/lib/groups/group-peer-manager.d.ts +212 -19
- package/lib/groups/group-peer-manager.js +1061 -69
- package/lib/groups/group-protocols.d.ts +485 -28
- package/lib/groups/group-protocols.js +289 -15
- package/lib/groups/invite-payload.d.ts +48 -0
- package/lib/groups/join-request-identity.d.ts +21 -0
- package/lib/groups/join-request-identity.js +43 -0
- package/lib/groups/join-utils.d.ts +60 -0
- package/lib/groups/join-utils.js +262 -0
- package/lib/groups/ledger-affected-events.d.ts +11 -6
- package/lib/groups/ledger-affected-events.js +15 -26
- package/lib/groups/ledger-commit-fold.d.ts +107 -0
- package/lib/groups/ledger-commit-fold.js +167 -0
- package/lib/groups/ledger-ingest.d.ts +124 -0
- package/lib/groups/ledger-ingest.js +212 -0
- package/lib/groups/ledger.d.ts +44 -0
- package/lib/groups/ledger.js +30 -0
- package/lib/groups/manager.d.ts +202 -19
- package/lib/groups/manager.js +623 -106
- package/lib/groups/mls-codec.d.ts +27 -6
- package/lib/groups/mls-codec.js +30 -15
- package/lib/groups/mls-encryptor.js +9 -6
- package/lib/groups/mls-group-handle.d.ts +37 -2
- package/lib/groups/mls-group-handle.js +12 -4
- package/lib/groups/mls-receive-errors.d.ts +0 -2
- package/lib/groups/mls-receive-errors.js +3 -6
- package/lib/groups/mls-state.d.ts +5 -3
- package/lib/groups/mls-state.js +27 -4
- package/lib/groups/peer-presence.d.ts +90 -0
- package/lib/groups/peer-presence.js +295 -0
- package/lib/groups/peer-selection.d.ts +37 -0
- package/lib/groups/peer-selection.js +72 -0
- package/lib/groups/roster-projection.d.ts +53 -0
- package/lib/groups/roster-projection.js +65 -0
- package/lib/groups/store-received-grant.d.ts +4 -3
- package/lib/groups/store-received-grant.js +80 -35
- package/lib/groups/store-received-revocation.d.ts +16 -13
- package/lib/groups/store-received-revocation.js +23 -22
- package/lib/hub/http-client.d.ts +10 -27
- package/lib/hub/http-client.js +2 -19
- package/lib/hub/hub-like.d.ts +57 -6
- package/lib/hub/hub-like.js +539 -52
- package/lib/hub/loopback-log-hub.d.ts +20 -0
- package/lib/hub/loopback-log-hub.js +178 -0
- package/lib/hub/manager.d.ts +25 -40
- package/lib/hub/manager.js +51 -94
- package/lib/hub/peer-scoped-hub-view.d.ts +35 -0
- package/lib/hub/peer-scoped-hub-view.js +92 -0
- package/lib/hub/sender-scoped-hub-view.d.ts +41 -0
- package/lib/hub/sender-scoped-hub-view.js +59 -0
- package/lib/hub/server-did.d.ts +67 -0
- package/lib/hub/server-did.js +131 -0
- package/lib/hub/wiring.d.ts +71 -14
- package/lib/hub/wiring.js +80 -23
- package/lib/index.d.ts +48 -13
- package/lib/index.js +257 -86
- package/lib/peer/connection-registry.d.ts +45 -0
- package/lib/peer/connection-registry.js +52 -0
- package/lib/peer/handlers.d.ts +69 -0
- package/lib/peer/handlers.js +110 -0
- package/lib/protocol.d.ts +213 -0
- package/lib/protocol.js +268 -0
- package/lib/schema.d.ts +2 -1
- package/lib/schema.js +805 -131
- package/lib/sync/access-default-sender.d.ts +23 -0
- package/lib/sync/access-default-sender.js +80 -0
- package/lib/sync/authorize.d.ts +57 -3
- package/lib/sync/authorize.js +45 -4
- package/lib/sync/broadcast-queue.d.ts +3 -4
- package/lib/sync/broadcast-queue.js +2 -3
- package/lib/sync/catalog-scope.d.ts +8 -7
- package/lib/sync/catalog-scope.js +55 -39
- package/lib/sync/errors.d.ts +9 -0
- package/lib/sync/errors.js +10 -0
- package/lib/sync/forwarder.d.ts +13 -19
- package/lib/sync/forwarder.js +13 -19
- package/lib/sync/handlers.js +54 -14
- package/lib/sync/hub-tunnel-sync-listener.d.ts +16 -6
- package/lib/sync/hub-tunnel-sync-listener.js +126 -37
- package/lib/sync/hub-tunnel-sync-provider.d.ts +31 -11
- package/lib/sync/hub-tunnel-sync-provider.js +68 -19
- package/lib/sync/merkle-channel.d.ts +9 -1
- package/lib/sync/merkle-channel.js +0 -0
- package/lib/sync/peer-registry.d.ts +14 -10
- package/lib/sync/peer-registry.js +0 -25
- package/lib/sync/sync-client.d.ts +11 -1
- package/lib/sync/sync-client.js +72 -10
- package/lib/sync/sync-manager.d.ts +22 -4
- package/lib/sync/sync-manager.js +39 -10
- package/lib/sync/tunnel-listeners.d.ts +52 -0
- package/lib/sync/tunnel-listeners.js +175 -0
- package/lib/sync/tunnel-observability.d.ts +25 -0
- package/lib/sync/tunnel-observability.js +63 -0
- package/lib/sync/tunnel-topics.d.ts +20 -0
- package/lib/sync/tunnel-topics.js +28 -0
- package/lib/types.d.ts +699 -28
- package/lib/types.js +0 -1
- package/lib/util/handler-error.d.ts +16 -0
- package/lib/util/handler-error.js +64 -0
- package/lib/util/mutex.d.ts +14 -1
- package/lib/util/mutex.js +37 -3
- package/package.json +59 -52
- package/lib/groups/ledger-entry.d.ts +0 -37
- package/lib/groups/ledger-entry.js +0 -56
- package/lib/groups/ledger-fold.d.ts +0 -56
- package/lib/groups/ledger-fold.js +0 -53
- package/lib/hub/did-observing-transport.d.ts +0 -75
- package/lib/hub/did-observing-transport.js +0 -126
- package/lib/hub/errors.d.ts +0 -24
- package/lib/hub/errors.js +0 -33
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Disposer } from '@sozai/async';
|
|
2
|
-
import { HubServerDIDMismatchError } from './errors.js';
|
|
3
|
-
/**
|
|
4
|
-
* Wraps a `ClientTransportOf<Protocol>` to enforce hub-server-DID
|
|
5
|
-
* TOFU + pinned-mismatch semantics on the receive side.
|
|
6
|
-
*
|
|
7
|
-
* - `expectedServerDID == null`: TOFU mode. First message bearing
|
|
8
|
-
* `payload.iss` fires `onServerDID(iss)` exactly once; subsequent messages
|
|
9
|
-
* never re-fire, even with a differing `iss`. Every message is forwarded
|
|
10
|
-
* to the inner Client untouched.
|
|
11
|
-
* - `expectedServerDID != null` and the first observed `iss` matches: the
|
|
12
|
-
* pin is already authoritative; `onServerDID` is NOT fired and forwarding
|
|
13
|
-
* continues normally.
|
|
14
|
-
* - `expectedServerDID != null` and the first observed `iss` differs: the
|
|
15
|
-
* wrapper enters a permanent failed state (`HubServerDIDMismatchError`).
|
|
16
|
-
* The current `read()` call AND every subsequent `read()` reject with the
|
|
17
|
-
* error; the offending message is NOT delivered. Inner-transport lifecycle
|
|
18
|
-
* stays the pool's responsibility — the wrapper does not dispose its inner.
|
|
19
|
-
*
|
|
20
|
-
* Extends `Disposer` and matches the `ClientTransportOf<Protocol>` shape
|
|
21
|
-
* structurally so it can be passed straight to `Client<Protocol>`.
|
|
22
|
-
*/ export class DIDObservingTransport extends Disposer {
|
|
23
|
-
#inner;
|
|
24
|
-
#onServerDID;
|
|
25
|
-
#expectedServerDID;
|
|
26
|
-
#hubURL;
|
|
27
|
-
#onMismatch;
|
|
28
|
-
#fired = false;
|
|
29
|
-
#failure = null;
|
|
30
|
-
constructor(params){
|
|
31
|
-
super({
|
|
32
|
-
signal: params.inner.signal,
|
|
33
|
-
dispose: async (reason)=>{
|
|
34
|
-
await params.inner.dispose(reason);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
this.#inner = params.inner;
|
|
38
|
-
this.#onServerDID = params.onServerDID;
|
|
39
|
-
this.#expectedServerDID = params.expectedServerDID;
|
|
40
|
-
this.#hubURL = params.hubURL;
|
|
41
|
-
this.#onMismatch = params.onMismatch;
|
|
42
|
-
}
|
|
43
|
-
get events() {
|
|
44
|
-
return this.#inner.events;
|
|
45
|
-
}
|
|
46
|
-
getWritable() {
|
|
47
|
-
return this.#inner.getWritable();
|
|
48
|
-
}
|
|
49
|
-
async read() {
|
|
50
|
-
if (this.#failure != null) {
|
|
51
|
-
throw this.#failure;
|
|
52
|
-
}
|
|
53
|
-
const result = await this.#inner.read();
|
|
54
|
-
const failure = this.#observe(result);
|
|
55
|
-
if (failure != null) {
|
|
56
|
-
throw failure;
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
async write(value) {
|
|
61
|
-
await this.#inner.write(value);
|
|
62
|
-
}
|
|
63
|
-
[Symbol.asyncIterator]() {
|
|
64
|
-
return {
|
|
65
|
-
next: async ()=>{
|
|
66
|
-
const result = await this.read();
|
|
67
|
-
if (result.done) {
|
|
68
|
-
return {
|
|
69
|
-
done: true,
|
|
70
|
-
value: result.value ?? null
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
done: false,
|
|
75
|
-
value: result.value
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Inspect a freshly-read result for `payload.iss`. Returns a
|
|
82
|
-
* `HubServerDIDMismatchError` to be thrown by the caller when in pinned
|
|
83
|
-
* mode and the observed DID does not match — in that case the wrapper
|
|
84
|
-
* also enters a permanent failed state and the offending message must NOT
|
|
85
|
-
* be returned to the caller. Returns `null` otherwise.
|
|
86
|
-
*/ #observe(result) {
|
|
87
|
-
if (this.#fired || result.done || result.value == null) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const payload = result.value.payload;
|
|
91
|
-
const iss = payload?.iss;
|
|
92
|
-
if (typeof iss !== 'string' || iss.length === 0) {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
this.#fired = true;
|
|
96
|
-
if (this.#expectedServerDID != null) {
|
|
97
|
-
if (iss === this.#expectedServerDID) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const error = new HubServerDIDMismatchError({
|
|
101
|
-
hubURL: this.#hubURL ?? '',
|
|
102
|
-
expectedServerDID: this.#expectedServerDID,
|
|
103
|
-
observedServerDID: iss
|
|
104
|
-
});
|
|
105
|
-
this.#failure = error;
|
|
106
|
-
if (this.#onMismatch != null) {
|
|
107
|
-
try {
|
|
108
|
-
this.#onMismatch({
|
|
109
|
-
hubURL: this.#hubURL ?? '',
|
|
110
|
-
expectedServerDID: this.#expectedServerDID,
|
|
111
|
-
observedServerDID: iss
|
|
112
|
-
});
|
|
113
|
-
} catch {
|
|
114
|
-
// observer errors must not mask the typed mismatch path
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return error;
|
|
118
|
-
}
|
|
119
|
-
// TOFU mode — fire-and-forget: forwarding must not wait on the observer.
|
|
120
|
-
// Errors are swallowed at the wrapper; the pool-side handler logs them.
|
|
121
|
-
void Promise.resolve().then(()=>this.#onServerDID(iss)).catch(()=>{
|
|
122
|
-
// intentional: capture failures don't break the read loop in TOFU mode
|
|
123
|
-
});
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
}
|
package/lib/hub/errors.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thrown by `DIDObservingTransport.read()` when the first observed `payload.iss`
|
|
3
|
-
* does not match the pinned `expectedServerDID`. The transport enters a
|
|
4
|
-
* permanent failed state: no message bearing the offending `iss` is delivered
|
|
5
|
-
* to the inner Client, and every subsequent `read()` rejects with the same
|
|
6
|
-
* error. In-flight Enkaku RPCs see this error as the `cause` of the Client's
|
|
7
|
-
* "Transport read failed" abort.
|
|
8
|
-
*
|
|
9
|
-
* Distinct from `HubServerDIDConflictError` (raised by manager-level
|
|
10
|
-
* `captureServerDID` when the pin row already differs from the observed DID
|
|
11
|
-
* on the TOFU capture path); this class is raised client-side, before any
|
|
12
|
-
* message is delivered, when a row was already pinned at connect time.
|
|
13
|
-
*/
|
|
14
|
-
export declare class HubServerDIDMismatchError extends Error {
|
|
15
|
-
#private;
|
|
16
|
-
constructor(params: {
|
|
17
|
-
hubURL: string;
|
|
18
|
-
expectedServerDID: string;
|
|
19
|
-
observedServerDID: string;
|
|
20
|
-
});
|
|
21
|
-
get hubURL(): string;
|
|
22
|
-
get expectedServerDID(): string;
|
|
23
|
-
get observedServerDID(): string;
|
|
24
|
-
}
|
package/lib/hub/errors.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Thrown by `DIDObservingTransport.read()` when the first observed `payload.iss`
|
|
3
|
-
* does not match the pinned `expectedServerDID`. The transport enters a
|
|
4
|
-
* permanent failed state: no message bearing the offending `iss` is delivered
|
|
5
|
-
* to the inner Client, and every subsequent `read()` rejects with the same
|
|
6
|
-
* error. In-flight Enkaku RPCs see this error as the `cause` of the Client's
|
|
7
|
-
* "Transport read failed" abort.
|
|
8
|
-
*
|
|
9
|
-
* Distinct from `HubServerDIDConflictError` (raised by manager-level
|
|
10
|
-
* `captureServerDID` when the pin row already differs from the observed DID
|
|
11
|
-
* on the TOFU capture path); this class is raised client-side, before any
|
|
12
|
-
* message is delivered, when a row was already pinned at connect time.
|
|
13
|
-
*/ export class HubServerDIDMismatchError extends Error {
|
|
14
|
-
#hubURL;
|
|
15
|
-
#expectedServerDID;
|
|
16
|
-
#observedServerDID;
|
|
17
|
-
constructor(params){
|
|
18
|
-
super(`hub at ${params.hubURL} signed responses with ${params.observedServerDID}; pinned to ${params.expectedServerDID}`);
|
|
19
|
-
this.name = 'HubServerDIDMismatchError';
|
|
20
|
-
this.#hubURL = params.hubURL;
|
|
21
|
-
this.#expectedServerDID = params.expectedServerDID;
|
|
22
|
-
this.#observedServerDID = params.observedServerDID;
|
|
23
|
-
}
|
|
24
|
-
get hubURL() {
|
|
25
|
-
return this.#hubURL;
|
|
26
|
-
}
|
|
27
|
-
get expectedServerDID() {
|
|
28
|
-
return this.#expectedServerDID;
|
|
29
|
-
}
|
|
30
|
-
get observedServerDID() {
|
|
31
|
-
return this.#observedServerDID;
|
|
32
|
-
}
|
|
33
|
-
}
|