Skip to content

Commit

Permalink
fixed bad password wallet test because of hardcoded checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensayshi committed Feb 13, 2015
1 parent 3e8fd5a commit 03a3ab1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/BlocktrailSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function initWallet($identifier, $password) {
$primaryPrivateKey = BIP32::master_key($primarySeed, $this->network, $this->testnet);

// create checksum (address) of the primary privatekey to compare to the stored checksum
$checksum2 = $this->createChecksum($primaryPrivateKey);
$checksum2 = self::createChecksum($primaryPrivateKey);
if ($checksum2 != $checksum) {
throw new WalletChecksumException("Checksum [{$checksum2}] does not match [{$checksum}], most likely due to incorrect password");
}
Expand All @@ -579,7 +579,7 @@ public function initWallet($identifier, $password) {
* @param string $primaryPrivateKey the private key for which we want a checksum
* @return bool|string
*/
protected function createChecksum($primaryPrivateKey) {
public static function createChecksum($primaryPrivateKey) {
return BIP32::key_to_address($primaryPrivateKey[0]);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/WalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ protected function _createTestWallet(BlocktrailSDKInterface $client, $identifier

$testnet = true;

$result = $client->_createNewWallet($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, "mkiPAxhzUMo8mAwW3q95q7aNuXt6HzbbUA", 9999);
// create a checksum of our private key which we'll later use to verify we used the right password
$checksum = BlocktrailSDK::createChecksum($primaryPrivateKey);

$result = $client->_createNewWallet($identifier, $primaryPublicKey, $backupPublicKey, $primaryMnemonic, $checksum, 9999);

$blocktrailPublicKeys = $result['blocktrail_public_keys'];
$keyIndex = $result['key_index'];
Expand Down

0 comments on commit 03a3ab1

Please sign in to comment.