"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 Sign extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['opt', 'algorithm', 'key', 'data'],
            fo: ['data'],
        }, {
            input: {
                algorithm: {
                    ref: true,
                },
                key: {
                    ref: true,
                },
                data: {
                    ref: true,
                },
            },
            output: {
                signature: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_ENCRYPT);
    }
    async f({ key, algorithm, data }, done, fail) {
        const { api: { crypto: { sign }, }, } = this.__system;
        const key_ = (await key.raw());
        const algorithm_ = (await algorithm.raw());
        const data_ = (await data.raw());
        let _signature;
        try {
            _signature = (await sign(algorithm_, key_, data_));
        }
        catch (err) {
            fail(err.message.toLowerCase());
            return;
        }
        const signature = (0, ArrayBuffer_1.wrapArrayBuffer)(_signature, this.__system);
        done({ signature });
    }
}
exports.default = Sign;
//# sourceMappingURL=index.js.map