Skip to content

Commit

Permalink
Use sodium compat as sodium extension throws error on curve check
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielkoerich committed Apr 28, 2022
1 parent ab97975 commit 3cb4b01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"guzzlehttp/guzzle": "^7.3",
"illuminate/http": "~8.0 || ~9.0",
"illuminate/support": "^8.0 || ~9.0",
"paragonie/sodium_compat": "^1.17",
"stephenhill/base58": "^1.1"
},
"require-dev": {
Expand Down
8 changes: 7 additions & 1 deletion src/PublicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tighten\SolanaPhpSdk;

use ParagonIE_Sodium_Compat;
use SodiumException;
use StephenHill\Base58;
use Tighten\SolanaPhpSdk\Exceptions\BaseSolanaPhpSdkException;
Expand Down Expand Up @@ -191,7 +192,12 @@ static function isOnCurve($publicKey): bool
? $publicKey->toBinaryString()
: $publicKey;

$_ = sodium_crypto_sign_ed25519_pk_to_curve25519($binaryString);
/**
* Sodium extension method sometimes returns "conversion failed" exception.
* $_ = sodium_crypto_sign_ed25519_pk_to_curve25519($binaryString);
*/
$_ = ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($binaryString);

return true;
} catch (SodiumException $exception) {
return false;
Expand Down

0 comments on commit 3cb4b01

Please sign in to comment.