@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/server.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,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,UAAU,EACV,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAyFtD,MAAM,iBAAiB,GAAG,aAAa,CAAC;AACxC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAEnC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5C,MAAM,oBAAoB,GAAI,MAAM,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAmB;IACrB,IAAI,GAAG,MAAM,CAAC;IAEd,OAAO,CAAqB;IAC5B,KAAK,CAA2B;IAChC,aAAa,CAAe;IAC5B,gBAAgB,CAAY;IAC5B,YAAY,CAAgB;IAC5B,YAAY,CAAgB;IAC5B,YAAY,CAAqB;IACjC,WAAW,CAAqB;IAChC,IAAI,CAA8B;IAElC,OAAO,GAA8B,IAAI,G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AE,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChG,IAAG,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IACjC,IAAI,CAAC;QAAC,OAAO,EAAE,GAAG,EAAE,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC;IAAC,CAAC;IACvD,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AAC7B,CAAC;AAED,SAAS,aAAa,CAAI,IAAwB;IAChD,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IACvD,IAAI,CAAC;QAAC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;IAAC,CAAC;IACrC,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AAC7B,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"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Parse an SSE stream into an async iterable of {@link SseEvent} records.
3
+ *
4
+ * The parser follows the HTML Living Standard ({@link https://html.spec.whatwg.org/multipage/server-sent-events.html})
5
+ * closely enough for our needs: LF and CRLF line terminators, multi-line
6
+ * `data` fields, `event` / `id` / `retry` fields, and `:`-prefixed comments.
7
+ * CR-only line terminators are not supported (every mainstream SSE
8
+ * implementation emits LF or CRLF).
9
+ *
10
+ * Pure, runtime-agnostic — works anywhere `ReadableStream<Uint8Array>` and
11
+ * `TextDecoder` exist (browsers and Node 22+).
12
+ *
13
+ * The caller owns stream lifecycle: cancellation should be effected via an
14
+ * `AbortController` on the producing `fetch`, which propagates as a read
15
+ * error and cleanly unwinds this generator's `finally`.
16
+ */
17
+ export async function* parseSseStream(readable) {
18
+ const decoder = new TextDecoder('utf-8');
19
+ const reader = readable.getReader();
20
+ let buffer = '';
21
+ let pending = {};
22
+ const dispatchPending = () => {
23
+ if (pending.data === undefined) {
24
+ pending = {};
25
+ return null;
26
+ }
27
+ const ev = { data: pending.data };
28
+ if (pending.event !== undefined)
29
+ ev.event = pending.event;
30
+ if (pending.id !== undefined)
31
+ ev.id = pending.id;
32
+ if (pending.retry !== undefined)
33
+ ev.retry = pending.retry;
34
+ pending = {};
35
+ return ev;
36
+ };
37
+ const processLine = (line) => {
38
+ if (line.startsWith(':'))
39
+ return; // comment
40
+ const colon = line.indexOf(':');
41
+ const field = colon === -1 ? line : line.slice(0, colon);
42
+ let value = colon === -1 ? '' : line.slice(colon + 1);
43
+ if (value.startsWith(' '))
44
+ value = value.slice(1);
45
+ switch (field) {
46
+ case 'data':
47
+ pending.data = pending.data === undefined ? value : `${pending.data}\n${value}`;
48
+ break;
49
+ case 'event':
50
+ pending.event = value;
51
+ break;
52
+ case 'id':
53
+ // Per spec: ignore ids containing NUL.
54
+ if (!value.includes('\0'))
55
+ pending.id = value;
56
+ break;
57
+ case 'retry': {
58
+ const n = Number(value);
59
+ if (Number.isInteger(n) && n >= 0)
60
+ pending.retry = n;
61
+ break;
62
+ }
63
+ // Other fields (including unknown names) are ignored per the spec.
64
+ }
65
+ };
66
+ try {
67
+ for (;;) {
68
+ const { value, done } = await reader.read();
69
+ if (done) {
70
+ // Flush any bytes the decoder is still holding.
71
+ buffer += decoder.decode();
72
+ if (buffer.length > 0) {
73
+ const line = buffer.endsWith('\r') ? buffer.slice(0, -1) : buffer;
74
+ if (line.length > 0)
75
+ processLine(line);
76
+ buffer = '';
77
+ }
78
+ const tail = dispatchPending();
79
+ if (tail)
80
+ yield tail;
81
+ return;
82
+ }
83
+ buffer += decoder.decode(value, { stream: true });
84
+ // Drain as many complete lines as are available.
85
+ let lineEnd = buffer.indexOf('\n');
86
+ while (lineEnd !== -1) {
87
+ let line = buffer.slice(0, lineEnd);
88
+ if (line.endsWith('\r'))
89
+ line = line.slice(0, -1);
90
+ buffer = buffer.slice(lineEnd + 1);
91
+ if (line.length === 0) {
92
+ const ev = dispatchPending();
93
+ if (ev)
94
+ yield ev;
95
+ }
96
+ else {
97
+ processLine(line);
98
+ }
99
+ lineEnd = buffer.indexOf('\n');
100
+ }
101
+ }
102
+ }
103
+ finally {
104
+ try {
105
+ reader.releaseLock();
106
+ }
107
+ catch { /* already released */ }
108
+ }
109
+ }
110
+ //# sourceMappingURL=sse-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-stream.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/sse-stream.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,cAAc,CACnC,QAAoC;IAEpC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;IAErC,IAAI,MAAM,GAAI,EAAE,CAAC;IACjB,IAAI,OAAO,GAAmE,EAAE,CAAC;IAEjF,MAAM,eAAe,GAAG,GAAoB,EAAE;QAC5C,IAAG,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,EAAE,GAAa,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAG,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,EAAE,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QACzD,IAAG,OAAO,CAAC,EAAE,KAAQ,SAAS;YAAE,EAAE,CAAC,EAAE,GAAM,OAAO,CAAC,EAAE,CAAC;QACtD,IAAG,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,EAAE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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACjD,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;gBAEnC,IAAG,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACrB,MAAM,EAAE,GAAG,eAAe,EAAE,CAAC;oBAC7B,IAAG,EAAE;wBAAE,MAAM,EAAE,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACN,WAAW,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC;gBACD,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
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 function formatSseEvent(event, data, id) {
10
+ const lines = [];
11
+ if (id !== undefined)
12
+ lines.push(`id: ${id}`);
13
+ lines.push(`event: ${event}`);
14
+ for (const part of data.split('\n'))
15
+ lines.push(`data: ${part}`);
16
+ lines.push('');
17
+ lines.push('');
18
+ return lines.join('\n');
19
+ }
20
+ /** SSE comment frame (server keepalive). Lines starting with `:` are ignored by compliant parsers. */
21
+ export function formatSseComment(comment) {
22
+ const safe = comment.replace(/\n/g, ' ');
23
+ return `: ${safe}\n\n`;
24
+ }
25
+ //# sourceMappingURL=sse-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-writer.js","sourceRoot":"","sources":["../../../../../../src/core/aggregation/transport/http/sse-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,IAAY,EAAE,EAAW;IACrE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAG,EAAE,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7C,KAAK,CAAC,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;IAC9B,KAAI,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAChE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,KAAK,IAAI,MAAM,CAAC;AACzB,CAAC"}
@@ -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.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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.js","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"}
@@ -3,6 +3,7 @@ import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
3
3
  import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
4
4
  import { finalizeEvent, nip44 } from 'nostr-tools';
5
5
  import { SimplePool } from 'nostr-tools/pool';
6
+ import { CONSOLE_LOGGER } from '../logger.js';
6
7
  import { COHORT_ADVERT } from '../messages/constants.js';
7
8
  import { isAggregationMessageType, isKeygenMessageType, isSignMessageType, isUpdateMessageType } from '../messages/guards.js';
8
9
  import { TransportAdapterError } from './error.js';
@@ -16,6 +17,8 @@ export const DEFAULT_NOSTR_RELAYS = [
16
17
  'wss://relay.snort.social',
17
18
  'wss://nostr-pub.wellorder.net',
18
19
  ];
20
+ /** Default `since` lookback for broadcast (COHORT_ADVERT) subscriptions: 5 minutes. */
21
+ export const DEFAULT_BROADCAST_LOOKBACK_MS = 5 * 60 * 1000;
19
22
  /**
20
23
  * Nostr Transport for did:btcr2 aggregation messages.
21
24
  *
@@ -39,8 +42,12 @@ export class NostrTransport {
39
42
  #actors = new Map();
40
43
  #peerRegistry = new Map();
41
44
  #started = false;
45
+ #logger;
46
+ #broadcastLookbackMs;
42
47
  constructor(config) {
43
48
  this.#relays = config?.relays ?? DEFAULT_NOSTR_RELAYS;
49
+ this.#logger = config?.logger ?? CONSOLE_LOGGER;
50
+ this.#broadcastLookbackMs = config?.broadcastLookbackMs ?? DEFAULT_BROADCAST_LOOKBACK_MS;
44
51
  }
45
52
  /**
46
53
  * Registers an actor (DID + keys) to send/receive messages with.
@@ -51,20 +58,72 @@ export class NostrTransport {
51
58
  * @example
52
59
  * const transport = new NostrTransport();
53
60
  * const keys = SchnorrKeyPair.generate();
54
- * transport.registerActor('did:btcr2:...', keys);
61
+ * const did = DidBtcr2.create(keys.publicKey.compressed, { idType: 'KEY', network: 'mutinynet' });
62
+ * transport.registerActor(did, keys);
55
63
  * transport.start();
56
64
  */
57
65
  registerActor(did, keys) {
58
- const entry = { keys, handlers: new Map() };
66
+ const entry = { keys, handlers: new Map(), subscriptions: [] };
59
67
  this.#actors.set(did, entry);
60
68
  // If already started, create a directed subscription for this actor
61
69
  if (this.#started && this.pool) {
62
70
  this.#subscribeDirected(did, entry);
63
71
  }
64
72
  }
73
+ /**
74
+ * Detach an actor: drop its handlers, close its relay subscriptions, and remove its keys + peer
75
+ * mapping. Idempotent.
76
+ * @param {string} did - The DID of the actor to unregister.
77
+ * @returns {void}
78
+ * @throws {TransportAdapterError} If the transport is not started or if the pool is unavailable.
79
+ * @example
80
+ * transport.unregisterActor(did);
81
+ */
82
+ unregisterActor(did) {
83
+ const entry = this.#actors.get(did);
84
+ if (!entry)
85
+ return;
86
+ for (const sub of entry.subscriptions) {
87
+ try {
88
+ sub.close();
89
+ }
90
+ catch (err) {
91
+ this.#logger.debug(`Error closing subscription for ${did}:`, err);
92
+ }
93
+ }
94
+ entry.subscriptions.length = 0;
95
+ entry.handlers.clear();
96
+ this.#actors.delete(did);
97
+ this.#peerRegistry.delete(did);
98
+ }
99
+ /**
100
+ * Remove a single (actor, messageType) handler. Idempotent.
101
+ * @param {string} actorDid - The DID of the actor.
102
+ * @param {string} messageType - The type of message to unregister the handler for.
103
+ * @returns {void}
104
+ * @example
105
+ * transport.unregisterMessageHandler(actorDid, messageType);
106
+ */
107
+ unregisterMessageHandler(actorDid, messageType) {
108
+ const actor = this.#actors.get(actorDid);
109
+ if (!actor)
110
+ return;
111
+ actor.handlers.delete(messageType);
112
+ }
113
+ /**
114
+ * Gets the public key for a registered actor by their DID.
115
+ * @param {string} did - The DID of the registered actor to get the public key for.
116
+ * @returns {Uint8Array | undefined} The compressed public key bytes for the actor's DID, or
117
+ * undefined if the DID is not registered.
118
+ */
65
119
  getActorPk(did) {
66
120
  return this.#actors.get(did)?.keys.publicKey.compressed;
67
121
  }
122
+ /**
123
+ * Registers a peer's communication public key for encrypted messages.
124
+ * @param {string} did - The DID of the peer to register.
125
+ * @param {Uint8Array} communicationPk - The compressed secp256k1 public key bytes for the peer.
126
+ */
68
127
  registerPeer(did, communicationPk) {
69
128
  try {
70
129
  new CompressedSecp256k1PublicKey(communicationPk);
@@ -74,9 +133,25 @@ export class NostrTransport {
74
133
  }
75
134
  this.#peerRegistry.set(did, communicationPk);
76
135
  }
136
+ /**
137
+ * Gets the registered communication public key for a peer by their DID.
138
+ * @param {string} did - The DID of the peer to get the communication public key for.
139
+ * @returns {Uint8Array | undefined} The compressed secp256k1 public key bytes for the peer, or
140
+ * undefined if the peer is not registered.
141
+ */
77
142
  getPeerPk(did) {
78
143
  return this.#peerRegistry.get(did);
79
144
  }
145
+ /**
146
+ * Registers a message handler function for a specific actor and message type. The handler will be called
147
+ * when a message of the specified type is received for the actor's DID. The transport must have been
148
+ * started for handlers to be invoked. If the transport is already started, the handler will be registered
149
+ * immediately; otherwise, it will be registered when the transport starts and the actor's subscription is created.
150
+ * @param {string} actorDid - The DID of the actor to register the message handler for.
151
+ * @param {string} messageType - The type of message to handle.
152
+ * @param {MessageHandler} handler - The function to handle incoming messages of the specified type.
153
+ * @throws {TransportAdapterError} If the actor DID is not registered or if the handler is invalid.
154
+ */
80
155
  registerMessageHandler(actorDid, messageType, handler) {
81
156
  const actor = this.#actors.get(actorDid);
82
157
  if (!actor) {
@@ -84,24 +159,61 @@ export class NostrTransport {
84
159
  }
85
160
  actor.handlers.set(messageType, handler);
86
161
  }
162
+ /**
163
+ * Starts the transport by connecting to the configured Nostr relays and setting up subscriptions
164
+ * for all registered actors. This method must be called after registering actors via registerActor()
165
+ * and before sending or receiving messages. The transport will subscribe to broadcast events (kind 1)
166
+ * for cohort adverts and directed events (kinds 1 and 1059) for each registered actor based on their
167
+ * public keys. Incoming events are processed and dispatched to the appropriate handlers based on
168
+ * message type. If the transport is already started, this method has no effect.
169
+ * @returns {NostrTransport}
170
+ */
87
171
  start() {
88
172
  if (this.#started)
89
173
  return this;
90
174
  this.#started = true;
91
175
  this.pool = new SimplePool();
92
- const since = Math.floor(Date.now() / 1000);
93
- // Broadcast subscription: kind 1 COHORT_ADVERT events (all actors receive these)
94
- this.pool.subscribeMany(this.#relays, { kinds: [1], '#t': [COHORT_ADVERT], since }, {
95
- onclose: (reasons) => console.debug('Nostr broadcast subscription closed', reasons),
176
+ // Broadcast subscription: kind 1 COHORT_ADVERT events (all actors receive
177
+ // these). Duplicate adverts are idempotent: AggregationParticipant stores
178
+ // discovered cohorts in a Map keyed by cohortId.
179
+ //
180
+ // The `since` filter is a workaround for relays that don't backfill
181
+ // historical events to late subscribers (observed on nos.lol and
182
+ // relay.snort.social). Without it, an advert published before a
183
+ // participant's subscription lands is lost on those relays. The default
184
+ // 5-minute window is generous enough to cover network + subscription
185
+ // setup delays while still excluding ancient traffic. Set
186
+ // broadcastLookbackMs to 0 to disable.
187
+ const broadcastFilter = {
188
+ kinds: [1],
189
+ '#t': [COHORT_ADVERT],
190
+ };
191
+ if (this.#broadcastLookbackMs > 0) {
192
+ broadcastFilter.since = Math.floor((Date.now() - this.#broadcastLookbackMs) / 1000);
193
+ }
194
+ this.pool.subscribeMany(this.#relays, broadcastFilter, {
195
+ onclose: (reasons) => this.#logger.debug('Nostr broadcast subscription closed', reasons),
96
196
  onevent: this.#handleBroadcastEvent.bind(this),
97
197
  });
98
198
  // Directed subscriptions for any actors already registered
99
199
  for (const [did, entry] of this.#actors) {
100
200
  this.#subscribeDirected(did, entry);
101
201
  }
102
- console.info(`NostrTransport started, listening on ${this.#relays.length} relay(s)`);
202
+ this.#logger.info(`NostrTransport started, listening on ${this.#relays.length} relay(s)`);
103
203
  return this;
104
204
  }
205
+ /**
206
+ * Sends a message by publishing a Nostr event to the configured relays. The message is serialized
207
+ * as JSON and included in the event content.
208
+ * @param {BaseMessage} message - The aggregation message to send. Must include a valid `type` property.
209
+ * @param {Did} sender - The DID of the registered actor sending the message. Must have been
210
+ * registered via registerActor().
211
+ * @param {Did} [to] - Optional recipient DID for directed messages. Required for encrypted message
212
+ * types. If provided, must have been registered via registerPeer().
213
+ * @returns {Promise<void>} Resolves when the message has been published to the relays. Note that
214
+ * publication is best-effort: the method will resolve as long as at least one relay accepts the
215
+ * event, even if others reject it.
216
+ */
105
217
  async sendMessage(message, sender, to) {
106
218
  const type = message.type;
107
219
  if (!type) {
@@ -132,7 +244,7 @@ export class NostrTransport {
132
244
  tags,
133
245
  content: JSON.stringify(message, _a.#jsonReplacer),
134
246
  }, senderKeys.secretKey.bytes);
135
- console.debug(`Publishing kind 1 [${type}]`);
247
+ this.#logger.debug(`Publishing kind 1 [${type}]`);
136
248
  await this.#publishToRelays(event);
137
249
  return;
138
250
  }
@@ -154,27 +266,88 @@ export class NostrTransport {
154
266
  tags,
155
267
  content,
156
268
  }, senderKeys.secretKey.bytes);
157
- console.debug(`Publishing kind 1059 [${type}]`);
269
+ this.#logger.debug(`Publishing kind 1059 [${type}]`);
158
270
  await this.#publishToRelays(event);
159
271
  return;
160
272
  }
161
- console.warn(`Unsupported message type: ${type}`);
273
+ this.#logger.warn(`Unsupported message type: ${type}`);
162
274
  }
275
+ /**
276
+ * Publish the message once immediately and then re-publish on an interval
277
+ * until the returned stop function is invoked.
278
+ *
279
+ * Useful for broadcast messages (COHORT_ADVERT) on relays that don't
280
+ * backfill historical events to late subscribers: republishing gives late
281
+ * joiners a window to discover the message without requiring protocol
282
+ * changes. Relay rate-limit / publish failures inside the interval are
283
+ * caught and logged rather than propagated — the caller should stop the
284
+ * repeater once the protocol condition is satisfied.
285
+ */
286
+ publishRepeating(message, sender, intervalMs, recipient) {
287
+ let stopped = false;
288
+ // Fire the first publish eagerly; any error surfaces as a rejected
289
+ // promise that we swallow to avoid unhandled rejections — the caller can
290
+ // observe delivery via receive-side handlers.
291
+ void this.sendMessage(message, sender, recipient).catch((err) => {
292
+ this.#logger.debug('publishRepeating first send failed:', err);
293
+ });
294
+ const timer = setInterval(() => {
295
+ if (stopped)
296
+ return;
297
+ void this.sendMessage(message, sender, recipient).catch((err) => {
298
+ this.#logger.debug('publishRepeating retry failed:', err);
299
+ });
300
+ }, intervalMs);
301
+ return () => {
302
+ if (stopped)
303
+ return;
304
+ stopped = true;
305
+ clearInterval(timer);
306
+ };
307
+ }
308
+ /**
309
+ * Creates a directed subscription for the given actor, filtering for messages that match the
310
+ * actor's public key. Messages received on this subscription are dispatched to the actor's
311
+ * registered handlers based on message type.
312
+ * @param {string} did - The DID of the actor to create the subscription for.
313
+ * @param {ActorEntry} entry - The actor's registration entry containing keys and handlers.
314
+ * @returns {void}
315
+ * @throws {TransportAdapterError} If the transport is not started or if the pool is unavailable.
316
+ */
163
317
  #subscribeDirected(did, entry) {
164
318
  if (!this.pool)
165
319
  return;
166
320
  const pkHex = bytesToHex(entry.keys.publicKey.x);
167
- const since = Math.floor(Date.now() / 1000);
168
- this.pool.subscribeMany(this.#relays, { kinds: [1, 1059], '#p': [pkHex], since }, {
169
- onclose: (reasons) => console.debug(`Nostr directed subscription closed for ${did}`, reasons),
321
+ // No `since` filter: directed messages must be retrievable on reconnect /
322
+ // crash-recovery. Out-of-phase messages are silently dropped by the state
323
+ // machines (AggregationService, AggregationParticipant), so replayed stale
324
+ // messages are harmless.
325
+ const sub = this.pool.subscribeMany(this.#relays, { kinds: [1, 1059], '#p': [pkHex] }, {
326
+ onclose: (reasons) => this.#logger.debug(`Nostr directed subscription closed for ${did}`, reasons),
170
327
  onevent: this.#makeActorEventHandler(did),
171
328
  });
329
+ entry.subscriptions.push(sub);
172
330
  }
331
+ /**
332
+ * Creates an event handler function for a specific actor that processes incoming events, decrypts
333
+ * if necessary, and dispatches messages to the actor's registered handlers based on message type.
334
+ * @param {string} actorDid - The DID of the actor to create the event handler for.
335
+ * @returns {(event: Event) => Promise<void>} An asynchronous event handler function that
336
+ * processes incoming events for the specified actor.
337
+ */
173
338
  #makeActorEventHandler(actorDid) {
174
339
  return async (event) => {
175
340
  const actor = this.#actors.get(actorDid);
176
341
  if (!actor)
177
342
  return;
343
+ // Relay self-echo: sendMessage() adds the sender's own pubkey to the
344
+ // event's `p` tags (so recipients can reply). The directed subscription
345
+ // filter `{'#p': [actor_pk]}` therefore matches every event this actor
346
+ // publishes. Skip — we don't need to process our own outgoing events,
347
+ // and attempting to NIP-44-decrypt them fails with "invalid MAC" because
348
+ // the content was encrypted for the recipient, not self.
349
+ if (event.pubkey === bytesToHex(actor.keys.publicKey.x))
350
+ return;
178
351
  let message;
179
352
  try {
180
353
  if (event.kind === 1) {
@@ -190,12 +363,22 @@ export class NostrTransport {
190
363
  }
191
364
  }
192
365
  catch (err) {
193
- console.debug(`Failed to parse event ${event.id} for ${actorDid}:`, err);
366
+ this.#logger.debug(`Failed to parse event ${event.id} for ${actorDid}:`, err);
194
367
  return;
195
368
  }
196
369
  this.#dispatchMessage(message, actor);
197
370
  };
198
371
  }
372
+ /**
373
+ * Handles incoming broadcast events (kind 1) by parsing the event content, validating it as an
374
+ * aggregation message, and dispatching it to all registered actors that have handlers for the
375
+ * message type. This is used for COHORT_ADVERT messages that need to be received by all actors
376
+ * regardless of DID.
377
+ * @param {Event} event - The Nostr event to handle, expected to be a kind 1 broadcast containing
378
+ * a COHORT_ADVERT message. The event content is parsed and dispatched to all registered actors
379
+ * that have handlers for the
380
+ * @returns
381
+ */
199
382
  async #handleBroadcastEvent(event) {
200
383
  if (event.kind !== 1)
201
384
  return;
@@ -204,7 +387,7 @@ export class NostrTransport {
204
387
  message = JSON.parse(event.content, _a.#jsonReviver);
205
388
  }
206
389
  catch (err) {
207
- console.debug(`Failed to parse broadcast event ${event.id}:`, err);
390
+ this.#logger.debug(`Failed to parse broadcast event ${event.id}:`, err);
208
391
  return;
209
392
  }
210
393
  if (message.body && typeof message.body === 'object') {
@@ -220,6 +403,18 @@ export class NostrTransport {
220
403
  await handler(message);
221
404
  }
222
405
  }
406
+ /**
407
+ * Dispatches a parsed message to the appropriate handler of a registered actor based on message type.
408
+ * The message is expected to have already been parsed from the Nostr event content and validated as
409
+ * an aggregation message. If the message has a body, its properties are merged into the top-level
410
+ * message object for easier handler access. The message is then dispatched to the handler registered
411
+ * for its type, if one exists.
412
+ * @param {Record<string, unknown>} message - The message object parsed from a Nostr event, expected to
413
+ * @param {ActorEntry} actor - The registered actor entry containing keys and handlers to dispatch the message to.
414
+ * @returns {void}
415
+ * @throws {TransportAdapterError} If the message type is unsupported or if no handler is registered
416
+ * for the message type.
417
+ */
223
418
  #dispatchMessage(message, actor) {
224
419
  if (message.body && typeof message.body === 'object') {
225
420
  message = { ...message, ...message.body };
@@ -231,6 +426,16 @@ export class NostrTransport {
231
426
  if (handler)
232
427
  handler(message);
233
428
  }
429
+ /**
430
+ * Publishes a Nostr event to the configured relays and handles the results. The method waits for all
431
+ * relay promises to settle and checks how many accepted or rejected the event. If all relays reject the event,
432
+ * an error is thrown. Otherwise, the method completes successfully even if some relays rejected the event,
433
+ * as long as at least one relay accepted it. Relay rejections are logged for debugging purposes.
434
+ * @param {Event} event - The Nostr event to publish to the configured relays. The event should already
435
+ * @returns {Promise<void>} A promise that resolves if the event was accepted by at least one relay, or rejects
436
+ * with a TransportAdapterError if all relays rejected the event.
437
+ * @throws {TransportAdapterError} If the pool is not initialized or if all relays reject the event.
438
+ */
234
439
  async #publishToRelays(event) {
235
440
  const relayPromises = this.pool?.publish(this.#relays, event);
236
441
  if (!relayPromises?.length)
@@ -239,18 +444,42 @@ export class NostrTransport {
239
444
  const accepted = results.filter(r => r.status === 'fulfilled').length;
240
445
  const rejected = results.filter(r => r.status === 'rejected');
241
446
  for (const r of rejected) {
242
- console.debug(`Relay rejected event ${event.id}: ${r.reason}`);
447
+ this.#logger.debug(`Relay rejected event ${event.id}: ${r.reason}`);
243
448
  }
244
449
  if (accepted === 0) {
245
450
  throw new TransportAdapterError(`All ${results.length} relay(s) rejected event ${event.id}`, 'PUBLISH_ERROR', { adapter: this.name, reasons: rejected.map(r => String(r.reason)) });
246
451
  }
247
452
  }
453
+ /**
454
+ * Custom JSON replacer to handle serialization of Uint8Array values as hex strings in message
455
+ * content. This allows messages containing binary data (e.g. public keys, signatures) to be correctly
456
+ * serialized to JSON for Nostr event content. The replacer checks if a value is a Uint8Array and, if so,
457
+ * converts it to a hex string wrapped in an object with a __bytes property. The corresponding reviver
458
+ * can then convert this back to a Uint8Array when parsing the message content from the event.
459
+ * @param {string} _key - The key of the property being processed.
460
+ * @param {unknown} value - The value to check if the message type is valid.
461
+ * @returns {unknown} The transformed value for JSON serialization. If the value is a Uint8Array,
462
+ * it returns an object with a __bytes property containing the hex string. Otherwise, it returns
463
+ * the value unchanged.
464
+ */
248
465
  static #jsonReplacer(_key, value) {
249
466
  if (value instanceof Uint8Array) {
250
467
  return { __bytes: bytesToHex(value) };
251
468
  }
252
469
  return value;
253
470
  }
471
+ /**
472
+ * Custom JSON reviver to handle deserialization of hex strings back into Uint8Array values in message
473
+ * content. This complements the custom replacer used during serialization, allowing messages that contain
474
+ * binary data (e.g. public keys, signatures) to be correctly reconstructed when parsing JSON from
475
+ * Nostr event content. The reviver checks if a value is an object with a __bytes property and,
476
+ * if so, converts the hex string back into a Uint8Array. Otherwise, it returns the value unchanged.
477
+ * @param {string} _key - The key of the property being processed.
478
+ * @param {unknown} value - The value to check if it is an object containing a __bytes property for
479
+ * hex string conversion.
480
+ * @returns {unknown} The transformed value for JSON deserialization. If the value is an object
481
+ * with a __bytes property, it returns a Uint8Array. Otherwise, it returns the value unchanged.
482
+ */
254
483
  static #jsonReviver(_key, value) {
255
484
  if (value && typeof value === 'object' && '__bytes' in value) {
256
485
  return hexToBytes(value.__bytes);