import { ah as i, ai as c, m as h, au as d } from "./platform-Cil_UtAQ.mjs";
import { A as m } from "./platform-vRQufc6j.mjs";
import { c as w } from "./create-CChLkbGc.mjs";
class o {
  network;
  chain;
  connection;
  contracts;
  chainId;
  coreBridge;
  constructor(e, n, t, s) {
    this.network = e, this.chain = n, this.connection = t, this.contracts = s, this.chainId = i(n);
    const r = s.coreBridge;
    if (!r)
      throw new Error(`CoreBridge contract Address for chain ${n} not found`);
    this.coreBridge = r;
  }
  getGuardianSet(e) {
    throw new Error("Method not implemented.");
  }
  getGuardianSetIndex() {
    throw new Error("Method not implemented.");
  }
  getMessageFee() {
    throw new Error("Method not implemented.");
  }
  static async fromRpc(e, n) {
    const [t, s] = await m.chainFromRpc(e), r = n[s];
    if (r.network !== t)
      throw new Error(`Network mismatch: ${r.network} !== ${t}`);
    return new o(t, s, e, r.contracts);
  }
  async *publishMessage(e, n) {
    throw new Error("Method not implemented.");
  }
  async *verifyMessage(e, n) {
    throw new Error("Not implemented.");
  }
  async parseTransaction(e) {
    return (await this.parseMessages(e)).map((t) => ({
      chain: t.emitterChain,
      emitter: t.emitterAddress,
      sequence: t.sequence
    }));
  }
  async parseMessages(e) {
    const n = await this.connection.getTransactionByHash({ transactionHash: e });
    if (n.type !== "user_transaction")
      throw new Error(`${e} is not a user_transaction`);
    const t = n.events.filter((s) => s.type.endsWith("WormholeMessage"));
    if (!t || t.length === 0)
      throw new Error(`WormholeMessage not found for ${e}`);
    return t.map((s) => {
      const r = s.data, a = new c(BigInt(r.sender).toString(16).padStart(64, "0"));
      return w("Uint8Array", {
        guardianSet: 0,
        // TODO: need to implement guardian set idx
        emitterChain: this.chain,
        emitterAddress: a,
        sequence: BigInt(r.sequence),
        timestamp: Number(r.timestamp),
        consistencyLevel: r.consistency_level,
        nonce: Number(r.nonce),
        signatures: [],
        payload: h.decode(r.payload)
      });
    });
  }
}
d("Aptos", "WormholeCore", o);
export {
  o as AptosWormholeCore
};
