"use strict";
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const create_1 = require("../../../codec/create");
const constants_1 = require("../constants");
const ExtrinsicSignature_1 = __importDefault(require("../v2/ExtrinsicSignature"));
const ExtrinsicPayload_1 = __importDefault(require("./ExtrinsicPayload"));
/**
 * @name GenericExtrinsicSignatureV3
 * @description
 * A container for the [[Signature]] associated with a specific [[Extrinsic]]
 */
class ExtrinsicSignatureV3 extends ExtrinsicSignature_1.default {
    /**
     * @description Adds a raw signature
     */
    addSignature(signer, signature, payload) {
        return this.injectSignature(create_1.createType(this.registry, 'Address', signer), create_1.createType(this.registry, 'Signature', signature), new ExtrinsicPayload_1.default(this.registry, payload));
    }
    /**
     * @description Creates a payload from the supplied options
     */
    createPayload(method, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion }, tip }) {
        return new ExtrinsicPayload_1.default(this.registry, {
            blockHash,
            era: era || constants_1.IMMORTAL_ERA,
            genesisHash,
            method: method.toHex(),
            nonce,
            specVersion,
            tip: tip || 0
        });
    }
    /**
     * @description Generate a payload and applies the signature from a keypair
     */
    sign(method, account, options) {
        const signer = create_1.createType(this.registry, 'Address', account.publicKey);
        const payload = this.createPayload(method, options);
        const signature = create_1.createType(this.registry, 'Signature', payload.sign(account));
        return this.injectSignature(signer, signature, payload);
    }
    /**
     * @description Generate a payload and applies a fake signature
     */
    signFake(method, address, options) {
        const signer = create_1.createType(this.registry, 'Address', address);
        const payload = this.createPayload(method, options);
        const signature = create_1.createType(this.registry, 'Signature', new Uint8Array(64).fill(0x42));
        return this.injectSignature(signer, signature, payload);
    }
}
exports.default = ExtrinsicSignatureV3;
