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 | 372 | public function __construct(EcAdapter $ecAdapter, $secp256k1_pubkey_t, $compressed = false) |
|
35 | { |
||
36 | 372 | if (!is_resource($secp256k1_pubkey_t) || |
|
37 | 372 | !get_resource_type($secp256k1_pubkey_t) === SECP256K1_TYPE_PUBKEY) { |
|
38 | throw new \InvalidArgumentException('Secp256k1\Key\PublicKey expects ' . SECP256K1_TYPE_PUBKEY . ' resource'); |
||
39 | } |
||
40 | |||
41 | 372 | if (false === is_bool($compressed)) { |
|
42 | throw new \InvalidArgumentException('PublicKey: Compressed must be a boolean'); |
||
43 | } |
||
44 | |||
45 | 372 | $this->ecAdapter = $ecAdapter; |
|
46 | 372 | $this->pubkey_t = $secp256k1_pubkey_t; |
|
47 | 372 | $this->compressed = $compressed; |
|
48 | 372 | } |
|
49 | |||
50 | /** |
||
51 | * @param BufferInterface $msg32 |
||
52 | * @param SignatureInterface $signature |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function verify(BufferInterface $msg32, SignatureInterface $signature) |
||
56 | { |
||
57 | return $this->ecAdapter->verify($msg32, $this, $signature); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return bool|false |
||
62 | */ |
||
63 | 351 | public function isCompressed() |
|
67 | |||
68 | /** |
||
69 | * @return resource |
||
70 | */ |
||
71 | 303 | public function getResource() |
|
75 | |||
76 | /** |
||
77 | * @return resource |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | 9 | private function clonePubkey() |
|
96 | |||
97 | /** |
||
98 | * @param int $tweak |
||
99 | * @return PublicKey |
||
100 | * @throws \Exception |
||
101 | */ |
||
102 | 6 | public function tweakAdd($tweak) |
|
115 | |||
116 | /** |
||
117 | * @param int $tweak |
||
118 | * @return PublicKey |
||
119 | * @throws \Exception |
||
120 | */ |
||
121 | 3 | public function tweakMul($tweak) |
|
134 | |||
135 | /** |
||
136 | * @return BufferInterface |
||
137 | */ |
||
138 | 294 | public function getBuffer() |
|
142 | } |
||
143 |