@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | public function __construct(array $params = null) |
50 | 50 | { |
51 | 51 | $this->keyInfo = array( |
52 | - 'private_key_hex' => $this->keyValueCheck($params['private_key_hex']), |
|
53 | - 'private_key_dec' => $this->keyValueCheck($params['private_key_dec']), |
|
54 | - 'public_key' => $this->keyValueCheck($params['public_key']), |
|
55 | - 'public_key_compressed' => $this->keyValueCheck($params['public_key_compressed']), |
|
56 | - 'public_key_x' => $this->keyValueCheck($params['public_key_x']), |
|
57 | - 'public_key_y' => $this->keyValueCheck($params['public_key_y']), |
|
58 | - 'generation_time' => '', |
|
59 | - ); |
|
52 | + 'private_key_hex' => $this->keyValueCheck($params['private_key_hex']), |
|
53 | + 'private_key_dec' => $this->keyValueCheck($params['private_key_dec']), |
|
54 | + 'public_key' => $this->keyValueCheck($params['public_key']), |
|
55 | + 'public_key_compressed' => $this->keyValueCheck($params['public_key_compressed']), |
|
56 | + 'public_key_x' => $this->keyValueCheck($params['public_key_x']), |
|
57 | + 'public_key_y' => $this->keyValueCheck($params['public_key_y']), |
|
58 | + 'generation_time' => '', |
|
59 | + ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | $comp_prefix = ($this->Modulo($point['R']['y'], '2') == '1') ? '03' : '02'; |
118 | 118 | |
119 | 119 | $this->keyInfo = array( |
120 | - 'private_key_hex' => $this->encodeHex($point['random_number']), |
|
121 | - 'private_key_dec' => $point['random_number'], |
|
122 | - 'public_key' => '04' . $point['Rx_hex'] . $point['Ry_hex'], |
|
123 | - 'public_key_compressed' => $comp_prefix . $point['Rx_hex'], |
|
124 | - 'public_key_x' => $point['Rx_hex'], |
|
125 | - 'public_key_y' => $point['Ry_hex'], |
|
126 | - ); |
|
120 | + 'private_key_hex' => $this->encodeHex($point['random_number']), |
|
121 | + 'private_key_dec' => $point['random_number'], |
|
122 | + 'public_key' => '04' . $point['Rx_hex'] . $point['Ry_hex'], |
|
123 | + 'public_key_compressed' => $comp_prefix . $point['Rx_hex'], |
|
124 | + 'public_key_x' => $point['Rx_hex'], |
|
125 | + 'public_key_y' => $point['Ry_hex'], |
|
126 | + ); |
|
127 | 127 | |
128 | 128 | return $this->keyInfo; |
129 | 129 | } |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | $this->keyInfo = array( |
120 | 120 | 'private_key_hex' => $this->encodeHex($point['random_number']), |
121 | 121 | 'private_key_dec' => $point['random_number'], |
122 | - 'public_key' => '04' . $point['Rx_hex'] . $point['Ry_hex'], |
|
123 | - 'public_key_compressed' => $comp_prefix . $point['Rx_hex'], |
|
122 | + 'public_key' => '04'.$point['Rx_hex'].$point['Ry_hex'], |
|
123 | + 'public_key_compressed' => $comp_prefix.$point['Rx_hex'], |
|
124 | 124 | 'public_key_x' => $point['Rx_hex'], |
125 | 125 | 'public_key_y' => $point['Ry_hex'], |
126 | 126 | ); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $pointX = substr($pubkey, 2); |
158 | 158 | $pointY = substr($this->calcYfromX($pointX, $prefix), 2); |
159 | 159 | |
160 | - $parsedValue = $this->prepAndClean($pointX . $pointY); |
|
160 | + $parsedValue = $this->prepAndClean($pointX.$pointY); |
|
161 | 161 | |
162 | 162 | return ($returnHex === false) ? $parsedValue : $this->encodeHex($parsedValue); |
163 | 163 | } |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | $this->pemInitialDataCheck($keypair); |
46 | 46 | |
47 | 47 | $ecpemstruct = array( |
48 | - 'sequence_beg' => '30', |
|
49 | - 'total_len' => '74', |
|
50 | - 'int_sec_beg' => '02', |
|
51 | - 'int_sec_len' => '01', |
|
52 | - 'int_sec_val' => '01', |
|
53 | - 'oct_sec_beg' => '04', |
|
54 | - 'oct_sec_len' => '20', |
|
55 | - 'oct_sec_val' => $keypair[0], |
|
56 | - 'a0_ele_beg' => 'a0', |
|
57 | - 'a0_ele_len' => '07', |
|
58 | - 'obj_id_beg' => '06', |
|
59 | - 'obj_id_len' => '05', |
|
60 | - 'obj_id_val' => '2b8104000a', |
|
61 | - 'a1_ele_beg' => 'a1', |
|
62 | - 'a1_ele_len' => '44', |
|
63 | - 'bit_str_beg' => '03', |
|
64 | - 'bit_str_len' => '42', |
|
65 | - 'bit_str_val' => '00' . $keypair[1], |
|
66 | - ); |
|
48 | + 'sequence_beg' => '30', |
|
49 | + 'total_len' => '74', |
|
50 | + 'int_sec_beg' => '02', |
|
51 | + 'int_sec_len' => '01', |
|
52 | + 'int_sec_val' => '01', |
|
53 | + 'oct_sec_beg' => '04', |
|
54 | + 'oct_sec_len' => '20', |
|
55 | + 'oct_sec_val' => $keypair[0], |
|
56 | + 'a0_ele_beg' => 'a0', |
|
57 | + 'a0_ele_len' => '07', |
|
58 | + 'obj_id_beg' => '06', |
|
59 | + 'obj_id_len' => '05', |
|
60 | + 'obj_id_val' => '2b8104000a', |
|
61 | + 'a1_ele_beg' => 'a1', |
|
62 | + 'a1_ele_len' => '44', |
|
63 | + 'bit_str_beg' => '03', |
|
64 | + 'bit_str_len' => '42', |
|
65 | + 'bit_str_val' => '00' . $keypair[1], |
|
66 | + ); |
|
67 | 67 | |
68 | 68 | $dec = trim(implode($ecpemstruct)); |
69 | 69 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | $this->pemDataLenCheck($decoded); |
87 | 87 | |
88 | 88 | $ecpemstruct = array( |
89 | - 'oct_sec_val' => substr($decoded, 14, 64), |
|
90 | - 'obj_id_val' => substr($decoded, 86, 10), |
|
91 | - 'bit_str_val' => substr($decoded, 106), |
|
89 | + 'oct_sec_val' => substr($decoded, 14, 64), |
|
90 | + 'obj_id_val' => substr($decoded, 86, 10), |
|
91 | + 'bit_str_val' => substr($decoded, 106), |
|
92 | 92 | ); |
93 | 93 | |
94 | 94 | $this->pemOidCheck($ecpemstruct['obj_id_val']); |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | $this->pemKeyLenCheck(array($private_key, $public_key)); |
100 | 100 | |
101 | 101 | return array( |
102 | - 'private_key' => $private_key, |
|
103 | - 'public_key' => $public_key |
|
102 | + 'private_key' => $private_key, |
|
103 | + 'public_key' => $public_key |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | 'a1_ele_len' => '44', |
63 | 63 | 'bit_str_beg' => '03', |
64 | 64 | 'bit_str_len' => '42', |
65 | - 'bit_str_val' => '00' . $keypair[1], |
|
65 | + 'bit_str_val' => '00'.$keypair[1], |
|
66 | 66 | ); |
67 | 67 | |
68 | 68 | $dec = trim(implode($ecpemstruct)); |
69 | 69 | |
70 | 70 | $this->pemDataLenCheck($dec); |
71 | 71 | |
72 | - return '-----BEGIN EC PRIVATE KEY-----' . "\r\n" . chunk_split(base64_encode($this->binConv($dec)), 64) . '-----END EC PRIVATE KEY-----'; |
|
72 | + return '-----BEGIN EC PRIVATE KEY-----'."\r\n".chunk_split(base64_encode($this->binConv($dec)), 64).'-----END EC PRIVATE KEY-----'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $this->pemOidCheck($ecpemstruct['obj_id_val']); |
95 | 95 | |
96 | 96 | $private_key = $ecpemstruct['oct_sec_val']; |
97 | - $public_key = '04' . $ecpemstruct['bit_str_val']; |
|
97 | + $public_key = '04'.$ecpemstruct['bit_str_val']; |
|
98 | 98 | |
99 | 99 | $this->pemKeyLenCheck(array($private_key, $public_key)); |
100 | 100 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | private function pemInitialDataCheck($keypair) |
114 | 114 | { |
115 | 115 | if (true === empty($keypair) || false === is_array($keypair) || strlen($keypair[0]) < 62 || strlen($keypair[1]) < 126) { |
116 | - throw new \Exception('Invalid or corrupt secp256k1 keypair provided. Cannot encode the keys to PEM format. Value checked was "' . var_export($keypair, true) . '".'); |
|
116 | + throw new \Exception('Invalid or corrupt secp256k1 keypair provided. Cannot encode the keys to PEM format. Value checked was "'.var_export($keypair, true).'".'); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | private function pemDataLenCheck($value) |
127 | 127 | { |
128 | 128 | if (strlen($value) < 220) { |
129 | - throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. Length < 220. Value received was "' . var_export($value, true) . '".'); |
|
129 | + throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. Length < 220. Value received was "'.var_export($value, true).'".'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | private function pemKeyLenCheck($values) |
140 | 140 | { |
141 | 141 | if (!is_array($values) || strlen($values[0]) < 62 || strlen($values[1]) < 126) { |
142 | - throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. Key lengths too short. Values checked were "' . var_export($values[0], true) . '" and "' . var_export($values[1], true) . '".'); |
|
142 | + throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. Key lengths too short. Values checked were "'.var_export($values[0], true).'" and "'.var_export($values[1], true).'".'); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | private function pemOidCheck($value) |
153 | 153 | { |
154 | 154 | if ($value != '2b8104000a') { |
155 | - throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. OID is not for EC key. Value checked was "' . var_export($value, true) . '".'); |
|
155 | + throw new \Exception('Invalid or corrupt secp256k1 key provided. Cannot decode the supplied PEM data. OID is not for EC key. Value checked was "'.var_export($value, true).'".'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $oid_string = ''; |
223 | 223 | |
224 | 224 | foreach ($oid as $key => $value) { |
225 | - $oid_string .= $value . "."; |
|
225 | + $oid_string .= $value."."; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $oid_string = substr($oid_string, 0, -1); |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | $this->raw_signature = ''; |
82 | 82 | |
83 | 83 | $this->P = array( |
84 | - 'x' => $this->Gx, |
|
85 | - 'y' => $this->Gy |
|
84 | + 'x' => $this->Gx, |
|
85 | + 'y' => $this->Gy |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | $this->keyUtil = new \Phactor\Key; |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | $signature = array( |
152 | - 'r' => $this->addHexPrefix(str_pad($this->encodeHex($r, false), 64, "0", STR_PAD_LEFT)), |
|
153 | - 's' => $this->addHexPrefix(str_pad($this->encodeHex($s, false), 64, "0", STR_PAD_LEFT)) |
|
154 | - ); |
|
152 | + 'r' => $this->addHexPrefix(str_pad($this->encodeHex($r, false), 64, "0", STR_PAD_LEFT)), |
|
153 | + 's' => $this->addHexPrefix(str_pad($this->encodeHex($s, false), 64, "0", STR_PAD_LEFT)) |
|
154 | + ); |
|
155 | 155 | |
156 | 156 | $this->r_coordinate = $signature['r']; |
157 | 157 | $this->s_coordinate = $signature['s']; |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | $retval = array( |
249 | 249 | 'bin_r' => $this->msbCheck($r[0]) . $r, |
250 | 250 | 'bin_s' => $this->msbCheck($s[0]) . $s |
251 | - ); |
|
251 | + ); |
|
252 | 252 | |
253 | 253 | $seq = chr(0x02) . chr(strlen($retval['bin_r'])) . $retval['bin_r'] . |
254 | - chr(0x02) . chr(strlen($retval['bin_s'])) . $retval['bin_s']; |
|
254 | + chr(0x02) . chr(strlen($retval['bin_s'])) . $retval['bin_s']; |
|
255 | 255 | |
256 | 256 | return bin2hex(chr(0x30) . chr(strlen($seq)) . $seq); |
257 | 257 | } |
@@ -270,19 +270,19 @@ discard block |
||
270 | 270 | |
271 | 271 | /* This is the main structure we'll use for storing our parsed signature. */ |
272 | 272 | $ecdsa_struct = array( |
273 | - 'sigstart' => '', |
|
274 | - 'siglen' => '', |
|
275 | - 'rtype' => '', |
|
276 | - 'rlen' => '', |
|
277 | - 'roffset' => 0, |
|
278 | - 'r' => '', |
|
279 | - 'stype' => '', |
|
280 | - 'slen' => '', |
|
281 | - 'soffset' => 0, |
|
282 | - 's' => '', |
|
283 | - 'original' => '', |
|
284 | - 'totallen' => 0 |
|
285 | - ); |
|
273 | + 'sigstart' => '', |
|
274 | + 'siglen' => '', |
|
275 | + 'rtype' => '', |
|
276 | + 'rlen' => '', |
|
277 | + 'roffset' => 0, |
|
278 | + 'r' => '', |
|
279 | + 'stype' => '', |
|
280 | + 'slen' => '', |
|
281 | + 'soffset' => 0, |
|
282 | + 's' => '', |
|
283 | + 'original' => '', |
|
284 | + 'totallen' => 0 |
|
285 | + ); |
|
286 | 286 | |
287 | 287 | $ecdsa_struct['original'] = $signature; |
288 | 288 | $ecdsa_struct['totallen'] = strlen($signature); |
@@ -333,8 +333,8 @@ discard block |
||
333 | 333 | $this->RangeCheck($ecdsa_struct['r']); |
334 | 334 | |
335 | 335 | return array( |
336 | - 'r' => $ecdsa_struct['r'], |
|
337 | - 's' => $ecdsa_struct['s'] |
|
336 | + 'r' => $ecdsa_struct['r'], |
|
337 | + 's' => $ecdsa_struct['s'] |
|
338 | 338 | ); |
339 | 339 | } |
340 | 340 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | do { |
130 | 130 | /* Get the message hash and a new random number */ |
131 | - $e = $this->decodeHex('0x' . hash('sha256', $message)); |
|
131 | + $e = $this->decodeHex('0x'.hash('sha256', $message)); |
|
132 | 132 | $k = $this->SecureRandomNumber(); |
133 | 133 | |
134 | 134 | /* Calculate a new curve point from R=k*G (x1,y1) */ |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | public function Verify($sig, $msg, $pubkey) |
174 | 174 | { |
175 | 175 | if (true === empty($sig) || true === empty($msg) || true === empty($pubkey)) { |
176 | - throw new \Exception('The signature, public key and message parameters are required to verify a signature. Value received for first parameter was "' . var_export($sig, true) . '", second parameter was "' . var_export($msg, true) . '" and third parameter was "' . var_export($pubkey, true) . '".'); |
|
176 | + throw new \Exception('The signature, public key and message parameters are required to verify a signature. Value received for first parameter was "'.var_export($sig, true).'", second parameter was "'.var_export($msg, true).'" and third parameter was "'.var_export($pubkey, true).'".'); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $e = ''; |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | $s = $this->binConv($this->CoordinateCheck($s)); |
247 | 247 | |
248 | 248 | $retval = array( |
249 | - 'bin_r' => $this->msbCheck($r[0]) . $r, |
|
250 | - 'bin_s' => $this->msbCheck($s[0]) . $s |
|
249 | + 'bin_r' => $this->msbCheck($r[0]).$r, |
|
250 | + 'bin_s' => $this->msbCheck($s[0]).$s |
|
251 | 251 | ); |
252 | 252 | |
253 | - $seq = chr(0x02) . chr(strlen($retval['bin_r'])) . $retval['bin_r'] . |
|
254 | - chr(0x02) . chr(strlen($retval['bin_s'])) . $retval['bin_s']; |
|
253 | + $seq = chr(0x02).chr(strlen($retval['bin_r'])).$retval['bin_r']. |
|
254 | + chr(0x02).chr(strlen($retval['bin_s'])).$retval['bin_s']; |
|
255 | 255 | |
256 | - return bin2hex(chr(0x30) . chr(strlen($seq)) . $seq); |
|
256 | + return bin2hex(chr(0x30).chr(strlen($seq)).$seq); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | private function ecdsaSigTotalLenCheck($value) |
346 | 346 | { |
347 | 347 | if ($value != '140' && $value != '142' && $value != '144') { |
348 | - throw new \Exception('Invalid ECDSA signature provided! Length is out of range for a correct signature. Value checked was "' . var_export($value, true) . '".'); |
|
348 | + throw new \Exception('Invalid ECDSA signature provided! Length is out of range for a correct signature. Value checked was "'.var_export($value, true).'".'); |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | private function derRecordStartCheck($value) |
359 | 359 | { |
360 | 360 | if ($value != '30') { |
361 | - throw new \Exception('Invalid ECDSA signature provided! Unknown signature format. Value checked was "' . var_export($value, true) . '".'); |
|
361 | + throw new \Exception('Invalid ECDSA signature provided! Unknown signature format. Value checked was "'.var_export($value, true).'".'); |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | private function derRecordTotalLenCheck($value) |
372 | 372 | { |
373 | 373 | if ($value != '44' && $value != '45' && $value != '46') { |
374 | - throw new \Exception('Invalid ECDSA signature provided! DER record length is invalid. Value checked was "' . var_export($value, true) . '".'); |
|
374 | + throw new \Exception('Invalid ECDSA signature provided! DER record length is invalid. Value checked was "'.var_export($value, true).'".'); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | private function derDataTypeCheck($value) |
385 | 385 | { |
386 | 386 | if ($value != '02') { |
387 | - throw new \Exception('Invalid ECDSA signature provided! DER record length is invalid. Value checked was "' . var_export($value, true) . '".'); |
|
387 | + throw new \Exception('Invalid ECDSA signature provided! DER record length is invalid. Value checked was "'.var_export($value, true).'".'); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | private function derDataLenCheck($value) |
398 | 398 | { |
399 | 399 | if ($value != '20' && $value != '21') { |
400 | - throw new \Exception('Invalid ECDSA signature provided! The coordinate length is invalid. Value checked was "' . var_export($value, true) . '".'); |
|
400 | + throw new \Exception('Invalid ECDSA signature provided! The coordinate length is invalid. Value checked was "'.var_export($value, true).'".'); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | public function GenerateNewPoint($ladder = true) |
268 | 268 | { |
269 | 269 | $P = array( |
270 | - 'x' => $this->Gx, |
|
271 | - 'y' => $this->Gy |
|
272 | - ); |
|
270 | + 'x' => $this->Gx, |
|
271 | + 'y' => $this->Gy |
|
272 | + ); |
|
273 | 273 | |
274 | 274 | do { |
275 | 275 | $random_number = $this->SecureRandomNumber(); |
@@ -285,10 +285,10 @@ discard block |
||
285 | 285 | } |
286 | 286 | |
287 | 287 | return array( |
288 | - 'random_number' => $random_number, |
|
289 | - 'R' => $R, |
|
290 | - 'Rx_hex' => $Rx_hex, |
|
291 | - 'Ry_hex' => $Ry_hex |
|
288 | + 'random_number' => $random_number, |
|
289 | + 'R' => $R, |
|
290 | + 'Rx_hex' => $Rx_hex, |
|
291 | + 'Ry_hex' => $Ry_hex |
|
292 | 292 | ); |
293 | 293 | } |
294 | 294 |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | if ($left == $right) { |
183 | 183 | return true; |
184 | 184 | } else { |
185 | - throw new \Exception('Point test failed! Cannot continue. I tested the point: ' . var_export($P, true) . ' but got the point: ' . var_export($test_point, true)); |
|
185 | + throw new \Exception('Point test failed! Cannot continue. I tested the point: '.var_export($P, true).' but got the point: '.var_export($test_point, true)); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } catch (\Exception $e) { |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $Rx_hex = str_pad($this->encodeHex($R['x']), 64, "0", STR_PAD_LEFT); |
274 | 274 | $Ry_hex = str_pad($this->encodeHex($R['y']), 64, "0", STR_PAD_LEFT); |
275 | 275 | } else { |
276 | - throw new \Exception('Point test failed! Cannot continue. I got the point: ' . var_export($R, true)); |
|
276 | + throw new \Exception('Point test failed! Cannot continue. I got the point: '.var_export($R, true)); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | return array( |
@@ -240,7 +240,7 @@ |
||
240 | 240 | case 'unk': |
241 | 241 | throw new \Exception('Unknown number type in BC::bcNormalize(). Cannot process!'); |
242 | 242 | } |
243 | - **/ |
|
243 | + **/ |
|
244 | 244 | |
245 | 245 | return $a; |
246 | 246 | } |
@@ -279,7 +279,7 @@ |
||
279 | 279 | |
280 | 280 | list($remain, $last) = array(bcdiv(bcsub($dec, $last), '16'), bcmod($dec, '16')); |
281 | 281 | |
282 | - return ($remain == 0) ? dechex($last) : $this->convertDecToHex($remain) . dechex($last); |
|
282 | + return ($remain == 0) ? dechex($last) : $this->convertDecToHex($remain).dechex($last); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -65,12 +65,12 @@ |
||
65 | 65 | public function __construct($pubkey = '', $type = '02', $version = '0F') |
66 | 66 | { |
67 | 67 | $this->rawHashes = array( |
68 | - 'step1' => null, |
|
69 | - 'step2' => null, |
|
70 | - 'step3' => null, |
|
71 | - 'step4' => null, |
|
72 | - 'step5' => null, |
|
73 | - 'step6' => null, |
|
68 | + 'step1' => null, |
|
69 | + 'step2' => null, |
|
70 | + 'step3' => null, |
|
71 | + 'step4' => null, |
|
72 | + 'step5' => null, |
|
73 | + 'step6' => null, |
|
74 | 74 | ); |
75 | 75 | |
76 | 76 | $this->encoded = ''; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $this->rawHashes['step2'] = hash('ripemd160', $this->rawHashes['step1']); |
131 | 131 | |
132 | 132 | /* prepend the hex SINversion and hex SINtype to the hex form of the ripemd160 hash */ |
133 | - $this->rawHashes['step3'] = $this->SINversion . $this->SINtype . $this->rawHashes['step2']; |
|
133 | + $this->rawHashes['step3'] = $this->SINversion.$this->SINtype.$this->rawHashes['step2']; |
|
134 | 134 | |
135 | 135 | /* |
136 | 136 | * convert the appended hex string back to binary and double sha256 hash it leaving |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $this->rawHashes['step5'] = substr(bin2hex($this->rawHashes['step4']), 0, 8); |
143 | 143 | |
144 | 144 | /* append the first 4 bytes to the fully appended string in step 3 */ |
145 | - $this->rawHashes['step6'] = $this->rawHashes['step3'] . $this->rawHashes['step5']; |
|
145 | + $this->rawHashes['step6'] = $this->rawHashes['step3'].$this->rawHashes['step5']; |
|
146 | 146 | |
147 | 147 | /* finally base58 encode it */ |
148 | 148 | $this->encoded = $this->encodeBase58($this->rawHashes['step6']); |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | public function __toString() |
82 | 82 | { |
83 | 83 | return json_encode(array( |
84 | - 'WIF_address' => $this->WIF_address, |
|
85 | - 'private_key' => $this->private_key, |
|
86 | - 'network_type' => $this->network_type, |
|
87 | - 'compressed_pubkey' => $this->compressed_pubkey_format, |
|
88 | - 'checksum' => $this->checksum) |
|
89 | - ); |
|
84 | + 'WIF_address' => $this->WIF_address, |
|
85 | + 'private_key' => $this->private_key, |
|
86 | + 'network_type' => $this->network_type, |
|
87 | + 'compressed_pubkey' => $this->compressed_pubkey_format, |
|
88 | + 'checksum' => $this->checksum) |
|
89 | + ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | $decoded_key = $this->stripHexPrefix($this->decodeBase58(trim($WIF_encoded_key))); |
383 | 383 | |
384 | 384 | list($private_key, $checksum_provided) = array( |
385 | - substr($decoded_key, 0, -8), |
|
386 | - substr($decoded_key, strlen($decoded_key) - 8) |
|
387 | - ); |
|
385 | + substr($decoded_key, 0, -8), |
|
386 | + substr($decoded_key, strlen($decoded_key) - 8) |
|
387 | + ); |
|
388 | 388 | |
389 | 389 | $private_key_type = substr($private_key, 0, 2); |
390 | 390 |
@@ -329,13 +329,13 @@ discard block |
||
329 | 329 | /* |
330 | 330 | * 2. Add a 0x80 byte in front of it for mainnet addresses or 0xef for testnet addresses. |
331 | 331 | */ |
332 | - $step2 = ($network == 'main') ? '80' . $step1 : 'ef' . $step1; |
|
332 | + $step2 = ($network == 'main') ? '80'.$step1 : 'ef'.$step1; |
|
333 | 333 | |
334 | 334 | /* |
335 | 335 | * 3. Append a 0x01 byte after it if it should be used with compressed public keys. Nothing is appended |
336 | 336 | * if it is used with uncompressed public keys. |
337 | 337 | */ |
338 | - $step3 = ($public_key_format == 'compressed') ? $step2 . '01' : $step2; |
|
338 | + $step3 = ($public_key_format == 'compressed') ? $step2.'01' : $step2; |
|
339 | 339 | |
340 | 340 | /* |
341 | 341 | * 4. Perform a SHA-256 hash on the extended key. |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | /* |
356 | 356 | * 7. Add the four checksum bytes from step 6 at the end of the extended key from step 3. |
357 | 357 | */ |
358 | - $step7 = $step3 . $this->checksum; |
|
358 | + $step7 = $step3.$this->checksum; |
|
359 | 359 | |
360 | 360 | /* |
361 | 361 | * 8. Convert the result from a byte string into a Base58 string using Base58Check encoding. |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $private_key_type = substr($private_key, 0, 2); |
390 | 390 | |
391 | 391 | if ($private_key_type != '80' && $private_key_type != 'ef') { |
392 | - throw new \Exception('Invalid WIF encoded private key! Network type was not present in value provided. Checked ' . $private_key . ' and found ' . $private_key_type); |
|
392 | + throw new \Exception('Invalid WIF encoded private key! Network type was not present in value provided. Checked '.$private_key.' and found '.$private_key_type); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | $private_key = substr($private_key, 2); |
@@ -397,10 +397,10 @@ discard block |
||
397 | 397 | $private_key = ($compressed_public_key == '01') ? substr($private_key, 0, -2) : $private_key; |
398 | 398 | |
399 | 399 | /* Now let's check our private key against the checksum provided. */ |
400 | - $new_checksum = substr(hash('sha256', hash('sha256', $this->binConv($private_key_type . $private_key . $compressed_public_key), true)), 0, 8); |
|
400 | + $new_checksum = substr(hash('sha256', hash('sha256', $this->binConv($private_key_type.$private_key.$compressed_public_key), true)), 0, 8); |
|
401 | 401 | |
402 | 402 | if ($new_checksum != $checksum_provided) { |
403 | - throw new \Exception('Invalid WIF encoded private key! Checksum is incorrect! Value encoded with key was: ' . $checksum_provided . ' but this does not match the recalculated value of: ' . $new_checksum . ' from the decoded provided value of: ' . $decoded_key); |
|
403 | + throw new \Exception('Invalid WIF encoded private key! Checksum is incorrect! Value encoded with key was: '.$checksum_provided.' but this does not match the recalculated value of: '.$new_checksum.' from the decoded provided value of: '.$decoded_key); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | return $private_key; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | case '10': |
84 | 84 | return $this->dec_chars; |
85 | 85 | default: |
86 | - throw new \Exception('Unknown base parameter passed to Number::BaseCheck() function. Value received was "' . var_export($base, true) . '".'); |
|
86 | + throw new \Exception('Unknown base parameter passed to Number::BaseCheck() function. Value received was "'.var_export($base, true).'".'); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $secure_random_number = ''; |
184 | 184 | |
185 | 185 | while (strlen($secure_random_number) < 78) { |
186 | - $secure_random_number = $secure_random_number . hexdec(bin2hex(openssl_random_pseudo_bytes(4, $cstrong))); |
|
186 | + $secure_random_number = $secure_random_number.hexdec(bin2hex(openssl_random_pseudo_bytes(4, $cstrong))); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | if ($secure_random_number === false || $cstrong === false) { |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function addHexPrefix($hex) |
218 | 218 | { |
219 | - return (substr($hex, 0, 2) != '0x') ? '0x' . $hex : $hex; |
|
219 | + return (substr($hex, 0, 2) != '0x') ? '0x'.$hex : $hex; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | private function hexLenCheck($hex) |
310 | 310 | { |
311 | 311 | if (strlen($hex) < 62) { |
312 | - throw new \Exception('The coordinate value checked was not in hex format or was invalid. Value checked was "' . var_export($hex, true) . '".'); |
|
312 | + throw new \Exception('The coordinate value checked was not in hex format or was invalid. Value checked was "'.var_export($hex, true).'".'); |
|
313 | 313 | } |
314 | 314 | } |
315 | 315 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $hex = $this->addHexPrefix($this->prepAndClean($hex)); |
293 | 293 | break; |
294 | 294 | default: |
295 | - throw new \Exception('Unknown data type passed to the binConv() function. Value received was "' . var_export($hex, true) . '".'); |
|
295 | + throw new \Exception('Unknown data type passed to the binConv() function. Value received was "'.var_export($hex, true).'".'); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | return strrev($this->encodeValue($hex, '256')); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | try { |
313 | 313 | |
314 | 314 | if (strlen($hex) % 2 != 0 || $this->Test($hex) != 'hex') { |
315 | - throw new \Exception('Uneven number of hex characters or invalid parameter passed to encodeBase58 function. Value received was "' . var_export($hex, true) . '".'); |
|
315 | + throw new \Exception('Uneven number of hex characters or invalid parameter passed to encodeBase58 function. Value received was "'.var_export($hex, true).'".'); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | $orighex = $hex; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | $return = strrev($this->encodeValue($hex, '58')); |
321 | 321 | |
322 | 322 | for ($i = 0; $i < strlen($orighex) && substr($orighex, $i, 2) == '00'; $i += 2) { |
323 | - $return = '1' . $return; |
|
323 | + $return = '1'.$return; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | return $return; |
@@ -356,10 +356,10 @@ discard block |
||
356 | 356 | $return = $this->encodeHex($return); |
357 | 357 | |
358 | 358 | for ($i = 0; $i < strlen($origbase58) && $origbase58[$i] == '1'; $i++) { |
359 | - $return = '00' . $return; |
|
359 | + $return = '00'.$return; |
|
360 | 360 | } |
361 | 361 | |
362 | - return (strlen($return) % 2 != 0) ? '0' . $return : $return; |
|
362 | + return (strlen($return) % 2 != 0) ? '0'.$return : $return; |
|
363 | 363 | |
364 | 364 | } catch (\Exception $e) { |
365 | 365 | // TODO: Need to do something useful here instead of re-throwing the exception. |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | foreach ($params as $key => $value) { |
402 | 402 | if ($this->numberCheck($value) === false) { |
403 | 403 | $caller = debug_backtrace(); |
404 | - throw new \Exception('Empty or invalid parameters passed to ' . $caller[count($caller) - 1]['function'] . ' function. Argument list received: ' . var_export($caller[count($caller) - 1]['args'], true)); |
|
404 | + throw new \Exception('Empty or invalid parameters passed to '.$caller[count($caller) - 1]['function'].' function. Argument list received: '.var_export($caller[count($caller) - 1]['args'], true)); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | $qq = $this->math->div($val, $base); |
429 | 429 | $rem = $this->math->mod($val, $base); |
430 | 430 | $val = $qq; |
431 | - $new = $new . $digits[$rem]; |
|
431 | + $new = $new.$digits[$rem]; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | return $new; |