例如,这是goerli: 0x60605c7e3fddd2be1fa63f4fa8ef12bfc5e5c69062c6a4788d1277e007e7de02.中的事务散列。
我们知道,公钥可以由ECDSA导出。我们可以从事务散列中得到v,r,S。因此,事务哈希=> vrs => ECDSA =>公钥。如何通过传输散列获取公钥?我想要一些密码。谢谢!
发布于 2023-03-22 15:33:48
下面是一个使用Node.js版本5.4.x的ethers.js脚本:
const { ethers } = require("ethers");
// Function to extract the address associated with to a transaction
async function getPublicKeyFromTransactionHash(provider, txHash) {
// Fetch the transaction using the transaction hash and provier
const tx = await provider.getTransaction(txHash);
// Extract the all the relevant fields from the transaction (We need all of them)
const unsignedTx = {
gasLimit: tx.gasLimit,
value: tx.value,
nonce: tx.nonce,
data: tx.data,
chainId: tx.chainId,
to: tx.to,
type: tx.type,
maxFeePerGas: tx.maxFeePerGas,
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
};
// Serializing tx without the signature
const serializedTx = ethers.utils.serializeTransaction(unsignedTx);
// Extract the signature (v, r, s) from the transaction
const { v, r, s } = tx;
// Join splitted signature
const signature = ethers.utils.joinSignature({ v, r, s });
// Recover the address or public key with (replace recoverAddress by recoverPublicKey) associated with the transaction
return ethers.utils.recoverAddress(
ethers.utils.keccak256(serializedTx),
signature
);
}
// Call the function with a provider and a transaction hash
(async () => {
// Public provider for Goerli
const provider = new ethers.providers.JsonRpcProvider(
"https://ethereum-goerli-rpc.allthatnode.com"
);
// Transaction hash
const txHash =
"0x60605c7e3fddd2be1fa63f4fa8ef12bfc5e5c69062c6a4788d1277e007e7de02";
// And finally call the function to extract the address associated with the transaction
const address = await getPublicKeyFromTransactionHash(provider, txHash);
console.log("Address:", address);
})();发布于 2023-03-23 08:50:47
要获取与事务哈希关联的公钥,需要使用块资源管理器。块资源管理器是一种搜索引擎,允许用户轻松地查找区块链上的信息。打开块资源管理器后,在搜索栏中输入事务哈希,并显示与事务关联的公钥。
发布于 2023-05-22 10:08:05
如果您想在golang:https://github.com/ashish10677/public-key-extractor中找到解决这个问题的方法,您可以检查这个问题。
https://ethereum.stackexchange.com/questions/147692
复制相似问题