Browse Source

make isPubKey function more resilent

Kieran Gibb 2 years ago
parent
commit
1c8adaa2a6
No account linked to committer's email address
2 changed files with 3 additions and 2 deletions
  1. 1
    0
      lib/key-handler.js
  2. 2
    2
      util.js

+ 1
- 0
lib/key-handler.js View File

@@ -11,6 +11,7 @@ const KeyHandler = module.exports = (collection) => ({
11 11
     if (entry.secretKey) entry.secretKey = entry.secretKey.toString('hex')
12 12
     collection.byKey[entry.publicKey] = entry
13 13
     if (entry.name) collection.byName[entry.name] = entry
14
+    return true
14 15
   },
15 16
   remove: (entry) => {
16 17
     if (isPubKey(entry)) {

+ 2
- 2
util.js View File

@@ -1,6 +1,6 @@
1 1
 function isPubKey (variable) {
2
-  var length = Buffer.from(variable, 'hex').length
3
-  return (typeof variable === 'string' || variable instanceof Buffer) && length === 32
2
+  if (!(typeof variable === 'string' || variable instanceof Buffer)) return false
3
+  return Buffer.from(variable, 'hex').length === 32
4 4
 }
5 5
 
6 6
 function isName (variable) {