fixes #193 fixes #192 fixes #107 - [x] Implement the new login process - [x] Tested - [x] Update the authenticator setup process - [x] Tested - [x] Update the authenticator remove process - [x] Tested - [x] Manifest format migrator - [x] Tested - [x] Make it possible to import SDA accounts - [x] Make sure confirmations still work - [x] Fetching - [x] Responding - [x] Make it so that the login process doesn't prompt for which method to use - [x] Make it so that device confirmation and email confirmation auth session guards work
85 lines
1.9 KiB
Rust
85 lines
1.9 KiB
Rust
use serde::Deserialize;
|
|
|
|
/// A mobile confirmation. There are multiple things that can be confirmed, like trade offers.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
|
pub struct Confirmation {
|
|
#[serde(rename = "type")]
|
|
pub conf_type: ConfirmationType,
|
|
pub type_name: String,
|
|
pub id: String,
|
|
/// Trade offer ID or market transaction ID
|
|
pub creator_id: String,
|
|
pub nonce: String,
|
|
pub creation_time: u64,
|
|
pub cancel: String,
|
|
pub accept: String,
|
|
pub icon: String,
|
|
pub multi: bool,
|
|
pub headline: String,
|
|
pub summary: Vec<String>,
|
|
}
|
|
|
|
impl Confirmation {
|
|
/// Human readable representation of this confirmation.
|
|
pub fn description(&self) -> String {
|
|
format!(
|
|
"{:?} - {} - {}",
|
|
self.conf_type,
|
|
self.headline,
|
|
self.summary.join(", ")
|
|
)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
|
#[repr(u32)]
|
|
#[serde(from = "u32")]
|
|
pub enum ConfirmationType {
|
|
Generic = 1,
|
|
Trade = 2,
|
|
MarketSell = 3,
|
|
AccountRecovery = 6,
|
|
Unknown(u32),
|
|
}
|
|
|
|
impl From<u32> for ConfirmationType {
|
|
fn from(text: u32) -> Self {
|
|
match text {
|
|
1 => ConfirmationType::Generic,
|
|
2 => ConfirmationType::Trade,
|
|
3 => ConfirmationType::MarketSell,
|
|
6 => ConfirmationType::AccountRecovery,
|
|
v => ConfirmationType::Unknown(v),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
pub struct ConfirmationListResponse {
|
|
pub success: bool,
|
|
pub conf: Vec<Confirmation>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize)]
|
|
pub struct SendConfirmationResponse {
|
|
pub success: bool,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_parse_email_change() -> anyhow::Result<()> {
|
|
let text = include_str!("fixtures/confirmations/email-change.json");
|
|
let confirmations = serde_json::from_str::<ConfirmationListResponse>(text)?;
|
|
|
|
assert_eq!(confirmations.conf.len(), 1);
|
|
|
|
let confirmation = &confirmations.conf[0];
|
|
|
|
assert_eq!(confirmation.conf_type, ConfirmationType::AccountRecovery);
|
|
|
|
Ok(())
|
|
}
|
|
}
|