actorRepository = $actorRepository; $this->appViewClient = $appViewClient; } /** * {@inheritdoc} */ protected function action(): Response { $params = $this->request->getQueryParams(); $handleParam = $params['handle'] ?? null; if (!is_string($handleParam) || trim($handleParam) === '') { $this->throwMissingKeyException('handle'); } $this->validateHandle($handleParam); // attempting to find the handle in our database try { $actor = $this->actorRepository->findActorByHandle($handleParam); return $this->respondWithData(new ResolveHandleResponse($actor->getDid())); } catch (ActorNotFoundException $e) { /** @var array{hostname: string} $pdsSettings */ $pdsSettings = $this->settings->get('pds'); $hostname = $pdsSettings['hostname']; if (str_ends_with($handleParam, ".{$hostname}")) { // we know for a fact that this handle should belong // to us, but we can't find it throw XrpcException::invalidRequest('Unable to resolve handle'); } } // defer to the appview for handles we don't host try { $did = $this->appViewClient->resolveHandle($handleParam); } catch (AppViewException $e) { throw XrpcException::invalidRequest('Unable to resolve handle'); } return $this->respondWithData(new ResolveHandleResponse($did)); } private function validateHandle(string $handle): void { $length = strlen($handle); if ($length < 3 || $length > 18) { throw XrpcException::invalidParam( $this->actionName, 'Invalid handle', $handle ); } } }