Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make DPoPKey serializable by storing keys as PEM strings

+34 -14
+30 -6
src/Data/DPoPKey.php
··· 4 4 5 5 use phpseclib3\Crypt\Common\PrivateKey; 6 6 use phpseclib3\Crypt\Common\PublicKey; 7 + use phpseclib3\Crypt\PublicKeyLoader; 7 8 8 9 class DPoPKey 9 10 { 11 + protected string $privateKeyPem; 12 + 13 + protected string $publicKeyPem; 14 + 10 15 public function __construct( 11 - public readonly PrivateKey $privateKey, 12 - public readonly PublicKey $publicKey, 16 + PrivateKey|string $privateKey, 17 + PublicKey|string $publicKey, 13 18 public readonly string $keyId, 14 - ) {} 19 + ) { 20 + // Store as PEM strings for serialization 21 + $this->privateKeyPem = $privateKey instanceof PrivateKey 22 + ? $privateKey->toString('PKCS8') 23 + : $privateKey; 24 + 25 + $this->publicKeyPem = $publicKey instanceof PublicKey 26 + ? $publicKey->toString('PKCS8') 27 + : $publicKey; 28 + } 29 + 30 + public function getPrivateKey(): PrivateKey 31 + { 32 + return PublicKeyLoader::load($this->privateKeyPem); 33 + } 34 + 35 + public function getPublicKey(): PublicKey 36 + { 37 + return PublicKeyLoader::load($this->publicKeyPem); 38 + } 15 39 16 40 public function getPublicJwk(): array 17 41 { 18 - $jwks = json_decode($this->publicKey->toString('JWK'), true); 42 + $jwks = json_decode($this->getPublicKey()->toString('JWK'), true); 19 43 20 44 // phpseclib returns JWKS format {"keys":[...]}, extract the first key 21 45 $jwk = $jwks['keys'][0] ?? $jwks; ··· 32 56 33 57 public function getPrivateJwk(): array 34 58 { 35 - $jwks = json_decode($this->privateKey->toString('JWK'), true); 59 + $jwks = json_decode($this->getPrivateKey()->toString('JWK'), true); 36 60 37 61 // phpseclib returns JWKS format {"keys":[...]}, extract the first key 38 62 $jwk = $jwks['keys'][0] ?? $jwks; ··· 49 73 50 74 public function toPEM(): string 51 75 { 52 - return $this->privateKey->toString('PKCS8'); 76 + return $this->privateKeyPem; 53 77 } 54 78 }
+4 -8
src/Storage/EncryptedFileKeyStore.php
··· 3 3 namespace SocialDept\AtpClient\Storage; 4 4 5 5 use Illuminate\Contracts\Encryption\Encrypter; 6 - use phpseclib3\Crypt\PublicKeyLoader; 7 6 use SocialDept\AtpClient\Contracts\KeyStore; 8 7 use SocialDept\AtpClient\Data\DPoPKey; 9 8 ··· 23 22 public function store(string $sessionId, DPoPKey $key): void 24 23 { 25 24 $data = [ 26 - 'privateKey' => $key->privateKey->toString('PKCS8'), 27 - 'publicKey' => $key->publicKey->toString('PKCS8'), 25 + 'privateKey' => $key->toPEM(), 26 + 'publicKey' => $key->getPublicKey()->toString('PKCS8'), 28 27 'keyId' => $key->keyId, 29 28 ]; 30 29 ··· 47 46 $encrypted = file_get_contents($path); 48 47 $data = $this->encrypter->decrypt($encrypted); 49 48 50 - $privateKey = PublicKeyLoader::load($data['privateKey']); 51 - $publicKey = PublicKeyLoader::load($data['publicKey']); 52 - 53 49 return new DPoPKey( 54 - privateKey: $privateKey, 55 - publicKey: $publicKey, 50 + privateKey: $data['privateKey'], 51 + publicKey: $data['publicKey'], 56 52 keyId: $data['keyId'], 57 53 ); 58 54 }