Skip to content

Commit

Permalink
Multi-signatures collector integration (#235)
Browse files Browse the repository at this point in the history
* Transfer SignaturesCollectorDependencies into sargon

* WIP

* Add passphrase factor source kind

* Add passphrase factor source

* Add FactorSourceIDFromHash samples

* Implement custom HDFactorSourceIdFromHash to keep track of the factor source id and the mnemonic it was created with

* Remove custom struct

* Add petition_for_factors

* Add Implement a general role with hd factor instances

* Add securified variant in EntitySecurityState

* Fix tests in petition_for_entity

* Transfer petition_for_transaction

* WIP more files

* Transfer SignaturesCollectorPreprocessor

* Implement transaction intent initializer that accepts account and identity addresses requiring auth

* Allow signing inputs in tests from associated mnemonics

* Transfer signatures collector tests

* Transfer remaining signatures_collector tests

* Include integration tests

* Rebase with main

* Remove Ord impl for Persona and Account

* Address todo comments

* Format code

* Fix errors in swift tests

* Remove comment

* Fix ide errors

* Add doc

* Add doc

* Remove doc

* Associate entity samples with entity address samples

* Add doc

* Rename

* Remove doc

* Destructure value

* Hide from function

* Rename function

* Rename general role samples

* Create HDFactorInstance directly from derivation path's params

* Rename parameter

* Expose role kind

* Add new constructor

* Return result when creating a new role

* Add apple tests for passphrase factor source

* Add doc

* Bump version

* Fix test

* Run clippy

* Run fmt
  • Loading branch information
micbakos-rdx authored Oct 15, 2024
1 parent b9d9995 commit 8540902
Show file tree
Hide file tree
Showing 123 changed files with 9,716 additions and 188 deletions.
38 changes: 22 additions & 16 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
@@ -0,0 +1,18 @@
//
// File.swift
//
//
// Created by Alexander Cyon on 2024-06-02.
//

import Foundation
import SargonUniFFI

extension PassphraseFactorSource {

public init(
mnemonicWithPassphrase mwp: MnemonicWithPassphrase
) {
self = newPassphraseFactorSourceFromMnemonicWithPassphrase(mwp: mwp)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ 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 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")

public static let sampleValues: [Self] = [
Expand All @@ -32,7 +34,9 @@ extension Mnemonic {
.sampleOffDeviceMnemonic,
.sampleOffDeviceMnemonicOther,
.sampleSecurityQuestions,
.sampleSecurityQuestionsOther
.sampleSecurityQuestionsOther,
.samplePassphrase,
.samplePassphraseOther
]
}
#endif // DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// PassphraseFactorSource+SampleValues.swift
//
//
// Created by Michael Bakogiannis on 7/10/24.
//

import Foundation
import SargonUniFFI

#if DEBUG
extension PassphraseFactorSource {
public static let sample: Self = newPassphraseFactorSourceSample()

public static let sampleOther: Self = newPassphraseFactorSourceSampleOther()
}

#endif // DEBUG

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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
}
}
}
Expand All @@ -35,6 +36,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
}
}

Expand All @@ -47,6 +49,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
}
}
set {
Expand All @@ -69,6 +72,9 @@ extension FactorSource: BaseFactorSourceProtocol {
case var .trustedContact(source):
source.common = newValue
self = .trustedContact(value: source)
case var .passphrase(source):
source.common = newValue
self = .passphrase(value: source)
}
}
}
Expand Down Expand Up @@ -112,4 +118,7 @@ extension FactorSource: BaseFactorSourceProtocol {
public var asTrustedContact: TrustedContactFactorSource? {
extract()
}
public var asPassphrase: PassphraseFactorSource? {
extract()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// PassphraseFactorSource+Swiftified.swift
//
//
// Created by Michael Bakogiannis on 7/10/24.
//

import Foundation
import SargonUniFFI

extension PassphraseFactorSource: SargonModel {}
extension PassphraseFactorSource: Identifiable {
public typealias ID = FactorSourceIDFromHash
}

extension PassphraseFactorSource: FactorSourceProtocol {
public static let kind: FactorSourceKind = .passphrase

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

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

public var factorSourceID: FactorSourceID {
id.asGeneral
}

public var factorSourceKind: FactorSourceKind {
.passphrase
}

public var supportsOlympia: Bool { asGeneral.supportsOlympia }
public var supportsBabylon: Bool { asGeneral.supportsBabylon }
}
6 changes: 6 additions & 0 deletions apple/Sources/Sargon/Protocols/EntityProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ extension EntityBaseProtocol {
factorInstances.insert(authSigning)
}
return factorInstances
case .securified(value: let value):
return []
}
}

public var hasAuthenticationSigningKey: Bool {
switch securityState {
case let .unsecured(unsecuredEntityControl):
unsecuredEntityControl.authenticationSigning != nil
case .securified(value: let value):
false // TODO handle that in the future
}
}

Expand All @@ -64,6 +68,8 @@ extension EntityBaseProtocol {
}

return factorSourceID
case .securified(value: _):
return nil // TODO handle that in the future
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions apple/Tests/TestCases/Profile/EntitySecurityStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,3 @@ import SargonUniFFI
import XCTest

final class EntitySecurityStateTests: Test<EntitySecurityState> {}

#if DEBUG
extension EntitySecurityState {
public var unsecured: UnsecuredEntityControl {
get {
switch self {
case let .unsecured(value):
return value
}
}
set {
self = .unsecured(value: newValue)
}
}
}
#endif // DEBUG
Loading

0 comments on commit 8540902

Please sign in to comment.