ethereumjs-util#ecrecover TypeScript Examples
The following examples show how to use
ethereumjs-util#ecrecover.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From multisig-react with MIT License | 7 votes |
isTxHashSignedWithPrefix = (txHash: string, signature: string, ownerAddress: string): boolean => {
let hasPrefix
try {
const rsvSig = {
r: Buffer.from(signature.slice(2, 66), 'hex'),
s: Buffer.from(signature.slice(66, 130), 'hex'),
v: parseInt(signature.slice(130, 132), 16),
}
const recoveredData = ecrecover(Buffer.from(txHash.slice(2), 'hex'), rsvSig.v, rsvSig.r, rsvSig.s)
const recoveredAddress = bufferToHex(pubToAddress(recoveredData))
hasPrefix = !sameString(recoveredAddress, ownerAddress)
} catch (e) {
hasPrefix = true
}
return hasPrefix
}
Example #2
Source File: is-signer.ts From ethereum-sdk with MIT License | 5 votes |
function recover(initialHash: Buffer, signature: Buffer): string {
const sig = fromRpcSig(signature)
const [hash, v] = fixHashAndV(sig.v, initialHash)
return bufferToHex(pubToAddress(ecrecover(hash, v, sig.r, sig.s)))
}