@kubun/plugin-p2p 0.11.0 → 0.12.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.
Files changed (156) hide show
  1. package/lib/context/group.js +1073 -746
  2. package/lib/context/hub.js +2 -1
  3. package/lib/context/join.js +50 -15
  4. package/lib/context/peer.d.ts +92 -0
  5. package/lib/context/peer.js +1216 -0
  6. package/lib/context/require-admin.d.ts +57 -0
  7. package/lib/context/require-admin.js +57 -0
  8. package/lib/context/sync.d.ts +12 -0
  9. package/lib/context/sync.js +234 -1
  10. package/lib/context/types.d.ts +56 -20
  11. package/lib/context/types.js +23 -3
  12. package/lib/groups/access-default-token.d.ts +44 -0
  13. package/lib/groups/access-default-token.js +103 -0
  14. package/lib/groups/admin-roster.d.ts +42 -117
  15. package/lib/groups/admin-roster.js +53 -168
  16. package/lib/groups/anchor-store.d.ts +15 -0
  17. package/lib/groups/anchor-store.js +37 -0
  18. package/lib/groups/app-cursor-store.d.ts +17 -0
  19. package/lib/groups/app-cursor-store.js +34 -0
  20. package/lib/groups/broadcast.d.ts +199 -81
  21. package/lib/groups/broadcast.js +443 -368
  22. package/lib/groups/catalog-token.d.ts +50 -0
  23. package/lib/groups/catalog-token.js +96 -0
  24. package/lib/groups/circle-projection.d.ts +32 -64
  25. package/lib/groups/circle-projection.js +95 -181
  26. package/lib/groups/circle-reducers.d.ts +71 -110
  27. package/lib/groups/circle-reducers.js +57 -127
  28. package/lib/groups/commit-adoption.d.ts +77 -0
  29. package/lib/groups/commit-adoption.js +108 -0
  30. package/lib/groups/commit-journal.d.ts +14 -0
  31. package/lib/groups/commit-journal.js +65 -0
  32. package/lib/groups/control-request.d.ts +66 -0
  33. package/lib/groups/control-request.js +101 -0
  34. package/lib/groups/events.d.ts +14 -1
  35. package/lib/groups/group-anchor.d.ts +18 -57
  36. package/lib/groups/group-anchor.js +15 -100
  37. package/lib/groups/group-crypto.d.ts +36 -13
  38. package/lib/groups/group-crypto.js +124 -50
  39. package/lib/groups/group-handle-registry.d.ts +106 -36
  40. package/lib/groups/group-handle-registry.js +351 -61
  41. package/lib/groups/group-handlers.d.ts +5 -4
  42. package/lib/groups/group-handlers.js +155 -29
  43. package/lib/groups/group-health-monitor.d.ts +1 -1
  44. package/lib/groups/group-health-monitor.js +1 -1
  45. package/lib/groups/group-mls.d.ts +35 -4
  46. package/lib/groups/group-mls.js +594 -62
  47. package/lib/groups/group-peer-manager.d.ts +212 -19
  48. package/lib/groups/group-peer-manager.js +1061 -69
  49. package/lib/groups/group-protocols.d.ts +485 -28
  50. package/lib/groups/group-protocols.js +289 -15
  51. package/lib/groups/invite-payload.d.ts +48 -0
  52. package/lib/groups/join-request-identity.d.ts +21 -0
  53. package/lib/groups/join-request-identity.js +43 -0
  54. package/lib/groups/join-utils.d.ts +60 -0
  55. package/lib/groups/join-utils.js +262 -0
  56. package/lib/groups/ledger-affected-events.d.ts +11 -6
  57. package/lib/groups/ledger-affected-events.js +15 -26
  58. package/lib/groups/ledger-commit-fold.d.ts +107 -0
  59. package/lib/groups/ledger-commit-fold.js +167 -0
  60. package/lib/groups/ledger-ingest.d.ts +124 -0
  61. package/lib/groups/ledger-ingest.js +212 -0
  62. package/lib/groups/ledger.d.ts +44 -0
  63. package/lib/groups/ledger.js +30 -0
  64. package/lib/groups/manager.d.ts +202 -19
  65. package/lib/groups/manager.js +623 -106
  66. package/lib/groups/mls-codec.d.ts +27 -6
  67. package/lib/groups/mls-codec.js +30 -15
  68. package/lib/groups/mls-encryptor.js +9 -6
  69. package/lib/groups/mls-group-handle.d.ts +37 -2
  70. package/lib/groups/mls-group-handle.js +12 -4
  71. package/lib/groups/mls-receive-errors.d.ts +0 -2
  72. package/lib/groups/mls-receive-errors.js +3 -6
  73. package/lib/groups/mls-state.d.ts +5 -3
  74. package/lib/groups/mls-state.js +27 -4
  75. package/lib/groups/peer-presence.d.ts +90 -0
  76. package/lib/groups/peer-presence.js +295 -0
  77. package/lib/groups/peer-selection.d.ts +37 -0
  78. package/lib/groups/peer-selection.js +72 -0
  79. package/lib/groups/roster-projection.d.ts +53 -0
  80. package/lib/groups/roster-projection.js +65 -0
  81. package/lib/groups/store-received-grant.d.ts +4 -3
  82. package/lib/groups/store-received-grant.js +80 -35
  83. package/lib/groups/store-received-revocation.d.ts +16 -13
  84. package/lib/groups/store-received-revocation.js +23 -22
  85. package/lib/hub/http-client.d.ts +10 -27
  86. package/lib/hub/http-client.js +2 -19
  87. package/lib/hub/hub-like.d.ts +57 -6
  88. package/lib/hub/hub-like.js +539 -52
  89. package/lib/hub/loopback-log-hub.d.ts +20 -0
  90. package/lib/hub/loopback-log-hub.js +178 -0
  91. package/lib/hub/manager.d.ts +25 -40
  92. package/lib/hub/manager.js +51 -94
  93. package/lib/hub/peer-scoped-hub-view.d.ts +35 -0
  94. package/lib/hub/peer-scoped-hub-view.js +92 -0
  95. package/lib/hub/sender-scoped-hub-view.d.ts +41 -0
  96. package/lib/hub/sender-scoped-hub-view.js +59 -0
  97. package/lib/hub/server-did.d.ts +67 -0
  98. package/lib/hub/server-did.js +131 -0
  99. package/lib/hub/wiring.d.ts +71 -14
  100. package/lib/hub/wiring.js +80 -23
  101. package/lib/index.d.ts +48 -13
  102. package/lib/index.js +257 -86
  103. package/lib/peer/connection-registry.d.ts +45 -0
  104. package/lib/peer/connection-registry.js +52 -0
  105. package/lib/peer/handlers.d.ts +69 -0
  106. package/lib/peer/handlers.js +110 -0
  107. package/lib/protocol.d.ts +213 -0
  108. package/lib/protocol.js +268 -0
  109. package/lib/schema.d.ts +2 -1
  110. package/lib/schema.js +805 -131
  111. package/lib/sync/access-default-sender.d.ts +23 -0
  112. package/lib/sync/access-default-sender.js +80 -0
  113. package/lib/sync/authorize.d.ts +57 -3
  114. package/lib/sync/authorize.js +45 -4
  115. package/lib/sync/broadcast-queue.d.ts +3 -4
  116. package/lib/sync/broadcast-queue.js +2 -3
  117. package/lib/sync/catalog-scope.d.ts +8 -7
  118. package/lib/sync/catalog-scope.js +55 -39
  119. package/lib/sync/errors.d.ts +9 -0
  120. package/lib/sync/errors.js +10 -0
  121. package/lib/sync/forwarder.d.ts +13 -19
  122. package/lib/sync/forwarder.js +13 -19
  123. package/lib/sync/handlers.js +54 -14
  124. package/lib/sync/hub-tunnel-sync-listener.d.ts +16 -6
  125. package/lib/sync/hub-tunnel-sync-listener.js +126 -37
  126. package/lib/sync/hub-tunnel-sync-provider.d.ts +31 -11
  127. package/lib/sync/hub-tunnel-sync-provider.js +68 -19
  128. package/lib/sync/merkle-channel.d.ts +9 -1
  129. package/lib/sync/merkle-channel.js +0 -0
  130. package/lib/sync/peer-registry.d.ts +14 -10
  131. package/lib/sync/peer-registry.js +0 -25
  132. package/lib/sync/sync-client.d.ts +11 -1
  133. package/lib/sync/sync-client.js +72 -10
  134. package/lib/sync/sync-manager.d.ts +22 -4
  135. package/lib/sync/sync-manager.js +39 -10
  136. package/lib/sync/tunnel-listeners.d.ts +52 -0
  137. package/lib/sync/tunnel-listeners.js +175 -0
  138. package/lib/sync/tunnel-observability.d.ts +25 -0
  139. package/lib/sync/tunnel-observability.js +63 -0
  140. package/lib/sync/tunnel-topics.d.ts +20 -0
  141. package/lib/sync/tunnel-topics.js +28 -0
  142. package/lib/types.d.ts +699 -28
  143. package/lib/types.js +0 -1
  144. package/lib/util/handler-error.d.ts +16 -0
  145. package/lib/util/handler-error.js +64 -0
  146. package/lib/util/mutex.d.ts +14 -1
  147. package/lib/util/mutex.js +37 -3
  148. package/package.json +56 -52
  149. package/lib/groups/ledger-entry.d.ts +0 -37
  150. package/lib/groups/ledger-entry.js +0 -56
  151. package/lib/groups/ledger-fold.d.ts +0 -56
  152. package/lib/groups/ledger-fold.js +0 -53
  153. package/lib/hub/did-observing-transport.d.ts +0 -75
  154. package/lib/hub/did-observing-transport.js +0 -126
  155. package/lib/hub/errors.d.ts +0 -24
  156. 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
- }
@@ -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
- }