1 | <?php |
||
20 | class HierarchicalKey |
||
21 | { |
||
22 | /** |
||
23 | * @var EcAdapterInterface |
||
24 | */ |
||
25 | private $ecAdapter; |
||
26 | |||
27 | /** |
||
28 | * @var int |
||
29 | */ |
||
30 | private $depth; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | private $parentFingerprint; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $sequence; |
||
41 | |||
42 | /** |
||
43 | * @var BufferInterface |
||
44 | */ |
||
45 | private $chainCode; |
||
46 | |||
47 | /** |
||
48 | * @var PublicKeyInterface|PrivateKeyInterface |
||
49 | */ |
||
50 | private $key; |
||
51 | |||
52 | /** |
||
53 | * @param EcAdapterInterface $ecAdapter |
||
54 | * @param int $depth |
||
55 | * @param int $parentFingerprint |
||
56 | * @param int $sequence |
||
57 | * @param BufferInterface $chainCode |
||
58 | * @param KeyInterface $key |
||
59 | * @throws \Exception |
||
60 | 150 | */ |
|
61 | 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 | 66 | */ |
|
84 | 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 | 36 | */ |
|
96 | public function getSequence() |
||
100 | |||
101 | /** |
||
102 | * Get the fingerprint of the parent key. For master keys, this is 00000000. |
||
103 | * |
||
104 | * @return string |
||
105 | 36 | */ |
|
106 | public function getFingerprint() |
||
114 | |||
115 | /** |
||
116 | * Return the fingerprint to be used for child keys. |
||
117 | * @return int |
||
118 | 42 | */ |
|
119 | 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 | 48 | */ |
|
130 | public function getChainCode() |
||
134 | |||
135 | /** |
||
136 | * @return PrivateKeyInterface |
||
137 | 78 | */ |
|
138 | public function getPrivateKey() |
||
146 | |||
147 | /** |
||
148 | * Get the public key the private key or public key. |
||
149 | * |
||
150 | * @return PublicKeyInterface |
||
151 | 84 | */ |
|
152 | public function getPublicKey() |
||
160 | |||
161 | /** |
||
162 | * @return HierarchicalKey |
||
163 | 24 | */ |
|
164 | public function toPublic() |
||
172 | |||
173 | /** |
||
174 | * Return whether this is a private key |
||
175 | * |
||
176 | * @return bool |
||
177 | 96 | */ |
|
178 | public function isPrivate() |
||
182 | |||
183 | /** |
||
184 | * Return whether the key is hardened |
||
185 | * |
||
186 | * @return bool |
||
187 | 6 | */ |
|
188 | 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 | 42 | */ |
|
200 | public function getHmacSeed($sequence) |
||
220 | |||
221 | /** |
||
222 | * Derive a child key |
||
223 | 42 | * |
|
224 | * @param int $sequence |
||
225 | 42 | * @return HierarchicalKey |
|
226 | 36 | * @throws \Exception |
|
227 | 36 | */ |
|
228 | public function deriveChild($sequence) |
||
250 | 18 | ||
251 | /** |
||
252 | 18 | * @param array|\stdClass|\Traversable $list |
|
253 | * @return HierarchicalKey |
||
254 | */ |
||
255 | public function deriveFromList($list) |
||
268 | |||
269 | /** |
||
270 | * Decodes a BIP32 path into actual 32bit sequence numbers and derives the child key |
||
271 | 18 | * |
|
272 | * @param string $path |
||
273 | 18 | * @return HierarchicalKey |
|
274 | 18 | * @throws \Exception |
|
275 | */ |
||
276 | public function derivePath($path) |
||
281 | |||
282 | 30 | /** |
|
283 | * Serializes the instance according to whether it wraps a private or public key. |
||
284 | 30 | * @param NetworkInterface $network |
|
285 | * @return string |
||
286 | 30 | */ |
|
287 | 30 | public function toExtendedKey(NetworkInterface $network = null) |
|
295 | |||
296 | /** |
||
297 | * Explicitly serialize as a private key. Throws an exception if |
||
298 | 30 | * the key isn't private. |
|
299 | * |
||
300 | 30 | * @param NetworkInterface $network |
|
301 | 6 | * @return string |
|
302 | */ |
||
303 | public function toExtendedPrivateKey(NetworkInterface $network = null) |
||
311 | |||
312 | /** |
||
313 | 24 | * Explicitly serialize as a public key. This will always work. |
|
314 | * |
||
315 | 24 | * @param NetworkInterface $network |
|
316 | 24 | * @return string |
|
317 | */ |
||
318 | public function toExtendedPublicKey(NetworkInterface $network = null) |
||
323 | } |
||
324 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..