import { decryptBoxSeal as e } from "../../crypto/ecdh.mjs";
import { decryptSealedKeys as t, encryptSealedKeys as n } from "../../crypto/ecdh-sealed-keys.mjs";
import { UserKeys as r } from "./keys.mjs";
import { Utxo as i } from "../utxo/Utxo.mjs";
import { ethers as a } from "ethers";
import { PublicKey as o } from "@solana/web3.js";
//#region libs/shared/common/src/data-structures/crypto-keys/encryptDecryptUtxo.ts
var s = (e) => e.startsWith("0x") ? e : `0x${e}`, c = 54912, l = 2, u = (e) => Uint8Array.from([Math.floor(e / 256), e % 256]), d = (e) => e[0] * 256 + e[1], f = (e) => {
	let t = [
		Buffer.from(a.toBeHex(e.amount)),
		Buffer.from(s(e.erc20TokenAddress)),
		Buffer.from(a.toBeHex(e.randomization ?? 0n)),
		Buffer.from(s(e.getStealthAddress())),
		Buffer.from(a.toBeHex(BigInt(e.timeStamp))),
		Buffer.from(a.toBeHex(e.isNewStyle ? 1n : 0n)),
		Buffer.from(a.toBeHex(e.H0?.[0] ?? 0n)),
		Buffer.from(a.toBeHex(e.H0?.[1] ?? 0n))
	];
	if (e.mintAddress) {
		let n = new o(e.mintAddress), r = a.hexlify(n.toBytes());
		t.push(Buffer.from(r));
	}
	let r = n(Buffer.concat(t), [e.getEncryptionKey()]);
	return Buffer.concat([Buffer.from(u(c)), Buffer.from(r)]);
}, p = (n, i) => {
	let { privateKey: a, publicKey: s } = r.getEncryptionKeyPair(i.getShieldedPrivateKey()), u = d(n) === c ? t(n.slice(l), a, s, 0) : e(n, a, s), f = Buffer.from(u).toString("utf-8").split("0x").filter((e) => e.length !== 0), p = (e) => BigInt(`0x${e}`), m = (e) => `0x${e}`, h = f.length >= 8, g = h && p(f[5]) === 1n, _ = h ? 8 : 6, v = f[_] ? m(f[_]) : void 0, y = v ? new o(Buffer.from(v.slice(2), "hex")).toString() : void 0;
	return {
		amount: p(f[0]),
		erc20TokenAddress: m(f[1]),
		randomization: p(f[2]),
		stealthAddress: m(f[3]),
		nullifyingKey: i.getShieldedPrivateKey(),
		timeStamp: p(f[4]).toString(),
		isNewStyle: g,
		...g ? { H0: [p(f[6]), p(f[7])] } : {},
		mintAddress: y
	};
}, m = (e, t) => new i(p(e, t));
//#endregion
export { m as decryptUtxo, p as decryptUtxoConstructorArgs, f as encryptUtxo };
