Airship\Cabin\Bridge\Blueprint\ChannelUpdates::verifyUpdate PHP Method

verifyUpdate() public method

Return an encoded message containing the updates, and an encoded Ed25519 signature of the message.
public verifyUpdate ( SignatureSecretKey $sk, string $challenge ) : array
$sk SignatureSecretKey
$challenge string
return array
    public function verifyUpdate(SignatureSecretKey $sk, string $challenge) : array
    {
        $tree = $this->getUpdatedMerkleTree();
        $now = new \DateTime('now');
        $updates = ['challenge' => $challenge, 'root' => $tree->getRoot(), 'timestamp' => $now->format(\AIRSHIP_DATE_FORMAT)];
        $response = \json_encode($updates);
        return [Base64UrlSafe::encode($response), Base64UrlSafe::encode(AsymmetricCrypto::sign($response, $sk, true))];
    }

Usage Example

Example #1
0
 /**
  * @route notary/verify
  */
 public function verify()
 {
     // Input validation
     if (empty($_POST['challenge'])) {
         \Airship\json_response(['status' => 'error', 'message' => 'Expected a challenge=something HTTP POST parameter.']);
     }
     if (!\is_string($_POST['challenge'])) {
         \Airship\json_response(['status' => 'error', 'message' => 'Challenge must be a string.']);
     }
     if (Binary::safeStrlen($_POST['challenge']) < 20) {
         \Airship\json_response(['status' => 'error', 'message' => 'Challenge is too short. Continuum should be generating a long random nonce.']);
     }
     try {
         list($update, $signature) = $this->chanUp->verifyUpdate($this->sk, $_POST['challenge']);
         \Airship\json_response(['status' => 'OK', 'response' => $update, 'signature' => $signature]);
     } catch (\Exception $ex) {
         \Airship\json_response(['status' => 'error', 'message' => $ex->getMessage()]);
     }
 }