From fb8422ce5fd8bd8e2c8da25f817ebbf17c97696b Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 28 Oct 2025 14:09:40 -0400 Subject: [PATCH] xs idx --- .../src/error/grok_client_error.rs | 4 ++ .../src/requests/index_page/mod.rs | 1 + .../generate_sign_for_new_conversation.rs | 2 +- .../src/requests/index_page/signature/mod.rs | 2 + .../index_page/signature/signature_xs.rs | 67 +++++++++++++++++++ .../src/requests/index_page/utils/mod.rs | 1 - 6 files changed, 75 insertions(+), 2 deletions(-) rename crates/api_clients/grok_client/src/requests/index_page/{utils => signature}/generate_sign_for_new_conversation.rs (96%) create mode 100644 crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs create mode 100644 crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs diff --git a/crates/api_clients/grok_client/src/error/grok_client_error.rs b/crates/api_clients/grok_client/src/error/grok_client_error.rs index 04c2a36dc6..f1c8f5be96 100644 --- a/crates/api_clients/grok_client/src/error/grok_client_error.rs +++ b/crates/api_clients/grok_client/src/error/grok_client_error.rs @@ -41,6 +41,9 @@ pub enum GrokClientError { /// Our script logic is out of date ScriptLogicOutOfDate, + /// Signature algorithm isn't working with inputs + BadSignatureInputs, + // /// An error reading the file for upload. // FileForUploadReadError(std::io::Error), // @@ -95,6 +98,7 @@ impl Display for GrokClientError { Self::FailedToDecodeVerificationToken(err) => write!(f, "Failed to decode verification token: {}", err), Self::InvalidVerificationTokenBytes => write!(f, "Invalid verification token bytes"), Self::ScriptLogicOutOfDate => write!(f, "Script logic out of date"), + Self::BadSignatureInputs => write!(f, "Bad signature inputs"), //Self::FileForUploadReadError(err) => write!(f, "Error reading file for upload: {}", err), //Self::FileForUploadHasInvalidPath => write!(f, "The file path provided for upload is invalid."), diff --git a/crates/api_clients/grok_client/src/requests/index_page/mod.rs b/crates/api_clients/grok_client/src/requests/index_page/mod.rs index 50ec10588b..8b585e2185 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/mod.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/mod.rs @@ -3,4 +3,5 @@ pub mod get_index_page; pub mod get_index_page_and_scripts; pub mod get_numbers; pub mod index_parsers; +pub mod signature; pub mod utils; diff --git a/crates/api_clients/grok_client/src/requests/index_page/utils/generate_sign_for_new_conversation.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/generate_sign_for_new_conversation.rs similarity index 96% rename from crates/api_clients/grok_client/src/requests/index_page/utils/generate_sign_for_new_conversation.rs rename to crates/api_clients/grok_client/src/requests/index_page/signature/generate_sign_for_new_conversation.rs index e34166b825..d55d6f476e 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/utils/generate_sign_for_new_conversation.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/generate_sign_for_new_conversation.rs @@ -83,7 +83,7 @@ pub fn generate_sign(args: GenerateSignArgs<'_>) -> Result<(), GrokClientError> mod tests { use errors::AnyhowResult; use crate::requests::index_page::index_parsers::parse_index_verification_token::VerificationToken; - use crate::requests::index_page::utils::generate_sign_for_new_conversation::{generate_sign, GenerateSignArgs}; + use crate::requests::index_page::signature::generate_sign_for_new_conversation::{generate_sign, GenerateSignArgs}; #[test] fn test() -> AnyhowResult<()> { diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs new file mode 100644 index 0000000000..090061232a --- /dev/null +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/mod.rs @@ -0,0 +1,2 @@ +pub mod signature_xs; +pub mod generate_sign_for_new_conversation; \ No newline at end of file diff --git a/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs new file mode 100644 index 0000000000..312d444b4c --- /dev/null +++ b/crates/api_clients/grok_client/src/requests/index_page/signature/signature_xs.rs @@ -0,0 +1,67 @@ +use crate::error::grok_client_error::GrokClientError; + +/* + @staticmethod + def xs(x_bytes: bytes, svg: str, x_values: list) -> str: + arr = list(x_bytes) -- we already have this + idx = arr[x_values[0]] % 16 + c = ((arr[x_values[1]] % 16) * (arr[x_values[2]] % 16)) * (arr[x_values[3]] % 16) + o = Signature.xa(svg) + vals = o[idx] + k = Signature.simulateStyle(vals, c) + + concat = str(k["color"]) + str(k["transform"]) + matches = findall(r"[\d\.\-]+", concat) + converted = [] + for m in matches: + num = float(m) + hexstr = Signature.tohex(num) + converted.append(hexstr) + joined = "".join(converted) + cleaned = joined.replace(".", "").replace("-", "") + return cleaned + */ + +/// `bytes` is +/// `svg_data` is the svg path stroke data +/// `x_values` are the magic numbers from the script +pub fn signature_xs(x_bytes: &[u8], svg_data: &str, x_values: &[u8]) -> Result { + /* +Inputs: +> xs.x_bytes = b'\xca\xddz\th\x94#\x8d\xac\xef\x01\x86x\xcc\\tB\x13\xdah\x8f\x17\x93\xd58fE\xd4\x97\x1a{\xb2\xbb\x1c\xc4+-\xe28E6.~g_\x04\x86T' +> xs.svg = M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110 +> xs.x_values = [40, 18, 3, 18] +Arr becomes: +xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 116, 66, 19, 218, 104, 143, 23, 147, 213, 56, 102, 69, 212, 151, 26, 123, 178, 187, 28, 196, 43, 45, 226, 56, 69, 54, 46, 126, 103, 95, 4, 134, 84] + */ + + // arr = list(x_bytes) -- we already have this as the input + let arr = x_bytes; + + // idx = arr[x_values[0]] % 16 + let i = x_values.get(0).map(|x| *x as usize).ok_or_else(|| GrokClientError::BadSignatureInputs)?; + let a = arr.get(i).map(|x| *x).ok_or_else(|| GrokClientError::BadSignatureInputs)?; + let idx = a % 16; + + println!("idx = {}", idx); + + + + Ok("".to_string()) +} + +#[cfg(test)] +mod tests { + use crate::requests::index_page::signature::signature_xs::signature_xs; + + #[test] + fn test() { + let x_bytes = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 116, 66, 19, 218, 104, 143, 23, 147, 213, 56, 102, 69, 212, 151, 26, 123, 178, 187, 28, 196, 43, 45, 226, 56, 69, 54, 46, 126, 103, 95, 4, 134, 84]; + let svg_data = "M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110"; + let x_values = [40, 18, 3, 18]; + + signature_xs(&x_bytes, &svg_data, &x_values).unwrap(); + + assert_eq!(1,2); + } +} \ No newline at end of file diff --git a/crates/api_clients/grok_client/src/requests/index_page/utils/mod.rs b/crates/api_clients/grok_client/src/requests/index_page/utils/mod.rs index 721c7e15a7..ff7f448a17 100644 --- a/crates/api_clients/grok_client/src/requests/index_page/utils/mod.rs +++ b/crates/api_clients/grok_client/src/requests/index_page/utils/mod.rs @@ -1,4 +1,3 @@ pub mod find_script_actions_and_xsid; -pub mod generate_sign_for_new_conversation; pub mod parse_numbers_from_xsid_script; pub mod verification_token_to_loading_anim;