1: <?php declare( strict_types = 1 );
2:
3: namespace Waves\Account;
4:
5: use Waves\Common\Base58String;
6:
7: class PrivateKey
8: {
9: const LENGTH = 32;
10:
11: private Base58String $key;
12: private PublicKey $publicKey;
13:
14: private function __construct(){}
15:
16: static function fromSeed( string $seed, int $nonce = 0 ): PrivateKey
17: {
18: $privateKey = new PrivateKey;
19: $privateKey->key = Base58String::fromBytes( ( new \deemru\WavesKit )->getPrivateKey( true, $seed, pack( 'N', $nonce ) ) );
20: return $privateKey;
21: }
22:
23: static function fromBytes( string $key ): PrivateKey
24: {
25: $privateKey = new PrivateKey;
26: $privateKey->key = Base58String::fromBytes( $key );
27: return $privateKey;
28: }
29:
30: static function fromString( string $key ): PrivateKey
31: {
32: $privateKey = new PrivateKey;
33: $privateKey->key = Base58String::fromString( $key );
34: return $privateKey;
35: }
36:
37: function publicKey(): PublicKey
38: {
39: if( !isset( $this->publicKey ) )
40: $this->publicKey = PublicKey::fromPrivateKey( $this );
41: return $this->publicKey;
42: }
43:
44: function bytes(): string
45: {
46: return $this->key->bytes();
47: }
48:
49: function toString(): string
50: {
51: return $this->key->toString();
52: }
53: }
54: