import { convertBigIntToBytes32 as e } from "../functions/utils/bytes32.utils.mjs";
import { ethers as t } from "ethers";
import { secp256k1 as n } from "@noble/curves/secp256k1.js";
import { hkdf as r } from "@noble/hashes/hkdf.js";
import { sha256 as i } from "@noble/hashes/sha2.js";
import { randomBytes as a } from "@noble/hashes/utils.js";
//#region libs/shared/common/src/crypto/ecdh-dual-path.ts
var o = (e, t) => r(i, n.getSharedSecret(e, t).slice(1, 33), void 0, void 0, 32), s = (e, t) => {
	if (e.length !== t.length) throw Error("xor: length mismatch");
	let n = new Uint8Array(e.length);
	for (let r = 0; r < e.length; r += 1) n[r] = e[r] ^ t[r];
	return n;
}, c = async (e, t, n) => {
	let r = new Uint8Array(e), i = new Uint8Array(t), a = new Uint8Array(n), o = await crypto.subtle.importKey("raw", r, { name: "AES-GCM" }, !1, ["encrypt"]);
	return new Uint8Array(await crypto.subtle.encrypt({
		name: "AES-GCM",
		iv: i
	}, o, a));
}, l = async (e, t, n) => {
	let r = new Uint8Array(e), i = new Uint8Array(t), a = new Uint8Array(n), o = await crypto.subtle.importKey("raw", r, { name: "AES-GCM" }, !1, ["decrypt"]);
	return new Uint8Array(await crypto.subtle.decrypt({
		name: "AES-GCM",
		iv: i
	}, o, a));
}, u = async (r, i, l, u) => {
	let d = n.utils.randomSecretKey(), f = BigInt(t.hexlify(d)), p = t.hexlify(i.publicKey), m = n.Point.fromHex(p.startsWith("0x") ? p.slice(2) : p).multiply(f), h = t.getBytes(`0x${m.toHex(!1)}`), g = n.Point.Fn.ORDER, _ = BigInt(t.hexlify(i.privateKey)) * f % g, v = new Uint8Array(e(_)), y = o(v, l), b = o(v, u), x = a(32), S = a(12), C = await c(x, S, r);
	return {
		blindedSenderKey: h,
		wrapKeyReceiver1: s(x, y),
		wrapKeyReceiver2: s(x, b),
		ciphertext: C,
		nonce: S
	};
}, d = async (e, t, n, r, i) => {
	let a = await l(s(r, o(t, n)), i, e);
	return new TextDecoder().decode(a);
};
//#endregion
export { d as decryptDualPath, u as encryptDualPath };
