Skip to content

Instantly share code, notes, and snippets.

@jackkleeman
Created March 31, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jackkleeman/8070687fd8527fcef66676e3c0af0083 to your computer and use it in GitHub Desktop.
Save jackkleeman/8070687fd8527fcef66676e3c0af0083 to your computer and use it in GitHub Desktop.
function init(m, email, password) {
// generate the database encryption key
vendor.nCrypto
.pbkdf2(
Buffer.from(m.mnemonic, "utf8"),
Buffer.from(databaseKeySeed, "utf8"),
2048,
64,
"sha512"
)
.then(function(buffer) {
dbKey = buffer.slice(0, 32);
// setup unencrypted local DB changefeed
PouchDB.plugin(vendor.cryptoPouch);
db = new PouchDB(localDBPrefix + m.dbName);
db.crypto({
key: dbKey
});
db
.changes({
since: "now",
live: true,
include_docs: true
})
.on("change", function(change) {
if (change.doc && change.doc.message) {
changefeed(change.doc);
}
})
.on("error", console.log);
});
// setup remote DB
var remoteDB = new PouchDB(remoteDBAddress);
// setup local DB
var localDB = new PouchDB(localDBPrefix + m.dbName);
localDB.replicate
.from(remoteDB)
.on("complete", function() {
localDB
.sync(remoteDB, {
live: true,
retry: true
})
})
}
@fredguth
Copy link

fredguth commented Apr 1, 2018

I am not sure If I understood. Can you create 2 localDBPrefix + m.dbName PouchDBs?
What does changefeed does?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment