@0xfacet/sdk
Version:
A toolkit for Facet blockchain integration.
41 lines (40 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFacetTransactionHashFromL1Hash = void 0;
const viem_1 = require("viem");
const chains_1 = require("viem/chains");
const addresses_1 = require("../constants/addresses");
const computeFacetTransactionHash_1 = require("./computeFacetTransactionHash");
const decodeFacetEncodedTransaction_1 = require("./decodeFacetEncodedTransaction");
/**
* Gets the Facet transaction hash from an L1 transaction hash
*
* @param l1TransactionHash - The hash of the L1 transaction
* @param l1ChainId - The chain ID of the L1 network (1 for mainnet, 11155111 for Sepolia)
* @returns The Facet transaction hash
* @throws Error if L1 chain is invalid or if the transaction is not a valid Facet transaction
*/
const getFacetTransactionHashFromL1Hash = async (l1TransactionHash, l1ChainId) => {
if (l1ChainId !== 1 && l1ChainId !== 11_155_111) {
throw new Error("Invalid L1 chain");
}
// Create a public client for the L1 chain
const l1PublicClient = (0, viem_1.createPublicClient)({
chain: l1ChainId === 1 ? chains_1.mainnet : chains_1.sepolia,
transport: (0, viem_1.http)(),
});
// Get the L1 transaction
const l1Transaction = await l1PublicClient.getTransaction({
hash: l1TransactionHash,
});
// Verify this is a transaction to the Facet Inbox
if (l1Transaction.to &&
(0, viem_1.getAddress)(l1Transaction.to) !== (0, viem_1.getAddress)(addresses_1.FACET_INBOX_ADDRESS)) {
throw new Error("Transaction is not to Facet Inbox address");
}
// Decode the transaction data to extract Facet transaction parameters
const { to, value, data, gasLimit, fctMintAmount } = await (0, decodeFacetEncodedTransaction_1.decodeFacetEncodedTransaction)(l1Transaction.input);
// Compute and return the Facet transaction hash
return (0, computeFacetTransactionHash_1.computeFacetTransactionHash)(l1TransactionHash, l1Transaction.from, to, value, data, gasLimit, fctMintAmount);
};
exports.getFacetTransactionHashFromL1Hash = getFacetTransactionHashFromL1Hash;