@nextera.one/axis-server-sdk 1.1.0 → 1.2.0

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/index.mjs CHANGED
@@ -117,142 +117,19 @@ function TlvRange(min, max, message) {
117
117
  // src/decorators/dto-schema.util.ts
118
118
  import "reflect-metadata";
119
119
 
120
- // src/core/varint.ts
121
- function encodeVarint(value) {
122
- if (value < 0) throw new Error("Varint must be unsigned");
123
- const bytes2 = [];
124
- while (true) {
125
- const byte = value & 127;
126
- value >>>= 7;
127
- if (value === 0) {
128
- bytes2.push(byte);
129
- break;
130
- }
131
- bytes2.push(byte | 128);
132
- }
133
- return new Uint8Array(bytes2);
134
- }
135
- function decodeVarint(buf, offset = 0) {
136
- let value = 0;
137
- let shift = 0;
138
- let length = 0;
139
- while (true) {
140
- if (offset + length >= buf.length) {
141
- throw new Error("Varint decode out of bounds");
142
- }
143
- const byte = buf[offset + length];
144
- value += (byte & 127) * Math.pow(2, shift);
145
- length++;
146
- shift += 7;
147
- if ((byte & 128) === 0) {
148
- break;
149
- }
150
- if (length > 8) throw new Error("Varint too large");
151
- }
152
- return { value, length };
153
- }
154
- function varintLength(value) {
155
- if (value < 0) throw new Error("Varint must be unsigned");
156
- let len = 0;
157
- do {
158
- value >>>= 7;
159
- len++;
160
- } while (value !== 0);
161
- return len;
162
- }
163
-
164
120
  // src/core/tlv.ts
165
- function encodeTLVs(tlvs) {
166
- const sorted = [...tlvs].sort((a, b) => a.type - b.type);
167
- for (let i = 0; i < sorted.length - 1; i++) {
168
- if (sorted[i].type === sorted[i + 1].type) {
169
- throw new Error(`Duplicate TLV type: ${sorted[i].type}`);
170
- }
171
- }
172
- let totalSize = 0;
173
- for (const t of sorted) {
174
- totalSize += varintLength(t.type);
175
- totalSize += varintLength(t.value.length);
176
- totalSize += t.value.length;
177
- }
178
- const buf = new Uint8Array(totalSize);
179
- let offset = 0;
180
- for (const t of sorted) {
181
- const typeBytes = encodeVarint(t.type);
182
- buf.set(typeBytes, offset);
183
- offset += typeBytes.length;
184
- const lenBytes = encodeVarint(t.value.length);
185
- buf.set(lenBytes, offset);
186
- offset += lenBytes.length;
187
- buf.set(t.value, offset);
188
- offset += t.value.length;
189
- }
190
- return buf;
191
- }
192
- function decodeTLVsList(buf, maxItems = 1024) {
193
- const list = [];
194
- let offset = 0;
195
- while (offset < buf.length) {
196
- if (list.length >= maxItems) throw new Error("TLV_LIMIT");
197
- const { value: type, length: typeLen } = decodeVarint(buf, offset);
198
- offset += typeLen;
199
- const { value: len, length: lenLen } = decodeVarint(buf, offset);
200
- offset += lenLen;
201
- if (offset + len > buf.length) {
202
- throw new Error(`TLV violation: Length ${len} exceeds buffer`);
203
- }
204
- const value = buf.slice(offset, offset + len);
205
- list.push({ type, value });
206
- offset += len;
207
- }
208
- return list;
209
- }
210
- function decodeTLVs(buf) {
211
- const map2 = /* @__PURE__ */ new Map();
212
- let offset = 0;
213
- let lastType = -1;
214
- while (offset < buf.length) {
215
- const { value: type, length: typeLen } = decodeVarint(buf, offset);
216
- offset += typeLen;
217
- if (type <= lastType) {
218
- throw new Error(
219
- `TLV violation: Unsorted or duplicate type ${type} after ${lastType}`
220
- );
221
- }
222
- lastType = type;
223
- const { value: len, length: lenLen } = decodeVarint(buf, offset);
224
- offset += lenLen;
225
- if (offset + len > buf.length) {
226
- throw new Error(`TLV violation: Length ${len} exceeds buffer`);
227
- }
228
- const value = buf.slice(offset, offset + len);
229
- map2.set(type, value);
230
- offset += len;
231
- }
232
- return map2;
233
- }
234
- function decodeObject(bytes2, depth = 0, limits = { maxDepth: 8, maxItems: 128 }) {
235
- if (depth > limits.maxDepth) {
236
- throw new Error("OBJECT_DEPTH_EXCEEDED");
237
- }
238
- const map2 = decodeTLVs(bytes2);
239
- return map2;
240
- }
241
- function decodeArray(bytes2, itemType, maxItems = 256) {
242
- const list = decodeTLVsList(bytes2, maxItems);
243
- const items = [];
244
- for (const tlv2 of list) {
245
- if (tlv2.type !== itemType) {
246
- throw new Error(`INVALID_ARRAY_ITEM:${tlv2.type}`);
247
- }
248
- items.push(tlv2.value);
249
- }
250
- return items;
251
- }
121
+ import {
122
+ TLV,
123
+ encodeTLVs,
124
+ decodeTLVs,
125
+ decodeTLVsList,
126
+ decodeObject,
127
+ decodeArray
128
+ } from "@nextera.one/axis-protocol";
252
129
 
253
130
  // src/decorators/dto-schema.util.ts
254
131
  function extractDtoSchema(dto) {
255
- const fieldMetas = Reflect.getOwnMetadata(TLV_FIELDS_KEY, dto) || [];
132
+ const fieldMetas = Reflect.getMetadata(TLV_FIELDS_KEY, dto) || [];
256
133
  if (fieldMetas.length === 0) {
257
134
  throw new Error(
258
135
  `DTO class ${dto.name} has no @TlvField decorators \u2014 nothing to validate`
@@ -271,7 +148,7 @@ function extractDtoSchema(dto) {
271
148
  scope: m.options.scope
272
149
  };
273
150
  });
274
- const validatorMetas = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, dto) || [];
151
+ const validatorMetas = Reflect.getMetadata(TLV_VALIDATORS_KEY, dto) || [];
275
152
  const validators = /* @__PURE__ */ new Map();
276
153
  for (const vm of validatorMetas) {
277
154
  const tag = tagByProp.get(vm.property);
@@ -286,7 +163,7 @@ function extractDtoSchema(dto) {
286
163
  return { fields, validators };
287
164
  }
288
165
  function buildDtoDecoder(dto) {
289
- const fieldMetas = Reflect.getOwnMetadata(TLV_FIELDS_KEY, dto) || [];
166
+ const fieldMetas = Reflect.getMetadata(TLV_FIELDS_KEY, dto) || [];
290
167
  if (fieldMetas.length === 0) {
291
168
  throw new Error(
292
169
  `DTO class ${dto.name} has no @TlvField decorators \u2014 cannot build decoder`
@@ -554,82 +431,73 @@ IntentRouter = __decorateClass([
554
431
  ], IntentRouter);
555
432
 
556
433
  // src/core/constants.ts
557
- var AXIS_MAGIC = new Uint8Array([65, 88, 73, 83, 49]);
558
- var AXIS_VERSION = 1;
559
- var MAX_HDR_LEN = 2048;
560
- var MAX_BODY_LEN = 65536;
561
- var MAX_SIG_LEN = 128;
562
- var MAX_FRAME_LEN = 70 * 1024;
563
- var FLAG_BODY_TLV = 1;
564
- var FLAG_CHAIN_REQ = 2;
565
- var FLAG_HAS_WITNESS = 4;
566
- var TLV_PID = 1;
567
- var TLV_TS = 2;
568
- var TLV_INTENT = 3;
569
- var TLV_ACTOR_ID = 4;
570
- var TLV_PROOF_TYPE = 5;
571
- var TLV_PROOF_REF = 6;
572
- var TLV_NONCE = 7;
573
- var TLV_AUD = 8;
574
- var TLV_REALM = TLV_AUD;
575
- var TLV_NODE = 9;
576
- var TLV_TRACE_ID = 10;
577
- var TLV_KID = 11;
578
- var TLV_RID = 15;
579
- var TLV_OK = 16;
580
- var TLV_EFFECT = 17;
581
- var TLV_ERROR_CODE = 18;
582
- var TLV_ERROR_MSG = 19;
583
- var TLV_PREV_HASH = 20;
584
- var TLV_RECEIPT_HASH = 21;
585
- var TLV_NODE_KID = 30;
586
- var TLV_NODE_CERT_HASH = 34;
587
- var TLV_LOOM_PRESENCE_ID = 91;
588
- var TLV_LOOM_WRIT = 92;
589
- var TLV_LOOM_THREAD_HASH = 93;
590
- var TLV_UPLOAD_ID = 70;
591
- var TLV_INDEX = 71;
592
- var TLV_OFFSET = 72;
593
- var TLV_SHA256_CHUNK = 73;
594
- var TLV_CAPSULE = 90;
595
- var TLV_BODY_OBJ = 254;
596
- var TLV_BODY_ARR = 255;
597
- var NCERT_NODE_ID = 1;
598
- var NCERT_KID = 2;
599
- var NCERT_ALG = 3;
600
- var NCERT_PUB = 4;
601
- var NCERT_NBF = 5;
602
- var NCERT_EXP = 6;
603
- var NCERT_SCOPE = 7;
604
- var NCERT_ISSUER_KID = 8;
605
- var NCERT_PAYLOAD = 50;
606
- var NCERT_SIG = 51;
607
- var PROOF_NONE = 0;
608
- var PROOF_CAPSULE = 1;
609
- var PROOF_JWT = 2;
610
- var PROOF_MTLS = 3;
611
- var PROOF_LOOM = 4;
612
- var PROOF_WITNESS = 5;
613
- var ProofType = /* @__PURE__ */ ((ProofType2) => {
614
- ProofType2[ProofType2["NONE"] = 0] = "NONE";
615
- ProofType2[ProofType2["CAPSULE"] = 1] = "CAPSULE";
616
- ProofType2[ProofType2["JWT"] = 2] = "JWT";
617
- ProofType2[ProofType2["MTLS"] = 3] = "MTLS";
618
- ProofType2[ProofType2["LOOM"] = 4] = "LOOM";
619
- ProofType2[ProofType2["WITNESS"] = 5] = "WITNESS";
620
- return ProofType2;
621
- })(ProofType || {});
622
- var BodyProfile = /* @__PURE__ */ ((BodyProfile2) => {
623
- BodyProfile2[BodyProfile2["RAW"] = 0] = "RAW";
624
- BodyProfile2[BodyProfile2["TLV_MAP"] = 1] = "TLV_MAP";
625
- BodyProfile2[BodyProfile2["OBJ"] = 2] = "OBJ";
626
- BodyProfile2[BodyProfile2["ARR"] = 3] = "ARR";
627
- return BodyProfile2;
628
- })(BodyProfile || {});
629
- var ERR_INVALID_PACKET = "INVALID_PACKET";
630
- var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
631
- var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
632
- var ERR_CONTRACT_VIOLATION = "CONTRACT_VIOLATION";
434
+ import {
435
+ AXIS_MAGIC,
436
+ AXIS_VERSION,
437
+ MAX_HDR_LEN,
438
+ MAX_BODY_LEN,
439
+ MAX_SIG_LEN,
440
+ MAX_FRAME_LEN,
441
+ FLAG_BODY_TLV,
442
+ FLAG_CHAIN_REQ,
443
+ FLAG_HAS_WITNESS,
444
+ TLV_PID,
445
+ TLV_TS,
446
+ TLV_INTENT,
447
+ TLV_ACTOR_ID,
448
+ TLV_PROOF_TYPE,
449
+ TLV_PROOF_REF,
450
+ TLV_NONCE,
451
+ TLV_AUD,
452
+ TLV_REALM,
453
+ TLV_NODE,
454
+ TLV_TRACE_ID,
455
+ TLV_KID,
456
+ TLV_RID,
457
+ TLV_OK,
458
+ TLV_EFFECT,
459
+ TLV_ERROR_CODE,
460
+ TLV_ERROR_MSG,
461
+ TLV_PREV_HASH,
462
+ TLV_RECEIPT_HASH,
463
+ TLV_NODE_KID,
464
+ TLV_NODE_CERT_HASH,
465
+ TLV_LOOM_PRESENCE_ID,
466
+ TLV_LOOM_WRIT,
467
+ TLV_LOOM_THREAD_HASH,
468
+ TLV_UPLOAD_ID,
469
+ TLV_INDEX,
470
+ TLV_OFFSET,
471
+ TLV_SHA256_CHUNK,
472
+ TLV_CAPSULE,
473
+ TLV_BODY_OBJ,
474
+ TLV_BODY_ARR,
475
+ NCERT_NODE_ID,
476
+ NCERT_KID,
477
+ NCERT_ALG,
478
+ NCERT_PUB,
479
+ NCERT_NBF,
480
+ NCERT_EXP,
481
+ NCERT_SCOPE,
482
+ NCERT_ISSUER_KID,
483
+ NCERT_PAYLOAD,
484
+ NCERT_SIG,
485
+ PROOF_NONE,
486
+ PROOF_CAPSULE,
487
+ PROOF_JWT,
488
+ PROOF_MTLS,
489
+ PROOF_LOOM,
490
+ PROOF_WITNESS,
491
+ ProofType,
492
+ BodyProfile,
493
+ ERR_INVALID_PACKET,
494
+ ERR_BAD_SIGNATURE,
495
+ ERR_REPLAY_DETECTED,
496
+ ERR_CONTRACT_VIOLATION
497
+ } from "@nextera.one/axis-protocol";
498
+
499
+ // src/core/varint.ts
500
+ import { encodeVarint, decodeVarint, varintLength } from "@nextera.one/axis-protocol";
633
501
 
634
502
  // src/core/signature.ts
635
503
  import * as crypto from "crypto";
@@ -2465,6 +2333,7 @@ export {
2465
2333
  Schema2012_PasskeyLoginVerifyRes,
2466
2334
  Schema2021_PasskeyRegisterOptionsReq,
2467
2335
  SensorDecisions,
2336
+ TLV,
2468
2337
  TLV_ACTOR_ID,
2469
2338
  TLV_AUD,
2470
2339
  TLV_BODY_ARR,