"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MLDSAKeyPairIdentity = void 0;
const utils_1 = require("@streamr/utils");
const KeyPairIdentity_1 = require("./KeyPairIdentity");
const trackerless_network_1 = require("@streamr/trackerless-network");
const signingUtil = utils_1.SigningUtil.getInstance('ML_DSA_87');
/**
 * An identity that uses a quantum-resistant ML-DSA-87 key pair to sign messages.
 */
class MLDSAKeyPairIdentity extends KeyPairIdentity_1.KeyPairIdentity {
    assertValidKeyPair() {
        signingUtil.assertValidKeyPair(this.publicKey, this.privateKey);
    }
    // eslint-disable-next-line class-methods-use-this
    getSignatureType() {
        return trackerless_network_1.SignatureType.ML_DSA_87;
    }
    async createMessageSignature(payload) {
        return signingUtil.createSignature(payload, this.privateKey);
    }
    /** @internal */
    static fromConfig(config) {
        const keyPairConfig = KeyPairIdentity_1.KeyPairIdentity.getKeyPairFromConfig(config);
        if (!keyPairConfig.publicKey) {
            throw new Error(`ML-DSA identity requires a publicKey to be given in the config!`);
        }
        return new MLDSAKeyPairIdentity((0, utils_1.hexToBinary)(keyPairConfig.publicKey), (0, utils_1.hexToBinary)(keyPairConfig.privateKey));
    }
    static generate() {
        const keyPair = signingUtil.generateKeyPair();
        return new MLDSAKeyPairIdentity(keyPair.publicKey, keyPair.privateKey);
    }
}
exports.MLDSAKeyPairIdentity = MLDSAKeyPairIdentity;
//# sourceMappingURL=MLDSAKeyPairIdentity.js.map