@did-btcr2/method 0.38.0 → 0.39.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 (240) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/browser.js +47859 -34821
  3. package/dist/browser.mjs +47858 -34820
  4. package/dist/cjs/index.js +405 -6065
  5. package/dist/esm/core/beacon/fee-estimator.js +6 -29
  6. package/dist/esm/core/beacon/fee-estimator.js.map +1 -1
  7. package/dist/esm/core/did-sender-resolver.js +26 -0
  8. package/dist/esm/core/did-sender-resolver.js.map +1 -0
  9. package/dist/esm/index.js +3 -17
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/types/core/beacon/fee-estimator.d.ts +4 -39
  12. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -1
  13. package/dist/types/core/did-sender-resolver.d.ts +14 -0
  14. package/dist/types/core/did-sender-resolver.d.ts.map +1 -0
  15. package/dist/types/index.d.ts +2 -16
  16. package/dist/types/index.d.ts.map +1 -1
  17. package/package.json +5 -4
  18. package/src/core/beacon/fee-estimator.ts +8 -51
  19. package/src/core/did-sender-resolver.ts +25 -0
  20. package/src/index.ts +3 -17
  21. package/dist/esm/core/aggregation/beacon-strategy.js +0 -76
  22. package/dist/esm/core/aggregation/beacon-strategy.js.map +0 -1
  23. package/dist/esm/core/aggregation/cohort.js +0 -316
  24. package/dist/esm/core/aggregation/cohort.js.map +0 -1
  25. package/dist/esm/core/aggregation/conditions.js +0 -102
  26. package/dist/esm/core/aggregation/conditions.js.map +0 -1
  27. package/dist/esm/core/aggregation/errors.js +0 -22
  28. package/dist/esm/core/aggregation/errors.js.map +0 -1
  29. package/dist/esm/core/aggregation/fallback-spend.js +0 -132
  30. package/dist/esm/core/aggregation/fallback-spend.js.map +0 -1
  31. package/dist/esm/core/aggregation/logger.js +0 -15
  32. package/dist/esm/core/aggregation/logger.js.map +0 -1
  33. package/dist/esm/core/aggregation/messages/base.js +0 -36
  34. package/dist/esm/core/aggregation/messages/base.js.map +0 -1
  35. package/dist/esm/core/aggregation/messages/bodies.js +0 -149
  36. package/dist/esm/core/aggregation/messages/bodies.js.map +0 -1
  37. package/dist/esm/core/aggregation/messages/constants.js +0 -37
  38. package/dist/esm/core/aggregation/messages/constants.js.map +0 -1
  39. package/dist/esm/core/aggregation/messages/factories.js +0 -139
  40. package/dist/esm/core/aggregation/messages/factories.js.map +0 -1
  41. package/dist/esm/core/aggregation/messages/guards.js +0 -40
  42. package/dist/esm/core/aggregation/messages/guards.js.map +0 -1
  43. package/dist/esm/core/aggregation/messages/index.js +0 -6
  44. package/dist/esm/core/aggregation/messages/index.js.map +0 -1
  45. package/dist/esm/core/aggregation/participant.js +0 -588
  46. package/dist/esm/core/aggregation/participant.js.map +0 -1
  47. package/dist/esm/core/aggregation/phases.js +0 -45
  48. package/dist/esm/core/aggregation/phases.js.map +0 -1
  49. package/dist/esm/core/aggregation/recovery-policy.js +0 -156
  50. package/dist/esm/core/aggregation/recovery-policy.js.map +0 -1
  51. package/dist/esm/core/aggregation/recovery-spend.js +0 -106
  52. package/dist/esm/core/aggregation/recovery-spend.js.map +0 -1
  53. package/dist/esm/core/aggregation/runner/aggregation-runner.js +0 -75
  54. package/dist/esm/core/aggregation/runner/aggregation-runner.js.map +0 -1
  55. package/dist/esm/core/aggregation/runner/events.js +0 -2
  56. package/dist/esm/core/aggregation/runner/events.js.map +0 -1
  57. package/dist/esm/core/aggregation/runner/index.js +0 -6
  58. package/dist/esm/core/aggregation/runner/index.js.map +0 -1
  59. package/dist/esm/core/aggregation/runner/participant-runner.js +0 -407
  60. package/dist/esm/core/aggregation/runner/participant-runner.js.map +0 -1
  61. package/dist/esm/core/aggregation/runner/service-runner.js +0 -699
  62. package/dist/esm/core/aggregation/runner/service-runner.js.map +0 -1
  63. package/dist/esm/core/aggregation/runner/typed-emitter.js +0 -80
  64. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +0 -1
  65. package/dist/esm/core/aggregation/service.js +0 -774
  66. package/dist/esm/core/aggregation/service.js.map +0 -1
  67. package/dist/esm/core/aggregation/signer.js +0 -33
  68. package/dist/esm/core/aggregation/signer.js.map +0 -1
  69. package/dist/esm/core/aggregation/signing-session.js +0 -195
  70. package/dist/esm/core/aggregation/signing-session.js.map +0 -1
  71. package/dist/esm/core/aggregation/transport/didcomm.js +0 -41
  72. package/dist/esm/core/aggregation/transport/didcomm.js.map +0 -1
  73. package/dist/esm/core/aggregation/transport/error.js +0 -12
  74. package/dist/esm/core/aggregation/transport/error.js.map +0 -1
  75. package/dist/esm/core/aggregation/transport/factory.js +0 -29
  76. package/dist/esm/core/aggregation/transport/factory.js.map +0 -1
  77. package/dist/esm/core/aggregation/transport/http/client.js +0 -350
  78. package/dist/esm/core/aggregation/transport/http/client.js.map +0 -1
  79. package/dist/esm/core/aggregation/transport/http/envelope.js +0 -126
  80. package/dist/esm/core/aggregation/transport/http/envelope.js.map +0 -1
  81. package/dist/esm/core/aggregation/transport/http/errors.js +0 -11
  82. package/dist/esm/core/aggregation/transport/http/errors.js.map +0 -1
  83. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js +0 -45
  84. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js.map +0 -1
  85. package/dist/esm/core/aggregation/transport/http/index.js +0 -12
  86. package/dist/esm/core/aggregation/transport/http/index.js.map +0 -1
  87. package/dist/esm/core/aggregation/transport/http/nonce-cache.js +0 -38
  88. package/dist/esm/core/aggregation/transport/http/nonce-cache.js.map +0 -1
  89. package/dist/esm/core/aggregation/transport/http/protocol.js +0 -28
  90. package/dist/esm/core/aggregation/transport/http/protocol.js.map +0 -1
  91. package/dist/esm/core/aggregation/transport/http/rate-limiter.js +0 -45
  92. package/dist/esm/core/aggregation/transport/http/rate-limiter.js.map +0 -1
  93. package/dist/esm/core/aggregation/transport/http/request-auth.js +0 -100
  94. package/dist/esm/core/aggregation/transport/http/request-auth.js.map +0 -1
  95. package/dist/esm/core/aggregation/transport/http/server.js +0 -481
  96. package/dist/esm/core/aggregation/transport/http/server.js.map +0 -1
  97. package/dist/esm/core/aggregation/transport/http/sse-stream.js +0 -110
  98. package/dist/esm/core/aggregation/transport/http/sse-stream.js.map +0 -1
  99. package/dist/esm/core/aggregation/transport/http/sse-writer.js +0 -25
  100. package/dist/esm/core/aggregation/transport/http/sse-writer.js.map +0 -1
  101. package/dist/esm/core/aggregation/transport/in-memory.js +0 -149
  102. package/dist/esm/core/aggregation/transport/in-memory.js.map +0 -1
  103. package/dist/esm/core/aggregation/transport/index.js +0 -8
  104. package/dist/esm/core/aggregation/transport/index.js.map +0 -1
  105. package/dist/esm/core/aggregation/transport/nostr.js +0 -491
  106. package/dist/esm/core/aggregation/transport/nostr.js.map +0 -1
  107. package/dist/esm/core/aggregation/transport/transport.js +0 -2
  108. package/dist/esm/core/aggregation/transport/transport.js.map +0 -1
  109. package/dist/types/core/aggregation/beacon-strategy.d.ts +0 -56
  110. package/dist/types/core/aggregation/beacon-strategy.d.ts.map +0 -1
  111. package/dist/types/core/aggregation/cohort.d.ts +0 -182
  112. package/dist/types/core/aggregation/cohort.d.ts.map +0 -1
  113. package/dist/types/core/aggregation/conditions.d.ts +0 -86
  114. package/dist/types/core/aggregation/conditions.d.ts.map +0 -1
  115. package/dist/types/core/aggregation/errors.d.ts +0 -14
  116. package/dist/types/core/aggregation/errors.d.ts.map +0 -1
  117. package/dist/types/core/aggregation/fallback-spend.d.ts +0 -94
  118. package/dist/types/core/aggregation/fallback-spend.d.ts.map +0 -1
  119. package/dist/types/core/aggregation/logger.d.ts +0 -22
  120. package/dist/types/core/aggregation/logger.d.ts.map +0 -1
  121. package/dist/types/core/aggregation/messages/base.d.ts +0 -58
  122. package/dist/types/core/aggregation/messages/base.d.ts.map +0 -1
  123. package/dist/types/core/aggregation/messages/bodies.d.ts +0 -177
  124. package/dist/types/core/aggregation/messages/bodies.d.ts.map +0 -1
  125. package/dist/types/core/aggregation/messages/constants.d.ts +0 -31
  126. package/dist/types/core/aggregation/messages/constants.d.ts.map +0 -1
  127. package/dist/types/core/aggregation/messages/factories.d.ts +0 -217
  128. package/dist/types/core/aggregation/messages/factories.d.ts.map +0 -1
  129. package/dist/types/core/aggregation/messages/guards.d.ts +0 -11
  130. package/dist/types/core/aggregation/messages/guards.d.ts.map +0 -1
  131. package/dist/types/core/aggregation/messages/index.d.ts +0 -6
  132. package/dist/types/core/aggregation/messages/index.d.ts.map +0 -1
  133. package/dist/types/core/aggregation/participant.d.ts +0 -162
  134. package/dist/types/core/aggregation/participant.d.ts.map +0 -1
  135. package/dist/types/core/aggregation/phases.d.ts +0 -55
  136. package/dist/types/core/aggregation/phases.d.ts.map +0 -1
  137. package/dist/types/core/aggregation/recovery-policy.d.ts +0 -132
  138. package/dist/types/core/aggregation/recovery-policy.d.ts.map +0 -1
  139. package/dist/types/core/aggregation/recovery-spend.d.ts +0 -94
  140. package/dist/types/core/aggregation/recovery-spend.d.ts.map +0 -1
  141. package/dist/types/core/aggregation/runner/aggregation-runner.d.ts +0 -72
  142. package/dist/types/core/aggregation/runner/aggregation-runner.d.ts.map +0 -1
  143. package/dist/types/core/aggregation/runner/events.d.ts +0 -147
  144. package/dist/types/core/aggregation/runner/events.d.ts.map +0 -1
  145. package/dist/types/core/aggregation/runner/index.d.ts +0 -6
  146. package/dist/types/core/aggregation/runner/index.d.ts.map +0 -1
  147. package/dist/types/core/aggregation/runner/participant-runner.d.ts +0 -122
  148. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +0 -1
  149. package/dist/types/core/aggregation/runner/service-runner.d.ts +0 -228
  150. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +0 -1
  151. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +0 -41
  152. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +0 -1
  153. package/dist/types/core/aggregation/service.d.ts +0 -177
  154. package/dist/types/core/aggregation/service.d.ts.map +0 -1
  155. package/dist/types/core/aggregation/signer.d.ts +0 -50
  156. package/dist/types/core/aggregation/signer.d.ts.map +0 -1
  157. package/dist/types/core/aggregation/signing-session.d.ts +0 -81
  158. package/dist/types/core/aggregation/signing-session.d.ts.map +0 -1
  159. package/dist/types/core/aggregation/transport/didcomm.d.ts +0 -23
  160. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +0 -1
  161. package/dist/types/core/aggregation/transport/error.d.ts +0 -8
  162. package/dist/types/core/aggregation/transport/error.d.ts.map +0 -1
  163. package/dist/types/core/aggregation/transport/factory.d.ts +0 -28
  164. package/dist/types/core/aggregation/transport/factory.d.ts.map +0 -1
  165. package/dist/types/core/aggregation/transport/http/client.d.ts +0 -48
  166. package/dist/types/core/aggregation/transport/http/client.d.ts.map +0 -1
  167. package/dist/types/core/aggregation/transport/http/envelope.d.ts +0 -64
  168. package/dist/types/core/aggregation/transport/http/envelope.d.ts.map +0 -1
  169. package/dist/types/core/aggregation/transport/http/errors.d.ts +0 -9
  170. package/dist/types/core/aggregation/transport/http/errors.d.ts.map +0 -1
  171. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts +0 -32
  172. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts.map +0 -1
  173. package/dist/types/core/aggregation/transport/http/index.d.ts +0 -12
  174. package/dist/types/core/aggregation/transport/http/index.d.ts.map +0 -1
  175. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts +0 -26
  176. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts.map +0 -1
  177. package/dist/types/core/aggregation/transport/http/protocol.d.ts +0 -53
  178. package/dist/types/core/aggregation/transport/http/protocol.d.ts.map +0 -1
  179. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts +0 -41
  180. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts.map +0 -1
  181. package/dist/types/core/aggregation/transport/http/request-auth.d.ts +0 -50
  182. package/dist/types/core/aggregation/transport/http/request-auth.d.ts.map +0 -1
  183. package/dist/types/core/aggregation/transport/http/server.d.ts +0 -110
  184. package/dist/types/core/aggregation/transport/http/server.d.ts.map +0 -1
  185. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts +0 -34
  186. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts.map +0 -1
  187. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts +0 -12
  188. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts.map +0 -1
  189. package/dist/types/core/aggregation/transport/in-memory.d.ts +0 -64
  190. package/dist/types/core/aggregation/transport/in-memory.d.ts.map +0 -1
  191. package/dist/types/core/aggregation/transport/index.d.ts +0 -8
  192. package/dist/types/core/aggregation/transport/index.d.ts.map +0 -1
  193. package/dist/types/core/aggregation/transport/nostr.d.ts +0 -153
  194. package/dist/types/core/aggregation/transport/nostr.d.ts.map +0 -1
  195. package/dist/types/core/aggregation/transport/transport.d.ts +0 -62
  196. package/dist/types/core/aggregation/transport/transport.d.ts.map +0 -1
  197. package/src/core/aggregation/beacon-strategy.ts +0 -142
  198. package/src/core/aggregation/cohort.ts +0 -415
  199. package/src/core/aggregation/conditions.ts +0 -172
  200. package/src/core/aggregation/errors.ts +0 -25
  201. package/src/core/aggregation/fallback-spend.ts +0 -223
  202. package/src/core/aggregation/logger.ts +0 -33
  203. package/src/core/aggregation/messages/base.ts +0 -80
  204. package/src/core/aggregation/messages/bodies.ts +0 -328
  205. package/src/core/aggregation/messages/constants.ts +0 -40
  206. package/src/core/aggregation/messages/factories.ts +0 -297
  207. package/src/core/aggregation/messages/guards.ts +0 -61
  208. package/src/core/aggregation/messages/index.ts +0 -5
  209. package/src/core/aggregation/participant.ts +0 -779
  210. package/src/core/aggregation/phases.ts +0 -91
  211. package/src/core/aggregation/recovery-policy.ts +0 -237
  212. package/src/core/aggregation/recovery-spend.ts +0 -192
  213. package/src/core/aggregation/runner/aggregation-runner.ts +0 -125
  214. package/src/core/aggregation/runner/events.ts +0 -129
  215. package/src/core/aggregation/runner/index.ts +0 -5
  216. package/src/core/aggregation/runner/participant-runner.ts +0 -488
  217. package/src/core/aggregation/runner/service-runner.ts +0 -888
  218. package/src/core/aggregation/runner/typed-emitter.ts +0 -87
  219. package/src/core/aggregation/service.ts +0 -1000
  220. package/src/core/aggregation/signer.ts +0 -67
  221. package/src/core/aggregation/signing-session.ts +0 -290
  222. package/src/core/aggregation/transport/didcomm.ts +0 -59
  223. package/src/core/aggregation/transport/error.ts +0 -13
  224. package/src/core/aggregation/transport/factory.ts +0 -65
  225. package/src/core/aggregation/transport/http/client.ts +0 -409
  226. package/src/core/aggregation/transport/http/envelope.ts +0 -204
  227. package/src/core/aggregation/transport/http/errors.ts +0 -11
  228. package/src/core/aggregation/transport/http/inbox-buffer.ts +0 -53
  229. package/src/core/aggregation/transport/http/index.ts +0 -11
  230. package/src/core/aggregation/transport/http/nonce-cache.ts +0 -43
  231. package/src/core/aggregation/transport/http/protocol.ts +0 -57
  232. package/src/core/aggregation/transport/http/rate-limiter.ts +0 -75
  233. package/src/core/aggregation/transport/http/request-auth.ts +0 -164
  234. package/src/core/aggregation/transport/http/server.ts +0 -615
  235. package/src/core/aggregation/transport/http/sse-stream.ts +0 -121
  236. package/src/core/aggregation/transport/http/sse-writer.ts +0 -23
  237. package/src/core/aggregation/transport/in-memory.ts +0 -178
  238. package/src/core/aggregation/transport/index.ts +0 -7
  239. package/src/core/aggregation/transport/nostr.ts +0 -576
  240. package/src/core/aggregation/transport/transport.ts +0 -79
