From 808b066da6b97882e388bc24dd26882cb89f51e5 Mon Sep 17 00:00:00 2001 From: Ammar Arif Date: Fri, 14 Jun 2024 15:48:12 -0400 Subject: [PATCH] rename struct --- src/session.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/session.rs b/src/session.rs index c6d40d0..1c234fa 100644 --- a/src/session.rs +++ b/src/session.rs @@ -24,7 +24,7 @@ pub struct Policy { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct Session { +pub struct SessionDetails { /// The expiration date of the session. pub expires_at: String, /// The policies that the session is allowed to execute. @@ -36,12 +36,12 @@ pub struct Session { #[serde(rename_all = "camelCase")] pub struct SessionCredentials { /// The signing key of the session. - pub private_key: String, - pub authorization: Vec, + pub private_key: FieldElement, + pub authorization: Vec, } /// Retrieves the session for the given chain id. -pub fn get(chain_id: FieldElement) -> anyhow::Result { +pub fn get(chain_id: FieldElement) -> anyhow::Result { let credentials = Credentials::load()?; let username = credentials.account.expect("id must exist").id; let contents = fs::read_to_string(get_file_path(&username, chain_id))?; @@ -49,7 +49,7 @@ pub fn get(chain_id: FieldElement) -> anyhow::Result { } /// Stores the session on-disk. -pub fn store(chain_id: FieldElement, session: Session) -> anyhow::Result<()> { +pub fn store(chain_id: FieldElement, session: SessionDetails) -> anyhow::Result<()> { // TODO: maybe can store the authenticated user in a global variable so that // we don't have to call load again if we already did it before. let credentials = Credentials::load()?; @@ -72,7 +72,7 @@ pub fn store(chain_id: FieldElement, session: Session) -> anyhow::Result<()> { } #[tracing::instrument(level = "trace", skip(rpc_url), fields(policies = policies.len()))] -pub async fn create(rpc_url: U, policies: &[Policy]) -> anyhow::Result +pub async fn create(rpc_url: U, policies: &[Policy]) -> anyhow::Result where U: Into, { @@ -91,11 +91,11 @@ fn open_session_creation_page( username: &str, rpc_url: &str, policies: &[Policy], -) -> anyhow::Result> { +) -> anyhow::Result> { let params = prepare_query_params(username, rpc_url, policies)?; let url = format!("https://x.cartridge.gg/slot/session?{params}"); - let (tx, rx) = channel::(1); + let (tx, rx) = channel::(1); let server = callback_server(tx)?; // get the callback server url @@ -131,8 +131,9 @@ fn prepare_query_params( } /// Create the callback server that will receive the session token from the browser. -fn callback_server(tx: Sender) -> anyhow::Result { - let handler = move |State(tx): State>, Json(session): Json| async move { +fn callback_server(tx: Sender) -> anyhow::Result { + let handler = move |State(tx): State>, + Json(session): Json| async move { trace!("Received session token from the browser."); tx.send(session).await.expect("qed; channel closed"); };