lookyman/chronicle-api

此包已被弃用,不再维护。没有建议替代包。

与Chronicle交互的客户端库

2.0.1 2018-01-25 12:57 UTC

This package is auto-updated.

Last update: 2024-05-04 16:01:58 UTC


README

Chronicle交互的客户端库。

Build Status Coverage Status Downloads Latest stable PHPStan level License

安装

composer require lookyman/chronicle-api

用法

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());

对于客户端和请求工厂的实现,例如,您可以分别使用Guzzle 6 HTTP适配器Guzzle HTTP工厂

所有端点返回Http\Promise\Promise,因此您可以简单地使用->wait()等待响应,或者使用->then()异步处理它。响应只是普通的数组,在Chronicle的文档中查找结构。