PHP code example of fissible / attest-laravel

1. Go to this page and download the library: Download fissible/attest-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fissible / attest-laravel example snippets


use Fissible\AttestLaravel\Facades\Attest;

Attest::chain('tenant:5')->record('contract.approved', [
    'contract_id' => 'C-2026-014',
    'approved_by' => 'user:7',
    'amount'      => 50_000,
]);

use Fissible\AttestLaravel\Facades\Attest;

$envelope = Attest::chain('tenant:5')->record('cms.entry.published', [
    'entry_id' => 42,
    'checksum' => 'sha256:abc...',
    'actor_id' => 7,
]);

use Fissible\AttestLaravel\Models\AttestEnvelope;

Attest::chain('tenant:5')->record(
    type: 'agent.decision',
    payload: ['disposition' => 'permit'],
    subject: 'order:42',
    correlation: $invocationId,
    tenant: 'acme',
);

$envelopes = AttestEnvelope::query()->forCorrelation($invocationId)->get();

foreach ($envelopes as $envelope) {
    $signed = $envelope->signed();   // decode the artifact itself
}

use Fissible\Attest\Chain\ChainStore;
use Fissible\Attest\Canonical\JcsEncoder;
use Fissible\Attest\Signing\Signer;
use Fissible\AttestLaravel\Import\EloquentImportMarkerTrait;
use Fissible\AttestLaravel\Import\GenericJsonlImporter;
use Fissible\AttestLaravel\Import\JsonlImportContext;
use Fissible\AttestLaravel\Import\JsonlImportOptions;
use Illuminate\Database\ConnectionInterface;

final class UpdaterAuditImporter extends GenericJsonlImporter
{
    use EloquentImportMarkerTrait;

    public function __construct(
        ChainStore $store,
        Signer $signer,
        private readonly ConnectionInterface $connection,
    ) {
        parent::__construct($store, $signer);
    }

    protected function importer(): string
    {
        return 'ops.updater.audit.global.v1';
    }

    protected function importMarkerConnection(): ConnectionInterface
    {
        return $this->connection;
    }

    protected function parseLine(string $line, int $lineNumber): ?array
    {
        $decoded = json_decode($line, true, flags: JSON_THROW_ON_ERROR);
        if (! is_array($decoded)) {
            throw new \RuntimeException("Line $lineNumber is not a JSON object.");
        }
        return $decoded;
    }

    protected function chainIdFor(array $parsed, JsonlImportContext $context): string
    {
        return 'updater:global';
    }

    protected function contentHashFor(array $parsed, JsonlImportContext $context): string
    {
        return hash('sha256', JcsEncoder::encode($parsed));
    }

    protected function buildPayload(array $parsed, JsonlImportContext $context): array
    {
        return $parsed;
    }
}

use Illuminate\Support\Facades\Schedule;

Schedule::command('attest:anchor --chain=tenant:5')->hourly();

use Fissible\AttestLaravel\Verification\ChainVerifier;
use Fissible\AttestLaravel\Verification\VerificationRequest;

$result = app(ChainVerifier::class)->verify(new VerificationRequest(
    chainId: 'tenant:5',
    trustedKeys: ['prod=<base64-public-key>'],
));

if ($result->isVerified()) {
    // $result->verifiedThroughSeq is the verified range extent.
}
bash
php artisan attest:verify --chain=tenant:5 --trusted-key=prod=<base64-public-key>
bash
composer vendor:publish --tag=attest-config
php artisan vendor:publish --tag=attest-migrations
php artisan migrate
bash
php artisan attest:anchor --chain=tenant:5 --from=1 --to=100 --sync
bash
php artisan attest:anchor --chain=tenant:5 --from=1 --queue=anchors
bash
php artisan attest:verify --chain=tenant:5 --trusted-key=prod=<base64-public-key>
bash
php artisan attest:verify \
    --chain=tenant:5 \
    --trusted-key=prod=<base64-public-key> \
    --min-anchor=local_only
bash
php artisan attest:bundle:export \
    --chain=tenant:5 \
    --from=1 \
    --to=100 \
    --out=storage/app/tenant-5.attest
bash
php artisan attest:bundle:verify \
    --bundle=storage/app/tenant-5.attest \
    --trusted-key=prod=<base64-public-key> \
    --min-anchor=local_only
bash
php artisan attest:integrity:audit --chain=tenant:5