Repository navigation
Expand file tree
/
Copy pathclass-verify-signature-test.php
More file actions
61 lines (55 loc) · 1.75 KB
/
Copy pathclass-verify-signature-test.php
File metadata and controls
61 lines (55 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Verify signature checks.
*
* @package WP_Rainbow
*/
namespace WP_Rainbow\Tests;
require __DIR__ . '/../../inc/class-wp-rainbow-login-functionality.php';
use Exception;
use PHPUnit\Framework\TestCase;
use Elliptic\EC;
use WP_Rainbow\WP_Rainbow_Login_Functionality;
/**
* These tests check signature verification.
*/
class Verify_Signature_Test extends TestCase {
/**
* Verify a generated message using library only.
*/
public function testVerificationLibraryOnly() {
$ec = new EC( 'secp256k1' );
$key = $ec->genKeyPair();
$msg = 'ab4c3451';
$signature = $key->sign( $msg );
$der_sign = $signature->toDER( 'hex' );
$this->assertTrue( $key->verify( $msg, $der_sign ) );
}
/**
* Verify a generated message using WP_Rainbow class.
*
* @throws Exception Throws if unsupported Keccak Hash output size.
*/
public function testVerificationWithClass() {
$this_plugin = new WP_Rainbow_Login_Functionality();
$msg_payload = [
'address' => '0xfe15a1eC58947149F81c33d5f5B6D74d952bc0F2',
'domain' => 'wp-rainbow.test',
'chainId' => 1,
'issuedAt' => '2022-03-22T22:52:03.693Z',
'nonce' => '5761ec5dfe',
'statement' => 'Log In with Ethereum to WP Rainbow',
'uri' => 'https://wp-rainbow.test',
'version' => 1,
];
$signature = '0x649726d97a8ebd2b67fcf867a08e504a8fbd7c9fe3af582f8b3f05dffdda6375717e1a69e7eddd9af2c5b6e92ad40402a2361b19652e1264d146c65e1110b6761c';
$address = '0xfe15a1eC58947149F81c33d5f5B6D74d952bc0F2';
$generated_message = $this_plugin->generate_message( $msg_payload );
$signature_verified = $this_plugin->verify_signature(
$generated_message,
$signature,
$address
);
$this->assertTrue( $signature_verified );
}
}