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

@@ -43,7 +43,7 @@
"compile-with-source-maps": "babel --optional runtime -s -t -d distrib/npm/ src/",
"prepublish": "npm test && npm run lint && npm run compile",
"test": "istanbul test _mocha",
"codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js",
"codecov": "cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'parser: babel-eslint' >> eslintrc; fi; eslint -c eslintrc src/*.js test/*.js"
},
"repository": {

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) {