@labacacia/nps-sdk 1.0.0-alpha.1 → 1.0.0-alpha.13
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.
- package/CHANGELOG.cn.md +181 -0
- package/CHANGELOG.md +234 -0
- package/LICENSE +0 -0
- package/NOTICE +0 -0
- package/README.cn.md +163 -0
- package/README.md +16 -6
- package/dist/core/anchor-cache.d.ts +0 -0
- package/dist/core/anchor-cache.d.ts.map +0 -0
- package/dist/core/anchor-cache.js +0 -0
- package/dist/core/anchor-cache.js.map +0 -0
- package/dist/core/cache.d.ts +0 -0
- package/dist/core/cache.d.ts.map +0 -0
- package/dist/core/cache.js +0 -0
- package/dist/core/cache.js.map +0 -0
- package/dist/core/canonical-json.d.ts +0 -0
- package/dist/core/canonical-json.d.ts.map +0 -0
- package/dist/core/canonical-json.js +0 -0
- package/dist/core/canonical-json.js.map +0 -0
- package/dist/core/codec.d.ts +0 -0
- package/dist/core/codec.d.ts.map +0 -0
- package/dist/core/codec.js +0 -0
- package/dist/core/codec.js.map +0 -0
- package/dist/core/codecs/index.d.ts +0 -0
- package/dist/core/codecs/index.d.ts.map +0 -0
- package/dist/core/codecs/index.js +0 -0
- package/dist/core/codecs/index.js.map +0 -0
- package/dist/core/codecs/ncp-codec.d.ts +0 -0
- package/dist/core/codecs/ncp-codec.d.ts.map +0 -0
- package/dist/core/codecs/ncp-codec.js +0 -0
- package/dist/core/codecs/ncp-codec.js.map +0 -0
- package/dist/core/codecs/tier1-json-codec.d.ts +0 -0
- package/dist/core/codecs/tier1-json-codec.d.ts.map +0 -0
- package/dist/core/codecs/tier1-json-codec.js +0 -0
- package/dist/core/codecs/tier1-json-codec.js.map +0 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts +0 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts.map +0 -0
- package/dist/core/codecs/tier2-msgpack-codec.js +0 -0
- package/dist/core/codecs/tier2-msgpack-codec.js.map +0 -0
- package/dist/core/crypto-provider.d.ts +0 -0
- package/dist/core/crypto-provider.d.ts.map +0 -0
- package/dist/core/crypto-provider.js +0 -0
- package/dist/core/crypto-provider.js.map +0 -0
- package/dist/core/exceptions.d.ts +0 -0
- package/dist/core/exceptions.d.ts.map +0 -0
- package/dist/core/exceptions.js +0 -0
- package/dist/core/exceptions.js.map +0 -0
- package/dist/core/frame-header.d.ts +1 -0
- package/dist/core/frame-header.d.ts.map +1 -1
- package/dist/core/frame-header.js +1 -0
- package/dist/core/frame-header.js.map +1 -1
- package/dist/core/frame-registry.d.ts +0 -0
- package/dist/core/frame-registry.d.ts.map +1 -1
- package/dist/core/frame-registry.js +1 -0
- package/dist/core/frame-registry.js.map +1 -1
- package/dist/core/frames.d.ts +3 -0
- package/dist/core/frames.d.ts.map +1 -1
- package/dist/core/frames.js +3 -0
- package/dist/core/frames.js.map +1 -1
- package/dist/core/index.d.ts +6 -4
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +17 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/registry.d.ts +0 -0
- package/dist/core/registry.d.ts.map +0 -0
- package/dist/core/registry.js +0 -0
- package/dist/core/registry.js.map +0 -0
- package/dist/core/status-codes.d.ts +20 -0
- package/dist/core/status-codes.d.ts.map +1 -1
- package/dist/core/status-codes.js +51 -0
- package/dist/core/status-codes.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ncp/frames/anchor-frame.d.ts +0 -0
- package/dist/ncp/frames/anchor-frame.d.ts.map +0 -0
- package/dist/ncp/frames/anchor-frame.js +0 -0
- package/dist/ncp/frames/anchor-frame.js.map +0 -0
- package/dist/ncp/frames/caps-frame.d.ts +0 -0
- package/dist/ncp/frames/caps-frame.d.ts.map +0 -0
- package/dist/ncp/frames/caps-frame.js +0 -0
- package/dist/ncp/frames/caps-frame.js.map +0 -0
- package/dist/ncp/frames/diff-frame.d.ts +0 -0
- package/dist/ncp/frames/diff-frame.d.ts.map +0 -0
- package/dist/ncp/frames/diff-frame.js +0 -0
- package/dist/ncp/frames/diff-frame.js.map +0 -0
- package/dist/ncp/frames/error-frame.d.ts +0 -0
- package/dist/ncp/frames/error-frame.d.ts.map +0 -0
- package/dist/ncp/frames/error-frame.js +0 -0
- package/dist/ncp/frames/error-frame.js.map +0 -0
- package/dist/ncp/frames/hello-frame.d.ts +0 -0
- package/dist/ncp/frames/hello-frame.d.ts.map +0 -0
- package/dist/ncp/frames/hello-frame.js +0 -0
- package/dist/ncp/frames/hello-frame.js.map +0 -0
- package/dist/ncp/frames/stream-frame.d.ts +0 -0
- package/dist/ncp/frames/stream-frame.d.ts.map +0 -0
- package/dist/ncp/frames/stream-frame.js +0 -0
- package/dist/ncp/frames/stream-frame.js.map +0 -0
- package/dist/ncp/frames.d.ts +25 -0
- package/dist/ncp/frames.d.ts.map +1 -1
- package/dist/ncp/frames.js +61 -0
- package/dist/ncp/frames.js.map +1 -1
- package/dist/ncp/handshake.d.ts +0 -0
- package/dist/ncp/handshake.d.ts.map +0 -0
- package/dist/ncp/handshake.js +0 -0
- package/dist/ncp/handshake.js.map +0 -0
- package/dist/ncp/index.d.ts +1 -0
- package/dist/ncp/index.d.ts.map +1 -1
- package/dist/ncp/index.js +1 -0
- package/dist/ncp/index.js.map +1 -1
- package/dist/ncp/ncp-error-codes.d.ts +5 -0
- package/dist/ncp/ncp-error-codes.d.ts.map +1 -1
- package/dist/ncp/ncp-error-codes.js +27 -0
- package/dist/ncp/ncp-error-codes.js.map +1 -1
- package/dist/ncp/ncp-patch-format.d.ts +0 -0
- package/dist/ncp/ncp-patch-format.d.ts.map +0 -0
- package/dist/ncp/ncp-patch-format.js +0 -0
- package/dist/ncp/ncp-patch-format.js.map +0 -0
- package/dist/ncp/preamble.d.ts +47 -0
- package/dist/ncp/preamble.d.ts.map +1 -0
- package/dist/ncp/preamble.js +74 -0
- package/dist/ncp/preamble.js.map +1 -0
- package/dist/ncp/registry.d.ts +0 -0
- package/dist/ncp/registry.d.ts.map +1 -1
- package/dist/ncp/registry.js +2 -1
- package/dist/ncp/registry.js.map +1 -1
- package/dist/ncp/stream-manager.d.ts +0 -0
- package/dist/ncp/stream-manager.d.ts.map +0 -0
- package/dist/ncp/stream-manager.js +0 -0
- package/dist/ncp/stream-manager.js.map +0 -0
- package/dist/ndp/dns-txt.d.ts +35 -0
- package/dist/ndp/dns-txt.d.ts.map +1 -0
- package/dist/ndp/dns-txt.js +67 -0
- package/dist/ndp/dns-txt.js.map +1 -0
- package/dist/ndp/frames.d.ts +34 -9
- package/dist/ndp/frames.d.ts.map +1 -1
- package/dist/ndp/frames.js +54 -15
- package/dist/ndp/frames.js.map +1 -1
- package/dist/ndp/index.d.ts +3 -0
- package/dist/ndp/index.d.ts.map +1 -1
- package/dist/ndp/index.js +3 -0
- package/dist/ndp/index.js.map +1 -1
- package/dist/ndp/ndp-error-codes.d.ts +25 -0
- package/dist/ndp/ndp-error-codes.d.ts.map +1 -0
- package/dist/ndp/ndp-error-codes.js +48 -0
- package/dist/ndp/ndp-error-codes.js.map +1 -0
- package/dist/ndp/ndp-registry.d.ts +2 -0
- package/dist/ndp/ndp-registry.d.ts.map +1 -1
- package/dist/ndp/ndp-registry.js +25 -0
- package/dist/ndp/ndp-registry.js.map +1 -1
- package/dist/ndp/registry.d.ts +0 -0
- package/dist/ndp/registry.d.ts.map +0 -0
- package/dist/ndp/registry.js +0 -0
- package/dist/ndp/registry.js.map +0 -0
- package/dist/ndp/security.d.ts +8 -0
- package/dist/ndp/security.d.ts.map +1 -0
- package/dist/ndp/security.js +9 -0
- package/dist/ndp/security.js.map +1 -0
- package/dist/ndp/validator.d.ts +0 -0
- package/dist/ndp/validator.d.ts.map +0 -0
- package/dist/ndp/validator.js +0 -0
- package/dist/ndp/validator.js.map +0 -0
- package/dist/nip/acme/client.d.ts +31 -0
- package/dist/nip/acme/client.d.ts.map +1 -0
- package/dist/nip/acme/client.js +136 -0
- package/dist/nip/acme/client.js.map +1 -0
- package/dist/nip/acme/index.d.ts +6 -0
- package/dist/nip/acme/index.d.ts.map +1 -0
- package/dist/nip/acme/index.js +8 -0
- package/dist/nip/acme/index.js.map +1 -0
- package/dist/nip/acme/jws.d.ts +31 -0
- package/dist/nip/acme/jws.d.ts.map +1 -0
- package/dist/nip/acme/jws.js +76 -0
- package/dist/nip/acme/jws.js.map +1 -0
- package/dist/nip/acme/messages.d.ts +71 -0
- package/dist/nip/acme/messages.d.ts.map +1 -0
- package/dist/nip/acme/messages.js +4 -0
- package/dist/nip/acme/messages.js.map +1 -0
- package/dist/nip/acme/server.d.ts +41 -0
- package/dist/nip/acme/server.d.ts.map +1 -0
- package/dist/nip/acme/server.js +458 -0
- package/dist/nip/acme/server.js.map +1 -0
- package/dist/nip/acme/wire.d.ts +19 -0
- package/dist/nip/acme/wire.d.ts.map +1 -0
- package/dist/nip/acme/wire.js +21 -0
- package/dist/nip/acme/wire.js.map +1 -0
- package/dist/nip/assurance-level.d.ts +19 -0
- package/dist/nip/assurance-level.d.ts.map +1 -0
- package/dist/nip/assurance-level.js +38 -0
- package/dist/nip/assurance-level.js.map +1 -0
- package/dist/nip/cert-format.d.ts +5 -0
- package/dist/nip/cert-format.d.ts.map +1 -0
- package/dist/nip/cert-format.js +6 -0
- package/dist/nip/cert-format.js.map +1 -0
- package/dist/nip/error-codes.d.ts +44 -0
- package/dist/nip/error-codes.d.ts.map +1 -0
- package/dist/nip/error-codes.js +97 -0
- package/dist/nip/error-codes.js.map +1 -0
- package/dist/nip/frames.d.ts +19 -1
- package/dist/nip/frames.d.ts.map +1 -1
- package/dist/nip/frames.js +39 -4
- package/dist/nip/frames.js.map +1 -1
- package/dist/nip/identity.d.ts +0 -0
- package/dist/nip/identity.d.ts.map +0 -0
- package/dist/nip/identity.js +0 -0
- package/dist/nip/identity.js.map +0 -0
- package/dist/nip/index.d.ts +7 -0
- package/dist/nip/index.d.ts.map +1 -1
- package/dist/nip/index.js +9 -0
- package/dist/nip/index.js.map +1 -1
- package/dist/nip/registry.d.ts +0 -0
- package/dist/nip/registry.d.ts.map +0 -0
- package/dist/nip/registry.js +0 -0
- package/dist/nip/registry.js.map +0 -0
- package/dist/nip/reputation-client.d.ts +116 -0
- package/dist/nip/reputation-client.d.ts.map +1 -0
- package/dist/nip/reputation-client.js +261 -0
- package/dist/nip/reputation-client.js.map +1 -0
- package/dist/nip/verifier.d.ts +23 -0
- package/dist/nip/verifier.d.ts.map +1 -0
- package/dist/nip/verifier.js +90 -0
- package/dist/nip/verifier.js.map +1 -0
- package/dist/nip/x509/builder.d.ts +35 -0
- package/dist/nip/x509/builder.d.ts.map +1 -0
- package/dist/nip/x509/builder.js +59 -0
- package/dist/nip/x509/builder.js.map +1 -0
- package/dist/nip/x509/index.d.ts +4 -0
- package/dist/nip/x509/index.d.ts.map +1 -0
- package/dist/nip/x509/index.js +6 -0
- package/dist/nip/x509/index.js.map +1 -0
- package/dist/nip/x509/oids.d.ts +16 -0
- package/dist/nip/x509/oids.d.ts.map +1 -0
- package/dist/nip/x509/oids.js +22 -0
- package/dist/nip/x509/oids.js.map +1 -0
- package/dist/nip/x509/verifier.d.ts +26 -0
- package/dist/nip/x509/verifier.d.ts.map +1 -0
- package/dist/nip/x509/verifier.js +171 -0
- package/dist/nip/x509/verifier.js.map +1 -0
- package/dist/nop/client.d.ts +0 -0
- package/dist/nop/client.d.ts.map +0 -0
- package/dist/nop/client.js +0 -0
- package/dist/nop/client.js.map +1 -1
- package/dist/nop/dag-validator.d.ts +15 -0
- package/dist/nop/dag-validator.d.ts.map +1 -0
- package/dist/nop/dag-validator.js +91 -0
- package/dist/nop/dag-validator.js.map +1 -0
- package/dist/nop/frames.d.ts +8 -3
- package/dist/nop/frames.d.ts.map +1 -1
- package/dist/nop/frames.js +21 -6
- package/dist/nop/frames.js.map +1 -1
- package/dist/nop/index.d.ts +3 -0
- package/dist/nop/index.d.ts.map +1 -1
- package/dist/nop/index.js +3 -0
- package/dist/nop/index.js.map +1 -1
- package/dist/nop/models.d.ts +13 -2
- package/dist/nop/models.d.ts.map +1 -1
- package/dist/nop/models.js +9 -0
- package/dist/nop/models.js.map +1 -1
- package/dist/nop/nop-error-codes.d.ts +31 -0
- package/dist/nop/nop-error-codes.d.ts.map +1 -0
- package/dist/nop/nop-error-codes.js +61 -0
- package/dist/nop/nop-error-codes.js.map +1 -0
- package/dist/nop/nop-types.d.ts +0 -0
- package/dist/nop/nop-types.d.ts.map +0 -0
- package/dist/nop/nop-types.js +0 -0
- package/dist/nop/nop-types.js.map +0 -0
- package/dist/nop/orchestrator.d.ts +66 -0
- package/dist/nop/orchestrator.d.ts.map +1 -0
- package/dist/nop/orchestrator.js +229 -0
- package/dist/nop/orchestrator.js.map +1 -0
- package/dist/nop/registry.d.ts +0 -0
- package/dist/nop/registry.d.ts.map +0 -0
- package/dist/nop/registry.js +0 -0
- package/dist/nop/registry.js.map +0 -0
- package/dist/nwp/anchor-client.d.ts +109 -0
- package/dist/nwp/anchor-client.d.ts.map +1 -0
- package/dist/nwp/anchor-client.js +279 -0
- package/dist/nwp/anchor-client.js.map +1 -0
- package/dist/nwp/anchor-server.d.ts +127 -0
- package/dist/nwp/anchor-server.d.ts.map +1 -0
- package/dist/nwp/anchor-server.js +649 -0
- package/dist/nwp/anchor-server.js.map +1 -0
- package/dist/nwp/bridge.d.ts +24 -0
- package/dist/nwp/bridge.d.ts.map +1 -0
- package/dist/nwp/bridge.js +26 -0
- package/dist/nwp/bridge.js.map +1 -0
- package/dist/nwp/cgn.d.ts +19 -0
- package/dist/nwp/cgn.d.ts.map +1 -0
- package/dist/nwp/cgn.js +29 -0
- package/dist/nwp/cgn.js.map +1 -0
- package/dist/nwp/client.d.ts +10 -3
- package/dist/nwp/client.d.ts.map +1 -1
- package/dist/nwp/client.js +58 -7
- package/dist/nwp/client.js.map +1 -1
- package/dist/nwp/frames.d.ts +56 -2
- package/dist/nwp/frames.d.ts.map +1 -1
- package/dist/nwp/frames.js +86 -4
- package/dist/nwp/frames.js.map +1 -1
- package/dist/nwp/http-headers.d.ts +24 -0
- package/dist/nwp/http-headers.d.ts.map +1 -0
- package/dist/nwp/http-headers.js +29 -0
- package/dist/nwp/http-headers.js.map +1 -0
- package/dist/nwp/index.d.ts +9 -0
- package/dist/nwp/index.d.ts.map +1 -1
- package/dist/nwp/index.js +9 -0
- package/dist/nwp/index.js.map +1 -1
- package/dist/nwp/manifest.d.ts +75 -0
- package/dist/nwp/manifest.d.ts.map +1 -0
- package/dist/nwp/manifest.js +5 -0
- package/dist/nwp/manifest.js.map +1 -0
- package/dist/nwp/memory-node-server.d.ts +70 -0
- package/dist/nwp/memory-node-server.d.ts.map +1 -0
- package/dist/nwp/memory-node-server.js +315 -0
- package/dist/nwp/memory-node-server.js.map +1 -0
- package/dist/nwp/nwp-error-codes.d.ts +48 -0
- package/dist/nwp/nwp-error-codes.d.ts.map +1 -0
- package/dist/nwp/nwp-error-codes.js +108 -0
- package/dist/nwp/nwp-error-codes.js.map +1 -0
- package/dist/nwp/registry.d.ts +0 -0
- package/dist/nwp/registry.d.ts.map +0 -0
- package/dist/nwp/registry.js +0 -0
- package/dist/nwp/registry.js.map +0 -0
- package/dist/nwp/reputation.d.ts +37 -0
- package/dist/nwp/reputation.d.ts.map +1 -0
- package/dist/nwp/reputation.js +118 -0
- package/dist/nwp/reputation.js.map +1 -0
- package/dist/setup.d.ts +0 -0
- package/dist/setup.d.ts.map +0 -0
- package/dist/setup.js +0 -0
- package/dist/setup.js.map +0 -0
- package/doc/nps-sdk.core.cn.md +321 -0
- package/doc/nps-sdk.core.md +326 -0
- package/doc/nps-sdk.ncp.cn.md +270 -0
- package/doc/nps-sdk.ncp.md +276 -0
- package/doc/nps-sdk.ndp.cn.md +267 -0
- package/doc/nps-sdk.ndp.md +273 -0
- package/doc/nps-sdk.nip.cn.md +265 -0
- package/doc/nps-sdk.nip.md +272 -0
- package/doc/nps-sdk.nop.cn.md +329 -0
- package/doc/nps-sdk.nop.md +332 -0
- package/doc/nps-sdk.nwp.cn.md +288 -0
- package/doc/nps-sdk.nwp.md +295 -0
- package/doc/overview.cn.md +149 -0
- package/doc/overview.md +153 -0
- package/package.json +33 -4
- package/CONTRIBUTING.md +0 -33
- package/dist/codec-CmHeovTV.d.cts +0 -120
- package/dist/codec-CmHeovTV.d.ts +0 -120
- package/dist/core/index.cjs +0 -371
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -41
- package/dist/frames-B3qLdl_g.d.cts +0 -77
- package/dist/frames-Ff7-ZPUl.d.ts +0 -77
- package/dist/index.cjs +0 -1556
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -21
- package/dist/ncp/index.cjs +0 -188
- package/dist/ncp/index.cjs.map +0 -1
- package/dist/ncp/index.d.cts +0 -6
- package/dist/ndp/index.cjs +0 -252
- package/dist/ndp/index.cjs.map +0 -1
- package/dist/ndp/index.d.cts +0 -86
- package/dist/nip/index.cjs +0 -214
- package/dist/nip/index.cjs.map +0 -1
- package/dist/nip/index.d.cts +0 -65
- package/dist/nop/index.cjs +0 -762
- package/dist/nop/index.cjs.map +0 -1
- package/dist/nop/index.d.cts +0 -155
- package/dist/nwp/index.cjs +0 -658
- package/dist/nwp/index.cjs.map +0 -1
- package/dist/nwp/index.d.cts +0 -65
- package/nip-ca-server/Dockerfile +0 -27
- package/nip-ca-server/README.md +0 -45
- package/nip-ca-server/db/001_init.sql +0 -25
- package/nip-ca-server/docker-compose.yml +0 -29
- package/nip-ca-server/package.json +0 -23
- package/nip-ca-server/src/ca.ts +0 -155
- package/nip-ca-server/src/db.ts +0 -104
- package/nip-ca-server/src/index.ts +0 -157
- package/nip-ca-server/tsconfig.json +0 -13
- package/src/core/anchor-cache.ts +0 -129
- package/src/core/cache.ts +0 -93
- package/src/core/canonical-json.ts +0 -50
- package/src/core/codec.ts +0 -158
- package/src/core/codecs/index.ts +0 -5
- package/src/core/codecs/ncp-codec.ts +0 -170
- package/src/core/codecs/tier1-json-codec.ts +0 -33
- package/src/core/codecs/tier2-msgpack-codec.ts +0 -30
- package/src/core/crypto-provider.ts +0 -47
- package/src/core/exceptions.ts +0 -57
- package/src/core/frame-header.ts +0 -282
- package/src/core/frame-registry.ts +0 -91
- package/src/core/frames.ts +0 -183
- package/src/core/index.ts +0 -10
- package/src/core/registry.ts +0 -28
- package/src/core/status-codes.ts +0 -46
- package/src/index.ts +0 -10
- package/src/ncp/frames/anchor-frame.ts +0 -87
- package/src/ncp/frames/caps-frame.ts +0 -59
- package/src/ncp/frames/diff-frame.ts +0 -69
- package/src/ncp/frames/error-frame.ts +0 -26
- package/src/ncp/frames/hello-frame.ts +0 -50
- package/src/ncp/frames/stream-frame.ts +0 -35
- package/src/ncp/frames.ts +0 -199
- package/src/ncp/handshake.ts +0 -95
- package/src/ncp/index.ts +0 -12
- package/src/ncp/ncp-error-codes.ts +0 -34
- package/src/ncp/ncp-patch-format.ts +0 -16
- package/src/ncp/registry.ts +0 -14
- package/src/ncp/stream-manager.ts +0 -212
- package/src/ndp/frames.ts +0 -124
- package/src/ndp/index.ts +0 -7
- package/src/ndp/ndp-registry.ts +0 -82
- package/src/ndp/registry.ts +0 -12
- package/src/ndp/validator.ts +0 -64
- package/src/nip/frames.ts +0 -106
- package/src/nip/identity.ts +0 -113
- package/src/nip/index.ts +0 -6
- package/src/nip/registry.ts +0 -12
- package/src/nop/client.ts +0 -103
- package/src/nop/frames.ts +0 -181
- package/src/nop/index.ts +0 -7
- package/src/nop/models.ts +0 -79
- package/src/nop/nop-types.ts +0 -208
- package/src/nop/registry.ts +0 -13
- package/src/nwp/client.ts +0 -114
- package/src/nwp/frames.ts +0 -116
- package/src/nwp/index.ts +0 -6
- package/src/nwp/registry.ts +0 -11
- package/src/setup.ts +0 -32
- package/tests/core/anchor-cache.test.ts +0 -242
- package/tests/core/codec.test.ts +0 -205
- package/tests/core/frame-registry.test.ts +0 -46
- package/tests/core.test.ts +0 -327
- package/tests/ncp/diff-binary-bitset.test.ts +0 -107
- package/tests/ncp/e2e-enc-reject.test.ts +0 -93
- package/tests/ncp/err-error-frame.test.ts +0 -152
- package/tests/ncp/frames.test.ts +0 -359
- package/tests/ncp/framing.test.ts +0 -233
- package/tests/ncp/hello-frame.test.ts +0 -122
- package/tests/ncp/inline-anchor.test.ts +0 -88
- package/tests/ncp/security.test.ts +0 -184
- package/tests/ncp/stream-window.test.ts +0 -167
- package/tests/ncp/stream.test.ts +0 -242
- package/tests/ncp/version-negotiation.test.ts +0 -123
- package/tests/ndp.test.ts +0 -271
- package/tests/nip.test.ts +0 -184
- package/tests/nop.test.ts +0 -344
- package/tests/nwp.test.ts +0 -237
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -20
- package/vitest.config.ts +0 -10
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* JWS signing helpers for ACME with Ed25519 (`alg: "EdDSA"` per RFC 8037).
|
|
5
|
+
*
|
|
6
|
+
* Wire shape (RFC 8555 §6.2 + RFC 7515 flattened JWS JSON serialization):
|
|
7
|
+
* {
|
|
8
|
+
* "protected": base64url(JSON({alg, nonce, url, [jwk|kid]})),
|
|
9
|
+
* "payload": base64url(JSON(payload)),
|
|
10
|
+
* "signature": base64url(Ed25519(protected || "." || payload))
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
import * as ed25519 from "@noble/ed25519";
|
|
14
|
+
import { sha512 } from "@noble/hashes/sha512";
|
|
15
|
+
import { sha256 } from "@noble/hashes/sha2";
|
|
16
|
+
ed25519.etc.sha512Sync = (...m) => sha512(ed25519.etc.concatBytes(...m));
|
|
17
|
+
export const ALG_EDDSA = "EdDSA"; // RFC 8037 §3.1
|
|
18
|
+
export const KTY_OKP = "OKP"; // RFC 8037 §2
|
|
19
|
+
export const CRV_ED25519 = "Ed25519"; // RFC 8037 §2
|
|
20
|
+
export function jwkFromPublicKey(rawPubKey) {
|
|
21
|
+
if (rawPubKey.length !== 32) {
|
|
22
|
+
throw new Error(`Ed25519 public key must be 32 bytes, got ${rawPubKey.length}`);
|
|
23
|
+
}
|
|
24
|
+
return { kty: KTY_OKP, crv: CRV_ED25519, x: b64uEncode(rawPubKey) };
|
|
25
|
+
}
|
|
26
|
+
export function publicKeyFromJwk(jwk) {
|
|
27
|
+
if (jwk.kty !== KTY_OKP || jwk.crv !== CRV_ED25519) {
|
|
28
|
+
throw new Error(`JWK is not OKP/Ed25519: kty=${jwk.kty} crv=${jwk.crv}`);
|
|
29
|
+
}
|
|
30
|
+
return b64uDecode(jwk.x);
|
|
31
|
+
}
|
|
32
|
+
/** RFC 7638 §3 thumbprint of an Ed25519 JWK (lex-sorted compact JSON, SHA-256, base64url). */
|
|
33
|
+
export function thumbprint(jwk) {
|
|
34
|
+
const canonical = `{"crv":"${jwk.crv}","kty":"${jwk.kty}","x":"${jwk.x}"}`;
|
|
35
|
+
return b64uEncode(sha256(new TextEncoder().encode(canonical)));
|
|
36
|
+
}
|
|
37
|
+
export function sign(header, payload, privKey) {
|
|
38
|
+
const headerBytes = new TextEncoder().encode(JSON.stringify(header));
|
|
39
|
+
const headerB64u = b64uEncode(headerBytes);
|
|
40
|
+
const payloadB64u = payload === null
|
|
41
|
+
? ""
|
|
42
|
+
: b64uEncode(new TextEncoder().encode(JSON.stringify(payload)));
|
|
43
|
+
const signingInput = new TextEncoder().encode(`${headerB64u}.${payloadB64u}`);
|
|
44
|
+
const sig = ed25519.sign(signingInput, privKey);
|
|
45
|
+
return { protected: headerB64u, payload: payloadB64u, signature: b64uEncode(sig) };
|
|
46
|
+
}
|
|
47
|
+
/** Verify a JWS envelope. Returns the parsed protected header on success, else null. */
|
|
48
|
+
export function verify(envelope, pubKey) {
|
|
49
|
+
try {
|
|
50
|
+
const signingInput = new TextEncoder().encode(`${envelope.protected}.${envelope.payload}`);
|
|
51
|
+
const sigBytes = b64uDecode(envelope.signature);
|
|
52
|
+
if (!ed25519.verify(sigBytes, signingInput, pubKey))
|
|
53
|
+
return null;
|
|
54
|
+
const headerJson = new TextDecoder().decode(b64uDecode(envelope.protected));
|
|
55
|
+
return JSON.parse(headerJson);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function decodePayload(envelope) {
|
|
62
|
+
if (!envelope.payload)
|
|
63
|
+
return null;
|
|
64
|
+
return JSON.parse(new TextDecoder().decode(b64uDecode(envelope.payload)));
|
|
65
|
+
}
|
|
66
|
+
// ── helpers ──────────────────────────────────────────────────────────────────
|
|
67
|
+
export function b64uEncode(bytes) {
|
|
68
|
+
return Buffer.from(bytes).toString("base64").replace(/=+$/, "")
|
|
69
|
+
.replace(/\+/g, "-").replace(/\//g, "_");
|
|
70
|
+
}
|
|
71
|
+
export function b64uDecode(s) {
|
|
72
|
+
const padded = s + "=".repeat((4 - (s.length % 4)) % 4);
|
|
73
|
+
const std = padded.replace(/-/g, "+").replace(/_/g, "/");
|
|
74
|
+
return new Uint8Array(Buffer.from(std, "base64"));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=jws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jws.js","sourceRoot":"","sources":["../../../src/nip/acme/jws.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** ACME wire-level DTOs (RFC 8555 + NPS-RFC-0002 §4.4) — plain interfaces. */
|
|
2
|
+
export interface DirectoryMeta {
|
|
3
|
+
termsOfService?: string;
|
|
4
|
+
website?: string;
|
|
5
|
+
caaIdentities?: readonly string[];
|
|
6
|
+
externalAccountRequired?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface Directory {
|
|
9
|
+
newNonce: string;
|
|
10
|
+
newAccount: string;
|
|
11
|
+
newOrder: string;
|
|
12
|
+
revokeCert?: string;
|
|
13
|
+
keyChange?: string;
|
|
14
|
+
meta?: DirectoryMeta;
|
|
15
|
+
}
|
|
16
|
+
export interface NewAccountPayload {
|
|
17
|
+
termsOfServiceAgreed?: boolean;
|
|
18
|
+
contact?: readonly string[];
|
|
19
|
+
onlyReturnExisting?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface Account {
|
|
22
|
+
status: string;
|
|
23
|
+
contact?: readonly string[];
|
|
24
|
+
orders?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface Identifier {
|
|
27
|
+
type: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
30
|
+
export interface NewOrderPayload {
|
|
31
|
+
identifiers: readonly Identifier[];
|
|
32
|
+
notBefore?: string;
|
|
33
|
+
notAfter?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ProblemDetail {
|
|
36
|
+
type: string;
|
|
37
|
+
detail?: string;
|
|
38
|
+
status?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface Order {
|
|
41
|
+
status: string;
|
|
42
|
+
expires?: string;
|
|
43
|
+
identifiers: readonly Identifier[];
|
|
44
|
+
authorizations: readonly string[];
|
|
45
|
+
finalize: string;
|
|
46
|
+
certificate?: string;
|
|
47
|
+
error?: ProblemDetail;
|
|
48
|
+
}
|
|
49
|
+
export interface Challenge {
|
|
50
|
+
type: string;
|
|
51
|
+
url: string;
|
|
52
|
+
status: string;
|
|
53
|
+
token: string;
|
|
54
|
+
validated?: string;
|
|
55
|
+
error?: ProblemDetail;
|
|
56
|
+
}
|
|
57
|
+
export interface Authorization {
|
|
58
|
+
status: string;
|
|
59
|
+
expires?: string;
|
|
60
|
+
identifier: Identifier;
|
|
61
|
+
challenges: readonly Challenge[];
|
|
62
|
+
}
|
|
63
|
+
export interface ChallengeRespondPayload {
|
|
64
|
+
/** base64url(Ed25519(token)) per NPS-RFC-0002 §4.4. */
|
|
65
|
+
agent_signature: string;
|
|
66
|
+
}
|
|
67
|
+
export interface FinalizePayload {
|
|
68
|
+
/** base64url(CSR DER). */
|
|
69
|
+
csr: string;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/nip/acme/messages.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAE9E,MAAM,WAAW,aAAa;IAC5B,cAAc,CAAC,EAAW,MAAM,CAAC;IACjC,OAAO,CAAC,EAAkB,MAAM,CAAC;IACjC,aAAa,CAAC,EAAY,SAAS,MAAM,EAAE,CAAC;IAC5C,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAK,MAAM,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,QAAQ,EAAK,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAG,MAAM,CAAC;IACpB,IAAI,CAAC,EAAQ,aAAa,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,OAAO,CAAC,EAAe,SAAS,MAAM,EAAE,CAAC;IACzC,kBAAkB,CAAC,EAAI,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,OAAO;IACtB,MAAM,EAAK,MAAM,CAAC;IAClB,OAAO,CAAC,EAAG,SAAS,MAAM,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAI,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAG,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IACnC,SAAS,CAAC,EAAG,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAI,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAK,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,MAAM,EAAU,MAAM,CAAC;IACvB,OAAO,CAAC,EAAQ,MAAM,CAAC;IACvB,WAAW,EAAK,SAAS,UAAU,EAAE,CAAC;IACtC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,EAAQ,MAAM,CAAC;IACvB,WAAW,CAAC,EAAI,MAAM,CAAC;IACvB,KAAK,CAAC,EAAU,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAQ,MAAM,CAAC;IACnB,GAAG,EAAS,MAAM,CAAC;IACnB,MAAM,EAAM,MAAM,CAAC;IACnB,KAAK,EAAO,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAM,aAAa,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAM,MAAM,CAAC;IACnB,OAAO,CAAC,EAAI,MAAM,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,uDAAuD;IACvD,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/nip/acme/messages.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,sCAAsC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as x509 from "@peculiar/x509";
|
|
2
|
+
export interface AcmeServerOptions {
|
|
3
|
+
caNid: string;
|
|
4
|
+
caKeys: CryptoKeyPair;
|
|
5
|
+
caRootCert: x509.X509Certificate;
|
|
6
|
+
certValidityMs: number;
|
|
7
|
+
}
|
|
8
|
+
export declare class AcmeServer {
|
|
9
|
+
readonly options: AcmeServerOptions;
|
|
10
|
+
private readonly server;
|
|
11
|
+
private readonly nonces;
|
|
12
|
+
private readonly accountJwks;
|
|
13
|
+
private readonly orders;
|
|
14
|
+
private readonly authzs;
|
|
15
|
+
private readonly challenges;
|
|
16
|
+
private readonly certs;
|
|
17
|
+
private boundPort;
|
|
18
|
+
constructor(options: AcmeServerOptions);
|
|
19
|
+
start(): Promise<this>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
get baseUrl(): string;
|
|
22
|
+
get directoryUrl(): string;
|
|
23
|
+
private dispatch;
|
|
24
|
+
private handleDirectory;
|
|
25
|
+
private handleNewNonce;
|
|
26
|
+
private handleNewAccount;
|
|
27
|
+
private handleNewOrder;
|
|
28
|
+
private handleAuthz;
|
|
29
|
+
private handleChallenge;
|
|
30
|
+
private handleFinalize;
|
|
31
|
+
private handleCert;
|
|
32
|
+
private handleOrder;
|
|
33
|
+
private mintNonce;
|
|
34
|
+
private consumeNonce;
|
|
35
|
+
private verifyAccount;
|
|
36
|
+
private readEnvelope;
|
|
37
|
+
private parseHeader;
|
|
38
|
+
private sendJson;
|
|
39
|
+
private sendProblem;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/nip/acme/server.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAevC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAY,MAAM,CAAC;IACxB,MAAM,EAAW,aAAa,CAAC;IAC/B,UAAU,EAAO,IAAI,CAAC,eAAe,CAAC;IACtC,cAAc,EAAG,MAAM,CAAC;CACzB;AA6BD,qBAAa,UAAU;aAUO,OAAO,EAAE,iBAAiB;IATtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAC1D,OAAO,CAAC,SAAS,CAAgB;gBAEL,OAAO,EAAE,iBAAiB;IAIhD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,OAAO,IAAU,MAAM,CAAiD;IAC5E,IAAI,YAAY,IAAK,MAAM,CAAwC;YAIrD,QAAQ;IAsBtB,OAAO,CAAC,eAAe;IASvB,OAAO,CAAC,cAAc;YAOR,gBAAgB;YAgChB,cAAc;YAwDd,WAAW;YA2BX,eAAe;YAyDf,cAAc;YAuEd,UAAU;YAmBV,WAAW;IAuBzB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;YAOP,YAAY;IAe1B,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,WAAW;CAKpB"}
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/**
|
|
4
|
+
* In-process ACME server implementing the `agent-01` challenge for NPS-RFC-0002 §4.4.
|
|
5
|
+
*
|
|
6
|
+
* Backed by Node's stdlib `http.createServer`. Suitable for tests and reference
|
|
7
|
+
* deployments. State is kept in memory.
|
|
8
|
+
*/
|
|
9
|
+
import * as ed25519 from "@noble/ed25519";
|
|
10
|
+
import { sha512 } from "@noble/hashes/sha512";
|
|
11
|
+
import { createServer } from "node:http";
|
|
12
|
+
import { randomBytes } from "node:crypto";
|
|
13
|
+
import * as x509 from "@peculiar/x509";
|
|
14
|
+
import { AssuranceLevel } from "../assurance-level.js";
|
|
15
|
+
import { ACME_CHALLENGE_FAILED } from "../error-codes.js";
|
|
16
|
+
import { issueLeaf } from "../x509/builder.js";
|
|
17
|
+
import * as Jws from "./jws.js";
|
|
18
|
+
import * as wire from "./wire.js";
|
|
19
|
+
ed25519.etc.sha512Sync = (...m) => sha512(ed25519.etc.concatBytes(...m));
|
|
20
|
+
x509.cryptoProvider.set(globalThis.crypto);
|
|
21
|
+
export class AcmeServer {
|
|
22
|
+
options;
|
|
23
|
+
server;
|
|
24
|
+
nonces = new Set();
|
|
25
|
+
accountJwks = new Map();
|
|
26
|
+
orders = new Map();
|
|
27
|
+
authzs = new Map();
|
|
28
|
+
challenges = new Map();
|
|
29
|
+
certs = new Map();
|
|
30
|
+
boundPort = 0;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.options = options;
|
|
33
|
+
this.server = createServer((req, res) => this.dispatch(req, res));
|
|
34
|
+
}
|
|
35
|
+
async start() {
|
|
36
|
+
await new Promise((resolve) => {
|
|
37
|
+
this.server.listen(0, "127.0.0.1", () => resolve());
|
|
38
|
+
});
|
|
39
|
+
const addr = this.server.address();
|
|
40
|
+
this.boundPort = typeof addr === "object" && addr !== null ? addr.port : 0;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
close() {
|
|
44
|
+
return new Promise((resolve) => this.server.close(() => resolve()));
|
|
45
|
+
}
|
|
46
|
+
get baseUrl() { return `http://127.0.0.1:${this.boundPort}`; }
|
|
47
|
+
get directoryUrl() { return `${this.baseUrl}/directory`; }
|
|
48
|
+
// ── Routing ──────────────────────────────────────────────────────────────
|
|
49
|
+
async dispatch(req, res) {
|
|
50
|
+
const url = req.url ?? "/";
|
|
51
|
+
const method = req.method ?? "GET";
|
|
52
|
+
try {
|
|
53
|
+
if (method === "GET" && url === "/directory")
|
|
54
|
+
return this.handleDirectory(res);
|
|
55
|
+
if (url === "/new-nonce")
|
|
56
|
+
return this.handleNewNonce(method, res);
|
|
57
|
+
if (method === "POST" && url === "/new-account")
|
|
58
|
+
return await this.handleNewAccount(req, res);
|
|
59
|
+
if (method === "POST" && url === "/new-order")
|
|
60
|
+
return await this.handleNewOrder(req, res);
|
|
61
|
+
if (method === "POST" && url.startsWith("/authz/"))
|
|
62
|
+
return await this.handleAuthz(req, res, url);
|
|
63
|
+
if (method === "POST" && url.startsWith("/chall/"))
|
|
64
|
+
return await this.handleChallenge(req, res, url);
|
|
65
|
+
if (method === "POST" && url.startsWith("/finalize/"))
|
|
66
|
+
return await this.handleFinalize(req, res, url);
|
|
67
|
+
if (method === "POST" && url.startsWith("/cert/"))
|
|
68
|
+
return await this.handleCert(req, res, url);
|
|
69
|
+
if (method === "POST" && url.startsWith("/order/"))
|
|
70
|
+
return await this.handleOrder(req, res, url);
|
|
71
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no such resource");
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
this.sendProblem(res, 500, "urn:ietf:params:acme:error:serverInternal", e.message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ── Endpoint handlers ────────────────────────────────────────────────────
|
|
78
|
+
handleDirectory(res) {
|
|
79
|
+
const dir = {
|
|
80
|
+
newNonce: `${this.baseUrl}/new-nonce`,
|
|
81
|
+
newAccount: `${this.baseUrl}/new-account`,
|
|
82
|
+
newOrder: `${this.baseUrl}/new-order`,
|
|
83
|
+
};
|
|
84
|
+
this.sendJson(res, 200, dir);
|
|
85
|
+
}
|
|
86
|
+
handleNewNonce(method, res) {
|
|
87
|
+
res.statusCode = method === "HEAD" ? 200 : 204;
|
|
88
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
89
|
+
res.setHeader("Cache-Control", "no-store");
|
|
90
|
+
res.end();
|
|
91
|
+
}
|
|
92
|
+
async handleNewAccount(req, res) {
|
|
93
|
+
const env = await this.readEnvelope(req, res);
|
|
94
|
+
if (!env)
|
|
95
|
+
return;
|
|
96
|
+
const header = this.parseHeader(env, res);
|
|
97
|
+
if (!header)
|
|
98
|
+
return;
|
|
99
|
+
if (!header.jwk) {
|
|
100
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", "newAccount must include a 'jwk' member");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
104
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const pub = Jws.publicKeyFromJwk(header.jwk);
|
|
108
|
+
if (Jws.verify(env, pub) === null) {
|
|
109
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", "JWS signature verify failed");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const accountId = `acc-${shortId()}`;
|
|
113
|
+
const accountUrl = `${this.baseUrl}/account/${accountId}`;
|
|
114
|
+
this.accountJwks.set(accountUrl, header.jwk);
|
|
115
|
+
res.statusCode = 201;
|
|
116
|
+
res.setHeader("Content-Type", "application/json");
|
|
117
|
+
res.setHeader("Location", accountUrl);
|
|
118
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
119
|
+
res.end(JSON.stringify({ status: wire.Status.VALID }));
|
|
120
|
+
}
|
|
121
|
+
async handleNewOrder(req, res) {
|
|
122
|
+
const env = await this.readEnvelope(req, res);
|
|
123
|
+
if (!env)
|
|
124
|
+
return;
|
|
125
|
+
const header = this.parseHeader(env, res);
|
|
126
|
+
if (!header)
|
|
127
|
+
return;
|
|
128
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
129
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!this.verifyAccount(env, header)) {
|
|
133
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:accountDoesNotExist", `unknown kid: ${header.kid ?? "<missing>"}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const payload = Jws.decodePayload(env);
|
|
137
|
+
if (!payload || !payload.identifiers?.length) {
|
|
138
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", "missing identifiers");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const ident = payload.identifiers[0];
|
|
142
|
+
const orderId = `ord-${shortId()}`;
|
|
143
|
+
const authzId = `az-${shortId()}`;
|
|
144
|
+
const challId = `ch-${shortId()}`;
|
|
145
|
+
const token = Jws.b64uEncode(new Uint8Array(randomBytes(32)));
|
|
146
|
+
const orderUrl = `${this.baseUrl}/order/${orderId}`;
|
|
147
|
+
const authzUrl = `${this.baseUrl}/authz/${authzId}`;
|
|
148
|
+
const challUrl = `${this.baseUrl}/chall/${challId}`;
|
|
149
|
+
const finalizeUrl = `${this.baseUrl}/finalize/${orderId}`;
|
|
150
|
+
this.challenges.set(challId, {
|
|
151
|
+
id: challId, type: wire.CHALLENGE_AGENT_01, status: wire.Status.PENDING,
|
|
152
|
+
token, authzId, accountUrl: header.kid ?? "",
|
|
153
|
+
});
|
|
154
|
+
this.authzs.set(authzId, {
|
|
155
|
+
id: authzId, identifier: ident, status: wire.Status.PENDING,
|
|
156
|
+
challengeIds: [challId], accountUrl: header.kid ?? "",
|
|
157
|
+
});
|
|
158
|
+
this.orders.set(orderId, {
|
|
159
|
+
id: orderId, identifier: ident, status: wire.Status.PENDING,
|
|
160
|
+
authzId, finalizeUrl, accountUrl: header.kid ?? "",
|
|
161
|
+
});
|
|
162
|
+
const order = {
|
|
163
|
+
status: wire.Status.PENDING,
|
|
164
|
+
identifiers: [ident],
|
|
165
|
+
authorizations: [authzUrl],
|
|
166
|
+
finalize: finalizeUrl,
|
|
167
|
+
};
|
|
168
|
+
res.statusCode = 201;
|
|
169
|
+
res.setHeader("Content-Type", "application/json");
|
|
170
|
+
res.setHeader("Location", orderUrl);
|
|
171
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
172
|
+
res.end(JSON.stringify(order));
|
|
173
|
+
}
|
|
174
|
+
async handleAuthz(req, res, url) {
|
|
175
|
+
const env = await this.readEnvelope(req, res);
|
|
176
|
+
if (!env)
|
|
177
|
+
return;
|
|
178
|
+
const header = this.parseHeader(env, res);
|
|
179
|
+
if (!header)
|
|
180
|
+
return;
|
|
181
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
182
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!this.verifyAccount(env, header)) {
|
|
186
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:unauthorized", "bad sig");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const id = url.replace(/^\/authz\//, "");
|
|
190
|
+
const az = this.authzs.get(id);
|
|
191
|
+
if (!az) {
|
|
192
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no authz");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const challenges = az.challengeIds.map((cid) => {
|
|
196
|
+
const cs = this.challenges.get(cid);
|
|
197
|
+
return {
|
|
198
|
+
type: cs.type, url: `${this.baseUrl}/chall/${cs.id}`,
|
|
199
|
+
status: cs.status, token: cs.token,
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
const authz = {
|
|
203
|
+
status: az.status, identifier: az.identifier, challenges,
|
|
204
|
+
};
|
|
205
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
206
|
+
this.sendJson(res, 200, authz);
|
|
207
|
+
}
|
|
208
|
+
async handleChallenge(req, res, url) {
|
|
209
|
+
const env = await this.readEnvelope(req, res);
|
|
210
|
+
if (!env)
|
|
211
|
+
return;
|
|
212
|
+
const header = this.parseHeader(env, res);
|
|
213
|
+
if (!header)
|
|
214
|
+
return;
|
|
215
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
216
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const accountJwk = this.accountJwks.get(header.kid ?? "");
|
|
220
|
+
if (!accountJwk) {
|
|
221
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:accountDoesNotExist", "unknown kid");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const accountPub = Jws.publicKeyFromJwk(accountJwk);
|
|
225
|
+
if (Jws.verify(env, accountPub) === null) {
|
|
226
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", "JWS sig fail");
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const id = url.replace(/^\/chall\//, "");
|
|
230
|
+
const ch = this.challenges.get(id);
|
|
231
|
+
if (!ch) {
|
|
232
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no chall");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const payload = Jws.decodePayload(env);
|
|
236
|
+
if (!payload?.agent_signature) {
|
|
237
|
+
ch.status = wire.Status.INVALID;
|
|
238
|
+
this.sendProblem(res, 400, ACME_CHALLENGE_FAILED, "missing agent_signature in challenge response");
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const sigBytes = Jws.b64uDecode(payload.agent_signature);
|
|
243
|
+
const tokenBytes = new TextEncoder().encode(ch.token);
|
|
244
|
+
if (!ed25519.verify(sigBytes, tokenBytes, accountPub)) {
|
|
245
|
+
ch.status = wire.Status.INVALID;
|
|
246
|
+
this.sendProblem(res, 400, ACME_CHALLENGE_FAILED, "agent-01 signature did not verify");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
ch.status = wire.Status.INVALID;
|
|
252
|
+
this.sendProblem(res, 400, ACME_CHALLENGE_FAILED, `agent-01 verification error: ${e.message}`);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
ch.status = wire.Status.VALID;
|
|
256
|
+
const az = this.authzs.get(ch.authzId);
|
|
257
|
+
if (az)
|
|
258
|
+
az.status = wire.Status.VALID;
|
|
259
|
+
for (const o of this.orders.values()) {
|
|
260
|
+
if (o.authzId === ch.authzId)
|
|
261
|
+
o.status = wire.Status.READY;
|
|
262
|
+
}
|
|
263
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
264
|
+
this.sendJson(res, 200, {
|
|
265
|
+
type: ch.type, url: `${this.baseUrl}/chall/${ch.id}`,
|
|
266
|
+
status: ch.status, token: ch.token,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
async handleFinalize(req, res, url) {
|
|
270
|
+
const env = await this.readEnvelope(req, res);
|
|
271
|
+
if (!env)
|
|
272
|
+
return;
|
|
273
|
+
const header = this.parseHeader(env, res);
|
|
274
|
+
if (!header)
|
|
275
|
+
return;
|
|
276
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
277
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!this.verifyAccount(env, header)) {
|
|
281
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:unauthorized", "bad sig");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const orderId = url.replace(/^\/finalize\//, "");
|
|
285
|
+
const os = this.orders.get(orderId);
|
|
286
|
+
if (!os) {
|
|
287
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no order");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (os.status !== wire.Status.READY) {
|
|
291
|
+
this.sendProblem(res, 403, "urn:ietf:params:acme:error:orderNotReady", `order is in state '${os.status}', not 'ready'`);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const fp = Jws.decodePayload(env);
|
|
295
|
+
if (!fp?.csr) {
|
|
296
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", "missing csr");
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
const csrDer = Jws.b64uDecode(fp.csr);
|
|
301
|
+
const csr = new x509.Pkcs10CertificateRequest(csrDer.buffer);
|
|
302
|
+
const subjectCn = (() => {
|
|
303
|
+
for (const rdn of csr.subject.split(",")) {
|
|
304
|
+
const t = rdn.trim();
|
|
305
|
+
if (t.startsWith("CN="))
|
|
306
|
+
return t.slice(3).replace(/\\([",+;<>\\])/g, "$1");
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
})();
|
|
310
|
+
if (subjectCn !== os.identifier.value) {
|
|
311
|
+
this.sendProblem(res, 400, "NIP-CERT-SUBJECT-NID-MISMATCH", `CSR subject CN '${subjectCn ?? ""}' does not match order identifier '${os.identifier.value}'`);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const subjectPub = await csr.publicKey.export();
|
|
315
|
+
const now = new Date();
|
|
316
|
+
const leaf = await issueLeaf({
|
|
317
|
+
subjectNid: os.identifier.value,
|
|
318
|
+
subjectPublicKey: subjectPub,
|
|
319
|
+
caKeys: this.options.caKeys,
|
|
320
|
+
issuerNid: this.options.caNid,
|
|
321
|
+
role: "agent",
|
|
322
|
+
assuranceLevel: AssuranceLevel.ANONYMOUS,
|
|
323
|
+
notBefore: new Date(now.getTime() - 60_000),
|
|
324
|
+
notAfter: new Date(now.getTime() + this.options.certValidityMs),
|
|
325
|
+
serialNumber: randomHexSerial(),
|
|
326
|
+
});
|
|
327
|
+
const certId = `crt-${shortId()}`;
|
|
328
|
+
const certUrl = `${this.baseUrl}/cert/${certId}`;
|
|
329
|
+
const pem = leaf.toString("pem") + this.options.caRootCert.toString("pem");
|
|
330
|
+
this.certs.set(certId, pem);
|
|
331
|
+
os.status = wire.Status.VALID;
|
|
332
|
+
os.certificateUrl = certUrl;
|
|
333
|
+
}
|
|
334
|
+
catch (e) {
|
|
335
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badCSR", `CSR processing failed: ${e.message}`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const authzUrl = `${this.baseUrl}/authz/${os.authzId}`;
|
|
339
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
340
|
+
this.sendJson(res, 200, {
|
|
341
|
+
status: os.status, identifiers: [os.identifier],
|
|
342
|
+
authorizations: [authzUrl], finalize: os.finalizeUrl,
|
|
343
|
+
certificate: os.certificateUrl,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async handleCert(req, res, url) {
|
|
347
|
+
const env = await this.readEnvelope(req, res);
|
|
348
|
+
if (!env)
|
|
349
|
+
return;
|
|
350
|
+
const header = this.parseHeader(env, res);
|
|
351
|
+
if (!header)
|
|
352
|
+
return;
|
|
353
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
354
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (!this.verifyAccount(env, header)) {
|
|
358
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:unauthorized", "bad sig");
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const certId = url.replace(/^\/cert\//, "");
|
|
362
|
+
const pem = this.certs.get(certId);
|
|
363
|
+
if (!pem) {
|
|
364
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no cert");
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
res.statusCode = 200;
|
|
368
|
+
res.setHeader("Content-Type", wire.CONTENT_TYPE_PEM_CERT);
|
|
369
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
370
|
+
res.end(pem);
|
|
371
|
+
}
|
|
372
|
+
async handleOrder(req, res, url) {
|
|
373
|
+
const env = await this.readEnvelope(req, res);
|
|
374
|
+
if (!env)
|
|
375
|
+
return;
|
|
376
|
+
const header = this.parseHeader(env, res);
|
|
377
|
+
if (!header)
|
|
378
|
+
return;
|
|
379
|
+
if (!this.consumeNonce(header.nonce)) {
|
|
380
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:badNonce", "invalid nonce");
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (!this.verifyAccount(env, header)) {
|
|
384
|
+
this.sendProblem(res, 401, "urn:ietf:params:acme:error:unauthorized", "bad sig");
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const orderId = url.replace(/^\/order\//, "");
|
|
388
|
+
const os = this.orders.get(orderId);
|
|
389
|
+
if (!os) {
|
|
390
|
+
this.sendProblem(res, 404, "urn:ietf:params:acme:error:malformed", "no order");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const authzUrl = `${this.baseUrl}/authz/${os.authzId}`;
|
|
394
|
+
res.setHeader("Replay-Nonce", this.mintNonce());
|
|
395
|
+
this.sendJson(res, 200, {
|
|
396
|
+
status: os.status, identifiers: [os.identifier],
|
|
397
|
+
authorizations: [authzUrl], finalize: os.finalizeUrl,
|
|
398
|
+
certificate: os.certificateUrl,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
// ── helpers ──────────────────────────────────────────────────────────────
|
|
402
|
+
mintNonce() {
|
|
403
|
+
const n = Jws.b64uEncode(new Uint8Array(randomBytes(16)));
|
|
404
|
+
this.nonces.add(n);
|
|
405
|
+
return n;
|
|
406
|
+
}
|
|
407
|
+
consumeNonce(nonce) {
|
|
408
|
+
return this.nonces.delete(nonce);
|
|
409
|
+
}
|
|
410
|
+
verifyAccount(env, header) {
|
|
411
|
+
if (!header.kid)
|
|
412
|
+
return false;
|
|
413
|
+
const jwk = this.accountJwks.get(header.kid);
|
|
414
|
+
if (!jwk)
|
|
415
|
+
return false;
|
|
416
|
+
return Jws.verify(env, Jws.publicKeyFromJwk(jwk)) !== null;
|
|
417
|
+
}
|
|
418
|
+
async readEnvelope(req, res) {
|
|
419
|
+
try {
|
|
420
|
+
const chunks = [];
|
|
421
|
+
for await (const chunk of req) {
|
|
422
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
423
|
+
}
|
|
424
|
+
const body = Buffer.concat(chunks).toString("utf8");
|
|
425
|
+
return JSON.parse(body);
|
|
426
|
+
}
|
|
427
|
+
catch (e) {
|
|
428
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", `body read/parse failed: ${e.message}`);
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
parseHeader(env, res) {
|
|
433
|
+
try {
|
|
434
|
+
return JSON.parse(new TextDecoder().decode(Jws.b64uDecode(env.protected)));
|
|
435
|
+
}
|
|
436
|
+
catch (e) {
|
|
437
|
+
this.sendProblem(res, 400, "urn:ietf:params:acme:error:malformed", `malformed protected header: ${e.message}`);
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
sendJson(res, status, body) {
|
|
442
|
+
res.statusCode = status;
|
|
443
|
+
res.setHeader("Content-Type", "application/json");
|
|
444
|
+
res.end(JSON.stringify(body));
|
|
445
|
+
}
|
|
446
|
+
sendProblem(res, status, type, detail) {
|
|
447
|
+
res.statusCode = status;
|
|
448
|
+
res.setHeader("Content-Type", wire.CONTENT_TYPE_PROBLEM);
|
|
449
|
+
res.end(JSON.stringify({ type, detail, status }));
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function shortId() {
|
|
453
|
+
return Buffer.from(randomBytes(8)).toString("hex");
|
|
454
|
+
}
|
|
455
|
+
function randomHexSerial() {
|
|
456
|
+
return Buffer.from(randomBytes(20)).toString("hex");
|
|
457
|
+
}
|
|
458
|
+
//# sourceMappingURL=server.js.map
|