@nextera.one/axis-server-sdk 2.1.0 → 2.1.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/dist/codec/axis1.encode.d.mts +10 -0
- package/dist/codec/axis1.encode.d.ts +10 -0
- package/dist/codec/axis1.encode.js +65 -0
- package/dist/codec/axis1.encode.js.map +1 -0
- package/dist/codec/axis1.encode.mjs +41 -0
- package/dist/codec/axis1.encode.mjs.map +1 -0
- package/dist/codec/axis1.signing.d.mts +8 -0
- package/dist/codec/axis1.signing.d.ts +8 -0
- package/dist/codec/axis1.signing.js +61 -0
- package/dist/codec/axis1.signing.js.map +1 -0
- package/dist/codec/axis1.signing.mjs +37 -0
- package/dist/codec/axis1.signing.mjs.map +1 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +6 -244
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +8 -238
- package/dist/core/index.mjs.map +1 -1
- package/dist/index-VxXqZPuH.d.mts +51 -0
- package/dist/index-VxXqZPuH.d.ts +51 -0
- package/dist/index.d.mts +1340 -480
- package/dist/index.d.ts +1340 -480
- package/dist/index.js +2952 -372
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2958 -364
- package/dist/index.mjs.map +1 -1
- package/dist/types/frame.d.mts +11 -0
- package/dist/types/frame.d.ts +11 -0
- package/dist/types/frame.js +78 -0
- package/dist/types/frame.js.map +1 -0
- package/dist/types/frame.mjs +54 -0
- package/dist/types/frame.mjs.map +1 -0
- package/package.json +2 -1
- package/dist/index-1uEwnW-w.d.mts +0 -122
- package/dist/index-1uEwnW-w.d.ts +0 -122
|
@@ -0,0 +1,65 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export * from '@nextera.one/axis-protocol';
|
|
2
|
+
export { A as AxisError, a as AxisFrameZ, c as computeReceiptHash, b as computeSignaturePayload, g as generateEd25519KeyPair, s as sha256, d as signFrame, v as verifyFrameSignature } from '../index-VxXqZPuH.mjs';
|
|
3
3
|
import 'zod';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
1
|
+
export * from '@nextera.one/axis-protocol';
|
|
2
|
+
export { A as AxisError, a as AxisFrameZ, c as computeReceiptHash, b as computeSignaturePayload, g as generateEd25519KeyPair, s as sha256, d as signFrame, v as verifyFrameSignature } from '../index-VxXqZPuH.js';
|
|
3
3
|
import 'zod';
|
package/dist/core/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
@@ -29,102 +30,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
30
|
// src/core/index.ts
|
|
30
31
|
var core_exports = {};
|
|
31
32
|
__export(core_exports, {
|
|
32
|
-
AXIS_MAGIC: () => import_axis_protocol.AXIS_MAGIC,
|
|
33
|
-
AXIS_VERSION: () => import_axis_protocol.AXIS_VERSION,
|
|
34
33
|
AxisError: () => AxisError,
|
|
35
34
|
AxisFrameZ: () => AxisFrameZ,
|
|
36
|
-
BodyProfile: () => import_axis_protocol.BodyProfile,
|
|
37
|
-
ERR_BAD_SIGNATURE: () => import_axis_protocol.ERR_BAD_SIGNATURE,
|
|
38
|
-
ERR_CONTRACT_VIOLATION: () => import_axis_protocol.ERR_CONTRACT_VIOLATION,
|
|
39
|
-
ERR_INVALID_PACKET: () => import_axis_protocol.ERR_INVALID_PACKET,
|
|
40
|
-
ERR_REPLAY_DETECTED: () => import_axis_protocol.ERR_REPLAY_DETECTED,
|
|
41
|
-
FLAG_BODY_TLV: () => import_axis_protocol.FLAG_BODY_TLV,
|
|
42
|
-
FLAG_CHAIN_REQ: () => import_axis_protocol.FLAG_CHAIN_REQ,
|
|
43
|
-
FLAG_HAS_WITNESS: () => import_axis_protocol.FLAG_HAS_WITNESS,
|
|
44
|
-
MAX_BODY_LEN: () => import_axis_protocol.MAX_BODY_LEN,
|
|
45
|
-
MAX_FRAME_LEN: () => import_axis_protocol.MAX_FRAME_LEN,
|
|
46
|
-
MAX_HDR_LEN: () => import_axis_protocol.MAX_HDR_LEN,
|
|
47
|
-
MAX_SIG_LEN: () => import_axis_protocol.MAX_SIG_LEN,
|
|
48
|
-
NCERT_ALG: () => import_axis_protocol.NCERT_ALG,
|
|
49
|
-
NCERT_EXP: () => import_axis_protocol.NCERT_EXP,
|
|
50
|
-
NCERT_ISSUER_KID: () => import_axis_protocol.NCERT_ISSUER_KID,
|
|
51
|
-
NCERT_KID: () => import_axis_protocol.NCERT_KID,
|
|
52
|
-
NCERT_NBF: () => import_axis_protocol.NCERT_NBF,
|
|
53
|
-
NCERT_NODE_ID: () => import_axis_protocol.NCERT_NODE_ID,
|
|
54
|
-
NCERT_PAYLOAD: () => import_axis_protocol.NCERT_PAYLOAD,
|
|
55
|
-
NCERT_PUB: () => import_axis_protocol.NCERT_PUB,
|
|
56
|
-
NCERT_SCOPE: () => import_axis_protocol.NCERT_SCOPE,
|
|
57
|
-
NCERT_SIG: () => import_axis_protocol.NCERT_SIG,
|
|
58
|
-
PROOF_CAPSULE: () => import_axis_protocol.PROOF_CAPSULE,
|
|
59
|
-
PROOF_JWT: () => import_axis_protocol.PROOF_JWT,
|
|
60
|
-
PROOF_LOOM: () => import_axis_protocol.PROOF_LOOM,
|
|
61
|
-
PROOF_MTLS: () => import_axis_protocol.PROOF_MTLS,
|
|
62
|
-
PROOF_NONE: () => import_axis_protocol.PROOF_NONE,
|
|
63
|
-
PROOF_WITNESS: () => import_axis_protocol.PROOF_WITNESS,
|
|
64
|
-
ProofType: () => import_axis_protocol.ProofType,
|
|
65
|
-
TLV: () => import_axis_protocol3.TLV,
|
|
66
|
-
TLV_ACTOR_ID: () => import_axis_protocol.TLV_ACTOR_ID,
|
|
67
|
-
TLV_AUD: () => import_axis_protocol.TLV_AUD,
|
|
68
|
-
TLV_BODY_ARR: () => import_axis_protocol.TLV_BODY_ARR,
|
|
69
|
-
TLV_BODY_OBJ: () => import_axis_protocol.TLV_BODY_OBJ,
|
|
70
|
-
TLV_CAPSULE: () => import_axis_protocol.TLV_CAPSULE,
|
|
71
|
-
TLV_EFFECT: () => import_axis_protocol.TLV_EFFECT,
|
|
72
|
-
TLV_ERROR_CODE: () => import_axis_protocol.TLV_ERROR_CODE,
|
|
73
|
-
TLV_ERROR_MSG: () => import_axis_protocol.TLV_ERROR_MSG,
|
|
74
|
-
TLV_INDEX: () => import_axis_protocol.TLV_INDEX,
|
|
75
|
-
TLV_INTENT: () => import_axis_protocol.TLV_INTENT,
|
|
76
|
-
TLV_KID: () => import_axis_protocol.TLV_KID,
|
|
77
|
-
TLV_LOOM_PRESENCE_ID: () => import_axis_protocol.TLV_LOOM_PRESENCE_ID,
|
|
78
|
-
TLV_LOOM_THREAD_HASH: () => import_axis_protocol.TLV_LOOM_THREAD_HASH,
|
|
79
|
-
TLV_LOOM_WRIT: () => import_axis_protocol.TLV_LOOM_WRIT,
|
|
80
|
-
TLV_NODE: () => import_axis_protocol.TLV_NODE,
|
|
81
|
-
TLV_NODE_CERT_HASH: () => import_axis_protocol.TLV_NODE_CERT_HASH,
|
|
82
|
-
TLV_NODE_KID: () => import_axis_protocol.TLV_NODE_KID,
|
|
83
|
-
TLV_NONCE: () => import_axis_protocol.TLV_NONCE,
|
|
84
|
-
TLV_OFFSET: () => import_axis_protocol.TLV_OFFSET,
|
|
85
|
-
TLV_OK: () => import_axis_protocol.TLV_OK,
|
|
86
|
-
TLV_PID: () => import_axis_protocol.TLV_PID,
|
|
87
|
-
TLV_PREV_HASH: () => import_axis_protocol.TLV_PREV_HASH,
|
|
88
|
-
TLV_PROOF_REF: () => import_axis_protocol.TLV_PROOF_REF,
|
|
89
|
-
TLV_PROOF_TYPE: () => import_axis_protocol.TLV_PROOF_TYPE,
|
|
90
|
-
TLV_REALM: () => import_axis_protocol.TLV_REALM,
|
|
91
|
-
TLV_RECEIPT_HASH: () => import_axis_protocol.TLV_RECEIPT_HASH,
|
|
92
|
-
TLV_RID: () => import_axis_protocol.TLV_RID,
|
|
93
|
-
TLV_SHA256_CHUNK: () => import_axis_protocol.TLV_SHA256_CHUNK,
|
|
94
|
-
TLV_TRACE_ID: () => import_axis_protocol.TLV_TRACE_ID,
|
|
95
|
-
TLV_TS: () => import_axis_protocol.TLV_TS,
|
|
96
|
-
TLV_UPLOAD_ID: () => import_axis_protocol.TLV_UPLOAD_ID,
|
|
97
35
|
computeReceiptHash: () => computeReceiptHash,
|
|
98
36
|
computeSignaturePayload: () => computeSignaturePayload,
|
|
99
|
-
decodeArray: () => import_axis_protocol3.decodeArray,
|
|
100
|
-
decodeFrame: () => decodeFrame,
|
|
101
|
-
decodeObject: () => import_axis_protocol3.decodeObject,
|
|
102
|
-
decodeTLVs: () => import_axis_protocol3.decodeTLVs,
|
|
103
|
-
decodeTLVsList: () => import_axis_protocol3.decodeTLVsList,
|
|
104
|
-
decodeVarint: () => import_axis_protocol2.decodeVarint,
|
|
105
|
-
encodeFrame: () => encodeFrame,
|
|
106
|
-
encodeTLVs: () => import_axis_protocol3.encodeTLVs,
|
|
107
|
-
encodeVarint: () => import_axis_protocol2.encodeVarint,
|
|
108
37
|
generateEd25519KeyPair: () => generateEd25519KeyPair,
|
|
109
|
-
getSignTarget: () => getSignTarget,
|
|
110
38
|
sha256: () => sha256,
|
|
111
39
|
signFrame: () => signFrame,
|
|
112
|
-
varintLength: () => import_axis_protocol2.varintLength,
|
|
113
40
|
verifyFrameSignature: () => verifyFrameSignature
|
|
114
41
|
});
|
|
115
42
|
module.exports = __toCommonJS(core_exports);
|
|
116
|
-
|
|
117
|
-
// src/core/constants.ts
|
|
118
|
-
var import_axis_protocol = require("@nextera.one/axis-protocol");
|
|
119
|
-
|
|
120
|
-
// src/core/varint.ts
|
|
121
|
-
var import_axis_protocol2 = require("@nextera.one/axis-protocol");
|
|
122
|
-
|
|
123
|
-
// src/core/tlv.ts
|
|
124
|
-
var import_axis_protocol3 = require("@nextera.one/axis-protocol");
|
|
43
|
+
__reExport(core_exports, require("@nextera.one/axis-protocol"), module.exports);
|
|
125
44
|
|
|
126
45
|
// src/core/axis-bin.ts
|
|
127
46
|
var z = __toESM(require("zod"));
|
|
47
|
+
var import_axis_protocol = require("@nextera.one/axis-protocol");
|
|
128
48
|
var AxisFrameZ = z.object({
|
|
129
49
|
/** Flag bits for protocol control (e.g., encryption, compression) */
|
|
130
50
|
flags: z.number().int().nonnegative(),
|
|
@@ -138,96 +58,11 @@ var AxisFrameZ = z.object({
|
|
|
138
58
|
/** The cryptographic signature covering the frame (except the signature itself) */
|
|
139
59
|
sig: z.custom((v) => v instanceof Uint8Array)
|
|
140
60
|
});
|
|
141
|
-
function encodeFrame(frame) {
|
|
142
|
-
const hdrBytes = (0, import_axis_protocol3.encodeTLVs)(
|
|
143
|
-
Array.from(frame.headers.entries()).map(([t, v]) => ({
|
|
144
|
-
type: t,
|
|
145
|
-
value: v
|
|
146
|
-
}))
|
|
147
|
-
);
|
|
148
|
-
if (hdrBytes.length > import_axis_protocol.MAX_HDR_LEN) throw new Error("Header too large");
|
|
149
|
-
if (frame.body.length > import_axis_protocol.MAX_BODY_LEN) throw new Error("Body too large");
|
|
150
|
-
if (frame.sig.length > import_axis_protocol.MAX_SIG_LEN) throw new Error("Signature too large");
|
|
151
|
-
const hdrLenBytes = (0, import_axis_protocol2.encodeVarint)(hdrBytes.length);
|
|
152
|
-
const bodyLenBytes = (0, import_axis_protocol2.encodeVarint)(frame.body.length);
|
|
153
|
-
const sigLenBytes = (0, import_axis_protocol2.encodeVarint)(frame.sig.length);
|
|
154
|
-
const totalLen = 5 + // Magic (AXIS1)
|
|
155
|
-
1 + // Version
|
|
156
|
-
1 + // Flags
|
|
157
|
-
hdrLenBytes.length + bodyLenBytes.length + sigLenBytes.length + hdrBytes.length + frame.body.length + frame.sig.length;
|
|
158
|
-
if (totalLen > import_axis_protocol.MAX_FRAME_LEN) throw new Error("Total frame too large");
|
|
159
|
-
const buf = new Uint8Array(totalLen);
|
|
160
|
-
let offset = 0;
|
|
161
|
-
buf.set(import_axis_protocol.AXIS_MAGIC, offset);
|
|
162
|
-
offset += 5;
|
|
163
|
-
buf[offset++] = import_axis_protocol.AXIS_VERSION;
|
|
164
|
-
buf[offset++] = frame.flags;
|
|
165
|
-
buf.set(hdrLenBytes, offset);
|
|
166
|
-
offset += hdrLenBytes.length;
|
|
167
|
-
buf.set(bodyLenBytes, offset);
|
|
168
|
-
offset += bodyLenBytes.length;
|
|
169
|
-
buf.set(sigLenBytes, offset);
|
|
170
|
-
offset += sigLenBytes.length;
|
|
171
|
-
buf.set(hdrBytes, offset);
|
|
172
|
-
offset += hdrBytes.length;
|
|
173
|
-
buf.set(frame.body, offset);
|
|
174
|
-
offset += frame.body.length;
|
|
175
|
-
buf.set(frame.sig, offset);
|
|
176
|
-
offset += frame.sig.length;
|
|
177
|
-
return buf;
|
|
178
|
-
}
|
|
179
|
-
function decodeFrame(buf) {
|
|
180
|
-
let offset = 0;
|
|
181
|
-
if (offset + 5 > buf.length) throw new Error("Packet too short");
|
|
182
|
-
for (let i = 0; i < 5; i++) {
|
|
183
|
-
if (buf[offset + i] !== import_axis_protocol.AXIS_MAGIC[i]) throw new Error("Invalid Magic");
|
|
184
|
-
}
|
|
185
|
-
offset += 5;
|
|
186
|
-
const ver = buf[offset++];
|
|
187
|
-
if (ver !== import_axis_protocol.AXIS_VERSION) throw new Error(`Unsupported version: ${ver}`);
|
|
188
|
-
const flags = buf[offset++];
|
|
189
|
-
const { value: hdrLen, length: hlLen } = (0, import_axis_protocol2.decodeVarint)(buf, offset);
|
|
190
|
-
offset += hlLen;
|
|
191
|
-
if (hdrLen > import_axis_protocol.MAX_HDR_LEN) throw new Error("Header limit exceeded");
|
|
192
|
-
const { value: bodyLen, length: blLen } = (0, import_axis_protocol2.decodeVarint)(buf, offset);
|
|
193
|
-
offset += blLen;
|
|
194
|
-
if (bodyLen > import_axis_protocol.MAX_BODY_LEN) throw new Error("Body limit exceeded");
|
|
195
|
-
const { value: sigLen, length: slLen } = (0, import_axis_protocol2.decodeVarint)(buf, offset);
|
|
196
|
-
offset += slLen;
|
|
197
|
-
if (sigLen > import_axis_protocol.MAX_SIG_LEN) throw new Error("Signature limit exceeded");
|
|
198
|
-
if (offset + hdrLen + bodyLen + sigLen > buf.length) {
|
|
199
|
-
throw new Error("Frame truncated");
|
|
200
|
-
}
|
|
201
|
-
const hdrBytes = buf.slice(offset, offset + hdrLen);
|
|
202
|
-
offset += hdrLen;
|
|
203
|
-
const bodyBytes = buf.slice(offset, offset + bodyLen);
|
|
204
|
-
offset += bodyLen;
|
|
205
|
-
const sigBytes = buf.slice(offset, offset + sigLen);
|
|
206
|
-
offset += sigLen;
|
|
207
|
-
const headers = (0, import_axis_protocol3.decodeTLVs)(hdrBytes);
|
|
208
|
-
return {
|
|
209
|
-
flags,
|
|
210
|
-
headers,
|
|
211
|
-
body: bodyBytes,
|
|
212
|
-
sig: sigBytes
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function getSignTarget(frame) {
|
|
216
|
-
return encodeFrame({
|
|
217
|
-
...frame,
|
|
218
|
-
sig: new Uint8Array(0)
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
61
|
|
|
222
62
|
// src/core/signature.ts
|
|
223
63
|
var crypto = __toESM(require("crypto"));
|
|
224
64
|
function computeSignaturePayload(frame) {
|
|
225
|
-
|
|
226
|
-
...frame,
|
|
227
|
-
sig: new Uint8Array(0)
|
|
228
|
-
};
|
|
229
|
-
const encoded = encodeFrame(frameWithoutSig);
|
|
230
|
-
return Buffer.from(encoded);
|
|
65
|
+
return Buffer.from((0, import_axis_protocol.getSignTarget)(frame));
|
|
231
66
|
}
|
|
232
67
|
function signFrame(frame, privateKey) {
|
|
233
68
|
const payload = computeSignaturePayload(frame);
|
|
@@ -350,87 +185,14 @@ var AxisError = class extends Error {
|
|
|
350
185
|
};
|
|
351
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
352
187
|
0 && (module.exports = {
|
|
353
|
-
AXIS_MAGIC,
|
|
354
|
-
AXIS_VERSION,
|
|
355
188
|
AxisError,
|
|
356
189
|
AxisFrameZ,
|
|
357
|
-
BodyProfile,
|
|
358
|
-
ERR_BAD_SIGNATURE,
|
|
359
|
-
ERR_CONTRACT_VIOLATION,
|
|
360
|
-
ERR_INVALID_PACKET,
|
|
361
|
-
ERR_REPLAY_DETECTED,
|
|
362
|
-
FLAG_BODY_TLV,
|
|
363
|
-
FLAG_CHAIN_REQ,
|
|
364
|
-
FLAG_HAS_WITNESS,
|
|
365
|
-
MAX_BODY_LEN,
|
|
366
|
-
MAX_FRAME_LEN,
|
|
367
|
-
MAX_HDR_LEN,
|
|
368
|
-
MAX_SIG_LEN,
|
|
369
|
-
NCERT_ALG,
|
|
370
|
-
NCERT_EXP,
|
|
371
|
-
NCERT_ISSUER_KID,
|
|
372
|
-
NCERT_KID,
|
|
373
|
-
NCERT_NBF,
|
|
374
|
-
NCERT_NODE_ID,
|
|
375
|
-
NCERT_PAYLOAD,
|
|
376
|
-
NCERT_PUB,
|
|
377
|
-
NCERT_SCOPE,
|
|
378
|
-
NCERT_SIG,
|
|
379
|
-
PROOF_CAPSULE,
|
|
380
|
-
PROOF_JWT,
|
|
381
|
-
PROOF_LOOM,
|
|
382
|
-
PROOF_MTLS,
|
|
383
|
-
PROOF_NONE,
|
|
384
|
-
PROOF_WITNESS,
|
|
385
|
-
ProofType,
|
|
386
|
-
TLV,
|
|
387
|
-
TLV_ACTOR_ID,
|
|
388
|
-
TLV_AUD,
|
|
389
|
-
TLV_BODY_ARR,
|
|
390
|
-
TLV_BODY_OBJ,
|
|
391
|
-
TLV_CAPSULE,
|
|
392
|
-
TLV_EFFECT,
|
|
393
|
-
TLV_ERROR_CODE,
|
|
394
|
-
TLV_ERROR_MSG,
|
|
395
|
-
TLV_INDEX,
|
|
396
|
-
TLV_INTENT,
|
|
397
|
-
TLV_KID,
|
|
398
|
-
TLV_LOOM_PRESENCE_ID,
|
|
399
|
-
TLV_LOOM_THREAD_HASH,
|
|
400
|
-
TLV_LOOM_WRIT,
|
|
401
|
-
TLV_NODE,
|
|
402
|
-
TLV_NODE_CERT_HASH,
|
|
403
|
-
TLV_NODE_KID,
|
|
404
|
-
TLV_NONCE,
|
|
405
|
-
TLV_OFFSET,
|
|
406
|
-
TLV_OK,
|
|
407
|
-
TLV_PID,
|
|
408
|
-
TLV_PREV_HASH,
|
|
409
|
-
TLV_PROOF_REF,
|
|
410
|
-
TLV_PROOF_TYPE,
|
|
411
|
-
TLV_REALM,
|
|
412
|
-
TLV_RECEIPT_HASH,
|
|
413
|
-
TLV_RID,
|
|
414
|
-
TLV_SHA256_CHUNK,
|
|
415
|
-
TLV_TRACE_ID,
|
|
416
|
-
TLV_TS,
|
|
417
|
-
TLV_UPLOAD_ID,
|
|
418
190
|
computeReceiptHash,
|
|
419
191
|
computeSignaturePayload,
|
|
420
|
-
decodeArray,
|
|
421
|
-
decodeFrame,
|
|
422
|
-
decodeObject,
|
|
423
|
-
decodeTLVs,
|
|
424
|
-
decodeTLVsList,
|
|
425
|
-
decodeVarint,
|
|
426
|
-
encodeFrame,
|
|
427
|
-
encodeTLVs,
|
|
428
|
-
encodeVarint,
|
|
429
192
|
generateEd25519KeyPair,
|
|
430
|
-
getSignTarget,
|
|
431
193
|
sha256,
|
|
432
194
|
signFrame,
|
|
433
|
-
|
|
434
|
-
|
|
195
|
+
verifyFrameSignature,
|
|
196
|
+
...require("@nextera.one/axis-protocol")
|
|
435
197
|
});
|
|
436
198
|
//# sourceMappingURL=index.js.map
|