Skip to content

Commit 2b612da

Browse files
committed
fixup! feat(truapi-server): add Rust host runtime
1 parent bc89542 commit 2b612da

6 files changed

Lines changed: 87 additions & 74 deletions

File tree

rust/crates/truapi-server/src/host_logic/sso/pairing.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use schnorrkel::{ExpansionMode, MiniSecretKey};
1515
use sha2::Sha256;
1616
use thiserror::Error;
1717
use truapi_platform::RuntimeConfig;
18+
#[cfg(test)]
19+
use truapi_platform::{HostInfo, PlatformInfo};
1820

1921
use crate::host_logic::session::SsoSessionInfo;
2022

@@ -408,27 +410,27 @@ pub fn build_pairing_deeplink(
408410
fn handshake_metadata(config: &RuntimeConfig) -> Vec<HandshakeMetadataEntry> {
409411
let mut entries = vec![HandshakeMetadataEntry(
410412
HandshakeMetadataKey::HostName,
411-
config.host_name.clone(),
413+
config.host_info.name.clone(),
412414
)];
413-
if let Some(value) = &config.host_version {
415+
if let Some(value) = &config.host_info.version {
414416
entries.push(HandshakeMetadataEntry(
415417
HandshakeMetadataKey::HostVersion,
416418
value.clone(),
417419
));
418420
}
419-
if let Some(value) = &config.host_icon {
421+
if let Some(value) = &config.host_info.icon {
420422
entries.push(HandshakeMetadataEntry(
421423
HandshakeMetadataKey::HostIcon,
422424
value.clone(),
423425
));
424426
}
425-
if let Some(value) = &config.platform_type {
427+
if let Some(value) = &config.platform_info.kind {
426428
entries.push(HandshakeMetadataEntry(
427429
HandshakeMetadataKey::PlatformType,
428430
value.clone(),
429431
));
430432
}
431-
if let Some(value) = &config.platform_version {
433+
if let Some(value) = &config.platform_info.version {
432434
entries.push(HandshakeMetadataEntry(
433435
HandshakeMetadataKey::PlatformVersion,
434436
value.clone(),
@@ -503,11 +505,15 @@ mod tests {
503505
fn runtime_config() -> RuntimeConfig {
504506
RuntimeConfig {
505507
product_id: "myapp.dot".to_string(),
506-
host_name: "Polkadot Web".to_string(),
507-
host_icon: Some("https://example.invalid/dotli.png".to_string()),
508-
host_version: Some("1.2.3".to_string()),
509-
platform_type: Some("Firefox".to_string()),
510-
platform_version: Some("192.32".to_string()),
508+
host_info: HostInfo {
509+
name: "Polkadot Web".to_string(),
510+
icon: Some("https://example.invalid/dotli.png".to_string()),
511+
version: Some("1.2.3".to_string()),
512+
},
513+
platform_info: PlatformInfo {
514+
kind: Some("Firefox".to_string()),
515+
version: Some("192.32".to_string()),
516+
},
511517
people_chain_genesis_hash: [0; 32],
512518
pairing_deeplink_scheme: "polkadotapp".to_string(),
513519
}

rust/crates/truapi-server/src/runtime.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ impl<P> PlatformRuntimeHost<P> {
205205
platform,
206206
RuntimeConfig {
207207
product_id: "unknown.dot".to_string(),
208-
host_name: "Polkadot Web".to_string(),
209-
host_icon: Some("https://example.invalid/dotli.png".to_string()),
210-
host_version: None,
211-
platform_type: None,
212-
platform_version: None,
208+
host_info: truapi_platform::HostInfo {
209+
name: "Polkadot Web".to_string(),
210+
icon: Some("https://example.invalid/dotli.png".to_string()),
211+
version: None,
212+
},
213+
platform_info: truapi_platform::PlatformInfo::default(),
213214
people_chain_genesis_hash: [0; 32],
214215
pairing_deeplink_scheme: "polkadotapp".to_string(),
215216
},

rust/crates/truapi-server/src/test_support.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ use truapi::versioned::account::HostAccountGetAliasRequest;
2929
use truapi::versioned::resource_allocation::HostRequestResourceAllocationRequest;
3030
use truapi_platform::{
3131
AuthPresenter, AuthState, ChainProvider, CoreStorage as PlatformCoreStorage, CoreStorageKey,
32-
Features as PlatformFeatures, JsonRpcConnection, Navigation as PlatformNavigation,
33-
Notifications as PlatformNotifications, Permissions as PlatformPermissions, PreimageHost,
34-
ProductStorage as PlatformProductStorage, RuntimeConfig, ThemeHost, UserConfirmation,
35-
UserConfirmationReview,
32+
Features as PlatformFeatures, HostInfo, JsonRpcConnection, Navigation as PlatformNavigation,
33+
Notifications as PlatformNotifications, Permissions as PlatformPermissions, PlatformInfo,
34+
PreimageHost, ProductStorage as PlatformProductStorage, RuntimeConfig, ThemeHost,
35+
UserConfirmation, UserConfirmationReview,
3636
};
3737

3838
/// Test spawner that matches the current target.
@@ -164,11 +164,12 @@ pub(crate) fn stub_platform() -> Arc<StubPlatform> {
164164
pub(crate) fn runtime_config(product_id: &str) -> RuntimeConfig {
165165
RuntimeConfig {
166166
product_id: product_id.to_string(),
167-
host_name: "Polkadot Web".to_string(),
168-
host_icon: Some("https://example.invalid/dotli.png".to_string()),
169-
host_version: None,
170-
platform_type: None,
171-
platform_version: None,
167+
host_info: HostInfo {
168+
name: "Polkadot Web".to_string(),
169+
icon: Some("https://example.invalid/dotli.png".to_string()),
170+
version: None,
171+
},
172+
platform_info: PlatformInfo::default(),
172173
people_chain_genesis_hash: [0; 32],
173174
pairing_deeplink_scheme: "polkadotapp".to_string(),
174175
}

rust/crates/truapi-server/src/wasm/mod.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use parity_scale_codec::{Decode, Encode};
2222
use send_wrapper::SendWrapper;
2323
use truapi::v01;
2424
use truapi_platform::{
25-
AuthPresenter, AuthState, ChainProvider, CoreStorage, CoreStorageKey, Features,
26-
JsonRpcConnection, Navigation, Notifications, Permissions, PreimageHost, ProductStorage,
27-
RuntimeConfig, RuntimeConfigValidationError, SessionUiInfo, ThemeHost, UserConfirmation,
28-
UserConfirmationReview,
25+
AuthPresenter, AuthState, ChainProvider, CoreStorage, CoreStorageKey, Features, HostInfo,
26+
JsonRpcConnection, Navigation, Notifications, Permissions, PlatformInfo, PreimageHost,
27+
ProductStorage, RuntimeConfig, RuntimeConfigValidationError, SessionUiInfo, ThemeHost,
28+
UserConfirmation, UserConfirmationReview,
2929
};
3030
use wasm_bindgen::JsCast;
3131
use wasm_bindgen::prelude::*;
@@ -780,35 +780,45 @@ fn runtime_config_from_js(value: &JsValue) -> Result<RuntimeConfig, JsValue> {
780780
let people = get_required_object(value, "people", "runtimeConfig.people")?;
781781
let pairing = get_required_object(value, "pairing", "runtimeConfig.pairing")?;
782782

783-
RuntimeConfig::new(RuntimeConfig {
784-
product_id: get_required_string_at(value, "productId", "runtimeConfig.productId")?,
785-
host_name: get_required_string_at(&host, "name", "runtimeConfig.host.name")?,
786-
host_icon: get_optional_string_at(&host, "icon", "runtimeConfig.host.icon")?,
787-
host_version: get_optional_string_at(&host, "version", "runtimeConfig.host.version")?,
788-
platform_type: platform
789-
.as_ref()
790-
.map(|p| get_optional_string_at(p, "type", "runtimeConfig.platform.type"))
791-
.transpose()?
792-
.flatten(),
793-
platform_version: platform
794-
.as_ref()
795-
.map(|p| get_optional_string_at(p, "version", "runtimeConfig.platform.version"))
796-
.transpose()?
797-
.flatten(),
798-
people_chain_genesis_hash: get_required_bytes32_at(
799-
&people,
800-
"genesisHash",
801-
"runtimeConfig.people.genesisHash",
802-
)?,
803-
pairing_deeplink_scheme: get_required_string_at(
783+
RuntimeConfig::new(
784+
get_required_string_at(value, "productId", "runtimeConfig.productId")?,
785+
HostInfo {
786+
name: get_required_string_at(&host, "name", "runtimeConfig.host.name")?,
787+
icon: get_optional_string_at(&host, "icon", "runtimeConfig.host.icon")?,
788+
version: get_optional_string_at(&host, "version", "runtimeConfig.host.version")?,
789+
},
790+
PlatformInfo {
791+
kind: platform
792+
.as_ref()
793+
.map(|p| get_optional_string_at(p, "type", "runtimeConfig.platform.type"))
794+
.transpose()?
795+
.flatten(),
796+
version: platform
797+
.as_ref()
798+
.map(|p| get_optional_string_at(p, "version", "runtimeConfig.platform.version"))
799+
.transpose()?
800+
.flatten(),
801+
},
802+
get_required_bytes32_at(&people, "genesisHash", "runtimeConfig.people.genesisHash")?,
803+
get_required_string_at(
804804
&pairing,
805805
"deeplinkScheme",
806806
"runtimeConfig.pairing.deeplinkScheme",
807807
)?,
808-
})
808+
)
809809
.map_err(runtime_config_validation_to_js)
810810
}
811811

812+
fn runtime_config_field_to_js(field: &str) -> &str {
813+
match field {
814+
"product_id" => "productId",
815+
"host_info.name" => "host.name",
816+
"pairing_deeplink_scheme" => "pairing.deeplinkScheme",
817+
"people_chain_genesis_hash" => "people.genesisHash",
818+
other => other,
819+
}
820+
}
821+
812822
fn runtime_config_validation_to_js(err: RuntimeConfigValidationError) -> JsValue {
813823
match err {
814824
RuntimeConfigValidationError::EmptyField { field } => JsValue::from_str(&format!(
@@ -827,16 +837,6 @@ fn runtime_config_validation_to_js(err: RuntimeConfigValidationError) -> JsValue
827837
}
828838
}
829839

830-
fn runtime_config_field_to_js(field: &str) -> &str {
831-
match field {
832-
"product_id" => "productId",
833-
"host_name" => "host.name",
834-
"pairing_deeplink_scheme" => "pairing.deeplinkScheme",
835-
"people_chain_genesis_hash" => "people.genesisHash",
836-
other => other,
837-
}
838-
}
839-
840840
fn get_required_object(value: &JsValue, name: &str, path: &str) -> Result<JsValue, JsValue> {
841841
let property = Reflect::get(value, &JsValue::from_str(name))?;
842842
if property.is_null() || property.is_undefined() {

rust/crates/truapi-server/tests/common/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::sync::Mutex;
66
use futures::stream::{self, BoxStream};
77
use truapi::v01;
88
use truapi_platform::{
9-
AuthPresenter, ChainProvider, CoreStorage, CoreStorageKey, Features, JsonRpcConnection,
10-
Navigation, Notifications, Permissions, PreimageHost, ProductStorage, RuntimeConfig, ThemeHost,
11-
UserConfirmation, UserConfirmationReview,
9+
AuthPresenter, ChainProvider, CoreStorage, CoreStorageKey, Features, HostInfo,
10+
JsonRpcConnection, Navigation, Notifications, Permissions, PlatformInfo, PreimageHost,
11+
ProductStorage, RuntimeConfig, ThemeHost, UserConfirmation, UserConfirmationReview,
1212
};
1313
use truapi_server::frame::ProtocolMessage;
1414
use truapi_server::transport::Transport;
@@ -49,11 +49,12 @@ pub fn test_spawner() -> truapi_server::subscription::Spawner {
4949
pub fn test_runtime_config() -> RuntimeConfig {
5050
RuntimeConfig {
5151
product_id: "dotli.dot".to_string(),
52-
host_name: "Polkadot Web".to_string(),
53-
host_icon: Some("https://dot.li/dotli.png".to_string()),
54-
host_version: None,
55-
platform_type: None,
56-
platform_version: None,
52+
host_info: HostInfo {
53+
name: "Polkadot Web".to_string(),
54+
icon: Some("https://dot.li/dotli.png".to_string()),
55+
version: None,
56+
},
57+
platform_info: PlatformInfo::default(),
5758
people_chain_genesis_hash: [0xa2; 32],
5859
pairing_deeplink_scheme: "polkadotapp".to_string(),
5960
}

rust/crates/truapi-server/tests/wasm_crypto_vectors.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use p256::elliptic_curve::sec1::ToEncodedPoint;
99
use parity_scale_codec::{Decode, Encode};
1010
use schnorrkel::{ExpansionMode, MiniSecretKey};
1111
use sha2::Sha256;
12-
use truapi_platform::RuntimeConfig;
12+
use truapi_platform::{HostInfo, PlatformInfo, RuntimeConfig};
1313
use truapi_server::host_logic::entropy::derive_product_entropy;
1414
use truapi_server::host_logic::product_account::{
1515
derive_product_public_key, product_public_key_to_address,
@@ -52,11 +52,15 @@ fn entropy_secret() -> [u8; 32] {
5252
fn runtime_config() -> RuntimeConfig {
5353
RuntimeConfig {
5454
product_id: "dotli.dot".to_string(),
55-
host_name: "Polkadot Web".to_string(),
56-
host_icon: Some("https://example.invalid/dotli.png".to_string()),
57-
host_version: Some("1.2.3".to_string()),
58-
platform_type: Some("Firefox".to_string()),
59-
platform_version: Some("192.32".to_string()),
55+
host_info: HostInfo {
56+
name: "Polkadot Web".to_string(),
57+
icon: Some("https://example.invalid/dotli.png".to_string()),
58+
version: Some("1.2.3".to_string()),
59+
},
60+
platform_info: PlatformInfo {
61+
kind: Some("Firefox".to_string()),
62+
version: Some("192.32".to_string()),
63+
},
6064
people_chain_genesis_hash: [0xa2; 32],
6165
pairing_deeplink_scheme: "polkadotapp".to_string(),
6266
}

0 commit comments

Comments
 (0)