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

Method signAndEncrypt

src/controller/editor.controller.js:485–551  ·  view source on GitHub ↗

* Encrypt, sign & encrypt, or sign only operation * @param {String} options.action - 'sign' or 'encrypt' * @param {String} options.message - body of the message * @param {String} options.keys - key data object (user id, key id, fingerprint, email and name) * @param {Array} options.attach

(options)

Source from the content-addressed store, hash-verified

483 * @return {Promise<String>} - message as armored block
484 */
485 async signAndEncrypt(options) {
486 if (options.action === 'encrypt') {
487 const noCache = options.noCache;
488 const keyFprs = await this.getPublicKeyFprs(options.keys);
489 let signKeyFpr;
490 let unlockKey;
491 let unlockedSignKey;
492 if (options.signMsg) {
493 signKeyFpr = options.signKeyFpr;
494 if (!signKeyFpr) {
495 const defaultKeyFpr = await getDefaultKeyFpr(this.state.keyringId);
496 signKeyFpr = defaultKeyFpr;
497 }
498 if (!signKeyFpr) {
499 throw new MvError('No private key found to sign this message.', 'NO_DEFAULT_KEY_FOUND');
500 }
501 unlockKey = async options => {
502 options.noCache = noCache;
503 options.reason = this.options.reason || 'PWD_DIALOG_REASON_SIGN';
504 options.sync = !prefs.security.password_cache;
505 options.key = unlockedSignKey ?? options.key;
506 unlockedSignKey = await this.unlockKey(options);
507 return unlockedSignKey;
508 };
509 }
510 let data;
511 let files = [];
512 let encFiles = [];
513 options.pgpMIME = this.pgpMIME;
514 if (this.state.integration && !this.pgpMIME) {
515 ({attachments: files, ...options} = options);
516 }
517 try {
518 data = buildMail(options);
519 } catch (error) {
520 if (this.ports.editorCont) {
521 this.ports.editorCont.emit('error-message', {error: mapError(error)});
522 }
523 }
524 if (data === null) {
525 throw new MvError('MIME building failed.');
526 }
527 const armored = await this.encryptMessage({
528 data,
529 keyFprs,
530 signKeyFpr,
531 unlockKey,
532 noCache
533 });
534 if (!this.pgpMIME && files.length) {
535 encFiles = await this.encryptFiles({
536 files,
537 keyFprs,
538 signKeyFpr,
539 unlockKey,
540 noCache
541 });
542 }

Callers 2

onEditorPlaintextMethod · 0.95

Calls 9

getPublicKeyFprsMethod · 0.95
unlockKeyMethod · 0.95
encryptMessageMethod · 0.95
encryptFilesMethod · 0.95
signMessageMethod · 0.95
getDefaultKeyFprFunction · 0.90
buildMailFunction · 0.90
mapErrorFunction · 0.90
emitMethod · 0.45

Tested by

no test coverage detected