Skip to content

Commit

Permalink
rename V3Crypt/Mnemonic to V3Crypt/EncryptionMnemonic to make it …
Browse files Browse the repository at this point in the history
…clear it's only usable for cipher text from `V3Crypt/Encryption`.
  • Loading branch information
rubensayshi committed Dec 6, 2016
1 parent 5ab7451 commit 946cb0e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/BlocktrailSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Blocktrail\SDK\Bitcoin\BIP32Key;
use Blocktrail\SDK\Connection\RestClient;
use Blocktrail\SDK\V3Crypt\Encryption;
use Blocktrail\SDK\V3Crypt\Mnemonic;
use Blocktrail\SDK\V3Crypt\EncryptionMnemonic;

/**
* Class BlocktrailSDK
Expand Down Expand Up @@ -926,10 +926,10 @@ protected function createNewWalletV3($options) {
return [
$wallet,
[
'encrypted_primary_seed' => $encryptedPrimarySeed ? Mnemonic::encode($encryptedPrimarySeed) : null,
'encrypted_primary_seed' => $encryptedPrimarySeed ? EncryptionMnemonic::encode($encryptedPrimarySeed) : null,
'backup_seed' => $backupSeed ? MnemonicFactory::bip39()->entropyToMnemonic($backupSeed) : null,
'recovery_encrypted_secret' => $recoveryEncryptedSecret ? Mnemonic::encode($recoveryEncryptedSecret) : null,
'encrypted_secret' => $encryptedSecret ? Mnemonic::encode($encryptedSecret) : null,
'recovery_encrypted_secret' => $recoveryEncryptedSecret ? EncryptionMnemonic::encode($recoveryEncryptedSecret) : null,
'encrypted_secret' => $encryptedSecret ? EncryptionMnemonic::encode($encryptedSecret) : null,
'blocktrail_public_keys' => Util::arrayMapWithIndex(function ($keyIndex, BIP32Key $pubKey) {
return [$keyIndex, $pubKey->tuple()];
}, $blocktrailPublicKeys),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BitWasp\Buffertools\Buffer;
use BitWasp\Buffertools\BufferInterface;

class Mnemonic
class EncryptionMnemonic
{
const CHUNK_SIZE = 4;
const PADDING_DUMMY = "\x81";
Expand Down
4 changes: 2 additions & 2 deletions src/WalletV3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Blocktrail\SDK\Exceptions\BlocktrailSDKException;
use Blocktrail\SDK\Exceptions\WalletDecryptException;
use Blocktrail\SDK\V3Crypt\Encryption;
use Blocktrail\SDK\V3Crypt\Mnemonic;
use Blocktrail\SDK\V3Crypt\EncryptionMnemonic;

class WalletV3 extends Wallet
{
Expand Down Expand Up @@ -158,7 +158,7 @@ public function passwordChange($newPassword) {
$this->encryptedSecret = $encryptedSecret;

return [
'encrypted_secret' => Mnemonic::encode($encryptedSecret),
'encrypted_secret' => EncryptionMnemonic::encode($encryptedSecret),
];
}
}
6 changes: 3 additions & 3 deletions src/WalletV3Sweeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BitWasp\Buffertools\BufferInterface;
use Blocktrail\SDK\Exceptions\BlocktrailSDKException;
use Blocktrail\SDK\V3Crypt\Encryption;
use Blocktrail\SDK\V3Crypt\Mnemonic;
use Blocktrail\SDK\V3Crypt\EncryptionMnemonic;

class WalletV3Sweeper extends WalletSweeper
{
Expand All @@ -27,11 +27,11 @@ public function __construct($encryptedPrimaryMnemonic, $encryptedSecretMnemonic,
$encryptedSecretMnemonic = str_replace(" ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($encryptedSecretMnemonic))));
$backupMnemonic = str_replace(" ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($backupMnemonic))));

if (!($secret = Encryption::decrypt(Mnemonic::decode($encryptedSecretMnemonic), $passphrase))) {
if (!($secret = Encryption::decrypt(EncryptionMnemonic::decode($encryptedSecretMnemonic), $passphrase))) {
throw new BlocktrailSDKException("Failed to decret password encrypted secret");
}

if (!($primarySeed = Encryption::decrypt(Mnemonic::decode($encryptedPrimaryMnemonic), $secret))) {
if (!($primarySeed = Encryption::decrypt(EncryptionMnemonic::decode($encryptedPrimaryMnemonic), $secret))) {
throw new BlocktrailSDKException("failed to decrypt encrypted primary seed! (weird!)");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use BitWasp\Buffertools\Buffer;
use BitWasp\Buffertools\BufferInterface;
use Blocktrail\SDK\V3Crypt\Mnemonic;
use Blocktrail\SDK\V3Crypt\EncryptionMnemonic;

class MnemonicTest extends AbstractTestCase
class EncryptionMnemonicTest extends AbstractTestCase
{
/**
* @return array
Expand All @@ -23,7 +23,7 @@ public function getConsistencyCheckVectors() {
* @param $mnemonic
*/
public function testConsistency(BufferInterface $data, $mnemonic) {
$this->assertEquals($mnemonic, Mnemonic::encode($data));
$this->assertTrue($data->equals(Mnemonic::decode($mnemonic)));
$this->assertEquals($mnemonic, EncryptionMnemonic::encode($data));
$this->assertTrue($data->equals(EncryptionMnemonic::decode($mnemonic)));
}
}
16 changes: 8 additions & 8 deletions tests/V3Crypt/FullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BitWasp\Buffertools\Buffer;
use BitWasp\Buffertools\BufferInterface;
use Blocktrail\SDK\V3Crypt\Encryption;
use Blocktrail\SDK\V3Crypt\Mnemonic;
use Blocktrail\SDK\V3Crypt\EncryptionMnemonic;

