import { A as r, a as h } from "./platform-vRQufc6j.mjs";
import { v as d, z as p } from "./chunk-KJH4KKG6-Brt4fyqz.mjs";
import { m as u, ci as m } from "./platform-Cil_UtAQ.mjs";
import { A as g, _ } from "./address-rVHWlcKQ.mjs";
async function f(i, t) {
  const [s, n] = await r.chainFromRpc(i), a = d.fromPrivateKey({
    // TODO: support secp256k1
    privateKey: new p(u.decode(t))
  });
  return new l(n, a, i);
}
class l {
  _chain;
  _account;
  _rpc;
  _debug;
  constructor(t, s, n, a) {
    this._chain = t, this._account = s, this._rpc = n, this._debug = a;
  }
  chain() {
    return this._chain;
  }
  address() {
    return this._account.accountAddress.toString();
  }
  async signAndSend(t) {
    const s = [];
    for (const n of t) {
      const { description: a, transaction: o } = n;
      this._debug && console.log(`Signing: ${a} for ${this.address()}`);
      const c = await this._rpc.transaction.build.simple({
        sender: this._account.accountAddress,
        data: o
      }), { hash: e } = await this._simSignSend(c);
      s.push(e);
    }
    return s;
  }
  async _simSignSend(t) {
    return await this._rpc.transaction.simulate.simple({
      signerPublicKey: this._account.publicKey,
      transaction: t
    }).then((s) => s.forEach((n) => {
      if (!n.success)
        throw new Error(`Transaction failed: ${n.vm_status}
${JSON.stringify(n, null, 2)}`);
    })), this._rpc.signAndSubmitTransaction({ signer: this._account, transaction: t }).then((s) => this._rpc.waitForTransaction({ transactionHash: s.hash }));
  }
}
const b = {
  Address: g,
  Platform: r,
  getSigner: f,
  protocols: {
    WormholeCore: () => import("./index-BScgBddV.mjs"),
    TokenBridge: () => import("./index-DHnmtpvA.mjs"),
    CircleBridge: () => import("./index-C5I7QiZ7.mjs")
  },
  getChain: (i, t, s) => new h(t, new r(i, m(i, _, {
    [t]: s
  })))
};
export {
  b as default
};
