* rev: "" * prev: nullable, * sig: * } * * @see https://atproto.com/specs/repository */ final class Commit { public const VERSION = 3; public static function fromUnsigned( UnsignedCommit $unsigned, Keypair $signer, DagCborEncoder $cborEncoder, ): self { $unsignedBytes = $cborEncoder->encode($unsigned->toMap()); $signature = $signer->sign($unsignedBytes); return new self( $unsigned->getDid(), $unsigned->getData(), $unsigned->getRev(), $unsigned->getPrev(), $signature, ); } public function __construct( private readonly string $did, private readonly CidLink $data, private readonly string $rev, private readonly ?CidLink $prev, private readonly string $signature, ) { } public function getDid(): string { return $this->did; } public function getData(): CidLink { return $this->data; } public function getRev(): string { return $this->rev; } public function getPrev(): ?CidLink { return $this->prev; } public function getSignature(): string { return $this->signature; } /** * @return array */ public function toMap(): array { return [ 'did' => $this->did, 'version' => self::VERSION, 'data' => $this->data, 'rev' => $this->rev, 'prev' => $this->prev, 'sig' => new CborBytes($this->signature), ]; } }