Add AddressBookRevokeAllSignatures method for revoking all signing keys of a contact

https://github.com/nosial/Socialbox-PHP/issues/73
This commit is contained in:
netkas 2025-03-13 14:20:27 -04:00
parent 86f18b577a
commit 66d2cd7907
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
3 changed files with 97 additions and 2 deletions

View file

@ -0,0 +1,58 @@
<?php
namespace Socialbox\Classes\StandardMethods\AddressBook;
use Socialbox\Abstracts\Method;
use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
use Socialbox\Exceptions\Standard\StandardRpcException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\ContactManager;
use Socialbox\Objects\ClientRequest;
use Socialbox\Objects\PeerAddress;
use Socialbox\Objects\RpcRequest;
class AddressBookRevokeAllSignatures extends Method
{
/**
* @inheritDoc
* @noinspection DuplicatedCode
*/
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
{
if(!$rpcRequest->containsParameter('peer'))
{
throw new MissingRpcArgumentException('peer');
}
$peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer'));
try
{
// Check if the contact already exists
$contact = ContactManager::getContact($request->getPeer(), $peerAddress);
}
catch (DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to check contact state with calling peer', StandardError::INTERNAL_SERVER_ERROR, $e);
}
if($contact === null)
{
return $rpcRequest->produceResponse(false);
}
try
{
ContactManager::removeAllContactSigningKeys($contact);
}
catch (DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to remove all contact signatures', StandardError::INTERNAL_SERVER_ERROR, $e);
}
// Return success
return $rpcRequest->produceResponse(true);
}
}