Browse Source

isNamedKeypair should convert keys to strings if they are passed as buffers

ameba23 3 years ago
parent
commit
921940a0f7
1 changed files with 15 additions and 4 deletions
  1. 15
    4
      util.js

+ 15
- 4
util.js View File

@@ -2,14 +2,19 @@ const Validator = require('is-my-json-valid')
2 2
 
3 3
 // Q: this is unnecessary?
4 4
 function isNamedKeypair (content) {
5
-  var schema =  {
5
+  content.publicKey = toStr(content.publicKey)
6
+  content.secretKey = toStr(content.secretKey)
7
+
8
+  var schema = {
6 9
     $schema: 'http://json-schema.org/schema#',
7 10
     type: 'object',
8 11
     required: ['publicKey', 'secretKey'],
9 12
     properties: {
10
-      publicKey: { type: 'string', pattern: '[A-Za-z0-9_-]' },
11
-      secretKey: { type: 'string', pattern: '[A-Za-z0-9_-]' },
12
-      name: { type: 'string' },
13
+      // publicKey: { type: 'string', pattern: '[A-Za-z0-9_-]' },
14
+      // secretKey: { type: 'string', pattern: '[A-Za-z0-9_-]' },
15
+      publicKey: { type: 'string' },
16
+      secretKey: { type: 'string' },
17
+      name: { type: 'string' }
13 18
     }
14 19
   }
15 20
 
@@ -17,4 +22,10 @@ function isNamedKeypair (content) {
17 22
   return validator(content)
18 23
 }
19 24
 
25
+function toStr (key) {
26
+  return Buffer.isBuffer(key)
27
+    ? key.toString('hex')
28
+    : key
29
+}
30
+
20 31
 module.exports = { isNamedKeypair }