Browse Source

hash the context

Kieran Gibb 2 years ago
parent
commit
473353cff6
No account linked to committer's email address
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      index.js

+ 3
- 2
index.js View File

@@ -15,8 +15,9 @@ class Crypto {
15 15
     return key
16 16
   }
17 17
 
18
-  keyPair (masterKey, id, context) {
19
-    if (!context) context = sodium.sodium_malloc(sodium.crypto_kdf_KEYBYTES)
18
+  keyPair (masterKey, id, conText = 'cobox') {
19
+    const context = sodium.sodium_malloc(sodium.crypto_hash_sha256_BYTES)
20
+    sodium.crypto_hash_sha256(context, Buffer.from(conText))
20 21
     const seed = sodium.sodium_malloc(sodium.crypto_kdf_KEYBYTES)
21 22
     sodium.crypto_kdf_derive_from_key(seed, id, context, masterKey)
22 23
     return crypto.keyPair(seed)