From 17f20b25b83f24a34d544c2600abc3549ca6fc66 Mon Sep 17 00:00:00 2001 From: netkas Date: Tue, 7 Jan 2025 15:29:37 -0500 Subject: [PATCH] Add new RPC methods for client capabilities and authentication --- src/Socialbox/SocialClient.php | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Socialbox/SocialClient.php b/src/Socialbox/SocialClient.php index ad44546..20b2675 100644 --- a/src/Socialbox/SocialClient.php +++ b/src/Socialbox/SocialClient.php @@ -23,7 +23,6 @@ * * @param string|PeerAddress $peerAddress The address of the peer to connect to. * @param ExportedSession|null $exportedSession Optional. The exported session to use for communication. - * @param array $options Optional. Additional options to pass to the client. * @throws CryptographyException If the public key is invalid. * @throws ResolutionException If the domain cannot be resolved. * @throws RpcException If the RPC request fails. @@ -59,6 +58,19 @@ )->getResponse()->getResult()); } + /** + * Retrieves the list of allowed methods, these are the methods that can be called by the client. + * + * @return array The allowed methods returned from the RPC request. + * @throws RpcException Thrown if the RPC request fails. + */ + public function getAllowedMethods(): array + { + return $this->sendRequest( + new RpcRequest(StandardMethods::GET_ALLOWED_METHODS->value, Utilities::randomCrc32()) + )->getResponse()->getResult(); + } + /** * Fetches the privacy policy document by sending a remote procedure call request. * @@ -320,6 +332,28 @@ )->getResponse()->getResult(); } + /** + * Authenticates a password by sending a remote procedure call request with an optional hashing operation. + * + * @param string $password The password to authenticate. + * @param bool $hash Indicates whether the password should be hashed using SHA-512 before authentication. + * @return bool The result of the password authentication request. + * @throws RpcException Thrown if the RPC request fails. + */ + public function verificationPasswordAuthentication(string $password, bool $hash=true): bool + { + if($hash) + { + $password = hash('sha512', $password); + } + + return (bool)$this->sendRequest( + new RpcRequest(StandardMethods::VERIFICATION_PASSWORD_AUTHENTICATION->value, Utilities::randomCrc32(), [ + 'password' => $password + ]) + )->getResponse()->getResult(); + } + /** * Sets a new password for settings with optional hashing. *