1 | <?php |
||
10 | class Network implements NetworkInterface |
||
11 | { |
||
12 | |||
13 | const BECH32_PREFIX_SEGWIT = "segwit"; |
||
14 | |||
15 | const BASE58_PREFIX_P2PKH = "p2pkh"; |
||
16 | const BASE58_PREFIX_P2SH = "p2sh"; |
||
17 | |||
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 $bip32ByteMap = []; |
||
35 | |||
36 | /** |
||
37 | * @var array map of bip32 key type to script type |
||
38 | */ |
||
39 | protected $bip32ScriptTypeMap = []; |
||
40 | |||
41 | /** |
||
42 | * @var string - single byte prefix for WIF encoding |
||
43 | */ |
||
44 | protected $wifPrefix; |
||
45 | |||
46 | /** |
||
47 | * @var string - message prefix for bitcoin signed messages |
||
48 | */ |
||
49 | protected $signedMessagePrefix; |
||
50 | |||
51 | /** |
||
52 | * @var string - 4 bytes for p2p magic |
||
53 | */ |
||
54 | protected $p2pMagic; |
||
55 | |||
56 | 134 | private function validateHexString($field, $value, $length) |
|
66 | 130 | ||
67 | 2 | public function __construct() |
|
85 | 8 | ||
86 | /** |
||
87 | * @param string $prefixType |
||
88 | * @return bool |
||
89 | */ |
||
90 | protected function hasBase58Prefix($prefixType) |
||
94 | |||
95 | /** |
||
96 | * @param string $prefixType |
||
97 | * @return string |
||
98 | * @throws MissingBase58Prefix |
||
99 | 20 | */ |
|
100 | protected function getBase58Prefix($prefixType) |
||
107 | 70 | ||
108 | /** |
||
109 | 70 | * @param string $prefixType |
|
110 | * @return bool |
||
111 | */ |
||
112 | protected function hasBech32Prefix($prefixType) |
||
116 | |||
117 | /** |
||
118 | 60 | * @param string $prefixType |
|
119 | * @return string |
||
120 | 60 | * @throws MissingBech32Prefix |
|
121 | 2 | */ |
|
122 | protected function getBech32Prefix($prefixType) |
||
129 | |||
130 | /** |
||
131 | * @param string $prefixType |
||
132 | * @return bool |
||
133 | 108 | */ |
|
134 | protected function hasBip32Prefix($prefixType) |
||
138 | |||
139 | 108 | /** |
|
140 | * @param string $prefixType |
||
141 | * @return string |
||
142 | * @throws MissingBech32Prefix |
||
143 | */ |
||
144 | protected function getBip32Prefix($prefixType) |
||
151 | 2 | ||
152 | /** |
||
153 | * @return string |
||
154 | 58 | * @throws MissingNetworkParameter |
|
155 | */ |
||
156 | public function getSignedMessageMagic() |
||
163 | 108 | ||
164 | /** |
||
165 | 108 | * @return string |
|
166 | 108 | * @throws MissingNetworkParameter |
|
167 | */ |
||
168 | public function getNetMagicBytes() |
||
175 | |||
176 | 104 | /** |
|
177 | * @return string |
||
178 | 104 | * @throws MissingNetworkParameter |
|
179 | 104 | */ |
|
180 | public function getPrivByte() |
||
187 | |||
188 | 10 | /** |
|
189 | 2 | * @inheritdoc |
|
190 | */ |
||
191 | public function getAddressByte() |
||
195 | |||
196 | /** |
||
197 | * @inheritdoc |
||
198 | */ |
||
199 | 104 | public function getP2shByte() |
|
203 | |||
204 | /** |
||
205 | 104 | * Get version bytes for XPUB key |
|
206 | 104 | * |
|
207 | * @return string |
||
208 | * @throws \Exception |
||
209 | */ |
||
210 | public function getHDPubByte() |
||
214 | |||
215 | 54 | /** |
|
216 | * Get version bytes for XPUB key |
||
217 | * |
||
218 | * @return string |
||
219 | 54 | * @throws \Exception |
|
220 | */ |
||
221 | public function getHDPrivByte() |
||
225 | |||
226 | /** |
||
227 | * @return bool |
||
228 | * @throws \Exception |
||
229 | */ |
||
230 | public function getSegwitBech32Prefix() |
||
234 | } |
||
235 |