@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,494 @@
1
+ export { c as useCborCollection, d as useCborFloat, a as useCborInteger, u as useCborParser, b as useCborString, e as useCborTag } from './useCborTag-B_iaShG6.js';
2
+ import { E as EncodableValue, a as EncodeOptions, b as EncodeResult } from './useCborSimpleEncoder-TVxzNJ_9.js';
3
+ export { D as DEFAULT_ENCODE_OPTIONS, g as EncodeContext, e as useCborCollectionEncoder, u as useCborEncoder, c as useCborIntegerEncoder, f as useCborSimpleEncoder, d as useCborStringEncoder } from './useCborSimpleEncoder-TVxzNJ_9.js';
4
+ import { P as ParseOptions, a as ParseResult, b as ParseResultWithMap } from './types-DvNlfbKB.js';
5
+ export { o as CborAdditionalInfo, C as CborContext, n as CborMajorType, f as CborMap, p as CborSimpleValue, q as CborTag, e as CborValue, m as DEFAULT_LIMITS, D as DEFAULT_OPTIONS, c as ParseError, d as ParserLimits, l as PlutusBytes, h as PlutusConstr, g as PlutusData, k as PlutusInt, j as PlutusList, i as PlutusMap, R as Result, S as SourceMapEntry, T as TaggedValue } from './types-DvNlfbKB.js';
6
+
7
+ /**
8
+ * useCborDiagnostic - RFC 8949 Appendix B Diagnostic Notation
9
+ *
10
+ * Converts CBOR values to human-readable diagnostic notation as defined
11
+ * in RFC 8949 (Concise Binary Object Representation).
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const { toDiagnostic } = useCborDiagnostic()
16
+ *
17
+ * toDiagnostic(100) // "100"
18
+ * toDiagnostic(new Uint8Array([1,2])) // "h'0102'"
19
+ * toDiagnostic([1, 2, 3]) // "[1, 2, 3]"
20
+ * toDiagnostic({a: 1}) // '{"a": 1}'
21
+ * ```
22
+ */
23
+ /**
24
+ * Options for diagnostic notation output
25
+ */
26
+ interface DiagnosticOptions {
27
+ /** Pretty print with indentation (default: false) */
28
+ pretty?: boolean;
29
+ /** Indentation string for pretty printing (default: ' ') */
30
+ indent?: string;
31
+ /** Maximum depth for nested structures (default: 100) */
32
+ maxDepth?: number;
33
+ /** Mark as indefinite-length (default: false) */
34
+ indefinite?: boolean;
35
+ /** Show byte offsets as comments (default: false) */
36
+ showOffsets?: boolean;
37
+ }
38
+ /**
39
+ * Composable for CBOR diagnostic notation
40
+ */
41
+ declare function useCborDiagnostic(): {
42
+ toDiagnostic: (value: unknown, options?: DiagnosticOptions) => string;
43
+ fromDiagnostic: (diag: string) => unknown;
44
+ toDiagnosticWithType: (value: unknown, majorType: number, options?: DiagnosticOptions) => string;
45
+ };
46
+
47
+ /**
48
+ * PathBuilder - Utilities for creating and manipulating source map paths
49
+ *
50
+ * Path format follows JSON Pointer (RFC 6901) with CBOR-specific extensions:
51
+ * - Array indices: [0], [1], [2]
52
+ * - Object/Map keys: .key, .nested.key
53
+ * - Special markers: [#header], [#content], [#value]
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { PathBuilder } from './pathBuilder'
58
+ *
59
+ * const path = PathBuilder.arrayIndex('', 0) // "[0]"
60
+ * const nested = PathBuilder.arrayIndex(path, 1) // "[0][1]"
61
+ * const key = PathBuilder.mapKey(nested, 'amount') // "[0][1].amount"
62
+ * const header = PathBuilder.header(key) // "[0][1].amount[#header]"
63
+ * ```
64
+ */
65
+ /**
66
+ * PathBuilder utility object with methods for creating and manipulating paths
67
+ */
68
+ declare const PathBuilder: {
69
+ /**
70
+ * Create root path (empty string)
71
+ */
72
+ root: () => string;
73
+ /**
74
+ * Create path for array index
75
+ * @param parent - Parent path
76
+ * @param index - Array index (0-based)
77
+ * @returns Path string like "[0]" or "[0][1]"
78
+ */
79
+ arrayIndex: (parent: string, index: number) => string;
80
+ /**
81
+ * Create path for map/object key
82
+ * @param parent - Parent path
83
+ * @param key - Key name (string or number)
84
+ * @returns Path string like ".key" or "[0].key"
85
+ */
86
+ mapKey: (parent: string, key: string | number) => string;
87
+ /**
88
+ * Create path for map key by index (for non-string keys)
89
+ * @param parent - Parent path
90
+ * @param index - Key index in map
91
+ * @returns Path string like "[#key:0]"
92
+ */
93
+ mapKeyIndex: (parent: string, index: number) => string;
94
+ /**
95
+ * Create path for header portion of a value
96
+ * Used for byte strings, text strings, arrays, maps, tags
97
+ * @param parent - Parent path
98
+ * @returns Path string like "[0][#header]"
99
+ */
100
+ header: (parent: string) => string;
101
+ /**
102
+ * Create path for content portion of a value
103
+ * Used for byte strings and text strings
104
+ * @param parent - Parent path
105
+ * @returns Path string like "[0][#content]"
106
+ */
107
+ content: (parent: string) => string;
108
+ /**
109
+ * Create path for tagged value
110
+ * @param parent - Parent path
111
+ * @returns Path string like "[0][#value]"
112
+ */
113
+ tagValue: (parent: string) => string;
114
+ /**
115
+ * Normalize a path by removing special markers (#header, #content, #value)
116
+ * Used for matching paths across different representations
117
+ * @param path - Path to normalize
118
+ * @returns Normalized path without special markers
119
+ */
120
+ normalize: (path: string) => string;
121
+ /**
122
+ * Check if path is a header path
123
+ * @param path - Path to check
124
+ * @returns True if path ends with [#header]
125
+ */
126
+ isHeader: (path: string) => boolean;
127
+ /**
128
+ * Check if path is a content path
129
+ * @param path - Path to check
130
+ * @returns True if path ends with [#content]
131
+ */
132
+ isContent: (path: string) => boolean;
133
+ /**
134
+ * Check if path is a tag value path
135
+ * @param path - Path to check
136
+ * @returns True if path ends with [#value]
137
+ */
138
+ isTagValue: (path: string) => boolean;
139
+ /**
140
+ * Check if path has any special marker
141
+ * @param path - Path to check
142
+ * @returns True if path ends with any special marker
143
+ */
144
+ hasMarker: (path: string) => boolean;
145
+ /**
146
+ * Get parent path (one level up)
147
+ * @param path - Path to get parent of
148
+ * @returns Parent path or null if already at root
149
+ */
150
+ getParent: (path: string) => string | null;
151
+ /**
152
+ * Get the depth (nesting level) of a path
153
+ * @param path - Path to measure
154
+ * @returns Number indicating nesting depth (0 for root)
155
+ */
156
+ getDepth: (path: string) => number;
157
+ /**
158
+ * Parse a path into its components
159
+ * @param path - Path to parse
160
+ * @returns Array of path segments
161
+ */
162
+ parse: (path: string) => Array<{
163
+ type: "index" | "key" | "marker";
164
+ value: string | number;
165
+ }>;
166
+ /**
167
+ * Build a path from segments
168
+ * @param segments - Array of path segments
169
+ * @returns Path string
170
+ */
171
+ build: (segments: Array<{
172
+ type: "index" | "key" | "marker";
173
+ value: string | number;
174
+ }>) => string;
175
+ /**
176
+ * Join multiple path segments
177
+ * @param paths - Path segments to join
178
+ * @returns Combined path
179
+ */
180
+ join: (...paths: string[]) => string;
181
+ /**
182
+ * Check if a path is a descendant of another path
183
+ * @param path - Path to check
184
+ * @param ancestor - Potential ancestor path
185
+ * @returns True if path is a descendant of ancestor
186
+ */
187
+ isDescendantOf: (path: string, ancestor: string) => boolean;
188
+ };
189
+
190
+ /**
191
+ * NACHOS - Not Another CBOR Handling Object System
192
+ *
193
+ * RFC 8949 CBOR (Concise Binary Object Representation) encoder and decoder
194
+ * with full source map support for interactive debugging.
195
+ *
196
+ * @module @marcuspuchalla/nachos
197
+ * @see https://datatracker.ietf.org/doc/html/rfc8949
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Simple decoding
202
+ * import { decode } from '@marcuspuchalla/nachos'
203
+ * const result = decode('1864') // { value: 100, bytesRead: 2 }
204
+ *
205
+ * // Simple encoding
206
+ * import { encode } from '@marcuspuchalla/nachos'
207
+ * const { hex, bytes } = encode(100) // hex: "1864"
208
+ *
209
+ * // With source maps for debugging
210
+ * import { decodeWithSourceMap } from '@marcuspuchalla/nachos'
211
+ * const { value, sourceMap } = decodeWithSourceMap('d87980')
212
+ * // sourceMap links hex bytes to decoded values
213
+ * ```
214
+ */
215
+
216
+ /**
217
+ * Decode CBOR hex string to JavaScript value
218
+ *
219
+ * @param hexString - CBOR data as hex string (e.g., "1864" for integer 100)
220
+ * @param options - Optional parser configuration
221
+ * @returns Decoded value and number of bytes consumed
222
+ *
223
+ * @throws {Error} If input is invalid or malformed CBOR
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * // Decode integer
228
+ * decode('1864') // { value: 100, bytesRead: 2 }
229
+ *
230
+ * // Decode string
231
+ * decode('6449455446') // { value: "IETF", bytesRead: 5 }
232
+ *
233
+ * // Decode array
234
+ * decode('83010203') // { value: [1, 2, 3], bytesRead: 4 }
235
+ *
236
+ * // With strict validation
237
+ * decode('1864', { strict: true })
238
+ *
239
+ * // With canonical validation
240
+ * decode('a16161 01', { validateCanonical: true })
241
+ * ```
242
+ *
243
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8949 | RFC 8949}
244
+ */
245
+ declare function decode(hexString: string, options?: ParseOptions): ParseResult;
246
+ /**
247
+ * Decode CBOR hex string with source map generation
248
+ *
249
+ * Source maps provide bidirectional linking between hex bytes and decoded values,
250
+ * enabling interactive debugging visualizations.
251
+ *
252
+ * @param hexString - CBOR data as hex string
253
+ * @param options - Optional parser configuration
254
+ * @returns Decoded value, byte count, and source map
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const { value, sourceMap } = decodeWithSourceMap('d87980')
259
+ * // value: { tag: 121, value: [] }
260
+ * // sourceMap: [
261
+ * // { path: '', start: 0, end: 3, majorType: 6, type: 'Tag 121', children: ['.value'] },
262
+ * // { path: '.value', start: 2, end: 3, majorType: 4, type: 'Array', parent: '' }
263
+ * // ]
264
+ *
265
+ * // Use source map for hex-to-JSON linking
266
+ * const entry = sourceMap.find(e => e.path === '.value')
267
+ * console.log(`Value is at bytes ${entry.start}-${entry.end}`)
268
+ * ```
269
+ */
270
+ declare function decodeWithSourceMap(hexString: string, options?: ParseOptions): ParseResultWithMap;
271
+ /**
272
+ * Encode JavaScript value to CBOR
273
+ *
274
+ * Automatically detects value type and uses appropriate CBOR encoding.
275
+ * Supports: numbers, bigints, strings, booleans, null, undefined, Uint8Arrays, arrays, objects, and tagged values.
276
+ *
277
+ * @param value - JavaScript value to encode
278
+ * @param options - Optional encoder configuration
279
+ * @returns CBOR bytes and hex string
280
+ *
281
+ * @throws {Error} If value type is unsupported or encoding fails
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * // Encode number
286
+ * encode(100) // { hex: "1864", bytes: Uint8Array[0x18, 0x64] }
287
+ *
288
+ * // Encode string
289
+ * encode("IETF") // { hex: "6449455446", bytes: ... }
290
+ *
291
+ * // Encode array
292
+ * encode([1, 2, 3]) // { hex: "83010203", bytes: ... }
293
+ *
294
+ * // Encode map (canonical - sorted keys)
295
+ * encode({ z: 1, a: 2 }, { canonical: true })
296
+ * // Keys will be sorted: { a: 2, z: 1 }
297
+ *
298
+ * // Encode tagged value
299
+ * encode({ tag: 121, value: [] }) // { hex: "d87980", bytes: ... }
300
+ * ```
301
+ */
302
+ declare function encode(value: EncodableValue, options?: Partial<EncodeOptions>): EncodeResult;
303
+ /**
304
+ * Encode JavaScript value to CBOR hex string
305
+ *
306
+ * Convenience function that returns only the hex string (not the bytes).
307
+ *
308
+ * @param value - JavaScript value to encode
309
+ * @param options - Optional encoder configuration
310
+ * @returns CBOR hex string
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * encodeToHex(100) // "1864"
315
+ * encodeToHex([1, 2, 3]) // "83010203"
316
+ * encodeToHex({ a: 1 }, { canonical: true }) // "a16161 01"
317
+ * ```
318
+ */
319
+ declare function encodeToHex(value: EncodableValue, options?: Partial<EncodeOptions>): string;
320
+ /**
321
+ * Encode JavaScript value to CBOR bytes
322
+ *
323
+ * Convenience function that returns only the bytes (not the hex string).
324
+ *
325
+ * @param value - JavaScript value to encode
326
+ * @param options - Optional encoder configuration
327
+ * @returns CBOR bytes as Uint8Array
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * const bytes = encodeToBytes(100) // Uint8Array[0x18, 0x64]
332
+ * const bytes = encodeToBytes([1, 2, 3]) // Uint8Array[0x83, 0x01, 0x02, 0x03]
333
+ * ```
334
+ */
335
+ declare function encodeToBytes(value: EncodableValue, options?: Partial<EncodeOptions>): Uint8Array;
336
+ /**
337
+ * Encode multiple values as CBOR sequence
338
+ *
339
+ * Creates a CBOR sequence (RFC 8742) by concatenating multiple encoded values.
340
+ * Useful for streaming or batch encoding.
341
+ *
342
+ * @param values - Array of values to encode
343
+ * @param options - Optional encoder configuration
344
+ * @returns Concatenated CBOR bytes and hex string
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * encodeSequence([1, "hello", [2, 3]])
349
+ * // Returns concatenated encoding: 0x01 + 0x6568656c6c6f + 0x820203
350
+ * ```
351
+ *
352
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc8742 | RFC 8742 - CBOR Sequences}
353
+ */
354
+ declare function encodeSequence(values: EncodableValue[], options?: Partial<EncodeOptions>): EncodeResult;
355
+ /**
356
+ * Class-based CBOR decoder
357
+ *
358
+ * Provides an object-oriented interface for CBOR decoding.
359
+ * Useful when you need to maintain decoder state or configuration.
360
+ *
361
+ * @example
362
+ * ```typescript
363
+ * const decoder = new CborDecoder({ strict: true })
364
+ *
365
+ * const result1 = decoder.decode('1864')
366
+ * const result2 = decoder.decode('6449455446')
367
+ *
368
+ * const withMap = decoder.decodeWithSourceMap('d87980')
369
+ * ```
370
+ */
371
+ declare class CborDecoder {
372
+ private options;
373
+ /**
374
+ * Create a new CBOR decoder
375
+ *
376
+ * @param options - Parser configuration
377
+ */
378
+ constructor(options?: ParseOptions);
379
+ /**
380
+ * Decode CBOR hex string
381
+ *
382
+ * @param hexString - CBOR data as hex string
383
+ * @returns Decoded value and byte count
384
+ */
385
+ decode(hexString: string): ParseResult;
386
+ /**
387
+ * Decode CBOR hex string with source map
388
+ *
389
+ * @param hexString - CBOR data as hex string
390
+ * @returns Decoded value, byte count, and source map
391
+ */
392
+ decodeWithSourceMap(hexString: string): ParseResultWithMap;
393
+ }
394
+ /**
395
+ * Class-based CBOR encoder
396
+ *
397
+ * Provides an object-oriented interface for CBOR encoding.
398
+ * Useful when you need to maintain encoder state or configuration.
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * const encoder = new CborEncoder({ canonical: true })
403
+ *
404
+ * const result1 = encoder.encode(100)
405
+ * const result2 = encoder.encode([1, 2, 3])
406
+ *
407
+ * const hex = encoder.encodeToHex({ a: 1 }) // Keys will be sorted
408
+ * ```
409
+ */
410
+ declare class CborEncoder {
411
+ private options;
412
+ /**
413
+ * Create a new CBOR encoder
414
+ *
415
+ * @param options - Encoder configuration
416
+ */
417
+ constructor(options?: Partial<EncodeOptions>);
418
+ /**
419
+ * Encode value to CBOR
420
+ *
421
+ * @param value - JavaScript value to encode
422
+ * @returns CBOR bytes and hex string
423
+ */
424
+ encode(value: EncodableValue): EncodeResult;
425
+ /**
426
+ * Encode value to CBOR hex string
427
+ *
428
+ * @param value - JavaScript value to encode
429
+ * @returns CBOR hex string
430
+ */
431
+ encodeToHex(value: EncodableValue): string;
432
+ /**
433
+ * Encode value to CBOR bytes
434
+ *
435
+ * @param value - JavaScript value to encode
436
+ * @returns CBOR bytes
437
+ */
438
+ encodeToBytes(value: EncodableValue): Uint8Array;
439
+ /**
440
+ * Encode multiple values as CBOR sequence
441
+ *
442
+ * @param values - Array of values to encode
443
+ * @returns Concatenated CBOR encoding
444
+ */
445
+ encodeSequence(values: EncodableValue[]): EncodeResult;
446
+ }
447
+
448
+ /**
449
+ * Convert a JavaScript value to RFC 8949 diagnostic notation
450
+ *
451
+ * Diagnostic notation is a human-readable representation of CBOR data
452
+ * as defined in RFC 8949 Appendix B.
453
+ *
454
+ * @param value - JavaScript value to convert
455
+ * @param options - Optional formatting options
456
+ * @returns Diagnostic notation string
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * toDiagnostic(100) // "100"
461
+ * toDiagnostic(new Uint8Array([1,2])) // "h'0102'"
462
+ * toDiagnostic([1, 2, 3]) // "[1, 2, 3]"
463
+ * toDiagnostic({a: 1}) // '{"a": 1}'
464
+ * toDiagnostic({tag: 1, value: 123}) // "1(123)"
465
+ *
466
+ * // Pretty print
467
+ * toDiagnostic([1, 2], { pretty: true })
468
+ * // "[\n 1,\n 2\n]"
469
+ *
470
+ * // Indefinite length
471
+ * toDiagnostic([1, 2], { indefinite: true })
472
+ * // "[_ 1, 2]"
473
+ * ```
474
+ */
475
+ declare function toDiagnostic(value: unknown, options?: DiagnosticOptions): string;
476
+ /**
477
+ * Decode CBOR and return diagnostic notation
478
+ *
479
+ * Combines decoding and diagnostic conversion in one step.
480
+ *
481
+ * @param hexString - CBOR data as hex string
482
+ * @param options - Optional formatting options
483
+ * @returns Diagnostic notation string
484
+ *
485
+ * @example
486
+ * ```typescript
487
+ * decodeToDiagnostic('1864') // "100"
488
+ * decodeToDiagnostic('83010203') // "[1, 2, 3]"
489
+ * decodeToDiagnostic('d87980') // "121([])"
490
+ * ```
491
+ */
492
+ declare function decodeToDiagnostic(hexString: string, options?: DiagnosticOptions): string;
493
+
494
+ export { CborDecoder, CborEncoder, type DiagnosticOptions, EncodableValue, EncodeOptions, EncodeResult, ParseOptions, ParseResult, ParseResultWithMap, PathBuilder, decode, decodeToDiagnostic, decodeWithSourceMap, encode, encodeSequence, encodeToBytes, encodeToHex, toDiagnostic, useCborDiagnostic };