1 | <?php |
||
23 | class PrivateKey extends Key implements PrivateKeyInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var \GMP |
||
27 | */ |
||
28 | private $secret; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $secretBin; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $compressed; |
||
39 | |||
40 | /** |
||
41 | * @var PublicKey |
||
42 | */ |
||
43 | private $publicKey; |
||
44 | |||
45 | /** |
||
46 | * @var EcAdapter |
||
47 | */ |
||
48 | private $ecAdapter; |
||
49 | |||
50 | /** |
||
51 | * @param EcAdapter $adapter |
||
52 | * @param \GMP $secret |
||
53 | * @param bool|false $compressed |
||
54 | * @throws \Exception |
||
55 | */ |
||
56 | 91 | public function __construct(EcAdapter $adapter, \GMP $secret, bool $compressed = false) |
|
72 | |||
73 | /** |
||
74 | * @param BufferInterface $msg32 |
||
75 | * @param RbgInterface|null $rbgInterface |
||
76 | * @return Signature |
||
77 | */ |
||
78 | 69 | public function sign(BufferInterface $msg32, RbgInterface $rbgInterface = null): Signature |
|
99 | |||
100 | /** |
||
101 | * @param BufferInterface $msg32 |
||
102 | * @param RbgInterface|null $rbfInterface |
||
103 | * @return CompactSignature |
||
104 | */ |
||
105 | 5 | public function signCompact(BufferInterface $msg32, RbgInterface $rbfInterface = null): CompactSignatureInterface |
|
131 | |||
132 | /** |
||
133 | * @return bool |
||
134 | */ |
||
135 | 75 | public function isCompressed(): bool |
|
139 | |||
140 | /** |
||
141 | * @return \GMP |
||
142 | */ |
||
143 | 3 | public function getSecret() |
|
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | 102 | public function getSecretBinary(): string |
|
155 | |||
156 | /** |
||
157 | * @return PublicKey |
||
158 | */ |
||
159 | 127 | public function getPublicKey() |
|
174 | |||
175 | /** |
||
176 | * @param \GMP $tweak |
||
177 | * @return KeyInterface |
||
178 | */ |
||
179 | 18 | public function tweakAdd(\GMP $tweak): KeyInterface |
|
180 | { |
||
181 | 18 | $adapter = $this->ecAdapter; |
|
182 | 18 | $math = $adapter->getMath(); |
|
183 | 18 | $context = $adapter->getContext(); |
|
184 | 18 | $privateKey = $this->getBinary(); // mod by reference |
|
185 | 18 | $tweak = Buffer::int($math->toString($tweak), 32)->getBinary(); |
|
186 | 18 | $ret = \secp256k1_ec_privkey_tweak_add( |
|
187 | 18 | $context, |
|
188 | 18 | $privateKey, |
|
189 | 18 | $tweak |
|
190 | ); |
||
191 | |||
192 | 18 | if ($ret !== 1) { |
|
193 | throw new \RuntimeException('Secp256k1 privkey tweak add: failed'); |
||
194 | } |
||
195 | |||
196 | 18 | $secret = new Buffer($privateKey); |
|
197 | 18 | return $adapter->getPrivateKey($secret->getGmp(), $this->compressed); |
|
198 | } |
||
199 | |||
200 | /** |
||
201 | * @param \GMP $tweak |
||
202 | * @return KeyInterface |
||
203 | */ |
||
204 | 1 | public function tweakMul(\GMP $tweak): KeyInterface |
|
205 | { |
||
206 | 1 | $privateKey = $this->getBinary(); |
|
207 | 1 | $math = $this->ecAdapter->getMath(); |
|
208 | 1 | $tweak = Buffer::int($math->toString($tweak), 32)->getBinary(); |
|
209 | 1 | $ret = \secp256k1_ec_privkey_tweak_mul( |
|
210 | 1 | $this->ecAdapter->getContext(), |
|
211 | 1 | $privateKey, |
|
212 | 1 | $tweak |
|
213 | ); |
||
214 | |||
215 | 1 | if ($ret !== 1) { |
|
216 | throw new \RuntimeException('Secp256k1 privkey tweak mul: failed'); |
||
217 | } |
||
218 | |||
219 | 1 | $secret = new Buffer($privateKey); |
|
220 | |||
221 | 1 | return $this->ecAdapter->getPrivateKey($secret->getGmp(), $this->compressed); |
|
222 | } |
||
223 | |||
224 | /** |
||
225 | * @param NetworkInterface $network |
||
226 | * @return string |
||
227 | */ |
||
228 | 5 | public function toWif(NetworkInterface $network = null): string |
|
234 | |||
235 | /** |
||
236 | * @return BufferInterface |
||
237 | */ |
||
238 | 100 | public function getBuffer(): BufferInterface |
|
242 | } |
||
243 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: