Something went wrong. Try again.
A barebones implementation of an atproto PDS in PHP and Slim Framework 4.
pds php atproto
Something went wrong. Try again.
1.6 kB · 53 lines
PHP
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?php
declare(strict_types=1);
namespace App\Infrastructure\Persistence\Crypto;
use App\Domain\Crypto\SigningKeyRepository;use App\Domain\Crypto\StoredSigningKey;use App\Infrastructure\Database\Database;use App\Infrastructure\Database\Row;use DateTimeImmutable;
/** * SQLite-backed {@see SigningKeyRepository} on the per-actor `signing_key` * table (see {@see \App\Infrastructure\Database\Schema\ActorStoreSchema}). */final class SqliteSigningKeyRepository implements SigningKeyRepository{ public function __construct(private readonly Database $db) { }
public function get(): ?StoredSigningKey { $row = $this->db->fetchOne( 'SELECT curve, private_key, did_key, created_at FROM signing_key WHERE id = 1' ); if ($row === null) { return null; }
return new StoredSigningKey( curve: Row::str($row, 'curve'), privateKey: Row::str($row, 'private_key'), didKey: Row::str($row, 'did_key'), createdAt: new DateTimeImmutable(Row::str($row, 'created_at')), ); }
public function save(StoredSigningKey $key): void { $this->db->execute( 'INSERT OR REPLACE INTO signing_key (id, curve, private_key, did_key, created_at) VALUES (1, :curve, :private_key, :did_key, :created_at)', [ ':curve' => $key->getCurve(), ':private_key' => $key->getPrivateKey(), ':did_key' => $key->getDidKey(), ':created_at' => $key->getCreatedAt()->format(DATE_ATOM), ], ); }}