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B,IAAK,MAAM,KAAO,KAAK,QAEjB,KAAO,IAAK,EAAU,GAAO,EAAI,IAEvC,OAAO,IAGb,EACA,aAAc,kBACL,KAAK,MACd,GAIoB,oBAAX,QAA0B,OAAO,SAC1C,OAAO,QAAQ,OAAO,OAAO","file":"/npm/crypto-pouch@4.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/crypto-pouch@4.0.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const Crypt = require('garbados-crypt')\nconst { transform } = require('transform-pouch')\n\nconst LOCAL_ID = '_local/crypto'\nconst IGNORE = ['_id', '_rev', '_deleted', '_conflicts']\n\nconst NO_COUCH = 'crypto-pouch does not work with pouchdb\\'s http adapter. Use a local adapter instead.'\n\nmodule.exports = {\n  transform,\n  crypto: async function (password, options = {}) {\n    if (this.adapter === 'http') {\n      throw new Error(NO_COUCH)\n    }\n    if (typeof password === 'object') {\n      // handle `db.crypto({ password, ...options })`\n      options = password\n      password = password.password\n      delete options.password\n    }\n    // setup ignore list\n    this._ignore = IGNORE.concat(options.ignore || [])\n    // setup crypto helper\n    const trySetup = async () => {\n      // try saving credentials to a local doc\n      try {\n        // first we try to get saved creds from the local doc\n        const { exportString } = await this.get(LOCAL_ID)\n        this._crypt = await Crypt.import(password, exportString)\n      } catch (err) {\n        // istanbul ignore else\n        if (err.status === 404) {\n          // but if the doc doesn't exist, we do first-time setup\n          this._crypt = new Crypt(password)\n          const exportString = await this._crypt.export()\n          try {\n            await this.put({ _id: LOCAL_ID, exportString })\n          } catch (err2) {\n            // istanbul ignore else\n            if (err2.status === 409) {\n              // if the doc was created while we were setting up,\n              // try setting up again to retrieve the saved credentials.\n              await trySetup()\n            } else {\n              throw err2\n            }\n          }\n        } else {\n          throw err\n        }\n      }\n    }\n    await trySetup()\n    // instrument document transforms\n    this.transform({\n      incoming: async (doc) => {\n        // if no crypt, ex: after .removeCrypto(), just return the doc\n        if (!this._crypt) { return doc }\n        if (doc._attachments && !this._ignore.includes('_attachments')) {\n          throw new Error('Attachments cannot be encrypted. Use {ignore: \"_attachments\"} option')\n        }\n        const encrypted = {}\n        for (const key of this._ignore) {\n          // attach ignored fields to encrypted doc\n          if (key in doc) encrypted[key] = doc[key]\n        }\n        encrypted.payload = await this._crypt.encrypt(JSON.stringify(doc))\n        return encrypted\n      },\n      outgoing: async (doc) => {\n        // if no crypt, ex: after .removeCrypto(), just return the doc\n        if (!this._crypt) { return doc }\n        if (!doc.payload) { return doc }\n        const decryptedString = await this._crypt.decrypt(doc.payload)\n        const decrypted = JSON.parse(decryptedString)\n        for (const key of this._ignore) {\n          // patch decrypted doc with ignored fields\n          if (key in doc) decrypted[key] = doc[key]\n        }\n        return decrypted\n      }\n    })\n  },\n  removeCrypto: function () {\n    delete this._crypt\n  }\n}\n\n// istanbul ignore next\nif (typeof window !== 'undefined' && window.PouchDB) {\n  window.PouchDB.plugin(module.exports)\n}\n"]}