@labacacia/nps-sdk 1.0.0-alpha.6 → 1.0.0-alpha.7

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 (365) hide show
  1. package/CHANGELOG.cn.md +115 -0
  2. package/CHANGELOG.md +124 -0
  3. package/README.cn.md +3 -1
  4. package/README.md +3 -1
  5. package/dist/core/anchor-cache.d.ts +42 -0
  6. package/dist/core/anchor-cache.d.ts.map +1 -0
  7. package/dist/core/anchor-cache.js +104 -0
  8. package/dist/core/anchor-cache.js.map +1 -0
  9. package/dist/core/cache.d.ts +14 -0
  10. package/dist/core/cache.d.ts.map +1 -0
  11. package/dist/core/cache.js +80 -0
  12. package/dist/core/cache.js.map +1 -0
  13. package/dist/core/canonical-json.d.ts +12 -0
  14. package/dist/core/canonical-json.d.ts.map +1 -0
  15. package/dist/core/canonical-json.js +44 -0
  16. package/dist/core/canonical-json.js.map +1 -0
  17. package/dist/core/codec.d.ts +32 -0
  18. package/dist/core/codec.d.ts.map +1 -0
  19. package/dist/core/codec.js +119 -0
  20. package/dist/core/codec.js.map +1 -0
  21. package/dist/core/codecs/index.d.ts +4 -0
  22. package/dist/core/codecs/index.d.ts.map +1 -0
  23. package/{src/core/codecs/index.ts → dist/core/codecs/index.js} +1 -0
  24. package/dist/core/codecs/index.js.map +1 -0
  25. package/dist/core/codecs/ncp-codec.d.ts +39 -0
  26. package/dist/core/codecs/ncp-codec.d.ts.map +1 -0
  27. package/dist/core/codecs/ncp-codec.js +93 -0
  28. package/dist/core/codecs/ncp-codec.js.map +1 -0
  29. package/dist/core/codecs/tier1-json-codec.d.ts +10 -0
  30. package/dist/core/codecs/tier1-json-codec.d.ts.map +1 -0
  31. package/{src/core/codecs/tier1-json-codec.ts → dist/core/codecs/tier1-json-codec.js} +11 -16
  32. package/dist/core/codecs/tier1-json-codec.js.map +1 -0
  33. package/dist/core/codecs/tier2-msgpack-codec.d.ts +10 -0
  34. package/dist/core/codecs/tier2-msgpack-codec.d.ts.map +1 -0
  35. package/{src/core/codecs/tier2-msgpack-codec.ts → dist/core/codecs/tier2-msgpack-codec.js} +10 -14
  36. package/dist/core/codecs/tier2-msgpack-codec.js.map +1 -0
  37. package/dist/core/crypto-provider.d.ts +31 -0
  38. package/dist/core/crypto-provider.d.ts.map +1 -0
  39. package/dist/core/crypto-provider.js +10 -0
  40. package/dist/core/crypto-provider.js.map +1 -0
  41. package/dist/core/exceptions.d.ts +27 -0
  42. package/dist/core/exceptions.d.ts.map +1 -0
  43. package/dist/core/exceptions.js +52 -0
  44. package/dist/core/exceptions.js.map +1 -0
  45. package/dist/core/frame-header.d.ts +87 -0
  46. package/dist/core/frame-header.d.ts.map +1 -0
  47. package/dist/core/frame-header.js +185 -0
  48. package/dist/core/frame-header.js.map +1 -0
  49. package/dist/core/frame-registry.d.ts +35 -0
  50. package/dist/core/frame-registry.d.ts.map +1 -0
  51. package/dist/core/frame-registry.js +63 -0
  52. package/dist/core/frame-registry.js.map +1 -0
  53. package/dist/core/frames.d.ts +81 -0
  54. package/dist/core/frames.d.ts.map +1 -0
  55. package/dist/core/frames.js +154 -0
  56. package/dist/core/frames.js.map +1 -0
  57. package/dist/core/index.d.ts +11 -0
  58. package/dist/core/index.d.ts.map +1 -0
  59. package/{src/core/index.ts → dist/core/index.js} +3 -23
  60. package/dist/core/index.js.map +1 -0
  61. package/dist/core/registry.d.ts +11 -0
  62. package/dist/core/registry.d.ts.map +1 -0
  63. package/dist/core/registry.js +17 -0
  64. package/dist/core/registry.js.map +1 -0
  65. package/dist/core/status-codes.d.ts +29 -0
  66. package/dist/core/status-codes.d.ts.map +1 -0
  67. package/dist/core/status-codes.js +39 -0
  68. package/dist/core/status-codes.js.map +1 -0
  69. package/dist/index.d.ts +2 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/{src/index.ts → dist/index.js} +1 -1
  72. package/dist/index.js.map +1 -0
  73. package/dist/ncp/frames/anchor-frame.d.ts +29 -0
  74. package/dist/ncp/frames/anchor-frame.d.ts.map +1 -0
  75. package/dist/ncp/frames/anchor-frame.js +54 -0
  76. package/dist/ncp/frames/anchor-frame.js.map +1 -0
  77. package/dist/ncp/frames/caps-frame.d.ts +29 -0
  78. package/dist/ncp/frames/caps-frame.d.ts.map +1 -0
  79. package/dist/ncp/frames/caps-frame.js +29 -0
  80. package/dist/ncp/frames/caps-frame.js.map +1 -0
  81. package/dist/ncp/frames/diff-frame.d.ts +32 -0
  82. package/dist/ncp/frames/diff-frame.d.ts.map +1 -0
  83. package/dist/ncp/frames/diff-frame.js +37 -0
  84. package/dist/ncp/frames/diff-frame.js.map +1 -0
  85. package/dist/ncp/frames/error-frame.d.ts +16 -0
  86. package/dist/ncp/frames/error-frame.d.ts.map +1 -0
  87. package/dist/ncp/frames/error-frame.js +13 -0
  88. package/dist/ncp/frames/error-frame.js.map +1 -0
  89. package/dist/ncp/frames/hello-frame.d.ts +21 -0
  90. package/dist/ncp/frames/hello-frame.d.ts.map +1 -0
  91. package/dist/ncp/frames/hello-frame.js +25 -0
  92. package/dist/ncp/frames/hello-frame.js.map +1 -0
  93. package/dist/ncp/frames/stream-frame.d.ts +16 -0
  94. package/dist/ncp/frames/stream-frame.d.ts.map +1 -0
  95. package/dist/ncp/frames/stream-frame.js +18 -0
  96. package/dist/ncp/frames/stream-frame.js.map +1 -0
  97. package/dist/ncp/frames.d.ts +94 -0
  98. package/dist/ncp/frames.d.ts.map +1 -0
  99. package/dist/ncp/frames.js +192 -0
  100. package/dist/ncp/frames.js.map +1 -0
  101. package/dist/ncp/handshake.d.ts +30 -0
  102. package/dist/ncp/handshake.d.ts.map +1 -0
  103. package/dist/ncp/handshake.js +80 -0
  104. package/dist/ncp/handshake.js.map +1 -0
  105. package/dist/ncp/index.d.ts +12 -0
  106. package/dist/ncp/index.d.ts.map +1 -0
  107. package/{src/ncp/index.ts → dist/ncp/index.js} +1 -0
  108. package/dist/ncp/index.js.map +1 -0
  109. package/dist/ncp/ncp-error-codes.d.ts +23 -0
  110. package/dist/ncp/ncp-error-codes.d.ts.map +1 -0
  111. package/dist/ncp/ncp-error-codes.js +34 -0
  112. package/dist/ncp/ncp-error-codes.js.map +1 -0
  113. package/dist/ncp/ncp-patch-format.d.ts +7 -0
  114. package/dist/ncp/ncp-patch-format.d.ts.map +1 -0
  115. package/dist/ncp/ncp-patch-format.js +13 -0
  116. package/dist/ncp/ncp-patch-format.js.map +1 -0
  117. package/dist/ncp/preamble.d.ts +47 -0
  118. package/dist/ncp/preamble.d.ts.map +1 -0
  119. package/dist/ncp/preamble.js +74 -0
  120. package/dist/ncp/preamble.js.map +1 -0
  121. package/dist/ncp/registry.d.ts +3 -0
  122. package/dist/ncp/registry.d.ts.map +1 -0
  123. package/dist/ncp/registry.js +13 -0
  124. package/dist/ncp/registry.js.map +1 -0
  125. package/dist/ncp/stream-manager.d.ts +57 -0
  126. package/dist/ncp/stream-manager.d.ts.map +1 -0
  127. package/dist/ncp/stream-manager.js +163 -0
  128. package/dist/ncp/stream-manager.js.map +1 -0
  129. package/dist/ndp/dns-txt.d.ts +35 -0
  130. package/dist/ndp/dns-txt.d.ts.map +1 -0
  131. package/dist/ndp/dns-txt.js +67 -0
  132. package/dist/ndp/dns-txt.js.map +1 -0
  133. package/dist/ndp/frames.d.ts +56 -0
  134. package/dist/ndp/frames.d.ts.map +1 -0
  135. package/dist/ndp/frames.js +87 -0
  136. package/dist/ndp/frames.js.map +1 -0
  137. package/dist/ndp/index.d.ts +6 -0
  138. package/dist/ndp/index.d.ts.map +1 -0
  139. package/{src/ndp/index.ts → dist/ndp/index.js} +1 -1
  140. package/dist/ndp/index.js.map +1 -0
  141. package/dist/ndp/ndp-registry.d.ts +13 -0
  142. package/dist/ndp/ndp-registry.d.ts.map +1 -0
  143. package/dist/ndp/ndp-registry.js +104 -0
  144. package/dist/ndp/ndp-registry.js.map +1 -0
  145. package/dist/ndp/registry.d.ts +3 -0
  146. package/dist/ndp/registry.d.ts.map +1 -0
  147. package/dist/ndp/registry.js +10 -0
  148. package/dist/ndp/registry.js.map +1 -0
  149. package/dist/ndp/validator.d.ts +18 -0
  150. package/dist/ndp/validator.d.ts.map +1 -0
  151. package/dist/ndp/validator.js +48 -0
  152. package/dist/ndp/validator.js.map +1 -0
  153. package/dist/nip/acme/client.d.ts +31 -0
  154. package/dist/nip/acme/client.d.ts.map +1 -0
  155. package/dist/nip/acme/client.js +136 -0
  156. package/dist/nip/acme/client.js.map +1 -0
  157. package/dist/nip/acme/index.d.ts +6 -0
  158. package/dist/nip/acme/index.d.ts.map +1 -0
  159. package/{src/nip/acme/index.ts → dist/nip/acme/index.js} +1 -1
  160. package/dist/nip/acme/index.js.map +1 -0
  161. package/dist/nip/acme/jws.d.ts +31 -0
  162. package/dist/nip/acme/jws.d.ts.map +1 -0
  163. package/dist/nip/acme/jws.js +76 -0
  164. package/dist/nip/acme/jws.js.map +1 -0
  165. package/dist/nip/acme/messages.d.ts +71 -0
  166. package/dist/nip/acme/messages.d.ts.map +1 -0
  167. package/dist/nip/acme/messages.js +4 -0
  168. package/dist/nip/acme/messages.js.map +1 -0
  169. package/dist/nip/acme/server.d.ts +41 -0
  170. package/dist/nip/acme/server.d.ts.map +1 -0
  171. package/dist/nip/acme/server.js +458 -0
  172. package/dist/nip/acme/server.js.map +1 -0
  173. package/dist/nip/acme/wire.d.ts +19 -0
  174. package/dist/nip/acme/wire.d.ts.map +1 -0
  175. package/dist/nip/acme/wire.js +21 -0
  176. package/dist/nip/acme/wire.js.map +1 -0
  177. package/dist/nip/assurance-level.d.ts +19 -0
  178. package/dist/nip/assurance-level.d.ts.map +1 -0
  179. package/dist/nip/assurance-level.js +38 -0
  180. package/dist/nip/assurance-level.js.map +1 -0
  181. package/dist/nip/cert-format.d.ts +5 -0
  182. package/dist/nip/cert-format.d.ts.map +1 -0
  183. package/dist/nip/cert-format.js +6 -0
  184. package/dist/nip/cert-format.js.map +1 -0
  185. package/dist/nip/error-codes.d.ts +25 -0
  186. package/dist/nip/error-codes.d.ts.map +1 -0
  187. package/{src/nip/error-codes.ts → dist/nip/error-codes.js} +19 -25
  188. package/dist/nip/error-codes.js.map +1 -0
  189. package/dist/nip/frames.d.ts +53 -0
  190. package/dist/nip/frames.d.ts.map +1 -0
  191. package/dist/nip/frames.js +106 -0
  192. package/dist/nip/frames.js.map +1 -0
  193. package/dist/nip/identity.d.ts +18 -0
  194. package/dist/nip/identity.d.ts.map +1 -0
  195. package/dist/nip/identity.js +94 -0
  196. package/dist/nip/identity.js.map +1 -0
  197. package/dist/nip/index.d.ts +11 -0
  198. package/dist/nip/index.d.ts.map +1 -0
  199. package/{src/nip/index.ts → dist/nip/index.js} +3 -2
  200. package/dist/nip/index.js.map +1 -0
  201. package/dist/nip/registry.d.ts +3 -0
  202. package/dist/nip/registry.d.ts.map +1 -0
  203. package/dist/nip/registry.js +10 -0
  204. package/dist/nip/registry.js.map +1 -0
  205. package/dist/nip/reputation-client.d.ts +116 -0
  206. package/dist/nip/reputation-client.d.ts.map +1 -0
  207. package/dist/nip/reputation-client.js +261 -0
  208. package/dist/nip/reputation-client.js.map +1 -0
  209. package/dist/nip/verifier.d.ts +23 -0
  210. package/dist/nip/verifier.d.ts.map +1 -0
  211. package/dist/nip/verifier.js +90 -0
  212. package/dist/nip/verifier.js.map +1 -0
  213. package/dist/nip/x509/builder.d.ts +35 -0
  214. package/dist/nip/x509/builder.d.ts.map +1 -0
  215. package/dist/nip/x509/builder.js +59 -0
  216. package/dist/nip/x509/builder.js.map +1 -0
  217. package/dist/nip/x509/index.d.ts +4 -0
  218. package/dist/nip/x509/index.d.ts.map +1 -0
  219. package/{src/nip/x509/index.ts → dist/nip/x509/index.js} +1 -1
  220. package/dist/nip/x509/index.js.map +1 -0
  221. package/dist/nip/x509/oids.d.ts +16 -0
  222. package/dist/nip/x509/oids.d.ts.map +1 -0
  223. package/{src/nip/x509/oids.ts → dist/nip/x509/oids.js} +5 -10
  224. package/dist/nip/x509/oids.js.map +1 -0
  225. package/dist/nip/x509/verifier.d.ts +26 -0
  226. package/dist/nip/x509/verifier.d.ts.map +1 -0
  227. package/dist/nip/x509/verifier.js +171 -0
  228. package/dist/nip/x509/verifier.js.map +1 -0
  229. package/dist/nop/client.d.ts +34 -0
  230. package/dist/nop/client.d.ts.map +1 -0
  231. package/dist/nop/client.js +90 -0
  232. package/dist/nop/client.js.map +1 -0
  233. package/dist/nop/frames.d.ts +65 -0
  234. package/dist/nop/frames.d.ts.map +1 -0
  235. package/dist/nop/frames.js +148 -0
  236. package/dist/nop/frames.js.map +1 -0
  237. package/dist/nop/index.d.ts +5 -0
  238. package/dist/nop/index.d.ts.map +1 -0
  239. package/{src/nop/index.ts → dist/nop/index.js} +1 -1
  240. package/dist/nop/index.js.map +1 -0
  241. package/dist/nop/models.d.ts +58 -0
  242. package/dist/nop/models.d.ts.map +1 -0
  243. package/dist/nop/models.js +50 -0
  244. package/dist/nop/models.js.map +1 -0
  245. package/dist/nop/nop-types.d.ts +136 -0
  246. package/dist/nop/nop-types.d.ts.map +1 -0
  247. package/dist/nop/nop-types.js +44 -0
  248. package/dist/nop/nop-types.js.map +1 -0
  249. package/dist/nop/registry.d.ts +3 -0
  250. package/dist/nop/registry.d.ts.map +1 -0
  251. package/dist/nop/registry.js +11 -0
  252. package/dist/nop/registry.js.map +1 -0
  253. package/dist/nwp/anchor-client.d.ts +109 -0
  254. package/dist/nwp/anchor-client.d.ts.map +1 -0
  255. package/dist/nwp/anchor-client.js +279 -0
  256. package/dist/nwp/anchor-client.js.map +1 -0
  257. package/dist/nwp/client.d.ts +22 -0
  258. package/dist/nwp/client.d.ts.map +1 -0
  259. package/dist/nwp/client.js +101 -0
  260. package/dist/nwp/client.js.map +1 -0
  261. package/dist/nwp/frames.d.ts +46 -0
  262. package/dist/nwp/frames.d.ts.map +1 -0
  263. package/dist/nwp/frames.js +81 -0
  264. package/dist/nwp/frames.js.map +1 -0
  265. package/dist/nwp/index.d.ts +5 -0
  266. package/dist/nwp/index.d.ts.map +1 -0
  267. package/{src/nwp/index.ts → dist/nwp/index.js} +2 -1
  268. package/dist/nwp/index.js.map +1 -0
  269. package/dist/nwp/registry.d.ts +3 -0
  270. package/dist/nwp/registry.d.ts.map +1 -0
  271. package/dist/nwp/registry.js +9 -0
  272. package/dist/nwp/registry.js.map +1 -0
  273. package/dist/setup.d.ts +10 -0
  274. package/dist/setup.d.ts.map +1 -0
  275. package/{src/setup.ts → dist/setup.js} +13 -16
  276. package/dist/setup.js.map +1 -0
  277. package/package.json +12 -1
  278. package/CONTRIBUTING.cn.md +0 -35
  279. package/CONTRIBUTING.md +0 -35
  280. package/nip-ca-server/Dockerfile +0 -27
  281. package/nip-ca-server/README.md +0 -45
  282. package/nip-ca-server/db/001_init.sql +0 -25
  283. package/nip-ca-server/docker-compose.yml +0 -29
  284. package/nip-ca-server/package.json +0 -23
  285. package/nip-ca-server/src/ca.ts +0 -155
  286. package/nip-ca-server/src/db.ts +0 -104
  287. package/nip-ca-server/src/index.ts +0 -157
  288. package/nip-ca-server/tsconfig.json +0 -13
  289. package/src/core/anchor-cache.ts +0 -129
  290. package/src/core/cache.ts +0 -93
  291. package/src/core/canonical-json.ts +0 -50
  292. package/src/core/codec.ts +0 -158
  293. package/src/core/codecs/ncp-codec.ts +0 -170
  294. package/src/core/crypto-provider.ts +0 -47
  295. package/src/core/exceptions.ts +0 -57
  296. package/src/core/frame-header.ts +0 -282
  297. package/src/core/frame-registry.ts +0 -91
  298. package/src/core/frames.ts +0 -184
  299. package/src/core/registry.ts +0 -28
  300. package/src/core/status-codes.ts +0 -47
  301. package/src/ncp/frames/anchor-frame.ts +0 -87
  302. package/src/ncp/frames/caps-frame.ts +0 -59
  303. package/src/ncp/frames/diff-frame.ts +0 -69
  304. package/src/ncp/frames/error-frame.ts +0 -26
  305. package/src/ncp/frames/hello-frame.ts +0 -50
  306. package/src/ncp/frames/stream-frame.ts +0 -35
  307. package/src/ncp/frames.ts +0 -251
  308. package/src/ncp/handshake.ts +0 -95
  309. package/src/ncp/ncp-error-codes.ts +0 -36
  310. package/src/ncp/ncp-patch-format.ts +0 -16
  311. package/src/ncp/preamble.ts +0 -79
  312. package/src/ncp/registry.ts +0 -15
  313. package/src/ncp/stream-manager.ts +0 -212
  314. package/src/ndp/dns-txt.ts +0 -86
  315. package/src/ndp/frames.ts +0 -124
  316. package/src/ndp/ndp-registry.ts +0 -116
  317. package/src/ndp/registry.ts +0 -12
  318. package/src/ndp/validator.ts +0 -64
  319. package/src/nip/acme/client.ts +0 -185
  320. package/src/nip/acme/jws.ts +0 -109
  321. package/src/nip/acme/messages.ts +0 -85
  322. package/src/nip/acme/server.ts +0 -480
  323. package/src/nip/acme/wire.ts +0 -24
  324. package/src/nip/assurance-level.ts +0 -40
  325. package/src/nip/cert-format.ts +0 -9
  326. package/src/nip/frames.ts +0 -138
  327. package/src/nip/identity.ts +0 -113
  328. package/src/nip/registry.ts +0 -12
  329. package/src/nip/verifier.ts +0 -122
  330. package/src/nip/x509/builder.ts +0 -91
  331. package/src/nip/x509/verifier.ts +0 -214
  332. package/src/nop/client.ts +0 -103
  333. package/src/nop/frames.ts +0 -181
  334. package/src/nop/models.ts +0 -79
  335. package/src/nop/nop-types.ts +0 -208
  336. package/src/nop/registry.ts +0 -13
  337. package/src/nwp/client.ts +0 -114
  338. package/src/nwp/frames.ts +0 -116
  339. package/src/nwp/registry.ts +0 -11
  340. package/tests/_rfc0002-keys.ts +0 -57
  341. package/tests/core/anchor-cache.test.ts +0 -242
  342. package/tests/core/codec.test.ts +0 -205
  343. package/tests/core/frame-registry.test.ts +0 -46
  344. package/tests/core.test.ts +0 -327
  345. package/tests/ncp/diff-binary-bitset.test.ts +0 -107
  346. package/tests/ncp/e2e-enc-reject.test.ts +0 -93
  347. package/tests/ncp/err-error-frame.test.ts +0 -152
  348. package/tests/ncp/frames.test.ts +0 -359
  349. package/tests/ncp/framing.test.ts +0 -233
  350. package/tests/ncp/hello-frame.test.ts +0 -122
  351. package/tests/ncp/inline-anchor.test.ts +0 -88
  352. package/tests/ncp/preamble.test.ts +0 -93
  353. package/tests/ncp/security.test.ts +0 -184
  354. package/tests/ncp/stream-window.test.ts +0 -167
  355. package/tests/ncp/stream.test.ts +0 -242
  356. package/tests/ncp/version-negotiation.test.ts +0 -123
  357. package/tests/ndp.test.ts +0 -377
  358. package/tests/nip-acme-agent01.test.ts +0 -192
  359. package/tests/nip-x509.test.ts +0 -280
  360. package/tests/nip.test.ts +0 -184
  361. package/tests/nop.test.ts +0 -344
  362. package/tests/nwp.test.ts +0 -237
  363. package/tsconfig.json +0 -20
  364. package/tsup.config.ts +0 -20
  365. package/vitest.config.ts +0 -10
