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.11.0
to
1.12.0
+437
lib/options-BZO68bQ0.d.ts
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 };
+1
-1

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

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

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

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

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

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

static create(mav: MtAiValue, parent: Parent | undefined, opts: RequiredDecodeOptions, stream: DecodeStream): unknown;
static decodeToEncodeOpts(decode: RequiredDecodeOptions): RequiredEncodeOptions;
/**

@@ -66,0 +67,0 @@ * Add the given child to the list of children, and update how many are

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

import{DCBOR_INT as h,MT as c,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{stringToHex as p,u8concat as E,u8toHex as m}from"./utils.js";import{DecodeStream as S}from"./decodeStream.js";import{Simple as T}from"./simple.js";import{Tag as g}from"./tag.js";import{checkSubnormal as I}from"./float.js";import{encode as D}from"./encoder.js";const O=new Map([[u.ZERO,1],[u.ONE,2],[u.TWO,3],[u.FOUR,5],[u.EIGHT,9]]),k=new Uint8Array(0);function v(d,n){return!n.boxed&&!n.preferMap&&d.every(([i])=>typeof i=="string")?Object.fromEntries(d):new Map(d)}class w{static defaultDecodeOptions={...S.defaultOptions,ParentType:w,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:j.PREFERRED,convertUnsafeIntsToFloat:!1,createObject:v,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(n,i,e,t){if([this.mt,this.ai,,this.offset]=n,this.left=i,this.parent=e,this.#e=t,e&&(this.depth=e.depth+1),this.mt===c.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(n,i,e,t){const[s,l,r,a]=n;switch(s){case c.POS_INT:case c.NEG_INT:{if(e.rejectInts)throw new Error(`Unexpected integer: ${r}`);if(e.rejectLargeNegatives&&r<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${r}`);let o=r;return e.convertUnsafeIntsToFloat&&o>=h.MIN&&o<=h.MAX&&(o=Number(r)),e.boxed?f(o,t.toHere(a)):o}case c.SIMPLE_FLOAT:if(l>u.ONE){if(e.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${r}`);if(e.rejectNegativeZero&&Object.is(r,-0))throw new Error("Decoding negative zero");if(e.rejectLongLoundNaN&&isNaN(r)){const o=t.toHere(a);if(o.length!==3||o[1]!==126||o[2]!==0)throw new Error(`Invalid NaN encoding: "${m(o)}"`)}if(e.rejectSubnormals&&I(t.toHere(a+1)),e.rejectLongFloats){const o=D(r,{chunkSize:9,reduceUnsafeNumbers:e.rejectUnsafeFloatInts});if(o[0]>>5!==s)throw new Error(`Should have been encoded as int, not float: ${r}`);if(o.length<O.get(l))throw new Error(`Number should have been encoded shorter: ${r}`)}if(typeof r=="number"&&e.boxed)return f(r,t.toHere(a))}else{if(e.rejectSimple&&r instanceof T)throw new Error(`Invalid simple value: ${r}`);if(e.rejectUndefined&&r===void 0)throw new Error("Unexpected undefined")}return r;case c.BYTE_STRING:case c.UTF8_STRING:if(r===1/0)return new e.ParentType(n,1/0,i,e);if(e.rejectStringsNotNormalizedAs&&typeof r=="string"){const o=r.normalize(e.rejectStringsNotNormalizedAs);if(r!==o)throw new Error(`String not normalized as "${e.rejectStringsNotNormalizedAs}", got [${p(r)}] instead of [${p(o)}]`)}return e.boxed?f(r,t.toHere(a)):r;case c.ARRAY:return new e.ParentType(n,r,i,e);case c.MAP:return new e.ParentType(n,r*2,i,e);case c.TAG:{const o=new e.ParentType(n,1,i,e);return o.children=new g(r),o}}throw new TypeError(`Invalid major type: ${s}`)}push(n,i,e){if(this.children.push(n),this.#t){const t=b(n)||i.toHere(e);this.#t.push(t)}return--this.left}replaceLast(n,i,e){let t,s=-1/0;if(this.children instanceof g?(s=0,t=this.children.contents,this.children.contents=n):(s=this.children.length-1,t=this.children[s],this.children[s]=n),this.#t){const l=b(n)||e.toHere(i.offset);this.#t[s]=l}return t}convert(n){let i;switch(this.mt){case c.ARRAY:i=this.children;break;case c.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,r]of e){const a=m(r);if(t.has(a))throw new Error(`Duplicate key: "0x${a}"`);t.add(a)}}i=this.#e.createObject(e,this.#e);break}case c.BYTE_STRING:return E(this.children);case c.UTF8_STRING:{const e=this.children.join("");i=this.#e.boxed?f(e,n.toHere(this.offset)):e;break}case c.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,n.toHere(this.offset)),i}#r(){const n=this.children,i=n.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]=[n[t],n[t+1],this.#t[t]];else for(let t=0;t<i;t+=2)e[t>>1]=[n[t],n[t+1],k];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};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-CftLBR4a.js';
import { D as DecodeOptions } from './options-BZO68bQ0.js';
import './sorts.js';

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

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

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

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

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

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

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

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

import { f as RequiredEncodeOptions, E as EncodeOptions, l as Writer, j as TaggedValue, T as TagNumber } from './options-CftLBR4a.js';
import { a as RequiredEncodeOptions, E as EncodeOptions, l as Writer, j as TaggedValue, T as TagNumber } from './options-BZO68bQ0.js';
import './sorts.js';

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

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

function o(e,n=0,t=!1){const r=e[n]&128?-1:1,f=(e[n]&124)>>2,a=(e[n]&3)<<8|e[n+1];if(f===0){if(t&&a!==0)throw new Error(`Unwanted subnormal: ${r*5960464477539063e-23*a}`);return r*5960464477539063e-23*a}else if(f===31)return a?NaN:r*(1/0);return r*2**(f-25)*(1024+a)}function s(e){const n=new DataView(new ArrayBuffer(4));n.setFloat32(0,e,!1);const t=n.getUint32(0,!1);if(t&8191)return null;let r=t>>16&32768;const f=t>>23&255,a=t&8388607;if(!(f===0&&a===0))if(f>=113&&f<=142)r+=(f-112<<10)+(a>>13);else if(f>=103&&f<113){if(a&(1<<126-f)-1)return null;r+=a+8388608>>126-f}else if(f===255)r|=31744,r|=a>>13;else return null;return r}function i(e){if(e!==0){const n=new ArrayBuffer(8),t=new DataView(n);t.setFloat64(0,e,!1);const r=t.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n)return r&0x8000000000000000n?-0:0}return e}function l(e){switch(e.length){case 2:o(e,0,!0);break;case 4:{const n=new DataView(e.buffer,e.byteOffset,e.byteLength),t=n.getUint32(0,!1);if(!(t&2139095040)&&t&8388607)throw new Error(`Unwanted subnormal: ${n.getFloat32(0,!1)}`);break}case 8:{const n=new DataView(e.buffer,e.byteOffset,e.byteLength),t=n.getBigUint64(0,!1);if((t&0x7ff0000000000000n)===0n&&t&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${n.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${e}`)}}export{l as checkSubnormal,i as flushToZero,s as halfToUint,o as parseHalf};
function o(e,n=0,t=!1){const r=e[n]&128?-1:1,f=(e[n]&124)>>2,a=(e[n]&3)<<8|e[n+1];if(f===0){if(t&&a!==0)throw new Error(`Unwanted subnormal: ${r*5960464477539063e-23*a}`);return r*5960464477539063e-23*a}else if(f===31)return a?NaN:r*(1/0);return r*2**(f-25)*(1024+a)}function s(e){const n=new DataView(new ArrayBuffer(4));n.setFloat32(0,e,!1);const t=n.getUint32(0,!1);if((t&8191)!==0)return null;let r=t>>16&32768;const f=t>>23&255,a=t&8388607;if(!(f===0&&a===0))if(f>=113&&f<=142)r+=(f-112<<10)+(a>>13);else if(f>=103&&f<113){if(a&(1<<126-f)-1)return null;r+=a+8388608>>126-f}else if(f===255)r|=31744,r|=a>>13;else return null;return r}function i(e){if(e!==0){const n=new ArrayBuffer(8),t=new DataView(n);t.setFloat64(0,e,!1);const r=t.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n)return r&0x8000000000000000n?-0:0}return e}function l(e){switch(e.length){case 2:o(e,0,!0);break;case 4:{const n=new DataView(e.buffer,e.byteOffset,e.byteLength),t=n.getUint32(0,!1);if((t&2139095040)===0&&t&8388607)throw new Error(`Unwanted subnormal: ${n.getFloat32(0,!1)}`);break}case 8:{const n=new DataView(e.buffer,e.byteOffset,e.byteLength),t=n.getBigUint64(0,!1);if((t&0x7ff0000000000000n)===0n&&t&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${n.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${e}`)}}export{l as checkSubnormal,i as flushToZero,s as halfToUint,o as parseHalf};

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

import { D as DecodeOptions } from './options-CftLBR4a.js';
export { C as CommentOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, h as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, O as ObjectCreator, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f 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-CftLBR4a.js';
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';
export { version } from './version.js';

@@ -4,0 +4,0 @@ export { DecodeStream, ValueGenerator } from './decodeStream.js';

import './sorts.js';
export { C as CommentOptions, D as DecodeOptions, b as DecodeStreamOptions, c as DecodeValue, a as Decodeable, h as DiagnosticSizes, E as EncodeOptions, M as MtAiValue, O as ObjectCreator, P as Parent, d as ParentConstructor, e as RequiredCommentOptions, R as RequiredDecodeOptions, f as RequiredEncodeOptions, n as RequiredWriterOptions, S as Sliceable, g as StringNormalization, W as WriterOptions } from './options-CftLBR4a.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';

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

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

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

import { k as ToCBOR, a as Decodeable, T as TagNumber, R as RequiredDecodeOptions, e as RequiredCommentOptions } from './options-CftLBR4a.js';
import { k as ToCBOR, b as Decodeable, T as TagNumber, R as RequiredDecodeOptions, f as RequiredCommentOptions } from './options-BZO68bQ0.js';
import './sorts.js';

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

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

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

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

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

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

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

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

export { T as TagNumber, j as TaggedValue, k as ToCBOR, l as Writer } from './options-CftLBR4a.js';
export { T as TagNumber, j as TaggedValue, k as ToCBOR, l as Writer } from './options-BZO68bQ0.js';
import './sorts.js';
{
"name": "cbor2",
"version": "1.11.0",
"version": "1.12.0",
"description": "Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).",

@@ -5,0 +5,0 @@ "exports": {

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 Decodeable as a, type DecodeStreamOptions as b, type DecodeValue as c, type ParentConstructor as d, type RequiredCommentOptions as e, type RequiredEncodeOptions 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 };