Skip to content

Commit

Permalink
Factor Source name updates (#283)
Browse files Browse the repository at this point in the history
* rename Passphrase to Password + hint

* wip

* wip

* wip

* DRY factor source

* wip

* wip

* bump version

* wip

* fmt

* fixes + tests

* bump version + fmt

* fix test

---------

Co-authored-by: Alexander Cyon <[email protected]>
  • Loading branch information
danvleju-rdx and CyonAlexRDX authored Nov 29, 2024
1 parent d016d67 commit 60beabe
Show file tree
Hide file tree
Showing 63 changed files with 570 additions and 327 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension ArculusCardFactorSource {

public init(
mnemonicWithPassphrase mwp: MnemonicWithPassphrase,
name: String
label: String
) {
self.init(mnemonicWithPassphrase: mwp, hint: .init(name: name, model: .arculusColdStorageWallet))
self.init(mnemonicWithPassphrase: mwp, hint: .init(label: label, model: .arculusColdStorageWallet))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ extension FactorSource {
public var supportsBabylon: Bool {
factorSourceSupportsBabylon(factorSource: self)
}

public var name: String {
factorSourceName(factorSource: self)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import SargonUniFFI

extension PasswordFactorSource {
public init(
mnemonicWithPassphrase mwp: MnemonicWithPassphrase,
hint: PasswordFactorSourceHint
) {
self = newPasswordFactorSourceFromMnemonicWithPassphrase(
mwp: mwp,
hint: hint
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ extension Mnemonic {
public static let sampleOffDeviceMnemonicOther: Self = newMnemonicSampleOffDeviceOther()
public static let sampleSecurityQuestions: Self = newMnemonicSampleSecurityQuestions()
public static let sampleSecurityQuestionsOther: Self = newMnemonicSampleSecurityQuestionsOther()
public static let samplePassphrase: Self = newMnemonicSamplePassphrase()
public static let samplePassphraseOther: Self = newMnemonicSamplePassphraseOther()
public static let samplePassword: Self = newMnemonicSamplePassword()
public static let samplePasswordOther: Self = newMnemonicSamplePasswordOther()

public static let sample24ZooVote: Self = try! Self(phrase: "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote")

Expand All @@ -35,8 +35,8 @@ extension Mnemonic {
.sampleOffDeviceMnemonicOther,
.sampleSecurityQuestions,
.sampleSecurityQuestionsOther,
.samplePassphrase,
.samplePassphraseOther,
.samplePassword,
.samplePasswordOther,
]
}
#endif // DEBUG

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation
import SargonUniFFI

#if DEBUG
extension PasswordFactorSource {
public static let sample: Self = newPasswordFactorSourceSample()

public static let sampleOther: Self = newPasswordFactorSourceSampleOther()
}

#endif // DEBUG
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension FactorSource: Identifiable {
case let .ledger(value): value.id.asGeneral
case let .offDeviceMnemonic(value): value.id.asGeneral
case let .trustedContact(value): value.id.asGeneral
case let .passphrase(value): value.id.asGeneral
case let .password(value): value.id.asGeneral
}
}
}
Expand All @@ -40,7 +40,7 @@ extension FactorSource: BaseFactorSourceProtocol {
case let .arculusCard(value): value.factorSourceKind
case let .offDeviceMnemonic(value): value.factorSourceKind
case let .trustedContact(value): value.factorSourceKind
case let .passphrase(value): value.factorSourceKind
case let .password(value): value.factorSourceKind
}
}

Expand All @@ -53,7 +53,7 @@ extension FactorSource: BaseFactorSourceProtocol {
case let .arculusCard(value): value.common
case let .offDeviceMnemonic(value): value.common
case let .trustedContact(value): value.common
case let .passphrase(value): value.common
case let .password(value): value.common
}
}
set {
Expand All @@ -76,9 +76,9 @@ extension FactorSource: BaseFactorSourceProtocol {
case var .trustedContact(source):
source.common = newValue
self = .trustedContact(value: source)
case var .passphrase(source):
case var .password(source):
source.common = newValue
self = .passphrase(value: source)
self = .password(value: source)
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ extension FactorSource: BaseFactorSourceProtocol {
extract()
}

public var asPassphrase: PassphraseFactorSource? {
public var asPassword: PasswordFactorSource? {
extract()
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import Foundation
import SargonUniFFI

// MARK: - PassphraseFactorSource + SargonModel
extension PassphraseFactorSource: SargonModel {}
// MARK: - PasswordFactorSource + SargonModel
extension PasswordFactorSource: SargonModel {}

// MARK: - PassphraseFactorSource + Identifiable
extension PassphraseFactorSource: Identifiable {
// MARK: - PasswordFactorSource + Identifiable
extension PasswordFactorSource: Identifiable {
public typealias ID = FactorSourceIDFromHash
}

// MARK: - PassphraseFactorSource + FactorSourceProtocol
extension PassphraseFactorSource: FactorSourceProtocol {
public static let kind: FactorSourceKind = .passphrase
// MARK: - PasswordFactorSource + FactorSourceProtocol
extension PasswordFactorSource: FactorSourceProtocol {
public static let kind: FactorSourceKind = .password

public static func extract(from someFactorSource: some BaseFactorSourceProtocol) -> Self? {
guard case let .passphrase(factorSource) = someFactorSource.asGeneral else { return nil }
guard case let .password(factorSource) = someFactorSource.asGeneral else { return nil }
return factorSource
}

public var asGeneral: FactorSource {
.passphrase(value: self)
.password(value: self)
}

public var factorSourceID: FactorSourceID {
id.asGeneral
}

public var factorSourceKind: FactorSourceKind {
.passphrase
.password
}

public var supportsOlympia: Bool { asGeneral.supportsOlympia }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ArculusCardFactorSourceTests: SpecificFactorSourceTest<ArculusCardFa
mnemonic: .sampleArculus,
passphrase: ""
),
name: "Test"
label: "Test"
).id,
SUT.sample.id
)
Expand Down
4 changes: 4 additions & 0 deletions apple/Tests/TestCases/Profile/Factor/FactorSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ final class FactorSourceTests: FactorSourceTest<FactorSource> {
XCTAssertEqual(SUT.sample.factorSourceKind, .device)
XCTAssertEqual(SUT.sampleOther.factorSourceKind, .ledgerHqHardwareWallet)
}

func test_name() {
XCTAssertEqual(SUT.sample.name, "My Phone")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LedgerHardwareWalletFactorSourceTests: SpecificFactorSourceTest<Ledg
mnemonic: .sampleLedger,
passphrase: ""
),
hint: .init(name: "Test", model: .nanoS),
hint: .init(label: "Test", model: .nanoS),
common: .babylon()
).id,
SUT.sample.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class OffDeviceMnemonicFactorSourceTests: SpecificFactorSourceTest<OffDevi
mnemonic: .sampleOffDeviceMnemonic,
passphrase: ""
),
hint: .init(displayName: "Test")
hint: .init(label: "Test")
).id,
SUT.sample.id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Sargon
import SargonUniFFI
import XCTest

final class PassphraseFactorSourceTests: SpecificFactorSourceTest<PassphraseFactorSource> {
func test_id_of_passphrase() {
final class PasswordFactorSourceTests: SpecificFactorSourceTest<PasswordFactorSource> {
func test_id_of_password() {
eachSample { sut in
XCTAssertEqual(sut.id.description, FactorSourceID.hash(value: sut.id).description)
}
Expand All @@ -15,9 +15,10 @@ final class PassphraseFactorSourceTests: SpecificFactorSourceTest<PassphraseFact
XCTAssertEqual(
SUT(
mnemonicWithPassphrase: .init(
mnemonic: .samplePassphrase,
mnemonic: .samplePassword,
passphrase: ""
)
),
hint: .init(label: "Password 1")
).id,
SUT.sample.id
)
Expand All @@ -31,13 +32,13 @@ final class PassphraseFactorSourceTests: SpecificFactorSourceTest<PassphraseFact

func test_kind() {
eachSample { sut in
XCTAssertEqual(sut.factorSourceKind, .passphrase)
XCTAssertEqual(sut.factorSourceKind, .password)
}
}

func test_as() {
eachSample { sut in
XCTAssertEqual(sut.asGeneral.asPassphrase, sut)
XCTAssertEqual(sut.asGeneral.asPassword, sut)
}
}

Expand All @@ -53,7 +54,7 @@ final class PassphraseFactorSourceTests: SpecificFactorSourceTest<PassphraseFact

func test_as_general() {
eachSample { sut in
XCTAssertEqual(sut.asGeneral, FactorSource.passphrase(value: sut))
XCTAssertEqual(sut.asGeneral, FactorSource.password(value: sut))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sargon-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon-uniffi"
# Don't forget to update version in crates/sargon/Cargo.toml
version = "1.1.69"
version = "1.1.70"
edition = "2021"
build = "build.rs"

Expand Down
4 changes: 2 additions & 2 deletions crates/sargon-uniffi/src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ pub enum CommonError {
#[error("Empty FactorSources list")]
FactorSourcesOfKindEmptyFactors = 10184,

#[error("Expected Passphrase factor source got something else")]
ExpectedPassphraseFactorSourceGotSomethingElse = 10185,
#[error("Expected Password factor source got something else")]
ExpectedPasswordFactorSourceGotSomethingElse = 10185,

#[error("Unknown persona.")]
UnknownPersona = 10186,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ pub fn new_mnemonic_sample_arculus_other() -> Mnemonic {
}

#[uniffi::export]
pub fn new_mnemonic_sample_passphrase() -> Mnemonic {
InternalMnemonic::sample_passphrase().into()
pub fn new_mnemonic_sample_password() -> Mnemonic {
InternalMnemonic::sample_password().into()
}

#[uniffi::export]
pub fn new_mnemonic_sample_passphrase_other() -> Mnemonic {
InternalMnemonic::sample_passphrase_other().into()
pub fn new_mnemonic_sample_password_other() -> Mnemonic {
InternalMnemonic::sample_password_other().into()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ use sargon::ArculusCardHint as InternalArculusCardHint;

#[derive(Clone, PartialEq, Eq, Hash, InternalConversion, uniffi::Record)]
pub struct ArculusCardHint {
/// A user-assigned name for the arculus card, intended to help users
/// differentiate between multiple arculus cards.
///
/// E.g. "Black" or "Silver"
pub name: String,
pub label: String,

pub model: ArculusCardModel,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod arculus_card_factor_source;
mod off_device_mnemonic_factor_source;
mod password_factor_source;
mod security_questions_factor_source;
mod trusted_contact_factor_source;

pub use arculus_card_factor_source::*;
pub use off_device_mnemonic_factor_source::*;
pub use password_factor_source::*;
pub use security_questions_factor_source::*;
pub use trusted_contact_factor_source::*;
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ use sargon::OffDeviceMnemonicHint as InternalOffDeviceMnemonicHint;
/// it and another one.
#[derive(Clone, PartialEq, Eq, Hash, InternalConversion, uniffi::Record)]
pub struct OffDeviceMnemonicHint {
pub display_name: DisplayName,
/// A user-assigned name for the passphrase, intended to help users
/// differentiate between multiple passphrases.
pub label: DisplayName,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod password_factor_source;
mod password_factor_source_hint;

pub use password_factor_source::*;
pub use password_factor_source_hint::*;
Loading

0 comments on commit 60beabe

Please sign in to comment.