/** * Fetch a public key and check the capability of the threemaId * * @param string $threemaId * @param \Closure $capabilityCheck * @return string Public key as binary * @throws Exception */ private final function fetchPublicKeyAndCheckCapability($threemaId, \Closure $capabilityCheck = null) { //fetch the public key $receiverPublicKey = $this->connection->fetchPublicKey($threemaId); if (null === $receiverPublicKey || !$receiverPublicKey->isSuccess()) { throw new Exception('Invalid threema id'); } if (null !== $capabilityCheck) { //check capability $capability = $this->connection->keyCapability($threemaId); if (null === $capability || false === $capabilityCheck->__invoke($capability)) { throw new Exception('threema id does not have the capability'); } } return $this->cryptTool->hex2bin($receiverPublicKey->getPublicKey()); }