@did-btcr2/method 0.28.0 → 0.32.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 (193) hide show
  1. package/README.md +13 -5
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +34125 -44647
  4. package/dist/browser.mjs +26409 -36931
  5. package/dist/cjs/index.js +2869 -679
  6. package/dist/esm/core/aggregation/beacon-strategy.js +62 -0
  7. package/dist/esm/core/aggregation/beacon-strategy.js.map +1 -0
  8. package/dist/esm/core/aggregation/cohort.js +31 -8
  9. package/dist/esm/core/aggregation/cohort.js.map +1 -1
  10. package/dist/esm/core/aggregation/logger.js +15 -0
  11. package/dist/esm/core/aggregation/logger.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/base.js +12 -1
  13. package/dist/esm/core/aggregation/messages/base.js.map +1 -1
  14. package/dist/esm/core/aggregation/messages/bodies.js +90 -0
  15. package/dist/esm/core/aggregation/messages/bodies.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/factories.js.map +1 -1
  17. package/dist/esm/core/aggregation/messages/index.js +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js.map +1 -1
  19. package/dist/esm/core/aggregation/participant.js +39 -46
  20. package/dist/esm/core/aggregation/participant.js.map +1 -1
  21. package/dist/esm/core/aggregation/runner/participant-runner.js +33 -7
  22. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
  23. package/dist/esm/core/aggregation/runner/service-runner.js +198 -19
  24. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -1
  25. package/dist/esm/core/aggregation/service.js +143 -15
  26. package/dist/esm/core/aggregation/service.js.map +1 -1
  27. package/dist/esm/core/aggregation/signing-session.js +44 -5
  28. package/dist/esm/core/aggregation/signing-session.js.map +1 -1
  29. package/dist/esm/core/aggregation/transport/didcomm.js +9 -0
  30. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -1
  31. package/dist/esm/core/aggregation/transport/factory.js +15 -6
  32. package/dist/esm/core/aggregation/transport/factory.js.map +1 -1
  33. package/dist/esm/core/aggregation/transport/http/client.js +350 -0
  34. package/dist/esm/core/aggregation/transport/http/client.js.map +1 -0
  35. package/dist/esm/core/aggregation/transport/http/envelope.js +126 -0
  36. package/dist/esm/core/aggregation/transport/http/envelope.js.map +1 -0
  37. package/dist/esm/core/aggregation/transport/http/errors.js +11 -0
  38. package/dist/esm/core/aggregation/transport/http/errors.js.map +1 -0
  39. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js +45 -0
  40. package/dist/esm/core/aggregation/transport/http/inbox-buffer.js.map +1 -0
  41. package/dist/esm/core/aggregation/transport/http/index.js +12 -0
  42. package/dist/esm/core/aggregation/transport/http/index.js.map +1 -0
  43. package/dist/esm/core/aggregation/transport/http/nonce-cache.js +38 -0
  44. package/dist/esm/core/aggregation/transport/http/nonce-cache.js.map +1 -0
  45. package/dist/esm/core/aggregation/transport/http/protocol.js +28 -0
  46. package/dist/esm/core/aggregation/transport/http/protocol.js.map +1 -0
  47. package/dist/esm/core/aggregation/transport/http/rate-limiter.js +45 -0
  48. package/dist/esm/core/aggregation/transport/http/rate-limiter.js.map +1 -0
  49. package/dist/esm/core/aggregation/transport/http/request-auth.js +100 -0
  50. package/dist/esm/core/aggregation/transport/http/request-auth.js.map +1 -0
  51. package/dist/esm/core/aggregation/transport/http/server.js +481 -0
  52. package/dist/esm/core/aggregation/transport/http/server.js.map +1 -0
  53. package/dist/esm/core/aggregation/transport/http/sse-stream.js +110 -0
  54. package/dist/esm/core/aggregation/transport/http/sse-stream.js.map +1 -0
  55. package/dist/esm/core/aggregation/transport/http/sse-writer.js +25 -0
  56. package/dist/esm/core/aggregation/transport/http/sse-writer.js.map +1 -0
  57. package/dist/esm/core/aggregation/transport/index.js +1 -0
  58. package/dist/esm/core/aggregation/transport/index.js.map +1 -1
  59. package/dist/esm/core/aggregation/transport/nostr.js +245 -16
  60. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -1
  61. package/dist/esm/core/beacon/beacon.js +295 -63
  62. package/dist/esm/core/beacon/beacon.js.map +1 -1
  63. package/dist/esm/core/beacon/cas-beacon.js +3 -3
  64. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  65. package/dist/esm/core/beacon/singleton-beacon.js +3 -3
  66. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  67. package/dist/esm/core/beacon/smt-beacon.js +3 -3
  68. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  69. package/dist/esm/core/beacon/utils.js +14 -9
  70. package/dist/esm/core/beacon/utils.js.map +1 -1
  71. package/dist/esm/core/updater.js +63 -55
  72. package/dist/esm/core/updater.js.map +1 -1
  73. package/dist/esm/did-btcr2.js +0 -4
  74. package/dist/esm/did-btcr2.js.map +1 -1
  75. package/dist/esm/index.js +2 -0
  76. package/dist/esm/index.js.map +1 -1
  77. package/dist/esm/utils/did-document.js +2 -2
  78. package/dist/esm/utils/did-document.js.map +1 -1
  79. package/dist/types/core/aggregation/beacon-strategy.d.ts +52 -0
  80. package/dist/types/core/aggregation/beacon-strategy.d.ts.map +1 -0
  81. package/dist/types/core/aggregation/cohort.d.ts +20 -3
  82. package/dist/types/core/aggregation/cohort.d.ts.map +1 -1
  83. package/dist/types/core/aggregation/logger.d.ts +22 -0
  84. package/dist/types/core/aggregation/logger.d.ts.map +1 -0
  85. package/dist/types/core/aggregation/messages/base.d.ts +13 -1
  86. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -1
  87. package/dist/types/core/aggregation/messages/bodies.d.ts +130 -0
  88. package/dist/types/core/aggregation/messages/bodies.d.ts.map +1 -0
  89. package/dist/types/core/aggregation/messages/factories.d.ts +1 -0
  90. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -1
  91. package/dist/types/core/aggregation/messages/index.d.ts +1 -0
  92. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -1
  93. package/dist/types/core/aggregation/participant.d.ts +2 -0
  94. package/dist/types/core/aggregation/participant.d.ts.map +1 -1
  95. package/dist/types/core/aggregation/runner/events.d.ts +32 -6
  96. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -1
  97. package/dist/types/core/aggregation/runner/participant-runner.d.ts +7 -5
  98. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
  99. package/dist/types/core/aggregation/runner/service-runner.d.ts +33 -3
  100. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -1
  101. package/dist/types/core/aggregation/service.d.ts +33 -2
  102. package/dist/types/core/aggregation/service.d.ts.map +1 -1
  103. package/dist/types/core/aggregation/signing-session.d.ts +5 -1
  104. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -1
  105. package/dist/types/core/aggregation/transport/didcomm.d.ts +3 -0
  106. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -1
  107. package/dist/types/core/aggregation/transport/factory.d.ts +22 -7
  108. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -1
  109. package/dist/types/core/aggregation/transport/http/client.d.ts +48 -0
  110. package/dist/types/core/aggregation/transport/http/client.d.ts.map +1 -0
  111. package/dist/types/core/aggregation/transport/http/envelope.d.ts +64 -0
  112. package/dist/types/core/aggregation/transport/http/envelope.d.ts.map +1 -0
  113. package/dist/types/core/aggregation/transport/http/errors.d.ts +9 -0
  114. package/dist/types/core/aggregation/transport/http/errors.d.ts.map +1 -0
  115. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts +32 -0
  116. package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts.map +1 -0
  117. package/dist/types/core/aggregation/transport/http/index.d.ts +12 -0
  118. package/dist/types/core/aggregation/transport/http/index.d.ts.map +1 -0
  119. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts +26 -0
  120. package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts.map +1 -0
  121. package/dist/types/core/aggregation/transport/http/protocol.d.ts +53 -0
  122. package/dist/types/core/aggregation/transport/http/protocol.d.ts.map +1 -0
  123. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts +41 -0
  124. package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts.map +1 -0
  125. package/dist/types/core/aggregation/transport/http/request-auth.d.ts +50 -0
  126. package/dist/types/core/aggregation/transport/http/request-auth.d.ts.map +1 -0
  127. package/dist/types/core/aggregation/transport/http/server.d.ts +110 -0
  128. package/dist/types/core/aggregation/transport/http/server.d.ts.map +1 -0
  129. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts +34 -0
  130. package/dist/types/core/aggregation/transport/http/sse-stream.d.ts.map +1 -0
  131. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts +12 -0
  132. package/dist/types/core/aggregation/transport/http/sse-writer.d.ts.map +1 -0
  133. package/dist/types/core/aggregation/transport/index.d.ts +1 -0
  134. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -1
  135. package/dist/types/core/aggregation/transport/nostr.d.ts +99 -1
  136. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -1
  137. package/dist/types/core/aggregation/transport/transport.d.ts +26 -1
  138. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -1
  139. package/dist/types/core/beacon/beacon.d.ts +149 -22
  140. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  141. package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
  142. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  143. package/dist/types/core/beacon/singleton-beacon.d.ts +3 -3
  144. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  145. package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
  146. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  147. package/dist/types/core/beacon/utils.d.ts +2 -2
  148. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  149. package/dist/types/core/updater.d.ts +27 -12
  150. package/dist/types/core/updater.d.ts.map +1 -1
  151. package/dist/types/did-btcr2.d.ts.map +1 -1
  152. package/dist/types/index.d.ts +2 -0
  153. package/dist/types/index.d.ts.map +1 -1
  154. package/package.json +5 -7
  155. package/src/core/aggregation/beacon-strategy.ts +123 -0
  156. package/src/core/aggregation/cohort.ts +34 -8
  157. package/src/core/aggregation/logger.ts +33 -0
  158. package/src/core/aggregation/messages/base.ts +20 -5
  159. package/src/core/aggregation/messages/bodies.ts +223 -0
  160. package/src/core/aggregation/messages/factories.ts +1 -0
  161. package/src/core/aggregation/messages/index.ts +1 -0
  162. package/src/core/aggregation/participant.ts +40 -46
  163. package/src/core/aggregation/runner/events.ts +27 -3
  164. package/src/core/aggregation/runner/participant-runner.ts +41 -7
  165. package/src/core/aggregation/runner/service-runner.ts +227 -19
  166. package/src/core/aggregation/service.ts +189 -20
  167. package/src/core/aggregation/signing-session.ts +65 -7
  168. package/src/core/aggregation/transport/didcomm.ts +17 -0
  169. package/src/core/aggregation/transport/factory.ts +48 -12
  170. package/src/core/aggregation/transport/http/client.ts +409 -0
  171. package/src/core/aggregation/transport/http/envelope.ts +204 -0
  172. package/src/core/aggregation/transport/http/errors.ts +11 -0
  173. package/src/core/aggregation/transport/http/inbox-buffer.ts +53 -0
  174. package/src/core/aggregation/transport/http/index.ts +11 -0
  175. package/src/core/aggregation/transport/http/nonce-cache.ts +43 -0
  176. package/src/core/aggregation/transport/http/protocol.ts +57 -0
  177. package/src/core/aggregation/transport/http/rate-limiter.ts +75 -0
  178. package/src/core/aggregation/transport/http/request-auth.ts +164 -0
  179. package/src/core/aggregation/transport/http/server.ts +615 -0
  180. package/src/core/aggregation/transport/http/sse-stream.ts +121 -0
  181. package/src/core/aggregation/transport/http/sse-writer.ts +23 -0
  182. package/src/core/aggregation/transport/index.ts +1 -0
  183. package/src/core/aggregation/transport/nostr.ts +266 -23
  184. package/src/core/aggregation/transport/transport.ts +34 -1
  185. package/src/core/beacon/beacon.ts +411 -79
  186. package/src/core/beacon/cas-beacon.ts +4 -4
  187. package/src/core/beacon/singleton-beacon.ts +4 -4
  188. package/src/core/beacon/smt-beacon.ts +4 -4
  189. package/src/core/beacon/utils.ts +16 -11
  190. package/src/core/updater.ts +113 -67
  191. package/src/did-btcr2.ts +0 -5
  192. package/src/index.ts +2 -0
  193. package/src/utils/did-document.ts +2 -2
