Ethereum PHP
PHP interface to Ethereum JSON-RPC API.
EcRecoverTest.php
Go to the documentation of this file.
1 <?php
2 namespace Ethereum;
3 
7 
14 
15 
27  public function ecRecoverDataProvider() {
28  /* Note:
29  * You can evaluate in browser using web3js:
30  *
31  * web3.personal.ecRecover(
32  * "I want to create a Account on this website. By I signing this text (using Ethereum personal_sign) I agree to the following conditions.",
33  * "0xbbdcdfb9fbe24d460a683633475c77a44072b527a127b159ffaaa043f5dc944105a1671c8b9df95e377d89ec17a1a0ed13f5caa33e5fa80bdf12391bf2e04e4f1c",
34  * (e,f)=>{console.log(e,f)}
35  * )
36  *
37  */
38  return [
39  // Array (Address, Message (UTF8), Signature, Message (Hex string))
40  [
41  '0xbe93f9bacbcffc8ee6663f2647917ed7a20a57bb',
42  'hello world',
43  '0xce909e8ea6851bc36c007a0072d0524b07a3ff8d4e623aca4c71ca8e57250c4d0a3fc38fa8fbaaa81ead4b9f6bd03356b6f8bf18bccad167d78891636e1d69561b',
44  '0x68656c6c6f20776f726c64'
45  ],
46  [
47  // Nethereum https://github.com/Nethereum/Nethereum/blob/6b4544ec8838cfb72ac3aed2f54ad6f62aafae78/src/Nethereum.Signer.UnitTests/EthereumMessageSignerTests.cs#L73-L82
48  '0xe651c5051ce42241765bbb24655a791ff0ec8d13',
49  'wee test message 18/09/2017 02:55PM',
50  '0xf5ac62a395216a84bd595069f1bb79f1ee08a15f07bb9d9349b3b185e69b20c60061dbe5cdbe7b4ed8d8fea707972f03c21dda80d99efde3d96b42c91b2703211b',
51  '0x7765652074657374206d6573736167652031382f30392f323031372030323a3535504d',
52  ],
53  [
54  '0x9283099a29556fcf8fff5b2cea2d4f67cb7a7a8b',
55  'I am but a stack exchange post',
56  '0x0cf7e2e1cbaf249175b8e004118a182eb378a0b78a7a741e72a0a34e970b59194aa4d9419352d181a4d1827abbad279ad4f5a7b60da5751b82fec4dde6f380a51b',
57  '0x4920616d20627574206120737461636b2065786368616e676520706f7374',
58  ],
59  [
60  '0xb61f34dc82977e2b8c2bd747284b47ab94615bff',
61  'I want to create a Account on this website. By I signing this text (using Ethereum personal_sign) I agree to the following conditions.',
62  '0xbbdcdfb9fbe24d460a683633475c77a44072b527a127b159ffaaa043f5dc944105a1671c8b9df95e377d89ec17a1a0ed13f5caa33e5fa80bdf12391bf2e04e4f1c',
63  '0x492077616e7420746f206372656174652061204163636f756e74206f6e207468697320776562736974652e2042792049207369676e696e672074686973207465787420287573696e6720457468657265756d20706572736f6e616c5f7369676e29204920616772656520746f2074686520666f6c6c6f77696e6720636f6e646974696f6e732e',
64  ],
65  ];
66  }
67 
68 
77  public function testUtf8ToMessage($address, $message, $signature, $messageHex)
78  {
79  $test = EthereumStatic::ensureHexPrefix(EthS::strToHex($message));
80  $this->assertSame($messageHex, $test);
81  }
82 
83 
94  public function testRestoreAddress($address, $message, $signature, $messageHex)
95  {
96  $recoveredAddr = Ethereum::personalEcRecover($message, new EthD($signature) );
97  $this->assertSame($address, $recoveredAddr);
98  }
99 
100 }
testRestoreAddress($address, $message, $signature, $messageHex)
testUtf8ToMessage($address, $message, $signature, $messageHex)
Definition: Abi.php:3