1 | <?php |
||
17 | class PrivateKey extends Key implements PrivateKeyInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var int|string |
||
21 | */ |
||
22 | private $secretMultiplier; |
||
23 | |||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | private $compressed; |
||
28 | |||
29 | /** |
||
30 | * @var PublicKey |
||
31 | */ |
||
32 | private $publicKey; |
||
33 | |||
34 | /** |
||
35 | * @var EcAdapter |
||
36 | */ |
||
37 | private $ecAdapter; |
||
38 | |||
39 | /** |
||
40 | * @param EcAdapter $ecAdapter |
||
41 | * @param $int |
||
42 | * @param bool $compressed |
||
43 | * @throws InvalidPrivateKey |
||
44 | */ |
||
45 | 65 | public function __construct(EcAdapter $ecAdapter, $int, $compressed = false) |
|
58 | |||
59 | /** |
||
60 | * @return int|string |
||
61 | */ |
||
62 | 56 | public function getSecretMultiplier() |
|
66 | |||
67 | /** |
||
68 | * @param BufferInterface $msg32 |
||
69 | * @param RbgInterface|null $rbg |
||
70 | * @return \BitWasp\Bitcoin\Crypto\EcAdapter\Signature\SignatureInterface |
||
71 | */ |
||
72 | public function sign(BufferInterface $msg32, RbgInterface $rbg = null) |
||
76 | |||
77 | /** |
||
78 | * @param int|string $tweak |
||
79 | * @return PrivateKeyInterface |
||
80 | */ |
||
81 | 7 | public function tweakAdd($tweak) |
|
82 | { |
||
83 | 7 | $adapter = $this->ecAdapter; |
|
84 | 7 | return $adapter->getPrivateKey( |
|
85 | $adapter |
||
86 | 7 | ->getMath() |
|
87 | 7 | ->getModularArithmetic( |
|
88 | $adapter |
||
89 | 7 | ->getGenerator() |
|
90 | 7 | ->getOrder() |
|
91 | ) |
||
92 | 7 | ->add( |
|
93 | $tweak, |
||
94 | 7 | $this->getSecretMultiplier() |
|
95 | ), |
||
96 | 7 | $this->compressed |
|
97 | ); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param int|string $tweak |
||
102 | * @return PrivateKeyInterface |
||
103 | */ |
||
104 | 1 | public function tweakMul($tweak) |
|
105 | { |
||
106 | 1 | $adapter = $this->ecAdapter; |
|
107 | 1 | return $adapter->getPrivateKey( |
|
108 | $adapter |
||
109 | 1 | ->getMath() |
|
110 | 1 | ->getModularArithmetic( |
|
111 | $adapter |
||
112 | 1 | ->getGenerator() |
|
113 | 1 | ->getOrder() |
|
114 | ) |
||
115 | 1 | ->mul( |
|
116 | $tweak, |
||
117 | 1 | $this->getSecretMultiplier() |
|
118 | ), |
||
119 | 1 | $this->compressed |
|
120 | ); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * {@inheritDoc} |
||
125 | */ |
||
126 | 33 | public function isCompressed() |
|
130 | |||
131 | /** |
||
132 | * Return the public key |
||
133 | * |
||
134 | * @return PublicKey |
||
135 | */ |
||
136 | 67 | public function getPublicKey() |
|
150 | |||
151 | /** |
||
152 | * @param NetworkInterface $network |
||
153 | * @return string |
||
154 | */ |
||
155 | 3 | public function toWif(NetworkInterface $network = null) |
|
156 | { |
||
157 | 3 | $network = $network ?: Bitcoin::getNetwork(); |
|
158 | 3 | $serializer = new WifPrivateKeySerializer( |
|
159 | 3 | $this->ecAdapter->getMath(), |
|
160 | 3 | new PrivateKeySerializer($this->ecAdapter) |
|
161 | ); |
||
162 | |||
163 | 3 | return $serializer->serialize($network, $this); |
|
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return \BitWasp\Buffertools\BufferInterface |
||
168 | */ |
||
169 | 33 | public function getBuffer() |
|
173 | } |
||
174 |