class FullTest extends AbstractTestCase
{
Expand Down Expand Up @@ -44,10 +44,10 @@ public function getPasswordResetVectors() {
* @param string $checksum
*/
public function testDecryptionOnly(BufferInterface $password, $encryptedPrimarySeedMnemonic, $encryptedSecretMnemonic, $checksum) {
$decodedSecret = Mnemonic::decode($encryptedSecretMnemonic);
$decodedSecret = EncryptionMnemonic::decode($encryptedSecretMnemonic);
$decryptedSecret = Encryption::decrypt($decodedSecret, $password);

$decodedPrimarySeed = Mnemonic::decode($encryptedPrimarySeedMnemonic);
$decodedPrimarySeed = EncryptionMnemonic::decode($encryptedPrimarySeedMnemonic);
$decryptedPrimarySeed = Encryption::decrypt($decodedPrimarySeed, $decryptedSecret);

$hdnode = HierarchicalKeyFactory::fromEntropy($decryptedPrimarySeed);
Expand All @@ -61,7 +61,7 @@ public function testDecryptionOnly(BufferInterface $password, $encryptedPrimaryS
* @dataProvider getPasswordResetVectors
*/
public function testAllowsPasswordReset(BufferInterface $expectedSecret, BufferInterface $recoverySecret, $recoveryEncryptedMnemonic) {
$decodedRS = Mnemonic::decode($recoveryEncryptedMnemonic);
$decodedRS = EncryptionMnemonic::decode($recoveryEncryptedMnemonic);
$decryptedSecret = Encryption::decrypt($decodedRS, $recoverySecret);

$this->assertEquals($decryptedSecret->getHex(), $expectedSecret->getHex());
Expand All @@ -83,14 +83,14 @@ public function testProcedure() {
$this->assertTrue($secret->equals(Encryption::decrypt($recoveryEncryptedSecret, $recoverySecret)));

$backupInfo = [
'encryptedPrimarySeed' => Mnemonic::encode($encryptedPrimarySeed),
'encryptedSecret' => Mnemonic::encode($encryptedSecret),
'recoveryEncryptedSecret' => Mnemonic::encode($recoveryEncryptedSecret),
'encryptedPrimarySeed' => EncryptionMnemonic::encode($encryptedPrimarySeed),
'encryptedSecret' => EncryptionMnemonic::encode($encryptedSecret),
'recoveryEncryptedSecret' => EncryptionMnemonic::encode($recoveryEncryptedSecret),
];

foreach ($backupInfo as $key => $val) {
$cmp = $$key;
$this->assertTrue(Mnemonic::decode($val)->equals($cmp));
$this->assertTrue(EncryptionMnemonic::decode($val)->equals($cmp));
}
}
}

0 comments on commit 946cb0e

Please sign in to comment.