@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
package/tests/ncp/frames.test.ts
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
|
|
3
|
-
//
|
|
4
|
-
// NCP Test Cases — Frame types + Tier-1 JSON codec
|
|
5
|
-
// Covers: NCP-E-01, E-03, NCP-A-01 to A-04, NCP-C-01 to C-04, NCP-D-01 to D-04
|
|
6
|
-
// Source: test/ncp_test_cases.md §2, §3
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect } from "vitest";
|
|
9
|
-
import { NcpError } from "../../src/core/frame-header.js";
|
|
10
|
-
import { encodeJson, decodeJson } from "../../src/core/codecs/tier1-json-codec.js";
|
|
11
|
-
import {
|
|
12
|
-
computeAnchorId,
|
|
13
|
-
validateAnchorFrame,
|
|
14
|
-
type AnchorFrame,
|
|
15
|
-
type FrameSchema,
|
|
16
|
-
} from "../../src/ncp/frames/anchor-frame.js";
|
|
17
|
-
import { validateCapsFrame, type CapsFrame } from "../../src/ncp/frames/caps-frame.js";
|
|
18
|
-
import { validateDiffSeq, type DiffFrame } from "../../src/ncp/frames/diff-frame.js";
|
|
19
|
-
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
// Helpers
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
|
|
24
|
-
const testSchema: FrameSchema = {
|
|
25
|
-
fields: [
|
|
26
|
-
{ name: "id", type: "uint64", semantic: "entity.id" },
|
|
27
|
-
{ name: "name", type: "string", semantic: "entity.label" },
|
|
28
|
-
{ name: "price", type: "decimal", semantic: "commerce.price.usd" },
|
|
29
|
-
{ name: "stock", type: "uint64", semantic: "commerce.inventory.count" },
|
|
30
|
-
],
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function makeValidAnchor(): AnchorFrame {
|
|
34
|
-
const anchor_id = computeAnchorId(testSchema);
|
|
35
|
-
return { frame: "0x01", anchor_id, schema: testSchema, ttl: 3600 };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// ===========================================================================
|
|
39
|
-
// Group 2: Encoding Tiers (Tier-1 JSON)
|
|
40
|
-
// ===========================================================================
|
|
41
|
-
|
|
42
|
-
describe("Group 2: Encoding — Tier-1 JSON", () => {
|
|
43
|
-
// -----------------------------------------------------------------------
|
|
44
|
-
// NCP-E-01: Tier-1 JSON (Valid)
|
|
45
|
-
// Spec: §3.2, §8 — Flags T0/T1 = 00
|
|
46
|
-
// -----------------------------------------------------------------------
|
|
47
|
-
it("NCP-E-01: encodes and decodes valid JSON payload", () => {
|
|
48
|
-
const anchor = makeValidAnchor();
|
|
49
|
-
const bytes = encodeJson(anchor);
|
|
50
|
-
const decoded = decodeJson(bytes) as AnchorFrame;
|
|
51
|
-
|
|
52
|
-
expect(decoded.frame).toBe("0x01");
|
|
53
|
-
expect(decoded.anchor_id).toBe(anchor.anchor_id);
|
|
54
|
-
expect(decoded.schema.fields).toHaveLength(4);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// -----------------------------------------------------------------------
|
|
58
|
-
// NCP-E-03: Tier-1 JSON (Malformed)
|
|
59
|
-
// Spec: §3.2, §8 — Invalid JSON → NPS-CLIENT-BAD-FRAME
|
|
60
|
-
// -----------------------------------------------------------------------
|
|
61
|
-
it("NCP-E-03: rejects malformed JSON payload", () => {
|
|
62
|
-
const bad = new TextEncoder().encode('{"frame":"0x01", "anchor_id":');
|
|
63
|
-
expect(() => decodeJson(bad)).toThrow(NcpError);
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
decodeJson(bad);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
expect((e as NcpError).code).toBe("NPS-CLIENT-BAD-FRAME");
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// ===========================================================================
|
|
74
|
-
// Group 3.1: AnchorFrame (0x01)
|
|
75
|
-
// ===========================================================================
|
|
76
|
-
|
|
77
|
-
describe("Group 3.1: AnchorFrame", () => {
|
|
78
|
-
// -----------------------------------------------------------------------
|
|
79
|
-
// NCP-A-01: Valid Anchor
|
|
80
|
-
// Spec: §4.1 — anchor_id = SHA-256(JCS(schema))
|
|
81
|
-
// -----------------------------------------------------------------------
|
|
82
|
-
it("NCP-A-01: computes correct anchor_id via JCS + SHA-256", () => {
|
|
83
|
-
const anchor_id = computeAnchorId(testSchema);
|
|
84
|
-
|
|
85
|
-
expect(anchor_id).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
86
|
-
|
|
87
|
-
// Same schema produces same ID (deterministic)
|
|
88
|
-
expect(computeAnchorId(testSchema)).toBe(anchor_id);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("NCP-A-01: different field order produces same anchor_id (JCS normalises)", () => {
|
|
92
|
-
const schemaA: FrameSchema = {
|
|
93
|
-
fields: [
|
|
94
|
-
{ name: "id", type: "uint64" },
|
|
95
|
-
{ name: "name", type: "string" },
|
|
96
|
-
],
|
|
97
|
-
};
|
|
98
|
-
const schemaB: FrameSchema = {
|
|
99
|
-
fields: [
|
|
100
|
-
{ name: "name", type: "string" },
|
|
101
|
-
{ name: "id", type: "uint64" },
|
|
102
|
-
],
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// NOTE: JCS sorts object keys, but array order is preserved.
|
|
106
|
-
// Different field ORDER in the array produces different hashes.
|
|
107
|
-
// Only different key ORDER within objects is normalised.
|
|
108
|
-
const idA = computeAnchorId(schemaA);
|
|
109
|
-
const idB = computeAnchorId(schemaB);
|
|
110
|
-
|
|
111
|
-
// Array order matters — these are different schemas
|
|
112
|
-
expect(idA).not.toBe(idB);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("NCP-A-01: validates and caches valid anchor frame", () => {
|
|
116
|
-
const anchor = makeValidAnchor();
|
|
117
|
-
expect(() => validateAnchorFrame(anchor)).not.toThrow();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// -----------------------------------------------------------------------
|
|
121
|
-
// NCP-A-02: Anchor ID Mismatch
|
|
122
|
-
// Spec: §4.1 — Provided anchor_id != SHA-256(JCS(schema))
|
|
123
|
-
// -----------------------------------------------------------------------
|
|
124
|
-
it("NCP-A-02: rejects anchor with wrong anchor_id", () => {
|
|
125
|
-
const anchor: AnchorFrame = {
|
|
126
|
-
frame: "0x01",
|
|
127
|
-
anchor_id: "sha256:0000000000000000000000000000000000000000000000000000000000000000",
|
|
128
|
-
schema: testSchema,
|
|
129
|
-
ttl: 3600,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
expect(() => validateAnchorFrame(anchor)).toThrow(NcpError);
|
|
133
|
-
try {
|
|
134
|
-
validateAnchorFrame(anchor);
|
|
135
|
-
} catch (e) {
|
|
136
|
-
expect((e as NcpError).code).toBe("NCP-ANCHOR-SCHEMA-INVALID");
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// -----------------------------------------------------------------------
|
|
141
|
-
// NCP-A-03: Anchor Poisoning — tested in Step 7 (AnchorCache)
|
|
142
|
-
// -----------------------------------------------------------------------
|
|
143
|
-
|
|
144
|
-
// -----------------------------------------------------------------------
|
|
145
|
-
// NCP-A-04: Invalid Schema Field
|
|
146
|
-
// Spec: §4.1 — Unsupported type (e.g. "tensor")
|
|
147
|
-
// -----------------------------------------------------------------------
|
|
148
|
-
it("NCP-A-04: rejects schema with unsupported field type", () => {
|
|
149
|
-
const badSchema: FrameSchema = {
|
|
150
|
-
fields: [
|
|
151
|
-
{ name: "id", type: "uint64" },
|
|
152
|
-
{ name: "embedding", type: "tensor" }, // not in valid types
|
|
153
|
-
],
|
|
154
|
-
};
|
|
155
|
-
const anchor_id = computeAnchorId(badSchema);
|
|
156
|
-
const anchor: AnchorFrame = {
|
|
157
|
-
frame: "0x01",
|
|
158
|
-
anchor_id,
|
|
159
|
-
schema: badSchema,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
expect(() => validateAnchorFrame(anchor)).toThrow(NcpError);
|
|
163
|
-
try {
|
|
164
|
-
validateAnchorFrame(anchor);
|
|
165
|
-
} catch (e) {
|
|
166
|
-
expect((e as NcpError).code).toBe("NCP-ANCHOR-SCHEMA-INVALID");
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("NCP-A-04: accepts all valid field types", () => {
|
|
171
|
-
const allTypes: FrameSchema = {
|
|
172
|
-
fields: [
|
|
173
|
-
{ name: "a", type: "string" },
|
|
174
|
-
{ name: "b", type: "uint64" },
|
|
175
|
-
{ name: "c", type: "int64" },
|
|
176
|
-
{ name: "d", type: "decimal" },
|
|
177
|
-
{ name: "e", type: "bool" },
|
|
178
|
-
{ name: "f", type: "timestamp" },
|
|
179
|
-
{ name: "g", type: "bytes" },
|
|
180
|
-
{ name: "h", type: "object" },
|
|
181
|
-
{ name: "i", type: "array" },
|
|
182
|
-
],
|
|
183
|
-
};
|
|
184
|
-
const anchor_id = computeAnchorId(allTypes);
|
|
185
|
-
const anchor: AnchorFrame = { frame: "0x01", anchor_id, schema: allTypes };
|
|
186
|
-
expect(() => validateAnchorFrame(anchor)).not.toThrow();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// NCP-A-05 and NCP-A-06 — tested in Step 7 (AnchorCache)
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// ===========================================================================
|
|
193
|
-
// Group 3.4: CapsFrame (0x04)
|
|
194
|
-
// ===========================================================================
|
|
195
|
-
|
|
196
|
-
describe("Group 3.4: CapsFrame", () => {
|
|
197
|
-
// -----------------------------------------------------------------------
|
|
198
|
-
// NCP-C-01: Empty Data
|
|
199
|
-
// Spec: §4.4 — count=0, data=[] is valid
|
|
200
|
-
// -----------------------------------------------------------------------
|
|
201
|
-
it("NCP-C-01: accepts empty data with count=0", () => {
|
|
202
|
-
const caps: CapsFrame = {
|
|
203
|
-
frame: "0x04",
|
|
204
|
-
anchor_ref: "sha256:abc123",
|
|
205
|
-
count: 0,
|
|
206
|
-
data: [],
|
|
207
|
-
};
|
|
208
|
-
expect(() => validateCapsFrame(caps)).not.toThrow();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// -----------------------------------------------------------------------
|
|
212
|
-
// NCP-C-02: Count Mismatch
|
|
213
|
-
// Spec: §4.4 — count MUST equal len(data)
|
|
214
|
-
// -----------------------------------------------------------------------
|
|
215
|
-
it("NCP-C-02: rejects count mismatch", () => {
|
|
216
|
-
const caps: CapsFrame = {
|
|
217
|
-
frame: "0x04",
|
|
218
|
-
anchor_ref: "sha256:abc123",
|
|
219
|
-
count: 3,
|
|
220
|
-
data: [{ id: 1 }, { id: 2 }], // 2 items but count says 3
|
|
221
|
-
};
|
|
222
|
-
expect(() => validateCapsFrame(caps)).toThrow(NcpError);
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
validateCapsFrame(caps);
|
|
226
|
-
} catch (e) {
|
|
227
|
-
expect((e as NcpError).code).toBe("NPS-CLIENT-BAD-FRAME");
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// -----------------------------------------------------------------------
|
|
232
|
-
// NCP-C-03: Cursor Handling
|
|
233
|
-
// Spec: §4.4 — Base64-URL next_cursor
|
|
234
|
-
// -----------------------------------------------------------------------
|
|
235
|
-
it("NCP-C-03: preserves Base64-URL cursor in round-trip", () => {
|
|
236
|
-
const caps: CapsFrame = {
|
|
237
|
-
frame: "0x04",
|
|
238
|
-
anchor_ref: "sha256:abc123",
|
|
239
|
-
count: 2,
|
|
240
|
-
data: [{ id: 1001 }, { id: 1002 }],
|
|
241
|
-
next_cursor: "eyJpZCI6MTAwM30", // {"id":1003}
|
|
242
|
-
};
|
|
243
|
-
expect(() => validateCapsFrame(caps)).not.toThrow();
|
|
244
|
-
|
|
245
|
-
const bytes = encodeJson(caps);
|
|
246
|
-
const decoded = decodeJson(bytes) as CapsFrame;
|
|
247
|
-
expect(decoded.next_cursor).toBe("eyJpZCI6MTAwM30");
|
|
248
|
-
|
|
249
|
-
// Decode the cursor
|
|
250
|
-
const cursorData = JSON.parse(
|
|
251
|
-
Buffer.from(decoded.next_cursor!, "base64url").toString(),
|
|
252
|
-
);
|
|
253
|
-
expect(cursorData.id).toBe(1003);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
// -----------------------------------------------------------------------
|
|
257
|
-
// NCP-C-04: Token Budget Hint
|
|
258
|
-
// Spec: §4.4 — token_est is informational
|
|
259
|
-
// -----------------------------------------------------------------------
|
|
260
|
-
it("NCP-C-04: preserves token_est in round-trip", () => {
|
|
261
|
-
const caps: CapsFrame = {
|
|
262
|
-
frame: "0x04",
|
|
263
|
-
anchor_ref: "sha256:abc123",
|
|
264
|
-
count: 1,
|
|
265
|
-
data: [{ id: 1 }],
|
|
266
|
-
token_est: 180,
|
|
267
|
-
};
|
|
268
|
-
const bytes = encodeJson(caps);
|
|
269
|
-
const decoded = decodeJson(bytes) as CapsFrame;
|
|
270
|
-
expect(decoded.token_est).toBe(180);
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// ===========================================================================
|
|
275
|
-
// Group 3.2: DiffFrame (0x02)
|
|
276
|
-
// ===========================================================================
|
|
277
|
-
|
|
278
|
-
describe("Group 3.2: DiffFrame", () => {
|
|
279
|
-
// -----------------------------------------------------------------------
|
|
280
|
-
// NCP-D-01: Valid Patch
|
|
281
|
-
// Spec: §4.2 — RFC 6902 JSON Patch applied to anchor data
|
|
282
|
-
// -----------------------------------------------------------------------
|
|
283
|
-
it("NCP-D-01: round-trips valid DiffFrame with JSON patch", () => {
|
|
284
|
-
const diff: DiffFrame = {
|
|
285
|
-
frame: "0x02",
|
|
286
|
-
anchor_ref: "sha256:abc123",
|
|
287
|
-
base_seq: 42,
|
|
288
|
-
patch_format: "json_patch",
|
|
289
|
-
entity_id: "product:1001",
|
|
290
|
-
patch: [
|
|
291
|
-
{ op: "replace", path: "/price", value: 299.0 },
|
|
292
|
-
{ op: "replace", path: "/stock", value: 48 },
|
|
293
|
-
],
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
const bytes = encodeJson(diff);
|
|
297
|
-
const decoded = decodeJson(bytes) as DiffFrame;
|
|
298
|
-
|
|
299
|
-
expect(decoded.anchor_ref).toBe("sha256:abc123");
|
|
300
|
-
expect(decoded.base_seq).toBe(42);
|
|
301
|
-
expect(decoded.patch).toHaveLength(2);
|
|
302
|
-
expect(decoded.patch[0]!.op).toBe("replace");
|
|
303
|
-
expect(decoded.patch[0]!.value).toBe(299.0);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// -----------------------------------------------------------------------
|
|
307
|
-
// NCP-D-02: Sequence Gap
|
|
308
|
-
// Spec: §4.2 — base_seq must match receiver's current sequence
|
|
309
|
-
// -----------------------------------------------------------------------
|
|
310
|
-
it("NCP-D-02: rejects sequence gap", () => {
|
|
311
|
-
const diff: DiffFrame = {
|
|
312
|
-
frame: "0x02",
|
|
313
|
-
anchor_ref: "sha256:abc123",
|
|
314
|
-
base_seq: 3,
|
|
315
|
-
patch: [{ op: "replace", path: "/price", value: 100 }],
|
|
316
|
-
};
|
|
317
|
-
const currentSeq = 5;
|
|
318
|
-
|
|
319
|
-
expect(() => validateDiffSeq(diff, currentSeq)).toThrow(NcpError);
|
|
320
|
-
try {
|
|
321
|
-
validateDiffSeq(diff, currentSeq);
|
|
322
|
-
} catch (e) {
|
|
323
|
-
expect((e as NcpError).code).toBe("NCP-STREAM-SEQ-GAP");
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("NCP-D-02: accepts matching sequence", () => {
|
|
328
|
-
const diff: DiffFrame = {
|
|
329
|
-
frame: "0x02",
|
|
330
|
-
anchor_ref: "sha256:abc123",
|
|
331
|
-
base_seq: 5,
|
|
332
|
-
patch: [{ op: "replace", path: "/price", value: 100 }],
|
|
333
|
-
};
|
|
334
|
-
expect(() => validateDiffSeq(diff, 5)).not.toThrow();
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// -----------------------------------------------------------------------
|
|
338
|
-
// NCP-D-03: Patch Target Invalid
|
|
339
|
-
// Spec: §4.2 — Patch path not in schema
|
|
340
|
-
// NOTE: Full validation requires schema context. Tested with fast-json-patch
|
|
341
|
-
// at integration level. Here we verify the DiffFrame structure.
|
|
342
|
-
// -----------------------------------------------------------------------
|
|
343
|
-
it("NCP-D-03: DiffFrame preserves patch paths for validation", () => {
|
|
344
|
-
const diff: DiffFrame = {
|
|
345
|
-
frame: "0x02",
|
|
346
|
-
anchor_ref: "sha256:abc123",
|
|
347
|
-
base_seq: 0,
|
|
348
|
-
patch: [{ op: "replace", path: "/nonexistent_field", value: 42 }],
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
const bytes = encodeJson(diff);
|
|
352
|
-
const decoded = decodeJson(bytes) as DiffFrame;
|
|
353
|
-
expect(decoded.patch[0]!.path).toBe("/nonexistent_field");
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
// -----------------------------------------------------------------------
|
|
357
|
-
// NCP-D-04: Missing Ref — tested in Step 7 (AnchorCache lookup)
|
|
358
|
-
// -----------------------------------------------------------------------
|
|
359
|
-
});
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
|
|
3
|
-
//
|
|
4
|
-
// NCP Test Cases — Group 1: Framing & Header (NCP-F-01 to NCP-F-07)
|
|
5
|
-
// Source: test/ncp_test_cases.md §1
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect } from "vitest";
|
|
8
|
-
import {
|
|
9
|
-
parseFrameHeader,
|
|
10
|
-
writeFrameHeader,
|
|
11
|
-
buildFlags,
|
|
12
|
-
EncodingTier,
|
|
13
|
-
FrameType,
|
|
14
|
-
NcpError,
|
|
15
|
-
DEFAULT_HEADER_SIZE,
|
|
16
|
-
EXTENDED_HEADER_SIZE,
|
|
17
|
-
} from "../../src/core/frame-header.js";
|
|
18
|
-
|
|
19
|
-
describe("Group 1: Framing & Header", () => {
|
|
20
|
-
// -----------------------------------------------------------------------
|
|
21
|
-
// NCP-F-01: Standard Header (Valid)
|
|
22
|
-
// Spec: §3.1 — Default 4-byte header
|
|
23
|
-
// -----------------------------------------------------------------------
|
|
24
|
-
it("NCP-F-01: decodes standard 4-byte header", () => {
|
|
25
|
-
// AnchorFrame (0x01), flags=0x00 (JSON, no flags), payload=32 bytes
|
|
26
|
-
const buf = new Uint8Array([0x01, 0x00, 0x00, 0x20]);
|
|
27
|
-
const h = parseFrameHeader(buf);
|
|
28
|
-
|
|
29
|
-
expect(h.frameType).toBe(FrameType.Anchor);
|
|
30
|
-
expect(h.tier).toBe(EncodingTier.Json);
|
|
31
|
-
expect(h.isFinal).toBe(false);
|
|
32
|
-
expect(h.isEncrypted).toBe(false);
|
|
33
|
-
expect(h.isExtended).toBe(false);
|
|
34
|
-
expect(h.payloadLength).toBe(32);
|
|
35
|
-
expect(h.headerSize).toBe(DEFAULT_HEADER_SIZE);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// -----------------------------------------------------------------------
|
|
39
|
-
// NCP-F-02: Extended Header (Valid)
|
|
40
|
-
// Spec: §3.1 — Extended 8-byte header (EXT=1)
|
|
41
|
-
// -----------------------------------------------------------------------
|
|
42
|
-
it("NCP-F-02: decodes extended 8-byte header with EXT=1", () => {
|
|
43
|
-
// AnchorFrame, EXT=1 (0x80), payload=65536 (just over default max)
|
|
44
|
-
const buf = new Uint8Array([0x01, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]);
|
|
45
|
-
const h = parseFrameHeader(buf);
|
|
46
|
-
|
|
47
|
-
expect(h.frameType).toBe(FrameType.Anchor);
|
|
48
|
-
expect(h.isExtended).toBe(true);
|
|
49
|
-
expect(h.payloadLength).toBe(65536);
|
|
50
|
-
expect(h.headerSize).toBe(EXTENDED_HEADER_SIZE);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// -----------------------------------------------------------------------
|
|
54
|
-
// NCP-F-03: EXT Flag Mismatch (Low)
|
|
55
|
-
// Spec: §3.1, §3.3 — EXT=1 with small payload is valid but inefficient
|
|
56
|
-
// -----------------------------------------------------------------------
|
|
57
|
-
it("NCP-F-03: accepts EXT=1 with small payload (inefficient but valid)", () => {
|
|
58
|
-
// Extended header, payload=100 bytes (well under 64KB)
|
|
59
|
-
const buf = new Uint8Array([0x01, 0x80, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00]);
|
|
60
|
-
const h = parseFrameHeader(buf);
|
|
61
|
-
|
|
62
|
-
expect(h.isExtended).toBe(true);
|
|
63
|
-
expect(h.payloadLength).toBe(100);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// -----------------------------------------------------------------------
|
|
67
|
-
// NCP-F-04: EXT Flag Mismatch (High) — NCP-FRAME-PAYLOAD-TOO-LARGE
|
|
68
|
-
// NOTE: This test belongs at the codec level (Step 5). Default header
|
|
69
|
-
// uint16 maxes at 65535 — can't physically express > 64KB.
|
|
70
|
-
// Codec validates payload against negotiated max_frame_payload.
|
|
71
|
-
// -----------------------------------------------------------------------
|
|
72
|
-
|
|
73
|
-
// -----------------------------------------------------------------------
|
|
74
|
-
// NCP-F-05: Buffer Underrun
|
|
75
|
-
// Spec: §3.1 — Incomplete data
|
|
76
|
-
// -----------------------------------------------------------------------
|
|
77
|
-
it("NCP-F-05: errors when buffer too small for header", () => {
|
|
78
|
-
// Only 1 byte — need at least 2 for type + flags
|
|
79
|
-
expect(() => parseFrameHeader(new Uint8Array([0x01]))).toThrow(NcpError);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("NCP-F-05: errors when buffer too small for default header", () => {
|
|
83
|
-
// 3 bytes — need 4 for default header
|
|
84
|
-
expect(() => parseFrameHeader(new Uint8Array([0x01, 0x00, 0x00]))).toThrow(
|
|
85
|
-
NcpError,
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("NCP-F-05: errors when buffer too small for extended header", () => {
|
|
90
|
-
// 4 bytes with EXT=1 — need 8
|
|
91
|
-
expect(() =>
|
|
92
|
-
parseFrameHeader(new Uint8Array([0x01, 0x80, 0x00, 0x00])),
|
|
93
|
-
).toThrow(NcpError);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// -----------------------------------------------------------------------
|
|
97
|
-
// NCP-F-06: Buffer Overrun
|
|
98
|
-
// Spec: §3.1 — Extra bytes are buffered for next frame
|
|
99
|
-
// -----------------------------------------------------------------------
|
|
100
|
-
it("NCP-F-06: parses header from oversized buffer", () => {
|
|
101
|
-
// 4-byte header + 250 extra bytes — header parses, remainder ignored
|
|
102
|
-
const buf = new Uint8Array(254);
|
|
103
|
-
buf[0] = 0x01; // AnchorFrame
|
|
104
|
-
buf[1] = 0x00; // no flags
|
|
105
|
-
buf[2] = 0x00;
|
|
106
|
-
buf[3] = 0x64; // payload = 100
|
|
107
|
-
|
|
108
|
-
const h = parseFrameHeader(buf);
|
|
109
|
-
expect(h.payloadLength).toBe(100);
|
|
110
|
-
// Codec would read buf[4..104] as payload, buffer buf[104..] for next frame
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// -----------------------------------------------------------------------
|
|
114
|
-
// NCP-F-07: Reserved Flags Non-Zero
|
|
115
|
-
// Spec: §3.2 — Bits 4-6 MUST be 0
|
|
116
|
-
// -----------------------------------------------------------------------
|
|
117
|
-
it("NCP-F-07: rejects non-zero reserved flag bits (bit 4)", () => {
|
|
118
|
-
const buf = new Uint8Array([0x01, 0x10, 0x00, 0x20]); // bit 4 set
|
|
119
|
-
expect(() => parseFrameHeader(buf)).toThrow(NcpError);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("NCP-F-07: rejects non-zero reserved flag bits (bit 5)", () => {
|
|
123
|
-
const buf = new Uint8Array([0x01, 0x20, 0x00, 0x20]); // bit 5 set
|
|
124
|
-
expect(() => parseFrameHeader(buf)).toThrow(NcpError);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("NCP-F-07: rejects non-zero reserved flag bits (bit 6)", () => {
|
|
128
|
-
const buf = new Uint8Array([0x01, 0x40, 0x00, 0x20]); // bit 6 set
|
|
129
|
-
expect(() => parseFrameHeader(buf)).toThrow(NcpError);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("NCP-F-07: error code is NCP-FRAME-FLAGS-INVALID", () => {
|
|
133
|
-
const buf = new Uint8Array([0x01, 0x20, 0x00, 0x20]);
|
|
134
|
-
try {
|
|
135
|
-
parseFrameHeader(buf);
|
|
136
|
-
expect.unreachable("should have thrown");
|
|
137
|
-
} catch (e) {
|
|
138
|
-
expect(e).toBeInstanceOf(NcpError);
|
|
139
|
-
expect((e as NcpError).code).toBe("NCP-FRAME-FLAGS-INVALID");
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// -----------------------------------------------------------------------
|
|
144
|
-
// Additional: Round-trip, ENC flag, write validation
|
|
145
|
-
// -----------------------------------------------------------------------
|
|
146
|
-
it("round-trips default header", () => {
|
|
147
|
-
const flags = buildFlags({ tier: EncodingTier.MsgPack, final: true });
|
|
148
|
-
const original = {
|
|
149
|
-
frameType: FrameType.Caps,
|
|
150
|
-
flags,
|
|
151
|
-
payloadLength: 1024,
|
|
152
|
-
tier: EncodingTier.MsgPack,
|
|
153
|
-
isFinal: true,
|
|
154
|
-
isEncrypted: false,
|
|
155
|
-
isExtended: false,
|
|
156
|
-
headerSize: DEFAULT_HEADER_SIZE,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const buf = new Uint8Array(DEFAULT_HEADER_SIZE);
|
|
160
|
-
writeFrameHeader(original, buf);
|
|
161
|
-
const parsed = parseFrameHeader(buf);
|
|
162
|
-
|
|
163
|
-
expect(parsed.frameType).toBe(original.frameType);
|
|
164
|
-
expect(parsed.payloadLength).toBe(original.payloadLength);
|
|
165
|
-
expect(parsed.tier).toBe(EncodingTier.MsgPack);
|
|
166
|
-
expect(parsed.isFinal).toBe(true);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("round-trips extended header", () => {
|
|
170
|
-
const flags = buildFlags({ tier: EncodingTier.Json, extended: true });
|
|
171
|
-
const original = {
|
|
172
|
-
frameType: FrameType.Stream,
|
|
173
|
-
flags,
|
|
174
|
-
payloadLength: 100_000,
|
|
175
|
-
tier: EncodingTier.Json,
|
|
176
|
-
isFinal: false,
|
|
177
|
-
isEncrypted: false,
|
|
178
|
-
isExtended: true,
|
|
179
|
-
headerSize: EXTENDED_HEADER_SIZE,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const buf = new Uint8Array(EXTENDED_HEADER_SIZE);
|
|
183
|
-
writeFrameHeader(original, buf);
|
|
184
|
-
const parsed = parseFrameHeader(buf);
|
|
185
|
-
|
|
186
|
-
expect(parsed.frameType).toBe(original.frameType);
|
|
187
|
-
expect(parsed.payloadLength).toBe(100_000);
|
|
188
|
-
expect(parsed.isExtended).toBe(true);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("detects ENC flag", () => {
|
|
192
|
-
const flags = buildFlags({ encrypted: true });
|
|
193
|
-
const buf = new Uint8Array([0x01, flags, 0x00, 0x20]);
|
|
194
|
-
const h = parseFrameHeader(buf);
|
|
195
|
-
expect(h.isEncrypted).toBe(true);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("write errors on undersized buffer", () => {
|
|
199
|
-
const h = {
|
|
200
|
-
frameType: FrameType.Anchor,
|
|
201
|
-
flags: 0x00,
|
|
202
|
-
payloadLength: 32,
|
|
203
|
-
tier: EncodingTier.Json,
|
|
204
|
-
isFinal: false,
|
|
205
|
-
isEncrypted: false,
|
|
206
|
-
isExtended: false,
|
|
207
|
-
headerSize: DEFAULT_HEADER_SIZE,
|
|
208
|
-
};
|
|
209
|
-
expect(() => writeFrameHeader(h, new Uint8Array(2))).toThrow();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("extended header reserved bytes are zero", () => {
|
|
213
|
-
const flags = buildFlags({ extended: true });
|
|
214
|
-
const h = {
|
|
215
|
-
frameType: FrameType.Anchor,
|
|
216
|
-
flags,
|
|
217
|
-
payloadLength: 70_000,
|
|
218
|
-
tier: EncodingTier.Json,
|
|
219
|
-
isFinal: false,
|
|
220
|
-
isEncrypted: false,
|
|
221
|
-
isExtended: true,
|
|
222
|
-
headerSize: EXTENDED_HEADER_SIZE,
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
const buf = new Uint8Array(EXTENDED_HEADER_SIZE);
|
|
226
|
-
buf[6] = 0xff; // pre-fill to prove write zeros
|
|
227
|
-
buf[7] = 0xff;
|
|
228
|
-
writeFrameHeader(h, buf);
|
|
229
|
-
|
|
230
|
-
expect(buf[6]).toBe(0);
|
|
231
|
-
expect(buf[7]).toBe(0);
|
|
232
|
-
});
|
|
233
|
-
});
|