Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
25.00% |
1 / 4 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Nimq_API | |
25.00% |
1 / 4 |
|
50.00% |
1 / 2 |
3.69 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| generate_address | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The local PHP library for generating addresses. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-bitcoin-gateway |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Bitcoin_Gateway\API\Helpers\Wallet; |
| 9 | |
| 10 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Helpers\Generate_Address_API_Interface; |
| 11 | use BrianHenryIE\WP_Bitcoin_Gateway\API\Model\Exceptions\BH_WP_Bitcoin_Gateway_Exception; |
| 12 | use BrianHenryIE\WP_Bitcoin_Gateway\Nimiq\XPub; |
| 13 | use Exception; |
| 14 | use Psr\Log\LoggerAwareTrait; |
| 15 | use Psr\Log\LoggerInterface; |
| 16 | |
| 17 | /** |
| 18 | * Use nimiq/php-xpub to generate public addresses. |
| 19 | */ |
| 20 | class Nimq_API implements Generate_Address_API_Interface { |
| 21 | use LoggerAwareTrait; |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @param LoggerInterface $logger PSR Logger. |
| 27 | */ |
| 28 | public function __construct( LoggerInterface $logger ) { |
| 29 | $this->setLogger( $logger ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Generate the nth address for the given xpub|ypub|zpub. |
| 34 | * |
| 35 | * @param string $public_address The wallet address. |
| 36 | * @param int $nth Derive path nth address in sequence. |
| 37 | * |
| 38 | * @return string |
| 39 | * @throws BH_WP_Bitcoin_Gateway_Exception Failed to generate address. |
| 40 | */ |
| 41 | public function generate_address( string $public_address, int $nth ): string { |
| 42 | |
| 43 | $xpub = XPub::fromString( $public_address ); |
| 44 | |
| 45 | $xpub_i_k = $xpub->derive( array( 0, $nth ) ); |
| 46 | |
| 47 | return $xpub_i_k->toAddress( 'btc' ); |
| 48 | } |
| 49 | } |