@marcuspuchalla/nachos 0.1.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +674 -0
  3. package/README.md +345 -0
  4. package/dist/chunk-2FUTHZQQ.cjs +755 -0
  5. package/dist/chunk-2FUTHZQQ.cjs.map +1 -0
  6. package/dist/chunk-2HBCILJS.cjs +2034 -0
  7. package/dist/chunk-2HBCILJS.cjs.map +1 -0
  8. package/dist/chunk-7CFYWHS6.js +742 -0
  9. package/dist/chunk-7CFYWHS6.js.map +1 -0
  10. package/dist/chunk-PD72MVTX.cjs +160 -0
  11. package/dist/chunk-PD72MVTX.cjs.map +1 -0
  12. package/dist/chunk-ZDZ2B5PE.js +149 -0
  13. package/dist/chunk-ZDZ2B5PE.js.map +1 -0
  14. package/dist/chunk-ZRPJUEIZ.js +2020 -0
  15. package/dist/chunk-ZRPJUEIZ.js.map +1 -0
  16. package/dist/encoder/index.cjs +57 -0
  17. package/dist/encoder/index.cjs.map +1 -0
  18. package/dist/encoder/index.d.cts +72 -0
  19. package/dist/encoder/index.d.ts +72 -0
  20. package/dist/encoder/index.js +4 -0
  21. package/dist/encoder/index.js.map +1 -0
  22. package/dist/index.cjs +606 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +494 -0
  25. package/dist/index.d.ts +494 -0
  26. package/dist/index.js +523 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/metafile-cjs.json +1 -0
  29. package/dist/metafile-esm.json +1 -0
  30. package/dist/parser/index.cjs +85 -0
  31. package/dist/parser/index.cjs.map +1 -0
  32. package/dist/parser/index.d.cts +72 -0
  33. package/dist/parser/index.d.ts +72 -0
  34. package/dist/parser/index.js +4 -0
  35. package/dist/parser/index.js.map +1 -0
  36. package/dist/types-DvNlfbKB.d.cts +301 -0
  37. package/dist/types-DvNlfbKB.d.ts +301 -0
  38. package/dist/useCborSimpleEncoder-ButVU988.d.cts +268 -0
  39. package/dist/useCborSimpleEncoder-TVxzNJ_9.d.ts +268 -0
  40. package/dist/useCborTag-B_iaShG6.d.ts +142 -0
  41. package/dist/useCborTag-BfTIV8HM.d.cts +142 -0
  42. package/package.json +102 -0
  43. package/src/__tests__/public-api.test.ts +326 -0
  44. package/src/encoder/__tests__/cbor-collection-encoder.test.ts +331 -0
  45. package/src/encoder/__tests__/cbor-integer-encoder.test.ts +283 -0
  46. package/src/encoder/__tests__/cbor-simple-encoder.test.ts +224 -0
  47. package/src/encoder/__tests__/cbor-string-encoder.test.ts +345 -0
  48. package/src/encoder/__tests__/cbor-tag-encoder.test.ts +565 -0
  49. package/src/encoder/composables/#useCborTagEncoder.ts# +158 -0
  50. package/src/encoder/composables/useCborCollectionEncoder.ts +424 -0
  51. package/src/encoder/composables/useCborEncoder.ts +203 -0
  52. package/src/encoder/composables/useCborIntegerEncoder.ts +188 -0
  53. package/src/encoder/composables/useCborSimpleEncoder.ts +266 -0
  54. package/src/encoder/composables/useCborStringEncoder.ts +266 -0
  55. package/src/encoder/composables/useCborTagEncoder.ts +158 -0
  56. package/src/encoder/index.ts +35 -0
  57. package/src/encoder/types.ts +88 -0
  58. package/src/encoder/utils.ts +80 -0
  59. package/src/index.ts +434 -0
  60. package/src/parser/__tests__/ast-tree-structure.test.ts +311 -0
  61. package/src/parser/__tests__/cbor-collection-errors.test.ts +296 -0
  62. package/src/parser/__tests__/cbor-collection.test.ts +369 -0
  63. package/src/parser/__tests__/cbor-deterministic-encoding.test.ts +432 -0
  64. package/src/parser/__tests__/cbor-diagnostic.test.ts +333 -0
  65. package/src/parser/__tests__/cbor-duplicate-keys.test.ts +235 -0
  66. package/src/parser/__tests__/cbor-float-errors.test.ts +222 -0
  67. package/src/parser/__tests__/cbor-float.test.ts +502 -0
  68. package/src/parser/__tests__/cbor-integer-errors.test.ts +139 -0
  69. package/src/parser/__tests__/cbor-integer.test.ts +200 -0
  70. package/src/parser/__tests__/cbor-map-duplicate-keys.test.ts +403 -0
  71. package/src/parser/__tests__/cbor-parser-errors.test.ts +126 -0
  72. package/src/parser/__tests__/cbor-security-dos-protection.test.ts +503 -0
  73. package/src/parser/__tests__/cbor-sequences.test.ts +150 -0
  74. package/src/parser/__tests__/cbor-source-map.test.ts +321 -0
  75. package/src/parser/__tests__/cbor-standard-tags.test.ts +340 -0
  76. package/src/parser/__tests__/cbor-string-errors.test.ts +227 -0
  77. package/src/parser/__tests__/cbor-string.test.ts +224 -0
  78. package/src/parser/__tests__/cbor-tag-advanced.test.ts +500 -0
  79. package/src/parser/__tests__/cbor-tag-errors.test.ts +447 -0
  80. package/src/parser/__tests__/cbor-tag-source-map.test.ts +360 -0
  81. package/src/parser/__tests__/cbor-tag.test.ts +684 -0
  82. package/src/parser/__tests__/extreme-edge-cases.test.ts +146 -0
  83. package/src/parser/__tests__/pathBuilder.test.ts +256 -0
  84. package/src/parser/__tests__/rfc-test-vectors.test.ts +607 -0
  85. package/src/parser/__tests__/security-limits.test.ts +248 -0
  86. package/src/parser/__tests__/utils-errors.test.ts +127 -0
  87. package/src/parser/composables/useCborCollection.ts +509 -0
  88. package/src/parser/composables/useCborDiagnostic.ts +381 -0
  89. package/src/parser/composables/useCborFloat.ts +256 -0
  90. package/src/parser/composables/useCborInteger.ts +114 -0
  91. package/src/parser/composables/useCborParser.ts +951 -0
  92. package/src/parser/composables/useCborString.ts +330 -0
  93. package/src/parser/composables/useCborStringTypes.ts +129 -0
  94. package/src/parser/composables/useCborTag.ts +739 -0
  95. package/src/parser/index.ts +56 -0
  96. package/src/parser/types.ts +371 -0
  97. package/src/parser/utils/pathBuilder.ts +259 -0
  98. package/src/parser/utils.ts +398 -0
  99. package/src/utils/__tests__/logger.test.ts +186 -0
  100. package/src/utils/logger.ts +96 -0
