@labacacia/nps-sdk 1.0.0-alpha.1
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/CONTRIBUTING.md +33 -0
- package/LICENSE +170 -0
- package/NOTICE +7 -0
- package/README.md +153 -0
- package/dist/codec-CmHeovTV.d.cts +120 -0
- package/dist/codec-CmHeovTV.d.ts +120 -0
- package/dist/core/anchor-cache.d.ts +42 -0
- package/dist/core/anchor-cache.d.ts.map +1 -0
- package/dist/core/anchor-cache.js +104 -0
- package/dist/core/anchor-cache.js.map +1 -0
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +80 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/canonical-json.d.ts +12 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +44 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/codec.d.ts +32 -0
- package/dist/core/codec.d.ts.map +1 -0
- package/dist/core/codec.js +119 -0
- package/dist/core/codec.js.map +1 -0
- package/dist/core/codecs/index.d.ts +4 -0
- package/dist/core/codecs/index.d.ts.map +1 -0
- package/dist/core/codecs/index.js +6 -0
- package/dist/core/codecs/index.js.map +1 -0
- package/dist/core/codecs/ncp-codec.d.ts +39 -0
- package/dist/core/codecs/ncp-codec.d.ts.map +1 -0
- package/dist/core/codecs/ncp-codec.js +93 -0
- package/dist/core/codecs/ncp-codec.js.map +1 -0
- package/dist/core/codecs/tier1-json-codec.d.ts +10 -0
- package/dist/core/codecs/tier1-json-codec.d.ts.map +1 -0
- package/dist/core/codecs/tier1-json-codec.js +28 -0
- package/dist/core/codecs/tier1-json-codec.js.map +1 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts +10 -0
- package/dist/core/codecs/tier2-msgpack-codec.d.ts.map +1 -0
- package/dist/core/codecs/tier2-msgpack-codec.js +26 -0
- package/dist/core/codecs/tier2-msgpack-codec.js.map +1 -0
- package/dist/core/crypto-provider.d.ts +31 -0
- package/dist/core/crypto-provider.d.ts.map +1 -0
- package/dist/core/crypto-provider.js +10 -0
- package/dist/core/crypto-provider.js.map +1 -0
- package/dist/core/exceptions.d.ts +27 -0
- package/dist/core/exceptions.d.ts.map +1 -0
- package/dist/core/exceptions.js +52 -0
- package/dist/core/exceptions.js.map +1 -0
- package/dist/core/frame-header.d.ts +87 -0
- package/dist/core/frame-header.d.ts.map +1 -0
- package/dist/core/frame-header.js +185 -0
- package/dist/core/frame-header.js.map +1 -0
- package/dist/core/frame-registry.d.ts +35 -0
- package/dist/core/frame-registry.d.ts.map +1 -0
- package/dist/core/frame-registry.js +63 -0
- package/dist/core/frame-registry.js.map +1 -0
- package/dist/core/frames.d.ts +80 -0
- package/dist/core/frames.d.ts.map +1 -0
- package/dist/core/frames.js +153 -0
- package/dist/core/frames.js.map +1 -0
- package/dist/core/index.cjs +371 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +41 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/registry.d.ts +11 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +17 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/status-codes.d.ts +28 -0
- package/dist/core/status-codes.d.ts.map +1 -0
- package/dist/core/status-codes.js +38 -0
- package/dist/core/status-codes.js.map +1 -0
- package/dist/frames-B3qLdl_g.d.cts +77 -0
- package/dist/frames-Ff7-ZPUl.d.ts +77 -0
- package/dist/index.cjs +1556 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/ncp/frames/anchor-frame.d.ts +29 -0
- package/dist/ncp/frames/anchor-frame.d.ts.map +1 -0
- package/dist/ncp/frames/anchor-frame.js +54 -0
- package/dist/ncp/frames/anchor-frame.js.map +1 -0
- package/dist/ncp/frames/caps-frame.d.ts +29 -0
- package/dist/ncp/frames/caps-frame.d.ts.map +1 -0
- package/dist/ncp/frames/caps-frame.js +29 -0
- package/dist/ncp/frames/caps-frame.js.map +1 -0
- package/dist/ncp/frames/diff-frame.d.ts +32 -0
- package/dist/ncp/frames/diff-frame.d.ts.map +1 -0
- package/dist/ncp/frames/diff-frame.js +37 -0
- package/dist/ncp/frames/diff-frame.js.map +1 -0
- package/dist/ncp/frames/error-frame.d.ts +16 -0
- package/dist/ncp/frames/error-frame.d.ts.map +1 -0
- package/dist/ncp/frames/error-frame.js +13 -0
- package/dist/ncp/frames/error-frame.js.map +1 -0
- package/dist/ncp/frames/hello-frame.d.ts +21 -0
- package/dist/ncp/frames/hello-frame.d.ts.map +1 -0
- package/dist/ncp/frames/hello-frame.js +25 -0
- package/dist/ncp/frames/hello-frame.js.map +1 -0
- package/dist/ncp/frames/stream-frame.d.ts +16 -0
- package/dist/ncp/frames/stream-frame.d.ts.map +1 -0
- package/dist/ncp/frames/stream-frame.js +18 -0
- package/dist/ncp/frames/stream-frame.js.map +1 -0
- package/dist/ncp/frames.d.ts +76 -0
- package/dist/ncp/frames.d.ts.map +1 -0
- package/dist/ncp/frames.js +147 -0
- package/dist/ncp/frames.js.map +1 -0
- package/dist/ncp/handshake.d.ts +30 -0
- package/dist/ncp/handshake.d.ts.map +1 -0
- package/dist/ncp/handshake.js +80 -0
- package/dist/ncp/handshake.js.map +1 -0
- package/dist/ncp/index.cjs +188 -0
- package/dist/ncp/index.cjs.map +1 -0
- package/dist/ncp/index.d.cts +6 -0
- package/dist/ncp/index.d.ts +11 -0
- package/dist/ncp/index.d.ts.map +1 -0
- package/dist/ncp/index.js +13 -0
- package/dist/ncp/index.js.map +1 -0
- package/dist/ncp/ncp-error-codes.d.ts +22 -0
- package/dist/ncp/ncp-error-codes.d.ts.map +1 -0
- package/dist/ncp/ncp-error-codes.js +32 -0
- package/dist/ncp/ncp-error-codes.js.map +1 -0
- package/dist/ncp/ncp-patch-format.d.ts +7 -0
- package/dist/ncp/ncp-patch-format.d.ts.map +1 -0
- package/dist/ncp/ncp-patch-format.js +13 -0
- package/dist/ncp/ncp-patch-format.js.map +1 -0
- package/dist/ncp/registry.d.ts +3 -0
- package/dist/ncp/registry.d.ts.map +1 -0
- package/dist/ncp/registry.js +12 -0
- package/dist/ncp/registry.js.map +1 -0
- package/dist/ncp/stream-manager.d.ts +57 -0
- package/dist/ncp/stream-manager.d.ts.map +1 -0
- package/dist/ncp/stream-manager.js +163 -0
- package/dist/ncp/stream-manager.js.map +1 -0
- package/dist/ndp/frames.d.ts +56 -0
- package/dist/ndp/frames.d.ts.map +1 -0
- package/dist/ndp/frames.js +87 -0
- package/dist/ndp/frames.js.map +1 -0
- package/dist/ndp/index.cjs +252 -0
- package/dist/ndp/index.cjs.map +1 -0
- package/dist/ndp/index.d.cts +86 -0
- package/dist/ndp/index.d.ts +5 -0
- package/dist/ndp/index.d.ts.map +1 -0
- package/dist/ndp/index.js +7 -0
- package/dist/ndp/index.js.map +1 -0
- package/dist/ndp/ndp-registry.d.ts +11 -0
- package/dist/ndp/ndp-registry.d.ts.map +1 -0
- package/dist/ndp/ndp-registry.js +79 -0
- package/dist/ndp/ndp-registry.js.map +1 -0
- package/dist/ndp/registry.d.ts +3 -0
- package/dist/ndp/registry.d.ts.map +1 -0
- package/dist/ndp/registry.js +10 -0
- package/dist/ndp/registry.js.map +1 -0
- package/dist/ndp/validator.d.ts +18 -0
- package/dist/ndp/validator.d.ts.map +1 -0
- package/dist/ndp/validator.js +48 -0
- package/dist/ndp/validator.js.map +1 -0
- package/dist/nip/frames.d.ts +44 -0
- package/dist/nip/frames.d.ts.map +1 -0
- package/dist/nip/frames.js +81 -0
- package/dist/nip/frames.js.map +1 -0
- package/dist/nip/identity.d.ts +18 -0
- package/dist/nip/identity.d.ts.map +1 -0
- package/dist/nip/identity.js +94 -0
- package/dist/nip/identity.js.map +1 -0
- package/dist/nip/index.cjs +214 -0
- package/dist/nip/index.cjs.map +1 -0
- package/dist/nip/index.d.cts +65 -0
- package/dist/nip/index.d.ts +4 -0
- package/dist/nip/index.d.ts.map +1 -0
- package/dist/nip/index.js +6 -0
- package/dist/nip/index.js.map +1 -0
- package/dist/nip/registry.d.ts +3 -0
- package/dist/nip/registry.d.ts.map +1 -0
- package/dist/nip/registry.js +10 -0
- package/dist/nip/registry.js.map +1 -0
- package/dist/nop/client.d.ts +34 -0
- package/dist/nop/client.d.ts.map +1 -0
- package/dist/nop/client.js +90 -0
- package/dist/nop/client.js.map +1 -0
- package/dist/nop/frames.d.ts +65 -0
- package/dist/nop/frames.d.ts.map +1 -0
- package/dist/nop/frames.js +148 -0
- package/dist/nop/frames.js.map +1 -0
- package/dist/nop/index.cjs +762 -0
- package/dist/nop/index.cjs.map +1 -0
- package/dist/nop/index.d.cts +155 -0
- package/dist/nop/index.d.ts +5 -0
- package/dist/nop/index.d.ts.map +1 -0
- package/dist/nop/index.js +7 -0
- package/dist/nop/index.js.map +1 -0
- package/dist/nop/models.d.ts +58 -0
- package/dist/nop/models.d.ts.map +1 -0
- package/dist/nop/models.js +50 -0
- package/dist/nop/models.js.map +1 -0
- package/dist/nop/nop-types.d.ts +136 -0
- package/dist/nop/nop-types.d.ts.map +1 -0
- package/dist/nop/nop-types.js +44 -0
- package/dist/nop/nop-types.js.map +1 -0
- package/dist/nop/registry.d.ts +3 -0
- package/dist/nop/registry.d.ts.map +1 -0
- package/dist/nop/registry.js +11 -0
- package/dist/nop/registry.js.map +1 -0
- package/dist/nwp/client.d.ts +22 -0
- package/dist/nwp/client.d.ts.map +1 -0
- package/dist/nwp/client.js +101 -0
- package/dist/nwp/client.js.map +1 -0
- package/dist/nwp/frames.d.ts +46 -0
- package/dist/nwp/frames.d.ts.map +1 -0
- package/dist/nwp/frames.js +81 -0
- package/dist/nwp/frames.js.map +1 -0
- package/dist/nwp/index.cjs +658 -0
- package/dist/nwp/index.cjs.map +1 -0
- package/dist/nwp/index.d.cts +65 -0
- package/dist/nwp/index.d.ts +4 -0
- package/dist/nwp/index.d.ts.map +1 -0
- package/dist/nwp/index.js +6 -0
- package/dist/nwp/index.js.map +1 -0
- package/dist/nwp/registry.d.ts +3 -0
- package/dist/nwp/registry.d.ts.map +1 -0
- package/dist/nwp/registry.js +9 -0
- package/dist/nwp/registry.js.map +1 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +29 -0
- package/dist/setup.js.map +1 -0
- package/nip-ca-server/Dockerfile +27 -0
- package/nip-ca-server/README.md +45 -0
- package/nip-ca-server/db/001_init.sql +25 -0
- package/nip-ca-server/docker-compose.yml +29 -0
- package/nip-ca-server/package.json +23 -0
- package/nip-ca-server/src/ca.ts +155 -0
- package/nip-ca-server/src/db.ts +104 -0
- package/nip-ca-server/src/index.ts +157 -0
- package/nip-ca-server/tsconfig.json +13 -0
- package/package.json +47 -0
- package/src/core/anchor-cache.ts +129 -0
- package/src/core/cache.ts +93 -0
- package/src/core/canonical-json.ts +50 -0
- package/src/core/codec.ts +158 -0
- package/src/core/codecs/index.ts +5 -0
- package/src/core/codecs/ncp-codec.ts +170 -0
- package/src/core/codecs/tier1-json-codec.ts +33 -0
- package/src/core/codecs/tier2-msgpack-codec.ts +30 -0
- package/src/core/crypto-provider.ts +47 -0
- package/src/core/exceptions.ts +57 -0
- package/src/core/frame-header.ts +282 -0
- package/src/core/frame-registry.ts +91 -0
- package/src/core/frames.ts +183 -0
- package/src/core/index.ts +10 -0
- package/src/core/registry.ts +28 -0
- package/src/core/status-codes.ts +46 -0
- package/src/index.ts +10 -0
- package/src/ncp/frames/anchor-frame.ts +87 -0
- package/src/ncp/frames/caps-frame.ts +59 -0
- package/src/ncp/frames/diff-frame.ts +69 -0
- package/src/ncp/frames/error-frame.ts +26 -0
- package/src/ncp/frames/hello-frame.ts +50 -0
- package/src/ncp/frames/stream-frame.ts +35 -0
- package/src/ncp/frames.ts +199 -0
- package/src/ncp/handshake.ts +95 -0
- package/src/ncp/index.ts +12 -0
- package/src/ncp/ncp-error-codes.ts +34 -0
- package/src/ncp/ncp-patch-format.ts +16 -0
- package/src/ncp/registry.ts +14 -0
- package/src/ncp/stream-manager.ts +212 -0
- package/src/ndp/frames.ts +124 -0
- package/src/ndp/index.ts +7 -0
- package/src/ndp/ndp-registry.ts +82 -0
- package/src/ndp/registry.ts +12 -0
- package/src/ndp/validator.ts +64 -0
- package/src/nip/frames.ts +106 -0
- package/src/nip/identity.ts +113 -0
- package/src/nip/index.ts +6 -0
- package/src/nip/registry.ts +12 -0
- package/src/nop/client.ts +103 -0
- package/src/nop/frames.ts +181 -0
- package/src/nop/index.ts +7 -0
- package/src/nop/models.ts +79 -0
- package/src/nop/nop-types.ts +208 -0
- package/src/nop/registry.ts +13 -0
- package/src/nwp/client.ts +114 -0
- package/src/nwp/frames.ts +116 -0
- package/src/nwp/index.ts +6 -0
- package/src/nwp/registry.ts +11 -0
- package/src/setup.ts +32 -0
- package/tests/core/anchor-cache.test.ts +242 -0
- package/tests/core/codec.test.ts +205 -0
- package/tests/core/frame-registry.test.ts +46 -0
- package/tests/core.test.ts +327 -0
- package/tests/ncp/diff-binary-bitset.test.ts +107 -0
- package/tests/ncp/e2e-enc-reject.test.ts +93 -0
- package/tests/ncp/err-error-frame.test.ts +152 -0
- package/tests/ncp/frames.test.ts +359 -0
- package/tests/ncp/framing.test.ts +233 -0
- package/tests/ncp/hello-frame.test.ts +122 -0
- package/tests/ncp/inline-anchor.test.ts +88 -0
- package/tests/ncp/security.test.ts +184 -0
- package/tests/ncp/stream-window.test.ts +167 -0
- package/tests/ncp/stream.test.ts +242 -0
- package/tests/ncp/version-negotiation.test.ts +123 -0
- package/tests/ndp.test.ts +271 -0
- package/tests/nip.test.ts +184 -0
- package/tests/nop.test.ts +344 -0
- package/tests/nwp.test.ts +237 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +20 -0
- package/vitest.config.ts +10 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Contributing to NPS
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to the Neural Protocol Suite.
|
|
4
|
+
|
|
5
|
+
## Issue Prefixes
|
|
6
|
+
|
|
7
|
+
| Prefix | Usage |
|
|
8
|
+
|--------|-------|
|
|
9
|
+
| `spec:` | Specification questions and design discussions |
|
|
10
|
+
| `impl:` | Implementation bugs and fixes |
|
|
11
|
+
| `sdk:` | SDK (Python / TypeScript) related |
|
|
12
|
+
| `docs:` | Documentation improvements |
|
|
13
|
+
|
|
14
|
+
## Workflow
|
|
15
|
+
|
|
16
|
+
1. Open an Issue first for any non-trivial change
|
|
17
|
+
2. Fork the repo and create a branch: `feature/your-feature` or `fix/your-fix`
|
|
18
|
+
3. Submit a Pull Request referencing the Issue
|
|
19
|
+
|
|
20
|
+
## Spec Changes
|
|
21
|
+
|
|
22
|
+
Changes to files under `spec/` require a discussion Issue before a PR is accepted.
|
|
23
|
+
Spec changes that affect wire format or frame structure require a version bump.
|
|
24
|
+
|
|
25
|
+
## Code Style
|
|
26
|
+
|
|
27
|
+
- **C# / .NET**: Follow standard Microsoft C# conventions, nullable enabled
|
|
28
|
+
- **Python**: PEP 8, type hints required
|
|
29
|
+
- **TypeScript**: Strict mode enabled
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
By contributing, you agree your contributions will be licensed under Apache 2.0.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of recording and
|
|
55
|
+
managing Contributions to the Work, but excluding communication that is
|
|
56
|
+
conspicularly marked or otherwise designated in writing by the copyright
|
|
57
|
+
owner as "Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contributor's Work constitutes direct or contributory patent
|
|
82
|
+
infringement, then any patent licenses granted to You under this
|
|
83
|
+
License for that Work shall terminate as of the date such litigation
|
|
84
|
+
is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
119
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
120
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
121
|
+
this License, without any additional terms or conditions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
124
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
125
|
+
except as required for reasonable and customary use in describing the
|
|
126
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
129
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
130
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
131
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
132
|
+
without limitation, any warranties or conditions of TITLE,
|
|
133
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
134
|
+
PURPOSE. You are solely responsible for determining the
|
|
135
|
+
appropriateness of using or reproducing the Work and assume any
|
|
136
|
+
risks associated with Your exercise of permissions under this License.
|
|
137
|
+
|
|
138
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
139
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
140
|
+
unless required by applicable law (such as deliberate and grossly
|
|
141
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
142
|
+
liable to You for damages, including any direct, indirect, special,
|
|
143
|
+
incidental, or exemplary damages of any character arising as a
|
|
144
|
+
result of this License or out of the use or inability to use the
|
|
145
|
+
Work (even if such Contributor has been advised of the possibility
|
|
146
|
+
of such damages).
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
150
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
151
|
+
obligations and/or rights consistent with this License. However, in
|
|
152
|
+
accepting such obligations, You may offer only obligations consistent
|
|
153
|
+
with this License and for which You can fully compensate for any
|
|
154
|
+
resulting liability.
|
|
155
|
+
|
|
156
|
+
END OF TERMS AND CONDITIONS
|
|
157
|
+
|
|
158
|
+
Copyright 2026 INNO LOTUS PTY LTD
|
|
159
|
+
|
|
160
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
161
|
+
you may not use this file except in compliance with the License.
|
|
162
|
+
You may obtain a copy of the License at
|
|
163
|
+
|
|
164
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
165
|
+
|
|
166
|
+
Unless required by applicable law or agreed to in writing, software
|
|
167
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
168
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
169
|
+
implied. See the License for the specific language governing
|
|
170
|
+
permissions and limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Neural Protocol Suite (NPS)
|
|
2
|
+
Copyright 2026 INNO LOTUS PTY LTD
|
|
3
|
+
|
|
4
|
+
This product includes software developed under the LabAcacia open-source lab,
|
|
5
|
+
operated by INNO LOTUS PTY LTD (https://innolotus.com).
|
|
6
|
+
|
|
7
|
+
NCP (Neural Communication Protocol) v0.2 was developed by Ori Lynn / INNO LOTUS PTY LTD.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# @labacacia/nps-sdk — TypeScript / Node.js
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the **Neural Protocol Suite** (NPS) — a protocol suite designed for AI Agents.
|
|
4
|
+
Part of the [LabAcacia](https://github.com/LabAcacia) / INNO LOTUS PTY LTD open-source ecosystem.
|
|
5
|
+
|
|
6
|
+
## Status
|
|
7
|
+
|
|
8
|
+
**v0.1.0 — Phase 2** · 5 protocols · 139 tests · ≥ 98% coverage
|
|
9
|
+
|
|
10
|
+
| Protocol | Class | Status |
|
|
11
|
+
|----------|-------|--------|
|
|
12
|
+
| NCP — Neural Communication Protocol | Framing, codec | ✅ |
|
|
13
|
+
| NWP — Neural Web Protocol | `NwpClient` | ✅ |
|
|
14
|
+
| NIP — Neural Identity Protocol | `NipIdentity` | ✅ |
|
|
15
|
+
| NDP — Neural Discovery Protocol | `InMemoryNdpRegistry`, `NdpAnnounceValidator` | ✅ |
|
|
16
|
+
| NOP — Neural Orchestration Protocol | `NopClient` | ✅ |
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @labacacia/nps-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> **Peer requirement:** Node.js 18+
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### NWP — query a node
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { NwpClient, QueryFrame } from "@labacacia/nps-sdk/nwp";
|
|
32
|
+
|
|
33
|
+
const client = new NwpClient("http://node.example.com:17433");
|
|
34
|
+
const caps = await client.query(new QueryFrame("sha256:<anchor-id>", { active: true }, 20));
|
|
35
|
+
console.log(caps.count, caps.data);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### NWP — stream results
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
for await (const chunk of client.stream(new QueryFrame("sha256:<anchor-id>"))) {
|
|
42
|
+
console.log(chunk.seq, chunk.data);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### NWP — invoke an action
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { ActionFrame } from "@labacacia/nps-sdk/nwp";
|
|
50
|
+
|
|
51
|
+
const result = await client.invoke(new ActionFrame("summarise", { maxTokens: 500 }));
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### NIP — Ed25519 identity
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { NipIdentity } from "@labacacia/nps-sdk/nip";
|
|
58
|
+
|
|
59
|
+
// Generate and persist
|
|
60
|
+
const id = NipIdentity.generate();
|
|
61
|
+
id.save("./my-key.json", process.env.KEY_PASS!);
|
|
62
|
+
|
|
63
|
+
// Load and sign
|
|
64
|
+
const loaded = NipIdentity.load("./my-key.json", process.env.KEY_PASS!);
|
|
65
|
+
const sig = loaded.sign({ action: "announce", nid: "urn:nps:node:example.com:data" });
|
|
66
|
+
const ok = loaded.verify({ action: "announce", nid: "urn:nps:node:example.com:data" }, sig);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### NDP — registry and signature validation
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { InMemoryNdpRegistry, NdpAnnounceValidator } from "@labacacia/nps-sdk/ndp";
|
|
73
|
+
import { AnnounceFrame } from "@labacacia/nps-sdk/ndp";
|
|
74
|
+
|
|
75
|
+
const registry = new InMemoryNdpRegistry();
|
|
76
|
+
const validator = new NdpAnnounceValidator();
|
|
77
|
+
validator.registerPublicKey(nid, identity.pubKeyString);
|
|
78
|
+
|
|
79
|
+
registry.announce(frame);
|
|
80
|
+
const resolved = registry.resolve("nwp://example.com/data/items");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### NOP — submit and wait for a task
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { NopClient, TaskFrame } from "@labacacia/nps-sdk/nop";
|
|
87
|
+
|
|
88
|
+
const client = new NopClient("http://orchestrator.example.com:17433");
|
|
89
|
+
const dag = {
|
|
90
|
+
nodes: [{ id: "classify", action: "classify-text", agent: "urn:nps:node:ml.example.com:classifier" }],
|
|
91
|
+
edges: [],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const taskId = await client.submit(new TaskFrame("my-task-1", dag));
|
|
95
|
+
const status = await client.wait(taskId, { timeoutMs: 30_000 });
|
|
96
|
+
console.log(status.state, status.aggregatedResult);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Package Exports
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { ... } from "@labacacia/nps-sdk"; // everything
|
|
103
|
+
import { ... } from "@labacacia/nps-sdk/core"; // codec, frames, registry, cache
|
|
104
|
+
import { ... } from "@labacacia/nps-sdk/ncp"; // AnchorFrame, CapsFrame, StreamFrame, …
|
|
105
|
+
import { ... } from "@labacacia/nps-sdk/nwp"; // NwpClient, QueryFrame, ActionFrame
|
|
106
|
+
import { ... } from "@labacacia/nps-sdk/nip"; // NipIdentity, IdentFrame, TrustFrame, RevokeFrame
|
|
107
|
+
import { ... } from "@labacacia/nps-sdk/ndp"; // InMemoryNdpRegistry, NdpAnnounceValidator, AnnounceFrame, …
|
|
108
|
+
import { ... } from "@labacacia/nps-sdk/nop"; // NopClient, NopTaskStatus, TaskFrame, …
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## NCP Codec
|
|
112
|
+
|
|
113
|
+
The codec layer supports dual-tier encoding and direct wire-format manipulation:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { NpsFrameCodec, EncodingTier } from "@labacacia/nps-sdk/core";
|
|
117
|
+
import { createDefaultRegistry } from "@labacacia/nps-sdk";
|
|
118
|
+
|
|
119
|
+
const codec = new NpsFrameCodec(createDefaultRegistry());
|
|
120
|
+
|
|
121
|
+
// Encode (defaults to MsgPack)
|
|
122
|
+
const wire = codec.encode(frame);
|
|
123
|
+
|
|
124
|
+
// Encode as JSON (debugging / interop)
|
|
125
|
+
const json = codec.encode(frame, { overrideTier: EncodingTier.JSON });
|
|
126
|
+
|
|
127
|
+
// Decode
|
|
128
|
+
const decoded = codec.decode(wire);
|
|
129
|
+
|
|
130
|
+
// Peek at the header without decoding the payload
|
|
131
|
+
const header = NpsFrameCodec.peekHeader(wire);
|
|
132
|
+
console.log(header.frameType, header.isExtended, header.payloadLength);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Install (no symlinks required on restricted filesystems)
|
|
139
|
+
npm install --no-bin-links
|
|
140
|
+
|
|
141
|
+
# Test
|
|
142
|
+
node node_modules/vitest/vitest.mjs run
|
|
143
|
+
|
|
144
|
+
# Test + coverage
|
|
145
|
+
node node_modules/vitest/vitest.mjs run --coverage
|
|
146
|
+
|
|
147
|
+
# Build (ESM + CJS)
|
|
148
|
+
node node_modules/tsup/dist/cli-default.js
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
Apache 2.0 — see [LICENSE](../../LICENSE)
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** Unified frame byte namespace for the full NPS suite (NPS-0 §9). */
|
|
2
|
+
declare enum FrameType {
|
|
3
|
+
ANCHOR = 1,
|
|
4
|
+
DIFF = 2,
|
|
5
|
+
STREAM = 3,
|
|
6
|
+
CAPS = 4,
|
|
7
|
+
ALIGN = 5,// deprecated — use AlignStream (0x43)
|
|
8
|
+
QUERY = 16,
|
|
9
|
+
ACTION = 17,
|
|
10
|
+
IDENT = 32,
|
|
11
|
+
TRUST = 33,
|
|
12
|
+
REVOKE = 34,
|
|
13
|
+
ANNOUNCE = 48,
|
|
14
|
+
RESOLVE = 49,
|
|
15
|
+
GRAPH = 50,
|
|
16
|
+
TASK = 64,
|
|
17
|
+
DELEGATE = 65,
|
|
18
|
+
SYNC = 66,
|
|
19
|
+
ALIGN_STREAM = 67,
|
|
20
|
+
ERROR = 254
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wire encoding tier, stored in the lower 2 bits of the flags byte (NPS-1 §3.2).
|
|
24
|
+
* 0x00 = Tier-1 JSON — human-readable; development / compatibility.
|
|
25
|
+
* 0x01 = Tier-2 MsgPack — binary, ~60 % smaller; production default.
|
|
26
|
+
*/
|
|
27
|
+
declare enum EncodingTier {
|
|
28
|
+
JSON = 0,
|
|
29
|
+
MSGPACK = 1
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Flags byte in the NPS frame header (NPS-1 §3.2).
|
|
33
|
+
* Bit layout (LSB = bit 0):
|
|
34
|
+
* Bits 0–1 (T0,T1) : Encoding tier
|
|
35
|
+
* Bit 2 (FINAL) : Last chunk of a StreamFrame; non-stream frames MUST set this
|
|
36
|
+
* Bit 3 (ENC) : Payload encrypted
|
|
37
|
+
* Bits 4–6 (RSV) : Reserved — sender MUST write 0
|
|
38
|
+
* Bit 7 (EXT) : Extended 8-byte header
|
|
39
|
+
*/
|
|
40
|
+
declare const FrameFlags: {
|
|
41
|
+
readonly NONE: 0;
|
|
42
|
+
readonly TIER1_JSON: 0;
|
|
43
|
+
readonly TIER2_MSGPACK: 1;
|
|
44
|
+
readonly FINAL: 4;
|
|
45
|
+
readonly ENCRYPTED: 8;
|
|
46
|
+
readonly EXT: 128;
|
|
47
|
+
};
|
|
48
|
+
declare const DEFAULT_HEADER_SIZE = 4;
|
|
49
|
+
declare const EXTENDED_HEADER_SIZE = 8;
|
|
50
|
+
declare const DEFAULT_MAX_PAYLOAD = 65535;
|
|
51
|
+
declare const EXTENDED_MAX_PAYLOAD = 4294967295;
|
|
52
|
+
/**
|
|
53
|
+
* NPS frame header, present at the start of every wire message (NPS-1 §3.1).
|
|
54
|
+
*
|
|
55
|
+
* Default (4 bytes, EXT=0):
|
|
56
|
+
* Byte 0 : FrameType
|
|
57
|
+
* Byte 1 : Flags
|
|
58
|
+
* Byte 2–3 : PayloadLength (big-endian uint16)
|
|
59
|
+
*
|
|
60
|
+
* Extended (8 bytes, EXT=1):
|
|
61
|
+
* Byte 0 : FrameType
|
|
62
|
+
* Byte 1 : Flags (bit 7 = 1)
|
|
63
|
+
* Byte 2–3 : Reserved (must be 0)
|
|
64
|
+
* Byte 4–7 : PayloadLength (big-endian uint32)
|
|
65
|
+
*/
|
|
66
|
+
declare class FrameHeader {
|
|
67
|
+
readonly frameType: FrameType;
|
|
68
|
+
readonly flags: number;
|
|
69
|
+
readonly payloadLength: number;
|
|
70
|
+
constructor(frameType: FrameType, flags: number, payloadLength: number);
|
|
71
|
+
get isExtended(): boolean;
|
|
72
|
+
get headerSize(): number;
|
|
73
|
+
get encodingTier(): EncodingTier;
|
|
74
|
+
get isFinal(): boolean;
|
|
75
|
+
get isEncrypted(): boolean;
|
|
76
|
+
static parse(buf: Uint8Array): FrameHeader;
|
|
77
|
+
toBytes(): Uint8Array;
|
|
78
|
+
toString(): string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface FrameClass {
|
|
82
|
+
fromDict(data: Record<string, unknown>): NpsFrame;
|
|
83
|
+
}
|
|
84
|
+
declare class FrameRegistry {
|
|
85
|
+
private readonly _map;
|
|
86
|
+
register(frameType: FrameType, cls: FrameClass): void;
|
|
87
|
+
resolve(frameType: FrameType): FrameClass;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface NpsFrame {
|
|
91
|
+
readonly frameType: FrameType;
|
|
92
|
+
readonly preferredTier: EncodingTier;
|
|
93
|
+
toDict(): Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
declare class Tier1JsonCodec {
|
|
96
|
+
encode(frame: NpsFrame): Uint8Array;
|
|
97
|
+
decode(frameType: FrameType, payload: Uint8Array, registry: FrameRegistry): NpsFrame;
|
|
98
|
+
}
|
|
99
|
+
declare class Tier2MsgPackCodec {
|
|
100
|
+
encode(frame: NpsFrame): Uint8Array;
|
|
101
|
+
decode(frameType: FrameType, payload: Uint8Array, registry: FrameRegistry): NpsFrame;
|
|
102
|
+
}
|
|
103
|
+
declare class NpsFrameCodec {
|
|
104
|
+
private readonly _registry;
|
|
105
|
+
private readonly _maxPayload;
|
|
106
|
+
private readonly _json;
|
|
107
|
+
private readonly _msgpack;
|
|
108
|
+
constructor(registry: FrameRegistry, options?: {
|
|
109
|
+
maxPayload?: number;
|
|
110
|
+
});
|
|
111
|
+
encode(frame: NpsFrame, options?: {
|
|
112
|
+
overrideTier?: EncodingTier;
|
|
113
|
+
}): Uint8Array;
|
|
114
|
+
decode(wire: Uint8Array): NpsFrame;
|
|
115
|
+
static peekHeader(wire: Uint8Array): FrameHeader;
|
|
116
|
+
private _buildFlags;
|
|
117
|
+
private _selectCodec;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { DEFAULT_HEADER_SIZE as D, EXTENDED_HEADER_SIZE as E, FrameRegistry as F, type NpsFrame as N, Tier1JsonCodec as T, DEFAULT_MAX_PAYLOAD as a, EXTENDED_MAX_PAYLOAD as b, EncodingTier as c, type FrameClass as d, FrameFlags as e, FrameHeader as f, FrameType as g, NpsFrameCodec as h, Tier2MsgPackCodec as i };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** Unified frame byte namespace for the full NPS suite (NPS-0 §9). */
|
|
2
|
+
declare enum FrameType {
|
|
3
|
+
ANCHOR = 1,
|
|
4
|
+
DIFF = 2,
|
|
5
|
+
STREAM = 3,
|
|
6
|
+
CAPS = 4,
|
|
7
|
+
ALIGN = 5,// deprecated — use AlignStream (0x43)
|
|
8
|
+
QUERY = 16,
|
|
9
|
+
ACTION = 17,
|
|
10
|
+
IDENT = 32,
|
|
11
|
+
TRUST = 33,
|
|
12
|
+
REVOKE = 34,
|
|
13
|
+
ANNOUNCE = 48,
|
|
14
|
+
RESOLVE = 49,
|
|
15
|
+
GRAPH = 50,
|
|
16
|
+
TASK = 64,
|
|
17
|
+
DELEGATE = 65,
|
|
18
|
+
SYNC = 66,
|
|
19
|
+
ALIGN_STREAM = 67,
|
|
20
|
+
ERROR = 254
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wire encoding tier, stored in the lower 2 bits of the flags byte (NPS-1 §3.2).
|
|
24
|
+
* 0x00 = Tier-1 JSON — human-readable; development / compatibility.
|
|
25
|
+
* 0x01 = Tier-2 MsgPack — binary, ~60 % smaller; production default.
|
|
26
|
+
*/
|
|
27
|
+
declare enum EncodingTier {
|
|
28
|
+
JSON = 0,
|
|
29
|
+
MSGPACK = 1
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Flags byte in the NPS frame header (NPS-1 §3.2).
|
|
33
|
+
* Bit layout (LSB = bit 0):
|
|
34
|
+
* Bits 0–1 (T0,T1) : Encoding tier
|
|
35
|
+
* Bit 2 (FINAL) : Last chunk of a StreamFrame; non-stream frames MUST set this
|
|
36
|
+
* Bit 3 (ENC) : Payload encrypted
|
|
37
|
+
* Bits 4–6 (RSV) : Reserved — sender MUST write 0
|
|
38
|
+
* Bit 7 (EXT) : Extended 8-byte header
|
|
39
|
+
*/
|
|
40
|
+
declare const FrameFlags: {
|
|
41
|
+
readonly NONE: 0;
|
|
42
|
+
readonly TIER1_JSON: 0;
|
|
43
|
+
readonly TIER2_MSGPACK: 1;
|
|
44
|
+
readonly FINAL: 4;
|
|
45
|
+
readonly ENCRYPTED: 8;
|
|
46
|
+
readonly EXT: 128;
|
|
47
|
+
};
|
|
48
|
+
declare const DEFAULT_HEADER_SIZE = 4;
|
|
49
|
+
declare const EXTENDED_HEADER_SIZE = 8;
|
|
50
|
+
declare const DEFAULT_MAX_PAYLOAD = 65535;
|
|
51
|
+
declare const EXTENDED_MAX_PAYLOAD = 4294967295;
|
|
52
|
+
/**
|
|
53
|
+
* NPS frame header, present at the start of every wire message (NPS-1 §3.1).
|
|
54
|
+
*
|
|
55
|
+
* Default (4 bytes, EXT=0):
|
|
56
|
+
* Byte 0 : FrameType
|
|
57
|
+
* Byte 1 : Flags
|
|
58
|
+
* Byte 2–3 : PayloadLength (big-endian uint16)
|
|
59
|
+
*
|
|
60
|
+
* Extended (8 bytes, EXT=1):
|
|
61
|
+
* Byte 0 : FrameType
|
|
62
|
+
* Byte 1 : Flags (bit 7 = 1)
|
|
63
|
+
* Byte 2–3 : Reserved (must be 0)
|
|
64
|
+
* Byte 4–7 : PayloadLength (big-endian uint32)
|
|
65
|
+
*/
|
|
66
|
+
declare class FrameHeader {
|
|
67
|
+
readonly frameType: FrameType;
|
|
68
|
+
readonly flags: number;
|
|
69
|
+
readonly payloadLength: number;
|
|
70
|
+
constructor(frameType: FrameType, flags: number, payloadLength: number);
|
|
71
|
+
get isExtended(): boolean;
|
|
72
|
+
get headerSize(): number;
|
|
73
|
+
get encodingTier(): EncodingTier;
|
|
74
|
+
get isFinal(): boolean;
|
|
75
|
+
get isEncrypted(): boolean;
|
|
76
|
+
static parse(buf: Uint8Array): FrameHeader;
|
|
77
|
+
toBytes(): Uint8Array;
|
|
78
|
+
toString(): string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface FrameClass {
|
|
82
|
+
fromDict(data: Record<string, unknown>): NpsFrame;
|
|
83
|
+
}
|
|
84
|
+
declare class FrameRegistry {
|
|
85
|
+
private readonly _map;
|
|
86
|
+
register(frameType: FrameType, cls: FrameClass): void;
|
|
87
|
+
resolve(frameType: FrameType): FrameClass;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface NpsFrame {
|
|
91
|
+
readonly frameType: FrameType;
|
|
92
|
+
readonly preferredTier: EncodingTier;
|
|
93
|
+
toDict(): Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
declare class Tier1JsonCodec {
|
|
96
|
+
encode(frame: NpsFrame): Uint8Array;
|
|
97
|
+
decode(frameType: FrameType, payload: Uint8Array, registry: FrameRegistry): NpsFrame;
|
|
98
|
+
}
|
|
99
|
+
declare class Tier2MsgPackCodec {
|
|
100
|
+
encode(frame: NpsFrame): Uint8Array;
|
|
101
|
+
decode(frameType: FrameType, payload: Uint8Array, registry: FrameRegistry): NpsFrame;
|
|
102
|
+
}
|
|
103
|
+
declare class NpsFrameCodec {
|
|
104
|
+
private readonly _registry;
|
|
105
|
+
private readonly _maxPayload;
|
|
106
|
+
private readonly _json;
|
|
107
|
+
private readonly _msgpack;
|
|
108
|
+
constructor(registry: FrameRegistry, options?: {
|
|
109
|
+
maxPayload?: number;
|
|
110
|
+
});
|
|
111
|
+
encode(frame: NpsFrame, options?: {
|
|
112
|
+
overrideTier?: EncodingTier;
|
|
113
|
+
}): Uint8Array;
|
|
114
|
+
decode(wire: Uint8Array): NpsFrame;
|
|
115
|
+
static peekHeader(wire: Uint8Array): FrameHeader;
|
|
116
|
+
private _buildFlags;
|
|
117
|
+
private _selectCodec;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { DEFAULT_HEADER_SIZE as D, EXTENDED_HEADER_SIZE as E, FrameRegistry as F, type NpsFrame as N, Tier1JsonCodec as T, DEFAULT_MAX_PAYLOAD as a, EXTENDED_MAX_PAYLOAD as b, EncodingTier as c, type FrameClass as d, FrameFlags as e, FrameHeader as f, FrameType as g, NpsFrameCodec as h, Tier2MsgPackCodec as i };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AnchorFrame } from "../ncp/frames/anchor-frame.js";
|
|
2
|
+
/**
|
|
3
|
+
* AnchorFrame cache with:
|
|
4
|
+
* - TTL-based expiry (NPS-1 §5.3)
|
|
5
|
+
* - LRU eviction at maxSize (NPS-1 §9, default 1000)
|
|
6
|
+
* - Anchor poisoning detection (NPS-1 §7.2)
|
|
7
|
+
*/
|
|
8
|
+
export declare class AnchorCache {
|
|
9
|
+
private readonly cache;
|
|
10
|
+
private readonly maxSize;
|
|
11
|
+
private readonly getNow;
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
maxSize?: number;
|
|
14
|
+
getNow?: () => number;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Cache an AnchorFrame.
|
|
18
|
+
*
|
|
19
|
+
* - ttl=0: frame is valid but not cached (NPS-1 §4.1)
|
|
20
|
+
* - Same anchor_id + same schema: idempotent (no-op)
|
|
21
|
+
* - Same anchor_id + different schema: NCP-ANCHOR-ID-MISMATCH (poison detection)
|
|
22
|
+
*
|
|
23
|
+
* @throws {NcpError} NCP-ANCHOR-ID-MISMATCH on anchor poisoning.
|
|
24
|
+
*/
|
|
25
|
+
set(frame: AnchorFrame): void;
|
|
26
|
+
/**
|
|
27
|
+
* Get a cached AnchorFrame by anchor_id.
|
|
28
|
+
*
|
|
29
|
+
* @returns The cached frame, or null if not found or expired.
|
|
30
|
+
*/
|
|
31
|
+
get(anchorId: string): AnchorFrame | null;
|
|
32
|
+
/**
|
|
33
|
+
* Get a cached AnchorFrame, throwing if not found.
|
|
34
|
+
* @throws {NcpError} NCP-ANCHOR-NOT-FOUND if not in cache or expired.
|
|
35
|
+
*/
|
|
36
|
+
getRequired(anchorId: string): AnchorFrame;
|
|
37
|
+
/** Current cache size. */
|
|
38
|
+
get size(): number;
|
|
39
|
+
/** Evict the least recently accessed entry. */
|
|
40
|
+
private evictLru;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=anchor-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor-cache.d.ts","sourceRoot":"","sources":["../../src/core/anchor-cache.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAQjE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;KAAE;IAKjE;;;;;;;;OAQG;IACH,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAiC7B;;;;OAIG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI;IAczC;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW;IAW1C,0BAA0B;IAC1B,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+CAA+C;IAC/C,OAAO,CAAC,QAAQ;CAejB"}
|