Skip to content

Commit bc89542

Browse files
committed
fixup! feat(truapi-platform): add host capability traits
1 parent 1ae2018 commit bc89542

2 files changed

Lines changed: 58 additions & 26 deletions

File tree

rust/crates/truapi-platform/src/lib.rs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,67 @@ use url::Url;
3131
pub struct RuntimeConfig {
3232
/// Canonical product identifier used for account derivation.
3333
pub product_id: String,
34+
/// Host metadata shown by the wallet during SSO pairing.
35+
pub host_info: HostInfo,
36+
/// Platform metadata shown by the wallet during SSO pairing.
37+
pub platform_info: PlatformInfo,
38+
/// People-chain genesis hash used for statement-store SSO.
39+
pub people_chain_genesis_hash: [u8; 32],
40+
/// Deeplink URI scheme used in pairing QR payloads, without `://`.
41+
pub pairing_deeplink_scheme: String,
42+
}
43+
44+
/// Host metadata shown by the wallet during SSO pairing.
45+
#[derive(Debug, Clone, PartialEq, Eq)]
46+
pub struct HostInfo {
3447
/// Host name shown by the wallet during SSO pairing.
35-
pub host_name: String,
48+
pub name: String,
3649
/// Optional host icon URL/CID shown by the wallet during SSO pairing.
37-
pub host_icon: Option<String>,
50+
pub icon: Option<String>,
3851
/// Optional host version shown by the wallet during SSO pairing.
39-
pub host_version: Option<String>,
52+
pub version: Option<String>,
53+
}
54+
55+
/// Platform metadata shown by the wallet during SSO pairing.
56+
#[derive(Debug, Clone, Default, PartialEq, Eq)]
57+
pub struct PlatformInfo {
4058
/// Optional platform/browser name shown by the wallet during SSO pairing.
41-
pub platform_type: Option<String>,
59+
pub kind: Option<String>,
4260
/// Optional platform/browser version shown by the wallet during SSO pairing.
43-
pub platform_version: Option<String>,
44-
/// People-chain genesis hash used for statement-store SSO.
45-
pub people_chain_genesis_hash: [u8; 32],
46-
/// Deeplink URI scheme used in pairing QR payloads, without `://`.
47-
pub pairing_deeplink_scheme: String,
61+
pub version: Option<String>,
4862
}
4963

5064
impl RuntimeConfig {
5165
/// Build a runtime config, validating fields whose representation cannot
5266
/// be made invalid by Rust types alone.
53-
pub fn new(config: Self) -> Result<Self, RuntimeConfigValidationError> {
67+
pub fn new(
68+
product_id: String,
69+
host_info: HostInfo,
70+
platform_info: PlatformInfo,
71+
people_chain_genesis_hash: [u8; 32],
72+
pairing_deeplink_scheme: String,
73+
) -> Result<Self, RuntimeConfigValidationError> {
74+
let config = Self {
75+
product_id,
76+
host_info,
77+
platform_info,
78+
people_chain_genesis_hash,
79+
pairing_deeplink_scheme,
80+
};
5481
config.validate()?;
5582
Ok(config)
5683
}
5784

5885
fn validate(&self) -> Result<(), RuntimeConfigValidationError> {
5986
require_non_empty("product_id", &self.product_id)?;
60-
require_non_empty("host_name", &self.host_name)?;
87+
require_non_empty("host_info.name", &self.host_info.name)?;
6188
require_non_empty("pairing_deeplink_scheme", &self.pairing_deeplink_scheme)?;
6289
if self.pairing_deeplink_scheme.contains("://") {
6390
return Err(RuntimeConfigValidationError::InvalidDeeplinkScheme {
6491
scheme: self.pairing_deeplink_scheme.clone(),
6592
});
6693
}
67-
if let Some(icon) = &self.host_icon {
94+
if let Some(icon) = &self.host_info.icon {
6895
let parsed =
6996
Url::parse(icon).map_err(|err| RuntimeConfigValidationError::InvalidHostIcon {
7097
reason: err.to_string(),
@@ -96,13 +123,13 @@ pub enum RuntimeConfigValidationError {
96123
field: &'static str,
97124
},
98125
/// Host icon URL could not be parsed as an absolute URL.
99-
#[display("host_icon must be an absolute HTTPS URL: {reason}")]
126+
#[display("host_info.icon must be an absolute HTTPS URL: {reason}")]
100127
InvalidHostIcon {
101128
/// Parse failure reason.
102129
reason: String,
103130
},
104131
/// Host icon URL used a non-HTTPS scheme.
105-
#[display("host_icon must use https scheme, got {scheme:?}")]
132+
#[display("host_info.icon must use https scheme, got {scheme:?}")]
106133
InsecureHostIcon {
107134
/// Actual URL scheme.
108135
scheme: String,

rust/crates/truapi-platform/tests/bounds.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
//! `impl Future`); the runtime consumes implementors via generics, not
55
//! `dyn Trait`.
66
7-
use truapi_platform::{Platform, RuntimeConfig, RuntimeConfigValidationError};
7+
use truapi_platform::{
8+
HostInfo, Platform, PlatformInfo, RuntimeConfig, RuntimeConfigValidationError,
9+
};
810

911
fn _assert_platform_bounds<T: Platform + Send + Sync + 'static>() {}
1012

@@ -44,7 +46,9 @@ fn runtime_config_validation_cases() {
4446
host_name: " ",
4547
host_icon: Some("https://dot.li/dotli.png"),
4648
pairing_deeplink_scheme: "polkadotapp",
47-
expected: Err(RuntimeConfigValidationError::EmptyField { field: "host_name" }),
49+
expected: Err(RuntimeConfigValidationError::EmptyField {
50+
field: "host_info.name",
51+
}),
4852
},
4953
TestCase {
5054
name: "rejects relative host icon",
@@ -79,16 +83,17 @@ fn runtime_config_validation_cases() {
7983
];
8084

8185
for case in cases {
82-
let result = RuntimeConfig::new(RuntimeConfig {
83-
product_id: case.product_id.to_string(),
84-
host_name: case.host_name.to_string(),
85-
host_icon: case.host_icon.map(str::to_string),
86-
host_version: None,
87-
platform_type: None,
88-
platform_version: None,
89-
people_chain_genesis_hash: [0xa2; 32],
90-
pairing_deeplink_scheme: case.pairing_deeplink_scheme.to_string(),
91-
})
86+
let result = RuntimeConfig::new(
87+
case.product_id.to_string(),
88+
HostInfo {
89+
name: case.host_name.to_string(),
90+
icon: case.host_icon.map(str::to_string),
91+
version: None,
92+
},
93+
PlatformInfo::default(),
94+
[0xa2; 32],
95+
case.pairing_deeplink_scheme.to_string(),
96+
)
9297
.map(|_| ());
9398
assert_eq!(result, case.expected, "{}", case.name);
9499
}

0 commit comments

Comments
 (0)