"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const CryptoKey_1 = require("../../../../../wrap/CryptoKey");
const _ids_1 = require("../../../../_ids");
class ImportJwkKey extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['algorithm', 'extractable', 'keyUsages', 'data'],
            o: ['key'],
        }, {
            input: {
                algorithm: {
                    ref: true,
                },
            },
            output: {
                key: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_IMPORT_JWT_KEY);
    }
    async f({ data, algorithm, extractable, keyUsages }, done, fail) {
        const { api: { crypto: { importKey }, }, } = this.__system;
        let algorithm_ = algorithm.raw();
        let key_;
        try {
            key_ = await importKey('jwk', data, algorithm_, extractable, keyUsages);
        }
        catch (err) {
            fail(err.message.toLowerCase());
            return;
        }
        const key = (0, CryptoKey_1.wrapCryptoKey)(key_, this.__system);
        done({ key });
    }
}
exports.default = ImportJwkKey;
//# sourceMappingURL=index.js.map