@nextera.one/axis-server-sdk 2.1.1 → 2.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextera.one/axis-server-sdk",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Axis Protocol server-side SDK — decorators, interfaces, and routing primitives for building Axis handlers",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,6 @@
32
32
  ],
33
33
  "scripts": {
34
34
  "build": "tsup",
35
- "test": "npm run build && node --test test/*.test.js",
36
35
  "prepublishOnly": "npm run build",
37
36
  "dev": "tsup --watch"
38
37
  },
@@ -75,7 +74,7 @@
75
74
  "esbuild-plugin-tsc": "^0.5.0",
76
75
  "reflect-metadata": "^0.2.2",
77
76
  "tsup": "^8.5.1",
78
- "typescript": "^6.0.2"
77
+ "typescript": "^5.9.3"
79
78
  },
80
79
  "dependencies": {
81
80
  "@nextera.one/axis-protocol": "^1.0.0",
@@ -1,10 +0,0 @@
1
- type Axis1FrameToEncode = {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- sig: Buffer;
7
- };
8
- declare function encodeAxis1Frame(f: Axis1FrameToEncode): Buffer;
9
-
10
- export { type Axis1FrameToEncode, encodeAxis1Frame };
@@ -1,10 +0,0 @@
1
- type Axis1FrameToEncode = {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- sig: Buffer;
7
- };
8
- declare function encodeAxis1Frame(f: Axis1FrameToEncode): Buffer;
9
-
10
- export { type Axis1FrameToEncode, encodeAxis1Frame };
@@ -1,65 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/codec/axis1.encode.ts
20
- var axis1_encode_exports = {};
21
- __export(axis1_encode_exports, {
22
- encodeAxis1Frame: () => encodeAxis1Frame
23
- });
24
- module.exports = __toCommonJS(axis1_encode_exports);
25
- var import_axis_protocol = require("@nextera.one/axis-protocol");
26
-
27
- // src/codec/tlv.encode.ts
28
- function encVarint(x) {
29
- if (x < 0n) throw new Error("VARINT_NEG");
30
- const out = [];
31
- while (x >= 0x80n) {
32
- out.push(Number(x & 0x7fn | 0x80n));
33
- x >>= 7n;
34
- }
35
- out.push(Number(x));
36
- return Buffer.from(out);
37
- }
38
-
39
- // src/codec/axis1.encode.ts
40
- var MAGIC = Buffer.from(import_axis_protocol.AXIS_MAGIC);
41
- function encodeAxis1Frame(f) {
42
- if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
43
- throw new Error("AXIS1_BAD_BUFFERS");
44
- }
45
- if (f.ver !== import_axis_protocol.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
46
- const hdrLen = encVarint(BigInt(f.hdr.length));
47
- const bodyLen = encVarint(BigInt(f.body.length));
48
- const sigLen = encVarint(BigInt(f.sig.length));
49
- return Buffer.concat([
50
- MAGIC,
51
- Buffer.from([f.ver & 255]),
52
- Buffer.from([f.flags & 255]),
53
- hdrLen,
54
- bodyLen,
55
- sigLen,
56
- f.hdr,
57
- f.body,
58
- f.sig
59
- ]);
60
- }
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
63
- encodeAxis1Frame
64
- });
65
- //# sourceMappingURL=axis1.encode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/codec/axis1.encode.ts","../../src/codec/tlv.encode.ts"],"sourcesContent":["// axis1.encode.ts\nimport { AXIS_MAGIC, AXIS_VERSION } from '@nextera.one/axis-protocol';\n\nimport { encVarint } from './tlv.encode';\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\nexport type Axis1FrameToEncode = {\n ver: number; // 1\n flags: number; // bit flags\n hdr: Buffer; // TLVs\n body: Buffer; // TLVs or raw payload\n sig: Buffer; // signature bytes\n};\n\nexport function encodeAxis1Frame(f: Axis1FrameToEncode): Buffer {\n if (\n !Buffer.isBuffer(f.hdr) ||\n !Buffer.isBuffer(f.body) ||\n !Buffer.isBuffer(f.sig)\n ) {\n throw new Error('AXIS1_BAD_BUFFERS');\n }\n if (f.ver !== AXIS_VERSION) throw new Error('AXIS1_BAD_VER');\n\n const hdrLen = encVarint(BigInt(f.hdr.length));\n const bodyLen = encVarint(BigInt(f.body.length));\n const sigLen = encVarint(BigInt(f.sig.length));\n\n return Buffer.concat([\n MAGIC,\n Buffer.from([f.ver & 0xff]),\n Buffer.from([f.flags & 0xff]),\n hdrLen,\n bodyLen,\n sigLen,\n f.hdr,\n f.body,\n f.sig,\n ]);\n}\n","// tlv.encode.ts\nimport { randomBytes } from 'crypto';\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('VARINT_NEG');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n\nexport function u64be(x: bigint): Buffer {\n if (x < 0n) throw new Error('U64_NEG');\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x, 0);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function bytes(b: Uint8Array | Buffer): Buffer {\n return Buffer.isBuffer(b) ? b : Buffer.from(b);\n}\n\nexport function nonce16(): Buffer {\n return randomBytes(16);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n if (!Number.isSafeInteger(type) || type < 0) throw new Error('TLV_BAD_TYPE');\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\n/**\n * Canonical TLV encoding:\n * - sorted by type ascending\n * - no duplicates by default\n */\nexport function buildTLVs(\n items: { type: number; value: Buffer }[],\n opts?: { allowDupTypes?: Set<number> },\n): Buffer {\n const allow = opts?.allowDupTypes ?? new Set<number>();\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAyC;;;ACElC,SAAS,UAAU,GAAmB;AAC3C,MAAI,IAAI,GAAI,OAAM,IAAI,MAAM,YAAY;AACxC,QAAM,MAAgB,CAAC;AACvB,SAAO,KAAK,OAAO;AACjB,QAAI,KAAK,OAAQ,IAAI,QAAS,KAAK,CAAC;AACpC,UAAM;AAAA,EACR;AACA,MAAI,KAAK,OAAO,CAAC,CAAC;AAClB,SAAO,OAAO,KAAK,GAAG;AACxB;;;ADPA,IAAM,QAAQ,OAAO,KAAK,+BAAU;AAU7B,SAAS,iBAAiB,GAA+B;AAC9D,MACE,CAAC,OAAO,SAAS,EAAE,GAAG,KACtB,CAAC,OAAO,SAAS,EAAE,IAAI,KACvB,CAAC,OAAO,SAAS,EAAE,GAAG,GACtB;AACA,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,EAAE,QAAQ,kCAAc,OAAM,IAAI,MAAM,eAAe;AAE3D,QAAM,SAAS,UAAU,OAAO,EAAE,IAAI,MAAM,CAAC;AAC7C,QAAM,UAAU,UAAU,OAAO,EAAE,KAAK,MAAM,CAAC;AAC/C,QAAM,SAAS,UAAU,OAAO,EAAE,IAAI,MAAM,CAAC;AAE7C,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,OAAO,KAAK,CAAC,EAAE,MAAM,GAAI,CAAC;AAAA,IAC1B,OAAO,KAAK,CAAC,EAAE,QAAQ,GAAI,CAAC;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA,EAAE;AAAA,IACF,EAAE;AAAA,IACF,EAAE;AAAA,EACJ,CAAC;AACH;","names":[]}
@@ -1,41 +0,0 @@
1
- // src/codec/axis1.encode.ts
2
- import { AXIS_MAGIC, AXIS_VERSION } from "@nextera.one/axis-protocol";
3
-
4
- // src/codec/tlv.encode.ts
5
- function encVarint(x) {
6
- if (x < 0n) throw new Error("VARINT_NEG");
7
- const out = [];
8
- while (x >= 0x80n) {
9
- out.push(Number(x & 0x7fn | 0x80n));
10
- x >>= 7n;
11
- }
12
- out.push(Number(x));
13
- return Buffer.from(out);
14
- }
15
-
16
- // src/codec/axis1.encode.ts
17
- var MAGIC = Buffer.from(AXIS_MAGIC);
18
- function encodeAxis1Frame(f) {
19
- if (!Buffer.isBuffer(f.hdr) || !Buffer.isBuffer(f.body) || !Buffer.isBuffer(f.sig)) {
20
- throw new Error("AXIS1_BAD_BUFFERS");
21
- }
22
- if (f.ver !== AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
23
- const hdrLen = encVarint(BigInt(f.hdr.length));
24
- const bodyLen = encVarint(BigInt(f.body.length));
25
- const sigLen = encVarint(BigInt(f.sig.length));
26
- return Buffer.concat([
27
- MAGIC,
28
- Buffer.from([f.ver & 255]),
29
- Buffer.from([f.flags & 255]),
30
- hdrLen,
31
- bodyLen,
32
- sigLen,
33
- f.hdr,
34
- f.body,
35
- f.sig
36
- ]);
37
- }
38
- export {
39
- encodeAxis1Frame
40
- };
41
- //# sourceMappingURL=axis1.encode.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/codec/axis1.encode.ts","../../src/codec/tlv.encode.ts"],"sourcesContent":["// axis1.encode.ts\nimport { AXIS_MAGIC, AXIS_VERSION } from '@nextera.one/axis-protocol';\n\nimport { encVarint } from './tlv.encode';\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\nexport type Axis1FrameToEncode = {\n ver: number; // 1\n flags: number; // bit flags\n hdr: Buffer; // TLVs\n body: Buffer; // TLVs or raw payload\n sig: Buffer; // signature bytes\n};\n\nexport function encodeAxis1Frame(f: Axis1FrameToEncode): Buffer {\n if (\n !Buffer.isBuffer(f.hdr) ||\n !Buffer.isBuffer(f.body) ||\n !Buffer.isBuffer(f.sig)\n ) {\n throw new Error('AXIS1_BAD_BUFFERS');\n }\n if (f.ver !== AXIS_VERSION) throw new Error('AXIS1_BAD_VER');\n\n const hdrLen = encVarint(BigInt(f.hdr.length));\n const bodyLen = encVarint(BigInt(f.body.length));\n const sigLen = encVarint(BigInt(f.sig.length));\n\n return Buffer.concat([\n MAGIC,\n Buffer.from([f.ver & 0xff]),\n Buffer.from([f.flags & 0xff]),\n hdrLen,\n bodyLen,\n sigLen,\n f.hdr,\n f.body,\n f.sig,\n ]);\n}\n","// tlv.encode.ts\nimport { randomBytes } from 'crypto';\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('VARINT_NEG');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n\nexport function u64be(x: bigint): Buffer {\n if (x < 0n) throw new Error('U64_NEG');\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x, 0);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function bytes(b: Uint8Array | Buffer): Buffer {\n return Buffer.isBuffer(b) ? b : Buffer.from(b);\n}\n\nexport function nonce16(): Buffer {\n return randomBytes(16);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n if (!Number.isSafeInteger(type) || type < 0) throw new Error('TLV_BAD_TYPE');\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\n/**\n * Canonical TLV encoding:\n * - sorted by type ascending\n * - no duplicates by default\n */\nexport function buildTLVs(\n items: { type: number; value: Buffer }[],\n opts?: { allowDupTypes?: Set<number> },\n): Buffer {\n const allow = opts?.allowDupTypes ?? new Set<number>();\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n"],"mappings":";AACA,SAAS,YAAY,oBAAoB;;;ACElC,SAAS,UAAU,GAAmB;AAC3C,MAAI,IAAI,GAAI,OAAM,IAAI,MAAM,YAAY;AACxC,QAAM,MAAgB,CAAC;AACvB,SAAO,KAAK,OAAO;AACjB,QAAI,KAAK,OAAQ,IAAI,QAAS,KAAK,CAAC;AACpC,UAAM;AAAA,EACR;AACA,MAAI,KAAK,OAAO,CAAC,CAAC;AAClB,SAAO,OAAO,KAAK,GAAG;AACxB;;;ADPA,IAAM,QAAQ,OAAO,KAAK,UAAU;AAU7B,SAAS,iBAAiB,GAA+B;AAC9D,MACE,CAAC,OAAO,SAAS,EAAE,GAAG,KACtB,CAAC,OAAO,SAAS,EAAE,IAAI,KACvB,CAAC,OAAO,SAAS,EAAE,GAAG,GACtB;AACA,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACA,MAAI,EAAE,QAAQ,aAAc,OAAM,IAAI,MAAM,eAAe;AAE3D,QAAM,SAAS,UAAU,OAAO,EAAE,IAAI,MAAM,CAAC;AAC7C,QAAM,UAAU,UAAU,OAAO,EAAE,KAAK,MAAM,CAAC;AAC/C,QAAM,SAAS,UAAU,OAAO,EAAE,IAAI,MAAM,CAAC;AAE7C,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,OAAO,KAAK,CAAC,EAAE,MAAM,GAAI,CAAC;AAAA,IAC1B,OAAO,KAAK,CAAC,EAAE,QAAQ,GAAI,CAAC;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA,EAAE;AAAA,IACF,EAAE;AAAA,IACF,EAAE;AAAA,EACJ,CAAC;AACH;","names":[]}
@@ -1,8 +0,0 @@
1
- declare function axis1SigningBytes(params: {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- }): Buffer;
7
-
8
- export { axis1SigningBytes };
@@ -1,8 +0,0 @@
1
- declare function axis1SigningBytes(params: {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- }): Buffer;
7
-
8
- export { axis1SigningBytes };
@@ -1,61 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/codec/axis1.signing.ts
20
- var axis1_signing_exports = {};
21
- __export(axis1_signing_exports, {
22
- axis1SigningBytes: () => axis1SigningBytes
23
- });
24
- module.exports = __toCommonJS(axis1_signing_exports);
25
- var import_axis_protocol = require("@nextera.one/axis-protocol");
26
-
27
- // src/codec/tlv.encode.ts
28
- function encVarint(x) {
29
- if (x < 0n) throw new Error("VARINT_NEG");
30
- const out = [];
31
- while (x >= 0x80n) {
32
- out.push(Number(x & 0x7fn | 0x80n));
33
- x >>= 7n;
34
- }
35
- out.push(Number(x));
36
- return Buffer.from(out);
37
- }
38
-
39
- // src/codec/axis1.signing.ts
40
- var MAGIC = Buffer.from(import_axis_protocol.AXIS_MAGIC);
41
- function axis1SigningBytes(params) {
42
- if (params.ver !== import_axis_protocol.AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
43
- const hdrLen = encVarint(BigInt(params.hdr.length));
44
- const bodyLen = encVarint(BigInt(params.body.length));
45
- const sigLenZero = encVarint(0n);
46
- return Buffer.concat([
47
- MAGIC,
48
- Buffer.from([params.ver & 255]),
49
- Buffer.from([params.flags & 255]),
50
- hdrLen,
51
- bodyLen,
52
- sigLenZero,
53
- params.hdr,
54
- params.body
55
- ]);
56
- }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- axis1SigningBytes
60
- });
61
- //# sourceMappingURL=axis1.signing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/codec/axis1.signing.ts","../../src/codec/tlv.encode.ts"],"sourcesContent":["// axis1.signing.ts\nimport { AXIS_MAGIC, AXIS_VERSION } from '@nextera.one/axis-protocol';\n\nimport { encVarint } from './tlv.encode';\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\nexport function axis1SigningBytes(params: {\n ver: number;\n flags: number;\n hdr: Buffer;\n body: Buffer;\n}): Buffer {\n if (params.ver !== AXIS_VERSION) throw new Error('AXIS1_BAD_VER');\n const hdrLen = encVarint(BigInt(params.hdr.length));\n const bodyLen = encVarint(BigInt(params.body.length));\n const sigLenZero = encVarint(0n); // IMPORTANT: sigLen=0 in signing bytes\n\n return Buffer.concat([\n MAGIC,\n Buffer.from([params.ver & 0xff]),\n Buffer.from([params.flags & 0xff]),\n hdrLen,\n bodyLen,\n sigLenZero,\n params.hdr,\n params.body,\n ]);\n}\n","// tlv.encode.ts\nimport { randomBytes } from 'crypto';\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('VARINT_NEG');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n\nexport function u64be(x: bigint): Buffer {\n if (x < 0n) throw new Error('U64_NEG');\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x, 0);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function bytes(b: Uint8Array | Buffer): Buffer {\n return Buffer.isBuffer(b) ? b : Buffer.from(b);\n}\n\nexport function nonce16(): Buffer {\n return randomBytes(16);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n if (!Number.isSafeInteger(type) || type < 0) throw new Error('TLV_BAD_TYPE');\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\n/**\n * Canonical TLV encoding:\n * - sorted by type ascending\n * - no duplicates by default\n */\nexport function buildTLVs(\n items: { type: number; value: Buffer }[],\n opts?: { allowDupTypes?: Set<number> },\n): Buffer {\n const allow = opts?.allowDupTypes ?? new Set<number>();\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAyC;;;ACElC,SAAS,UAAU,GAAmB;AAC3C,MAAI,IAAI,GAAI,OAAM,IAAI,MAAM,YAAY;AACxC,QAAM,MAAgB,CAAC;AACvB,SAAO,KAAK,OAAO;AACjB,QAAI,KAAK,OAAQ,IAAI,QAAS,KAAK,CAAC;AACpC,UAAM;AAAA,EACR;AACA,MAAI,KAAK,OAAO,CAAC,CAAC;AAClB,SAAO,OAAO,KAAK,GAAG;AACxB;;;ADPA,IAAM,QAAQ,OAAO,KAAK,+BAAU;AAE7B,SAAS,kBAAkB,QAKvB;AACT,MAAI,OAAO,QAAQ,kCAAc,OAAM,IAAI,MAAM,eAAe;AAChE,QAAM,SAAS,UAAU,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,QAAM,UAAU,UAAU,OAAO,OAAO,KAAK,MAAM,CAAC;AACpD,QAAM,aAAa,UAAU,EAAE;AAE/B,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,OAAO,KAAK,CAAC,OAAO,MAAM,GAAI,CAAC;AAAA,IAC/B,OAAO,KAAK,CAAC,OAAO,QAAQ,GAAI,CAAC;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -1,37 +0,0 @@
1
- // src/codec/axis1.signing.ts
2
- import { AXIS_MAGIC, AXIS_VERSION } from "@nextera.one/axis-protocol";
3
-
4
- // src/codec/tlv.encode.ts
5
- function encVarint(x) {
6
- if (x < 0n) throw new Error("VARINT_NEG");
7
- const out = [];
8
- while (x >= 0x80n) {
9
- out.push(Number(x & 0x7fn | 0x80n));
10
- x >>= 7n;
11
- }
12
- out.push(Number(x));
13
- return Buffer.from(out);
14
- }
15
-
16
- // src/codec/axis1.signing.ts
17
- var MAGIC = Buffer.from(AXIS_MAGIC);
18
- function axis1SigningBytes(params) {
19
- if (params.ver !== AXIS_VERSION) throw new Error("AXIS1_BAD_VER");
20
- const hdrLen = encVarint(BigInt(params.hdr.length));
21
- const bodyLen = encVarint(BigInt(params.body.length));
22
- const sigLenZero = encVarint(0n);
23
- return Buffer.concat([
24
- MAGIC,
25
- Buffer.from([params.ver & 255]),
26
- Buffer.from([params.flags & 255]),
27
- hdrLen,
28
- bodyLen,
29
- sigLenZero,
30
- params.hdr,
31
- params.body
32
- ]);
33
- }
34
- export {
35
- axis1SigningBytes
36
- };
37
- //# sourceMappingURL=axis1.signing.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/codec/axis1.signing.ts","../../src/codec/tlv.encode.ts"],"sourcesContent":["// axis1.signing.ts\nimport { AXIS_MAGIC, AXIS_VERSION } from '@nextera.one/axis-protocol';\n\nimport { encVarint } from './tlv.encode';\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\nexport function axis1SigningBytes(params: {\n ver: number;\n flags: number;\n hdr: Buffer;\n body: Buffer;\n}): Buffer {\n if (params.ver !== AXIS_VERSION) throw new Error('AXIS1_BAD_VER');\n const hdrLen = encVarint(BigInt(params.hdr.length));\n const bodyLen = encVarint(BigInt(params.body.length));\n const sigLenZero = encVarint(0n); // IMPORTANT: sigLen=0 in signing bytes\n\n return Buffer.concat([\n MAGIC,\n Buffer.from([params.ver & 0xff]),\n Buffer.from([params.flags & 0xff]),\n hdrLen,\n bodyLen,\n sigLenZero,\n params.hdr,\n params.body,\n ]);\n}\n","// tlv.encode.ts\nimport { randomBytes } from 'crypto';\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('VARINT_NEG');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n\nexport function u64be(x: bigint): Buffer {\n if (x < 0n) throw new Error('U64_NEG');\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x, 0);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function bytes(b: Uint8Array | Buffer): Buffer {\n return Buffer.isBuffer(b) ? b : Buffer.from(b);\n}\n\nexport function nonce16(): Buffer {\n return randomBytes(16);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n if (!Number.isSafeInteger(type) || type < 0) throw new Error('TLV_BAD_TYPE');\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\n/**\n * Canonical TLV encoding:\n * - sorted by type ascending\n * - no duplicates by default\n */\nexport function buildTLVs(\n items: { type: number; value: Buffer }[],\n opts?: { allowDupTypes?: Set<number> },\n): Buffer {\n const allow = opts?.allowDupTypes ?? new Set<number>();\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type && !allow.has(sorted[i].type)) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n"],"mappings":";AACA,SAAS,YAAY,oBAAoB;;;ACElC,SAAS,UAAU,GAAmB;AAC3C,MAAI,IAAI,GAAI,OAAM,IAAI,MAAM,YAAY;AACxC,QAAM,MAAgB,CAAC;AACvB,SAAO,KAAK,OAAO;AACjB,QAAI,KAAK,OAAQ,IAAI,QAAS,KAAK,CAAC;AACpC,UAAM;AAAA,EACR;AACA,MAAI,KAAK,OAAO,CAAC,CAAC;AAClB,SAAO,OAAO,KAAK,GAAG;AACxB;;;ADPA,IAAM,QAAQ,OAAO,KAAK,UAAU;AAE7B,SAAS,kBAAkB,QAKvB;AACT,MAAI,OAAO,QAAQ,aAAc,OAAM,IAAI,MAAM,eAAe;AAChE,QAAM,SAAS,UAAU,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,QAAM,UAAU,UAAU,OAAO,OAAO,KAAK,MAAM,CAAC;AACpD,QAAM,aAAa,UAAU,EAAE;AAE/B,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,OAAO,KAAK,CAAC,OAAO,MAAM,GAAI,CAAC;AAAA,IAC/B,OAAO,KAAK,CAAC,OAAO,QAAQ,GAAI,CAAC;AAAA,IACjC;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,OAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -1,51 +0,0 @@
1
- import * as _nextera_one_axis_protocol from '@nextera.one/axis-protocol';
2
- import { AxisFrame } from '@nextera.one/axis-protocol';
3
- import * as z from 'zod';
4
-
5
- function _mergeNamespaces(n, m) {
6
- m.forEach(function (e) {
7
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
8
- if (k !== 'default' && !(k in n)) {
9
- var d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: function () { return e[k]; }
13
- });
14
- }
15
- });
16
- });
17
- return Object.freeze(n);
18
- }
19
-
20
- declare const AxisFrameZ: z.ZodType<AxisFrame>;
21
-
22
- declare function computeSignaturePayload(frame: AxisFrame): Buffer;
23
- declare function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer;
24
- declare function verifyFrameSignature(frame: AxisFrame, publicKey: Buffer): boolean;
25
- declare function generateEd25519KeyPair(): {
26
- privateKey: Buffer;
27
- publicKey: Buffer;
28
- };
29
- declare function sha256(data: Buffer | Uint8Array): Buffer;
30
- declare function computeReceiptHash(receiptBytes: Buffer | Uint8Array, prevHash?: Buffer | Uint8Array): Buffer;
31
-
32
- declare class AxisError extends Error {
33
- code: string;
34
- httpStatus: number;
35
- details?: Record<string, any> | undefined;
36
- constructor(code: string, message: string, httpStatus?: number, details?: Record<string, any> | undefined);
37
- }
38
-
39
- var index = /*#__PURE__*/_mergeNamespaces({
40
- __proto__: null,
41
- AxisError: AxisError,
42
- AxisFrameZ: AxisFrameZ,
43
- computeReceiptHash: computeReceiptHash,
44
- computeSignaturePayload: computeSignaturePayload,
45
- generateEd25519KeyPair: generateEd25519KeyPair,
46
- sha256: sha256,
47
- signFrame: signFrame,
48
- verifyFrameSignature: verifyFrameSignature
49
- }, [_nextera_one_axis_protocol]);
50
-
51
- export { AxisError as A, AxisFrameZ as a, computeSignaturePayload as b, computeReceiptHash as c, signFrame as d, generateEd25519KeyPair as g, index as i, sha256 as s, verifyFrameSignature as v };
@@ -1,51 +0,0 @@
1
- import * as _nextera_one_axis_protocol from '@nextera.one/axis-protocol';
2
- import { AxisFrame } from '@nextera.one/axis-protocol';
3
- import * as z from 'zod';
4
-
5
- function _mergeNamespaces(n, m) {
6
- m.forEach(function (e) {
7
- e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
8
- if (k !== 'default' && !(k in n)) {
9
- var d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: function () { return e[k]; }
13
- });
14
- }
15
- });
16
- });
17
- return Object.freeze(n);
18
- }
19
-
20
- declare const AxisFrameZ: z.ZodType<AxisFrame>;
21
-
22
- declare function computeSignaturePayload(frame: AxisFrame): Buffer;
23
- declare function signFrame(frame: AxisFrame, privateKey: Buffer): Buffer;
24
- declare function verifyFrameSignature(frame: AxisFrame, publicKey: Buffer): boolean;
25
- declare function generateEd25519KeyPair(): {
26
- privateKey: Buffer;
27
- publicKey: Buffer;
28
- };
29
- declare function sha256(data: Buffer | Uint8Array): Buffer;
30
- declare function computeReceiptHash(receiptBytes: Buffer | Uint8Array, prevHash?: Buffer | Uint8Array): Buffer;
31
-
32
- declare class AxisError extends Error {
33
- code: string;
34
- httpStatus: number;
35
- details?: Record<string, any> | undefined;
36
- constructor(code: string, message: string, httpStatus?: number, details?: Record<string, any> | undefined);
37
- }
38
-
39
- var index = /*#__PURE__*/_mergeNamespaces({
40
- __proto__: null,
41
- AxisError: AxisError,
42
- AxisFrameZ: AxisFrameZ,
43
- computeReceiptHash: computeReceiptHash,
44
- computeSignaturePayload: computeSignaturePayload,
45
- generateEd25519KeyPair: generateEd25519KeyPair,
46
- sha256: sha256,
47
- signFrame: signFrame,
48
- verifyFrameSignature: verifyFrameSignature
49
- }, [_nextera_one_axis_protocol]);
50
-
51
- export { AxisError as A, AxisFrameZ as a, computeSignaturePayload as b, computeReceiptHash as c, signFrame as d, generateEd25519KeyPair as g, index as i, sha256 as s, verifyFrameSignature as v };
@@ -1,11 +0,0 @@
1
- type Axis1DecodedFrame = {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- sig: Buffer;
7
- frameSize: number;
8
- };
9
- declare function decodeAxis1Frame(buf: Buffer): Axis1DecodedFrame;
10
-
11
- export { type Axis1DecodedFrame, decodeAxis1Frame };
@@ -1,11 +0,0 @@
1
- type Axis1DecodedFrame = {
2
- ver: number;
3
- flags: number;
4
- hdr: Buffer;
5
- body: Buffer;
6
- sig: Buffer;
7
- frameSize: number;
8
- };
9
- declare function decodeAxis1Frame(buf: Buffer): Axis1DecodedFrame;
10
-
11
- export { type Axis1DecodedFrame, decodeAxis1Frame };
@@ -1,78 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/types/frame.ts
20
- var frame_exports = {};
21
- __export(frame_exports, {
22
- decodeAxis1Frame: () => decodeAxis1Frame
23
- });
24
- module.exports = __toCommonJS(frame_exports);
25
- var import_axis_protocol = require("@nextera.one/axis-protocol");
26
-
27
- // src/types/tlv.ts
28
- function decVarint(buf, off) {
29
- let shift = 0n;
30
- let x = 0n;
31
- while (true) {
32
- if (off >= buf.length) throw new Error("varint overflow");
33
- const b = BigInt(buf[off++]);
34
- x |= (b & 0x7fn) << shift;
35
- if ((b & 0x80n) === 0n) break;
36
- shift += 7n;
37
- if (shift > 63n) throw new Error("varint too large");
38
- }
39
- return { val: x, off };
40
- }
41
-
42
- // src/types/frame.ts
43
- var MAGIC = Buffer.from(import_axis_protocol.AXIS_MAGIC);
44
- function decodeAxis1Frame(buf) {
45
- let off = 0;
46
- const magic = buf.subarray(off, off + 5);
47
- off += 5;
48
- if (magic.length !== 5 || !magic.equals(MAGIC))
49
- throw new Error("AXIS1_BAD_MAGIC");
50
- if (off + 2 > buf.length) throw new Error("AXIS1_TRUNCATED");
51
- const ver = buf[off++];
52
- const flags = buf[off++];
53
- const h1 = decVarint(buf, off);
54
- off = h1.off;
55
- const b1 = decVarint(buf, off);
56
- off = b1.off;
57
- const s1 = decVarint(buf, off);
58
- off = s1.off;
59
- const hdrLen = Number(h1.val);
60
- const bodyLen = Number(b1.val);
61
- const sigLen = Number(s1.val);
62
- if (hdrLen < 0 || bodyLen < 0 || sigLen < 0) throw new Error("AXIS1_LEN_NEG");
63
- if (off + hdrLen + bodyLen + sigLen > buf.length)
64
- throw new Error("AXIS1_TRUNCATED_PAYLOAD");
65
- const hdr = buf.subarray(off, off + hdrLen);
66
- off += hdrLen;
67
- const body = buf.subarray(off, off + bodyLen);
68
- off += bodyLen;
69
- const sig = buf.subarray(off, off + sigLen);
70
- off += sigLen;
71
- if (off !== buf.length) throw new Error("AXIS1_TRAILING_BYTES");
72
- return { ver, flags, hdr, body, sig, frameSize: buf.length };
73
- }
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- decodeAxis1Frame
77
- });
78
- //# sourceMappingURL=frame.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/frame.ts","../../src/types/tlv.ts"],"sourcesContent":["import { AXIS_MAGIC } from '@nextera.one/axis-protocol';\n\nimport { decVarint } from './tlv';\n\n/**\n * Axis1DecodedFrame\n *\n * Represents a parsed AXIS v1 binary frame.\n *\n * @typedef {Object} Axis1DecodedFrame\n */\nexport type Axis1DecodedFrame = {\n /** Protocol version (should be 1) */\n ver: number;\n /** Frame flags for protocol extensions */\n flags: number;\n /** Raw header bytes (containing primary TLVs) */\n hdr: Buffer;\n /** Raw body bytes (the main payload) */\n body: Buffer;\n /** Cryptographic signature bytes */\n sig: Buffer;\n /** Total original size of the frame in bytes */\n frameSize: number;\n};\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\n/**\n * Decodes a raw binary buffer into a structured Axis1DecodedFrame.\n * Implements the AXIS v1 wire format specification.\n *\n * **Binary Structure (canonical):**\n * 1. Magic: 'AXIS1' (5 bytes)\n * 2. Version: (1 byte)\n * 3. Flags: (1 byte)\n * 4. HDR_LEN: Varint\n * 5. BODY_LEN: Varint\n * 6. SIG_LEN: Varint\n * 7. HDR: (HDR_LEN bytes)\n * 8. BODY: (BODY_LEN bytes)\n * 9. SIG: (SIG_LEN bytes)\n *\n * @param {Buffer} buf - Raw bytes from the wire\n * @returns {Axis1DecodedFrame} Parsed frame object\n * @throws {Error} If magic is invalid, frame is truncated, or lengths are inconsistent\n */\nexport function decodeAxis1Frame(buf: Buffer): Axis1DecodedFrame {\n let off = 0;\n\n const magic = buf.subarray(off, off + 5);\n off += 5;\n if (magic.length !== 5 || !magic.equals(MAGIC))\n throw new Error('AXIS1_BAD_MAGIC');\n\n if (off + 2 > buf.length) throw new Error('AXIS1_TRUNCATED');\n const ver = buf[off++];\n const flags = buf[off++];\n\n // Read all three lengths first (canonical order: hdrLen, bodyLen, sigLen)\n const h1 = decVarint(buf, off);\n off = h1.off;\n const b1 = decVarint(buf, off);\n off = b1.off;\n const s1 = decVarint(buf, off);\n off = s1.off;\n\n const hdrLen = Number(h1.val);\n const bodyLen = Number(b1.val);\n const sigLen = Number(s1.val);\n\n if (hdrLen < 0 || bodyLen < 0 || sigLen < 0) throw new Error('AXIS1_LEN_NEG');\n\n if (off + hdrLen + bodyLen + sigLen > buf.length)\n throw new Error('AXIS1_TRUNCATED_PAYLOAD');\n\n // Then read payloads in order: HDR, BODY, SIG\n const hdr = buf.subarray(off, off + hdrLen);\n off += hdrLen;\n const body = buf.subarray(off, off + bodyLen);\n off += bodyLen;\n const sig = buf.subarray(off, off + sigLen);\n off += sigLen;\n\n if (off !== buf.length) throw new Error('AXIS1_TRAILING_BYTES');\n\n return { ver, flags, hdr, body, sig, frameSize: buf.length };\n}\n","/**\n * Decodes a variable-length integer (Varint) from a buffer.\n * Supports up to 64-bit integers.\n *\n * @param {Buffer} buf - The buffer to read from\n * @param {number} off - The offset to start reading from\n * @returns {Object} The decoded bigint value and the new offset\n * @throws {Error} If the varint is malformed or exceeds 64 bits\n */\nexport function decVarint(\n buf: Buffer,\n off: number,\n): { val: bigint; off: number } {\n let shift = 0n;\n let x = 0n;\n while (true) {\n if (off >= buf.length) throw new Error('varint overflow');\n const b = BigInt(buf[off++]);\n x |= (b & 0x7fn) << shift;\n if ((b & 0x80n) === 0n) break;\n shift += 7n;\n if (shift > 63n) throw new Error('varint too large');\n }\n return { val: x, off };\n}\n\nimport type { TLV } from '../core/tlv';\n\n/**\n * Parses a buffer into an array of TLV objects.\n *\n * @param {Buffer} buf - The buffer containing TLV-encoded data\n * @param {number} [maxItems=512] - Security limit for the number of TLVs to parse\n * @returns {TLV[]} An array of parsed TLVs\n * @throws {Error} If TLV structure is invalid or limits are exceeded\n */\nexport function parseTLVs(buf: Buffer, maxItems: number = 512): TLV[] {\n const out: TLV[] = [];\n let off = 0;\n while (off < buf.length) {\n if (out.length >= maxItems) throw new Error('TLV_TOO_MANY_ITEMS');\n const t1 = decVarint(buf, off);\n off = t1.off;\n const t2 = decVarint(buf, off);\n off = t2.off;\n const type = Number(t1.val);\n const len = Number(t2.val);\n if (len < 0 || off + len > buf.length) {\n throw new Error('TLV_LEN_INVALID');\n }\n const value = buf.subarray(off, off + len);\n off += len;\n out.push({ type, value });\n }\n return out;\n}\n\n/**\n * Parses TLVs and organizes them into a Map for efficient access.\n * Multiple values for the same type are preserved in an array.\n *\n * @param {Buffer} buf - The raw TLV-encoded buffer\n * @returns {Map<number, Buffer[]>} A map of Tag -> [Values]\n */\nexport function tlvMap(buf: Buffer): Map<number, Buffer[]> {\n const m = new Map<number, Buffer[]>();\n for (const it of parseTLVs(buf)) {\n const arr = m.get(it.type) ?? [];\n arr.push(it.value as Buffer);\n m.set(it.type, arr);\n }\n return m;\n}\n\nexport function asUtf8(b?: Buffer): string | undefined {\n if (!b) return undefined;\n return b.toString('utf8');\n}\n\nexport function asBigintVarint(b?: Buffer): bigint | undefined {\n if (!b) return undefined;\n const { val, off } = decVarint(b, 0);\n if (off !== b.length) throw new Error('VARINT_TRAILING_BYTES');\n return val;\n}\n\n/**\n * Parses an 8-byte big-endian buffer as a BigInt.\n * Used for timestamps which are sent as fixed 8-byte u64.\n */\nexport function asBigint64BE(b?: Buffer): bigint | undefined {\n if (!b) return undefined;\n if (b.length !== 8) throw new Error('Expected 8 bytes for u64');\n return b.readBigUInt64BE(0);\n}\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('varint neg');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\nexport function buildTLVs(items: { type: number; value: Buffer }[]): Buffer {\n // Canonical: sort by type ascending\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n // Canonical: forbid duplicate tags by default\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n\nexport function u64be(x: bigint): Buffer {\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA2B;;;ACSpB,SAAS,UACd,KACA,KAC8B;AAC9B,MAAI,QAAQ;AACZ,MAAI,IAAI;AACR,SAAO,MAAM;AACX,QAAI,OAAO,IAAI,OAAQ,OAAM,IAAI,MAAM,iBAAiB;AACxD,UAAM,IAAI,OAAO,IAAI,KAAK,CAAC;AAC3B,UAAM,IAAI,UAAU;AACpB,SAAK,IAAI,WAAW,GAAI;AACxB,aAAS;AACT,QAAI,QAAQ,IAAK,OAAM,IAAI,MAAM,kBAAkB;AAAA,EACrD;AACA,SAAO,EAAE,KAAK,GAAG,IAAI;AACvB;;;ADEA,IAAM,QAAQ,OAAO,KAAK,+BAAU;AAqB7B,SAAS,iBAAiB,KAAgC;AAC/D,MAAI,MAAM;AAEV,QAAM,QAAQ,IAAI,SAAS,KAAK,MAAM,CAAC;AACvC,SAAO;AACP,MAAI,MAAM,WAAW,KAAK,CAAC,MAAM,OAAO,KAAK;AAC3C,UAAM,IAAI,MAAM,iBAAiB;AAEnC,MAAI,MAAM,IAAI,IAAI,OAAQ,OAAM,IAAI,MAAM,iBAAiB;AAC3D,QAAM,MAAM,IAAI,KAAK;AACrB,QAAM,QAAQ,IAAI,KAAK;AAGvB,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AACT,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AACT,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AAET,QAAM,SAAS,OAAO,GAAG,GAAG;AAC5B,QAAM,UAAU,OAAO,GAAG,GAAG;AAC7B,QAAM,SAAS,OAAO,GAAG,GAAG;AAE5B,MAAI,SAAS,KAAK,UAAU,KAAK,SAAS,EAAG,OAAM,IAAI,MAAM,eAAe;AAE5E,MAAI,MAAM,SAAS,UAAU,SAAS,IAAI;AACxC,UAAM,IAAI,MAAM,yBAAyB;AAG3C,QAAM,MAAM,IAAI,SAAS,KAAK,MAAM,MAAM;AAC1C,SAAO;AACP,QAAM,OAAO,IAAI,SAAS,KAAK,MAAM,OAAO;AAC5C,SAAO;AACP,QAAM,MAAM,IAAI,SAAS,KAAK,MAAM,MAAM;AAC1C,SAAO;AAEP,MAAI,QAAQ,IAAI,OAAQ,OAAM,IAAI,MAAM,sBAAsB;AAE9D,SAAO,EAAE,KAAK,OAAO,KAAK,MAAM,KAAK,WAAW,IAAI,OAAO;AAC7D;","names":[]}
@@ -1,54 +0,0 @@
1
- // src/types/frame.ts
2
- import { AXIS_MAGIC } from "@nextera.one/axis-protocol";
3
-
4
- // src/types/tlv.ts
5
- function decVarint(buf, off) {
6
- let shift = 0n;
7
- let x = 0n;
8
- while (true) {
9
- if (off >= buf.length) throw new Error("varint overflow");
10
- const b = BigInt(buf[off++]);
11
- x |= (b & 0x7fn) << shift;
12
- if ((b & 0x80n) === 0n) break;
13
- shift += 7n;
14
- if (shift > 63n) throw new Error("varint too large");
15
- }
16
- return { val: x, off };
17
- }
18
-
19
- // src/types/frame.ts
20
- var MAGIC = Buffer.from(AXIS_MAGIC);
21
- function decodeAxis1Frame(buf) {
22
- let off = 0;
23
- const magic = buf.subarray(off, off + 5);
24
- off += 5;
25
- if (magic.length !== 5 || !magic.equals(MAGIC))
26
- throw new Error("AXIS1_BAD_MAGIC");
27
- if (off + 2 > buf.length) throw new Error("AXIS1_TRUNCATED");
28
- const ver = buf[off++];
29
- const flags = buf[off++];
30
- const h1 = decVarint(buf, off);
31
- off = h1.off;
32
- const b1 = decVarint(buf, off);
33
- off = b1.off;
34
- const s1 = decVarint(buf, off);
35
- off = s1.off;
36
- const hdrLen = Number(h1.val);
37
- const bodyLen = Number(b1.val);
38
- const sigLen = Number(s1.val);
39
- if (hdrLen < 0 || bodyLen < 0 || sigLen < 0) throw new Error("AXIS1_LEN_NEG");
40
- if (off + hdrLen + bodyLen + sigLen > buf.length)
41
- throw new Error("AXIS1_TRUNCATED_PAYLOAD");
42
- const hdr = buf.subarray(off, off + hdrLen);
43
- off += hdrLen;
44
- const body = buf.subarray(off, off + bodyLen);
45
- off += bodyLen;
46
- const sig = buf.subarray(off, off + sigLen);
47
- off += sigLen;
48
- if (off !== buf.length) throw new Error("AXIS1_TRAILING_BYTES");
49
- return { ver, flags, hdr, body, sig, frameSize: buf.length };
50
- }
51
- export {
52
- decodeAxis1Frame
53
- };
54
- //# sourceMappingURL=frame.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types/frame.ts","../../src/types/tlv.ts"],"sourcesContent":["import { AXIS_MAGIC } from '@nextera.one/axis-protocol';\n\nimport { decVarint } from './tlv';\n\n/**\n * Axis1DecodedFrame\n *\n * Represents a parsed AXIS v1 binary frame.\n *\n * @typedef {Object} Axis1DecodedFrame\n */\nexport type Axis1DecodedFrame = {\n /** Protocol version (should be 1) */\n ver: number;\n /** Frame flags for protocol extensions */\n flags: number;\n /** Raw header bytes (containing primary TLVs) */\n hdr: Buffer;\n /** Raw body bytes (the main payload) */\n body: Buffer;\n /** Cryptographic signature bytes */\n sig: Buffer;\n /** Total original size of the frame in bytes */\n frameSize: number;\n};\n\nconst MAGIC = Buffer.from(AXIS_MAGIC);\n\n/**\n * Decodes a raw binary buffer into a structured Axis1DecodedFrame.\n * Implements the AXIS v1 wire format specification.\n *\n * **Binary Structure (canonical):**\n * 1. Magic: 'AXIS1' (5 bytes)\n * 2. Version: (1 byte)\n * 3. Flags: (1 byte)\n * 4. HDR_LEN: Varint\n * 5. BODY_LEN: Varint\n * 6. SIG_LEN: Varint\n * 7. HDR: (HDR_LEN bytes)\n * 8. BODY: (BODY_LEN bytes)\n * 9. SIG: (SIG_LEN bytes)\n *\n * @param {Buffer} buf - Raw bytes from the wire\n * @returns {Axis1DecodedFrame} Parsed frame object\n * @throws {Error} If magic is invalid, frame is truncated, or lengths are inconsistent\n */\nexport function decodeAxis1Frame(buf: Buffer): Axis1DecodedFrame {\n let off = 0;\n\n const magic = buf.subarray(off, off + 5);\n off += 5;\n if (magic.length !== 5 || !magic.equals(MAGIC))\n throw new Error('AXIS1_BAD_MAGIC');\n\n if (off + 2 > buf.length) throw new Error('AXIS1_TRUNCATED');\n const ver = buf[off++];\n const flags = buf[off++];\n\n // Read all three lengths first (canonical order: hdrLen, bodyLen, sigLen)\n const h1 = decVarint(buf, off);\n off = h1.off;\n const b1 = decVarint(buf, off);\n off = b1.off;\n const s1 = decVarint(buf, off);\n off = s1.off;\n\n const hdrLen = Number(h1.val);\n const bodyLen = Number(b1.val);\n const sigLen = Number(s1.val);\n\n if (hdrLen < 0 || bodyLen < 0 || sigLen < 0) throw new Error('AXIS1_LEN_NEG');\n\n if (off + hdrLen + bodyLen + sigLen > buf.length)\n throw new Error('AXIS1_TRUNCATED_PAYLOAD');\n\n // Then read payloads in order: HDR, BODY, SIG\n const hdr = buf.subarray(off, off + hdrLen);\n off += hdrLen;\n const body = buf.subarray(off, off + bodyLen);\n off += bodyLen;\n const sig = buf.subarray(off, off + sigLen);\n off += sigLen;\n\n if (off !== buf.length) throw new Error('AXIS1_TRAILING_BYTES');\n\n return { ver, flags, hdr, body, sig, frameSize: buf.length };\n}\n","/**\n * Decodes a variable-length integer (Varint) from a buffer.\n * Supports up to 64-bit integers.\n *\n * @param {Buffer} buf - The buffer to read from\n * @param {number} off - The offset to start reading from\n * @returns {Object} The decoded bigint value and the new offset\n * @throws {Error} If the varint is malformed or exceeds 64 bits\n */\nexport function decVarint(\n buf: Buffer,\n off: number,\n): { val: bigint; off: number } {\n let shift = 0n;\n let x = 0n;\n while (true) {\n if (off >= buf.length) throw new Error('varint overflow');\n const b = BigInt(buf[off++]);\n x |= (b & 0x7fn) << shift;\n if ((b & 0x80n) === 0n) break;\n shift += 7n;\n if (shift > 63n) throw new Error('varint too large');\n }\n return { val: x, off };\n}\n\nimport type { TLV } from '../core/tlv';\n\n/**\n * Parses a buffer into an array of TLV objects.\n *\n * @param {Buffer} buf - The buffer containing TLV-encoded data\n * @param {number} [maxItems=512] - Security limit for the number of TLVs to parse\n * @returns {TLV[]} An array of parsed TLVs\n * @throws {Error} If TLV structure is invalid or limits are exceeded\n */\nexport function parseTLVs(buf: Buffer, maxItems: number = 512): TLV[] {\n const out: TLV[] = [];\n let off = 0;\n while (off < buf.length) {\n if (out.length >= maxItems) throw new Error('TLV_TOO_MANY_ITEMS');\n const t1 = decVarint(buf, off);\n off = t1.off;\n const t2 = decVarint(buf, off);\n off = t2.off;\n const type = Number(t1.val);\n const len = Number(t2.val);\n if (len < 0 || off + len > buf.length) {\n throw new Error('TLV_LEN_INVALID');\n }\n const value = buf.subarray(off, off + len);\n off += len;\n out.push({ type, value });\n }\n return out;\n}\n\n/**\n * Parses TLVs and organizes them into a Map for efficient access.\n * Multiple values for the same type are preserved in an array.\n *\n * @param {Buffer} buf - The raw TLV-encoded buffer\n * @returns {Map<number, Buffer[]>} A map of Tag -> [Values]\n */\nexport function tlvMap(buf: Buffer): Map<number, Buffer[]> {\n const m = new Map<number, Buffer[]>();\n for (const it of parseTLVs(buf)) {\n const arr = m.get(it.type) ?? [];\n arr.push(it.value as Buffer);\n m.set(it.type, arr);\n }\n return m;\n}\n\nexport function asUtf8(b?: Buffer): string | undefined {\n if (!b) return undefined;\n return b.toString('utf8');\n}\n\nexport function asBigintVarint(b?: Buffer): bigint | undefined {\n if (!b) return undefined;\n const { val, off } = decVarint(b, 0);\n if (off !== b.length) throw new Error('VARINT_TRAILING_BYTES');\n return val;\n}\n\n/**\n * Parses an 8-byte big-endian buffer as a BigInt.\n * Used for timestamps which are sent as fixed 8-byte u64.\n */\nexport function asBigint64BE(b?: Buffer): bigint | undefined {\n if (!b) return undefined;\n if (b.length !== 8) throw new Error('Expected 8 bytes for u64');\n return b.readBigUInt64BE(0);\n}\n\nexport function encVarint(x: bigint): Buffer {\n if (x < 0n) throw new Error('varint neg');\n const out: number[] = [];\n while (x >= 0x80n) {\n out.push(Number((x & 0x7fn) | 0x80n));\n x >>= 7n;\n }\n out.push(Number(x));\n return Buffer.from(out);\n}\n\nexport function tlv(type: number, value: Buffer): Buffer {\n return Buffer.concat([\n encVarint(BigInt(type)),\n encVarint(BigInt(value.length)),\n value,\n ]);\n}\n\nexport function buildTLVs(items: { type: number; value: Buffer }[]): Buffer {\n // Canonical: sort by type ascending\n const sorted = [...items].sort((a, b) => a.type - b.type);\n\n // Canonical: forbid duplicate tags by default\n for (let i = 1; i < sorted.length; i++) {\n if (sorted[i].type === sorted[i - 1].type) {\n throw new Error(`TLV_DUP_TYPE_${sorted[i].type}`);\n }\n }\n\n return Buffer.concat(sorted.map((it) => tlv(it.type, it.value)));\n}\n\nexport function u64be(x: bigint): Buffer {\n const b = Buffer.alloc(8);\n b.writeBigUInt64BE(x);\n return b;\n}\n\nexport function utf8(s: string): Buffer {\n return Buffer.from(s, 'utf8');\n}\n\nexport function varintU(x: number | bigint): Buffer {\n const v = typeof x === 'number' ? BigInt(x) : x;\n return encVarint(v);\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;;;ACSpB,SAAS,UACd,KACA,KAC8B;AAC9B,MAAI,QAAQ;AACZ,MAAI,IAAI;AACR,SAAO,MAAM;AACX,QAAI,OAAO,IAAI,OAAQ,OAAM,IAAI,MAAM,iBAAiB;AACxD,UAAM,IAAI,OAAO,IAAI,KAAK,CAAC;AAC3B,UAAM,IAAI,UAAU;AACpB,SAAK,IAAI,WAAW,GAAI;AACxB,aAAS;AACT,QAAI,QAAQ,IAAK,OAAM,IAAI,MAAM,kBAAkB;AAAA,EACrD;AACA,SAAO,EAAE,KAAK,GAAG,IAAI;AACvB;;;ADEA,IAAM,QAAQ,OAAO,KAAK,UAAU;AAqB7B,SAAS,iBAAiB,KAAgC;AAC/D,MAAI,MAAM;AAEV,QAAM,QAAQ,IAAI,SAAS,KAAK,MAAM,CAAC;AACvC,SAAO;AACP,MAAI,MAAM,WAAW,KAAK,CAAC,MAAM,OAAO,KAAK;AAC3C,UAAM,IAAI,MAAM,iBAAiB;AAEnC,MAAI,MAAM,IAAI,IAAI,OAAQ,OAAM,IAAI,MAAM,iBAAiB;AAC3D,QAAM,MAAM,IAAI,KAAK;AACrB,QAAM,QAAQ,IAAI,KAAK;AAGvB,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AACT,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AACT,QAAM,KAAK,UAAU,KAAK,GAAG;AAC7B,QAAM,GAAG;AAET,QAAM,SAAS,OAAO,GAAG,GAAG;AAC5B,QAAM,UAAU,OAAO,GAAG,GAAG;AAC7B,QAAM,SAAS,OAAO,GAAG,GAAG;AAE5B,MAAI,SAAS,KAAK,UAAU,KAAK,SAAS,EAAG,OAAM,IAAI,MAAM,eAAe;AAE5E,MAAI,MAAM,SAAS,UAAU,SAAS,IAAI;AACxC,UAAM,IAAI,MAAM,yBAAyB;AAG3C,QAAM,MAAM,IAAI,SAAS,KAAK,MAAM,MAAM;AAC1C,SAAO;AACP,QAAM,OAAO,IAAI,SAAS,KAAK,MAAM,OAAO;AAC5C,SAAO;AACP,QAAM,MAAM,IAAI,SAAS,KAAK,MAAM,MAAM;AAC1C,SAAO;AAEP,MAAI,QAAQ,IAAI,OAAQ,OAAM,IAAI,MAAM,sBAAsB;AAE9D,SAAO,EAAE,KAAK,OAAO,KAAK,MAAM,KAAK,WAAW,IAAI,OAAO;AAC7D;","names":[]}