Renamed approval factory
This commit is contained in:
parent
c97c6d1fc2
commit
f560e7fa96
40
contracts/staking/test/utils/approval_factory.ts
Normal file
40
contracts/staking/test/utils/approval_factory.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user