Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Account | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getPublicKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSecretKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Attestto\SolanaPhpSdk; |
| 4 | |
| 5 | use Attestto\SolanaPhpSdk\Util\Buffer; |
| 6 | use Attestto\SolanaPhpSdk\Util\HasPublicKey; |
| 7 | use Attestto\SolanaPhpSdk\Util\HasSecretKey; |
| 8 | |
| 9 | class Account implements HasPublicKey, HasSecretKey |
| 10 | { |
| 11 | protected Keypair $keypair; |
| 12 | |
| 13 | /** |
| 14 | * @param $secretKey |
| 15 | */ |
| 16 | public function __construct($secretKey = null) |
| 17 | { |
| 18 | if ($secretKey) { |
| 19 | $secretKeyString = Buffer::from($secretKey)->toString(); |
| 20 | |
| 21 | $this->keypair = Keypair::fromSecretKey($secretKeyString); |
| 22 | } else { |
| 23 | $this->keypair = Keypair::generate(); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return PublicKey |
| 29 | */ |
| 30 | public function getPublicKey(): PublicKey |
| 31 | { |
| 32 | return $this->keypair->getPublicKey(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return Buffer |
| 37 | */ |
| 38 | public function getSecretKey(): Buffer |
| 39 | { |
| 40 | return $this->keypair->getSecretKey(); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | } |