Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let wallet1 = await open({
privateKey: '0x3141592653589793238462643383279502884197169399375105820974944592'
})
let wallet2 = await open({
privateKey: '0x2141592653589793238462643383279502884197169399375105820974944592'
})
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:8546'))
acOptions = Object.assign({}, { web3 }, { abi }, { contractAddress: address }, { primaryAccount })
// contractAPI = new ContractAPI(web3, abi, address, primaryAccount)
const signer1 = async (id, data) => { return await wallet1.signMessage({ message: data }) }
const signer2 = async (id, data) => { return await wallet2.signMessage({ message: data }) }
id1 = await IdentityProvider.createIdentity(keystore, wallet1.address, { type: 'ethers', identitySignerFn: signer1 })
id2 = await IdentityProvider.createIdentity(keystore, wallet2.address, { type: 'ethers', identitySignerFn: signer2 })
orbitdb1 = await OrbitDB.createInstance(ipfs, {
acType: 'eth-contract',
acOptions: acOptions,
directory: dbPath + '/1',
identity: id1
})
orbitdb2 = await OrbitDB.createInstance(ipfs, {
acType: 'contract',
acOptions: acOptions,
directory: dbPath + '/2',
identity: id2
})
})
export default async function startIpfs() {
// FIXME: Doesn't work on brave
console.log('Starting ipfs and orbitdb...');
window.ipfsNode = await IPFS.create(ipfsOptions);
const options = { id: 'local-id' };
const identity = await Identities.createIdentity(options);
const orbitdb = await OrbitDB.createInstance(window.ipfsNode, { identity });
// each user has their own metadata database
window.metadataDb = await orbitdb.docs('metadataDb', { indexBy: 'fileId' });
await window.metadataDb.load();
// TODO: Sharding of public database
// Create Public Metadata Registry
// const publicDb = {
// // Give write access to everyone
// accessController: {
// write: ['*'],
// },
// };
// const metadataRegistry = await orbitdb.eventlog('metadataRegistry', publicDb);
// Connect to Public Metadata Registry
// Create default `level` store
options.storage = Storage(null, storageOptions)
}
if (options.identity && options.identity.provider.keystore) {
options.keystore = options.identity.provider.keystore
}
if (!options.keystore) {
const keystorePath = path.join(options.directory, id, '/keystore')
const keyStorage = await options.storage.createStore(keystorePath)
options.keystore = new Keystore(keyStorage)
}
if (!options.identity) {
options.identity = await Identities.createIdentity({
id: options.id || id,
keystore: options.keystore
})
}
if (!options.cache) {
const cachePath = path.join(options.directory, id, '/cache')
const cacheStorage = await options.storage.createStore(cachePath)
options.cache = new Cache(cacheStorage)
}
const finalOptions = Object.assign({}, options, { peerId: id })
return new OrbitDB(ipfs, options.identity, finalOptions)
}
rmrf.sync(signingKeysPath)
await fs.copy(identityKeyFixtures, identityKeysPath)
await fs.copy(signingKeyFixtures, signingKeysPath)
const defaultOptions = { identityKeysPath, signingKeysPath }
keystore = new Keystore(identityKeysPath)
signingKeystore = new Keystore(signingKeysPath)
const users = ['userA', 'userB', 'userC', 'userD']
options = users.map((user) => {
return Object.assign({}, defaultOptions, { id: user, keystore, signingKeystore })
})
testIdentity = await IdentityProvider.createIdentity(options[0])
testIdentity2 = await IdentityProvider.createIdentity(options[1])
testIdentity3 = await IdentityProvider.createIdentity(options[2])
testIdentity4 = await IdentityProvider.createIdentity(options[3])
ipfs = await startIpfs(IPFS, ipfsConfig)
})
async getOdbId (space) {
return Identities.createIdentity({
type: '3ID',
threeId: this,
space
})
}
if (defaultIdentityProvider) {
logger.info(`Connecting to Orbit as ${JSON.stringify(credentials)}`)
credentials = { type: 'orbitdb', id: credentials }
}
const profile = {
name: defaultIdentityProvider ? credentials : credentials.username,
location: 'Earth',
image: null
}
const identityKeysPath = path.join('./orbitdb', this._options.directory || '', 'keystore') || credentials.keystorePath
const newCredentials = Object.assign({}, credentials, { identityKeysPath })
const identity = await Identities.createIdentity(newCredentials)
this._user = new OrbitUser(identity, profile)
this._orbitdb = await OrbitDB.createInstance(
this._ipfs,
Object.assign(
{},
this._options.dbOptions,
{
directory: this._options.directory,
identity: this.user.identity
}
)
)
this._startPollingForPeers()
'use strict'
const path = require('path')
const EventEmitter = require('events').EventEmitter
const OrbitDB = require('orbit-db')
const Logger = require('logplease')
const Identities = require('orbit-db-identity-provider')
const MetamaskIdentityProvider = require('./IdentityProviders/purser-metamask-identity-provider')
Identities.addIdentityProvider(MetamaskIdentityProvider)
const OrbitUser = require('./orbit-user')
const Channel = require('./Channel')
const logger = Logger.create('Orbit', { color: Logger.Colors.Green })
Logger.setLogLevel(
process.env.NODE_ENV === 'development' ? Logger.LogLevels.DEBUG : Logger.LogLevels.ERROR
)
const getAppPath = () =>
process.type && process.env.ENV !== 'dev' ? process.resourcesPath + '/app/' : process.cwd()
const defaultOptions = {
dbOptions: {
const didJWT = require('did-jwt')
const Identities = require('orbit-db-identity-provider')
const { OdbIdentityProvider } = require('3box-orbitdb-plugins')
Identities.addIdentityProvider(OdbIdentityProvider)
const pubKey = '044f5c08e2150b618264c4794d99a22238bf60f1133a7f563e74fcf55ddb16748159872687a613545c65567d2b7a4d4e3ac03763e1d9a5fcfe512a371faa48a781'
const privKey = '95838ece1ac686bde68823b21ce9f564bc536eebb9c3500fa6da81f17086a6be'
const didResolverMock = async (did) => {
return {
'@context': 'https://w3id.org/did/v1',
'id': did,
'publicKey': [{
'id': `${did}#signingKey`,
'type': 'Secp256k1VerificationKey2018',
'publicKeyHex': pubKey
}],
'authentication': [{
'type': 'Secp256k1SignatureAuthentication2018',
'publicKey': `${did}#signingKey`
const { mnemonicToSeed, entropyToMnemonic } = require('@ethersproject/hdnode')
const EventEmitter = require('events')
const didJWT = require('did-jwt')
const DidDocument = require('ipfs-did-document')
const IpfsMini = require('ipfs-mini')
const localstorage = require('store')
const Identities = require('orbit-db-identity-provider')
const { OdbIdentityProvider } = require('3box-orbitdb-plugins')
Identities.addIdentityProvider(OdbIdentityProvider)
const utils = require('../utils/index')
const Keyring = require('./keyring')
const config = require('../config.js')
const DID_METHOD_NAME = '3'
const STORAGE_KEY = 'serialized3id_'
const MUPORT_IPFS = { host: config.muport_ipfs_host, port: config.muport_ipfs_port, protocol: config.muport_ipfs_protocol}
const POLL_INTERVAL = 500
class ThreeId {
constructor (provider, ipfs, opts = {}) {
this.events = new EventEmitter()
this._provider = provider
this._has3idProv = Boolean(opts.has3idProv)
this._ipfs = ipfs
this._muportIpfs = opts.muportIpfs || MUPORT_IPFS