@naylence/advanced-security 0.3.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 (304) hide show
  1. package/LICENSE +33 -0
  2. package/NOTICE +5 -0
  3. package/README.md +101 -0
  4. package/dist/browser/index.js +157043 -0
  5. package/dist/browser/index.js.map +1 -0
  6. package/dist/cjs/browser.js +6 -0
  7. package/dist/cjs/browser.js.map +1 -0
  8. package/dist/cjs/index.js +7 -0
  9. package/dist/cjs/index.js.map +1 -0
  10. package/dist/cjs/naylence/fame/factory-manifest.js +24 -0
  11. package/dist/cjs/naylence/fame/factory-manifest.js.map +1 -0
  12. package/dist/cjs/naylence/fame/security/cert/ca-service-client.js +284 -0
  13. package/dist/cjs/naylence/fame/security/cert/ca-service-client.js.map +1 -0
  14. package/dist/cjs/naylence/fame/security/cert/ca-service-factory.js +65 -0
  15. package/dist/cjs/naylence/fame/security/cert/ca-service-factory.js.map +1 -0
  16. package/dist/cjs/naylence/fame/security/cert/ca-types.js +36 -0
  17. package/dist/cjs/naylence/fame/security/cert/ca-types.js.map +1 -0
  18. package/dist/cjs/naylence/fame/security/cert/default-ca-service-factory.js +70 -0
  19. package/dist/cjs/naylence/fame/security/cert/default-ca-service-factory.js.map +1 -0
  20. package/dist/cjs/naylence/fame/security/cert/default-ca-service.js +270 -0
  21. package/dist/cjs/naylence/fame/security/cert/default-ca-service.js.map +1 -0
  22. package/dist/cjs/naylence/fame/security/cert/default-certificate-manager-factory.js +77 -0
  23. package/dist/cjs/naylence/fame/security/cert/default-certificate-manager-factory.js.map +1 -0
  24. package/dist/cjs/naylence/fame/security/cert/default-certificate-manager.js +675 -0
  25. package/dist/cjs/naylence/fame/security/cert/default-certificate-manager.js.map +1 -0
  26. package/dist/cjs/naylence/fame/security/cert/grants.js +5 -0
  27. package/dist/cjs/naylence/fame/security/cert/grants.js.map +1 -0
  28. package/dist/cjs/naylence/fame/security/cert/index.js +52 -0
  29. package/dist/cjs/naylence/fame/security/cert/index.js.map +1 -0
  30. package/dist/cjs/naylence/fame/security/cert/internal-ca-service.js +793 -0
  31. package/dist/cjs/naylence/fame/security/cert/internal-ca-service.js.map +1 -0
  32. package/dist/cjs/naylence/fame/security/cert/util.js +120 -0
  33. package/dist/cjs/naylence/fame/security/cert/util.js.map +1 -0
  34. package/dist/cjs/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.js +89 -0
  35. package/dist/cjs/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.js.map +1 -0
  36. package/dist/cjs/naylence/fame/security/encryption/channel/channel-encryption-manager.js +732 -0
  37. package/dist/cjs/naylence/fame/security/encryption/channel/channel-encryption-manager.js.map +1 -0
  38. package/dist/cjs/naylence/fame/security/encryption/channel/index.js +8 -0
  39. package/dist/cjs/naylence/fame/security/encryption/channel/index.js.map +1 -0
  40. package/dist/cjs/naylence/fame/security/encryption/composite-encryption-manager-factory.js +117 -0
  41. package/dist/cjs/naylence/fame/security/encryption/composite-encryption-manager-factory.js.map +1 -0
  42. package/dist/cjs/naylence/fame/security/encryption/composite-encryption-manager.js +325 -0
  43. package/dist/cjs/naylence/fame/security/encryption/composite-encryption-manager.js.map +1 -0
  44. package/dist/cjs/naylence/fame/security/encryption/default-secure-channel-manager-factory.js +57 -0
  45. package/dist/cjs/naylence/fame/security/encryption/default-secure-channel-manager-factory.js.map +1 -0
  46. package/dist/cjs/naylence/fame/security/encryption/default-secure-channel-manager.js +282 -0
  47. package/dist/cjs/naylence/fame/security/encryption/default-secure-channel-manager.js.map +1 -0
  48. package/dist/cjs/naylence/fame/security/encryption/encryption-manager-registry.js +173 -0
  49. package/dist/cjs/naylence/fame/security/encryption/encryption-manager-registry.js.map +1 -0
  50. package/dist/cjs/naylence/fame/security/encryption/index.js +16 -0
  51. package/dist/cjs/naylence/fame/security/encryption/index.js.map +1 -0
  52. package/dist/cjs/naylence/fame/security/encryption/sealed/index.js +8 -0
  53. package/dist/cjs/naylence/fame/security/encryption/sealed/index.js.map +1 -0
  54. package/dist/cjs/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.js +86 -0
  55. package/dist/cjs/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.js.map +1 -0
  56. package/dist/cjs/naylence/fame/security/encryption/sealed/x25519-encryption-manager.js +546 -0
  57. package/dist/cjs/naylence/fame/security/encryption/sealed/x25519-encryption-manager.js.map +1 -0
  58. package/dist/cjs/naylence/fame/security/index.js +11 -0
  59. package/dist/cjs/naylence/fame/security/index.js.map +1 -0
  60. package/dist/cjs/naylence/fame/security/keys/index.js +9 -0
  61. package/dist/cjs/naylence/fame/security/keys/index.js.map +1 -0
  62. package/dist/cjs/naylence/fame/security/keys/x5c-key-manager-factory.js +40 -0
  63. package/dist/cjs/naylence/fame/security/keys/x5c-key-manager-factory.js.map +1 -0
  64. package/dist/cjs/naylence/fame/security/keys/x5c-key-manager.js +441 -0
  65. package/dist/cjs/naylence/fame/security/keys/x5c-key-manager.js.map +1 -0
  66. package/dist/cjs/naylence/fame/security/register-advanced-security-factories.js +131 -0
  67. package/dist/cjs/naylence/fame/security/register-advanced-security-factories.js.map +1 -0
  68. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-signer-factory.js +71 -0
  69. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-signer-factory.js.map +1 -0
  70. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-verifier-factory.js +31 -0
  71. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-verifier-factory.js.map +1 -0
  72. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-verifier.js +176 -0
  73. package/dist/cjs/naylence/fame/security/signing/eddsa-envelope-verifier.js.map +1 -0
  74. package/dist/cjs/naylence/fame/stickiness/aft-helper.js +77 -0
  75. package/dist/cjs/naylence/fame/stickiness/aft-helper.js.map +1 -0
  76. package/dist/cjs/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.js +69 -0
  77. package/dist/cjs/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.js.map +1 -0
  78. package/dist/cjs/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.js +451 -0
  79. package/dist/cjs/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.js.map +1 -0
  80. package/dist/cjs/naylence/fame/stickiness/aft-model.js +62 -0
  81. package/dist/cjs/naylence/fame/stickiness/aft-model.js.map +1 -0
  82. package/dist/cjs/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.js +54 -0
  83. package/dist/cjs/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.js.map +1 -0
  84. package/dist/cjs/naylence/fame/stickiness/aft-replica-stickiness-manager.js +208 -0
  85. package/dist/cjs/naylence/fame/stickiness/aft-replica-stickiness-manager.js.map +1 -0
  86. package/dist/cjs/naylence/fame/stickiness/aft-signer.js +154 -0
  87. package/dist/cjs/naylence/fame/stickiness/aft-signer.js.map +1 -0
  88. package/dist/cjs/naylence/fame/stickiness/aft-utils.js +95 -0
  89. package/dist/cjs/naylence/fame/stickiness/aft-utils.js.map +1 -0
  90. package/dist/cjs/naylence/fame/stickiness/aft-verifier.js +297 -0
  91. package/dist/cjs/naylence/fame/stickiness/aft-verifier.js.map +1 -0
  92. package/dist/cjs/naylence/fame/stickiness/index.js +40 -0
  93. package/dist/cjs/naylence/fame/stickiness/index.js.map +1 -0
  94. package/dist/cjs/naylence/fame/stickiness/stickiness-mode.js +28 -0
  95. package/dist/cjs/naylence/fame/stickiness/stickiness-mode.js.map +1 -0
  96. package/dist/cjs/naylence/fame/welcome/advanced-welcome-service-factory.js +97 -0
  97. package/dist/cjs/naylence/fame/welcome/advanced-welcome-service-factory.js.map +1 -0
  98. package/dist/cjs/naylence/fame/welcome/advanced-welcome-service.js +216 -0
  99. package/dist/cjs/naylence/fame/welcome/advanced-welcome-service.js.map +1 -0
  100. package/dist/cjs/naylence/fame/welcome/index.js +9 -0
  101. package/dist/cjs/naylence/fame/welcome/index.js.map +1 -0
  102. package/dist/cjs/plugin.js +41 -0
  103. package/dist/cjs/plugin.js.map +1 -0
  104. package/dist/esm/browser.js +3 -0
  105. package/dist/esm/browser.js.map +1 -0
  106. package/dist/esm/index.js +4 -0
  107. package/dist/esm/index.js.map +1 -0
  108. package/dist/esm/naylence/fame/factory-manifest.js +21 -0
  109. package/dist/esm/naylence/fame/factory-manifest.js.map +1 -0
  110. package/dist/esm/naylence/fame/security/cert/ca-server.js +153 -0
  111. package/dist/esm/naylence/fame/security/cert/ca-server.js.map +1 -0
  112. package/dist/esm/naylence/fame/security/cert/ca-service-client.js +278 -0
  113. package/dist/esm/naylence/fame/security/cert/ca-service-client.js.map +1 -0
  114. package/dist/esm/naylence/fame/security/cert/ca-service-factory.js +61 -0
  115. package/dist/esm/naylence/fame/security/cert/ca-service-factory.js.map +1 -0
  116. package/dist/esm/naylence/fame/security/cert/ca-types.js +31 -0
  117. package/dist/esm/naylence/fame/security/cert/ca-types.js.map +1 -0
  118. package/dist/esm/naylence/fame/security/cert/default-ca-service-factory.js +66 -0
  119. package/dist/esm/naylence/fame/security/cert/default-ca-service-factory.js.map +1 -0
  120. package/dist/esm/naylence/fame/security/cert/default-ca-service.js +233 -0
  121. package/dist/esm/naylence/fame/security/cert/default-ca-service.js.map +1 -0
  122. package/dist/esm/naylence/fame/security/cert/default-certificate-manager-factory.js +73 -0
  123. package/dist/esm/naylence/fame/security/cert/default-certificate-manager-factory.js.map +1 -0
  124. package/dist/esm/naylence/fame/security/cert/default-certificate-manager.js +638 -0
  125. package/dist/esm/naylence/fame/security/cert/default-certificate-manager.js.map +1 -0
  126. package/dist/esm/naylence/fame/security/cert/grants.js +2 -0
  127. package/dist/esm/naylence/fame/security/cert/grants.js.map +1 -0
  128. package/dist/esm/naylence/fame/security/cert/index.js +12 -0
  129. package/dist/esm/naylence/fame/security/cert/index.js.map +1 -0
  130. package/dist/esm/naylence/fame/security/cert/internal-ca-service.js +750 -0
  131. package/dist/esm/naylence/fame/security/cert/internal-ca-service.js.map +1 -0
  132. package/dist/esm/naylence/fame/security/cert/util.js +116 -0
  133. package/dist/esm/naylence/fame/security/cert/util.js.map +1 -0
  134. package/dist/esm/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.js +85 -0
  135. package/dist/esm/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.js.map +1 -0
  136. package/dist/esm/naylence/fame/security/encryption/channel/channel-encryption-manager.js +728 -0
  137. package/dist/esm/naylence/fame/security/encryption/channel/channel-encryption-manager.js.map +1 -0
  138. package/dist/esm/naylence/fame/security/encryption/channel/index.js +3 -0
  139. package/dist/esm/naylence/fame/security/encryption/channel/index.js.map +1 -0
  140. package/dist/esm/naylence/fame/security/encryption/composite-encryption-manager-factory.js +113 -0
  141. package/dist/esm/naylence/fame/security/encryption/composite-encryption-manager-factory.js.map +1 -0
  142. package/dist/esm/naylence/fame/security/encryption/composite-encryption-manager.js +321 -0
  143. package/dist/esm/naylence/fame/security/encryption/composite-encryption-manager.js.map +1 -0
  144. package/dist/esm/naylence/fame/security/encryption/default-secure-channel-manager-factory.js +53 -0
  145. package/dist/esm/naylence/fame/security/encryption/default-secure-channel-manager-factory.js.map +1 -0
  146. package/dist/esm/naylence/fame/security/encryption/default-secure-channel-manager.js +278 -0
  147. package/dist/esm/naylence/fame/security/encryption/default-secure-channel-manager.js.map +1 -0
  148. package/dist/esm/naylence/fame/security/encryption/encryption-manager-registry.js +167 -0
  149. package/dist/esm/naylence/fame/security/encryption/encryption-manager-registry.js.map +1 -0
  150. package/dist/esm/naylence/fame/security/encryption/index.js +7 -0
  151. package/dist/esm/naylence/fame/security/encryption/index.js.map +1 -0
  152. package/dist/esm/naylence/fame/security/encryption/sealed/index.js +3 -0
  153. package/dist/esm/naylence/fame/security/encryption/sealed/index.js.map +1 -0
  154. package/dist/esm/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.js +82 -0
  155. package/dist/esm/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.js.map +1 -0
  156. package/dist/esm/naylence/fame/security/encryption/sealed/x25519-encryption-manager.js +542 -0
  157. package/dist/esm/naylence/fame/security/encryption/sealed/x25519-encryption-manager.js.map +1 -0
  158. package/dist/esm/naylence/fame/security/index.js +6 -0
  159. package/dist/esm/naylence/fame/security/index.js.map +1 -0
  160. package/dist/esm/naylence/fame/security/keys/index.js +3 -0
  161. package/dist/esm/naylence/fame/security/keys/index.js.map +1 -0
  162. package/dist/esm/naylence/fame/security/keys/x5c-key-manager-factory.js +36 -0
  163. package/dist/esm/naylence/fame/security/keys/x5c-key-manager-factory.js.map +1 -0
  164. package/dist/esm/naylence/fame/security/keys/x5c-key-manager.js +405 -0
  165. package/dist/esm/naylence/fame/security/keys/x5c-key-manager.js.map +1 -0
  166. package/dist/esm/naylence/fame/security/register-advanced-security-factories.js +95 -0
  167. package/dist/esm/naylence/fame/security/register-advanced-security-factories.js.map +1 -0
  168. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-signer-factory.js +34 -0
  169. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-signer-factory.js.map +1 -0
  170. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-verifier-factory.js +27 -0
  171. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-verifier-factory.js.map +1 -0
  172. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-verifier.js +172 -0
  173. package/dist/esm/naylence/fame/security/signing/eddsa-envelope-verifier.js.map +1 -0
  174. package/dist/esm/naylence/fame/stickiness/aft-helper.js +72 -0
  175. package/dist/esm/naylence/fame/stickiness/aft-helper.js.map +1 -0
  176. package/dist/esm/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.js +65 -0
  177. package/dist/esm/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.js.map +1 -0
  178. package/dist/esm/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.js +447 -0
  179. package/dist/esm/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.js.map +1 -0
  180. package/dist/esm/naylence/fame/stickiness/aft-model.js +54 -0
  181. package/dist/esm/naylence/fame/stickiness/aft-model.js.map +1 -0
  182. package/dist/esm/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.js +50 -0
  183. package/dist/esm/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.js.map +1 -0
  184. package/dist/esm/naylence/fame/stickiness/aft-replica-stickiness-manager.js +203 -0
  185. package/dist/esm/naylence/fame/stickiness/aft-replica-stickiness-manager.js.map +1 -0
  186. package/dist/esm/naylence/fame/stickiness/aft-signer.js +147 -0
  187. package/dist/esm/naylence/fame/stickiness/aft-signer.js.map +1 -0
  188. package/dist/esm/naylence/fame/stickiness/aft-utils.js +90 -0
  189. package/dist/esm/naylence/fame/stickiness/aft-utils.js.map +1 -0
  190. package/dist/esm/naylence/fame/stickiness/aft-verifier.js +290 -0
  191. package/dist/esm/naylence/fame/stickiness/aft-verifier.js.map +1 -0
  192. package/dist/esm/naylence/fame/stickiness/index.js +11 -0
  193. package/dist/esm/naylence/fame/stickiness/index.js.map +1 -0
  194. package/dist/esm/naylence/fame/stickiness/stickiness-mode.js +24 -0
  195. package/dist/esm/naylence/fame/stickiness/stickiness-mode.js.map +1 -0
  196. package/dist/esm/naylence/fame/welcome/advanced-welcome-service-factory.js +93 -0
  197. package/dist/esm/naylence/fame/welcome/advanced-welcome-service-factory.js.map +1 -0
  198. package/dist/esm/naylence/fame/welcome/advanced-welcome-service.js +212 -0
  199. package/dist/esm/naylence/fame/welcome/advanced-welcome-service.js.map +1 -0
  200. package/dist/esm/naylence/fame/welcome/index.js +3 -0
  201. package/dist/esm/naylence/fame/welcome/index.js.map +1 -0
  202. package/dist/esm/plugin.js +37 -0
  203. package/dist/esm/plugin.js.map +1 -0
  204. package/dist/types/browser.d.ts +2 -0
  205. package/dist/types/browser.d.ts.map +1 -0
  206. package/dist/types/index.d.ts +4 -0
  207. package/dist/types/index.d.ts.map +1 -0
  208. package/dist/types/naylence/fame/factory-manifest.d.ts +9 -0
  209. package/dist/types/naylence/fame/factory-manifest.d.ts.map +1 -0
  210. package/dist/types/naylence/fame/security/cert/ca-server.d.ts +19 -0
  211. package/dist/types/naylence/fame/security/cert/ca-server.d.ts.map +1 -0
  212. package/dist/types/naylence/fame/security/cert/ca-service-client.d.ts +75 -0
  213. package/dist/types/naylence/fame/security/cert/ca-service-client.d.ts.map +1 -0
  214. package/dist/types/naylence/fame/security/cert/ca-service-factory.d.ts +43 -0
  215. package/dist/types/naylence/fame/security/cert/ca-service-factory.d.ts.map +1 -0
  216. package/dist/types/naylence/fame/security/cert/ca-types.d.ts +97 -0
  217. package/dist/types/naylence/fame/security/cert/ca-types.d.ts.map +1 -0
  218. package/dist/types/naylence/fame/security/cert/default-ca-service-factory.d.ts +55 -0
  219. package/dist/types/naylence/fame/security/cert/default-ca-service-factory.d.ts.map +1 -0
  220. package/dist/types/naylence/fame/security/cert/default-ca-service.d.ts +84 -0
  221. package/dist/types/naylence/fame/security/cert/default-ca-service.d.ts.map +1 -0
  222. package/dist/types/naylence/fame/security/cert/default-certificate-manager-factory.d.ts +25 -0
  223. package/dist/types/naylence/fame/security/cert/default-certificate-manager-factory.d.ts.map +1 -0
  224. package/dist/types/naylence/fame/security/cert/default-certificate-manager.d.ts +38 -0
  225. package/dist/types/naylence/fame/security/cert/default-certificate-manager.d.ts.map +1 -0
  226. package/dist/types/naylence/fame/security/cert/grants.d.ts +2 -0
  227. package/dist/types/naylence/fame/security/cert/grants.d.ts.map +1 -0
  228. package/dist/types/naylence/fame/security/cert/index.d.ts +11 -0
  229. package/dist/types/naylence/fame/security/cert/index.d.ts.map +1 -0
  230. package/dist/types/naylence/fame/security/cert/internal-ca-service.d.ts +132 -0
  231. package/dist/types/naylence/fame/security/cert/internal-ca-service.d.ts.map +1 -0
  232. package/dist/types/naylence/fame/security/cert/util.d.ts +35 -0
  233. package/dist/types/naylence/fame/security/cert/util.d.ts.map +1 -0
  234. package/dist/types/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.d.ts +29 -0
  235. package/dist/types/naylence/fame/security/encryption/channel/channel-encryption-manager-factory.d.ts.map +1 -0
  236. package/dist/types/naylence/fame/security/encryption/channel/channel-encryption-manager.d.ts +51 -0
  237. package/dist/types/naylence/fame/security/encryption/channel/channel-encryption-manager.d.ts.map +1 -0
  238. package/dist/types/naylence/fame/security/encryption/channel/index.d.ts +3 -0
  239. package/dist/types/naylence/fame/security/encryption/channel/index.d.ts.map +1 -0
  240. package/dist/types/naylence/fame/security/encryption/composite-encryption-manager-factory.d.ts +32 -0
  241. package/dist/types/naylence/fame/security/encryption/composite-encryption-manager-factory.d.ts.map +1 -0
  242. package/dist/types/naylence/fame/security/encryption/composite-encryption-manager.d.ts +52 -0
  243. package/dist/types/naylence/fame/security/encryption/composite-encryption-manager.d.ts.map +1 -0
  244. package/dist/types/naylence/fame/security/encryption/default-secure-channel-manager-factory.d.ts +23 -0
  245. package/dist/types/naylence/fame/security/encryption/default-secure-channel-manager-factory.d.ts.map +1 -0
  246. package/dist/types/naylence/fame/security/encryption/default-secure-channel-manager.d.ts +37 -0
  247. package/dist/types/naylence/fame/security/encryption/default-secure-channel-manager.d.ts.map +1 -0
  248. package/dist/types/naylence/fame/security/encryption/encryption-manager-registry.d.ts +34 -0
  249. package/dist/types/naylence/fame/security/encryption/encryption-manager-registry.d.ts.map +1 -0
  250. package/dist/types/naylence/fame/security/encryption/index.d.ts +7 -0
  251. package/dist/types/naylence/fame/security/encryption/index.d.ts.map +1 -0
  252. package/dist/types/naylence/fame/security/encryption/sealed/index.d.ts +3 -0
  253. package/dist/types/naylence/fame/security/encryption/sealed/index.d.ts.map +1 -0
  254. package/dist/types/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.d.ts +28 -0
  255. package/dist/types/naylence/fame/security/encryption/sealed/x25519-encryption-manager-factory.d.ts.map +1 -0
  256. package/dist/types/naylence/fame/security/encryption/sealed/x25519-encryption-manager.d.ts +43 -0
  257. package/dist/types/naylence/fame/security/encryption/sealed/x25519-encryption-manager.d.ts.map +1 -0
  258. package/dist/types/naylence/fame/security/index.d.ts +6 -0
  259. package/dist/types/naylence/fame/security/index.d.ts.map +1 -0
  260. package/dist/types/naylence/fame/security/keys/index.d.ts +3 -0
  261. package/dist/types/naylence/fame/security/keys/index.d.ts.map +1 -0
  262. package/dist/types/naylence/fame/security/keys/x5c-key-manager-factory.d.ts +19 -0
  263. package/dist/types/naylence/fame/security/keys/x5c-key-manager-factory.d.ts.map +1 -0
  264. package/dist/types/naylence/fame/security/keys/x5c-key-manager.d.ts +39 -0
  265. package/dist/types/naylence/fame/security/keys/x5c-key-manager.d.ts.map +1 -0
  266. package/dist/types/naylence/fame/security/register-advanced-security-factories.d.ts +8 -0
  267. package/dist/types/naylence/fame/security/register-advanced-security-factories.d.ts.map +1 -0
  268. package/dist/types/naylence/fame/security/signing/eddsa-envelope-signer-factory.d.ts +20 -0
  269. package/dist/types/naylence/fame/security/signing/eddsa-envelope-signer-factory.d.ts.map +1 -0
  270. package/dist/types/naylence/fame/security/signing/eddsa-envelope-verifier-factory.d.ts +21 -0
  271. package/dist/types/naylence/fame/security/signing/eddsa-envelope-verifier-factory.d.ts.map +1 -0
  272. package/dist/types/naylence/fame/security/signing/eddsa-envelope-verifier.d.ts +17 -0
  273. package/dist/types/naylence/fame/security/signing/eddsa-envelope-verifier.d.ts.map +1 -0
  274. package/dist/types/naylence/fame/stickiness/aft-helper.d.ts +29 -0
  275. package/dist/types/naylence/fame/stickiness/aft-helper.d.ts.map +1 -0
  276. package/dist/types/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.d.ts +25 -0
  277. package/dist/types/naylence/fame/stickiness/aft-load-balancer-stickiness-manager-factory.d.ts.map +1 -0
  278. package/dist/types/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.d.ts +33 -0
  279. package/dist/types/naylence/fame/stickiness/aft-load-balancer-stickiness-manager.d.ts.map +1 -0
  280. package/dist/types/naylence/fame/stickiness/aft-model.d.ts +33 -0
  281. package/dist/types/naylence/fame/stickiness/aft-model.d.ts.map +1 -0
  282. package/dist/types/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.d.ts +23 -0
  283. package/dist/types/naylence/fame/stickiness/aft-replica-stickiness-manager-factory.d.ts.map +1 -0
  284. package/dist/types/naylence/fame/stickiness/aft-replica-stickiness-manager.d.ts +31 -0
  285. package/dist/types/naylence/fame/stickiness/aft-replica-stickiness-manager.d.ts.map +1 -0
  286. package/dist/types/naylence/fame/stickiness/aft-signer.d.ts +55 -0
  287. package/dist/types/naylence/fame/stickiness/aft-signer.d.ts.map +1 -0
  288. package/dist/types/naylence/fame/stickiness/aft-utils.d.ts +4 -0
  289. package/dist/types/naylence/fame/stickiness/aft-utils.d.ts.map +1 -0
  290. package/dist/types/naylence/fame/stickiness/aft-verifier.d.ts +50 -0
  291. package/dist/types/naylence/fame/stickiness/aft-verifier.d.ts.map +1 -0
  292. package/dist/types/naylence/fame/stickiness/index.d.ts +15 -0
  293. package/dist/types/naylence/fame/stickiness/index.d.ts.map +1 -0
  294. package/dist/types/naylence/fame/stickiness/stickiness-mode.d.ts +7 -0
  295. package/dist/types/naylence/fame/stickiness/stickiness-mode.d.ts.map +1 -0
  296. package/dist/types/naylence/fame/welcome/advanced-welcome-service-factory.d.ts +21 -0
  297. package/dist/types/naylence/fame/welcome/advanced-welcome-service-factory.d.ts.map +1 -0
  298. package/dist/types/naylence/fame/welcome/advanced-welcome-service.d.ts +21 -0
  299. package/dist/types/naylence/fame/welcome/advanced-welcome-service.d.ts.map +1 -0
  300. package/dist/types/naylence/fame/welcome/index.d.ts +3 -0
  301. package/dist/types/naylence/fame/welcome/index.d.ts.map +1 -0
  302. package/dist/types/plugin.d.ts +11 -0
  303. package/dist/types/plugin.d.ts.map +1 -0
  304. package/package.json +130 -0
