* Import armored keys into the keyring * @param {Object } armoredKeys - armored keys of type 'public' or 'private' * @return {Array } import result messages in the form {type, message}, type could be 'error' or 'success'
(armoredKeys)
| 61 | * @return {Array<Object>} import result messages in the form {type, message}, type could be 'error' or 'success' |
| 62 | */ |
| 63 | async importKeys(armoredKeys) { |
| 64 | const result = []; |
| 65 | // sort, public keys first |
| 66 | armoredKeys = armoredKeys.sort((a, b) => b.type.localeCompare(a.type)); |
| 67 | // import |
| 68 | for (const key of armoredKeys) { |
| 69 | try { |
| 70 | if (key.type === 'public') { |
| 71 | result.push(...await this.importPublicKey(key.armored, this.keystore)); |
| 72 | } else if (key.type === 'private') { |
| 73 | result.push(...await this.importPrivateKey(key.armored, this.keystore)); |
| 74 | } |
| 75 | } catch (e) { |
| 76 | console.log('Exception on key import:', e); |
| 77 | result.push({ |
| 78 | type: 'error', |
| 79 | message: l10n.get('key_import_unable', [e]) |
| 80 | }); |
| 81 | } |
| 82 | } |
| 83 | // exit if no import succeeded |
| 84 | if (!result.some(message => message.type === 'success')) { |
| 85 | return result; |
| 86 | } |
| 87 | try { |
| 88 | await this.keystore.store(); |
| 89 | await this.sync.commit(); |
| 90 | } catch (e) { |
| 91 | console.log('keystore.store() failed:', e); |
| 92 | await this.sync.clear(); |
| 93 | result.length = 0; |
| 94 | result.push({type: 'error', message: e.message}); |
| 95 | } |
| 96 | // if no default key in the keyring set, then first found private key will be set as default for the keyring |
| 97 | if (!await this.hasDefaultKey() && this.keystore.privateKeys.keys.length > 0) { |
| 98 | await this.setDefaultKey(this.keystore.privateKeys.keys[0].getFingerprint()); |
| 99 | } |
| 100 | return result; |
| 101 | } |
| 102 | |
| 103 | async importPublicKey(armored) { |
| 104 | const result = []; |
nothing calls this directly
no test coverage detected