aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-24 01:08:06 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-31 08:11:30 +0800
commite5b7e29113fb7c87f41e492abb1fd81247f0db46 (patch)
treebf51ba5949b1aa697d071780bf792445c153ea9f /packages/contracts/src
parentecdd0ce9f2378a1ac271b9eb5661a6d37d6edf41 (diff)
downloaddexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar.gz
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar.bz2
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar.lz
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar.xz
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.tar.zst
dexon-sol-tools-e5b7e29113fb7c87f41e492abb1fd81247f0db46.zip
Add signer to txHash, allow approveValidator to be used with executeTransaction
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol7
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol1
-rw-r--r--packages/contracts/src/utils/transaction_factory.ts9
3 files changed, 10 insertions, 7 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index 8ef961a81..e2d4808c3 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -19,6 +19,7 @@
pragma solidity ^0.4.24;
import "./mixins/MSignatureValidator.sol";
+import "./mixins/MTransactions.sol";
import "./interfaces/ISigner.sol";
import "./interfaces/IValidator.sol";
import "./libs/LibExchangeErrors.sol";
@@ -27,7 +28,8 @@ import "../../utils/LibBytes/LibBytes.sol";
contract MixinSignatureValidator is
LibBytes,
LibExchangeErrors,
- MSignatureValidator
+ MSignatureValidator,
+ MTransactions
{
// Mapping of hash => signer => signed
@@ -63,7 +65,8 @@ contract MixinSignatureValidator is
)
external
{
- allowedValidators[msg.sender][validator] = approval;
+ address signer = getCurrentContextAddress();
+ allowedValidators[signer][validator] = approval;
}
/// @dev Verifies that a hash has been signed by the given signer.
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
index 12bba1ef2..d153dfa5c 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinTransactions.sol
@@ -56,6 +56,7 @@ contract MixinTransactions is
// Calculate transaction hash
bytes32 transactionHash = keccak256(
address(this),
+ signer,
salt,
data
);
diff --git a/packages/contracts/src/utils/transaction_factory.ts b/packages/contracts/src/utils/transaction_factory.ts
index 941bff96d..65cdb3f89 100644
--- a/packages/contracts/src/utils/transaction_factory.ts
+++ b/packages/contracts/src/utils/transaction_factory.ts
@@ -7,26 +7,25 @@ import { signingUtils } from './signing_utils';
import { SignatureType, SignedTransaction } from './types';
export class TransactionFactory {
- private _signer: string;
+ private _signerBuff: Buffer;
private _exchangeAddress: string;
private _privateKey: Buffer;
constructor(privateKey: Buffer, exchangeAddress: string) {
this._privateKey = privateKey;
this._exchangeAddress = exchangeAddress;
- const signerBuff = ethUtil.privateToAddress(this._privateKey);
- this._signer = `0x${signerBuff.toString('hex')}`;
+ this._signerBuff = ethUtil.privateToAddress(this._privateKey);
}
public newSignedTransaction(
data: string,
signatureType: SignatureType = SignatureType.Ecrecover,
): SignedTransaction {
const salt = generatePseudoRandomSalt();
- const txHash = crypto.solSHA3([this._exchangeAddress, salt, ethUtil.toBuffer(data)]);
+ const txHash = crypto.solSHA3([this._exchangeAddress, this._signerBuff, salt, ethUtil.toBuffer(data)]);
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
const signedTx = {
exchangeAddress: this._exchangeAddress,
salt,
- signer: this._signer,
+ signer: `0x${this._signerBuff.toString('hex')}`,
data,
signature: `0x${signature.toString('hex')}`,
};