Skip to content

Commit

Permalink
fix: proof of poe address case sensitivity (#956)
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarodragan authored May 21, 2019
1 parent 85d6d1d commit 5785a15
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/helpers/ethereum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe } from 'riteway'

import { signatureIsValid } from './ethereum'

describe('signatureIsValid()', async (assert) => {
const signedMessage = {
address: '0xBe7d20A0f75DbcCb82EFe6AE3aF1768E5E83D0B8',
msg: 'Proof of POE',
sig: '0x5e06a683754daa113774b42a1c3fd1f038b95e82eea918d404bab8d229df4ed0' +
'6a4f5497aa9969a55aa559b97a48655d99b08c6992134c2d5d65b3becb11cf2b1c',
version: '3',
signer: 'MEW',
}

const secondAddress = '0xc2e359382B61356e37AF9523f20771fa6fc1C8fC'

assert({
given: 'a correct checksum-cased address, signature and message combination',
should: 'return true',
actual: signatureIsValid(signedMessage.address, signedMessage.msg, signedMessage.sig),
expected: true,
})

assert({
given: 'a correct non-checksum-cased address, signature and message combination',
should: 'return true',
actual: signatureIsValid(signedMessage.address.toLowerCase(), signedMessage.msg, signedMessage.sig),
expected: true,
})

assert({
given: 'a signature that matches the message but not the address',
should: 'return false',
actual: signatureIsValid(secondAddress, signedMessage.msg, signedMessage.sig),
expected: false,
})

assert({
given: 'an empty signature',
should: 'return false',
actual: signatureIsValid(signedMessage.address, signedMessage.msg, ''),
expected: false,
})

assert({
given: 'an empty message',
should: 'return false',
actual: signatureIsValid(signedMessage.address, '', signedMessage.sig),
expected: false,
})

assert({
given: 'an invalid signature',
should: 'return false',
actual: signatureIsValid(signedMessage.address, signedMessage.msg, 'saywhat'),
expected: false,
})
})
2 changes: 1 addition & 1 deletion src/helpers/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function signatureIsValid(address: string, message: string, signature: st
const addressBuffer = publicToAddress(publicKey)
const addressVerified = bufferToHex(addressBuffer)

return addressVerified === address
return addressVerified.toLowerCase() === address.toLowerCase()
} catch (exception) {
if (exception.message === 'Invalid signature length')
return false
Expand Down
1 change: 1 addition & 0 deletions tests/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../../src/decorators/injectDao/injectDao.test'
import '../../src/emails/forgotPassword.test'
import '../../src/emails/verify.test'
import '../../src/extensions/Error.test'
import '../../src/helpers/ethereum.test'
import '../../src/helpers/token.test'
import '../../src/helpers/uuid.test'
import '../../src/loadConfiguration.test'
Expand Down

0 comments on commit 5785a15

Please sign in to comment.