import { type TArg, type TRet } from '@noble/hashes/utils.js'; import * as P from 'micro-packed'; /** * ASN.1 OID coder without DER tag/length wrappers. * @example * Encode one ASN.1 object identifier without DER tag and length bytes. * ```ts * import { oid } from 'micro-key-producer/asn1.js'; * oid.encode('1.3.6.1.4.1.11591.15.1'); * ``` */ export declare const oid: P.CoderType; /** * ASN.1 OID coder that decodes known OIDs to names and preserves unknown OIDs as raw dotted text. * @example * Encode a named OID and decode the same bytes back to its known name. * ```ts * import { oidName } from 'micro-key-producer/asn1.js'; * oidName.decode(oidName.encode('signedData')); * ``` */ export declare const oidName: P.CoderType; type ASN1DebugTag = { TAG: 'universal'; data: { constructed: number; type: string; }; } | { TAG: 'application'; data: { constructed: number; number: number; }; } | { TAG: 'contextSpecific'; data: { constructed: number; number: number; }; } | { TAG: 'private'; data: { constructed: number; number: number; }; }; type ASN1DebugTLV = { tag: ASN1DebugTag; data: Uint8Array; }; type ASN1Debug = null | bigint | string | Uint8Array | ASN1DebugTLV | ASN1Debug[]; type ASN1StructRecord> = { [K in keyof T]: P.CoderType; }; /** Generic ASN.1 tree node used for lossless unsupported DER TLV payloads. */ type TLVNode = { /** First ASN.1 identifier octet. */ tag: number; /** Full ASN.1 identifier octets when the tag uses high-tag-number form. */ tagHex?: string; /** Nested child nodes for constructed values. */ children?: TLVNode[]; /** Hex-encoded payload for primitive values. */ valueHex?: string; }; /** Generic ASN.1 AlgorithmIdentifier shell with optional raw parameters. */ type ASN1AlgorithmIdentifier = { /** Algorithm object identifier. */ algorithm: string; /** Optional raw AlgorithmIdentifier parameters TLV. */ params?: TLVNode; }; /** Generic ASN.1 Attribute shell with raw SET OF values. */ type ASN1Attribute = { /** Attribute object identifier. */ oid: string; /** Raw ASN.1 attribute values. */ values: Uint8Array[]; }; /** Generic ASN.1 Time choice. */ type ASN1Time = { TAG: 'utc'; data: string; } | { TAG: 'generalized'; data: string; }; /** Generic ASN.1 string value choice used by schema-less TLV helpers. */ type ASN1StringValue = { TAG: 'utf8'; data: string; } | { TAG: 'printable'; data: string; } | { TAG: 'teletex'; data: string; } | { TAG: 'ia5'; data: string; } | { TAG: 'bmp'; data: string; } | { TAG: 'universal'; data: string; } | { TAG: 'visible'; data: string; } | { TAG: 'numeric'; data: string; }; /** Generic parsed ASN.1 string-or-raw value. */ type ASN1StringOrRaw = ASN1StringValue | { TAG: 'raw'; data: TLVNode; }; /** Generic best-effort parsed ASN.1 ANY value. */ type ASN1AnyValue = { TAG: 'text'; data: ASN1StringValue; } | { TAG: 'oid'; data: string; } | { TAG: 'int'; data: bigint; } | { TAG: 'bool'; data: boolean; } | { TAG: 'time'; data: ASN1Time; } | { TAG: 'octet'; data: Uint8Array; } | { TAG: 'raw'; data: TLVNode; }; type ASN1TagCoder = P.CoderType & { tagByte: number; tagBytes: number[]; constructed: number; inner: P.CoderType; }; type ASN1MaybeCoder = P.CoderType & Partial, 'tagByte' | 'tagBytes' | 'constructed' | 'inner'>>; type ASN1ChoiceRecord> = { [K in keyof T]: ASN1MaybeCoder; }; type ASN1ChoiceResult> = { [K in keyof T]: { TAG: K; data: T[K]; }; }[keyof T]; type ASN1Value = C extends ASN1MaybeCoder ? T : never; type ASN1Pub = { debug: P.CoderType; tagged: (tag: number, inner: P.CoderType) => ASN1TagCoder; ASCII: P.CoderType; Integer: ASN1TagCoder; /** Create a nonnegative DER INTEGER coder with a maximum content width. */ integer: (maxBytes: number) => ASN1TagCoder; Boolean: ASN1TagCoder; OctetString: ASN1TagCoder; OID: ASN1TagCoder; OIDMap: ASN1TagCoder; BitString: ASN1TagCoder; BitStringRaw: ASN1TagCoder<{ unused: number; bytes: Uint8Array; }>; UTF8: ASN1TagCoder; UTF8String: ASN1TagCoder; IA5String: ASN1TagCoder; PrintableString: ASN1TagCoder; TeletexString: ASN1TagCoder; VisibleString: ASN1TagCoder; NumericString: ASN1TagCoder; BMPString: ASN1TagCoder; UniversalString: ASN1TagCoder; String: P.CoderType; UTCTime: ASN1TagCoder; GeneralizedTime: ASN1TagCoder; Time: P.CoderType; null: ASN1TagCoder; any: P.CoderType; TLVNode: P.CoderType; StringOrRaw: P.CoderType; AnyValue: P.CoderType; AlgorithmIdentifier: ASN1TagCoder; Attribute: ASN1TagCoder; ECDSASig: ASN1TagCoder<{ r: bigint; s: bigint; }>; choice: >(variants: ASN1ChoiceRecord) => P.CoderType>; sequence: >(fields: ASN1StructRecord) => ASN1TagCoder; set: (inner: P.CoderType, opts?: { ber?: boolean; }) => ASN1TagCoder; explicit: (number: number, inner: P.CoderType) => ASN1TagCoder; implicit: (number: number, inner: ASN1TagCoder) => ASN1TagCoder; optional: { (inner: ASN1TagCoder): ASN1TagCoder; (inner: P.CoderType): P.CoderType; }; validate: (inner: C, fn: (value: ASN1Value) => ASN1Value) => C; }; /** Generic ASN.1 building blocks. */ export declare const ASN1: TRet; type BERPub = { view: (src: TArg, opts?: BEROpts) => TRet; decode: (src: TArg, opts?: { allowBER?: boolean; }) => TRet<{ nodes: BerNode[]; der: Uint8Array; }>; encode: (nodes: BerNode[], der: TArg) => TRet; normalize: (src: TArg, opts?: { allowBER?: boolean; }) => TRet; }; type DERPub = { /** DER length coder with minimal-length validation. */ length: P.CoderType; }; type BerNode = { len: number; lenBytes: number; indefinite: boolean; bitUnused?: number; children?: BerNode[]; cls: number; tagNum: number; cons: boolean; }; type BERDoc = { nodes: BerNode[]; der: Uint8Array; }; type BEROpts = { allowBER?: boolean; }; /** BER decoder/encoder used to normalize supported BER input to DER. */ export declare const BER: TRet; /** DER helpers. */ export declare const DER: TRet; export {};