From ec17971757f50c72fe9aef72df7f0906520ffb8d Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 20 Mar 2018 11:52:07 +0800 Subject: [PATCH 1/3] Rename travis config name. --- .travis.yaml => .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .travis.yaml => .travis.yml (100%) diff --git a/.travis.yaml b/.travis.yml similarity index 100% rename from .travis.yaml rename to .travis.yml From 248dd7548bc2b94b523f82098d7c263a8da8409b Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 20 Mar 2018 13:48:53 +0800 Subject: [PATCH 2/3] Change namespace and packages version. --- composer.json | 10 ++-- composer.lock | 88 +++++++++++++++++------------------ src/Transaction.php | 10 ++-- test/TestCase.php | 4 +- test/unit/TransactionTest.php | 2 +- 5 files changed, 55 insertions(+), 59 deletions(-) diff --git a/composer.json b/composer.json index 3ce15dc..f95de58 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ ], "minimum-stability": "dev", "require-dev": { - "phpunit/phpunit": "~6.0" + "phpunit/phpunit": "^6.1" }, "autoload": { "psr-4": { - "EthereumTx\\": "src/" + "Web3p\\EthereumTx\\": "src/" } }, "autoload-dev": { @@ -24,8 +24,8 @@ } }, "require": { - "web3p/rlp": "dev-master", - "web3p/secp256k1": "dev-master", - "kornrunner/keccak": "dev-master" + "web3p/rlp": "~0.2", + "web3p/secp256k1": "~0.2", + "kornrunner/keccak": "~1" } } diff --git a/composer.lock b/composer.lock index f3742b6..b51bca3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "df26fe6f6503a7a7b81051f13ed25810", + "content-hash": "d49eae17ce62b9584285247e680e8e4a", "packages": [ { "name": "fgrosse/phpasn1", @@ -77,7 +77,7 @@ }, { "name": "kornrunner/keccak", - "version": "dev-master", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/kornrunner/php-keccak.git", @@ -117,7 +117,7 @@ "keccak", "sha-3" ], - "time": "2018-03-05 10:32:01" + "time": "2018-03-05T10:32:01+00:00" }, { "name": "mdanter/ecc", @@ -193,16 +193,16 @@ }, { "name": "web3p/rlp", - "version": "dev-master", + "version": "v0.2", "source": { "type": "git", "url": "https://github.com/web3p/rlp.git", - "reference": "c4b0e84d3c96d4e920b7f627cb33d945b0d5e281" + "reference": "7cd33e17735515ab7d86a659406c325660b37840" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web3p/rlp/zipball/c4b0e84d3c96d4e920b7f627cb33d945b0d5e281", - "reference": "c4b0e84d3c96d4e920b7f627cb33d945b0d5e281", + "url": "https://api.github.com/repos/web3p/rlp/zipball/7cd33e17735515ab7d86a659406c325660b37840", + "reference": "7cd33e17735515ab7d86a659406c325660b37840", "shasum": "" }, "require-dev": { @@ -211,7 +211,7 @@ "type": "library", "autoload": { "psr-4": { - "RLP\\": "src/" + "Web3p\\RLP\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -225,20 +225,20 @@ } ], "description": "Recursive Length Prefix Encoding in PHP.", - "time": "2018-03-08 09:24:09" + "time": "2018-03-19T15:21:29+00:00" }, { "name": "web3p/secp256k1", - "version": "dev-master", + "version": "v0.2", "source": { "type": "git", "url": "https://github.com/web3p/secp256k1.git", - "reference": "c31138e694eb84199b16d2f91494e07e34a752af" + "reference": "f63f4e88de662311f114b510a1c17a460e20dbf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/web3p/secp256k1/zipball/c31138e694eb84199b16d2f91494e07e34a752af", - "reference": "c31138e694eb84199b16d2f91494e07e34a752af", + "url": "https://api.github.com/repos/web3p/secp256k1/zipball/f63f4e88de662311f114b510a1c17a460e20dbf2", + "reference": "f63f4e88de662311f114b510a1c17a460e20dbf2", "shasum": "" }, "require": { @@ -250,7 +250,7 @@ "type": "library", "autoload": { "psr-4": { - "Secp256k1\\": "src/" + "Web3p\\Secp256k1\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -264,7 +264,7 @@ } ], "description": "Ethereum secp256k1 library in PHP.", - "time": "2018-02-25 13:59:35" + "time": "2018-03-20T02:37:13+00:00" } ], "packages-dev": [ @@ -321,7 +321,7 @@ "constructor", "instantiate" ], - "time": "2018-03-05T09:41:42+00:00" + "time": "2018-03-05 09:41:42" }, { "name": "myclabs/deep-copy", @@ -371,7 +371,7 @@ "object", "object graph" ], - "time": "2017-12-18T00:20:24+00:00" + "time": "2017-12-18 00:20:24" }, { "name": "phar-io/manifest", @@ -426,7 +426,7 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-04-07T07:07:10+00:00" + "time": "2017-04-07 07:07:10" }, { "name": "phar-io/version", @@ -527,7 +527,7 @@ "reflection", "static analysis" ], - "time": "2018-02-14T18:58:54+00:00" + "time": "2018-02-14 18:58:54" }, { "name": "phpdocumentor/reflection-docblock", @@ -574,7 +574,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2018-02-14T19:00:58+00:00" + "time": "2018-02-14 19:00:58" }, { "name": "phpdocumentor/type-resolver", @@ -619,7 +619,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2018-02-14T18:59:20+00:00" + "time": "2018-02-14 18:59:20" }, { "name": "phpspec/prophecy", @@ -682,7 +682,7 @@ "spy", "stub" ], - "time": "2018-02-19T10:16:54+00:00" + "time": "2018-02-19 10:16:54" }, { "name": "phpunit/php-code-coverage", @@ -745,7 +745,7 @@ "testing", "xunit" ], - "time": "2017-12-07T10:13:30+00:00" + "time": "2017-12-07 10:13:30" }, { "name": "phpunit/php-file-iterator", @@ -792,7 +792,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "time": "2017-11-27 13:52:08" }, { "name": "phpunit/php-text-template", @@ -882,7 +882,7 @@ "keywords": [ "timer" ], - "time": "2018-01-06T05:27:16+00:00" + "time": "2018-01-06 05:27:16" }, { "name": "phpunit/php-token-stream", @@ -931,7 +931,7 @@ "keywords": [ "tokenizer" ], - "time": "2017-11-27T08:47:38+00:00" + "time": "2017-11-27 08:47:38" }, { "name": "phpunit/phpunit", @@ -939,12 +939,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "6bd77b57707c236833d2b57b968e403df060c9d9" + "reference": "ea739aae4742aa4eae1e98d4d06acdbf01692415" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6bd77b57707c236833d2b57b968e403df060c9d9", - "reference": "6bd77b57707c236833d2b57b968e403df060c9d9", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ea739aae4742aa4eae1e98d4d06acdbf01692415", + "reference": "ea739aae4742aa4eae1e98d4d06acdbf01692415", "shasum": "" }, "require": { @@ -1015,7 +1015,7 @@ "testing", "xunit" ], - "time": "2018-02-26T07:01:09+00:00" + "time": "2018-03-15T16:51:04+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -1074,7 +1074,7 @@ "mock", "xunit" ], - "time": "2018-01-07T17:10:51+00:00" + "time": "2018-01-07 17:10:51" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1119,7 +1119,7 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T10:23:55+00:00" + "time": "2017-03-04 10:23:55" }, { "name": "sebastian/comparator", @@ -1183,7 +1183,7 @@ "compare", "equality" ], - "time": "2018-02-01T13:46:46+00:00" + "time": "2018-02-01 13:46:46" }, { "name": "sebastian/diff", @@ -1235,7 +1235,7 @@ "keywords": [ "diff" ], - "time": "2017-12-14T11:32:19+00:00" + "time": "2017-12-14 11:32:19" }, { "name": "sebastian/environment", @@ -1352,7 +1352,7 @@ "export", "exporter" ], - "time": "2017-11-16T09:48:09+00:00" + "time": "2017-11-16 09:48:09" }, { "name": "sebastian/global-state", @@ -1403,7 +1403,7 @@ "keywords": [ "global state" ], - "time": "2017-11-16T09:49:42+00:00" + "time": "2017-11-16 09:49:42" }, { "name": "sebastian/object-enumerator", @@ -1450,7 +1450,7 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-11-16T09:50:04+00:00" + "time": "2017-11-16 09:50:04" }, { "name": "sebastian/object-reflector", @@ -1495,7 +1495,7 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2018-01-07T16:00:13+00:00" + "time": "2018-01-07 16:00:13" }, { "name": "sebastian/recursion-context", @@ -1548,7 +1548,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-11-16T10:04:08+00:00" + "time": "2017-11-16 10:04:08" }, { "name": "sebastian/resource-operations", @@ -1590,7 +1590,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2016-10-03T07:43:09+00:00" + "time": "2016-10-03 07:43:09" }, { "name": "sebastian/version", @@ -1723,16 +1723,12 @@ "check", "validate" ], - "time": "2018-01-29T19:49:41+00:00" + "time": "2018-01-29 19:49:41" } ], "aliases": [], "minimum-stability": "dev", - "stability-flags": { - "web3p/rlp": 20, - "web3p/secp256k1": 20, - "kornrunner/keccak": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/src/Transaction.php b/src/Transaction.php index a3c922b..bd1f613 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -9,13 +9,13 @@ * @license MIT */ -namespace EthereumTx; +namespace Web3p\EthereumTx; use InvalidArgumentException; use RuntimeException; use kornrunner\Keccak; -use RLP\RLP; -use Secp256k1\Secp256k1; +use Web3p\RLP\RLP; +use Web3p\Secp256k1\Secp256k1; use ArrayAccess; class Transaction implements ArrayAccess @@ -57,14 +57,14 @@ class Transaction implements ArrayAccess /** * rlp * - * @var \RLP\RLP + * @var \Web3p\RLP\RLP */ protected $rlp; /** * secp256k1 * - * @var \Secp256k1\Secp256k1 + * @var \Web3p\Secp256k1\Secp256k1 */ protected $secp256k1; diff --git a/test/TestCase.php b/test/TestCase.php index b8b9fcc..d1acdac 100644 --- a/test/TestCase.php +++ b/test/TestCase.php @@ -3,14 +3,14 @@ namespace Test; use \PHPUnit\Framework\TestCase as BaseTestCase; -use RLP\RLP; +use Web3p\RLP\RLP; class TestCase extends BaseTestCase { /** * rlp * - * @var \RLP\RLP + * @var \Web3p\RLP\RLP */ protected $rlp; diff --git a/test/unit/TransactionTest.php b/test/unit/TransactionTest.php index 71df579..72eee74 100644 --- a/test/unit/TransactionTest.php +++ b/test/unit/TransactionTest.php @@ -3,7 +3,7 @@ namespace Test\Unit; use Test\TestCase; -use EthereumTx\Transaction; +use Web3p\EthereumTx\Transaction; class TransactionTest extends TestCase { From fd47d79440c42ddc0bed5f61787eb61cc1b28cdb Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 20 Mar 2018 15:08:58 +0800 Subject: [PATCH 3/3] README.md --- README.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f690af8..0f711fe 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,9 @@ composer require web3p/ethereum-tx Create a transaction: ```php -use EthereumTx\Transaction; +use Web3p\EthereumTx\Transaction; +// without chainId $transaction = new Transaction([ 'nonce' => '0x01', 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', @@ -25,18 +26,136 @@ $transaction = new Transaction([ 'value' => '0x9184e72a', 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' ]); + +// with chainId +$transaction = new Transaction([ + 'nonce' => '0x01', + 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + 'gas' => '0x76c0', + 'gasPrice' => '0x9184e72a000', + 'value' => '0x9184e72a', + 'chainId' => 1, + 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' +]); ``` Sign a transaction: ```php -use EthereumTx\Transaction; +use Web3p\EthereumTx\Transaction; $signedTransaction = $transaction->sign('your private key'); ``` # API -Todo. +### Web3p\EthereumTx\Transaction + +#### sha3 + +Returns keccak256 encoding of given data. + +> It will be removed in the next version. + +`sha3(string $input)` + +String input + +###### Example + +* Encode string. + +```php +use Web3p\EthereumTx\Transaction; + +$transaction = new Transaction([ + 'nonce' => '0x01', + 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + 'gas' => '0x76c0', + 'gasPrice' => '0x9184e72a000', + 'value' => '0x9184e72a', + 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' +]); +$hashedString = $transaction->sha3('web3p'); +``` + +#### serialize + +Returns recursive length prefix encoding of transaction data. + +`serialize()` + +###### Example + +* Serialize the transaction data. + +```php +use Web3p\EthereumTx\Transaction; + +$transaction = new Transaction([ + 'nonce' => '0x01', + 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + 'gas' => '0x76c0', + 'gasPrice' => '0x9184e72a000', + 'value' => '0x9184e72a', + 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' +]); +$serializedTx = $transaction->serialize(); +``` + +#### sign + +Returns signed of transaction data. + +`sign(string $privateKey)` + +String privateKey - hexed private key with zero prefixed. + +###### Example + +* Sign the transaction data. + +```php +use Web3p\EthereumTx\Transaction; + +$transaction = new Transaction([ + 'nonce' => '0x01', + 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + 'gas' => '0x76c0', + 'gasPrice' => '0x9184e72a000', + 'value' => '0x9184e72a', + 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' +]); +$signedTx = $transaction->sign($stringPrivateKey); +``` + +#### hash + +Returns keccak256 encoding of serialized transaction data. + +`hash()` + +###### Example + +* Hash serialized transaction data. + +```php +use Web3p\EthereumTx\Transaction; + +$transaction = new Transaction([ + 'nonce' => '0x01', + 'from' => '0xb60e8dd61c5d32be8058bb8eb970870f07233155', + 'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567', + 'gas' => '0x76c0', + 'gasPrice' => '0x9184e72a000', + 'value' => '0x9184e72a', + 'data' => '0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675' +]); +$hashedTx = $transaction->serialize(); +``` # License MIT