mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Verify that generated keypair correctly signs message
This commit is contained in:
@@ -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