Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const startOrbitDbServer = async ipfs => {
// Remap the peer connected to ours which will wait before exchanging heads
// with the same peer
const orbitGlobal = new OrbitDB(ipfs, config.ORBIT_DB_PATH, {
keystore: new InsertOnlyKeystore()
})
orbitGlobal._onPeerConnected = _onPeerConnected
orbitGlobal.keystore.registerSignVerify(
config.GLOBAL_KEYS,
undefined,
verifyRegistrySignature,
message => {
handleGlobalRegistryWrite(orbitGlobal, message.payload)
}
)
const globalRegistry = await orbitGlobal.kvstore(config.GLOBAL_KEYS, {
write: ['*']
ipfs.on("ready", async () => {
// remap the peer connected to ours which will wait before exchanging heads with the same peer
const orbit_global = new OrbitDB(ipfs, "odb/Main", {keystore:new InsertOnlyKeystore()})
orbit_global._onPeerConnected = _onPeerConnected
ipfs.setMaxListeners(MAX_IPFS_CONNECTIONS)
orbit_global.keystore.registerSignVerify(GLOBAL_KEYS, undefined, verifyRegistrySignature, message => {
handleGlobalRegistryWrite(orbit_global, message.payload)
})
const global_registry = await orbit_global.kvstore(GLOBAL_KEYS, { write: ['*'] })
rebroadcastOnReplicate(orbit_global, global_registry)
orbit_global.keystore.registerSignVerify(CONV_INIT_PREFIX, undefined, verifyConversationSignature(global_registry),
message => {
const eth_address = message.id.substr(-42) //hopefully the last 42 is the eth address
onConverse(orbit_global, eth_address, message.payload)
})
ipfs.on('ready', async () => {
// Create a database
const orbitdb = new OrbitDB(ipfs)
const db = await orbitdb.docstore('obligatron.test')
resolve(db)
})
})
export async function start() {
if (!window.ipfs) {
window.ipfs = new IPFS({
repo: 'ipfs-v6-boards-v0',
EXPERIMENTAL: {
pubsub: true
}
});
await new Promise(resolve => {
window.ipfs.on('ready', () => resolve())
})
}
if (!window.orbitDb) {
OrbitDB.addDatabaseType(BoardStore.type, BoardStore)
window.orbitDb = new OrbitDB(window.ipfs)
}
}
constructor(ipfs: IPFS, dbAddress?: string) {
super();
this.ipfs = ipfs;
this.address = dbAddress ? `${dbAddress}/disk` : 'disk';
this.orbit = new OrbitDB(ipfs);
}
return new Promise((resolve, reject) => {
if (peerId) {
orbitdb = new OrbitDB(ipfs, './orbitdb', { peerId })
return resolve(orbitdb.id)
}
PeerId.create((err, peer) => {
if (err)
return reject(err)
const p = peer.toJSON()
const peerId = p.id
const key = ec.keyFromPrivate(privateKey || p.privKey)
localStorage.setItem(peerId, JSON.stringify({
publicKey: key.getPublic('hex'),
privateKey: key.getPrivate('hex')
}))