1 | <?php |
||
13 | class Network implements NetworkInterface |
||
14 | { |
||
15 | const BECH32_PREFIX_SEGWIT = "segwit"; |
||
16 | |||
17 | const BASE58_ADDRESS_P2PKH = "p2pkh"; |
||
18 | const BASE58_ADDRESS_P2SH = "p2sh"; |
||
19 | const BASE58_WIF = "wif"; |
||
20 | const BIP32_PREFIX_XPUB = "xpub"; |
||
21 | const BIP32_PREFIX_XPRV = "xprv"; |
||
22 | |||
23 | /** |
||
24 | * @var array map of base58 address type to byte |
||
25 | */ |
||
26 | protected $base58PrefixMap = []; |
||
27 | |||
28 | /** |
||
29 | * @var array map of bech32 address type to HRP |
||
30 | */ |
||
31 | protected $bech32PrefixMap = []; |
||
32 | |||
33 | /** |
||
34 | * @var array map of bip32 type to bytes |
||
35 | */ |
||
36 | protected $bip32PrefixMap = []; |
||
37 | |||
38 | /** |
||
39 | * @var array map of bip32 key type to script type |
||
40 | */ |
||
41 | protected $bip32ScriptTypeMap = []; |
||
42 | |||
43 | /** |
||
44 | * @var string - message prefix for bitcoin signed messages |
||
45 | */ |
||
46 | protected $signedMessagePrefix; |
||
47 | |||
48 | /** |
||
49 | * @var string - 4 bytes for p2p magic |
||
50 | */ |
||
51 | protected $p2pMagic; |
||
52 | |||
53 | /** |
||
54 | * @param string $field - name of field being validated |
||
55 | * @param string $value - we check this value |
||
56 | * @param int $length - length we require |
||
57 | * @throws InvalidNetworkParameter |
||
58 | */ |
||
59 | 142 | private function validateHexString(string $field, string $value, int $length) |
|
69 | |||
70 | /** |
||
71 | * Network constructor. |
||
72 | * @throws InvalidNetworkParameter |
||
73 | */ |
||
74 | 142 | public function __construct() |
|
92 | |||
93 | /** |
||
94 | * @param string $prefixType |
||
95 | * @return bool |
||
96 | */ |
||
97 | 79 | protected function hasBase58Prefix(string $prefixType): bool |
|
101 | |||
102 | /** |
||
103 | * @param string $prefixType |
||
104 | * @return string |
||
105 | * @throws MissingBase58Prefix |
||
106 | */ |
||
107 | 77 | protected function getBase58Prefix(string $prefixType): string |
|
114 | |||
115 | /** |
||
116 | * @param string $prefixType |
||
117 | * @return bool |
||
118 | */ |
||
119 | 42 | protected function hasBech32Prefix(string $prefixType): bool |
|
123 | |||
124 | /** |
||
125 | * @param string $prefixType |
||
126 | * @return string |
||
127 | * @throws MissingBech32Prefix |
||
128 | */ |
||
129 | 40 | protected function getBech32Prefix(string $prefixType): string |
|
136 | |||
137 | /** |
||
138 | * @param string $prefixType |
||
139 | * @return bool |
||
140 | */ |
||
141 | 65 | protected function hasBip32Prefix(string $prefixType): bool |
|
145 | |||
146 | /** |
||
147 | * @param string $prefixType |
||
148 | * @return string |
||
149 | * @throws MissingBip32Prefix |
||
150 | */ |
||
151 | 63 | protected function getBip32Prefix(string $prefixType): string |
|
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | * @throws MissingNetworkParameter |
||
162 | * @see NetworkInterface::getSignedMessageMagic |
||
163 | */ |
||
164 | 22 | public function getSignedMessageMagic(): string |
|
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | * @throws MissingNetworkParameter |
||
175 | * @see NetworkInterface::getNetMagicBytes() |
||
176 | */ |
||
177 | 15 | public function getNetMagicBytes(): string |
|
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | * @throws MissingBase58Prefix |
||
188 | */ |
||
189 | 28 | public function getPrivByte(): string |
|
193 | |||
194 | /** |
||
195 | * @return string |
||
196 | * @throws MissingBase58Prefix |
||
197 | * @see NetworkInterface::getAddressByte() |
||
198 | */ |
||
199 | 47 | public function getAddressByte(): string |
|
203 | /** |
||
204 | * @return int |
||
205 | * @throws MissingBase58Prefix |
||
206 | * @see NetworkInterface::getAddressPrefixLength() |
||
207 | */ |
||
208 | public function getAddressPrefixLength(): int |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | * @throws MissingBase58Prefix |
||
216 | * @see NetworkInterface::getP2shByte() |
||
217 | */ |
||
218 | public function getP2shByte(): string |
||
222 | |||
223 | /** |
||
224 | * @return int |
||
225 | * @throws MissingBase58Prefix |
||
226 | * @see NetworkInterface::getP2shPrefixLength() |
||
227 | */ |
||
228 | public function getP2shPrefixLength(): int |
||
232 | |||
233 | /** |
||
234 | * @return string |
||
235 | * @throws MissingBip32Prefix |
||
236 | * @see NetworkInterface::getHDPubByte() |
||
237 | */ |
||
238 | public function getHDPubByte(): string |
||
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | * @throws MissingBip32Prefix |
||
246 | * @see NetworkInterface::getHDPrivByte() |
||
247 | */ |
||
248 | public function getHDPrivByte(): string |
||
252 | |||
253 | /** |
||
254 | * @return string |
||
255 | * @throws MissingBech32Prefix |
||
256 | * @see NetworkInterface::getSegwitBech32Prefix() |
||
257 | */ |
||
258 | public function getSegwitBech32Prefix(): string |
||
262 | } |
||
263 |