UNPKG

@coti-io/coti-sdk-typescript

Version:

A library for encryption, decryption and cryptographic utilities for the COTI blockchain.

50 lines (49 loc) 2 kB
import { ctUint256 } from './types'; /** Radix used for hex encoding/decoding in this module. */ export declare const HEX_BASE = 16; /** Byte length of a single {@link ctUint} on the wire (ciphertext + random `r`). */ export declare const CT_SIZE = 32; /** * Encodes an unsigned bigint as a fixed-width big-endian byte array. * * @param value - Integer to encode. * @param width - Output length in bytes; leading zero bytes are emitted as needed. * @returns Big-endian bytes of length `width`. */ export declare function bigintToBytesBE(value: bigint, width: number): Uint8Array; /** * Decodes a big-endian byte array into an unsigned bigint. * * @param bytes - Non-empty byte array to decode. * @returns Unsigned integer represented by `bytes`. * @throws SyntaxError if `bytes` is empty. */ export declare function bytesToBigint(bytes: Uint8Array): bigint; /** * Encodes bytes as a lowercase hex string (two digits per byte). * * @param bytes - Byte array to encode. * @returns Hex string without `0x` prefix. */ export declare function bytesToHex(bytes: Uint8Array): string; /** * Serializes a {@link ctUint} bigint to its 32-byte on-wire representation. * * @param ciphertext - ctUint value as a bigint. * @returns 32-byte big-endian blob ({@link CT_SIZE} bytes). */ export declare function ctUintToBytes(ciphertext: bigint): Uint8Array; /** * Serializes a {@link ctUint256} to a 64-byte concatenation of its two ctUint limbs. * * @param ciphertext - ctUint256 with `ciphertextHigh` and `ciphertextLow`. * @returns 64-byte buffer: high limb (32 B) followed by low limb (32 B). */ export declare function ctUint256ToBytes(ciphertext: ctUint256): Uint8Array; /** * Parses a 64-byte ciphertext blob into a {@link ctUint256} object. * * @param ciphertext - 64-byte buffer (typically from encryption helpers). * @returns ctUint256 with `ciphertextHigh` and `ciphertextLow` bigints. */ export declare function ciphertextBytesToCtUint256(ciphertext: Uint8Array): ctUint256;