Skip to content

Commit ed58496

Browse files
author
Danny Diekroeger
committed
handle support for xlm import new format
1 parent a7e8593 commit ed58496

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

app/admin.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ const saveKeys = co(function *(keys, type) {
238238
return;
239239
}
240240

241-
242-
243241
const keyDocs = keys
244242
.filter( key => validateKey(key, type))
245243
.map( key => ({
@@ -279,11 +277,45 @@ const handleImportKeys = co(function *(args) {
279277
throw new Error('please specify the path to a CSV file containing the public keys to import');
280278
}
281279

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);
283283

284284
yield saveKeys(keys, type);
285285
});
286286

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+
const formattedkeys = [];
309+
_.forEach(keys, function(key) {
310+
formattedkeys.push({
311+
pub: type === 'xlm' ? key.xlmpub : key.pub,
312+
signature: type === 'xlm' ? key.xlmSignature : key.signature,
313+
path: key.path
314+
});
315+
})
316+
return formattedkeys;
317+
}
318+
287319
const handleDeriveKey = function(args) {
288320
try {
289321
const childKey = utils.deriveChildKey(args.master, args.path, args.type, false);

0 commit comments

Comments
 (0)