MCPcopy
hub / github.com/mailvelope/mailvelope / canUnlockKey

Method canUnlockKey

src/controller/sync.controller.js:181–203  ·  view source on GitHub ↗

* Check if key can be unlocked without requesting the password from the user * @param {String} operation - 'decrypt' or 'sign', the operation for which the key is required * @param {Object} options - mandatory * @param {openpgp.key.Key} options.key * @param {String} [options.password]

(operation, options)

Source from the content-addressed store, hash-verified

179 * @return {Boolean} - true if key can be unlocked
180 */
181 async canUnlockKey(operation, options) {
182 if (options.password) {
183 // key can always be unlocked with password
184 return true;
185 }
186 const isKeyCached = await isCached(options.key.getFingerprint());
187 if (isKeyCached) {
188 return true;
189 }
190 try {
191 let key;
192 if (operation === 'sign') {
193 key = await options.key.getSigningKey();
194 return key && key.isDecrypted();
195 } else if (operation === 'decrypt') {
196 key = await options.key.getEncryptionKey();
197 return key && key.isDecrypted();
198 }
199 } catch (e) {
200 console.log('No valid key for operation sign or decrypt', e);
201 return false;
202 }
203 }
204
205 sync(type, data) {
206 return new Promise((resolve, reject) => {

Callers 6

triggerSyncMethod · 0.95
downloadSyncMessageMethod · 0.95
onSetDataMethod · 0.45
onClippedArmoredMethod · 0.45
onMultipartEncryptedMethod · 0.45

Calls 1

isCachedFunction · 0.90

Tested by

no test coverage detected