@floegence/flowersec-core 5.11.0 → 6.1.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 (716) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +170 -58
  3. package/THIRD_PARTY_NOTICES.md +3072 -7
  4. package/dist/application/rpcJSON.d.ts +15 -0
  5. package/dist/{rpc/validate.js → application/rpcJSON.js} +1 -1
  6. package/dist/browser/clientV4.d.ts +61 -0
  7. package/dist/browser/clientV4.js +179 -0
  8. package/dist/browser/index.d.ts +15 -8
  9. package/dist/browser/index.js +5 -3
  10. package/dist/browser/indexedDBPoolV4.d.ts +101 -0
  11. package/dist/browser/indexedDBPoolV4.js +634 -0
  12. package/dist/browser/liveHTTPSV4.d.ts +35 -0
  13. package/dist/browser/liveHTTPSV4.js +162 -0
  14. package/dist/browser/localBrowserBridge.d.ts +20 -0
  15. package/dist/browser/localBrowserBridge.js +82 -0
  16. package/dist/browser/poolServerAllow.d.ts +21 -0
  17. package/dist/browser/poolServerAllow.js +151 -0
  18. package/dist/browser/webTransportPositionsV4.d.ts +16 -0
  19. package/dist/browser/webTransportPositionsV4.js +75 -0
  20. package/dist/browser/webTransportStreamV4.d.ts +36 -0
  21. package/dist/browser/webTransportStreamV4.js +370 -0
  22. package/dist/browser/webTransportV4.d.ts +126 -0
  23. package/dist/browser/webTransportV4.js +627 -0
  24. package/dist/browser/wssV4.d.ts +69 -0
  25. package/dist/browser/wssV4.js +339 -0
  26. package/dist/cli.d.ts +24 -1
  27. package/dist/cli.js +91 -119
  28. package/dist/defaults.d.ts +1 -23
  29. package/dist/defaults.js +1 -23
  30. package/dist/facade.d.ts +104 -21
  31. package/dist/facade.js +45 -8
  32. package/dist/generated/brotliWorker.d.ts +1 -0
  33. package/dist/generated/brotliWorker.js +3 -0
  34. package/dist/generated/idna151.d.ts +2 -0
  35. package/dist/generated/idna151.js +38 -0
  36. package/dist/generated/normalization151.d.ts +5 -0
  37. package/dist/generated/normalization151.js +878 -0
  38. package/dist/generated/sqliteWorkers.d.ts +2 -0
  39. package/dist/generated/sqliteWorkers.js +3 -0
  40. package/dist/generated/transportV4APIResults.d.ts +21 -1
  41. package/dist/generated/transportV4APIResults.js +42 -1
  42. package/dist/generated/transportV4Registry.d.ts +276 -2
  43. package/dist/generated/transportV4Registry.js +10 -4
  44. package/dist/interop/browserRunner.d.ts +72 -0
  45. package/dist/interop/browserRunner.js +354 -0
  46. package/dist/interop/currentClock.d.ts +3 -0
  47. package/dist/interop/currentClock.js +39 -0
  48. package/dist/interop/currentContracts.d.ts +6 -0
  49. package/dist/interop/currentContracts.js +14 -0
  50. package/dist/interop/currentNativeTunnel.d.ts +31 -0
  51. package/dist/interop/currentNativeTunnel.js +185 -0
  52. package/dist/interop/currentParity.d.ts +68 -0
  53. package/dist/interop/currentParity.js +392 -0
  54. package/dist/interop/currentPeer.d.ts +252 -0
  55. package/dist/interop/currentPeer.js +677 -0
  56. package/dist/interop/currentRegisteredTunnelPeer.d.ts +37 -0
  57. package/dist/interop/currentRegisteredTunnelPeer.js +93 -0
  58. package/dist/interop/currentRelayPeer.d.ts +131 -0
  59. package/dist/interop/currentRelayPeer.js +263 -0
  60. package/dist/interop/currentServer.d.ts +44 -0
  61. package/dist/interop/currentServer.js +299 -0
  62. package/dist/interop/currentTLSPin.d.ts +9 -0
  63. package/dist/interop/currentTLSPin.js +44 -0
  64. package/dist/interop/currentTunnelMaterial.d.ts +34 -0
  65. package/dist/interop/currentTunnelMaterial.js +100 -0
  66. package/dist/interop/httpApplicationPeer.d.ts +15 -0
  67. package/dist/interop/httpApplicationPeer.js +167 -0
  68. package/dist/interop/invalidProofPeer.d.ts +8 -0
  69. package/dist/interop/invalidProofPeer.js +106 -0
  70. package/dist/interop/proxyServerPeer.js +8 -56
  71. package/dist/interop/serverParityPeer.d.ts +101 -1
  72. package/dist/interop/serverParityPeer.js +550 -578
  73. package/dist/node/acceptorCurrent.d.ts +55 -0
  74. package/dist/node/acceptorCurrent.js +286 -0
  75. package/dist/node/admissionRecord.d.ts +23 -0
  76. package/dist/node/admissionRecord.js +178 -0
  77. package/dist/node/clientV4.d.ts +59 -0
  78. package/dist/node/clientV4.js +197 -0
  79. package/dist/node/connectionPath.d.ts +2 -0
  80. package/dist/node/connectionPath.js +18 -0
  81. package/dist/node/endpointDialer.d.ts +70 -0
  82. package/dist/node/endpointDialer.js +231 -0
  83. package/dist/node/endpointListener.d.ts +48 -0
  84. package/dist/node/endpointListener.js +403 -0
  85. package/dist/node/endpointTransport.d.ts +7 -0
  86. package/dist/node/endpointTransport.js +18 -0
  87. package/dist/node/grantIssuerCurrent.d.ts +64 -0
  88. package/dist/node/grantIssuerCurrent.js +355 -0
  89. package/dist/node/index.d.ts +52 -16
  90. package/dist/node/index.js +24 -6
  91. package/dist/node/liveHTTPSV4.d.ts +28 -0
  92. package/dist/node/liveHTTPSV4.js +298 -0
  93. package/dist/node/liveTunnelAuthorityCurrent.d.ts +153 -0
  94. package/dist/node/liveTunnelAuthorityCurrent.js +590 -0
  95. package/dist/node/nativeDuplexBridgeV4.d.ts +41 -0
  96. package/dist/node/nativeDuplexBridgeV4.js +494 -0
  97. package/dist/node/nativeTransportCurrent.d.ts +196 -0
  98. package/dist/node/nativeTransportCurrent.js +37 -0
  99. package/dist/node/poolServerAllow.d.ts +33 -0
  100. package/dist/node/poolServerAllow.js +277 -0
  101. package/dist/node/proxyCredentials.d.ts +67 -0
  102. package/dist/node/proxyCredentials.js +364 -0
  103. package/dist/node/proxyNetwork.d.ts +18 -0
  104. package/dist/node/proxyNetwork.js +213 -0
  105. package/dist/node/proxyServer.d.ts +30 -4
  106. package/dist/node/proxyServer.js +599 -154
  107. package/dist/node/rawQUICCurrent.d.ts +139 -0
  108. package/dist/node/rawQUICCurrent.js +1177 -0
  109. package/dist/node/registeredLiveTunnelControl.d.ts +74 -0
  110. package/dist/node/registeredLiveTunnelControl.js +865 -0
  111. package/dist/node/registeredPoolTunnelAuthority.d.ts +50 -0
  112. package/dist/node/registeredPoolTunnelAuthority.js +305 -0
  113. package/dist/node/registeredTunnelControl.d.ts +189 -0
  114. package/dist/node/registeredTunnelControl.js +1007 -0
  115. package/dist/node/registeredWinnerContinuation.d.ts +26 -0
  116. package/dist/node/registeredWinnerContinuation.js +83 -0
  117. package/dist/node/relayNativePair.d.ts +62 -0
  118. package/dist/node/relayNativePair.js +737 -0
  119. package/dist/node/relayRecord.d.ts +57 -0
  120. package/dist/node/relayRecord.js +275 -0
  121. package/dist/node/serveRawQUIC.d.ts +58 -0
  122. package/dist/node/serveRawQUIC.js +331 -0
  123. package/dist/node/serveWSS.d.ts +58 -0
  124. package/dist/node/serveWSS.js +309 -0
  125. package/dist/node/sqliteAdmission.d.ts +100 -0
  126. package/dist/node/sqliteAdmission.js +1185 -0
  127. package/dist/node/sqliteExecutionContentV4.d.ts +63 -0
  128. package/dist/node/sqliteExecutionContentV4.js +251 -0
  129. package/dist/node/sqliteExecutionV4.d.ts +114 -0
  130. package/dist/node/sqliteExecutionV4.js +1052 -0
  131. package/dist/node/sqliteFormat.d.ts +20 -0
  132. package/dist/node/sqliteFormat.js +72 -0
  133. package/dist/node/sqliteInspectionV4.d.ts +7 -0
  134. package/dist/node/sqliteInspectionV4.js +47 -0
  135. package/dist/node/sqliteNativeV4.d.ts +3 -0
  136. package/dist/node/sqliteNativeV4.js +16 -0
  137. package/dist/node/sqlitePoolV4.d.ts +41 -0
  138. package/dist/node/sqlitePoolV4.js +282 -0
  139. package/dist/node/sqlitePoolWorkerProgramV4.js +411 -0
  140. package/dist/node/sqlitePoolWorkerV4.d.ts +67 -0
  141. package/dist/node/sqlitePoolWorkerV4.js +206 -0
  142. package/dist/node/sqliteV4.d.ts +82 -0
  143. package/dist/node/sqliteV4.js +166 -0
  144. package/dist/node/sqliteWorkerProgramV4.js +175 -0
  145. package/dist/node/sqliteWorkerV4.d.ts +47 -0
  146. package/dist/node/sqliteWorkerV4.js +142 -0
  147. package/dist/node/streamDuplexV4.d.ts +33 -0
  148. package/dist/node/streamDuplexV4.js +359 -0
  149. package/dist/node/tunnelListenerPreparation.d.ts +37 -0
  150. package/dist/node/tunnelListenerPreparation.js +162 -0
  151. package/dist/node/tunnelRuntime.d.ts +124 -0
  152. package/dist/node/tunnelRuntime.js +1205 -0
  153. package/dist/node/webTransportCurrent.d.ts +24 -0
  154. package/dist/node/webTransportCurrent.js +12 -0
  155. package/dist/node/wssV4.d.ts +99 -0
  156. package/dist/node/wssV4.js +846 -0
  157. package/dist/proxy/admission.d.ts +21 -0
  158. package/dist/proxy/admission.js +126 -0
  159. package/dist/proxy/brotliBody.d.ts +10 -0
  160. package/dist/proxy/brotliBody.js +85 -0
  161. package/dist/proxy/credentialControl.d.ts +30 -0
  162. package/dist/proxy/credentialControl.js +86 -0
  163. package/dist/proxy/currentStream.d.ts +24 -0
  164. package/dist/proxy/currentStream.js +158 -0
  165. package/dist/proxy/fetch.d.ts +3 -2
  166. package/dist/proxy/fetch.js +96 -29
  167. package/dist/proxy/headers.d.ts +8 -0
  168. package/dist/proxy/headers.js +63 -0
  169. package/dist/proxy/index.d.ts +4 -0
  170. package/dist/proxy/index.js +2 -0
  171. package/dist/proxy/integration.d.ts +12 -8
  172. package/dist/proxy/integration.js +23 -16
  173. package/dist/proxy/policy.d.ts +5 -0
  174. package/dist/proxy/policy.js +60 -22
  175. package/dist/proxy/publicationOwner.d.ts +10 -0
  176. package/dist/proxy/publicationOwner.js +130 -0
  177. package/dist/proxy/requestAssociation.d.ts +11 -0
  178. package/dist/proxy/requestAssociation.js +8 -0
  179. package/dist/proxy/runtime.d.ts +3 -1
  180. package/dist/proxy/runtime.js +403 -170
  181. package/dist/proxy/scope.js +2 -2
  182. package/dist/proxy/serviceWorker.d.ts +3 -0
  183. package/dist/proxy/serviceWorker.js +634 -176
  184. package/dist/proxy/serviceWorkerRuntime.js +26 -1
  185. package/dist/proxy/stream.d.ts +16 -3
  186. package/dist/proxy/stream.js +6 -0
  187. package/dist/proxy/surface.d.ts +45 -0
  188. package/dist/proxy/surface.js +384 -0
  189. package/dist/proxy/types.d.ts +49 -6
  190. package/dist/proxy/windowBridge.d.ts +11 -3
  191. package/dist/proxy/windowBridge.js +62 -19
  192. package/dist/proxy/wire.d.ts +11 -0
  193. package/dist/proxy/wire.js +214 -0
  194. package/dist/proxy/wsPatch.js +13 -6
  195. package/dist/public/contract.d.ts +0 -71
  196. package/dist/public/contract.js +0 -8
  197. package/dist/public/streamKind.d.ts +3 -0
  198. package/dist/public/streamKind.js +19 -0
  199. package/dist/public/streamMetadata.d.ts +34 -2
  200. package/dist/public/streamMetadata.js +206 -13
  201. package/dist/v4/admissionOffer.d.ts +8 -0
  202. package/dist/v4/checkpoint.d.ts +23 -0
  203. package/dist/v4/checkpoint.js +16 -0
  204. package/dist/v4/clientServices.d.ts +35 -0
  205. package/dist/v4/clientServices.js +11 -0
  206. package/dist/v4/connectionDiagnostic.d.ts +42 -0
  207. package/dist/v4/connectionDiagnostic.js +45 -0
  208. package/dist/v4/connectionRequirements.d.ts +5 -0
  209. package/dist/v4/connectionRequirements.js +34 -0
  210. package/dist/v4/controller.d.ts +122 -0
  211. package/dist/v4/controller.js +1161 -0
  212. package/dist/v4/controllerNotifications.d.ts +81 -0
  213. package/dist/v4/controllerNotifications.js +610 -0
  214. package/dist/v4/diagnostics.d.ts +44 -0
  215. package/dist/v4/diagnostics.js +9 -0
  216. package/dist/v4/drain.d.ts +39 -0
  217. package/dist/v4/drain.js +80 -0
  218. package/dist/v4/duplexBridge.d.ts +53 -0
  219. package/dist/v4/duplexBridge.js +446 -0
  220. package/dist/v4/entrypoints.d.ts +20 -0
  221. package/dist/v4/entrypoints.js +50 -0
  222. package/dist/v4/eventSource.d.ts +34 -0
  223. package/dist/v4/eventSource.js +28 -0
  224. package/dist/v4/handlerPlan.d.ts +53 -0
  225. package/dist/v4/handlerPlan.js +129 -0
  226. package/dist/v4/liveness.d.ts +20 -0
  227. package/dist/v4/liveness.js +10 -0
  228. package/dist/v4/localReport.d.ts +17 -0
  229. package/dist/v4/localReport.js +10 -0
  230. package/dist/v4/messageDefinition.d.ts +66 -0
  231. package/dist/v4/messageDefinition.js +109 -0
  232. package/dist/v4/messageStream.d.ts +89 -0
  233. package/dist/v4/messageStream.js +1375 -0
  234. package/dist/v4/notificationOperation.d.ts +30 -0
  235. package/dist/v4/notificationOperation.js +31 -0
  236. package/dist/v4/notificationSubscription.d.ts +47 -0
  237. package/dist/v4/notificationSubscription.js +24 -0
  238. package/dist/v4/operationReference.d.ts +28 -0
  239. package/dist/v4/operationReference.js +61 -0
  240. package/dist/v4/operationReferenceCodec.d.ts +20 -0
  241. package/dist/v4/operationReferenceCodec.js +129 -0
  242. package/dist/v4/operationReferenceStore.d.ts +90 -0
  243. package/dist/v4/operationReferenceStore.js +272 -0
  244. package/dist/v4/operationResultRead.d.ts +26 -0
  245. package/dist/v4/operationResultRead.js +24 -0
  246. package/dist/v4/poolControl.d.ts +11 -0
  247. package/dist/v4/poolControl.js +50 -0
  248. package/dist/v4/poolSource.d.ts +93 -0
  249. package/dist/v4/poolSource.js +900 -0
  250. package/dist/v4/public.d.ts +232 -0
  251. package/dist/v4/public.js +632 -0
  252. package/dist/v4/responsePublication.d.ts +48 -0
  253. package/dist/v4/responsePublication.js +227 -0
  254. package/dist/v4/resume.d.ts +17 -0
  255. package/dist/v4/resume.js +15 -0
  256. package/dist/v4/runtime/applicationExecutor.d.ts +190 -0
  257. package/dist/v4/runtime/applicationExecutor.js +759 -0
  258. package/dist/v4/runtime/applicationHeader.d.ts +61 -0
  259. package/dist/v4/runtime/applicationHeader.js +222 -0
  260. package/dist/v4/runtime/canonicalText.d.ts +8 -0
  261. package/dist/v4/runtime/canonicalText.js +142 -0
  262. package/dist/v4/runtime/cbor.d.ts +92 -0
  263. package/dist/v4/runtime/cbor.js +728 -0
  264. package/dist/v4/runtime/cborWriter.d.ts +18 -0
  265. package/dist/v4/runtime/cborWriter.js +59 -0
  266. package/dist/v4/runtime/checkpointToken.d.ts +41 -0
  267. package/dist/v4/runtime/checkpointToken.js +61 -0
  268. package/dist/v4/runtime/clientAdmission.d.ts +40 -0
  269. package/dist/v4/runtime/clientAdmission.js +378 -0
  270. package/dist/v4/runtime/clientSessionSpec.d.ts +45 -0
  271. package/dist/v4/runtime/clientSessionSpec.js +91 -0
  272. package/dist/v4/runtime/clock.d.ts +80 -0
  273. package/dist/v4/runtime/clock.js +284 -0
  274. package/dist/v4/runtime/connectionFacts.d.ts +23 -0
  275. package/dist/v4/runtime/connectionFacts.js +106 -0
  276. package/dist/v4/runtime/contractAcceptance.d.ts +20 -0
  277. package/dist/v4/runtime/contractAcceptance.js +91 -0
  278. package/dist/v4/runtime/contractQuery.d.ts +57 -0
  279. package/dist/v4/runtime/contractQuery.js +265 -0
  280. package/dist/v4/runtime/contractQueryAccess.d.ts +25 -0
  281. package/dist/v4/runtime/contractQueryAccess.js +117 -0
  282. package/dist/v4/runtime/contractQueryAcquisition.d.ts +83 -0
  283. package/dist/v4/runtime/contractQueryAcquisition.js +572 -0
  284. package/dist/v4/runtime/contractQueryClient.d.ts +70 -0
  285. package/dist/v4/runtime/contractQueryClient.js +411 -0
  286. package/dist/v4/runtime/contractQueryCodecs.d.ts +20 -0
  287. package/dist/v4/runtime/contractQueryCodecs.js +71 -0
  288. package/dist/v4/runtime/contractQueryExchange.d.ts +36 -0
  289. package/dist/v4/runtime/contractQueryExchange.js +160 -0
  290. package/dist/v4/runtime/contractQueryService.d.ts +42 -0
  291. package/dist/v4/runtime/contractQueryService.js +572 -0
  292. package/dist/v4/runtime/contractQuerySession.d.ts +38 -0
  293. package/dist/v4/runtime/contractQuerySession.js +158 -0
  294. package/dist/v4/runtime/contractRoutes.d.ts +87 -0
  295. package/dist/v4/runtime/contractRoutes.js +396 -0
  296. package/dist/v4/runtime/contractSnapshotReader.d.ts +59 -0
  297. package/dist/v4/runtime/contractSnapshotReader.js +418 -0
  298. package/dist/v4/runtime/contractSnapshotWriter.d.ts +32 -0
  299. package/dist/v4/runtime/contractSnapshotWriter.js +208 -0
  300. package/dist/v4/runtime/controllerServiceSource.d.ts +23 -0
  301. package/dist/v4/runtime/controllerServiceSource.js +109 -0
  302. package/dist/v4/runtime/controllerUnaryRoute.d.ts +28 -0
  303. package/dist/v4/runtime/credentialNamespace.d.ts +143 -0
  304. package/dist/v4/runtime/credentialNamespace.js +1286 -0
  305. package/dist/v4/runtime/credentialSupport.d.ts +60 -0
  306. package/dist/v4/runtime/credentialSupport.js +294 -0
  307. package/dist/v4/runtime/credentialVerifier.d.ts +404 -0
  308. package/dist/v4/runtime/credentialVerifier.js +1443 -0
  309. package/dist/v4/runtime/cryptoUsage.d.ts +135 -0
  310. package/dist/v4/runtime/cryptoUsage.js +552 -0
  311. package/dist/v4/runtime/deadline.d.ts +31 -0
  312. package/dist/v4/runtime/deadline.js +188 -0
  313. package/dist/v4/runtime/diagnosticCounters.d.ts +15 -0
  314. package/dist/v4/runtime/diagnosticCounters.js +78 -0
  315. package/dist/v4/runtime/diagnosticObservation.d.ts +25 -0
  316. package/dist/v4/runtime/diagnosticObservation.js +67 -0
  317. package/dist/v4/runtime/diagnosticSink.d.ts +16 -0
  318. package/dist/v4/runtime/diagnosticSink.js +320 -0
  319. package/dist/v4/runtime/ed25519.d.ts +1 -0
  320. package/dist/v4/runtime/ed25519.js +34 -0
  321. package/dist/v4/runtime/endpointHop.d.ts +12 -0
  322. package/dist/v4/runtime/endpointHop.js +26 -0
  323. package/dist/v4/runtime/envelope.d.ts +66 -0
  324. package/dist/v4/runtime/envelope.js +275 -0
  325. package/dist/v4/runtime/environment.d.ts +277 -0
  326. package/dist/v4/runtime/environment.js +1913 -0
  327. package/dist/v4/runtime/executionManagementChannel.d.ts +27 -0
  328. package/dist/v4/runtime/executionManagementChannel.js +733 -0
  329. package/dist/v4/runtime/executionManagementCodec.d.ts +84 -0
  330. package/dist/v4/runtime/executionManagementCodec.js +127 -0
  331. package/dist/v4/runtime/executionStorage.d.ts +71 -0
  332. package/dist/v4/runtime/executionStorage.js +10 -0
  333. package/dist/v4/runtime/fixedDiagnosticExecutor.d.ts +34 -0
  334. package/dist/v4/runtime/fixedDiagnosticExecutor.js +149 -0
  335. package/dist/v4/runtime/fixedManagementExecutor.d.ts +21 -0
  336. package/dist/v4/runtime/fixedManagementExecutor.js +153 -0
  337. package/dist/v4/runtime/fixedQueryExecutor.d.ts +46 -0
  338. package/dist/v4/runtime/fixedQueryExecutor.js +311 -0
  339. package/dist/v4/runtime/grantDigest.d.ts +9 -0
  340. package/dist/v4/runtime/grantDigest.js +31 -0
  341. package/dist/v4/runtime/hopAuthentication.d.ts +51 -0
  342. package/dist/v4/runtime/hopAuthentication.js +392 -0
  343. package/dist/v4/runtime/host.d.ts +15 -0
  344. package/dist/v4/runtime/host.js +332 -0
  345. package/dist/v4/runtime/initializerWorkload.d.ts +38 -0
  346. package/dist/v4/runtime/initializerWorkload.js +164 -0
  347. package/dist/v4/runtime/lifecycle.d.ts +5 -0
  348. package/dist/v4/runtime/lifecycle.js +17 -0
  349. package/dist/v4/runtime/liveAuthorization.d.ts +42 -0
  350. package/dist/v4/runtime/liveAuthorization.js +133 -0
  351. package/dist/v4/runtime/liveAuthorizationWire.d.ts +8 -0
  352. package/dist/v4/runtime/liveAuthorizationWire.js +31 -0
  353. package/dist/v4/runtime/liveCarrierPreparation.d.ts +9 -0
  354. package/dist/v4/runtime/liveCarrierPreparation.js +27 -0
  355. package/dist/v4/runtime/liveness.d.ts +37 -0
  356. package/dist/v4/runtime/liveness.js +319 -0
  357. package/dist/v4/runtime/maintenancePositions.d.ts +29 -0
  358. package/dist/v4/runtime/maintenancePositions.js +152 -0
  359. package/dist/v4/runtime/messageCodec.d.ts +20 -0
  360. package/dist/v4/runtime/messageCodec.js +192 -0
  361. package/dist/v4/runtime/namespaceContinuity.d.ts +20 -0
  362. package/dist/v4/runtime/namespaceContinuity.js +176 -0
  363. package/dist/v4/runtime/nativeCandidates.d.ts +18 -0
  364. package/dist/v4/runtime/nativeCandidates.js +109 -0
  365. package/dist/v4/runtime/nativeFailure.d.ts +10 -0
  366. package/dist/v4/runtime/nativeFailure.js +32 -0
  367. package/dist/v4/runtime/nativeFrame.d.ts +47 -0
  368. package/dist/v4/runtime/nativeFrame.js +318 -0
  369. package/dist/v4/runtime/nativeIngress.d.ts +30 -0
  370. package/dist/v4/runtime/nativeIngress.js +177 -0
  371. package/dist/v4/runtime/nativePositions.d.ts +24 -0
  372. package/dist/v4/runtime/nativePositions.js +131 -0
  373. package/dist/v4/runtime/nativeProviderPositions.d.ts +16 -0
  374. package/dist/v4/runtime/nativeProviderPositions.js +75 -0
  375. package/dist/v4/runtime/nativeSend.d.ts +15 -0
  376. package/dist/v4/runtime/nativeSend.js +57 -0
  377. package/dist/v4/runtime/noiseHandshake.d.ts +70 -0
  378. package/dist/v4/runtime/noiseHandshake.js +373 -0
  379. package/dist/v4/runtime/noiseWasmBinary.d.ts +2 -0
  380. package/dist/v4/runtime/noiseWasmBinary.js +3 -0
  381. package/dist/v4/runtime/notifyChannel.d.ts +37 -0
  382. package/dist/v4/runtime/notifyChannel.js +277 -0
  383. package/dist/v4/runtime/notifyDispatch.d.ts +108 -0
  384. package/dist/v4/runtime/notifyDispatch.js +717 -0
  385. package/dist/v4/runtime/notifyExecution.d.ts +18 -0
  386. package/dist/v4/runtime/notifyExecution.js +59 -0
  387. package/dist/v4/runtime/notifyPreparation.d.ts +70 -0
  388. package/dist/v4/runtime/notifyPreparation.js +465 -0
  389. package/dist/v4/runtime/openAdmission.d.ts +125 -0
  390. package/dist/v4/runtime/openAdmission.js +810 -0
  391. package/dist/v4/runtime/peerOpenPreparation.d.ts +18 -0
  392. package/dist/v4/runtime/peerOpenPreparation.js +61 -0
  393. package/dist/v4/runtime/poolJournal.d.ts +18 -0
  394. package/dist/v4/runtime/poolJournal.js +14 -0
  395. package/dist/v4/runtime/poolJournalStorage.d.ts +4 -0
  396. package/dist/v4/runtime/poolJournalStorage.js +172 -0
  397. package/dist/v4/runtime/poolRecord.d.ts +9 -0
  398. package/dist/v4/runtime/poolRecord.js +23 -0
  399. package/dist/v4/runtime/poolRecordStorage.d.ts +10 -0
  400. package/dist/v4/runtime/poolRecordStorage.js +216 -0
  401. package/dist/v4/runtime/poolServerAllow.d.ts +49 -0
  402. package/dist/v4/runtime/poolServerAllow.js +38 -0
  403. package/dist/v4/runtime/poolSpend.d.ts +20 -0
  404. package/dist/v4/runtime/poolSpend.js +4 -0
  405. package/dist/v4/runtime/queryRenewalPosition.d.ts +59 -0
  406. package/dist/v4/runtime/queryRenewalPosition.js +220 -0
  407. package/dist/v4/runtime/random.d.ts +15 -0
  408. package/dist/v4/runtime/random.js +71 -0
  409. package/dist/v4/runtime/rawStreamPreparation.d.ts +40 -0
  410. package/dist/v4/runtime/rawStreamPreparation.js +125 -0
  411. package/dist/v4/runtime/receiveDirection.d.ts +135 -0
  412. package/dist/v4/runtime/receiveDirection.js +957 -0
  413. package/dist/v4/runtime/receiveWorkspace.d.ts +19 -0
  414. package/dist/v4/runtime/receiveWorkspace.js +82 -0
  415. package/dist/v4/runtime/record.d.ts +7 -0
  416. package/dist/v4/runtime/record.js +173 -0
  417. package/dist/v4/runtime/recordCrypto.d.ts +121 -0
  418. package/dist/v4/runtime/recordCrypto.js +633 -0
  419. package/dist/v4/runtime/recordWorkspace.d.ts +17 -0
  420. package/dist/v4/runtime/recordWorkspace.js +69 -0
  421. package/dist/v4/runtime/registeredCarrierPreparation.d.ts +17 -0
  422. package/dist/v4/runtime/registeredCarrierPreparation.js +191 -0
  423. package/dist/v4/runtime/rekey.d.ts +40 -0
  424. package/dist/v4/runtime/rekey.js +362 -0
  425. package/dist/v4/runtime/relayCredentials.d.ts +126 -0
  426. package/dist/v4/runtime/relayCredentials.js +349 -0
  427. package/dist/v4/runtime/replayWindow.d.ts +6 -0
  428. package/dist/v4/runtime/replayWindow.js +59 -0
  429. package/dist/v4/runtime/resources.d.ts +200 -0
  430. package/dist/v4/runtime/resources.js +1236 -0
  431. package/dist/v4/runtime/resumeCodec.d.ts +44 -0
  432. package/dist/v4/runtime/resumeCodec.js +192 -0
  433. package/dist/v4/runtime/resumeStream.d.ts +23 -0
  434. package/dist/v4/runtime/resumeStream.js +23 -0
  435. package/dist/v4/runtime/rpcApplication.d.ts +234 -0
  436. package/dist/v4/runtime/rpcApplication.js +2170 -0
  437. package/dist/v4/runtime/rpcApplicationServices.d.ts +18 -0
  438. package/dist/v4/runtime/rpcApplicationServices.js +62 -0
  439. package/dist/v4/runtime/rpcCallCapacity.d.ts +62 -0
  440. package/dist/v4/runtime/rpcCallCapacity.js +289 -0
  441. package/dist/v4/runtime/rpcChannel.d.ts +58 -0
  442. package/dist/v4/runtime/rpcChannel.js +334 -0
  443. package/dist/v4/runtime/rpcCompletion.d.ts +42 -0
  444. package/dist/v4/runtime/rpcCompletion.js +152 -0
  445. package/dist/v4/runtime/rpcEventSource.d.ts +27 -0
  446. package/dist/v4/runtime/rpcEventSource.js +201 -0
  447. package/dist/v4/runtime/rpcFragment.d.ts +42 -0
  448. package/dist/v4/runtime/rpcFragment.js +227 -0
  449. package/dist/v4/runtime/rpcInput.d.ts +41 -0
  450. package/dist/v4/runtime/rpcInput.js +137 -0
  451. package/dist/v4/runtime/rpcNetwork.d.ts +143 -0
  452. package/dist/v4/runtime/rpcNetwork.js +652 -0
  453. package/dist/v4/runtime/rpcOutputInterest.d.ts +20 -0
  454. package/dist/v4/runtime/rpcOutputInterest.js +106 -0
  455. package/dist/v4/runtime/rpcPayload.d.ts +24 -0
  456. package/dist/v4/runtime/rpcPayload.js +82 -0
  457. package/dist/v4/runtime/rpcPreacceptedStreams.d.ts +46 -0
  458. package/dist/v4/runtime/rpcPreacceptedStreams.js +406 -0
  459. package/dist/v4/runtime/rpcPublisher.d.ts +49 -0
  460. package/dist/v4/runtime/rpcPublisher.js +406 -0
  461. package/dist/v4/runtime/rpcReceiver.d.ts +40 -0
  462. package/dist/v4/runtime/rpcReceiver.js +255 -0
  463. package/dist/v4/runtime/rpcResumeDispatch.d.ts +46 -0
  464. package/dist/v4/runtime/rpcResumeDispatch.js +266 -0
  465. package/dist/v4/runtime/rpcStream.d.ts +14 -0
  466. package/dist/v4/runtime/rpcStream.js +12 -0
  467. package/dist/v4/runtime/rpcStreamMessages.d.ts +53 -0
  468. package/dist/v4/runtime/rpcStreamMessages.js +428 -0
  469. package/dist/v4/runtime/rpcStreamPreparation.d.ts +21 -0
  470. package/dist/v4/runtime/rpcStreamPreparation.js +110 -0
  471. package/dist/v4/runtime/rpcStreamingDispatch.d.ts +26 -0
  472. package/dist/v4/runtime/rpcStreamingDispatch.js +607 -0
  473. package/dist/v4/runtime/rpcStreamingExchange.d.ts +91 -0
  474. package/dist/v4/runtime/rpcStreamingExchange.js +812 -0
  475. package/dist/v4/runtime/rpcUnaryCall.d.ts +16 -0
  476. package/dist/v4/runtime/rpcUnaryCall.js +152 -0
  477. package/dist/v4/runtime/rpcUnaryDispatch.d.ts +34 -0
  478. package/dist/v4/runtime/rpcUnaryDispatch.js +569 -0
  479. package/dist/v4/runtime/rpcUnaryExchange.d.ts +127 -0
  480. package/dist/v4/runtime/rpcUnaryExchange.js +1042 -0
  481. package/dist/v4/runtime/rpcUnaryPreparation.d.ts +102 -0
  482. package/dist/v4/runtime/rpcUnaryPreparation.js +736 -0
  483. package/dist/v4/runtime/rpcUnaryRegistration.d.ts +33 -0
  484. package/dist/v4/runtime/rpcUnaryRegistration.js +113 -0
  485. package/dist/v4/runtime/rpcUnaryResultRecipient.d.ts +21 -0
  486. package/dist/v4/runtime/rpcUnaryResultRecipient.js +57 -0
  487. package/dist/v4/runtime/schema.d.ts +26 -0
  488. package/dist/v4/runtime/schema.js +668 -0
  489. package/dist/v4/runtime/schemaRegistry.d.ts +128 -0
  490. package/dist/v4/runtime/schemaRegistry.js +74 -0
  491. package/dist/v4/runtime/sendBudget.d.ts +10 -0
  492. package/dist/v4/runtime/sendBudget.js +46 -0
  493. package/dist/v4/runtime/serveGroup.d.ts +73 -0
  494. package/dist/v4/runtime/serveGroup.js +589 -0
  495. package/dist/v4/runtime/serverAdmission.d.ts +33 -0
  496. package/dist/v4/runtime/serverAdmission.js +342 -0
  497. package/dist/v4/runtime/serverAdmissionAuthority.d.ts +23 -0
  498. package/dist/v4/runtime/serverAdmissionAuthority.js +5 -0
  499. package/dist/v4/runtime/serverSessionSpec.d.ts +9 -0
  500. package/dist/v4/runtime/serverSessionSpec.js +12 -0
  501. package/dist/v4/runtime/serviceBinding.d.ts +128 -0
  502. package/dist/v4/runtime/serviceBinding.js +1435 -0
  503. package/dist/v4/runtime/serviceBindingConfig.d.ts +72 -0
  504. package/dist/v4/runtime/serviceBindingConfig.js +85 -0
  505. package/dist/v4/runtime/serviceBindingPool.d.ts +58 -0
  506. package/dist/v4/runtime/serviceBindingPool.js +327 -0
  507. package/dist/v4/runtime/serviceContract.d.ts +111 -0
  508. package/dist/v4/runtime/serviceContract.js +588 -0
  509. package/dist/v4/runtime/serviceInputs.d.ts +30 -0
  510. package/dist/v4/runtime/serviceInputs.js +201 -0
  511. package/dist/v4/runtime/serviceOfferPlan.d.ts +81 -0
  512. package/dist/v4/runtime/serviceOfferPlan.js +335 -0
  513. package/dist/v4/runtime/serviceOfferScheduler.d.ts +12 -0
  514. package/dist/v4/runtime/serviceOfferScheduler.js +201 -0
  515. package/dist/v4/runtime/serviceOfferWork.d.ts +25 -0
  516. package/dist/v4/runtime/serviceOfferWork.js +1 -0
  517. package/dist/v4/runtime/session.d.ts +411 -0
  518. package/dist/v4/runtime/session.js +6369 -0
  519. package/dist/v4/runtime/sessionActivity.d.ts +19 -0
  520. package/dist/v4/runtime/sessionActivity.js +97 -0
  521. package/dist/v4/runtime/sessionAdmission.d.ts +93 -0
  522. package/dist/v4/runtime/sessionAdmission.js +498 -0
  523. package/dist/v4/runtime/sessionCleanup.d.ts +47 -0
  524. package/dist/v4/runtime/sessionCleanup.js +268 -0
  525. package/dist/v4/runtime/sessionKeyPreparation.d.ts +19 -0
  526. package/dist/v4/runtime/sessionKeyPreparation.js +50 -0
  527. package/dist/v4/runtime/signedMap.d.ts +68 -0
  528. package/dist/v4/runtime/signedMap.js +425 -0
  529. package/dist/v4/runtime/streamAdapter.d.ts +113 -0
  530. package/dist/v4/runtime/streamAdapter.js +62 -0
  531. package/dist/v4/runtime/streamData.d.ts +11 -0
  532. package/dist/v4/runtime/streamData.js +50 -0
  533. package/dist/v4/runtime/streamOpenPreparation.d.ts +23 -0
  534. package/dist/v4/runtime/streamOpenPreparation.js +77 -0
  535. package/dist/v4/runtime/streamRegistration.d.ts +87 -0
  536. package/dist/v4/runtime/streamRegistration.js +296 -0
  537. package/dist/v4/runtime/taskObservation.d.ts +1 -0
  538. package/dist/v4/runtime/taskObservation.js +48 -0
  539. package/dist/v4/runtime/timeArithmetic.d.ts +29 -0
  540. package/dist/v4/runtime/timeArithmetic.js +107 -0
  541. package/dist/v4/runtime/unreliable.d.ts +76 -0
  542. package/dist/v4/runtime/unreliable.js +473 -0
  543. package/dist/v4/runtime/volatileExecutions.d.ts +128 -0
  544. package/dist/v4/runtime/volatileExecutions.js +792 -0
  545. package/dist/v4/runtime/wireRegistry.d.ts +52 -0
  546. package/dist/v4/runtime/wireRegistry.js +29 -0
  547. package/dist/v4/runtime/writeRequest.d.ts +42 -0
  548. package/dist/v4/runtime/writeRequest.js +237 -0
  549. package/dist/v4/serve.d.ts +107 -0
  550. package/dist/v4/serve.js +80 -0
  551. package/dist/v4/serviceClient.d.ts +92 -0
  552. package/dist/v4/serviceClient.js +323 -0
  553. package/dist/v4/serviceDefinition.d.ts +138 -0
  554. package/dist/v4/serviceDefinition.js +150 -0
  555. package/dist/v4/serviceDependencies.d.ts +66 -0
  556. package/dist/v4/serviceDependencies.js +250 -0
  557. package/dist/v4/serviceFactory.d.ts +31 -0
  558. package/dist/v4/serviceFactory.js +157 -0
  559. package/dist/v4/serviceHandlers.d.ts +55 -0
  560. package/dist/v4/serviceHandlers.js +15 -0
  561. package/dist/v4/serviceMembers.d.ts +4 -0
  562. package/dist/v4/serviceMembers.js +12 -0
  563. package/dist/v4/staticServiceContracts.d.ts +43 -0
  564. package/dist/v4/staticServiceContracts.js +161 -0
  565. package/dist/v4/storageFormat.d.ts +16 -0
  566. package/dist/v4/storageFormat.js +5 -0
  567. package/dist/v4/streamContent.d.ts +30 -0
  568. package/dist/v4/streamContent.js +29 -0
  569. package/dist/v4/streamHandlers.d.ts +61 -0
  570. package/dist/v4/streamHandlers.js +16 -0
  571. package/dist/v4/streamingOperation.d.ts +64 -0
  572. package/dist/v4/streamingOperation.js +141 -0
  573. package/dist/v4/testSupport/cbor.d.ts +124 -0
  574. package/dist/v4/testSupport/cbor.js +230 -0
  575. package/dist/v4/testSupport/credentials.d.ts +55 -0
  576. package/dist/v4/testSupport/credentials.js +111 -0
  577. package/dist/v4/testSupport/unicode.d.ts +19 -0
  578. package/dist/v4/testSupport/unicode.js +112 -0
  579. package/dist/v4/unaryOperation.d.ts +59 -0
  580. package/dist/v4/unaryOperation.js +80 -0
  581. package/dist/v4/unreliable.d.ts +26 -0
  582. package/dist/v4/unreliable.js +10 -0
  583. package/dist/v4/webStreams.d.ts +30 -0
  584. package/dist/v4/webStreams.js +377 -0
  585. package/package.json +19 -16
  586. package/sbom/cyclonedx.json +761 -43
  587. package/sbom/spdx.json +566 -49
  588. package/dist/browser/connectSessionV3.d.ts +0 -31
  589. package/dist/browser/connectSessionV3.js +0 -241
  590. package/dist/browser/directWebSocketProfileV1.d.ts +0 -14
  591. package/dist/browser/directWebSocketProfileV1.js +0 -71
  592. package/dist/browser/httpDirectV1.d.ts +0 -30
  593. package/dist/browser/httpDirectV1.js +0 -52
  594. package/dist/browser/privateLoopbackV1.d.ts +0 -30
  595. package/dist/browser/privateLoopbackV1.js +0 -70
  596. package/dist/framing/index.d.ts +0 -1
  597. package/dist/framing/index.js +0 -1
  598. package/dist/framing/jsonframe.d.ts +0 -14
  599. package/dist/framing/jsonframe.js +0 -42
  600. package/dist/node/acceptor.d.ts +0 -36
  601. package/dist/node/acceptor.js +0 -155
  602. package/dist/node/acceptorV3.d.ts +0 -57
  603. package/dist/node/acceptorV3.js +0 -227
  604. package/dist/node/byteStreamDuplex.d.ts +0 -4
  605. package/dist/node/byteStreamDuplex.js +0 -69
  606. package/dist/node/connectSessionV3.d.ts +0 -24
  607. package/dist/node/connectSessionV3.js +0 -79
  608. package/dist/node/nativeTransportAddon.d.ts +0 -104
  609. package/dist/node/nativeTransportAddon.js +0 -212
  610. package/dist/node/rawQuicAdapterV3.d.ts +0 -10
  611. package/dist/node/rawQuicAdapterV3.js +0 -76
  612. package/dist/node/rawQuicServerV3.d.ts +0 -24
  613. package/dist/node/rawQuicServerV3.js +0 -34
  614. package/dist/node/runtimeAuthorizationV3.d.ts +0 -29
  615. package/dist/node/runtimeAuthorizationV3.js +0 -126
  616. package/dist/node/tunnelRuntimeV3.d.ts +0 -57
  617. package/dist/node/tunnelRuntimeV3.js +0 -857
  618. package/dist/node/webSocketServerV3.d.ts +0 -27
  619. package/dist/node/webSocketServerV3.js +0 -219
  620. package/dist/node/wsFactory.d.ts +0 -8
  621. package/dist/node/wsFactory.js +0 -84
  622. package/dist/public/streamHandlers.d.ts +0 -20
  623. package/dist/public/streamHandlers.js +0 -127
  624. package/dist/rpc/callError.d.ts +0 -5
  625. package/dist/rpc/callError.js +0 -11
  626. package/dist/rpc/caller.d.ts +0 -8
  627. package/dist/rpc/client.d.ts +0 -23
  628. package/dist/rpc/client.js +0 -171
  629. package/dist/rpc/index.d.ts +0 -6
  630. package/dist/rpc/index.js +0 -6
  631. package/dist/rpc/rpcProxy.d.ts +0 -16
  632. package/dist/rpc/rpcProxy.js +0 -58
  633. package/dist/rpc/server.d.ts +0 -51
  634. package/dist/rpc/server.js +0 -283
  635. package/dist/rpc/typed.d.ts +0 -5
  636. package/dist/rpc/typed.js +0 -9
  637. package/dist/rpc/validate.d.ts +0 -4
  638. package/dist/rpc/wire.d.ts +0 -15
  639. package/dist/v3/admissionError.d.ts +0 -4
  640. package/dist/v3/admissionError.js +0 -8
  641. package/dist/v3/artifact.d.ts +0 -145
  642. package/dist/v3/artifact.js +0 -1176
  643. package/dist/v3/artifactLease.d.ts +0 -17
  644. package/dist/v3/artifactLease.js +0 -109
  645. package/dist/v3/browserRuntime.d.ts +0 -37
  646. package/dist/v3/browserRuntime.js +0 -197
  647. package/dist/v3/browserSessionRuntime.d.ts +0 -2
  648. package/dist/v3/browserSessionRuntime.js +0 -21
  649. package/dist/v3/capability.d.ts +0 -32
  650. package/dist/v3/capability.js +0 -345
  651. package/dist/v3/carrier.d.ts +0 -84
  652. package/dist/v3/carrier.js +0 -411
  653. package/dist/v3/connectionController.d.ts +0 -100
  654. package/dist/v3/connectionController.js +0 -861
  655. package/dist/v3/contract.d.ts +0 -65
  656. package/dist/v3/contract.js +0 -3
  657. package/dist/v3/controller.d.ts +0 -45
  658. package/dist/v3/controller.js +0 -316
  659. package/dist/v3/handshake.d.ts +0 -81
  660. package/dist/v3/handshake.js +0 -471
  661. package/dist/v3/jcs.d.ts +0 -6
  662. package/dist/v3/jcs.js +0 -69
  663. package/dist/v3/jsonPreflight.d.ts +0 -1
  664. package/dist/v3/jsonPreflight.js +0 -251
  665. package/dist/v3/nodeRuntime.d.ts +0 -43
  666. package/dist/v3/nodeRuntime.js +0 -373
  667. package/dist/v3/nodeSessionRuntime.d.ts +0 -2
  668. package/dist/v3/nodeSessionRuntime.js +0 -13
  669. package/dist/v3/protocol.d.ts +0 -99
  670. package/dist/v3/protocol.js +0 -674
  671. package/dist/v3/publicApi.d.ts +0 -12
  672. package/dist/v3/publicApi.js +0 -46
  673. package/dist/v3/publicSession.js +0 -281
  674. package/dist/v3/retryDisposition.d.ts +0 -16
  675. package/dist/v3/retryDisposition.js +0 -23
  676. package/dist/v3/runtimeAdapters.d.ts +0 -9
  677. package/dist/v3/runtimeAdapters.js +0 -109
  678. package/dist/v3/security.d.ts +0 -36
  679. package/dist/v3/security.js +0 -113
  680. package/dist/v3/serverAdmission.d.ts +0 -38
  681. package/dist/v3/serverAdmission.js +0 -223
  682. package/dist/v3/session.d.ts +0 -322
  683. package/dist/v3/session.js +0 -2302
  684. package/dist/v3/sessionConnector.d.ts +0 -42
  685. package/dist/v3/sessionConnector.js +0 -513
  686. package/dist/v3/streamLifetimeLedger.d.ts +0 -31
  687. package/dist/v3/streamLifetimeLedger.js +0 -131
  688. package/dist/v3/streamMetadata.js +0 -7
  689. package/dist/v3/transportConstants.d.ts +0 -56
  690. package/dist/v3/transportConstants.js +0 -59
  691. package/dist/v3/unreliableMessage.d.ts +0 -44
  692. package/dist/v3/unreliableMessage.js +0 -287
  693. package/dist/v3/webSocketCarrier.d.ts +0 -31
  694. package/dist/v3/webSocketCarrier.js +0 -370
  695. package/dist/v3/webTransportCarrier.d.ts +0 -27
  696. package/dist/v3/webTransportCarrier.js +0 -552
  697. package/dist/ws-client/binaryTransport.d.ts +0 -64
  698. package/dist/ws-client/binaryTransport.js +0 -393
  699. package/dist/yamux/byteReader.d.ts +0 -13
  700. package/dist/yamux/byteReader.js +0 -81
  701. package/dist/yamux/constants.d.ts +0 -10
  702. package/dist/yamux/constants.js +0 -14
  703. package/dist/yamux/errors.d.ts +0 -15
  704. package/dist/yamux/errors.js +0 -34
  705. package/dist/yamux/header.d.ts +0 -17
  706. package/dist/yamux/header.js +0 -26
  707. package/dist/yamux/index.d.ts +0 -6
  708. package/dist/yamux/index.js +0 -6
  709. package/dist/yamux/session.d.ts +0 -81
  710. package/dist/yamux/session.js +0 -401
  711. package/dist/yamux/stream.d.ts +0 -42
  712. package/dist/yamux/stream.js +0 -296
  713. /package/dist/{rpc/caller.js → node/sqlitePoolWorkerProgramV4.d.ts} +0 -0
  714. /package/dist/{rpc/wire.js → node/sqliteWorkerProgramV4.d.ts} +0 -0
  715. /package/dist/{v3/publicSession.d.ts → v4/admissionOffer.js} +0 -0
  716. /package/dist/{v3/streamMetadata.d.ts → v4/runtime/controllerUnaryRoute.js} +0 -0
