@nextera.one/axis-server-sdk 1.0.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 +84 -7
- package/dist/index.d.ts +84 -7
- package/dist/index.js +363 -310
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +310 -208
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -31,20 +31,243 @@ function Handler(intent) {
|
|
|
31
31
|
|
|
32
32
|
// src/decorators/intent.decorator.ts
|
|
33
33
|
import "reflect-metadata";
|
|
34
|
+
var INTENT_METADATA_KEY = "axis:intent";
|
|
34
35
|
var INTENT_ROUTES_KEY = "axis:intent_routes";
|
|
35
36
|
function Intent(action, options) {
|
|
36
37
|
return (target, propertyKey) => {
|
|
38
|
+
Reflect.defineMetadata(
|
|
39
|
+
INTENT_METADATA_KEY,
|
|
40
|
+
{ intent: action, ...options },
|
|
41
|
+
target,
|
|
42
|
+
propertyKey
|
|
43
|
+
);
|
|
37
44
|
const routes = Reflect.getMetadata(INTENT_ROUTES_KEY, target.constructor) || [];
|
|
38
45
|
routes.push({
|
|
39
46
|
action,
|
|
40
47
|
methodName: propertyKey,
|
|
41
48
|
absolute: options?.absolute,
|
|
42
|
-
frame: options?.frame
|
|
49
|
+
frame: options?.frame,
|
|
50
|
+
kind: options?.kind,
|
|
51
|
+
bodyProfile: options?.bodyProfile,
|
|
52
|
+
tlv: options?.tlv,
|
|
53
|
+
dto: options?.dto
|
|
43
54
|
});
|
|
44
55
|
Reflect.defineMetadata(INTENT_ROUTES_KEY, routes, target.constructor);
|
|
45
56
|
};
|
|
46
57
|
}
|
|
47
58
|
|
|
59
|
+
// src/decorators/tlv-field.decorator.ts
|
|
60
|
+
import "reflect-metadata";
|
|
61
|
+
var TLV_FIELDS_KEY = "axis:tlv:fields";
|
|
62
|
+
var TLV_VALIDATORS_KEY = "axis:tlv:validators";
|
|
63
|
+
function TlvField(tag, options) {
|
|
64
|
+
return (target, propertyKey) => {
|
|
65
|
+
const existing = Reflect.getOwnMetadata(TLV_FIELDS_KEY, target.constructor) || [];
|
|
66
|
+
existing.push({
|
|
67
|
+
property: String(propertyKey),
|
|
68
|
+
tag,
|
|
69
|
+
options
|
|
70
|
+
});
|
|
71
|
+
Reflect.defineMetadata(TLV_FIELDS_KEY, existing, target.constructor);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function TlvValidate(validator) {
|
|
75
|
+
return (target, propertyKey) => {
|
|
76
|
+
const existing = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, target.constructor) || [];
|
|
77
|
+
const prop = String(propertyKey);
|
|
78
|
+
let entry = existing.find((e) => e.property === prop);
|
|
79
|
+
if (!entry) {
|
|
80
|
+
entry = { property: prop, tag: 0, validators: [] };
|
|
81
|
+
existing.push(entry);
|
|
82
|
+
}
|
|
83
|
+
entry.validators.push(validator);
|
|
84
|
+
Reflect.defineMetadata(TLV_VALIDATORS_KEY, existing, target.constructor);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function TlvUtf8Pattern(pattern, message) {
|
|
88
|
+
return TlvValidate((val, prop) => {
|
|
89
|
+
const str = new TextDecoder().decode(val);
|
|
90
|
+
return pattern.test(str) ? null : message || `${prop}: failed pattern check`;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function TlvMinLen(min, message) {
|
|
94
|
+
return TlvValidate((val, prop) => {
|
|
95
|
+
return val.length >= min ? null : message || `${prop}: too short (${val.length} < ${min})`;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function TlvEnum(allowed, message) {
|
|
99
|
+
const set = new Set(allowed);
|
|
100
|
+
return TlvValidate((val, prop) => {
|
|
101
|
+
const str = new TextDecoder().decode(val);
|
|
102
|
+
return set.has(str) ? null : message || `${prop}: must be one of [${allowed.join(", ")}]`;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function TlvRange(min, max, message) {
|
|
106
|
+
return TlvValidate((val, prop) => {
|
|
107
|
+
if (val.length !== 8) return `${prop}: u64 must be 8 bytes`;
|
|
108
|
+
let n = 0n;
|
|
109
|
+
for (const b of val) n = n << 8n | BigInt(b);
|
|
110
|
+
if (n < min || n > max) {
|
|
111
|
+
return message || `${prop}: value ${n} out of range [${min}, ${max}]`;
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/decorators/dto-schema.util.ts
|
|
118
|
+
import "reflect-metadata";
|
|
119
|
+
|
|
120
|
+
// src/core/tlv.ts
|
|
121
|
+
import {
|
|
122
|
+
TLV,
|
|
123
|
+
encodeTLVs,
|
|
124
|
+
decodeTLVs,
|
|
125
|
+
decodeTLVsList,
|
|
126
|
+
decodeObject,
|
|
127
|
+
decodeArray
|
|
128
|
+
} from "@nextera.one/axis-protocol";
|
|
129
|
+
|
|
130
|
+
// src/decorators/dto-schema.util.ts
|
|
131
|
+
function extractDtoSchema(dto) {
|
|
132
|
+
const fieldMetas = Reflect.getMetadata(TLV_FIELDS_KEY, dto) || [];
|
|
133
|
+
if (fieldMetas.length === 0) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`DTO class ${dto.name} has no @TlvField decorators \u2014 nothing to validate`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const tagByProp = /* @__PURE__ */ new Map();
|
|
139
|
+
const fields = fieldMetas.map((m) => {
|
|
140
|
+
tagByProp.set(m.property, m.tag);
|
|
141
|
+
return {
|
|
142
|
+
name: m.property,
|
|
143
|
+
tag: m.tag,
|
|
144
|
+
kind: m.options.kind,
|
|
145
|
+
required: m.options.required,
|
|
146
|
+
maxLen: m.options.maxLen,
|
|
147
|
+
max: m.options.max,
|
|
148
|
+
scope: m.options.scope
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
const validatorMetas = Reflect.getMetadata(TLV_VALIDATORS_KEY, dto) || [];
|
|
152
|
+
const validators = /* @__PURE__ */ new Map();
|
|
153
|
+
for (const vm of validatorMetas) {
|
|
154
|
+
const tag = tagByProp.get(vm.property);
|
|
155
|
+
if (tag === void 0) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`@TlvValidate on ${dto.name}.${vm.property} but no @TlvField found for that property`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
vm.tag = tag;
|
|
161
|
+
validators.set(tag, vm.validators);
|
|
162
|
+
}
|
|
163
|
+
return { fields, validators };
|
|
164
|
+
}
|
|
165
|
+
function buildDtoDecoder(dto) {
|
|
166
|
+
const fieldMetas = Reflect.getMetadata(TLV_FIELDS_KEY, dto) || [];
|
|
167
|
+
if (fieldMetas.length === 0) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`DTO class ${dto.name} has no @TlvField decorators \u2014 cannot build decoder`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
const tagMap = /* @__PURE__ */ new Map();
|
|
173
|
+
for (const m of fieldMetas) {
|
|
174
|
+
tagMap.set(m.tag, { property: m.property, kind: m.options.kind });
|
|
175
|
+
}
|
|
176
|
+
return (bodyBytes) => {
|
|
177
|
+
const tlvMap2 = decodeTLVs(new Uint8Array(bodyBytes));
|
|
178
|
+
const result = {};
|
|
179
|
+
for (const [tag, raw] of tlvMap2) {
|
|
180
|
+
const meta = tagMap.get(tag);
|
|
181
|
+
if (!meta) continue;
|
|
182
|
+
switch (meta.kind) {
|
|
183
|
+
case "utf8":
|
|
184
|
+
result[meta.property] = new TextDecoder().decode(raw);
|
|
185
|
+
break;
|
|
186
|
+
case "u64": {
|
|
187
|
+
let n = 0n;
|
|
188
|
+
for (let i = 0; i < raw.length; i++) {
|
|
189
|
+
n = n << 8n | BigInt(raw[i]);
|
|
190
|
+
}
|
|
191
|
+
result[meta.property] = n;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case "bytes":
|
|
195
|
+
case "bytes16":
|
|
196
|
+
result[meta.property] = raw;
|
|
197
|
+
break;
|
|
198
|
+
case "bool":
|
|
199
|
+
result[meta.property] = raw.length > 0 && raw[0] !== 0;
|
|
200
|
+
break;
|
|
201
|
+
case "obj":
|
|
202
|
+
case "arr":
|
|
203
|
+
result[meta.property] = JSON.parse(new TextDecoder().decode(raw));
|
|
204
|
+
break;
|
|
205
|
+
default:
|
|
206
|
+
result[meta.property] = raw;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/base/axis-tlv.dto.ts
|
|
214
|
+
var AxisTlvDto = class {
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/base/axis-id.dto.ts
|
|
218
|
+
var AxisIdDto = class extends AxisTlvDto {
|
|
219
|
+
};
|
|
220
|
+
__decorateClass([
|
|
221
|
+
TlvField(1, { kind: "utf8", required: true, maxLen: 128 }),
|
|
222
|
+
TlvMinLen(1, "id must not be empty")
|
|
223
|
+
], AxisIdDto.prototype, "id", 2);
|
|
224
|
+
|
|
225
|
+
// src/base/axis-partial-type.ts
|
|
226
|
+
import "reflect-metadata";
|
|
227
|
+
function AxisPartialType(BaseDto) {
|
|
228
|
+
class PartialDto extends BaseDto {
|
|
229
|
+
}
|
|
230
|
+
const fields = Reflect.getOwnMetadata(TLV_FIELDS_KEY, BaseDto) || [];
|
|
231
|
+
const partialFields = fields.map((f) => ({
|
|
232
|
+
property: f.property,
|
|
233
|
+
tag: f.tag,
|
|
234
|
+
options: { ...f.options, required: false }
|
|
235
|
+
}));
|
|
236
|
+
Reflect.defineMetadata(TLV_FIELDS_KEY, partialFields, PartialDto);
|
|
237
|
+
const validators = Reflect.getOwnMetadata(TLV_VALIDATORS_KEY, BaseDto) || [];
|
|
238
|
+
if (validators.length > 0) {
|
|
239
|
+
Reflect.defineMetadata(TLV_VALIDATORS_KEY, [...validators], PartialDto);
|
|
240
|
+
}
|
|
241
|
+
Object.defineProperty(PartialDto, "name", {
|
|
242
|
+
value: `Partial${BaseDto.name}`
|
|
243
|
+
});
|
|
244
|
+
return PartialDto;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/base/axis-response.dto.ts
|
|
248
|
+
var RESPONSE_TAG_ID = 1;
|
|
249
|
+
var RESPONSE_TAG_CREATED_AT = 2;
|
|
250
|
+
var RESPONSE_TAG_UPDATED_AT = 3;
|
|
251
|
+
var RESPONSE_TAG_CREATED_BY = 4;
|
|
252
|
+
var RESPONSE_TAG_UPDATED_BY = 5;
|
|
253
|
+
var AxisResponseDto = class extends AxisTlvDto {
|
|
254
|
+
};
|
|
255
|
+
__decorateClass([
|
|
256
|
+
TlvField(RESPONSE_TAG_ID, { kind: "utf8" })
|
|
257
|
+
], AxisResponseDto.prototype, "id", 2);
|
|
258
|
+
__decorateClass([
|
|
259
|
+
TlvField(RESPONSE_TAG_CREATED_AT, { kind: "u64" })
|
|
260
|
+
], AxisResponseDto.prototype, "created_at", 2);
|
|
261
|
+
__decorateClass([
|
|
262
|
+
TlvField(RESPONSE_TAG_UPDATED_AT, { kind: "u64" })
|
|
263
|
+
], AxisResponseDto.prototype, "updated_at", 2);
|
|
264
|
+
__decorateClass([
|
|
265
|
+
TlvField(RESPONSE_TAG_CREATED_BY, { kind: "utf8" })
|
|
266
|
+
], AxisResponseDto.prototype, "created_by", 2);
|
|
267
|
+
__decorateClass([
|
|
268
|
+
TlvField(RESPONSE_TAG_UPDATED_BY, { kind: "utf8" })
|
|
269
|
+
], AxisResponseDto.prototype, "updated_by", 2);
|
|
270
|
+
|
|
48
271
|
// src/engine/intent.router.ts
|
|
49
272
|
import { Injectable as Injectable2 } from "@nestjs/common";
|
|
50
273
|
var IntentRouter = class {
|
|
@@ -208,215 +431,73 @@ IntentRouter = __decorateClass([
|
|
|
208
431
|
], IntentRouter);
|
|
209
432
|
|
|
210
433
|
// src/core/constants.ts
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
})(ProofType || {});
|
|
276
|
-
var BodyProfile = /* @__PURE__ */ ((BodyProfile2) => {
|
|
277
|
-
BodyProfile2[BodyProfile2["RAW"] = 0] = "RAW";
|
|
278
|
-
BodyProfile2[BodyProfile2["TLV_MAP"] = 1] = "TLV_MAP";
|
|
279
|
-
BodyProfile2[BodyProfile2["OBJ"] = 2] = "OBJ";
|
|
280
|
-
BodyProfile2[BodyProfile2["ARR"] = 3] = "ARR";
|
|
281
|
-
return BodyProfile2;
|
|
282
|
-
})(BodyProfile || {});
|
|
283
|
-
var ERR_INVALID_PACKET = "INVALID_PACKET";
|
|
284
|
-
var ERR_BAD_SIGNATURE = "BAD_SIGNATURE";
|
|
285
|
-
var ERR_REPLAY_DETECTED = "REPLAY_DETECTED";
|
|
286
|
-
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";
|
|
287
498
|
|
|
288
499
|
// src/core/varint.ts
|
|
289
|
-
|
|
290
|
-
if (value < 0) throw new Error("Varint must be unsigned");
|
|
291
|
-
const bytes2 = [];
|
|
292
|
-
while (true) {
|
|
293
|
-
const byte = value & 127;
|
|
294
|
-
value >>>= 7;
|
|
295
|
-
if (value === 0) {
|
|
296
|
-
bytes2.push(byte);
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
bytes2.push(byte | 128);
|
|
300
|
-
}
|
|
301
|
-
return new Uint8Array(bytes2);
|
|
302
|
-
}
|
|
303
|
-
function decodeVarint(buf, offset = 0) {
|
|
304
|
-
let value = 0;
|
|
305
|
-
let shift = 0;
|
|
306
|
-
let length = 0;
|
|
307
|
-
while (true) {
|
|
308
|
-
if (offset + length >= buf.length) {
|
|
309
|
-
throw new Error("Varint decode out of bounds");
|
|
310
|
-
}
|
|
311
|
-
const byte = buf[offset + length];
|
|
312
|
-
value += (byte & 127) * Math.pow(2, shift);
|
|
313
|
-
length++;
|
|
314
|
-
shift += 7;
|
|
315
|
-
if ((byte & 128) === 0) {
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
if (length > 8) throw new Error("Varint too large");
|
|
319
|
-
}
|
|
320
|
-
return { value, length };
|
|
321
|
-
}
|
|
322
|
-
function varintLength(value) {
|
|
323
|
-
if (value < 0) throw new Error("Varint must be unsigned");
|
|
324
|
-
let len = 0;
|
|
325
|
-
do {
|
|
326
|
-
value >>>= 7;
|
|
327
|
-
len++;
|
|
328
|
-
} while (value !== 0);
|
|
329
|
-
return len;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// src/core/tlv.ts
|
|
333
|
-
function encodeTLVs(tlvs) {
|
|
334
|
-
const sorted = [...tlvs].sort((a, b) => a.type - b.type);
|
|
335
|
-
for (let i = 0; i < sorted.length - 1; i++) {
|
|
336
|
-
if (sorted[i].type === sorted[i + 1].type) {
|
|
337
|
-
throw new Error(`Duplicate TLV type: ${sorted[i].type}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
let totalSize = 0;
|
|
341
|
-
for (const t of sorted) {
|
|
342
|
-
totalSize += varintLength(t.type);
|
|
343
|
-
totalSize += varintLength(t.value.length);
|
|
344
|
-
totalSize += t.value.length;
|
|
345
|
-
}
|
|
346
|
-
const buf = new Uint8Array(totalSize);
|
|
347
|
-
let offset = 0;
|
|
348
|
-
for (const t of sorted) {
|
|
349
|
-
const typeBytes = encodeVarint(t.type);
|
|
350
|
-
buf.set(typeBytes, offset);
|
|
351
|
-
offset += typeBytes.length;
|
|
352
|
-
const lenBytes = encodeVarint(t.value.length);
|
|
353
|
-
buf.set(lenBytes, offset);
|
|
354
|
-
offset += lenBytes.length;
|
|
355
|
-
buf.set(t.value, offset);
|
|
356
|
-
offset += t.value.length;
|
|
357
|
-
}
|
|
358
|
-
return buf;
|
|
359
|
-
}
|
|
360
|
-
function decodeTLVsList(buf, maxItems = 1024) {
|
|
361
|
-
const list = [];
|
|
362
|
-
let offset = 0;
|
|
363
|
-
while (offset < buf.length) {
|
|
364
|
-
if (list.length >= maxItems) throw new Error("TLV_LIMIT");
|
|
365
|
-
const { value: type, length: typeLen } = decodeVarint(buf, offset);
|
|
366
|
-
offset += typeLen;
|
|
367
|
-
const { value: len, length: lenLen } = decodeVarint(buf, offset);
|
|
368
|
-
offset += lenLen;
|
|
369
|
-
if (offset + len > buf.length) {
|
|
370
|
-
throw new Error(`TLV violation: Length ${len} exceeds buffer`);
|
|
371
|
-
}
|
|
372
|
-
const value = buf.slice(offset, offset + len);
|
|
373
|
-
list.push({ type, value });
|
|
374
|
-
offset += len;
|
|
375
|
-
}
|
|
376
|
-
return list;
|
|
377
|
-
}
|
|
378
|
-
function decodeTLVs(buf) {
|
|
379
|
-
const map2 = /* @__PURE__ */ new Map();
|
|
380
|
-
let offset = 0;
|
|
381
|
-
let lastType = -1;
|
|
382
|
-
while (offset < buf.length) {
|
|
383
|
-
const { value: type, length: typeLen } = decodeVarint(buf, offset);
|
|
384
|
-
offset += typeLen;
|
|
385
|
-
if (type <= lastType) {
|
|
386
|
-
throw new Error(
|
|
387
|
-
`TLV violation: Unsorted or duplicate type ${type} after ${lastType}`
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
lastType = type;
|
|
391
|
-
const { value: len, length: lenLen } = decodeVarint(buf, offset);
|
|
392
|
-
offset += lenLen;
|
|
393
|
-
if (offset + len > buf.length) {
|
|
394
|
-
throw new Error(`TLV violation: Length ${len} exceeds buffer`);
|
|
395
|
-
}
|
|
396
|
-
const value = buf.slice(offset, offset + len);
|
|
397
|
-
map2.set(type, value);
|
|
398
|
-
offset += len;
|
|
399
|
-
}
|
|
400
|
-
return map2;
|
|
401
|
-
}
|
|
402
|
-
function decodeObject(bytes2, depth = 0, limits = { maxDepth: 8, maxItems: 128 }) {
|
|
403
|
-
if (depth > limits.maxDepth) {
|
|
404
|
-
throw new Error("OBJECT_DEPTH_EXCEEDED");
|
|
405
|
-
}
|
|
406
|
-
const map2 = decodeTLVs(bytes2);
|
|
407
|
-
return map2;
|
|
408
|
-
}
|
|
409
|
-
function decodeArray(bytes2, itemType, maxItems = 256) {
|
|
410
|
-
const list = decodeTLVsList(bytes2, maxItems);
|
|
411
|
-
const items = [];
|
|
412
|
-
for (const tlv2 of list) {
|
|
413
|
-
if (tlv2.type !== itemType) {
|
|
414
|
-
throw new Error(`INVALID_ARRAY_ITEM:${tlv2.type}`);
|
|
415
|
-
}
|
|
416
|
-
items.push(tlv2.value);
|
|
417
|
-
}
|
|
418
|
-
return items;
|
|
419
|
-
}
|
|
500
|
+
import { encodeVarint, decodeVarint, varintLength } from "@nextera.one/axis-protocol";
|
|
420
501
|
|
|
421
502
|
// src/core/signature.ts
|
|
422
503
|
import * as crypto from "crypto";
|
|
@@ -2189,7 +2270,11 @@ export {
|
|
|
2189
2270
|
AXIS_VERSION,
|
|
2190
2271
|
ats1_exports as Ats1Codec,
|
|
2191
2272
|
AxisFrameZ,
|
|
2273
|
+
AxisIdDto,
|
|
2192
2274
|
T as AxisPacketTags,
|
|
2275
|
+
AxisPartialType,
|
|
2276
|
+
AxisResponseDto,
|
|
2277
|
+
AxisTlvDto,
|
|
2193
2278
|
BodyProfile,
|
|
2194
2279
|
CAPABILITIES,
|
|
2195
2280
|
ContractViolationError,
|
|
@@ -2207,6 +2292,7 @@ export {
|
|
|
2207
2292
|
FLAG_HAS_WITNESS,
|
|
2208
2293
|
HANDLER_METADATA_KEY,
|
|
2209
2294
|
Handler,
|
|
2295
|
+
INTENT_METADATA_KEY,
|
|
2210
2296
|
INTENT_REQUIREMENTS,
|
|
2211
2297
|
INTENT_ROUTES_KEY,
|
|
2212
2298
|
INTENT_SENSITIVITY_MAP,
|
|
@@ -2236,12 +2322,18 @@ export {
|
|
|
2236
2322
|
PROOF_NONE,
|
|
2237
2323
|
PROOF_WITNESS,
|
|
2238
2324
|
ProofType,
|
|
2325
|
+
RESPONSE_TAG_CREATED_AT,
|
|
2326
|
+
RESPONSE_TAG_CREATED_BY,
|
|
2327
|
+
RESPONSE_TAG_ID,
|
|
2328
|
+
RESPONSE_TAG_UPDATED_AT,
|
|
2329
|
+
RESPONSE_TAG_UPDATED_BY,
|
|
2239
2330
|
RiskDecision,
|
|
2240
2331
|
Schema2002_PasskeyLoginOptionsRes,
|
|
2241
2332
|
Schema2011_PasskeyLoginVerifyReq,
|
|
2242
2333
|
Schema2012_PasskeyLoginVerifyRes,
|
|
2243
2334
|
Schema2021_PasskeyRegisterOptionsReq,
|
|
2244
2335
|
SensorDecisions,
|
|
2336
|
+
TLV,
|
|
2245
2337
|
TLV_ACTOR_ID,
|
|
2246
2338
|
TLV_AUD,
|
|
2247
2339
|
TLV_BODY_ARR,
|
|
@@ -2250,6 +2342,7 @@ export {
|
|
|
2250
2342
|
TLV_EFFECT,
|
|
2251
2343
|
TLV_ERROR_CODE,
|
|
2252
2344
|
TLV_ERROR_MSG,
|
|
2345
|
+
TLV_FIELDS_KEY,
|
|
2253
2346
|
TLV_INDEX,
|
|
2254
2347
|
TLV_INTENT,
|
|
2255
2348
|
TLV_KID,
|
|
@@ -2273,12 +2366,20 @@ export {
|
|
|
2273
2366
|
TLV_TRACE_ID,
|
|
2274
2367
|
TLV_TS,
|
|
2275
2368
|
TLV_UPLOAD_ID,
|
|
2369
|
+
TLV_VALIDATORS_KEY,
|
|
2370
|
+
TlvEnum,
|
|
2371
|
+
TlvField,
|
|
2372
|
+
TlvMinLen,
|
|
2373
|
+
TlvRange,
|
|
2374
|
+
TlvUtf8Pattern,
|
|
2375
|
+
TlvValidate,
|
|
2276
2376
|
axis1SigningBytes,
|
|
2277
2377
|
b64urlDecode,
|
|
2278
2378
|
b64urlDecodeString,
|
|
2279
2379
|
b64urlEncode,
|
|
2280
2380
|
b64urlEncodeString,
|
|
2281
2381
|
buildAts1Hdr,
|
|
2382
|
+
buildDtoDecoder,
|
|
2282
2383
|
buildPacket,
|
|
2283
2384
|
buildReceiptHash,
|
|
2284
2385
|
buildTLVs,
|
|
@@ -2301,6 +2402,7 @@ export {
|
|
|
2301
2402
|
encodeFrame,
|
|
2302
2403
|
encodeTLVs,
|
|
2303
2404
|
encodeVarint,
|
|
2405
|
+
extractDtoSchema,
|
|
2304
2406
|
generateEd25519KeyPair,
|
|
2305
2407
|
getSignTarget,
|
|
2306
2408
|
hasScope,
|