"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const kyber_1 = require("@dedis/kyber");
const crypto_browserify_1 = require("crypto-browserify");
const identity_ed25519_1 = tslib_1.__importDefault(require("./identity-ed25519"));
const ed25519 = kyber_1.curve.newCurve("edwards25519");
const { schnorr } = kyber_1.sign;
class SignerEd25519 extends identity_ed25519_1.default {
    constructor(pub, priv) {
        super({ point: pub.toProto() });
        this.priv = priv;
    }
    get secret() {
        return this.priv;
    }
    /**
     * Create a Ed25519 signer from the private given as a buffer
     *
     * @param bytes the private key
     * @returns the new signer
     */
    static fromBytes(bytes) {
        const priv = ed25519.scalar();
        priv.unmarshalBinary(bytes);
        return new SignerEd25519(ed25519.point().base().mul(priv), priv);
    }
    static random() {
        const priv = ed25519.scalar().setBytes(crypto_browserify_1.randomBytes(32));
        const pub = ed25519.point().mul(priv);
        return new SignerEd25519(pub, priv);
    }
    /** @inheritdoc */
    sign(msg) {
        return schnorr.sign(ed25519, this.priv, msg);
    }
}
exports.default = SignerEd25519;