@@ -1,12 +1,27 @@
1
- import type { Transport, TransportType } from './transport.js';
2
- export interface TransportConfig {
3
- type: TransportType;
1
+ import type { Logger } from '../logger.js';
2
+ import type { HttpClientTransportConfig } from './http/client.js';
3
+ import type { HttpServerTransportConfig } from './http/server.js';
4
+ import type { Transport } from './transport.js';
5
+ /** Discriminated-union config for {@link TransportFactory.establish}. */
6
+ export type TransportConfig = NostrTransportConfigOption | DidCommTransportConfigOption | HttpClientTransportConfigOption | HttpServerTransportConfigOption;
7
+ export interface NostrTransportConfigOption {
8
+ type: 'nostr';
4
9
  relays?: string[];
10
+ logger?: Logger;
11
+ broadcastLookbackMs?: number;
5
12
  }
6
- /**
7
- * Factory for creating Transport instances.
8
- * @class TransportFactory
9
- */
13
+ export interface DidCommTransportConfigOption {
14
+ type: 'didcomm';
15
+ }
16
+ export interface HttpClientTransportConfigOption extends HttpClientTransportConfig {
17
+ type: 'http';
18
+ role: 'client';
19
+ }
20
+ export interface HttpServerTransportConfigOption extends HttpServerTransportConfig {
21
+ type: 'http';
22
+ role: 'server';
23
+ }
24
+ /** Factory for creating Transport instances. */
10
25
  export declare class TransportFactory {
11
26
  static establish(config: TransportConfig): Transport;
12
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/factory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS;CAarD"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAElE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAGlE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,yEAAyE;AACzE,MAAM,MAAM,eAAe,GACvB,0BAA0B,GAC1B,4BAA4B,GAC5B,+BAA+B,GAC/B,+BAA+B,CAAC;AAEpC,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,MAAM,WAAW,+BAAgC,SAAQ,yBAAyB;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,+BAAgC,SAAQ,yBAAyB;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,gDAAgD;AAChD,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS;CAwBrD"}
@@ -0,0 +1,48 @@
1
+ import type { SchnorrKeyPair } from '@did-btcr2/keypair';
2
+ import type { Logger } from '../../logger.js';
3
+ import type { BaseMessage } from '../../messages/base.js';
4
+ import type { MessageHandler, Transport } from '../transport.js';
5
+ export interface HttpClientTransportConfig {
6
+ /** Base URL of the aggregation service (e.g. `https://aggregator.example.com/`). */
7
+ baseUrl: string | URL;
8
+ /** Custom `fetch` implementation (tests, Workers, React Native). Defaults to `globalThis.fetch`. */
9
+ fetchImpl?: typeof fetch;
10
+ /** Diagnostic logger. Defaults to {@link CONSOLE_LOGGER}. */
11
+ logger?: Logger;
12
+ /** Reconnect backoff (ms) given attempt count (0-based). */
13
+ reconnectBackoff?: (attempt: number) => number;
14
+ /** Envelope / request-auth clock-skew tolerance in seconds. */
15
+ clockSkewSec?: number;
16
+ }
17
+ /** Default exponential backoff: 1s, 2s, 4s, ..., capped at 30s, 20% jitter. */
18
+ export declare function defaultReconnectBackoff(attempt: number): number;
19
+ /**
20
+ * HTTP transport client. Implements the transport-agnostic {@link Transport}
21
+ * interface; the wire is fetch-based SSE for incoming events and fetch-based
22
+ * POST for outgoing messages. All runtime I/O goes through `fetchImpl` so
23
+ * tests can substitute a mock without touching the network.
24
+ */
25
+ export declare class HttpClientTransport implements Transport {
26
+ #private;
27
+ readonly name = "http";
28
+ constructor(config: HttpClientTransportConfig);
29
+ start(): void;
30
+ /**
31
+ * Tear down all SSE subscriptions and stop reconnect loops. Not part of the
32
+ * {@link Transport} interface, but needed in tests and whenever a client
33
+ * wants to cleanly disconnect without unregistering every actor.
34
+ *
35
+ * Idempotent. Actors remain registered (re-call {@link start} to resume).
36
+ */
37
+ stop(): void;
38
+ registerActor(did: string, keys: SchnorrKeyPair): void;
39
+ unregisterActor(did: string): void;
40
+ getActorPk(did: string): Uint8Array | undefined;
41
+ registerPeer(did: string, communicationPk: Uint8Array): void;
42
+ getPeerPk(did: string): Uint8Array | undefined;
43
+ registerMessageHandler(actorDid: string, messageType: string, handler: MessageHandler): void;
44
+ unregisterMessageHandler(actorDid: string, messageType: string): void;
45
+ sendMessage(message: BaseMessage, sender: string, recipient?: string): Promise<void>;
46
+ publishRepeating(message: BaseMessage, sender: string, intervalMs: number, recipient?: string): () => void;
47
+ }
48
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAYjE,MAAM,WAAW,yBAAyB;IACxC,oFAAoF;IACpF,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC;IACtB,oGAAoG;IACpG,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/C,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,+EAA+E;AAC/E,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI/D;AAQD;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,SAAS;;IACnD,QAAQ,CAAC,IAAI,UAAU;gBAcX,MAAM,EAAE,yBAAyB;IAkB7C,KAAK,IAAI,IAAI;IAYb;;;;;;OAMG;IACH,IAAI,IAAI,IAAI;IAUZ,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI;IAStD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQlC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI/C,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,UAAU,GAAG,IAAI;IAa5D,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI9C,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAY5F,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAI/D,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC1F,gBAAgB,CACd,OAAO,EAAI,WAAW,EACtB,MAAM,EAAK,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,IAAI;CAuKd"}
@@ -0,0 +1,64 @@
1
+ import type { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
2
+ import type { BaseMessage } from '../../messages/base.js';
3
+ import { type SignedEnvelope } from './protocol.js';
4
+ /** Any shape acceptable as an envelope payload. `BaseMessage` instances are
5
+ * `toJSON`-normalized before signing so class vs. POJO callers produce the
6
+ * same canonical form. */
7
+ export type EnvelopeMessage = BaseMessage | Record<string, unknown>;
8
+ export interface SignEnvelopeOptions {
9
+ /** Recipient DID. Omit for broadcasts. */
10
+ to?: string;
11
+ /** Override the random nonce (tests). */
12
+ nonce?: string;
13
+ /** Override the unix-seconds timestamp (tests). */
14
+ timestamp?: number;
15
+ }
16
+ export interface VerifyEnvelopeOptions {
17
+ /** Reject if `envelope.from` doesn't match. */
18
+ expectedFrom?: string;
19
+ /** Reject if `envelope.to` doesn't match. Pass `undefined` to require a broadcast. */
20
+ expectedTo?: string;
21
+ /** Clock-skew tolerance (seconds). Defaults to {@link DEFAULT_CLOCK_SKEW_SEC}. */
22
+ clockSkewSec?: number;
23
+ /** Clock override (tests). Defaults to `Date.now`. */
24
+ now?: () => number;
25
+ }
26
+ /**
27
+ * Build a {@link SignedEnvelope} around `message`.
28
+ *
29
+ * Pure function — no I/O beyond `randomBytes` for nonce generation (which
30
+ * uses the platform's cryptographic RNG: `crypto.getRandomValues` in browsers,
31
+ * `node:crypto` in Node). Deterministic when both `nonce` and `timestamp` are
32
+ * supplied via {@link SignEnvelopeOptions}.
33
+ */
34
+ export declare function signEnvelope(message: EnvelopeMessage, sender: {
35
+ did: string;
36
+ keys: SchnorrKeyPair;
37
+ }, opts?: SignEnvelopeOptions): SignedEnvelope;
38
+ /**
39
+ * Verify a {@link SignedEnvelope} against the sender's compressed secp256k1
40
+ * communication public key. Throws {@link HttpTransportError} on any failure;
41
+ * returns normally on success.
42
+ *
43
+ * Does NOT check nonce uniqueness — replay protection is the caller's
44
+ * responsibility (the server-side transport maintains an LRU cache).
45
+ */
46
+ export declare function verifyEnvelope(envelope: SignedEnvelope, senderPk: CompressedSecp256k1PublicKey, opts?: VerifyEnvelopeOptions): void;
47
+ /**
48
+ * Recursively replace `Uint8Array` values with `{ __bytes: hex }` sentinel
49
+ * objects so they survive JSON canonicalization / HTTP body serialization.
50
+ * Pairs with {@link reviveFromWire}.
51
+ *
52
+ * Without this, `JSON.stringify` serializes a `Uint8Array` as an index-keyed
53
+ * object (`{"0":1,"1":2,...}`), which `canonicalize` then re-parses into a
54
+ * plain object — the receiver cannot reconstruct the original bytes even
55
+ * though the signature still verifies.
56
+ */
57
+ export declare function normalizeForWire(value: unknown): unknown;
58
+ /**
59
+ * Recursively convert `{ __bytes: hex }` sentinels back into `Uint8Array`
60
+ * values. Call on `envelope.message` *after* successful verification and
61
+ * before handing the payload to a runner's handler.
62
+ */
63
+ export declare function reviveFromWire(value: unknown): unknown;
64
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/envelope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB;;2BAE2B;AAC3B,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpE,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,EAC9C,IAAI,GAAK,mBAAwB,GAChC,cAAc,CAkBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,4BAA4B,EACtC,IAAI,GAAM,qBAA0B,GACnC,IAAI,CAgEN;AAUD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAexD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAetD"}
@@ -0,0 +1,9 @@
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 declare class HttpTransportError extends TransportAdapterError {
7
+ constructor(message: string, type?: string, data?: Record<string, any>);
8
+ }
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,qBAAqB;gBAC/C,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA6B,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAG7F"}
@@ -0,0 +1,32 @@
1
+ export interface StoredEvent {
2
+ /** Monotonic ID assigned at append time. Stable across the buffer's lifetime. */
3
+ id: string;
4
+ /** SSE event name. */
5
+ event: string;
6
+ /** SSE data payload (typically a JSON-stringified {@link SignedEnvelope}). */
7
+ data: string;
8
+ }
9
+ /**
10
+ * Fixed-capacity FIFO ring buffer of SSE events for a single actor's inbox.
11
+ *
12
+ * When a subscriber (re)connects with a `Last-Event-ID` header, the server
13
+ * uses {@link since} to replay everything that arrived while the subscriber
14
+ * was disconnected. Events older than the replay window (evicted from the
15
+ * ring) are unrecoverable — callers should choose `capacity` based on
16
+ * expected message rate × acceptable reconnect window.
17
+ */
18
+ export declare class InboxBuffer {
19
+ #private;
20
+ constructor(capacity?: number);
21
+ /** Append an event. Returns the stored record (including its assigned id). */
22
+ append(event: string, data: string): StoredEvent;
23
+ /**
24
+ * Return stored events with id strictly greater than `lastEventId`. If
25
+ * `lastEventId` is unset or unparseable, returns everything currently
26
+ * retained.
27
+ */
28
+ since(lastEventId?: string): StoredEvent[];
29
+ /** Currently retained event count. */
30
+ size(): number;
31
+ }
32
+ //# sourceMappingURL=inbox-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-buffer.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/inbox-buffer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,iFAAiF;IACjF,EAAE,EAAE,MAAM,CAAC;IACX,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;;gBAKV,QAAQ,SAAM;IAK1B,8EAA8E;IAC9E,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW;IAOhD;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAO1C,sCAAsC;IACtC,IAAI,IAAI,MAAM;CAGf"}
@@ -0,0 +1,12 @@
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.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","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"}
@@ -0,0 +1,26 @@
1
+ export interface NonceCacheConfig {
2
+ /** Max distinct entries to retain before FIFO eviction. Default 10,000. */
3
+ maxEntries?: number;
4
+ }
5
+ /**
6
+ * Bounded anti-replay cache for `(did, nonce)` pairs.
7
+ *
8
+ * Replay windowing is the caller's responsibility — this cache only detects
9
+ * duplicates. Callers are expected to reject envelopes/headers whose timestamp
10
+ * is outside the clock-skew window *before* consulting the cache, so entries
11
+ * here are always within the protocol's acceptable window.
12
+ *
13
+ * Eviction is strict-FIFO (Map insertion order) once `maxEntries` is reached.
14
+ */
15
+ export declare class NonceCache {
16
+ #private;
17
+ constructor(config?: NonceCacheConfig);
18
+ /**
19
+ * Record a nonce. Returns `true` if it was novel (caller should accept the
20
+ * request) or `false` if it was a replay (caller should reject).
21
+ */
22
+ store(did: string, nonce: string, timestampSec: number): boolean;
23
+ /** Current cache size. Exposed for observability and tests. */
24
+ size(): number;
25
+ }
26
+ //# sourceMappingURL=nonce-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonce-cache.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/nonce-cache.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,qBAAa,UAAU;;gBAIT,MAAM,GAAE,gBAAqB;IAIzC;;;OAGG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;IAWhE,+DAA+D;IAC/D,IAAI,IAAI,MAAM;CAGf"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * On-the-wire version of the HTTP transport envelope. Separate from
3
+ * {@link AGGREGATION_WIRE_VERSION} (which versions the aggregation protocol
4
+ * payloads) so transport-layer changes don't force a protocol bump.
5
+ */
6
+ export declare const HTTP_ENVELOPE_VERSION = 1;
7
+ /**
8
+ * HTTP routes served by {@link HttpServerTransport}. The `{did}` placeholder
9
+ * in {@link HTTP_ROUTE.ACTOR_INBOX} is substituted with a URL-safe DID at
10
+ * request time.
11
+ */
12
+ export declare const HTTP_ROUTE: {
13
+ readonly ADVERTS: "/v1/adverts";
14
+ readonly MESSAGES: "/v1/messages";
15
+ readonly ACTOR_INBOX: "/v1/actors/{did}/inbox";
16
+ readonly WELL_KNOWN: "/v1/.well-known/aggregation";
17
+ };
18
+ /** Server-Sent Events event names used by the broadcast + inbox streams. */
19
+ export declare const SSE_EVENT: {
20
+ readonly ADVERT: "advert";
21
+ readonly MESSAGE: "message";
22
+ readonly HEARTBEAT: "heartbeat";
23
+ };
24
+ /** Default clock-skew tolerance for envelope timestamps (seconds). */
25
+ export declare const DEFAULT_CLOCK_SKEW_SEC = 60;
26
+ /** Default length of the per-envelope anti-replay nonce (bytes). */
27
+ export declare const DEFAULT_NONCE_LEN_BYTES = 16;
28
+ /**
29
+ * Tamper-evident wrapper around an aggregation {@link BaseMessage}. Every
30
+ * authenticated HTTP request and inbox SSE event carries one of these.
31
+ *
32
+ * The signature is BIP340 Schnorr over the SHA-256 of the JCS-canonicalized
33
+ * envelope **excluding** the `sig` field. Receivers reconstruct the same
34
+ * canonical form, verify the signature against the sender's registered
35
+ * communication public key, and reject outside-skew timestamps.
36
+ */
37
+ export interface SignedEnvelope {
38
+ /** Envelope format version; must equal {@link HTTP_ENVELOPE_VERSION}. */
39
+ v: number;
40
+ /** Sender DID. */
41
+ from: string;
42
+ /** Recipient DID. Omitted for broadcasts (e.g. COHORT_ADVERT). */
43
+ to?: string;
44
+ /** Unix seconds at which the envelope was produced. */
45
+ timestamp: number;
46
+ /** Hex-encoded random nonce, {@link DEFAULT_NONCE_LEN_BYTES} bytes. */
47
+ nonce: string;
48
+ /** Aggregation message payload (plain-JSON form, `toJSON`-normalized). */
49
+ message: Record<string, unknown>;
50
+ /** Hex-encoded 64-byte BIP340 Schnorr signature. */
51
+ sig: string;
52
+ }
53
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/protocol.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,4EAA4E;AAC5E,eAAO,MAAM,SAAS;;;;CAIZ,CAAC;AAEX,sEAAsE;AACtE,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,CAAC,EAAE,MAAM,CAAC;IACV,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;CACb"}
@@ -0,0 +1,41 @@
1
+ export interface BucketState {
2
+ tokens: number;
3
+ lastRefillMs: number;
4
+ }
5
+ /**
6
+ * Pluggable storage backend for rate-limit state. The default
7
+ * {@link InMemoryRateLimitStore} is a plain Map; swap in Redis-backed or
8
+ * SQLite-backed implementations for multi-instance deployments.
9
+ */
10
+ export interface RateLimitStore {
11
+ get(key: string): BucketState | undefined;
12
+ set(key: string, state: BucketState): void;
13
+ }
14
+ export declare class InMemoryRateLimitStore implements RateLimitStore {
15
+ #private;
16
+ get(key: string): BucketState | undefined;
17
+ set(key: string, state: BucketState): void;
18
+ }
19
+ export interface RateLimiterConfig {
20
+ /** Steady-state request rate per key (requests per second). Default 10. */
21
+ rps?: number;
22
+ /** Peak burst allowance (bucket capacity). Default 30. */
23
+ burst?: number;
24
+ /** Optional pluggable store. Defaults to an in-memory Map. */
25
+ store?: RateLimitStore;
26
+ }
27
+ /**
28
+ * Token-bucket rate limiter keyed by an opaque string (typically a verified
29
+ * sender DID). Tokens refill linearly at `rps` up to `burst`. Each `consume`
30
+ * call atomically debits one token or returns `false` to reject.
31
+ *
32
+ * The limiter is synchronous and deterministic given `nowMs` — tests can
33
+ * drive it with a fixed clock to exercise exact boundaries.
34
+ */
35
+ export declare class RateLimiter {
36
+ #private;
37
+ constructor(config?: RateLimiterConfig);
38
+ /** Consume one token for `key`. Returns `true` if accepted, `false` if throttled. */
39
+ consume(key: string, nowMs: number): boolean;
40
+ }
41
+ //# sourceMappingURL=rate-limiter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/rate-limiter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IAC1C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC5C;AAED,qBAAa,sBAAuB,YAAW,cAAc;;IAG3D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI;CAG3C;AAED,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,qBAAa,WAAW;;gBAKV,MAAM,GAAE,iBAAsB;IAM1C,qFAAqF;IACrF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;CAkB7C"}
@@ -0,0 +1,50 @@
1
+ import type { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
2
+ /**
3
+ * `Authorization`-header scheme used to authenticate SSE subscription
4
+ * requests. The header value takes the form
5
+ * `BTCR2-Sig v=<n>,did=<did>,ts=<unix>,nonce=<hex>,sig=<hex>`.
6
+ *
7
+ * Used only for GET endpoints (SSE inbox subscribe). POST endpoints carry a
8
+ * full {@link SignedEnvelope} in the request body instead.
9
+ */
10
+ export declare const REQUEST_AUTH_SCHEME = "BTCR2-Sig";
11
+ export interface ParsedRequestAuth {
12
+ /** Transport envelope format version. */
13
+ v: number;
14
+ /** Subscriber DID. */
15
+ did: string;
16
+ /** Unix-seconds timestamp. */
17
+ ts: number;
18
+ /** Hex-encoded anti-replay nonce. */
19
+ nonce: string;
20
+ /** Hex-encoded 64-byte BIP340 signature. */
21
+ sig: string;
22
+ }
23
+ export interface BuildRequestAuthOptions {
24
+ nonce?: string;
25
+ timestamp?: number;
26
+ }
27
+ /**
28
+ * Build an `Authorization` header value proving the caller controls the
29
+ * private key for `did`. Covers a specific request path so the signature
30
+ * can't be replayed against a different endpoint.
31
+ */
32
+ export declare function buildRequestAuth(did: string, keys: SchnorrKeyPair, path: string, opts?: BuildRequestAuthOptions): string;
33
+ /**
34
+ * Parse a `BTCR2-Sig` auth header value into its structured fields. Does NOT
35
+ * verify the signature — call {@link verifyRequestAuth} for that.
36
+ */
37
+ export declare function parseRequestAuth(headerValue: string): ParsedRequestAuth;
38
+ export interface VerifyRequestAuthOptions {
39
+ clockSkewSec?: number;
40
+ now?: () => number;
41
+ }
42
+ /**
43
+ * Parse + verify an auth header. Throws {@link HttpTransportError} on any
44
+ * failure; returns the parsed fields on success.
45
+ *
46
+ * `expectedPath` must match the path the signature commits to. `senderPk`
47
+ * must correspond to the DID the signer claims.
48
+ */
49
+ export declare function verifyRequestAuth(headerValue: string, expectedPath: string, senderPk: CompressedSecp256k1PublicKey, opts?: VerifyRequestAuthOptions): ParsedRequestAuth;
50
+ //# sourceMappingURL=request-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-auth.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/request-auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAMvF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,CAAC,EAAE,MAAM,CAAC;IACV,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAG,MAAM,EACZ,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,uBAA4B,GACjC,MAAM,CAcR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,CA4BvE;AAED,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAG,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAM,4BAA4B,EAC1C,IAAI,GAAU,wBAA6B,GAC1C,iBAAiB,CAmDnB"}
@@ -0,0 +1,110 @@
1
+ import type { SchnorrKeyPair } from '@did-btcr2/keypair';
2
+ import type { Logger } from '../../logger.js';
3
+ import type { BaseMessage } from '../../messages/base.js';
4
+ import type { MessageHandler, Transport } from '../transport.js';
5
+ import { NonceCache } from './nonce-cache.js';
6
+ import { RateLimiter } from './rate-limiter.js';
7
+ /** Framework-agnostic incoming-request shape. */
8
+ export interface HttpRequestLike {
9
+ method: string;
10
+ /** Either a full URL or path+query; path extraction works with both. */
11
+ url: string;
12
+ /** Header names MUST be lowercased. */
13
+ headers: Record<string, string>;
14
+ /** Request body (already read). Undefined for GETs. */
15
+ body?: string;
16
+ /** Optional remote-address hint for per-IP policies (advert rate limits etc). */
17
+ remoteAddr?: string;
18
+ }
19
+ /** Framework-agnostic outgoing-response shape. */
20
+ export interface HttpResponseLike {
21
+ status: number;
22
+ headers: Record<string, string>;
23
+ body: string;
24
+ }
25
+ /**
26
+ * Framework-agnostic SSE stream handle. Callers (Express/Hono/Fastify/Workers)
27
+ * adapt this to their response-writing primitives. All methods are synchronous
28
+ * from the transport's perspective; the adapter is free to buffer/batch.
29
+ */
30
+ export interface SseStream {
31
+ /** Write a named event with data and optional id. */
32
+ writeEvent(event: string, data: string, id?: string): void;
33
+ /** Write a comment frame (keepalive; ignored by parsers). */
34
+ writeComment(comment: string): void;
35
+ /** Close the stream from the server side. */
36
+ close(): void;
37
+ /** Register a callback fired when the client disconnects (or we close). */
38
+ onClose(cb: () => void): void;
39
+ }
40
+ export type CorsPolicy = {
41
+ mode: 'permissive';
42
+ } | {
43
+ mode: 'allowlist';
44
+ origins: string[];
45
+ } | {
46
+ mode: 'same-origin';
47
+ };
48
+ export interface HttpServerTransportConfig {
49
+ logger?: Logger;
50
+ /** CORS policy. Defaults to `{ mode: 'permissive' }`. */
51
+ cors?: CorsPolicy;
52
+ /** Envelope / request-auth clock-skew tolerance, seconds. */
53
+ clockSkewSec?: number;
54
+ /** Per-recipient inbox buffer size. Default 100. */
55
+ inboxBufferSize?: number;
56
+ /** Advert cache TTL, milliseconds. Default 5 minutes. */
57
+ advertTtlMs?: number;
58
+ /** Custom rate limiter (pre-configured). If absent, uses defaults. */
59
+ rateLimiter?: RateLimiter;
60
+ /** Custom nonce cache (pre-configured). If absent, uses defaults. */
61
+ nonceCache?: NonceCache;
62
+ /** SSE heartbeat interval, milliseconds. Default 20000. Set 0 to disable. */
63
+ heartbeatIntervalMs?: number;
64
+ /** Clock injection point for tests. Returns unix milliseconds. */
65
+ now?: () => number;
66
+ }
67
+ /**
68
+ * Server-side HTTP transport. Sans-I/O — the caller mounts
69
+ * {@link handleRequest} and {@link handleSse} under their HTTP framework of
70
+ * choice; the transport owns only in-memory state (actors, inboxes, advert
71
+ * cache, replay / rate-limit policies).
72
+ *
73
+ * Implements the generic {@link Transport} interface so the aggregation
74
+ * runners can drive it exactly the same way they drive {@link NostrTransport}
75
+ * or {@link HttpClientTransport}.
76
+ */
77
+ export declare class HttpServerTransport implements Transport {
78
+ #private;
79
+ readonly name = "http";
80
+ constructor(config?: HttpServerTransportConfig);
81
+ start(): void;
82
+ /**
83
+ * Detach the transport: close every open SSE subscription, clear the advert
84
+ * cache, and drop all actor / peer / inbox state. Intended for shutdown and
85
+ * for test teardown.
86
+ */
87
+ stop(): void;
88
+ registerActor(did: string, keys: SchnorrKeyPair): void;
89
+ unregisterActor(did: string): void;
90
+ getActorPk(did: string): Uint8Array | undefined;
91
+ registerPeer(did: string, communicationPk: Uint8Array): void;
92
+ getPeerPk(did: string): Uint8Array | undefined;
93
+ registerMessageHandler(actorDid: string, messageType: string, handler: MessageHandler): void;
94
+ unregisterMessageHandler(actorDid: string, messageType: string): void;
95
+ sendMessage(message: BaseMessage, sender: string, recipient?: string): Promise<void>;
96
+ publishRepeating(message: BaseMessage, sender: string, _intervalMs: number, _recipient?: string): () => void;
97
+ /**
98
+ * Handle a POST / GET request (non-SSE). The caller dispatches SSE paths to
99
+ * {@link handleSse} instead. Returns a fully formed response; the caller's
100
+ * adapter turns it into an HTTP write.
101
+ */
102
+ handleRequest(req: HttpRequestLike): Promise<HttpResponseLike>;
103
+ /**
104
+ * Open an SSE stream for a GET request. The caller is responsible for
105
+ * flushing writes and propagating the `onClose` callback when the HTTP
106
+ * connection ends.
107
+ */
108
+ handleSse(req: HttpRequestLike, stream: SseStream): void;
109
+ }
110
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/server.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Parsed Server-Sent Events record.
3
+ *
4
+ * Events without a `data` field are never yielded (per the SSE spec — only a
5
+ * blank line that follows at least one `data:` line dispatches an event).
6
+ */
7
+ export interface SseEvent {
8
+ /** Optional event name (from `event:` field). Defaults to "message" if omitted. */
9
+ event?: string;
10
+ /** Accumulated data payload (multiple `data:` lines joined with `\n`). */
11
+ data: string;
12
+ /** Last-Event-ID value for reconnect resumption. */
13
+ id?: string;
14
+ /** Retry delay hint in milliseconds. */
15
+ retry?: number;
16
+ }
17
+ /**
18
+ * Parse an SSE stream into an async iterable of {@link SseEvent} records.
19
+ *
20
+ * The parser follows the HTML Living Standard ({@link https://html.spec.whatwg.org/multipage/server-sent-events.html})
21
+ * closely enough for our needs: LF and CRLF line terminators, multi-line
22
+ * `data` fields, `event` / `id` / `retry` fields, and `:`-prefixed comments.
23
+ * CR-only line terminators are not supported (every mainstream SSE
24
+ * implementation emits LF or CRLF).
25
+ *
26
+ * Pure, runtime-agnostic — works anywhere `ReadableStream<Uint8Array>` and
27
+ * `TextDecoder` exist (browsers and Node 22+).
28
+ *
29
+ * The caller owns stream lifecycle: cancellation should be effected via an
30
+ * `AbortController` on the producing `fetch`, which propagates as a read
31
+ * error and cleanly unwinds this generator's `finally`.
32
+ */
33
+ export declare function parseSseStream(readable: ReadableStream<Uint8Array>): AsyncGenerator<SseEvent, void, void>;
34
+ //# sourceMappingURL=sse-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-stream.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/sse-stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,mFAAmF;IACnF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAuB,cAAc,CACnC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,GACnC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAqFtC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Format an SSE event frame. Pairs with {@link parseSseStream}.
3
+ *
4
+ * Multi-line `data` is split across multiple `data:` lines per the SSE spec —
5
+ * each embedded `\n` becomes its own line, and the parser rejoins them.
6
+ *
7
+ * The returned string includes a trailing blank line (the dispatch marker).
8
+ */
9
+ export declare function formatSseEvent(event: string, data: string, id?: string): string;
10
+ /** SSE comment frame (server keepalive). Lines starting with `:` are ignored by compliant parsers. */
11
+ export declare function formatSseComment(comment: string): string;
12
+ //# sourceMappingURL=sse-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-writer.d.ts","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/sse-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAQ/E;AAED,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGxD"}
@@ -3,4 +3,5 @@ export * from './error.js';
3
3
  export * from './factory.js';
4
4
  export * from './nostr.js';
5
5
  export * from './didcomm.js';
6
+ export * from './http/index.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/aggregation/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}