Add signature validator tests

This commit is contained in:
Amir Bandeali
2019-02-13 14:13:32 -08:00
parent 99aeaddf42
commit bebcd99b3b
12 changed files with 174 additions and 80 deletions

View File

@@ -1 +1,3 @@
export { approvalHashUtils } from './approval_hash';
export { TECTransactionFactory } from './tec_transaction_factory';
export * from './types';

View File

@@ -0,0 +1,31 @@
import { TransactionFactory } from '@0x/contracts-test-utils';
import { SignatureType, SignedZeroExTransaction } from '@0x/types';
import * as ethUtil from 'ethereumjs-util';
import { TECSignatureType } from './types';
export class TECTransactionFactory extends TransactionFactory {
constructor(privateKey: Buffer, exchangeAddress: string) {
super(privateKey, exchangeAddress);
}
public newSignedTECTransaction(
data: string,
signatureType: TECSignatureType = TECSignatureType.EthSign,
): SignedZeroExTransaction {
let exchangeSignatureType;
if (signatureType === TECSignatureType.EthSign) {
exchangeSignatureType = SignatureType.EthSign;
} else if (signatureType === TECSignatureType.EIP712) {
exchangeSignatureType = SignatureType.EIP712;
} else {
throw new Error(`Error: ${signatureType} not a valid signature type`);
}
const signedTransaction = super.newSignedTransaction(data, exchangeSignatureType);
const tecSignatureTypeByte = ethUtil.toBuffer(signatureType).toString('hex');
signedTransaction.signature = `${signedTransaction.signature.slice(
0,
signedTransaction.signature.length - 2,
)}${tecSignatureTypeByte}`;
return signedTransaction;
}
}

View File

@@ -5,3 +5,10 @@ export interface TECApproval {
transactionSignature: string;
approvalExpirationTimeSeconds: BigNumber;
}
export enum TECSignatureType {
Illegal,
EIP712,
EthSign,
NSignatureTypes,
}