@kaiachain/web3js-ext
Version:
web3.js extension for kaiachain blockchain
25 lines (24 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.recoverTransaction = void 0;
const js_ext_core_1 = require("@kaiachain/js-ext-core");
const web3_eth_accounts_1 = require("web3-eth-accounts");
const web3_utils_1 = require("web3-utils");
const sign_js_1 = require("./sign.js");
// Analogous to: web3-eth-accounts/src/accounts.ts:recoverTransaction
// Replaces: web3.eth.accounts.recoverTransaction
// Because: Klaytn Tx sender can be decoupled from the signer address recovered from ecrecover.
// For Klaytn Tx, return the explicit "from" field from the Tx RLP.
function recoverTransaction(rawTransaction) {
const tx = (0, js_ext_core_1.parseTransaction)(rawTransaction);
if (!(0, js_ext_core_1.isKlaytnTxType)((0, sign_js_1._parseTxType)(tx.type))) {
// fall back to original web3.eth.accounts.recoverTransaction
return (0, web3_eth_accounts_1.recoverTransaction)(rawTransaction);
}
if (!tx.from) {
// this should never happen because Klaytn Tx RLP always contains `from`.
throw new Error(`missing tx.from in tx type ${tx.type}`);
}
return (0, web3_utils_1.toChecksumAddress)(tx.from);
}
exports.recoverTransaction = recoverTransaction;