@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/src/ndp/frames.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { EncodingTier, FrameType } from "../core/frames.js";
|
|
5
|
-
import type { NpsFrame } from "../core/codec.js";
|
|
6
|
-
|
|
7
|
-
export interface NdpAddress {
|
|
8
|
-
host: string;
|
|
9
|
-
port: number;
|
|
10
|
-
protocol: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface NdpGraphNode {
|
|
14
|
-
nid: string;
|
|
15
|
-
addresses: readonly NdpAddress[];
|
|
16
|
-
capabilities: readonly string[];
|
|
17
|
-
nodeType?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface NdpResolveResult {
|
|
21
|
-
host: string;
|
|
22
|
-
port: number;
|
|
23
|
-
ttl: number;
|
|
24
|
-
certFingerprint?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class AnnounceFrame implements NpsFrame {
|
|
28
|
-
readonly frameType = FrameType.ANNOUNCE;
|
|
29
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
public readonly nid: string,
|
|
33
|
-
public readonly addresses: readonly NdpAddress[],
|
|
34
|
-
public readonly capabilities: readonly string[],
|
|
35
|
-
public readonly ttl: number,
|
|
36
|
-
public readonly timestamp: string,
|
|
37
|
-
public readonly signature: string,
|
|
38
|
-
public readonly nodeType?: string,
|
|
39
|
-
) {}
|
|
40
|
-
|
|
41
|
-
unsignedDict(): Record<string, unknown> {
|
|
42
|
-
return {
|
|
43
|
-
nid: this.nid,
|
|
44
|
-
addresses: this.addresses,
|
|
45
|
-
capabilities: this.capabilities,
|
|
46
|
-
ttl: this.ttl,
|
|
47
|
-
timestamp: this.timestamp,
|
|
48
|
-
node_type: this.nodeType ?? null,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
toDict(): Record<string, unknown> {
|
|
53
|
-
return { ...this.unsignedDict(), signature: this.signature };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
static fromDict(data: Record<string, unknown>): AnnounceFrame {
|
|
57
|
-
return new AnnounceFrame(
|
|
58
|
-
data["nid"] as string,
|
|
59
|
-
data["addresses"] as NdpAddress[],
|
|
60
|
-
data["capabilities"] as string[],
|
|
61
|
-
data["ttl"] as number,
|
|
62
|
-
data["timestamp"] as string,
|
|
63
|
-
data["signature"] as string,
|
|
64
|
-
(data["node_type"] as string | null) ?? undefined,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class ResolveFrame implements NpsFrame {
|
|
70
|
-
readonly frameType = FrameType.RESOLVE;
|
|
71
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
72
|
-
|
|
73
|
-
constructor(
|
|
74
|
-
public readonly target: string,
|
|
75
|
-
public readonly requesterNid?: string,
|
|
76
|
-
public readonly resolved?: NdpResolveResult,
|
|
77
|
-
) {}
|
|
78
|
-
|
|
79
|
-
toDict(): Record<string, unknown> {
|
|
80
|
-
return {
|
|
81
|
-
target: this.target,
|
|
82
|
-
requester_nid: this.requesterNid ?? null,
|
|
83
|
-
resolved: this.resolved ?? null,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static fromDict(data: Record<string, unknown>): ResolveFrame {
|
|
88
|
-
return new ResolveFrame(
|
|
89
|
-
data["target"] as string,
|
|
90
|
-
(data["requester_nid"] as string | null) ?? undefined,
|
|
91
|
-
(data["resolved"] as NdpResolveResult | null) ?? undefined,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export class GraphFrame implements NpsFrame {
|
|
97
|
-
readonly frameType = FrameType.GRAPH;
|
|
98
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
99
|
-
|
|
100
|
-
constructor(
|
|
101
|
-
public readonly seq: number,
|
|
102
|
-
public readonly initialSync: boolean,
|
|
103
|
-
public readonly nodes?: readonly NdpGraphNode[],
|
|
104
|
-
public readonly patch?: readonly Record<string, unknown>[],
|
|
105
|
-
) {}
|
|
106
|
-
|
|
107
|
-
toDict(): Record<string, unknown> {
|
|
108
|
-
return {
|
|
109
|
-
seq: this.seq,
|
|
110
|
-
initial_sync: this.initialSync,
|
|
111
|
-
nodes: this.nodes ?? null,
|
|
112
|
-
patch: this.patch ?? null,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static fromDict(data: Record<string, unknown>): GraphFrame {
|
|
117
|
-
return new GraphFrame(
|
|
118
|
-
data["seq"] as number,
|
|
119
|
-
data["initial_sync"] as boolean,
|
|
120
|
-
(data["nodes"] as NdpGraphNode[] | null) ?? undefined,
|
|
121
|
-
(data["patch"] as Record<string, unknown>[] | null) ?? undefined,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/ndp/index.ts
DELETED
package/src/ndp/ndp-registry.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { AnnounceFrame, NdpResolveResult } from "./frames.js";
|
|
5
|
-
|
|
6
|
-
interface RegistryEntry {
|
|
7
|
-
frame: AnnounceFrame;
|
|
8
|
-
expiresAt: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class InMemoryNdpRegistry {
|
|
12
|
-
private readonly _store = new Map<string, RegistryEntry>();
|
|
13
|
-
|
|
14
|
-
// Replaceable for testing
|
|
15
|
-
clock: () => number = () => Date.now();
|
|
16
|
-
|
|
17
|
-
announce(frame: AnnounceFrame): void {
|
|
18
|
-
const expiresAt = this.clock() + frame.ttl * 1000;
|
|
19
|
-
if (frame.ttl === 0) {
|
|
20
|
-
this._store.delete(frame.nid);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
this._store.set(frame.nid, { frame, expiresAt });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getByNid(nid: string): AnnounceFrame | undefined {
|
|
27
|
-
const entry = this._store.get(nid);
|
|
28
|
-
if (entry === undefined) return undefined;
|
|
29
|
-
if (this.clock() > entry.expiresAt) {
|
|
30
|
-
this._store.delete(nid);
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return entry.frame;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
resolve(target: string): NdpResolveResult | undefined {
|
|
37
|
-
for (const [nid, entry] of this._store) {
|
|
38
|
-
if (this.clock() > entry.expiresAt) { this._store.delete(nid); continue; }
|
|
39
|
-
if (!InMemoryNdpRegistry.nwpTargetMatchesNid(nid, target)) continue;
|
|
40
|
-
const addr = entry.frame.addresses[0];
|
|
41
|
-
if (addr === undefined) continue;
|
|
42
|
-
return { host: addr.host, port: addr.port, ttl: entry.frame.ttl };
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getAll(): AnnounceFrame[] {
|
|
48
|
-
const now = this.clock();
|
|
49
|
-
const result: AnnounceFrame[] = [];
|
|
50
|
-
for (const [nid, entry] of this._store) {
|
|
51
|
-
if (now > entry.expiresAt) { this._store.delete(nid); continue; }
|
|
52
|
-
result.push(entry.frame);
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static nwpTargetMatchesNid(nid: string, target: string): boolean {
|
|
58
|
-
// NID: urn:nps:node:{authority}:{path-segment}
|
|
59
|
-
// target: nwp://{authority}/{path}
|
|
60
|
-
const nidParts = nid.split(":");
|
|
61
|
-
if (nidParts.length < 5 || nidParts[0] !== "urn" || nidParts[1] !== "nps" || nidParts[2] !== "node") {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (!target.startsWith("nwp://")) return false;
|
|
65
|
-
|
|
66
|
-
const nidAuthority = nidParts[3]!;
|
|
67
|
-
const nidPath = nidParts[4]!;
|
|
68
|
-
const rest = target.slice("nwp://".length);
|
|
69
|
-
const slashIdx = rest.indexOf("/");
|
|
70
|
-
if (slashIdx === -1) return false;
|
|
71
|
-
|
|
72
|
-
const urlAuthority = rest.slice(0, slashIdx);
|
|
73
|
-
const urlPath = rest.slice(slashIdx + 1); // without leading slash
|
|
74
|
-
|
|
75
|
-
if (urlAuthority !== nidAuthority) return false;
|
|
76
|
-
|
|
77
|
-
// nidPath must be a prefix of urlPath at a segment boundary
|
|
78
|
-
if (urlPath === nidPath) return true;
|
|
79
|
-
if (urlPath.startsWith(nidPath + "/")) return true;
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
}
|
package/src/ndp/registry.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { FrameRegistry } from "../core/registry.js";
|
|
5
|
-
import { FrameType } from "../core/frames.js";
|
|
6
|
-
import { AnnounceFrame, GraphFrame, ResolveFrame } from "./frames.js";
|
|
7
|
-
|
|
8
|
-
export function registerNdpFrames(registry: FrameRegistry): void {
|
|
9
|
-
registry.register(FrameType.ANNOUNCE, AnnounceFrame);
|
|
10
|
-
registry.register(FrameType.RESOLVE, ResolveFrame);
|
|
11
|
-
registry.register(FrameType.GRAPH, GraphFrame);
|
|
12
|
-
}
|
package/src/ndp/validator.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import * as ed25519 from "@noble/ed25519";
|
|
5
|
-
import { sha512 } from "@noble/hashes/sha512";
|
|
6
|
-
import type { AnnounceFrame } from "./frames.js";
|
|
7
|
-
|
|
8
|
-
ed25519.etc.sha512Sync = (...m) => sha512(ed25519.etc.concatBytes(...m));
|
|
9
|
-
|
|
10
|
-
export interface NdpAnnounceResult {
|
|
11
|
-
isValid: boolean;
|
|
12
|
-
errorCode?: string;
|
|
13
|
-
message?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const NdpAnnounceResult = {
|
|
17
|
-
ok: (): NdpAnnounceResult => ({ isValid: true }),
|
|
18
|
-
fail: (errorCode: string, message: string): NdpAnnounceResult => ({ isValid: false, errorCode, message }),
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class NdpAnnounceValidator {
|
|
22
|
-
private readonly _keys = new Map<string, string>(); // nid → "ed25519:<hex>"
|
|
23
|
-
|
|
24
|
-
registerPublicKey(nid: string, encodedPubKey: string): void {
|
|
25
|
-
this._keys.set(nid, encodedPubKey);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
removePublicKey(nid: string): void {
|
|
29
|
-
this._keys.delete(nid);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get knownPublicKeys(): ReadonlyMap<string, string> {
|
|
33
|
-
return this._keys;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
validate(frame: AnnounceFrame): NdpAnnounceResult {
|
|
37
|
-
const encoded = this._keys.get(frame.nid);
|
|
38
|
-
if (encoded === undefined) {
|
|
39
|
-
return NdpAnnounceResult.fail("NDP-ANNOUNCE-NID-MISMATCH", `No public key registered for NID: ${frame.nid}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const prefix = "ed25519:";
|
|
44
|
-
const pubHex = encoded.startsWith(prefix) ? encoded.slice(prefix.length) : encoded;
|
|
45
|
-
const pubKey = Buffer.from(pubHex, "hex");
|
|
46
|
-
|
|
47
|
-
const sig = frame.signature;
|
|
48
|
-
if (!sig.startsWith(prefix)) {
|
|
49
|
-
return NdpAnnounceResult.fail("NDP-ANNOUNCE-SIG-INVALID", "Signature must start with 'ed25519:'");
|
|
50
|
-
}
|
|
51
|
-
const sigBytes = Buffer.from(sig.slice(prefix.length), "base64");
|
|
52
|
-
|
|
53
|
-
const unsigned = frame.unsignedDict();
|
|
54
|
-
const canonical = JSON.stringify(unsigned, Object.keys(unsigned).sort());
|
|
55
|
-
const message = new TextEncoder().encode(canonical);
|
|
56
|
-
|
|
57
|
-
const valid = ed25519.verify(sigBytes, message, pubKey);
|
|
58
|
-
if (!valid) return NdpAnnounceResult.fail("NDP-ANNOUNCE-SIG-INVALID", "Ed25519 signature verification failed.");
|
|
59
|
-
return NdpAnnounceResult.ok();
|
|
60
|
-
} catch {
|
|
61
|
-
return NdpAnnounceResult.fail("NDP-ANNOUNCE-SIG-INVALID", "Ed25519 signature verification failed.");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/nip/frames.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { EncodingTier, FrameType } from "../core/frames.js";
|
|
5
|
-
import type { NpsFrame } from "../core/codec.js";
|
|
6
|
-
|
|
7
|
-
export interface IdentMetadata {
|
|
8
|
-
issuer: string;
|
|
9
|
-
issuedAt: string;
|
|
10
|
-
expiresAt?: string;
|
|
11
|
-
capabilities?: readonly string[];
|
|
12
|
-
scopes?: readonly string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class IdentFrame implements NpsFrame {
|
|
16
|
-
readonly frameType = FrameType.IDENT;
|
|
17
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
public readonly nid: string,
|
|
21
|
-
public readonly pubKey: string,
|
|
22
|
-
public readonly metadata: IdentMetadata,
|
|
23
|
-
public readonly signature: string,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
unsignedDict(): Record<string, unknown> {
|
|
27
|
-
return {
|
|
28
|
-
nid: this.nid,
|
|
29
|
-
pub_key: this.pubKey,
|
|
30
|
-
metadata: this.metadata,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
toDict(): Record<string, unknown> {
|
|
35
|
-
return { ...this.unsignedDict(), signature: this.signature };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static fromDict(data: Record<string, unknown>): IdentFrame {
|
|
39
|
-
return new IdentFrame(
|
|
40
|
-
data["nid"] as string,
|
|
41
|
-
data["pub_key"] as string,
|
|
42
|
-
data["metadata"] as IdentMetadata,
|
|
43
|
-
data["signature"] as string,
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class TrustFrame implements NpsFrame {
|
|
49
|
-
readonly frameType = FrameType.TRUST;
|
|
50
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
51
|
-
|
|
52
|
-
constructor(
|
|
53
|
-
public readonly issuerNid: string,
|
|
54
|
-
public readonly subjectNid: string,
|
|
55
|
-
public readonly scopes: readonly string[],
|
|
56
|
-
public readonly expiresAt: string,
|
|
57
|
-
public readonly signature: string,
|
|
58
|
-
) {}
|
|
59
|
-
|
|
60
|
-
toDict(): Record<string, unknown> {
|
|
61
|
-
return {
|
|
62
|
-
issuer_nid: this.issuerNid,
|
|
63
|
-
subject_nid: this.subjectNid,
|
|
64
|
-
scopes: this.scopes,
|
|
65
|
-
expires_at: this.expiresAt,
|
|
66
|
-
signature: this.signature,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static fromDict(data: Record<string, unknown>): TrustFrame {
|
|
71
|
-
return new TrustFrame(
|
|
72
|
-
data["issuer_nid"] as string,
|
|
73
|
-
data["subject_nid"] as string,
|
|
74
|
-
data["scopes"] as string[],
|
|
75
|
-
data["expires_at"] as string,
|
|
76
|
-
data["signature"] as string,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class RevokeFrame implements NpsFrame {
|
|
82
|
-
readonly frameType = FrameType.REVOKE;
|
|
83
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
84
|
-
|
|
85
|
-
constructor(
|
|
86
|
-
public readonly nid: string,
|
|
87
|
-
public readonly reason?: string,
|
|
88
|
-
public readonly revokedAt?: string,
|
|
89
|
-
) {}
|
|
90
|
-
|
|
91
|
-
toDict(): Record<string, unknown> {
|
|
92
|
-
return {
|
|
93
|
-
nid: this.nid,
|
|
94
|
-
reason: this.reason ?? null,
|
|
95
|
-
revoked_at: this.revokedAt ?? null,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
static fromDict(data: Record<string, unknown>): RevokeFrame {
|
|
100
|
-
return new RevokeFrame(
|
|
101
|
-
data["nid"] as string,
|
|
102
|
-
(data["reason"] as string | null) ?? undefined,
|
|
103
|
-
(data["revoked_at"] as string | null) ?? undefined,
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
package/src/nip/identity.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* NipIdentity — Ed25519 key management and signing for NPS NID identity.
|
|
6
|
-
* Uses @noble/ed25519 for signing; node:crypto for key storage encryption.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as ed25519 from "@noble/ed25519";
|
|
10
|
-
import { sha512 } from "@noble/hashes/sha512";
|
|
11
|
-
import { createCipheriv, createDecipheriv, pbkdf2Sync, randomBytes } from "node:crypto";
|
|
12
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
13
|
-
|
|
14
|
-
// noble/ed25519 requires sha512 to be set explicitly in Node environments
|
|
15
|
-
ed25519.etc.sha512Sync = (...m) => sha512(ed25519.etc.concatBytes(...m));
|
|
16
|
-
|
|
17
|
-
const KEY_FILE_VERSION = 1;
|
|
18
|
-
const PBKDF2_ITERS = 600_000;
|
|
19
|
-
const SALT_BYTES = 16;
|
|
20
|
-
const IV_BYTES = 12;
|
|
21
|
-
const KEY_BYTES = 32;
|
|
22
|
-
|
|
23
|
-
interface KeyFileEnvelope {
|
|
24
|
-
version: number;
|
|
25
|
-
salt: string; // hex
|
|
26
|
-
iv: string; // hex
|
|
27
|
-
ciphertext: string; // hex
|
|
28
|
-
pubKey: string; // hex
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class NipIdentity {
|
|
32
|
-
private constructor(
|
|
33
|
-
private readonly _privKey: Uint8Array,
|
|
34
|
-
public readonly pubKey: Uint8Array,
|
|
35
|
-
) {}
|
|
36
|
-
|
|
37
|
-
// ── Factory ───────────────────────────────────────────────────────────────
|
|
38
|
-
|
|
39
|
-
static generate(): NipIdentity {
|
|
40
|
-
const priv = ed25519.utils.randomPrivateKey();
|
|
41
|
-
const pub = ed25519.getPublicKey(priv);
|
|
42
|
-
return new NipIdentity(priv, pub);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static fromPrivateKey(privKey: Uint8Array): NipIdentity {
|
|
46
|
-
const pub = ed25519.getPublicKey(privKey);
|
|
47
|
-
return new NipIdentity(privKey, pub);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Load from an AES-256-GCM encrypted key file. */
|
|
51
|
-
static load(path: string, passphrase: string): NipIdentity {
|
|
52
|
-
const envelope = JSON.parse(readFileSync(path, "utf8")) as KeyFileEnvelope;
|
|
53
|
-
const salt = Buffer.from(envelope.salt, "hex");
|
|
54
|
-
const iv = Buffer.from(envelope.iv, "hex");
|
|
55
|
-
const ct = Buffer.from(envelope.ciphertext, "hex");
|
|
56
|
-
|
|
57
|
-
const dk = pbkdf2Sync(passphrase, salt, PBKDF2_ITERS, KEY_BYTES, "sha256");
|
|
58
|
-
const decipher = createDecipheriv("aes-256-gcm", dk, iv);
|
|
59
|
-
// Last 16 bytes of ciphertext are the GCM auth tag
|
|
60
|
-
const authTag = ct.slice(ct.length - 16);
|
|
61
|
-
const body = ct.slice(0, ct.length - 16);
|
|
62
|
-
(decipher as ReturnType<typeof createDecipheriv> & { setAuthTag(tag: Buffer): void }).setAuthTag(authTag);
|
|
63
|
-
const priv = Buffer.concat([decipher.update(body), decipher.final()]);
|
|
64
|
-
return NipIdentity.fromPrivateKey(new Uint8Array(priv));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Save to an AES-256-GCM encrypted key file. */
|
|
68
|
-
save(path: string, passphrase: string): void {
|
|
69
|
-
const salt = randomBytes(SALT_BYTES);
|
|
70
|
-
const iv = randomBytes(IV_BYTES);
|
|
71
|
-
const dk = pbkdf2Sync(passphrase, salt, PBKDF2_ITERS, KEY_BYTES, "sha256");
|
|
72
|
-
const cipher = createCipheriv("aes-256-gcm", dk, iv);
|
|
73
|
-
const body = Buffer.concat([cipher.update(Buffer.from(this._privKey)), cipher.final()]);
|
|
74
|
-
const tag = (cipher as ReturnType<typeof createCipheriv> & { getAuthTag(): Buffer }).getAuthTag();
|
|
75
|
-
|
|
76
|
-
const envelope: KeyFileEnvelope = {
|
|
77
|
-
version: KEY_FILE_VERSION,
|
|
78
|
-
salt: salt.toString("hex"),
|
|
79
|
-
iv: iv.toString("hex"),
|
|
80
|
-
ciphertext: Buffer.concat([body, tag]).toString("hex"),
|
|
81
|
-
pubKey: Buffer.from(this.pubKey).toString("hex"),
|
|
82
|
-
};
|
|
83
|
-
writeFileSync(path, JSON.stringify(envelope, null, 2), "utf8");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ── Signing ───────────────────────────────────────────────────────────────
|
|
87
|
-
|
|
88
|
-
/** Sign a dict payload. Returns `ed25519:<base64url>`. */
|
|
89
|
-
sign(payload: Record<string, unknown>): string {
|
|
90
|
-
const canonical = JSON.stringify(payload, Object.keys(payload).sort());
|
|
91
|
-
const bytes = new TextEncoder().encode(canonical);
|
|
92
|
-
const sig = ed25519.sign(bytes, this._privKey);
|
|
93
|
-
return `ed25519:${Buffer.from(sig).toString("base64")}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Verify a signature string against a dict payload. */
|
|
97
|
-
verify(payload: Record<string, unknown>, signature: string): boolean {
|
|
98
|
-
if (!signature.startsWith("ed25519:")) return false;
|
|
99
|
-
try {
|
|
100
|
-
const canonical = JSON.stringify(payload, Object.keys(payload).sort());
|
|
101
|
-
const bytes = new TextEncoder().encode(canonical);
|
|
102
|
-
const sigBytes = Buffer.from(signature.slice("ed25519:".length), "base64");
|
|
103
|
-
return ed25519.verify(sigBytes, bytes, this.pubKey);
|
|
104
|
-
} catch {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Public key as `ed25519:<hex>` string. */
|
|
110
|
-
get pubKeyString(): string {
|
|
111
|
-
return `ed25519:${Buffer.from(this.pubKey).toString("hex")}`;
|
|
112
|
-
}
|
|
113
|
-
}
|
package/src/nip/index.ts
DELETED
package/src/nip/registry.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { FrameRegistry } from "../core/registry.js";
|
|
5
|
-
import { FrameType } from "../core/frames.js";
|
|
6
|
-
import { IdentFrame, TrustFrame, RevokeFrame } from "./frames.js";
|
|
7
|
-
|
|
8
|
-
export function registerNipFrames(registry: FrameRegistry): void {
|
|
9
|
-
registry.register(FrameType.IDENT, IdentFrame);
|
|
10
|
-
registry.register(FrameType.TRUST, TrustFrame);
|
|
11
|
-
registry.register(FrameType.REVOKE, RevokeFrame);
|
|
12
|
-
}
|
package/src/nop/client.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { NpsFrameCodec } from "../core/codec.js";
|
|
5
|
-
import { EncodingTier } from "../core/frames.js";
|
|
6
|
-
import { FrameRegistry } from "../core/registry.js";
|
|
7
|
-
import { registerNcpFrames } from "../ncp/registry.js";
|
|
8
|
-
import { registerNopFrames } from "./registry.js";
|
|
9
|
-
import { TaskState } from "./models.js";
|
|
10
|
-
import type { TaskFrame } from "./frames.js";
|
|
11
|
-
|
|
12
|
-
const TERMINAL_STATES = new Set<TaskState>([
|
|
13
|
-
TaskState.COMPLETED,
|
|
14
|
-
TaskState.FAILED,
|
|
15
|
-
TaskState.CANCELLED,
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
export class NopTaskStatus {
|
|
19
|
-
constructor(private readonly _raw: Record<string, unknown>) {}
|
|
20
|
-
|
|
21
|
-
get taskId(): string { return this._raw["task_id"] as string; }
|
|
22
|
-
get state(): TaskState { return this._raw["state"] as TaskState; }
|
|
23
|
-
get isTerminal(): boolean { return TERMINAL_STATES.has(this._raw["state"] as TaskState); }
|
|
24
|
-
get aggregatedResult(): unknown { return this._raw["aggregated_result"]; }
|
|
25
|
-
get errorCode(): string | undefined { return (this._raw["error_code"] as string | null) ?? undefined; }
|
|
26
|
-
get errorMessage(): string | undefined { return (this._raw["error_message"] as string | null) ?? undefined; }
|
|
27
|
-
get nodeResults(): Record<string, unknown> { return (this._raw["node_results"] as Record<string, unknown> | undefined) ?? {}; }
|
|
28
|
-
get raw(): Record<string, unknown> { return this._raw; }
|
|
29
|
-
|
|
30
|
-
toString(): string {
|
|
31
|
-
return `NopTaskStatus(taskId=${this.taskId}, state=${String(this._raw["state"])})`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class NopClient {
|
|
36
|
-
private readonly _baseUrl: string;
|
|
37
|
-
private readonly _codec: NpsFrameCodec;
|
|
38
|
-
private readonly _tier: EncodingTier;
|
|
39
|
-
|
|
40
|
-
constructor(
|
|
41
|
-
baseUrl: string,
|
|
42
|
-
options: { defaultTier?: EncodingTier; registry?: FrameRegistry } = {},
|
|
43
|
-
) {
|
|
44
|
-
this._baseUrl = baseUrl.replace(/\/$/, "");
|
|
45
|
-
this._tier = options.defaultTier ?? EncodingTier.MSGPACK;
|
|
46
|
-
|
|
47
|
-
const registry = options.registry ?? (() => {
|
|
48
|
-
const r = new FrameRegistry();
|
|
49
|
-
registerNcpFrames(r);
|
|
50
|
-
registerNopFrames(r);
|
|
51
|
-
return r;
|
|
52
|
-
})();
|
|
53
|
-
this._codec = new NpsFrameCodec(registry);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async submit(frame: TaskFrame): Promise<string> {
|
|
57
|
-
const wire = this._codec.encode(frame, { overrideTier: this._tier });
|
|
58
|
-
const res = await fetch(`${this._baseUrl}/task`, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
body: wire,
|
|
61
|
-
headers: { "Content-Type": "application/x-nps-frame", "Accept": "application/json" },
|
|
62
|
-
});
|
|
63
|
-
if (!res.ok) throw new Error(`NOP /task failed: HTTP ${res.status}`);
|
|
64
|
-
const data = await res.json() as Record<string, unknown>;
|
|
65
|
-
return data["task_id"] as string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async getStatus(taskId: string): Promise<NopTaskStatus> {
|
|
69
|
-
const res = await fetch(`${this._baseUrl}/task/${taskId}`, {
|
|
70
|
-
headers: { "Accept": "application/json" },
|
|
71
|
-
});
|
|
72
|
-
if (!res.ok) throw new Error(`NOP /task/${taskId} failed: HTTP ${res.status}`);
|
|
73
|
-
return new NopTaskStatus(await res.json() as Record<string, unknown>);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async cancel(taskId: string): Promise<void> {
|
|
77
|
-
const res = await fetch(`${this._baseUrl}/task/${taskId}/cancel`, {
|
|
78
|
-
method: "POST",
|
|
79
|
-
headers: { "Accept": "application/json" },
|
|
80
|
-
});
|
|
81
|
-
if (!res.ok) throw new Error(`NOP /task/${taskId}/cancel failed: HTTP ${res.status}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async wait(
|
|
85
|
-
taskId: string,
|
|
86
|
-
options: { pollIntervalMs?: number; timeoutMs?: number } = {},
|
|
87
|
-
): Promise<NopTaskStatus> {
|
|
88
|
-
const pollIntervalMs = options.pollIntervalMs ?? 1000;
|
|
89
|
-
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
90
|
-
const deadline = Date.now() + timeoutMs;
|
|
91
|
-
|
|
92
|
-
while (true) {
|
|
93
|
-
const status = await this.getStatus(taskId);
|
|
94
|
-
if (status.isTerminal) return status;
|
|
95
|
-
|
|
96
|
-
const remaining = deadline - Date.now();
|
|
97
|
-
if (remaining <= 0) {
|
|
98
|
-
throw new Error(`Task '${taskId}' did not complete within ${timeoutMs}ms (state: ${String(status.raw["state"])}).`);
|
|
99
|
-
}
|
|
100
|
-
await new Promise((resolve) => setTimeout(resolve, Math.min(pollIntervalMs, remaining)));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|