@@ -0,0 +1,1177 @@
1
+ import { isIP } from "node:net";
2
+ import { pinProfile } from "./wssV4.js";
3
+ import { createHash, X509Certificate } from "node:crypto";
4
+ import { CredentialWork, credentialWorkCharge, equalCredential, requireCredential } from "../v4/runtime/credentialSupport.js";
5
+ import { ResourceVector } from "../v4/runtime/resources.js";
6
+ import { timerChunk } from "../v4/runtime/deadline.js";
7
+ import { NativeDirectionFailure } from "../v4/runtime/nativeFailure.js";
8
+ import { NativeProviderPositions, nativeProviderStreamCharge } from "../v4/runtime/nativeProviderPositions.js";
9
+ import { HopAuthentication, HopAuthenticationPreparation, hopAuthenticationCharge } from "../v4/runtime/hopAuthentication.js";
10
+ import { observeTask } from "../v4/runtime/taskObservation.js";
11
+ function nativeFailure(error) {
12
+ if (error instanceof NativeDirectionFailure)
13
+ return error;
14
+ if (error instanceof Error) {
15
+ const native = error;
16
+ const reason = native.source === "stream" ? native.reason : native.code === "normal_drained" || native.code === "direction_reset" ? native.code : native.message;
17
+ if (reason === "normal_drained" || reason === "direction_reset")
18
+ return new NativeDirectionFailure(reason);
19
+ }
20
+ return new Error("carrier_failed");
21
+ }
22
+ /** A finite local carrier set. Each entry has its own TLS/Origin configuration;
23
+ * a verified Route chooses among these entries and never supplies configuration. */
24
+ export function captureNodeRawQUICCandidates(inputs) {
25
+ requireCredential(Array.isArray(inputs) && inputs.length >= 1 && inputs.length <= 2, "configuration_capacity");
26
+ const candidates = [];
27
+ try {
28
+ for (const input of inputs)
29
+ candidates.push(captureNodeRawQUIC(input));
30
+ const first = candidates[0];
31
+ requireCredential(new Set(candidates.map(value => value.nativeCarrier ?? "raw-quic")).size === candidates.length &&
32
+ candidates.every(value => value.applicationStreams === first.applicationStreams), "configuration_capacity");
33
+ return Object.freeze(candidates);
34
+ }
35
+ catch (error) {
36
+ for (const value of candidates)
37
+ for (const root of value.trustRootsDER ?? [])
38
+ root.fill(0);
39
+ throw error;
40
+ }
41
+ }
42
+ /** Reserves one independently owned native plan for each possible retry before
43
+ * Acquire. Per-attempt vectors take only their actual carrier's bounded share. */
44
+ export function nodeRawQUICCandidateAdmissionCosts(maxFrame, candidates, runtimeBytes, attemptLimit) {
45
+ requireCredential(Number.isSafeInteger(attemptLimit) && attemptLimit >= 1 && attemptLimit <= 16 && candidates.length >= 1, "configuration_capacity");
46
+ const plans = candidates.map(value => nodeRawQUICAdmissionCosts(maxFrame, value, runtimeBytes));
47
+ const shape = plans[0];
48
+ requireCredential(plans.every(plan => plan.length === shape.length && plan.every((part, index) => part[0] === shape[index][0])), "configuration_capacity");
49
+ const maximum = shape.map((part, index) => {
50
+ const vectors = plans.map(plan => plan[index][1].values());
51
+ return [part[0], new ResourceVector(vectors[0].map((_, dimension) => vectors.reduce((value, current) => current[dimension] > value ? current[dimension] : value, 0n)))];
52
+ });
53
+ return Object.freeze(Array.from({ length: attemptLimit }, () => [["node_raw_quic_candidate_route", credentialWorkCharge(16384, runtimeBytes)], ...maximum]).flat());
54
+ }
55
+ export function nodeNativePreparationBudgetCost(runtimeBytes) {
56
+ return ["node_native_preparation_budget", new ResourceVector([16384n + runtimeBytes, 65536n, 0n, 1n, 1n, 0n, 0n, 0n, 0n, 0n, 0n])];
57
+ }
58
+ const preparationOwners = new WeakMap();
59
+ export class NodeNativePreparationOwner {
60
+ #budget;
61
+ #dependency;
62
+ #configured = false;
63
+ #transferred = false;
64
+ #closed = false;
65
+ #candidates = new Map();
66
+ constructor(runtime, binding, admission) {
67
+ requireCredential(typeof binding.createPreparationBudget === "function", "configuration_capacity");
68
+ const cost = nodeNativePreparationBudgetCost(runtime.resources.runtimeBytes), reference = admission?.take([cost])[0];
69
+ try {
70
+ this.#dependency = runtime.admitDependency(cost[0], cost[1], reference, admission);
71
+ }
72
+ finally {
73
+ reference?.release();
74
+ }
75
+ try {
76
+ this.#budget = binding.createPreparationBudget();
77
+ this.#dependency.onClose(() => { this.#budget.close(); });
78
+ }
79
+ catch (error) {
80
+ this.#dependency.release();
81
+ throw error;
82
+ }
83
+ }
84
+ configure(fields) {
85
+ this.#dependency.check();
86
+ requireCredential(!this.#closed && !this.#configured, "credential_binding");
87
+ const pool = fields.source === "preauthorized_pool";
88
+ this.#budget.configure({ preauthInputBytes: pool ? fields.totalPreparationBytes ?? fields.preparationBytes : 1048576,
89
+ addressAttempts: pool ? fields.totalCandidateAttempts ?? 1 : 2, workUnits: pool ? fields.totalPreparationWork ?? fields.preparationWork : 4096 });
90
+ this.#configured = true;
91
+ }
92
+ candidate(fields) {
93
+ this.#dependency.check();
94
+ requireCredential(!this.#closed && this.#configured, "credential_binding");
95
+ const pool = fields.source === "preauthorized_pool";
96
+ const index = fields.candidateIndex ?? 0;
97
+ requireCredential(Number.isSafeInteger(index) && index >= 0 && index < 16, "credential_binding");
98
+ const original = this.#candidates.get(index);
99
+ if (original !== undefined)
100
+ return original;
101
+ const candidate = this.#budget.beginCandidate({ preauthInputBytes: pool ? fields.preparationBytes : 1048576,
102
+ addressAttempts: pool ? fields.preparationAddressAttempts ?? 1 : 2, workUnits: pool ? fields.preparationWork : 4096 });
103
+ this.#candidates.set(index, candidate);
104
+ return candidate;
105
+ }
106
+ transfer(carrier) { requireCredential(!this.#transferred && !this.#closed, "credential_binding"); carrier.retainPreparationOwner(() => this.close()); this.#transferred = true; }
107
+ releaseUnused() { if (!this.#transferred)
108
+ this.close(); }
109
+ close() { if (this.#closed)
110
+ return; this.#closed = true; this.#budget.close(); this.#candidates.clear(); this.#dependency.release(); }
111
+ }
112
+ export function prepayNodeNativePreparationBudget(runtime, admission, binding) {
113
+ requireCredential(!preparationOwners.has(admission), "credential_binding");
114
+ preparationOwners.set(admission, new NodeNativePreparationOwner(runtime, binding, admission));
115
+ }
116
+ export function releaseNodeNativePreparationBudget(admission) { preparationOwners.get(admission)?.releaseUnused(); preparationOwners.delete(admission); }
117
+ export function originalNodeNativePreparationOwner(runtime, fields, binding, admission) {
118
+ const owner = admission === undefined ? new NodeNativePreparationOwner(runtime, binding) : preparationOwners.get(admission);
119
+ requireCredential(owner !== undefined, "configuration_capacity");
120
+ try {
121
+ owner.configure(fields);
122
+ return owner;
123
+ }
124
+ catch (error) {
125
+ owner.releaseUnused();
126
+ throw error;
127
+ }
128
+ }
129
+ export function captureNodeRawQUIC(input, beforeCopy) {
130
+ const applicationStreams = input.applicationStreams, streamBufferBytes = input.streamBufferBytes;
131
+ const runtimeBytes = input.runtimeBytes, providerRuntimeBytes = input.providerRuntimeBytes, providerStreamBytes = input.providerStreamBytes;
132
+ const roots = input.trustRootsDER, nativeCarrier = input.nativeCarrier ?? "raw-quic", wt = input.webTransport;
133
+ requireCredential(nativeCarrier === "raw-quic" || nativeCarrier === "webtransport", "configuration_capacity");
134
+ if (nativeCarrier === "webtransport") {
135
+ requireCredential(wt !== undefined && Number.isSafeInteger(wt.headerBytes) && wt.headerBytes >= 1024 && wt.headerBytes <= 65536 && Number.isSafeInteger(wt.controlBytes) && wt.controlBytes >= 16384 && wt.controlBytes <= 1048576 &&
136
+ Array.isArray(wt.tuples) && wt.tuples.length >= 1 && wt.tuples.length <= 2 && new Set(wt.tuples).size === wt.tuples.length && wt.tuples.every(tuple => tuple === "chromium_draft02" || tuple === "native_h3") &&
137
+ Array.isArray(wt.allowedOrigins) && wt.allowedOrigins.length <= 64 && new Set(wt.allowedOrigins).size === wt.allowedOrigins.length && typeof wt.allowAbsentOrigin === "boolean", "configuration_capacity");
138
+ for (const origin of wt.allowedOrigins) {
139
+ const parsed = new URL(origin);
140
+ requireCredential(parsed.origin === origin && (parsed.protocol === "https:" || parsed.protocol === "http:") && origin.length <= 4096, "configuration_capacity");
141
+ }
142
+ }
143
+ else
144
+ requireCredential(wt === undefined, "configuration_capacity");
145
+ requireCredential(Number.isSafeInteger(applicationStreams) && applicationStreams >= 1 && applicationStreams <= 4096 &&
146
+ Number.isSafeInteger(streamBufferBytes) && streamBufferBytes >= 65544 && streamBufferBytes <= 16777224 &&
147
+ [runtimeBytes, providerRuntimeBytes, providerStreamBytes].every(value => typeof value === "bigint" && value > 0n && value <= 0xffffffffffffffffn) &&
148
+ (roots === undefined || Array.isArray(roots) && roots.length > 0 && roots.length <= 64 && roots.every(value => value instanceof Uint8Array && value.byteLength > 0 && value.byteLength <= 65536) && roots.reduce((n, value) => n + value.byteLength, 0) <= 1048576), "configuration_capacity");
149
+ const transport = { nativeCarrier, ...(wt === undefined ? {} : { webTransport: Object.freeze({ ...wt, tuples: Object.freeze([...wt.tuples]), allowedOrigins: Object.freeze([...wt.allowedOrigins]) }) }) };
150
+ beforeCopy?.({ applicationStreams, streamBufferBytes, runtimeBytes, providerRuntimeBytes, providerStreamBytes, ...transport, ...(roots === undefined ? {} : { trustRootsDER: roots }) });
151
+ return Object.freeze({ applicationStreams, streamBufferBytes, runtimeBytes, providerRuntimeBytes, providerStreamBytes, ...transport,
152
+ ...(roots === undefined ? {} : { trustRootsDER: Object.freeze(roots.map(value => new Uint8Array(value))) }) });
153
+ }
154
+ /** Exact captured configuration for adoption of a physical listener. */
155
+ export function sameNodeRawQUICOptions(left, right) {
156
+ if ((left.nativeCarrier ?? "raw-quic") !== (right.nativeCarrier ?? "raw-quic") || left.applicationStreams !== right.applicationStreams ||
157
+ left.streamBufferBytes !== right.streamBufferBytes || left.runtimeBytes !== right.runtimeBytes || left.providerRuntimeBytes !== right.providerRuntimeBytes || left.providerStreamBytes !== right.providerStreamBytes)
158
+ return false;
159
+ const roots = left.trustRootsDER, otherRoots = right.trustRootsDER;
160
+ if ((roots === undefined) !== (otherRoots === undefined) || roots !== undefined && (roots.length !== otherRoots.length || !roots.every((bytes, index) => equalCredential(bytes, otherRoots[index]))))
161
+ return false;
162
+ const wt = left.webTransport, otherWT = right.webTransport;
163
+ return wt === undefined ? otherWT === undefined : otherWT !== undefined && wt.headerBytes === otherWT.headerBytes && wt.controlBytes === otherWT.controlBytes && wt.allowAbsentOrigin === otherWT.allowAbsentOrigin &&
164
+ wt.tuples.length === otherWT.tuples.length && wt.tuples.every((tuple, index) => tuple === otherWT.tuples[index]) && wt.allowedOrigins.length === otherWT.allowedOrigins.length && wt.allowedOrigins.every((origin, index) => origin === otherWT.allowedOrigins[index]);
165
+ }
166
+ /** ABI4 prepays two native datagram queues, the fixed UDP receive scratch
167
+ * buffer and aggregate receive/send windows before connect/bind. The native
168
+ * endpoint uses a 1472-byte maximum payload; the supported UDP runtime has at
169
+ * most 64 GRO segments and 32 receive slots. Library heap and stream metadata
170
+ * remain separately covered by providerRuntimeBytes. */
171
+ export function nativeRawQUICQueueBytes(options) {
172
+ const streamRead = BigInt(Math.min(16384, options.streamBufferBytes)), aggregate = BigInt(options.applicationStreams + 1) * streamRead;
173
+ const receiveScratch = 1472n * 64n * 32n;
174
+ return 131072n + receiveScratch + (options.webTransport === undefined ? 0n : BigInt(2 * options.webTransport.controlBytes + 4 * options.webTransport.headerBytes)) + 2n * (aggregate < 16777216n ? aggregate : 16777216n);
175
+ }
176
+ export function nodeRawQUICAdmissionCosts(maxFrame, options, runtimeBytes) {
177
+ const maximum = Math.max(maxFrame, 65536) + 8;
178
+ requireCredential(maximum <= options.streamBufferBytes, "configuration_capacity");
179
+ const main = new ResourceVector([options.runtimeBytes + 65536n + 16384n + 1024n + BigInt(options.applicationStreams + 1) * 128n,
180
+ options.providerRuntimeBytes + nativeRawQUICQueueBytes(options), 0n, BigInt(options.applicationStreams + 20), 4n, 8n, 1n, 1n, 1n, 0n, 5n]);
181
+ const position = nativeProviderStreamCharge(maximum, options.runtimeBytes, options.providerStreamBytes);
182
+ return [["node_raw_quic", main], ...Array.from({ length: options.applicationStreams + 1 }, () => ["carrier_stream_position", position]),
183
+ ["node_raw_quic_policy", credentialWorkCharge(16384, runtimeBytes)]];
184
+ }
185
+ /** Each object is tied to actual native create/accept provenance. An observer
186
+ * cancellation never releases a handle or byte borrow before native exit. */
187
+ class RawQUICStream {
188
+ role;
189
+ origin;
190
+ maximum;
191
+ position;
192
+ checking;
193
+ released;
194
+ mode = "stream";
195
+ #done;
196
+ #resolve;
197
+ #raw;
198
+ #creating = true;
199
+ #closed = false;
200
+ #nativeEnded = false;
201
+ #released = false;
202
+ #reading = false;
203
+ #writing = false;
204
+ #unobservedWrite = false;
205
+ #tails = 0;
206
+ #borrowed = false;
207
+ #input;
208
+ #read;
209
+ #writeFailure;
210
+ #writeObserver;
211
+ #detachWrite;
212
+ #fin;
213
+ #stop;
214
+ #reset;
215
+ constructor(role, origin, maximum, position, checking, released) {
216
+ this.role = role;
217
+ this.origin = origin;
218
+ this.maximum = maximum;
219
+ this.position = position;
220
+ this.checking = checking;
221
+ this.released = released;
222
+ this.#done = new Promise(resolve => { this.#resolve = resolve; });
223
+ }
224
+ attach(raw) {
225
+ if (!this.#creating)
226
+ throw new Error("credential_binding");
227
+ this.#raw = raw;
228
+ this.#creating = false;
229
+ void raw.waitTermination().then(() => { this.#nativeEnded = true; if (this.#unobservedWrite)
230
+ this.#writing = false; this.#finish(); }, () => { void this.close(); });
231
+ this.#detachWrite = raw.onWriteFailure(reason => { this.#writeFailure = new NativeDirectionFailure(reason); this.#writeObserver?.(this.#writeFailure); });
232
+ if (this.#closed)
233
+ raw.abort();
234
+ }
235
+ creationFailed() { if (!this.#creating) {
236
+ void this.close();
237
+ return;
238
+ } this.#creating = false; this.#nativeEnded = true; void this.close(); }
239
+ #check() { if (this.#closed || this.#creating || this.#nativeEnded || this.#released)
240
+ throw new Error("carrier_closed"); this.position.check(); this.checking(); }
241
+ observeWriteFailure(callback) {
242
+ if (this.#writeObserver !== undefined)
243
+ throw new Error("busy");
244
+ this.#writeObserver = callback;
245
+ if (this.#writeFailure !== undefined)
246
+ queueMicrotask(() => { if (this.#writeObserver === callback)
247
+ callback(this.#writeFailure); });
248
+ return () => { if (this.#writeObserver === callback)
249
+ this.#writeObserver = undefined; };
250
+ }
251
+ async read(maxBytes, options) {
252
+ this.#check();
253
+ if (options?.signal?.aborted)
254
+ throw new Error("canceled");
255
+ requireCredential(Number.isSafeInteger(maxBytes) && maxBytes > 0 && maxBytes <= this.maximum, "configuration_capacity");
256
+ if (this.#reading)
257
+ throw new Error("busy");
258
+ this.#borrowed = false;
259
+ this.#input?.fill(0);
260
+ this.#input = undefined;
261
+ this.#reading = true;
262
+ const cancel = () => this.#read?.cancel();
263
+ options?.signal?.addEventListener("abort", cancel, { once: true });
264
+ let actual;
265
+ try {
266
+ const operation = this.#read = this.#raw.read(Math.min(maxBytes, 16384));
267
+ actual = operation.result().catch(error => { throw nativeFailure(error); }).then(bytes => {
268
+ if (bytes === null)
269
+ return null;
270
+ requireCredential(bytes instanceof Uint8Array && bytes.length > 0 && bytes.length <= Math.min(maxBytes, 16384) && bytes.buffer.byteLength <= 16384, "credential_binding");
271
+ if (this.#closed || options?.signal?.aborted) {
272
+ bytes.fill(0);
273
+ throw new Error("canceled");
274
+ }
275
+ this.#input = bytes;
276
+ this.#borrowed = true;
277
+ return bytes;
278
+ }).finally(() => { this.#reading = false; this.#read = undefined; options?.signal?.removeEventListener("abort", cancel); this.#finish(); });
279
+ if (options?.signal?.aborted)
280
+ operation.cancel();
281
+ }
282
+ catch (error) {
283
+ this.#reading = false;
284
+ this.#read = undefined;
285
+ options?.signal?.removeEventListener("abort", cancel);
286
+ this.#finish();
287
+ throw error;
288
+ }
289
+ return observeTask(actual, options?.signal);
290
+ }
291
+ submit(bytes, admitted, beforeSubmit) {
292
+ this.#check();
293
+ if (this.#writing || this.#fin !== undefined || this.#reset !== undefined)
294
+ return undefined;
295
+ if (this.#writeFailure !== undefined)
296
+ throw this.#writeFailure;
297
+ requireCredential(bytes.length > 0 && bytes.length <= this.maximum, "configuration_capacity");
298
+ // Acquire custody before native submission: synchronous promise hooks may
299
+ // close the original owner while a receipt or completion is constructed.
300
+ beforeSubmit?.();
301
+ this.#writing = true;
302
+ let native;
303
+ try {
304
+ native = this.#raw.submit(bytes);
305
+ }
306
+ catch (error) {
307
+ this.#writing = false;
308
+ this.#finish();
309
+ throw nativeFailure(error);
310
+ }
311
+ if (native === undefined) {
312
+ this.#writing = false;
313
+ this.#finish();
314
+ return undefined;
315
+ }
316
+ try {
317
+ admitted();
318
+ }
319
+ catch {
320
+ void this.close();
321
+ }
322
+ let completion;
323
+ try {
324
+ completion = native.completion().catch(error => { throw nativeFailure(error); })
325
+ .finally(() => { this.#writing = false; this.#finish(); });
326
+ }
327
+ catch {
328
+ // A malformed provider receipt cannot erase an accepted native borrow.
329
+ // Keep custody until the actual stream termination observation settles.
330
+ this.#unobservedWrite = true;
331
+ if (this.#nativeEnded)
332
+ this.#writing = false;
333
+ void this.close();
334
+ completion = this.#done.then(() => { throw new Error("carrier_failed"); });
335
+ }
336
+ return Object.freeze({ completion });
337
+ }
338
+ async write(bytes, options) {
339
+ if (options?.signal?.aborted)
340
+ throw new Error("canceled");
341
+ const output = this.submit(bytes, () => { });
342
+ if (output === undefined)
343
+ throw new Error("carrier_closed");
344
+ await observeTask(output.completion, options?.signal);
345
+ return bytes.length;
346
+ }
347
+ #tail(run) {
348
+ this.#tails++;
349
+ let actual;
350
+ try {
351
+ actual = run();
352
+ }
353
+ catch (error) {
354
+ this.#tails--;
355
+ this.#finish();
356
+ return Promise.reject(error);
357
+ }
358
+ return actual.finally(() => { this.#tails--; this.#finish(); });
359
+ }
360
+ closeWrite() {
361
+ if (this.#fin !== undefined)
362
+ return this.#fin;
363
+ // Peer STOP_SENDING may retire both physical directions before the
364
+ // original FIN record's completion resumes in JavaScript. Native cleanup
365
+ // is then already complete; authenticated DRAINED remains Session-owned.
366
+ if (this.#nativeEnded)
367
+ return Promise.resolve();
368
+ this.#check();
369
+ return this.#fin ??= this.#tail(() => this.#raw.closeWrite()).catch(error => { throw nativeFailure(error); });
370
+ }
371
+ stopSending(reason) {
372
+ this.#borrowed = false;
373
+ if (this.#creating || this.#raw === undefined || this.#nativeEnded)
374
+ return Promise.resolve();
375
+ return this.#stop ??= this.#tail(() => this.#raw.stopSending(reason));
376
+ }
377
+ resetWrite() {
378
+ if (this.#fin !== undefined)
379
+ return this.#fin;
380
+ if (this.#creating || this.#raw === undefined || this.#nativeEnded)
381
+ return Promise.resolve();
382
+ return this.#reset ??= this.#tail(() => this.#raw.resetWrite());
383
+ }
384
+ close() {
385
+ this.#closed = true;
386
+ this.#borrowed = false;
387
+ this.#read?.cancel();
388
+ this.#raw?.abort();
389
+ this.#finish();
390
+ return this.#done;
391
+ }
392
+ cleanupComplete() { return this.#released; }
393
+ waitTermination() { return this.#done; }
394
+ #finish() {
395
+ if (this.#released || this.#creating || !this.#nativeEnded || this.#reading || this.#writing || this.#tails !== 0 || this.#borrowed)
396
+ return;
397
+ this.#released = this.#closed = true;
398
+ this.#input?.fill(0);
399
+ this.#input = undefined;
400
+ this.#detachWrite?.();
401
+ this.#detachWrite = undefined;
402
+ this.#writeObserver = undefined;
403
+ this.#raw = undefined;
404
+ this.checking = undefined;
405
+ this.position?.release();
406
+ this.position = undefined;
407
+ const done = this.released;
408
+ this.released = undefined;
409
+ done?.();
410
+ this.#resolve();
411
+ }
412
+ }
413
+ export class NodeRawQUICCarrier {
414
+ environment;
415
+ dependency;
416
+ positions;
417
+ options;
418
+ preparation;
419
+ role;
420
+ path;
421
+ selectedCandidateIndex;
422
+ preparationBudget;
423
+ mode = "stream";
424
+ nativeStreams;
425
+ nativeDatagrams;
426
+ #datagramReading = false;
427
+ #datagramRead;
428
+ #done;
429
+ #resolve;
430
+ #session;
431
+ #tls;
432
+ #preparationOwnerRelease;
433
+ #preparationCompleted = false;
434
+ #wt;
435
+ get nativeCarrier() { return this.options.nativeCarrier ?? "raw-quic"; }
436
+ #alpn() { return this.nativeCarrier === "webtransport" ? "h3" : this.path === "direct" ? "flowersec-direct/4" : "flowersec-tunnel/4"; }
437
+ #path() { return this.nativeCarrier === "webtransport" ? `/flowersec/webtransport/v4/${this.path}` : ""; }
438
+ #checkOrigin(leg, node = 0, schema = "Leg") {
439
+ const origin = leg.optional("origin_policy", node, schema), actual = this.#wt?.origin;
440
+ if (this.nativeCarrier === "raw-quic") {
441
+ requireCredential(origin < 0 || leg.doc.boolean(leg.field("allow_absent", origin, "OriginPolicy")));
442
+ return;
443
+ }
444
+ requireCredential(origin >= 0 && this.#wt !== undefined);
445
+ if (actual === undefined)
446
+ requireCredential(leg.doc.boolean(leg.field("allow_absent", origin, "OriginPolicy")), "credential_untrusted");
447
+ else
448
+ requireCredential([...leg.items("origins", origin, "OriginPolicy")].some(entry => leg.doc.text(entry) === actual), "credential_untrusted");
449
+ }
450
+ #captureWT(session) {
451
+ if (this.nativeCarrier !== "webtransport") {
452
+ requireCredential(session.kind === "raw_quic");
453
+ return;
454
+ }
455
+ requireCredential(session.kind === "webtransport" && typeof session.request === "function");
456
+ const request = session.request();
457
+ requireCredential(request.scheme === "https" && request.path === this.#path() && request.authority.length > 0 && request.authority.length <= 512 && (request.origin === undefined || request.origin.length <= 4096) &&
458
+ request.sessionFlowControl === false && request.streamPrefixes === "rfc_webtransport" && request.datagramContext === "rfc_h3_quarter_stream_id" && this.options.webTransport.tuples.includes(request.tuple) &&
459
+ (request.tuple === "chromium_draft02" && request.protocol === "webtransport" || request.tuple === "native_h3" && request.protocol === "webtransport-h3"), "credential_untrusted");
460
+ this.#wt = Object.freeze({ ...request });
461
+ }
462
+ #maintenance;
463
+ #acceptedMaintenance;
464
+ #streams = new Set();
465
+ #physical = new Map();
466
+ #closed = false;
467
+ #nativeEnded = false;
468
+ #connecting = false;
469
+ #operations = 0;
470
+ #accepting = false;
471
+ #activated = false;
472
+ #applications = false;
473
+ #released = false;
474
+ #connect;
475
+ #expectation;
476
+ #certificateEnd;
477
+ #accepted;
478
+ constructor(environment, dependency, positions, options, preparation, role = "client", path = "direct", selectedCandidateIndex = -1, preparationBudget) {
479
+ this.environment = environment;
480
+ this.dependency = dependency;
481
+ this.positions = positions;
482
+ this.options = options;
483
+ this.preparation = preparation;
484
+ this.role = role;
485
+ this.path = path;
486
+ this.selectedCandidateIndex = selectedCandidateIndex;
487
+ this.preparationBudget = preparationBudget;
488
+ this.#done = new Promise(resolve => { this.#resolve = resolve; });
489
+ this.nativeStreams = Object.freeze({ capacity: options.applicationStreams, enable: () => { this.#check(); this.#applications = true; },
490
+ open: (operation) => this.#application(true, operation), accept: (operation) => this.#application(false, operation) });
491
+ this.nativeDatagrams = Object.freeze({ maxDatagramBytes: () => this.maxDatagramBytes(),
492
+ receive: (maximum, operation) => this.receiveDatagram(maximum, operation),
493
+ submit: (bytes, admitted) => this.submitDatagram(bytes, admitted) });
494
+ dependency.onClose(() => { void this.close(); });
495
+ }
496
+ #check() { this.dependency.check(); if (this.#closed || this.#nativeEnded || this.#session === undefined)
497
+ throw new Error("carrier_closed"); }
498
+ #captureTLS(session) {
499
+ requireCredential(this.#tls === undefined);
500
+ const native = session.tls();
501
+ if (!(native.peerLeafDER instanceof Uint8Array) || native.peerLeafDER.length > 65536) {
502
+ if (native.peerLeafDER instanceof Uint8Array)
503
+ native.peerLeafDER.fill(0);
504
+ requireCredential(false, "credential_untrusted");
505
+ }
506
+ // ABI4 returns this bounded owned copy. Keep exactly one private snapshot
507
+ // for the original carrier rather than recopying its leaf on each guard.
508
+ this.#tls = Object.freeze({ version: native.version, alpn: native.alpn, earlyDataAccepted: native.earlyDataAccepted, dedicatedConnection: native.dedicatedConnection,
509
+ peerLeafDER: native.peerLeafDER, certificateVerified: native.certificateVerified });
510
+ }
511
+ checkPreparation() {
512
+ this.#check();
513
+ this.preparation.check();
514
+ const tls = this.#tls;
515
+ requireCredential(this.#session.wireVersion === 4 && this.#session.path === this.path && tls.version === "TLSv1.3" && tls.alpn === this.#alpn() &&
516
+ tls.earlyDataAccepted === false && tls.dedicatedConnection === true && tls.peerLeafDER instanceof Uint8Array && (this.role === "server" || tls.peerLeafDER.length > 0) && tls.peerLeafDER.length <= 65536 &&
517
+ this.#session.inboundBidirectionalStreamCapacity >= this.options.applicationStreams + 1 && typeof this.#session.maxDatagramBytes === "function" &&
518
+ typeof this.#session.receiveDatagram === "function" && typeof this.#session.submitDatagram === "function", "credential_untrusted");
519
+ const now = this.environment.clock.sample().requireInterval();
520
+ if (this.#certificateEnd !== undefined)
521
+ requireCredential(now.upperMS < this.#certificateEnd, "credential_expired");
522
+ const expected = this.#expectation;
523
+ if (expected !== undefined) {
524
+ if (expected.mode === "ca")
525
+ requireCredential(tls.certificateVerified, "credential_untrusted");
526
+ else {
527
+ const leaf = new Uint8Array(createHash("sha256").update(tls.peerLeafDER).digest());
528
+ try {
529
+ requireCredential(expected.pins.some(pin => now.lowerMS >= pin.from && now.upperMS < pin.until && equalCredential(pin.digest, leaf)), "credential_expired");
530
+ }
531
+ finally {
532
+ leaf.fill(0);
533
+ }
534
+ }
535
+ }
536
+ }
537
+ /** Called only by the configured current native listener. A dedicated
538
+ * candidate can finish physical Prepare before accepting its peer's first
539
+ * maintenance stream; the original carrier retains that later native tail. */
540
+ async accept(session, endpoint, signal, deferMaintenance = false) {
541
+ this.dependency.check();
542
+ this.preparation.check();
543
+ requireCredential(this.role === "server" && this.#session === undefined && !this.#closed, "credential_binding");
544
+ this.#connecting = true;
545
+ this.#session = session;
546
+ this.#accepted = Object.freeze({ ...endpoint });
547
+ const cancel = () => { void this.close(); };
548
+ signal?.addEventListener("abort", cancel, { once: true });
549
+ try {
550
+ void session.waitTermination().then(() => { this.#nativeEnded = true; void this.close(); this.#finish(); }, () => { void this.close(); });
551
+ if (signal?.aborted)
552
+ throw new Error("canceled");
553
+ this.#captureWT(session);
554
+ this.#captureTLS(session);
555
+ this.checkPreparation();
556
+ const local = session.localAddress();
557
+ requireCredential(local.port === endpoint.port && (isIP(endpoint.host) === 0 || local.host === endpoint.host), "credential_binding");
558
+ const now = this.environment.clock.sample().requireInterval(), from = BigInt(endpoint.leaf.validFromDate.getTime()), until = BigInt(endpoint.leaf.validToDate.getTime());
559
+ requireCredential(now.lowerMS >= from && now.upperMS < until, "credential_expired");
560
+ this.#certificateEnd = until;
561
+ this.#checkWTAuthority(endpoint.host, endpoint.port);
562
+ // Shared ingress ends network Prepare after the original physical
563
+ // binding checks, before waiting for a peer's HELLO/HOP stream. A
564
+ // dedicated candidate keeps its explicit token until the physical
565
+ // candidate race selects and retires all other sockets.
566
+ if (this.preparationBudget === undefined)
567
+ this.completePreparation();
568
+ if (!deferMaintenance)
569
+ this.#maintenance = await this.#createStream(false, true, signal === undefined ? undefined : { signal });
570
+ this.checkPreparation();
571
+ this.#activated = true;
572
+ }
573
+ catch (error) {
574
+ void this.close();
575
+ throw error;
576
+ }
577
+ finally {
578
+ this.#connecting = false;
579
+ signal?.removeEventListener("abort", cancel);
580
+ this.#finish();
581
+ }
582
+ }
583
+ /** Compare complete original signed route facts with the accepted listener,
584
+ * never with a remote header, proxy assertion or QUIC stream number. */
585
+ checkAcceptedRoute(fields, endpointRole = 1) {
586
+ this.checkPreparation();
587
+ const actual = this.#accepted;
588
+ requireCredential(this.role === "server" && actual !== undefined && fields.accessClass === 0n, "credential_binding");
589
+ const ref = this.environment.reserveConnectionWork("accepted_raw_quic_route", credentialWorkCharge(16384, this.environment.resources.runtimeBytes));
590
+ let work;
591
+ try {
592
+ work = new CredentialWork(this.environment.resources, 16384, ref);
593
+ const route = work.parse(fields.route, "Route", 16384);
594
+ try {
595
+ const leg = route.field(this.path === "direct" ? "direct_leg" : endpointRole === 0 ? "client_leg" : "server_leg"), tls = route.field("tls_policy", leg, "Leg");
596
+ requireCredential(route.uint("path_kind") === (this.path === "direct" ? 0n : 1n) && route.uint("access_class", leg, "Leg") === 0n && route.uint("carrier", leg, "Leg") === (this.nativeCarrier === "webtransport" ? 2n : 0n) &&
597
+ route.uint("dialer_role", leg, "Leg") === (this.path === "direct" ? 0n : 2n) && route.uint("listener_role", leg, "Leg") === BigInt(endpointRole) && route.text("alpn", leg, "Leg") === this.#alpn() &&
598
+ route.text("path", leg, "Leg") === this.#path() && route.text("subprotocol", leg, "Leg") === "" && route.text("host", leg, "Leg") === actual.host &&
599
+ route.uint("port", leg, "Leg") === BigInt(actual.port), "credential_binding");
600
+ this.#checkOrigin(route, leg, "Leg");
601
+ this.#checkWTAuthority(actual.host, actual.port);
602
+ const mode = route.uint("mode", tls, "TLSPolicy");
603
+ if (mode === 0n)
604
+ requireCredential(isIP(actual.host) ? actual.leaf.checkIP(actual.host) === actual.host : actual.leaf.checkHost(actual.host, { subject: "never" }) !== undefined, "credential_binding");
605
+ else {
606
+ requireCredential(mode === 1n && route.uint("pin_kind", tls, "TLSPolicy") === 0n, "credential_binding");
607
+ const now = this.environment.clock.sample().requireInterval(), window = pinProfile(actual.leaf, now), digest = new Uint8Array(createHash("sha256").update(actual.leaf.raw).digest());
608
+ try {
609
+ requireCredential([...route.items("pins", tls, "TLSPolicy")].some(pin => {
610
+ const from = route.uint("not_before_ms", pin, "TLSPin"), until = route.uint("not_after_ms", pin, "TLSPin");
611
+ return now.lowerMS >= from && now.upperMS < until && from >= window.from && until <= window.until && equalCredential(digest, route.bytes("leaf_der_sha256", pin, "TLSPin"));
612
+ }), "credential_binding");
613
+ }
614
+ finally {
615
+ digest.fill(0);
616
+ }
617
+ }
618
+ }
619
+ finally {
620
+ route.close();
621
+ }
622
+ this.checkPreparation();
623
+ }
624
+ finally {
625
+ work?.close();
626
+ ref.release();
627
+ }
628
+ }
629
+ checkAcceptedHopRoute(credentials, reference, localRole = 2) {
630
+ this.checkPreparation();
631
+ credentials.check(reference);
632
+ const actual = this.#accepted;
633
+ requireCredential(actual !== undefined && this.path === "tunnel");
634
+ const ref = this.environment.reserveConnectionWork("accepted_relay_quic_policy", credentialWorkCharge(16384, this.environment.resources.runtimeBytes));
635
+ let work;
636
+ const bytes = credentials.descriptor(reference);
637
+ try {
638
+ work = new CredentialWork(this.environment.resources, 16384, ref);
639
+ const leg = work.parse(bytes, "Leg", 16384, 16384, { selectors: { path_kind: "tunnel" } });
640
+ try {
641
+ const tls = leg.field("tls_policy"), host = leg.text("host");
642
+ requireCredential(leg.uint("carrier") === (this.nativeCarrier === "webtransport" ? 2n : 0n) && leg.uint("access_class") === 0n && leg.uint("dialer_role") === (localRole === 2 ? BigInt(credentials.role) : 2n) && leg.uint("listener_role") === BigInt(localRole) && leg.text("alpn") === this.#alpn() && leg.text("path") === this.#path() && leg.text("subprotocol") === "" && host === actual.host && leg.uint("port") === BigInt(actual.port));
643
+ this.#checkOrigin(leg);
644
+ this.#checkWTAuthority(actual.host, actual.port);
645
+ const mode = leg.uint("mode", tls, "TLSPolicy");
646
+ if (mode === 0n)
647
+ requireCredential(isIP(host) ? actual.leaf.checkIP(host) === host : actual.leaf.checkHost(host, { subject: "never" }) !== undefined);
648
+ else {
649
+ requireCredential(mode === 1n && leg.uint("pin_kind", tls, "TLSPolicy") === 0n);
650
+ const now = this.environment.clock.sample().requireInterval(), window = pinProfile(actual.leaf, now), digest = new Uint8Array(createHash("sha256").update(actual.leaf.raw).digest());
651
+ try {
652
+ requireCredential([...leg.items("pins", tls, "TLSPolicy")].some(pin => { const from = leg.uint("not_before_ms", pin, "TLSPin"), until = leg.uint("not_after_ms", pin, "TLSPin"); return now.lowerMS >= from && now.upperMS < until && from >= window.from && until <= window.until && equalCredential(digest, leg.bytes("leaf_der_sha256", pin, "TLSPin")); }));
653
+ }
654
+ finally {
655
+ digest.fill(0);
656
+ }
657
+ }
658
+ }
659
+ finally {
660
+ leg.close();
661
+ }
662
+ }
663
+ finally {
664
+ bytes.fill(0);
665
+ work?.close();
666
+ ref.release();
667
+ }
668
+ }
669
+ #checkWTAuthority(host, port) {
670
+ if (this.#wt === undefined)
671
+ return;
672
+ const expected = new URL(`https://${isIP(host) === 6 ? `[${host}]` : host}:${port}${this.#path()}`);
673
+ requireCredential(this.#wt.authority === expected.host, "credential_untrusted");
674
+ }
675
+ async prepare(driver, endpoint, expectation, signal) {
676
+ this.dependency.check();
677
+ this.preparation.check();
678
+ requireCredential(this.role === "client" && !this.#connecting && this.#session === undefined && !this.#closed, "credential_binding");
679
+ this.#expectation = expectation;
680
+ this.#connecting = true;
681
+ let timer;
682
+ let submitted = false, tlsVerified = false;
683
+ const cancel = () => { this.#connect?.cancel(); void this.close(); };
684
+ signal?.addEventListener("abort", cancel, { once: true });
685
+ try {
686
+ this.dependency.check();
687
+ this.preparation.check();
688
+ if (signal?.aborted)
689
+ throw new Error("canceled");
690
+ const connectOptions = { host: endpoint.host, port: endpoint.port, serverName: expectation.serverName, path: this.path,
691
+ inboundBidirectionalStreamCapacity: this.options.applicationStreams + 1, readBufferBytes: Math.min(16384, this.options.streamBufferBytes), datagramQueueBytes: 65536,
692
+ handshakeTimeoutMs: Math.min(60000, Number(this.preparation.remainingMS())), ...(this.preparationBudget === undefined ? {} : { preparationBudget: this.preparationBudget }), tlsMode: expectation.mode,
693
+ ...(expectation.mode === "ca" ? { trustRootsDer: this.options.trustRootsDER } : { activeLeafDerSha256: expectation.pins.map(pin => pin.digest) }) };
694
+ const operation = this.#connect = this.nativeCarrier === "raw-quic" ? driver.connectRawQuic(connectOptions) : driver.connectWebTransport({ ...connectOptions,
695
+ connectPath: this.#path(), tuple: "native_h3", headerBytes: this.options.webTransport.headerBytes, controlBytes: this.options.webTransport.controlBytes });
696
+ submitted = true;
697
+ const tick = () => { try {
698
+ this.preparation.check();
699
+ this.dependency.check();
700
+ timer = setTimeout(tick, timerChunk(this.preparation.remainingMS()));
701
+ }
702
+ catch {
703
+ cancel();
704
+ } };
705
+ tick();
706
+ if (signal?.aborted)
707
+ cancel();
708
+ const actual = operation.result().then(async (session) => {
709
+ this.#session = session;
710
+ void session.waitTermination().then(() => { this.#nativeEnded = true; void this.close(); this.#finish(); }, () => { void this.close(); });
711
+ if (this.#closed || signal?.aborted) {
712
+ session.abort();
713
+ throw new Error("canceled");
714
+ }
715
+ this.#captureWT(session);
716
+ this.#captureTLS(session);
717
+ this.checkPreparation();
718
+ this.#checkWTAuthority(endpoint.host, endpoint.port);
719
+ requireCredential(this.#wt === undefined || this.#wt.origin === undefined, "credential_untrusted");
720
+ const certificate = new X509Certificate(this.#tls.peerLeafDER), from = BigInt(certificate.validFromDate.getTime()), until = BigInt(certificate.validToDate.getTime());
721
+ const now = this.environment.clock.sample().requireInterval();
722
+ requireCredential(now.lowerMS >= from && now.upperMS < until && (isIP(expectation.serverName) ? certificate.checkIP(expectation.serverName) === expectation.serverName : certificate.checkHost(expectation.serverName, { subject: "never" }) !== undefined), "credential_untrusted");
723
+ this.#certificateEnd = until;
724
+ if (expectation.mode === "pin")
725
+ pinProfile(certificate, now);
726
+ tlsVerified = true;
727
+ this.#maintenance = await this.#createStream(true, true);
728
+ this.checkPreparation();
729
+ }).finally(() => { this.#connecting = false; this.#connect = undefined; if (this.#session === undefined)
730
+ this.#nativeEnded = true; this.#finish(); });
731
+ await observeTask(actual, signal);
732
+ }
733
+ catch (error) {
734
+ // A synchronous refusal transfers no native operation. A submitted
735
+ // connection keeps its original custody through the actual continuation.
736
+ if (!submitted) {
737
+ this.#connecting = false;
738
+ this.#nativeEnded = true;
739
+ }
740
+ void this.close();
741
+ if (!tlsVerified && error instanceof Error && ["credential_binding", "credential_untrusted", "credential_expired"].includes(error.message))
742
+ this.environment.diagnosticCounters.observe("tls_rejection", { phase: "prepare", code: "tls_rejected" });
743
+ if (error instanceof Error && ["handshake_failed", "pin_mismatch", "pin_certificate_invalid", "invalid_alpn"].includes(error.message)) {
744
+ this.environment.diagnosticCounters.observe("tls_rejection", { phase: "prepare", code: "tls_rejected" });
745
+ throw new Error("authentication_failed");
746
+ }
747
+ throw error;
748
+ }
749
+ finally {
750
+ if (timer !== undefined)
751
+ clearTimeout(timer);
752
+ signal?.removeEventListener("abort", cancel);
753
+ }
754
+ }
755
+ async authenticateHop(credentials, signer, random, resources, reference, options, acceptedHello, prepared, originalDeadline) {
756
+ const incarnation = new Uint8Array(16);
757
+ let ref = prepared, hop;
758
+ try {
759
+ this.checkPreparation();
760
+ requireCredential(this.path === "tunnel" && (credentials.role === 0 || credentials.role === 1));
761
+ if (originalDeadline !== undefined)
762
+ this.preparation.tightenFrom(originalDeadline);
763
+ if (this.role === "server")
764
+ this.checkAcceptedHopRoute(credentials, reference, credentials.role);
765
+ ref ??= this.environment.reserveConnectionWork("endpoint_hop_authentication", hopAuthenticationCharge(resources.runtimeBytes));
766
+ random(incarnation);
767
+ if (!(ref instanceof HopAuthenticationPreparation))
768
+ requireCredential(ref.sameEnvironment(reference));
769
+ hop = new HopAuthentication({ resources, transport: this, credentials, localRole: credentials.role, localIncarnation: incarnation, random, signer, deadline: this.preparation,
770
+ guard: () => this.checkPreparation(), ...(acceptedHello === undefined ? {} : { acceptedHello }) }, ref, reference);
771
+ await hop.authenticateEndpoint(options);
772
+ }
773
+ finally {
774
+ hop?.close();
775
+ incarnation.fill(0);
776
+ if (ref instanceof HopAuthenticationPreparation)
777
+ ref.close();
778
+ else
779
+ ref?.release();
780
+ }
781
+ }
782
+ retainPreparationOwner(release) { requireCredential(!this.#closed && this.#preparationOwnerRelease === undefined, "credential_binding"); this.#preparationOwnerRelease = release; }
783
+ completePreparation() {
784
+ if (this.#preparationCompleted)
785
+ return;
786
+ this.checkPreparation();
787
+ if (this.preparationBudget !== undefined)
788
+ requireCredential(typeof this.#session.completePreparation === "function", "configuration_capacity");
789
+ this.#session.completePreparation?.();
790
+ this.#preparationCompleted = true;
791
+ }
792
+ activate() { this.checkPreparation(); this.#activated = true; }
793
+ exportBinding(artifactDigest) {
794
+ this.checkPreparation();
795
+ requireCredential(artifactDigest.length === 32 && artifactDigest.some(byte => byte !== 0));
796
+ const output = this.#session.exportKeyingMaterial(32, "EXPORTER-flowersec-v4", artifactDigest);
797
+ requireCredential(output.length === 32);
798
+ return output;
799
+ }
800
+ async #createStream(local, maintenance, options) {
801
+ this.#check();
802
+ if (options?.signal?.aborted)
803
+ throw new Error("canceled");
804
+ const position = this.positions.acquire(maintenance);
805
+ let rawBinding;
806
+ const stream = new RawQUICStream(this.role, maintenance ? "maintenance" : local ? "local" : "peer", this.options.streamBufferBytes, position, () => this.#check(), () => { if (rawBinding !== undefined)
807
+ this.#physical.delete(rawBinding); this.#streams.delete(stream); this.#finish(); });
808
+ this.#streams.add(stream);
809
+ this.#operations++;
810
+ let operation, acceptHeld = false;
811
+ try {
812
+ this.#check();
813
+ position.check();
814
+ if (options?.signal?.aborted)
815
+ throw new Error("canceled");
816
+ if (!local && !maintenance) {
817
+ if (this.#accepting)
818
+ throw new Error("carrier_closed");
819
+ this.#accepting = true;
820
+ acceptHeld = true;
821
+ }
822
+ operation = local ? this.#session.openStream() : this.#session.acceptStream();
823
+ }
824
+ catch (error) {
825
+ if (acceptHeld)
826
+ this.#accepting = false;
827
+ stream.creationFailed();
828
+ this.#operations--;
829
+ this.#finish();
830
+ throw error;
831
+ }
832
+ const cancel = () => { operation.cancel(); void stream.close(); };
833
+ options?.signal?.addEventListener("abort", cancel, { once: true });
834
+ const actual = operation.result().then(raw => {
835
+ try {
836
+ requireCredential(!this.#physical.has(raw), "credential_binding");
837
+ rawBinding = raw;
838
+ this.#physical.set(raw, stream);
839
+ stream.attach(raw);
840
+ }
841
+ catch (error) {
842
+ stream.creationFailed();
843
+ void this.close();
844
+ throw error;
845
+ }
846
+ if (this.#closed || options?.signal?.aborted) {
847
+ void stream.close();
848
+ throw new Error("canceled");
849
+ }
850
+ return stream;
851
+ }, error => { stream.creationFailed(); throw error; })
852
+ .finally(() => { if (acceptHeld)
853
+ this.#accepting = false; this.#operations--; options?.signal?.removeEventListener("abort", cancel); this.#finish(); });
854
+ if (options?.signal?.aborted)
855
+ cancel();
856
+ return observeTask(actual, options?.signal);
857
+ }
858
+ async #application(local, options) {
859
+ this.#check();
860
+ if (!this.#activated || !this.#applications || !local && this.#accepting)
861
+ throw new Error("carrier_closed");
862
+ // The native accept owns its gate through actual completion. An observer's
863
+ // cancellation can return earlier without admitting a second native accept.
864
+ return this.#createStream(local, false, options);
865
+ }
866
+ #acceptMaintenance(options) {
867
+ this.#check();
868
+ if (!this.#activated || this.role !== "server")
869
+ return Promise.reject(new Error("carrier_closed"));
870
+ if (options?.signal?.aborted)
871
+ return Promise.reject(new Error("canceled"));
872
+ // One original native accept owns the prepaid maintenance position through
873
+ // actual completion. Concurrent observers never create another accept.
874
+ this.#acceptedMaintenance ??= this.#createStream(false, true, options).then(stream => {
875
+ this.#check();
876
+ this.#maintenance = stream;
877
+ return stream;
878
+ });
879
+ return observeTask(this.#acceptedMaintenance, options?.signal);
880
+ }
881
+ read(maxBytes, options) {
882
+ this.#check();
883
+ if (!this.#activated)
884
+ return Promise.reject(new Error("carrier_closed"));
885
+ return this.#maintenance === undefined ? this.#acceptMaintenance(options).then(stream => stream.read(maxBytes, options)) : this.#maintenance.read(maxBytes, options);
886
+ }
887
+ write(bytes, options) {
888
+ this.#check();
889
+ if (!this.#activated)
890
+ return Promise.reject(new Error("carrier_closed"));
891
+ return this.#maintenance === undefined ? this.#acceptMaintenance(options).then(stream => stream.write(bytes, options)) : this.#maintenance.write(bytes, options);
892
+ }
893
+ submit(bytes, admitted, beforeSubmit) { this.#check(); if (!this.#activated || this.#maintenance === undefined)
894
+ return undefined; return this.#maintenance.submit(bytes, admitted, beforeSubmit); }
895
+ maxDatagramBytes() {
896
+ this.#check();
897
+ const maximum = this.#session.maxDatagramBytes();
898
+ if (!Number.isSafeInteger(maximum) || maximum < 0)
899
+ throw new Error("carrier_failed");
900
+ return Math.min(maximum, 1024);
901
+ }
902
+ async receiveDatagram(maximum, options) {
903
+ this.#check();
904
+ if (!this.#activated || !this.#applications || this.#datagramReading || !Number.isSafeInteger(maximum) || maximum < 1 || maximum > 1024)
905
+ throw new Error("carrier_closed");
906
+ if (options?.signal?.aborted)
907
+ throw new Error("canceled");
908
+ this.#datagramReading = true;
909
+ this.#operations++;
910
+ let operation;
911
+ const cancel = () => operation?.cancel();
912
+ try {
913
+ operation = this.#datagramRead = this.#session.receiveDatagram(maximum);
914
+ if (this.#closed || options?.signal?.aborted)
915
+ operation.cancel();
916
+ options?.signal?.addEventListener("abort", cancel, { once: true });
917
+ if (options?.signal?.aborted)
918
+ cancel();
919
+ const bytes = await operation.result();
920
+ try {
921
+ this.#check();
922
+ if (options?.signal?.aborted)
923
+ throw new Error("canceled");
924
+ if (!(bytes instanceof Uint8Array) || bytes.length > maximum)
925
+ throw new Error("carrier_failed");
926
+ return new Uint8Array(bytes);
927
+ }
928
+ finally {
929
+ bytes.fill(0);
930
+ }
931
+ }
932
+ finally {
933
+ options?.signal?.removeEventListener("abort", cancel);
934
+ this.#datagramRead = undefined;
935
+ this.#datagramReading = false;
936
+ this.#operations--;
937
+ this.#finish();
938
+ }
939
+ }
940
+ submitDatagram(bytes, admitted) {
941
+ this.#check();
942
+ if (!this.#activated || !this.#applications || bytes.length > this.maxDatagramBytes())
943
+ return undefined;
944
+ const receipt = this.#session.submitDatagram(bytes);
945
+ if (receipt === undefined)
946
+ return undefined;
947
+ this.#operations++;
948
+ let acknowledgment;
949
+ try {
950
+ admitted();
951
+ }
952
+ catch (error) {
953
+ acknowledgment = error;
954
+ }
955
+ const completion = (async () => {
956
+ try {
957
+ await receipt.completion();
958
+ if (acknowledgment !== undefined)
959
+ throw acknowledgment;
960
+ }
961
+ finally {
962
+ this.#operations--;
963
+ this.#finish();
964
+ }
965
+ })();
966
+ return Object.freeze({ completion });
967
+ }
968
+ close() {
969
+ if (!this.#closed) {
970
+ this.#closed = true;
971
+ this.#connect?.cancel();
972
+ this.#datagramRead?.cancel();
973
+ this.positions.close();
974
+ for (const stream of Array.from(this.#streams))
975
+ void stream.close();
976
+ this.#session?.abort();
977
+ if (this.#session === undefined && !this.#connecting)
978
+ this.#nativeEnded = true;
979
+ }
980
+ this.#finish();
981
+ return this.#done;
982
+ }
983
+ waitTermination() { return this.#done; }
984
+ #finish() {
985
+ if (this.#released || !this.#closed || !this.#nativeEnded || this.#connecting || this.#operations !== 0 || this.#streams.size !== 0 || !this.positions.cleanupComplete())
986
+ return;
987
+ this.#released = true;
988
+ this.#maintenance = undefined;
989
+ this.#acceptedMaintenance = undefined;
990
+ this.#session = undefined;
991
+ this.#accepted = undefined;
992
+ this.#tls?.peerLeafDER.fill(0);
993
+ this.#tls = undefined;
994
+ this.#wt = undefined;
995
+ for (const pin of this.#expectation?.pins ?? [])
996
+ pin.digest.fill(0);
997
+ this.#expectation = undefined;
998
+ this.#preparationOwnerRelease?.();
999
+ this.#preparationOwnerRelease = undefined;
1000
+ this.dependency.release();
1001
+ this.#resolve();
1002
+ }
1003
+ }
1004
+ export function nodeRawQUICRouteCarrier(environment, candidate, endpointRole = 0, admission) {
1005
+ const reference = environment.reserveConnectionWork("node_raw_quic_candidate_route", credentialWorkCharge(16384, environment.resources.runtimeBytes), admission);
1006
+ let work;
1007
+ try {
1008
+ work = new CredentialWork(environment.resources, 16384, reference);
1009
+ const route = work.parse(candidate.route, "Route", 16384);
1010
+ try {
1011
+ requireCredential(route.uint("path_kind") === BigInt(candidate.pathKind), "credential_binding");
1012
+ const leg = route.field(candidate.pathKind === 0 ? "direct_leg" : endpointRole === 0 ? "client_leg" : "server_leg"), carrier = route.uint("carrier", leg, "Leg");
1013
+ requireCredential(route.uint("access_class", leg, "Leg") === candidate.accessClass && (carrier === 0n || carrier === 2n), "credential_untrusted");
1014
+ return carrier === 2n ? "webtransport" : "raw-quic";
1015
+ }
1016
+ finally {
1017
+ route.close();
1018
+ }
1019
+ }
1020
+ finally {
1021
+ work?.close();
1022
+ reference.release();
1023
+ }
1024
+ }
1025
+ /** Attempts only the verifier-authorized candidate order, with one separately
1026
+ * prepaid carrier plan per attempt. A failed provider is fully retired by
1027
+ * prepareNodeRawQUIC before the next candidate can consume its plan. */
1028
+ export async function prepareNodeRawQUICCandidates(environment, fields, configured, drivers, signal, admission, endpointRole = 0, physicalDialerRole = endpointRole, attemptLimit = fields.totalCandidateAttempts ?? 1) {
1029
+ const candidates = fields.candidates ?? [], preferred = fields.candidateIndex ?? candidates[0]?.candidateIndex ?? -1;
1030
+ requireCredential(candidates.length > 0 && candidates.some(value => value.candidateIndex === preferred) && Number.isSafeInteger(attemptLimit) && attemptLimit >= 1 && attemptLimit <= 16, "credential_binding");
1031
+ if (fields.source === "preauthorized_pool")
1032
+ requireCredential(fields.preparationWork >= 1, "configuration_capacity");
1033
+ const signedLimit = fields.totalCandidateAttempts ?? 1;
1034
+ requireCredential(Number.isSafeInteger(signedLimit) && signedLimit >= 1, "credential_binding");
1035
+ const ordered = [candidates.find(value => value.candidateIndex === preferred), ...candidates.filter(value => value.candidateIndex !== preferred)].slice(0, Math.min(attemptLimit, signedLimit));
1036
+ const owner = originalNodeNativePreparationOwner(environment, fields, drivers[configured[0]?.nativeCarrier ?? "raw-quic"], admission);
1037
+ let lastError;
1038
+ try {
1039
+ for (const candidate of ordered) {
1040
+ if (signal?.aborted)
1041
+ throw new Error("canceled");
1042
+ fields.preparationDeadline.check();
1043
+ requireCredential(candidate.pathKind === fields.pathKind, "credential_binding");
1044
+ const kind = nodeRawQUICRouteCarrier(environment, candidate, endpointRole, admission), options = configured.find(value => (value.nativeCarrier ?? "raw-quic") === kind), driver = drivers[kind];
1045
+ if (options === undefined || driver === undefined)
1046
+ continue;
1047
+ const selected = Object.freeze({ ...fields, ...candidate });
1048
+ let carrier;
1049
+ try {
1050
+ carrier = await prepareNodeRawQUIC(environment, selected, options, driver, signal, admission, endpointRole, physicalDialerRole, candidate.candidateIndex, owner.candidate(selected));
1051
+ // Network Prepare ends before durable spend. Activated HOP has its own
1052
+ // original Grant quota and cannot consume this candidate's UDP cap.
1053
+ carrier.completePreparation();
1054
+ owner.transfer(carrier);
1055
+ return carrier;
1056
+ }
1057
+ catch (error) {
1058
+ if (carrier !== undefined)
1059
+ await Promise.allSettled([carrier.close(), carrier.waitTermination()]);
1060
+ lastError = error;
1061
+ const code = error instanceof Error ? error.message : "";
1062
+ if (signal?.aborted || ["canceled", "credential_binding", "credential_untrusted", "credential_expired", "credential_closed", "configuration_capacity", "resource_exhausted", "admission_closed", "required_guarantee_unavailable"].includes(code))
1063
+ throw error;
1064
+ }
1065
+ }
1066
+ if (lastError !== undefined)
1067
+ throw lastError;
1068
+ throw new Error("connection_requirement_unavailable");
1069
+ }
1070
+ finally {
1071
+ owner.releaseUnused();
1072
+ }
1073
+ }
1074
+ export async function prepareNodeRawQUIC(environment, fields, options, driver, signal, admission, endpointRole = 0, physicalDialerRole = endpointRole, selectedCandidateIndex = fields.candidateIndex ?? -1, preparationBudget) {
1075
+ requireCredential(fields.accessClass === 0n, "credential_untrusted");
1076
+ const costs = nodeRawQUICAdmissionCosts(fields.maxFrame, options, environment.resources.runtimeBytes), refs = admission?.take(costs.slice(0, -1));
1077
+ let reserved;
1078
+ try {
1079
+ reserved = environment.admitDependencyPositions("node_raw_quic", costs[0][1], costs[1][1], options.applicationStreams + 1, refs, admission);
1080
+ }
1081
+ finally {
1082
+ for (const ref of refs ?? [])
1083
+ ref.release();
1084
+ }
1085
+ const { dependency, positions: prepaid } = reserved;
1086
+ let positions, carrier, work;
1087
+ try {
1088
+ positions = new NativeProviderPositions(prepaid);
1089
+ const ref = environment.reserveConnectionWork("node_raw_quic_policy", costs[costs.length - 1][1], admission);
1090
+ try {
1091
+ work = new CredentialWork(environment.resources, 16384, ref);
1092
+ }
1093
+ finally {
1094
+ ref.release();
1095
+ }
1096
+ const route = work.parse(fields.route, "Route", 16384);
1097
+ let endpoint, expectation;
1098
+ try {
1099
+ const leg = route.field(fields.pathKind === 0 ? "direct_leg" : endpointRole === 0 ? "client_leg" : "server_leg"), tls = route.field("tls_policy", leg, "Leg"), origin = route.optional("origin_policy", leg, "Leg");
1100
+ requireCredential(route.uint("path_kind") === BigInt(fields.pathKind) && route.uint("access_class", leg, "Leg") === 0n && route.uint("carrier", leg, "Leg") === (options.nativeCarrier === "webtransport" ? 2n : 0n) &&
1101
+ route.uint("endpoint_role", leg, "Leg") === (fields.pathKind === 0 ? 1n : BigInt(endpointRole)) && route.uint("dialer_role", leg, "Leg") === BigInt(physicalDialerRole) && route.uint("listener_role", leg, "Leg") === (fields.pathKind === 0 ? 1n : physicalDialerRole === 2 ? BigInt(endpointRole) : 2n) && route.text("path", leg, "Leg") === (options.nativeCarrier === "webtransport" ? `/flowersec/webtransport/v4/${fields.pathKind === 0 ? "direct" : "tunnel"}` : "") &&
1102
+ route.text("subprotocol", leg, "Leg") === "" && route.text("alpn", leg, "Leg") === (options.nativeCarrier === "webtransport" ? "h3" : fields.pathKind === 0 ? "flowersec-direct/4" : "flowersec-tunnel/4") && (origin < 0 ? options.nativeCarrier !== "webtransport" : route.doc.boolean(route.field("allow_absent", origin, "OriginPolicy"))), "credential_untrusted");
1103
+ endpoint = { host: route.text("host", leg, "Leg"), port: Number(route.uint("port", leg, "Leg")) };
1104
+ const mode = route.uint("mode", tls, "TLSPolicy"), pins = [], now = environment.clock.sample().requireInterval();
1105
+ if (mode === 0n)
1106
+ requireCredential(options.trustRootsDER !== undefined, "configuration_capacity");
1107
+ else {
1108
+ requireCredential(mode === 1n && route.uint("pin_kind", tls, "TLSPolicy") === 0n, "credential_untrusted");
1109
+ for (const pin of route.items("pins", tls, "TLSPolicy")) {
1110
+ const from = route.uint("not_before_ms", pin, "TLSPin"), until = route.uint("not_after_ms", pin, "TLSPin");
1111
+ if (now.lowerMS >= from && now.upperMS < until)
1112
+ pins.push({ from, until, digest: route.bytes("leaf_der_sha256", pin, "TLSPin") });
1113
+ }
1114
+ requireCredential(pins.length > 0 && pins.length <= 16, "credential_expired");
1115
+ }
1116
+ expectation = { serverName: endpoint.host, mode: mode === 0n ? "ca" : "pin", pins };
1117
+ }
1118
+ finally {
1119
+ route.close();
1120
+ work.close();
1121
+ work = undefined;
1122
+ }
1123
+ carrier = new NodeRawQUICCarrier(environment, dependency, positions, options, fields.preparationDeadline, "client", fields.pathKind === 0 ? "direct" : "tunnel", selectedCandidateIndex, preparationBudget);
1124
+ await carrier.prepare(driver, endpoint, expectation, signal);
1125
+ requireCredential((fields.required & 1n) === 0n || carrier.maxDatagramBytes() >= 76, "required_guarantee_unavailable");
1126
+ return carrier;
1127
+ }
1128
+ catch (error) {
1129
+ work?.close();
1130
+ if (carrier !== undefined)
1131
+ await Promise.allSettled([carrier.close(), carrier.waitTermination()]);
1132
+ else {
1133
+ positions?.close();
1134
+ for (const position of prepaid)
1135
+ position.closeAfterUse();
1136
+ dependency.release();
1137
+ }
1138
+ throw error;
1139
+ }
1140
+ }
1141
+ /** Relay dialing is selected from the original verified server Grant. No
1142
+ * endpoint Session fields or direct route are manufactured for this hop. */
1143
+ export function rawQUICRelayDialPolicy(environment, credentials, options, reference) {
1144
+ credentials.check(reference);
1145
+ const ref = environment.reserveConnectionWork("relay_quic_dial_policy", credentialWorkCharge(16384, environment.resources.runtimeBytes));
1146
+ let work;
1147
+ const bytes = credentials.descriptor(reference);
1148
+ try {
1149
+ work = new CredentialWork(environment.resources, 16384, ref);
1150
+ const leg = work.parse(bytes, "Leg", 16384, 16384, { selectors: { path_kind: "tunnel" } });
1151
+ try {
1152
+ const tls = leg.field("tls_policy"), origin = leg.optional("origin_policy");
1153
+ requireCredential(leg.uint("carrier") === (options.nativeCarrier === "webtransport" ? 2n : 0n) && leg.uint("access_class") === 0n && leg.uint("dialer_role") === 2n && leg.uint("listener_role") === BigInt(credentials.role) && leg.text("alpn") === (options.nativeCarrier === "webtransport" ? "h3" : "flowersec-tunnel/4") && leg.text("path") === (options.nativeCarrier === "webtransport" ? "/flowersec/webtransport/v4/tunnel" : "") && leg.text("subprotocol") === "" && (origin < 0 || leg.doc.boolean(leg.field("allow_absent", origin, "OriginPolicy"))));
1154
+ const host = leg.text("host"), port = Number(leg.uint("port")), mode = leg.uint("mode", tls, "TLSPolicy"), pins = [], now = environment.clock.sample().requireInterval();
1155
+ if (mode === 0n)
1156
+ requireCredential(options.trustRootsDER !== undefined, "configuration_capacity");
1157
+ else {
1158
+ requireCredential(mode === 1n && leg.uint("pin_kind", tls, "TLSPolicy") === 0n);
1159
+ for (const pin of leg.items("pins", tls, "TLSPolicy")) {
1160
+ const from = leg.uint("not_before_ms", pin, "TLSPin"), until = leg.uint("not_after_ms", pin, "TLSPin");
1161
+ if (now.lowerMS >= from && now.upperMS < until)
1162
+ pins.push({ from, until, digest: leg.bytes("leaf_der_sha256", pin, "TLSPin") });
1163
+ }
1164
+ requireCredential(pins.length > 0, "credential_expired");
1165
+ }
1166
+ return Object.freeze({ endpoint: Object.freeze({ host, port }), expectation: Object.freeze({ mode: mode === 0n ? "ca" : "pin", serverName: host, pins: Object.freeze(pins) }) });
1167
+ }
1168
+ finally {
1169
+ leg.close();
1170
+ }
1171
+ }
1172
+ finally {
1173
+ bytes.fill(0);
1174
+ work?.close();
1175
+ ref.release();
1176
+ }
1177
+ }