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" }, diff --git a/src/Transaction.php b/src/Transaction.php index 33c6206..d684512 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; @@ -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', ''); @@ -336,6 +340,7 @@ public function hash($includeSignature=false) $txData[$key] = $data; } } + $this->txData = $rawTxData; } $serializedTx = $this->rlp->encode($txData)->toString('utf8'); 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',