From 65daf89d5af4155dcc20d18919f8ebd45631bd9d Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Fri, 25 May 2018 15:17:07 +0800 Subject: [PATCH 1/4] Add EIP155 signing data test --- test/unit/TransactionTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/unit/TransactionTest.php b/test/unit/TransactionTest.php index 57d7382..d0e80be 100644 --- a/test/unit/TransactionTest.php +++ b/test/unit/TransactionTest.php @@ -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', From 3900aa775187f6db83e9f6730fb25837121df882 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 30 May 2018 16:04:39 +0800 Subject: [PATCH 2/4] Remove minimum-stability:dev --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index b28110e..f47b1c8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,6 @@ "email": "alk03073135@gmail.com" } ], - "minimum-stability": "dev", "require-dev": { "phpunit/phpunit": "^6.1" }, From e123ccbf2197dee517f8ad63b0495dd9c52edcc4 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sat, 2 Jun 2018 14:47:31 +0800 Subject: [PATCH 3/4] Set options canonical is true --- src/Transaction.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Transaction.php b/src/Transaction.php index 33c6206..48bda9d 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -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; From 471affb19ecac5d5e989ad959b001402bfba2acb Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Sat, 2 Jun 2018 22:17:34 +0800 Subject: [PATCH 4/4] Fix sign method --- src/Transaction.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Transaction.php b/src/Transaction.php index 48bda9d..d684512 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -323,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', ''); @@ -338,6 +340,7 @@ public function hash($includeSignature=false) $txData[$key] = $data; } } + $this->txData = $rawTxData; } $serializedTx = $this->rlp->encode($txData)->toString('utf8');