2
2
3
3
namespace AndKom \Bitcoin \Blockchain \Crypto ;
4
4
5
- use AndKom \Bitcoin \Blockchain \Exception \ CryptoException ;
5
+ use AndKom \Bitcoin \Blockchain \Exceptions \ PublicKeyException ;
6
6
use AndKom \Bitcoin \Blockchain \Utils ;
7
7
use Mdanter \Ecc \EccFactory ;
8
8
@@ -57,12 +57,12 @@ public function getX(): \GMP
57
57
58
58
/**
59
59
* @return \GMP
60
- * @throws CryptoException
60
+ * @throws PublicKeyException
61
61
*/
62
62
public function getY (): \GMP
63
63
{
64
64
if ($ this ->isCompressed ()) {
65
- throw new CryptoException ("Compressed public key doesn't have Y coordinate. " );
65
+ throw new PublicKeyException ("Compressed public key doesn't have Y coordinate. " );
66
66
}
67
67
68
68
return $ this ->y ;
@@ -86,12 +86,12 @@ public function isCompressed(): bool
86
86
87
87
/**
88
88
* @return PublicKey
89
- * @throws CryptoException
89
+ * @throws PublicKeyException
90
90
*/
91
91
public function compress (): self
92
92
{
93
93
if ($ this ->isCompressed ()) {
94
- throw new CryptoException ('Public key is already compressed. ' );
94
+ throw new PublicKeyException ('Public key is already compressed. ' );
95
95
}
96
96
97
97
$ wasOdd = gmp_cmp (
@@ -104,12 +104,12 @@ public function compress(): self
104
104
105
105
/**
106
106
* @return PublicKey
107
- * @throws CryptoException
107
+ * @throws PublicKeyException
108
108
*/
109
109
public function decompress (): self
110
110
{
111
111
if (!$ this ->isCompressed ()) {
112
- throw new CryptoException ('Public key is already decompressed. ' );
112
+ throw new PublicKeyException ('Public key is already decompressed. ' );
113
113
}
114
114
115
115
$ curve = EccFactory::getSecgCurves ()->generator256k1 ()->getCurve ();
@@ -120,7 +120,7 @@ public function decompress(): self
120
120
121
121
/**
122
122
* @return \Mdanter\Ecc\Crypto\Key\PublicKey
123
- * @throws CryptoException
123
+ * @throws PublicKeyException
124
124
*/
125
125
public function getEccPublicKey (): \Mdanter \Ecc \Crypto \Key \PublicKey
126
126
{
@@ -142,7 +142,7 @@ public function getEccPublicKey(): \Mdanter\Ecc\Crypto\Key\PublicKey
142
142
/**
143
143
* @param string $data
144
144
* @return PublicKey
145
- * @throws CryptoException
145
+ * @throws PublicKeyException
146
146
*/
147
147
static public function parse (string $ data ): self
148
148
{
@@ -152,7 +152,7 @@ static public function parse(string $data): self
152
152
$ prefix = $ data [0 ];
153
153
154
154
if ($ prefix != static ::PREFIX_COMPRESSED_ODD && $ prefix != static ::PREFIX_COMPRESSED_EVEN ) {
155
- throw new CryptoException ('Invalid compressed public key prefix. ' );
155
+ throw new PublicKeyException ('Invalid compressed public key prefix. ' );
156
156
}
157
157
158
158
$ x = Utils::binToGmp (substr ($ data , 1 , 32 ));
@@ -161,13 +161,13 @@ static public function parse(string $data): self
161
161
$ prefix = $ data [0 ];
162
162
163
163
if ($ prefix != static ::PREFIX_UNCOMPRESSED ) {
164
- throw new CryptoException ('Invalid uncompressed public key prefix. ' );
164
+ throw new PublicKeyException ('Invalid uncompressed public key prefix. ' );
165
165
}
166
166
167
167
$ x = Utils::binToGmp (substr ($ data , 1 , 32 ));
168
168
$ y = Utils::binToGmp (substr ($ data , 33 , 32 ));
169
169
} else {
170
- throw new CryptoException ('Invalid public key size. ' );
170
+ throw new PublicKeyException ('Invalid public key size. ' );
171
171
}
172
172
173
173
return new static ($ x , $ y , $ prefix == static ::PREFIX_COMPRESSED_ODD );
0 commit comments