"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const KeyProps_1 = require("./KeyProps");
const sdk_1 = require("@hiero-ledger/sdk");
const PublicKey_1 = __importDefault(require("./PublicKey"));
class PrivateKey {
    key;
    type;
    publicKey;
    constructor(props) {
        const { key, type } = props;
        this.type = this.validateType(type);
        this.key = key;
        this.publicKey = PublicKey_1.default.fromHederaKey(this.toHashgraphKey().publicKey);
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    static validate(val) {
        const err = [];
        return err;
    }
    toString() {
        return JSON.stringify({
            key: this.key,
            type: this.type,
        });
    }
    validateType(type) {
        if (type && Object.keys(KeyProps_1.KeyType).includes(type)) {
            return Object.entries(KeyProps_1.KeyType).filter(([key]) => key === type)[0][1];
        }
        return KeyProps_1.KeyType.NULL;
    }
    toHashgraphKey() {
        //try {
        return this.type === KeyProps_1.KeyType.ED25519
            ? sdk_1.PrivateKey.fromStringED25519(this.key)
            : sdk_1.PrivateKey.fromStringECDSA(this.key);
        //} catch (error) {
        //	console.log(error);
        //	throw new PrivateKeyNotValid(this.key);
        //}
    }
}
exports.default = PrivateKey;
