mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Disable Ethereum and DID identity providers for now
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user