1: <?php declare( strict_types = 1 );
2:
3: namespace Waves\Common;
4:
5: use Waves\Util\Functions;
6:
7: class Base58String
8: {
9: private string $bytes;
10: private string $encoded;
11:
12: private function __construct(){}
13:
14: static function emptyString(): Base58String
15: {
16: $base58String = new Base58String;
17: $base58String->bytes = '';
18: $base58String->encoded = '';
19: return $base58String;
20: }
21:
22: static function fromString( string $encoded ): Base58String
23: {
24: $base58String = new Base58String;
25: $base58String->encoded = $encoded;
26: return $base58String;
27: }
28:
29: static function fromBytes( string $bytes ): Base58String
30: {
31: $base58String = new Base58String;
32: $base58String->bytes = $bytes;
33: return $base58String;
34: }
35:
36: function bytes(): string
37: {
38: if( !isset( $this->bytes ) )
39: $this->bytes = Functions::base58Decode( $this->encoded );
40: return $this->bytes;
41: }
42:
43: function encoded(): string
44: {
45: if( !isset( $this->encoded ) )
46: $this->encoded = Functions::base58Encode( $this->bytes );
47: return $this->encoded;
48: }
49:
50: function toString(): string
51: {
52: return $this->encoded();
53: }
54: }
55: