Skip to content

Commit 4ae0a53

Browse files
authored
Merge pull request #42 from BitGo/importing-xlm-keys
[BG-9532] Importing xlm keys
2 parents a7e8593 + 05a2d87 commit 4ae0a53

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

app/admin.js

Lines changed: 39 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,49 @@ 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+
// 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+
287323
const handleDeriveKey = function(args) {
288324
try {
289325
const childKey = utils.deriveChildKey(args.master, args.path, args.type, false);

0 commit comments

Comments
 (0)