|
2 | 2 |
|
3 | 3 | namespace Tests\Functional\Util\Crypto; |
4 | 4 |
|
| 5 | +use Casper\Util\ByteUtil; |
5 | 6 | use PHPUnit\Framework\TestCase; |
6 | 7 |
|
7 | 8 | use Casper\Util\Crypto\Secp256K1Key; |
@@ -52,9 +53,42 @@ public function testExportPrivateKeyInPem(): void |
52 | 53 | } |
53 | 54 |
|
54 | 55 | /** |
| 56 | + * Test hashes that were incorrectly signed with Mdanter\Ecc\Crypto\Signature\Signer |
| 57 | + * For tested hashes Mdanter\Ecc\Crypto\Signature\Signer calculates wrong S value |
| 58 | + * |
| 59 | + * Fixed bug by installing https://github.com/Bit-Wasp/secp256k1-php and |
| 60 | + * replacing signature creation with method from the installed lib instead of |
| 61 | + * Mdanter\Ecc\Crypto\Signature\Signer |
| 62 | + * |
55 | 63 | * @throws \Exception |
56 | 64 | */ |
57 | | - public function testSigningAndVerification(): void |
| 65 | + public function testSigning(): void |
| 66 | + { |
| 67 | + $hash1 = '7603b5b40d32cffd00d375de90b4610c6b3fcb7fd4cceefe408d23453f42e482'; |
| 68 | + $hash2 = '2225cb72ec2058fa153c2b494e416a336f48b0b89ba4fc444151e708907fd53a'; |
| 69 | + $hash3 = 'c02fd8c56ee37fa4ba6bf260742c21cd0d427914f3cac266bf58266decb4c77d'; |
| 70 | + $hash4 = '766d28afb40744c703591334ecc02d18faee90f420159eb4b542915ff7589e25'; |
| 71 | + $hash5 = '8f5a6f914d39149fc7ee4d3318e899bf3c7ecf54e63a64d6c715a33c4f47374d'; |
| 72 | + |
| 73 | + $correctSignatureForHash1 = 'b23038d56a9b7d025453c6d0288be95bccdf5b29e327be89baa143df7f88d57a3d9ab479b353d6604d084a9296fc76a1f4020ee639744ba61430e51b0df423ac'; |
| 74 | + $correctSignatureForHash2 = '79b77c21e0db001eda6f79fbd3ae92e3022d55b07dc3fa4d932dc38abd7933c7224243f0a4f7a133ccd966389012c493dd9e2dc7b69f118465305f6efdfc1fd5'; |
| 75 | + $correctSignatureForHash3 = '065a3d85843334ab9fbf5998aa28c2f8b997989764591f781372386c1009ae5766560182f77ae3917198eb62d969582c4ec7e0bad99e33759d5d8ec84910d980'; |
| 76 | + $correctSignatureForHash4 = '02f1ca3e4f58d1f2ba64ad55893a87a442e63b7fae7df7eb883ded7ad22f92af06e4b96d78b150fd9bf8603e4e4fcee45a49704aacfcfe1ebd3702a8a6a5d929'; |
| 77 | + $correctSignatureForHash5 = 'f0d1775662db12dc7bfde1779b9a9bfbf0d1497e04e7b1fd253a3d3b7726c6f873dea751d162cb1f017f954d3f1d41bae8f115451042665c5b02411560479b7a'; |
| 78 | + |
| 79 | + $secp256k1KeyPair = Secp256K1Key::createFromPrivateKeyFile('tests/Assets/Secp256K1SecretKey.pem'); |
| 80 | + |
| 81 | + $this->assertEquals($correctSignatureForHash1, $secp256k1KeyPair->sign(ByteUtil::hexToString($hash1))); |
| 82 | + $this->assertEquals($correctSignatureForHash2, $secp256k1KeyPair->sign(ByteUtil::hexToString($hash2))); |
| 83 | + $this->assertEquals($correctSignatureForHash3, $secp256k1KeyPair->sign(ByteUtil::hexToString($hash3))); |
| 84 | + $this->assertEquals($correctSignatureForHash4, $secp256k1KeyPair->sign(ByteUtil::hexToString($hash4))); |
| 85 | + $this->assertEquals($correctSignatureForHash5, $secp256k1KeyPair->sign(ByteUtil::hexToString($hash5))); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @throws \Exception |
| 90 | + */ |
| 91 | + public function testSignatureVerification(): void |
58 | 92 | { |
59 | 93 | $message = 'Hello world'; |
60 | 94 | $secp256k1KeyPair = Secp256K1Key::createFromPrivateKeyFile('tests/Assets/Secp256K1SecretKey.pem'); |
|
0 commit comments