1 | <?php |
||
12 | class ElectrumKey |
||
13 | { |
||
14 | /** |
||
15 | * @var EcAdapterInterface |
||
16 | */ |
||
17 | private $ecAdapter; |
||
18 | |||
19 | /** |
||
20 | * @var null|PrivateKeyInterface |
||
21 | */ |
||
22 | private $masterPrivate; |
||
23 | |||
24 | /** |
||
25 | * @var PublicKeyInterface |
||
26 | */ |
||
27 | private $masterPublic; |
||
28 | |||
29 | /** |
||
30 | * @param EcAdapterInterface $ecAdapter |
||
31 | * @param KeyInterface $masterKey |
||
32 | */ |
||
33 | 8 | public function __construct(EcAdapterInterface $ecAdapter, KeyInterface $masterKey) |
|
34 | { |
||
35 | 8 | if ($masterKey->isCompressed()) { |
|
36 | 2 | throw new \RuntimeException('Electrum keys are not compressed'); |
|
37 | } |
||
38 | |||
39 | 8 | if ($masterKey instanceof PrivateKeyInterface) { |
|
40 | 6 | $this->masterPrivate = $masterKey; |
|
41 | 6 | $this->masterPublic = $masterKey->getPublicKey(); |
|
42 | 4 | } elseif ($masterKey instanceof PublicKeyInterface) { |
|
43 | 4 | $this->masterPublic = $masterKey; |
|
44 | } |
||
45 | |||
46 | 8 | $this->ecAdapter = $ecAdapter; |
|
47 | 8 | } |
|
48 | |||
49 | /** |
||
50 | * @return PrivateKeyInterface |
||
51 | */ |
||
52 | 4 | public function getMasterPrivateKey() |
|
53 | { |
||
54 | 4 | if (null === $this->masterPrivate) { |
|
55 | 2 | throw new \RuntimeException("Cannot produce master private key from master public key"); |
|
56 | } |
||
57 | |||
58 | 2 | return $this->masterPrivate; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return PublicKeyInterface |
||
63 | */ |
||
64 | 2 | public function getMasterPublicKey() |
|
68 | |||
69 | /** |
||
70 | * @return Buffer |
||
71 | */ |
||
72 | 2 | public function getMPK() |
|
76 | |||
77 | /** |
||
78 | * @param int $sequence |
||
79 | * @param bool $change |
||
80 | * @return \GMP |
||
81 | */ |
||
82 | 2 | public function getSequenceOffset($sequence, $change = false) |
|
87 | |||
88 | /** |
||
89 | * @param int $sequence |
||
90 | * @param bool $change |
||
91 | * @return PrivateKeyInterface|PublicKeyInterface |
||
92 | */ |
||
93 | 2 | public function deriveChild($sequence, $change = false) |
|
98 | } |
||
99 |