var d = Object.defineProperty;
var p = (n, t, s) => t in n ? d(n, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[t] = s;
var r = (n, t, s) => p(n, typeof t != "symbol" ? t + "" : t, s);
import { A as o, a as u } from "./platform-CyoDzIPB.mjs";
import { z as g, a as m } from "./chunk-KJH4KKG6-cfe1Zo7n.mjs";
import { a3 as _, br as f } from "./address-CrYNZ_Nj.mjs";
import { A as l, _ as A } from "./address-BJNAPSnr.mjs";
async function S(n, t) {
  const [s, i] = await o.chainFromRpc(n), a = g.fromPrivateKey({
    // TODO: support secp256k1
    privateKey: new m(_.decode(t))
  });
  return new w(i, a, n);
}
class w {
  constructor(t, s, i, a) {
    r(this, "_chain");
    r(this, "_account");
    r(this, "_rpc");
    r(this, "_debug");
    this._chain = t, this._account = s, this._rpc = i, this._debug = a;
  }
  chain() {
    return this._chain;
  }
  address() {
    return this._account.accountAddress.toString();
  }
  async signAndSend(t) {
    const s = [];
    for (const i of t) {
      const { description: a, transaction: c } = i;
      this._debug && console.log(`Signing: ${a} for ${this.address()}`);
      const e = await this._rpc.transaction.build.simple({
        sender: this._account.accountAddress,
        data: c
      }), { hash: h } = await this._simSignSend(e);
      s.push(h);
    }
    return s;
  }
  async _simSignSend(t) {
    return await this._rpc.transaction.simulate.simple({
      signerPublicKey: this._account.publicKey,
      transaction: t
    }).then((s) => s.forEach((i) => {
      if (!i.success)
        throw new Error(`Transaction failed: ${i.vm_status}
${JSON.stringify(i, null, 2)}`);
    })), this._rpc.signAndSubmitTransaction({ signer: this._account, transaction: t }).then((s) => this._rpc.waitForTransaction({ transactionHash: s.hash }));
  }
}
const P = {
  Address: l,
  Platform: o,
  getSigner: S,
  protocols: {
    WormholeCore: () => import("./index-DUoona4h.mjs"),
    TokenBridge: () => import("./index-D5Wl9ZPE.mjs"),
    CircleBridge: () => import("./index-B8CSnOaL.mjs")
  },
  getChain: (n, t, s) => new u(t, new o(n, f(n, A, {
    [t]: s
  })))
};
export {
  P as default
};
