aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-06-08 07:03:14 +0800
committerJacob Evans <jacob@dekz.net>2018-06-08 07:09:30 +0800
commita8d328bfc926a62d61830334fadc43fc5d013e0e (patch)
treed07cc75b63623a5a795b74c02b52d56edf392e90 /packages/contracts
parenta59e9f024e76122c76600d938b565ea47938b287 (diff)
downloaddexon-sol-tools-a8d328bfc926a62d61830334fadc43fc5d013e0e.tar.gz
dexon-sol-tools-a8d328bfc926a62d61830334fadc43fc5d013e0e.tar.zst
dexon-sol-tools-a8d328bfc926a62d61830334fadc43fc5d013e0e.zip
Basic EIP712 encoder
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/utils/transaction_factory.ts21
1 files changed, 11 insertions, 10 deletions
diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts
index 7aaf3691c..bb15a0309 100644
--- a/packages/contracts/src/utils/transaction_factory.ts
+++ b/packages/contracts/src/utils/transaction_factory.ts
@@ -26,21 +26,22 @@ export class TransactionFactory {
public newSignedTransaction(data: string, signatureType: SignatureType = SignatureType.EthSign): SignedTransaction {
const executeTransactionSchemaHashBuff = EIP712Utils.compileSchema(EIP712_EXECUTE_TRANSACTION_SCHEMA);
const salt = generatePseudoRandomSalt();
- const dataHash = crypto.solSHA3([ethUtil.toBuffer(data)]);
- const executeTransactionDataHash = crypto.solSHA3([
- executeTransactionSchemaHashBuff,
+ const signer = `0x${this._signerBuff.toString('hex')}`;
+ const executeTransactionData = {
salt,
- EIP712Utils.pad32Buffer(this._signerBuff),
- dataHash,
- ]);
- const txHash = EIP712Utils.createEIP712Message(executeTransactionDataHash, this._exchangeAddress);
+ signer,
+ data,
+ };
+ const executeTransactionHashBuff = EIP712Utils.structHash(
+ EIP712_EXECUTE_TRANSACTION_SCHEMA,
+ executeTransactionData,
+ );
+ const txHash = EIP712Utils.createEIP712Message(executeTransactionHashBuff, this._exchangeAddress);
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
const signedTx = {
exchangeAddress: this._exchangeAddress,
- salt,
- signer: `0x${this._signerBuff.toString('hex')}`,
- data,
signature: `0x${signature.toString('hex')}`,
+ ...executeTransactionData,
};
return signedTx;
}