-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sc0Vu/init-wallet
basic ethereum wallet
- Loading branch information
Showing
10 changed files
with
4,739 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: PHP | ||
|
||
on: ["push", "pull_request", "workflow_dispatch"] | ||
|
||
jobs: | ||
build_and_test: | ||
name: Build and test ethereum-wallet with ${{ matrix.php-version }} | ||
strategy: | ||
matrix: | ||
# bitcoin didn't support 8.0 yet, see: https://github.com/Bit-Wasp/bitcoin-php/pull/898 | ||
php-version: ["7.2", "7.3", "7.4"] | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
|
||
- name: PHP version | ||
run: | | ||
php --version | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Validate composer.json and composer.lock | ||
run: composer validate | ||
|
||
- name: Cache Composer packages | ||
id: composer-cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-php-${{ matrix.php-version }}- | ||
- name: Install dependencies | ||
if: steps.composer-cache.outputs.cache-hit != 'true' | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run test suite | ||
run: vendor/bin/phpunit --coverage-clover=coverage.xml | ||
|
||
- uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,109 @@ | ||
# ethereum-wallet | ||
[![PHP](https://github.com/web3p/ethereum-wallet/actions/workflows/php.yml/badge.svg)](https://github.com/web3p/ethereum-wallet/actions/workflows/php.yml) | ||
[![codecov](https://codecov.io/gh/web3p/ethereum-wallet/branch/master/graph/badge.svg)](https://codecov.io/gh/web3p/ethereum-wallet) | ||
[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/web3p/ethereum-wallet/blob/master/LICENSE) | ||
|
||
Ethereum wallet. | ||
|
||
# Install | ||
|
||
``` | ||
composer require web3p/ethereum-wallet | ||
``` | ||
|
||
# Usage | ||
|
||
Generate a new wallet: | ||
|
||
```php | ||
use Web3p\EthereumWallet\Wallet; | ||
|
||
$wallet = new Wallet(); | ||
$mnemonicLength = 15; | ||
$wallet->generate($mnemonicLength); | ||
|
||
// $wallet->address; | ||
// danger zone, if the data was leaked, money would be stolen | ||
// $wallet->privateKey; | ||
// $wallet->mnemonic; | ||
``` | ||
|
||
Recover wallet from mnemonic: | ||
|
||
```php | ||
use Web3p\EthereumWallet\Wallet; | ||
|
||
$wallet = new Wallet(); | ||
$mnemonic = '..........'; | ||
$wallet->fromMnemonic($mnemonic); | ||
|
||
// $wallet->address; | ||
// danger zone, if the data was leaked, money would be stolen | ||
// $wallet->privateKey; | ||
// $wallet->mnemonic; | ||
``` | ||
|
||
# API | ||
|
||
### Web3p\EthereumWallet\Wallet | ||
|
||
#### setWordlist | ||
|
||
Set different mnemonic wordlist, the default is english. | ||
|
||
`setWordlist(WordList $wordlist)` | ||
|
||
wordList - \BitWasp\Bitcoin\Mnemonic\WordList | ||
|
||
###### Example | ||
|
||
```php | ||
use Web3p\EthereumWallet\Wallet; | ||
use Web3p\EthereumWallet\Wordlist\BIP39ChineseTraditionalWordList; | ||
|
||
$wallet = new Wallet(); | ||
$zh_TW_wordlist = new BIP39ChineseTraditionalWordList; | ||
$wallet->wordlist = $zh_TW_wordlist; | ||
``` | ||
|
||
#### generate | ||
|
||
Returns a new wallet for the given mnemonic length. | ||
|
||
`generate(int $mnemonicLength)` | ||
|
||
mnemonicLength - integer. | ||
|
||
###### Example | ||
|
||
* Generate a new wallet with 12 mnemonic. | ||
|
||
```php | ||
use Web3p\EthereumWallet\Wallet; | ||
|
||
$wallet = new Wallet(); | ||
$wallet->generate(12); | ||
``` | ||
|
||
#### fromMnemonic | ||
|
||
Returns a wallet recover from the mnemonic. | ||
|
||
`fromMnemonic(string $mnemonic)` | ||
|
||
mnemonic - string. | ||
|
||
###### Example | ||
|
||
* Recover from a wallet. | ||
|
||
```php | ||
use Web3p\EthereumWallet\Wallet; | ||
|
||
$wallet = new Wallet(); | ||
$mnemonic = '..........'; | ||
$wallet->fromMnemonic($mnemonic); | ||
``` | ||
|
||
# License | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "web3p/ethereum-wallet", | ||
"description": "Ethereum wallet library in PHP.", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "sc0Vu", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require-dev": { | ||
"phpunit/phpunit": "~7 | ~8.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Web3p\\EthereumWallet\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Test\\": "test/" | ||
} | ||
}, | ||
"require": { | ||
"PHP": "^7.1 | ^8.0", | ||
"web3p/ethereum-util": "^0.1", | ||
"bitwasp/bitcoin": "^1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
|
||
<testsuite name="Ethereum wallet unit test"> | ||
<directory suffix="Test.php">./test/unit</directory> | ||
</testsuite> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
Oops, something went wrong.