@@ -1,350 +0,0 @@
1
- import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
2
- import { Identifier } from '../../../identifier.js';
3
- import { CONSOLE_LOGGER } from '../../logger.js';
4
- import { reviveFromWire, signEnvelope, verifyEnvelope } from './envelope.js';
5
- import { HttpTransportError } from './errors.js';
6
- import { DEFAULT_CLOCK_SKEW_SEC, HTTP_ROUTE, SSE_EVENT, } from './protocol.js';
7
- import { buildRequestAuth } from './request-auth.js';
8
- import { parseSseStream } from './sse-stream.js';
9
- /** Default exponential backoff: 1s, 2s, 4s, ..., capped at 30s, 20% jitter. */
10
- export function defaultReconnectBackoff(attempt) {
11
- const base = Math.min(1000 * 2 ** attempt, 30_000);
12
- const jitter = base * 0.2 * Math.random();
13
- return Math.floor(base + jitter);
14
- }
15
- /**
16
- * HTTP transport client. Implements the transport-agnostic {@link Transport}
17
- * interface; the wire is fetch-based SSE for incoming events and fetch-based
18
- * POST for outgoing messages. All runtime I/O goes through `fetchImpl` so
19
- * tests can substitute a mock without touching the network.
20
- */
21
- export class HttpClientTransport {
22
- name = 'http';
23
- #baseUrl;
24
- #fetch;
25
- #logger;
26
- #backoff;
27
- #clockSkewSec;
28
- #actors = new Map();
29
- #peers = new Map();
30
- #started = false;
31
- #broadcastAbort;
32
- constructor(config) {
33
- const base = typeof config.baseUrl === 'string' ? new URL(config.baseUrl) : new URL(config.baseUrl.href);
34
- if (!base.pathname.endsWith('/'))
35
- base.pathname += '/';
36
- this.#baseUrl = base;
37
- this.#logger = config.logger ?? CONSOLE_LOGGER;
38
- this.#backoff = config.reconnectBackoff ?? defaultReconnectBackoff;
39
- this.#clockSkewSec = config.clockSkewSec ?? DEFAULT_CLOCK_SKEW_SEC;
40
- const fetchImpl = config.fetchImpl ?? globalThis.fetch;
41
- if (typeof fetchImpl !== 'function') {
42
- throw new HttpTransportError('No fetch implementation available. Pass config.fetchImpl explicitly.', 'NO_FETCH_IMPL');
43
- }
44
- this.#fetch = fetchImpl;
45
- }
46
- start() {
47
- if (this.#started)
48
- return;
49
- this.#started = true;
50
- this.#broadcastAbort = new AbortController();
51
- this.#runBroadcastLoop(this.#broadcastAbort.signal);
52
- for (const [did, entry] of this.#actors) {
53
- this.#openInbox(did, entry);
54
- }
55
- }
56
- /**
57
- * Tear down all SSE subscriptions and stop reconnect loops. Not part of the
58
- * {@link Transport} interface, but needed in tests and whenever a client
59
- * wants to cleanly disconnect without unregistering every actor.
60
- *
61
- * Idempotent. Actors remain registered (re-call {@link start} to resume).
62
- */
63
- stop() {
64
- this.#broadcastAbort?.abort();
65
- this.#broadcastAbort = undefined;
66
- for (const entry of this.#actors.values()) {
67
- entry.inboxAbort?.abort();
68
- entry.inboxAbort = undefined;
69
- }
70
- this.#started = false;
71
- }
72
- registerActor(did, keys) {
73
- const existing = this.#actors.get(did);
74
- if (existing?.inboxAbort)
75
- existing.inboxAbort.abort();
76
- const entry = { keys, handlers: new Map() };
77
- this.#actors.set(did, entry);
78
- if (this.#started)
79
- this.#openInbox(did, entry);
80
- }
81
- unregisterActor(did) {
82
- const entry = this.#actors.get(did);
83
- if (!entry)
84
- return;
85
- entry.inboxAbort?.abort();
86
- this.#actors.delete(did);
87
- this.#peers.delete(did);
88
- }
89
- getActorPk(did) {
90
- return this.#actors.get(did)?.keys.publicKey.compressed;
91
- }
92
- registerPeer(did, communicationPk) {
93
- try {
94
- new CompressedSecp256k1PublicKey(communicationPk);
95
- }
96
- catch {
97
- throw new HttpTransportError(`Invalid communication public key for peer ${did}: expected a 33-byte compressed secp256k1 key.`, 'INVALID_PEER_KEY', { did, keyLength: communicationPk.length });
98
- }
99
- this.#peers.set(did, communicationPk);
100
- }
101
- getPeerPk(did) {
102
- return this.#peers.get(did);
103
- }
104
- registerMessageHandler(actorDid, messageType, handler) {
105
- const actor = this.#actors.get(actorDid);
106
- if (!actor) {
107
- throw new HttpTransportError(`Cannot register handler: actor ${actorDid} not registered. Call registerActor() first.`, 'UNKNOWN_ACTOR', { did: actorDid });
108
- }
109
- actor.handlers.set(messageType, handler);
110
- }
111
- unregisterMessageHandler(actorDid, messageType) {
112
- this.#actors.get(actorDid)?.handlers.delete(messageType);
113
- }
114
- async sendMessage(message, sender, recipient) {
115
- const actor = this.#actors.get(sender);
116
- if (!actor) {
117
- throw new HttpTransportError(`Unknown sender: ${sender}. Call registerActor() before sending messages.`, 'UNKNOWN_SENDER', { did: sender });
118
- }
119
- const envelope = signEnvelope(message, { did: sender, keys: actor.keys }, { to: recipient });
120
- const url = this.#route(HTTP_ROUTE.MESSAGES);
121
- const res = await this.#fetch(url, {
122
- method: 'POST',
123
- headers: { 'content-type': 'application/json' },
124
- body: JSON.stringify(envelope),
125
- });
126
- if (!res.ok) {
127
- const body = await safeText(res);
128
- throw new HttpTransportError(`sendMessage failed: HTTP ${res.status}`, 'SEND_MESSAGE_HTTP', { status: res.status, body: body.slice(0, 256), messageType: message.type });
129
- }
130
- }
131
- publishRepeating(message, sender, intervalMs, recipient) {
132
- let stopped = false;
133
- const attempt = () => {
134
- if (stopped)
135
- return;
136
- this.sendMessage(message, sender, recipient).catch((err) => {
137
- this.#logger.debug('publishRepeating send failed:', err);
138
- });
139
- };
140
- attempt();
141
- const timer = setInterval(attempt, intervalMs);
142
- return () => {
143
- if (stopped)
144
- return;
145
- stopped = true;
146
- clearInterval(timer);
147
- };
148
- }
149
- #route(template) {
150
- // Strip the leading slash so `new URL(rel, base)` is resolved against the
151
- // base's pathname instead of replacing it.
152
- return new URL(template.replace(/^\//, ''), this.#baseUrl);
153
- }
154
- #openInbox(did, entry) {
155
- const abort = new AbortController();
156
- entry.inboxAbort = abort;
157
- this.#runInboxLoop(did, entry, abort.signal);
158
- }
159
- async #runBroadcastLoop(signal) {
160
- const url = this.#route(HTTP_ROUTE.ADVERTS);
161
- let attempt = 0;
162
- while (!signal.aborted) {
163
- try {
164
- const res = await this.#fetch(url, {
165
- method: 'GET',
166
- headers: { accept: 'text/event-stream' },
167
- signal,
168
- });
169
- if (!res.ok || !res.body) {
170
- this.#logger.warn(`Broadcast subscribe failed: HTTP ${res.status}`);
171
- await sleep(this.#backoff(attempt++), signal);
172
- continue;
173
- }
174
- attempt = 0;
175
- for await (const ev of parseSseStream(res.body)) {
176
- if (signal.aborted)
177
- return;
178
- if (ev.event !== SSE_EVENT.ADVERT)
179
- continue;
180
- this.#dispatchBroadcast(ev.data);
181
- }
182
- }
183
- catch (err) {
184
- if (signal.aborted)
185
- return;
186
- this.#logger.debug('Broadcast loop error:', err);
187
- try {
188
- await sleep(this.#backoff(attempt++), signal);
189
- }
190
- catch {
191
- return; // sleep was aborted
192
- }
193
- }
194
- }
195
- }
196
- async #runInboxLoop(did, entry, signal) {
197
- const url = this.#route(HTTP_ROUTE.ACTOR_INBOX.replace('{did}', encodeURIComponent(did)));
198
- let attempt = 0;
199
- while (!signal.aborted) {
200
- try {
201
- const auth = buildRequestAuth(did, entry.keys, url.pathname);
202
- const res = await this.#fetch(url, {
203
- method: 'GET',
204
- headers: { accept: 'text/event-stream', authorization: auth },
205
- signal,
206
- });
207
- if (!res.ok || !res.body) {
208
- this.#logger.warn(`Inbox subscribe failed for ${did}: HTTP ${res.status}`);
209
- await sleep(this.#backoff(attempt++), signal);
210
- continue;
211
- }
212
- attempt = 0;
213
- for await (const ev of parseSseStream(res.body)) {
214
- if (signal.aborted)
215
- return;
216
- if (ev.event !== SSE_EVENT.MESSAGE)
217
- continue;
218
- await this.#dispatchInbox(ev.data, did, entry);
219
- }
220
- }
221
- catch (err) {
222
- if (signal.aborted)
223
- return;
224
- this.#logger.debug(`Inbox loop error for ${did}:`, err);
225
- try {
226
- await sleep(this.#backoff(attempt++), signal);
227
- }
228
- catch {
229
- return;
230
- }
231
- }
232
- }
233
- }
234
- #dispatchBroadcast(dataJson) {
235
- const envelope = parseEnvelope(dataJson, this.#logger);
236
- if (!envelope)
237
- return;
238
- const senderPk = this.#resolveSenderPk(envelope.from);
239
- if (!senderPk) {
240
- this.#logger.debug(`Broadcast from unresolvable DID: ${envelope.from}`);
241
- return;
242
- }
243
- try {
244
- verifyEnvelope(envelope, senderPk, { clockSkewSec: this.#clockSkewSec });
245
- }
246
- catch (err) {
247
- this.#logger.debug('Broadcast envelope verification failed:', err);
248
- return;
249
- }
250
- const revived = reviveFromWire(envelope.message);
251
- const flat = flattenMessage(revived);
252
- const messageType = typeof flat.type === 'string' ? flat.type : undefined;
253
- if (!messageType)
254
- return;
255
- for (const actor of this.#actors.values()) {
256
- const handler = actor.handlers.get(messageType);
257
- if (handler)
258
- void Promise.resolve(handler(flat));
259
- }
260
- }
261
- async #dispatchInbox(dataJson, actorDid, entry) {
262
- const envelope = parseEnvelope(dataJson, this.#logger);
263
- if (!envelope)
264
- return;
265
- const senderPk = this.#resolveSenderPk(envelope.from);
266
- if (!senderPk) {
267
- this.#logger.debug(`Inbox message from unresolvable DID: ${envelope.from}`);
268
- return;
269
- }
270
- try {
271
- verifyEnvelope(envelope, senderPk, {
272
- clockSkewSec: this.#clockSkewSec,
273
- expectedTo: actorDid,
274
- });
275
- }
276
- catch (err) {
277
- this.#logger.debug(`Inbox envelope verification failed for ${actorDid}:`, err);
278
- return;
279
- }
280
- const revived = reviveFromWire(envelope.message);
281
- const flat = flattenMessage(revived);
282
- const messageType = typeof flat.type === 'string' ? flat.type : undefined;
283
- if (!messageType)
284
- return;
285
- const handler = entry.handlers.get(messageType);
286
- if (handler)
287
- await handler(flat);
288
- }
289
- #resolveSenderPk(did) {
290
- const peerBytes = this.#peers.get(did);
291
- if (peerBytes) {
292
- try {
293
- return new CompressedSecp256k1PublicKey(peerBytes);
294
- }
295
- catch { /* fall through to DID decode */ }
296
- }
297
- try {
298
- const components = Identifier.decode(did);
299
- if (components.idType === 'KEY') {
300
- return new CompressedSecp256k1PublicKey(components.genesisBytes);
301
- }
302
- }
303
- catch {
304
- // Not a decodable did:btcr2 KEY identifier.
305
- }
306
- return undefined;
307
- }
308
- }
309
- function sleep(ms, signal) {
310
- if (ms <= 0)
311
- return Promise.resolve();
312
- return new Promise((resolve, reject) => {
313
- const onAbort = () => {
314
- clearTimeout(timer);
315
- reject(new Error('aborted'));
316
- };
317
- const timer = setTimeout(() => {
318
- signal.removeEventListener('abort', onAbort);
319
- resolve();
320
- }, ms);
321
- if (signal.aborted)
322
- onAbort();
323
- else
324
- signal.addEventListener('abort', onAbort, { once: true });
325
- });
326
- }
327
- async function safeText(res) {
328
- try {
329
- return await res.text();
330
- }
331
- catch {
332
- return '';
333
- }
334
- }
335
- function parseEnvelope(dataJson, logger) {
336
- try {
337
- return JSON.parse(dataJson);
338
- }
339
- catch (err) {
340
- logger.debug('SSE event: failed to parse envelope JSON:', err);
341
- return undefined;
342
- }
343
- }
344
- function flattenMessage(msg) {
345
- if (msg.body && typeof msg.body === 'object') {
346
- return { ...msg, ...msg.body };
347
- }
348
- return msg;
349
- }
350
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAejD,+EAA+E;AAC/E,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,MAAM,IAAI,GAAK,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,OAAO,EAAE,MAAM,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;AACnC,CAAC;AAQD;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IACrB,IAAI,GAAG,MAAM,CAAC;IAEd,QAAQ,CAAW;IACnB,MAAM,CAAsB;IAC5B,OAAO,CAAe;IACtB,QAAQ,CAAmC;IAC3C,aAAa,CAAS;IAEtB,OAAO,GAA8B,IAAI,GAAG,EAAE,CAAC;IAC/C,MAAM,GAA+B,IAAI,GAAG,EAAE,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AAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,GAAa;IACnC,IAAI,CAAC;QAAC,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAAC,CAAC;IAChC,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC;IAAC,CAAC;AACtB,CAAC;AAED,SAAS,aAAa,CAAC,QAAgB,EAAE,MAAc;IACrD,IAAI,CAAC;QAAC,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAmB,CAAC;IAAC,CAAC;IACtD,OAAM,GAAG,EAAE,CAAC;QACV,MAAM,CAAC,KAAK,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;QAC/D,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,GAA4B;IAClD,IAAG,GAAG,CAAC,IAAI,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,EAAE,GAAG,GAAG,EAAE,GAAI,GAAG,CAAC,IAAgC,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,126 +0,0 @@
1
- import { canonicalHashBytes } from '@did-btcr2/common';
2
- import { bytesToHex, hexToBytes, randomBytes } from '@noble/hashes/utils';
3
- import { HttpTransportError } from './errors.js';
4
- import { DEFAULT_CLOCK_SKEW_SEC, DEFAULT_NONCE_LEN_BYTES, HTTP_ENVELOPE_VERSION, } from './protocol.js';
5
- /**
6
- * Build a {@link SignedEnvelope} around `message`.
7
- *
8
- * Pure function - no I/O beyond `randomBytes` for nonce generation (which
9
- * uses the platform's cryptographic RNG: `crypto.getRandomValues` in browsers,
10
- * `node:crypto` in Node). Deterministic when both `nonce` and `timestamp` are
11
- * supplied via {@link SignEnvelopeOptions}.
12
- */
13
- export function signEnvelope(message, sender, opts = {}) {
14
- const timestamp = opts.timestamp ?? Math.floor(Date.now() / 1000);
15
- const nonce = opts.nonce ?? bytesToHex(randomBytes(DEFAULT_NONCE_LEN_BYTES));
16
- const messageJson = normalizeForWire(normalizeMessage(message));
17
- const unsigned = {
18
- v: HTTP_ENVELOPE_VERSION,
19
- from: sender.did,
20
- ...(opts.to !== undefined ? { to: opts.to } : {}),
21
- timestamp,
22
- nonce,
23
- message: messageJson,
24
- };
25
- const digest = canonicalHashBytes(unsigned);
26
- const sig = sender.keys.secretKey.sign(digest, { scheme: 'schnorr' });
27
- return { ...unsigned, sig: bytesToHex(sig) };
28
- }
29
- /**
30
- * Verify a {@link SignedEnvelope} against the sender's compressed secp256k1
31
- * communication public key. Throws {@link HttpTransportError} on any failure;
32
- * returns normally on success.
33
- *
34
- * Does NOT check nonce uniqueness - replay protection is the caller's
35
- * responsibility (the server-side transport maintains an LRU cache).
36
- */
37
- export function verifyEnvelope(envelope, senderPk, opts = {}) {
38
- if (envelope.v !== HTTP_ENVELOPE_VERSION) {
39
- throw new HttpTransportError(`Unsupported envelope version: ${envelope.v}`, 'ENVELOPE_VERSION_MISMATCH', { version: envelope.v, expected: HTTP_ENVELOPE_VERSION });
40
- }
41
- if (opts.expectedFrom !== undefined && envelope.from !== opts.expectedFrom) {
42
- throw new HttpTransportError(`Envelope from mismatch: expected ${opts.expectedFrom}, got ${envelope.from}`, 'ENVELOPE_FROM_MISMATCH', { expected: opts.expectedFrom, got: envelope.from });
43
- }
44
- if ('expectedTo' in opts && envelope.to !== opts.expectedTo) {
45
- throw new HttpTransportError(`Envelope to mismatch: expected ${opts.expectedTo ?? '<broadcast>'}, got ${envelope.to ?? '<broadcast>'}`, 'ENVELOPE_TO_MISMATCH', { expected: opts.expectedTo, got: envelope.to });
46
- }
47
- const skewSec = opts.clockSkewSec ?? DEFAULT_CLOCK_SKEW_SEC;
48
- const nowMs = opts.now ? opts.now() : Date.now();
49
- const nowSec = Math.floor(nowMs / 1000);
50
- const diff = Math.abs(nowSec - envelope.timestamp);
51
- if (diff > skewSec) {
52
- throw new HttpTransportError(`Envelope timestamp out of skew: ${diff}s > ${skewSec}s`, 'ENVELOPE_TIMESTAMP_SKEW', { diff, skewSec, timestamp: envelope.timestamp, now: nowSec });
53
- }
54
- let sigBytes;
55
- try {
56
- sigBytes = hexToBytes(envelope.sig);
57
- }
58
- catch {
59
- throw new HttpTransportError('Envelope signature is not valid hex', 'ENVELOPE_SIG_HEX');
60
- }
61
- if (sigBytes.length !== 64) {
62
- throw new HttpTransportError(`Invalid signature length: ${sigBytes.length} (expected 64)`, 'ENVELOPE_SIG_LENGTH', { length: sigBytes.length });
63
- }
64
- const { sig: _sig, ...unsigned } = envelope;
65
- const digest = canonicalHashBytes(unsigned);
66
- const ok = senderPk.verify(sigBytes, digest, { scheme: 'schnorr' });
67
- if (!ok) {
68
- throw new HttpTransportError('Envelope signature verification failed', 'ENVELOPE_SIG_INVALID');
69
- }
70
- }
71
- function normalizeMessage(message) {
72
- const maybeToJSON = message.toJSON;
73
- if (typeof maybeToJSON === 'function') {
74
- return maybeToJSON.call(message);
75
- }
76
- return message;
77
- }
78
- /**
79
- * Recursively replace `Uint8Array` values with `{ __bytes: hex }` sentinel
80
- * objects so they survive JSON canonicalization / HTTP body serialization.
81
- * Pairs with {@link reviveFromWire}.
82
- *
83
- * Without this, `JSON.stringify` serializes a `Uint8Array` as an index-keyed
84
- * object (`{"0":1,"1":2,...}`), which `canonicalize` then re-parses into a
85
- * plain object - the receiver cannot reconstruct the original bytes even
86
- * though the signature still verifies.
87
- */
88
- export function normalizeForWire(value) {
89
- if (value instanceof Uint8Array) {
90
- return { __bytes: bytesToHex(value) };
91
- }
92
- if (Array.isArray(value)) {
93
- return value.map((v) => normalizeForWire(v));
94
- }
95
- if (value && typeof value === 'object') {
96
- const out = {};
97
- for (const [k, v] of Object.entries(value)) {
98
- out[k] = normalizeForWire(v);
99
- }
100
- return out;
101
- }
102
- return value;
103
- }
104
- /**
105
- * Recursively convert `{ __bytes: hex }` sentinels back into `Uint8Array`
106
- * values. Call on `envelope.message` *after* successful verification and
107
- * before handing the payload to a runner's handler.
108
- */
109
- export function reviveFromWire(value) {
110
- if (value && typeof value === 'object' && !Array.isArray(value)) {
111
- const rec = value;
112
- const keys = Object.keys(rec);
113
- if (keys.length === 1 && keys[0] === '__bytes' && typeof rec.__bytes === 'string') {
114
- return hexToBytes(rec.__bytes);
115
- }
116
- const out = {};
117
- for (const [k, v] of Object.entries(rec))
118
- out[k] = reviveFromWire(v);
119
- return out;
120
- }
121
- if (Array.isArray(value)) {
122
- return value.map((v) => reviveFromWire(v));
123
- }
124
- return value;
125
- }
126
- //# sourceMappingURL=envelope.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,eAAe,CAAC;AA2BvB;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAwB,EACxB,MAA8C,EAC9C,OAA+B,EAAE;IAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAClE,MAAM,KAAK,GAAO,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC;IACjF,MAAM,WAAW,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAA4B,CAAC;IAE3F,MAAM,QAAQ,GAAgC;QAC5C,CAAC,EAAW,qBAAqB;QACjC,IAAI,EAAQ,MAAM,CAAC,GAAG;QACtB,G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,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,IAAG,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/D,MAAM,GAAG,GAAG,KAAgC,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAG,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACjF,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,GAAG,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO,GAAG,CAAC;IACb,CAAC;IACD,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,11 +0,0 @@
1
- import { TransportAdapterError } from '../error.js';
2
- /**
3
- * Errors raised by the HTTP transport adapter. Extends {@link TransportAdapterError}
4
- * so callers can catch HTTP-specific failures narrowly or transport failures broadly.
5
- */
6
- export class HttpTransportError extends TransportAdapterError {
7
- constructor(message, type = 'HttpTransportError', data) {
8
- super(message, type, { adapter: 'http', ...(data ?? {}) });
9
- }
10
- }
11
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAO,kBAAmB,SAAQ,qBAAqB;IAC3D,YAAY,OAAe,EAAE,OAAe,oBAAoB,EAAE,IAA0B;QAC1F,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
@@ -1,45 +0,0 @@
1
- /**
2
- * Fixed-capacity FIFO ring buffer of SSE events for a single actor's inbox.
3
- *
4
- * When a subscriber (re)connects with a `Last-Event-ID` header, the server
5
- * uses {@link since} to replay everything that arrived while the subscriber
6
- * was disconnected. Events older than the replay window (evicted from the
7
- * ring) are unrecoverable - callers should choose `capacity` based on
8
- * expected message rate × acceptable reconnect window.
9
- */
10
- export class InboxBuffer {
11
- #capacity;
12
- #entries = [];
13
- #nextId = 1;
14
- constructor(capacity = 100) {
15
- if (capacity < 1)
16
- throw new Error(`InboxBuffer capacity must be >= 1; got ${capacity}`);
17
- this.#capacity = capacity;
18
- }
19
- /** Append an event. Returns the stored record (including its assigned id). */
20
- append(event, data) {
21
- const stored = { id: String(this.#nextId++), event, data };
22
- this.#entries.push(stored);
23
- if (this.#entries.length > this.#capacity)
24
- this.#entries.shift();
25
- return stored;
26
- }
27
- /**
28
- * Return stored events with id strictly greater than `lastEventId`. If
29
- * `lastEventId` is unset or unparseable, returns everything currently
30
- * retained.
31
- */
32
- since(lastEventId) {
33
- if (!lastEventId)
34
- return this.#entries.slice();
35
- const boundary = Number(lastEventId);
36
- if (!Number.isFinite(boundary))
37
- return this.#entries.slice();
38
- return this.#entries.filter((e) => Number(e.id) > boundary);
39
- }
40
- /** Currently retained event count. */
41
- size() {
42
- return this.#entries.length;
43
- }
44
- }
45
- //# sourceMappingURL=inbox-buffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"inbox-buffer.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/inbox-buffer.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IACb,SAAS,CAAS;IAClB,QAAQ,GAAkB,EAAE,CAAC;IACtC,OAAO,GAAG,CAAC,CAAC;IAEZ,YAAY,QAAQ,GAAG,GAAG;QACxB,IAAG,QAAQ,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,QAAQ,EAAE,CAAC,CAAC;QACvF,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,8EAA8E;IAC9E,MAAM,CAAC,KAAa,EAAE,IAAY;QAChC,MAAM,MAAM,GAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACxE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3B,IAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS;YAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAChE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAoB;QACxB,IAAG,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QACrC,IAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC9D,CAAC;IAED,sCAAsC;IACtC,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;CACF"}
@@ -1,12 +0,0 @@
1
- export * from './errors.js';
2
- export * from './protocol.js';
3
- export * from './envelope.js';
4
- export * from './sse-stream.js';
5
- export * from './sse-writer.js';
6
- export * from './request-auth.js';
7
- export * from './nonce-cache.js';
8
- export * from './rate-limiter.js';
9
- export * from './inbox-buffer.js';
10
- export * from './client.js';
11
- export * from './server.js';
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
@@ -1,38 +0,0 @@
1
- /**
2
- * Bounded anti-replay cache for `(did, nonce)` pairs.
3
- *
4
- * Replay windowing is the caller's responsibility - this cache only detects
5
- * duplicates. Callers are expected to reject envelopes/headers whose timestamp
6
- * is outside the clock-skew window *before* consulting the cache, so entries
7
- * here are always within the protocol's acceptable window.
8
- *
9
- * Eviction is strict-FIFO (Map insertion order) once `maxEntries` is reached.
10
- */
11
- export class NonceCache {
12
- #maxEntries;
13
- #entries = new Map();
14
- constructor(config = {}) {
15
- this.#maxEntries = config.maxEntries ?? 10_000;
16
- }
17
- /**
18
- * Record a nonce. Returns `true` if it was novel (caller should accept the
19
- * request) or `false` if it was a replay (caller should reject).
20
- */
21
- store(did, nonce, timestampSec) {
22
- const key = `${did}:${nonce}`;
23
- if (this.#entries.has(key))
24
- return false;
25
- this.#entries.set(key, timestampSec);
26
- if (this.#entries.size > this.#maxEntries) {
27
- const oldest = this.#entries.keys().next();
28
- if (!oldest.done)
29
- this.#entries.delete(oldest.value);
30
- }
31
- return true;
32
- }
33
- /** Current cache size. Exposed for observability and tests. */
34
- size() {
35
- return this.#entries.size;
36
- }
37
- }
38
- //# sourceMappingURL=nonce-cache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nonce-cache.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/nonce-cache.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACZ,WAAW,CAAS;IACpB,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE9C,YAAY,SAA2B,EAAE;QACvC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC;IACjD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAW,EAAE,KAAa,EAAE,YAAoB;QACpD,MAAM,GAAG,GAAG,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QAC9B,IAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QACrC,IAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YAC3C,IAAG,CAAC,MAAM,CAAC,IAAI;gBAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+DAA+D;IAC/D,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;CACF"}