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 | * @throws InvalidNetworkParameter |
||
56 | 134 | */ |
|
57 | private function validateHexString($field, $value, $length) |
||
67 | 2 | ||
68 | /** |
||
69 | * Network constructor. |
||
70 | 128 | * @throws InvalidNetworkParameter |
|
71 | 2 | */ |
|
72 | public function __construct() |
||
90 | |||
91 | 48 | /** |
|
92 | * @param string $prefixType |
||
93 | 48 | * @return bool |
|
94 | */ |
||
95 | protected function hasBase58Prefix($prefixType) |
||
99 | 20 | ||
100 | /** |
||
101 | 20 | * @param string $prefixType |
|
102 | * @return string |
||
103 | * @throws MissingBase58Prefix |
||
104 | */ |
||
105 | protected function getBase58Prefix($prefixType) |
||
112 | |||
113 | /** |
||
114 | * @param string $prefixType |
||
115 | * @return bool |
||
116 | */ |
||
117 | protected function hasBech32Prefix($prefixType) |
||
121 | 2 | ||
122 | /** |
||
123 | * @param string $prefixType |
||
124 | 58 | * @return string |
|
125 | * @throws MissingBech32Prefix |
||
126 | */ |
||
127 | protected function getBech32Prefix($prefixType) |
||
134 | |||
135 | 108 | /** |
|
136 | 108 | * @param string $prefixType |
|
137 | * @return bool |
||
138 | */ |
||
139 | 108 | protected function hasBip32Prefix($prefixType) |
|
143 | |||
144 | /** |
||
145 | * @param $prefixType |
||
146 | * @return mixed |
||
147 | * @throws MissingBip32Prefix |
||
148 | 60 | */ |
|
149 | protected function getBip32Prefix($prefixType) |
||
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | * @throws MissingNetworkParameter |
||
160 | * @see NetworkInterface::getSignedMessageMagic |
||
161 | */ |
||
162 | public function getSignedMessageMagic() |
||
169 | 108 | ||
170 | /** |
||
171 | * @return string |
||
172 | * @throws MissingNetworkParameter |
||
173 | * @see NetworkInterface::getNetMagicBytes() |
||
174 | */ |
||
175 | public function getNetMagicBytes() |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | * @throws MissingBase58Prefix |
||
186 | 10 | */ |
|
187 | public function getPrivByte() |
||
191 | |||
192 | 8 | /** |
|
193 | * @return string |
||
194 | * @throws MissingBase58Prefix |
||
195 | * @see NetworkInterface::getAddressByte() |
||
196 | */ |
||
197 | public function getAddressByte() |
||
201 | 104 | ||
202 | /** |
||
203 | * @return string |
||
204 | * @throws MissingBase58Prefix |
||
205 | 104 | * @see NetworkInterface::getP2shByte() |
|
206 | 104 | */ |
|
207 | public function getP2shByte() |
||
211 | |||
212 | /** |
||
213 | 54 | * @return mixed|string |
|
214 | * @throws MissingBip32Prefix |
||
215 | 54 | * @see NetworkInterface::getHDPubByte() |
|
216 | */ |
||
217 | public function getHDPubByte() |
||
221 | |||
222 | /** |
||
223 | * @return mixed|string |
||
224 | * @throws MissingBip32Prefix |
||
225 | * @see NetworkInterface::getHDPrivByte() |
||
226 | */ |
||
227 | public function getHDPrivByte() |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | * @throws MissingBech32Prefix |
||
235 | * @see NetworkInterface::getSegwitBech32Prefix() |
||
236 | */ |
||
237 | public function getSegwitBech32Prefix() |
||
241 | } |
||
242 |