import ChallengeRegistry from "@counterfactual/cf-adjudicator-contracts/expected-build-artifacts/ChallengeRegistry.json" ; import { AppIdentity , NetworkContext , Node , SignedStateHashUpdate } from "@counterfactual/types" ; import { Interface , joinSignature , keccak256 , Signature , solidityPack } from "ethers/utils" ; import { sortSignaturesBySignerAddress } from "../utils" ; import { EthereumCommitment } from "./types" ; import { appIdentityToHash } from "./utils/app-identity" ; const iface = new Interface ( ChallengeRegistry . abi ) ; export class SetStateCommitment extends EthereumCommitment { constructor ( public readonly networkContext , public readonly appIdentity , public readonly hashedAppState , public readonly appVersionNumber , public readonly timeout ) { super ( ) ; } public hashToSign ( ) { return keccak256 ( solidityPack ( [ "bytes1" , "bytes32" , "uint256" , "uint256" , "bytes32" ] , [ "0x19" , appIdentityToHash ( this . appIdentity ) , this . appVersionNumber , this . timeout , this . hashedAppState ] ) ) ; } public getSignedTransaction ( sigs ) { return { to : this . networkContext . ChallengeRegistry , value : 0 , data : iface . functions . setState . encode ( [ this . appIdentity , this . getSignedStateHashUpdate ( sigs ) ] ) } ; } private getSignedStateHashUpdate ( signatures ) { return { appStateHash : this . hashedAppState , versionNumber : this . appVersionNumber , timeout : this . timeout , signatures : sortSignaturesBySignerAddress ( this . hashToSign ( ) , signatures ) . map ( joinSignature ) } ; } }