Skip to content

Commit

Permalink
[ABW-4135] Export method to derive public keys (#350)
Browse files Browse the repository at this point in the history
* WIP

* extension for Subintent

* additions for auth intent

* export method to get Hash from AuthIntentHash

* remove export

* allow to create account with specific Factor Source

* export method to create account with specific factor source

* only pre derive VECI

* export method to create Persona

* specify network id when creating account

* WIP

* Rename variant

* fixes after rebase

* revert cache filling quantiites changes

* tests and improvements

* treat main babylon device factor source as 'main_bdfs' rather than 'bdfs'

* remove is_main_bdfs() from FactorSourceCommon

* remove unwanted change

* Release 1.1.118

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Generated by cargo-workspaces

---------

Co-authored-by: micbakos-rdx <[email protected]>
  • Loading branch information
matiasbzurovski and micbakos-rdx authored Jan 23, 2025
1 parent 5766453 commit 4653813
Show file tree
Hide file tree
Showing 111 changed files with 879 additions and 345 deletions.
186 changes: 103 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ members = [
"crates/system/profile-state-holder",
"crates/system/interactors",
"crates/system/os/accounts",
"crates/system/os/derive-public-keys",
"crates/system/os/factors",
"crates/system/os/os",
"crates/system/os/security-center",
Expand Down Expand Up @@ -167,6 +168,7 @@ default-members = [
"crates/system/profile-state-holder",
"crates/system/interactors",
"crates/system/os/accounts",
"crates/system/os/derive-public-keys",
"crates/system/os/factors",
"crates/system/os/os",
"crates/system/os/security-center",
Expand Down Expand Up @@ -275,6 +277,7 @@ sub-systems = { path = "crates/system/sub-systems" }
profile-state-holder = { path = "crates/system/profile-state-holder" }
interactors = { path = "crates/system/interactors" }
sargon-os-accounts = { path = "crates/system/os/accounts" }
sargon-os-derive-public-keys = { path = "crates/system/os/derive-public-keys" }
sargon-os-factors = { path = "crates/system/os/factors" }
sargon-os = { path = "crates/system/os/os" }
sargon-os-security-center = { path = "crates/system/os/security-center" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ extension AddressOfAccountOrPersona {
public func formatted(_ format: AddressFormat) -> String {
addressOfAccountOrPersonaFormatted(address: self, format: format)
}

public var accountAddress: AccountAddress? {
switch self {
case let .account(address): address
case .identity: nil
}
}
}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ extension CompiledSubintent {
public var data: Data {
compiledSubintentBytes(compiledIntent: self)
}

public func decompile() -> Subintent {
compiledSubintentDecompile(compiledIntent: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ extension CompiledTransactionIntent {
public var data: Data {
compiledTransactionIntentBytes(compiledIntent: self)
}

public func decompile() -> TransactionIntent {
compiledTransactionIntentDecompile(compiledIntent: self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Foundation
import SargonUniFFI

extension DappToWalletInteractionMetadata {
public init(jsonData: some DataProtocol) throws {
self = try newDappToWalletInteractionMetadataFromJsonBytes(
jsonBytes: Data(jsonData)
)
}

public func jsonData() -> Data {
dappToWalletInteractionMetadataToJsonBytes(
dappToWalletInteractionMetadata: self
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation
import SargonUniFFI

extension AuthIntent {
public func hash() -> AuthIntentHash {
authIntentGetHash(authIntent: self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation
import SargonUniFFI

#if DEBUG
extension DappToWalletInteractionMetadata {
public static let sample: Self = newDappToWalletInteractionMetadataSample()
public static let sampleOther: Self = newDappToWalletInteractionMetadataSampleOther()
}
#endif // DEBUG
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation
import SargonUniFFI

// MARK: - DappToWalletInteractionMetadata + SargonObjectCodable
extension DappToWalletInteractionMetadata: SargonObjectCodable {}

// MARK: - DappToWalletInteractionMetadata + SargonModel
extension DappToWalletInteractionMetadata: SargonModel {}
29 changes: 27 additions & 2 deletions apple/Sources/Sargon/SargonOS/SargonOS+SargonOSProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,33 @@ extension SargonOS: SargonOSProtocol {
extension SargonOS {
@discardableResult
public func createAccount(
named accountName: DisplayName
factorSource: FactorSource,
networkId: NetworkID?,
name: DisplayName
) async throws -> Account {
try await createAndSaveNewAccount(networkId: currentNetworkID, name: accountName)
try await createAndSaveNewAccountWithFactorSource(factorSource: factorSource, networkId: networkId ?? currentNetworkID, name: name)
}

@discardableResult
public func createAccountWithBDFS(
networkId: NetworkID?,
name: DisplayName
) async throws -> Account {
try await createAndSaveNewAccountWithMainBdfs(networkId: networkId ?? currentNetworkID, name: name)
}

public func createPersona(
factorSource: FactorSource,
name: DisplayName,
personaData: PersonaData?
) async throws -> Persona {
try await createAndSaveNewPersonaWithFactorSource(factorSource: factorSource, networkId: currentNetworkID, name: name, personaData: personaData)
}

public func createPersonaWithBDFS(
name: DisplayName,
personaData: PersonaData?
) async throws -> Persona {
try await createAndSaveNewPersonaWithMainBdfs(networkId: currentNetworkID, name: name, personaData: personaData)
}
}
9 changes: 6 additions & 3 deletions apple/Sources/Sargon/SargonOS/SargonOS+Static+Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ struct SargonOSAlreadyBooted: LocalizedError {
extension SargonOS {
public nonisolated(unsafe) static var shared: SargonOS {
guard let shared = _shared else {
fatalError("`SargonOS.shared` not created, create it with `SargonOS.creatingShared:bootingWith` and pass it a `BIOS`.")
fatalError("`SargonOS.shared` not created, create it with `SargonOS.creatingShared:bootingWith:hostInteractor` and pass it a `BIOS` and a `HostInteractor`.")
}
return shared
}

/// Can be access later with `OS.shared`
@discardableResult
public static func creatingShared(
bootingWith bios: BIOS
bootingWith bios: BIOS,
hostInteractor: HostInteractor
) async throws -> SargonOS {
try await _creatingShared(
bootingWith: bios,
hostInteractor: hostInteractor,
isEmulatingFreshInstall: false
)
}
Expand All @@ -33,14 +35,15 @@ extension SargonOS {
@discardableResult
static func _creatingShared(
bootingWith bios: BIOS,
hostInteractor: HostInteractor,
isEmulatingFreshInstall: Bool
) async throws -> SargonOS {
if !isEmulatingFreshInstall, _shared != nil {
throw SargonOSAlreadyBooted()
}
let shared = await SargonOS.boot(
bios: bios,
interactor: ThrowingHostInteractor.shared
interactor: hostInteractor
)
Self._shared = shared
return shared
Expand Down
12 changes: 7 additions & 5 deletions apple/Sources/Sargon/SargonOS/SargonOSProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import SargonUniFFI
public protocol SargonOSProtocol {
var os: SargonOS { get }

func createAccount(
named accountName: DisplayName
func createAccountWithBDFS(
networkId: NetworkID?,
name: DisplayName
) async throws -> Account
}

// MARK: Forward calls to `os`
extension SargonOSProtocol {
public func createAccount(
named accountName: DisplayName
public func createAccountWithBDFS(
networkId: NetworkID?,
name: DisplayName
) async throws -> Account {
try await os.createAccount(named: accountName)
try await os.createAccountWithBDFS(networkId: networkId, name: name)
}
}

Expand Down
7 changes: 4 additions & 3 deletions apple/Sources/Sargon/SargonOS/TestOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ extension TestOS {
)
} ?? nextAccountName()

let _ = try await os.createAccount(
named: accountName
let _ = try await os.createAccountWithBDFS(
networkId: nil,
name: accountName
)
return self
}
Expand All @@ -68,7 +69,7 @@ extension TestOS {
count: UInt16,
namePrefix: DisplayName
) async throws -> Self {
let _ = try await os.batchCreateManyAccountsThenSaveOnce(count: count, networkId: currentNetworkID, namePrefix: namePrefix.value)
let _ = try await os.batchCreateManyAccountsWithMainBdfsThenSaveOnce(count: count, networkId: currentNetworkID, namePrefix: namePrefix.value)
return self
}
}
Expand Down
11 changes: 6 additions & 5 deletions apple/Tests/IntegrationTests/SargonOS/SargonOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class SargonOSTests: OSTest {
secureStorageDriver: Insecure︕!TestOnly︕!Ephemeral︕!SecureStorage(
keychainService: "test"
)
)
),
hostInteractor: ThrowingHostInteractor.shared
)
XCTAssertTrue(SUT.shared === sut)
}
Expand All @@ -38,9 +39,9 @@ final class SargonOSTests: OSTest {
keychainService: "test"
)
)
let _ = try await SUT.creatingShared(bootingWith: bios)
let _ = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared)
do {
let _ = try await SUT.creatingShared(bootingWith: bios)
let _ = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared)
XCTFail("Should have thrown")
} catch let err as SargonOSAlreadyBooted {
XCTAssertEqual(err.errorDescription, "Radix Wallet core already initialized, should not have been initialized twice. This is a Radix developer error.")
Expand All @@ -53,8 +54,8 @@ final class SargonOSTests: OSTest {
keychainService: "test"
)
)
let first = try await SUT.creatingShared(bootingWith: bios)
let second = try await SUT._creatingShared(bootingWith: bios, isEmulatingFreshInstall: true)
let first = try await SUT.creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared)
let second = try await SUT._creatingShared(bootingWith: bios, hostInteractor: ThrowingHostInteractor.shared, isEmulatingFreshInstall: true)
XCTAssertFalse(first === second)
XCTAssertTrue(SUT.shared === second)
}
Expand Down
4 changes: 2 additions & 2 deletions apple/Tests/IntegrationTests/SargonOS/TestOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class TestOSTests: OSTest {
let sut = await TestOS()
try await sut.os.newWallet(shouldPreDeriveInstances: false)
let displayName: DisplayName = "New"
let account = try await sut.createAccount(named: displayName)
let account = try await sut.createAccountWithBDFS(networkId: nil, name: displayName)
XCTAssertEqual(account.displayName, displayName)
XCTAssertEqual(try sut.accountsForDisplayOnCurrentNetwork, [AccountForDisplay(account)])
}
Expand All @@ -70,7 +70,7 @@ final class TestOSTests: OSTest {
let sut = await TestOS()
try await sut.os.newWallet(shouldPreDeriveInstances: false)
let displayName: DisplayName = "New"
let account = try await sut.createAccount(named: displayName)
let account = try await sut.createAccountWithBDFS(networkId: nil, name: displayName)
let lookedUp = try sut.accountByAddress(account.address)
XCTAssertEqual(lookedUp, account)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ import Sargon
import SargonUniFFI
import XCTest

final class AddressOfAccountOrPersonaTests: AddressTest<AddressOfAccountOrPersona> {}
final class AddressOfAccountOrPersonaTests: AddressTest<AddressOfAccountOrPersona> {
func testAccountAddress() throws {
let accountAddress = AccountAddress.sample

var sut = SUT.account(accountAddress)
XCTAssertEqual(sut.accountAddress, accountAddress)

sut = SUT.identity(.sample)
XCTAssertNil(sut.accountAddress)
}
}
2 changes: 1 addition & 1 deletion crates/app/home-cards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "home-cards"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/key-derivation-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-derivation-traits"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions crates/app/key-derivation-traits/src/derivation_purpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub enum DerivationPurpose {
/// When adding a new factor source, initiates keys collection
/// for collecting various factor instances.
PreDerivingKeys,

/// When deriving accounts for recovery.
AccountRecovery,
}

impl DerivationPurpose {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect-models"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect"
version = "1.1.117"
version = "1.1.118"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/app/security-center/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "security-center"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing-traits"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing"
version = "1.1.117"
version = "1.1.118"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/common/build-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "build-info"
version = "1.1.117"
version = "1.1.118"
edition = "2021"
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion crates/common/bytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bytes"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/entity-foundation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "entity-foundation"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/host-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "host-info"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/identified-vec-of/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "identified-vec-of"
version = "1.1.117"
version = "1.1.118"
edition = "2021"

[dependencies]
Expand Down
Loading

0 comments on commit 4653813

Please sign in to comment.