From f560e7fa963b97d91c29777750aa77c782af3ab9 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 27 Jun 2019 09:15:17 -0700 Subject: [PATCH] Renamed approval factory --- .../staking/test/utils/approval_factory.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 contracts/staking/test/utils/approval_factory.ts diff --git a/contracts/staking/test/utils/approval_factory.ts b/contracts/staking/test/utils/approval_factory.ts new file mode 100644 index 0000000000..a1837a1d9d --- /dev/null +++ b/contracts/staking/test/utils/approval_factory.ts @@ -0,0 +1,40 @@ +import { signingUtils } from '@0x/contracts-test-utils'; +import { SignatureType } from '@0x/types'; +import * as ethUtil from 'ethereumjs-util'; + +import { hashUtils } from './hash_utils'; +import { SignedStakingPoolApproval } from './types'; + +export class ApprovalFactory { + private readonly _privateKey: Buffer; + private readonly _verifyingContractAddress: string; + private readonly _chainId: number; + + constructor(privateKey: Buffer, verifyingContractAddress: string, chainId: number) { + this._privateKey = privateKey; + this._verifyingContractAddress = verifyingContractAddress; + this._chainId = chainId; + } + + public newSignedApproval( + poolId: string, + makerAddress: string, + signatureType: SignatureType = SignatureType.EthSign, + ): SignedStakingPoolApproval { + const approvalHashBuff = hashUtils.getStakingPoolApprovalHashBuffer( + poolId, + makerAddress, + this._verifyingContractAddress, + this._chainId, + ); + const signatureBuff = signingUtils.signMessage(approvalHashBuff, this._privateKey, signatureType); + const signedApproval = { + makerAddress, + poolId, + verifyingContractAddress: this._verifyingContractAddress, + chainId: this._chainId, + signature: ethUtil.addHexPrefix(signatureBuff.toString('hex')), + }; + return signedApproval; + } +}