Closed mmv08 closed 3 years ago
You just removed an assert and created a local variable that isn't used anywhere.
This code makes no sense.
@junderw copypaste gone wrong, sorry :)
@junderw any updates?
Why do we need this change?
Buffer.alloc(4) instanceof Uint8Array
in node return true
Lol, I tried to reproduce it again so I can properly explain but I couldn't. I had a problem with the validation when trying to sign a transaction with a ledger hardware wallet, cannot reproduce it anymore 🤷♂️ I'm sorry
@fanatid I managed to reproduce this again
The error happens within this snippet:
import { bufferToHex, ecrecover, pubToAddress } from 'ethereumjs-util'
export const 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) {
console.error(e)
hasPrefix = true
}
return hasPrefix
}
I haven't had time to dive in into ethereumjs-util
and see if they perform some manipulations over signature Buffer
~Fixes #175~
If I understand correctly, Buffer is a subclass of Uint8Array that extends it, thus it should be ok to use Buffer.
API reference mentions that the browser's Buffer is lacking behind, this is why I included
isNode
flag