@labacacia/nps-sdk 1.0.0-alpha.6 → 1.0.0-alpha.8
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 +126 -0
- package/CHANGELOG.md +135 -0
- package/README.cn.md +9 -2
- package/README.md +9 -2
- 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/{src/core/codecs/index.ts → dist/core/codecs/index.js} +1 -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/{src/core/codecs/tier1-json-codec.ts → dist/core/codecs/tier1-json-codec.js} +11 -16
- 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/{src/core/codecs/tier2-msgpack-codec.ts → dist/core/codecs/tier2-msgpack-codec.js} +10 -14
- 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 +82 -0
- package/dist/core/frames.d.ts.map +1 -0
- package/dist/core/frames.js +155 -0
- package/dist/core/frames.js.map +1 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.d.ts.map +1 -0
- package/{src/core/index.ts → dist/core/index.js} +3 -23
- 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 +29 -0
- package/dist/core/status-codes.d.ts.map +1 -0
- package/dist/core/status-codes.js +39 -0
- package/dist/core/status-codes.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -1
- 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 +94 -0
- package/dist/ncp/frames.d.ts.map +1 -0
- package/dist/ncp/frames.js +192 -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.d.ts +12 -0
- package/dist/ncp/index.d.ts.map +1 -0
- package/{src/ncp/index.ts → dist/ncp/index.js} +1 -0
- package/dist/ncp/index.js.map +1 -0
- package/dist/ncp/ncp-error-codes.d.ts +23 -0
- package/dist/ncp/ncp-error-codes.d.ts.map +1 -0
- package/dist/ncp/ncp-error-codes.js +34 -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/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 +3 -0
- package/dist/ncp/registry.d.ts.map +1 -0
- package/dist/ncp/registry.js +13 -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/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 +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.d.ts +6 -0
- package/dist/ndp/index.d.ts.map +1 -0
- package/{src/ndp/index.ts → dist/ndp/index.js} +1 -1
- package/dist/ndp/index.js.map +1 -0
- package/dist/ndp/ndp-registry.d.ts +13 -0
- package/dist/ndp/ndp-registry.d.ts.map +1 -0
- package/dist/ndp/ndp-registry.js +104 -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/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/{src/nip/acme/index.ts → dist/nip/acme/index.js} +1 -1
- 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 +25 -0
- package/dist/nip/error-codes.d.ts.map +1 -0
- package/{src/nip/error-codes.ts → dist/nip/error-codes.js} +19 -25
- package/dist/nip/error-codes.js.map +1 -0
- package/dist/nip/frames.d.ts +53 -0
- package/dist/nip/frames.d.ts.map +1 -0
- package/dist/nip/frames.js +106 -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.d.ts +11 -0
- package/dist/nip/index.d.ts.map +1 -0
- package/{src/nip/index.ts → dist/nip/index.js} +3 -2
- 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/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/{src/nip/x509/index.ts → dist/nip/x509/index.js} +1 -1
- 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/{src/nip/x509/oids.ts → dist/nip/x509/oids.js} +5 -10
- 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 +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.d.ts +5 -0
- package/dist/nop/index.d.ts.map +1 -0
- package/{src/nop/index.ts → dist/nop/index.js} +1 -1
- 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/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/client.d.ts +28 -0
- package/dist/nwp/client.d.ts.map +1 -0
- package/dist/nwp/client.js +142 -0
- package/dist/nwp/client.js.map +1 -0
- package/dist/nwp/frames.d.ts +107 -0
- package/dist/nwp/frames.d.ts.map +1 -0
- package/dist/nwp/frames.js +198 -0
- package/dist/nwp/frames.js.map +1 -0
- package/dist/nwp/index.d.ts +6 -0
- package/dist/nwp/index.d.ts.map +1 -0
- package/{src/nwp/index.ts → dist/nwp/index.js} +3 -1
- package/dist/nwp/index.js.map +1 -0
- package/dist/nwp/manifest.d.ts +69 -0
- package/dist/nwp/manifest.d.ts.map +1 -0
- package/dist/nwp/manifest.js +4 -0
- package/dist/nwp/manifest.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 +10 -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/{src/setup.ts → dist/setup.js} +13 -16
- package/dist/setup.js.map +1 -0
- package/package.json +12 -1
- package/CONTRIBUTING.cn.md +0 -35
- package/CONTRIBUTING.md +0 -35
- 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/ncp-codec.ts +0 -170
- 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 -184
- package/src/core/registry.ts +0 -28
- package/src/core/status-codes.ts +0 -47
- 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 -251
- package/src/ncp/handshake.ts +0 -95
- package/src/ncp/ncp-error-codes.ts +0 -36
- package/src/ncp/ncp-patch-format.ts +0 -16
- package/src/ncp/preamble.ts +0 -79
- package/src/ncp/registry.ts +0 -15
- package/src/ncp/stream-manager.ts +0 -212
- package/src/ndp/dns-txt.ts +0 -86
- package/src/ndp/frames.ts +0 -124
- package/src/ndp/ndp-registry.ts +0 -116
- package/src/ndp/registry.ts +0 -12
- package/src/ndp/validator.ts +0 -64
- package/src/nip/acme/client.ts +0 -185
- package/src/nip/acme/jws.ts +0 -109
- package/src/nip/acme/messages.ts +0 -85
- package/src/nip/acme/server.ts +0 -480
- package/src/nip/acme/wire.ts +0 -24
- package/src/nip/assurance-level.ts +0 -40
- package/src/nip/cert-format.ts +0 -9
- package/src/nip/frames.ts +0 -138
- package/src/nip/identity.ts +0 -113
- package/src/nip/registry.ts +0 -12
- package/src/nip/verifier.ts +0 -122
- package/src/nip/x509/builder.ts +0 -91
- package/src/nip/x509/verifier.ts +0 -214
- package/src/nop/client.ts +0 -103
- package/src/nop/frames.ts +0 -181
- 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/registry.ts +0 -11
- package/tests/_rfc0002-keys.ts +0 -57
- 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/preamble.test.ts +0 -93
- 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 -377
- package/tests/nip-acme-agent01.test.ts +0 -192
- package/tests/nip-x509.test.ts +0 -280
- 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/ncp/frames.ts
DELETED
|
@@ -1,251 +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
|
-
// ── FrameSchema ───────────────────────────────────────────────────────────────
|
|
8
|
-
|
|
9
|
-
export interface SchemaField {
|
|
10
|
-
name: string;
|
|
11
|
-
type: string;
|
|
12
|
-
semantic?: string;
|
|
13
|
-
nullable?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface FrameSchema {
|
|
17
|
-
fields: readonly SchemaField[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// ── AnchorFrame ───────────────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
export class AnchorFrame implements NpsFrame {
|
|
23
|
-
readonly frameType = FrameType.ANCHOR;
|
|
24
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
25
|
-
|
|
26
|
-
constructor(
|
|
27
|
-
public readonly anchorId: string,
|
|
28
|
-
public readonly schema: FrameSchema,
|
|
29
|
-
public readonly ttl: number = 3600,
|
|
30
|
-
) {}
|
|
31
|
-
|
|
32
|
-
toDict(): Record<string, unknown> {
|
|
33
|
-
return {
|
|
34
|
-
anchor_id: this.anchorId,
|
|
35
|
-
schema: { fields: this.schema.fields.map((f) => ({ ...f })) },
|
|
36
|
-
ttl: this.ttl,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static fromDict(data: Record<string, unknown>): AnchorFrame {
|
|
41
|
-
const schemaRaw = data["schema"] as { fields: SchemaField[] };
|
|
42
|
-
return new AnchorFrame(
|
|
43
|
-
data["anchor_id"] as string,
|
|
44
|
-
{ fields: schemaRaw.fields },
|
|
45
|
-
(data["ttl"] as number | undefined) ?? 3600,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ── JsonPatchOperation ────────────────────────────────────────────────────────
|
|
51
|
-
|
|
52
|
-
export interface JsonPatchOperation {
|
|
53
|
-
op: string;
|
|
54
|
-
path: string;
|
|
55
|
-
value?: unknown;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ── DiffFrame ─────────────────────────────────────────────────────────────────
|
|
59
|
-
|
|
60
|
-
export class DiffFrame implements NpsFrame {
|
|
61
|
-
readonly frameType = FrameType.DIFF;
|
|
62
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
63
|
-
|
|
64
|
-
constructor(
|
|
65
|
-
public readonly anchorRef: string,
|
|
66
|
-
public readonly baseSeq: number,
|
|
67
|
-
public readonly patch: readonly JsonPatchOperation[],
|
|
68
|
-
public readonly entityId?: string,
|
|
69
|
-
) {}
|
|
70
|
-
|
|
71
|
-
toDict(): Record<string, unknown> {
|
|
72
|
-
return {
|
|
73
|
-
anchor_ref: this.anchorRef,
|
|
74
|
-
base_seq: this.baseSeq,
|
|
75
|
-
patch: this.patch.map((p) => ({ ...p })),
|
|
76
|
-
entity_id: this.entityId ?? null,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static fromDict(data: Record<string, unknown>): DiffFrame {
|
|
81
|
-
return new DiffFrame(
|
|
82
|
-
data["anchor_ref"] as string,
|
|
83
|
-
data["base_seq"] as number,
|
|
84
|
-
data["patch"] as JsonPatchOperation[],
|
|
85
|
-
(data["entity_id"] as string | null) ?? undefined,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ── StreamFrame ───────────────────────────────────────────────────────────────
|
|
91
|
-
|
|
92
|
-
export class StreamFrame implements NpsFrame {
|
|
93
|
-
readonly frameType = FrameType.STREAM;
|
|
94
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
95
|
-
|
|
96
|
-
constructor(
|
|
97
|
-
public readonly streamId: string,
|
|
98
|
-
public readonly seq: number,
|
|
99
|
-
public readonly isLast: boolean,
|
|
100
|
-
public readonly data: readonly Record<string, unknown>[],
|
|
101
|
-
public readonly anchorRef?: string,
|
|
102
|
-
public readonly windowSize?: number,
|
|
103
|
-
) {}
|
|
104
|
-
|
|
105
|
-
toDict(): Record<string, unknown> {
|
|
106
|
-
return {
|
|
107
|
-
stream_id: this.streamId,
|
|
108
|
-
seq: this.seq,
|
|
109
|
-
is_last: this.isLast,
|
|
110
|
-
data: this.data,
|
|
111
|
-
anchor_ref: this.anchorRef ?? null,
|
|
112
|
-
window_size: this.windowSize ?? null,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static fromDict(data: Record<string, unknown>): StreamFrame {
|
|
117
|
-
return new StreamFrame(
|
|
118
|
-
data["stream_id"] as string,
|
|
119
|
-
data["seq"] as number,
|
|
120
|
-
data["is_last"] as boolean,
|
|
121
|
-
data["data"] as Record<string, unknown>[],
|
|
122
|
-
(data["anchor_ref"] as string | null) ?? undefined,
|
|
123
|
-
(data["window_size"] as number | null) ?? undefined,
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ── CapsFrame ─────────────────────────────────────────────────────────────────
|
|
129
|
-
|
|
130
|
-
export class CapsFrame implements NpsFrame {
|
|
131
|
-
readonly frameType = FrameType.CAPS;
|
|
132
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
133
|
-
|
|
134
|
-
constructor(
|
|
135
|
-
public readonly anchorRef: string,
|
|
136
|
-
public readonly count: number,
|
|
137
|
-
public readonly data: readonly Record<string, unknown>[],
|
|
138
|
-
public readonly nextCursor?: string,
|
|
139
|
-
public readonly tokenEst?: number,
|
|
140
|
-
public readonly cached?: boolean,
|
|
141
|
-
public readonly tokenizerUsed?: string,
|
|
142
|
-
) {}
|
|
143
|
-
|
|
144
|
-
toDict(): Record<string, unknown> {
|
|
145
|
-
return {
|
|
146
|
-
anchor_ref: this.anchorRef,
|
|
147
|
-
count: this.count,
|
|
148
|
-
data: this.data,
|
|
149
|
-
next_cursor: this.nextCursor ?? null,
|
|
150
|
-
token_est: this.tokenEst ?? null,
|
|
151
|
-
cached: this.cached ?? null,
|
|
152
|
-
tokenizer_used: this.tokenizerUsed ?? null,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
static fromDict(data: Record<string, unknown>): CapsFrame {
|
|
157
|
-
return new CapsFrame(
|
|
158
|
-
data["anchor_ref"] as string,
|
|
159
|
-
data["count"] as number,
|
|
160
|
-
data["data"] as Record<string, unknown>[],
|
|
161
|
-
(data["next_cursor"] as string | null) ?? undefined,
|
|
162
|
-
(data["token_est"] as number | null) ?? undefined,
|
|
163
|
-
(data["cached"] as boolean | null) ?? undefined,
|
|
164
|
-
(data["tokenizer_used"] as string | null) ?? undefined,
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// ── ErrorFrame ────────────────────────────────────────────────────────────────
|
|
170
|
-
|
|
171
|
-
export class ErrorFrame implements NpsFrame {
|
|
172
|
-
readonly frameType = FrameType.ERROR;
|
|
173
|
-
readonly preferredTier = EncodingTier.MSGPACK;
|
|
174
|
-
|
|
175
|
-
constructor(
|
|
176
|
-
public readonly status: string,
|
|
177
|
-
public readonly error: string,
|
|
178
|
-
public readonly message?: string,
|
|
179
|
-
public readonly details?: Record<string, unknown>,
|
|
180
|
-
) {}
|
|
181
|
-
|
|
182
|
-
toDict(): Record<string, unknown> {
|
|
183
|
-
return {
|
|
184
|
-
status: this.status,
|
|
185
|
-
error: this.error,
|
|
186
|
-
message: this.message ?? null,
|
|
187
|
-
details: this.details ?? null,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
static fromDict(data: Record<string, unknown>): ErrorFrame {
|
|
192
|
-
return new ErrorFrame(
|
|
193
|
-
data["status"] as string,
|
|
194
|
-
data["error"] as string,
|
|
195
|
-
(data["message"] as string | null) ?? undefined,
|
|
196
|
-
(data["details"] as Record<string, unknown> | null) ?? undefined,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ── HelloFrame ────────────────────────────────────────────────────────────────
|
|
202
|
-
// NPS-1 §4.6 — Native-mode handshake (0x06). Always Tier-1 JSON: encoding
|
|
203
|
-
// is not yet negotiated when this frame is sent.
|
|
204
|
-
|
|
205
|
-
export class HelloFrame implements NpsFrame {
|
|
206
|
-
readonly frameType = FrameType.HELLO;
|
|
207
|
-
readonly preferredTier = EncodingTier.JSON;
|
|
208
|
-
|
|
209
|
-
static readonly DEFAULT_MAX_FRAME_PAYLOAD = 0xFFFF;
|
|
210
|
-
static readonly DEFAULT_MAX_CONCURRENT_STREAMS = 32;
|
|
211
|
-
|
|
212
|
-
constructor(
|
|
213
|
-
public readonly npsVersion: string,
|
|
214
|
-
public readonly supportedEncodings: readonly string[],
|
|
215
|
-
public readonly supportedProtocols: readonly string[],
|
|
216
|
-
public minVersion?: string,
|
|
217
|
-
public agentId?: string,
|
|
218
|
-
public maxFramePayload: number = HelloFrame.DEFAULT_MAX_FRAME_PAYLOAD,
|
|
219
|
-
public extSupport: boolean = false,
|
|
220
|
-
public maxConcurrentStreams: number = HelloFrame.DEFAULT_MAX_CONCURRENT_STREAMS,
|
|
221
|
-
public e2eEncAlgorithms?: readonly string[],
|
|
222
|
-
) {}
|
|
223
|
-
|
|
224
|
-
toDict(): Record<string, unknown> {
|
|
225
|
-
return {
|
|
226
|
-
nps_version: this.npsVersion,
|
|
227
|
-
supported_encodings: [...this.supportedEncodings],
|
|
228
|
-
supported_protocols: [...this.supportedProtocols],
|
|
229
|
-
min_version: this.minVersion ?? null,
|
|
230
|
-
agent_id: this.agentId ?? null,
|
|
231
|
-
max_frame_payload: this.maxFramePayload,
|
|
232
|
-
ext_support: this.extSupport,
|
|
233
|
-
max_concurrent_streams: this.maxConcurrentStreams,
|
|
234
|
-
e2e_enc_algorithms: this.e2eEncAlgorithms ? [...this.e2eEncAlgorithms] : null,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
static fromDict(data: Record<string, unknown>): HelloFrame {
|
|
239
|
-
return new HelloFrame(
|
|
240
|
-
data["nps_version"] as string,
|
|
241
|
-
(data["supported_encodings"] as string[]) ?? [],
|
|
242
|
-
(data["supported_protocols"] as string[]) ?? [],
|
|
243
|
-
(data["min_version"] as string | null) ?? undefined,
|
|
244
|
-
(data["agent_id"] as string | null) ?? undefined,
|
|
245
|
-
(data["max_frame_payload"] as number | null) ?? HelloFrame.DEFAULT_MAX_FRAME_PAYLOAD,
|
|
246
|
-
(data["ext_support"] as boolean | null) ?? false,
|
|
247
|
-
(data["max_concurrent_streams"] as number | null) ?? HelloFrame.DEFAULT_MAX_CONCURRENT_STREAMS,
|
|
248
|
-
(data["e2e_enc_algorithms"] as string[] | null) ?? undefined,
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
}
|
package/src/ncp/handshake.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
|
|
3
|
-
//
|
|
4
|
-
// Handshake — Version negotiation and encoding negotiation
|
|
5
|
-
// NPS-1 §2.6
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Parse a "major.minor" (optionally "major.minor.patch") version string into a
|
|
9
|
-
* tuple of numeric components. Invalid parts become NaN which makes subsequent
|
|
10
|
-
* comparisons return false in both directions (safe failure).
|
|
11
|
-
*/
|
|
12
|
-
function parseVersion(v: string): number[] {
|
|
13
|
-
return v.split(".").map((p) => Number.parseInt(p, 10));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Numeric component-wise comparison of two version strings.
|
|
18
|
-
* Returns negative if a < b, zero if equal, positive if a > b.
|
|
19
|
-
* Avoids the lexicographic pitfall where "0.9" > "0.10".
|
|
20
|
-
*/
|
|
21
|
-
function compareVersions(a: string, b: string): number {
|
|
22
|
-
const partsA = parseVersion(a);
|
|
23
|
-
const partsB = parseVersion(b);
|
|
24
|
-
const len = Math.max(partsA.length, partsB.length);
|
|
25
|
-
for (let i = 0; i < len; i += 1) {
|
|
26
|
-
const x = partsA[i] ?? 0;
|
|
27
|
-
const y = partsB[i] ?? 0;
|
|
28
|
-
if (x !== y) return x - y;
|
|
29
|
-
}
|
|
30
|
-
return 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Negotiate the session NPS version between client and server.
|
|
35
|
-
*
|
|
36
|
-
* Session version = numeric min of client.nps_version and server.nps_version
|
|
37
|
-
* (component-wise — "0.9" < "0.10" < "1.0").
|
|
38
|
-
* If the effective client minimum (min_version ?? nps_version) > server.nps_version,
|
|
39
|
-
* the versions are incompatible.
|
|
40
|
-
*
|
|
41
|
-
* Spec: NPS-1 §2.6
|
|
42
|
-
*/
|
|
43
|
-
export function negotiateVersion(
|
|
44
|
-
client: { nps_version: string; min_version?: string },
|
|
45
|
-
server: { nps_version: string },
|
|
46
|
-
): { session_version: string; compatible: boolean; error_code?: string } {
|
|
47
|
-
const clientMin = client.min_version ?? client.nps_version;
|
|
48
|
-
const serverVersion = server.nps_version;
|
|
49
|
-
|
|
50
|
-
if (compareVersions(clientMin, serverVersion) > 0) {
|
|
51
|
-
return {
|
|
52
|
-
session_version: serverVersion,
|
|
53
|
-
compatible: false,
|
|
54
|
-
error_code: "NCP-VERSION-INCOMPATIBLE",
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Session version = component-wise min of client.nps_version and server.nps_version
|
|
59
|
-
const sessionVersion =
|
|
60
|
-
compareVersions(client.nps_version, serverVersion) <= 0
|
|
61
|
-
? client.nps_version
|
|
62
|
-
: serverVersion;
|
|
63
|
-
|
|
64
|
-
return { session_version: sessionVersion, compatible: true };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Negotiate the encoding between client and server preferred lists.
|
|
69
|
-
*
|
|
70
|
-
* Returns the first mutually supported encoding, preferring "msgpack" over "json".
|
|
71
|
-
* Returns null if there is no intersection.
|
|
72
|
-
*/
|
|
73
|
-
export function negotiateEncoding(
|
|
74
|
-
client: string[],
|
|
75
|
-
server: string[],
|
|
76
|
-
): { encoding: string | null } {
|
|
77
|
-
const serverSet = new Set(server);
|
|
78
|
-
|
|
79
|
-
// Prefer msgpack over json (and over any other encoding)
|
|
80
|
-
if (client.includes("msgpack") && serverSet.has("msgpack")) {
|
|
81
|
-
return { encoding: "msgpack" };
|
|
82
|
-
}
|
|
83
|
-
if (client.includes("json") && serverSet.has("json")) {
|
|
84
|
-
return { encoding: "json" };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Fall back to first intersection in client-preference order
|
|
88
|
-
for (const enc of client) {
|
|
89
|
-
if (serverSet.has(enc)) {
|
|
90
|
-
return { encoding: enc };
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return { encoding: null };
|
|
95
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
|
|
3
|
-
//
|
|
4
|
-
// NCP Error Codes — All v0.4 protocol error codes
|
|
5
|
-
// NPS-1 §6 + §7.4
|
|
6
|
-
//
|
|
7
|
-
// Implementation-only codes (NCP_FRAME_PARSE_ERROR, NCP_FRAME_INCOMPLETE) cover
|
|
8
|
-
// wire-layer parse failures not in spec §6. See test/ncp_test_results.md spec
|
|
9
|
-
// question 2 for the proposal to register them upstream.
|
|
10
|
-
|
|
11
|
-
export const NCP_ERROR_CODES = {
|
|
12
|
-
// Implementation-only codes (not in spec §6 — see test_results.md spec question 2)
|
|
13
|
-
NCP_FRAME_PARSE_ERROR: "NCP-FRAME-PARSE-ERROR",
|
|
14
|
-
NCP_FRAME_INCOMPLETE: "NCP-FRAME-INCOMPLETE",
|
|
15
|
-
// NPS-RFC-0001 — native-mode preamble
|
|
16
|
-
NCP_PREAMBLE_INVALID: "NCP-PREAMBLE-INVALID",
|
|
17
|
-
// Spec-defined codes
|
|
18
|
-
NCP_FRAME_UNKNOWN_TYPE: "NCP-FRAME-UNKNOWN-TYPE",
|
|
19
|
-
NCP_FRAME_PAYLOAD_TOO_LARGE: "NCP-FRAME-PAYLOAD-TOO-LARGE",
|
|
20
|
-
NCP_FRAME_FLAGS_INVALID: "NCP-FRAME-FLAGS-INVALID",
|
|
21
|
-
NCP_ANCHOR_NOT_FOUND: "NCP-ANCHOR-NOT-FOUND",
|
|
22
|
-
NCP_ANCHOR_SCHEMA_INVALID: "NCP-ANCHOR-SCHEMA-INVALID",
|
|
23
|
-
NCP_ANCHOR_ID_MISMATCH: "NCP-ANCHOR-ID-MISMATCH",
|
|
24
|
-
NCP_ANCHOR_STALE: "NCP-ANCHOR-STALE",
|
|
25
|
-
NCP_STREAM_SEQ_GAP: "NCP-STREAM-SEQ-GAP",
|
|
26
|
-
NCP_STREAM_NOT_FOUND: "NCP-STREAM-NOT-FOUND",
|
|
27
|
-
NCP_STREAM_LIMIT_EXCEEDED: "NCP-STREAM-LIMIT-EXCEEDED",
|
|
28
|
-
NCP_STREAM_WINDOW_OVERFLOW: "NCP-STREAM-WINDOW-OVERFLOW",
|
|
29
|
-
NCP_ENCODING_UNSUPPORTED: "NCP-ENCODING-UNSUPPORTED",
|
|
30
|
-
NCP_DIFF_FORMAT_UNSUPPORTED: "NCP-DIFF-FORMAT-UNSUPPORTED",
|
|
31
|
-
NCP_VERSION_INCOMPATIBLE: "NCP-VERSION-INCOMPATIBLE",
|
|
32
|
-
NCP_ENC_NOT_NEGOTIATED: "NCP-ENC-NOT-NEGOTIATED",
|
|
33
|
-
NCP_ENC_AUTH_FAILED: "NCP-ENC-AUTH-FAILED",
|
|
34
|
-
} as const;
|
|
35
|
-
|
|
36
|
-
export type NcpErrorCode = typeof NCP_ERROR_CODES[keyof typeof NCP_ERROR_CODES];
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Copyright (c) 2026 LabAcacia / INNO LOTUS PTY LTD
|
|
3
|
-
//
|
|
4
|
-
// NCP Patch Format — DiffFrame patch encoding types
|
|
5
|
-
// NPS-1 §4.2
|
|
6
|
-
|
|
7
|
-
export const PATCH_FORMAT = {
|
|
8
|
-
JSON_PATCH: "json_patch",
|
|
9
|
-
BINARY_BITSET: "binary_bitset",
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
export type PatchFormat = typeof PATCH_FORMAT[keyof typeof PATCH_FORMAT];
|
|
13
|
-
|
|
14
|
-
export function isValidPatchFormat(v: unknown): v is PatchFormat {
|
|
15
|
-
return v === PATCH_FORMAT.JSON_PATCH || v === PATCH_FORMAT.BINARY_BITSET;
|
|
16
|
-
}
|
package/src/ncp/preamble.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 INNO LOTUS PTY LTD
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* NCP native-mode connection preamble — the 8-byte ASCII constant
|
|
6
|
-
* `"NPS/1.0\n"` that every native-mode client MUST emit immediately
|
|
7
|
-
* after the transport handshake and before its first HelloFrame.
|
|
8
|
-
* Defined by NPS-RFC-0001 and NPS-1 NCP §2.6.1.
|
|
9
|
-
*
|
|
10
|
-
* HTTP-mode connections do not use the preamble.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export const PREAMBLE_LITERAL = "NPS/1.0\n";
|
|
14
|
-
export const PREAMBLE_LENGTH = 8;
|
|
15
|
-
export const PREAMBLE_BYTES: Uint8Array = new TextEncoder().encode(PREAMBLE_LITERAL);
|
|
16
|
-
/** Validation timeout in milliseconds (NPS-RFC-0001 §4.1). */
|
|
17
|
-
export const PREAMBLE_READ_TIMEOUT_MS = 10_000;
|
|
18
|
-
/** Maximum delay before closing after a mismatch, in milliseconds. */
|
|
19
|
-
export const PREAMBLE_CLOSE_DEADLINE_MS = 500;
|
|
20
|
-
|
|
21
|
-
export const PREAMBLE_ERROR_CODE = "NCP-PREAMBLE-INVALID";
|
|
22
|
-
export const PREAMBLE_STATUS_CODE = "NPS-PROTO-PREAMBLE-INVALID";
|
|
23
|
-
|
|
24
|
-
export class NcpPreambleInvalidError extends Error {
|
|
25
|
-
readonly errorCode = PREAMBLE_ERROR_CODE;
|
|
26
|
-
readonly statusCode = PREAMBLE_STATUS_CODE;
|
|
27
|
-
|
|
28
|
-
constructor(reason: string) {
|
|
29
|
-
super(reason);
|
|
30
|
-
this.name = "NcpPreambleInvalidError";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Returns `true` iff `buf` starts with the 8-byte NPS/1.0 preamble.
|
|
36
|
-
* Safe to call with shorter buffers.
|
|
37
|
-
*/
|
|
38
|
-
export function preambleMatches(buf: Uint8Array): boolean {
|
|
39
|
-
if (buf.length < PREAMBLE_LENGTH) return false;
|
|
40
|
-
for (let i = 0; i < PREAMBLE_LENGTH; i++) {
|
|
41
|
-
if (buf[i] !== PREAMBLE_BYTES[i]) return false;
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Validates a presumed-preamble buffer.
|
|
48
|
-
* Returns `{ valid: true, reason: "" }` on success or `{ valid: false, reason }` on failure.
|
|
49
|
-
*/
|
|
50
|
-
export function tryValidatePreamble(buf: Uint8Array): { valid: boolean; reason: string } {
|
|
51
|
-
if (buf.length < PREAMBLE_LENGTH) {
|
|
52
|
-
return { valid: false, reason: `short read (${buf.length}/${PREAMBLE_LENGTH} bytes); peer is not speaking NCP` };
|
|
53
|
-
}
|
|
54
|
-
if (!preambleMatches(buf)) {
|
|
55
|
-
// "NPS/" = 0x4E 0x50 0x53 0x2F
|
|
56
|
-
const isNps = buf[0] === 0x4e && buf[1] === 0x50 && buf[2] === 0x53 && buf[3] === 0x2f;
|
|
57
|
-
if (isNps) {
|
|
58
|
-
return { valid: false, reason: "future-major-version NPS preamble; close with NPS-PREAMBLE-UNSUPPORTED-VERSION diagnostic" };
|
|
59
|
-
}
|
|
60
|
-
return { valid: false, reason: "preamble mismatch; peer is not speaking NPS/1.x" };
|
|
61
|
-
}
|
|
62
|
-
return { valid: true, reason: "" };
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Validates a presumed-preamble buffer, throwing {@link NcpPreambleInvalidError} on mismatch.
|
|
67
|
-
*/
|
|
68
|
-
export function validatePreamble(buf: Uint8Array): void {
|
|
69
|
-
const { valid, reason } = tryValidatePreamble(buf);
|
|
70
|
-
if (!valid) throw new NcpPreambleInvalidError(reason);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Writes the preamble bytes to `writer`.
|
|
75
|
-
* `writer` must expose a `write(buf: Uint8Array): void` method (e.g. Node.js `net.Socket`).
|
|
76
|
-
*/
|
|
77
|
-
export function writePreamble(writer: { write(buf: Uint8Array): void }): void {
|
|
78
|
-
writer.write(PREAMBLE_BYTES);
|
|
79
|
-
}
|
package/src/ncp/registry.ts
DELETED
|
@@ -1,15 +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 { AnchorFrame, CapsFrame, DiffFrame, ErrorFrame, HelloFrame, StreamFrame } from "./frames.js";
|
|
7
|
-
|
|
8
|
-
export function registerNcpFrames(registry: FrameRegistry): void {
|
|
9
|
-
registry.register(FrameType.ANCHOR, AnchorFrame);
|
|
10
|
-
registry.register(FrameType.DIFF, DiffFrame);
|
|
11
|
-
registry.register(FrameType.STREAM, StreamFrame);
|
|
12
|
-
registry.register(FrameType.CAPS, CapsFrame);
|
|
13
|
-
registry.register(FrameType.HELLO, HelloFrame);
|
|
14
|
-
registry.register(FrameType.ERROR, ErrorFrame);
|
|
15
|
-
}
|