Skip to content

Commit

Permalink
Wallet interaction models (#98)
Browse files Browse the repository at this point in the history
* wip

* wip

* response encoding

* wip

* wip

* wip

* wip

* wip

* rename

* wip

* wip

* wip

* wip

* fix one

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* [ABW-3207] app link parsing (#102)

* Radix Connect app link parsing

* pr review changes

* add missing model files

* add parser test for invalid url

* update invalid url test input data

* update session_id

* reafactor link parse method

* change interaction_id.rs

* add addition dapp_request tests

* add util function for parsing url

* add test for invalid url parsing

* use defined constructors for request objects

---------

Co-authored-by: jakub-rdx <[email protected]>
  • Loading branch information
GhenadieVP and jakub-rdx authored Apr 26, 2024
1 parent 6a4e34c commit 9dacad5
Show file tree
Hide file tree
Showing 73 changed files with 3,262 additions and 13 deletions.
155 changes: 155 additions & 0 deletions fixtures/vector/wallet_interactions_dapp_to_wallet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
[
{
"interactionId" : "d59590ea-d50b-4e8d-a5e1-da3a2574ae5c",
"items" : {
"discriminator" : "authorizedRequest",
"auth" : {
"discriminator" : "loginWithChallenge",
"challenge" : "e280cfa39e1499f2862e59759cc2fc990cce28b70a7989324fe91c47814d0630"
},
"reset" : {
"accounts" : true,
"personaData" : true
},
"ongoingAccounts" : {
"numberOfAccounts" : {
"quantifier" : "atLeast",
"quantity" : 4
},
"challenge" : "e280cfa39e1499f2862e59759cc2fc990cce28b70a7989324fe91c47814d0630"
},
"ongoingPersonaData" : {
"isRequestingName" : true,
"numberOfRequestedEmailAddresses" : {
"quantifier" : "exactly",
"quantity" : 1
},
"numberOfRequestedPhoneNumbers" : {
"quantifier" : "exactly",
"quantity" : 1
}
}
},
"metadata" : {
"version" : 2,
"networkId" : 2,
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
},
{
"interactionId" : "d59590ea-d50b-4e8d-a5e1-da3a2574ae5c",
"items" : {
"discriminator" : "authorizedRequest",
"auth" : {
"discriminator" : "loginWithoutChallenge"
},
"reset" : {
"accounts" : true,
"personaData" : true
},
"ongoingAccounts" : {
"numberOfAccounts" : {
"quantifier" : "exactly",
"quantity" : 4
},
"challenge" : "e280cfa39e1499f2862e59759cc2fc990cce28b70a7989324fe91c47814d0630"
},
"ongoingPersonaData" : {
"isRequestingName" : true,
"numberOfRequestedEmailAddresses" : {
"quantifier" : "atLeast",
"quantity" : 1
},
"numberOfRequestedPhoneNumbers" : {
"quantifier" : "atLeast",
"quantity" : 1
}
}
},
"metadata" : {
"version" : 2,
"networkId" : 2,
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
},
{
"interactionId" : "4051ff20-03b0-4a48-8205-0e8e8c673289",
"items" : {
"discriminator" : "transaction",
"send" : {
"version" : 1,
"message" : "test message",
"blobs": ["0061736d0100000001c8011c60037f7f7f0060027f7f0060027f7f017f60017f0060037f7f7f017f60017f017f60047f7f7f7f0060017f017e60037f7f7f017e60057f7f7f7f7f0060057f7f7f7f7f017f60027f7e017f60037f7f7e0"],
"transactionManifest" : "CALL_FUNCTION Address(\"package_tdx_2_1pkgxxxxxxxxxplxxxxxxxxxxxxx020379220524xxxxxxxxxe4r780\") \n \"OneResourcePool\"\n \"instantiate\"\n Enum<OwnerRole::Fixed>(Enum<AccessRule::AllowAll>())\n Enum<AccessRule::AllowAll>() \n Address(\"resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc\")\n None;"
}
},
"metadata" : {
"version" : 2,
"networkId" : 2,
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
},
{
"interactionId" : "51a720a5-9f80-4d0f-8264-704d1645f0af",
"items" : {
"discriminator" : "unauthorizedRequest",
"oneTimeAccounts" : {
"numberOfAccounts" : {
"quantifier" : "atLeast",
"quantity" : 1
},
"challenge" : "84a5234f14a50dee062dc7a6a51f4bdab7cab5faadea05542af2040688d8fb6c"
},
"oneTimePersonaData" : {
"isRequestingName" : true,
"numberOfRequestedEmailAddresses" : {
"quantifier" : "exactly",
"quantity" : 1
},
"numberOfRequestedPhoneNumbers" : {
"quantifier" : "exactly",
"quantity" : 1
}
}
},
"metadata" : {
"version" : 2,
"networkId" : 2,
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
},
{
"interactionId" : "51a720a5-9f80-4d0f-8264-704d1645f0af",
"items" : {
"discriminator" : "unauthorizedRequest",
"oneTimeAccounts" : {
"numberOfAccounts" : {
"quantifier" : "exactly",
"quantity" : 1
},
"challenge" : "84a5234f14a50dee062dc7a6a51f4bdab7cab5faadea05542af2040688d8fb6c"
},
"oneTimePersonaData" : {
"isRequestingName" : true,
"numberOfRequestedEmailAddresses" : {
"quantifier" : "atLeast",
"quantity" : 1
},
"numberOfRequestedPhoneNumbers" : {
"quantifier" : "atLeast",
"quantity" : 1
}
}
},
"metadata" : {
"version" : 2,
"networkId" : 2,
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
}
]
115 changes: 115 additions & 0 deletions fixtures/vector/wallet_interactions_wallet_to_dapp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
[
{
"discriminator" : "success",
"interactionId" : "06f00fbc-67ed-4a22-a122-1da719b25b6f",
"items" : {
"discriminator" : "authorizedRequest",
"auth" : {
"discriminator" : "loginWithChallenge",
"persona" : {
"identityAddress" : "identity_tdx_2_12twas58v4sthsmuky5653dup0drez3vcfwsfm6kp40qu9qyt8fgts6",
"label" : "Usdudh"
},
"challenge" : "069ef236486d4cd5706b5e5b168e19f750ffd1b4876529a0a9de966d50a15ab7",
"proof" : {
"publicKey" : "ff8aee4c625738e35d837edb11e33b8abe0d6f40849ca1451edaba84d04d0699",
"curve" : "curve25519",
"signature" : "10177ac7d486691777133ffe59d46d55529d86cb1c4ce66aa82f432372f33e24d803d8498f42e26fe113c030fce68c526aeacff94334ba5a7f7ef84c2936eb05"
}
},
"ongoingAccounts" : {
"accounts" : [
{
"address" : "account_tdx_2_129qeystv8tufmkmjrry2g6kadhhfh4f7rd0x3t9yagcvfhspt62paz",
"label" : "Dff",
"appearanceId" : 0
},
{
"address" : "account_tdx_2_128928hvf6pjr3rx2xvdw6ulf7pc8g88ya8ma3j8dtjmntckz09fr3n",
"label" : "Ghhvgfvf",
"appearanceId" : 1
}
],
"challenge" : "069ef236486d4cd5706b5e5b168e19f750ffd1b4876529a0a9de966d50a15ab7",
"proofs" : [
{
"proof" : {
"publicKey" : "11b162e3343ce770b6e9ed8a29d125b5580d1272b0dc4e2bd0fcae33320d9566",
"curve" : "curve25519",
"signature" : "e18617b527d4d33607a8adb6a040c26ca97642ec89dd8a6fe7a41fa724473e4cc69b0729c1df57aba77455801f2eef6f28848a5d206e3739de29ca2288957502"
},
"accountAddress" : "account_tdx_2_129qeystv8tufmkmjrry2g6kadhhfh4f7rd0x3t9yagcvfhspt62paz"
},
{
"proof" : {
"publicKey" : "5386353e4cc27e3d27d064d777d811e242a16ba7aefd425062ed46631739619d",
"curve" : "curve25519",
"signature" : "0143fd941d51f531c8265b0f6b24f4cfcdfd24b40aac47dee6fb3386ce0d400563c892e3894a33840d1c7af2dd43ecd0729fd209171003765d109a04d7485605"
},
"accountAddress" : "account_tdx_2_128928hvf6pjr3rx2xvdw6ulf7pc8g88ya8ma3j8dtjmntckz09fr3n"
}
]
},
"ongoingPersonaData" : {
"name" : {
"variant" : "western",
"familyName" : "Family",
"givenNames" : "Given",
"nickname" : "Nick"
},
"emailAddresses" : [
"[email protected]"
],
"phoneNumbers" : [
"071234579"
]
}
}
},
{
"discriminator" : "success",
"interactionId" : "278608e0-e5ca-416e-8339-f2d2695651c4",
"items" : {
"oneTimeAccounts" : {
"accounts" : [
{
"address" : "account_tdx_2_129qeystv8tufmkmjrry2g6kadhhfh4f7rd0x3t9yagcvfhspt62paz",
"label" : "Dff",
"appearanceId" : 0
}
]
},
"discriminator" : "unauthorizedRequest",
"oneTimePersonaData" : {
"name" : {
"variant" : "western",
"familyName" : "Family",
"givenNames" : "Given",
"nickname" : "Nick"
},
"emailAddresses" : [
"[email protected]"
],
"phoneNumbers" : [
"071234579"
]
}
}
},
{
"discriminator" : "failure",
"interactionId" : "278608e0-e5ca-416e-8339-f2d2695651c4",
"error" : "rejectedByUser",
"message" : "User rejected the request"
},
{
"discriminator" : "success",
"interactionId" : "c42f8825-4bbb-4ce2-a646-776b529e2f51",
"items" : {
"send" : {
"transactionIntentHash" : "txid_tdx_2_1mwuvufnewv6qkxdaesx0gcwap7n79knhkn0crsc8dg9g9k7qknjs6vkd3n"
},
"discriminator" : "transaction"
}
}
]
12 changes: 12 additions & 0 deletions src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ pub enum CommonError {

#[error("Invalid LedgerHardwareWalletModel, bad value: {bad_value}")]
InvalidLedgerHardwareWalletModel { bad_value: String } = 10126,

#[error("RadixConnectMobile invalid URL, bad value: {bad_value}")]
RadixConnectMobileInvalidRequestUrl { bad_value: String } = 10127,

#[error("RadixConnectMobile invalid origin, bad value: {bad_value}")]
RadixConnectMobileInvalidOrigin { bad_value: String } = 10128,

#[error("Failed to create Session (UUID) from string: {bad_value}")]
RadixConnectMobileInvalidSessionID { bad_value: String } = 10129,

#[error("Failed to create InteractionID (UUID) from string: {bad_value}")]
RadixMobileInvalidInteractionID { bad_value: String } = 10130,
}

#[uniffi::export]
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/core/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod appearance_id;
mod appearance_id_uniffi_fn;
mod bag_of_bytes;
mod bag_of_bytes_uniffi_fn;
mod decimal192;
Expand All @@ -12,10 +14,15 @@ mod logged_result;
mod non_empty_max_n_bytes;
mod nonce;
mod nonce_uniffi_fn;
mod requested_number_quantifier;
mod requested_quantity;
mod requested_quantity_uniffi_fn;
mod rounding_mode;
mod safe_to_log;
mod signatures;

pub use appearance_id::*;
pub use appearance_id_uniffi_fn::*;
#[macro_use]
mod secret_bytes;

Expand All @@ -33,6 +40,9 @@ pub use logged_result::*;
pub use non_empty_max_n_bytes::*;
pub use nonce::*;
pub use nonce_uniffi_fn::*;
pub use requested_number_quantifier::*;
pub use requested_quantity::*;
pub use requested_quantity_uniffi_fn::*;
pub use rounding_mode::*;
pub use safe_to_log::*;
pub use secret_bytes::*;
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions src/core/utils/string_utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::CommonError;
use url::Url;

/// Returns the last `n` chars of the &str `s`. If `s` is shorter than `n`
/// we panic.
pub fn suffix_str(n: usize, s: impl AsRef<str>) -> String {
Expand Down Expand Up @@ -27,6 +30,12 @@ impl StrExt for str {
}
}

pub fn parse_url(s: impl AsRef<str>) -> Result<Url, CommonError> {
Url::try_from(s.as_ref()).map_err(|_| CommonError::InvalidURL {
bad_value: s.as_ref().to_owned(),
})
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -58,4 +67,14 @@ mod tests {
assert_eq!("fo".remove_last(), "f");
assert_eq!("Foobar".remove_last(), "Fooba");
}

#[test]
fn test_parse_url() {
assert!(parse_url("https://radixdlt.com").is_ok());
}

#[test]
fn test_parse_url_invalid() {
assert!(parse_url("https/radixdlt").is_err());
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod core;
mod gateway_api;
mod hierarchical_deterministic;
mod profile;
mod radix_connect;
mod wallet;
mod wrapped_radix_engine_toolkit;

Expand All @@ -13,6 +14,7 @@ pub mod prelude {
pub use crate::gateway_api::*;
pub use crate::hierarchical_deterministic::*;
pub use crate::profile::*;
pub use crate::radix_connect::*;
pub use crate::wallet::*;
pub use crate::wrapped_radix_engine_toolkit::*;

Expand Down
3 changes: 1 addition & 2 deletions src/profile/v100/app_preferences/gateways/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ impl From<NetworkID> for Gateway {

impl Gateway {
pub fn new(url: String, id: NetworkID) -> Result<Self> {
let url = Url::try_from(url.as_str())
.map_err(|_| CommonError::InvalidURL { bad_value: url })?;
let url = parse_url(url)?;
let network = NetworkDefinition::lookup_by_id(id)?;
Ok(Self { url, network })
}
Expand Down
4 changes: 0 additions & 4 deletions src/profile/v100/entity/account/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
mod account;
mod account_uniffi_fn;
mod appearance_id;
mod appearance_id_uniffi_fn;
mod on_ledger_settings;

pub use account::*;
pub use account_uniffi_fn::*;
pub use appearance_id::*;
pub use appearance_id_uniffi_fn::*;
pub use on_ledger_settings::*;
Loading

0 comments on commit 9dacad5

Please sign in to comment.