@marcuspuchalla/nachos 0.1.1 → 0.1.3

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 (46) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/{chunk-7CFYWHS6.js → chunk-2MTLSQ7E.js} +58 -10
  3. package/dist/chunk-2MTLSQ7E.js.map +1 -0
  4. package/dist/{chunk-ZRPJUEIZ.js → chunk-5A5T56JB.js} +170 -22
  5. package/dist/chunk-5A5T56JB.js.map +1 -0
  6. package/dist/{chunk-2HBCILJS.cjs → chunk-PTWN7K3Y.cjs} +169 -21
  7. package/dist/chunk-PTWN7K3Y.cjs.map +1 -0
  8. package/dist/{chunk-2FUTHZQQ.cjs → chunk-R62CQQNI.cjs} +58 -10
  9. package/dist/chunk-R62CQQNI.cjs.map +1 -0
  10. package/dist/encoder/index.cjs +13 -13
  11. package/dist/encoder/index.js +1 -1
  12. package/dist/index.cjs +20 -20
  13. package/dist/index.d.cts +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +4 -4
  16. package/dist/metafile-cjs.json +1 -1
  17. package/dist/metafile-esm.json +1 -1
  18. package/dist/parser/index.cjs +14 -14
  19. package/dist/parser/index.d.cts +1 -1
  20. package/dist/parser/index.d.ts +1 -1
  21. package/dist/parser/index.js +1 -1
  22. package/dist/{useCborTag-BfTIV8HM.d.cts → useCborTag-Cs1CZuXZ.d.cts} +2 -2
  23. package/dist/{useCborTag-B_iaShG6.d.ts → useCborTag-xV2Pz2VY.d.ts} +2 -2
  24. package/package.json +1 -1
  25. package/src/__tests__/roundtrip.test.ts +702 -0
  26. package/src/encoder/__tests__/cbor-collection-encoder.test.ts +26 -0
  27. package/src/encoder/__tests__/cbor-encoder-errors.test.ts +812 -0
  28. package/src/encoder/__tests__/cbor-string-encoder.test.ts +14 -0
  29. package/src/encoder/composables/useCborCollectionEncoder.ts +30 -0
  30. package/src/encoder/composables/useCborEncoder.ts +6 -1
  31. package/src/encoder/composables/useCborSimpleEncoder.ts +7 -2
  32. package/src/encoder/composables/useCborStringEncoder.ts +23 -10
  33. package/src/parser/__tests__/cbor-float-errors.test.ts +41 -0
  34. package/src/parser/__tests__/cbor-security-dos-protection.test.ts +2 -2
  35. package/src/parser/__tests__/cbor-standard-tags.test.ts +29 -0
  36. package/src/parser/__tests__/cbor-string-errors.test.ts +4 -4
  37. package/src/parser/__tests__/cbor-tag-errors.test.ts +1 -1
  38. package/src/parser/composables/useCborFloat.ts +93 -8
  39. package/src/parser/composables/useCborParser.ts +0 -19
  40. package/src/parser/composables/useCborString.ts +22 -4
  41. package/src/parser/composables/useCborTag.ts +104 -16
  42. package/dist/chunk-2FUTHZQQ.cjs.map +0 -1
  43. package/dist/chunk-2HBCILJS.cjs.map +0 -1
  44. package/dist/chunk-7CFYWHS6.js.map +0 -1
  45. package/dist/chunk-ZRPJUEIZ.js.map +0 -1
  46. package/src/encoder/composables/#useCborTagEncoder.ts# +0 -158
package/CHANGELOG.md CHANGED
@@ -5,6 +5,38 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.3] - 2026-02-09
9
+
10
+ ### Fixed
11
+
12
+ #### Critical Bugs
13
+ - **Float parser ReferenceError** - `options` variable was not accessible in float parsing, causing 29 test failures
14
+ - **Missing CborByteString import** - Tag parser failed when decoding byte-string tagged values
15
+ - **Float16 subnormal encoding** - Mantissa bits were being lost for subnormal half-precision floats
16
+
17
+ #### Security Hardening
18
+ - **Tag parser internal security checks** - Added depth, array length, map size, and indefinite-length validation to tag-internal array/map parsing
19
+ - **String encoder pre-allocation check** - Size validation now happens before buffer allocation (DoS prevention)
20
+ - **Default nesting limits** - Updated default `maxDepth` and `maxTagDepth` to 100 (was hardcoded as 64)
21
+ - **Replaced magic numbers** - All hardcoded limit values now use `DEFAULT_LIMITS` constants
22
+
23
+ #### RFC 8949 Compliance
24
+ - **Canonical NaN validation** - Float32/float64 NaN payloads are now validated in canonical mode
25
+ - **Canonical shortest-form float validation** - Values that fit in float16 are rejected in float32/float64 canonical mode
26
+ - **Indefinite-length chunk validation** - String chunks inside indefinite-length strings must be definite-length per RFC 3.2.3
27
+ - **Canonical + indefinite conflict** - Auto-resolves `canonical: true` with `allowIndefinite: true` instead of silently misbehaving
28
+
29
+ ### Added
30
+
31
+ #### Tests
32
+ - 91 round-trip encode/decode tests covering all CBOR major types
33
+ - 70 encoder error handling and canonical encoding tests
34
+ - Total test count increased from 1038 to 1199
35
+
36
+ ### Removed
37
+ - Stale Emacs backup file
38
+ - Commented-out dead code in parser
39
+
8
40
  ## [0.1.0] - 2025-12-01
9
41
 
10
42
  ### Added
