1 | <?php |
||
22 | class EcAdapter implements EcAdapterInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var Math |
||
26 | */ |
||
27 | private $math; |
||
28 | |||
29 | /** |
||
30 | * @var GeneratorPoint |
||
31 | */ |
||
32 | private $generator; |
||
33 | |||
34 | /** |
||
35 | * @param Math $math |
||
36 | * @param GeneratorPoint $generator |
||
37 | 19 | */ |
|
38 | public function __construct(Math $math, GeneratorPoint $generator) |
||
43 | |||
44 | /** |
||
45 | * @return Math |
||
46 | 638 | */ |
|
47 | public function getMath() |
||
51 | |||
52 | /** |
||
53 | * @return GeneratorPoint |
||
54 | 293 | */ |
|
55 | public function getGenerator() |
||
59 | |||
60 | /** |
||
61 | * @param \GMP $scalar |
||
62 | * @param bool|false $compressed |
||
63 | * @return PrivateKey |
||
64 | 125 | */ |
|
65 | public function getPrivateKey(\GMP $scalar, $compressed = false) |
||
69 | |||
70 | /** |
||
71 | * @param PointInterface $point |
||
72 | * @param bool|false $compressed |
||
73 | * @return PublicKey |
||
74 | 105 | */ |
|
75 | public function getPublicKey(PointInterface $point, $compressed = false) |
||
79 | |||
80 | /** |
||
81 | * @param \GMP $r |
||
82 | * @param \GMP $s |
||
83 | * @return Signature |
||
84 | */ |
||
85 | public function getSignature(\GMP $r, \GMP $s) |
||
89 | |||
90 | /** |
||
91 | * @param BufferInterface $messageHash |
||
92 | * @param PublicKey $publicKey |
||
93 | * @param Signature $signature |
||
94 | * @return bool |
||
95 | 47 | */ |
|
96 | private function doVerify(BufferInterface $messageHash, PublicKey $publicKey, Signature $signature) |
||
102 | 47 | ||
103 | 47 | /** |
|
104 | 47 | * @param BufferInterface $messageHash |
|
105 | 3 | * @param PublicKeyInterface $publicKey |
|
106 | * @param SignatureInterface $signature |
||
107 | * @return bool |
||
108 | 44 | */ |
|
109 | public function verify(BufferInterface $messageHash, PublicKeyInterface $publicKey, SignatureInterface $signature) |
||
115 | 44 | ||
116 | 44 | /** |
|
117 | * @param BufferInterface $messageHash |
||
118 | 44 | * @param PrivateKey $privateKey |
|
119 | * @param RbgInterface|null $rbg |
||
120 | * @return Signature |
||
121 | */ |
||
122 | private function doSign(BufferInterface $messageHash, PrivateKey $privateKey, RbgInterface $rbg = null) |
||
139 | |||
140 | 46 | /** |
|
141 | * @param BufferInterface $messageHash |
||
142 | 46 | * @param PrivateKeyInterface $privateKey |
|
143 | 46 | * @param RbgInterface $rbg |
|
144 | * @return SignatureInterface |
||
145 | 46 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
|
146 | 46 | */ |
|
147 | 46 | public function sign(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
152 | 46 | ||
153 | /** |
||
154 | * @param BufferInterface $messageHash |
||
155 | * @param CompactSignatureInterface $signature |
||
156 | 46 | * @return PublicKey |
|
157 | 46 | * @throws \Exception |
|
158 | 46 | */ |
|
159 | 46 | public function recover(BufferInterface $messageHash, CompactSignatureInterface $signature) |
|
216 | 17 | ||
217 | 17 | /** |
|
218 | * Attempt to calculate the public key recovery param by trial and error |
||
219 | * |
||
220 | 17 | * @param \GMP $r |
|
221 | * @param \GMP $s |
||
222 | * @param BufferInterface $messageHash |
||
223 | 17 | * @param PublicKey $publicKey |
|
224 | 17 | * @return int |
|
225 | 9 | * @throws \Exception |
|
226 | 3 | */ |
|
227 | public function calcPubKeyRecoveryParam(\GMP $r, \GMP $s, BufferInterface $messageHash, PublicKey $publicKey) |
||
243 | |||
244 | 17 | /** |
|
245 | 17 | * @param BufferInterface $messageHash |
|
246 | 17 | * @param PrivateKey $privateKey |
|
247 | * @param RbgInterface|null $rbg |
||
248 | * @return CompactSignature |
||
249 | 17 | * @throws \Exception |
|
250 | 17 | */ |
|
251 | 17 | private function doSignCompact(BufferInterface $messageHash, PrivateKey $privateKey, RbgInterface $rbg = null) |
|
265 | |||
266 | /** |
||
267 | * @param PrivateKeyInterface $privateKey |
||
268 | * @param BufferInterface $messageHash |
||
269 | * @param RbgInterface $rbg |
||
270 | * @return CompactSignature |
||
271 | */ |
||
272 | 15 | public function signCompact(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
277 | 15 | ||
278 | 12 | /** |
|
279 | 12 | * @param BufferInterface $privateKey |
|
280 | * @return bool |
||
281 | 5 | */ |
|
282 | 3 | public function validatePrivateKey(BufferInterface $privateKey) |
|
288 | |||
289 | /** |
||
290 | * @param \GMP $element |
||
291 | * @param bool $half |
||
292 | * @return bool |
||
293 | */ |
||
294 | public function validateSignatureElement(\GMP $element, $half = false) |
||
304 | 12 | ||
305 | 12 | /** |
|
306 | 12 | * @param BufferInterface $publicKey |
|
307 | 12 | * @return PublicKeyInterface |
|
308 | 6 | * @throws \Exception |
|
309 | */ |
||
310 | public function publicKeyFromBuffer(BufferInterface $publicKey) |
||
340 | } |
||
341 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.