cleanup tests
[squeep-mystery-box] / README.md
1 # Mystery Box
2
3 Our very own way of converting a buffer or serializable object to and from an opaque and web-safe representation, which we can let anyone see without disclosing the contents, nor allowing it to be modified without detection.
4
5 In our case, this results in a Base64URL encoded string containing a bespoke packing of encrypted and verified data.
6
7 ## API
8
9 - `async pack(contents, version, flags)`
10 - `async unpack(box)`
11
12 ## Example
13
14 ```js
15 const { MysteryBox } = require('@squeep/mystery-box');
16 const assert = require('assert');
17
18 const mb = new MysteryBox(console, {
19 encryptionSecret: 'very secret',
20 });
21
22 (async () => {
23 const data = { important: 'to keep secret' };
24 const encrypted = await mb.pack(data);
25 const decrypted = await mb.unpack(encrypted);
26 assert.deepStrictEqual(decrypted, data);
27 })()
28 .then(() => console.log('data retrieved!'));
29 ```
30
31 ## Details
32
33 This relies on AEAD ciphers, such as `aes-256-gcm` and `chacha20-poly1305`, to encrypt the payload and authenticate the additional metadata (version identifier, flags indicating payload details, the iv of the cipher, and the salt used to create the key) needed to decrypt the payload.
34
35 For each box, a new key is generated using the stored secret and a securely-random salt by way of a mechanism such as an XOF such as `shake256`, a hash such as `blake2b512`, or a more time-consuming multi-round hash such as `scrypt`. This key is used to encrypt and authenticate the data and metadata, which is then encoded as a base64url string.