1 | <?php |
||
24 | class EcAdapter implements EcAdapterInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var Math |
||
28 | */ |
||
29 | private $math; |
||
30 | |||
31 | /** |
||
32 | * @var GeneratorPoint |
||
33 | */ |
||
34 | private $generator; |
||
35 | |||
36 | /** |
||
37 | * @param Math $math |
||
38 | * @param GeneratorPoint $generator |
||
39 | */ |
||
40 | 4 | public function __construct(Math $math, GeneratorPoint $generator) |
|
45 | |||
46 | /** |
||
47 | * @return Math |
||
48 | */ |
||
49 | 1357 | public function getMath(): Math |
|
53 | |||
54 | /** |
||
55 | * @return GeneratorPoint |
||
56 | */ |
||
57 | 194 | public function getGenerator() |
|
61 | |||
62 | /** |
||
63 | * @param \GMP $scalar |
||
64 | * @param bool|false $compressed |
||
65 | * @return PrivateKeyInterface |
||
66 | */ |
||
67 | 40 | public function getPrivateKey(\GMP $scalar, bool $compressed = false): PrivateKeyInterface |
|
71 | |||
72 | /** |
||
73 | * @param PointInterface $point |
||
74 | * @param bool|false $compressed |
||
75 | * @return PublicKey |
||
76 | */ |
||
77 | 55 | public function getPublicKey(PointInterface $point, bool $compressed = false) |
|
81 | |||
82 | /** |
||
83 | * @param \GMP $r |
||
84 | * @param \GMP $s |
||
85 | * @return Signature |
||
86 | */ |
||
87 | public function getSignature(\GMP $r, \GMP $s): SignatureInterface |
||
91 | |||
92 | /** |
||
93 | * @param BufferInterface $messageHash |
||
94 | * @param PublicKey $publicKey |
||
95 | * @param Signature $signature |
||
96 | * @return bool |
||
97 | */ |
||
98 | 155 | private function doVerify(BufferInterface $messageHash, PublicKey $publicKey, Signature $signature) |
|
104 | |||
105 | /** |
||
106 | * @param BufferInterface $messageHash |
||
107 | * @param PublicKeyInterface $publicKey |
||
108 | * @param SignatureInterface $signature |
||
109 | * @return bool |
||
110 | */ |
||
111 | 155 | public function verify(BufferInterface $messageHash, PublicKeyInterface $publicKey, SignatureInterface $signature): bool |
|
117 | |||
118 | /** |
||
119 | * @param BufferInterface $messageHash |
||
120 | * @param PrivateKey $privateKey |
||
121 | * @param RbgInterface|null $rbg |
||
122 | * @return Signature |
||
123 | */ |
||
124 | 33 | private function doSign(BufferInterface $messageHash, PrivateKey $privateKey, RbgInterface $rbg = null): Signature |
|
141 | |||
142 | /** |
||
143 | * @param BufferInterface $messageHash |
||
144 | * @param PrivateKeyInterface $privateKey |
||
145 | * @param RbgInterface $rbg |
||
146 | * @return SignatureInterface |
||
147 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
||
148 | */ |
||
149 | 33 | public function sign(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null): SignatureInterface |
|
154 | |||
155 | /** |
||
156 | * @param BufferInterface $messageHash |
||
157 | * @param CompactSignatureInterface $signature |
||
158 | * @return PublicKeyInterface |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | 7 | public function recover(BufferInterface $messageHash, CompactSignatureInterface $signature): PublicKeyInterface |
|
218 | |||
219 | /** |
||
220 | * Attempt to calculate the public key recovery param by trial and error |
||
221 | * |
||
222 | * @param \GMP $r |
||
223 | * @param \GMP $s |
||
224 | * @param BufferInterface $messageHash |
||
225 | * @param PublicKey $publicKey |
||
226 | * @return int |
||
227 | * @throws \Exception |
||
228 | */ |
||
229 | 6 | public function calcPubKeyRecoveryParam(\GMP $r, \GMP $s, BufferInterface $messageHash, PublicKey $publicKey): int |
|
245 | |||
246 | /** |
||
247 | * @param BufferInterface $messageHash |
||
248 | * @param PrivateKey $privateKey |
||
249 | * @param RbgInterface|null $rbg |
||
250 | * @return CompactSignature |
||
251 | * @throws \Exception |
||
252 | */ |
||
253 | 5 | private function doSignCompact(BufferInterface $messageHash, PrivateKey $privateKey, RbgInterface $rbg = null): CompactSignature |
|
267 | |||
268 | /** |
||
269 | * @param PrivateKeyInterface $privateKey |
||
270 | * @param BufferInterface $messageHash |
||
271 | * @param RbgInterface $rbg |
||
272 | * @return CompactSignatureInterface |
||
273 | */ |
||
274 | 5 | public function signCompact(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null): CompactSignatureInterface |
|
279 | |||
280 | /** |
||
281 | * @param BufferInterface $privateKey |
||
282 | * @return bool |
||
283 | */ |
||
284 | 42 | public function validatePrivateKey(BufferInterface $privateKey): bool |
|
290 | |||
291 | /** |
||
292 | * @param \GMP $element |
||
293 | * @param bool $half |
||
294 | * @return bool |
||
295 | */ |
||
296 | 35 | public function validateSignatureElement(\GMP $element, bool $half = false): bool |
|
306 | |||
307 | /** |
||
308 | * @param BufferInterface $publicKey |
||
309 | * @return PublicKeyInterface |
||
310 | * @throws \Exception |
||
311 | */ |
||
312 | 187 | public function publicKeyFromBuffer(BufferInterface $publicKey): PublicKeyInterface |
|
343 | } |
||
344 |
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.