1 | <?php |
||
13 | class PublicKey extends Key implements PublicKeyInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var EcAdapter |
||
17 | */ |
||
18 | private $ecAdapter; |
||
19 | |||
20 | /** |
||
21 | * @var bool|false |
||
22 | */ |
||
23 | private $compressed; |
||
24 | |||
25 | /** |
||
26 | * @var resource |
||
27 | */ |
||
28 | private $pubkey_t; |
||
29 | |||
30 | /** |
||
31 | * @param EcAdapter $ecAdapter |
||
32 | * @param resource $secp256k1_pubkey_t |
||
33 | * @param bool|false $compressed |
||
34 | */ |
||
35 | public function __construct(EcAdapter $ecAdapter, $secp256k1_pubkey_t, $compressed = false) |
||
36 | { |
||
37 | if (!is_resource($secp256k1_pubkey_t) || |
||
38 | !get_resource_type($secp256k1_pubkey_t) === SECP256K1_TYPE_PUBKEY) { |
||
39 | throw new \InvalidArgumentException('Secp256k1\Key\PublicKey expects ' . SECP256K1_TYPE_PUBKEY . ' resource'); |
||
40 | } |
||
41 | |||
42 | if (false === is_bool($compressed)) { |
||
43 | throw new \InvalidArgumentException('PublicKey: Compressed must be a boolean'); |
||
44 | } |
||
45 | |||
46 | $this->ecAdapter = $ecAdapter; |
||
47 | $this->pubkey_t = $secp256k1_pubkey_t; |
||
48 | $this->compressed = $compressed; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param BufferInterface $msg32 |
||
53 | * @param SignatureInterface $signature |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function verify(BufferInterface $msg32, SignatureInterface $signature) |
||
60 | |||
61 | /** |
||
62 | * @param PublicKey $other |
||
63 | * @return bool |
||
64 | */ |
||
65 | private function doEquals(PublicKey $other) |
||
76 | |||
77 | /** |
||
78 | * @param PublicKeyInterface $other |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function equals(PublicKeyInterface $other) |
||
86 | |||
87 | /** |
||
88 | * @return bool|false |
||
89 | */ |
||
90 | public function isCompressed() |
||
94 | |||
95 | /** |
||
96 | * @return resource |
||
97 | */ |
||
98 | public function getResource() |
||
102 | |||
103 | /** |
||
104 | * @return resource |
||
105 | * @throws \Exception |
||
106 | */ |
||
107 | private function clonePubkey() |
||
123 | |||
124 | /** |
||
125 | * @param \GMP $tweak |
||
126 | * @return PublicKey |
||
127 | * @throws \Exception |
||
128 | */ |
||
129 | public function tweakAdd(\GMP $tweak) |
||
141 | |||
142 | /** |
||
143 | * @param \GMP $tweak |
||
144 | * @return PublicKey |
||
145 | * @throws \Exception |
||
146 | */ |
||
147 | public function tweakMul(\GMP $tweak) |
||
159 | |||
160 | /** |
||
161 | * @return BufferInterface |
||
162 | */ |
||
163 | public function getBuffer() |
||
167 | } |
||
168 |