mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Disable Ethereum and DID identity providers for now
This commit is contained in:
parent
79e3487bfe
commit
739ddc9ded
@ -1,69 +1,69 @@
|
||||
import IdentityProvider from './interface.js'
|
||||
import * as u8a from 'uint8arrays'
|
||||
import { DID } from 'dids'
|
||||
// import IdentityProvider from './interface.js'
|
||||
// import * as u8a from 'uint8arrays'
|
||||
// import { DID } from 'dids'
|
||||
|
||||
const type = 'DID'
|
||||
// const type = 'DID'
|
||||
|
||||
class DIDIdentityProvider extends IdentityProvider {
|
||||
constructor ({ didProvider }) {
|
||||
super()
|
||||
// class DIDIdentityProvider extends IdentityProvider {
|
||||
// constructor ({ didProvider }) {
|
||||
// super()
|
||||
|
||||
if (!didProvider) {
|
||||
throw new Error('DIDIdentityProvider requires a didProvider parameter')
|
||||
}
|
||||
// if (!didProvider) {
|
||||
// throw new Error('DIDIdentityProvider requires a didProvider parameter')
|
||||
// }
|
||||
|
||||
this.did = new DID({
|
||||
resolver: DIDIdentityProvider.did._resolver,
|
||||
provider: didProvider
|
||||
})
|
||||
}
|
||||
// this.did = new DID({
|
||||
// resolver: DIDIdentityProvider.did._resolver,
|
||||
// provider: didProvider
|
||||
// })
|
||||
// }
|
||||
|
||||
static get type () { return type }
|
||||
// static get type () { return type }
|
||||
|
||||
async getId () {
|
||||
if (!this.did.authenticated) {
|
||||
await this.did.authenticate()
|
||||
}
|
||||
return this.did.id
|
||||
}
|
||||
// async getId () {
|
||||
// if (!this.did.authenticated) {
|
||||
// await this.did.authenticate()
|
||||
// }
|
||||
// return this.did.id
|
||||
// }
|
||||
|
||||
async signIdentity (data) {
|
||||
if (!this.did.authenticated) {
|
||||
await this.did.authenticate()
|
||||
}
|
||||
const payload = u8a.toString(u8a.fromString(data, 'base16'), 'base64url')
|
||||
const { signatures } = await this.did.createJWS(payload)
|
||||
// encode as JWS with detached payload
|
||||
return `${signatures[0].protected}..${signatures[0].signature}`
|
||||
}
|
||||
// async signIdentity (data) {
|
||||
// if (!this.did.authenticated) {
|
||||
// await this.did.authenticate()
|
||||
// }
|
||||
// const payload = u8a.toString(u8a.fromString(data, 'base16'), 'base64url')
|
||||
// const { signatures } = await this.did.createJWS(payload)
|
||||
// // encode as JWS with detached payload
|
||||
// return `${signatures[0].protected}..${signatures[0].signature}`
|
||||
// }
|
||||
|
||||
static setDIDResolver (resolver) {
|
||||
if (!this.did) {
|
||||
this.did = new DID({ resolver })
|
||||
} else {
|
||||
this.did.setResolver(resolver)
|
||||
}
|
||||
}
|
||||
// static setDIDResolver (resolver) {
|
||||
// if (!this.did) {
|
||||
// this.did = new DID({ resolver })
|
||||
// } else {
|
||||
// this.did.setResolver(resolver)
|
||||
// }
|
||||
// }
|
||||
|
||||
static async verifyIdentity (identity) {
|
||||
if (!this.did) {
|
||||
throw new Error('The DID resolver must first be set with setDIDResolver()')
|
||||
}
|
||||
// static async verifyIdentity (identity) {
|
||||
// if (!this.did) {
|
||||
// throw new Error('The DID resolver must first be set with setDIDResolver()')
|
||||
// }
|
||||
|
||||
const { publicKey, signatures } = identity
|
||||
const data = publicKey + signatures.id
|
||||
// const { publicKey, signatures } = identity
|
||||
// const data = publicKey + signatures.id
|
||||
|
||||
try {
|
||||
const payload = u8a.toString(u8a.fromString(data, 'base16'), 'base64url')
|
||||
const [header, signature] = signatures.publicKey.split('..')
|
||||
const jws = [header, payload, signature].join('.')
|
||||
await this.did.verifyJWS(jws)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
// try {
|
||||
// const payload = u8a.toString(u8a.fromString(data, 'base16'), 'base64url')
|
||||
// const [header, signature] = signatures.publicKey.split('..')
|
||||
// const jws = [header, payload, signature].join('.')
|
||||
// await this.did.verifyJWS(jws)
|
||||
// } catch (e) {
|
||||
// return false
|
||||
// }
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
export default DIDIdentityProvider
|
||||
// export default DIDIdentityProvider
|
||||
|
@ -1,70 +1,70 @@
|
||||
import IdentityProvider from './interface.js'
|
||||
import { Wallet, verifyMessage } from '@ethersproject/wallet'
|
||||
// import IdentityProvider from './interface.js'
|
||||
// import { Wallet, verifyMessage } from '@ethersproject/wallet'
|
||||
|
||||
const type = 'ethereum'
|
||||
// const type = 'ethereum'
|
||||
|
||||
class EthIdentityProvider extends IdentityProvider {
|
||||
constructor ({ wallet } = {}) {
|
||||
super()
|
||||
this.wallet = wallet
|
||||
}
|
||||
// class EthIdentityProvider extends IdentityProvider {
|
||||
// constructor ({ wallet } = {}) {
|
||||
// super()
|
||||
// this.wallet = wallet
|
||||
// }
|
||||
|
||||
// Returns the type of the identity provider
|
||||
static get type () { return type }
|
||||
// // Returns the type of the identity provider
|
||||
// static get type () { return type }
|
||||
|
||||
// Returns the signer's id
|
||||
async getId (options = {}) {
|
||||
if (!this.wallet) {
|
||||
this.wallet = await this._createWallet(options)
|
||||
}
|
||||
return this.wallet.getAddress()
|
||||
}
|
||||
// // Returns the signer's id
|
||||
// async getId (options = {}) {
|
||||
// if (!this.wallet) {
|
||||
// this.wallet = await this._createWallet(options)
|
||||
// }
|
||||
// return this.wallet.getAddress()
|
||||
// }
|
||||
|
||||
// Returns a signature of pubkeysignature
|
||||
async signIdentity (data) {
|
||||
const wallet = this.wallet
|
||||
// // Returns a signature of pubkeysignature
|
||||
// async signIdentity (data) {
|
||||
// const wallet = this.wallet
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error('wallet is required')
|
||||
}
|
||||
// if (!wallet) {
|
||||
// throw new Error('wallet is required')
|
||||
// }
|
||||
|
||||
return wallet.signMessage(data)
|
||||
}
|
||||
// return wallet.signMessage(data)
|
||||
// }
|
||||
|
||||
static async verifyIdentity (identity) {
|
||||
// Verify that identity was signed by the id
|
||||
const signerAddress = verifyMessage(
|
||||
identity.publicKey + identity.signatures.id,
|
||||
identity.signatures.publicKey
|
||||
)
|
||||
return (signerAddress === identity.id)
|
||||
}
|
||||
// static async verifyIdentity (identity) {
|
||||
// // Verify that identity was signed by the id
|
||||
// const signerAddress = verifyMessage(
|
||||
// identity.publicKey + identity.signatures.id,
|
||||
// identity.signatures.publicKey
|
||||
// )
|
||||
// return (signerAddress === identity.id)
|
||||
// }
|
||||
|
||||
async _createWallet (options = {}) {
|
||||
if (options.mnemonicOpts) {
|
||||
if (!options.mnemonicOpts.mnemonic) {
|
||||
throw new Error('mnemonic is required')
|
||||
}
|
||||
// async _createWallet (options = {}) {
|
||||
// if (options.mnemonicOpts) {
|
||||
// if (!options.mnemonicOpts.mnemonic) {
|
||||
// throw new Error('mnemonic is required')
|
||||
// }
|
||||
|
||||
const { mnemonic, path, wordlist } = options.mnemonicOpts
|
||||
return Wallet.fromMnemonic(mnemonic, path, wordlist)
|
||||
}
|
||||
// const { mnemonic, path, wordlist } = options.mnemonicOpts
|
||||
// return Wallet.fromMnemonic(mnemonic, path, wordlist)
|
||||
// }
|
||||
|
||||
if (options.encryptedJsonOpts) {
|
||||
if (!options.encryptedJsonOpts.json) {
|
||||
throw new Error('encrypted json is required')
|
||||
}
|
||||
// if (options.encryptedJsonOpts) {
|
||||
// if (!options.encryptedJsonOpts.json) {
|
||||
// throw new Error('encrypted json is required')
|
||||
// }
|
||||
|
||||
if (!options.encryptedJsonOpts.password) {
|
||||
throw new Error('password for encrypted json is required')
|
||||
}
|
||||
// if (!options.encryptedJsonOpts.password) {
|
||||
// throw new Error('password for encrypted json is required')
|
||||
// }
|
||||
|
||||
const { json, password, progressCallback } = options.encryptedJsonOpts
|
||||
return Wallet.fromEncryptedJson(json, password, progressCallback)
|
||||
}
|
||||
// const { json, password, progressCallback } = options.encryptedJsonOpts
|
||||
// return Wallet.fromEncryptedJson(json, password, progressCallback)
|
||||
// }
|
||||
|
||||
return Wallet.createRandom()
|
||||
}
|
||||
}
|
||||
// return Wallet.createRandom()
|
||||
// }
|
||||
// }
|
||||
|
||||
export default EthIdentityProvider
|
||||
// export default EthIdentityProvider
|
||||
|
@ -1,4 +1,4 @@
|
||||
export { default as DIDIdentityProvider } from './did.js'
|
||||
export { default as EthIdentityProvider } from './ethereum.js'
|
||||
// export { default as DIDIdentityProvider } from './did.js'
|
||||
// export { default as EthIdentityProvider } from './ethereum.js'
|
||||
export { default as IdentityProvider } from './interface.js'
|
||||
export { default as OrbitDBIdentityProvider } from './orbitdb.js'
|
||||
|
@ -1,158 +1,158 @@
|
||||
import assert from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
|
||||
import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
|
||||
import Identity from '../../src/identities/identity.js'
|
||||
import { Ed25519Provider } from 'key-did-provider-ed25519'
|
||||
import KeyDidResolver from 'key-did-resolver'
|
||||
import DIDIdentityProvider from '../../src/identities/providers/did.js'
|
||||
// import assert from 'assert'
|
||||
// import rmrf from 'rimraf'
|
||||
// import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
|
||||
// import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
|
||||
// import Identity from '../../src/identities/identity.js'
|
||||
// import { Ed25519Provider } from 'key-did-provider-ed25519'
|
||||
// import KeyDidResolver from 'key-did-resolver'
|
||||
// import DIDIdentityProvider from '../../src/identities/providers/did.js'
|
||||
|
||||
const seed = new Uint8Array([157, 94, 116, 198, 19, 248, 93, 239, 173, 82, 245, 222, 199, 7, 183, 177, 123, 238, 83, 240, 143, 188, 87, 191, 33, 95, 58, 136, 46, 218, 219, 245])
|
||||
const didStr = 'did:key:z6MkpnTJwrrVuphNh1uKb5DB7eRxvqniVaSDUHU6jtGVmn3r'
|
||||
const type = DIDIdentityProvider.type
|
||||
// const seed = new Uint8Array([157, 94, 116, 198, 19, 248, 93, 239, 173, 82, 245, 222, 199, 7, 183, 177, 123, 238, 83, 240, 143, 188, 87, 191, 33, 95, 58, 136, 46, 218, 219, 245])
|
||||
// const didStr = 'did:key:z6MkpnTJwrrVuphNh1uKb5DB7eRxvqniVaSDUHU6jtGVmn3r'
|
||||
// const type = DIDIdentityProvider.type
|
||||
|
||||
describe('DID Identity Provider', function () {
|
||||
let keystore
|
||||
let identities
|
||||
// describe('DID Identity Provider', function () {
|
||||
// let keystore
|
||||
// let identities
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore()
|
||||
DIDIdentityProvider.setDIDResolver(KeyDidResolver.getResolver())
|
||||
addIdentityProvider(DIDIdentityProvider)
|
||||
identities = await Identities({ keystore })
|
||||
})
|
||||
// before(async () => {
|
||||
// keystore = await KeyStore()
|
||||
// DIDIdentityProvider.setDIDResolver(KeyDidResolver.getResolver())
|
||||
// addIdentityProvider(DIDIdentityProvider)
|
||||
// identities = await Identities({ keystore })
|
||||
// })
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
rmrf.sync('./keystore')
|
||||
rmrf.sync('./orbitdb')
|
||||
})
|
||||
// after(async () => {
|
||||
// if (keystore) {
|
||||
// await keystore.close()
|
||||
// }
|
||||
// rmrf.sync('./keystore')
|
||||
// rmrf.sync('./orbitdb')
|
||||
// })
|
||||
|
||||
describe('create an DID identity', () => {
|
||||
let identity
|
||||
// describe('create an DID identity', () => {
|
||||
// let identity
|
||||
|
||||
before(async () => {
|
||||
const didProvider = new Ed25519Provider(seed)
|
||||
identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
})
|
||||
// before(async () => {
|
||||
// const didProvider = new Ed25519Provider(seed)
|
||||
// identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
// })
|
||||
|
||||
it('has the correct id', async () => {
|
||||
assert.strictEqual(identity.id, didStr)
|
||||
})
|
||||
// it('has the correct id', async () => {
|
||||
// assert.strictEqual(identity.id, didStr)
|
||||
// })
|
||||
|
||||
it('created a key for id in keystore', async () => {
|
||||
const key = await keystore.getKey(didStr)
|
||||
assert.notStrictEqual(key, undefined)
|
||||
})
|
||||
// it('created a key for id in keystore', async () => {
|
||||
// const key = await keystore.getKey(didStr)
|
||||
// assert.notStrictEqual(key, undefined)
|
||||
// })
|
||||
|
||||
it('has the correct public key', async () => {
|
||||
const signingKey = await keystore.getKey(didStr)
|
||||
assert.notStrictEqual(signingKey, undefined)
|
||||
assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
|
||||
})
|
||||
// it('has the correct public key', async () => {
|
||||
// const signingKey = await keystore.getKey(didStr)
|
||||
// assert.notStrictEqual(signingKey, undefined)
|
||||
// assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
|
||||
// })
|
||||
|
||||
it('has a signature for the id', async () => {
|
||||
const signingKey = await keystore.getKey(didStr)
|
||||
const idSignature = await signMessage(signingKey, didStr)
|
||||
const verifies = await verifyMessage(idSignature, identity.publicKey, didStr)
|
||||
assert.strictEqual(verifies, true)
|
||||
assert.strictEqual(identity.signatures.id, idSignature)
|
||||
})
|
||||
// it('has a signature for the id', async () => {
|
||||
// const signingKey = await keystore.getKey(didStr)
|
||||
// const idSignature = await signMessage(signingKey, didStr)
|
||||
// const verifies = await verifyMessage(idSignature, identity.publicKey, didStr)
|
||||
// assert.strictEqual(verifies, true)
|
||||
// assert.strictEqual(identity.signatures.id, idSignature)
|
||||
// })
|
||||
|
||||
it('has a signature for the publicKey', async () => {
|
||||
const signingKey = await keystore.getKey(didStr)
|
||||
const idSignature = await signMessage(signingKey, didStr)
|
||||
assert.notStrictEqual(idSignature, undefined)
|
||||
})
|
||||
})
|
||||
// it('has a signature for the publicKey', async () => {
|
||||
// const signingKey = await keystore.getKey(didStr)
|
||||
// const idSignature = await signMessage(signingKey, didStr)
|
||||
// assert.notStrictEqual(idSignature, undefined)
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('verify identity', () => {
|
||||
let identity
|
||||
// describe('verify identity', () => {
|
||||
// let identity
|
||||
|
||||
before(async () => {
|
||||
const didProvider = new Ed25519Provider(seed)
|
||||
identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
})
|
||||
// before(async () => {
|
||||
// const didProvider = new Ed25519Provider(seed)
|
||||
// identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
// })
|
||||
|
||||
it('DID identity verifies', async () => {
|
||||
const verified = await identities.verifyIdentity(identity)
|
||||
assert.strictEqual(verified, true)
|
||||
})
|
||||
// it('DID identity verifies', async () => {
|
||||
// const verified = await identities.verifyIdentity(identity)
|
||||
// assert.strictEqual(verified, true)
|
||||
// })
|
||||
|
||||
it('DID identity with incorrect id does not verify', async () => {
|
||||
const { publicKey, signatures, type } = identity
|
||||
const identity2 = await Identity({
|
||||
id: 'NotAnId',
|
||||
publicKey,
|
||||
signatures,
|
||||
type
|
||||
})
|
||||
const verified = await identities.verifyIdentity(identity2)
|
||||
assert.strictEqual(verified, false)
|
||||
})
|
||||
})
|
||||
// it('DID identity with incorrect id does not verify', async () => {
|
||||
// const { publicKey, signatures, type } = identity
|
||||
// const identity2 = await Identity({
|
||||
// id: 'NotAnId',
|
||||
// publicKey,
|
||||
// signatures,
|
||||
// type
|
||||
// })
|
||||
// const verified = await identities.verifyIdentity(identity2)
|
||||
// assert.strictEqual(verified, false)
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('sign data with an identity', () => {
|
||||
let identity
|
||||
const data = 'hello friend'
|
||||
// describe('sign data with an identity', () => {
|
||||
// let identity
|
||||
// const data = 'hello friend'
|
||||
|
||||
before(async () => {
|
||||
const didProvider = new Ed25519Provider(seed)
|
||||
identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
})
|
||||
// before(async () => {
|
||||
// const didProvider = new Ed25519Provider(seed)
|
||||
// identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
// })
|
||||
|
||||
it('sign data', async () => {
|
||||
const signingKey = await keystore.getKey(identity.id)
|
||||
const expectedSignature = await signMessage(signingKey, data)
|
||||
const signature = await identities.sign(identity, data, keystore)
|
||||
assert.strictEqual(signature, expectedSignature)
|
||||
})
|
||||
// it('sign data', async () => {
|
||||
// const signingKey = await keystore.getKey(identity.id)
|
||||
// const expectedSignature = await signMessage(signingKey, data)
|
||||
// const signature = await identities.sign(identity, data, keystore)
|
||||
// assert.strictEqual(signature, expectedSignature)
|
||||
// })
|
||||
|
||||
it('throws an error if private key is not found from keystore', async () => {
|
||||
// Remove the key from the keystore (we're using a mock storage in these tests)
|
||||
const { publicKey, signatures, type } = identity
|
||||
const modifiedIdentity = await Identity({
|
||||
id: 'this id does not exist',
|
||||
publicKey,
|
||||
signatures: {
|
||||
id: '<sig>',
|
||||
publicKey: signatures.publicKey
|
||||
},
|
||||
type
|
||||
})
|
||||
let signature
|
||||
let err
|
||||
try {
|
||||
signature = await identities.sign(modifiedIdentity, data, keystore)
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
assert.strictEqual(signature, undefined)
|
||||
assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
|
||||
})
|
||||
// it('throws an error if private key is not found from keystore', async () => {
|
||||
// // Remove the key from the keystore (we're using a mock storage in these tests)
|
||||
// const { publicKey, signatures, type } = identity
|
||||
// const modifiedIdentity = await Identity({
|
||||
// id: 'this id does not exist',
|
||||
// publicKey,
|
||||
// signatures: {
|
||||
// id: '<sig>',
|
||||
// publicKey: signatures.publicKey
|
||||
// },
|
||||
// type
|
||||
// })
|
||||
// let signature
|
||||
// let err
|
||||
// try {
|
||||
// signature = await identities.sign(modifiedIdentity, data, keystore)
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.strictEqual(signature, undefined)
|
||||
// assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
|
||||
// })
|
||||
|
||||
describe('verify data signed by an identity', () => {
|
||||
const data = 'hello friend'
|
||||
let identity
|
||||
let signature
|
||||
// describe('verify data signed by an identity', () => {
|
||||
// const data = 'hello friend'
|
||||
// let identity
|
||||
// let signature
|
||||
|
||||
before(async () => {
|
||||
const didProvider = new Ed25519Provider(seed)
|
||||
identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
signature = await identities.sign(identity, data, keystore)
|
||||
})
|
||||
// before(async () => {
|
||||
// const didProvider = new Ed25519Provider(seed)
|
||||
// identity = await identities.createIdentity({ type, keystore, didProvider })
|
||||
// signature = await identities.sign(identity, data, keystore)
|
||||
// })
|
||||
|
||||
it('verifies that the signature is valid', async () => {
|
||||
const verified = await identities.verify(signature, identity.publicKey, data)
|
||||
assert.strictEqual(verified, true)
|
||||
})
|
||||
// it('verifies that the signature is valid', async () => {
|
||||
// const verified = await identities.verify(signature, identity.publicKey, data)
|
||||
// assert.strictEqual(verified, true)
|
||||
// })
|
||||
|
||||
it('doesn\'t verify invalid signature', async () => {
|
||||
const verified = await identities.verify('invalid', identity.publicKey, data)
|
||||
assert.strictEqual(verified, false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
// it('doesn\'t verify invalid signature', async () => {
|
||||
// const verified = await identities.verify('invalid', identity.publicKey, data)
|
||||
// assert.strictEqual(verified, false)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
@ -1,154 +1,154 @@
|
||||
import assert from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
|
||||
import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
|
||||
import Identity from '../../src/identities/identity.js'
|
||||
import EthIdentityProvider from '../../src/identities/providers/ethereum.js'
|
||||
// import assert from 'assert'
|
||||
// import rmrf from 'rimraf'
|
||||
// import KeyStore, { signMessage, verifyMessage } from '../../src/key-store.js'
|
||||
// import Identities, { addIdentityProvider } from '../../src/identities/identities.js'
|
||||
// import Identity from '../../src/identities/identity.js'
|
||||
// import EthIdentityProvider from '../../src/identities/providers/ethereum.js'
|
||||
|
||||
const type = EthIdentityProvider.type
|
||||
// const type = EthIdentityProvider.type
|
||||
|
||||
describe('Ethereum Identity Provider', function () {
|
||||
let keystore
|
||||
let identities
|
||||
// describe('Ethereum Identity Provider', function () {
|
||||
// let keystore
|
||||
// let identities
|
||||
|
||||
before(async () => {
|
||||
keystore = await KeyStore()
|
||||
// before(async () => {
|
||||
// keystore = await KeyStore()
|
||||
|
||||
addIdentityProvider(EthIdentityProvider)
|
||||
identities = await Identities({ keystore })
|
||||
})
|
||||
// addIdentityProvider(EthIdentityProvider)
|
||||
// identities = await Identities({ keystore })
|
||||
// })
|
||||
|
||||
after(async () => {
|
||||
if (keystore) {
|
||||
await keystore.close()
|
||||
}
|
||||
rmrf.sync('./keystore')
|
||||
rmrf.sync('./orbitdb')
|
||||
})
|
||||
// after(async () => {
|
||||
// if (keystore) {
|
||||
// await keystore.close()
|
||||
// }
|
||||
// rmrf.sync('./keystore')
|
||||
// rmrf.sync('./orbitdb')
|
||||
// })
|
||||
|
||||
describe('create an ethereum identity', () => {
|
||||
let identity
|
||||
let wallet
|
||||
// describe('create an ethereum identity', () => {
|
||||
// let identity
|
||||
// let wallet
|
||||
|
||||
before(async () => {
|
||||
const ethIdentityProvider = new EthIdentityProvider()
|
||||
wallet = await ethIdentityProvider._createWallet()
|
||||
identity = await identities.createIdentity({ type, keystore, wallet })
|
||||
})
|
||||
// before(async () => {
|
||||
// const ethIdentityProvider = new EthIdentityProvider()
|
||||
// wallet = await ethIdentityProvider._createWallet()
|
||||
// identity = await identities.createIdentity({ type, keystore, wallet })
|
||||
// })
|
||||
|
||||
it('has the correct id', async () => {
|
||||
assert.strictEqual(identity.id, wallet.address)
|
||||
})
|
||||
// it('has the correct id', async () => {
|
||||
// assert.strictEqual(identity.id, wallet.address)
|
||||
// })
|
||||
|
||||
it('created a key for id in keystore', async () => {
|
||||
const key = await keystore.getKey(wallet.address)
|
||||
assert.notStrictEqual(key, undefined)
|
||||
})
|
||||
// it('created a key for id in keystore', async () => {
|
||||
// const key = await keystore.getKey(wallet.address)
|
||||
// assert.notStrictEqual(key, undefined)
|
||||
// })
|
||||
|
||||
it('has the correct public key', async () => {
|
||||
const signingKey = await keystore.getKey(wallet.address)
|
||||
assert.notStrictEqual(signingKey, undefined)
|
||||
assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
|
||||
})
|
||||
// it('has the correct public key', async () => {
|
||||
// const signingKey = await keystore.getKey(wallet.address)
|
||||
// assert.notStrictEqual(signingKey, undefined)
|
||||
// assert.strictEqual(identity.publicKey, keystore.getPublic(signingKey))
|
||||
// })
|
||||
|
||||
it('has a signature for the id', async () => {
|
||||
const signingKey = await keystore.getKey(wallet.address)
|
||||
const idSignature = await signMessage(signingKey, wallet.address)
|
||||
const verifies = await verifyMessage(idSignature, Buffer.from(signingKey.public.marshal()).toString('hex'), wallet.address)
|
||||
assert.strictEqual(verifies, true)
|
||||
assert.strictEqual(identity.signatures.id, idSignature)
|
||||
})
|
||||
// it('has a signature for the id', async () => {
|
||||
// const signingKey = await keystore.getKey(wallet.address)
|
||||
// const idSignature = await signMessage(signingKey, wallet.address)
|
||||
// const verifies = await verifyMessage(idSignature, Buffer.from(signingKey.public.marshal()).toString('hex'), wallet.address)
|
||||
// assert.strictEqual(verifies, true)
|
||||
// assert.strictEqual(identity.signatures.id, idSignature)
|
||||
// })
|
||||
|
||||
it('has a signature for the publicKey', async () => {
|
||||
const signingKey = await keystore.getKey(wallet.address)
|
||||
const idSignature = await signMessage(signingKey, wallet.address)
|
||||
const publicKeyAndIdSignature = await wallet.signMessage(identity.publicKey + idSignature)
|
||||
assert.strictEqual(identity.signatures.publicKey, publicKeyAndIdSignature)
|
||||
})
|
||||
})
|
||||
// it('has a signature for the publicKey', async () => {
|
||||
// const signingKey = await keystore.getKey(wallet.address)
|
||||
// const idSignature = await signMessage(signingKey, wallet.address)
|
||||
// const publicKeyAndIdSignature = await wallet.signMessage(identity.publicKey + idSignature)
|
||||
// assert.strictEqual(identity.signatures.publicKey, publicKeyAndIdSignature)
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('verify identity', () => {
|
||||
let identity
|
||||
// describe('verify identity', () => {
|
||||
// let identity
|
||||
|
||||
before(async () => {
|
||||
identity = await identities.createIdentity({ keystore, type })
|
||||
})
|
||||
// before(async () => {
|
||||
// identity = await identities.createIdentity({ keystore, type })
|
||||
// })
|
||||
|
||||
it('ethereum identity verifies', async () => {
|
||||
const verified = await identities.verifyIdentity(identity)
|
||||
assert.strictEqual(verified, true)
|
||||
})
|
||||
// it('ethereum identity verifies', async () => {
|
||||
// const verified = await identities.verifyIdentity(identity)
|
||||
// assert.strictEqual(verified, true)
|
||||
// })
|
||||
|
||||
it('ethereum identity with incorrect id does not verify', async () => {
|
||||
const { publicKey, signatures, type } = identity
|
||||
const identity2 = await Identity({
|
||||
id: 'NotAnId',
|
||||
publicKey,
|
||||
signatures,
|
||||
type
|
||||
})
|
||||
const verified = await identities.verifyIdentity(identity2)
|
||||
assert.strictEqual(verified, false)
|
||||
})
|
||||
})
|
||||
// it('ethereum identity with incorrect id does not verify', async () => {
|
||||
// const { publicKey, signatures, type } = identity
|
||||
// const identity2 = await Identity({
|
||||
// id: 'NotAnId',
|
||||
// publicKey,
|
||||
// signatures,
|
||||
// type
|
||||
// })
|
||||
// const verified = await identities.verifyIdentity(identity2)
|
||||
// assert.strictEqual(verified, false)
|
||||
// })
|
||||
// })
|
||||
|
||||
describe('sign data with an identity', () => {
|
||||
let identity
|
||||
const data = 'hello friend'
|
||||
// describe('sign data with an identity', () => {
|
||||
// let identity
|
||||
// const data = 'hello friend'
|
||||
|
||||
before(async () => {
|
||||
identity = await identities.createIdentity({ keystore, type })
|
||||
})
|
||||
// before(async () => {
|
||||
// identity = await identities.createIdentity({ keystore, type })
|
||||
// })
|
||||
|
||||
it('sign data', async () => {
|
||||
const signingKey = await keystore.getKey(identity.id)
|
||||
const expectedSignature = await signMessage(signingKey, data)
|
||||
const signature = await identities.sign(identity, data, keystore)
|
||||
assert.strictEqual(signature, expectedSignature)
|
||||
})
|
||||
// it('sign data', async () => {
|
||||
// const signingKey = await keystore.getKey(identity.id)
|
||||
// const expectedSignature = await signMessage(signingKey, data)
|
||||
// const signature = await identities.sign(identity, data, keystore)
|
||||
// assert.strictEqual(signature, expectedSignature)
|
||||
// })
|
||||
|
||||
it('throws an error if private key is not found from keystore', async () => {
|
||||
// Remove the key from the keystore (we're using a mock storage in these tests)
|
||||
const { publicKey, signatures, type } = identity
|
||||
const modifiedIdentity = await Identity({
|
||||
id: 'this id does not exist',
|
||||
publicKey,
|
||||
signatures: {
|
||||
id: '<sig>',
|
||||
publicKey: signatures.publicKey
|
||||
},
|
||||
type
|
||||
})
|
||||
let signature
|
||||
let err
|
||||
try {
|
||||
signature = await identities.sign(modifiedIdentity, data, keystore)
|
||||
} catch (e) {
|
||||
err = e.toString()
|
||||
}
|
||||
assert.strictEqual(signature, undefined)
|
||||
assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
|
||||
})
|
||||
// it('throws an error if private key is not found from keystore', async () => {
|
||||
// // Remove the key from the keystore (we're using a mock storage in these tests)
|
||||
// const { publicKey, signatures, type } = identity
|
||||
// const modifiedIdentity = await Identity({
|
||||
// id: 'this id does not exist',
|
||||
// publicKey,
|
||||
// signatures: {
|
||||
// id: '<sig>',
|
||||
// publicKey: signatures.publicKey
|
||||
// },
|
||||
// type
|
||||
// })
|
||||
// let signature
|
||||
// let err
|
||||
// try {
|
||||
// signature = await identities.sign(modifiedIdentity, data, keystore)
|
||||
// } catch (e) {
|
||||
// err = e.toString()
|
||||
// }
|
||||
// assert.strictEqual(signature, undefined)
|
||||
// assert.strictEqual(err, 'Error: Private signing key not found from KeyStore')
|
||||
// })
|
||||
|
||||
describe('verify data signed by an identity', () => {
|
||||
const data = 'hello friend'
|
||||
let identity
|
||||
let signature
|
||||
// describe('verify data signed by an identity', () => {
|
||||
// const data = 'hello friend'
|
||||
// let identity
|
||||
// let signature
|
||||
|
||||
before(async () => {
|
||||
identity = await identities.createIdentity({ type, keystore })
|
||||
signature = await identities.sign(identity, data, keystore)
|
||||
})
|
||||
// before(async () => {
|
||||
// identity = await identities.createIdentity({ type, keystore })
|
||||
// signature = await identities.sign(identity, data, keystore)
|
||||
// })
|
||||
|
||||
it('verifies that the signature is valid', async () => {
|
||||
const verified = await identities.verify(signature, identity.publicKey, data)
|
||||
assert.strictEqual(verified, true)
|
||||
})
|
||||
// it('verifies that the signature is valid', async () => {
|
||||
// const verified = await identities.verify(signature, identity.publicKey, data)
|
||||
// assert.strictEqual(verified, true)
|
||||
// })
|
||||
|
||||
it('doesn\'t verify invalid signature', async () => {
|
||||
const verified = await identities.verify('invalid', identity.publicKey, data)
|
||||
assert.strictEqual(verified, false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
// it('doesn\'t verify invalid signature', async () => {
|
||||
// const verified = await identities.verify('invalid', identity.publicKey, data)
|
||||
// assert.strictEqual(verified, false)
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
|
Loading…
x
Reference in New Issue
Block a user