import { Fr, NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage } from '@aztec/circuits.js';
import { schemas } from '@aztec/foundation/schemas';
import { z } from 'zod';
import { SiblingPath } from '../sibling_path/index.js';
/**
 * Nullifier membership witness.
 * @remarks When this represents membership witness of a low nullifier it can be used to perform a nullifier
 * non-inclusion proof by leveraging the "linked list structure" of leaves and proving that a lower nullifier
 * is pointing to a bigger next value than the nullifier we are trying to prove non-inclusion for.
 */
export class NullifierMembershipWitness {
    constructor(
    /**
     * The index of the nullifier in a tree.
     */
    index, 
    /**
     * Preimage of the nullifier.
     */
    leafPreimage, 
    /**
     * Sibling path to prove membership of the nullifier.
     */
    siblingPath) {
        this.index = index;
        this.leafPreimage = leafPreimage;
        this.siblingPath = siblingPath;
    }
    static get schema() {
        return z
            .object({
            index: schemas.BigInt,
            leafPreimage: NullifierLeafPreimage.schema,
            siblingPath: SiblingPath.schemaFor(NULLIFIER_TREE_HEIGHT),
        })
            .transform(({ index, leafPreimage, siblingPath }) => new NullifierMembershipWitness(index, leafPreimage, siblingPath));
    }
    static random() {
        return new NullifierMembershipWitness(BigInt(Math.floor(Math.random() * 1000)), NullifierLeafPreimage.random(), SiblingPath.random(NULLIFIER_TREE_HEIGHT));
    }
    /**
     * Returns a field array representation of a nullifier witness.
     * @returns A field array representation of a nullifier witness.
     */
    toFields() {
        return [new Fr(this.index), ...this.leafPreimage.toFields(), ...this.siblingPath.toFields()];
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnVsbGlmaWVyX3RyZWUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW50ZXJmYWNlcy9udWxsaWZpZXJfdHJlZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsRUFBRSxFQUFFLHFCQUFxQixFQUFFLHFCQUFxQixFQUFFLE1BQU0sb0JBQW9CLENBQUM7QUFDdEYsT0F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