public function requestCertificate(string $csr): Promise {
        return call(function () use ($csr) {
            $begin = 'REQUEST-----';
            $end = '----END';

            $beginPos = strpos($csr, $begin) + strlen($begin);

            if ($beginPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, $beginPos);

            $endPos = strpos($csr, $end);

            if ($endPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, 0, $endPos);

            $enc = new Base64UrlSafeEncoder;

            /** @var Response $response */
            $response = yield $this->acmeClient->post(AcmeResource::NEW_CERTIFICATE, [
                'csr' => $enc->encode(base64_decode($csr)),
            ]);

            if ($response->getStatus() === 201) {
                if (!$response->hasHeader('location')) {
                    throw new AcmeException('Protocol Violation: No Location Header');
                }

                return $response->getHeader('location');
            }

            throw $this->generateException($response, yield $response->getBody());
        });
    }