1 | <?php |
||
11 | class Network implements NetworkInterface |
||
12 | { |
||
13 | const BECH32_PREFIX_SEGWIT = "segwit"; |
||
14 | |||
15 | const BASE58_ADDRESS_P2PKH = "p2pkh"; |
||
16 | const BASE58_ADDRESS_P2SH = "p2sh"; |
||
17 | const BASE58_WIF = "wif"; |
||
18 | const BIP32_PREFIX_XPUB = "xpub"; |
||
19 | const BIP32_PREFIX_XPRV = "xprv"; |
||
20 | |||
21 | /** |
||
22 | * @var array map of base58 address type to byte |
||
23 | */ |
||
24 | protected $base58PrefixMap = []; |
||
25 | |||
26 | /** |
||
27 | * @var array map of bech32 address type to HRP |
||
28 | */ |
||
29 | protected $bech32PrefixMap = []; |
||
30 | |||
31 | /** |
||
32 | * @var array map of bip32 type to bytes |
||
33 | */ |
||
34 | protected $bip32PrefixMap = []; |
||
35 | |||
36 | /** |
||
37 | * @var array map of bip32 key type to script type |
||
38 | */ |
||
39 | protected $bip32ScriptTypeMap = []; |
||
40 | |||
41 | /** |
||
42 | * @var string - message prefix for bitcoin signed messages |
||
43 | */ |
||
44 | protected $signedMessagePrefix; |
||
45 | |||
46 | /** |
||
47 | * @var string - 4 bytes for p2p magic |
||
48 | */ |
||
49 | protected $p2pMagic; |
||
50 | |||
51 | /** |
||
52 | * @param string $field - name of field being validated |
||
53 | * @param mixed $value - we check this value |
||
54 | * @param int $length - length we require |
||
55 | */ |
||
56 | 109 | private function validateHexString($field, $value, $length) |
|
66 | |||
67 | /** |
||
68 | * Network constructor. |
||
69 | */ |
||
70 | 109 | public function __construct() |
|
88 | |||
89 | /** |
||
90 | * @param string $prefixType |
||
91 | * @return bool |
||
92 | */ |
||
93 | 61 | protected function hasBase58Prefix($prefixType) |
|
97 | |||
98 | /** |
||
99 | * @param string $prefixType |
||
100 | * @return string |
||
101 | * @throws MissingBase58Prefix |
||
102 | */ |
||
103 | 59 | protected function getBase58Prefix($prefixType) |
|
110 | |||
111 | /** |
||
112 | * @param string $prefixType |
||
113 | * @return bool |
||
114 | */ |
||
115 | 36 | protected function hasBech32Prefix($prefixType) |
|
119 | |||
120 | /** |
||
121 | * @param string $prefixType |
||
122 | * @return string |
||
123 | * @throws MissingBech32Prefix |
||
124 | */ |
||
125 | 34 | protected function getBech32Prefix($prefixType) |
|
132 | |||
133 | /** |
||
134 | * @param string $prefixType |
||
135 | * @return bool |
||
136 | */ |
||
137 | 59 | protected function hasBip32Prefix($prefixType) |
|
141 | |||
142 | /** |
||
143 | * @param $prefixType |
||
144 | * @return mixed |
||
145 | * @throws MissingBip32Prefix |
||
146 | */ |
||
147 | 57 | protected function getBip32Prefix($prefixType) |
|
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | * @throws MissingNetworkParameter |
||
158 | * @see NetworkInterface::getSignedMessageMagic |
||
159 | */ |
||
160 | 21 | public function getSignedMessageMagic() |
|
167 | |||
168 | /** |
||
169 | * @return string |
||
170 | * @throws MissingNetworkParameter |
||
171 | * @see NetworkInterface::getNetMagicBytes() |
||
172 | */ |
||
173 | 15 | public function getNetMagicBytes() |
|
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | * @throws MissingBase58Prefix |
||
184 | */ |
||
185 | 21 | public function getPrivByte() |
|
189 | |||
190 | /** |
||
191 | * @return string |
||
192 | * @throws MissingBase58Prefix |
||
193 | * @see NetworkInterface::getAddressByte() |
||
194 | */ |
||
195 | 39 | public function getAddressByte() |
|
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | * @throws MissingBase58Prefix |
||
203 | * @see NetworkInterface::getP2shByte() |
||
204 | */ |
||
205 | 45 | public function getP2shByte() |
|
209 | |||
210 | /** |
||
211 | * @return mixed|string |
||
212 | * @throws MissingBip32Prefix |
||
213 | * @see NetworkInterface::getHDPubByte() |
||
214 | */ |
||
215 | 55 | public function getHDPubByte() |
|
219 | |||
220 | /** |
||
221 | * @return mixed|string |
||
222 | * @throws MissingBip32Prefix |
||
223 | * @see NetworkInterface::getHDPrivByte() |
||
224 | */ |
||
225 | 55 | public function getHDPrivByte() |
|
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | * @throws MissingBech32Prefix |
||
233 | * @see NetworkInterface::getSegwitBech32Prefix() |
||
234 | */ |
||
235 | 32 | public function getSegwitBech32Prefix() |
|
239 | } |
||
240 |