@@ -238,8 +238,6 @@ const saveKeys = co(function *(keys, type) {
238
238
return ;
239
239
}
240
240
241
-
242
-
243
241
const keyDocs = keys
244
242
. filter ( key => validateKey ( key , type ) )
245
243
. map ( key => ( {
@@ -279,11 +277,49 @@ const handleImportKeys = co(function *(args) {
279
277
throw new Error ( 'please specify the path to a CSV file containing the public keys to import' ) ;
280
278
}
281
279
282
- const keys = JSON . parse ( fs . readFileSync ( path , { encoding : 'utf8' } ) ) ;
280
+ let keys = JSON . parse ( fs . readFileSync ( path , { encoding : 'utf8' } ) ) ;
281
+
282
+ keys = formatKeysByType ( keys , type ) ;
283
283
284
284
yield saveKeys ( keys , type ) ;
285
285
} ) ;
286
286
287
+ /**
288
+ * This function handles a new type of key-import format
289
+ * For example, a key can be imported as such:
290
+ * {
291
+ * pub: "xpub20412049182341234"
292
+ * xlmpub: "GSLKJASDFJASLFASDFAS"
293
+ * signature: "IK/alkjELASJFLAKJSDFLAKSFASDFW=="
294
+ * xlmSignature: "KOPASIK------PSDIFAPSDFOAF"
295
+ * path: "100"
296
+ * }
297
+ * If this key comes in, we can save it either as type xpub or xlm (depending on what the admin specifies on the command line)
298
+ * If the above key is imported as type 'xlm', we will change it to the following format:
299
+ * {
300
+ * pub: "GSLKJASDFJASLFASDFAS"
301
+ * signature: "KOPASIK------PSDIFAPSDFOAF"
302
+ * path: "100"
303
+ * }
304
+ * Notice that we replaced the pub and signature fields with the XLM info.
305
+ * Alternatively, if the key is specified to be an xpub, we would just remove the XLM info and continue as normal
306
+ */
307
+ const formatKeysByType = function ( keys , type ) {
308
+ // if using the old format, don't do anything here, just return the keys
309
+ if ( ! keys [ 0 ] . xlmpub ) {
310
+ return keys ;
311
+ }
312
+ const formattedkeys = [ ] ;
313
+ _ . forEach ( keys , function ( key ) {
314
+ formattedkeys . push ( {
315
+ pub : type === 'xlm' ? key . xlmpub : key . pub ,
316
+ signature : type === 'xlm' ? key . xlmSignature : key . signature ,
317
+ path : key . path
318
+ } ) ;
319
+ } )
320
+ return formattedkeys ;
321
+ }
322
+
287
323
const handleDeriveKey = function ( args ) {
288
324
try {
289
325
const childKey = utils . deriveChildKey ( args . master , args . path , args . type , false ) ;
0 commit comments