Skip to content

Commit

Permalink
updates to make it work with Android
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasbzurovski committed Feb 6, 2025
1 parent 16679c4 commit 8bb3af2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ extension FactorSourceID {
public func toString() -> String {
factorSourceIdToString(factorSourceId: self)
}

public var kind: FactorSourceKind {
switch self {
case let .hash(value):
value.kind
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ThrowingHostInteractor: HostInteractor {
.rejected
}

public func spotCheck(factorSourceId: FactorSourceIdFromHash) async throws -> SpotCheckResponse {
public func spotCheck(factorSource: FactorSource) async throws -> SpotCheckResponse {
throw CommonError.HostInteractionAborted
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ final class MnemonicWithPassphraseTests: Test<MnemonicWithPassphrase> {
func testJSONRoundtripAllSamples() throws {
try eachSampleCodableRoundtripTest()
}

func testInitWithoutPaspshrase() {
let sut = SUT.init(mnemonic: .sample)
let sut = SUT(mnemonic: .sample)
XCTAssertEqual(sut.passphrase, "")
}
}
6 changes: 4 additions & 2 deletions crates/system/interactors/src/spot_check_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum SpotCheckResponse {
ArculusCard { id: FactorSourceIDFromHash },

/// The user retrieved a `MnemonicWithPassphrase`.
/// Used for the identification of any other `FactorSource`.
MnemonicWithPassphrase { value: MnemonicWithPassphrase },
/// Used for the identification of any software `FactorSource`.
Software {
mnemonic_with_passphrase: MnemonicWithPassphrase,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ impl SpotCheckInteractor for TestSpotCheckInteractor {
SpotCheckUser::ArculusCard(id) => {
Ok(SpotCheckResponse::ArculusCard { id })
}
SpotCheckUser::MnemonicWithPassphrase(value) => {
Ok(SpotCheckResponse::MnemonicWithPassphrase { value })
SpotCheckUser::Software(mnemonic_with_passphrase) => {
Ok(SpotCheckResponse::Software {
mnemonic_with_passphrase,
})
}
}
}
Expand All @@ -28,7 +30,7 @@ pub enum SpotCheckUser {
Failure(CommonError),
Ledger(Exactly32Bytes),
ArculusCard(FactorSourceIDFromHash),
MnemonicWithPassphrase(MnemonicWithPassphrase),
Software(MnemonicWithPassphrase),
}

impl TestSpotCheckInteractor {
Expand All @@ -51,11 +53,9 @@ impl TestSpotCheckInteractor {
Self::new(SpotCheckUser::ArculusCard(id))
}

pub fn new_mnemonic_with_passphrase(
pub fn new_software(
mnemonic_with_passphrase: MnemonicWithPassphrase,
) -> Self {
Self::new(SpotCheckUser::MnemonicWithPassphrase(
mnemonic_with_passphrase,
))
Self::new(SpotCheckUser::Software(mnemonic_with_passphrase))
}
}
43 changes: 18 additions & 25 deletions crates/system/os/os/src/sargon_os_factors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ impl SargonOS {
);
Ok(id == id_from_hash)
}
SpotCheckResponse::MnemonicWithPassphrase { value } => {
SpotCheckResponse::Software {
mnemonic_with_passphrase,
} => {
let accepted_kinds = [
FactorSourceKind::Device,
FactorSourceKind::OffDeviceMnemonic,
Expand All @@ -562,12 +564,13 @@ impl SargonOS {
];
assert!(
accepted_kinds.contains(&kind),
"Unexpected MnemonicWithPassphrase Response for {:?}",
"Unexpected Software Response for {:?}",
kind
);
let built_id =
FactorSourceIDFromHash::from_mnemonic_with_passphrase(
kind, &value,
kind,
&mnemonic_with_passphrase,
);
Ok(built_id == id_from_hash)
}
Expand Down Expand Up @@ -1124,9 +1127,7 @@ mod tests {
let interactors =
Interactors::new_from_clients_and_spot_check_interactor(
&clients,
Arc::new(
TestSpotCheckInteractor::new_mnemonic_with_passphrase(mwp),
),
Arc::new(TestSpotCheckInteractor::new_software(mwp)),
);
let os = timeout(
SARGON_OS_TEST_MAX_ASYNC_DURATION,
Expand All @@ -1153,9 +1154,7 @@ mod tests {
let interactors =
Interactors::new_from_clients_and_spot_check_interactor(
&clients,
Arc::new(
TestSpotCheckInteractor::new_mnemonic_with_passphrase(mwp),
),
Arc::new(TestSpotCheckInteractor::new_software(mwp)),
);
let os = timeout(
SARGON_OS_TEST_MAX_ASYNC_DURATION,
Expand Down Expand Up @@ -1273,19 +1272,17 @@ mod tests {

#[actix_rt::test]
#[should_panic(
expected = "Unexpected MnemonicWithPassphrase Response for LedgerHQHardwareWallet"
expected = "Unexpected Software Response for LedgerHQHardwareWallet"
)]
async fn spot_check__ledger__mvp_response() {
async fn spot_check__ledger__software_response() {
let clients = Clients::new(Bios::new(Drivers::test()));
let factor_source = LedgerHardwareWalletFactorSource::sample();
let interactors =
Interactors::new_from_clients_and_spot_check_interactor(
&clients,
Arc::new(
TestSpotCheckInteractor::new_mnemonic_with_passphrase(
MnemonicWithPassphrase::sample(),
),
),
Arc::new(TestSpotCheckInteractor::new_software(
MnemonicWithPassphrase::sample(),
)),
);
let os = timeout(
SARGON_OS_TEST_MAX_ASYNC_DURATION,
Expand Down Expand Up @@ -1358,20 +1355,16 @@ mod tests {
}

#[actix_rt::test]
#[should_panic(
expected = "Unexpected MnemonicWithPassphrase Response for ArculusCard"
)]
async fn spot_check__arculus__mvp_response() {
#[should_panic(expected = "Unexpected Software Response for ArculusCard")]
async fn spot_check__arculus__software_response() {
let clients = Clients::new(Bios::new(Drivers::test()));
let factor_source = ArculusCardFactorSource::sample();
let interactors =
Interactors::new_from_clients_and_spot_check_interactor(
&clients,
Arc::new(
TestSpotCheckInteractor::new_mnemonic_with_passphrase(
MnemonicWithPassphrase::sample(),
),
),
Arc::new(TestSpotCheckInteractor::new_software(
MnemonicWithPassphrase::sample(),
)),
);
let os = timeout(
SARGON_OS_TEST_MAX_ASYNC_DURATION,
Expand Down
6 changes: 4 additions & 2 deletions crates/uniffi/uniffi_SPLIT_ME/src/types/spot_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub enum SpotCheckResponse {
ArculusCard { id: FactorSourceIDFromHash },

/// The user retrieved a `MnemonicWithPassphrase`.
/// Used for the identification of any other `FactorSource`.
MnemonicWithPassphrase { value: MnemonicWithPassphrase },
/// Used for the identification of any software `FactorSource`.
Software {
mnemonic_with_passphrase: MnemonicWithPassphrase,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.radixdlt.sargon.os.interactor
import com.radixdlt.sargon.AuthorizationPurpose
import com.radixdlt.sargon.AuthorizationResponse
import com.radixdlt.sargon.CommonException
import com.radixdlt.sargon.FactorSource
import com.radixdlt.sargon.HostInteractor
import com.radixdlt.sargon.KeyDerivationRequest
import com.radixdlt.sargon.KeyDerivationResponse
Expand All @@ -12,6 +13,7 @@ import com.radixdlt.sargon.SignRequestOfTransactionIntent
import com.radixdlt.sargon.SignResponseOfAuthIntentHash
import com.radixdlt.sargon.SignResponseOfSubintentHash
import com.radixdlt.sargon.SignResponseOfTransactionIntentHash
import com.radixdlt.sargon.SpotCheckResponse

class FakeHostInteractor: HostInteractor {
override suspend fun signTransactions(
Expand All @@ -36,4 +38,8 @@ class FakeHostInteractor: HostInteractor {
return AuthorizationResponse.REJECTED
}

override suspend fun spotCheck(factorSource: FactorSource): SpotCheckResponse {
throw CommonException.HostInteractionAborted()
}

}

0 comments on commit 8bb3af2

Please sign in to comment.