1 | <?php |
||
12 | class PublicKey extends Key implements PublicKeyInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var EcAdapter |
||
16 | */ |
||
17 | private $ecAdapter; |
||
18 | |||
19 | /** |
||
20 | * @var bool|false |
||
21 | */ |
||
22 | private $compressed; |
||
23 | |||
24 | /** |
||
25 | * @var resource |
||
26 | */ |
||
27 | private $pubkey_t; |
||
28 | |||
29 | /** |
||
30 | * @param EcAdapter $ecAdapter |
||
31 | * @param resource $secp256k1_pubkey_t |
||
32 | * @param bool|false $compressed |
||
33 | */ |
||
34 | 195 | public function __construct(EcAdapter $ecAdapter, $secp256k1_pubkey_t, $compressed = false) |
|
49 | |||
50 | /** |
||
51 | * @param Buffer $msg32 |
||
52 | * @param SignatureInterface $signature |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function verify(Buffer $msg32, SignatureInterface $signature) |
||
59 | |||
60 | /** |
||
61 | * @return bool|false |
||
62 | */ |
||
63 | 183 | public function isCompressed() |
|
67 | |||
68 | /** |
||
69 | * @return resource |
||
70 | */ |
||
71 | 189 | public function getResource() |
|
75 | |||
76 | /** |
||
77 | * @return resource |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | 9 | private function clonePubkey() |
|
97 | |||
98 | /** |
||
99 | * @param int $tweak |
||
100 | * @return PublicKey |
||
101 | * @throws \Exception |
||
102 | */ |
||
103 | 6 | public function tweakAdd($tweak) |
|
104 | { |
||
105 | 6 | $context = $this->ecAdapter->getContext(); |
|
106 | 6 | $math = $this->ecAdapter->getMath(); |
|
107 | 6 | $bin = pack('H*', str_pad($math->decHex($tweak), 64, '0', STR_PAD_LEFT)); |
|
108 | |||
109 | 6 | $clone = $this->clonePubkey(); |
|
110 | if (1 !== secp256k1_ec_pubkey_tweak_add($context, $clone, $bin)) { |
||
111 | throw new \RuntimeException('Secp256k1: tweak add failed.'); |
||
112 | } |
||
113 | |||
114 | return new PublicKey($this->ecAdapter, $clone, $this->compressed); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param int $tweak |
||
119 | * @return PublicKey |
||
120 | * @throws \Exception |
||
121 | */ |
||
122 | 3 | public function tweakMul($tweak) |
|
123 | { |
||
124 | 3 | $context = $this->ecAdapter->getContext(); |
|
125 | 3 | $math = $this->ecAdapter->getMath(); |
|
126 | 3 | $bin = pack('H*', str_pad($math->decHex($tweak), 64, '0', STR_PAD_LEFT)); |
|
127 | |||
128 | 3 | $clone = $this->clonePubkey(); |
|
129 | if (1 !== secp256k1_ec_pubkey_tweak_mul($context, $clone, $bin)) { |
||
130 | throw new \RuntimeException('Secp256k1: tweak mul failed.'); |
||
131 | } |
||
132 | |||
133 | return new PublicKey($this->ecAdapter, $clone, $this->compressed); |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @return Buffer |
||
138 | */ |
||
139 | 180 | public function getBuffer() |
|
143 | } |
||
144 |
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: