MCPcopy Index your code
hub / github.com/mailvelope/mailvelope / importKey

Method importKey

src/controller/import.controller.js:78–120  ·  view source on GitHub ↗
(keyringId, armored, rotation)

Source from the content-addressed store, hash-verified

76 }
77
78 async importKey(keyringId, armored, rotation) {
79 try {
80 this.keyringId = keyringId;
81 // check keyringId
82 this.keyring = await getKeyringById(keyringId);
83 this.armored = armored;
84 this.rotation = rotation;
85 this.key = await readKey({armoredKey: this.armored});
86 this.key = await sanitizeKey(this.key);
87 if (!this.key || await verifyPrimaryKey(this.key) === KEY_STATUS.invalid) {
88 throw new Error('Key is invalid.');
89 }
90 this.armored = this.key.armor();
91 // collect key details
92 [this.keyDetails] = await mapKeys([this.key]);
93 if (this.keyDetails.type === 'private') {
94 throw new Error('Import of private keys not allowed.');
95 }
96 const users = [];
97 for (const [index, user] of this.key.users.entries()) {
98 if (!user.userID) {
99 // filter out user attribute packages
100 continue;
101 }
102 const userStatus = await verifyUser(user);
103 const uiUser = {id: index, userId: user.userID.userID, name: user.userID.name, email: user.userID.email, status: userStatus};
104 parseUserId(uiUser);
105 users.push(uiUser);
106 }
107 this.keyDetails.users = users;
108 // check if key already in keyring
109 const fingerprint = this.key.getFingerprint();
110 let stockKey = this.keyring.keystore.getKeysForId(fingerprint);
111 if (stockKey) {
112 stockKey = stockKey[0];
113 return this.updateKey(fingerprint, stockKey, this.key);
114 } else {
115 return this.openPopup();
116 }
117 } catch (err) {
118 throw new MvError(err.message, 'IMPORT_ERROR');
119 }
120 }
121
122 async updateKey(fingerprint, stockKey, newKey) {
123 const statusBefore = await verifyPrimaryKey(stockKey);

Callers 3

importKeysMethod · 0.45
lookupKeyFunction · 0.45
importPubKeyMethod · 0.45

Calls 9

updateKeyMethod · 0.95
openPopupMethod · 0.95
sanitizeKeyFunction · 0.90
verifyPrimaryKeyFunction · 0.90
mapKeysFunction · 0.90
verifyUserFunction · 0.90
parseUserIdFunction · 0.90
getKeysForIdMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected