|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Btccom\JustEncrypt\Test; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Buffertools\Buffer; |
|
6
|
|
|
use BitWasp\Buffertools\BufferInterface; |
|
7
|
|
|
use Btccom\JustEncrypt\Encryption; |
|
8
|
|
|
use Btccom\JustEncrypt\EncryptionMnemonic; |
|
9
|
|
|
|
|
10
|
|
|
class FullTest extends AbstractTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param int $len |
|
14
|
|
|
* @return BufferInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
public function random($len) |
|
17
|
|
|
{ |
|
18
|
|
|
return new Buffer(random_bytes($len)); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testProcedure() |
|
22
|
|
|
{ |
|
23
|
|
|
$passphrase = new Buffer('FFUgnayLMUDLqpTY2bctzBvx5ckPhFt3n5VadNxyMp8XwpZ8SjVJRZpALTWaUvnE7Fru8j8GqgSzC8zdHeQxV6CM2jzL46ULQeRjPXAsVrbSSYnvW8Axrfgv'); |
|
24
|
|
|
$primarySeed = $this->random(32); |
|
25
|
|
|
$secret = $this->random(32); |
|
26
|
|
|
|
|
27
|
|
|
$encryptedSecret = Encryption::encrypt($secret, $passphrase)->getBuffer(); |
|
28
|
|
|
$this->assertTrue($secret->equals(Encryption::decrypt($encryptedSecret, $passphrase))); |
|
29
|
|
|
|
|
30
|
|
|
$encryptedPrimarySeed = Encryption::encrypt($primarySeed, $secret)->getBuffer(); |
|
31
|
|
|
$this->assertTrue($primarySeed->equals(Encryption::decrypt($encryptedPrimarySeed, $secret))); |
|
32
|
|
|
|
|
33
|
|
|
$recoverySecret = $this->random(32); |
|
34
|
|
|
$recoveryEncryptedSecret = Encryption::encrypt($secret, $recoverySecret)->getBuffer(); |
|
35
|
|
|
$this->assertTrue($secret->equals(Encryption::decrypt($recoveryEncryptedSecret, $recoverySecret))); |
|
36
|
|
|
|
|
37
|
|
|
$backupInfo = [ |
|
38
|
|
|
'encryptedPrimarySeed' => EncryptionMnemonic::encode($encryptedPrimarySeed), |
|
39
|
|
|
'encryptedSecret' => EncryptionMnemonic::encode($encryptedSecret), |
|
40
|
|
|
'recoveryEncryptedSecret' => EncryptionMnemonic::encode($recoveryEncryptedSecret), |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
foreach ($backupInfo as $key => $val) { |
|
44
|
|
|
$cmp = $$key; |
|
45
|
|
|
$this->assertTrue(EncryptionMnemonic::decode($val)->equals($cmp)); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|