@sempdev/semp 0.4.3

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 (559) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/brief/address.d.ts +77 -0
  4. package/dist/brief/address.d.ts.map +1 -0
  5. package/dist/brief/address.js +217 -0
  6. package/dist/brief/address.js.map +1 -0
  7. package/dist/brief/brief.d.ts +75 -0
  8. package/dist/brief/brief.d.ts.map +1 -0
  9. package/dist/brief/brief.js +56 -0
  10. package/dist/brief/brief.js.map +1 -0
  11. package/dist/brief/index.d.ts +11 -0
  12. package/dist/brief/index.d.ts.map +1 -0
  13. package/dist/brief/index.js +11 -0
  14. package/dist/brief/index.js.map +1 -0
  15. package/dist/canonical/index.d.ts +8 -0
  16. package/dist/canonical/index.d.ts.map +1 -0
  17. package/dist/canonical/index.js +8 -0
  18. package/dist/canonical/index.js.map +1 -0
  19. package/dist/canonical/marshal.d.ts +35 -0
  20. package/dist/canonical/marshal.d.ts.map +1 -0
  21. package/dist/canonical/marshal.js +107 -0
  22. package/dist/canonical/marshal.js.map +1 -0
  23. package/dist/clockskew/index.d.ts +52 -0
  24. package/dist/clockskew/index.d.ts.map +1 -0
  25. package/dist/clockskew/index.js +62 -0
  26. package/dist/clockskew/index.js.map +1 -0
  27. package/dist/closure/closure.d.ts +106 -0
  28. package/dist/closure/closure.d.ts.map +1 -0
  29. package/dist/closure/closure.js +152 -0
  30. package/dist/closure/closure.js.map +1 -0
  31. package/dist/closure/driver.d.ts +103 -0
  32. package/dist/closure/driver.d.ts.map +1 -0
  33. package/dist/closure/driver.js +126 -0
  34. package/dist/closure/driver.js.map +1 -0
  35. package/dist/closure/index.d.ts +13 -0
  36. package/dist/closure/index.d.ts.map +1 -0
  37. package/dist/closure/index.js +13 -0
  38. package/dist/closure/index.js.map +1 -0
  39. package/dist/closure/store.d.ts +80 -0
  40. package/dist/closure/store.d.ts.map +1 -0
  41. package/dist/closure/store.js +89 -0
  42. package/dist/closure/store.js.map +1 -0
  43. package/dist/crypto/aead.d.ts +29 -0
  44. package/dist/crypto/aead.d.ts.map +1 -0
  45. package/dist/crypto/aead.js +48 -0
  46. package/dist/crypto/aead.js.map +1 -0
  47. package/dist/crypto/argon2.d.ts +20 -0
  48. package/dist/crypto/argon2.d.ts.map +1 -0
  49. package/dist/crypto/argon2.js +28 -0
  50. package/dist/crypto/argon2.js.map +1 -0
  51. package/dist/crypto/index.d.ts +14 -0
  52. package/dist/crypto/index.d.ts.map +1 -0
  53. package/dist/crypto/index.js +14 -0
  54. package/dist/crypto/index.js.map +1 -0
  55. package/dist/crypto/kdf.d.ts +96 -0
  56. package/dist/crypto/kdf.d.ts.map +1 -0
  57. package/dist/crypto/kdf.js +122 -0
  58. package/dist/crypto/kdf.js.map +1 -0
  59. package/dist/crypto/kem.d.ts +85 -0
  60. package/dist/crypto/kem.d.ts.map +1 -0
  61. package/dist/crypto/kem.js +130 -0
  62. package/dist/crypto/kem.js.map +1 -0
  63. package/dist/crypto/mac.d.ts +19 -0
  64. package/dist/crypto/mac.d.ts.map +1 -0
  65. package/dist/crypto/mac.js +32 -0
  66. package/dist/crypto/mac.js.map +1 -0
  67. package/dist/delivery/ack.d.ts +125 -0
  68. package/dist/delivery/ack.d.ts.map +1 -0
  69. package/dist/delivery/ack.js +141 -0
  70. package/dist/delivery/ack.js.map +1 -0
  71. package/dist/delivery/blocklist.d.ts +87 -0
  72. package/dist/delivery/blocklist.d.ts.map +1 -0
  73. package/dist/delivery/blocklist.js +107 -0
  74. package/dist/delivery/blocklist.js.map +1 -0
  75. package/dist/delivery/cancel.d.ts +60 -0
  76. package/dist/delivery/cancel.d.ts.map +1 -0
  77. package/dist/delivery/cancel.js +43 -0
  78. package/dist/delivery/cancel.js.map +1 -0
  79. package/dist/delivery/disposition.d.ts +106 -0
  80. package/dist/delivery/disposition.d.ts.map +1 -0
  81. package/dist/delivery/disposition.js +105 -0
  82. package/dist/delivery/disposition.js.map +1 -0
  83. package/dist/delivery/fetch.d.ts +59 -0
  84. package/dist/delivery/fetch.d.ts.map +1 -0
  85. package/dist/delivery/fetch.js +47 -0
  86. package/dist/delivery/fetch.js.map +1 -0
  87. package/dist/delivery/forwarder.d.ts +106 -0
  88. package/dist/delivery/forwarder.d.ts.map +1 -0
  89. package/dist/delivery/forwarder.js +251 -0
  90. package/dist/delivery/forwarder.js.map +1 -0
  91. package/dist/delivery/inbox.d.ts +42 -0
  92. package/dist/delivery/inbox.d.ts.map +1 -0
  93. package/dist/delivery/inbox.js +68 -0
  94. package/dist/delivery/inbox.js.map +1 -0
  95. package/dist/delivery/index.d.ts +31 -0
  96. package/dist/delivery/index.d.ts.map +1 -0
  97. package/dist/delivery/index.js +31 -0
  98. package/dist/delivery/index.js.map +1 -0
  99. package/dist/delivery/internalroute.d.ts +50 -0
  100. package/dist/delivery/internalroute.d.ts.map +1 -0
  101. package/dist/delivery/internalroute.js +23 -0
  102. package/dist/delivery/internalroute.js.map +1 -0
  103. package/dist/delivery/pipeline.d.ts +153 -0
  104. package/dist/delivery/pipeline.d.ts.map +1 -0
  105. package/dist/delivery/pipeline.js +356 -0
  106. package/dist/delivery/pipeline.js.map +1 -0
  107. package/dist/delivery/policy_state.d.ts +105 -0
  108. package/dist/delivery/policy_state.d.ts.map +1 -0
  109. package/dist/delivery/policy_state.js +293 -0
  110. package/dist/delivery/policy_state.js.map +1 -0
  111. package/dist/delivery/queue.d.ts +47 -0
  112. package/dist/delivery/queue.d.ts.map +1 -0
  113. package/dist/delivery/queue.js +33 -0
  114. package/dist/delivery/queue.js.map +1 -0
  115. package/dist/delivery/receipt.d.ts +137 -0
  116. package/dist/delivery/receipt.d.ts.map +1 -0
  117. package/dist/delivery/receipt.js +181 -0
  118. package/dist/delivery/receipt.js.map +1 -0
  119. package/dist/delivery/receipt_store.d.ts +81 -0
  120. package/dist/delivery/receipt_store.d.ts.map +1 -0
  121. package/dist/delivery/receipt_store.js +74 -0
  122. package/dist/delivery/receipt_store.js.map +1 -0
  123. package/dist/delivery/retry.d.ts +78 -0
  124. package/dist/delivery/retry.d.ts.map +1 -0
  125. package/dist/delivery/retry.js +132 -0
  126. package/dist/delivery/retry.js.map +1 -0
  127. package/dist/delivery/scheduler.d.ts +156 -0
  128. package/dist/delivery/scheduler.d.ts.map +1 -0
  129. package/dist/delivery/scheduler.js +349 -0
  130. package/dist/delivery/scheduler.js.map +1 -0
  131. package/dist/delivery/stage_partition.d.ts +87 -0
  132. package/dist/delivery/stage_partition.d.ts.map +1 -0
  133. package/dist/delivery/stage_partition.js +122 -0
  134. package/dist/delivery/stage_partition.js.map +1 -0
  135. package/dist/delivery/staged_runner.d.ts +100 -0
  136. package/dist/delivery/staged_runner.d.ts.map +1 -0
  137. package/dist/delivery/staged_runner.js +277 -0
  138. package/dist/delivery/staged_runner.js.map +1 -0
  139. package/dist/delivery/submission.d.ts +72 -0
  140. package/dist/delivery/submission.d.ts.map +1 -0
  141. package/dist/delivery/submission.js +58 -0
  142. package/dist/delivery/submission.js.map +1 -0
  143. package/dist/delivery/sync.d.ts +68 -0
  144. package/dist/delivery/sync.d.ts.map +1 -0
  145. package/dist/delivery/sync.js +99 -0
  146. package/dist/delivery/sync.js.map +1 -0
  147. package/dist/delivery/user_policy.d.ts +74 -0
  148. package/dist/delivery/user_policy.d.ts.map +1 -0
  149. package/dist/delivery/user_policy.js +140 -0
  150. package/dist/delivery/user_policy.js.map +1 -0
  151. package/dist/discovery/cache.d.ts +37 -0
  152. package/dist/discovery/cache.d.ts.map +1 -0
  153. package/dist/discovery/cache.js +45 -0
  154. package/dist/discovery/cache.js.map +1 -0
  155. package/dist/discovery/configuration.d.ts +97 -0
  156. package/dist/discovery/configuration.d.ts.map +1 -0
  157. package/dist/discovery/configuration.js +146 -0
  158. package/dist/discovery/configuration.js.map +1 -0
  159. package/dist/discovery/dns.d.ts +56 -0
  160. package/dist/discovery/dns.d.ts.map +1 -0
  161. package/dist/discovery/dns.js +120 -0
  162. package/dist/discovery/dns.js.map +1 -0
  163. package/dist/discovery/domain_keys.d.ts +62 -0
  164. package/dist/discovery/domain_keys.d.ts.map +1 -0
  165. package/dist/discovery/domain_keys.js +89 -0
  166. package/dist/discovery/domain_keys.js.map +1 -0
  167. package/dist/discovery/index.d.ts +19 -0
  168. package/dist/discovery/index.d.ts.map +1 -0
  169. package/dist/discovery/index.js +19 -0
  170. package/dist/discovery/index.js.map +1 -0
  171. package/dist/discovery/lookup.d.ts +72 -0
  172. package/dist/discovery/lookup.d.ts.map +1 -0
  173. package/dist/discovery/lookup.js +121 -0
  174. package/dist/discovery/lookup.js.map +1 -0
  175. package/dist/discovery/onion.d.ts +34 -0
  176. package/dist/discovery/onion.d.ts.map +1 -0
  177. package/dist/discovery/onion.js +61 -0
  178. package/dist/discovery/onion.js.map +1 -0
  179. package/dist/discovery/partition.d.ts +96 -0
  180. package/dist/discovery/partition.d.ts.map +1 -0
  181. package/dist/discovery/partition.js +247 -0
  182. package/dist/discovery/partition.js.map +1 -0
  183. package/dist/discovery/resolver.d.ts +113 -0
  184. package/dist/discovery/resolver.d.ts.map +1 -0
  185. package/dist/discovery/resolver.js +176 -0
  186. package/dist/discovery/resolver.js.map +1 -0
  187. package/dist/discovery/txt.d.ts +39 -0
  188. package/dist/discovery/txt.d.ts.map +1 -0
  189. package/dist/discovery/txt.js +71 -0
  190. package/dist/discovery/txt.js.map +1 -0
  191. package/dist/enclosure/forwarding.d.ts +128 -0
  192. package/dist/enclosure/forwarding.d.ts.map +1 -0
  193. package/dist/enclosure/forwarding.js +119 -0
  194. package/dist/enclosure/forwarding.js.map +1 -0
  195. package/dist/enclosure/index.d.ts +11 -0
  196. package/dist/enclosure/index.d.ts.map +1 -0
  197. package/dist/enclosure/index.js +11 -0
  198. package/dist/enclosure/index.js.map +1 -0
  199. package/dist/envelope/buckets.d.ts +38 -0
  200. package/dist/envelope/buckets.d.ts.map +1 -0
  201. package/dist/envelope/buckets.js +73 -0
  202. package/dist/envelope/buckets.js.map +1 -0
  203. package/dist/envelope/canonical.d.ts +28 -0
  204. package/dist/envelope/canonical.d.ts.map +1 -0
  205. package/dist/envelope/canonical.js +54 -0
  206. package/dist/envelope/canonical.js.map +1 -0
  207. package/dist/envelope/compose.d.ts +171 -0
  208. package/dist/envelope/compose.d.ts.map +1 -0
  209. package/dist/envelope/compose.js +237 -0
  210. package/dist/envelope/compose.js.map +1 -0
  211. package/dist/envelope/encode.d.ts +41 -0
  212. package/dist/envelope/encode.d.ts.map +1 -0
  213. package/dist/envelope/encode.js +69 -0
  214. package/dist/envelope/encode.js.map +1 -0
  215. package/dist/envelope/index.d.ts +20 -0
  216. package/dist/envelope/index.d.ts.map +1 -0
  217. package/dist/envelope/index.js +20 -0
  218. package/dist/envelope/index.js.map +1 -0
  219. package/dist/envelope/open_any.d.ts +48 -0
  220. package/dist/envelope/open_any.d.ts.map +1 -0
  221. package/dist/envelope/open_any.js +81 -0
  222. package/dist/envelope/open_any.js.map +1 -0
  223. package/dist/envelope/open_verified.d.ts +59 -0
  224. package/dist/envelope/open_verified.d.ts.map +1 -0
  225. package/dist/envelope/open_verified.js +67 -0
  226. package/dist/envelope/open_verified.js.map +1 -0
  227. package/dist/envelope/padding.d.ts +55 -0
  228. package/dist/envelope/padding.d.ts.map +1 -0
  229. package/dist/envelope/padding.js +162 -0
  230. package/dist/envelope/padding.js.map +1 -0
  231. package/dist/envelope/rejection.d.ts +22 -0
  232. package/dist/envelope/rejection.d.ts.map +1 -0
  233. package/dist/envelope/rejection.js +30 -0
  234. package/dist/envelope/rejection.js.map +1 -0
  235. package/dist/envelope/sendtime.d.ts +49 -0
  236. package/dist/envelope/sendtime.d.ts.map +1 -0
  237. package/dist/envelope/sendtime.js +87 -0
  238. package/dist/envelope/sendtime.js.map +1 -0
  239. package/dist/envelope/verify.d.ts +29 -0
  240. package/dist/envelope/verify.d.ts.map +1 -0
  241. package/dist/envelope/verify.js +90 -0
  242. package/dist/envelope/verify.js.map +1 -0
  243. package/dist/extensions/index.d.ts +7 -0
  244. package/dist/extensions/index.d.ts.map +1 -0
  245. package/dist/extensions/index.js +7 -0
  246. package/dist/extensions/index.js.map +1 -0
  247. package/dist/extensions/limits.d.ts +101 -0
  248. package/dist/extensions/limits.d.ts.map +1 -0
  249. package/dist/extensions/limits.js +175 -0
  250. package/dist/extensions/limits.js.map +1 -0
  251. package/dist/handshake/abort.d.ts +49 -0
  252. package/dist/handshake/abort.d.ts.map +1 -0
  253. package/dist/handshake/abort.js +82 -0
  254. package/dist/handshake/abort.js.map +1 -0
  255. package/dist/handshake/capabilities.d.ts +46 -0
  256. package/dist/handshake/capabilities.d.ts.map +1 -0
  257. package/dist/handshake/capabilities.js +114 -0
  258. package/dist/handshake/capabilities.js.map +1 -0
  259. package/dist/handshake/client_state.d.ts +186 -0
  260. package/dist/handshake/client_state.d.ts.map +1 -0
  261. package/dist/handshake/client_state.js +520 -0
  262. package/dist/handshake/client_state.js.map +1 -0
  263. package/dist/handshake/confirm.d.ts +21 -0
  264. package/dist/handshake/confirm.d.ts.map +1 -0
  265. package/dist/handshake/confirm.js +27 -0
  266. package/dist/handshake/confirm.js.map +1 -0
  267. package/dist/handshake/driver.d.ts +126 -0
  268. package/dist/handshake/driver.d.ts.map +1 -0
  269. package/dist/handshake/driver.js +251 -0
  270. package/dist/handshake/driver.js.map +1 -0
  271. package/dist/handshake/federation.d.ts +365 -0
  272. package/dist/handshake/federation.d.ts.map +1 -0
  273. package/dist/handshake/federation.js +664 -0
  274. package/dist/handshake/federation.js.map +1 -0
  275. package/dist/handshake/first_contact.d.ts +57 -0
  276. package/dist/handshake/first_contact.d.ts.map +1 -0
  277. package/dist/handshake/first_contact.js +124 -0
  278. package/dist/handshake/first_contact.js.map +1 -0
  279. package/dist/handshake/identity.d.ts +101 -0
  280. package/dist/handshake/identity.d.ts.map +1 -0
  281. package/dist/handshake/identity.js +117 -0
  282. package/dist/handshake/identity.js.map +1 -0
  283. package/dist/handshake/index.d.ts +21 -0
  284. package/dist/handshake/index.d.ts.map +1 -0
  285. package/dist/handshake/index.js +21 -0
  286. package/dist/handshake/index.js.map +1 -0
  287. package/dist/handshake/messages.d.ts +176 -0
  288. package/dist/handshake/messages.d.ts.map +1 -0
  289. package/dist/handshake/messages.js +125 -0
  290. package/dist/handshake/messages.js.map +1 -0
  291. package/dist/handshake/pow.d.ts +53 -0
  292. package/dist/handshake/pow.d.ts.map +1 -0
  293. package/dist/handshake/pow.js +142 -0
  294. package/dist/handshake/pow.js.map +1 -0
  295. package/dist/handshake/resume_driver.d.ts +56 -0
  296. package/dist/handshake/resume_driver.d.ts.map +1 -0
  297. package/dist/handshake/resume_driver.js +75 -0
  298. package/dist/handshake/resume_driver.js.map +1 -0
  299. package/dist/handshake/server.d.ts +112 -0
  300. package/dist/handshake/server.d.ts.map +1 -0
  301. package/dist/handshake/server.js +247 -0
  302. package/dist/handshake/server.js.map +1 -0
  303. package/dist/handshake/server_state.d.ts +102 -0
  304. package/dist/handshake/server_state.d.ts.map +1 -0
  305. package/dist/handshake/server_state.js +278 -0
  306. package/dist/handshake/server_state.js.map +1 -0
  307. package/dist/index.d.ts +33 -0
  308. package/dist/index.d.ts.map +1 -0
  309. package/dist/index.js +33 -0
  310. package/dist/index.js.map +1 -0
  311. package/dist/keys/compromise.d.ts +118 -0
  312. package/dist/keys/compromise.d.ts.map +1 -0
  313. package/dist/keys/compromise.js +218 -0
  314. package/dist/keys/compromise.js.map +1 -0
  315. package/dist/keys/device_certificate.d.ts +166 -0
  316. package/dist/keys/device_certificate.d.ts.map +1 -0
  317. package/dist/keys/device_certificate.js +328 -0
  318. package/dist/keys/device_certificate.js.map +1 -0
  319. package/dist/keys/device_records.d.ts +175 -0
  320. package/dist/keys/device_records.d.ts.map +1 -0
  321. package/dist/keys/device_records.js +418 -0
  322. package/dist/keys/device_records.js.map +1 -0
  323. package/dist/keys/directory_cache.d.ts +64 -0
  324. package/dist/keys/directory_cache.d.ts.map +1 -0
  325. package/dist/keys/directory_cache.js +98 -0
  326. package/dist/keys/directory_cache.js.map +1 -0
  327. package/dist/keys/directory_state.d.ts +79 -0
  328. package/dist/keys/directory_state.d.ts.map +1 -0
  329. package/dist/keys/directory_state.js +155 -0
  330. package/dist/keys/directory_state.js.map +1 -0
  331. package/dist/keys/index.d.ts +18 -0
  332. package/dist/keys/index.d.ts.map +1 -0
  333. package/dist/keys/index.js +18 -0
  334. package/dist/keys/index.js.map +1 -0
  335. package/dist/keys/key_revocation.d.ts +61 -0
  336. package/dist/keys/key_revocation.d.ts.map +1 -0
  337. package/dist/keys/key_revocation.js +88 -0
  338. package/dist/keys/key_revocation.js.map +1 -0
  339. package/dist/keys/request.d.ts +124 -0
  340. package/dist/keys/request.d.ts.map +1 -0
  341. package/dist/keys/request.js +130 -0
  342. package/dist/keys/request.js.map +1 -0
  343. package/dist/keys/sign.d.ts +49 -0
  344. package/dist/keys/sign.d.ts.map +1 -0
  345. package/dist/keys/sign.js +80 -0
  346. package/dist/keys/sign.js.map +1 -0
  347. package/dist/keys/signed.d.ts +80 -0
  348. package/dist/keys/signed.d.ts.map +1 -0
  349. package/dist/keys/signed.js +138 -0
  350. package/dist/keys/signed.js.map +1 -0
  351. package/dist/keys/store.d.ts +138 -0
  352. package/dist/keys/store.d.ts.map +1 -0
  353. package/dist/keys/store.js +107 -0
  354. package/dist/keys/store.js.map +1 -0
  355. package/dist/largeattachment/crypto.d.ts +47 -0
  356. package/dist/largeattachment/crypto.d.ts.map +1 -0
  357. package/dist/largeattachment/crypto.js +235 -0
  358. package/dist/largeattachment/crypto.js.map +1 -0
  359. package/dist/largeattachment/enclosure.d.ts +48 -0
  360. package/dist/largeattachment/enclosure.d.ts.map +1 -0
  361. package/dist/largeattachment/enclosure.js +102 -0
  362. package/dist/largeattachment/enclosure.js.map +1 -0
  363. package/dist/largeattachment/index.d.ts +15 -0
  364. package/dist/largeattachment/index.d.ts.map +1 -0
  365. package/dist/largeattachment/index.js +15 -0
  366. package/dist/largeattachment/index.js.map +1 -0
  367. package/dist/largeattachment/store.d.ts +36 -0
  368. package/dist/largeattachment/store.d.ts.map +1 -0
  369. package/dist/largeattachment/store.js +37 -0
  370. package/dist/largeattachment/store.js.map +1 -0
  371. package/dist/largeattachment/types.d.ts +56 -0
  372. package/dist/largeattachment/types.d.ts.map +1 -0
  373. package/dist/largeattachment/types.js +31 -0
  374. package/dist/largeattachment/types.js.map +1 -0
  375. package/dist/largeattachment/upload.d.ts +62 -0
  376. package/dist/largeattachment/upload.d.ts.map +1 -0
  377. package/dist/largeattachment/upload.js +166 -0
  378. package/dist/largeattachment/upload.js.map +1 -0
  379. package/dist/migration/index.d.ts +17 -0
  380. package/dist/migration/index.d.ts.map +1 -0
  381. package/dist/migration/index.js +17 -0
  382. package/dist/migration/index.js.map +1 -0
  383. package/dist/migration/lockout.d.ts +48 -0
  384. package/dist/migration/lockout.d.ts.map +1 -0
  385. package/dist/migration/lockout.js +57 -0
  386. package/dist/migration/lockout.js.map +1 -0
  387. package/dist/migration/migration.d.ts +48 -0
  388. package/dist/migration/migration.d.ts.map +1 -0
  389. package/dist/migration/migration.js +58 -0
  390. package/dist/migration/migration.js.map +1 -0
  391. package/dist/migration/notice.d.ts +33 -0
  392. package/dist/migration/notice.d.ts.map +1 -0
  393. package/dist/migration/notice.js +85 -0
  394. package/dist/migration/notice.js.map +1 -0
  395. package/dist/migration/orchestrate.d.ts +109 -0
  396. package/dist/migration/orchestrate.d.ts.map +1 -0
  397. package/dist/migration/orchestrate.js +212 -0
  398. package/dist/migration/orchestrate.js.map +1 -0
  399. package/dist/migration/publication_store.d.ts +34 -0
  400. package/dist/migration/publication_store.d.ts.map +1 -0
  401. package/dist/migration/publication_store.js +44 -0
  402. package/dist/migration/publication_store.js.map +1 -0
  403. package/dist/migration/sign.d.ts +65 -0
  404. package/dist/migration/sign.d.ts.map +1 -0
  405. package/dist/migration/sign.js +331 -0
  406. package/dist/migration/sign.js.map +1 -0
  407. package/dist/migration/types.d.ts +92 -0
  408. package/dist/migration/types.d.ts.map +1 -0
  409. package/dist/migration/types.js +26 -0
  410. package/dist/migration/types.js.map +1 -0
  411. package/dist/reasoncodes.d.ts +42 -0
  412. package/dist/reasoncodes.d.ts.map +1 -0
  413. package/dist/reasoncodes.js +80 -0
  414. package/dist/reasoncodes.js.map +1 -0
  415. package/dist/recovery/bundle.d.ts +34 -0
  416. package/dist/recovery/bundle.d.ts.map +1 -0
  417. package/dist/recovery/bundle.js +144 -0
  418. package/dist/recovery/bundle.js.map +1 -0
  419. package/dist/recovery/bundle_crypto.d.ts +60 -0
  420. package/dist/recovery/bundle_crypto.d.ts.map +1 -0
  421. package/dist/recovery/bundle_crypto.js +179 -0
  422. package/dist/recovery/bundle_crypto.js.map +1 -0
  423. package/dist/recovery/bundle_store.d.ts +57 -0
  424. package/dist/recovery/bundle_store.d.ts.map +1 -0
  425. package/dist/recovery/bundle_store.js +104 -0
  426. package/dist/recovery/bundle_store.js.map +1 -0
  427. package/dist/recovery/index.d.ts +19 -0
  428. package/dist/recovery/index.d.ts.map +1 -0
  429. package/dist/recovery/index.js +19 -0
  430. package/dist/recovery/index.js.map +1 -0
  431. package/dist/recovery/manifest_crosscheck.d.ts +59 -0
  432. package/dist/recovery/manifest_crosscheck.d.ts.map +1 -0
  433. package/dist/recovery/manifest_crosscheck.js +59 -0
  434. package/dist/recovery/manifest_crosscheck.js.map +1 -0
  435. package/dist/recovery/shamir.d.ts +51 -0
  436. package/dist/recovery/shamir.d.ts.map +1 -0
  437. package/dist/recovery/shamir.js +181 -0
  438. package/dist/recovery/shamir.js.map +1 -0
  439. package/dist/recovery/sign.d.ts +61 -0
  440. package/dist/recovery/sign.d.ts.map +1 -0
  441. package/dist/recovery/sign.js +359 -0
  442. package/dist/recovery/sign.js.map +1 -0
  443. package/dist/recovery/types.d.ts +180 -0
  444. package/dist/recovery/types.d.ts.map +1 -0
  445. package/dist/recovery/types.js +31 -0
  446. package/dist/recovery/types.js.map +1 -0
  447. package/dist/reputation/abuse_report.d.ts +62 -0
  448. package/dist/reputation/abuse_report.d.ts.map +1 -0
  449. package/dist/reputation/abuse_report.js +111 -0
  450. package/dist/reputation/abuse_report.js.map +1 -0
  451. package/dist/reputation/bucketize.d.ts +31 -0
  452. package/dist/reputation/bucketize.d.ts.map +1 -0
  453. package/dist/reputation/bucketize.js +77 -0
  454. package/dist/reputation/bucketize.js.map +1 -0
  455. package/dist/reputation/gossip.d.ts +24 -0
  456. package/dist/reputation/gossip.d.ts.map +1 -0
  457. package/dist/reputation/gossip.js +64 -0
  458. package/dist/reputation/gossip.js.map +1 -0
  459. package/dist/reputation/gossip_fetch.d.ts +64 -0
  460. package/dist/reputation/gossip_fetch.d.ts.map +1 -0
  461. package/dist/reputation/gossip_fetch.js +114 -0
  462. package/dist/reputation/gossip_fetch.js.map +1 -0
  463. package/dist/reputation/index.d.ts +20 -0
  464. package/dist/reputation/index.d.ts.map +1 -0
  465. package/dist/reputation/index.js +20 -0
  466. package/dist/reputation/index.js.map +1 -0
  467. package/dist/reputation/observation_store.d.ts +67 -0
  468. package/dist/reputation/observation_store.d.ts.map +1 -0
  469. package/dist/reputation/observation_store.js +171 -0
  470. package/dist/reputation/observation_store.js.map +1 -0
  471. package/dist/reputation/pow.d.ts +91 -0
  472. package/dist/reputation/pow.d.ts.map +1 -0
  473. package/dist/reputation/pow.js +209 -0
  474. package/dist/reputation/pow.js.map +1 -0
  475. package/dist/reputation/sign.d.ts +40 -0
  476. package/dist/reputation/sign.d.ts.map +1 -0
  477. package/dist/reputation/sign.js +202 -0
  478. package/dist/reputation/sign.js.map +1 -0
  479. package/dist/reputation/types.d.ts +133 -0
  480. package/dist/reputation/types.d.ts.map +1 -0
  481. package/dist/reputation/types.js +33 -0
  482. package/dist/reputation/types.js.map +1 -0
  483. package/dist/reputation/whois.d.ts +25 -0
  484. package/dist/reputation/whois.d.ts.map +1 -0
  485. package/dist/reputation/whois.js +20 -0
  486. package/dist/reputation/whois.js.map +1 -0
  487. package/dist/seal/index.d.ts +8 -0
  488. package/dist/seal/index.d.ts.map +1 -0
  489. package/dist/seal/index.js +8 -0
  490. package/dist/seal/index.js.map +1 -0
  491. package/dist/seal/wrap.d.ts +74 -0
  492. package/dist/seal/wrap.d.ts.map +1 -0
  493. package/dist/seal/wrap.js +213 -0
  494. package/dist/seal/wrap.js.map +1 -0
  495. package/dist/session/dispatcher.d.ts +65 -0
  496. package/dist/session/dispatcher.d.ts.map +1 -0
  497. package/dist/session/dispatcher.js +96 -0
  498. package/dist/session/dispatcher.js.map +1 -0
  499. package/dist/session/index.d.ts +15 -0
  500. package/dist/session/index.d.ts.map +1 -0
  501. package/dist/session/index.js +15 -0
  502. package/dist/session/index.js.map +1 -0
  503. package/dist/session/rekey.d.ts +108 -0
  504. package/dist/session/rekey.d.ts.map +1 -0
  505. package/dist/session/rekey.js +207 -0
  506. package/dist/session/rekey.js.map +1 -0
  507. package/dist/session/rekey_seal.d.ts +66 -0
  508. package/dist/session/rekey_seal.d.ts.map +1 -0
  509. package/dist/session/rekey_seal.js +153 -0
  510. package/dist/session/rekey_seal.js.map +1 -0
  511. package/dist/session/resume.d.ts +125 -0
  512. package/dist/session/resume.d.ts.map +1 -0
  513. package/dist/session/resume.js +263 -0
  514. package/dist/session/resume.js.map +1 -0
  515. package/dist/session/session.d.ts +136 -0
  516. package/dist/session/session.d.ts.map +1 -0
  517. package/dist/session/session.js +188 -0
  518. package/dist/session/session.js.map +1 -0
  519. package/dist/transparency/index.d.ts +13 -0
  520. package/dist/transparency/index.d.ts.map +1 -0
  521. package/dist/transparency/index.js +13 -0
  522. package/dist/transparency/index.js.map +1 -0
  523. package/dist/transparency/log.d.ts +61 -0
  524. package/dist/transparency/log.d.ts.map +1 -0
  525. package/dist/transparency/log.js +133 -0
  526. package/dist/transparency/log.js.map +1 -0
  527. package/dist/transparency/merkle.d.ts +59 -0
  528. package/dist/transparency/merkle.d.ts.map +1 -0
  529. package/dist/transparency/merkle.js +314 -0
  530. package/dist/transparency/merkle.js.map +1 -0
  531. package/dist/transparency/sign.d.ts +48 -0
  532. package/dist/transparency/sign.d.ts.map +1 -0
  533. package/dist/transparency/sign.js +140 -0
  534. package/dist/transparency/sign.js.map +1 -0
  535. package/dist/transparency/types.d.ts +97 -0
  536. package/dist/transparency/types.d.ts.map +1 -0
  537. package/dist/transparency/types.js +25 -0
  538. package/dist/transparency/types.js.map +1 -0
  539. package/dist/transport/h2.d.ts +163 -0
  540. package/dist/transport/h2.d.ts.map +1 -0
  541. package/dist/transport/h2.js +397 -0
  542. package/dist/transport/h2.js.map +1 -0
  543. package/dist/transport/index.d.ts +15 -0
  544. package/dist/transport/index.d.ts.map +1 -0
  545. package/dist/transport/index.js +15 -0
  546. package/dist/transport/index.js.map +1 -0
  547. package/dist/transport/memory.d.ts +21 -0
  548. package/dist/transport/memory.d.ts.map +1 -0
  549. package/dist/transport/memory.js +112 -0
  550. package/dist/transport/memory.js.map +1 -0
  551. package/dist/transport/transport.d.ts +54 -0
  552. package/dist/transport/transport.d.ts.map +1 -0
  553. package/dist/transport/transport.js +20 -0
  554. package/dist/transport/transport.js.map +1 -0
  555. package/dist/transport/ws.d.ts +40 -0
  556. package/dist/transport/ws.d.ts.map +1 -0
  557. package/dist/transport/ws.js +204 -0
  558. package/dist/transport/ws.js.map +1 -0
  559. package/package.json +147 -0
