/** * RFC 8017 §4 integer/octet-string primitives, and the canonical byte * encodings pinned by spec §6.12. Mirrors `crates/px402-core/src/encoding.rs`. * * `I2OSP` (Integer-to-Octet-String) and `OS2IP` (Octet-String-to-Integer) are * the two conversions every fixed-width RSA field in this SDK's hash and * signature encodings is built from: "integers modulo an RSA modulus... * fixed-width, left-padded with zero bytes to exactly `L = ceil(bitlen(N) / * 8)`. Minimal-length big-endian encoding is FORBIDDEN." (§6.12) * * JS `BigInt` has no natural byte encoding, and every hand-rolled * bigint-to-bytes conversion (including one built on `toString(16)`, where an * odd-length hex string silently loses a nibble on parse-back) strips leading * zero bytes. Roughly 1 in 256 values modulo an RSA modulus has a leading * zero byte, so any code path that skips `i2osp` in favour of a "natural" * conversion is wrong on ~0.4% of coins -- frequent enough to reach * production, rare enough to pass a hand-written test suite. Every * fixed-width integer field in this SDK MUST go through `i2osp` / `os2ip`, * and neither is implemented via string conversion of any radix. */ /** * RFC 5869 §2.3 caps a single HKDF-Expand call at `255 * HashLen` octets. For * SHA-512, `HashLen = 64`, so the cap is 16,320 bytes -- the RFC's * counter-based construction uses a single output octet as the block * counter, `1..=255`. `kdf.ts` and `selectSeeded.ts` both enforce this * explicitly against every call; it lives here, beside the other canonical * encoding constants, rather than being asserted "by construction" anywhere. */ export declare const MAX_HKDF_OUT = 16320; /** * `I2OSP(v, len)` (RFC 8017 §4.1): the fixed-width, left-zero-padded * big-endian encoding of `v` in exactly `len` bytes. * * Fails -- rather than truncating -- when `v >= 2^(8*len)`, i.e. when `v`'s * minimal big-endian encoding does not fit in `len` bytes. RFC 8017 itself * specifies this as an error ("integer too large"); spec §6.12 repeats it * explicitly for `pad(v, L)`. Silently truncating would drop high-order * bytes of `v` and let two distinct integers encode identically. * * Implemented with bigint shifts only (no `toString` of any radix): the * output buffer is filled from the least-significant byte backward, and * whatever remains of `v` after `len` bytes have been consumed is the * overflow check. */ export declare function i2osp(v: bigint, len: number): Uint8Array; /** * `OS2IP(X)` (RFC 8017 §4.2), with an optional caller-fixed input length: * interprets `bytes` as a big-endian unsigned integer, and -- when * `expectLen` is supplied -- only if `bytes.length === expectLen` exactly. * * The length check is the point of taking `expectLen` at all: a bare * `OS2IP` happily accepts both a minimal-length encoding and a zero-padded * one for the same integer, which is exactly the ambiguity §6.12 forbids. * Requiring the caller to state the width it expects (the modulus width * `L`, at every current call site) turns "two byte strings decode to the * same integer" into "one of them is simply rejected." * * Implemented by accumulating big-endian bytes directly into a bigint (no * intermediate hex string), so an odd digit count can never lose a nibble. */ export declare function os2ip(bytes: Uint8Array, expectLen?: number): bigint; /** `be32(n)` -- spec §6.12: a 4-byte big-endian unsigned integer (refresh's `attempt`/`i`/`j` indices). */ export declare function be32(n: number): Uint8Array; /** * `be64(n)` -- spec §6.12: an 8-byte big-endian unsigned integer (the * withdraw coin counter). Accepts `bigint` so a lifetime-monotonic counter * is never silently clamped to `Number.MAX_SAFE_INTEGER`; `number` is * accepted only as a convenience for small, exactly-representable values. */ export declare function be64(n: bigint | number): Uint8Array; /** Concatenates byte strings, in argument order, into one freshly allocated `Uint8Array`. */ export declare function concat(...parts: Uint8Array[]): Uint8Array; /** * Bare lowercase hex, no `0x` (§6.14's spelling for an opaque protocol byte * string, and the key every coin map in this package uses). */ export declare function hexOf(bytes: Uint8Array): string; /** * Byte-for-byte equality, length first. Not constant-time: every caller * compares public values (hashes, keys, chain links). */ export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;