Closed ck-kc closed 3 years ago
the encryption stuff requires streams and buffers and string_decoder, you are probably better off using browserify to bundle this and then use that from react-native
@calvinmetcalf You can explain better ? I have the same issue of @ck-alpha
react native doesn't include any of the native node modules like stream or crypto which other bundlers like browserify shim for you so you're probably better off including a pre bundled version of this library if you want to use it with react native
@calvinmetcalf Tranks for your attention. I try your solution adding the code to a file in my project and used in my database file, but I get this error: Unable to resolve module './lib/_stream_duplex.js'
My code implementation:
import PouchDB from 'pouchdb-react-native';
import Find from 'pouchdb-find';
import Load from 'pouchdb-load';
import SQLite from 'react-native-sqlite-2';
import CryptoPouch from './crypto-pouch';
import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite';
import Search from 'pouchdb-quick-search';
import { DEVELOPMENT } from 'app/configs/constants';
PouchDB.plugin(SQLiteAdapterFactory(SQLite));
PouchDB.plugin(Find);
PouchDB.plugin(Search);
PouchDB.plugin(Load);
PouchDB.plugin(CryptoPouch);
/*
* DEBUG POUCH DB
* Options: *, pouchdb:api, pouchdb:http
* PouchDB.debug.enable(pouchdb:api)
*/
class Database {
constructor() {
this.pouchdb = null;
this.local = null;
this.remote = null;
}
setup({ local = null, remote = null }) {
if(this.local !== local || this.remote !== remote) {
this.local = local;
this.remote = remote;
this.pouchdb = {
local : new PouchDB(local, { include_docs : true, auto_compaction : true, adapter : 'react-native-sqlite' }),
remote : (remote && new PouchDB(remote, { skipSetup : true })) || null
};
['local', 'remote'].forEach(prop => {
this.pouchdb[prop].crypto(local, {
algorithm: 'chacha20'
});
});
}
return this.pouchdb;
}
reset() {
this.local = null;
this.remote = null;
this.pouchdb = null;
}
destroy() {
if(this.pouchdb && this.pouchdb.local) {
return this.pouchdb.local.destroy();
}
return this.pouchdb;
}
onSync({ onChange, onError, onComplete }) {
return this.pouchdb.local.sync(this.pouchdb.remote, {
live : true,
retry : true
}).on('change', onChange)
.on('complete', onComplete)
.on('error', onError)
}
}
// exporting Database as a Singleton
export default new Database();
Hey everybody! We just published version 4.0 which bundles some very different dependencies that might work better for your situation. I invite you to try again and let me know how it goes :)
I'm closing this issue for now since it's been a few years, but I can re-open it if you still need help.
Anyone done any work on porting crypto-pouch to react native?
I got stuck installing it due to lack of stream in react native. I can't remember which dependency required this...
Tried playing with rn-nodeify but it decided to delete all my package.jsons...
If no-one has done any work on it so far, I might start a fork and work it out.