|
@ -15,7 +15,8 @@ function initIPFS(){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function createDatabases() { |
|
|
async function createDatabases() { |
|
|
orbitdb = await OrbitDB.createInstance(ipfs); |
|
|
console.log("Creating databases..."); |
|
|
|
|
|
orbitdb = await new OrbitDB(ipfs); |
|
|
topicsDB = await orbitdb.keyvalue('topics'); |
|
|
topicsDB = await orbitdb.keyvalue('topics'); |
|
|
postsDB = await orbitdb.keyvalue('posts'); |
|
|
postsDB = await orbitdb.keyvalue('posts'); |
|
|
store.dispatch({ |
|
|
store.dispatch({ |
|
@ -26,13 +27,12 @@ async function createDatabases() { |
|
|
id: orbitdb.id |
|
|
id: orbitdb.id |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const identityKey = orbitdb.keystore.getKey(orbitdb.identity.id); |
|
|
|
|
|
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); |
|
|
const orbitKey = orbitdb.keystore.getKey(orbitdb.id); |
|
|
|
|
|
|
|
|
const returnValue = { |
|
|
const returnValue = { |
|
|
identityId: orbitdb.identity.id, |
|
|
identityId: "Tempus", |
|
|
identityPublicKey: identityKey.getPublic('hex'), |
|
|
identityPublicKey: "edax", |
|
|
identityPrivateKey: identityKey.getPrivate('hex'), |
|
|
identityPrivateKey: "rerum", |
|
|
orbitId: orbitdb.id, |
|
|
orbitId: orbitdb.id, |
|
|
orbitPublicKey: orbitKey.getPublic('hex'), |
|
|
orbitPublicKey: orbitKey.getPublic('hex'), |
|
|
orbitPrivateKey: orbitKey.getPrivate('hex'), |
|
|
orbitPrivateKey: orbitKey.getPrivate('hex'), |
|
@ -46,19 +46,16 @@ async function createDatabases() { |
|
|
|
|
|
|
|
|
async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, |
|
|
async function loadDatabases(identityId, identityPublicKey, identityPrivateKey, |
|
|
orbitId, orbitPublicKey, orbitPrivateKey, topicsDB, postsDB) { |
|
|
orbitId, orbitPublicKey, orbitPrivateKey, topicsDB, postsDB) { |
|
|
|
|
|
console.log("Loading databases..."); |
|
|
let directory = "./orbitdb"; |
|
|
let directory = "./orbitdb"; |
|
|
let keystore = Keystore.create(path.join(directory, identityId, '/keystore')); |
|
|
let keystore = Keystore.create(path.join(directory, orbitId, '/keystore')); |
|
|
keystore._storage.setItem(identityId, JSON.stringify({ |
|
|
|
|
|
publicKey: identityPublicKey, |
|
|
|
|
|
privateKey: identityPrivateKey |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
keystore._storage.setItem(orbitId, JSON.stringify({ |
|
|
keystore._storage.setItem(orbitId, JSON.stringify({ |
|
|
publicKey: orbitPublicKey, |
|
|
publicKey: orbitPublicKey, |
|
|
privateKey: orbitPrivateKey |
|
|
privateKey: orbitPrivateKey |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
orbitdb = await OrbitDB.createInstance(ipfs, {directory: directory, peerId:identityId, keystore:keystore}); |
|
|
orbitdb = await new OrbitDB(ipfs, directory, { peerId:orbitId, keystore:keystore}); |
|
|
topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDB +'/topics'); |
|
|
topicsDB = await orbitdb.keyvalue('/orbitdb/' + topicsDB +'/topics'); |
|
|
postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDB +'/posts'); |
|
|
postsDB = await orbitdb.keyvalue('/orbitdb/' + postsDB +'/posts'); |
|
|
|
|
|
|
|
|