diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ffac8d2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +[root] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_size = 4 +indent_style = tab +trim_trailing_whitespace = true \ No newline at end of file diff --git a/src/Base58.php b/src/Base58.php index bc24524..2b369aa 100644 --- a/src/Base58.php +++ b/src/Base58.php @@ -39,7 +39,7 @@ private static function decToHex(BigInteger $dec): string while (!$dec->equals(0)) { $remainder = $dec->mod(16); $dec = $dec->div(16); - $res = dechex((int)$remainder->toDec()).$res; + $res = dechex((int)$remainder->toDec()) . $res; } return $res; @@ -58,7 +58,7 @@ private static function encodeBlock(array $data, array $res, int $res_offset): a $length = count($data); if ($length < 1 || $length > self::FULL_ENCODED_BLOCK_SIZE) { - throw new Exception("Invalid block length: ". $length); + throw new Exception("Invalid block length: " . $length); } $num = self::uint8beTo64($data); @@ -115,7 +115,7 @@ private static function decodeBlock(array $data, array $res): array $length = count($data); if ($length < 1 || $length > self::FULL_ENCODED_BLOCK_SIZE) { - throw new Exception("Invalid block length: ". $length); + throw new Exception("Invalid block length: " . $length); } $num = new BigInteger(0); @@ -125,7 +125,7 @@ private static function decodeBlock(array $data, array $res): array $char_value = strpos(self::ALPHABET, $char); if ($char_value === false) { - throw new Exception("Invalid character: ". $char); + throw new Exception("Invalid character: " . $char); } $num = $num->mul(self::ALPHABET_SIZE)->add($char_value); @@ -161,4 +161,4 @@ public static function decode(string $base58): string return bin2hex(implode('', $res)); } -} \ No newline at end of file +} diff --git a/src/wordsets/portuguese.ws.php b/src/wordsets/portuguese.ws.php index c82acd4..bcd6c0b 100644 --- a/src/wordsets/portuguese.ws.php +++ b/src/wordsets/portuguese.ws.php @@ -1674,6 +1674,6 @@ public static function words(): array "zeloso", "zenite", "zumbi" - ]; + ]; } } diff --git a/src/wordsets/russian.ws.php b/src/wordsets/russian.ws.php index 57f6f35..7daad4a 100644 --- a/src/wordsets/russian.ws.php +++ b/src/wordsets/russian.ws.php @@ -16,7 +16,6 @@ class russian implements Wordset public static function name(): string { return "русский язык"; - } /** @@ -1674,6 +1673,6 @@ public static function words(): array "яхта", "ячейка", "ящик" - ]; + ]; } } diff --git a/src/wordsets/spanish.ws.php b/src/wordsets/spanish.ws.php index 0d2bb0a..b4a6c04 100644 --- a/src/wordsets/spanish.ws.php +++ b/src/wordsets/spanish.ws.php @@ -16,7 +16,6 @@ class spanish implements Wordset public static function name(): string { return "Español"; - } /** diff --git a/tests/unit/Base58Test.php b/tests/unit/Base58Test.php index 0691b7b..3606688 100644 --- a/tests/unit/Base58Test.php +++ b/tests/unit/Base58Test.php @@ -13,7 +13,7 @@ class Base58Test extends TestCase public function testEncode() { $this->assertSame($this->testEncoded, Base58::encode($this->testDecoded)); - + $this->expectException(TypeError::class); Base58::encode("invalid"); } diff --git a/tests/unit/CryptonoteTest.php b/tests/unit/CryptonoteTest.php index cbd4459..6461486 100644 --- a/tests/unit/CryptonoteTest.php +++ b/tests/unit/CryptonoteTest.php @@ -8,48 +8,42 @@ class CryptonoteTest extends TestCase { - private $testDecodedKeccak = "6fd43e7cffc31bb581d7421c8698e29aa2bd8e7186a394b85299908b4eb9b175"; - private $testEncodedKeccak = "0b6a7d8d740055460014f9c3e31063c5bb8e254cb9fee970294a0d0064429ca8"; - - private $testHexSeed = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08"; - private $testPubViewKey = "a21d0a8ceacdb5e6a5d8bba57741123671c83a3b34187fe23324112b0c7b7760"; - private $testPrivateViewKey = "e7cbc9050333b9ed07843ce835547c07c8a8d6b7acc10bebb60d7d6fe1a82f05"; - private $testPubSpendKey = "765d0b9d61e8ca67b8902f6b133ae7bcdde5419c72ab6244ed7400789db7be99"; - private $testPrivateSpendKey = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08"; - - private $testAddressNetByte = "12"; - private $testAddress = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLYj"; - private $testAddressBad = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLzj"; - - private $testPaymentId = "ef64f0a81b022a81"; - private $testIntegratedAddress = "4FowJQLEWXKJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cHDPkStRLntqFZqGwKS"; - - /** @var Cryptonote */ - private $cr; - - public function setUp(): void - { - $this->cr = new Cryptonote(MoneroNetwork::mainnet); - } - - public function testKeccak256(): void - { - $result = $this->cr->keccak_256($this->testDecodedKeccak); - $this->assertEquals($this->testEncodedKeccak, $result); - } - - public function testGenNewHexSeed(): void - { - $result = $this->cr->gen_new_hex_seed(); - $this->assertIsString($result); - $this->assertEquals(64, strlen($result)); - } - - // public function testDeriveViewKey(): void - // { - // $result = $this->cr->derive_viewKey($this->testPrivateSpendKey); - // $this->assertEquals($this->testPrivateViewKey, $result); - // } + private $testDecodedKeccak = "6fd43e7cffc31bb581d7421c8698e29aa2bd8e7186a394b85299908b4eb9b175"; + private $testEncodedKeccak = "0b6a7d8d740055460014f9c3e31063c5bb8e254cb9fee970294a0d0064429ca8"; + + private $testHexSeed = "92df69221844dc2a77389e2c3ebae5fa32517c04826c870fb952171fb192cc08"; + private $testPubViewKey = "a21d0a8ceacdb5e6a5d8bba57741123671c83a3b34187fe23324112b0c7b7760"; + private $testPrivateViewKey = "e7cbc9050333b9ed07843ce835547c07c8a8d6b7acc10bebb60d7d6fe1a82f05"; + private $testPubSpendKey = "765d0b9d61e8ca67b8902f6b133ae7bcdde5419c72ab6244ed7400789db7be99"; + private $testPrivateSpendKey = "282a30d36de33cc65eb7804126a7644c2cce00ce2aac171a7c24496ba2764701"; + + private $testAddressNetByte = "12"; + private $testAddress = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLYj"; + private $testAddressBad = "467GHbWjuFoJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cBu3mLzj"; + + private $testPaymentId = "ef64f0a81b022a81"; + private $testIntegratedAddress = "4FowJQLEWXKJMDwegvhEJAYbFAyZ6Y2GqCXgebZd96CDShSESH5nCKEfaaER1vCYKTA7BQkyE5gBGeqRRcX8Fe1cHDPkStRLntqFZqGwKS"; + + /** @var Cryptonote */ + private $cr; + + public function setUp(): void + { + $this->cr = new Cryptonote(MoneroNetwork::mainnet); + } + + public function testKeccak256(): void + { + $result = Cryptonote::keccak_256($this->testDecodedKeccak); + $this->assertEquals($this->testEncodedKeccak, $result); + } + + public function testGenNewHexSeed(): void + { + $result = $this->cr->gen_new_hex_seed(); + $this->assertIsString($result); + $this->assertEquals(64, strlen($result)); + } public function testScReduce(): void { @@ -57,40 +51,35 @@ public function testScReduce(): void $this->assertEquals("65", $result); } - public function testEncodeAddress(): void - { - $result = $this->cr->encode_address($this->testPubSpendKey, $this->testPubViewKey); - $this->assertEquals($this->testAddress, $result); - } - - public function testVerifyChecksum(): void - { - $result = $this->cr->verify_checksum($this->testAddress); - $this->assertTrue($result); - - $result = $this->cr->verify_checksum($this->testAddressBad); - $this->assertFalse($result); - } - - public function testDecodeAddress(): void - { - $result = $this->cr->decode_address($this->testAddress); - $this->assertIsArray($result); - - $this->assertEquals($this->testAddressNetByte, $result["networkByte"]); - $this->assertEquals($this->testPubSpendKey, $result["spendKey"]); - $this->assertEquals($this->testPubViewKey, $result["viewKey"]); - } - - public function testIntegratedAddrFromKeys(): void - { - $result = $this->cr->integrated_addr_from_keys($this->testPubSpendKey, $this->testPubViewKey, $this->testPaymentId); - $this->assertEquals($this->testIntegratedAddress, $result); - } - - // public function testAddressFromSeed(): void - // { - // $result = $this->cr->address_from_seed($this->testHexSeed); - // $this->assertEquals($this->testAddress, $result); - // } -} \ No newline at end of file + + public function testEncodeAddress(): void + { + $result = $this->cr->encode_address($this->testPubSpendKey, $this->testPubViewKey); + $this->assertEquals($this->testAddress, $result); + } + + public function testVerifyChecksum(): void + { + $result = $this->cr->verify_checksum($this->testAddress); + $this->assertTrue($result); + + $result = $this->cr->verify_checksum($this->testAddressBad); + $this->assertFalse($result); + } + + public function testDecodeAddress(): void + { + $result = $this->cr->decode_address($this->testAddress); + $this->assertIsArray($result); + + $this->assertEquals($this->testAddressNetByte, $result["networkByte"]); + $this->assertEquals($this->testPubSpendKey, $result["spendKey"]); + $this->assertEquals($this->testPubViewKey, $result["viewKey"]); + } + + public function testIntegratedAddrFromKeys(): void + { + $result = $this->cr->integrated_addr_from_keys($this->testPubSpendKey, $this->testPubViewKey, $this->testPaymentId); + $this->assertEquals($this->testIntegratedAddress, $result); + } +}