import { constructStealthAddressStructure as e, isValidPrivateAddress as t } from "./addresses.mjs";
import { randomBigInt as n } from "../web3/etherFunctions.mjs";
import { UserKeys as r } from "../../data-structures/crypto-keys/keys.mjs";
import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
import { calcStealthAddressStructure as a } from "../snarkjs/common.snarkjs.mjs";
//#region libs/shared/common/src/functions/utils/buildClaimableDepositPlan.ts
var o = ({ userKeys: o, recipientAmounts: s, recipientAddresses: c, recipientInfos: l, nonce: u, tokenAddress: d }) => {
	if (c.length !== s.length) throw Error("recipientAddresses must have the same length as recipientAmounts");
	if (l && l.length !== s.length) throw Error("recipientInfos must have the same length as recipientAmounts");
	let f = l ?? Array(s.length).fill(void 0), p = 0n, m = [];
	return {
		stealthAddressStructures: s.map((s, l) => {
			let h = f[l];
			if (h) {
				if (!t(h)) throw Error("Invalid recipient info");
				return e(h);
			}
			let g = u + p;
			p += 1n;
			let _ = o.getClaimableSignatureFromNonce(g), v = new r(_), y = v.getShieldedPrivateKey(), b = v.getSpendingKeyPair().pubSpendingBJJPoint, x = new i({
				amount: s,
				erc20TokenAddress: d,
				nullifyingKey: y,
				spendingPublicKey: b,
				isNewStyle: !0
			});
			return m.push({
				recipientIndex: l,
				recipientAddress: c[l],
				shieldedPrivateKey: y,
				claimableSignature: _,
				utxo: x
			}), a(x.randomization ?? r.findCorrectRandomization(n(31), y), y, b);
		}),
		fallbackRecipients: m
	};
};
//#endregion
export { o as buildClaimableDepositPlan };
