"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const ArrayBuffer_1 = require("../../../../../wrap/ArrayBuffer");
const _ids_1 = require("../../../../_ids");
class Decrypt extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['algorithm', 'key', 'data', 'opt'],
            fo: ['data'],
        }, {
            input: {
                algorithm: {
                    ref: true,
                },
                key: {
                    ref: true,
                },
                data: {
                    ref: true,
                },
            },
            output: {
                data: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_DECRYPT);
    }
    async f({ opt, key, algorithm, data }, done, fail) {
        const { api: { crypto: { decrypt }, }, } = this.__system;
        const key_ = (await key.raw());
        const algorithm_ = (await algorithm.raw());
        const data_ = (await data.raw());
        let _data;
        try {
            _data = await decrypt(algorithm_, key_, data_);
        }
        catch (err) {
            if (err.name === 'OperationError') {
                fail('operation error');
                return;
            }
            fail(err.message.toLowerCase());
            return;
        }
        const __data = (0, ArrayBuffer_1.wrapArrayBuffer)(_data, this.__system);
        done({ data: __data });
    }
}
exports.default = Decrypt;
//# sourceMappingURL=index.js.map