Skip to content

Commit

Permalink
Merge pull request #9 from sc0Vu/master
Browse files Browse the repository at this point in the history
Add EIP155 signing data test
  • Loading branch information
sc0Vu committed Jun 2, 2018
2 parents 063108a + 471affb commit 5f431ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require-dev": {
"phpunit/phpunit": "^6.1"
},
Expand Down
7 changes: 6 additions & 1 deletion src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ public function sign(string $privateKey)
{
$txHash = $this->hash(false);
$privateKey = $this->secp256k1->keyFromPrivate($privateKey, 'hex');
$signature = $privateKey->sign($txHash);
$signature = $privateKey->sign($txHash, [
'canonical' => true
]);
$r = $signature->r;
$s = $signature->s;
$v = $signature->recoveryParam + 35;
Expand Down Expand Up @@ -321,6 +323,8 @@ public function hash($includeSignature=false)
if ($includeSignature) {
$txData = $this->txData;
} else {
$rawTxData = $this->txData;

if ($chainId && $chainId > 0) {
$v = (int) $chainId;
$this->offsetSet('r', '');
Expand All @@ -336,6 +340,7 @@ public function hash($includeSignature=false)
$txData[$key] = $data;
}
}
$this->txData = $rawTxData;
}
$serializedTx = $this->rlp->encode($txData)->toString('utf8');

Expand Down
15 changes: 15 additions & 0 deletions test/unit/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ public function testSerialize()
*/
public function testEIP155()
{
// test signing data
$transaction = new Transaction([
'nonce' => '0x09',
'to' => '0x3535353535353535353535353535353535353535',
'gas' => '0x5208',
'gasPrice' => '0x4a817c800',
'value' => '0xde0b6b3a7640000',
'chainId' => 1,
'data' => ''
]);
$transaction['r'] = '';
$transaction['s'] = '';
$transaction['v'] = 1;
$this->assertEquals('ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080', $transaction->serialize()->toString('hex'));

$transaction = new Transaction([
'nonce' => '0x09',
'to' => '0x3535353535353535353535353535353535353535',
Expand Down

0 comments on commit 5f431ba

Please sign in to comment.