PHP Classes

File: docs/

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  Chronicle  >  docs/  >  Download  
File: docs/
Role: Example script
Content type: text/markdown
Description: Example script
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change:
Date: 4 years ago
Size: 2,214 bytes


Class file image Download

How to Write to Your Chronicle

Important: Any HTTP client that signs messages with Ed25519 as defined in the Sapient specification can write to a Chronicle, regardless of what programming language you're using. If you're not a PHP developer, don't be discouraged just because our examples are in PHP.

If you have an HTTP client, such as Guzzle, with a Sapient adapter, all you need to do is send messages like so:


use ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;
use ParagonIE\Sapient\Sapient;
use GuzzleHttp\Client;

 * @global SigningSecretKey $secret
 * @global Sapient $sapient
 * @global Client $http 

$message = 'lorem ipsum';

// Create a signed HTTP request (PSR-7)
$request = $sapient->createSignedRequest(

// Send the request to the Chronicle
$response = $http->send($request);

If the request was successful, the JSON response you receive should include a valid signature.


use GuzzleHttp\Psr7\Response;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\Sapient\Exception\{

 * @global Response $response
 * @global SigningPublicKey $publicKey

try {
    $decoded = $sapient->decodeSignedJsonResponse($response, $publicKey);
} catch (InvalidMessageException $ex) {
    // Invalid signature
} catch (HeaderMissingException $ex) {
    // Not signed

The above snippet assumes that you've already created a keypair for the client, and loaded it like so:

use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;

 * @global string $secretKeyText 

$secret = new SigningSecretKey(

This creates a SigningSecretKey object, which is used by Sapient.

For more information send a message to info at phpclasses dot org.