1. Go to this page and download the library: Download k2gl/in-toto-attestation 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/ */
k2gl / in-toto-attestation example snippets
use K2gl\InToto\Statement;
use K2gl\InToto\ResourceDescriptor;
use K2gl\Dsse\Ed25519Signer;
$statement = new Statement(
subject: [
new ResourceDescriptor(
name: 'pkg:composer/k2gl/[email protected]',
digest: ['sha256' => '…'],
),
],
predicateType: 'https://slsa.dev/provenance/v1',
predicate: ['buildDefinition' => [/* … */], 'runDetails' => [/* … */]],
);
$envelope = $statement->sign($signer); // a K2gl\Dsse\Envelope
echo $envelope->toJson();
use K2gl\InToto\PredicateRegistry;
use K2gl\InToto\Statement;
use K2gl\Dsse\Envelope;
use K2gl\Dsse\Ed25519Verifier;
$envelope = Envelope::fromJson($json);
$envelope->verify($verifier); // DSSE signature check (throws on failure)
$statement = Statement::fromEnvelope($envelope);
$statement->predicateType; // 'https://slsa.dev/provenance/v1'
$statement->subject[0]->digest; // ['sha256' => '…']
$statement->subject[0]->hasDigest('sha256', $expectedHex); // case-insensitive digest check
$statement->predicate(PredicateRegistry::default()); // typed Predicate when registered, else the raw array
use K2gl\InToto\StatementVersion;
$statement = Statement::fromEnvelope($envelope);
$statement->version === StatementVersion::V0_1; // true for a legacy bundle