All files / lib/Model PreloadedVault.js

15% Statements 3/20
0% Branches 0/4
0% Functions 0/7
15% Lines 3/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55  1x 1x                                                                                                     1x  
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const PassmanCrypto_1 = require("../Service/PassmanCrypto");
/**
 * The PreloadedVault contains only generic vault information, got from the /api/v1/vaults GET request.
 * It can be used as fast and small data structure during vault authentication, before any modification or credential is needed.
 */
class PreloadedVault {
    genericVaultInformation;
    server;
    constructor(genericVaultInformation, server) {
        this.genericVaultInformation = genericVaultInformation;
        this.server = server;
    }
    /**
     * Tests the vault key on the challenge_password
     * @param vaultKey
     */
    testVaultKey(vaultKey) {
        try {
            if (this.genericVaultInformation.challenge_password) {
                PassmanCrypto_1.PassmanCrypto.decryptString(this.genericVaultInformation.challenge_password, vaultKey);
                return true;
            }
            else {
                console.error('May we need credentials to test the vault key!');
                // would require fetching the full vault, instead of using this PreloadedVault
                return false;
            }
        }
        catch (e) {
        }
        return false;
    }
    static parseResponse(vaultsResponse, server) {
        if (vaultsResponse) {
            let newPreloadedVaults = [];
            vaultsResponse.forEach((vaultInformationFromServer) => {
                newPreloadedVaults.push(new PreloadedVault(vaultInformationFromServer, server));
            });
            return newPreloadedVaults;
        }
    }
    get id() {
        return this.genericVaultInformation.vault_id;
    }
    get guid() {
        return this.genericVaultInformation.guid;
    }
    get name() {
        return this.genericVaultInformation.name;
    }
}
exports.default = PreloadedVault;