* Generate a new PGP keypair and optionally upload the public key to the * key server. * @param {String} options.keyAlgo - public-key crypto algorithm of the key * @param {number} options.numBits - the keysize in bits * @param {Array} options.userIds - email addresses and names * @par
({keyAlgo, numBits, userIds, passphrase, uploadPublicKey, keyExpirationTime})
| 317 | * @yield {Object} - the generated key pair |
| 318 | */ |
| 319 | async generateKey({keyAlgo, numBits, userIds, passphrase, uploadPublicKey, keyExpirationTime}) { |
| 320 | userIds = userIds.map(userId => ({name: userId.fullName, email: userId.email})); |
| 321 | const newKey = await this.keystore.generateKey({keyAlgo, userIds, passphrase, numBits: parseInt(numBits), keyExpirationTime}); |
| 322 | this.keystore.privateKeys.push(newKey.privateKey); |
| 323 | // upload public key |
| 324 | // currently only the Mailvelope key server is supported but Web Key Directory |
| 325 | // publishing could also happen at this point. |
| 326 | if (uploadPublicKey) { |
| 327 | await mveloKeyServerUpload({publicKeyArmored: newKey.publicKey.armor()}); |
| 328 | } |
| 329 | return newKey; |
| 330 | } |
| 331 | } |