import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
import { createJsonRpcProvider as t } from "../../functions/utils/create-provider.mjs";
import { ethers as n } from "ethers";
import { Keypair as r } from "@solana/web3.js";
import i from "bs58";
import a from "tweetnacl";
//#region libs/shared/common/src/data-structures/AccountActions/AccountActions.ts
var o = class {
	static getEvmPrivateKeyFromSolanaPrivateKey = (e) => {
		let t = i.decode(e).slice(0, 32);
		return n.hexlify(t);
	};
	static getSolanaPrivateKeyFromEvmPrivateKey = (e) => {
		let t = n.getBytes(e), a = r.fromSeed(t);
		return i.encode(a.secretKey);
	};
	static getSolanaSignerFromPrivateKey = (e) => {
		let t = i.decode(e);
		return r.fromSecretKey(t);
	};
	static getSignerAddressFromPrivateKey(t, r) {
		return e(t) ? this.getSolanaSignerFromPrivateKey(r).publicKey.toString() : new n.Wallet(r).address;
	}
	static signMessageFromPrivateKey = async (t, r, i) => {
		if (e(t)) {
			let e = this.getSolanaSignerFromPrivateKey(r), t = n.isHexString(i) ? n.getBytes(i) : new TextEncoder().encode(i), o = a.sign.detached(t, e.secretKey);
			return `0x${Buffer.from(o).toString("hex")}`;
		}
		let o = new n.Wallet(r), s = n.isHexString(i) ? n.getBytes(i) : i;
		return o.signMessage(s);
	};
	static signSolanaTransactionFromPrivateKey = (t, n, r) => {
		if (!e(t)) throw Error("Solana transaction signing is only available for Solana chains");
		let i = this.getSolanaSignerFromPrivateKey(n);
		r.sign([i]);
	};
	static sendAndSignSolanaTransactionFromPrivateKey = async (e, t, n, r = !1) => {
		let i = this.getSolanaSignerFromPrivateKey(t);
		return n.sign([i]), await e.sendRawTransaction(n.serialize(), {
			skipPreflight: r,
			preflightCommitment: "confirmed"
		});
	};
	static signTypedDataFromPrivateKey = async (t, r, i, a, o) => {
		if (e(t)) throw Error("Solana does not support typed data");
		return await new n.Wallet(r).signTypedData(i, a, o);
	};
	static authorizeDelegation = async (r, i, a, o) => {
		if (e(r)) throw Error("Solana does not support delegation");
		let s = t(r);
		return await new n.Wallet(i).connect(s).authorize({
			address: a,
			...o !== void 0 && { nonce: o }
		});
	};
	static getAddressFromSubAccount = (t, n) => e(t) ? n.solanaAddress : n.ethAddress;
	static getPrivateKeyFromSubAccount = (t, n) => e(t) ? n.solanaPrivateKey : n.privateKey;
	static getAvailableAddressFromSubAccount = (e) => {
		let t = e.ethAddress ?? e.solanaAddress;
		if (!t) throw Error("No address available for subaccount");
		return t;
	};
};
//#endregion
export { o as AccountActions };