@@ -0,0 +1,268 @@
1
+ import { h as PlutusConstr, s as CborByteString, t as CborTextString } from './types-DvNlfbKB.js';
2
+
3
+ /**
4
+ * CBOR Encoder Type Definitions
5
+ * Following RFC 8949 specification
6
+ */
7
+
8
+ /**
9
+ * Encoder options for controlling behavior
10
+ */
11
+ interface EncodeOptions {
12
+ /** Enable canonical encoding (shortest form, sorted maps) */
13
+ canonical?: boolean;
14
+ /** Allow indefinite-length encoding (false in canonical mode) */
15
+ allowIndefinite?: boolean;
16
+ /** Reject duplicate map keys */
17
+ rejectDuplicateKeys?: boolean;
18
+ /** Maximum nesting depth */
19
+ maxDepth?: number;
20
+ /** Maximum output size in bytes */
21
+ maxOutputSize?: number;
22
+ }
23
+ /**
24
+ * Default encode options
25
+ */
26
+ declare const DEFAULT_ENCODE_OPTIONS: Required<EncodeOptions>;
27
+ /**
28
+ * Result of encoding operation
29
+ */
30
+ interface EncodeResult {
31
+ /** Encoded CBOR bytes */
32
+ bytes: Uint8Array;
33
+ /** Hex string representation */
34
+ hex: string;
35
+ }
36
+ /**
37
+ * Values that can be encoded to CBOR
38
+ *
39
+ * Supports both plain objects (for convenience) and Maps (for type preservation).
40
+ * Map<any, any> is preferred for maps with non-string keys (integers, Uint8Arrays, etc.)
41
+ */
42
+ type EncodableValue = number | bigint | string | boolean | null | undefined | Uint8Array | EncodableValue[] | {
43
+ [key: string]: EncodableValue;
44
+ } | Map<EncodableValue, EncodableValue> | TaggedValue;
45
+ /**
46
+ * Tagged CBOR value (Major Type 6)
47
+ */
48
+ interface TaggedValue {
49
+ tag: number;
50
+ value: EncodableValue;
51
+ plutus?: PlutusConstr;
52
+ }
53
+ /**
54
+ * Encoding context that tracks state during CBOR encoding
55
+ */
56
+ interface EncodeContext {
57
+ /** Current nesting depth */
58
+ depth: number;
59
+ /** Bytes written so far */
60
+ bytesWritten: number;
61
+ /** Encoder options */
62
+ options: Required<EncodeOptions>;
63
+ }
64
+
65
+ /**
66
+ * Main CBOR Encoder Composable
67
+ * High-level API for encoding JavaScript values to CBOR
68
+ * Following RFC 8949 specification
69
+ */
70
+
71
+ /**
72
+ * Main CBOR Encoder Composable
73
+ *
74
+ * Provides a unified interface for encoding any JavaScript value to CBOR.
75
+ * Automatically selects the appropriate encoder based on value type.
76
+ *
77
+ * @param options - Global encoder options
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const { encode } = useCborEncoder()
82
+ *
83
+ * // Encode various types
84
+ * encode(42) // Integer
85
+ * encode("hello") // Text string
86
+ * encode([1, 2, 3]) // Array
87
+ * encode({ a: 1 }) // Map
88
+ * encode(true) // Boolean
89
+ * encode(3.14) // Float
90
+ * encode(new Uint8Array([0xff])) // Byte string
91
+ *
92
+ * // With options
93
+ * const { encode: encodeCanonical } = useCborEncoder({ canonical: true })
94
+ * encodeCanonical({ z: 1, a: 2 }) // Keys will be sorted
95
+ * ```
96
+ */
97
+ declare function useCborEncoder(globalOptions?: Partial<EncodeOptions>): {
98
+ encode: (value: EncodableValue) => EncodeResult;
99
+ encodeToHex: (value: EncodableValue) => string;
100
+ encodeToBytes: (value: EncodableValue) => Uint8Array;
101
+ encodeSequence: (values: EncodableValue[]) => EncodeResult;
102
+ };
103
+
104
+ /**
105
+ * CBOR Integer Encoder Composable
106
+ * Handles Major Type 0 (Unsigned) and Major Type 1 (Negative)
107
+ * Following RFC 8949 specification
108
+ */
109
+
110
+ /**
111
+ * CBOR Integer Encoder Composable
112
+ *
113
+ * Provides functions to encode integers to CBOR format:
114
+ * - Major Type 0: Unsigned integers (0 to 2^64-1)
115
+ * - Major Type 1: Negative integers (-1 to -2^64)
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const { encodeUnsignedInt, encodeNegativeInt, encodeInteger } = useCborIntegerEncoder()
120
+ *
121
+ * // Encode unsigned integer
122
+ * const result1 = encodeUnsignedInt(100)
123
+ * // result1: { bytes: Uint8Array([0x18, 0x64]), hex: '1864' }
124
+ *
125
+ * // Encode negative integer
126
+ * const result2 = encodeNegativeInt(-100)
127
+ * // result2: { bytes: Uint8Array([0x38, 0x63]), hex: '3863' }
128
+ *
129
+ * // Auto-detect integer type
130
+ * const result3 = encodeInteger(-100)
131
+ * // result3: { bytes: Uint8Array([0x38, 0x63]), hex: '3863' }
132
+ * ```
133
+ */
134
+ declare function useCborIntegerEncoder(): {
135
+ encodeUnsignedInt: (value: number | bigint) => EncodeResult;
136
+ encodeNegativeInt: (value: number | bigint) => EncodeResult;
137
+ encodeInteger: (value: number | bigint) => EncodeResult;
138
+ };
139
+
140
+ /**
141
+ * CBOR String Encoder Composable
142
+ * Handles Major Type 2 (Byte Strings) and Major Type 3 (Text Strings)
143
+ * Following RFC 8949 specification
144
+ */
145
+
146
+ interface StringEncodeOptions {
147
+ indefinite?: boolean;
148
+ }
149
+ /**
150
+ * CBOR String Encoder Composable
151
+ *
152
+ * Provides functions to encode byte strings and text strings:
153
+ * - Major Type 2: Byte strings (Uint8Array)
154
+ * - Major Type 3: Text strings (UTF-8 encoded)
155
+ *
156
+ * Supports both definite-length and indefinite-length encoding.
157
+ *
158
+ * @param options - Global encoder options
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * const { encodeByteString, encodeTextString } = useCborStringEncoder()
163
+ *
164
+ * // Encode byte string
165
+ * const bytes = new Uint8Array([0x01, 0x02, 0x03])
166
+ * const result1 = encodeByteString(bytes)
167
+ * // result1: { bytes: Uint8Array([0x43, 0x01, 0x02, 0x03]), hex: '43010203' }
168
+ *
169
+ * // Encode text string
170
+ * const result2 = encodeTextString('Hello')
171
+ * // result2: { bytes: Uint8Array([0x65, 0x48, 0x65, 0x6c, 0x6c, 0x6f]), hex: '6548656c6c6f' }
172
+ *
173
+ * // Indefinite-length encoding
174
+ * const chunks = [new Uint8Array([0xaa]), new Uint8Array([0xbb])]
175
+ * const result3 = encodeByteStringIndefinite(chunks)
176
+ * // result3: { bytes: Uint8Array([0x5f, 0x41, 0xaa, 0x41, 0xbb, 0xff]), hex: '5f41aa41bbff' }
177
+ * ```
178
+ */
179
+ declare function useCborStringEncoder(globalOptions?: Partial<EncodeOptions>): {
180
+ encodeByteString: (data: Uint8Array | Uint8Array[] | CborByteString, encodeOptions?: StringEncodeOptions) => EncodeResult;
181
+ encodeByteStringIndefinite: (chunks: Uint8Array[]) => EncodeResult;
182
+ encodeTextString: (text: string | CborTextString, encodeOptions?: StringEncodeOptions) => EncodeResult;
183
+ encodeTextStringIndefinite: (chunks: string[]) => EncodeResult;
184
+ };
185
+
186
+ /**
187
+ * CBOR Collection Encoder Composable
188
+ * Handles Major Type 4 (Arrays) and Major Type 5 (Maps)
189
+ * Following RFC 8949 specification
190
+ */
191
+
192
+ interface CollectionEncodeOptions {
193
+ indefinite?: boolean;
194
+ }
195
+ /**
196
+ * CBOR Collection Encoder Composable
197
+ *
198
+ * Provides functions to encode arrays and maps:
199
+ * - Major Type 4: Arrays
200
+ * - Major Type 5: Maps (objects or Map instances)
201
+ *
202
+ * Supports both definite-length and indefinite-length encoding.
203
+ * Handles canonical encoding with sorted map keys.
204
+ * Enforces depth and size limits.
205
+ *
206
+ * @param options - Global encoder options
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const { encodeArray, encodeMap } = useCborCollectionEncoder()
211
+ *
212
+ * // Encode array
213
+ * const arr = [1, 2, 3]
214
+ * const result1 = encodeArray(arr)
215
+ * // result1: { bytes: Uint8Array([0x83, 0x01, 0x02, 0x03]), hex: '83010203' }
216
+ *
217
+ * // Encode map
218
+ * const map = { amount: 1000000 }
219
+ * const result2 = encodeMap(map)
220
+ * // result2: { bytes: ..., hex: 'a166616d6f756e741a000f4240' }
221
+ * ```
222
+ */
223
+ declare function useCborCollectionEncoder(globalOptions?: Partial<EncodeOptions>): {
224
+ encodeArray: (array: EncodableValue[], encodeOptions?: CollectionEncodeOptions) => EncodeResult;
225
+ encodeArrayIndefinite: (array: EncodableValue[]) => EncodeResult;
226
+ encodeMap: (map: Map<EncodableValue, EncodableValue> | {
227
+ [key: string]: EncodableValue;
228
+ }, encodeOptions?: CollectionEncodeOptions) => EncodeResult;
229
+ encodeMapIndefinite: (map: Map<EncodableValue, EncodableValue> | {
230
+ [key: string]: EncodableValue;
231
+ }) => EncodeResult;
232
+ setMainEncode: (encodeFn: (value: EncodableValue) => EncodeResult) => void;
233
+ };
234
+
235
+ /**
236
+ * CBOR Simple Values and Floats Encoder Composable
237
+ * Handles Major Type 7 (Floats and Simple Values)
238
+ * Following RFC 8949 specification
239
+ */
240
+
241
+ /**
242
+ * CBOR Simple Values and Floats Encoder Composable
243
+ *
244
+ * Provides functions to encode:
245
+ * - Simple values: false, true, null, undefined
246
+ * - Floating-point numbers: float16, float32, float64
247
+ *
248
+ * @param options - Global encoder options
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * const { encodeSimple, encodeFloat } = useCborSimpleEncoder()
253
+ *
254
+ * // Encode simple values
255
+ * const result1 = encodeSimple(true)
256
+ * // result1: { bytes: Uint8Array([0xf5]), hex: 'f5' }
257
+ *
258
+ * // Encode float
259
+ * const result2 = encodeFloat(1.1)
260
+ * // result2: { bytes: Uint8Array([0xfb, ...]), hex: 'fb...' }
261
+ * ```
262
+ */
263
+ declare function useCborSimpleEncoder(_globalOptions?: Partial<EncodeOptions>): {
264
+ encodeSimple: (value: boolean | null | undefined) => EncodeResult;
265
+ encodeFloat: (value: number, precision?: 16 | 32 | 64) => EncodeResult;
266
+ };
267
+
268
+ export { DEFAULT_ENCODE_OPTIONS as D, type EncodableValue as E, type TaggedValue as T, type EncodeOptions as a, type EncodeResult as b, useCborIntegerEncoder as c, useCborStringEncoder as d, useCborCollectionEncoder as e, useCborSimpleEncoder as f, type EncodeContext as g, useCborEncoder as u };
@@ -0,0 +1,142 @@
1
+ import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry } from './types-DvNlfbKB.js';
2
+
3
+ /**
4
+ * CBOR Main Parser Composable
5
+ * Orchestrates all CBOR parsers and provides a unified parse interface
6
+ * Auto-detects major type and dispatches to appropriate parser
7
+ */
8
+
9
+ /**
10
+ * Main CBOR parser composable
11
+ * Provides a unified interface for parsing any CBOR data
12
+ *
13
+ * @returns Object with parse function
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const { parse } = useCborParser()
18
+ * const result = parse('1864') // { value: 100, bytesRead: 2 }
19
+ * ```
20
+ */
21
+ declare function useCborParser(): {
22
+ parse: (hexString: string, options?: ParseOptions) => ParseResult;
23
+ parseWithSourceMap: (hexString: string, options?: ParseOptions) => ParseResultWithMap;
24
+ parseSequence: (hexString: string, options?: ParseOptions) => CborValue[];
25
+ parseSequenceWithSourceMap: (hexString: string, options?: ParseOptions) => {
26
+ values: CborValue[];
27
+ sourceMaps: SourceMapEntry[][];
28
+ };
29
+ };
30
+
31
+ /**
32
+ * CBOR Integer Parser Composable
33
+ * Handles Major Types 0 (Unsigned) and 1 (Negative)
34
+ * Supports BigInt for 64-bit values outside Number.MAX_SAFE_INTEGER
35
+ */
36
+
37
+ /**
38
+ * Composable for parsing CBOR integers (Major Types 0 and 1)
39
+ *
40
+ * @returns Object with parseInteger function
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const { parseInteger } = useCborInteger()
45
+ * const result = parseInteger('1864') // 100
46
+ * ```
47
+ */
48
+ declare function useCborInteger(): {
49
+ parseInteger: (hexString: string, options?: ParseOptions) => ParseResult;
50
+ };
51
+
52
+ /**
53
+ * CBOR String Parser Composable
54
+ * Handles Major Types 2 (Byte Strings) and 3 (Text Strings)
55
+ * Supports definite and indefinite length encoding
56
+ */
57
+
58
+ /**
59
+ * Composable for parsing CBOR strings (Major Types 2 and 3)
60
+ *
61
+ * @returns Object with string parsing functions
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const { parseString } = useCborString()
66
+ * const result = parseString('6449455446') // "IETF"
67
+ * ```
68
+ */
69
+ declare function useCborString(): {
70
+ parseString: (hexString: string, options?: ParseOptions) => ParseResult;
71
+ parseByteString: (buffer: Uint8Array, offset?: number, options?: ParseOptions) => ParseResult;
72
+ parseTextString: (buffer: Uint8Array, offset?: number, options?: ParseOptions) => ParseResult;
73
+ };
74
+
75
+ /**
76
+ * CBOR Collection Parser Composable
77
+ * Handles Major Types 4 (Arrays) and 5 (Maps)
78
+ * Supports definite and indefinite length encoding
79
+ */
80
+
81
+ /**
82
+ * Composable for parsing CBOR collections (Major Types 4 and 5)
83
+ *
84
+ * @returns Object with parseArray and parseMap functions
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const { parseArray } = useCborCollection()
89
+ * const result = parseArray('83010203') // [1, 2, 3]
90
+ * ```
91
+ */
92
+ declare function useCborCollection(): {
93
+ parseArray: (hexString: string, options?: ParseOptions) => ParseResult;
94
+ parseMap: (hexString: string, options?: ParseOptions) => ParseResult;
95
+ };
96
+
97
+ /**
98
+ * CBOR Float and Simple Values Parser Composable
99
+ * Handles Major Type 7 (Simple Values and Floats)
100
+ * Supports Float16, Float32, Float64, and simple values (true, false, null, undefined)
101
+ */
102
+
103
+ /**
104
+ * Composable for parsing CBOR floats and simple values (Major Type 7)
105
+ *
106
+ * @returns Object with parse, parseFloat, and parseSimple functions
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const { parse } = useCborFloat()
111
+ * const result = parse('f5') // true
112
+ * ```
113
+ */
114
+ declare function useCborFloat(): {
115
+ parse: (hexString: string, _options?: ParseOptions) => ParseResult;
116
+ parseFloat: (hexString: string, _options?: ParseOptions) => ParseResult;
117
+ parseSimple: (hexString: string, _options?: ParseOptions) => ParseResult;
118
+ };
119
+
120
+ /**
121
+ * CBOR Tag Parser Composable
122
+ * Handles Major Type 6 (Semantic Tags)
123
+ * Supports standard tags (0-5), encoding hints (21-36), self-describe (55799), and Cardano tags
124
+ */
125
+
126
+ /**
127
+ * Composable for parsing CBOR tags (Major Type 6)
128
+ *
129
+ * @returns Object with parseTag and parse functions
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const { parseTag } = useCborTag()
134
+ * const result = parseTag('c11a514b67b0') // 1(1363896240) - epoch timestamp
135
+ * ```
136
+ */
137
+ declare function useCborTag(): {
138
+ parseTag: (hexString: string, options?: ParseOptions) => ParseResult;
139
+ parse: (hexString: string, options?: ParseOptions) => ParseResult;
140
+ };
141
+
142
+ export { useCborInteger as a, useCborString as b, useCborCollection as c, useCborFloat as d, useCborTag as e, useCborParser as u };
@@ -0,0 +1,142 @@
1
+ import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap, e as CborValue, S as SourceMapEntry } from './types-DvNlfbKB.cjs';
2
+
3
+ /**
4
+ * CBOR Main Parser Composable
5
+ * Orchestrates all CBOR parsers and provides a unified parse interface
6
+ * Auto-detects major type and dispatches to appropriate parser
7
+ */
8
+
9
+ /**
10
+ * Main CBOR parser composable
11
+ * Provides a unified interface for parsing any CBOR data
12
+ *
13
+ * @returns Object with parse function
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const { parse } = useCborParser()
18
+ * const result = parse('1864') // { value: 100, bytesRead: 2 }
19
+ * ```
20
+ */
21
+ declare function useCborParser(): {
22
+ parse: (hexString: string, options?: ParseOptions) => ParseResult;
23
+ parseWithSourceMap: (hexString: string, options?: ParseOptions) => ParseResultWithMap;
24
+ parseSequence: (hexString: string, options?: ParseOptions) => CborValue[];
25
+ parseSequenceWithSourceMap: (hexString: string, options?: ParseOptions) => {
26
+ values: CborValue[];
27
+ sourceMaps: SourceMapEntry[][];
28
+ };
29
+ };
30
+
31
+ /**
32
+ * CBOR Integer Parser Composable
33
+ * Handles Major Types 0 (Unsigned) and 1 (Negative)
34
+ * Supports BigInt for 64-bit values outside Number.MAX_SAFE_INTEGER
35
+ */
36
+
37
+ /**
38
+ * Composable for parsing CBOR integers (Major Types 0 and 1)
39
+ *
40
+ * @returns Object with parseInteger function
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const { parseInteger } = useCborInteger()
45
+ * const result = parseInteger('1864') // 100
46
+ * ```
47
+ */
48
+ declare function useCborInteger(): {
49
+ parseInteger: (hexString: string, options?: ParseOptions) => ParseResult;
50
+ };
51
+
52
+ /**
53
+ * CBOR String Parser Composable
54
+ * Handles Major Types 2 (Byte Strings) and 3 (Text Strings)
55
+ * Supports definite and indefinite length encoding
56
+ */
57
+
58
+ /**
59
+ * Composable for parsing CBOR strings (Major Types 2 and 3)
60
+ *
61
+ * @returns Object with string parsing functions
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const { parseString } = useCborString()
66
+ * const result = parseString('6449455446') // "IETF"
67
+ * ```
68
+ */
69
+ declare function useCborString(): {
70
+ parseString: (hexString: string, options?: ParseOptions) => ParseResult;
71
+ parseByteString: (buffer: Uint8Array, offset?: number, options?: ParseOptions) => ParseResult;
72
+ parseTextString: (buffer: Uint8Array, offset?: number, options?: ParseOptions) => ParseResult;
73
+ };
74
+
75
+ /**
76
+ * CBOR Collection Parser Composable
77
+ * Handles Major Types 4 (Arrays) and 5 (Maps)
78
+ * Supports definite and indefinite length encoding
79
+ */
80
+
81
+ /**
82
+ * Composable for parsing CBOR collections (Major Types 4 and 5)
83
+ *
84
+ * @returns Object with parseArray and parseMap functions
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const { parseArray } = useCborCollection()
89
+ * const result = parseArray('83010203') // [1, 2, 3]
90
+ * ```
91
+ */
92
+ declare function useCborCollection(): {
93
+ parseArray: (hexString: string, options?: ParseOptions) => ParseResult;
94
+ parseMap: (hexString: string, options?: ParseOptions) => ParseResult;
95
+ };
96
+
97
+ /**
98
+ * CBOR Float and Simple Values Parser Composable
99
+ * Handles Major Type 7 (Simple Values and Floats)
100
+ * Supports Float16, Float32, Float64, and simple values (true, false, null, undefined)
101
+ */
102
+
103
+ /**
104
+ * Composable for parsing CBOR floats and simple values (Major Type 7)
105
+ *
106
+ * @returns Object with parse, parseFloat, and parseSimple functions
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const { parse } = useCborFloat()
111
+ * const result = parse('f5') // true
112
+ * ```
113
+ */
114
+ declare function useCborFloat(): {
115
+ parse: (hexString: string, _options?: ParseOptions) => ParseResult;
116
+ parseFloat: (hexString: string, _options?: ParseOptions) => ParseResult;
117
+ parseSimple: (hexString: string, _options?: ParseOptions) => ParseResult;
118
+ };
119
+
120
+ /**
121
+ * CBOR Tag Parser Composable
122
+ * Handles Major Type 6 (Semantic Tags)
123
+ * Supports standard tags (0-5), encoding hints (21-36), self-describe (55799), and Cardano tags
124
+ */
125
+
126
+ /**
127
+ * Composable for parsing CBOR tags (Major Type 6)
128
+ *
129
+ * @returns Object with parseTag and parse functions
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const { parseTag } = useCborTag()
134
+ * const result = parseTag('c11a514b67b0') // 1(1363896240) - epoch timestamp
135
+ * ```
136
+ */
137
+ declare function useCborTag(): {
138
+ parseTag: (hexString: string, options?: ParseOptions) => ParseResult;
139
+ parse: (hexString: string, options?: ParseOptions) => ParseResult;
140
+ };
141
+
142
+ export { useCborInteger as a, useCborString as b, useCborCollection as c, useCborFloat as d, useCborTag as e, useCborParser as u };
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@marcuspuchalla/nachos",
3
+ "version": "0.1.0",
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
+ "keywords": [
6
+ "nachos",
7
+ "cbor",
8
+ "codec",
9
+ "encoder",
10
+ "decoder",
11
+ "rfc8949",
12
+ "serialization",
13
+ "deserialization",
14
+ "cardano",
15
+ "blockchain",
16
+ "plutus",
17
+ "binary",
18
+ "parser",
19
+ "source-map",
20
+ "typescript",
21
+ "zero-dependencies"
22
+ ],
23
+ "author": "Marcus Puchalla",
24
+ "license": "GPL-3.0",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/marcuspuchalla/nachos.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/marcuspuchalla/nachos/issues"
31
+ },
32
+ "homepage": "https://github.com/marcuspuchalla/nachos#readme",
33
+ "type": "module",
34
+ "main": "./dist/index.cjs",
35
+ "module": "./dist/index.js",
36
+ "types": "./dist/index.d.ts",
37
+ "exports": {
38
+ ".": {
39
+ "import": {
40
+ "types": "./dist/index.d.ts",
41
+ "default": "./dist/index.js"
42
+ },
43
+ "require": {
44
+ "types": "./dist/index.d.ts",
45
+ "default": "./dist/index.cjs"
46
+ }
47
+ },
48
+ "./parser": {
49
+ "import": {
50
+ "types": "./dist/parser/index.d.ts",
51
+ "default": "./dist/parser/index.js"
52
+ },
53
+ "require": {
54
+ "types": "./dist/parser/index.d.ts",
55
+ "default": "./dist/parser/index.cjs"
56
+ }
57
+ },
58
+ "./encoder": {
59
+ "import": {
60
+ "types": "./dist/encoder/index.d.ts",
61
+ "default": "./dist/encoder/index.js"
62
+ },
63
+ "require": {
64
+ "types": "./dist/encoder/index.d.ts",
65
+ "default": "./dist/encoder/index.cjs"
66
+ }
67
+ },
68
+ "./package.json": "./package.json"
69
+ },
70
+ "files": [
71
+ "dist",
72
+ "src",
73
+ "README.md",
74
+ "LICENSE",
75
+ "CHANGELOG.md"
76
+ ],
77
+ "scripts": {
78
+ "build": "tsup",
79
+ "build:watch": "tsup --watch",
80
+ "type-check": "tsc --noEmit",
81
+ "test": "vitest run",
82
+ "test:watch": "vitest",
83
+ "test:coverage": "vitest run --coverage",
84
+ "lint": "eslint src --ext .ts",
85
+ "format": "prettier --write \"src/**/*.ts\"",
86
+ "prepublishOnly": "npm run build && npm test"
87
+ },
88
+ "engines": {
89
+ "node": ">=18.0.0"
90
+ },
91
+ "devDependencies": {
92
+ "@types/node": "^20.0.0",
93
+ "@vitest/coverage-v8": "^2.1.8",
94
+ "tsup": "^8.0.0",
95
+ "typescript": "~5.6.3",
96
+ "vitest": "^2.1.8"
97
+ },
98
+ "sideEffects": false,
99
+ "publishConfig": {
100
+ "access": "public"
101
+ }
102
+ }