Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ First: this library only makes sense if your clients sit behind a firewall, or i

This library monkey-patches either the Firebase Admin SDK or the Firebase JavaScript Client SDK to automatically encrypt and decrypt keys and values of your choosing using AES-SIV, and to compress encrypted string values. Almost everything just works, except that `startAt` and `endAt` queries on encrypted data would produce randomly ordered results and so are forbidden. `equalTo` queries will work fine, however, since a given plaintext value will always encrypt to the same ciphertext — but it will also let an attacker know if any two values are equal, even if they don't know what they are.

The library works both in Node (20.x+) and in the browser. In the browser, you need to also load [`crypto-js`](https://github.com/brix/crypto-js) (the following modules are sufficient: `core.js`, `lib-typedarrays.js`, `enc-base64.js`, `enc-base64url.js`, `sha1.js`, `md5.js`, `evpkdf.js`, `cipher-core.js`, `aes.js`, `mode-ctr.js`) and [`cryptojs-extension`](https://github.com/artjomb/cryptojs-extension) (only `build/siv.js` is required). If you want to enable caching to enhance performance, then in the browser you'll also want to load [`node-lru-cache`](https://github.com/isaacs/node-lru-cache). All these libraries are automatically included in the Node distribution.
The library works both in Node (20.x+) and in the browser. In the browser, you need to also load [`crypto-js`](https://github.com/brix/crypto-js) (the following modules are sufficient: `core.js`, `lib-typedarrays.js`, `enc-base64.js`, `enc-base64url.js`, `sha1.js`, `md5.js`, `evpkdf.js`, `cipher-core.js`, `aes.js`, `mode-ctr.js`) and [`cryptojs-extension`](https://github.com/artjomb/cryptojs-extension) (only `build/siv.js` is required). If you want to enable caching to enhance performance, then in the browser you'll also want to load [`lru-cache`](https://github.com/isaacs/node-lru-cache) into the `lrucache` global variable. All these libraries are automatically included in the Node distribution.

Upon requiring this library, the `admin.database()` or `firebase.database()` method as well as the
`app.App.database()` methods are monkey-patched to return a custom `FireCrypt` instance in place of
Expand Down Expand Up @@ -54,7 +54,7 @@ The `options` are as follows:
* `keyCheckValue`: a value generated by a previous call to `configureFireCrypt()` used to verify that the `aes-siv` `key` used in both calls is the same. If a different key was used to generate the `keyCheckValue` then an error with `firecrypt === 'WRONG_KEY'` will be thrown.
* For convenience, the `keyCheckValue` is also available at any time via
`admin.database().encryptionKeyCheckValue` or `firebase.database().encryptionKeyCheckValue`.
* `cacheSize`: the maximum size in bytes of the encryption and decryption caches, used to improve performance. In the browser, the caches will only be activated if `LRUCache` is defined; it should conform to the API of [`node-lru-cache`](https://github.com/isaacs/node-lru-cache). You can also specify `encryptionCacheSize` and `decryptionCacheSize` separately.
* `cacheSize`: the maximum size in bytes of the encryption and decryption caches, used to improve performance. In the browser, the caches will only be activated if `lrucache.LRUCache` is defined; it should conform to the API of [`lru-cache`](https://github.com/isaacs/node-lru-cache). You can also specify `encryptionCacheSize` and `decryptionCacheSize` separately.
* `compression`: the compression algorithm to use. Currently supported values are:
* `deflate`: the classic, low-overhead deflate algorithm.
* `none`: no compression.
Expand Down
16 changes: 8 additions & 8 deletions dist/browser/firecrypt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/firecrypt.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/browser/firecrypt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/firecrypt.min.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/node/firecrypt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/firecrypt.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default [
...globals.es2017,
CryptoJS: false,
fflate: false,
LRUCache: false,
lrucache: false,
},
ecmaVersion: 2019,
sourceType: 'module',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"crypto-js": "^4.0.0",
"cryptojs-extension": "github:reviewable/cryptojs-extension",
"fflate": "^0.8.2",
"serialized-lru-cache": "^3.1.0"
"lru-cache": "^11.2.6"
},
"peerDependencies": {
"firebase": "9.x || 10.x",
Expand Down
14 changes: 7 additions & 7 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export default class Crypto {
}
this._compressionThreshold = options.compressionThreshold || 150;

if (typeof LRUCache === 'function') {
this._encryptionCache = new LRUCache({
max: options.encryptionCacheSize,
length: this._computeCacheItemSize,
if (typeof lrucache !== 'undefined') {
this._encryptionCache = new lrucache.LRUCache({
maxSize: options.encryptionCacheSize,
sizeCalculation: this._computeCacheItemSize,
});
this._decryptionCache = new LRUCache({
max: options.decryptionCacheSize,
length: this._computeCacheItemSize,
this._decryptionCache = new lrucache.LRUCache({
maxSize: options.decryptionCacheSize,
sizeCalculation: this._computeCacheItemSize,
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/firecrypt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (typeof require !== 'undefined') {
/* eslint-disable no-undef */
if (typeof fflate === 'undefined') global.fflate = require('fflate');
if (typeof LRUCache === 'undefined') global.LRUCache = require('lru-cache');
if (typeof lrucache === 'undefined') global.lrucache = require('lru-cache');
if (typeof CryptoJS === 'undefined') global.CryptoJS = require('crypto-js/core');
require('crypto-js/lib-typedarrays');
require('crypto-js/enc-base64');
Expand Down
123 changes: 94 additions & 29 deletions tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading