Skip to content

Commit 83a52fb

Browse files
mradkovnduchak
authored andcommitted
fix(Crypto): Fix keypair verification (#605)
* convert test message to buffer in isValidKeypair fixes aeternity/aepp-base#1090 * add test for keypair validity verification
1 parent 14eaa3d commit 83a52fb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

es/utils/crypto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export function encodeTx (txData) {
498498
* @return {Boolean} Valid?
499499
*/
500500
export function isValidKeypair (privateKey, publicKey) {
501-
const message = 'TheMessage'
501+
const message = Buffer.from('TheMessage')
502502
const signature = sign(message, privateKey)
503503
return verify(message, signature, publicKey)
504504
}

test/unit/crypto.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ describe('crypto', () => {
4848
assert.isAtMost(keyPair.publicKey.length, 53)
4949
})
5050
})
51-
51+
52+
describe('isValidKeypair', () => {
53+
it('verify the generated key pair', () => {
54+
const keyPair = Crypto.generateKeyPair(true)
55+
assert.ok(keyPair)
56+
const verifyResult = Crypto.isValidKeypair(keyPair.secretKey, keyPair.publicKey)
57+
assert.isTrue(verifyResult)
58+
})
59+
})
60+
5261
describe('encryptPassword', () => {
5362
describe('generate a password encrypted key pair', () => {
5463
const keyPair = Crypto.generateKeyPair(true)

0 commit comments

Comments
 (0)