From e4840a5b3cd917c369416b216057515373c0a24f Mon Sep 17 00:00:00 2001 From: micha vie Date: Thu, 6 Apr 2023 13:22:27 +0200 Subject: [PATCH] code formatting --- src/Auth/NativeAuthServer.php | 12 ++++++------ src/Multiversx.php | 2 +- tests/Auth/NativeAuthServerTest.php | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Auth/NativeAuthServer.php b/src/Auth/NativeAuthServer.php index ff9d220..b6d0985 100644 --- a/src/Auth/NativeAuthServer.php +++ b/src/Auth/NativeAuthServer.php @@ -7,8 +7,6 @@ use Peerme\Mx\SignableMessage; use Peerme\Mx\Signature; use Peerme\Mx\UserVerifier; -use Peerme\MxLaravel\Auth\NativeAuthDecoded; -use Peerme\MxLaravel\Auth\NativeAuthValidateResult; use Peerme\MxLaravel\Exceptions\NativeAuthInvalidSignatureException; use Peerme\MxLaravel\Exceptions\NativeAuthInvalidTokenTtlException; use Peerme\MxLaravel\Exceptions\NativeAuthOriginNotAcceptedException; @@ -24,7 +22,8 @@ public function __construct( ) { } - public function decode(string $accessToken): NativeAuthDecoded { + public function decode(string $accessToken): NativeAuthDecoded + { $tokenComponents = explode('.', $accessToken); throw_unless(count($tokenComponents) === 3, InvalidArgumentException::class, 'invalid token'); @@ -50,13 +49,14 @@ public function decode(string $accessToken): NativeAuthDecoded { ); } - public function validate(string $accessToken): NativeAuthValidateResult { + public function validate(string $accessToken): NativeAuthValidateResult + { $decoded = $this->decode($accessToken); throw_unless($decoded->ttl <= $this->maxExpirySeconds, NativeAuthInvalidTokenTtlException::class, $decoded->ttl, $this->maxExpirySeconds); $hasAcceptedOrigins = count($this->acceptedOrigins) > 0; - $isInvalidOrigin = !in_array($decoded->origin, $this->acceptedOrigins) && !in_array('https://' . $decoded->origin, $this->acceptedOrigins); + $isInvalidOrigin = ! in_array($decoded->origin, $this->acceptedOrigins) && ! in_array('https://'.$decoded->origin, $this->acceptedOrigins); throw_if($hasAcceptedOrigins && $isInvalidOrigin, NativeAuthOriginNotAcceptedException::class, $decoded->origin); $this->ensureNotExpired($decoded); @@ -70,7 +70,7 @@ public function validate(string $accessToken): NativeAuthValidateResult { $valid = UserVerifier::fromAddress(Address::fromBech32($decoded->address)) ->verify($verifiable); - if (!$valid && !$this->skipLegacyValidation) { + if (! $valid && ! $this->skipLegacyValidation) { $verifiable = new SignableMessage( message: "{$decoded->address}{$decoded->body}{}", signature: new Signature($decoded->signature), diff --git a/src/Multiversx.php b/src/Multiversx.php index 28e3ccb..7ff8d14 100644 --- a/src/Multiversx.php +++ b/src/Multiversx.php @@ -51,7 +51,7 @@ public static function apiWithCache(Carbon $expiresAt, ?ClientInterface $httpCli $expiresAt->diffInSeconds(now()), ); - $stack->push(new CacheMiddleware($cacheStrategy),'cache'); + $stack->push(new CacheMiddleware($cacheStrategy), 'cache'); $client = ClientFactory::create(config('multiversx.urls.api'), [ 'handler' => $stack, diff --git a/tests/Auth/NativeAuthServerTest.php b/tests/Auth/NativeAuthServerTest.php index 5bc7f1f..0c4eaec 100644 --- a/tests/Auth/NativeAuthServerTest.php +++ b/tests/Auth/NativeAuthServerTest.php @@ -11,18 +11,18 @@ use Peerme\MxLaravel\Exceptions\NativeAuthTokenExpiredException; beforeEach(function () { - $alicePem = "-----BEGIN PRIVATE KEY for erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th----- + $alicePem = '-----BEGIN PRIVATE KEY for erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th----- NDEzZjQyNTc1ZjdmMjZmYWQzMzE3YTc3ODc3MTIxMmZkYjgwMjQ1ODUwOTgxZTQ4 YjU4YTRmMjVlMzQ0ZThmOTAxMzk0NzJlZmY2ODg2NzcxYTk4MmYzMDgzZGE1ZDQy MWYyNGMyOTE4MWU2Mzg4ODIyOGRjODFjYTYwZDY5ZTE= - -----END PRIVATE KEY for erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th-----"; + -----END PRIVATE KEY for erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th-----'; $signer = UserSigner::fromPem($alicePem); $address = 'erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th'; $blockHash = '591a3cf6fc0d083179f18640e7c63e2b6a0711f95b9d67910bc525139fce106d'; $ttl = 86_400; $origin = 'api.multiversx.com'; - $init = rtrim(base64_encode($origin), '=') . '.' . $blockHash . '.' . $ttl . '.' . 'e30'; + $init = rtrim(base64_encode($origin), '=').'.'.$blockHash.'.'.$ttl.'.'.'e30'; $signature = $signer->sign((new SignableMessage( message: $address.$init, @@ -34,7 +34,7 @@ $this->signature = $signature; $this->blockHash = $blockHash; $this->ttl = $ttl; - $this->accessToken = rtrim(base64_encode($this->address), '=') . '.' . rtrim(base64_encode($init), '=') . '.' . $signature; + $this->accessToken = rtrim(base64_encode($this->address), '=').'.'.rtrim(base64_encode($init), '=').'.'.$signature; $this->blockTimestamp = 1671009408; $this->origin = $origin; $this->nativeServerConfig = [