NOMAD_PROTOCOL_VERSION ]; Hook::call('zot_revision', $x); return $x['revision']; } public static function get_std_version(): string { if (defined('STD_VERSION')) { return STD_VERSION; } return '0.0.0'; } public static function getVapidKey() { $private_key = openssl_pkey_new([ 'private_key_type' => OPENSSL_KEYTYPE_EC, 'curve_name' => 'prime256v1', ]); $details = openssl_pkey_get_details($private_key); $private_key_raw = $details['ec']['d']; $public_key_raw = $details['ec']['x'] . $details['ec']['y']; $auth_token = base64_encode(openssl_random_pseudo_bytes(16)); $vapid = [ 'private_key' => rtrim(strtr(base64_encode($private_key_raw), '+/', '-_'), '='), 'public_key' => rtrim(strtr(base64_encode($public_key_raw), '+/', '-_'), '='), 'auth_token' => $auth_token, ]; return json_encode($vapid); } public static function getApplicationServerKey($vapid) { $publicKey = $vapid['public_key']; $public_key_bytes = base64_decode($publicKey); // Check that the public key has the correct format if (strlen($public_key_bytes) != 65 || ord($public_key_bytes[0]) != 4) { // The public key has an incorrect format // Handle the error here } // Extract the x and y coordinates of the point $x = substr($public_key_bytes, 1, 32); $y = substr($public_key_bytes, 33, 32); // Pack the bytes of the public key in the correct order $application_server_key = "\x04" . $x . $y; return base64_encode($application_server_key); } }