import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
export const MAX_FINGERPRINT_SIZE = 64;
export class Fingerprint {
    fp;
    h;
    seed;
    constructor(buf, hash, seed, fingerprintSize = 2) {
        if (fingerprintSize > MAX_FINGERPRINT_SIZE) {
            throw new TypeError('Invalid Fingerprint Size');
        }
        const fnv = hash.hashV(buf, seed);
        const fp = uint8ArrayAlloc(fingerprintSize);
        for (let i = 0; i < fp.length; i++) {
            fp[i] = fnv[i];
        }
        if (fp.length === 0) {
            fp[0] = 7;
        }
        this.fp = fp;
        this.h = hash;
        this.seed = seed;
    }
    hash() {
        return this.h.hash(this.fp, this.seed);
    }
    equals(other) {
        if (!(other?.fp instanceof Uint8Array)) {
            return false;
        }
        return uint8ArrayEquals(this.fp, other.fp);
    }
}
//# sourceMappingURL=fingerprint.js.map