Skip to content

Commit

Permalink
Add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Jul 8, 2024
1 parent b3739a3 commit ab393fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/Crypto/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Exception;
use StarkNet\Constants;
use StarkNet\Utils;
use BN\BN;

class Key {
/**
Expand All @@ -25,7 +24,7 @@ class Key {
* generation on mainnet.
*
* @param BigNumber $keySeed
* @return BigNumber
* @return string
*/
public static function grindKey ($keySeed)
{
Expand All @@ -38,13 +37,11 @@ public static function grindKey ($keySeed)
$key = Utils::toBn(\hash('sha256', $msg, false));
if ($key->compare($maxAllowedValue) < 0) {
$result = $key->divide($ecOrder);
// normalize the bignumber
return new BN($result[1]->toString());
return $result[1]->toHex();
}
if ($i === 100000) {
throw new Exception('grindKey is broken: tried 100k vals');
}
}
return $maxAllowedValue;
}
}
5 changes: 4 additions & 1 deletion test/unit/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function testGrindKey()
{

$result = Key::grindKey('86F3E7293141F20A8BAFF320E8EE4ACCB9D4A4BF2B4D295E8CEE784DB46E0519');
$this->assertEquals('5c8c8683596c732541a59e03007b2d30dbbbb873556fe65b5fb63c16688f941', substr($result->toString(16), 1, 64));
$this->assertEquals('05c8c8683596c732541a59e03007b2d30dbbbb873556fe65b5fb63c16688f941', $result);

$result = Key::grindKey('94F3E7293141F20A8BAFF320E8EE4ACCB9D4A4BF2B4D295E8CEE784DB46E0595');
$this->assertEquals('033880b9aba464c1c01c9f8f5b4fc1134698f9b0a8d18505cab6cdd34d93dc02', $result);
}
}

0 comments on commit ab393fd

Please sign in to comment.