garbados / comdb

A PouchDB plugin that transparently encrypts and decrypts its data.
61 stars 4 forks source link

Can't get In E2E with memory to work #13

Closed mbeckenbach closed 2 years ago

mbeckenbach commented 3 years ago

Hi,

tanks for this awesome lib!

I am trying to get the e2e encryption working in an angular 10 app. Just like you showed it here: https://github.com/garbados/comdb/issues/4

But i have trouble with the pouchdb-adapter-memory.

When I import it as this:

import PouchDB from 'pouchdb'; // Works
import PouchAuth from 'pouchdb-authentication'; // Works
import comdb from 'comdb'; // Works
import PouchMemory from 'pouchdb-adapter-memory'; // Does not

PouchDB.plugin(PouchAuth);
PouchDB.plugin(comdb);
PouchDB.plugin(PouchMemory);

I get this at app start:

Error: ./node_modules/sublevel-pouchdb/node_modules/readable-stream/readable.js
Module not found: Error: Can't resolve 'stream' in 'C:\source\ngcp\node_modules\sublevel-pouchdb\node_modules\readable-stream
'``

Then I tried to import this: 

import PouchMemory from 'pouchdb/dist/pouchdb.memory';


and got

memory adapter plugin error: Cannot find global "PouchDB" object! Did you remember to include pouchdb.js? core.js:6210 ERROR Error: Invalid plugin: got "[object Object]", expected an object or a function



I simply don't get it. Do you have any idea? I would be very thankful.
Btw. what I actually try to accomplish in the end is storing data encrypted on the client while having the decrypted version on the server. :-)
garbados commented 3 years ago

Have you installed pouchdb-adapter-memory as a dependency?

garbados commented 3 years ago

It's hard for me to guess what's going wrong since I'm not familiar with Angular (not since a much earlier version). It might be that your compilation process doesn't know what to do with pouchdb-adapter-memory's implementation. It was last modified around 2017 so it might reflect some older conventions that cause more recent tools to choke. If you can isolate a bug, I'd be happy to file the issue and follow up on it.

garbados commented 3 years ago

Furthermore, I've detected some bugs in this E2E approach using ComDB that I am still working to resolve. I'm glad you find this library useful, but be warned it is still rather experimental.

jjtolton commented 2 years ago

Hi @garbados ! Curious what the status on this is and if you have any plans to tinker with it any further? I wasn't able to get any of the encryption/reload recipes to work.

var PASSWORD = "blahzeblaht";
const db = new PouchDB("local");
db.setPassword(PASSWORD).then(async () => { 
  await db.loadEncrypted();
});

I then execute: await db.post({name: 'bob'}) and that works ok.

then await db.allDocs({include_docs: true}) returns the expected results. However, when I reload the page, I get this error:

image

If I try the same experiment but with adapter='memory' (after destroying all the databases),


// db already exists, we are just adding encryption
var PASSWORD = "blahzeblaht";
const db = new PouchDB("local3",  {adapter: "memory"});

db.setPassword(PASSWORD).then(async () => { 
  await db.loadEncrypted();
});

I get image

I tried tinkering with the source code a little bit but didn't get anywhere. Curious if you had any insight.

garbados commented 2 years ago

Hi @jjtolton ! I'll look into your issue and see if I can't reproduce it. But yeah, my open source contributions outside of work are pretty limited these days.

jjtolton commented 2 years ago

If it needs to be a paid thing to help move this along let me know. Setup a GitHub sponsors page or send me an email @.***! Happy to contribute.

On Mon, Mar 21, 2022 at 2:54 PM Diana Thayer @.***> wrote:

Hi @jjtolton https://github.com/jjtolton ! I'll look into your issue and see if I can't reproduce it. But yeah, my open source contributions outside of work are pretty limited these days.

— Reply to this email directly, view it on GitHub https://github.com/garbados/comdb/issues/13#issuecomment-1074289487, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPJX45AORD6ON3W4TGCJ6DVBDAVVANCNFSM437ROZ3Q . You are receiving this because you were mentioned.Message ID: @.***>

jjtolton commented 2 years ago

@garbados sorry, my email is my github name at gmail

garbados commented 2 years ago

Hi @jjtolton ! I'm in the process of setting up a GitHub Sponsors account. In the meantime, I'm taking a look at this today.

jjtolton commented 2 years ago

Thanks so much! Looking forward to testing, this is a great project.

On Sun, Apr 24, 2022 at 1:49 PM Diana Thayer @.***> wrote:

Hi @jjtolton https://github.com/jjtolton ! I'm in the process of setting up a GitHub Sponsors account. In the meantime, I'm taking a look at this today.

— Reply to this email directly, view it on GitHub https://github.com/garbados/comdb/issues/13#issuecomment-1107887087, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACPJX442MEGWYF6DVOZU7KTVGWCRDANCNFSM437ROZ3Q . You are receiving this because you were mentioned.Message ID: @.***>

garbados commented 2 years ago

OK. I'm able to reproduce the bug. It seems the document revision isn't being appropriately tied back to a document after its creation if it was created with post(). I have a fix locally and I'm writing a test to verify.

garbados commented 2 years ago

Hi @jjtolton ! I've isolated your particular issue here and pushed a fix here. I'll be closing this issue as it doesn't look like the OP is coming back.