Skip to main content

Module encoding

Module encoding 

Source
Expand description

Byte/integer encodings used at the EdDSA boundary.

EdDSA-Poseidon (@zk-kit/eddsa-poseidon) is little-endian for all buffer<->integer conversions (leBufferToBigInt / leBigIntToBuffer) - the opposite of the note cipher, which is big-endian. Keeping the two explicit here prevents accidental endianness flips.

Functions§

biguint_to_be_32
Integer -> fixed 32-byte big-endian bytes (bigIntToBytes(value, 32)), used for the cipher key material and sha256BigInt. Packs the raw value with NO field reduction (left-padded with zeros). Panics if the value does not fit in 32 bytes (matches the TS overflow guard at value >= 2^256).
biguint_to_le_bytes
Integer -> fixed-length little-endian bytes (leBigIntToBuffer(value, len)). Panics if the value does not fit in len bytes (matches the JS overflow guard).
dec_to_biguint
Parse a non-negative decimal string into a raw integer (no field reduction) - the boundary for the cipher key material, sha256BigInt, and the EdDSA message.
from_hex
Decode a hex string into bytes with the lenient semantics of Node’s Buffer.from(hex, "hex") (the EdDSA private-key encoding): parse byte pairs left-to-right, stop at the first invalid hex character, and drop a trailing odd nibble. No 0x stripping - Buffer.from does not strip it either (it would stop at the x).
le_bytes_to_biguint
Little-endian bytes -> integer (leBufferToBigInt).