mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
Verify that generated keypair correctly signs message
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user