Browse Source

move byKey function from group cli

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

+ 7
- 0
index.js View File

@@ -38,6 +38,13 @@ class Crypto {
38 38
     return { publicKey, symmetricKey }
39 39
   }
40 40
 
41
+  isKey (key) {
42
+    const length = Buffer.from(key, 'hex').length
43
+    return typeof key === 'string' &&
44
+      length === sodium.crypto_sign_PUBLICKEYBYTES ||
45
+      length === sodium.crypto_sign_PUBLICKEYBYTES + sodium.crypto_secretbox_KEYBYTES
46
+  }
47
+
41 48
   isAccessKey (key) {
42 49
     try { var keys = this.unpack(key) }
43 50
     catch (err) { return false }