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