socialdept / atp-cbor
CBOR, CAR, and CID binary encoding for AT Protocol in PHP
Requires
- php: ^8.3
- ext-gmp: *
- simplito/elliptic-php: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.89
- phpunit/phpunit: ^11.0|^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
CBOR, CAR, and CID binary encoding for AT Protocol in PHP.
This package reads and writes the binary formats of the AT Protocol in plain PHP, with no Laravel dependency. It decodes and encodes DAG-CBOR, reads CAR archives and the records in a repository's tree, parses CIDs, checks getRecord proofs, and signs PLC operations with secp256k1 keys. To learn all about it, head over to the documentation.
Here are a few short examples of what you can do. Decode CBOR from a firehose event:
use SocialDept\AtpCbor\Core\CBOR; $decoded = CBOR::decode($binaryData);
Read the blocks of a CAR archive into a map of CID to bytes:
use SocialDept\AtpCbor\Core\CAR; $blocks = CAR::blockMap($carData);
Parse a CID and turn it back into a string:
use SocialDept\AtpCbor\Core\CID; $cid = CID::fromString('bafyreie5cvv4h45feadgeuwhbcutmh6t7ceseocckahdoe6uat64zmz454'); $cid->version; // 1 $cid->toString();
Check that a record from com.atproto.sync.getRecord sits where its repo's commit says:
use SocialDept\AtpCbor\Proof\RecordProof; $proven = RecordProof::verify($car, 'app.bsky.graph.verification', $rkey, did: $issuerDid); $proven->record;
Documentation
You'll find the documentation on https://socialde.pt/docs/atp-cbor.
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving it? Feel free to create an issue on GitHub.
Testing
vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more information.
