| 253 | } |
| 254 | |
| 255 | async addUser(unlockedKey, user) { |
| 256 | const {user: {userID: primaryUserId}, selfCertification: primaryUserSelfCertification} = await unlockedKey.getPrimaryUser(); |
| 257 | const {privateKey: updatedKey} = await reformatKey({privateKey: unlockedKey, userIDs: [{name: primaryUserId.name, email: primaryUserId.email}, user], keyExpirationTime: primaryUserSelfCertification.keyExpirationTime, format: 'object'}); |
| 258 | const fingerprint = updatedKey.getFingerprint(); |
| 259 | await this.sync.add(fingerprint, keyringSync.UPDATE); |
| 260 | const originalKey = this.getPrivateKeyByFpr(fingerprint); |
| 261 | originalKey.users.push(updatedKey.users[1]); |
| 262 | if (primaryUserSelfCertification.isPrimaryUserID !== true) { |
| 263 | // openpgp.reformatKey sets the first user ID as primary. We update the old user ID if primary flag is not yet set. |
| 264 | await originalKey.users.find(({userID: {userID}}) => userID === primaryUserId.userID).update(updatedKey.users[0]); |
| 265 | } |
| 266 | await this.keystore.store(); |
| 267 | await this.sync.commit(); |
| 268 | } |
| 269 | |
| 270 | async setKeyExDate(unlockedKey, newExDate) { |
| 271 | const keyExpirationTime = newExDate ? (newExDate.getTime() - unlockedKey.keyPacket.created.getTime()) / 1000 : 0; |