From 8920080ada6c5705e2be086ffbf2f85e19e10640 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 3 Feb 2025 15:00:37 -0500 Subject: [PATCH] Added method VerifyPeerSignature --- .../Core/VerifyPeerSignature.php | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/Socialbox/Classes/StandardMethods/Core/VerifyPeerSignature.php diff --git a/src/Socialbox/Classes/StandardMethods/Core/VerifyPeerSignature.php b/src/Socialbox/Classes/StandardMethods/Core/VerifyPeerSignature.php new file mode 100644 index 0000000..0d7f079 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/Core/VerifyPeerSignature.php @@ -0,0 +1,83 @@ +containsParameter('signing_peer')) + { + throw new MissingRpcArgumentException('signing_peer'); + } + + if(!$rpcRequest->containsParameter('signature_uuid')) + { + throw new MissingRpcArgumentException('signature_uuid'); + } + + if(!$rpcRequest->containsParameter('signature_key')) + { + throw new MissingRpcArgumentException('signature_key'); + } + + if(!$rpcRequest->containsParameter('signature')) + { + throw new MissingRpcArgumentException('signature'); + } + + if(!$rpcRequest->containsParameter('message_hash')) + { + throw new MissingRpcArgumentException('message_hash'); + } + + if(!$rpcRequest->containsParameter('signature_time')) + { + throw new MissingRpcArgumentException('signature_time'); + } + + // Parse the peer address + try + { + $peerAddress = PeerAddress::fromAddress($rpcRequest->getParameter('signing_peer')); + } + catch(InvalidArgumentException $e) + { + throw new InvalidRpcArgumentException('signing_peer', $e); + } + + try + { + return $rpcRequest->produceResponse(Socialbox::verifyPeerSignature( + signingPeer: $peerAddress, + signatureUuid: $rpcRequest->getParameter('signature_uuid'), + signatureKey: $rpcRequest->getParameter('signature_key'), + signature: $rpcRequest->getParameter('signature'), + messageHash: $rpcRequest->getParameter('message_hash'), + signatureTime: $rpcRequest->getParameter('signature_time') + )->value); + } + catch (Exception $e) + { + throw new StandardRpcException('Failed to resolve peer signature', StandardError::INTERNAL_SERVER_ERROR, $e); + } + } + } \ No newline at end of file