"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const enums_1 = require("../../../enums");
const utils_1 = require("../../../utils");
const utils_2 = require("../../../utils");
const schemas = __importStar(require("../schemas"));
const transaction_1 = require("../transaction");
class MultiSignatureRegistrationTransaction extends transaction_1.Transaction {
    static getSchema() {
        return schemas.multiSignatureLegacy;
    }
    static staticFee(feeContext = {}) {
        if (feeContext.data?.asset?.multiSignatureLegacy) {
            return super.staticFee(feeContext).times(feeContext.data.asset.multiSignatureLegacy.keysgroup.length + 1);
        }
        return super.staticFee(feeContext);
    }
    verify() {
        return utils_1.isException(this.data);
    }
    serialize(options) {
        const { data } = this;
        const legacyAsset = data.asset.multiSignatureLegacy;
        const joined = legacyAsset.keysgroup.map((k) => (k.startsWith("+") ? k.slice(1) : k)).join("");
        const keysgroupBuffer = Buffer.from(joined, "hex");
        const buff = new utils_2.ByteBuffer(Buffer.alloc(keysgroupBuffer.length + 3));
        buff.writeUInt8(legacyAsset.min);
        buff.writeUInt8(legacyAsset.keysgroup.length);
        buff.writeUInt8(legacyAsset.lifetime);
        buff.writeBuffer(keysgroupBuffer);
        return buff;
    }
    deserialize(buf) {
        const { data } = this;
        const multiSignatureLegacy = { keysgroup: [], lifetime: 0, min: 0 };
        multiSignatureLegacy.min = buf.readUInt8();
        const num = buf.readUInt8();
        multiSignatureLegacy.lifetime = buf.readUInt8();
        for (let index = 0; index < num; index++) {
            const key = buf.readBuffer(33).toString("hex");
            multiSignatureLegacy.keysgroup.push(key);
        }
        data.asset = { multiSignatureLegacy };
    }
}
exports.MultiSignatureRegistrationTransaction = MultiSignatureRegistrationTransaction;
MultiSignatureRegistrationTransaction.typeGroup = enums_1.TransactionTypeGroup.Core;
MultiSignatureRegistrationTransaction.type = enums_1.TransactionType.MultiSignature;
MultiSignatureRegistrationTransaction.key = "multiSignature";
MultiSignatureRegistrationTransaction.version = 1;
MultiSignatureRegistrationTransaction.defaultStaticFee = utils_2.BigNumber.make("500000000");
//# sourceMappingURL=multi-signature-registration.js.map