Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Apr 6, 2023
1 parent 369cee8 commit e4840a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/Auth/NativeAuthServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');

Expand All @@ -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);
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/Multiversx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions tests/Auth/NativeAuthServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [
Expand Down

0 comments on commit e4840a5

Please sign in to comment.