@@ -0,0 +1,664 @@
1
+ /**
2
+ * Federation handshake (server ↔ server) per HANDSHAKE.md §5.
3
+ *
4
+ * Two servers establish a federation session by exchanging four
5
+ * messages — symmetric in shape to the client handshake but with
6
+ * domain identity in plaintext on both sides plus a domain-proof
7
+ * verification step:
8
+ *
9
+ * 1. ServerInit (initiator → responder) carrying the initiator's
10
+ * domain, ephemeral key, identity proof, and a {@link DomainProof}
11
+ * that the responder verifies via DNS / certificate / well-known.
12
+ * 2. FederationResponse (responder → initiator) carrying the
13
+ * responder's identity material, the {@link DomainVerificationResult},
14
+ * negotiated capabilities, and the responder's
15
+ * {@link FederationPolicy}.
16
+ * 3. FederationConfirm (initiator → responder) with the
17
+ * confirmation hash and a {@link FederationAcceptance} block
18
+ * stating whether the initiator accepts the policy.
19
+ * 4. FederationAccepted (responder → initiator) finalizing the
20
+ * session and (optionally) issuing a resumption ticket.
21
+ *
22
+ * @module
23
+ */
24
+ import { marshal as canonicalMarshal } from "../canonical/index.js";
25
+ import { deriveSessionKeysWithResumption, newHKDFSHA512, x25519Agree, x25519PublicKey, } from "../crypto/index.js";
26
+ import { fingerprint, publicKeyFromSeed, sign as ed25519Sign, verify as ed25519Verify, } from "../keys/index.js";
27
+ import { confirmationHash } from "./confirm.js";
28
+ import { HandshakeRejectedError } from "./driver.js";
29
+ import { IdentityPrefix } from "./identity.js";
30
+ import { HandshakePrefix, HandshakeVersion, } from "./messages.js";
31
+ /** Wire-level discriminators (shared with the client handshake). */
32
+ export const FederationMessageType = "SEMP_HANDSHAKE";
33
+ /**
34
+ * Permissive verifier that accepts every proof. Tests / single-
35
+ * process deployments only — production MUST NOT use it.
36
+ */
37
+ export class TrustingDomainVerifier {
38
+ async verify() {
39
+ return;
40
+ }
41
+ }
42
+ /**
43
+ * Decide which of two simultaneously-initiated federation handshakes
44
+ * proceeds per SESSION.md §2.5.2. Both peers agree on the winner
45
+ * without external coordination — lexicographic compare provides
46
+ * exactly this property.
47
+ *
48
+ * Returns the winning `session_id` (the one that proceeds).
49
+ */
50
+ export function resolveCollision(idA, idB) {
51
+ return idA > idB ? idA : idB;
52
+ }
53
+ /** Default acceptor that accepts every policy (tests). */
54
+ export const acceptAllPolicies = () => null;
55
+ /**
56
+ * Stateful federation initiator. Mirror of `semp-go/handshake.Initiator`.
57
+ * Single-shot — discard after success or error.
58
+ */
59
+ export class FederationInitiator {
60
+ cfg;
61
+ localDomainPub;
62
+ localDomainKeyId;
63
+ nonce = null;
64
+ ephPriv = null;
65
+ ephPub = null;
66
+ initCanonical = null;
67
+ respCanonical = null;
68
+ sessionId = "";
69
+ sessionKeys = null;
70
+ finalSession = null;
71
+ resumptionSecret = null;
72
+ resumeNonce = null;
73
+ constructor(cfg) {
74
+ if (cfg.suite !== "x25519-chacha20-poly1305") {
75
+ throw new Error(`handshake: federation initiator only supports baseline suite, got ${cfg.suite}`);
76
+ }
77
+ if (cfg.localDomain === "") {
78
+ throw new Error("handshake: federation initiator empty localDomain");
79
+ }
80
+ if (cfg.localServerID === "") {
81
+ throw new Error("handshake: federation initiator empty localServerID");
82
+ }
83
+ if (cfg.localDomainSeed.length === 0) {
84
+ throw new Error("handshake: federation initiator empty localDomainSeed");
85
+ }
86
+ if (cfg.peerDomain === "") {
87
+ throw new Error("handshake: federation initiator empty peerDomain");
88
+ }
89
+ this.cfg = cfg;
90
+ this.localDomainPub = publicKeyFromSeed(cfg.localDomainSeed);
91
+ this.localDomainKeyId = fingerprint(this.localDomainPub);
92
+ if (cfg.initiatorEphemeralPriv !== undefined) {
93
+ this.ephPriv = cfg.initiatorEphemeralPriv;
94
+ }
95
+ if (cfg.initiatorNonce !== undefined) {
96
+ this.nonce = cfg.initiatorNonce;
97
+ }
98
+ }
99
+ /** Build ServerInit bytes (message 1). */
100
+ init() {
101
+ if (this.initCanonical !== null) {
102
+ throw new Error("handshake: federation initiator init already called");
103
+ }
104
+ if (this.ephPriv === null) {
105
+ this.ephPriv = randomBytes(32);
106
+ }
107
+ this.ephPub = x25519PublicKey(this.ephPriv);
108
+ if (this.nonce === null) {
109
+ this.nonce = randomBytes(32);
110
+ }
111
+ const ephKeyId = fingerprint(this.ephPub);
112
+ // Inner identity proof: sig over eph_pub || nonce with SEMP-IDENTITY: prefix.
113
+ const innerInput = concat(new TextEncoder().encode(IdentityPrefix), concat(this.ephPub, this.nonce));
114
+ const innerSig = ed25519Sign(this.cfg.localDomainSeed, innerInput);
115
+ const msg = {
116
+ type: FederationMessageType,
117
+ step: "init",
118
+ party: "server",
119
+ version: HandshakeVersion,
120
+ nonce: base64Encode(this.nonce),
121
+ server_id: this.cfg.localServerID,
122
+ server_domain: this.cfg.localDomain,
123
+ server_ephemeral_key: {
124
+ algorithm: this.cfg.suite,
125
+ key: base64Encode(this.ephPub),
126
+ key_id: ephKeyId,
127
+ },
128
+ server_identity_proof: {
129
+ key_id: this.localDomainKeyId,
130
+ signature: base64Encode(innerSig),
131
+ },
132
+ domain_proof: this.cfg.domainProof,
133
+ capabilities: this.cfg.capabilities,
134
+ server_signature: "",
135
+ extensions: {},
136
+ };
137
+ msg.server_signature = signServerMessage(msg, this.cfg.localDomainSeed);
138
+ this.initCanonical = canonicalMarshal(msg);
139
+ return this.initCanonical;
140
+ }
141
+ /** Process FederationResponse (message 2) and produce FederationConfirm bytes. */
142
+ onResponse(data) {
143
+ if (this.initCanonical === null) {
144
+ throw new Error("handshake: onResponse before init");
145
+ }
146
+ if (this.ephPriv === null || this.nonce === null) {
147
+ throw new Error("handshake: federation initiator state missing");
148
+ }
149
+ const m = JSON.parse(new TextDecoder().decode(data));
150
+ if (m["step"] === "rejected") {
151
+ const rej = m;
152
+ throw new HandshakeRejectedError(rej.session_id, rej.reason_code, rej.reason);
153
+ }
154
+ if (m["type"] !== FederationMessageType ||
155
+ m["step"] !== "response" ||
156
+ m["party"] !== "server") {
157
+ throw new Error(`handshake: federation response type/step/party mismatch`);
158
+ }
159
+ const resp = m;
160
+ if (resp.server_domain !== this.cfg.peerDomain) {
161
+ throw new Error(`handshake: response server_domain ${JSON.stringify(resp.server_domain)} != configured peer ${JSON.stringify(this.cfg.peerDomain)}`);
162
+ }
163
+ if (resp.client_nonce !== base64Encode(this.nonce)) {
164
+ throw new Error("handshake: federation response client_nonce mismatch");
165
+ }
166
+ if (resp.domain_verification_result.status !== "verified") {
167
+ throw new Error(`handshake: peer rejected our domain proof: ${resp.domain_verification_result.detail ?? ""}`);
168
+ }
169
+ const peerDomainPub = this.cfg.peerDomainPubLookup(resp.server_domain);
170
+ if (!verifyServerMessage(resp, resp.server_signature, peerDomainPub)) {
171
+ throw new Error("handshake: federation response server_signature did not verify");
172
+ }
173
+ // Inner identity proof check.
174
+ const serverEphPub = base64Decode(resp.server_ephemeral_key.key);
175
+ const serverNonce = base64Decode(resp.server_nonce);
176
+ const innerInput = concat(new TextEncoder().encode(IdentityPrefix), concat(concat(serverEphPub, serverNonce), this.nonce));
177
+ const innerSig = base64Decode(resp.server_identity_proof.signature);
178
+ if (!ed25519Verify(peerDomainPub, innerSig, innerInput)) {
179
+ throw new Error("handshake: peer inner identity_signature did not verify");
180
+ }
181
+ const shared = x25519Agree(this.ephPriv, serverEphPub);
182
+ const kdf = newHKDFSHA512();
183
+ this.sessionKeys = deriveSessionKeysWithResumption(kdf, shared, this.nonce, serverNonce);
184
+ // Erase ephemeral private once shared secret is in hand.
185
+ this.ephPriv.fill(0);
186
+ this.ephPriv = null;
187
+ this.respCanonical = canonicalMarshal(resp);
188
+ const ch = confirmationHash(this.initCanonical, this.respCanonical);
189
+ const acceptor = this.cfg.policyAcceptor ?? acceptAllPolicies;
190
+ const reason = acceptor(resp.federation_policy);
191
+ const acceptance = reason === null
192
+ ? { accepted: true, policy_acknowledged: true }
193
+ : { accepted: false, policy_acknowledged: false, reason };
194
+ const confirm = {
195
+ type: FederationMessageType,
196
+ step: "confirm",
197
+ party: "server",
198
+ version: HandshakeVersion,
199
+ session_id: resp.session_id,
200
+ confirmation_hash: base64Encode(ch),
201
+ federation_acceptance: acceptance,
202
+ server_signature: "",
203
+ extensions: {},
204
+ };
205
+ confirm.server_signature = signServerMessage(confirm, this.cfg.localDomainSeed);
206
+ this.sessionId = resp.session_id;
207
+ return canonicalMarshal(confirm);
208
+ }
209
+ /** Process FederationAccepted (message 4) and finalize the session. */
210
+ onAccepted(data) {
211
+ if (this.sessionKeys === null) {
212
+ throw new Error("handshake: onAccepted before onResponse");
213
+ }
214
+ const m = JSON.parse(new TextDecoder().decode(data));
215
+ if (m["step"] === "rejected") {
216
+ const rej = m;
217
+ throw new HandshakeRejectedError(rej.session_id, rej.reason_code, rej.reason);
218
+ }
219
+ if (m["type"] !== FederationMessageType ||
220
+ m["step"] !== "accepted" ||
221
+ m["party"] !== "server") {
222
+ throw new Error("handshake: federation accepted type/step/party mismatch");
223
+ }
224
+ const acc = m;
225
+ if (acc.session_id !== this.sessionId) {
226
+ throw new Error("handshake: federation accepted session_id mismatch");
227
+ }
228
+ const peerDomainPub = this.cfg.peerDomainPubLookup(this.cfg.peerDomain);
229
+ if (!verifyServerMessage(acc, acc.server_signature, peerDomainPub)) {
230
+ throw new Error("handshake: federation accepted server_signature did not verify");
231
+ }
232
+ const ttl = acc.session_ttl > 0 ? acc.session_ttl : 3600;
233
+ this.finalSession = {
234
+ sessionId: acc.session_id,
235
+ sessionTTL: ttl,
236
+ keys: this.sessionKeys,
237
+ peerDomain: this.cfg.peerDomain,
238
+ ...(acc.resumption_ticket !== undefined
239
+ ? { resumptionTicket: acc.resumption_ticket }
240
+ : {}),
241
+ extensions: acc.extensions,
242
+ };
243
+ }
244
+ /** Final session populated by {@link onAccepted}. */
245
+ session() {
246
+ if (this.finalSession === null) {
247
+ throw new Error("handshake: federation session not yet established");
248
+ }
249
+ return this.finalSession;
250
+ }
251
+ /** Load `K_resumption` recovered from a prior session before {@link resume}. */
252
+ loadResumptionSecret(secret) {
253
+ if (secret.length === 0) {
254
+ throw new Error("handshake: empty resumption secret");
255
+ }
256
+ this.resumptionSecret = secret.slice();
257
+ }
258
+ /**
259
+ * Build a {@link FederationResume} bytes per §2.8.7. `ticket` is
260
+ * the opaque value from the prior FederationAccepted's
261
+ * `resumption_ticket.value` (already base64-decoded). Pass
262
+ * `peerConfigurationRevision = 0` to omit it.
263
+ */
264
+ resume(ticket, peerConfigurationRevision = 0) {
265
+ if (this.resumptionSecret === null) {
266
+ throw new Error("handshake: resume before loadResumptionSecret");
267
+ }
268
+ if (ticket.length === 0) {
269
+ throw new Error("handshake: empty federation resumption ticket");
270
+ }
271
+ if (this.resumeNonce === null) {
272
+ this.resumeNonce = randomBytes(32);
273
+ }
274
+ if (this.ephPriv === null) {
275
+ this.ephPriv = randomBytes(32);
276
+ }
277
+ this.ephPub = x25519PublicKey(this.ephPriv);
278
+ const ephKeyId = fingerprint(this.ephPub);
279
+ const out = {
280
+ type: FederationMessageType,
281
+ step: "resume",
282
+ party: "server",
283
+ version: HandshakeVersion,
284
+ nonce: base64Encode(this.resumeNonce),
285
+ server_id: this.cfg.localServerID,
286
+ server_domain: this.cfg.localDomain,
287
+ ...(peerConfigurationRevision > 0
288
+ ? { peer_configuration_revision: peerConfigurationRevision }
289
+ : {}),
290
+ resumption_ticket: base64Encode(ticket),
291
+ client_ephemeral_key: {
292
+ algorithm: this.cfg.suite,
293
+ key: base64Encode(this.ephPub),
294
+ key_id: ephKeyId,
295
+ },
296
+ transport: "websocket",
297
+ extensions: {},
298
+ };
299
+ return canonicalMarshal(out);
300
+ }
301
+ /**
302
+ * Process the responder's FederationAccepted in response to
303
+ * {@link resume} and derive resumed session keys per §2.8.3.
304
+ */
305
+ onResumeAccepted(data) {
306
+ if (this.resumptionSecret === null || this.resumeNonce === null) {
307
+ throw new Error("handshake: onResumeAccepted before resume");
308
+ }
309
+ if (this.ephPriv === null) {
310
+ throw new Error("handshake: federation resume ephemeral missing");
311
+ }
312
+ const m = JSON.parse(new TextDecoder().decode(data));
313
+ if (m["step"] === "rejected") {
314
+ const rej = m;
315
+ throw new HandshakeRejectedError(rej.session_id, rej.reason_code, rej.reason);
316
+ }
317
+ if (m["type"] !== FederationMessageType ||
318
+ m["step"] !== "accepted" ||
319
+ m["party"] !== "server") {
320
+ throw new Error("handshake: resumed federation accepted type/step/party mismatch");
321
+ }
322
+ const acc = m;
323
+ if (acc.server_ephemeral_key === undefined ||
324
+ acc.server_nonce === undefined ||
325
+ acc.resumption_ticket === undefined) {
326
+ throw new Error("handshake: resumed federation accepted missing server_ephemeral_key / server_nonce / resumption_ticket");
327
+ }
328
+ const peerDomainPub = this.cfg.peerDomainPubLookup(this.cfg.peerDomain);
329
+ if (!verifyServerMessage(acc, acc.server_signature, peerDomainPub)) {
330
+ throw new Error("handshake: resumed federation accepted server_signature did not verify");
331
+ }
332
+ const serverNonce = base64Decode(acc.server_nonce);
333
+ const serverEphPub = base64Decode(acc.server_ephemeral_key.key);
334
+ const ephShared = x25519Agree(this.ephPriv, serverEphPub);
335
+ this.ephPriv.fill(0);
336
+ this.ephPriv = null;
337
+ // K_resumption mixes into IKM per §2.8.3.
338
+ const ikm = concat(this.resumptionSecret, ephShared);
339
+ const kdf = newHKDFSHA512();
340
+ const resumed = deriveSessionKeysWithResumption(kdf, ikm, this.resumeNonce, serverNonce);
341
+ this.resumptionSecret.fill(0);
342
+ this.resumptionSecret = null;
343
+ const ttl = acc.session_ttl > 0 ? acc.session_ttl : 3600;
344
+ const sess = {
345
+ sessionId: acc.session_id,
346
+ sessionTTL: ttl,
347
+ keys: resumed,
348
+ peerDomain: this.cfg.peerDomain,
349
+ resumptionTicket: acc.resumption_ticket,
350
+ extensions: acc.extensions,
351
+ };
352
+ this.finalSession = sess;
353
+ return {
354
+ session: sess,
355
+ newTicket: base64Decode(acc.resumption_ticket.value),
356
+ };
357
+ }
358
+ /** Wipe in-memory secret state. */
359
+ erase() {
360
+ if (this.ephPriv !== null) {
361
+ this.ephPriv.fill(0);
362
+ this.ephPriv = null;
363
+ }
364
+ if (this.nonce !== null) {
365
+ this.nonce.fill(0);
366
+ this.nonce = null;
367
+ }
368
+ if (this.resumptionSecret !== null) {
369
+ this.resumptionSecret.fill(0);
370
+ this.resumptionSecret = null;
371
+ }
372
+ this.sessionKeys = null;
373
+ }
374
+ }
375
+ /**
376
+ * Stateful federation responder. Mirror of `semp-go/handshake.Responder`.
377
+ * Single-shot — discard after success or error.
378
+ */
379
+ export class FederationResponder {
380
+ cfg;
381
+ localDomainPub;
382
+ localDomainKeyId;
383
+ verifier;
384
+ sessionTTL;
385
+ sessionId = "";
386
+ peerDomain = "";
387
+ peerNonce = null;
388
+ serverNonce = null;
389
+ respEphPriv = null;
390
+ initCanonical = null;
391
+ respCanonical = null;
392
+ sessionKeys = null;
393
+ finalSession = null;
394
+ constructor(cfg) {
395
+ if (cfg.suite !== "x25519-chacha20-poly1305") {
396
+ throw new Error(`handshake: federation responder only supports baseline suite, got ${cfg.suite}`);
397
+ }
398
+ if (cfg.localDomain === "") {
399
+ throw new Error("handshake: federation responder empty localDomain");
400
+ }
401
+ if (cfg.localDomainSeed.length === 0) {
402
+ throw new Error("handshake: federation responder empty localDomainSeed");
403
+ }
404
+ this.cfg = cfg;
405
+ this.localDomainPub = publicKeyFromSeed(cfg.localDomainSeed);
406
+ this.localDomainKeyId = fingerprint(this.localDomainPub);
407
+ this.verifier = cfg.verifier ?? new TrustingDomainVerifier();
408
+ this.sessionTTL = cfg.sessionTTL ?? 3600;
409
+ }
410
+ /**
411
+ * Process ServerInit (message 1) and produce FederationResponse
412
+ * bytes. Throws on signature, identity-proof, or domain-proof
413
+ * verification failure.
414
+ */
415
+ async onInit(data) {
416
+ if (this.initCanonical !== null) {
417
+ throw new Error("handshake: federation responder onInit called twice");
418
+ }
419
+ const m = JSON.parse(new TextDecoder().decode(data));
420
+ if (m["type"] !== FederationMessageType ||
421
+ m["step"] !== "init" ||
422
+ m["party"] !== "server") {
423
+ throw new Error("handshake: federation init type/step/party mismatch");
424
+ }
425
+ const init = m;
426
+ if (init.server_domain === "") {
427
+ throw new Error("handshake: empty initiator server_domain");
428
+ }
429
+ const peerDomainPub = this.cfg.peerDomainPubLookup(init.server_domain);
430
+ if (!verifyServerMessage(init, init.server_signature, peerDomainPub)) {
431
+ throw new Error("handshake: federation init server_signature did not verify");
432
+ }
433
+ // Inner identity proof: sig over eph_pub || nonce.
434
+ const clientEphPub = base64Decode(init.server_ephemeral_key.key);
435
+ const clientNonce = base64Decode(init.nonce);
436
+ const innerInput = concat(new TextEncoder().encode(IdentityPrefix), concat(clientEphPub, clientNonce));
437
+ const innerSig = base64Decode(init.server_identity_proof.signature);
438
+ if (!ed25519Verify(peerDomainPub, innerSig, innerInput)) {
439
+ throw new Error("handshake: federation init inner identity_signature did not verify");
440
+ }
441
+ // Domain-proof verification.
442
+ let result = {
443
+ status: "verified",
444
+ method: init.domain_proof.method,
445
+ };
446
+ try {
447
+ await this.verifier.verify(init.server_domain, init.domain_proof, init.nonce);
448
+ }
449
+ catch (err) {
450
+ const detail = err instanceof Error ? err.message : String(err);
451
+ result = {
452
+ status: "rejected",
453
+ method: init.domain_proof.method,
454
+ detail,
455
+ };
456
+ throw new Error(`handshake: federation domain proof verification failed: ${detail}`);
457
+ }
458
+ // Capability negotiation: pick the first mutually-supported suite.
459
+ const negotiated = pickSuite(init.capabilities.encryption_algorithms, this.cfg.capabilities.encryption_algorithms);
460
+ if (negotiated === undefined) {
461
+ throw new Error("handshake: federation no mutually supported suite");
462
+ }
463
+ if (negotiated !== this.cfg.suite) {
464
+ throw new Error(`handshake: federation negotiated suite ${negotiated} != responder suite ${this.cfg.suite}`);
465
+ }
466
+ this.respEphPriv = this.cfg.responderEphemeralPriv ?? randomBytes(32);
467
+ const respEphPub = x25519PublicKey(this.respEphPriv);
468
+ const respEphKeyId = fingerprint(respEphPub);
469
+ this.serverNonce = this.cfg.responderNonce ?? randomBytes(32);
470
+ this.sessionId = this.cfg.generateSessionId();
471
+ const shared = x25519Agree(this.respEphPriv, clientEphPub);
472
+ const kdf = newHKDFSHA512();
473
+ this.sessionKeys = deriveSessionKeysWithResumption(kdf, shared, clientNonce, this.serverNonce);
474
+ // Inner identity proof: sig over eph_pub || server_nonce || client_nonce.
475
+ const proofInput = concat(new TextEncoder().encode(IdentityPrefix), concat(concat(respEphPub, this.serverNonce), clientNonce));
476
+ const proofSig = ed25519Sign(this.cfg.localDomainSeed, proofInput);
477
+ const resp = {
478
+ type: FederationMessageType,
479
+ step: "response",
480
+ party: "server",
481
+ version: HandshakeVersion,
482
+ session_id: this.sessionId,
483
+ client_nonce: init.nonce,
484
+ server_nonce: base64Encode(this.serverNonce),
485
+ server_id: this.cfg.localServerID,
486
+ server_domain: this.cfg.localDomain,
487
+ server_ephemeral_key: {
488
+ algorithm: this.cfg.suite,
489
+ key: base64Encode(respEphPub),
490
+ key_id: respEphKeyId,
491
+ },
492
+ server_identity_proof: {
493
+ key_id: this.localDomainKeyId,
494
+ signature: base64Encode(proofSig),
495
+ },
496
+ domain_verification_result: result,
497
+ negotiated: {
498
+ encryption_algorithm: negotiated,
499
+ extensions: [],
500
+ },
501
+ federation_policy: this.cfg.policy,
502
+ server_signature: "",
503
+ extensions: {},
504
+ };
505
+ resp.server_signature = signServerMessage(resp, this.cfg.localDomainSeed);
506
+ this.peerDomain = init.server_domain;
507
+ this.peerNonce = clientNonce;
508
+ this.initCanonical = data;
509
+ this.respCanonical = canonicalMarshal(resp);
510
+ return this.respCanonical;
511
+ }
512
+ /**
513
+ * Process FederationConfirm (message 3) and produce
514
+ * FederationAccepted bytes (message 4). Throws if the initiator
515
+ * rejected the policy or the confirmation hash doesn't match.
516
+ */
517
+ onConfirm(data, opts = {}) {
518
+ if (this.initCanonical === null ||
519
+ this.respCanonical === null ||
520
+ this.sessionKeys === null) {
521
+ throw new Error("handshake: federation onConfirm before onInit");
522
+ }
523
+ const m = JSON.parse(new TextDecoder().decode(data));
524
+ if (m["type"] !== FederationMessageType ||
525
+ m["step"] !== "confirm" ||
526
+ m["party"] !== "server") {
527
+ throw new Error("handshake: federation confirm type/step/party mismatch");
528
+ }
529
+ const confirm = m;
530
+ if (confirm.session_id !== this.sessionId) {
531
+ throw new Error("handshake: federation confirm session_id mismatch");
532
+ }
533
+ const peerDomainPub = this.cfg.peerDomainPubLookup(this.peerDomain);
534
+ if (!verifyServerMessage(confirm, confirm.server_signature, peerDomainPub)) {
535
+ throw new Error("handshake: federation confirm server_signature did not verify");
536
+ }
537
+ const wantHash = confirmationHash(this.initCanonical, this.respCanonical);
538
+ const gotHash = base64Decode(confirm.confirmation_hash);
539
+ if (!constantTimeEqual(gotHash, wantHash)) {
540
+ throw new Error("handshake: federation confirmation hash mismatch");
541
+ }
542
+ if (!confirm.federation_acceptance.accepted) {
543
+ throw new Error(`handshake: federation initiator rejected our policy: ${confirm.federation_acceptance.reason ?? ""}`);
544
+ }
545
+ const ticket = opts.issueResumptionTicket?.(this.sessionKeys);
546
+ const acc = {
547
+ type: FederationMessageType,
548
+ step: "accepted",
549
+ party: "server",
550
+ version: HandshakeVersion,
551
+ session_id: this.sessionId,
552
+ status: "accepted",
553
+ session_ttl: this.sessionTTL,
554
+ ...(ticket !== undefined ? { resumption_ticket: ticket } : {}),
555
+ server_signature: "",
556
+ extensions: {},
557
+ };
558
+ acc.server_signature = signServerMessage(acc, this.cfg.localDomainSeed);
559
+ this.finalSession = {
560
+ sessionId: this.sessionId,
561
+ sessionTTL: this.sessionTTL,
562
+ keys: this.sessionKeys,
563
+ peerDomain: this.peerDomain,
564
+ };
565
+ if (this.respEphPriv !== null) {
566
+ this.respEphPriv.fill(0);
567
+ this.respEphPriv = null;
568
+ }
569
+ return canonicalMarshal(acc);
570
+ }
571
+ /** Final session populated by {@link onConfirm}. */
572
+ session() {
573
+ if (this.finalSession === null) {
574
+ throw new Error("handshake: federation responder session not yet established");
575
+ }
576
+ return this.finalSession;
577
+ }
578
+ /** Wipe in-memory secret state. */
579
+ erase() {
580
+ if (this.respEphPriv !== null) {
581
+ this.respEphPriv.fill(0);
582
+ this.respEphPriv = null;
583
+ }
584
+ if (this.peerNonce !== null) {
585
+ this.peerNonce.fill(0);
586
+ this.peerNonce = null;
587
+ }
588
+ if (this.serverNonce !== null) {
589
+ this.serverNonce.fill(0);
590
+ this.serverNonce = null;
591
+ }
592
+ this.sessionKeys = null;
593
+ }
594
+ }
595
+ // ---------------------------------------------------------------------------
596
+ // Helpers
597
+ function signServerMessage(msg, seed) {
598
+ const clone = JSON.parse(JSON.stringify(msg));
599
+ clone.server_signature = "";
600
+ const canonical = canonicalMarshal(clone);
601
+ const signingInput = concat(new TextEncoder().encode(HandshakePrefix), canonical);
602
+ return base64Encode(ed25519Sign(seed, signingInput));
603
+ }
604
+ function verifyServerMessage(msg, signatureB64, domainPub) {
605
+ if (signatureB64 === "") {
606
+ return false;
607
+ }
608
+ const clone = JSON.parse(JSON.stringify(msg));
609
+ clone["server_signature"] = "";
610
+ const canonical = canonicalMarshal(clone);
611
+ const signingInput = concat(new TextEncoder().encode(HandshakePrefix), canonical);
612
+ return ed25519Verify(domainPub, base64Decode(signatureB64), signingInput);
613
+ }
614
+ function pickSuite(offered, supported) {
615
+ for (const s of supported) {
616
+ if (offered.includes(s)) {
617
+ return s;
618
+ }
619
+ }
620
+ return undefined;
621
+ }
622
+ function constantTimeEqual(a, b) {
623
+ if (a.length !== b.length) {
624
+ return false;
625
+ }
626
+ let diff = 0;
627
+ for (let i = 0; i < a.length; i++) {
628
+ diff |= (a[i] ?? 0) ^ (b[i] ?? 0);
629
+ }
630
+ return diff === 0;
631
+ }
632
+ function randomBytes(n) {
633
+ const out = new Uint8Array(n);
634
+ globalThis.crypto.getRandomValues(out);
635
+ return out;
636
+ }
637
+ function concat(a, b) {
638
+ const out = new Uint8Array(a.length + b.length);
639
+ out.set(a, 0);
640
+ out.set(b, a.length);
641
+ return out;
642
+ }
643
+ function base64Encode(b) {
644
+ if (typeof Buffer !== "undefined") {
645
+ return Buffer.from(b).toString("base64");
646
+ }
647
+ let bin = "";
648
+ for (let i = 0; i < b.length; i++) {
649
+ bin += String.fromCharCode(b[i] ?? 0);
650
+ }
651
+ return btoa(bin);
652
+ }
653
+ function base64Decode(s) {
654
+ if (typeof Buffer !== "undefined") {
655
+ return new Uint8Array(Buffer.from(s, "base64"));
656
+ }
657
+ const bin = atob(s);
658
+ const out = new Uint8Array(bin.length);
659
+ for (let i = 0; i < bin.length; i++) {
660
+ out[i] = bin.charCodeAt(i);
661
+ }
662
+ return out;
663
+ }
664
+ //# sourceMappingURL=federation.js.map