blind-encryption-sodium 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/index.js +20 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -30,6 +30,18 @@ const base = new Autobase(store, {
30
30
  })
31
31
  ```
32
32
 
33
+ ### Usage with encryption-encoding
34
+
35
+ Internally, Autobase uses this with encryption-encoding
36
+
37
+ ```js
38
+ const { encrypt, decrypt } = require('encryption-encoding')
39
+ const BlindEncryptionSodium = require('blind-encryption-sodium')
40
+
41
+ const encryptedAndEncoded = await encrypt(encryptionKey, bes.encrypt.bind(bes))
42
+ const decrypted = await decrypt(encryptedAndEncoded, bes.decrypt.bind(bes))
43
+ ```
44
+
33
45
  ## License
34
46
 
35
47
  Apache-2.0
package/index.js CHANGED
@@ -5,32 +5,32 @@ class BlindEncryptionSodium {
5
5
  constructor(entropy) {
6
6
  this._entropy = entropy || null
7
7
  this._type = 1
8
- }
9
-
10
- async encrypt(key) {
11
- const buffer = b4a.allocUnsafe(
12
- key.byteLength + sodium.crypto_secretbox_MACBYTES + sodium.crypto_secretbox_NONCEBYTES
13
- )
14
- const nonce = buffer.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
15
- const box = buffer.subarray(nonce.byteLength)
16
8
 
17
- sodium.randombytes_buf(nonce)
18
- sodium.crypto_secretbox_easy(box, key, nonce, this._entropy)
9
+ this.encrypt = async (key) => {
10
+ const buffer = b4a.allocUnsafe(
11
+ key.byteLength + sodium.crypto_secretbox_MACBYTES + sodium.crypto_secretbox_NONCEBYTES
12
+ )
13
+ const nonce = buffer.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
14
+ const box = buffer.subarray(nonce.byteLength)
19
15
 
20
- return { value: buffer, type: 1 }
21
- }
16
+ sodium.randombytes_buf(nonce)
17
+ sodium.crypto_secretbox_easy(box, key, nonce, this._entropy)
22
18
 
23
- async decrypt({ value, type }) {
24
- if (type !== this._type) {
25
- throw new Error('Not encrypted using BlindEncryptionSodium')
19
+ return { value: buffer, type: 1 }
26
20
  }
27
21
 
28
- const nonce = value.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
29
- const box = value.subarray(nonce.byteLength)
30
- const output = b4a.allocUnsafe(box.byteLength - sodium.crypto_secretbox_MACBYTES)
22
+ this.decrypt = async ({ value, type }) => {
23
+ if (type !== this._type) {
24
+ throw new Error('Not encrypted using BlindEncryptionSodium')
25
+ }
31
26
 
32
- sodium.crypto_secretbox_open_easy(output, box, nonce, this._entropy)
33
- return output
27
+ const nonce = value.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
28
+ const box = value.subarray(nonce.byteLength)
29
+ const output = b4a.allocUnsafe(box.byteLength - sodium.crypto_secretbox_MACBYTES)
30
+
31
+ sodium.crypto_secretbox_open_easy(output, box, nonce, this._entropy)
32
+ return output
33
+ }
34
34
  }
35
35
  }
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blind-encryption-sodium",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Implemention of encryption encoding for Autobase blind encryption using sodium easy box",
5
5
  "main": "index.js",
6
6
  "exports": {