From fe217002e3cc36f02b315f89140f529eba91edce Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 29 Jan 2025 15:25:36 -0500 Subject: [PATCH] Added method (incomplete) ResolvePeerSignature --- .../StandardMethods/ResolvePeerSignature.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Socialbox/Classes/StandardMethods/ResolvePeerSignature.php diff --git a/src/Socialbox/Classes/StandardMethods/ResolvePeerSignature.php b/src/Socialbox/Classes/StandardMethods/ResolvePeerSignature.php new file mode 100644 index 0000000..be46141 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/ResolvePeerSignature.php @@ -0,0 +1,68 @@ +containsParameter('peer')) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'peer' parameter"); + } + + if(!$rpcRequest->containsParameter('uuid')) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'uuid' parameter"); + } + + try + { + $uuid = Uuid::fromString($rpcRequest->getParameter('uuid')); + } + catch(InvalidArgumentException $e) + { + throw new StandardException('Invalid UUID', StandardError::RPC_INVALID_ARGUMENTS, $e); + } + + // Parse the peer address + try + { + $peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('peer')); + } + catch(InvalidArgumentException $e) + { + throw new StandardException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e); + } + + try + { + return $rpcRequest->produceResponse(Socialbox::resolvePeerSignature($peerAddress, $uuid->toRfc4122())); + } + catch(StandardException $e) + { + throw $e; + } + catch (Exception $e) + { + throw new StandardException('Failed to resolve peer signature', StandardError::INTERNAL_SERVER_ERROR, $e); + } + } + } \ No newline at end of file