@@ -0,0 +1,74 @@
1
+ // Copyright 2026 INNO LOTUS PTY LTD
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * NCP native-mode connection preamble — the 8-byte ASCII constant
5
+ * `"NPS/1.0\n"` that every native-mode client MUST emit immediately
6
+ * after the transport handshake and before its first HelloFrame.
7
+ * Defined by NPS-RFC-0001 and NPS-1 NCP §2.6.1.
8
+ *
9
+ * HTTP-mode connections do not use the preamble.
10
+ */
11
+ export const PREAMBLE_LITERAL = "NPS/1.0\n";
12
+ export const PREAMBLE_LENGTH = 8;
13
+ export const PREAMBLE_BYTES = new TextEncoder().encode(PREAMBLE_LITERAL);
14
+ /** Validation timeout in milliseconds (NPS-RFC-0001 §4.1). */
15
+ export const PREAMBLE_READ_TIMEOUT_MS = 10_000;
16
+ /** Maximum delay before closing after a mismatch, in milliseconds. */
17
+ export const PREAMBLE_CLOSE_DEADLINE_MS = 500;
18
+ export const PREAMBLE_ERROR_CODE = "NCP-PREAMBLE-INVALID";
19
+ export const PREAMBLE_STATUS_CODE = "NPS-PROTO-PREAMBLE-INVALID";
20
+ export class NcpPreambleInvalidError extends Error {
21
+ errorCode = PREAMBLE_ERROR_CODE;
22
+ statusCode = PREAMBLE_STATUS_CODE;
23
+ constructor(reason) {
24
+ super(reason);
25
+ this.name = "NcpPreambleInvalidError";
26
+ }
27
+ }
28
+ /**
29
+ * Returns `true` iff `buf` starts with the 8-byte NPS/1.0 preamble.
30
+ * Safe to call with shorter buffers.
31
+ */
32
+ export function preambleMatches(buf) {
33
+ if (buf.length < PREAMBLE_LENGTH)
34
+ return false;
35
+ for (let i = 0; i < PREAMBLE_LENGTH; i++) {
36
+ if (buf[i] !== PREAMBLE_BYTES[i])
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+ /**
42
+ * Validates a presumed-preamble buffer.
43
+ * Returns `{ valid: true, reason: "" }` on success or `{ valid: false, reason }` on failure.
44
+ */
45
+ export function tryValidatePreamble(buf) {
46
+ if (buf.length < PREAMBLE_LENGTH) {
47
+ return { valid: false, reason: `short read (${buf.length}/${PREAMBLE_LENGTH} bytes); peer is not speaking NCP` };
48
+ }
49
+ if (!preambleMatches(buf)) {
50
+ // "NPS/" = 0x4E 0x50 0x53 0x2F
51
+ const isNps = buf[0] === 0x4e && buf[1] === 0x50 && buf[2] === 0x53 && buf[3] === 0x2f;
52
+ if (isNps) {
53
+ return { valid: false, reason: "future-major-version NPS preamble; close with NPS-PREAMBLE-UNSUPPORTED-VERSION diagnostic" };
54
+ }
55
+ return { valid: false, reason: "preamble mismatch; peer is not speaking NPS/1.x" };
56
+ }
57
+ return { valid: true, reason: "" };
58
+ }
59
+ /**
60
+ * Validates a presumed-preamble buffer, throwing {@link NcpPreambleInvalidError} on mismatch.
61
+ */
62
+ export function validatePreamble(buf) {
63
+ const { valid, reason } = tryValidatePreamble(buf);
64
+ if (!valid)
65
+ throw new NcpPreambleInvalidError(reason);
66
+ }
67
+ /**
68
+ * Writes the preamble bytes to `writer`.
69
+ * `writer` must expose a `write(buf: Uint8Array): void` method (e.g. Node.js `net.Socket`).
70
+ */
71
+ export function writePreamble(writer) {
72
+ writer.write(PREAMBLE_BYTES);
73
+ }
74
+ //# sourceMappingURL=preamble.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preamble.js","sourceRoot":"","sources":["../../src/ncp/preamble.ts"],"names":[],"mappings":"AAAA,o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e,mCAAmC,EAAE,CAAC;IACnH,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,+BAA+B;QAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;QACvF,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,2FAA2F,EAAE,CAAC;QAC/H,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,iDAAiD,EAAE,CAAC;IACrF,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAe;IAC9C,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAwC;IACpE,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { FrameRegistry } from "../core/registry.js";
2
+ export declare function registerNcpFrames(registry: FrameRegistry): void;
3
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/ncp/registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAO/D"}
@@ -0,0 +1,13 @@
1
+ // Copyright 2026 INNO LOTUS PTY LTD
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { FrameType } from "../core/frames.js";
4
+ import { AnchorFrame, CapsFrame, DiffFrame, ErrorFrame, HelloFrame, StreamFrame } from "./frames.js";
5
+ export function registerNcpFrames(registry) {
6
+ registry.register(FrameType.ANCHOR, AnchorFrame);
7
+ registry.register(FrameType.DIFF, DiffFrame);
8
+ registry.register(FrameType.STREAM, StreamFrame);
9
+ registry.register(FrameType.CAPS, CapsFrame);
10
+ registry.register(FrameType.HELLO, HelloFrame);
11
+ registry.register(FrameType.ERROR, ErrorFrame);
12
+ }
13
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/ncp/registry.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,sCAAsC;AAGtC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAErG,MAAM,UAAU,iBAAiB,CAAC,QAAuB;IACvD,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAI,SAAS,CAAC,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAI,SAAS,CAAC,CAAC;IAC/C,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAG,UAAU,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAG,UAAU,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { StreamFrame } from "./frames/stream-frame.js";
2
+ /**
3
+ * Manages concurrent StreamFrame streams.
4
+ *
5
+ * - Tracks active streams by stream_id
6
+ * - Validates sequential seq numbers
7
+ * - Enforces max concurrent stream limit (NPS-1 §7.3, default 32)
8
+ * - Detects early termination via error_code
9
+ * - Enforces window-based flow control on outgoing streams (NCP-S-07–11)
10
+ */
11
+ export declare class StreamManager {
12
+ private readonly streams;
13
+ private readonly outgoing;
14
+ private readonly maxConcurrent;
15
+ constructor(options?: {
16
+ maxConcurrent?: number;
17
+ });
18
+ /**
19
+ * Receive a StreamFrame chunk.
20
+ *
21
+ * @returns true if stream is complete (is_last=true or error_code set).
22
+ * @throws {NcpError} NCP-STREAM-LIMIT-EXCEEDED if too many concurrent streams.
23
+ * @throws {NcpError} NCP-STREAM-NOT-FOUND if frame.seq > 0 for a stream that was never opened.
24
+ * @throws {NcpError} NPS-CLIENT-CONFLICT if the stream_id was already completed (stream-id reuse; see test_cases NCP-S-04).
25
+ * @throws {NcpError} NCP-STREAM-SEQ-GAP if sequence number is not expected.
26
+ */
27
+ receive(frame: StreamFrame): boolean;
28
+ /**
29
+ * Send a StreamFrame on an outgoing stream, enforcing window-based flow control.
30
+ *
31
+ * - seq=0 with window_size initialises remainingWindow (no decrement for opening frame).
32
+ * - Subsequent sends decrement remainingWindow when flow control is active.
33
+ * - Throws NCP-STREAM-WINDOW-OVERFLOW when remainingWindow === 0.
34
+ *
35
+ * @throws {NcpError} NCP-STREAM-WINDOW-OVERFLOW if window is exhausted.
36
+ */
37
+ send(frame: StreamFrame): void;
38
+ /**
39
+ * Update the send window for a stream.
40
+ *
41
+ * Called when a reverse-direction StreamFrame arrives with data=[] and window_size set.
42
+ * Replaces remainingWindow with new_size. Sets paused=true when new_size === 0.
43
+ */
44
+ updateWindow(streamId: string, newSize: number): void;
45
+ /**
46
+ * Returns true when the outgoing stream is paused (window=0 was received).
47
+ * Resumes (returns false) once a non-zero window update arrives.
48
+ */
49
+ isPaused(streamId: string): boolean;
50
+ /** Get reassembled data for a completed stream. */
51
+ getData(streamId: string): unknown[] | null;
52
+ /** Get error code if stream terminated with error. */
53
+ getError(streamId: string): string | undefined;
54
+ /** Number of active (non-completed) streams. */
55
+ get activeCount(): number;
56
+ }
57
+ //# sourceMappingURL=stream-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-manager.d.ts","sourceRoot":"","sources":["../../src/ncp/stream-manager.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAgB5D;;;;;;;;GAQG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmC;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;IAIhD;;;;;;;;OAQG;IACH,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAwEpC;;;;;;;;OAQG;IACH,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IA8B9B;;;;;OAKG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAerD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAInC,mDAAmD;IACnD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,IAAI;IAM3C,sDAAsD;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI9C,gDAAgD;IAChD,IAAI,WAAW,IAAI,MAAM,CAMxB;CACF"}
@@ -0,0 +1,163 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
3
+ //
4
+ // StreamManager — Concurrent stream tracking, sequence validation, flow control
5
+ // NPS-1 §4.3, §7.3
6
+ import { NcpError } from "../core/frame-header.js";
7
+ import { NCP_ERROR_CODES } from "./ncp-error-codes.js";
8
+ /**
9
+ * Manages concurrent StreamFrame streams.
10
+ *
11
+ * - Tracks active streams by stream_id
12
+ * - Validates sequential seq numbers
13
+ * - Enforces max concurrent stream limit (NPS-1 §7.3, default 32)
14
+ * - Detects early termination via error_code
15
+ * - Enforces window-based flow control on outgoing streams (NCP-S-07–11)
16
+ */
17
+ export class StreamManager {
18
+ streams = new Map();
19
+ outgoing = new Map();
20
+ maxConcurrent;
21
+ constructor(options) {
22
+ this.maxConcurrent = options?.maxConcurrent ?? 32;
23
+ }
24
+ /**
25
+ * Receive a StreamFrame chunk.
26
+ *
27
+ * @returns true if stream is complete (is_last=true or error_code set).
28
+ * @throws {NcpError} NCP-STREAM-LIMIT-EXCEEDED if too many concurrent streams.
29
+ * @throws {NcpError} NCP-STREAM-NOT-FOUND if frame.seq > 0 for a stream that was never opened.
30
+ * @throws {NcpError} NPS-CLIENT-CONFLICT if the stream_id was already completed (stream-id reuse; see test_cases NCP-S-04).
31
+ * @throws {NcpError} NCP-STREAM-SEQ-GAP if sequence number is not expected.
32
+ */
33
+ receive(frame) {
34
+ let stream = this.streams.get(frame.stream_id);
35
+ if (!stream) {
36
+ // A stream is opened only by seq=0. Any other seq on an unknown stream_id
37
+ // means the opener was never seen (NCP-S-13: unknown stream_id).
38
+ if (frame.seq !== 0) {
39
+ throw new NcpError(NCP_ERROR_CODES.NCP_STREAM_NOT_FOUND, `Unknown stream_id ${frame.stream_id} — first frame must have seq=0`);
40
+ }
41
+ // New stream — check concurrent limit
42
+ if (this.streams.size >= this.maxConcurrent) {
43
+ throw new NcpError(NCP_ERROR_CODES.NCP_STREAM_LIMIT_EXCEEDED, `Max concurrent streams (${this.maxConcurrent}) exceeded`);
44
+ }
45
+ stream = {
46
+ streamId: frame.stream_id,
47
+ expectedSeq: 0,
48
+ chunks: [],
49
+ completed: false,
50
+ };
51
+ this.streams.set(frame.stream_id, stream);
52
+ }
53
+ // Reject writes to completed streams. Per test_cases NCP-S-04, the spec does
54
+ // not assign a dedicated NCP code for stream-id reuse; interim mapping uses
55
+ // the NPS-level NPS-CLIENT-CONFLICT until a spec-side code is added.
56
+ if (stream.completed) {
57
+ throw new NcpError("NPS-CLIENT-CONFLICT", `Stream ${frame.stream_id} is already completed — cannot reuse stream_id`);
58
+ }
59
+ // Sequence validation
60
+ if (frame.seq !== stream.expectedSeq) {
61
+ // Duplicate detection — same seq as last accepted
62
+ if (frame.seq < stream.expectedSeq) {
63
+ // Ignore duplicate (idempotent)
64
+ return false;
65
+ }
66
+ throw new NcpError(NCP_ERROR_CODES.NCP_STREAM_SEQ_GAP, `Expected seq ${stream.expectedSeq}, got ${frame.seq} on stream ${frame.stream_id}`);
67
+ }
68
+ stream.chunks.push(frame.data);
69
+ stream.expectedSeq = frame.seq + 1;
70
+ // Early termination via error_code
71
+ if (frame.error_code) {
72
+ stream.completed = true;
73
+ stream.errorCode = frame.error_code;
74
+ return true;
75
+ }
76
+ // Normal completion
77
+ if (frame.is_last) {
78
+ stream.completed = true;
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ /**
84
+ * Send a StreamFrame on an outgoing stream, enforcing window-based flow control.
85
+ *
86
+ * - seq=0 with window_size initialises remainingWindow (no decrement for opening frame).
87
+ * - Subsequent sends decrement remainingWindow when flow control is active.
88
+ * - Throws NCP-STREAM-WINDOW-OVERFLOW when remainingWindow === 0.
89
+ *
90
+ * @throws {NcpError} NCP-STREAM-WINDOW-OVERFLOW if window is exhausted.
91
+ */
92
+ send(frame) {
93
+ let out = this.outgoing.get(frame.stream_id);
94
+ if (!out) {
95
+ out = {
96
+ streamId: frame.stream_id,
97
+ remainingWindow: undefined,
98
+ paused: false,
99
+ };
100
+ this.outgoing.set(frame.stream_id, out);
101
+ }
102
+ // Opening frame: initialise window from window_size if provided.
103
+ if (frame.seq === 0 && frame.window_size !== undefined) {
104
+ out.remainingWindow = frame.window_size;
105
+ return; // opening frame does not consume a window slot
106
+ }
107
+ // Flow control check for subsequent frames.
108
+ if (out.remainingWindow !== undefined) {
109
+ if (out.remainingWindow === 0) {
110
+ throw new NcpError(NCP_ERROR_CODES.NCP_STREAM_WINDOW_OVERFLOW, `Window exhausted on stream ${frame.stream_id}`);
111
+ }
112
+ out.remainingWindow -= 1;
113
+ }
114
+ }
115
+ /**
116
+ * Update the send window for a stream.
117
+ *
118
+ * Called when a reverse-direction StreamFrame arrives with data=[] and window_size set.
119
+ * Replaces remainingWindow with new_size. Sets paused=true when new_size === 0.
120
+ */
121
+ updateWindow(streamId, newSize) {
122
+ let out = this.outgoing.get(streamId);
123
+ if (!out) {
124
+ out = {
125
+ streamId,
126
+ remainingWindow: newSize,
127
+ paused: newSize === 0,
128
+ };
129
+ this.outgoing.set(streamId, out);
130
+ return;
131
+ }
132
+ out.remainingWindow = newSize;
133
+ out.paused = newSize === 0;
134
+ }
135
+ /**
136
+ * Returns true when the outgoing stream is paused (window=0 was received).
137
+ * Resumes (returns false) once a non-zero window update arrives.
138
+ */
139
+ isPaused(streamId) {
140
+ return this.outgoing.get(streamId)?.paused ?? false;
141
+ }
142
+ /** Get reassembled data for a completed stream. */
143
+ getData(streamId) {
144
+ const stream = this.streams.get(streamId);
145
+ if (!stream || !stream.completed)
146
+ return null;
147
+ return stream.chunks.flat();
148
+ }
149
+ /** Get error code if stream terminated with error. */
150
+ getError(streamId) {
151
+ return this.streams.get(streamId)?.errorCode;
152
+ }
153
+ /** Number of active (non-completed) streams. */
154
+ get activeCount() {
155
+ let count = 0;
156
+ for (const s of this.streams.values()) {
157
+ if (!s.completed)
158
+ count++;
159
+ }
160
+ return count;
161
+ }
162
+ }
163
+ //# sourceMappingURL=stream-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-manager.js","sourceRoot":"","sources":["../../src/ncp/stream-manager.ts"],"names":[],"mappings":"AAAA,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AgB;QACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC;IACtD,CAAC;IAED,mDAAmD;IACnD,OAAO,CAAC,QAAgB;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC;QAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED,sDAAsD;IACtD,QAAQ,CAAC,QAAgB;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC/C,CAAC;IAED,gDAAgD;IAChD,IAAI,WAAW;QACb,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,CAAC,CAAC,SAAS;gBAAE,KAAK,EAAE,CAAC;QAC5B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ import type { NdpResolveResult } from "./frames.js";
2
+ export declare const DNS_TXT_DEFAULT_TTL = 300;
3
+ /**
4
+ * Extract the hostname from an NWP target URI.
5
+ * e.g. "nwp://api.example.com/products" → "api.example.com"
6
+ */
7
+ export declare function extractHostFromTarget(target: string): string | undefined;
8
+ /**
9
+ * Parse one TXT record (array of string chunks) into an NdpResolveResult.
10
+ *
11
+ * Expected format (chunks joined with a single space):
12
+ * v=nps1 type=<type> port=<port> nid=<nid> fp=sha256:<fingerprint>
13
+ *
14
+ * Rules:
15
+ * - `v` MUST be present and equal to "nps1"
16
+ * - `nid` MUST be present
17
+ * - `port` defaults to 17433 when absent
18
+ * - `fp` is mapped to certFingerprint
19
+ */
20
+ export declare function parseNpsTxtRecord(parts: string[], host: string): NdpResolveResult | undefined;
21
+ /**
22
+ * Abstraction over DNS TXT lookups.
23
+ * The default implementation uses Node's `dns.promises`; pass a mock in tests.
24
+ */
25
+ export interface DnsTxtLookup {
26
+ resolveTxt(hostname: string): Promise<string[][]>;
27
+ }
28
+ /**
29
+ * System DNS TXT resolver backed by Node's built-in `dns.promises`.
30
+ * The dynamic `import()` keeps browser bundles from failing at parse time.
31
+ */
32
+ export declare class SystemDnsTxtLookup implements DnsTxtLookup {
33
+ resolveTxt(hostname: string): Promise<string[][]>;
34
+ }
35
+ //# sourceMappingURL=dns-txt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dns-txt.d.ts","sourceRoot":"","sources":["../../src/ndp/dns-txt.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMxE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,EAAE,MAAM,GACX,gBAAgB,GAAG,SAAS,CAgC9B;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CACnD;AAED;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,YAAY;IAC/C,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;CAIxD"}
@@ -0,0 +1,67 @@
1
+ // Copyright 2026 INNO LOTUS PTY LTD
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export const DNS_TXT_DEFAULT_TTL = 300;
4
+ /**
5
+ * Extract the hostname from an NWP target URI.
6
+ * e.g. "nwp://api.example.com/products" → "api.example.com"
7
+ */
8
+ export function extractHostFromTarget(target) {
9
+ if (!target.startsWith("nwp://"))
10
+ return undefined;
11
+ const rest = target.slice("nwp://".length);
12
+ const slashIdx = rest.indexOf("/");
13
+ const host = slashIdx === -1 ? rest : rest.slice(0, slashIdx);
14
+ return host.length > 0 ? host : undefined;
15
+ }
16
+ /**
17
+ * Parse one TXT record (array of string chunks) into an NdpResolveResult.
18
+ *
19
+ * Expected format (chunks joined with a single space):
20
+ * v=nps1 type=<type> port=<port> nid=<nid> fp=sha256:<fingerprint>
21
+ *
22
+ * Rules:
23
+ * - `v` MUST be present and equal to "nps1"
24
+ * - `nid` MUST be present
25
+ * - `port` defaults to 17433 when absent
26
+ * - `fp` is mapped to certFingerprint
27
+ */
28
+ export function parseNpsTxtRecord(parts, host) {
29
+ const joined = parts.join(" ");
30
+ const kv = new Map();
31
+ for (const token of joined.split(/\s+/)) {
32
+ const eq = token.indexOf("=");
33
+ if (eq === -1)
34
+ continue;
35
+ const key = token.slice(0, eq);
36
+ const val = token.slice(eq + 1);
37
+ kv.set(key, val);
38
+ }
39
+ if (kv.get("v") !== "nps1")
40
+ return undefined;
41
+ const nid = kv.get("nid");
42
+ if (!nid)
43
+ return undefined;
44
+ const rawPort = kv.get("port");
45
+ const port = rawPort !== undefined ? Number(rawPort) : 17433;
46
+ const fp = kv.get("fp");
47
+ const result = {
48
+ host,
49
+ port,
50
+ ttl: DNS_TXT_DEFAULT_TTL,
51
+ };
52
+ if (fp !== undefined) {
53
+ result.certFingerprint = fp;
54
+ }
55
+ return result;
56
+ }
57
+ /**
58
+ * System DNS TXT resolver backed by Node's built-in `dns.promises`.
59
+ * The dynamic `import()` keeps browser bundles from failing at parse time.
60
+ */
61
+ export class SystemDnsTxtLookup {
62
+ async resolveTxt(hostname) {
63
+ const { promises: dns } = await import("node:dns");
64
+ return dns.resolveTxt(hostname);
65
+ }
66
+ }
67
+ //# sourceMappingURL=dns-txt.js.map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AG,CAAC,CAAC,CAAC;QAChC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IAE7C,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAE3B,MAAM,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAM,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChE,MAAM,EAAE,GAAQ,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,MAAM,GAAqB;QAC/B,IAAI;QACJ,IAAI;QACJ,GAAG,EAAE,mBAAmB;KACzB,CAAC;IAEF,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,MAAM,CAAC,eAAe,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAUD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,KAAK,CAAC,UAAU,CAAC,QAAgB;QAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QACnD,OAAO,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,56 @@
1
+ import { EncodingTier, FrameType } from "../core/frames.js";
2
+ import type { NpsFrame } from "../core/codec.js";
3
+ export interface NdpAddress {
4
+ host: string;
5
+ port: number;
6
+ protocol: string;
7
+ }
8
+ export interface NdpGraphNode {
9
+ nid: string;
10
+ addresses: readonly NdpAddress[];
11
+ capabilities: readonly string[];
12
+ nodeType?: string;
13
+ }
14
+ export interface NdpResolveResult {
15
+ host: string;
16
+ port: number;
17
+ ttl: number;
18
+ certFingerprint?: string;
19
+ }
20
+ export declare class AnnounceFrame implements NpsFrame {
21
+ readonly nid: string;
22
+ readonly addresses: readonly NdpAddress[];
23
+ readonly capabilities: readonly string[];
24
+ readonly ttl: number;
25
+ readonly timestamp: string;
26
+ readonly signature: string;
27
+ readonly nodeType?: string | undefined;
28
+ readonly frameType = FrameType.ANNOUNCE;
29
+ readonly preferredTier = EncodingTier.MSGPACK;
30
+ constructor(nid: string, addresses: readonly NdpAddress[], capabilities: readonly string[], ttl: number, timestamp: string, signature: string, nodeType?: string | undefined);
31
+ unsignedDict(): Record<string, unknown>;
32
+ toDict(): Record<string, unknown>;
33
+ static fromDict(data: Record<string, unknown>): AnnounceFrame;
34
+ }
35
+ export declare class ResolveFrame implements NpsFrame {
36
+ readonly target: string;
37
+ readonly requesterNid?: string | undefined;
38
+ readonly resolved?: NdpResolveResult | undefined;
39
+ readonly frameType = FrameType.RESOLVE;
40
+ readonly preferredTier = EncodingTier.MSGPACK;
41
+ constructor(target: string, requesterNid?: string | undefined, resolved?: NdpResolveResult | undefined);
42
+ toDict(): Record<string, unknown>;
43
+ static fromDict(data: Record<string, unknown>): ResolveFrame;
44
+ }
45
+ export declare class GraphFrame implements NpsFrame {
46
+ readonly seq: number;
47
+ readonly initialSync: boolean;
48
+ readonly nodes?: readonly NdpGraphNode[] | undefined;
49
+ readonly patch?: readonly Record<string, unknown>[] | undefined;
50
+ readonly frameType = FrameType.GRAPH;
51
+ readonly preferredTier = EncodingTier.MSGPACK;
52
+ constructor(seq: number, initialSync: boolean, nodes?: readonly NdpGraphNode[] | undefined, patch?: readonly Record<string, unknown>[] | undefined);
53
+ toDict(): Record<string, unknown>;
54
+ static fromDict(data: Record<string, unknown>): GraphFrame;
55
+ }
56
+ //# sourceMappingURL=frames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frames.d.ts","sourceRo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License-Identifier: Apache-2.0
3
+ import { EncodingTier, FrameType } from "../core/frames.js";
4
+ export class AnnounceFrame {
5
+ nid;
6
+ addresses;
7
+ capabilities;
8
+ ttl;
9
+ timestamp;
10
+ signature;
11
+ nodeType;
12
+ frameType = FrameType.ANNOUNCE;
13
+ preferredTier = EncodingTier.MSGPACK;
14
+ constructor(nid, addresses, capabilities, ttl, timestamp, signature, nodeType) {
15
+ this.nid = nid;
16
+ this.addresses = addresses;
17
+ this.capabilities = capabilities;
18
+ this.ttl = ttl;
19
+ this.timestamp = timestamp;
20
+ this.signature = signature;
21
+ this.nodeType = nodeType;
22
+ }
23
+ unsignedDict() {
24
+ return {
25
+ nid: this.nid,
26
+ addresses: this.addresses,
27
+ capabilities: this.capabilities,
28
+ ttl: this.ttl,
29
+ timestamp: this.timestamp,
30
+ node_type: this.nodeType ?? null,
31
+ };
32
+ }
33
+ toDict() {
34
+ return { ...this.unsignedDict(), signature: this.signature };
35
+ }
36
+ static fromDict(data) {
37
+ return new AnnounceFrame(data["nid"], data["addresses"], data["capabilities"], data["ttl"], data["timestamp"], data["signature"], data["node_type"] ?? undefined);
38
+ }
39
+ }
40
+ export class ResolveFrame {
41
+ target;
42
+ requesterNid;
43
+ resolved;
44
+ frameType = FrameType.RESOLVE;
45
+ preferredTier = EncodingTier.MSGPACK;
46
+ constructor(target, requesterNid, resolved) {
47
+ this.target = target;
48
+ this.requesterNid = requesterNid;
49
+ this.resolved = resolved;
50
+ }
51
+ toDict() {
52
+ return {
53
+ target: this.target,
54
+ requester_nid: this.requesterNid ?? null,
55
+ resolved: this.resolved ?? null,
56
+ };
57
+ }
58
+ static fromDict(data) {
59
+ return new ResolveFrame(data["target"], data["requester_nid"] ?? undefined, data["resolved"] ?? undefined);
60
+ }
61
+ }
62
+ export class GraphFrame {
63
+ seq;
64
+ initialSync;
65
+ nodes;
66
+ patch;
67
+ frameType = FrameType.GRAPH;
68
+ preferredTier = EncodingTier.MSGPACK;
69
+ constructor(seq, initialSync, nodes, patch) {
70
+ this.seq = seq;
71
+ this.initialSync = initialSync;
72
+ this.nodes = nodes;
73
+ this.patch = patch;
74
+ }
75
+ toDict() {
76
+ return {
77
+ seq: this.seq,
78
+ initial_sync: this.initialSync,
79
+ nodes: this.nodes ?? null,
80
+ patch: this.patch ?? null,
81
+ };
82
+ }
83
+ static fromDict(data) {
84
+ return new GraphFrame(data["seq"], data["initial_sync"], data["nodes"] ?? undefined, data["patch"] ?? undefined);
85
+ }
86
+ }
87
+ //# sourceMappingURL=frames.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frames.js","sourceRoot":"","sources":["../../src/ndp/frames.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAuB5D,MAAM,OAAO,aAAa;IAKN;IACA;IACA;IACA;IACA;IACA;IACA;IAVT,SAAS,GAAO,SAAS,CAAC,QAAQ,CAAC;IACnC,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC;IAE9C,YACkB,GAAoB,EACpB,SAAmC,EACnC,YAA+B,EAC/B,GAAoB,EACpB,SAAoB,EACpB,SAAoB,EACpB,QAAoB;QANpB,QAAG,GAAH,GAAG,CAAiB;QACpB,cAAS,GAAT,SAAS,CAA0B;QACnC,iBAAY,GAAZ,YAAY,CAAmB;QAC/B,QAAG,GAAH,GAAG,CAAiB;QACpB,cAAS,GAAT,SAAS,CAAW;QACpB,cAAS,GAAT,SAAS,CAAW;QACpB,aAAQ,GAAR,QAAQ,CAAY;IACnC,CAAC;IAEJ,YAAY;QACV,OAAO;YACL,GAAG,EAAW,IAAI,CAAC,GAAG;YACtB,SAAS,EAAK,IAAI,CAAC,SAAS;YAC5B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,GAAG,EAAW,IAAI,CAAC,GAAG;YACtB,SAAS,EAAK,IAAI,CAAC,SAAS;YAC5B,SAAS,EAAK,IAAI,CAAC,QAAQ,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AK,CAAC;IAChC,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC;IAE9C,YACkB,GAAmB,EACnB,WAAoB,EACpB,KAAoC,EACpC,KAA+C;QAH/C,QAAG,GAAH,GAAG,CAAgB;QACnB,gBAAW,GAAX,WAAW,CAAS;QACpB,UAAK,GAAL,KAAK,CAA+B;QACpC,UAAK,GAAL,KAAK,CAA0C;IAC9D,CAAC;IAEJ,MAAM;QACJ,OAAO;YACL,GAAG,EAAW,IAAI,CAAC,GAAG;YACtB,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,KAAK,EAAS,IAAI,CAAC,KAAK,IAAI,IAAI;YAChC,KAAK,EAAS,IAAI,CAAC,KAAK,IAAI,IAAI;SACjC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAA6B;QAC3C,OAAO,IAAI,UAAU,CACnB,IAAI,CAAC,KAAK,CAAoB,EAC9B,IAAI,CAAC,cAAc,CAAY,EAC9B,IAAI,CAAC,OAAO,CAA2B,IAAI,SAAS,EACpD,IAAI,CAAC,OAAO,CAAsC,IAAI,SAAS,CACjE,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export * from "./frames.js";
2
+ export * from "./registry.js";
3
+ export * from "./ndp-registry.js";
4
+ export * from "./validator.js";
5
+ export * from "./dns-txt.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ndp/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -1,8 +1,8 @@
1
1
  // Copyright 2026 INNO LOTUS PTY LTD
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
4
3
  export * from "./frames.js";
5
4
  export * from "./registry.js";
6
5
  export * from "./ndp-registry.js";
7
6
  export * from "./validator.js";
8
7
  export * from "./dns-txt.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ndp/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,sCAAsC;AAEtC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { AnnounceFrame, NdpResolveResult } from "./frames.js";
2
+ import { type DnsTxtLookup } from "./dns-txt.js";
3
+ export declare class InMemoryNdpRegistry {
4
+ private readonly _store;
5
+ clock: () => number;
6
+ announce(frame: AnnounceFrame): void;
7
+ getByNid(nid: string): AnnounceFrame | undefined;
8
+ resolve(target: string): NdpResolveResult | undefined;
9
+ getAll(): AnnounceFrame[];
10
+ resolveWithDns(target: string, resolver?: DnsTxtLookup): Promise<NdpResolveResult | undefined>;
11
+ static nwpTargetMatchesNid(nid: string, target: string): boolean;
12
+ }
13
+ //# sourceMappingURL=ndp-registry.d.ts.map