From d82e7042a6faa6291e4e0c102b9cb27710ab5833 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 11 Feb 2025 14:50:57 -0500 Subject: [PATCH] Added client method createSignature --- src/Socialbox/SocialClient.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Socialbox/SocialClient.php b/src/Socialbox/SocialClient.php index 2d19b77..e05b80c 100644 --- a/src/Socialbox/SocialClient.php +++ b/src/Socialbox/SocialClient.php @@ -16,6 +16,7 @@ use Socialbox\Exceptions\ResolutionException; use Socialbox\Exceptions\RpcException; use Socialbox\Objects\Client\ExportedSession; + use Socialbox\Objects\Client\SignatureKeyPair; use Socialbox\Objects\PeerAddress; use Socialbox\Objects\RpcRequest; use Socialbox\Objects\Standard\Contact; @@ -44,6 +45,35 @@ parent::__construct($identifiedAs, $server, $exportedSession); } + /** + * Create a new signing keypair, sends it to the server and saves it locally with the session so that the client + * can use the SigningKey pair for signing and verifying signatures in the future. + * + * This is not a server-side operation, the server only stores the public key and associates it with the peer's + * profile. The private key is stored locally and is never sent to the server. + * + * @param string|null $name Optional. The name of the signature + * @param int|null $expires Optional. The Unix timestamp of the expiration time + * @return string The UUID of the signature + * @throws CryptographyException Thrown if there was an error while generating the signing key pair + * @throws RpcException Thrown if there was an error with the RPC request + */ + public function createSignature(?string $name=null, ?int $expires=null): string + { + $signature = Cryptography::generateSigningKeyPair(); + $uuid = $this->settingsAddSignature($signature->getPublicKey(), $name, $expires); + + $this->addSigningKey(new SignatureKeyPair([ + 'uuid' => $uuid, + 'name' => $name, + 'public_key' => $signature->getPublicKey(), + 'private_key' => $signature->getPrivateKey(), + 'expires' => $expires + ])); + + return $uuid; + } + /** * Adds a new peer to the AddressBook, returns True upon success or False if the contact already exists in * the address book.