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 | */ |
||
38 | 19 | public function __construct(Math $math, GeneratorPoint $generator) |
|
39 | { |
||
40 | 19 | $this->math = $math; |
|
41 | 19 | $this->generator = $generator; |
|
42 | 19 | } |
|
43 | |||
44 | /** |
||
45 | * @return Math |
||
46 | */ |
||
47 | 614 | public function getMath() |
|
48 | { |
||
49 | 614 | return $this->math; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return GeneratorPoint |
||
54 | */ |
||
55 | 169 | public function getGenerator() |
|
56 | { |
||
57 | 169 | return $this->generator; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param \GMP $scalar |
||
62 | * @param bool|false $compressed |
||
63 | * @return PrivateKey |
||
64 | */ |
||
65 | 125 | public function getPrivateKey(\GMP $scalar, $compressed = false) |
|
66 | { |
||
67 | 125 | return new PrivateKey($this, $scalar, $compressed); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param PointInterface $point |
||
72 | * @param bool|false $compressed |
||
73 | * @return PublicKey |
||
74 | */ |
||
75 | 105 | public function getPublicKey(PointInterface $point, $compressed = false) |
|
76 | { |
||
77 | 105 | return new PublicKey($this, $point, $compressed); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param \GMP $r |
||
82 | * @param \GMP $s |
||
83 | * @return Signature |
||
84 | */ |
||
85 | public function getSignature(\GMP $r, \GMP $s) |
||
86 | { |
||
87 | return new Signature($this, $r, $s); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param BufferInterface $messageHash |
||
92 | * @param PublicKey $publicKey |
||
93 | * @param Signature $signature |
||
94 | * @return bool |
||
95 | */ |
||
96 | 47 | private function doVerify(BufferInterface $messageHash, PublicKey $publicKey, Signature $signature) |
|
102 | |||
103 | /** |
||
104 | * @param BufferInterface $messageHash |
||
105 | * @param PublicKeyInterface $publicKey |
||
106 | * @param SignatureInterface $signature |
||
107 | * @return bool |
||
108 | */ |
||
109 | 47 | public function verify(BufferInterface $messageHash, PublicKeyInterface $publicKey, SignatureInterface $signature) |
|
115 | |||
116 | /** |
||
117 | * @param BufferInterface $messageHash |
||
118 | * @param PrivateKey $privateKey |
||
119 | * @param RbgInterface|null $rbg |
||
120 | * @return Signature |
||
121 | */ |
||
122 | 46 | private function doSign(BufferInterface $messageHash, PrivateKey $privateKey, RbgInterface $rbg = null) |
|
139 | |||
140 | /** |
||
141 | * @param BufferInterface $messageHash |
||
142 | * @param PrivateKeyInterface $privateKey |
||
143 | * @param RbgInterface $rbg |
||
144 | * @return SignatureInterface |
||
145 | * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure |
||
146 | */ |
||
147 | 46 | public function sign(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
152 | |||
153 | /** |
||
154 | * @param BufferInterface $messageHash |
||
155 | * @param CompactSignatureInterface $signature |
||
156 | * @return PublicKey |
||
157 | * @throws \Exception |
||
158 | */ |
||
159 | 17 | public function recover(BufferInterface $messageHash, CompactSignatureInterface $signature) |
|
216 | |||
217 | /** |
||
218 | * Attempt to calculate the public key recovery param by trial and error |
||
219 | * |
||
220 | * @param \GMP $r |
||
221 | * @param \GMP $s |
||
222 | * @param BufferInterface $messageHash |
||
223 | * @param PublicKey $publicKey |
||
224 | * @return int |
||
225 | * @throws \Exception |
||
226 | */ |
||
227 | 15 | public function calcPubKeyRecoveryParam(\GMP $r, \GMP $s, BufferInterface $messageHash, PublicKey $publicKey) |
|
243 | |||
244 | /** |
||
245 | * @param BufferInterface $messageHash |
||
246 | * @param PrivateKey $privateKey |
||
247 | * @param RbgInterface|null $rbg |
||
248 | * @return CompactSignature |
||
249 | * @throws \Exception |
||
250 | */ |
||
251 | 12 | 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 | 12 | public function signCompact(BufferInterface $messageHash, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
277 | |||
278 | /** |
||
279 | * @param BufferInterface $privateKey |
||
280 | * @return bool |
||
281 | */ |
||
282 | 129 | public function validatePrivateKey(BufferInterface $privateKey) |
|
288 | |||
289 | /** |
||
290 | * @param \GMP $element |
||
291 | * @param bool $half |
||
292 | * @return bool |
||
293 | */ |
||
294 | 50 | public function validateSignatureElement(\GMP $element, $half = false) |
|
304 | |||
305 | /** |
||
306 | * @param BufferInterface $publicKey |
||
307 | * @return PublicKeyInterface |
||
308 | * @throws \Exception |
||
309 | */ |
||
310 | 158 | 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.