import { A as AbstractFormatter } from '../abstract-formatter-Dvp6Dh6e.js';
import { A as AbstractSymmetricCrypt } from '../abstract-symmetric-crypt-C3ASlnxn.js';
import { A as AbstractStruct } from '../abstract-struct-CmI-d1DB.js';

type CryptKeyCallback = (zoneId: number | bigint) => Buffer;
/**
 * Signature v5 envelope/parser
 */
declare class Signature5 extends AbstractSignature {
    VERSION: number;
    protected HEADER_LENGTH: number;
    protected zoneId: number | bigint | undefined;
    /**
     * Creates a new signature envelope
     */
    constructor(zoneId?: bigint, payload?: Payload);
    /**
     * Retrieve zone ID
     * @return int|null
     */
    getZoneId(): bigint | number | undefined;
    /**
     * Embed new zone ID
     * @param int zoneId
     * @return void
     */
    setZoneId(zoneId: bigint): void;
    /**
     * Simplified signature parsing/validation
     * @param string signature
     * @param array ipAddresses
     * @param string userAgent
     * @param Closure|string cryptKey
     * @param AbstractFormatter|null formatter
     * @return self
     */
    static createFromRequest(signature: string, ipAddresses: Array<string>, userAgent: string, cryptKey: Buffer | CryptKeyCallback, formatter?: AbstractFormatter | null): AbstractSignature;
    private static toCallback;
    /**
     * Default V5 signature validator
     * @param array result
     * @param array ipAddresses
     * @param string userAgent
     * @throws Error
     */
    verify(ipAddresses: Array<string>, userAgent: string): boolean;
    /**
     * Produce an encrypted signature
     * @param AdScore\Common\Struct\AbstractStruct struct
     * @param AdScore\Common\Crypt\Symmetric\AbstractSymmetricCrypt crypt
     * @param string cryptKey
     * @param AdScore\Common\Formatter\AbstractFormatter formatter		Signature formatter
     * @return string
     */
    format(struct: AbstractStruct, crypt: AbstractSymmetricCrypt, cryptKey: Buffer, formatter?: AbstractFormatter | null): string;
    /**
     * Parses and decodes a signature
     * @param string signature Formatted signature
     * @param Closure onCryptKeyRequest Zone ID is passed as parameter, this callback should return a decryption key
     * @param AdScore\Common\Formatter\AbstractFormatter formatter Signature format decoder
     */
    parse(signature: string, onCryptKeyRequest: (zoneId: bigint | number) => Buffer, formatter?: AbstractFormatter | null): void;
    /**
     * Decrypts and unpacks payload
     * @param string payload
     * @param string key
     * @return array
     */
    protected decryptPayload(payload: Buffer, key: Buffer): object;
}

type Payload = Record<string, any>;
/**
 * Abstract signature
 */
declare abstract class AbstractSignature {
    protected payload: Payload | null;
    protected result: number | null;
    /**
     * TODO: used in unit testing, will be changed to `jest.spy`
     */
    structType?: string;
    encryptionType?: string;
    /**
     * Retrieve embedded payload
     * @return Payload | null
     */
    getPayload(): Payload | null;
    /**
     * Embed new payload
     * @param payload
     * @return void
     */
    setPayload(payload: Payload): void;
    /**
     * Returns verification result
     */
    getResult(): number;
    /**
     * Simplified signature parsing/validation
     * @param signature Signature content
     * @param ipAddresses Array of client's IP addresses
     * @param userAgent Client's User Agent
     * @param cryptKey Signature decoding key
     * @param formatter Optional formatter (if signature content is not a standard Base64)
     * @return AbstractSignature
     */
    static createFromRequest(signature: string, ipAddresses: Array<string>, userAgent: string, cryptKey: Buffer | CryptKeyCallback, formatter?: AbstractFormatter | null): AbstractSignature;
    /**
     * Returns default formatter
     * @return AbstractFormatter
     */
    protected getDefaultFormatter(): AbstractFormatter;
    bytesCompare(known: Buffer | null, user: Buffer | null, n: number): boolean;
    private hashEquals;
}

interface SignatureErrorInterface {
}

/**
 * Malformed or truncated signatures
 */
declare class SignatureParseError extends Error implements SignatureErrorInterface {
}

/**
 * Invalid or outdated signatures
 */
declare class VerifyError extends Error implements SignatureErrorInterface {
}

/**
 * Occurs usually when invalid decoder is applied to signature
 */
declare class VersionError extends Error implements SignatureErrorInterface {
}

export { AbstractSignature, type CryptKeyCallback, type Payload, Signature5, type SignatureErrorInterface, SignatureParseError, VerifyError, VersionError };
