2017 © Pedro Peláez
 

library chronicle-api

Client library for interacting with Chronicle

image

lookyman/chronicle-api

Client library for interacting with Chronicle

  • Thursday, January 25, 2018
  • by lookyman
  • Repository
  • 2 Watchers
  • 8 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Lookyman/Chronicle

Client library for interacting with Chronicle., (*1)

Build Status Coverage Status Downloads Latest stable PHPStan level License, (*2)

Installation

composer require lookyman/chronicle-api

Usage

use Lookyman\Chronicle\Api;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\SigningPublicKey;
use ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;

$api = new Api(
    new Client(), // Client must implement Http\Client\HttpAsyncClient
    new RequestFactory(), // RequestFactory must implement Interop\Http\Factory\RequestFactoryInterface
    'https://chronicle.uri',
    new SigningPublicKey(Base64UrlSafe::decode('chronicle public key')) // optional, omit if you don't care about validating API responses
);
var_dump($api->lastHash()->wait());

// you must authenticate first before you can publish a message
$api->authenticate(
    new SigningSecretKey(Base64UrlSafe::decode('your secret key')),
    'your client id'
);
var_dump($api->publish('hello world')->wait());

For implementations of client and request factory, you can use for example Guzzle 6 HTTP Adapter and HTTP Factory for Guzzle respectively., (*3)

All endpoints return Http\Promise\Promise, so you can either just ->wait() for the response, or handle it asynchronously with ->then(). Responses are just plain arrays, look up the structure in the Chronicle's documentation., (*4)

The Versions