@wormhole-foundation/sdk-aptos-core
Version:
SDK for Solana, used in conjunction with @wormhole-foundation/connect-sdk
81 lines • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AptosWormholeCore = void 0;
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
const sdk_aptos_1 = require("@wormhole-foundation/sdk-aptos");
class AptosWormholeCore {
network;
chain;
connection;
contracts;
chainId;
coreBridge;
constructor(network, chain, connection, contracts) {
this.network = network;
this.chain = chain;
this.connection = connection;
this.contracts = contracts;
this.chainId = (0, sdk_connect_1.toChainId)(chain);
const coreBridgeAddress = contracts.coreBridge;
if (!coreBridgeAddress)
throw new Error(`CoreBridge contract Address for chain ${chain} not found`);
this.coreBridge = coreBridgeAddress;
}
getGuardianSet(index) {
throw new Error("Method not implemented.");
}
getGuardianSetIndex() {
throw new Error("Method not implemented.");
}
getMessageFee() {
throw new Error("Method not implemented.");
}
static async fromRpc(connection, config) {
const [network, chain] = await sdk_aptos_1.AptosPlatform.chainFromRpc(connection);
const conf = config[chain];
if (conf.network !== network)
throw new Error(`Network mismatch: ${conf.network} !== ${network}`);
return new AptosWormholeCore(network, chain, connection, conf.contracts);
}
async *publishMessage(sender, message) {
throw new Error("Method not implemented.");
}
async *verifyMessage(sender, vaa) {
throw new Error("Not implemented.");
}
async parseTransaction(txid) {
const msgs = await this.parseMessages(txid);
return msgs.map((message) => {
return {
chain: message.emitterChain,
emitter: message.emitterAddress,
sequence: message.sequence,
};
});
}
async parseMessages(txid) {
const transaction = await this.connection.getTransactionByHash({ transactionHash: txid });
if (transaction.type !== "user_transaction")
throw new Error(`${txid} is not a user_transaction`);
const messages = transaction.events.filter((event) => event.type.endsWith("WormholeMessage"));
if (!messages || messages.length === 0)
throw new Error(`WormholeMessage not found for ${txid}`);
return messages.map((message) => {
const msg = message.data;
const emitter = new sdk_connect_1.UniversalAddress(BigInt(msg.sender).toString(16).padStart(64, "0"));
return (0, sdk_connect_1.createVAA)("Uint8Array", {
guardianSet: 0, // TODO: need to implement guardian set idx
emitterChain: this.chain,
emitterAddress: emitter,
sequence: BigInt(msg.sequence),
timestamp: Number(msg.timestamp),
consistencyLevel: msg.consistency_level,
nonce: Number(msg.nonce),
signatures: [],
payload: sdk_connect_1.encoding.hex.decode(msg.payload),
});
});
}
}
exports.AptosWormholeCore = AptosWormholeCore;
//# sourceMappingURL=core.js.map