Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

cbor2

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cbor2 - npm Package Compare versions

Comparing version
1.12.0
to
2.0.0
+532
lib/options-p0HVYXSE.d.ts
import { KeySorter, KeyValueEncoded } from './sorts.js';
/**
* Any class. Ish.
*/
type AbstractClassType<T extends abstract new (...args: any) => any> = abstract new (...args: any) => InstanceType<T>;
/**
* A potentially-tagged value. If the tag is NaN, it will not be used.
* Otherwise, it must be an integer that will be written as a CBOR tag
* before the value is encoded.
*/
type TaggedValue = [tag: TagNumber, value: unknown];
/**
* Encode an object of the given type into a CBOR stream. Return a
* TaggedValue for automatic processing, which will write the tag (unless it
* is a NaN), then the value. If manual processing is desired, use the given
* writer to put bytes in the outputs stream.
*/
type TypeEncoder<T> = (obj: T, w: Writer, opts: RequiredEncodeOptions) => TaggedValue | undefined;
/**
* Contain a set of mappings from an object constructor to a matching
* TypeEncoder.
*/
declare class TypeEncoderMap {
#private;
/**
* Register an encoder for a given type.
*
* @param typ The class to encode. This is the function for the constructor
* of objects of this type. For example, Uint8Array the value of the
* constructor property of a Uint8Array instance.
* @param encoder The function to use for encoding this type.
* @returns Previous registration, or undefined if none.
*/
registerEncoder<T extends AbstractClassType<T>>(typ: T, encoder: TypeEncoder<InstanceType<T>>): TypeEncoder<T> | undefined;
/**
* Get the encoder for a given class.
*
* @param typ Constructor function.
* @returns Encoder, or undefined if none specified.
*/
get<T extends AbstractClassType<T>>(typ: T): TypeEncoder<InstanceType<T>> | undefined;
/**
* Delete the encoder for a given class.
*
* @param typ Constructor function.
* @returns true if class found and deleted, otherwise false.
*/
delete<T extends AbstractClassType<T>>(typ: T): boolean;
/**
* Remove all classes from the map.
*/
clear(): void;
}
declare class Writer {
#private;
static defaultOptions: RequiredWriterOptions;
constructor(opts?: WriterOptions);
get length(): number;
read(): Uint8Array;
write(buf: Uint8Array): void;
writeUint8(n: number): void;
writeUint16(n: number, littleEndian?: boolean): void;
writeUint32(n: number, littleEndian?: boolean): void;
writeBigUint64(n: bigint, littleEndian?: boolean): void;
writeInt16(n: number, littleEndian?: boolean): void;
writeInt32(n: number, littleEndian?: boolean): void;
writeBigInt64(n: bigint, littleEndian?: boolean): void;
writeFloat32(n: number, littleEndian?: boolean): void;
writeFloat64(n: number, littleEndian?: boolean): void;
clear(): void;
}
interface ToCBOR {
/**
* If an object implements this interface, this method will be used to
* serialize the object when encoding. Return undefined if you don't want
* any further serialization to take place. Return an array of [tag, value]
* if you would like default serialization, where if tag is not NaN, a
* CBOR tag will be written before the value.
*
* @param w Writer.
* @param opts Options.
*/
toCBOR(w: Writer, opts: RequiredEncodeOptions): TaggedValue | undefined;
}
type SimpleValue = true | false | null | undefined | Simple;
/**
* A CBOR "Simple" value that is not one of the pre-standardized set.
*/
declare class Simple implements ToCBOR {
static KnownSimple: Map<number, SimpleValue>;
value: number;
constructor(value: number);
static create(num: number): SimpleValue;
toCBOR(w: Writer, opts: RequiredEncodeOptions): undefined;
toString(): string;
/**
* Convert this simple value to a useful data type, if possible.
*
* @returns The converted value.
*/
decode(): SimpleValue;
}
type TagNumber = bigint | number | Number;
interface ITag {
readonly tag: TagNumber;
readonly contents: unknown;
}
/**
* Apply this to a TagDecoder function to get commenting support.
*/
interface ICommenter {
/**
* If true, do not output text for child nodes. The comment function
* will handle that. If true, ensure that the text returned by the comment
* function ends in a newline.
* @default false
*/
noChildren?: boolean;
/**
* When commenting on this tag, if this function returns a string, it will
* be appended after the tag number and a colon.
*
* @param tag The tag to comment on.
* @param opts Options.
* @param depth How deep are we in indentation clicks so far?
*/
comment?(tag: ITag, opts: RequiredCommentOptions, depth: number): string;
}
type BaseDecoder = (tag: ITag, opts: RequiredDecodeOptions) => unknown;
type TagDecoder = BaseDecoder & ICommenter;
type TagDecoderMap = Map<TagNumber, TagDecoder>;
/**
* Options for decoding.
*/
interface DecodeStreamOptions {
/**
* Maximum allowed depth to parse into CBOR structures. This limit is
* security-relevant for untrusted inputs. May be set to Infinity for
* trusted inputs, but be careful!
* @default 1024
*/
maxDepth?: number;
/**
* If the input is a string, how should it be decoded into a byte stream?
* Ignored if the input is a Uint8Array.
* @default null
*/
encoding?: 'base64' | 'hex' | null;
/**
* Reject integers and lengths that could have been encoded in a smaller
* encoding.
*
* @default false
*/
requirePreferred?: boolean;
}
/**
* These less-complex types are decoded as tokens at this level.
*/
type DecodeValue = Simple | Symbol | Uint8Array | bigint | boolean | number | string | null | undefined;
interface Sliceable {
toHere(begin?: number): Uint8Array;
}
/**
* Information about a decoded CBOR data item. 3-element tuple, containing:
* - Major type.
* - Additional Information (int if < 23, else length as 24-27, 31 as stream).
* - Decoded token value.
* - Offset into the input where this item started.
*/
type MtAiValue = [
mt: number,
ai: number,
val: DecodeValue,
offset: number,
len: bigint | number
];
interface ParentConstructor {
new (mav: MtAiValue, left: number, parent: Parent | undefined, opts: RequiredDecodeOptions): Parent;
}
interface Decodeable {
decode(options: RequiredDecodeOptions): unknown;
}
interface Parent {
parent: Parent | undefined;
children: Decodeable | unknown[];
left: number;
offset: number;
depth: number;
get done(): boolean;
get isStreaming(): boolean;
push(child: unknown, stream: Sliceable, offset: number): number;
replaceLast(child: unknown, item: Parent, stream: Sliceable): unknown;
convert(stream: Sliceable): unknown;
}
/**
* See String.prototype.normalize.
*/
type StringNormalization = 'NFC' | 'NFD' | 'NFKC' | 'NFKD';
/**
* Different styles of diagnose output for "spec" sizes. "Spec" sizes
* are _i for 0-23 encoded in the AI byte, _0 for one extra byte, _1
* for two extra bytes, _2 for four extra bytes, _3 for eight extra bytes,
* and a plain _ for indefinite encoding.
*/
declare enum DiagnosticSizes {
/** Never use spec sizes, except for as required for indefinite encoding. */
NEVER = -1,
/** Only use spec sizes when non-preferred encoding was used. */
PREFERRED = 0,
/** Always use spec sizes. */
ALWAYS = 1
}
type ObjectCreator = (kve: KeyValueEncoded[], opts: RequiredDecodeOptions) => unknown;
/**
* Decoding options.
*/
interface DecodeOptions extends DecodeStreamOptions {
/**
* What type to create when a container is needed? This is used internally
* by comment and diagnose to add separate functionality. Internal use only.
* @default CBORcontainer
* @private
*/
ParentType?: ParentConstructor;
/**
* Should numbers and strings be created as boxed instances, which retain
* their original encoding for round-tripping? If this is true,
* saveOriginal is also set to true. Think of this as "saveOriginal +
* extras". The thought is that most use cases for saveOriginal will want
* the original encoding of an object or array, and won't care about the
* original encoding of strings and numbers. Turning this on also has the
* side-effect of making all CBOR maps decode as JS Map objects, rather than
* plain Objects.
* @default false
*/
boxed?: boolean;
/**
* Turn on options for draft-ietf-cbor-cde-05.
*/
cde?: boolean;
/**
* In dCBOR, JS numbers between 2^53 and 2^64 get encoded as CBOR integers.
* When decoding, present them as JS numbers instead of BigInt, losing
* accuracy.
*/
convertUnsafeIntsToFloat?: boolean;
/**
* Turn on options for draft-mcnally-deterministic-cbor-11.
*/
dcbor?: boolean;
/**
* Should the size of an element always be appended to that element using
* an underscore when calling diagnose?
* @default DiagnosticSizes.PREFERRED
*/
diagnosticSizes?: DiagnosticSizes;
/**
* Create an object from an array of key-value pairs. The default
* implementation creates a plain JS object if all of the keys are strings,
* otherwise creates a Map (unless preferMap or boxed is set, in which case
* a Map is always created).
*/
createObject?: ObjectCreator;
/**
* Always generate Map instances when decoding, instead of trying to
* generate object instances when all of the keys are strings. If you
* have the boxed option on, this option has no effect, and Maps are always
* produced.
*/
preferMap?: boolean;
/**
* Pretty-print diagnostic format.
* @default false
*/
pretty?: boolean;
/**
* Reject negative integers in the range [CBOR_NEGATIVE_INT_MAX ...
* STANDARD_NEGATIVE_INT_MAX - 1].
* @default false
*/
rejectLargeNegatives?: boolean;
/**
* If there are bigint (tag 2/3) in the incoming data, exit with an error.
* @default false
*/
rejectBigInts?: boolean;
/**
* If there are duplicate keys in a map, should we throw an exception? Note:
* this is more compute-intensive than expected at the moment, but that will
* be fixed eventually.
* @default false
*/
rejectDuplicateKeys?: boolean;
/**
* Reject any floating point numbers. This might be used in profiles that
* are not expecting floats to prevent one from being coerced to an
* integer-looking number without the receiver knowing.
* @default false
*/
rejectFloats?: boolean;
/**
* Reject any mt 0/1 numbers. This might be used in profiles that expect
* all numbers to be encoded as floating point.
* @default false
*/
rejectInts?: boolean;
/**
* Reject floating point numbers that should have been encoded in shorter
* form, including having been encoded as an integer.
*/
rejectLongFloats?: boolean;
/**
* Reject NaNs that are not encoded as 0x7e00.
* @default false
*/
rejectLongLoundNaN?: boolean;
/**
* If negative zero (-0) is received, throw an error.
* @default false
*/
rejectNegativeZero?: boolean;
/**
* Reject simple values other than true, false, undefined, and null.
* @default false
*/
rejectSimple?: boolean;
/**
* Reject any attempt to decode streaming CBOR.
* @default false
*/
rejectStreaming?: boolean;
/**
* Reject subnormal floating point numbers.
* @default false
*/
rejectSubnormals?: boolean;
/**
* Reject strings that are not normalized with the given normalization form.
* Don't use this without Unicode expertise.
*/
rejectStringsNotNormalizedAs?: StringNormalization | null;
/**
* For dCBOR, reject "integers" between 2^53 and 2^64 that were encoded
* as floats.
*/
rejectUnsafeFloatInts?: boolean;
/**
* Reject the `undefined` simple value. Usually used with rejectSimple.
* @default false
*/
rejectUndefined?: boolean;
/**
* Save the original bytes associated with every object as a property of
* that object. Use `getEncoded(obj)` to retrieve the associated bytes.
* If you need the original encoded form of primitive items such as numbers
* and strings, set `boxed: true` as well.
*/
saveOriginal?: boolean;
/**
* If non-null, keys being decoded MUST be in this order. Note that this is a
* superset of rejectDuplicateKeys, and is slightly more efficient.
* @default null
*/
sortKeys?: KeySorter | null;
/**
* If non-null, prefer any tags in the map to ones have have been registered
* with Tag.registerDecoder.
*/
tags?: TagDecoderMap | null;
}
type RequiredDecodeOptions = Required<DecodeOptions>;
/**
* Comment options on top of the decode options.
*/
interface CommentOptions extends DecodeOptions {
/**
* For the root object, how many levels of nesting is it already?
* Happens with tag 24.
* @default 0
*/
initialDepth?: number;
/**
* If true, don't add the initial 0xHEX line to comment output.
* @default false
*/
noPrefixHex?: boolean;
/**
* The '--' separating bytes from description must be in at least this
* column.
* @default 0
*/
minCol: number;
}
type RequiredCommentOptions = Required<CommentOptions>;
interface WriterOptions {
chunkSize?: number;
}
type RequiredWriterOptions = Required<WriterOptions>;
interface EncodeOptions extends WriterOptions {
/**
* Encode all integers as floating point numbers of the correct size.
* @default false
*/
avoidInts?: boolean;
/**
* Turn on options for draft-ietf-cbor-cde-05.
*/
cde?: boolean;
/**
* Should bigints that can fit into normal integers be collapsed into
* normal integers?
* @default true
*/
collapseBigInts?: boolean;
/**
* Turn on options for draft-mcnally-deterministic-cbor-11.
*/
dcbor?: boolean;
/**
* When writing floats, always use the 64-bit version. Often combined with
* `avoidInts`.
* @default false
*/
float64?: boolean;
/**
* When writing floats, first flush any subnormal numbers to zero before
* decising on encoding.
*/
flushToZero?: boolean;
/**
* How to write TypedArrays?
* Null to use the current platform's endian-ness.
* True to always use little-endian.
* False to always use big-endian.
* @default null
*/
forceEndian?: boolean | null;
/**
* Ignore sizes on boxed numbers; they might be overly-large.
* @default false
*/
ignoreOriginalEncoding?: boolean;
/**
* Do not encode numbers in the range [CBOR_NEGATIVE_INT_MAX ...
* STANDARD_NEGATIVE_INT_MAX - 1] as MT 1.
* @default false
*/
largeNegativeAsBigInt?: boolean;
/**
* Per dcbor:
*
* "MUST check whether floating point values to be encoded have the
* numerically equal value in DCBOR_INT = [-2^63, 2^64-1]. If that is the
* case, it MUST be converted to that numerically equal integer value
* before encoding it. (Preferred encoding will then ensure the shortest
* length encoding is used.) If a floating point value has a non-zero
* fractional part, or an exponent that takes it out of DCBOR_INT, the
* original floating point value is used for encoding. (Specifically,
* conversion to a CBOR bignum is never considered.)"
*
* This should only apply to "integers" that are outside the JS safe range
* of [-(2^53 - 1), 2^53-1].
*/
reduceUnsafeNumbers?: boolean;
/**
* Do not encode bigints that cannot be reduced to integers.
* @default false
*/
rejectBigInts?: boolean;
/**
* If true, error instead of encoding an instance of Simple.
* @default false
*/
rejectCustomSimples?: boolean;
/**
* Check that Maps do not contain keys that encode to the same bytes as
* one another. This is possible in a Map with object keys.
* @default false
*/
rejectDuplicateKeys?: boolean;
/**
* Do not encode floating point numbers that cannot be reduced to integers.
* @default false
*/
rejectFloats?: boolean;
/**
* If true, error instead of encoding `undefined`.
* @default false
*/
rejectUndefined?: boolean;
/**
* If true, encode -0 as 0.
* @default false
*/
simplifyNegativeZero?: boolean;
/**
* How should the key/value pairs be sorted before an object or Map
* gets created? If null, no sorting is performed.
* @default null
*/
sortKeys?: KeySorter | null;
/**
* If specified, normalize strings on encoding. 'NFD' may optimize for CPU,
* 'NFC' may optimize for size. Don't use this without Unicode
* expertise. In particular, the 'K' forms are really unlikely to be useful.
* @default undefined
*/
stringNormalization?: StringNormalization | null;
/**
* If spcified, override how these types are encoded for this call to encode.
*/
types?: TypeEncoderMap | null;
/**
* Allow non-wellformed strings (strings containing unpaired surrogates) to
* be encoded as tag 273. This is optional since a) most protocol use cases
* should use string UTF8 and b) this adds a potentially-slow for large
* strings check for well-formedness. You may want this if you are storing
* test inputs or outputs and want to ensure that you have the full range of
* JS strings as possibilities. Note: I doubt that tag 273 is
* widely-implemented at this time, so this is another reason you should not
* use this if you are trying to interoperate.
*/
wtf8?: boolean;
}
type RequiredEncodeOptions = Required<EncodeOptions>;
export { type AbstractClassType as A, type BaseDecoder as B, type CommentOptions as C, type DecodeOptions as D, type EncodeOptions as E, type ICommenter as I, type MtAiValue as M, type ObjectCreator as O, type Parent as P, type RequiredDecodeOptions as R, type Sliceable as S, type TagDecoder as T, type WriterOptions as W, type RequiredEncodeOptions as a, type Decodeable as b, type DecodeStreamOptions as c, type DecodeValue as d, type ITag as e, type ParentConstructor as f, type RequiredCommentOptions as g, type StringNormalization as h, type TagDecoderMap as i, type TagNumber as j, DiagnosticSizes as k, Simple as l, type ToCBOR as m, Writer as n, type TaggedValue as o, type TypeEncoder as p, TypeEncoderMap as q, type SimpleValue as r, type RequiredWriterOptions as s };
export { A as AbstractClassType, o as TaggedValue, p as TypeEncoder, q as TypeEncoderMap } from './options-p0HVYXSE.js';
import './sorts.js';
class s{#e=new Map;registerEncoder(e,t){const n=this.#e.get(e);return this.#e.set(e,t),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}}export{s as TypeEncoderMap};
+1
-1

@@ -1,2 +0,2 @@

import { C as CommentOptions } from './options-BZO68bQ0.js';
import { C as CommentOptions } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -3,0 +3,0 @@

@@ -40,2 +40,3 @@ /**

JSON: number;
WTF8: number;
REGEXP: number;

@@ -42,0 +43,0 @@ SELF_DESCRIBED: number;

@@ -1,1 +0,1 @@

const f={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},I={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,SET:258,JSON:262,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},o={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},T={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23};class N{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")}const S={MIN:-(2n**63n),MAX:2n**64n-1n};export{S as DCBOR_INT,f as MT,o as NUMBYTES,T as SIMPLE,N as SYMS,I as TAG};
const f={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},I={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,SET:258,JSON:262,WTF8:273,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},o={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},T={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23};class N{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")}const S={MIN:-(2n**63n),MAX:2n**64n-1n};export{S as DCBOR_INT,f as MT,o as NUMBYTES,T as SIMPLE,N as SYMS,I as TAG};

@@ -1,2 +0,2 @@

import { R as RequiredDecodeOptions, D as DecodeOptions, P as Parent, M as MtAiValue, a as RequiredEncodeOptions } from './options-BZO68bQ0.js';
import { R as RequiredDecodeOptions, D as DecodeOptions, P as Parent, M as MtAiValue, a as RequiredEncodeOptions } from './options-p0HVYXSE.js';
import { DecodeStream } from './decodeStream.js';

@@ -3,0 +3,0 @@ import { Tag } from './tag.js';

@@ -1,1 +0,1 @@

import{DCBOR_INT as h,MT as a,NUMBYTES as u}from"./constants.js";import{DiagnosticSizes as j}from"./options.js";import{sortCoreDeterministic as y}from"./sorts.js";import{box as f,getEncoded as b,saveEncoded as N}from"./box.js";import{defaultEncodeOptions as E,encode as T}from"./encoder.js";import{stringToHex as p,u8concat as S,u8toHex as g}from"./utils.js";import{DecodeStream as I}from"./decodeStream.js";import{Simple as O}from"./simple.js";import{Tag as m}from"./tag.js";import{checkSubnormal as D}from"./float.js";const v=new Map([[u.ZERO,1],[u.ONE,2],[u.TWO,3],[u.FOUR,5],[u.EIGHT,9]]),A=new Uint8Array(0);function k(d,r){return!r.boxed&&!r.preferMap&&d.every(([i])=>typeof i=="string")?Object.fromEntries(d):new Map(d)}class w{static defaultDecodeOptions={...I.defaultOptions,ParentType:w,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:j.PREFERRED,convertUnsafeIntsToFloat:!1,createObject:k,pretty:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:y};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(r,i,e,t){if([this.mt,this.ai,,this.offset]=r,this.left=i,this.parent=e,this.#e=t,e&&(this.depth=e.depth+1),this.mt===a.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===u.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(r,i,e,t){const[s,l,n,c]=r;switch(s){case a.POS_INT:case a.NEG_INT:{if(e.rejectInts)throw new Error(`Unexpected integer: ${n}`);if(e.rejectLargeNegatives&&n<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${n}`);let o=n;return e.convertUnsafeIntsToFloat&&o>=h.MIN&&o<=h.MAX&&(o=Number(n)),e.boxed?f(o,t.toHere(c)):o}case a.SIMPLE_FLOAT:if(l>u.ONE){if(e.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${n}`);if(e.rejectNegativeZero&&Object.is(n,-0))throw new Error("Decoding negative zero");if(e.rejectLongLoundNaN&&isNaN(n)){const o=t.toHere(c);if(o.length!==3||o[1]!==126||o[2]!==0)throw new Error(`Invalid NaN encoding: "${g(o)}"`)}if(e.rejectSubnormals&&D(t.toHere(c+1)),e.rejectLongFloats){const o=T(n,{chunkSize:9,reduceUnsafeNumbers:e.rejectUnsafeFloatInts});if(o[0]>>5!==s)throw new Error(`Should have been encoded as int, not float: ${n}`);if(o.length<v.get(l))throw new Error(`Number should have been encoded shorter: ${n}`)}if(typeof n=="number"&&e.boxed)return f(n,t.toHere(c))}else{if(e.rejectSimple&&n instanceof O)throw new Error(`Invalid simple value: ${n}`);if(e.rejectUndefined&&n===void 0)throw new Error("Unexpected undefined")}return n;case a.BYTE_STRING:case a.UTF8_STRING:if(n===1/0)return new e.ParentType(r,1/0,i,e);if(e.rejectStringsNotNormalizedAs&&typeof n=="string"){const o=n.normalize(e.rejectStringsNotNormalizedAs);if(n!==o)throw new Error(`String not normalized as "${e.rejectStringsNotNormalizedAs}", got [${p(n)}] instead of [${p(o)}]`)}return e.boxed?f(n,t.toHere(c)):n;case a.ARRAY:return new e.ParentType(r,n,i,e);case a.MAP:return new e.ParentType(r,n*2,i,e);case a.TAG:{const o=new e.ParentType(r,1,i,e);return o.children=new m(n),o}}throw new TypeError(`Invalid major type: ${s}`)}static decodeToEncodeOpts(r){return{...E,avoidInts:r.rejectInts,float64:!r.rejectLongFloats,flushToZero:r.rejectSubnormals,largeNegativeAsBigInt:r.rejectLargeNegatives,sortKeys:r.sortKeys}}push(r,i,e){if(this.children.push(r),this.#t){const t=b(r)||i.toHere(e);this.#t.push(t)}return--this.left}replaceLast(r,i,e){let t,s=-1/0;if(this.children instanceof m?(s=0,t=this.children.contents,this.children.contents=r):(s=this.children.length-1,t=this.children[s],this.children[s]=r),this.#t){const l=b(r)||e.toHere(i.offset);this.#t[s]=l}return t}convert(r){let i;switch(this.mt){case a.ARRAY:i=this.children;break;case a.MAP:{const e=this.#r();if(this.#e.sortKeys){let t;for(const s of e){if(t&&this.#e.sortKeys(t,s)>=0)throw new Error(`Duplicate or out of order key: "0x${s[2]}"`);t=s}}else if(this.#e.rejectDuplicateKeys){const t=new Set;for(const[s,l,n]of e){const c=g(n);if(t.has(c))throw new Error(`Duplicate key: "0x${c}"`);t.add(c)}}i=this.#e.createObject(e,this.#e);break}case a.BYTE_STRING:return S(this.children);case a.UTF8_STRING:{const e=this.children.join("");i=this.#e.boxed?f(e,r.toHere(this.offset)):e;break}case a.TAG:i=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&i&&typeof i=="object"&&N(i,r.toHere(this.offset)),i}#r(){const r=this.children,i=r.length;if(i%2)throw new Error("Missing map value");const e=new Array(i/2);if(this.#t)for(let t=0;t<i;t+=2)e[t>>1]=[r[t],r[t+1],this.#t[t]];else for(let t=0;t<i;t+=2)e[t>>1]=[r[t],r[t+1],A];return e}}export{w as CBORcontainer};
import{DCBOR_INT as h,MT as a,NUMBYTES as u}from"./constants.js";import{DiagnosticSizes as j}from"./options.js";import{sortCoreDeterministic as y}from"./sorts.js";import{box as f,getEncoded as b,saveEncoded as N}from"./box.js";import{defaultEncodeOptions as E,encode as T}from"./encoder.js";import{stringToHex as p,u8concat as S,u8toHex as g}from"./utils.js";import{DecodeStream as I}from"./decodeStream.js";import{Simple as O}from"./simple.js";import{Tag as m}from"./tag.js";import{checkSubnormal as D}from"./float.js";const v=new Map([[u.ZERO,1],[u.ONE,2],[u.TWO,3],[u.FOUR,5],[u.EIGHT,9]]),A=new Uint8Array(0);function k(d,r){return!r.boxed&&!r.preferMap&&d.every(([i])=>typeof i=="string")?Object.fromEntries(d):new Map(d)}class w{static defaultDecodeOptions={...I.defaultOptions,ParentType:w,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:j.PREFERRED,convertUnsafeIntsToFloat:!1,createObject:k,pretty:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:y};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(r,i,e,t){if([this.mt,this.ai,,this.offset]=r,this.left=i,this.parent=e,this.#e=t,e&&(this.depth=e.depth+1),this.mt===a.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===u.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(r,i,e,t){const[s,l,n,c]=r;switch(s){case a.POS_INT:case a.NEG_INT:{if(e.rejectInts)throw new Error(`Unexpected integer: ${n}`);if(e.rejectLargeNegatives&&n<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${n}`);let o=n;return e.convertUnsafeIntsToFloat&&o>=h.MIN&&o<=h.MAX&&(o=Number(n)),e.boxed?f(o,t.toHere(c)):o}case a.SIMPLE_FLOAT:if(l>u.ONE){if(e.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${n}`);if(e.rejectNegativeZero&&Object.is(n,-0))throw new Error("Decoding negative zero");if(e.rejectLongLoundNaN&&isNaN(n)){const o=t.toHere(c);if(o.length!==3||o[1]!==126||o[2]!==0)throw new Error(`Invalid NaN encoding: "${g(o)}"`)}if(e.rejectSubnormals&&D(t.toHere(c+1)),e.rejectLongFloats){const o=T(n,{chunkSize:9,reduceUnsafeNumbers:e.rejectUnsafeFloatInts});if(o[0]>>5!==s)throw new Error(`Should have been encoded as int, not float: ${n}`);if(o.length<v.get(l))throw new Error(`Number should have been encoded shorter: ${n}`)}if(typeof n=="number"&&e.boxed)return f(n,t.toHere(c))}else{if(e.rejectSimple&&n instanceof O)throw new Error(`Invalid simple value: ${n}`);if(e.rejectUndefined&&n===void 0)throw new Error("Unexpected undefined")}return n;case a.BYTE_STRING:case a.UTF8_STRING:if(n===1/0)return new e.ParentType(r,1/0,i,e);if(e.rejectStringsNotNormalizedAs&&typeof n=="string"){const o=n.normalize(e.rejectStringsNotNormalizedAs);if(n!==o)throw new Error(`String not normalized as "${e.rejectStringsNotNormalizedAs}", got [${p(n)}] instead of [${p(o)}]`)}return e.boxed?f(n,t.toHere(c)):n;case a.ARRAY:return new e.ParentType(r,n,i,e);case a.MAP:return new e.ParentType(r,n*2,i,e);case a.TAG:{const o=new e.ParentType(r,1,i,e);return o.children=new m(n),o}}throw new TypeError(`Invalid major type: ${s}`)}static decodeToEncodeOpts(r){return{...E,avoidInts:r.rejectInts,float64:!r.rejectLongFloats,flushToZero:r.rejectSubnormals,largeNegativeAsBigInt:r.rejectLargeNegatives,sortKeys:r.sortKeys}}push(r,i,e){if(this.children.push(r),this.#t){const t=b(r)||i.toHere(e);this.#t.push(t)}return--this.left}replaceLast(r,i,e){let t,s=-1/0;if(this.children instanceof m?(s=0,t=this.children.contents,this.children.contents=r):(s=this.children.length-1,t=this.children[s],this.children[s]=r),this.#t){const l=b(r)||e.toHere(i.offset);this.#t[s]=l}return t}convert(r){let i;switch(this.mt){case a.ARRAY:i=this.children;break;case a.MAP:{const e=this.#r();if(this.#e.sortKeys){let t;for(const s of e){if(t&&this.#e.sortKeys(t,s)>=0)throw new Error(`Duplicate or out of order key: "0x${s[2]}"`);t=s}}else if(this.#e.rejectDuplicateKeys){const t=new Set;for(const[s,l,n]of e){const c=g(n);if(t.has(c))throw new Error(`Duplicate key: "0x${c}"`);t.add(c)}}i=this.#e.createObject(e,this.#e);break}case a.BYTE_STRING:return S(this.children);case a.UTF8_STRING:{const e=this.children.join("");i=this.#e.boxed?f(e,r.toHere(this.offset)):e;break}case a.TAG:i=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&i&&typeof i=="object"&&N(i,r.toHere(this.offset)),i}#r(){const r=this.children,i=r.length;if(i%2)throw new Error("Missing map value");const e=new Array(i/2);if(this.#t)for(let t=0;t<i;t+=2)e[t>>1]=[r[t],r[t+1],this.#t[t]];else for(let t=0;t<i;t+=2)e[t>>1]=[r[t],r[t+1],A];return e}}export{w as CBORcontainer};

@@ -1,2 +0,2 @@

import { D as DecodeOptions } from './options-BZO68bQ0.js';
import { D as DecodeOptions, M as MtAiValue } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -13,3 +13,60 @@

declare function decode<T = unknown>(src: Uint8Array | string, options?: DecodeOptions): T;
/**
* Decode the bytes of a CBOR Sequence to major-type/additional-information/
* value tuples. Each of these tuples is an event in parsing the sequence.
*
* Note that this includes items indicating the start of an array or map, and
* the end of an indefinite-length item, and tag numbers separate from the
* tag content. Does not guarantee that the input is valid.
*
* Will attempt to read all items in an array or map, even if indefinite.
* Throws when there is insufficient data to do so. The same applies when
* reading tagged items, byte strings and text strings.
*
* @see https://www.rfc-editor.org/rfc/rfc8742.html
* @example
* ```js
* const s = new Sequence(buffer);
* for (const [majorType, additionalInfo, value] of s.seq()) {
* ...
* }
* ```
*/
declare class SequenceEvents {
#private;
/**
* Create an Event
* @param src CBOR bytes to decode.
* @param options Options for decoding.
*/
constructor(src: Uint8Array | string, options?: DecodeOptions);
/**
* Peek at the next tuple, allowing for later reads.
*
* @throws {Error} On insufficient data.
*/
peek(): MtAiValue | undefined;
/**
* Read the next tuple.
*
* @throws {Error} On insufficient data.
*/
read(): MtAiValue | undefined;
/**
* Iterate over all tuples.
*
* @throws {Error} On insufficient data.
*/
[Symbol.iterator](): Generator<MtAiValue, void, undefined>;
}
/**
* Decode a CBOR Sequence consisting of multiple CBOR items.
*
* @param src CBOR bytes to decode.
* @param options Options for decoding.
* @yields JS value decoded from CBOR sequence.
* @see https://www.rfc-editor.org/rfc/rfc8742.html
*/
declare function decodeSequence<T = unknown>(src: Uint8Array | string, options?: DecodeOptions): Generator<T, undefined, undefined>;
export { decode };
export { SequenceEvents, decode, decodeSequence };

@@ -1,1 +0,1 @@

import{CBORcontainer as o}from"./container.js";import{DecodeStream as d}from"./decodeStream.js";import{SYMS as f}from"./constants.js";function O(a,i={}){const n={...o.defaultDecodeOptions};if(i.dcbor?Object.assign(n,o.dcborDecodeOptions):i.cde&&Object.assign(n,o.cdeDecodeOptions),Object.assign(n,i),Object.hasOwn(n,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");n.boxed&&(n.saveOriginal=!0);const t=new d(a,n);let e,r;for(const s of t){if(r=o.create(s,e,n,t),s[2]===f.BREAK)if(e?.isStreaming)e.left=0;else throw new Error("Unexpected BREAK");else e&&e.push(r,t,s[3]);for(r instanceof o&&(e=r);e?.done;){r=e.convert(t);const c=e.parent;c?.replaceLast(r,e,t),e=c}}return r}export{O as decode};
import{DecodeStream as a}from"./decodeStream.js";import{CBORcontainer as s}from"./container.js";import{SYMS as u}from"./constants.js";function c(i){const e={...s.defaultDecodeOptions};if(i.dcbor?Object.assign(e,s.dcborDecodeOptions):i.cde&&Object.assign(e,s.cdeDecodeOptions),Object.assign(e,i),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}class d{parent=void 0;ret=void 0;step(e,n,t){if(this.ret=s.create(e,this.parent,n,t),e[2]===u.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,t,e[3]);for(this.ret instanceof s&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(t);const r=this.parent.parent;r?.replaceLast(this.ret,this.parent,t),this.parent=r}}}function l(i,e={}){const n=c(e),t=new a(i,n),r=new d;for(const o of t)r.step(o,n,t);return r.ret}class O{#t;#e;constructor(e,n={}){const t=new a(e,c(n));this.#t=t.seq()}peek(){return this.#e||(this.#e=this.#n()),this.#e}read(){const e=this.#e??this.#n();return this.#e=void 0,e}*[Symbol.iterator](){for(;;){const e=this.read();if(!e)return;yield e}}#n(){const{value:e,done:n}=this.#t.next();if(!n)return e}}function*b(i,e={}){const n=c(e),t=new a(i,n),r=new d;for(const o of t.seq())r.step(o,n,t),r.parent||(yield r.ret)}export{O as SequenceEvents,l as decode,b as decodeSequence};

@@ -1,2 +0,2 @@

import { S as Sliceable, c as DecodeStreamOptions, M as MtAiValue } from './options-BZO68bQ0.js';
import { S as Sliceable, c as DecodeStreamOptions, M as MtAiValue } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -14,2 +14,8 @@

constructor(src: Uint8Array | string, opts?: DecodeStreamOptions);
/**
* Get the chunk of this stream from the given position to the current offset.
*
* @param begin Position to read from. Should be <= current offset.
* @returns Subarray of input stream (not copy).
*/
toHere(begin: number): Uint8Array;

@@ -29,4 +35,26 @@ /**

[Symbol.iterator](): ValueGenerator;
/**
* Get a stream of events describing all CBOR items in the input CBOR Sequence
* consisting of multiple CBOR items. Yields Value tuples.
*
* Note that this includes items indicating the start of an array or map, and
* the end of an indefinite-length item, and tag numbers separate from the tag
* content. Does not guarantee that the input is valid.
*
* Will attempt to read all items in an array or map, even if indefinite.
* Throws when there is insufficient data to do so. The same applies when
* reading tagged items, byte strings and text strings.
*
* @throws On insufficient data.
* @example
* ```js
* const s = new DecodeStream(buffer);
* for (const [majorType, additionalInfo, value] of s.seq()) {
* ...
* }
* ```
*/
seq(): ValueGenerator;
}
export { DecodeStream, type ValueGenerator };

@@ -1,1 +0,1 @@

import{MT as s,NUMBYTES as l,SYMS as d}from"./constants.js";import{base64ToBytes as m,hexToU8 as b,subarrayRanges as u}from"./utils.js";import{Simple as E}from"./simple.js";import{parseHalf as g}from"./float.js";const p=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0});class y{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#t;#r;#e=0;#i;constructor(t,r){if(this.#i={...y.defaultOptions,...r},typeof t=="string")switch(this.#i.encoding){case"hex":this.#t=b(t);break;case"base64":this.#t=m(t);break;default:throw new TypeError(`Encoding not implemented: "${this.#i.encoding}"`)}else this.#t=t;this.#r=new DataView(this.#t.buffer,this.#t.byteOffset,this.#t.byteLength)}toHere(t){return u(this.#t,t,this.#e)}*[Symbol.iterator](){if(yield*this.#n(0),this.#e!==this.#t.length)throw new Error("Extra data in input")}*#n(t){if(t++>this.#i.maxDepth)throw new Error(`Maximum depth ${this.#i.maxDepth} exceeded`);const r=this.#e,c=this.#r.getUint8(this.#e++),i=c>>5,n=c&31;let e=n,f=!1,a=0;switch(n){case l.ONE:if(a=1,e=this.#r.getUint8(this.#e),i===s.SIMPLE_FLOAT){if(e<32)throw new Error(`Invalid simple encoding in extra byte: ${e}`);f=!0}else if(this.#i.requirePreferred&&e<24)throw new Error(`Unexpectedly long integer encoding (1) for ${e}`);break;case l.TWO:if(a=2,i===s.SIMPLE_FLOAT)e=g(this.#t,this.#e);else if(e=this.#r.getUint16(this.#e,!1),this.#i.requirePreferred&&e<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${e}`);break;case l.FOUR:if(a=4,i===s.SIMPLE_FLOAT)e=this.#r.getFloat32(this.#e,!1);else if(e=this.#r.getUint32(this.#e,!1),this.#i.requirePreferred&&e<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${e}`);break;case l.EIGHT:{if(a=8,i===s.SIMPLE_FLOAT)e=this.#r.getFloat64(this.#e,!1);else if(e=this.#r.getBigUint64(this.#e,!1),e<=Number.MAX_SAFE_INTEGER&&(e=Number(e)),this.#i.requirePreferred&&e<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${e}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${n}`);case l.INDEFINITE:switch(i){case s.POS_INT:case s.NEG_INT:case s.TAG:throw new Error(`Invalid indefinite encoding for MT ${i}`);case s.SIMPLE_FLOAT:yield[i,n,d.BREAK,r,0];return}e=1/0;break;default:f=!0}switch(this.#e+=a,i){case s.POS_INT:yield[i,n,e,r,a];break;case s.NEG_INT:yield[i,n,typeof e=="bigint"?-1n-e:-1-Number(e),r,a];break;case s.BYTE_STRING:e===1/0?yield*this.#s(i,t,r):yield[i,n,this.#a(e),r,e];break;case s.UTF8_STRING:e===1/0?yield*this.#s(i,t,r):yield[i,n,p.decode(this.#a(e)),r,e];break;case s.ARRAY:if(e===1/0)yield*this.#s(i,t,r,!1);else{const o=Number(e);yield[i,n,o,r,a];for(let h=0;h<o;h++)yield*this.#n(t+1)}break;case s.MAP:if(e===1/0)yield*this.#s(i,t,r,!1);else{const o=Number(e);yield[i,n,o,r,a];for(let h=0;h<o;h++)yield*this.#n(t),yield*this.#n(t)}break;case s.TAG:yield[i,n,e,r,a],yield*this.#n(t);break;case s.SIMPLE_FLOAT:{const o=e;f&&(e=E.create(Number(e))),yield[i,n,e,r,o];break}}}#a(t){const r=u(this.#t,this.#e,this.#e+=t);if(r.length!==t)throw new Error(`Unexpected end of stream reading ${t} bytes, got ${r.length}`);return r}*#s(t,r,c,i=!0){for(yield[t,l.INDEFINITE,1/0,c,1/0];;){const n=this.#n(r),e=n.next(),[f,a,o]=e.value;if(o===d.BREAK){yield e.value,n.next();return}if(i){if(f!==t)throw new Error(`Unmatched major type. Expected ${t}, got ${f}.`);if(a===l.INDEFINITE)throw new Error("New stream started in typed stream")}yield e.value,yield*n}}}export{y as DecodeStream};
import{MT as s,NUMBYTES as l,SYMS as d}from"./constants.js";import{base64ToBytes as m,hexToU8 as b,subarrayRanges as u}from"./utils.js";import{Simple as g}from"./simple.js";import{parseHalf as E}from"./float.js";const p=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0});class y{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#t;#r;#e=0;#i;constructor(t,r){if(this.#i={...y.defaultOptions,...r},typeof t=="string")switch(this.#i.encoding){case"hex":this.#t=b(t);break;case"base64":this.#t=m(t);break;default:throw new TypeError(`Encoding not implemented: "${this.#i.encoding}"`)}else this.#t=t;this.#r=new DataView(this.#t.buffer,this.#t.byteOffset,this.#t.byteLength)}toHere(t){return u(this.#t,t,this.#e)}*[Symbol.iterator](){if(yield*this.#n(0),this.#e!==this.#t.length)throw new Error("Extra data in input")}*seq(){for(;this.#e<this.#t.length;)yield*this.#n(0)}*#n(t){if(t++>this.#i.maxDepth)throw new Error(`Maximum depth ${this.#i.maxDepth} exceeded`);const r=this.#e,c=this.#r.getUint8(this.#e++),i=c>>5,n=c&31;let e=n,f=!1,a=0;switch(n){case l.ONE:if(a=1,e=this.#r.getUint8(this.#e),i===s.SIMPLE_FLOAT){if(e<32)throw new Error(`Invalid simple encoding in extra byte: ${e}`);f=!0}else if(this.#i.requirePreferred&&e<24)throw new Error(`Unexpectedly long integer encoding (1) for ${e}`);break;case l.TWO:if(a=2,i===s.SIMPLE_FLOAT)e=E(this.#t,this.#e);else if(e=this.#r.getUint16(this.#e,!1),this.#i.requirePreferred&&e<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${e}`);break;case l.FOUR:if(a=4,i===s.SIMPLE_FLOAT)e=this.#r.getFloat32(this.#e,!1);else if(e=this.#r.getUint32(this.#e,!1),this.#i.requirePreferred&&e<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${e}`);break;case l.EIGHT:{if(a=8,i===s.SIMPLE_FLOAT)e=this.#r.getFloat64(this.#e,!1);else if(e=this.#r.getBigUint64(this.#e,!1),e<=Number.MAX_SAFE_INTEGER&&(e=Number(e)),this.#i.requirePreferred&&e<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${e}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${n}`);case l.INDEFINITE:switch(i){case s.POS_INT:case s.NEG_INT:case s.TAG:throw new Error(`Invalid indefinite encoding for MT ${i}`);case s.SIMPLE_FLOAT:yield[i,n,d.BREAK,r,0];return}e=1/0;break;default:f=!0}switch(this.#e+=a,i){case s.POS_INT:yield[i,n,e,r,a];break;case s.NEG_INT:yield[i,n,typeof e=="bigint"?-1n-e:-1-Number(e),r,a];break;case s.BYTE_STRING:e===1/0?yield*this.#s(i,t,r):yield[i,n,this.#a(e),r,e];break;case s.UTF8_STRING:e===1/0?yield*this.#s(i,t,r):yield[i,n,p.decode(this.#a(e)),r,e];break;case s.ARRAY:if(e===1/0)yield*this.#s(i,t,r,!1);else{const o=Number(e);yield[i,n,o,r,a];for(let h=0;h<o;h++)yield*this.#n(t+1)}break;case s.MAP:if(e===1/0)yield*this.#s(i,t,r,!1);else{const o=Number(e);yield[i,n,o,r,a];for(let h=0;h<o;h++)yield*this.#n(t),yield*this.#n(t)}break;case s.TAG:yield[i,n,e,r,a],yield*this.#n(t);break;case s.SIMPLE_FLOAT:{const o=e;f&&(e=g.create(Number(e))),yield[i,n,e,r,o];break}}}#a(t){const r=u(this.#t,this.#e,this.#e+=t);if(r.length!==t)throw new Error(`Unexpected end of stream reading ${t} bytes, got ${r.length}`);return r}*#s(t,r,c,i=!0){for(yield[t,l.INDEFINITE,1/0,c,1/0];;){const n=this.#n(r),e=n.next(),[f,a,o]=e.value;if(o===d.BREAK){yield e.value,n.next();return}if(i){if(f!==t)throw new Error(`Unmatched major type. Expected ${t}, got ${f}.`);if(a===l.INDEFINITE)throw new Error("New stream started in typed stream")}yield e.value,yield*n}}}export{y as DecodeStream};

@@ -1,2 +0,2 @@

import { D as DecodeOptions } from './options-BZO68bQ0.js';
import { D as DecodeOptions } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

import { a as RequiredEncodeOptions, E as EncodeOptions, l as Writer, j as TaggedValue, T as TagNumber } from './options-BZO68bQ0.js';
import { a as RequiredEncodeOptions, E as EncodeOptions, n as Writer, j as TagNumber, A as AbstractClassType, p as TypeEncoder } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -27,7 +27,2 @@

declare const dcborEncodeOptions: EncodeOptions;
/**
* Any class. Ish.
*/
type AbstractClassType<T extends abstract new (...args: any) => any> = abstract new (...args: any) => InstanceType<T>;
type TypeEncoder<T> = (obj: T, w: Writer, opts: RequiredEncodeOptions) => TaggedValue | undefined;
interface ToJSON {

@@ -112,6 +107,6 @@ /**

*
* @param obj Buffer.
* @param u Buffer.
* @param w Writer.
*/
declare function writeUint8Array(obj: unknown, w: Writer): undefined;
declare function writeUint8Array(u: Uint8Array, w: Writer): undefined;
/**

@@ -178,2 +173,2 @@ * Add a known converter for the given type to CBOR.

export { type AbstractClassType, ENCODED, type ToJSON, type TypeEncoder, cdeEncodeOptions, clearEncoder, dcborEncodeOptions, defaultEncodeOptions, encode, encodedNumber, registerEncoder, writeArray, writeBigInt, writeFloat, writeInt, writeLength, writeNumber, writeString, writeTag, writeUint8Array, writeUnknown };
export { ENCODED, type ToJSON, cdeEncodeOptions, clearEncoder, dcborEncodeOptions, defaultEncodeOptions, encode, encodedNumber, registerEncoder, writeArray, writeBigInt, writeFloat, writeInt, writeLength, writeNumber, writeString, writeTag, writeUint8Array, writeUnknown };

@@ -1,1 +0,1 @@

import{DCBOR_INT as x,MT as s,NUMBYTES as u,SIMPLE as T,SYMS as g,TAG as A}from"./constants.js";import{sortCoreDeterministic as L}from"./sorts.js";import{Writer as N}from"./writer.js";import{box as _,getEncodedLength as G}from"./box.js";import{flushToZero as D,halfToUint as S}from"./float.js";import{hexToU8 as M}from"./utils.js";const{ENCODED:te}=g,O=s.SIMPLE_FLOAT<<5|u.TWO,h=s.SIMPLE_FLOAT<<5|u.FOUR,B=s.SIMPLE_FLOAT<<5|u.EIGHT,C=s.SIMPLE_FLOAT<<5|T.TRUE,j=s.SIMPLE_FLOAT<<5|T.FALSE,W=s.SIMPLE_FLOAT<<5|T.UNDEFINED,P=s.SIMPLE_FLOAT<<5|T.NULL,q=new TextEncoder,k={...N.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null},R={cde:!0,ignoreOriginalEncoding:!0,sortKeys:L},$={...R,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function I(e){const n=e<0;return typeof e=="bigint"?[n?-e-1n:e,n]:[n?-e-1:e,n]}function p(e,n,t){if(t.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${e}`);if(isNaN(e))n.writeUint8(O),n.writeUint16(32256);else if(!t.float64&&Math.fround(e)===e){const r=S(e);r===null?(n.writeUint8(h),n.writeFloat32(e)):(n.writeUint8(O),n.writeUint16(r))}else n.writeUint8(B),n.writeFloat64(e)}function a(e,n,t){const[r,i]=I(e);if(i&&t)throw new TypeError(`Negative size: ${e}`);t??=i?s.NEG_INT:s.POS_INT,t<<=5,r<24?n.writeUint8(t|r):r<=255?(n.writeUint8(t|u.ONE),n.writeUint8(r)):r<=65535?(n.writeUint8(t|u.TWO),n.writeUint16(r)):r<=4294967295?(n.writeUint8(t|u.FOUR),n.writeUint32(r)):(n.writeUint8(t|u.EIGHT),n.writeBigUint64(BigInt(r)))}function U(e,n,t){typeof e=="number"?a(e,n,s.TAG):typeof e=="object"&&!t.ignoreOriginalEncoding&&g.ENCODED in e?n.write(e[g.ENCODED]):e<=Number.MAX_SAFE_INTEGER?a(Number(e),n,s.TAG):(n.writeUint8(s.TAG<<5|u.EIGHT),n.writeBigUint64(BigInt(e)))}function l(e,n,t){const[r,i]=I(e);if(t.collapseBigInts&&(!t.largeNegativeAsBigInt||e>=-0x8000000000000000n)){if(r<=0xffffffffn){a(Number(e),n);return}if(r<=0xffffffffffffffffn){const E=(i?s.NEG_INT:s.POS_INT)<<5;n.writeUint8(E|u.EIGHT),n.writeBigUint64(r);return}}if(t.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${e}`);const o=i?A.NEG_BIGINT:A.POS_BIGINT,d=r.toString(16),f=d.length%2?"0":"";U(o,n,t);const c=M(f+d);a(c.length,n,s.BYTE_STRING),n.write(c)}function z(e,n,t){t.flushToZero&&(e=D(e)),Object.is(e,-0)?t.simplifyNegativeZero?t.avoidInts?p(0,n,t):a(0,n):p(e,n,t):!t.avoidInts&&Number.isSafeInteger(e)?a(e,n):t.reduceUnsafeNumbers&&Math.floor(e)===e&&e>=x.MIN&&e<=x.MAX?l(BigInt(e),n,t):p(e,n,t)}function K(e,n,t){const r=t.stringNormalization?e.normalize(t.stringNormalization):e,i=q.encode(r);a(i.length,n,s.UTF8_STRING),n.write(i)}function H(e,n,t){const r=e;F(r,r.length,s.ARRAY,n,t);for(const i of r)b(i,n,t)}function Z(e,n){const t=e;a(t.length,n,s.BYTE_STRING),n.write(t)}const m=new Map([[Array,H],[Uint8Array,Z]]);function ie(e,n){const t=m.get(e);return m.set(e,n),t}function re(e){const n=m.get(e);return m.delete(e),n}function F(e,n,t,r,i){const o=G(e);o&&!i.ignoreOriginalEncoding?r.write(o):a(n,r,t)}function J(e,n,t){if(e===null){n.writeUint8(P);return}if(!t.ignoreOriginalEncoding&&g.ENCODED in e){n.write(e[g.ENCODED]);return}const r=m.get(e.constructor);if(r){const o=r(e,n,t);o&&((typeof o[0]=="bigint"||isFinite(Number(o[0])))&&U(o[0],n,t),b(o[1],n,t));return}if(typeof e.toCBOR=="function"){const o=e.toCBOR(n,t);o&&((typeof o[0]=="bigint"||isFinite(Number(o[0])))&&U(o[0],n,t),b(o[1],n,t));return}if(typeof e.toJSON=="function"){b(e.toJSON(),n,t);return}const i=Object.entries(e).map(o=>[o[0],o[1],Y(o[0],t)]);t.sortKeys&&i.sort(t.sortKeys),F(e,i.length,s.MAP,n,t);for(const[o,d,f]of i)n.write(f),b(d,n,t)}function b(e,n,t){switch(typeof e){case"number":z(e,n,t);break;case"bigint":l(e,n,t);break;case"string":K(e,n,t);break;case"boolean":n.writeUint8(e?C:j);break;case"undefined":if(t.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");n.writeUint8(W);break;case"object":J(e,n,t);break;case"symbol":throw new TypeError(`Unknown symbol: ${e.toString()}`);default:throw new TypeError(`Unknown type: ${typeof e}, ${String(e)}`)}}function Y(e,n={}){const t={...k};n.dcbor?Object.assign(t,$):n.cde&&Object.assign(t,R),Object.assign(t,n);const r=new N(t);return b(e,r,t),r.read()}function oe(e,n,t=s.POS_INT){n||(n="f");const r={...k,collapseBigInts:!1,chunkSize:10,simplifyNegativeZero:!1},i=new N(r),o=Number(e);function d(f){if(Object.is(e,-0))throw new Error("Invalid integer: -0");const[c,E]=I(e);if(E&&t!==s.POS_INT)throw new Error("Invalid major type combination");const w=typeof f=="number"&&isFinite(f);if(w&&!Number.isSafeInteger(o))throw new TypeError(`Unsafe number for ${n}: ${e}`);if(c>f)throw new TypeError(`Undersized encoding ${n} for: ${e}`);const y=(E?s.NEG_INT:t)<<5;return w?[y,Number(c)]:[y,c]}switch(n){case"bigint":if(Object.is(e,-0))throw new TypeError("Invalid bigint: -0");e=BigInt(e),l(e,i,r);break;case"f":p(o,i,r);break;case"f16":{const f=S(o);if(f===null)throw new TypeError(`Invalid f16: ${e}`);i.writeUint8(O),i.writeUint16(f);break}case"f32":if(!isNaN(o)&&Math.fround(o)!==o)throw new TypeError(`Invalid f32: ${e}`);i.writeUint8(h),i.writeFloat32(o);break;case"f64":i.writeUint8(B),i.writeFloat64(o);break;case"i":if(Object.is(e,-0))throw new Error("Invalid integer: -0");if(Number.isSafeInteger(o))a(o,i,e<0?void 0:t);else{const[f,c]=d(1/0);c>0xffffffffffffffffn?(e=BigInt(e),l(e,i,r)):(i.writeUint8(f|u.EIGHT),i.writeBigUint64(BigInt(c)))}break;case"i0":{const[f,c]=d(23);i.writeUint8(f|c);break}case"i8":{const[f,c]=d(255);i.writeUint8(f|u.ONE),i.writeUint8(c);break}case"i16":{const[f,c]=d(65535);i.writeUint8(f|u.TWO),i.writeUint16(c);break}case"i32":{const[f,c]=d(4294967295);i.writeUint8(f|u.FOUR),i.writeUint32(c);break}case"i64":{const[f,c]=d(0xffffffffffffffffn);i.writeUint8(f|u.EIGHT),i.writeBigUint64(BigInt(c));break}default:throw new TypeError(`Invalid number encoding: "${n}"`)}return _(e,i.read())}export{te as ENCODED,R as cdeEncodeOptions,re as clearEncoder,$ as dcborEncodeOptions,k as defaultEncodeOptions,Y as encode,oe as encodedNumber,ie as registerEncoder,H as writeArray,l as writeBigInt,p as writeFloat,a as writeInt,F as writeLength,z as writeNumber,K as writeString,U as writeTag,Z as writeUint8Array,b as writeUnknown};
import{TypeEncoderMap as L}from"./typeEncoderMap.js";import{DCBOR_INT as x,MT as f,NUMBYTES as d,SIMPLE as l,SYMS as m,TAG as I}from"./constants.js";import{sortCoreDeterministic as _}from"./sorts.js";import{Writer as O}from"./writer.js";import{box as G,getEncodedLength as C}from"./box.js";import{flushToZero as D,halfToUint as S}from"./float.js";import{Wtf8Encoder as M}from"@cto.af/wtf8";import{hexToU8 as W}from"./utils.js";const{ENCODED:se}=m,U=f.SIMPLE_FLOAT<<5|d.TWO,h=f.SIMPLE_FLOAT<<5|d.FOUR,B=f.SIMPLE_FLOAT<<5|d.EIGHT,j=f.SIMPLE_FLOAT<<5|l.TRUE,P=f.SIMPLE_FLOAT<<5|l.FALSE,$=f.SIMPLE_FLOAT<<5|l.UNDEFINED,q=f.SIMPLE_FLOAT<<5|l.NULL,z=new TextEncoder,K=new M,k={...O.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1},F={cde:!0,ignoreOriginalEncoding:!0,sortKeys:_},H={...F,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function y(e){const n=e<0;return typeof e=="bigint"?[n?-e-1n:e,n]:[n?-e-1:e,n]}function T(e,n,t){if(t.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${e}`);if(isNaN(e))n.writeUint8(U),n.writeUint16(32256);else if(!t.float64&&Math.fround(e)===e){const r=S(e);r===null?(n.writeUint8(h),n.writeFloat32(e)):(n.writeUint8(U),n.writeUint16(r))}else n.writeUint8(B),n.writeFloat64(e)}function a(e,n,t){const[r,i]=y(e);if(i&&t)throw new TypeError(`Negative size: ${e}`);t??=i?f.NEG_INT:f.POS_INT,t<<=5,r<24?n.writeUint8(t|r):r<=255?(n.writeUint8(t|d.ONE),n.writeUint8(r)):r<=65535?(n.writeUint8(t|d.TWO),n.writeUint16(r)):r<=4294967295?(n.writeUint8(t|d.FOUR),n.writeUint32(r)):(n.writeUint8(t|d.EIGHT),n.writeBigUint64(BigInt(r)))}function p(e,n,t){typeof e=="number"?a(e,n,f.TAG):typeof e=="object"&&!t.ignoreOriginalEncoding&&m.ENCODED in e?n.write(e[m.ENCODED]):e<=Number.MAX_SAFE_INTEGER?a(Number(e),n,f.TAG):(n.writeUint8(f.TAG<<5|d.EIGHT),n.writeBigUint64(BigInt(e)))}function N(e,n,t){const[r,i]=y(e);if(t.collapseBigInts&&(!t.largeNegativeAsBigInt||e>=-0x8000000000000000n)){if(r<=0xffffffffn){a(Number(e),n);return}if(r<=0xffffffffffffffffn){const E=(i?f.NEG_INT:f.POS_INT)<<5;n.writeUint8(E|d.EIGHT),n.writeBigUint64(r);return}}if(t.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${e}`);const o=i?I.NEG_BIGINT:I.POS_BIGINT,c=r.toString(16),s=c.length%2?"0":"";p(o,n,t);const u=W(s+c);a(u.length,n,f.BYTE_STRING),n.write(u)}function Y(e,n,t){t.flushToZero&&(e=D(e)),Object.is(e,-0)?t.simplifyNegativeZero?t.avoidInts?T(0,n,t):a(0,n):T(e,n,t):!t.avoidInts&&Number.isSafeInteger(e)?a(e,n):t.reduceUnsafeNumbers&&Math.floor(e)===e&&e>=x.MIN&&e<=x.MAX?N(BigInt(e),n,t):T(e,n,t)}function Z(e,n,t){const r=t.stringNormalization?e.normalize(t.stringNormalization):e;if(t.wtf8&&!e.isWellFormed()){const i=K.encode(r);p(I.WTF8,n,t),a(i.length,n,f.BYTE_STRING),n.write(i)}else{const i=z.encode(r);a(i.length,n,f.UTF8_STRING),n.write(i)}}function J(e,n,t){const r=e;R(r,r.length,f.ARRAY,n,t);for(const i of r)g(i,n,t)}function V(e,n){a(e.length,n,f.BYTE_STRING),n.write(e)}const b=new L;b.registerEncoder(Array,J),b.registerEncoder(Uint8Array,V);function ce(e,n){return b.registerEncoder(e,n)}function ue(e){const n=b.get(e);return b.delete(e),n}function R(e,n,t,r,i){const o=C(e);o&&!i.ignoreOriginalEncoding?r.write(o):a(n,r,t)}function X(e,n,t){if(e===null){n.writeUint8(q);return}if(!t.ignoreOriginalEncoding&&m.ENCODED in e){n.write(e[m.ENCODED]);return}const r=e.constructor;if(r){const o=t.types?.get(r)??b.get(r);if(o){const c=o(e,n,t);if(c!==void 0){if(!Array.isArray(c)||c.length!==2)throw new Error("Invalid encoder return value");(typeof c[0]=="bigint"||isFinite(Number(c[0])))&&p(c[0],n,t),g(c[1],n,t)}return}}if(typeof e.toCBOR=="function"){const o=e.toCBOR(n,t);o&&((typeof o[0]=="bigint"||isFinite(Number(o[0])))&&p(o[0],n,t),g(o[1],n,t));return}if(typeof e.toJSON=="function"){g(e.toJSON(),n,t);return}const i=Object.entries(e).map(o=>[o[0],o[1],Q(o[0],t)]);t.sortKeys&&i.sort(t.sortKeys),R(e,i.length,f.MAP,n,t);for(const[o,c,s]of i)n.write(s),g(c,n,t)}function g(e,n,t){switch(typeof e){case"number":Y(e,n,t);break;case"bigint":N(e,n,t);break;case"string":Z(e,n,t);break;case"boolean":n.writeUint8(e?j:P);break;case"undefined":if(t.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");n.writeUint8($);break;case"object":X(e,n,t);break;case"symbol":throw new TypeError(`Unknown symbol: ${e.toString()}`);default:throw new TypeError(`Unknown type: ${typeof e}, ${String(e)}`)}}function Q(e,n={}){const t={...k};n.dcbor?Object.assign(t,H):n.cde&&Object.assign(t,F),Object.assign(t,n);const r=new O(t);return g(e,r,t),r.read()}function de(e,n,t=f.POS_INT){n||(n="f");const r={...k,collapseBigInts:!1,chunkSize:10,simplifyNegativeZero:!1},i=new O(r),o=Number(e);function c(s){if(Object.is(e,-0))throw new Error("Invalid integer: -0");const[u,E]=y(e);if(E&&t!==f.POS_INT)throw new Error("Invalid major type combination");const w=typeof s=="number"&&isFinite(s);if(w&&!Number.isSafeInteger(o))throw new TypeError(`Unsafe number for ${n}: ${e}`);if(u>s)throw new TypeError(`Undersized encoding ${n} for: ${e}`);const A=(E?f.NEG_INT:t)<<5;return w?[A,Number(u)]:[A,u]}switch(n){case"bigint":if(Object.is(e,-0))throw new TypeError("Invalid bigint: -0");e=BigInt(e),N(e,i,r);break;case"f":T(o,i,r);break;case"f16":{const s=S(o);if(s===null)throw new TypeError(`Invalid f16: ${e}`);i.writeUint8(U),i.writeUint16(s);break}case"f32":if(!isNaN(o)&&Math.fround(o)!==o)throw new TypeError(`Invalid f32: ${e}`);i.writeUint8(h),i.writeFloat32(o);break;case"f64":i.writeUint8(B),i.writeFloat64(o);break;case"i":if(Object.is(e,-0))throw new Error("Invalid integer: -0");if(Number.isSafeInteger(o))a(o,i,e<0?void 0:t);else{const[s,u]=c(1/0);u>0xffffffffffffffffn?(e=BigInt(e),N(e,i,r)):(i.writeUint8(s|d.EIGHT),i.writeBigUint64(BigInt(u)))}break;case"i0":{const[s,u]=c(23);i.writeUint8(s|u);break}case"i8":{const[s,u]=c(255);i.writeUint8(s|d.ONE),i.writeUint8(u);break}case"i16":{const[s,u]=c(65535);i.writeUint8(s|d.TWO),i.writeUint16(u);break}case"i32":{const[s,u]=c(4294967295);i.writeUint8(s|d.FOUR),i.writeUint32(u);break}case"i64":{const[s,u]=c(0xffffffffffffffffn);i.writeUint8(s|d.EIGHT),i.writeBigUint64(BigInt(u));break}default:throw new TypeError(`Invalid number encoding: "${n}"`)}return G(e,i.read())}export{se as ENCODED,F as cdeEncodeOptions,ue as clearEncoder,H as dcborEncodeOptions,k as defaultEncodeOptions,Q as encode,de as encodedNumber,ce as registerEncoder,J as writeArray,N as writeBigInt,T as writeFloat,a as writeInt,R as writeLength,Y as writeNumber,Z as writeString,p as writeTag,V as writeUint8Array,g as writeUnknown};

@@ -1,6 +0,6 @@

import { D as DecodeOptions } from './options-BZO68bQ0.js';
export { C as CommentOptions, c as DecodeStreamOptions, d as DecodeValue, b as Decodeable, h as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, O as ObjectCreator, P as Parent, e as ParentConstructor, f as RequiredCommentOptions, R as RequiredDecodeOptions, a as RequiredEncodeOptions, i as Simple, S as Sliceable, g as StringNormalization, T as TagNumber, j as TaggedValue, k as ToCBOR, l as Writer, W as WriterOptions } from './options-BZO68bQ0.js';
import { D as DecodeOptions } from './options-p0HVYXSE.js';
export { A as AbstractClassType, B as BaseDecoder, C as CommentOptions, c as DecodeStreamOptions, d as DecodeValue, b as Decodeable, k as DiagnosticSizes, E as EncodeOptions, I as ICommenter, e as ITag, M as MtAiValue, O as ObjectCreator, P as Parent, f as ParentConstructor, g as RequiredCommentOptions, R as RequiredDecodeOptions, a as RequiredEncodeOptions, l as Simple, S as Sliceable, h as StringNormalization, T as TagDecoder, i as TagDecoderMap, j as TagNumber, o as TaggedValue, m as ToCBOR, p as TypeEncoder, q as TypeEncoderMap, n as Writer, W as WriterOptions } from './options-p0HVYXSE.js';
export { version } from './version.js';
export { DecodeStream, ValueGenerator } from './decodeStream.js';
export { decode } from './decoder.js';
export { SequenceEvents, decode, decodeSequence } from './decoder.js';
export { diagnose } from './diagnostic.js';

@@ -7,0 +7,0 @@ export { comment } from './comment.js';

@@ -1,1 +0,1 @@

import"./types.js";import{version as c}from"./version.js";import{CBORcontainer as e}from"./container.js";import{DiagnosticSizes as a}from"./options.js";import{decode as O}from"./decoder.js";import{diagnose as x}from"./diagnostic.js";import{comment as l}from"./comment.js";import{cdeEncodeOptions as D,defaultEncodeOptions as E,dcborEncodeOptions as b,encode as S,encodedNumber as C}from"./encoder.js";import{Simple as j}from"./simple.js";import{Tag as T}from"./tag.js";import{saveEncoded as q,saveEncodedLength as v,unbox as N,getEncoded as z}from"./box.js";const{cdeDecodeOptions:r,dcborDecodeOptions:n,defaultDecodeOptions:d}=e;export{a as DiagnosticSizes,j as Simple,T as Tag,r as cdeDecodeOptions,D as cdeEncodeOptions,l as comment,n as dcborDecodeOptions,b as dcborEncodeOptions,O as decode,d as defaultDecodeOptions,E as defaultEncodeOptions,x as diagnose,S as encode,C as encodedNumber,z as getEncoded,q as saveEncoded,v as saveEncodedLength,N as unbox,c as version};
import"./types.js";import{version as i}from"./version.js";import{CBORcontainer as e}from"./container.js";import{DiagnosticSizes as m}from"./options.js";import{decode as O,decodeSequence as f,SequenceEvents as u}from"./decoder.js";import{diagnose as g}from"./diagnostic.js";import{comment as D}from"./comment.js";import{cdeEncodeOptions as y,defaultEncodeOptions as T,dcborEncodeOptions as b,encode as S,encodedNumber as C}from"./encoder.js";import{Simple as R}from"./simple.js";import{Tag as v}from"./tag.js";import{saveEncoded as B,saveEncodedLength as M,unbox as N,getEncoded as z}from"./box.js";const{cdeDecodeOptions:r,dcborDecodeOptions:n,defaultDecodeOptions:d}=e;import{TypeEncoderMap as I}from"./typeEncoderMap.js";export{m as DiagnosticSizes,u as SequenceEvents,R as Simple,v as Tag,I as TypeEncoderMap,r as cdeDecodeOptions,y as cdeEncodeOptions,D as comment,n as dcborDecodeOptions,b as dcborEncodeOptions,O as decode,f as decodeSequence,d as defaultDecodeOptions,T as defaultEncodeOptions,g as diagnose,S as encode,C as encodedNumber,z as getEncoded,B as saveEncoded,M as saveEncodedLength,N as unbox,i as version};
import './sorts.js';
export { C as CommentOptions, D as DecodeOptions, c as DecodeStreamOptions, d as DecodeValue, b as Decodeable, h as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, O as ObjectCreator, P as Parent, e as ParentConstructor, f as RequiredCommentOptions, R as RequiredDecodeOptions, a as RequiredEncodeOptions, n as RequiredWriterOptions, S as Sliceable, g as StringNormalization, W as WriterOptions } from './options-BZO68bQ0.js';
export { B as BaseDecoder, C as CommentOptions, D as DecodeOptions, c as DecodeStreamOptions, d as DecodeValue, b as Decodeable, k as DiagnosticSizes, E as EncodeOptions, I as ICommenter, e as ITag, M as MtAiValue, O as ObjectCreator, P as Parent, f as ParentConstructor, g as RequiredCommentOptions, R as RequiredDecodeOptions, a as RequiredEncodeOptions, s as RequiredWriterOptions, S as Sliceable, h as StringNormalization, T as TagDecoder, i as TagDecoderMap, j as TagNumber, W as WriterOptions } from './options-p0HVYXSE.js';

@@ -1,2 +0,2 @@

export { i as Simple, m as SimpleValue } from './options-BZO68bQ0.js';
export { l as Simple, r as SimpleValue } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -1,32 +0,9 @@

import { k as ToCBOR, b as Decodeable, T as TagNumber, R as RequiredDecodeOptions, f as RequiredCommentOptions } from './options-BZO68bQ0.js';
import { m as ToCBOR, b as Decodeable, e as ITag, j as TagNumber, T as TagDecoder, R as RequiredDecodeOptions, g as RequiredCommentOptions } from './options-p0HVYXSE.js';
import './sorts.js';
/**
* Apply this to a TagDecoder function to get commenting support.
*/
interface Commenter {
/**
* If true, do not output text for child nodes. The comment function
* will handle that. If true, ensure that the text returned by the comment
* function ends in a newline.
* @default false
*/
noChildren?: boolean;
/**
* When commenting on this tag, if this function returns a string, it will
* be appended after the tag number and a colon.
*
* @param tag The tag to comment on.
* @param opts Options.
* @param depth How deep are we in indentation clicks so far?
*/
comment?(tag: Tag, opts: RequiredCommentOptions, depth: number): string;
}
type BaseDecoder = (tag: Tag, opts: RequiredDecodeOptions) => unknown;
type TagDecoder = BaseDecoder & Commenter;
/**
* A CBOR tagged value.
* @see [IANA Registry](https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml)
* @see https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
*/
declare class Tag implements ToCBOR, Decodeable {
declare class Tag implements ToCBOR, Decodeable, ITag {
#private;

@@ -103,2 +80,2 @@ readonly tag: TagNumber;

export { type BaseDecoder, type Commenter, Tag, type TagDecoder };
export { Tag };

@@ -1,1 +0,1 @@

class i{static#e=new Map;tag;contents;constructor(t,e=void 0){this.tag=t,this.contents=e}get noChildren(){return!!i.#e.get(this.tag)?.noChildren}static registerDecoder(t,e,n){const o=this.#e.get(t);return this.#e.set(t,e),o&&("comment"in e||(e.comment=o.comment),"noChildren"in e||(e.noChildren=o.noChildren)),n&&!e.comment&&(e.comment=()=>`(${n})`),o}static clearDecoder(t){const e=this.#e.get(t);return this.#e.delete(t),e}static getDecoder(t){return this.#e.get(t)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(t){return this.contents=t,1}decode(t){const e=i.#e.get(this.tag);return e?e(this,t):this}comment(t,e){const n=i.#e.get(this.tag);if(n?.comment)return n.comment(this,t,e)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return`${this.tag}(${n(this.contents,e)})`}}export{i as Tag};
class i{static#e=new Map;tag;contents;constructor(e,t=void 0){this.tag=e,this.contents=t}get noChildren(){return!!i.#e.get(this.tag)?.noChildren}static registerDecoder(e,t,n){const o=this.#e.get(e);return this.#e.set(e,t),o&&("comment"in t||(t.comment=o.comment),"noChildren"in t||(t.noChildren=o.noChildren)),n&&!t.comment&&(t.comment=()=>`(${n})`),o}static clearDecoder(e){const t=this.#e.get(e);return this.#e.delete(e),t}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){const t=e?.tags?.get(this.tag)??i.#e.get(this.tag);return t?t(this,e):this}comment(e,t){const n=e?.tags?.get(this.tag)??i.#e.get(this.tag);if(n?.comment)return n.comment(this,e,t)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,t,n){return`${this.tag}(${n(this.contents,t)})`}}export{i as Tag};

@@ -1,3 +0,3 @@

import{MT as R,TAG as a}from"./constants.js";import{Tag as i}from"./tag.js";import{box as x,getEncoded as $}from"./box.js";import{base64ToBytes as L,base64UrlToBytes as q,isBigEndian as C,u8toHex as A}from"./utils.js";import{encode as w,registerEncoder as s,writeInt as v,writeLength as V,writeTag as k,writeUnknown as P}from"./encoder.js";import{CBORcontainer as F}from"./container.js";import{comment as K}from"./comment.js";const B=!C();function S(e){if(typeof e=="object"&&e){if(e.constructor!==Number)throw new Error(`Expected number: ${e}`)}else if(typeof e!="number")throw new Error(`Expected number: ${e}`)}function f(e){if(typeof e=="object"&&e){if(e.constructor!==String)throw new Error(`Expected string: ${e}`)}else if(typeof e!="string")throw new Error(`Expected string: ${e}`)}function l(e){if(!(e instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${e}`)}function U(e){if(!Array.isArray(e))throw new Error(`Expected Array: ${e}`)}s(Map,(e,r,n)=>{const t=[...e.entries()].map(o=>[o[0],o[1],w(o[0],n)]);if(n.rejectDuplicateKeys){const o=new Set;for(const[d,u,y]of t){const g=A(y);if(o.has(g))throw new Error(`Duplicate map key: 0x${g}`);o.add(g)}}n.sortKeys&&t.sort(n.sortKeys),V(e,e.size,R.MAP,r,n);for(const[o,d,u]of t)r.write(u),P(d,r,n)});function h(e){return f(e.contents),new Date(e.contents)}h.comment=e=>(f(e.contents),`(String Date) ${new Date(e.contents).toISOString()}`),i.registerDecoder(a.DATE_STRING,h);function O(e){return S(e.contents),new Date(e.contents*1e3)}O.comment=e=>(S(e.contents),`(Epoch Date) ${new Date(e.contents*1e3).toISOString()}`),i.registerDecoder(a.DATE_EPOCH,O),s(Date,e=>[a.DATE_EPOCH,e.valueOf()/1e3]);function p(e,r,n){if(l(r.contents),n.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${r}(h'${A(r.contents)}')`);if(n.requirePreferred&&r.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${r.tag}(h'${A(r.contents)})`);let t=r.contents.reduce((o,d)=>o<<8n|BigInt(d),0n);if(e&&(t=-1n-t),n.requirePreferred&&t>=Number.MIN_SAFE_INTEGER&&t<=Number.MAX_SAFE_INTEGER)throw new Error(`Decoding bigint that could have been int: ${t}n`);return n.boxed?x(t,r.contents):t}const N=p.bind(null,!1),_=p.bind(null,!0);N.comment=(e,r)=>`(Positive BigInt) ${p(!1,e,r)}n`,_.comment=(e,r)=>`(Negative BigInt) ${p(!0,e,r)}n`,i.registerDecoder(a.POS_BIGINT,N),i.registerDecoder(a.NEG_BIGINT,_);function I(e,r){return l(e.contents),e}I.comment=(e,r,n)=>{l(e.contents);const t={...r,initialDepth:n+2,noPrefixHex:!0},o=$(e);let u=2**((o[0]&31)-24)+1;const y=o[u]&31;let g=A(o.subarray(u,++u));y>=24&&(g+=" ",g+=A(o.subarray(u,u+2**(y-24)))),t.minCol=Math.max(t.minCol,(n+1)*2+g.length);const b=K(e.contents,t);let T=`Embedded CBOR
`;return T+=`${"".padStart((n+1)*2," ")}${g}`.padEnd(t.minCol+1," "),T+=`-- Bytes (Length: ${e.contents.length})
`,T+=b,T},I.noChildren=!0,i.registerDecoder(a.CBOR,I),i.registerDecoder(a.URI,e=>(f(e.contents),new URL(e.contents)),"URI"),s(URL,e=>[a.URI,e.toString()]),i.registerDecoder(a.BASE64URL,e=>(f(e.contents),q(e.contents)),"Base64url-encoded"),i.registerDecoder(a.BASE64,e=>(f(e.contents),L(e.contents)),"Base64-encoded"),i.registerDecoder(35,e=>(f(e.contents),new RegExp(e.contents)),"RegExp"),i.registerDecoder(21065,e=>{f(e.contents);const r=`^(?:${e.contents})$`;return new RegExp(r,"u")},"I-RegExp"),i.registerDecoder(a.REGEXP,e=>{if(U(e.contents),e.contents.length<1||e.contents.length>2)throw new Error(`Invalid RegExp Array: ${e.contents}`);return new RegExp(e.contents[0],e.contents[1])},"RegExp"),s(RegExp,e=>[a.REGEXP,[e.source,e.flags]]),i.registerDecoder(64,e=>(l(e.contents),e.contents),"uint8 Typed Array");function c(e,r,n){l(e.contents);let t=e.contents.length;if(t%r.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${r.BYTES_PER_ELEMENT}, got: ${t}`);t/=r.BYTES_PER_ELEMENT;const o=new r(t),d=new DataView(e.contents.buffer,e.contents.byteOffset,e.contents.byteLength),u=d[`get${r.name.replace(/Array/,"")}`].bind(d);for(let y=0;y<t;y++)o[y]=u(y*r.BYTES_PER_ELEMENT,n);return o}function E(e,r,n,t,o){const d=o.forceEndian??B;if(k(d?r:n,e,o),v(t.byteLength,e,R.BYTE_STRING),B===d)e.write(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));else{const y=`write${t.constructor.name.replace(/Array/,"")}`,g=e[y].bind(e);for(const b of t)g(b,d)}}i.registerDecoder(65,e=>c(e,Uint16Array,!1),"uint16, big endian, Typed Array"),i.registerDecoder(66,e=>c(e,Uint32Array,!1),"uint32, big endian, Typed Array"),i.registerDecoder(67,e=>c(e,BigUint64Array,!1),"uint64, big endian, Typed Array"),i.registerDecoder(68,e=>(l(e.contents),new Uint8ClampedArray(e.contents)),"uint8 Typed Array, clamped arithmetic"),s(Uint8ClampedArray,e=>[68,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),i.registerDecoder(69,e=>c(e,Uint16Array,!0),"uint16, little endian, Typed Array"),s(Uint16Array,(e,r,n)=>E(r,69,65,e,n)),i.registerDecoder(70,e=>c(e,Uint32Array,!0),"uint32, little endian, Typed Array"),s(Uint32Array,(e,r,n)=>E(r,70,66,e,n)),i.registerDecoder(71,e=>c(e,BigUint64Array,!0),"uint64, little endian, Typed Array"),s(BigUint64Array,(e,r,n)=>E(r,71,67,e,n)),i.registerDecoder(72,e=>(l(e.contents),new Int8Array(e.contents)),"sint8 Typed Array"),s(Int8Array,e=>[72,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),i.registerDecoder(73,e=>c(e,Int16Array,!1),"sint16, big endian, Typed Array"),i.registerDecoder(74,e=>c(e,Int32Array,!1),"sint32, big endian, Typed Array"),i.registerDecoder(75,e=>c(e,BigInt64Array,!1),"sint64, big endian, Typed Array"),i.registerDecoder(77,e=>c(e,Int16Array,!0),"sint16, little endian, Typed Array"),s(Int16Array,(e,r,n)=>E(r,77,73,e,n)),i.registerDecoder(78,e=>c(e,Int32Array,!0),"sint32, little endian, Typed Array"),s(Int32Array,(e,r,n)=>E(r,78,74,e,n)),i.registerDecoder(79,e=>c(e,BigInt64Array,!0),"sint64, little endian, Typed Array"),s(BigInt64Array,(e,r,n)=>E(r,79,75,e,n)),i.registerDecoder(81,e=>c(e,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),i.registerDecoder(82,e=>c(e,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),i.registerDecoder(85,e=>c(e,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),s(Float32Array,(e,r,n)=>E(r,85,81,e,n)),i.registerDecoder(86,e=>c(e,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),s(Float64Array,(e,r,n)=>E(r,86,82,e,n)),i.registerDecoder(a.SET,(e,r)=>{if(U(e.contents),r.sortKeys){const n=F.decodeToEncodeOpts(r);let t=null;for(const o of e.contents){const d=[o,void 0,w(o,n)];if(t&&r.sortKeys(t,d)>=0)throw new Error(`Set items out of order in tag #${a.SET}`);t=d}}return new Set(e.contents)},"Set"),s(Set,(e,r,n)=>{let t=[...e];if(n.sortKeys){const o=t.map(d=>[d,void 0,w(d,n)]);o.sort(n.sortKeys),t=o.map(([d])=>d)}return[a.SET,t]}),i.registerDecoder(a.JSON,e=>(f(e.contents),JSON.parse(e.contents)),"JSON-encoded"),i.registerDecoder(a.SELF_DESCRIBED,e=>e.contents,"Self-Described"),i.registerDecoder(a.INVALID_16,()=>{throw new Error(`Tag always invalid: ${a.INVALID_16}`)},"Invalid"),i.registerDecoder(a.INVALID_32,()=>{throw new Error(`Tag always invalid: ${a.INVALID_32}`)},"Invalid"),i.registerDecoder(a.INVALID_64,()=>{throw new Error(`Tag always invalid: ${a.INVALID_64}`)},"Invalid");function D(e){throw new Error(`Encoding ${e.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}s(ArrayBuffer,D),s(DataView,D),typeof SharedArrayBuffer<"u"&&s(SharedArrayBuffer,D);function m(e){return[NaN,e.valueOf()]}s(Boolean,m),s(Number,m),s(String,m),s(BigInt,m);
import{MT as R,TAG as a}from"./constants.js";import{box as L,getEncoded as q}from"./box.js";import{base64ToBytes as C,base64UrlToBytes as v,isBigEndian as V,u8toHex as A}from"./utils.js";import{encode as b,registerEncoder as s,writeInt as W,writeLength as k,writeTag as F,writeUnknown as P}from"./encoder.js";import{CBORcontainer as M}from"./container.js";import{Tag as i}from"./tag.js";import{Wtf8Decoder as B}from"@cto.af/wtf8";import{comment as K}from"./comment.js";const S=!V();function O(e){if(typeof e=="object"&&e){if(e.constructor!==Number)throw new Error(`Expected number: ${e}`)}else if(typeof e!="number")throw new Error(`Expected number: ${e}`)}function E(e){if(typeof e=="object"&&e){if(e.constructor!==String)throw new Error(`Expected string: ${e}`)}else if(typeof e!="string")throw new Error(`Expected string: ${e}`)}function f(e){if(!(e instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${e}`)}function U(e){if(!Array.isArray(e))throw new Error(`Expected Array: ${e}`)}s(Map,(e,r,n)=>{const t=[...e.entries()].map(o=>[o[0],o[1],b(o[0],n)]);if(n.rejectDuplicateKeys){const o=new Set;for(const[d,u,y]of t){const g=A(y);if(o.has(g))throw new Error(`Duplicate map key: 0x${g}`);o.add(g)}}n.sortKeys&&t.sort(n.sortKeys),k(e,e.size,R.MAP,r,n);for(const[o,d,u]of t)r.write(u),P(d,r,n)});function h(e){return E(e.contents),new Date(e.contents)}h.comment=e=>(E(e.contents),`(String Date) ${new Date(e.contents).toISOString()}`),i.registerDecoder(a.DATE_STRING,h);function N(e){return O(e.contents),new Date(e.contents*1e3)}N.comment=e=>(O(e.contents),`(Epoch Date) ${new Date(e.contents*1e3).toISOString()}`),i.registerDecoder(a.DATE_EPOCH,N),s(Date,e=>[a.DATE_EPOCH,e.valueOf()/1e3]);function T(e,r,n){if(f(r.contents),n.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${r}(h'${A(r.contents)}')`);if(n.requirePreferred&&r.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${r.tag}(h'${A(r.contents)})`);let t=r.contents.reduce((o,d)=>o<<8n|BigInt(d),0n);if(e&&(t=-1n-t),n.requirePreferred&&t>=Number.MIN_SAFE_INTEGER&&t<=Number.MAX_SAFE_INTEGER)throw new Error(`Decoding bigint that could have been int: ${t}n`);return n.boxed?L(t,r.contents):t}const _=T.bind(null,!1),$=T.bind(null,!0);_.comment=(e,r)=>`(Positive BigInt) ${T(!1,e,r)}n`,$.comment=(e,r)=>`(Negative BigInt) ${T(!0,e,r)}n`,i.registerDecoder(a.POS_BIGINT,_),i.registerDecoder(a.NEG_BIGINT,$);function D(e,r){return f(e.contents),e}D.comment=(e,r,n)=>{f(e.contents);const t={...r,initialDepth:n+2,noPrefixHex:!0},o=q(e);let u=2**((o[0]&31)-24)+1;const y=o[u]&31;let g=A(o.subarray(u,++u));y>=24&&(g+=" ",g+=A(o.subarray(u,u+2**(y-24)))),t.minCol=Math.max(t.minCol,(n+1)*2+g.length);const p=K(e.contents,t);let I=`Embedded CBOR
`;return I+=`${"".padStart((n+1)*2," ")}${g}`.padEnd(t.minCol+1," "),I+=`-- Bytes (Length: ${e.contents.length})
`,I+=p,I},D.noChildren=!0,i.registerDecoder(a.CBOR,D),i.registerDecoder(a.URI,e=>(E(e.contents),new URL(e.contents)),"URI"),s(URL,e=>[a.URI,e.toString()]),i.registerDecoder(a.BASE64URL,e=>(E(e.contents),v(e.contents)),"Base64url-encoded"),i.registerDecoder(a.BASE64,e=>(E(e.contents),C(e.contents)),"Base64-encoded"),i.registerDecoder(35,e=>(E(e.contents),new RegExp(e.contents)),"RegExp"),i.registerDecoder(21065,e=>{E(e.contents);const r=`^(?:${e.contents})$`;return new RegExp(r,"u")},"I-RegExp"),i.registerDecoder(a.REGEXP,e=>{if(U(e.contents),e.contents.length<1||e.contents.length>2)throw new Error(`Invalid RegExp Array: ${e.contents}`);return new RegExp(e.contents[0],e.contents[1])},"RegExp"),s(RegExp,e=>[a.REGEXP,[e.source,e.flags]]),i.registerDecoder(64,e=>(f(e.contents),e.contents),"uint8 Typed Array");function c(e,r,n){f(e.contents);let t=e.contents.length;if(t%r.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${r.BYTES_PER_ELEMENT}, got: ${t}`);t/=r.BYTES_PER_ELEMENT;const o=new r(t),d=new DataView(e.contents.buffer,e.contents.byteOffset,e.contents.byteLength),u=d[`get${r.name.replace(/Array/,"")}`].bind(d);for(let y=0;y<t;y++)o[y]=u(y*r.BYTES_PER_ELEMENT,n);return o}function l(e,r,n,t,o){const d=o.forceEndian??S;if(F(d?r:n,e,o),W(t.byteLength,e,R.BYTE_STRING),S===d)e.write(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));else{const y=`write${t.constructor.name.replace(/Array/,"")}`,g=e[y].bind(e);for(const p of t)g(p,d)}}i.registerDecoder(65,e=>c(e,Uint16Array,!1),"uint16, big endian, Typed Array"),i.registerDecoder(66,e=>c(e,Uint32Array,!1),"uint32, big endian, Typed Array"),i.registerDecoder(67,e=>c(e,BigUint64Array,!1),"uint64, big endian, Typed Array"),i.registerDecoder(68,e=>(f(e.contents),new Uint8ClampedArray(e.contents)),"uint8 Typed Array, clamped arithmetic"),s(Uint8ClampedArray,e=>[68,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),i.registerDecoder(69,e=>c(e,Uint16Array,!0),"uint16, little endian, Typed Array"),s(Uint16Array,(e,r,n)=>l(r,69,65,e,n)),i.registerDecoder(70,e=>c(e,Uint32Array,!0),"uint32, little endian, Typed Array"),s(Uint32Array,(e,r,n)=>l(r,70,66,e,n)),i.registerDecoder(71,e=>c(e,BigUint64Array,!0),"uint64, little endian, Typed Array"),s(BigUint64Array,(e,r,n)=>l(r,71,67,e,n)),i.registerDecoder(72,e=>(f(e.contents),new Int8Array(e.contents)),"sint8 Typed Array"),s(Int8Array,e=>[72,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),i.registerDecoder(73,e=>c(e,Int16Array,!1),"sint16, big endian, Typed Array"),i.registerDecoder(74,e=>c(e,Int32Array,!1),"sint32, big endian, Typed Array"),i.registerDecoder(75,e=>c(e,BigInt64Array,!1),"sint64, big endian, Typed Array"),i.registerDecoder(77,e=>c(e,Int16Array,!0),"sint16, little endian, Typed Array"),s(Int16Array,(e,r,n)=>l(r,77,73,e,n)),i.registerDecoder(78,e=>c(e,Int32Array,!0),"sint32, little endian, Typed Array"),s(Int32Array,(e,r,n)=>l(r,78,74,e,n)),i.registerDecoder(79,e=>c(e,BigInt64Array,!0),"sint64, little endian, Typed Array"),s(BigInt64Array,(e,r,n)=>l(r,79,75,e,n)),i.registerDecoder(81,e=>c(e,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),i.registerDecoder(82,e=>c(e,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),i.registerDecoder(85,e=>c(e,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),s(Float32Array,(e,r,n)=>l(r,85,81,e,n)),i.registerDecoder(86,e=>c(e,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),s(Float64Array,(e,r,n)=>l(r,86,82,e,n)),i.registerDecoder(a.SET,(e,r)=>{if(U(e.contents),r.sortKeys){const n=M.decodeToEncodeOpts(r);let t=null;for(const o of e.contents){const d=[o,void 0,b(o,n)];if(t&&r.sortKeys(t,d)>=0)throw new Error(`Set items out of order in tag #${a.SET}`);t=d}}return new Set(e.contents)},"Set"),s(Set,(e,r,n)=>{let t=[...e];if(n.sortKeys){const o=t.map(d=>[d,void 0,b(d,n)]);o.sort(n.sortKeys),t=o.map(([d])=>d)}return[a.SET,t]}),i.registerDecoder(a.JSON,e=>(E(e.contents),JSON.parse(e.contents)),"JSON-encoded");function x(e){return f(e.contents),new B().decode(e.contents)}x.comment=e=>{f(e.contents);const r=new B;return`(WTF8 string): ${JSON.stringify(r.decode(e.contents))}`},i.registerDecoder(a.WTF8,x),i.registerDecoder(a.SELF_DESCRIBED,e=>e.contents,"Self-Described"),i.registerDecoder(a.INVALID_16,()=>{throw new Error(`Tag always invalid: ${a.INVALID_16}`)},"Invalid"),i.registerDecoder(a.INVALID_32,()=>{throw new Error(`Tag always invalid: ${a.INVALID_32}`)},"Invalid"),i.registerDecoder(a.INVALID_64,()=>{throw new Error(`Tag always invalid: ${a.INVALID_64}`)},"Invalid");function w(e){throw new Error(`Encoding ${e.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}s(ArrayBuffer,w),s(DataView,w),typeof SharedArrayBuffer<"u"&&s(SharedArrayBuffer,w);function m(e){return[NaN,e.valueOf()]}s(Boolean,m),s(Number,m),s(String,m),s(BigInt,m);

@@ -1,3 +0,3 @@

declare const version = "1.12.0";
declare const version = "2.0.0";
export { version };

@@ -1,1 +0,1 @@

const o="1.12.0";export{o as version};
const o="2.0.0";export{o as version};

@@ -1,2 +0,2 @@

export { T as TagNumber, j as TaggedValue, k as ToCBOR, l as Writer } from './options-BZO68bQ0.js';
export { m as ToCBOR, n as Writer } from './options-p0HVYXSE.js';
import './sorts.js';

@@ -1,1 +0,1 @@

class e{static defaultOptions={chunkSize:4096};#r;#i=[];#s=null;#t=0;#a=0;constructor(t={}){if(this.#r={...e.defaultOptions,...t},this.#r.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#r.chunkSize}`);this.#n()}get length(){return this.#a}read(){this.#l();const t=new Uint8Array(this.#a);let i=0;for(const s of this.#i)t.set(s,i),i+=s.length;return this.#n(),t}write(t){const i=t.length;i>this.#o()?(this.#l(),i>this.#r.chunkSize?(this.#i.push(t),this.#n()):(this.#n(),this.#i[this.#i.length-1].set(t),this.#t=i)):(this.#i[this.#i.length-1].set(t,this.#t),this.#t+=i),this.#a+=i}writeUint8(t){this.#e(1),this.#s.setUint8(this.#t,t),this.#h(1)}writeUint16(t,i=!1){this.#e(2),this.#s.setUint16(this.#t,t,i),this.#h(2)}writeUint32(t,i=!1){this.#e(4),this.#s.setUint32(this.#t,t,i),this.#h(4)}writeBigUint64(t,i=!1){this.#e(8),this.#s.setBigUint64(this.#t,t,i),this.#h(8)}writeInt16(t,i=!1){this.#e(2),this.#s.setInt16(this.#t,t,i),this.#h(2)}writeInt32(t,i=!1){this.#e(4),this.#s.setInt32(this.#t,t,i),this.#h(4)}writeBigInt64(t,i=!1){this.#e(8),this.#s.setBigInt64(this.#t,t,i),this.#h(8)}writeFloat32(t,i=!1){this.#e(4),this.#s.setFloat32(this.#t,t,i),this.#h(4)}writeFloat64(t,i=!1){this.#e(8),this.#s.setFloat64(this.#t,t,i),this.#h(8)}clear(){this.#a=0,this.#i=[],this.#n()}#n(){const t=new Uint8Array(this.#r.chunkSize);this.#i.push(t),this.#t=0,this.#s=new DataView(t.buffer,t.byteOffset,t.byteLength)}#l(){if(this.#t===0){this.#i.pop();return}const t=this.#i.length-1;this.#i[t]=this.#i[t].subarray(0,this.#t),this.#t=0,this.#s=null}#o(){const t=this.#i.length-1;return this.#i[t].length-this.#t}#e(t){this.#o()<t&&(this.#l(),this.#n())}#h(t){this.#t+=t,this.#a+=t}}export{e as Writer};
class e{static defaultOptions={chunkSize:4096};#r;#i=[];#s=null;#t=0;#a=0;constructor(t={}){if(this.#r={...e.defaultOptions,...t},this.#r.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#r.chunkSize}`);this.#n()}get length(){return this.#a}read(){this.#o();const t=new Uint8Array(this.#a);let i=0;for(const s of this.#i)t.set(s,i),i+=s.length;return this.#n(),t}write(t){const i=t.length;i>this.#l()?(this.#o(),i>this.#r.chunkSize?(this.#i.push(t),this.#n()):(this.#n(),this.#i[this.#i.length-1].set(t),this.#t=i)):(this.#i[this.#i.length-1].set(t,this.#t),this.#t+=i),this.#a+=i}writeUint8(t){this.#e(1),this.#s.setUint8(this.#t,t),this.#h(1)}writeUint16(t,i=!1){this.#e(2),this.#s.setUint16(this.#t,t,i),this.#h(2)}writeUint32(t,i=!1){this.#e(4),this.#s.setUint32(this.#t,t,i),this.#h(4)}writeBigUint64(t,i=!1){this.#e(8),this.#s.setBigUint64(this.#t,t,i),this.#h(8)}writeInt16(t,i=!1){this.#e(2),this.#s.setInt16(this.#t,t,i),this.#h(2)}writeInt32(t,i=!1){this.#e(4),this.#s.setInt32(this.#t,t,i),this.#h(4)}writeBigInt64(t,i=!1){this.#e(8),this.#s.setBigInt64(this.#t,t,i),this.#h(8)}writeFloat32(t,i=!1){this.#e(4),this.#s.setFloat32(this.#t,t,i),this.#h(4)}writeFloat64(t,i=!1){this.#e(8),this.#s.setFloat64(this.#t,t,i),this.#h(8)}clear(){this.#a=0,this.#i=[],this.#n()}#n(){const t=new Uint8Array(this.#r.chunkSize);this.#i.push(t),this.#t=0,this.#s=new DataView(t.buffer,t.byteOffset,t.byteLength)}#o(){if(this.#t===0){this.#i.pop();return}const t=this.#i.length-1;this.#i[t]=this.#i[t].subarray(0,this.#t),this.#t=0,this.#s=null}#l(){const t=this.#i.length-1;return this.#i[t].length-this.#t}#e(t){this.#l()<t&&(this.#o(),this.#n())}#h(t){this.#t+=t,this.#a+=t}}export{e as Writer};
{
"name": "cbor2",
"version": "1.12.0",
"version": "2.0.0",
"description": "Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).",

@@ -33,3 +33,4 @@ "exports": {

"rfc7049",
"rfc8949"
"rfc8949",
"rfc8742"
],

@@ -45,8 +46,15 @@ "author": {

"url": "https://github.com/irfan798"
},
{
"name": "Mark Wubben",
"url": "https://novemberborn.net"
}
],
"license": "MIT",
"dependencies": {
"@cto.af/wtf8": "0.0.2"
},
"engines": {
"node": ">=18.7"
"node": ">=20"
}
}

@@ -61,3 +61,3 @@ # cbor2

- number (including -0, NaN, and ±Infinity)
- string
- string (Set the wtf8 option to enable encoding invalid UTF-16 strings to tag 273)
- bigint

@@ -111,2 +111,3 @@ - Array

| 262 | any |
| 273 | string |
| 21065 | RegExp |

@@ -175,2 +176,19 @@ | 21066 | RegExp |

If you want to have different encoders for different calls to `encode`, you
can pass a `types` parameter to `encode`:
```js
import {TypeEncoderMap, encode} from 'cbor2';
import {Buffer} from 'node:buffer';
const types = new TypeEncoderMap();
types.registerEncoder(Buffer, b => [
// Don't write a tag
NaN,
// New view on the ArrayBuffer, without copying bytes
new Uint8Array(b.buffer, b.byteOffset, b.byteLength),
]);
encode(Buffer.from('foo'), {types});
```
## Adding new decoders

@@ -200,2 +218,12 @@

Finally, you can pass a `tags` parameter to `decode` to specify tag decoding
for a single call to `decode`:
```js
const tags = new Map([
[64000, ({contents}) => new Foo(contents[0], contents[1])],
]);
decode('d9fa00820102', {tags});
```
## Boxed Types

@@ -237,2 +265,18 @@

## CBOR Sequences
If you would like to decode a
[CBOR Sequence](https://www.rfc-editor.org/rfc/rfc8742.html),
use the `decodeSequence` method, which returns an iterator:
```js
import {decodeSequence} from 'cbor';
for (const item of decodeSequence('0102')) {
console.log(item); // First 1, then 2
}
// Or
const seq = [...decodeSequence('0102')]; // [1, 2]
```
## Developers

@@ -239,0 +283,0 @@

import { KeySorter, KeyValueEncoded } from './sorts.js';
declare class Writer {
#private;
static defaultOptions: RequiredWriterOptions;
constructor(opts?: WriterOptions);
get length(): number;
read(): Uint8Array;
write(buf: Uint8Array): void;
writeUint8(n: number): void;
writeUint16(n: number, littleEndian?: boolean): void;
writeUint32(n: number, littleEndian?: boolean): void;
writeBigUint64(n: bigint, littleEndian?: boolean): void;
writeInt16(n: number, littleEndian?: boolean): void;
writeInt32(n: number, littleEndian?: boolean): void;
writeBigInt64(n: bigint, littleEndian?: boolean): void;
writeFloat32(n: number, littleEndian?: boolean): void;
writeFloat64(n: number, littleEndian?: boolean): void;
clear(): void;
}
type TagNumber = bigint | number | Number;
/**
* A potentially-tagged value. If the tag is NaN, it will not be used.
* Otherwise, it must be an integer that will be written as a CBOR tag
* before the value is encoded.
*/
type TaggedValue = [tag: TagNumber, value: unknown];
interface ToCBOR {
/**
* If an object implements this interface, this method will be used to
* serialize the object when encoding. Return undefined if you don't want
* any further serialization to take place. Return an array of [tag, value]
* if you would like default serialization, where if tag is not NaN, a
* CBOR tag will be written before the value.
*
* @param w Writer.
* @param opts Options.
*/
toCBOR(w: Writer, opts: RequiredEncodeOptions): TaggedValue | undefined;
}
type SimpleValue = true | false | null | undefined | Simple;
/**
* A CBOR "Simple" value that is not one of the pre-standardized set.
*/
declare class Simple implements ToCBOR {
static KnownSimple: Map<number, SimpleValue>;
value: number;
constructor(value: number);
static create(num: number): SimpleValue;
toCBOR(w: Writer, opts: RequiredEncodeOptions): undefined;
toString(): string;
/**
* Convert this simple value to a useful data type, if possible.
*
* @returns The converted value.
*/
decode(): SimpleValue;
}
/**
* Options for decoding.
*/
interface DecodeStreamOptions {
/**
* Maximum allowed depth to parse into CBOR structures. This limit is
* security-relevant for untrusted inputs. May be set to Infinity for
* trusted inputs, but be careful!
* @default 1024
*/
maxDepth?: number;
/**
* If the input is a string, how should it be decoded into a byte stream?
* Ignored if the input is a Uint8Array.
* @default null
*/
encoding?: 'base64' | 'hex' | null;
/**
* Reject integers and lengths that could have been encoded in a smaller
* encoding.
*
* @default false
*/
requirePreferred?: boolean;
}
/**
* These less-complex types are decoded as tokens at this level.
*/
type DecodeValue = Simple | Symbol | Uint8Array | bigint | boolean | number | string | null | undefined;
interface Sliceable {
toHere(begin?: number): Uint8Array;
}
/**
* Information about a decoded CBOR data item. 3-element tuple, containing:
* - Major type.
* - Additional Information (int if < 23, else length as 24-27, 31 as stream).
* - Decoded token value.
* - Offset into the input where this item started.
*/
type MtAiValue = [
mt: number,
ai: number,
val: DecodeValue,
offset: number,
len: bigint | number
];
interface ParentConstructor {
new (mav: MtAiValue, left: number, parent: Parent | undefined, opts: RequiredDecodeOptions): Parent;
}
interface Decodeable {
decode(options: RequiredDecodeOptions): unknown;
}
interface Parent {
parent: Parent | undefined;
children: Decodeable | unknown[];
left: number;
offset: number;
depth: number;
get done(): boolean;
get isStreaming(): boolean;
push(child: unknown, stream: Sliceable, offset: number): number;
replaceLast(child: unknown, item: Parent, stream: Sliceable): unknown;
convert(stream: Sliceable): unknown;
}
/**
* See String.prototype.normalize.
*/
type StringNormalization = 'NFC' | 'NFD' | 'NFKC' | 'NFKD';
/**
* Different styles of diagnose output for "spec" sizes. "Spec" sizes
* are _i for 0-23 encoded in the AI byte, _0 for one extra byte, _1
* for two extra bytes, _2 for four extra bytes, _3 for eight extra bytes,
* and a plain _ for indefinite encoding.
*/
declare enum DiagnosticSizes {
/** Never use spec sizes, except for as required for indefinite encoding. */
NEVER = -1,
/** Only use spec sizes when non-preferred encoding was used. */
PREFERRED = 0,
/** Always use spec sizes. */
ALWAYS = 1
}
type ObjectCreator = (kve: KeyValueEncoded[], opts: RequiredDecodeOptions) => unknown;
/**
* Decoding options.
*/
interface DecodeOptions extends DecodeStreamOptions {
/**
* What type to create when a container is needed? This is used internally
* by comment and diagnose to add separate functionality. Internal use only.
* @default CBORcontainer
* @private
*/
ParentType?: ParentConstructor;
/**
* Should numbers and strings be created as boxed instances, which retain
* their original encoding for round-tripping? If this is true,
* saveOriginal is also set to true. Think of this as "saveOriginal +
* extras". The thought is that most use cases for saveOriginal will want
* the original encoding of an object or array, and won't care about the
* original encoding of strings and numbers. Turning this on also has the
* side-effect of making all CBOR maps decode as JS Map objects, rather than
* plain Objects.
* @default false
*/
boxed?: boolean;
/**
* Turn on options for draft-ietf-cbor-cde-05.
*/
cde?: boolean;
/**
* In dCBOR, JS numbers between 2^53 and 2^64 get encoded as CBOR integers.
* When decoding, present them as JS numbers instead of BigInt, losing
* accuracy.
*/
convertUnsafeIntsToFloat?: boolean;
/**
* Turn on options for draft-mcnally-deterministic-cbor-11.
*/
dcbor?: boolean;
/**
* Should the size of an element always be appended to that element using
* an underscore when calling diagnose?
* @default DiagnosticSizes.PREFERRED
*/
diagnosticSizes?: DiagnosticSizes;
/**
* Create an object from an array of key-value pairs. The default
* implementation creates a plain JS object if all of the keys are strings,
* otherwise creates a Map (unless preferMap or boxed is set, in which case
* a Map is always created).
*/
createObject?: ObjectCreator;
/**
* Always generate Map instances when decoding, instead of trying to
* generate object instances when all of the keys are strings. If you
* have the boxed option on, this option has no effect, and Maps are always
* produced.
*/
preferMap?: boolean;
/**
* Pretty-print diagnostic format.
* @default false
*/
pretty?: boolean;
/**
* Reject negative integers in the range [CBOR_NEGATIVE_INT_MAX ...
* STANDARD_NEGATIVE_INT_MAX - 1].
* @default false
*/
rejectLargeNegatives?: boolean;
/**
* If there are bigint (tag 2/3) in the incoming data, exit with an error.
* @default false
*/
rejectBigInts?: boolean;
/**
* If there are duplicate keys in a map, should we throw an exception? Note:
* this is more compute-intensive than expected at the moment, but that will
* be fixed eventually.
* @default false
*/
rejectDuplicateKeys?: boolean;
/**
* Reject any floating point numbers. This might be used in profiles that
* are not expecting floats to prevent one from being coerced to an
* integer-looking number without the receiver knowing.
* @default false
*/
rejectFloats?: boolean;
/**
* Reject any mt 0/1 numbers. This might be used in profiles that expect
* all numbers to be encoded as floating point.
* @default false
*/
rejectInts?: boolean;
/**
* Reject floating point numbers that should have been encoded in shorter
* form, including having been encoded as an integer.
*/
rejectLongFloats?: boolean;
/**
* Reject NaNs that are not encoded as 0x7e00.
* @default false
*/
rejectLongLoundNaN?: boolean;
/**
* If negative zero (-0) is received, throw an error.
* @default false
*/
rejectNegativeZero?: boolean;
/**
* Reject simple values other than true, false, undefined, and null.
* @default false
*/
rejectSimple?: boolean;
/**
* Reject any attempt to decode streaming CBOR.
* @default false
*/
rejectStreaming?: boolean;
/**
* Reject subnormal floating point numbers.
* @default false
*/
rejectSubnormals?: boolean;
/**
* Reject strings that are not normalized with the given normalization form.
* Don't use this without Unicode expertise.
*/
rejectStringsNotNormalizedAs?: StringNormalization | null;
/**
* For dCBOR, reject "integers" between 2^53 and 2^64 that were encoded
* as floats.
*/
rejectUnsafeFloatInts?: boolean;
/**
* Reject the `undefined` simple value. Usually used with rejectSimple.
* @default false
*/
rejectUndefined?: boolean;
/**
* Save the original bytes associated with every object as a property of
* that object. Use `getEncoded(obj)` to retrieve the associated bytes.
* If you need the original encoded form of primitive items such as numbers
* and strings, set `boxed: true` as well.
*/
saveOriginal?: boolean;
/**
* If non-null, keys being decoded MUST be in this order. Note that this is a
* superset of rejectDuplicateKeys, and is slightly more efficient.
* @default null
*/
sortKeys?: KeySorter | null;
}
type RequiredDecodeOptions = Required<DecodeOptions>;
/**
* Comment options on top of the decode options.
*/
interface CommentOptions extends DecodeOptions {
/**
* For the root object, how many levels of nesting is it already?
* Happens with tag 24.
* @default 0
*/
initialDepth?: number;
/**
* If true, don't add the initial 0xHEX line to comment output.
* @default false
*/
noPrefixHex?: boolean;
/**
* The '--' separating bytes from description must be in at least this
* column.
* @default 0
*/
minCol: number;
}
type RequiredCommentOptions = Required<CommentOptions>;
interface WriterOptions {
chunkSize?: number;
}
type RequiredWriterOptions = Required<WriterOptions>;
interface EncodeOptions extends WriterOptions {
/**
* Encode all integers as floating point numbers of the correct size.
* @default false
*/
avoidInts?: boolean;
/**
* Turn on options for draft-ietf-cbor-cde-05.
*/
cde?: boolean;
/**
* Should bigints that can fit into normal integers be collapsed into
* normal integers?
* @default true
*/
collapseBigInts?: boolean;
/**
* Turn on options for draft-mcnally-deterministic-cbor-11.
*/
dcbor?: boolean;
/**
* When writing floats, always use the 64-bit version. Often combined with
* `avoidInts`.
* @default false
*/
float64?: boolean;
/**
* When writing floats, first flush any subnormal numbers to zero before
* decising on encoding.
*/
flushToZero?: boolean;
/**
* How to write TypedArrays?
* Null to use the current platform's endian-ness.
* True to always use little-endian.
* False to always use big-endian.
* @default null
*/
forceEndian?: boolean | null;
/**
* Ignore sizes on boxed numbers; they might be overly-large.
* @default false
*/
ignoreOriginalEncoding?: boolean;
/**
* Do not encode numbers in the range [CBOR_NEGATIVE_INT_MAX ...
* STANDARD_NEGATIVE_INT_MAX - 1] as MT 1.
* @default false
*/
largeNegativeAsBigInt?: boolean;
/**
* Per dcbor:
*
* "MUST check whether floating point values to be encoded have the
* numerically equal value in DCBOR_INT = [-2^63, 2^64-1]. If that is the
* case, it MUST be converted to that numerically equal integer value
* before encoding it. (Preferred encoding will then ensure the shortest
* length encoding is used.) If a floating point value has a non-zero
* fractional part, or an exponent that takes it out of DCBOR_INT, the
* original floating point value is used for encoding. (Specifically,
* conversion to a CBOR bignum is never considered.)"
*
* This should only apply to "integers" that are outside the JS safe range
* of [-(2^53 - 1), 2^53-1].
*/
reduceUnsafeNumbers?: boolean;
/**
* Do not encode bigints that cannot be reduced to integers.
* @default false
*/
rejectBigInts?: boolean;
/**
* If true, error instead of encoding an instance of Simple.
* @default false
*/
rejectCustomSimples?: boolean;
/**
* Check that Maps do not contain keys that encode to the same bytes as
* one another. This is possible in a Map with object keys.
* @default false
*/
rejectDuplicateKeys?: boolean;
/**
* Do not encode floating point numbers that cannot be reduced to integers.
* @default false
*/
rejectFloats?: boolean;
/**
* If true, error instead of encoding `undefined`.
* @default false
*/
rejectUndefined?: boolean;
/**
* If true, encode -0 as 0.
* @default false
*/
simplifyNegativeZero?: boolean;
/**
* How should the key/value pairs be sorted before an object or Map
* gets created? If null, no sorting is performed.
* @default null
*/
sortKeys?: KeySorter | null;
/**
* If specified, normalize strings on encoding. 'NFD' may optimize for CPU,
* 'NFC' may optimize for size. Don't use this without Unicode
* expertise. In particular, the 'K' forms are really unlikely to be useful.
* @default undefined
*/
stringNormalization?: StringNormalization | null;
}
type RequiredEncodeOptions = Required<EncodeOptions>;
export { type CommentOptions as C, type DecodeOptions as D, type EncodeOptions as E, type MtAiValue as M, type ObjectCreator as O, type Parent as P, type RequiredDecodeOptions as R, type Sliceable as S, type TagNumber as T, type WriterOptions as W, type RequiredEncodeOptions as a, type Decodeable as b, type DecodeStreamOptions as c, type DecodeValue as d, type ParentConstructor as e, type RequiredCommentOptions as f, type StringNormalization as g, DiagnosticSizes as h, Simple as i, type TaggedValue as j, type ToCBOR as k, Writer as l, type SimpleValue as m, type RequiredWriterOptions as n };