@@ -158,6 +158,9 @@ function useCborStringEncoder(globalOptions) {
158
158
  const encodeByteString = (data, encodeOptions) => {
159
159
  const isIndefinite = isCborByteString(data) && data[INDEFINITE_SYMBOL] === true;
160
160
  if (encodeOptions?.indefinite || Array.isArray(data) || isIndefinite) {
161
+ if (options.allowIndefinite === false) {
162
+ throw new Error("Indefinite-length encoding is not allowed");
163
+ }
161
164
  if (options.canonical) {
162
165
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
163
166
  }
@@ -168,17 +171,20 @@ function useCborStringEncoder(globalOptions) {
168
171
  return encodeByteStringIndefinite(Array.isArray(bytes2) ? bytes2 : [bytes2]);
169
172
  }
170
173
  const bytes = isCborByteString(data) ? data.bytes : data;
174
+ if (bytes.length + 9 > options.maxOutputSize) {
175
+ throw new Error(`Encoded output exceeds maximum size`);
176
+ }
171
177
  const header = encodeLengthHeader(2, bytes.length);
172
178
  const result = concatenateUint8Arrays([header, bytes]);
173
- if (result.length > options.maxOutputSize) {
174
- throw new Error("Encoded output exceeds maximum size");
175
- }
176
179
  return {
177
180
  bytes: result,
178
181
  hex: bytesToHex(result)
179
182
  };
180
183
  };
181
184
  const encodeByteStringIndefinite = (chunks) => {
185
+ if (options.allowIndefinite === false) {
186
+ throw new Error("Indefinite-length encoding is not allowed");
187
+ }
182
188
  if (options.canonical) {
183
189
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
184
190
  }
@@ -198,6 +204,9 @@ function useCborStringEncoder(globalOptions) {
198
204
  const encodeTextString = (text, encodeOptions) => {
199
205
  const isIndefinite = isCborTextString(text) && text[INDEFINITE_SYMBOL] === true;
200
206
  if (encodeOptions?.indefinite || isIndefinite) {
207
+ if (options.allowIndefinite === false) {
208
+ throw new Error("Indefinite-length encoding is not allowed");
209
+ }
201
210
  if (options.canonical) {
202
211
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
203
212
  }
@@ -210,17 +219,20 @@ function useCborStringEncoder(globalOptions) {
210
219
  const textStr = isCborTextString(text) ? text.text : text;
211
220
  const encoder = new TextEncoder();
212
221
  const utf8Bytes = encoder.encode(textStr);
222
+ if (utf8Bytes.length + 9 > options.maxOutputSize) {
223
+ throw new Error(`Encoded output exceeds maximum size`);
224
+ }
213
225
  const header = encodeLengthHeader(3, utf8Bytes.length);
214
226
  const result = concatenateUint8Arrays([header, utf8Bytes]);
215
- if (result.length > options.maxOutputSize) {
216
- throw new Error("Encoded output exceeds maximum size");
217
- }
218
227
  return {
219
228
  bytes: result,
220
229
  hex: bytesToHex(result)
221
230
  };
222
231
  };
223
232
  const encodeTextStringIndefinite = (chunks) => {
233
+ if (options.allowIndefinite === false) {
234
+ throw new Error("Indefinite-length encoding is not allowed");
235
+ }
224
236
  if (options.canonical) {
225
237
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
226
238
  }
@@ -276,6 +288,9 @@ function useCborCollectionEncoder(globalOptions) {
276
288
  const isIndefinite = value[INDEFINITE_SYMBOL] === true;
277
289
  const newCtx = { ...ctx, depth: ctx.depth + 1 };
278
290
  if (isIndefinite) {
291
+ if (ctx.options.allowIndefinite === false) {
292
+ throw new Error("Indefinite-length encoding is not allowed");
293
+ }
279
294
  const parts = [new Uint8Array([159])];
280
295
  for (const item of value) {
281
296
  const encoded = encodeValue(item, newCtx);
@@ -295,6 +310,9 @@ function useCborCollectionEncoder(globalOptions) {
295
310
  const isIndefinite = value[INDEFINITE_SYMBOL] === true;
296
311
  const newCtx = { ...ctx, depth: ctx.depth + 1 };
297
312
  if (isIndefinite) {
313
+ if (ctx.options.allowIndefinite === false) {
314
+ throw new Error("Indefinite-length encoding is not allowed");
315
+ }
298
316
  const entries = value instanceof Map ? Array.from(value.entries()) : Object.entries(value);
299
317
  const parts = [new Uint8Array([191])];
300
318
  for (const [key, val] of entries) {
@@ -352,6 +370,9 @@ function useCborCollectionEncoder(globalOptions) {
352
370
  const encodeArray = (array, encodeOptions) => {
353
371
  const isIndefinite = array[INDEFINITE_SYMBOL] === true;
354
372
  if (encodeOptions?.indefinite || isIndefinite) {
373
+ if (options.allowIndefinite === false) {
374
+ throw new Error("Indefinite-length encoding is not allowed");
375
+ }
355
376
  if (options.canonical) {
356
377
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
357
378
  }
@@ -365,6 +386,9 @@ function useCborCollectionEncoder(globalOptions) {
365
386
  return encodeArrayInternal(array, ctx);
366
387
  };
367
388
  const encodeArrayIndefinite = (array) => {
389
+ if (options.allowIndefinite === false) {
390
+ throw new Error("Indefinite-length encoding is not allowed");
391
+ }
368
392
  if (options.canonical) {
369
393
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
370
394
  }
@@ -399,6 +423,17 @@ function useCborCollectionEncoder(globalOptions) {
399
423
  return compareBytes(keyA, keyB);
400
424
  });
401
425
  }
426
+ if (ctx.options.rejectDuplicateKeys) {
427
+ const seen = /* @__PURE__ */ new Set();
428
+ for (const [key] of entries) {
429
+ const keyBytes = encodeValue(key, { ...ctx, depth: ctx.depth + 1, bytesWritten: 0 });
430
+ const keyHex = bytesToHex(keyBytes);
431
+ if (seen.has(keyHex)) {
432
+ throw new Error("Duplicate map key detected");
433
+ }
434
+ seen.add(keyHex);
435
+ }
436
+ }
402
437
  const header = encodeLengthHeader(5, entries.length);
403
438
  const parts = [header];
404
439
  for (const [key, value] of entries) {
@@ -420,6 +455,9 @@ function useCborCollectionEncoder(globalOptions) {
420
455
  const encodeMap = (map, encodeOptions) => {
421
456
  const isIndefinite = map[INDEFINITE_SYMBOL] === true;
422
457
  if (encodeOptions?.indefinite || isIndefinite) {
458
+ if (options.allowIndefinite === false) {
459
+ throw new Error("Indefinite-length encoding is not allowed");
460
+ }
423
461
  if (options.canonical) {
424
462
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
425
463
  }
@@ -433,6 +471,9 @@ function useCborCollectionEncoder(globalOptions) {
433
471
  return encodeMapInternal(map, ctx);
434
472
  };
435
473
  const encodeMapIndefinite = (map) => {
474
+ if (options.allowIndefinite === false) {
475
+ throw new Error("Indefinite-length encoding is not allowed");
476
+ }
436
477
  if (options.canonical) {
437
478
  throw new Error("Indefinite-length encoding not allowed in canonical mode");
438
479
  }
@@ -502,9 +543,13 @@ function useCborSimpleEncoder(_globalOptions) {
502
543
  const mant64 = Number(bits & 0xfffffffffffffn);
503
544
  let exp16;
504
545
  let mant16;
505
- if (exp64 < -14) {
546
+ if (exp64 < -24) {
506
547
  exp16 = 0;
507
548
  mant16 = 0;
549
+ } else if (exp64 < -14) {
550
+ exp16 = 0;
551
+ const shift = -14 - exp64;
552
+ mant16 = (1 << 10 | mant64 >> 42) + ((1 << shift - 1) - 1) >> shift;
508
553
  } else if (exp64 > 15) {
509
554
  exp16 = 31;
510
555
  mant16 = 0;
@@ -657,6 +702,9 @@ function useCborTagEncoder() {
657
702
  // src/encoder/composables/useCborEncoder.ts
658
703
  function useCborEncoder(globalOptions) {
659
704
  const options = { ...DEFAULT_ENCODE_OPTIONS, ...globalOptions };
705
+ if (options.canonical && options.allowIndefinite) {
706
+ options.allowIndefinite = false;
707
+ }
660
708
  const { encodeInteger } = useCborIntegerEncoder();
661
709
  const { encodeTextString, encodeByteString } = useCborStringEncoder(options);
662
710
  const { encodeArray, encodeMap, setMainEncode } = useCborCollectionEncoder(options);
@@ -669,7 +717,7 @@ function useCborEncoder(globalOptions) {
669
717
  return encodeSimple(value);
670
718
  }
671
719
  if (typeof value === "number") {
672
- if (Number.isInteger(value) && Number.isSafeInteger(value)) {
720
+ if (Number.isSafeInteger(value)) {
673
721
  return encodeInteger(value);
674
722
  }
675
723
  return encodeFloat(value);
@@ -738,5 +786,5 @@ function useCborEncoder(globalOptions) {
738
786
  }
739
787
 
740
788
  export { DEFAULT_ENCODE_OPTIONS, bytesToHex, compareBytes, concatenateUint8Arrays, useCborCollectionEncoder, useCborEncoder, useCborIntegerEncoder, useCborSimpleEncoder, useCborStringEncoder, useCborTagEncoder, writeBigUint, writeUint };
741
- //# sourceMappingURL=chunk-7CFYWHS6.js.map
742
- //# sourceMappingURL=chunk-7CFYWHS6.js.map
789
+ //# sourceMappingURL=chunk-2MTLSQ7E.js.map
790
+ //# sourceMappingURL=chunk-2MTLSQ7E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/encoder/types.ts","../src/encoder/utils.ts","../src/encoder/composables/useCborIntegerEncoder.ts","../src/encoder/composables/useCborStringEncoder.ts","../src/encoder/composables/useCborCollectionEncoder.ts","../src/encoder/composables/useCborSimpleEncoder.ts","../src/encoder/composables/useCborTagEncoder.ts","../src/encoder/composables/useCborEncoder.ts"],"names":["bytes","textStr"],"mappings":";;;AA+BO,IAAM,sBAAA,GAAkD;AAAA,EAC7D,SAAA,EAAW,KAAA;AAAA,EACX,eAAA,EAAiB,IAAA;AAAA,EACjB,mBAAA,EAAqB,KAAA;AAAA,EACrB,QAAA,EAAU,EAAA;AAAA,EACV,aAAA,EAAe,MAAM,IAAA,GAAO;AAAA;AAC9B;;;AC9BO,SAAS,WAAW,KAAA,EAA2B;AACpD,EAAA,OAAO,MAAM,IAAA,CAAK,KAAK,CAAA,CACpB,GAAA,CAAI,OAAK,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAA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iB,CAAC,MAAA,KAA2C;AACjE,IAAA,MAAM,WAAyB,EAAC;AAEhC,IAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,MAAA,MAAM,MAAA,GAAS,OAAO,KAAK,CAAA;AAC3B,MAAA,QAAA,CAAS,IAAA,CAAK,OAAO,KAAK,CAAA;AAAA,IAC5B;AAGA,IAAA,MAAM,WAAA,GAAc,SAAS,MAAA,CAAO,CAAC,KAAK,GAAA,KAAQ,GAAA,GAAM,GAAA,CAAI,MAAA,EAAQ,CAAC,CAAA;AACrE,IAAA,MAAM,YAAA,GAAe,IAAI,UAAA,CAAW,WAAW,CAAA;AAE/C,IAAA,IAAI,MAAA,GAAS,CAAA;AACb,IAAA,KAAA,MAAW,SAAS,QAAA,EAAU;AAC5B,MAAA,YAAA,CAAa,GAAA,CAAI,OAAO,MAAM,CAAA;AAC9B,MAAA,MAAA,IAAU,KAAA,CAAM,MAAA;AAAA,IAClB;AAEA,IAAA,MAAM,MAAM,KAAA,CAAM,IAAA,CAAK,YAAY,CAAA,CAChC,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,QAAA,CAAS,EAAE,EAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CACxC,KAAK,EAAE,CAAA;AAEV,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,YAAA;AAAA,MACP;AAAA,KACF;AAAA,EACF,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,WAAA;AAAA,IACA,aAAA;AAAA,IACA;AAAA,GACF;AACF","file":"chunk-2MTLSQ7E.js","sourcesContent":["/**\n * CBOR Encoder Type Definitions\n * Following RFC 8949 specification\n */\n\nimport type { PlutusConstr, CborByteString, CborTextString } from '../parser/types'\nimport { INDEFINITE_SYMBOL, ALL_ENTRIES_SYMBOL } from '../parser/types'\n\n// Re-export symbols and types for use in encoder\nexport { INDEFINITE_SYMBOL, ALL_ENTRIES_SYMBOL }\nexport type { CborByteString, CborTextString }\n\n/**\n * Encoder options for controlling behavior\n */\nexport interface EncodeOptions {\n /** Enable canonical encoding (shortest form, sorted maps) */\n canonical?: boolean\n /** Allow indefinite-length encoding (false in canonical mode) */\n allowIndefinite?: boolean\n /** Reject duplicate map keys */\n rejectDuplicateKeys?: boolean\n /** Maximum nesting depth */\n maxDepth?: number\n /** Maximum output size in bytes */\n maxOutputSize?: number\n}\n\n/**\n * Default encode options\n */\nexport const DEFAULT_ENCODE_OPTIONS: Required<EncodeOptions> = {\n canonical: false,\n allowIndefinite: true,\n rejectDuplicateKeys: false,\n maxDepth: 64,\n maxOutputSize: 100 * 1024 * 1024 // 100 MB\n}\n\n/**\n * Result of encoding operation\n */\nexport interface EncodeResult {\n /** Encoded CBOR bytes */\n bytes: Uint8Array\n /** Hex string representation */\n hex: string\n}\n\n/**\n * Values that can be encoded to CBOR\n *\n * Supports both plain objects (for convenience) and Maps (for type preservation).\n * Map<any, any> is preferred for maps with non-string keys (integers, Uint8Arrays, etc.)\n */\nexport type EncodableValue =\n | number\n | bigint\n | string\n | boolean\n | null\n | undefined\n | Uint8Array\n | EncodableValue[]\n | { [key: string]: EncodableValue } // Plain object (legacy/convenience)\n | Map<EncodableValue, EncodableValue> // Map (preserves key types)\n | TaggedValue\n\n/**\n * Tagged CBOR value (Major Type 6)\n */\nexport interface TaggedValue {\n tag: number\n value: EncodableValue\n plutus?: PlutusConstr\n}\n\n/**\n * Encoding context that tracks state during CBOR encoding\n */\nexport interface EncodeContext {\n /** Current nesting depth */\n depth: number\n /** Bytes written so far */\n bytesWritten: number\n /** Encoder options */\n options: Required<EncodeOptions>\n}\n","/**\n * CBOR Encoder Utility Functions\n */\n\n/**\n * Convert Uint8Array to hex string\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n}\n\n/**\n * Concatenate multiple Uint8Arrays\n */\nexport function concatenateUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0)\n const result = new Uint8Array(totalLength)\n\n let offset = 0\n for (const arr of arrays) {\n result.set(arr, offset)\n offset += arr.length\n }\n\n return result\n}\n\n/**\n * Compare two Uint8Arrays bytewise (for canonical map sorting)\n */\nexport function compareBytes(a: Uint8Array, b: Uint8Array): number {\n // First, compare lengths\n if (a.length !== b.length) {\n return a.length - b.length\n }\n\n // Then, compare bytewise\n for (let i = 0; i < a.length; i++) {\n const byteA = a[i]\n const byteB = b[i]\n if (byteA === undefined || byteB === undefined) {\n throw new Error(`Unexpected undefined byte at index ${i}`)\n }\n if (byteA !== byteB) {\n return byteA - byteB\n }\n }\n\n return 0\n}\n\n/**\n * Write unsigned integer to bytes (big-endian)\n */\nexport function writeUint(value: number, bytes: number): Uint8Array {\n const result = new Uint8Array(bytes)\n\n for (let i = bytes - 1; i >= 0; i--) {\n result[i] = value & 0xff\n value = value >>> 8\n }\n\n return result\n}\n\n/**\n * Write BigInt to bytes (big-endian)\n */\nexport function writeBigUint(value: bigint, bytes: number): Uint8Array {\n const result = new Uint8Array(bytes)\n\n for (let i = bytes - 1; i >= 0; i--) {\n result[i] = Number(value & 0xffn)\n value = value >> 8n\n }\n\n return result\n}\n","/**\n * CBOR Integer Encoder Composable\n * Handles Major Type 0 (Unsigned) and Major Type 1 (Negative)\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult } from '../types'\nimport { bytesToHex, writeUint, writeBigUint } from '../utils'\n\n/**\n * CBOR Integer Encoder Composable\n *\n * Provides functions to encode integers to CBOR format:\n * - Major Type 0: Unsigned integers (0 to 2^64-1)\n * - Major Type 1: Negative integers (-1 to -2^64)\n *\n * @example\n * ```ts\n * const { encodeUnsignedInt, encodeNegativeInt, encodeInteger } = useCborIntegerEncoder()\n *\n * // Encode unsigned integer\n * const result1 = encodeUnsignedInt(100)\n * // result1: { bytes: Uint8Array([0x18, 0x64]), hex: '1864' }\n *\n * // Encode negative integer\n * const result2 = encodeNegativeInt(-100)\n * // result2: { bytes: Uint8Array([0x38, 0x63]), hex: '3863' }\n *\n * // Auto-detect integer type\n * const result3 = encodeInteger(-100)\n * // result3: { bytes: Uint8Array([0x38, 0x63]), hex: '3863' }\n * ```\n */\nexport function useCborIntegerEncoder() {\n /**\n * Encode unsigned integer (Major Type 0)\n *\n * Encoding rules:\n * - 0-23: Direct encoding in initial byte (0x00-0x17)\n * - 24-255: 0x18 + 1 byte\n * - 256-65535: 0x19 + 2 bytes\n * - 65536-4294967295: 0x1a + 4 bytes\n * - 4294967296-2^64-1: 0x1b + 8 bytes\n *\n * @param value - Unsigned integer (0 to 2^64-1)\n * @returns Encoded CBOR bytes and hex string\n * @throws Error if value is negative or >= 2^64\n */\n const encodeUnsignedInt = (value: number | bigint): EncodeResult => {\n // Convert to BigInt for consistent handling\n const bigValue = typeof value === 'bigint' ? value : BigInt(value)\n\n // Validate value is non-negative\n if (bigValue < 0n) {\n throw new Error('Cannot encode negative value as unsigned integer')\n }\n\n // Validate value doesn't exceed 2^64-1\n const MAX_UINT64 = 18446744073709551615n // 2^64 - 1\n if (bigValue > MAX_UINT64) {\n throw new Error('Value exceeds maximum unsigned integer (2^64-1)')\n }\n\n let bytes: Uint8Array\n\n // Direct encoding (0-23)\n if (bigValue <= 23n) {\n bytes = new Uint8Array([Number(bigValue)])\n }\n // 1-byte encoding (24-255)\n else if (bigValue <= 255n) {\n bytes = new Uint8Array([0x18, Number(bigValue)])\n }\n // 2-byte encoding (256-65535)\n else if (bigValue <= 65535n) {\n const valueBytes = writeUint(Number(bigValue), 2)\n bytes = new Uint8Array([0x19, ...valueBytes])\n }\n // 4-byte encoding (65536-4294967295)\n else if (bigValue <= 4294967295n) {\n const valueBytes = writeUint(Number(bigValue), 4)\n bytes = new Uint8Array([0x1a, ...valueBytes])\n }\n // 8-byte encoding (> 4294967295)\n else {\n const valueBytes = writeBigUint(bigValue, 8)\n bytes = new Uint8Array([0x1b, ...valueBytes])\n }\n\n return {\n bytes,\n hex: bytesToHex(bytes)\n }\n }\n\n /**\n * Encode negative integer (Major Type 1)\n *\n * CBOR encodes negative integers as: -1 - N\n * where N is the encoded value\n *\n * Encoding rules:\n * - -1 to -24: Direct encoding in initial byte (0x20-0x37)\n * - -25 to -256: 0x38 + 1 byte\n * - -257 to -65536: 0x39 + 2 bytes\n * - -65537 to -4294967296: 0x3a + 4 bytes\n * - -4294967297 to -2^64: 0x3b + 8 bytes\n *\n * @param value - Negative integer (-1 to -2^64)\n * @returns Encoded CBOR bytes and hex string\n * @throws Error if value is non-negative or < -2^64\n */\n const encodeNegativeInt = (value: number | bigint): EncodeResult => {\n // Convert to BigInt for consistent handling\n const bigValue = typeof value === 'bigint' ? value : BigInt(value)\n\n // Validate value is negative\n if (bigValue >= 0n) {\n throw new Error('Cannot encode positive value as negative integer')\n }\n\n // Validate value doesn't exceed -2^64\n const MIN_INT64 = -18446744073709551616n // -2^64\n if (bigValue < MIN_INT64) {\n throw new Error('Value exceeds minimum negative integer (-2^64)')\n }\n\n // CBOR encodes negative as: -1 - N\n // So for value V, we encode N = -1 - V\n const encoded = -1n - bigValue\n\n let bytes: Uint8Array\n\n // Direct encoding (-1 to -24, encoded as 0-23)\n if (encoded <= 23n) {\n bytes = new Uint8Array([0x20 + Number(encoded)])\n }\n // 1-byte encoding (-25 to -256, encoded as 24-255)\n else if (encoded <= 255n) {\n bytes = new Uint8Array([0x38, Number(encoded)])\n }\n // 2-byte encoding (-257 to -65536, encoded as 256-65535)\n else if (encoded <= 65535n) {\n const valueBytes = writeUint(Number(encoded), 2)\n bytes = new Uint8Array([0x39, ...valueBytes])\n }\n // 4-byte encoding (-65537 to -4294967296, encoded as 65536-4294967295)\n else if (encoded <= 4294967295n) {\n const valueBytes = writeUint(Number(encoded), 4)\n bytes = new Uint8Array([0x3a, ...valueBytes])\n }\n // 8-byte encoding (< -4294967296)\n else {\n const valueBytes = writeBigUint(encoded, 8)\n bytes = new Uint8Array([0x3b, ...valueBytes])\n }\n\n return {\n bytes,\n hex: bytesToHex(bytes)\n }\n }\n\n /**\n * Encode integer (auto-detect type)\n *\n * Automatically selects Major Type 0 (unsigned) or Major Type 1 (negative)\n * based on the sign of the value.\n *\n * @param value - Any integer\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeInteger = (value: number | bigint): EncodeResult => {\n const bigValue = typeof value === 'bigint' ? value : BigInt(value)\n\n if (bigValue < 0n) {\n return encodeNegativeInt(bigValue)\n } else {\n return encodeUnsignedInt(bigValue)\n }\n }\n\n return {\n encodeUnsignedInt,\n encodeNegativeInt,\n encodeInteger\n }\n}\n","/**\n * CBOR String Encoder Composable\n * Handles Major Type 2 (Byte Strings) and Major Type 3 (Text Strings)\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult, EncodeOptions, CborByteString, CborTextString } from '../types'\nimport { DEFAULT_ENCODE_OPTIONS, INDEFINITE_SYMBOL } from '../types'\nimport { bytesToHex, concatenateUint8Arrays, writeUint, writeBigUint } from '../utils'\nimport { useCborByteString, useCborTextString } from '../../parser/composables/useCborStringTypes'\n\ninterface StringEncodeOptions {\n indefinite?: boolean\n}\n\n/**\n * CBOR String Encoder Composable\n *\n * Provides functions to encode byte strings and text strings:\n * - Major Type 2: Byte strings (Uint8Array)\n * - Major Type 3: Text strings (UTF-8 encoded)\n *\n * Supports both definite-length and indefinite-length encoding.\n *\n * @param options - Global encoder options\n *\n * @example\n * ```ts\n * const { encodeByteString, encodeTextString } = useCborStringEncoder()\n *\n * // Encode byte string\n * const bytes = new Uint8Array([0x01, 0x02, 0x03])\n * const result1 = encodeByteString(bytes)\n * // result1: { bytes: Uint8Array([0x43, 0x01, 0x02, 0x03]), hex: '43010203' }\n *\n * // Encode text string\n * const result2 = encodeTextString('Hello')\n * // result2: { bytes: Uint8Array([0x65, 0x48, 0x65, 0x6c, 0x6c, 0x6f]), hex: '6548656c6c6f' }\n *\n * // Indefinite-length encoding\n * const chunks = [new Uint8Array([0xaa]), new Uint8Array([0xbb])]\n * const result3 = encodeByteStringIndefinite(chunks)\n * // result3: { bytes: Uint8Array([0x5f, 0x41, 0xaa, 0x41, 0xbb, 0xff]), hex: '5f41aa41bbff' }\n * ```\n */\nexport function useCborStringEncoder(globalOptions?: Partial<EncodeOptions>) {\n const options = { ...DEFAULT_ENCODE_OPTIONS, ...globalOptions }\n const { isCborByteString } = useCborByteString()\n const { isCborTextString } = useCborTextString()\n\n /**\n * Encode the length header for a string\n *\n * @param majorType - Major type (2 for bytes, 3 for text)\n * @param length - Length of the string in bytes\n * @returns Encoded length header\n */\n const encodeLengthHeader = (majorType: number, length: number): Uint8Array => {\n const baseValue = majorType << 5\n\n // Direct encoding (0-23)\n if (length <= 23) {\n return new Uint8Array([baseValue | length])\n }\n // 1-byte length (24-255)\n else if (length <= 255) {\n return new Uint8Array([baseValue | 24, length])\n }\n // 2-byte length (256-65535)\n else if (length <= 65535) {\n const lengthBytes = writeUint(length, 2)\n return new Uint8Array([baseValue | 25, ...lengthBytes])\n }\n // 4-byte length (65536-4294967295)\n else if (length <= 4294967295) {\n const lengthBytes = writeUint(length, 4)\n return new Uint8Array([baseValue | 26, ...lengthBytes])\n }\n // 8-byte length (> 4294967295)\n else {\n const lengthBytes = length > Number.MAX_SAFE_INTEGER\n ? writeBigUint(BigInt(length), 8)\n : writeUint(length, 8)\n return new Uint8Array([baseValue | 27, ...lengthBytes])\n }\n }\n\n /**\n * Encode byte string (Major Type 2)\n *\n * Can encode either:\n * - Definite-length: Single Uint8Array\n * - Indefinite-length: Array of Uint8Array chunks (if indefinite option is set)\n *\n * @param data - Byte data or array of chunks\n * @param encodeOptions - Encoding options\n * @returns Encoded CBOR bytes and hex string\n * @throws Error if indefinite encoding is used in canonical mode\n */\n const encodeByteString = (\n data: Uint8Array | Uint8Array[] | CborByteString,\n encodeOptions?: StringEncodeOptions\n ): EncodeResult => {\n // Check if it's a CborByteString with indefinite marker\n const isIndefinite = isCborByteString(data) && (data as any)[INDEFINITE_SYMBOL] === true\n\n // Handle indefinite-length encoding\n if (encodeOptions?.indefinite || Array.isArray(data) || isIndefinite) {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n // If it's a CborByteString with chunks, use the original chunks\n if (isCborByteString(data) && data.chunks) {\n return encodeByteStringIndefinite(data.chunks)\n }\n\n // Otherwise, get the actual bytes and encode as single chunk\n const bytes = isCborByteString(data) ? data.bytes : (Array.isArray(data) ? data : [data])\n return encodeByteStringIndefinite(Array.isArray(bytes) ? bytes : [bytes])\n }\n\n // Definite-length encoding - extract bytes from CborByteString if needed\n const bytes = isCborByteString(data) ? data.bytes : (data as Uint8Array)\n\n // Check size limit before allocating (header is at most 9 bytes)\n if (bytes.length + 9 > options.maxOutputSize) {\n throw new Error(`Encoded output exceeds maximum size`)\n }\n\n const header = encodeLengthHeader(2, bytes.length)\n const result = concatenateUint8Arrays([header, bytes])\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Encode byte string with indefinite length (Major Type 2)\n *\n * Format: 0x5f + chunk1 + chunk2 + ... + 0xff\n * Each chunk is a definite-length byte string.\n *\n * @param chunks - Array of byte string chunks\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeByteStringIndefinite = (chunks: Uint8Array[]): EncodeResult => {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n const parts: Uint8Array[] = [new Uint8Array([0x5f])] // Start marker\n\n // Encode each chunk as definite-length byte string\n for (const chunk of chunks) {\n const header = encodeLengthHeader(2, chunk.length)\n parts.push(header)\n parts.push(chunk)\n }\n\n parts.push(new Uint8Array([0xff])) // Break marker\n\n const result = concatenateUint8Arrays(parts)\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Encode text string (Major Type 3)\n *\n * Text strings are encoded as UTF-8 bytes.\n *\n * @param text - Text string to encode\n * @param _encodeOptions - Encoding options (reserved for future use)\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeTextString = (\n text: string | CborTextString,\n encodeOptions?: StringEncodeOptions\n ): EncodeResult => {\n // Check if it's a CborTextString with indefinite marker\n const isIndefinite = isCborTextString(text) && (text as any)[INDEFINITE_SYMBOL] === true\n\n // Handle indefinite-length encoding\n if (encodeOptions?.indefinite || isIndefinite) {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n // If it's a CborTextString with chunks, use the original chunks\n if (isCborTextString(text) && text.chunks) {\n return encodeTextStringIndefinite(text.chunks)\n }\n\n // Otherwise, get the actual text and encode as single chunk\n const textStr = isCborTextString(text) ? text.text : text\n return encodeTextStringIndefinite([textStr])\n }\n\n // Definite-length encoding - extract text from CborTextString if needed\n const textStr = isCborTextString(text) ? text.text : text\n\n // Convert string to UTF-8 bytes\n const encoder = new TextEncoder()\n const utf8Bytes = encoder.encode(textStr)\n\n // Check size limit before allocating (header is at most 9 bytes)\n if (utf8Bytes.length + 9 > options.maxOutputSize) {\n throw new Error(`Encoded output exceeds maximum size`)\n }\n\n const header = encodeLengthHeader(3, utf8Bytes.length)\n const result = concatenateUint8Arrays([header, utf8Bytes])\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Encode text string with indefinite length (Major Type 3)\n *\n * Format: 0x7f + chunk1 + chunk2 + ... + 0xff\n * Each chunk is a definite-length text string.\n *\n * @param chunks - Array of text string chunks\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeTextStringIndefinite = (chunks: string[]): EncodeResult => {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n const parts: Uint8Array[] = [new Uint8Array([0x7f])] // Start marker\n\n // Encode each chunk as definite-length text string\n const encoder = new TextEncoder()\n for (const chunk of chunks) {\n const utf8Bytes = encoder.encode(chunk)\n const header = encodeLengthHeader(3, utf8Bytes.length)\n parts.push(header)\n parts.push(utf8Bytes)\n }\n\n parts.push(new Uint8Array([0xff])) // Break marker\n\n const result = concatenateUint8Arrays(parts)\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n return {\n encodeByteString,\n encodeByteStringIndefinite,\n encodeTextString,\n encodeTextStringIndefinite\n }\n}\n","/**\n * CBOR Collection Encoder Composable\n * Handles Major Type 4 (Arrays) and Major Type 5 (Maps)\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult, EncodeOptions, EncodeContext, EncodableValue } from '../types'\nimport { DEFAULT_ENCODE_OPTIONS, INDEFINITE_SYMBOL, ALL_ENTRIES_SYMBOL } from '../types'\nimport { bytesToHex, concatenateUint8Arrays, compareBytes } from '../utils'\nimport { useCborIntegerEncoder } from './useCborIntegerEncoder'\nimport { useCborStringEncoder } from './useCborStringEncoder'\nimport { useCborByteString, useCborTextString } from '../../parser/composables/useCborStringTypes'\n\ninterface CollectionEncodeOptions {\n indefinite?: boolean\n}\n\n/**\n * CBOR Collection Encoder Composable\n *\n * Provides functions to encode arrays and maps:\n * - Major Type 4: Arrays\n * - Major Type 5: Maps (objects or Map instances)\n *\n * Supports both definite-length and indefinite-length encoding.\n * Handles canonical encoding with sorted map keys.\n * Enforces depth and size limits.\n *\n * @param options - Global encoder options\n *\n * @example\n * ```ts\n * const { encodeArray, encodeMap } = useCborCollectionEncoder()\n *\n * // Encode array\n * const arr = [1, 2, 3]\n * const result1 = encodeArray(arr)\n * // result1: { bytes: Uint8Array([0x83, 0x01, 0x02, 0x03]), hex: '83010203' }\n *\n * // Encode map\n * const map = { amount: 1000000 }\n * const result2 = encodeMap(map)\n * // result2: { bytes: ..., hex: 'a166616d6f756e741a000f4240' }\n * ```\n */\nexport function useCborCollectionEncoder(globalOptions?: Partial<EncodeOptions>) {\n const options = { ...DEFAULT_ENCODE_OPTIONS, ...globalOptions }\n\n // Get other encoders\n const { encodeInteger } = useCborIntegerEncoder()\n const { encodeTextString, encodeByteString } = useCborStringEncoder(globalOptions)\n const { isCborByteString } = useCborByteString()\n const { isCborTextString } = useCborTextString()\n\n /**\n * Encode a single value (recursive)\n *\n * NOTE: This is set by the main encoder to enable recursive encoding of all types\n * including tagged values. This avoids circular dependencies.\n */\n let mainEncode: ((value: EncodableValue) => EncodeResult) | null = null\n\n /**\n * Set the main encode function for recursive encoding\n * This must be called by useCborEncoder before encoding collections\n */\n const setMainEncode = (encodeFn: (value: EncodableValue) => EncodeResult) => {\n mainEncode = encodeFn\n }\n\n /**\n * Encode a single value (recursive)\n *\n * @param value - Value to encode\n * @param ctx - Encoding context for depth tracking\n * @returns Encoded CBOR bytes\n */\n const encodeValue = (value: EncodableValue, ctx: EncodeContext): Uint8Array => {\n // Check depth limit\n if (ctx.depth > ctx.options.maxDepth) {\n throw new Error('Maximum nesting depth exceeded')\n }\n\n // Encode based on type\n if (value === null || value === undefined) {\n // null/undefined -> CBOR null (0xf6)\n return new Uint8Array([0xf6])\n }\n else if (typeof value === 'boolean') {\n // true: 0xf5, false: 0xf4\n return new Uint8Array([value ? 0xf5 : 0xf4])\n }\n else if (typeof value === 'number' || typeof value === 'bigint') {\n return encodeInteger(value).bytes\n }\n else if (typeof value === 'string' || isCborTextString(value)) {\n return encodeTextString(value).bytes\n }\n else if (value instanceof Uint8Array || isCborByteString(value)) {\n return encodeByteString(value).bytes\n }\n else if (Array.isArray(value)) {\n // Recursive array encoding - check for indefinite marker\n const isIndefinite = (value as any)[INDEFINITE_SYMBOL] === true\n const newCtx = { ...ctx, depth: ctx.depth + 1 }\n\n if (isIndefinite) {\n if (ctx.options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n // Use indefinite encoding - but need to recursively encode items\n const parts: Uint8Array[] = [new Uint8Array([0x9f])] // Start marker\n for (const item of value) {\n const encoded = encodeValue(item, newCtx)\n parts.push(encoded)\n }\n parts.push(new Uint8Array([0xff])) // Break marker\n return concatenateUint8Arrays(parts)\n } else {\n return encodeArrayInternal(value, newCtx).bytes\n }\n }\n else if (typeof value === 'object' && value !== null && 'tag' in value && 'value' in value) {\n // Tagged value - delegate to main encoder if available\n if (mainEncode) {\n return mainEncode(value).bytes\n }\n throw new Error('Tagged value encoding requires main encoder to be set')\n }\n else if (value instanceof Map || (typeof value === 'object' && value !== null)) {\n // Recursive map encoding - check for indefinite marker\n const isIndefinite = (value as any)[INDEFINITE_SYMBOL] === true\n const newCtx = { ...ctx, depth: ctx.depth + 1 }\n\n if (isIndefinite) {\n if (ctx.options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n // Use indefinite encoding\n const entries: Array<[EncodableValue, EncodableValue]> =\n value instanceof Map\n ? Array.from(value.entries())\n : Object.entries(value)\n\n const parts: Uint8Array[] = [new Uint8Array([0xbf])] // Start marker\n for (const [key, val] of entries) {\n const encodedKey = encodeValue(key, newCtx)\n const encodedValue = encodeValue(val, newCtx)\n parts.push(encodedKey)\n parts.push(encodedValue)\n }\n parts.push(new Uint8Array([0xff])) // Break marker\n return concatenateUint8Arrays(parts)\n } else {\n return encodeMapInternal(value as Map<EncodableValue, EncodableValue> | { [key: string]: EncodableValue }, newCtx).bytes\n }\n }\n else {\n throw new Error(`Unsupported value type: ${typeof value}`)\n }\n }\n\n /**\n * Encode length header for arrays and maps\n *\n * @param majorType - Major type (4 for arrays, 5 for maps)\n * @param length - Number of elements\n * @returns Encoded length header\n */\n const encodeLengthHeader = (majorType: number, length: number): Uint8Array => {\n const baseValue = majorType << 5\n\n if (length <= 23) {\n return new Uint8Array([baseValue | length])\n }\n else if (length <= 255) {\n return new Uint8Array([baseValue | 24, length])\n }\n else if (length <= 65535) {\n return new Uint8Array([baseValue | 25, length >> 8, length & 0xff])\n }\n else if (length <= 4294967295) {\n return new Uint8Array([\n baseValue | 26,\n (length >> 24) & 0xff,\n (length >> 16) & 0xff,\n (length >> 8) & 0xff,\n length & 0xff\n ])\n }\n else {\n throw new Error('Collection too large to encode')\n }\n }\n\n /**\n * Internal array encoding (used by recursive calls)\n */\n const encodeArrayInternal = (\n array: EncodableValue[],\n ctx: EncodeContext\n ): EncodeResult => {\n const header = encodeLengthHeader(4, array.length)\n const parts: Uint8Array[] = [header]\n\n // Encode each element\n for (const item of array) {\n const encoded = encodeValue(item, ctx)\n parts.push(encoded)\n }\n\n const result = concatenateUint8Arrays(parts)\n\n // Check output size\n ctx.bytesWritten += result.length\n if (ctx.bytesWritten > ctx.options.maxOutputSize) {\n throw new Error('Encoded output exceeds maximum size')\n }\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Encode array (Major Type 4)\n *\n * @param array - Array of encodable values\n * @param encodeOptions - Encoding options\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeArray = (\n array: EncodableValue[],\n encodeOptions?: CollectionEncodeOptions\n ): EncodeResult => {\n // Check if array was originally encoded with indefinite length\n const isIndefinite = (array as any)[INDEFINITE_SYMBOL] === true\n\n // Handle indefinite-length encoding\n if (encodeOptions?.indefinite || isIndefinite) {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n return encodeArrayIndefinite(array)\n }\n\n // Definite-length encoding\n const ctx: EncodeContext = {\n depth: 0,\n bytesWritten: 0,\n options\n }\n\n return encodeArrayInternal(array, ctx)\n }\n\n /**\n * Encode array with indefinite length\n *\n * @param array - Array of encodable values\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeArrayIndefinite = (array: EncodableValue[]): EncodeResult => {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n const parts: Uint8Array[] = [new Uint8Array([0x9f])] // Start marker\n\n const ctx: EncodeContext = {\n depth: 0,\n bytesWritten: 0,\n options\n }\n\n // Encode each element\n for (const item of array) {\n const encoded = encodeValue(item, ctx)\n parts.push(encoded)\n }\n\n parts.push(new Uint8Array([0xff])) // Break marker\n\n const result = concatenateUint8Arrays(parts)\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Internal map encoding (used by recursive calls)\n */\n const encodeMapInternal = (\n map: Map<EncodableValue, EncodableValue> | { [key: string]: EncodableValue },\n ctx: EncodeContext\n ): EncodeResult => {\n // Check for ALL_ENTRIES_SYMBOL for byte-perfect preservation with duplicates\n let entries: Array<[EncodableValue, EncodableValue]>\n\n if ((map as any)[ALL_ENTRIES_SYMBOL]) {\n // Use the preserved entries (includes duplicates and original order)\n entries = (map as any)[ALL_ENTRIES_SYMBOL]\n } else {\n // Convert object to Map if needed\n entries = map instanceof Map\n ? Array.from(map.entries())\n : Object.entries(map)\n }\n\n // In canonical mode, sort entries by encoded key (unless using allEntries for byte-perfect)\n if (ctx.options.canonical && !(map as any)[ALL_ENTRIES_SYMBOL]) {\n entries.sort((a, b) => {\n const keyA = encodeValue(a[0], { ...ctx, depth: ctx.depth + 1 })\n const keyB = encodeValue(b[0], { ...ctx, depth: ctx.depth + 1 })\n return compareBytes(keyA, keyB)\n })\n }\n\n if (ctx.options.rejectDuplicateKeys) {\n const seen = new Set<string>()\n for (const [key] of entries) {\n const keyBytes = encodeValue(key, { ...ctx, depth: ctx.depth + 1, bytesWritten: 0 })\n const keyHex = bytesToHex(keyBytes)\n if (seen.has(keyHex)) {\n throw new Error('Duplicate map key detected')\n }\n seen.add(keyHex)\n }\n }\n\n const header = encodeLengthHeader(5, entries.length)\n const parts: Uint8Array[] = [header]\n\n // Encode each key-value pair\n for (const [key, value] of entries) {\n const encodedKey = encodeValue(key, ctx)\n const encodedValue = encodeValue(value, ctx)\n parts.push(encodedKey)\n parts.push(encodedValue)\n }\n\n const result = concatenateUint8Arrays(parts)\n\n // Check output size\n ctx.bytesWritten += result.length\n if (ctx.bytesWritten > ctx.options.maxOutputSize) {\n throw new Error('Encoded output exceeds maximum size')\n }\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n /**\n * Encode map (Major Type 5)\n *\n * @param map - Map or plain object\n * @param encodeOptions - Encoding options\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeMap = (\n map: Map<EncodableValue, EncodableValue> | { [key: string]: EncodableValue },\n encodeOptions?: CollectionEncodeOptions\n ): EncodeResult => {\n // Check if map was originally encoded with indefinite length\n const isIndefinite = (map as any)[INDEFINITE_SYMBOL] === true\n\n // Handle indefinite-length encoding\n if (encodeOptions?.indefinite || isIndefinite) {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n return encodeMapIndefinite(map)\n }\n\n // Definite-length encoding\n const ctx: EncodeContext = {\n depth: 0,\n bytesWritten: 0,\n options\n }\n\n return encodeMapInternal(map, ctx)\n }\n\n /**\n * Encode map with indefinite length\n *\n * @param map - Map or plain object\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeMapIndefinite = (\n map: Map<EncodableValue, EncodableValue> | { [key: string]: EncodableValue }\n ): EncodeResult => {\n if (options.allowIndefinite === false) {\n throw new Error('Indefinite-length encoding is not allowed')\n }\n if (options.canonical) {\n throw new Error('Indefinite-length encoding not allowed in canonical mode')\n }\n\n const entries: Array<[EncodableValue, EncodableValue]> =\n map instanceof Map\n ? Array.from(map.entries())\n : Object.entries(map)\n\n const parts: Uint8Array[] = [new Uint8Array([0xbf])] // Start marker\n\n const ctx: EncodeContext = {\n depth: 0,\n bytesWritten: 0,\n options\n }\n\n // Encode each key-value pair\n for (const [key, value] of entries) {\n const encodedKey = encodeValue(key, ctx)\n const encodedValue = encodeValue(value, ctx)\n parts.push(encodedKey)\n parts.push(encodedValue)\n }\n\n parts.push(new Uint8Array([0xff])) // Break marker\n\n const result = concatenateUint8Arrays(parts)\n\n return {\n bytes: result,\n hex: bytesToHex(result)\n }\n }\n\n return {\n encodeArray,\n encodeArrayIndefinite,\n encodeMap,\n encodeMapIndefinite,\n setMainEncode\n }\n}\n","/**\n * CBOR Simple Values and Floats Encoder Composable\n * Handles Major Type 7 (Floats and Simple Values)\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult, EncodeOptions } from '../types'\nimport { bytesToHex } from '../utils'\nimport { useCborIntegerEncoder } from './useCborIntegerEncoder'\n\n/**\n * CBOR Simple Values and Floats Encoder Composable\n *\n * Provides functions to encode:\n * - Simple values: false, true, null, undefined\n * - Floating-point numbers: float16, float32, float64\n *\n * @param options - Global encoder options\n *\n * @example\n * ```ts\n * const { encodeSimple, encodeFloat } = useCborSimpleEncoder()\n *\n * // Encode simple values\n * const result1 = encodeSimple(true)\n * // result1: { bytes: Uint8Array([0xf5]), hex: 'f5' }\n *\n * // Encode float\n * const result2 = encodeFloat(1.1)\n * // result2: { bytes: Uint8Array([0xfb, ...]), hex: 'fb...' }\n * ```\n */\nexport function useCborSimpleEncoder(_globalOptions?: Partial<EncodeOptions>) {\n const { encodeInteger } = useCborIntegerEncoder()\n\n /**\n * Encode simple values (booleans, null, undefined)\n *\n * @param value - Simple value to encode\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeSimple = (value: boolean | null | undefined): EncodeResult => {\n let byte: number\n\n if (value === false) {\n byte = 0xf4\n } else if (value === true) {\n byte = 0xf5\n } else if (value === null) {\n byte = 0xf6\n } else if (value === undefined) {\n byte = 0xf7\n } else {\n throw new Error(`Unsupported simple value: ${value}`)\n }\n\n return {\n bytes: new Uint8Array([byte]),\n hex: bytesToHex(new Uint8Array([byte]))\n }\n }\n\n /**\n * Encode float16 (IEEE 754 half precision)\n *\n * @param value - Number to encode\n * @returns Uint8Array with float16 bytes (2 bytes)\n */\n const encodeFloat16Bytes = (value: number): Uint8Array => {\n // Handle special cases\n if (value === 0) return new Uint8Array([0x00, 0x00])\n if (value === -0) return new Uint8Array([0x80, 0x00])\n if (Number.isNaN(value)) return new Uint8Array([0x7e, 0x00])\n if (value === Infinity) return new Uint8Array([0x7c, 0x00])\n if (value === -Infinity) return new Uint8Array([0xfc, 0x00])\n\n // Convert float64 to float16\n const sign = value < 0 ? 1 : 0\n const absValue = Math.abs(value)\n\n // Get exponent and mantissa from float64\n const buffer = new ArrayBuffer(8)\n const view = new DataView(buffer)\n view.setFloat64(0, absValue, false)\n\n const bits = view.getBigUint64(0, false)\n const exp64 = Number((bits >> 52n) & 0x7ffn) - 1023\n const mant64 = Number(bits & 0xfffffffffffffn)\n\n // Convert to float16 range\n let exp16: number\n let mant16: number\n\n if (exp64 < -24) {\n // Too small even for subnormal float16\n exp16 = 0\n mant16 = 0\n } else if (exp64 < -14) {\n // Subnormal float16: shift the implicit 1.mantissa into the fraction bits\n exp16 = 0\n const shift = -14 - exp64\n mant16 = (((1 << 10) | (mant64 >> 42)) + ((1 << (shift - 1)) - 1)) >> shift\n } else if (exp64 > 15) {\n // Overflow to infinity\n exp16 = 31\n mant16 = 0\n } else {\n // Normal number\n exp16 = exp64 + 15\n // Take top 10 bits of mantissa\n mant16 = mant64 >> 42\n }\n\n const float16 = (sign << 15) | (exp16 << 10) | mant16\n\n return new Uint8Array([\n (float16 >> 8) & 0xff,\n float16 & 0xff\n ])\n }\n\n /**\n * Encode float32 (IEEE 754 single precision)\n *\n * @param value - Number to encode\n * @returns Uint8Array with float32 bytes (4 bytes)\n */\n const encodeFloat32Bytes = (value: number): Uint8Array => {\n const buffer = new ArrayBuffer(4)\n const view = new DataView(buffer)\n view.setFloat32(0, value, false) // Big-endian\n\n return new Uint8Array(buffer)\n }\n\n /**\n * Encode float64 (IEEE 754 double precision)\n *\n * @param value - Number to encode\n * @returns Uint8Array with float64 bytes (8 bytes)\n */\n const encodeFloat64Bytes = (value: number): Uint8Array => {\n const buffer = new ArrayBuffer(8)\n const view = new DataView(buffer)\n view.setFloat64(0, value, false) // Big-endian\n\n return new Uint8Array(buffer)\n }\n\n /**\n * Check if a number can be exactly represented as float16\n *\n * @param value - Number to check\n * @returns True if can be represented as float16\n */\n const canBeFloat16 = (value: number): boolean => {\n // Special values\n if (!Number.isFinite(value) || value === 0 || value === -0) {\n return true\n }\n\n // Check range\n const absValue = Math.abs(value)\n if (absValue < 0.00006103515625 || absValue > 65504) {\n return false\n }\n\n // Encode and decode to check for precision loss\n const bytes = encodeFloat16Bytes(value)\n const view = new DataView(bytes.buffer)\n const bits = view.getUint16(0, false)\n\n const sign = (bits >> 15) & 0x1\n const exp = (bits >> 10) & 0x1f\n const mant = bits & 0x3ff\n\n let decoded: number\n\n if (exp === 0) {\n decoded = (sign ? -1 : 1) * Math.pow(2, -14) * (mant / 1024)\n } else if (exp === 31) {\n decoded = mant === 0 ? (sign ? -Infinity : Infinity) : NaN\n } else {\n decoded = (sign ? -1 : 1) * Math.pow(2, exp - 15) * (1 + mant / 1024)\n }\n\n return decoded === value\n }\n\n /**\n * Check if a number can be exactly represented as float32\n *\n * @param value - Number to check\n * @returns True if can be represented as float32\n */\n const canBeFloat32 = (value: number): boolean => {\n // Special values\n if (!Number.isFinite(value) || value === 0 || value === -0) {\n return true\n }\n\n // Encode as float32 and decode back to check for precision loss\n const buffer = new ArrayBuffer(4)\n const view = new DataView(buffer)\n view.setFloat32(0, value, false)\n const decoded = view.getFloat32(0, false)\n\n return decoded === value\n }\n\n /**\n * Check if a number is an integer\n *\n * @param value - Number to check\n * @returns True if value is an integer\n */\n const isInteger = (value: number): boolean => {\n return Number.isInteger(value) && Number.isSafeInteger(value)\n }\n\n /**\n * Encode floating-point number\n *\n * @param value - Number to encode\n * @param precision - Optional precision (16, 32, or 64). If not specified, uses smallest possible.\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeFloat = (value: number, precision?: 16 | 32 | 64): EncodeResult => {\n let bytes: Uint8Array\n\n // If value is an integer, encode as integer\n if (isInteger(value) && !precision) {\n return encodeInteger(value)\n }\n\n // If precision is specified, use it\n if (precision === 16) {\n const floatBytes = encodeFloat16Bytes(value)\n bytes = new Uint8Array([0xf9, ...floatBytes])\n } else if (precision === 32) {\n const floatBytes = encodeFloat32Bytes(value)\n bytes = new Uint8Array([0xfa, ...floatBytes])\n } else if (precision === 64) {\n const floatBytes = encodeFloat64Bytes(value)\n bytes = new Uint8Array([0xfb, ...floatBytes])\n } else {\n // Auto-detect smallest precision\n if (canBeFloat16(value)) {\n const floatBytes = encodeFloat16Bytes(value)\n bytes = new Uint8Array([0xf9, ...floatBytes])\n } else if (canBeFloat32(value)) {\n const floatBytes = encodeFloat32Bytes(value)\n bytes = new Uint8Array([0xfa, ...floatBytes])\n } else {\n // Use float64 for best precision\n const floatBytes = encodeFloat64Bytes(value)\n bytes = new Uint8Array([0xfb, ...floatBytes])\n }\n }\n\n return {\n bytes,\n hex: bytesToHex(bytes)\n }\n }\n\n return {\n encodeSimple,\n encodeFloat\n }\n}\n","/**\n * CBOR Tag Encoder Composable\n * Handles Major Type 6 (Semantic Tags)\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult, TaggedValue, EncodableValue } from '../types'\nimport { bytesToHex, writeUint, writeBigUint } from '../utils'\n\n/**\n * CBOR Tag Encoder Composable\n *\n * Provides functions to encode tagged values to CBOR format:\n * - Major Type 6: Semantic tags (0 to 2^64-1)\n *\n * Tags provide semantic meaning to CBOR values:\n * - Tag 0: Date/time string (RFC 3339)\n * - Tag 1: Epoch timestamp\n * - Tag 2: Positive bignum\n * - Tag 3: Negative bignum\n * - Tag 258: Cardano set (CIP-0005)\n * - And many more...\n *\n * @example\n * ```ts\n * const { encodeTag } = useCborTagEncoder()\n *\n * // Encode date/time string (tag 0)\n * const result1 = encodeTag(0, '2013-03-21T20:04:00Z', encode)\n * // result1.hex: 'c074323031332d30332d32315432303a30343a30305a'\n *\n * // Encode positive bignum (tag 2)\n * const result2 = encodeTag(2, new Uint8Array([0x01, 0xff]), encode)\n * // result2.hex: 'c24201ff'\n *\n * // Encode Cardano set (tag 258)\n * const result3 = encodeTag(258, [1, 2, 3], encode)\n * // result3.hex: 'd9010283010203'\n * ```\n */\nexport function useCborTagEncoder() {\n /**\n * Encode tag number (Major Type 6 header)\n *\n * Tag numbers use the same encoding rules as unsigned integers:\n * - 0-23: Direct encoding in initial byte (0xc0-0xd7)\n * - 24-255: 0xd8 + 1 byte\n * - 256-65535: 0xd9 + 2 bytes\n * - 65536-4294967295: 0xda + 4 bytes\n * - 4294967296-2^64-1: 0xdb + 8 bytes\n *\n * @param tagNumber - Tag number (0 to 2^64-1)\n * @returns Encoded tag header bytes\n * @throws Error if tag number is negative or >= 2^64\n */\n const encodeTagNumber = (tagNumber: number | bigint): Uint8Array => {\n // Convert to BigInt for consistent handling\n const bigTag = typeof tagNumber === 'bigint' ? tagNumber : BigInt(tagNumber)\n\n // Validate tag is non-negative\n if (bigTag < 0n) {\n throw new Error('Tag number cannot be negative')\n }\n\n // Validate tag doesn't exceed 2^64-1\n const MAX_UINT64 = 18446744073709551615n // 2^64 - 1\n if (bigTag > MAX_UINT64) {\n throw new Error('Tag number exceeds maximum (2^64-1)')\n }\n\n let bytes: Uint8Array\n\n // Direct encoding (0-23) - Major type 6 (0xc0) + tag number\n if (bigTag <= 23n) {\n bytes = new Uint8Array([0xc0 + Number(bigTag)])\n }\n // 1-byte encoding (24-255) - 0xd8 + 1 byte\n else if (bigTag <= 255n) {\n bytes = new Uint8Array([0xd8, Number(bigTag)])\n }\n // 2-byte encoding (256-65535) - 0xd9 + 2 bytes\n else if (bigTag <= 65535n) {\n const valueBytes = writeUint(Number(bigTag), 2)\n bytes = new Uint8Array([0xd9, ...valueBytes])\n }\n // 4-byte encoding (65536-4294967295) - 0xda + 4 bytes\n else if (bigTag <= 4294967295n) {\n const valueBytes = writeUint(Number(bigTag), 4)\n bytes = new Uint8Array([0xda, ...valueBytes])\n }\n // 8-byte encoding (> 4294967295) - 0xdb + 8 bytes\n else {\n const valueBytes = writeBigUint(bigTag, 8)\n bytes = new Uint8Array([0xdb, ...valueBytes])\n }\n\n return bytes\n }\n\n /**\n * Encode tagged value (tag + content)\n *\n * A tagged value consists of:\n * 1. Tag number (Major Type 6 header)\n * 2. Tagged content (recursively encoded value)\n *\n * The encode function is passed as a parameter to avoid circular dependencies.\n *\n * @param tagNumber - Tag number\n * @param value - Value to tag\n * @param encode - Encoder function for the tagged value\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeTag = (\n tagNumber: number | bigint,\n value: EncodableValue,\n encode: (value: EncodableValue) => EncodeResult\n ): EncodeResult => {\n // Encode tag number\n const tagBytes = encodeTagNumber(tagNumber)\n\n // Recursively encode the tagged value\n const valueResult = encode(value)\n\n // Concatenate tag header + value bytes\n const totalLength = tagBytes.length + valueResult.bytes.length\n const bytes = new Uint8Array(totalLength)\n bytes.set(tagBytes, 0)\n bytes.set(valueResult.bytes, tagBytes.length)\n\n return {\n bytes,\n hex: bytesToHex(bytes)\n }\n }\n\n /**\n * Encode TaggedValue object\n *\n * Convenience function for encoding { tag, value } objects.\n *\n * @param taggedValue - Object with tag and value properties\n * @param encode - Encoder function for the tagged value\n * @returns Encoded CBOR bytes and hex string\n */\n const encodeTaggedValue = (\n taggedValue: TaggedValue,\n encode: (value: EncodableValue) => EncodeResult\n ): EncodeResult => {\n return encodeTag(taggedValue.tag, taggedValue.value, encode)\n }\n\n return {\n encodeTagNumber,\n encodeTag,\n encodeTaggedValue\n }\n}\n","/**\n * Main CBOR Encoder Composable\n * High-level API for encoding JavaScript values to CBOR\n * Following RFC 8949 specification\n */\n\nimport type { EncodeResult, EncodeOptions, EncodableValue, TaggedValue } from '../types'\nimport { DEFAULT_ENCODE_OPTIONS } from '../types'\nimport { useCborIntegerEncoder } from './useCborIntegerEncoder'\nimport { useCborStringEncoder } from './useCborStringEncoder'\nimport { useCborCollectionEncoder } from './useCborCollectionEncoder'\nimport { useCborSimpleEncoder } from './useCborSimpleEncoder'\nimport { useCborTagEncoder } from './useCborTagEncoder'\nimport { useCborByteString, useCborTextString } from '../../parser/composables/useCborStringTypes'\n\n/**\n * Main CBOR Encoder Composable\n *\n * Provides a unified interface for encoding any JavaScript value to CBOR.\n * Automatically selects the appropriate encoder based on value type.\n *\n * @param options - Global encoder options\n *\n * @example\n * ```ts\n * const { encode } = useCborEncoder()\n *\n * // Encode various types\n * encode(42) // Integer\n * encode(\"hello\") // Text string\n * encode([1, 2, 3]) // Array\n * encode({ a: 1 }) // Map\n * encode(true) // Boolean\n * encode(3.14) // Float\n * encode(new Uint8Array([0xff])) // Byte string\n *\n * // With options\n * const { encode: encodeCanonical } = useCborEncoder({ canonical: true })\n * encodeCanonical({ z: 1, a: 2 }) // Keys will be sorted\n * ```\n */\nexport function useCborEncoder(globalOptions?: Partial<EncodeOptions>) {\n const options = { ...DEFAULT_ENCODE_OPTIONS, ...globalOptions }\n\n // Canonical mode overrides: indefinite-length is forbidden per RFC 8949 Section 4.2\n if (options.canonical && options.allowIndefinite) {\n options.allowIndefinite = false\n }\n\n // Get all specialized encoders\n const { encodeInteger } = useCborIntegerEncoder()\n const { encodeTextString, encodeByteString } = useCborStringEncoder(options)\n const { encodeArray, encodeMap, setMainEncode } = useCborCollectionEncoder(options)\n const { encodeSimple, encodeFloat } = useCborSimpleEncoder(options)\n const { encodeTaggedValue } = useCborTagEncoder()\n\n // Get type guards for composable string types\n const { isCborByteString } = useCborByteString()\n const { isCborTextString } = useCborTextString()\n\n /**\n * Encode any JavaScript value to CBOR\n *\n * Automatically detects the type and uses the appropriate encoder:\n * - number/bigint → Integer or Float\n * - string → Text string\n * - boolean/null/undefined → Simple values\n * - Uint8Array → Byte string\n * - Array → CBOR array\n * - {tag: number, value: any} → Tagged value\n * - Object/Map → CBOR map\n *\n * @param value - Value to encode\n * @returns Encoded CBOR bytes and hex string\n * @throws Error if value type is unsupported\n */\n const encode = (value: EncodableValue): EncodeResult => {\n // Handle null/undefined/boolean\n if (value === null || value === undefined || typeof value === 'boolean') {\n return encodeSimple(value)\n }\n\n // Handle numbers\n if (typeof value === 'number') {\n // Check if it's an integer\n if (Number.isSafeInteger(value)) {\n return encodeInteger(value)\n }\n // It's a float\n return encodeFloat(value)\n }\n\n // Handle bigint\n if (typeof value === 'bigint') {\n return encodeInteger(value)\n }\n\n // Handle composable text strings (check before primitive strings)\n if (isCborTextString(value)) {\n return encodeTextString(value)\n }\n\n // Handle strings\n if (typeof value === 'string') {\n return encodeTextString(value)\n }\n\n // Handle composable byte strings (check before Uint8Array)\n if (isCborByteString(value)) {\n return encodeByteString(value)\n }\n\n // Handle Uint8Array (byte strings)\n if (value instanceof Uint8Array) {\n return encodeByteString(value)\n }\n\n // Handle arrays\n if (Array.isArray(value)) {\n return encodeArray(value)\n }\n\n // Handle Map\n if (value instanceof Map) {\n return encodeMap(value)\n }\n\n // Handle tagged values (MUST come before plain objects)\n // Check for {tag: number, value: any} structure\n if (typeof value === 'object' && value !== null && 'tag' in value && 'value' in value && typeof (value as { tag: unknown }).tag === 'number') {\n return encodeTaggedValue(value as TaggedValue, encode)\n }\n\n // Handle plain objects\n if (typeof value === 'object' && value !== null) {\n return encodeMap(value as { [key: string]: EncodableValue })\n }\n\n throw new Error(`Unsupported value type: ${typeof value}`)\n }\n\n // Set the main encode function for recursive collection encoding\n // This allows the collection encoder to handle nested tagged values\n setMainEncode(encode)\n\n /**\n * Encode value and return only the hex string\n *\n * @param value - Value to encode\n * @returns Hex string representation\n */\n const encodeToHex = (value: EncodableValue): string => {\n return encode(value).hex\n }\n\n /**\n * Encode value and return only the bytes\n *\n * @param value - Value to encode\n * @returns Uint8Array bytes\n */\n const encodeToBytes = (value: EncodableValue): Uint8Array => {\n return encode(value).bytes\n }\n\n /**\n * Encode multiple values in sequence\n *\n * Useful for CBOR sequences (RFC 8742)\n *\n * @param values - Values to encode\n * @returns Concatenated CBOR encoding\n */\n const encodeSequence = (values: EncodableValue[]): EncodeResult => {\n const allBytes: Uint8Array[] = []\n\n for (const value of values) {\n const result = encode(value)\n allBytes.push(result.bytes)\n }\n\n // Concatenate all encoded values\n const totalLength = allBytes.reduce((sum, arr) => sum + arr.length, 0)\n const concatenated = new Uint8Array(totalLength)\n\n let offset = 0\n for (const bytes of allBytes) {\n concatenated.set(bytes, offset)\n offset += bytes.length\n }\n\n const hex = Array.from(concatenated)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('')\n\n return {\n bytes: concatenated,\n hex\n }\n }\n\n return {\n encode,\n encodeToHex,\n encodeToBytes,\n encodeSequence\n }\n}\n"]}