mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Add tests for custom keystores
This commit is contained in:
53
test/utils/custom-test-keystore.js
Normal file
53
test/utils/custom-test-keystore.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const EC = require('elliptic').ec
|
||||
const ec = new EC('secp256k1')
|
||||
|
||||
/**
|
||||
* A custom keystore example
|
||||
*/
|
||||
class CustomTestKeystore {
|
||||
constructor(signer) {
|
||||
this.createKey();
|
||||
}
|
||||
|
||||
createKey() {
|
||||
const key = ec.genKeyPair()
|
||||
this.key = ec.keyPair({
|
||||
pub: key.getPublic('hex'),
|
||||
priv: key.getPrivate('hex'),
|
||||
privEnc: 'hex',
|
||||
pubEnc: 'hex',
|
||||
})
|
||||
|
||||
return this.key
|
||||
}
|
||||
|
||||
getKey() {
|
||||
return this.key
|
||||
}
|
||||
|
||||
// TODO: check if this is really in use
|
||||
generateKey() {
|
||||
return Promise.resolve(this.createKey())
|
||||
}
|
||||
|
||||
importPublicKey(key) {
|
||||
return Promise.resolve(ec.keyFromPublic(key, 'hex'))
|
||||
}
|
||||
|
||||
importPrivateKey(key) {
|
||||
return Promise.resolve(ec.keyFromPrivate(key, 'hex'))
|
||||
}
|
||||
|
||||
sign(key, data) {
|
||||
const sig = ec.sign(data, key)
|
||||
return Promise.resolve(sig.toDER('hex'))
|
||||
}
|
||||
|
||||
verify(signature, key, data) {
|
||||
let res = false
|
||||
res = ec.verify(data, signature, key)
|
||||
return Promise.resolve(res)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CustomTestKeystore()
|
||||
Reference in New Issue
Block a user