Browse Source

Merge branch 'add-encryption-key' of CoBox/cobox-crypto into master

peg 3 years ago
parent
commit
7602f0420d
1 changed files with 3 additions and 23 deletions
  1. 3
    23
      index.js

+ 3
- 23
index.js View File

@@ -35,7 +35,9 @@ class Crypto {
35 35
     if (key.length === sodium.crypto_sign_PUBLICKEYBYTES) return { publicKey: key }
36 36
     const publicKey = key.slice(0, sodium.crypto_sign_PUBLICKEYBYTES)
37 37
     const symmetricKey = key.slice(sodium.crypto_secretbox_KEYBYTES)
38
-    return { publicKey, symmetricKey }
38
+    const encryptionKey = sodium.sodium_malloc(sodium.crypto_secretbox_KEYBYTES)
39
+    sodium.crypto_hash_sha256(encryptionKey, key)
40
+    return { publicKey, symmetricKey, encryptionKey }
39 41
   }
40 42
 
41 43
   isKey (key) {
@@ -45,28 +47,6 @@ class Crypto {
45 47
       length === sodium.crypto_sign_PUBLICKEYBYTES + sodium.crypto_secretbox_KEYBYTES
46 48
   }
47 49
 
48
-  isAccessKey (key) {
49
-    try { var keys = this.unpack(key) }
50
-    catch (err) { return false }
51
-    return keys.publicKey !== undefined &&
52
-      keys.publicKey !== null &&
53
-      keys.publicKey.length === sodium.crypto_sign_PUBLICKEYBYTES &&
54
-      keys.symmetricKey !== undefined &&
55
-      keys.symmetricKey !== null &&
56
-      keys.symmetricKey.length === sodium.crypto_secretbox_KEYBYTES
57
-  }
58
-
59
-  isBlindKey (key) {
60
-    try { var keys = this.unpack(key) }
61
-    catch (err) { return false }
62
-    var keys = this.unpack(key)
63
-    return keys.publicKey !== undefined &&
64
-      keys.publicKey !== null &&
65
-      keys.publicKey.length === sodium.crypto_sign_PUBLICKEYBYTES &&
66
-      (keys.symmetricKey === undefined ||
67
-      keys.symmetricKey === null)
68
-  }
69
-
70 50
   encoder (encryptionKey, opts = {}) {
71 51
     var can = Buffer.isBuffer(encryptionKey) &&
72 52
       (encryptionKey.length === sodium.crypto_secretbox_KEYBYTES)