Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Discord REST API</title>
- <meta charset="UTF-8" />
- </head>
- <body>
- <?php
- use Elliptic\EdDSA;
- class Interaction
- {
- public static function verifyKey($rawBody, $signature, $timestamp, $client_public_key)
- {
- $ec = new EdDSA('ed25519');
- $key = $ec->keyFromPublic($client_public_key, 'hex');
- $message = array_merge(unpack('C*', $timestamp), unpack('C*', $rawBody));
- return $key->verify($message, $signature) == TRUE;
- }
- }
- abstract class InteractionResponseFlags
- {
- const EPHEMERAL = 1 << 6;
- }
- abstract class InteractionResponseType
- {
- const PONG = 1;
- const ACKNOWLEDGE = 2;
- const CHANNEL_MESSAGE = 3;
- const CHANNEL_MESSAGE_WITH_SOURCE = 4;
- const ACKNOWLEDGE_WITH_SOURCE = 5;
- }
- abstract class InteractionType
- {
- const PING = 1;
- const APPLICATION_COMMAND = 2;
- }
- if(isset($_POST["type"]))
- {
- if($_POST["type"] === 1)
- {
- $CLIENT_PUBLIC_KEY = getenv('CLIENT_PUBLIC_KEY');
- $signature = $_SERVER['HTTP_X_SIGNATURE_ED25519'];
- $timestamp = $_SERVER['HTTP_X_SIGNATURE_TIMESTAMP'];
- $postData = file_get_contents('php://input');
- if(Interaction::verifyKey($postData, $signature, $timestamp, $CLIENT_PUBLIC_KEY))
- {
- echo json_encode(array(
- 'type' => InteractionResponseType::PONG
- ));
- }
- else
- {
- http_response_code(401);
- echo "Not verified";
- }
- http_response_code(200);
- echo json_encode(array("type" => 1));
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement