import { EthAddress, GrumpkinAddress } from '@polyaztec/barretenberg/address';
import { AccountTx, createAccountProofSigningData, ProofId } from '@polyaztec/barretenberg/client_proofs';
export class AccountProofInputCreator {
    constructor(paymentProofInputCreator, wasm) {
        this.paymentProofInputCreator = paymentProofInputCreator;
        this.wasm = wasm;
    }
    async createProofInputs({ accountPublicKey, aliasHash, newAccountPublicKey, newSpendingPublicKey1, newSpendingPublicKey2, deposit, fee, depositor, inputNotes, spendingKeyAccount, dataRoot, allowChain, }, authAlgos) {
        // TODO - check AccountProofRequestData
        const accountProofInput = await this.createAccountProofInput(accountPublicKey, aliasHash, newAccountPublicKey, newSpendingPublicKey1, newSpendingPublicKey2, spendingKeyAccount, dataRoot);
        const payFeeViaDeposit = (deposit.value || fee.value) && !depositor.equals(EthAddress.ZERO);
        const depositProofInputs = payFeeViaDeposit
            ? await this.paymentProofInputCreator.createProofInputs({
                accountPublicKey,
                proofId: ProofId.DEPOSIT,
                assetValue: deposit,
                fee,
                publicOwner: depositor,
                recipient: accountPublicKey,
                recipientSpendingKeyRequired: true,
                inputNotes,
                spendingKeyAccount: {
                    ...spendingKeyAccount,
                    // The spending key exists for a request to recover an account, but its private key was discarded after
                    // recovery payload was generated. We only have the siganure for the account proof, and can't use that
                    // spending key to create and sign a deposit tx.
                    spendingPublicKey: accountPublicKey.equals(newAccountPublicKey)
                        ? accountPublicKey
                        : spendingKeyAccount.spendingPublicKey,
                },
                dataRoot,
                allowChain,
                hideNoteCreator: false,
            }, authAlgos)
            : [];
        const feeProofInputs = fee.value && !payFeeViaDeposit
            ? await this.paymentProofInputCreator.createFeeProofInputs(accountPublicKey, fee, inputNotes, spendingKeyAccount, dataRoot, allowChain, authAlgos)
            : [];
        return [accountProofInput, ...depositProofInputs, ...feeProofInputs];
    }
    async createAccountProofInput(accountPublicKey, aliasHash, newAccountPublicKey, newSpendingPublicKey1, newSpendingPublicKey2, { spendingPublicKey, accountIndex, accountPath }, dataRoot) {
        const create = accountPublicKey.equals(spendingPublicKey);
        const migrate = !newAccountPublicKey.equals(accountPublicKey);
        const tx = new AccountTx(dataRoot, accountPublicKey, newAccountPublicKey || accountPublicKey, newSpendingPublicKey1 || GrumpkinAddress.ZERO, newSpendingPublicKey2 || GrumpkinAddress.ZERO, aliasHash, create, migrate, accountIndex, accountPath, spendingPublicKey);
        const signingData = await createAccountProofSigningData(tx, this.wasm);
        return { tx, signingData };
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9wcm9vZl9pbnB1dF9jcmVhdG9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3Byb29mcy9wcm9vZl9pbnB1dC9hY2NvdW50X3Byb29mX2lucHV0X2NyZWF0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLFVBQVUsRUFBRSxlQUFlLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUM5RSxPQUFPLEVBQUUsU0FBUyxFQUFFLDZCQUE2QixFQUFFLE9BQU8sRUFBRSxNQUFNLHVDQUF1QyxDQUFDO0FBTzFHLE1BQU0sT0FBTyx3QkFBd0I7SUFDbkMsWUFBb0Isd0JBQWtELEVBQVUsSUFBc0I7UUFBbEYsNkJBQXdCLEdBQXhCLHdCQUF3QixDQUEwQjtRQUFVLFNBQUksR0FBSixJQUFJLENBQWtCO0lBQUcsQ0FBQztJQUVuRyxLQUFLLENBQUMsaUJBQWlCLENBQzVCLEVBQ0UsZ0JBQWdCLEVBQ2hCLFNBQVMsRUFDVCxtQkFBbUIsRUFDbkIscUJBQXFCLEVBQ3JCLHFCQUFxQixFQUNyQixPQUFPLEVBQ1AsR0FBRyxFQUNILFNBQVMsRUFDVCxVQUFVLEVBQ1Ysa0JBQWtCLEVBQ2xCLFFBQVEsRUFDUixVQUFVLEdBQ2MsRUFDMUIsU0FBeUI7UUFFekIsdUNBQXVDO1FBRXZ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