crypto-pouch icon indicating copy to clipboard operation
crypto-pouch copied to clipboard

How to use in Browser?

Open klues opened this issue 6 years ago • 8 comments

The provided link in the readme: the browserified version from wzrd.in is dead.

So how could I get crypto-pouch running in a browser? Is there any other place to get a compiled js-file that can be used in browsers?

klues avatar Nov 28 '18 12:11 klues

I use it the following way in my extension:

import CryptoPouch from 'crypto-pouch'
PouchDB.plugin(CryptoPouch);

and then

db.crypto(password)

kiyanovsky avatar Dec 09 '18 15:12 kiyanovsky

The link is dead, where else can we get the browserified version?

tibomogul avatar Feb 25 '19 09:02 tibomogul

At this time, we don't distribute browserified versions of crypto-pouch. That may change soon, though! In the meantime, you're best off creating your own, like this:

$ curl https://unpkg.com/[email protected]/index.js > crypto-pouch-original.js
$ npx browserify crypto-pouch-original.js -o crypto-pouch.js

Now you can include crypto-pouch.js in your projects with a <script> tag:

<script src="crypto-pouch.js" charset="utf-8"></script>

Let me know if that works for you :)

I'll leave this issue open until we distribute a browserified version ourselves.

garbados avatar Aug 06 '21 23:08 garbados

Hey,

I'm struggeling to get crypto-pouch working in the browser. I tried the steps above and they didn't work.

First I had to do a npm add crypto-pouch before doing the browserfy (makes sense it needs it's dependencies there).

But even after that it fails in the browser with: "Invalid plugin: got "[object Object]", expected an object or a function"

It basically seems to fail when the plugin is being added to pouch:

if (typeof window !== 'undefined' && window.PouchDB) { window.PouchDB.plugin(exports) }

Hopefully someone can advice on how to get this running!

Best, Olav

t0PPy avatar Nov 18 '22 20:11 t0PPy

it fails in the browser with: "Invalid plugin: got "[object Object]", expected an object or a function"

same here.

any advice on how to workaround this ?

setop avatar Nov 29 '23 11:11 setop

Hey folks. I'm unable to reproduce this issue based on the info provided. If you can provide more info about your setup, I can try reproducing this again. Until then, this works on my end:

const CryptoPouch = require('crypto-pouch')
const PouchDB = require('pouchdb')
PouchDB.plugin(CryptoPouch)

const db = new PouchDB("test")

db.crypto("hello world")
  .then(() => console.log("encrypted!"))
  .then(() => db.post({hello: "world"}))
  .then(({ id }) => console.log(id))

This prints:

encrypted!
f261a66f-df0d-49c5-9a8c-e071a59bc0c7

When reporting issues, please supply:

  • Your PouchDB version.
  • How you bundle PouchDB and Crypto-Pouch.

For my part, I tried with PouchDB v7.2.2 and v8.0.1.

garbados avatar Nov 29 '23 16:11 garbados

I tried to "browserify" crypto-pouch and garbados-crypt, then import in an a html plas using a <script> tag. And get the error.

setop avatar Nov 30 '23 16:11 setop

I tried to "browserify" crypto-pouch and garbados-crypt, then import in an a html plas using a <script> tag. And get the error.

You shouldn't need to browserify these things directly. Browserify the entry point of your program -- where you require these things, where your app starts. That will automatically bring in dependencies. Otherwise, IIRC, Browserify wraps these dependencies so they aren't available in a global context, as your setup requires.

garbados avatar Dec 07 '23 14:12 garbados