"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const _ids_1 = require("../../../../_ids");
class Verify extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['opt', 'algorithm', 'key', 'signature', 'data'],
            o: ['valid'],
        }, {
            input: {
                algorithm: {
                    ref: true,
                },
                key: {
                    ref: true,
                },
                data: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_VERIFY);
    }
    async f({ key, algorithm, signature, data }, done) {
        const { api: { crypto: { verify }, }, } = this.__system;
        const key_ = (await key.raw());
        const algorithm_ = (await algorithm.raw());
        const data_ = (await data.raw());
        const signature_ = (await signature.raw());
        let valid;
        try {
            valid = await verify(algorithm_, key_, signature_, data_);
        }
        catch (err) {
            done(undefined, err.message.toLowerCase());
            return;
        }
        done({ valid });
    }
}
exports.default = Verify;
//# sourceMappingURL=index.js.map