Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABW-3810] Models for one time persona/accounts authentication #228

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sargon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sargon"
version = "1.1.24"
version = "1.1.25"
edition = "2021"
build = "build.rs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,43 @@
"origin" : "https://dev-sandbox.rdx-works-main.extratools.works/",
"dAppDefinitionAddress" : "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze"
}
},
{
"interactionId": "2916ad16-52a0-4564-a611-4971883c1322",
"items": {
"discriminator": "unauthorizedRequest",
"proofOfOwnership": {
"challenge": "4c85e4a903ab97450ef83763f8d4ca55a43efe843e1d2ced78a4940e5c397c9c",
"accountAddresses": [
"account_tdx_2_12ytkalad6hfxamsz4a7r8tevz7ahurfj58dlp4phl4nca5hs0hpu90"
]
}
},
"metadata": {
"version": 2,
"dAppDefinitionAddress": "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze",
"networkId": 2,
"origin": "https://dev-sandbox.rdx-works-main.extratools.works/"
}
},
{
"interactionId": "17d530f6-0cb6-4122-8540-64e46a2e0f84",
"items": {
"discriminator": "unauthorizedRequest",
"proofOfOwnership": {
"challenge": "e280cfa39e1499f2862e59759cc2fc990cce28b70a7989324fe91c47814d0630",
"accountAddresses": [
"account_tdx_2_12ytkalad6hfxamsz4a7r8tevz7ahurfj58dlp4phl4nca5hs0hpu90",
"account_tdx_2_129qeystv8tufmkmjrry2g6kadhhfh4f7rd0x3t9yagcvfhspt62paz"
],
"identityAddress": "identity_tdx_2_12fat0nh0gymw9j4rqka5344p3h3r86x4z0hkw2v78r03pt0kfv0qva"
}
},
"metadata": {
"version": 2,
"dAppDefinitionAddress": "account_tdx_2_12xd46c22d6m696lv565t9afn088htudtq275px3qs925ywwty8axze",
"networkId": 2,
"origin": "https://dev-sandbox.rdx-works-main.extratools.works/"
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,69 @@
]
}
}
},
{
"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"
},
{
"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"
}
},
{
"discriminator" : "success",
"interactionId" : "2916ad16-52a0-4564-a611-4971883c1322",
"items" : {
"discriminator" : "unauthorizedRequest",
"proofOfOwnership": {
"challenge": "4c85e4a903ab97450ef83763f8d4ca55a43efe843e1d2ced78a4940e5c397c9c",
"proofs": [
{
"accountAddress": "account_tdx_2_12ytkalad6hfxamsz4a7r8tevz7ahurfj58dlp4phl4nca5hs0hpu90",
"proof": {
"publicKey": "ff8aee4c625738e35d837edb11e33b8abe0d6f40849ca1451edaba84d04d0699",
"curve": "curve25519",
"signature": "10177ac7d486691777133ffe59d46d55529d86cb1c4ce66aa82f432372f33e24d803d8498f42e26fe113c030fce68c526aeacff94334ba5a7f7ef84c2936eb05"
}
}
]
}
}
},
{
"discriminator" : "success",
"interactionId" : "17d530f6-0cb6-4122-8540-64e46a2e0f84",
"items" : {
"discriminator" : "unauthorizedRequest",
"proofOfOwnership": {
"challenge": "e280cfa39e1499f2862e59759cc2fc990cce28b70a7989324fe91c47814d0630",
"proofs": [
{
"accountAddress": "account_tdx_2_12ytkalad6hfxamsz4a7r8tevz7ahurfj58dlp4phl4nca5hs0hpu90",
"proof": {
"publicKey": "ff8aee4c625738e35d837edb11e33b8abe0d6f40849ca1451edaba84d04d0699",
"curve": "curve25519",
"signature": "10177ac7d486691777133ffe59d46d55529d86cb1c4ce66aa82f432372f33e24d803d8498f42e26fe113c030fce68c526aeacff94334ba5a7f7ef84c2936eb05"
}
},
{
"identityAddress": "identity_tdx_2_12fat0nh0gymw9j4rqka5344p3h3r86x4z0hkw2v78r03pt0kfv0qva",
"proof": {
"publicKey": "ff8aee4c625738e35d837edb11e33b8abe0d6f40849ca1451edaba84d04d0699",
"curve": "curve25519",
"signature": "10177ac7d486691777133ffe59d46d55529d86cb1c4ce66aa82f432372f33e24d803d8498f42e26fe113c030fce68c526aeacff94334ba5a7f7ef84c2936eb05"
}
}
]
}
}
}
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod accounts;
mod persona_data;
mod proof_of_ownership;
mod reset;

pub use accounts::*;
pub use persona_data::*;
pub use proof_of_ownership::*;
pub use reset::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use crate::prelude::*;

/// A request to prove ownership of `Accounts` and/or a `Persona`.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, uniffi::Record)]
#[serde(rename_all = "camelCase")]
pub struct DappToWalletInteractionProofOfOwnershipRequestItem {
/// The challenge that must be signed to prove ownership.
pub challenge: DappToWalletInteractionAuthChallengeNonce,

/// The list of `AccountAddress`es for which the wallet must prove ownership.
#[serde(skip_serializing_if = "Option::is_none")]
pub account_addresses: Option<Vec<AccountAddress>>,

/// The `IdentityAddress` for which the wallet must prove ownership.
#[serde(skip_serializing_if = "Option::is_none")]
pub identity_address: Option<IdentityAddress>,
}

