"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");
/**
 * An identity that uses a quantum-resistant ML-DSA-87 key pair to sign messages.
 */
class MLDSAKeyPairIdentity extends KeyPairIdentity_1.KeyPairIdentity {
    assertKeyPairIsValid() {
        // Validity of key pair is tested by signing and validating something
        const payload = Buffer.from('data-to-sign');
        const signature = utils_1.ML_DSA_87.createSignature(payload, this.privateKey);
        if (!utils_1.ML_DSA_87.verifySignature(this.publicKey, payload, signature)) {
            throw new Error(`The given publicKey and privateKey don't match!`);
        }
    }
    // eslint-disable-next-line class-methods-use-this
    getSignatureType() {
        return trackerless_network_1.SignatureType.ML_DSA_87;
    }
    // eslint-disable-next-line class-methods-use-this
    getExpectedPublicKeyLength() {
        return 2592;
    }
    // eslint-disable-next-line class-methods-use-this
    getExpectedPrivateKeyLength() {
        return 4896;
    }
    async createMessageSignature(payload) {
        return utils_1.ML_DSA_87.createSignature(payload, this.privateKey);
    }
    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 = utils_1.ML_DSA_87.generateKeyPair();
        return new MLDSAKeyPairIdentity(keyPair.publicKey, keyPair.privateKey);
    }
}
exports.MLDSAKeyPairIdentity = MLDSAKeyPairIdentity;
//# sourceMappingURL=MLDSAKeyPairIdentity.js.map