"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const CryptoKey_1 = require("../../../../../wrap/CryptoKey");
const _ids_1 = require("../../../../_ids");
class GenerateKey extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['algorithm', 'extractable', 'keyUsages'],
            fo: ['key'],
        }, {
            input: {
                algorithm: {
                    ref: true,
                },
            },
            output: {
                key: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_GENERATE_KEY);
    }
    async f({ algorithm, extractable, keyUsages }, done, fail) {
        const { api: { crypto: { generateKey }, }, } = this.__system;
        const algorithm_ = algorithm.raw();
        if (!['HMAC'].includes(algorithm_.name)) {
            fail('invalid algorithm single key generation');
            return;
        }
        let key_;
        try {
            key_ = (await generateKey(algorithm_, extractable, keyUsages));
        }
        catch (err) {
            fail(err.message.toLowerCase());
            return;
        }
        const key = (0, CryptoKey_1.wrapCryptoKey)(key_, this.__system);
        done({ key });
    }
}
exports.default = GenerateKey;
//# sourceMappingURL=index.js.map