"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockEcdsaSigner = void 0;
const elliptic = __importStar(require("elliptic"));
class MockEcdsaSigner {
    // eslint-disable-next-line @typescript-eslint/no-empty-function
    constructor() { }
    static defaultAccount() {
        return this.fromPrivateKey(this.DEFAULT_ACCOUNT);
    }
    static fromPrivateKey(privateKey) {
        const signer = new MockEcdsaSigner();
        const privateKeyObject = this.ec.keyFromPrivate(privateKey, 'hex');
        signer.setKeyPair(privateKeyObject);
        signer.publicKey = Buffer.from(privateKeyObject.getPublic().encode('hex', true), 'hex');
        return signer;
    }
    static newAccount() {
        const kp = this.ec.genKeyPair();
        return this.fromPrivateKey(kp.getPrivate().toString('hex'));
    }
    setKeyPair(keyPair) {
        this.keyPair = keyPair;
    }
    getPublicKey() {
        return this.publicKey;
    }
    async sign(hash) {
        const { r, s, recoveryParam } = await this.keyPair.sign(hash, { canonical: true });
        const valid = await MockEcdsaSigner.ec.verify(hash, { r, s }, this.publicKey);
        if (!valid) {
            throw new Error('Invalid signature');
        }
        return Promise.resolve({
            r: `0x${r.toString('hex')}`,
            s: `0x${s.toString('hex')}`,
            recid: recoveryParam,
        });
    }
    async getPublicKeyAsync() {
        return Promise.resolve(this.publicKey);
    }
}
exports.MockEcdsaSigner = MockEcdsaSigner;
MockEcdsaSigner.DEFAULT_ACCOUNT = '569405dde106c67d8a36191827f5fa3705461ba8d44c0774cee910b529e3e6d3';
MockEcdsaSigner.ec = new elliptic.ec('secp256k1');
