mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00

package-lock pointing to branch more cache management stuff WIP Passing tests Removing static linking fixing tests and linting fixing package.json removing last debugger removing last debugger Adding keystore and cache getters PR comments Removing extraneous cache management Package files Closing caches using dbAddress as this.caches key new tests for store management Working but with slightly different semantics Rebuild package-lock Dependency updates removeHandler restoring db.close in replication status test package.json files move handler to orbitdb.caches Test updates Cache management cleanup use store.options.directory requestCache in onLoad and onDrop add status test Adding db to this.stores in onLoad and onDrop Working RC5 before rebase Updating package-lock restoring original replicaiton status test package files removing keystore getter more keystore cleanup typo
83 lines
1.6 KiB
JavaScript
83 lines
1.6 KiB
JavaScript
const EC = require('elliptic').ec
|
|
const ec = new EC('secp256k1')
|
|
const IdentityProvider = require('orbit-db-identity-provider/src/identity-provider-interface')
|
|
/**
|
|
* A custom keystore example
|
|
*/
|
|
class CustomTestKeystore {
|
|
constructor (storage) {
|
|
// Use just one key throughout the keystore
|
|
// for mock purposes
|
|
this.key = this.createKey()
|
|
}
|
|
|
|
hasKey () {
|
|
return this.key !== undefined ? true : false
|
|
}
|
|
|
|
createKey (id) {
|
|
const key = ec.genKeyPair()
|
|
const keyPair = {
|
|
public: {
|
|
marshal: () => key.getPublic('hex')
|
|
},
|
|
priv: key.getPrivate('hex'),
|
|
privEnc: 'hex',
|
|
pubEnc: 'hex',
|
|
}
|
|
|
|
return keyPair
|
|
}
|
|
|
|
getKey (id) {
|
|
return this.key
|
|
}
|
|
|
|
sign (key, data) {
|
|
return Promise.resolve('<signature>')
|
|
}
|
|
|
|
verify (signature, publicKey, data) {
|
|
return Promise.resolve(true)
|
|
}
|
|
|
|
getPublic (key) {
|
|
return key.public.marshal()
|
|
}
|
|
|
|
close () {}
|
|
}
|
|
|
|
class CustomIdProvider extends IdentityProvider {
|
|
constructor (options = {}) {
|
|
super()
|
|
this._keystore = options.keystore || new CustomTestKeystore()
|
|
}
|
|
|
|
// Returns the type of the identity provider
|
|
static get type () { return 'custom' }
|
|
|
|
async getId (options = {}) {
|
|
return 'id'
|
|
}
|
|
|
|
async signIdentity (data, options = {}) {
|
|
const keystore = this._keystore
|
|
return keystore.sign(null, data)
|
|
}
|
|
|
|
static async verifyIdentity (identity) {
|
|
// Verify that identity was signed by the ID
|
|
return true
|
|
}
|
|
}
|
|
|
|
module.exports = (LocalStorage, mkdir) => {
|
|
return {
|
|
create: (directory) => {
|
|
return new CustomTestKeystore()
|
|
},
|
|
identityProvider: CustomIdProvider
|
|
}
|
|
}
|