Verify that generated keypair correctly signs message

This commit is contained in:
Elliot Lee
2017-09-20 10:15:09 -07:00
parent 30400e6e92
commit 119dfa8d9f
2 changed files with 9 additions and 2 deletions

View File

@@ -73,7 +73,14 @@ function select(algorithm) {
function deriveKeypair(seed, options) {
const decoded = addressCodec.decodeSeed(seed)
const algorithm = decoded.type === 'ed25519' ? 'ed25519' : 'ecdsa-secp256k1'
return select(algorithm).deriveKeypair(decoded.bytes, options)
const method = select(algorithm)
const keypair = method.deriveKeypair(decoded.bytes, options)
const messageToVerify = hash('This test message should verify.')
const signature = method.sign(messageToVerify, keypair.privateKey)
if (method.verify(messageToVerify, signature, keypair.publicKey) !== true) {
throw new Error('derived keypair did not generate verifiable signature');
}
return keypair
}
function getAlgorithmFromKey(key) {