Renamed approval factory

This commit is contained in:
Greg Hysen 2019-06-27 09:15:17 -07:00
parent c97c6d1fc2
commit f560e7fa96

View 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;
}
}