impl DappToWalletInteractionProofOfOwnershipRequestItem {
pub fn new(
challenge: impl Into<DappToWalletInteractionAuthChallengeNonce>,
account_addresses: impl Into<Option<Vec<AccountAddress>>>,
identity_address: impl Into<Option<IdentityAddress>>,
) -> Self {
Self {
challenge: challenge.into(),
account_addresses: account_addresses.into(),
identity_address: identity_address.into(),
}
}
}

impl HasSampleValues for DappToWalletInteractionProofOfOwnershipRequestItem {
fn sample() -> Self {
Self::new(
DappToWalletInteractionAuthChallengeNonce::sample(),
vec![AccountAddress::sample(), AccountAddress::sample_other()],
IdentityAddress::sample(),
)
}

fn sample_other() -> Self {
Self::new(
DappToWalletInteractionAuthChallengeNonce::sample_other(),
vec![AccountAddress::sample_other()],
IdentityAddress::sample_other(),
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[allow(clippy::upper_case_acronyms)]
type SUT = DappToWalletInteractionProofOfOwnershipRequestItem;

#[test]
fn equality() {
assert_eq!(SUT::sample(), SUT::sample());
assert_eq!(SUT::sample_other(), SUT::sample_other());
}

#[test]
fn inequality() {
assert_ne!(SUT::sample(), SUT::sample_other());
}

#[test]
fn json_roundtrip() {
assert_eq_after_json_roundtrip(
&SUT::sample(),
r#"
{
"challenge": "deaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead",
"accountAddresses": [
"account_rdx128y6j78mt0aqv6372evz28hrxp8mn06ccddkr7xppc88hyvynvjdwr",
"account_rdx12xkzynhzgtpnnd02tudw2els2g9xl73yk54ppw8xekt2sdrlaer264"
],
"identityAddress": "identity_rdx122yy9pkfdrkam4evxcwh235c4qc52wujkwnt52q7vqxefhnlen489g"
}
"#,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub struct DappToWalletInteractionUnauthorizedRequestItems {
#[serde(skip_serializing_if = "Option::is_none")]
pub one_time_persona_data:
Option<DappToWalletInteractionPersonaDataRequestItem>,

#[serde(skip_serializing_if = "Option::is_none")]
pub proof_of_ownership:
Option<DappToWalletInteractionProofOfOwnershipRequestItem>,
}

impl DappToWalletInteractionUnauthorizedRequestItems {
Expand All @@ -19,10 +23,14 @@ impl DappToWalletInteractionUnauthorizedRequestItems {
one_time_persona_data: impl Into<
Option<DappToWalletInteractionPersonaDataRequestItem>,
>,
proof_of_ownership: impl Into<
Option<DappToWalletInteractionProofOfOwnershipRequestItem>,
>,
) -> Self {
Self {
one_time_accounts: one_time_accounts.into(),
one_time_persona_data: one_time_persona_data.into(),
proof_of_ownership: proof_of_ownership.into(),
}
}
}
Expand All @@ -32,13 +40,15 @@ impl HasSampleValues for DappToWalletInteractionUnauthorizedRequestItems {
Self::new(
DappToWalletInteractionAccountsRequestItem::sample(),
DappToWalletInteractionPersonaDataRequestItem::sample(),
DappToWalletInteractionProofOfOwnershipRequestItem::sample(),
)
}

fn sample_other() -> Self {
Self::new(
DappToWalletInteractionAccountsRequestItem::sample_other(),
DappToWalletInteractionPersonaDataRequestItem::sample_other(),
DappToWalletInteractionProofOfOwnershipRequestItem::sample_other(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum DappWalletInteractionErrorType {
InvalidRequest,
IncompatibleVersion,
FailedToSignAuthChallenge,
InvalidPersonaOrAccounts,
}

impl HasSampleValues for DappWalletInteractionErrorType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ use crate::prelude::*;
#[serde(rename_all = "camelCase")]
pub struct WalletToDappInteractionAuthorizedRequestResponseItems {
pub auth: WalletToDappInteractionAuthRequestResponseItem,

#[serde(skip_serializing_if = "Option::is_none")]
pub ongoing_accounts:
Option<WalletToDappInteractionAccountsRequestResponseItem>,

#[serde(skip_serializing_if = "Option::is_none")]
pub ongoing_persona_data:
Option<WalletToDappInteractionPersonaDataRequestResponseItem>,

#[serde(skip_serializing_if = "Option::is_none")]
pub one_time_accounts:
Option<WalletToDappInteractionAccountsRequestResponseItem>,

#[serde(skip_serializing_if = "Option::is_none")]
pub one_time_persona_data:
Option<WalletToDappInteractionPersonaDataRequestResponseItem>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ mod account;
mod auth;
mod authorized_request;
mod items;
mod persona;
mod persona_data;
mod proof_of_ownership;
mod success;
mod transaction;
mod unauthorized_request;
Expand All @@ -11,7 +13,9 @@ pub use account::*;
pub use auth::*;
pub use authorized_request::*;
pub use items::*;
pub use persona::*;
pub use persona_data::*;
pub use proof_of_ownership::*;
pub use success::*;
pub use transaction::*;
pub use unauthorized_request::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod persona_proof;

pub use persona_proof::*;
Loading
Loading