UNPKG

passbolt-styleguide

Version:

Passbolt styleguide contains common styling assets used by the different sites, plugin, etc.

97 lines (87 loc) 3.74 kB
/** * Passbolt ~ Open source password manager for teams * Copyright (c) Passbolt SA (https://www.passbolt.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 4.11.0 */ import MetadataKeysCollection from "../../../models/entity/metadata/metadataKeysCollection"; import ExternalGpgKeyPairEntity from "../../../models/entity/gpgkey/external/externalGpgKeyPairEntity"; import MetadataKeyEntity from "../../../models/entity/metadata/metadataKeyEntity"; export const METADATA_KEYS_CREATE_EVENT = "passbolt.metadata.create-key"; export const METADATA_KEYS_GENERATE_EVENT = "passbolt.metadata.generate-metadata-key"; export const METADATA_KEYS_FIND_ALL_EVENT = "passbolt.metadata.find-all-non-deleted-metadata-keys"; export const METADATA_SHARE_METADATA_PRIVATE_KEYS_EVENT = "passbolt.metadata.share-missing-metadata-private-keys-with-user"; export const METADATA_KEYS_ROTATE_EVENT = "passbolt.metadata.rotate-metadata-key"; export const METADATA_KEYS_RESUME_ROTATE_EVENT = "passbolt.metadata.resume-rotate-metadata-key"; class MetadataKeysServiceWorkerService { /** * Constructor * @param {port} port The browser extension background page / service worker port. */ constructor(port) { this.port = port; } /** * Find the metadata keys. * @returns {Promise<MetadataKeysCollection>} */ async findAll() { const metadataKeysDto = await this.port.request(METADATA_KEYS_FIND_ALL_EVENT); return new MetadataKeysCollection(metadataKeysDto); } /** * Generate a metadata key pair. * @returns {Promise<ExternalGpgKeyPairEntity>} */ async generateKeyPair() { const externalGpgKeyPairDto = await this.port.request(METADATA_KEYS_GENERATE_EVENT); return new ExternalGpgKeyPairEntity(externalGpgKeyPairDto); } /** * Create a metadata key. * @param {ExternalGpgKeyPairEntity} metadataKeyPair The metadata key pair. * @returns {Promise<MetadataKeyEntity>} */ async createKey(metadataKeyPair) { if (!(metadataKeyPair instanceof ExternalGpgKeyPairEntity)) { throw new TypeError("The parameter `metadataKeyPair` should be of type ExternalGpgKeyPairEntity."); } const contains = { public_key: true, private_key: true }; const metadataKeyDto = await this.port.request(METADATA_KEYS_CREATE_EVENT, metadataKeyPair.toDto(contains)); return new MetadataKeyEntity(metadataKeyDto); } /** * Share a missing metadata keys with an expected user. * @param {string} userId The user id which does not have all keys. * @returns {Promise<void>} */ async share(userId) { await this.port.request(METADATA_SHARE_METADATA_PRIVATE_KEYS_EVENT, userId); } /** * Rotate a metadata keys. * @param {ExternalGpgKeyPairEntity} metadataKeyPair The metadata key pair. * @param {string} metadataKeyId The metadata key id. * @returns {Promise<void>} */ async rotate(metadataKeyPair, metadataKeyId) { await this.port.request(METADATA_KEYS_ROTATE_EVENT, metadataKeyPair, metadataKeyId); } /** * Resume incomplete rotation of a metadata keys. * @param {MetadataKeyEntity} metadataKey The metadata key to delete. * @returns {Promise<void>} */ async resumeRotation(metadataKey) { await this.port.request(METADATA_KEYS_RESUME_ROTATE_EVENT, metadataKey); } } export default MetadataKeysServiceWorkerService;