/** *** Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. *** Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie. *** All rights reserved. *** *** This file is part of Catapult. *** *** Catapult is free software: you can redistribute it and/or modify *** it under the terms of the GNU Lesser General Public License as published by *** the Free Software Foundation, either version 3 of the License, or *** (at your option) any later version. *** *** Catapult is distributed in the hope that it will be useful, *** but WITHOUT ANY WARRANTY; without even the implied warranty of *** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *** GNU Lesser General Public License for more details. *** *** You should have received a copy of the GNU Lesser General Public License *** along with Catapult. If not, see . **/ import { CosignatureBuilder } from './CosignatureBuilder'; import { GeneratorUtils } from './GeneratorUtils'; import { Hash256Dto } from './Hash256Dto'; import { PublicKeyDto } from './PublicKeyDto'; import { Serializer } from './Serializer'; import { SignatureDto } from './SignatureDto'; /** * Cosignature detached from an AggregateCompleteTransaction or AggregateBondedTransaction. **/ export class DetachedCosignatureBuilder extends CosignatureBuilder implements Serializer { /** Hash of the AggregateBondedTransaction that is signed by this cosignature.. **/ readonly parentHash: Hash256Dto; /** * Constructor. * * @param version Version.. * @param signerPublicKey Cosigner public key.. * @param signature Transaction signature.. * @param parentHash Hash of the AggregateBondedTransaction that is signed by this cosignature.. */ public constructor(version: number[], signerPublicKey: PublicKeyDto, signature: SignatureDto, parentHash: Hash256Dto) { super(version, signerPublicKey, signature); GeneratorUtils.notNull(parentHash, 'parentHash is null or undefined'); this.parentHash = parentHash; } /** * Load from binary array - Creates an object from payload. * * @param payload - Byte payload to use to serialize the object. */ public static loadFromBinary(payload: Uint8Array): DetachedCosignatureBuilder { const byteArray = Array.from(payload); const superObject = CosignatureBuilder.loadFromBinary(payload); byteArray.splice(0, superObject.getSize()); const parentHash: Hash256Dto = Hash256Dto.loadFromBinary(Uint8Array.from(byteArray)); byteArray.splice(0, parentHash.getSize()); return new DetachedCosignatureBuilder(superObject.version, superObject.signerPublicKey, superObject.signature, parentHash); } /** * Creates an instance of DetachedCosignatureBuilder. * * @param version Version.. * @param signerPublicKey Cosigner public key.. * @param signature Transaction signature.. * @param parentHash Hash of the AggregateBondedTransaction that is signed by this cosignature.. * @return Instance of DetachedCosignatureBuilder. */ public static createDetachedCosignatureBuilder( version: number[], signerPublicKey: PublicKeyDto, signature: SignatureDto, parentHash: Hash256Dto, ): DetachedCosignatureBuilder { return new DetachedCosignatureBuilder(version, signerPublicKey, signature, parentHash); } /** * Gets Hash of the AggregateBondedTransaction that is signed by this cosignature.. * * @return Hash of the AggregateBondedTransaction that is signed by this cosignature.. */ public getParentHash(): Hash256Dto { return this.parentHash; } /** * Gets the size of the object. * * @return Size in bytes. */ public getSize(): number { let size = super.getSize(); size += this.parentHash.getSize(); // parentHash return size; } /** * Serializes an object to bytes. * * @return Serialized bytes. */ public serialize(): Uint8Array { let newArray = Uint8Array.from([]); const superBytes = super.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes); const parentHashBytes = this.parentHash.serialize(); newArray = GeneratorUtils.concatTypedArrays(newArray, parentHashBytes); return newArray; } }