@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/core/index.d.mts +2 -96
- package/dist/core/index.d.ts +2 -96
- package/dist/core/index.js +94 -294
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +74 -205
- package/dist/core/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +113 -313
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -210
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
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,
|