Skip to content

Commit

Permalink
fix(Crypto): Fix keypair verification (#605)
Browse files Browse the repository at this point in the history
* convert test message to buffer in isValidKeypair 

fixes aeternity/aepp-base#1090

* add test for keypair validity verification
  • Loading branch information
mradkov authored and nduchak committed Aug 14, 2019
1 parent 14eaa3d commit 83a52fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion es/utils/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export function encodeTx (txData) {
* @return {Boolean} Valid?
*/
export function isValidKeypair (privateKey, publicKey) {
const message = 'TheMessage'
const message = Buffer.from('TheMessage')
const signature = sign(message, privateKey)
return verify(message, signature, publicKey)
}
Expand Down
11 changes: 10 additions & 1 deletion test/unit/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ describe('crypto', () => {
assert.isAtMost(keyPair.publicKey.length, 53)
})
})


describe('isValidKeypair', () => {
it('verify the generated key pair', () => {
const keyPair = Crypto.generateKeyPair(true)
assert.ok(keyPair)
const verifyResult = Crypto.isValidKeypair(keyPair.secretKey, keyPair.publicKey)
assert.isTrue(verifyResult)
})
})

describe('encryptPassword', () => {
describe('generate a password encrypted key pair', () => {
const keyPair = Crypto.generateKeyPair(true)
Expand Down

0 comments on commit 83a52fb

Please sign in to comment.