@marcuspuchalla/nachos 0.1.1 → 0.1.4
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/CHANGELOG.md +55 -0
- package/dist/{chunk-ZRPJUEIZ.js → chunk-5IWW5H47.js} +546 -227
- package/dist/chunk-5IWW5H47.js.map +1 -0
- package/dist/{chunk-2HBCILJS.cjs → chunk-RVG2BY32.cjs} +545 -226
- package/dist/chunk-RVG2BY32.cjs.map +1 -0
- package/dist/{chunk-2FUTHZQQ.cjs → chunk-S4RXO6IB.cjs} +244 -166
- package/dist/chunk-S4RXO6IB.cjs.map +1 -0
- package/dist/{chunk-7CFYWHS6.js → chunk-UMAX5MX5.js} +244 -166
- package/dist/chunk-UMAX5MX5.js.map +1 -0
- package/dist/encoder/index.cjs +13 -13
- package/dist/encoder/index.d.cts +2 -2
- package/dist/encoder/index.d.ts +2 -2
- package/dist/encoder/index.js +1 -1
- package/dist/index.cjs +32 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -19
- package/dist/index.d.ts +28 -19
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/parser/index.cjs +14 -14
- package/dist/parser/index.d.cts +3 -1
- package/dist/parser/index.d.ts +3 -1
- package/dist/parser/index.js +1 -1
- package/dist/{useCborSimpleEncoder-TVxzNJ_9.d.ts → useCborSimpleEncoder-BoKEmjP9.d.ts} +0 -2
- package/dist/{useCborSimpleEncoder-ButVU988.d.cts → useCborSimpleEncoder-C_OHxoB8.d.cts} +0 -2
- package/dist/{useCborTag-B_iaShG6.d.ts → useCborTag-BD6Sqp7p.d.ts} +11 -6
- package/dist/{useCborTag-BfTIV8HM.d.cts → useCborTag-QpZR-Er2.d.cts} +11 -6
- package/package.json +1 -1
- package/src/__tests__/public-api.test.ts +153 -0
- package/src/__tests__/roundtrip.test.ts +701 -0
- package/src/encoder/__tests__/cbor-collection-encoder.test.ts +129 -5
- package/src/encoder/__tests__/cbor-encoder-errors.test.ts +847 -0
- package/src/encoder/__tests__/cbor-simple-encoder.test.ts +126 -0
- package/src/encoder/__tests__/cbor-string-encoder.test.ts +14 -0
- package/src/encoder/composables/useCborCollectionEncoder.ts +56 -23
- package/src/encoder/composables/useCborEncoder.ts +27 -1
- package/src/encoder/composables/useCborSimpleEncoder.ts +40 -8
- package/src/encoder/composables/useCborStringEncoder.ts +23 -10
- package/src/encoder/types.ts +0 -2
- package/src/index.ts +29 -20
- package/src/parser/__tests__/buffer-native-parsing.test.ts +338 -0
- package/src/parser/__tests__/cbor-float-errors.test.ts +41 -0
- package/src/parser/__tests__/cbor-map-duplicate-keys.test.ts +97 -7
- package/src/parser/__tests__/cbor-security-dos-protection.test.ts +166 -33
- package/src/parser/__tests__/cbor-standard-tags.test.ts +104 -7
- package/src/parser/__tests__/cbor-string-errors.test.ts +4 -4
- package/src/parser/__tests__/cbor-tag-errors.test.ts +1 -1
- package/src/parser/__tests__/cbor-tag-reparse-fix.test.ts +268 -0
- package/src/parser/composables/useCborCollection.ts +45 -42
- package/src/parser/composables/useCborFloat.ts +95 -9
- package/src/parser/composables/useCborInteger.ts +24 -10
- package/src/parser/composables/useCborParser.ts +387 -216
- package/src/parser/composables/useCborString.ts +22 -4
- package/src/parser/composables/useCborTag.ts +149 -53
- package/src/parser/utils.ts +11 -0
- package/dist/chunk-2FUTHZQQ.cjs.map +0 -1
- package/dist/chunk-2HBCILJS.cjs.map +0 -1
- package/dist/chunk-7CFYWHS6.js.map +0 -1
- package/dist/chunk-ZRPJUEIZ.js.map +0 -1
- package/src/encoder/composables/#useCborTagEncoder.ts# +0 -158
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry } from './types-DvNlfbKB.js';
|
|
1
|
+
import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry, h as PlutusConstr } from './types-DvNlfbKB.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* CBOR Main Parser Composable
|
|
@@ -19,9 +19,9 @@ import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as Cbor
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
declare function useCborParser(): {
|
|
22
|
-
parse: (
|
|
23
|
-
parseWithSourceMap: (
|
|
24
|
-
parseSequence: (
|
|
22
|
+
parse: (input: string | Uint8Array, options?: ParseOptions) => ParseResult;
|
|
23
|
+
parseWithSourceMap: (input: string | Uint8Array, options?: ParseOptions) => ParseResultWithMap;
|
|
24
|
+
parseSequence: (input: string | Uint8Array, options?: ParseOptions) => CborValue[];
|
|
25
25
|
parseSequenceWithSourceMap: (hexString: string, options?: ParseOptions) => {
|
|
26
26
|
values: CborValue[];
|
|
27
27
|
sourceMaps: SourceMapEntry[][];
|
|
@@ -47,6 +47,7 @@ declare function useCborParser(): {
|
|
|
47
47
|
*/
|
|
48
48
|
declare function useCborInteger(): {
|
|
49
49
|
parseInteger: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
50
|
+
parseIntegerFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions) => ParseResult;
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -112,9 +113,10 @@ declare function useCborCollection(): {
|
|
|
112
113
|
* ```
|
|
113
114
|
*/
|
|
114
115
|
declare function useCborFloat(): {
|
|
115
|
-
parse: (hexString: string,
|
|
116
|
-
parseFloat: (hexString: string,
|
|
116
|
+
parse: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
117
|
+
parseFloat: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
117
118
|
parseSimple: (hexString: string, _options?: ParseOptions) => ParseResult;
|
|
119
|
+
parseFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions) => ParseResult;
|
|
118
120
|
};
|
|
119
121
|
|
|
120
122
|
/**
|
|
@@ -137,6 +139,9 @@ declare function useCborFloat(): {
|
|
|
137
139
|
declare function useCborTag(): {
|
|
138
140
|
parseTag: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
139
141
|
parse: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
142
|
+
parseTagFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions, tagDepth?: number) => ParseResult;
|
|
143
|
+
validateTagSemantics: (tagNumber: number, value: CborValue, options?: ParseOptions) => void;
|
|
144
|
+
decodePlutusConstructor: (tagNumber: number, value: CborValue) => PlutusConstr | null;
|
|
140
145
|
};
|
|
141
146
|
|
|
142
147
|
export { useCborInteger as a, useCborString as b, useCborCollection as c, useCborFloat as d, useCborTag as e, useCborParser as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry } from './types-DvNlfbKB.cjs';
|
|
1
|
+
import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry, h as PlutusConstr } from './types-DvNlfbKB.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* CBOR Main Parser Composable
|
|
@@ -19,9 +19,9 @@ import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as Cbor
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
declare function useCborParser(): {
|
|
22
|
-
parse: (
|
|
23
|
-
parseWithSourceMap: (
|
|
24
|
-
parseSequence: (
|
|
22
|
+
parse: (input: string | Uint8Array, options?: ParseOptions) => ParseResult;
|
|
23
|
+
parseWithSourceMap: (input: string | Uint8Array, options?: ParseOptions) => ParseResultWithMap;
|
|
24
|
+
parseSequence: (input: string | Uint8Array, options?: ParseOptions) => CborValue[];
|
|
25
25
|
parseSequenceWithSourceMap: (hexString: string, options?: ParseOptions) => {
|
|
26
26
|
values: CborValue[];
|
|
27
27
|
sourceMaps: SourceMapEntry[][];
|
|
@@ -47,6 +47,7 @@ declare function useCborParser(): {
|
|
|
47
47
|
*/
|
|
48
48
|
declare function useCborInteger(): {
|
|
49
49
|
parseInteger: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
50
|
+
parseIntegerFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions) => ParseResult;
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -112,9 +113,10 @@ declare function useCborCollection(): {
|
|
|
112
113
|
* ```
|
|
113
114
|
*/
|
|
114
115
|
declare function useCborFloat(): {
|
|
115
|
-
parse: (hexString: string,
|
|
116
|
-
parseFloat: (hexString: string,
|
|
116
|
+
parse: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
117
|
+
parseFloat: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
117
118
|
parseSimple: (hexString: string, _options?: ParseOptions) => ParseResult;
|
|
119
|
+
parseFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions) => ParseResult;
|
|
118
120
|
};
|
|
119
121
|
|
|
120
122
|
/**
|
|
@@ -137,6 +139,9 @@ declare function useCborFloat(): {
|
|
|
137
139
|
declare function useCborTag(): {
|
|
138
140
|
parseTag: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
139
141
|
parse: (hexString: string, options?: ParseOptions) => ParseResult;
|
|
142
|
+
parseTagFromBuffer: (buffer: Uint8Array, offset: number, options?: ParseOptions, tagDepth?: number) => ParseResult;
|
|
143
|
+
validateTagSemantics: (tagNumber: number, value: CborValue, options?: ParseOptions) => void;
|
|
144
|
+
decodePlutusConstructor: (tagNumber: number, value: CborValue) => PlutusConstr | null;
|
|
140
145
|
};
|
|
141
146
|
|
|
142
147
|
export { useCborInteger as a, useCborString as b, useCborCollection as c, useCborFloat as d, useCborTag as e, useCborParser as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcuspuchalla/nachos",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "NACHOS - Not Another CBOR Handling Object System. RFC 8949 CBOR encoder/decoder with full source map support for interactive debugging. Zero dependencies, TypeScript, works in Node.js and browsers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nachos",
|
|
@@ -123,6 +123,14 @@ describe('Public API - Functional Encode', () => {
|
|
|
123
123
|
expect(result.hex).toBe('010203')
|
|
124
124
|
expect(result.bytes).toEqual(new Uint8Array([0x01, 0x02, 0x03]))
|
|
125
125
|
})
|
|
126
|
+
|
|
127
|
+
it('encode() should preserve -0', () => {
|
|
128
|
+
const result = encode(-0)
|
|
129
|
+
expect(result.hex).toBe('f98000')
|
|
130
|
+
|
|
131
|
+
const decoded = decode(result.hex)
|
|
132
|
+
expect(Object.is(decoded.value, -0)).toBe(true)
|
|
133
|
+
})
|
|
126
134
|
})
|
|
127
135
|
|
|
128
136
|
describe('Public API - Diagnostic Notation', () => {
|
|
@@ -277,6 +285,151 @@ describe('Public API - Utilities', () => {
|
|
|
277
285
|
})
|
|
278
286
|
})
|
|
279
287
|
|
|
288
|
+
describe('Public API - Uint8Array Decode', () => {
|
|
289
|
+
it('decode() should accept Uint8Array input for integers', () => {
|
|
290
|
+
const result = decode(new Uint8Array([0x18, 0x64]))
|
|
291
|
+
expect(result.value).toBe(100)
|
|
292
|
+
expect(result.bytesRead).toBe(2)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it('decode() should accept Uint8Array for small integers', () => {
|
|
296
|
+
const result = decode(new Uint8Array([0x01]))
|
|
297
|
+
expect(result.value).toBe(1)
|
|
298
|
+
expect(result.bytesRead).toBe(1)
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
it('decode(Uint8Array) should produce identical results to decode(hexString)', () => {
|
|
302
|
+
// Integer 100
|
|
303
|
+
const hexResult = decode('1864')
|
|
304
|
+
const bytesResult = decode(new Uint8Array([0x18, 0x64]))
|
|
305
|
+
expect(bytesResult.value).toEqual(hexResult.value)
|
|
306
|
+
expect(bytesResult.bytesRead).toEqual(hexResult.bytesRead)
|
|
307
|
+
|
|
308
|
+
// String "IETF"
|
|
309
|
+
const hexStr = decode('6449455446')
|
|
310
|
+
const bytesStr = decode(new Uint8Array([0x64, 0x49, 0x45, 0x54, 0x46]))
|
|
311
|
+
expect(bytesStr.value).toEqual(hexStr.value)
|
|
312
|
+
expect(bytesStr.bytesRead).toEqual(hexStr.bytesRead)
|
|
313
|
+
|
|
314
|
+
// Array [1, 2, 3]
|
|
315
|
+
const hexArr = decode('83010203')
|
|
316
|
+
const bytesArr = decode(new Uint8Array([0x83, 0x01, 0x02, 0x03]))
|
|
317
|
+
expect(bytesArr.value).toEqual(hexArr.value)
|
|
318
|
+
expect(bytesArr.bytesRead).toEqual(hexArr.bytesRead)
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it('decode(Uint8Array) should enforce maxInputSize limit', () => {
|
|
322
|
+
const bytes = new Uint8Array([0x01])
|
|
323
|
+
// Should succeed with a large enough limit
|
|
324
|
+
expect(() => decode(bytes, { limits: { maxInputSize: 100 } })).not.toThrow()
|
|
325
|
+
|
|
326
|
+
// Should throw when bytes exceed the limit
|
|
327
|
+
const largeBytes = new Uint8Array(200)
|
|
328
|
+
largeBytes[0] = 0x01 // valid CBOR integer 1
|
|
329
|
+
expect(() => decode(largeBytes, { limits: { maxInputSize: 10 } })).toThrow(/exceeds limit/)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
it('decode(Uint8Array) should handle tagged values', () => {
|
|
333
|
+
// d87980 = tag 121, empty array
|
|
334
|
+
const result = decode(new Uint8Array([0xd8, 0x79, 0x80]))
|
|
335
|
+
expect(result.value).toMatchObject({ tag: 121, value: [] })
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('decode(Uint8Array) should handle maps', () => {
|
|
339
|
+
// a16161 01 = {"a": 1}
|
|
340
|
+
const result = decode(new Uint8Array([0xa1, 0x61, 0x61, 0x01]))
|
|
341
|
+
expect(result.bytesRead).toBe(4)
|
|
342
|
+
// Map with string key "a" -> 1
|
|
343
|
+
expect(result.value).toBeInstanceOf(Map)
|
|
344
|
+
expect((result.value as Map<string, number>).get('a')).toBe(1)
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
it('decode(Uint8Array) should handle boolean and null', () => {
|
|
348
|
+
expect(decode(new Uint8Array([0xf5])).value).toBe(true)
|
|
349
|
+
expect(decode(new Uint8Array([0xf4])).value).toBe(false)
|
|
350
|
+
expect(decode(new Uint8Array([0xf6])).value).toBe(null)
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('decode(Uint8Array) should reject empty Uint8Array', () => {
|
|
354
|
+
expect(() => decode(new Uint8Array([]))).toThrow()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('decode(Uint8Array) should accept options', () => {
|
|
358
|
+
const result = decode(new Uint8Array([0x18, 0x64]), { strict: true })
|
|
359
|
+
expect(result.value).toBe(100)
|
|
360
|
+
})
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
describe('Public API - Uint8Array DecodeWithSourceMap', () => {
|
|
364
|
+
it('decodeWithSourceMap() should accept Uint8Array input', () => {
|
|
365
|
+
// d87980 = tag 121, empty array
|
|
366
|
+
const result = decodeWithSourceMap(new Uint8Array([0xd8, 0x79, 0x80]))
|
|
367
|
+
expect(result.value).toMatchObject({ tag: 121, value: [] })
|
|
368
|
+
expect(result.sourceMap).toBeDefined()
|
|
369
|
+
expect(Array.isArray(result.sourceMap)).toBe(true)
|
|
370
|
+
expect(result.sourceMap.length).toBeGreaterThan(0)
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
it('decodeWithSourceMap(Uint8Array) should match hex string results', () => {
|
|
374
|
+
const hexResult = decodeWithSourceMap('d87980')
|
|
375
|
+
const bytesResult = decodeWithSourceMap(new Uint8Array([0xd8, 0x79, 0x80]))
|
|
376
|
+
expect(bytesResult.value).toEqual(hexResult.value)
|
|
377
|
+
expect(bytesResult.sourceMap.length).toBe(hexResult.sourceMap.length)
|
|
378
|
+
})
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
describe('Public API - Uint8Array CborDecoder Class', () => {
|
|
382
|
+
it('CborDecoder.decode() should accept Uint8Array', () => {
|
|
383
|
+
const decoder = new CborDecoder()
|
|
384
|
+
const result = decoder.decode(new Uint8Array([0x18, 0x64]))
|
|
385
|
+
expect(result.value).toBe(100)
|
|
386
|
+
expect(result.bytesRead).toBe(2)
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
it('CborDecoder.decodeWithSourceMap() should accept Uint8Array', () => {
|
|
390
|
+
const decoder = new CborDecoder()
|
|
391
|
+
const result = decoder.decodeWithSourceMap(new Uint8Array([0xd8, 0x79, 0x80]))
|
|
392
|
+
expect(result.value).toMatchObject({ tag: 121, value: [] })
|
|
393
|
+
expect(result.sourceMap).toBeDefined()
|
|
394
|
+
})
|
|
395
|
+
|
|
396
|
+
it('CborDecoder with options should work with Uint8Array', () => {
|
|
397
|
+
const decoder = new CborDecoder({ strict: true })
|
|
398
|
+
const result = decoder.decode(new Uint8Array([0x18, 0x64]))
|
|
399
|
+
expect(result.value).toBe(100)
|
|
400
|
+
})
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
describe('Public API - Uint8Array useCborParser', () => {
|
|
404
|
+
it('parse() should accept Uint8Array', () => {
|
|
405
|
+
const { parse } = useCborParser()
|
|
406
|
+
const result = parse(new Uint8Array([0x18, 0x64]))
|
|
407
|
+
expect(result.value).toBe(100)
|
|
408
|
+
expect(result.bytesRead).toBe(2)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('parseWithSourceMap() should accept Uint8Array', () => {
|
|
412
|
+
const { parseWithSourceMap } = useCborParser()
|
|
413
|
+
const result = parseWithSourceMap(new Uint8Array([0xd8, 0x79, 0x80]))
|
|
414
|
+
expect(result.value).toMatchObject({ tag: 121, value: [] })
|
|
415
|
+
expect(result.sourceMap).toBeDefined()
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
it('parseSequence() should accept Uint8Array', () => {
|
|
419
|
+
const { parseSequence } = useCborParser()
|
|
420
|
+
// Three separate integers: 1, 2, 3
|
|
421
|
+
const result = parseSequence(new Uint8Array([0x01, 0x02, 0x03]))
|
|
422
|
+
expect(result).toEqual([1, 2, 3])
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
it('parseSequence(Uint8Array) should match hex string results', () => {
|
|
426
|
+
const { parseSequence } = useCborParser()
|
|
427
|
+
const hexResult = parseSequence('010203')
|
|
428
|
+
const bytesResult = parseSequence(new Uint8Array([0x01, 0x02, 0x03]))
|
|
429
|
+
expect(bytesResult).toEqual(hexResult)
|
|
430
|
+
})
|
|
431
|
+
})
|
|
432
|
+
|
|
280
433
|
describe('Public API - Constants and Enums', () => {
|
|
281
434
|
it('DEFAULT_OPTIONS should be exported', () => {
|
|
282
435
|
expect(DEFAULT_OPTIONS).toBeDefined()
|