1 | <?php |
||
19 | class HierarchicalKey |
||
20 | { |
||
21 | /** |
||
22 | * @var EcAdapterInterface |
||
23 | */ |
||
24 | private $ecAdapter; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $depth; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $parentFingerprint; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $sequence; |
||
40 | |||
41 | /** |
||
42 | * @var BufferInterface |
||
43 | */ |
||
44 | private $chainCode; |
||
45 | |||
46 | /** |
||
47 | * @var KeyInterface |
||
48 | */ |
||
49 | private $key; |
||
50 | |||
51 | /** |
||
52 | * @param EcAdapterInterface $ecAdapter |
||
53 | * @param int $depth |
||
54 | * @param int $parentFingerprint |
||
55 | * @param int $sequence |
||
56 | * @param BufferInterface $chainCode |
||
57 | * @param KeyInterface $key |
||
58 | * @throws \Exception |
||
59 | */ |
||
60 | 75 | public function __construct(EcAdapterInterface $ecAdapter, $depth, $parentFingerprint, $sequence, BufferInterface $chainCode, KeyInterface $key) |
|
78 | |||
79 | /** |
||
80 | * Return the depth of this key. This is limited to 256 sequential derivations. |
||
81 | * |
||
82 | * @return int |
||
83 | */ |
||
84 | 33 | public function getDepth() |
|
88 | |||
89 | /** |
||
90 | * Get the sequence number for this address. Hardened keys are |
||
91 | * created with sequence > 0x80000000. a sequence number lower |
||
92 | * than this can be derived with the public key. |
||
93 | * |
||
94 | * @return int |
||
95 | */ |
||
96 | 18 | public function getSequence() |
|
100 | |||
101 | /** |
||
102 | * Get the fingerprint of the parent key. For master keys, this is 00000000. |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | 18 | public function getFingerprint() |
|
114 | |||
115 | /** |
||
116 | * Return the fingerprint to be used for child keys. |
||
117 | * @return int |
||
118 | */ |
||
119 | 21 | public function getChildFingerprint() |
|
123 | |||
124 | /** |
||
125 | * Return the chain code - a deterministic 'salt' for HMAC-SHA512 |
||
126 | * in child derivations |
||
127 | * |
||
128 | * @return BufferInterface |
||
129 | */ |
||
130 | 27 | public function getChainCode() |
|
134 | |||
135 | /** |
||
136 | * @return PrivateKeyInterface |
||
137 | */ |
||
138 | 42 | public function getPrivateKey() |
|
146 | |||
147 | /** |
||
148 | * Get the public key the private key or public key. |
||
149 | * |
||
150 | * @return PublicKey |
||
151 | */ |
||
152 | 42 | public function getPublicKey() |
|
160 | |||
161 | /** |
||
162 | * @return HierarchicalKey |
||
163 | */ |
||
164 | 12 | public function toPublic() |
|
172 | |||
173 | /** |
||
174 | * Return whether this is a private key |
||
175 | * |
||
176 | * @return bool |
||
177 | */ |
||
178 | 48 | public function isPrivate() |
|
182 | |||
183 | /** |
||
184 | * Return whether the key is hardened |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | 3 | public function isHardened() |
|
192 | |||
193 | /** |
||
194 | * Create a buffer containing data to be hashed hashed to yield the child offset |
||
195 | * |
||
196 | * @param int $sequence |
||
197 | * @return BufferInterface |
||
198 | * @throws \Exception |
||
199 | */ |
||
200 | 21 | public function getHmacSeed($sequence) |
|
217 | |||
218 | /** |
||
219 | * Derive a child key |
||
220 | * |
||
221 | * @param int $sequence |
||
222 | * @return HierarchicalKey |
||
223 | * @throws \Exception |
||
224 | */ |
||
225 | 21 | public function deriveChild($sequence) |
|
247 | |||
248 | /** |
||
249 | * @param array|\stdClass|\Traversable $list |
||
250 | * @return HierarchicalKey |
||
251 | */ |
||
252 | 9 | public function deriveFromList($list) |
|
265 | |||
266 | /** |
||
267 | * Decodes a BIP32 path into actual 32bit sequence numbers and derives the child key |
||
268 | * |
||
269 | * @param string $path |
||
270 | * @return HierarchicalKey |
||
271 | * @throws \Exception |
||
272 | */ |
||
273 | 9 | public function derivePath($path) |
|
278 | |||
279 | /** |
||
280 | * Serializes the instance according to whether it wraps a private or public key. |
||
281 | * @param NetworkInterface $network |
||
282 | * @return string |
||
283 | */ |
||
284 | 15 | public function toExtendedKey(NetworkInterface $network = null) |
|
292 | |||
293 | /** |
||
294 | * Explicitly serialize as a private key. Throws an exception if |
||
295 | * the key isn't private. |
||
296 | * |
||
297 | * @param NetworkInterface $network |
||
298 | * @return string |
||
299 | */ |
||
300 | 15 | public function toExtendedPrivateKey(NetworkInterface $network = null) |
|
308 | |||
309 | /** |
||
310 | * Explicitly serialize as a public key. This will always work. |
||
311 | * |
||
312 | * @param NetworkInterface $network |
||
313 | * @return string |
||
314 | */ |
||
315 | 12 | public function toExtendedPublicKey(NetworkInterface $network = null) |
|
320 | } |
||
321 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.