@@ -0,0 +1,728 @@
1
+ import { chacha20poly1305 } from "@noble/ciphers/chacha.js";
2
+ import { FameAddress, formatAddress, localDeliveryContext, } from "@naylence/core";
3
+ import { EncryptionResult, } from "@naylence/runtime";
4
+ import { requireCryptoSupport } from "@naylence/runtime";
5
+ import { getLogger } from "@naylence/runtime";
6
+ import { generateId } from "@naylence/core";
7
+ import { urlsafeBase64Decode } from "@naylence/runtime";
8
+ const logger = getLogger("naylence.fame.security.encryption.channel.channel_encryption_manager");
9
+ const SUPPORTED_CHANNEL_ALGORITHMS = ["chacha20-poly1305-channel"];
10
+ const CHANNEL_ENCRYPTION_ALGORITHM = "chacha20-poly1305-channel";
11
+ const HANDSHAKE_ALGORITHM = "CHACHA20P1305";
12
+ const SYSTEM_INBOX = "__sys__";
13
+ const NONCE_LENGTH = 12;
14
+ function isTaskSpawnerLike(value) {
15
+ return Boolean(value && typeof value.spawn === "function");
16
+ }
17
+ function toUint8Array(value) {
18
+ if (value instanceof Uint8Array) {
19
+ return value;
20
+ }
21
+ if (typeof ArrayBuffer !== "undefined") {
22
+ if (value instanceof ArrayBuffer) {
23
+ return new Uint8Array(value);
24
+ }
25
+ if (ArrayBuffer.isView(value)) {
26
+ const view = value;
27
+ return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
28
+ }
29
+ }
30
+ if (Array.isArray(value)) {
31
+ return Uint8Array.from(value);
32
+ }
33
+ return null;
34
+ }
35
+ function encodeBase64(data) {
36
+ if (typeof Buffer !== "undefined") {
37
+ return Buffer.from(data).toString("base64");
38
+ }
39
+ let binary = "";
40
+ for (const byte of data) {
41
+ binary += String.fromCharCode(byte);
42
+ }
43
+ if (typeof btoa === "function") {
44
+ return btoa(binary);
45
+ }
46
+ throw new Error("Base64 encoding not supported in this environment");
47
+ }
48
+ function decodeBase64(encoded) {
49
+ if (typeof Buffer !== "undefined") {
50
+ return Uint8Array.from(Buffer.from(encoded, "base64"));
51
+ }
52
+ if (typeof atob === "function") {
53
+ const binary = atob(encoded);
54
+ const bytes = new Uint8Array(binary.length);
55
+ for (let i = 0; i < binary.length; i += 1) {
56
+ bytes[i] = binary.charCodeAt(i);
57
+ }
58
+ return bytes;
59
+ }
60
+ throw new Error("Base64 decoding not supported in this environment");
61
+ }
62
+ function randomBytes(length) {
63
+ if (typeof crypto !== "undefined" &&
64
+ typeof crypto.getRandomValues === "function") {
65
+ const buffer = new Uint8Array(length);
66
+ crypto.getRandomValues(buffer);
67
+ return buffer;
68
+ }
69
+ try {
70
+ const { randomBytes: nodeRandomBytes } = require("node:crypto");
71
+ return nodeRandomBytes(length);
72
+ }
73
+ catch {
74
+ throw new Error("Crypto random bytes are not available in this environment");
75
+ }
76
+ }
77
+ function toFameAddress(value) {
78
+ if (!value) {
79
+ return null;
80
+ }
81
+ if (value instanceof FameAddress) {
82
+ return value;
83
+ }
84
+ return new FameAddress(String(value));
85
+ }
86
+ function toDestinationString(value) {
87
+ if (!value) {
88
+ return null;
89
+ }
90
+ if (value instanceof FameAddress) {
91
+ return value.toString();
92
+ }
93
+ if (typeof value === "string") {
94
+ return value;
95
+ }
96
+ return null;
97
+ }
98
+ function makeJsonSerializable(value) {
99
+ if (value === null || value === undefined) {
100
+ return null;
101
+ }
102
+ if (Array.isArray(value)) {
103
+ return value.map((item) => makeJsonSerializable(item));
104
+ }
105
+ if (value instanceof Uint8Array) {
106
+ return Array.from(value);
107
+ }
108
+ if (typeof value === "object") {
109
+ const candidate = value;
110
+ if (typeof candidate.toJSON === "function") {
111
+ return candidate.toJSON();
112
+ }
113
+ if (typeof candidate.model_dump === "function") {
114
+ return candidate.model_dump();
115
+ }
116
+ if (typeof candidate.dict === "function") {
117
+ return candidate.dict();
118
+ }
119
+ return { ...candidate };
120
+ }
121
+ return value;
122
+ }
123
+ export class ChannelEncryptionManager {
124
+ constructor({ secureChannelManager = null, nodeLike = null, taskSpawner = null, } = {}) {
125
+ this.pendingEnvelopes = new Map();
126
+ this.handshakeInProgress = new Set();
127
+ this.addrChannelMap = new Map();
128
+ this.secureChannelManager = secureChannelManager ?? null;
129
+ this.nodeLike = nodeLike ?? null;
130
+ this.taskSpawner =
131
+ taskSpawner ?? (isTaskSpawnerLike(nodeLike) ? nodeLike : taskSpawner);
132
+ }
133
+ async encryptEnvelope(envelope, opts = null) {
134
+ const frame = envelope.frame;
135
+ if (!this.isDataFrame(frame)) {
136
+ return EncryptionResult.skipped(envelope);
137
+ }
138
+ if (frame.payload === null || typeof frame.payload === "undefined") {
139
+ return EncryptionResult.skipped(envelope);
140
+ }
141
+ const destination = opts?.destination ?? envelope.to ?? null;
142
+ const destinationStr = toDestinationString(destination);
143
+ if (!destinationStr) {
144
+ logger.warning("no_destination_for_channel_encryption", {
145
+ envelope_id: envelope.id,
146
+ });
147
+ return EncryptionResult.skipped(envelope);
148
+ }
149
+ if (!this.secureChannelManager) {
150
+ logger.warning("no_secure_channel_manager_available", {
151
+ envelope_id: envelope.id,
152
+ });
153
+ return EncryptionResult.skipped(envelope);
154
+ }
155
+ const existingChannelId = this.findExistingChannel(destinationStr);
156
+ if (existingChannelId) {
157
+ try {
158
+ return this.encryptWithChannel(envelope, existingChannelId);
159
+ }
160
+ catch (error) {
161
+ logger.error("channel_encryption_failed", {
162
+ error: error instanceof Error ? error.message : String(error),
163
+ channel_id: existingChannelId,
164
+ });
165
+ return EncryptionResult.skipped(envelope);
166
+ }
167
+ }
168
+ await this.queueAndInitiateHandshake(envelope, destination, destinationStr, opts ?? null);
169
+ return EncryptionResult.queued();
170
+ }
171
+ async decryptEnvelope(envelope, opts = null) {
172
+ void opts;
173
+ requireCryptoSupport();
174
+ const frame = envelope.frame;
175
+ if (!this.isDataFrame(frame) ||
176
+ frame.payload === null ||
177
+ typeof frame.payload === "undefined") {
178
+ return envelope;
179
+ }
180
+ if (!envelope.sec || !envelope.sec.enc) {
181
+ return envelope;
182
+ }
183
+ const encHeader = envelope.sec.enc;
184
+ if (!encHeader.alg || !this.isChannelAlgorithm(encHeader.alg)) {
185
+ return envelope;
186
+ }
187
+ const channelId = encHeader.kid;
188
+ if (!channelId) {
189
+ logger.error("missing_channel_id_in_encryption_header", {
190
+ envelope_id: envelope.id,
191
+ });
192
+ return envelope;
193
+ }
194
+ const nonce = this.decodeNonceValue(encHeader.val ?? "");
195
+ if (!nonce) {
196
+ logger.error("invalid_nonce_in_encryption_header", {
197
+ envelope_id: envelope.id,
198
+ value_present: Boolean(encHeader.val),
199
+ });
200
+ return envelope;
201
+ }
202
+ if (!this.secureChannelManager) {
203
+ logger.warning("no_secure_channel_manager_for_decryption", {
204
+ envelope_id: envelope.id,
205
+ });
206
+ return envelope;
207
+ }
208
+ const channelState = this.getChannelState(channelId);
209
+ if (!channelState) {
210
+ logger.error("channel_not_available_for_decryption", {
211
+ channel_id: channelId,
212
+ });
213
+ return envelope;
214
+ }
215
+ const ciphertext = this.extractCiphertext(frame.payload);
216
+ if (!ciphertext) {
217
+ logger.error("invalid_ciphertext_payload", { envelope_id: envelope.id });
218
+ return envelope;
219
+ }
220
+ try {
221
+ const aad = new TextEncoder().encode(channelId);
222
+ const aead = chacha20poly1305(channelState.key, nonce, aad);
223
+ const plaintextBytes = aead.decrypt(ciphertext);
224
+ const decodedPayload = this.deserializePayload(plaintextBytes);
225
+ frame.payload = decodedPayload;
226
+ frame.codec = "json";
227
+ if (envelope.sec) {
228
+ delete envelope.sec.enc;
229
+ if (!envelope.sec.sig) {
230
+ envelope.sec = undefined;
231
+ }
232
+ }
233
+ if (envelope.replyTo) {
234
+ this.addrChannelMap.set(String(envelope.replyTo), channelId);
235
+ }
236
+ if (envelope.sid) {
237
+ this.addrChannelMap.set(envelope.sid, channelId);
238
+ }
239
+ return envelope;
240
+ }
241
+ catch (error) {
242
+ logger.error("channel_decryption_failed", {
243
+ channel_id: channelId,
244
+ error: error instanceof Error ? error.message : String(error),
245
+ });
246
+ return envelope;
247
+ }
248
+ }
249
+ async notifyChannelEstablished(channelId) {
250
+ logger.debug("channel_encryption_manager_notified", {
251
+ channel_id: channelId,
252
+ manager_type: "channel",
253
+ });
254
+ if (!channelId.startsWith("auto-")) {
255
+ logger.warning("unexpected_channel_id_format", { channel_id: channelId });
256
+ return;
257
+ }
258
+ const destinationStr = this.extractDestinationFromChannelId(channelId);
259
+ if (!destinationStr) {
260
+ logger.warning("cannot_parse_destination_from_channel_id", {
261
+ channel_id: channelId,
262
+ });
263
+ return;
264
+ }
265
+ this.handshakeInProgress.delete(destinationStr);
266
+ if (!this.pendingEnvelopes.has(destinationStr)) {
267
+ logger.debug("no_pending_queue_for_destination", {
268
+ destination: destinationStr,
269
+ });
270
+ return;
271
+ }
272
+ const queuedEnvelopes = this.pendingEnvelopes.get(destinationStr) ?? [];
273
+ this.pendingEnvelopes.delete(destinationStr);
274
+ if (!this.secureChannelManager) {
275
+ logger.error("no_secure_channel_manager_for_queue_drain", {
276
+ channel_id: channelId,
277
+ });
278
+ return;
279
+ }
280
+ for (const envelope of queuedEnvelopes) {
281
+ try {
282
+ const result = this.encryptWithChannel(envelope, channelId);
283
+ if (!result.envelope) {
284
+ logger.warning("failed_to_encrypt_queued_envelope", {
285
+ envelope_id: envelope.id,
286
+ channel_id: channelId,
287
+ });
288
+ continue;
289
+ }
290
+ const encryptedEnvelope = result.envelope;
291
+ this.runAsyncTask(() => this.deliverEnvelope(encryptedEnvelope), `deliver-queued-${envelope.id}`);
292
+ }
293
+ catch (error) {
294
+ logger.error("failed_to_encrypt_queued_envelope", {
295
+ envelope_id: envelope.id,
296
+ error: error instanceof Error ? error.message : String(error),
297
+ });
298
+ }
299
+ }
300
+ }
301
+ async notifyChannelFailed(channelId, reason = "handshake_failed") {
302
+ logger.debug("channel_encryption_manager_notified_failure", {
303
+ channel_id: channelId,
304
+ reason,
305
+ });
306
+ if (!channelId.startsWith("auto-")) {
307
+ logger.warning("unexpected_channel_id_format_on_failure", {
308
+ channel_id: channelId,
309
+ });
310
+ return;
311
+ }
312
+ const destinationStr = this.extractDestinationFromChannelId(channelId);
313
+ if (!destinationStr) {
314
+ logger.warning("cannot_parse_destination_from_channel_id_on_failure", {
315
+ channel_id: channelId,
316
+ });
317
+ return;
318
+ }
319
+ this.handshakeInProgress.delete(destinationStr);
320
+ // Clear any cached channel mapping for this destination since the channel failed
321
+ const cachedChannelId = this.addrChannelMap.get(destinationStr);
322
+ if (cachedChannelId === channelId) {
323
+ this.addrChannelMap.delete(destinationStr);
324
+ logger.debug("cleared_channel_cache_for_failed_channel", {
325
+ destination: destinationStr,
326
+ channel_id: channelId,
327
+ });
328
+ }
329
+ const queuedEnvelopes = this.pendingEnvelopes.get(destinationStr);
330
+ if (!queuedEnvelopes || queuedEnvelopes.length === 0) {
331
+ logger.debug("no_pending_queue_for_failed_destination", {
332
+ destination: destinationStr,
333
+ });
334
+ return;
335
+ }
336
+ this.pendingEnvelopes.delete(destinationStr);
337
+ for (const envelope of queuedEnvelopes) {
338
+ await this.handleFailedEnvelope(envelope, destinationStr, channelId, reason);
339
+ }
340
+ }
341
+ /**
342
+ * Clear cached channel mappings for a destination.
343
+ * This should be called when routes are removed or channels are closed
344
+ * to prevent using stale channel references.
345
+ */
346
+ clearChannelCacheForDestination(destination) {
347
+ const cached = this.addrChannelMap.get(destination);
348
+ if (cached) {
349
+ this.addrChannelMap.delete(destination);
350
+ logger.debug("cleared_channel_cache_for_destination", {
351
+ destination,
352
+ cached_channel_id: cached,
353
+ });
354
+ }
355
+ }
356
+ isChannelAlgorithm(algorithm) {
357
+ return SUPPORTED_CHANNEL_ALGORITHMS.includes(algorithm);
358
+ }
359
+ isDataFrame(frame) {
360
+ return Boolean(frame && frame.type === "Data");
361
+ }
362
+ findExistingChannel(destination) {
363
+ if (!this.secureChannelManager) {
364
+ return null;
365
+ }
366
+ const cached = this.addrChannelMap.get(destination);
367
+ if (cached && this.getChannelState(cached)) {
368
+ logger.debug("using_cached_channel", { destination, channel_id: cached });
369
+ return cached;
370
+ }
371
+ const channels = this.secureChannelManager.channels;
372
+ for (const channelId of Object.keys(channels)) {
373
+ if (channelId.startsWith(`auto-${destination}-`)) {
374
+ this.addrChannelMap.set(destination, channelId);
375
+ logger.debug("using_existing_channel", {
376
+ destination,
377
+ channel_id: channelId,
378
+ });
379
+ return channelId;
380
+ }
381
+ }
382
+ return null;
383
+ }
384
+ async queueAndInitiateHandshake(envelope, destination, destinationStr, opts) {
385
+ const queue = this.pendingEnvelopes.get(destinationStr) ?? [];
386
+ queue.push(envelope);
387
+ this.pendingEnvelopes.set(destinationStr, queue);
388
+ logger.debug("queued_envelope_for_channel_handshake", {
389
+ envelope_id: envelope.id,
390
+ destination: destinationStr,
391
+ });
392
+ if (this.handshakeInProgress.has(destinationStr)) {
393
+ logger.debug("handshake_already_in_progress", {
394
+ destination: destinationStr,
395
+ });
396
+ return;
397
+ }
398
+ this.handshakeInProgress.add(destinationStr);
399
+ const taskName = `handshake-${destinationStr}`;
400
+ this.runAsyncTask(async () => {
401
+ try {
402
+ await this.initiateChannelHandshakeAsync(destination ?? destinationStr, destinationStr, opts);
403
+ }
404
+ finally {
405
+ this.handshakeInProgress.delete(destinationStr);
406
+ }
407
+ }, taskName);
408
+ }
409
+ async initiateChannelHandshakeAsync(destination, destinationStr, opts) {
410
+ void opts;
411
+ if (!this.secureChannelManager) {
412
+ logger.error("no_secure_channel_manager_for_async_handshake_initiation");
413
+ return;
414
+ }
415
+ const channelId = this.generateChannelId(destinationStr);
416
+ try {
417
+ const openFrame = this.secureChannelManager.generateOpenFrame(channelId, HANDSHAKE_ALGORITHM);
418
+ const success = await this.sendSecureOpenFrameAsync(openFrame, destination);
419
+ if (success) {
420
+ logger.debug("sent_secure_open_frame_async", {
421
+ channel_id: channelId,
422
+ destination: destinationStr,
423
+ });
424
+ }
425
+ else {
426
+ logger.warning("failed_to_send_secure_open_frame_async", {
427
+ channel_id: channelId,
428
+ });
429
+ }
430
+ }
431
+ catch (error) {
432
+ logger.error("async_channel_handshake_initiation_failed", {
433
+ destination: destinationStr,
434
+ error: error instanceof Error ? error.message : String(error),
435
+ });
436
+ }
437
+ }
438
+ async sendSecureOpenFrameAsync(openFrame, destination) {
439
+ const node = this.nodeLike;
440
+ if (!node) {
441
+ logger.error("no_node_available_for_sending_secure_open_async");
442
+ return false;
443
+ }
444
+ const envelopeFactory = node.envelopeFactory;
445
+ if (!envelopeFactory) {
446
+ logger.error("no_envelope_factory_available_for_secure_open_async");
447
+ return false;
448
+ }
449
+ const replyTo = this.buildSystemReplyTo();
450
+ if (!replyTo) {
451
+ logger.error("no_physical_path_available_for_reply_to_async");
452
+ return false;
453
+ }
454
+ const toAddress = toFameAddress(destination);
455
+ if (!toAddress) {
456
+ logger.error("invalid_destination_for_secure_open", {
457
+ destination: String(destination),
458
+ });
459
+ return false;
460
+ }
461
+ const envelope = envelopeFactory.createEnvelope({
462
+ to: toAddress,
463
+ frame: openFrame,
464
+ replyTo,
465
+ corrId: generateId(),
466
+ });
467
+ await this.deliverEnvelope(envelope);
468
+ logger.debug("delivered_secure_open_frame_async", {
469
+ channel_id: openFrame.cid,
470
+ });
471
+ return true;
472
+ }
473
+ async deliverEnvelope(envelope) {
474
+ const node = this.nodeLike;
475
+ if (!node) {
476
+ logger.error("no_node_available_for_delivery", {
477
+ envelope_id: envelope.id,
478
+ });
479
+ return;
480
+ }
481
+ const context = localDeliveryContext(node.sid ?? undefined);
482
+ await node.deliver(envelope, context);
483
+ }
484
+ encryptWithChannel(envelope, channelId) {
485
+ if (!this.secureChannelManager) {
486
+ logger.error("no_secure_channel_manager_for_encryption");
487
+ return EncryptionResult.skipped(envelope);
488
+ }
489
+ const frame = envelope.frame;
490
+ if (!this.isDataFrame(frame)) {
491
+ logger.error("attempted_to_encrypt_non_dataframe", {
492
+ frame_type: frame.type ?? typeof frame,
493
+ });
494
+ return EncryptionResult.skipped(envelope);
495
+ }
496
+ const channelState = this.getChannelState(channelId);
497
+ if (!channelState) {
498
+ logger.error("channel_not_in_channels", { channel_id: channelId });
499
+ return EncryptionResult.skipped(envelope);
500
+ }
501
+ const payloadBytes = this.serializePayload(frame.payload);
502
+ if (!payloadBytes) {
503
+ return EncryptionResult.skipped(envelope);
504
+ }
505
+ const nonce = randomBytes(NONCE_LENGTH);
506
+ const aad = new TextEncoder().encode(channelId);
507
+ const aead = chacha20poly1305(channelState.key, nonce, aad);
508
+ const ciphertext = aead.encrypt(payloadBytes);
509
+ const encryptionHeader = {
510
+ alg: CHANNEL_ENCRYPTION_ALGORITHM,
511
+ val: Array.from(nonce)
512
+ .map((byte) => byte.toString(16).padStart(2, "0"))
513
+ .join(""), // Hex encoding (Python reference)
514
+ kid: channelId,
515
+ };
516
+ const encodedCiphertext = encodeBase64(ciphertext);
517
+ frame.payload = encodedCiphertext;
518
+ frame.codec = "b64";
519
+ if (envelope.sec) {
520
+ envelope.sec.enc = encryptionHeader;
521
+ }
522
+ else {
523
+ envelope.sec = { enc: encryptionHeader };
524
+ }
525
+ return EncryptionResult.ok(envelope);
526
+ }
527
+ serializePayload(payload) {
528
+ if (payload === null || typeof payload === "undefined") {
529
+ return null;
530
+ }
531
+ if (payload instanceof Uint8Array) {
532
+ return payload;
533
+ }
534
+ if (typeof ArrayBuffer !== "undefined") {
535
+ if (payload instanceof ArrayBuffer || ArrayBuffer.isView(payload)) {
536
+ return toUint8Array(payload);
537
+ }
538
+ }
539
+ if (typeof payload === "string") {
540
+ return new TextEncoder().encode(payload);
541
+ }
542
+ if (typeof payload === "number" || typeof payload === "boolean") {
543
+ return new TextEncoder().encode(JSON.stringify(payload));
544
+ }
545
+ const serializable = makeJsonSerializable(payload);
546
+ return new TextEncoder().encode(JSON.stringify(serializable));
547
+ }
548
+ extractCiphertext(payload) {
549
+ if (payload instanceof Uint8Array) {
550
+ return payload;
551
+ }
552
+ if (typeof payload === "string") {
553
+ try {
554
+ return decodeBase64(payload);
555
+ }
556
+ catch (error) {
557
+ logger.error("failed_to_decode_base64_ciphertext", {
558
+ error: error instanceof Error ? error.message : String(error),
559
+ });
560
+ return null;
561
+ }
562
+ }
563
+ if (payload instanceof ArrayBuffer ||
564
+ ArrayBuffer.isView(payload)) {
565
+ return toUint8Array(payload);
566
+ }
567
+ return null;
568
+ }
569
+ deserializePayload(bytes) {
570
+ const decoder = new TextDecoder();
571
+ const decoded = decoder.decode(bytes);
572
+ try {
573
+ return JSON.parse(decoded);
574
+ }
575
+ catch {
576
+ return decoded;
577
+ }
578
+ }
579
+ extractDestinationFromChannelId(channelId) {
580
+ const parts = channelId.split("-");
581
+ if (parts.length < 3) {
582
+ return null;
583
+ }
584
+ return parts.slice(1, -1).join("-");
585
+ }
586
+ async handleFailedEnvelope(envelope, destinationStr, channelId, reason) {
587
+ logger.warning("envelope_failed_due_to_channel_handshake_failure", {
588
+ envelope_id: envelope.id,
589
+ destination: destinationStr,
590
+ channel_id: channelId,
591
+ reason,
592
+ });
593
+ const frame = envelope.frame;
594
+ if (!this.isDataFrame(frame)) {
595
+ logger.debug("skipping_nack_for_non_dataframe", {
596
+ envelope_id: envelope.id,
597
+ frame_type: frame.type ?? typeof frame,
598
+ });
599
+ return;
600
+ }
601
+ if (!envelope.replyTo) {
602
+ logger.debug("skipping_nack_no_reply_to", { envelope_id: envelope.id });
603
+ return;
604
+ }
605
+ await this.sendDeliveryNack(envelope, `channel_handshake_failed: ${reason}`);
606
+ }
607
+ async sendDeliveryNack(envelope, failureReason) {
608
+ const node = this.nodeLike;
609
+ if (!node) {
610
+ logger.error("no_node_available_for_sending_delivery_nack");
611
+ return;
612
+ }
613
+ const envelopeFactory = node.envelopeFactory;
614
+ if (!envelopeFactory) {
615
+ logger.error("no_envelope_factory_available_for_delivery_nack");
616
+ return;
617
+ }
618
+ const replyTo = toFameAddress(envelope.replyTo ?? null);
619
+ if (!replyTo) {
620
+ logger.error("invalid_reply_to_for_delivery_nack", {
621
+ reply_to: envelope.replyTo,
622
+ });
623
+ return;
624
+ }
625
+ const nackFrame = {
626
+ type: "DeliveryAck",
627
+ ok: false,
628
+ code: "channel_handshake_failed",
629
+ reason: failureReason,
630
+ };
631
+ const nackEnvelope = envelopeFactory.createEnvelope({
632
+ to: replyTo,
633
+ frame: nackFrame,
634
+ corrId: envelope.corrId ?? generateId(),
635
+ });
636
+ await this.deliverEnvelope(nackEnvelope);
637
+ logger.debug("delivered_delivery_nack", {
638
+ original_envelope_id: envelope.id,
639
+ nack_envelope_id: nackEnvelope.id,
640
+ });
641
+ }
642
+ getChannelState(channelId) {
643
+ if (!this.secureChannelManager) {
644
+ return null;
645
+ }
646
+ const channelState = this.secureChannelManager.channels[channelId];
647
+ return channelState ?? null;
648
+ }
649
+ buildSystemReplyTo() {
650
+ const node = this.nodeLike;
651
+ if (!node) {
652
+ return null;
653
+ }
654
+ const physicalPath = node.physicalPath ?? "";
655
+ if (!physicalPath) {
656
+ return null;
657
+ }
658
+ return formatAddress(SYSTEM_INBOX, physicalPath);
659
+ }
660
+ generateChannelId(destinationStr) {
661
+ return `auto-${destinationStr}-${generateId()}`;
662
+ }
663
+ runAsyncTask(task, name) {
664
+ if (this.taskSpawner) {
665
+ this.taskSpawner.spawn(async () => {
666
+ await task();
667
+ }, { name });
668
+ return;
669
+ }
670
+ (async () => {
671
+ try {
672
+ await task();
673
+ }
674
+ catch (error) {
675
+ logger.error("async_task_failed", {
676
+ task_name: name,
677
+ error: error instanceof Error ? error.message : String(error),
678
+ });
679
+ }
680
+ })().catch(() => {
681
+ // Swallow to avoid unhandled rejection; error already logged above.
682
+ });
683
+ }
684
+ decodeNonceValue(value) {
685
+ if (!value) {
686
+ return null;
687
+ }
688
+ const hexCandidate = value.trim();
689
+ if (hexCandidate.length % 2 === 0 && /^[0-9a-fA-F]+$/.test(hexCandidate)) {
690
+ const bytes = new Uint8Array(hexCandidate.length / 2);
691
+ for (let i = 0; i < hexCandidate.length; i += 2) {
692
+ bytes[i / 2] = parseInt(hexCandidate.slice(i, i + 2), 16);
693
+ }
694
+ if (bytes.length > 0) {
695
+ return bytes;
696
+ }
697
+ }
698
+ const base64Candidates = [
699
+ value,
700
+ value.replace(/-/g, "+").replace(/_/g, "/"),
701
+ ];
702
+ for (const candidate of base64Candidates) {
703
+ try {
704
+ // Standard base64 decode first (Buffer), then urlsafe fallback
705
+ if (typeof Buffer !== "undefined") {
706
+ const decoded = Uint8Array.from(Buffer.from(candidate, "base64"));
707
+ if (decoded.length > 0) {
708
+ return decoded;
709
+ }
710
+ }
711
+ }
712
+ catch {
713
+ // ignore and try next
714
+ }
715
+ try {
716
+ const decoded = urlsafeBase64Decode(candidate);
717
+ if (decoded.length > 0) {
718
+ return decoded;
719
+ }
720
+ }
721
+ catch {
722
+ // ignore and continue
723
+ }
724
+ }
725
+ return null;
726
+ }
727
+ }
728
+ //# sourceMappingURL=channel-encryption-manager.js.map