"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebCryptoPrimitives = void 0;
const RSA_1 = require("./RSA");
const AES_1 = require("./AES");
const shamir_1 = require("./shamir");
const HMACUtils_1 = require("./HMACUtils");
const utils_1 = require("../utils");
/**
 * Gives access to cryptographic primitives.
 */
class WebCryptoPrimitives {
    get crypto() {
        return this._crypto;
    }
    get shamir() {
        return this._shamir;
    }
    get RSA() {
        return this._rsa;
    }
    get AES() {
        return this._aes;
    }
    get HMAC() {
        return this._hmac;
    }
    constructor(crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : {}) {
        this._crypto = crypto;
        this._rsa = new RSA_1.RSAUtilsImpl(crypto);
        this._aes = new AES_1.AESUtilsImpl(crypto);
        this._shamir = new shamir_1.WebcryptoShamir(crypto);
        this._hmac = new HMACUtils_1.HMACUtilsImpl(crypto);
    }
    randomUuid() {
        return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, 
        //Keep next inlined or you will lose the random
        (c) => (Number(c) ^ (this.crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (Number(c) / 4)))).toString(16));
    }
    sha256(data) {
        return this.crypto.subtle.digest('SHA-256', (0, utils_1.ua2ab)(data));
    }
    sha512(data) {
        return this.crypto.subtle.digest('SHA-512', (0, utils_1.ua2ab)(data));
    }
    randomBytes(n) {
        const res = new Uint8Array(n);
        this.crypto.getRandomValues(res);
        return res;
    }
}
exports.WebCryptoPrimitives = WebCryptoPrimitives;
//# sourceMappingURL=CryptoPrimitives.js.map