1 | <?php |
||
19 | class EcAdapter implements EcAdapterInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var Math |
||
23 | */ |
||
24 | private $math; |
||
25 | |||
26 | /** |
||
27 | * @var GeneratorPoint |
||
28 | */ |
||
29 | private $generator; |
||
30 | |||
31 | /** |
||
32 | * @var resource |
||
33 | */ |
||
34 | private $context; |
||
35 | |||
36 | /** |
||
37 | * @param Math $math |
||
38 | * @param GeneratorPoint $generator |
||
39 | * @param resource $secp256k1_context_t |
||
40 | */ |
||
41 | 33 | public function __construct(Math $math, GeneratorPoint $generator, $secp256k1_context_t) |
|
50 | |||
51 | /** |
||
52 | * @return Math |
||
53 | */ |
||
54 | 783 | public function getMath() |
|
58 | |||
59 | /** |
||
60 | * @return GeneratorPoint |
||
61 | */ |
||
62 | 48 | public function getGenerator() |
|
66 | |||
67 | /** |
||
68 | * @param Buffer $privateKey |
||
69 | * @return bool |
||
70 | */ |
||
71 | 231 | public function validatePrivateKey(Buffer $privateKey) |
|
75 | |||
76 | /** |
||
77 | * @param array $signatures |
||
78 | * @param Buffer $messageHash |
||
79 | * @param \BitWasp\Bitcoin\Crypto\EcAdapter\Key\PublicKeyInterface[] $publicKeys |
||
80 | * @return array |
||
81 | */ |
||
82 | public function associateSigs(array $signatures, Buffer $messageHash, array $publicKeys) |
||
83 | { |
||
84 | $sigCount = count($signatures); |
||
85 | $linked = []; |
||
86 | foreach ($signatures as $c => $signature) { |
||
87 | foreach ($publicKeys as $key) { |
||
88 | $verify = $this->verify($messageHash, $key, $signature); |
||
89 | if ($verify) { |
||
90 | $linked[$key->getPubKeyHash()->getHex()][] = $signature; |
||
91 | if (count($linked) === $sigCount) { |
||
92 | break 2; |
||
93 | } else { |
||
94 | break; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | return $linked; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param int|string $element |
||
104 | * @param bool $half |
||
105 | * @return bool |
||
106 | */ |
||
107 | 9 | public function validateSignatureElement($element, $half = false) |
|
117 | |||
118 | /** |
||
119 | * @param int|string $int |
||
120 | * @param bool|false $compressed |
||
121 | * @return PrivateKey |
||
122 | */ |
||
123 | 225 | public function getPrivateKey($int, $compressed = false) |
|
127 | |||
128 | /** |
||
129 | * @return resource |
||
130 | */ |
||
131 | 429 | public function getContext() |
|
135 | |||
136 | /** |
||
137 | * @param Buffer $msg32 |
||
138 | * @param PrivateKey $privateKey |
||
139 | * @return Signature |
||
140 | */ |
||
141 | 27 | private function doSign(Buffer $msg32, PrivateKey $privateKey) |
|
160 | |||
161 | /** |
||
162 | * @param Buffer $msg32 |
||
163 | * @param PrivateKeyInterface $privateKey |
||
164 | * @param RbgInterface|null $rbg |
||
165 | * @return Signature |
||
166 | */ |
||
167 | 27 | public function sign(Buffer $msg32, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
172 | |||
173 | /** |
||
174 | * @param Buffer $msg32 |
||
175 | * @param PublicKey $publicKey |
||
176 | * @param Signature $signature |
||
177 | * @return bool |
||
178 | */ |
||
179 | 9 | private function doVerify(Buffer $msg32, PublicKey $publicKey, Signature $signature) |
|
183 | |||
184 | /** |
||
185 | * @param Buffer $msg32 |
||
186 | * @param PublicKeyInterface $publicKey |
||
187 | * @param SignatureInterface $signature |
||
188 | * @return bool |
||
189 | */ |
||
190 | 9 | public function verify(Buffer $msg32, PublicKeyInterface $publicKey, SignatureInterface $signature) |
|
196 | |||
197 | /** |
||
198 | * @param Buffer $msg32 |
||
199 | * @param CompactSignature $compactSig |
||
200 | * @return PublicKey |
||
201 | */ |
||
202 | 21 | private function doRecover(Buffer $msg32, CompactSignature $compactSig) |
|
214 | |||
215 | /** |
||
216 | * @param Buffer $msg32 |
||
217 | * @param CompactSignatureInterface $compactSig |
||
218 | * @return PublicKey |
||
219 | */ |
||
220 | 21 | public function recover(Buffer $msg32, CompactSignatureInterface $compactSig) |
|
225 | |||
226 | /** |
||
227 | * @param Buffer $msg32 |
||
228 | * @param PrivateKey $privateKey |
||
229 | * @return CompactSignature |
||
230 | */ |
||
231 | 18 | private function doSignCompact(Buffer $msg32, PrivateKey $privateKey) |
|
253 | |||
254 | /** |
||
255 | * @param Buffer $msg32 |
||
256 | * @param PrivateKeyInterface $privateKey |
||
257 | * @param RbgInterface|null $rbg |
||
258 | * @return CompactSignatureInterface |
||
259 | */ |
||
260 | 18 | public function signCompact(Buffer $msg32, PrivateKeyInterface $privateKey, RbgInterface $rbg = null) |
|
265 | } |
||
266 |
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.