From 0471e0ebde0b9bb791a7f0411471a0ad90c3bb40 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:32:55 +0300 Subject: [PATCH 01/11] wip --- RadixWallet.xcodeproj/project.pbxproj | 27 ++- .../xcshareddata/swiftpm/Package.resolved | 11 +- .../DappInteractionClient+Interfce.swift | 30 +-- .../DappInteractionClient+Live.swift | 76 ++++--- ...LedgerHardwareWalletClient+Interface.swift | 8 +- .../ROLAClient/ROLAClient+Interface.swift | 12 +- .../Clients/ROLAClient/ROLAClient+Live.swift | 14 +- .../Clients/ROLAClient/ROLAFailure.swift | 3 +- .../RadixConnectClient+Live.swift | 4 +- .../Models/TransactionFailure.swift | 2 +- .../P2P+RTCIncomingMessage.swift | 2 +- .../P2P+RTCMessageFromPeer.swift | 2 +- .../P2P+RTCOutgoingMessage.swift | 2 +- .../P2P+ConnectorExtension+Request.swift | 10 +- .../Interaction/DTO/NumberOfAccounts.swift | 6 +- .../Requests/AccountsRequestItem.swift | 29 ++- .../Requests/AuthRequestItem.swift | 108 +++++----- .../Requests/PersonaDataRequestItem.swift | 87 ++++---- .../Requests/ResetRequestItem.swift | 28 +-- .../Transactions/SendTransactionRequest.swift | 156 +++++++------- .../WalletInteraction+PreviewValue.swift | 145 +++++-------- .../Interaction/WalletInteraction.swift | 169 ++++++++------- .../Interaction/WalletInteractionItems.swift | 164 +++++++-------- .../DTO/P2P+Dapp+Response+Persona.swift | 32 ++- .../DTO/WalletAccount.swift | 74 +++---- .../P2P+Dapp+Response.swift | 140 ++++--------- .../AccountsRequestResponseItem.swift | 70 +++---- .../AuthRequestResponseItem.swift | 129 ++++++------ .../PersonaDataRequestResponseItem.swift | 37 ++-- .../SendTransactionResponseItem.swift | 56 ++--- .../WalletInteractionFailureResponse.swift | 196 +++++++++--------- .../WalletInteractionSuccessResponse.swift | 31 ++- ...alletInteractionSuccessResponseItems.swift | 150 +++++++------- .../Dapp/Models/WalletInteractionTypes.swift | 158 ++++++++++++++ .../Core/SharedModels/P2P/DappOrigin.swift | 40 ---- .../AccountPermission/AccountPermission.swift | 4 +- ...ountPermissionChooseAccounts+Reducer.swift | 16 +- .../Login/Coordinator/Login+View.swift | 2 +- .../Children/Login/Coordinator/Login.swift | 8 +- .../OneTimePersonaData+View.swift | 2 +- .../OneTimePersonaData.swift | 8 +- .../PersonaDataPermission+View.swift | 2 +- .../PersonaDataPermission.swift | 8 +- .../PersonaDataPermissionBox.swift | 6 +- .../DappInteractionCoordinator+View.swift | 4 +- .../DappInteractionCoordinator.swift | 14 +- .../Coordinator/DappInteractionFlow.swift | 121 +++++------ .../DappInteractionLoading+View.swift | 2 +- .../Coordinator/DappInteractionLoading.swift | 10 +- .../Coordinator/DappInteractionModels.swift | 91 ++++---- .../Interactor/DappInteractor.swift | 28 +-- .../TransactionReview+View.swift | 2 +- ...ge2MigrateToSargon+SharedPersonaData.swift | 12 +- .../Stage2MigrateToSargpn+PersonaData.swift | 10 +- ...ateToSargon+RadixConnectModels+Logic.swift | 12 +- .../ROLAClientTests/ROLAClientTests.swift | 4 +- 56 files changed, 1270 insertions(+), 1304 deletions(-) create mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/DappOrigin.swift diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 3c7b1031d0..a7da142ab6 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 56; + objectVersion = 60; objects = { /* Begin PBXBuildFile section */ @@ -12,7 +12,6 @@ 4813AFE22BC9A9AD0046BCAD /* Stage1MigrateToSargon+NetworkDefinition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFE12BC9A9AD0046BCAD /* Stage1MigrateToSargon+NetworkDefinition.swift */; }; 4813AFEB2BC9AF4A0046BCAD /* RawRepresentable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFEA2BC9AF4A0046BCAD /* RawRepresentable+Extensions.swift */; }; 4813AFEF2BC9B08F0046BCAD /* DappDefinitionAddress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFEE2BC9B08F0046BCAD /* DappDefinitionAddress.swift */; }; - 4813AFF12BC9B0F60046BCAD /* DappOrigin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFF02BC9B0F60046BCAD /* DappOrigin.swift */; }; 4813AFF52BC9B2D70046BCAD /* Stage2MigrateToSargon+SharedPersonaData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFF42BC9B2D70046BCAD /* Stage2MigrateToSargon+SharedPersonaData.swift */; }; 4813AFFB2BC9B5A90046BCAD /* Stage2MigrateToSargpn+PersonaData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813AFFA2BC9B5A90046BCAD /* Stage2MigrateToSargpn+PersonaData.swift */; }; 4813B0012BCA48CE0046BCAD /* Stage2MigrateToSargon+ProfileNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4813B0002BCA48CE0046BCAD /* Stage2MigrateToSargon+ProfileNetwork.swift */; }; @@ -1167,6 +1166,7 @@ E7A5AC962C09F447006CB6EC /* ResetWalletClient+Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC952C09F447006CB6EC /* ResetWalletClient+Interface.swift */; }; E7A5AC982C09F44C006CB6EC /* ResetWalletClient+Live.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC972C09F44C006CB6EC /* ResetWalletClient+Live.swift */; }; E7A5AC9A2C09F453006CB6EC /* ResetWalletClient+Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC992C09F453006CB6EC /* ResetWalletClient+Test.swift */; }; + E7A5AC9D2C108F2F006CB6EC /* WalletInteractionTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */; }; E7AE2D052BF7844300830BAA /* Sargon in Frameworks */ = {isa = PBXBuildFile; productRef = E695F2DD2BECDD7C00761ACE /* Sargon */; }; E7AE2D0A2C05F39800830BAA /* ClaimWallet+Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7AE2D092C05F39800830BAA /* ClaimWallet+Reducer.swift */; }; E7AE2D0C2C05F39E00830BAA /* ClaimWallet+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7AE2D0B2C05F39E00830BAA /* ClaimWallet+View.swift */; }; @@ -1194,7 +1194,6 @@ 4813AFE12BC9A9AD0046BCAD /* Stage1MigrateToSargon+NetworkDefinition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stage1MigrateToSargon+NetworkDefinition.swift"; sourceTree = ""; }; 4813AFEA2BC9AF4A0046BCAD /* RawRepresentable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RawRepresentable+Extensions.swift"; sourceTree = ""; }; 4813AFEE2BC9B08F0046BCAD /* DappDefinitionAddress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DappDefinitionAddress.swift; sourceTree = ""; }; - 4813AFF02BC9B0F60046BCAD /* DappOrigin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DappOrigin.swift; sourceTree = ""; }; 4813AFF42BC9B2D70046BCAD /* Stage2MigrateToSargon+SharedPersonaData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stage2MigrateToSargon+SharedPersonaData.swift"; sourceTree = ""; }; 4813AFFA2BC9B5A90046BCAD /* Stage2MigrateToSargpn+PersonaData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stage2MigrateToSargpn+PersonaData.swift"; sourceTree = ""; }; 4813B0002BCA48CE0046BCAD /* Stage2MigrateToSargon+ProfileNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stage2MigrateToSargon+ProfileNetwork.swift"; sourceTree = ""; }; @@ -2319,6 +2318,7 @@ E7A5AC952C09F447006CB6EC /* ResetWalletClient+Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Interface.swift"; sourceTree = ""; }; E7A5AC972C09F44C006CB6EC /* ResetWalletClient+Live.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Live.swift"; sourceTree = ""; }; E7A5AC992C09F453006CB6EC /* ResetWalletClient+Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Test.swift"; sourceTree = ""; }; + E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInteractionTypes.swift; sourceTree = ""; }; E7AE2D092C05F39800830BAA /* ClaimWallet+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ClaimWallet+Reducer.swift"; sourceTree = ""; }; E7AE2D0B2C05F39E00830BAA /* ClaimWallet+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ClaimWallet+View.swift"; sourceTree = ""; }; E7AE2D0D2C07359500830BAA /* FullScreenOverlayCoordinator+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FullScreenOverlayCoordinator+Reducer.swift"; sourceTree = ""; }; @@ -5300,7 +5300,6 @@ 48CFC1652ADC10D900E77A5C /* P2P */ = { isa = PBXGroup; children = ( - 4813AFF02BC9B0F60046BCAD /* DappOrigin.swift */, 48CFC1662ADC10D900E77A5C /* ConnectorExtension */, 48CFC16B2ADC10D900E77A5C /* Dapp */, 48CFC1892ADC10D900E77A5C /* P2P.swift */, @@ -5333,6 +5332,7 @@ 48CFC16C2ADC10D900E77A5C /* Models */ = { isa = PBXGroup; children = ( + E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */, 48CFC16D2ADC10D900E77A5C /* InteractionResponse */, 48CFC17B2ADC10D900E77A5C /* Interaction */, ); @@ -6675,7 +6675,7 @@ 5B1C4FD32BBB0B0C00B9436F /* XCRemoteSwiftPackageReference "AppsFlyerFramework-Strict" */, 8318BB172BC8403800057BCB /* XCRemoteSwiftPackageReference "swift-custom-dump" */, E6A0B0492BF23C7000617DAC /* XCRemoteSwiftPackageReference "swift-identified-collections" */, - E7AE2D072BF7855500830BAA /* XCRemoteSwiftPackageReference "sargon" */, + E7A5AC9B2C0F3EBA006CB6EC /* XCLocalSwiftPackageReference "../sargon" */, ); productRefGroup = 48CFBC502ADC106300E77A5C /* Products */; projectDirPath = ""; @@ -7464,7 +7464,6 @@ A462B58A2B83673000C26D20 /* StateKeyValueStoreKeysResponseItem.swift in Sources */, 83EE5EEE2BE3C16F00B1531D /* StatePackageCodePageResponse.swift in Sources */, 48CFC2982ADC10D900E77A5C /* CustomizeFees+View.swift in Sources */, - 4813AFF12BC9B0F60046BCAD /* DappOrigin.swift in Sources */, 48CFC3312ADC10D900E77A5C /* ImportMnemonicWord+View.swift in Sources */, 48CFC55A2ADC10DA00E77A5C /* MetadataNonFungibleGlobalIdArrayValue.swift in Sources */, 83EE47572AF0DE8F00155F03 /* TransactionIntentStatus.swift in Sources */, @@ -7548,6 +7547,7 @@ 48CFC65D2ADC10DB00E77A5C /* Profile+AuthorizedDapps+Edit.swift in Sources */, 48CFC5552ADC10DA00E77A5C /* MetadataU64ArrayValue.swift in Sources */, 48CFC5242ADC10DA00E77A5C /* MetadataI32Value.swift in Sources */, + E7A5AC9D2C108F2F006CB6EC /* WalletInteractionTypes.swift in Sources */, 48CFC2522ADC10D900E77A5C /* AddNewGateway+Reducer.swift in Sources */, E7B7A0FD2BBBFB6100EEE900 /* HeaderListViewContainer.swift in Sources */, 48CFC3FA2ADC10D900E77A5C /* SignalingClient.swift in Sources */, @@ -8381,6 +8381,13 @@ }; /* End XCConfigurationList section */ +/* Begin XCLocalSwiftPackageReference section */ + E7A5AC9B2C0F3EBA006CB6EC /* XCLocalSwiftPackageReference "../sargon" */ = { + isa = XCLocalSwiftPackageReference; + relativePath = ../sargon; + }; +/* End XCLocalSwiftPackageReference section */ + /* Begin XCRemoteSwiftPackageReference section */ 48FFFA972ADC1EEC00B2B213 /* XCRemoteSwiftPackageReference "AsyncExtensions" */ = { isa = XCRemoteSwiftPackageReference; @@ -8654,14 +8661,6 @@ version = 1.0.2; }; }; - E7AE2D072BF7855500830BAA /* XCRemoteSwiftPackageReference "sargon" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/radixdlt/sargon"; - requirement = { - kind = exactVersion; - version = 1.0.7; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ diff --git a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9f0ac9444e..eee24e2200 100644 --- a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "7d3590b225945abb1bc0ab6c684b005c28c64bdc204afcc2d34c3e379ef8a3c8", + "originHash" : "1d033d2d9728e181322e687c87550e30c6bcdac33f59fe631e1e37780502d076", "pins" : [ { "identity" : "anycodable", @@ -109,15 +109,6 @@ "version" : "11.6.4" } }, - { - "identity" : "sargon", - "kind" : "remoteSourceControl", - "location" : "https://github.com/radixdlt/sargon", - "state" : { - "revision" : "37221d388f75bdf4ce2ef9d2e4ed6fa686072969", - "version" : "1.0.7" - } - }, { "identity" : "screenshotpreventing-ios", "kind" : "remoteSourceControl", diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift index 1886cdaaaa..5d11d942d0 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift @@ -21,34 +21,16 @@ extension DappInteractionClient { case accountTransfer } - public typealias AddWalletInteraction = @Sendable (_ items: P2P.Dapp.Request.Items, _ interaction: WalletInteraction) async -> P2P.RTCOutgoingMessage.Response? + public typealias AddWalletInteraction = @Sendable (_ items: DappToWalletInteractionItems, _ interaction: WalletInteraction) async -> P2P.RTCOutgoingMessage.Response? public typealias CompleteInteraction = @Sendable (P2P.RTCOutgoingMessage) async throws -> Void } -extension P2P.Dapp.Request.ID { - public static func walletInteractionID(for interaction: DappInteractionClient.WalletInteraction) -> Self { - "\(interaction.rawValue)_\(UUID().uuidString)" - } - - public var isWalletAccountDepositSettingsInteraction: Bool { - rawValue.hasPrefix(DappInteractionClient.WalletInteraction.accountDepositSettings.rawValue) - } - - public var isWalletAccountTransferInteraction: Bool { - rawValue.hasPrefix(DappInteractionClient.WalletInteraction.accountTransfer.rawValue) - } - - public var isWalletInteraction: Bool { - isWalletAccountTransferInteraction || isWalletAccountDepositSettingsInteraction - } -} - extension DappInteractionClient { public struct RequestEnvelope: Sendable, Hashable { public let route: P2P.Route - public let request: P2P.Dapp.Request + public let request: DappToWalletInteraction - public init(route: P2P.Route, request: P2P.Dapp.Request) { + public init(route: P2P.Route, request: DappToWalletInteraction) { self.route = route self.request = request } @@ -64,12 +46,12 @@ extension DappInteractionClient { } public enum Request: Sendable, Hashable { - case valid(P2P.Dapp.Request) - case invalid(request: P2P.Dapp.RequestUnvalidated, reason: InvalidRequestReason) + case valid(DappToWalletInteraction) + case invalid(request: DappToWalletInteractionUnvalidated, reason: InvalidRequestReason) } public enum InvalidRequestReason: Sendable, Hashable { - case incompatibleVersion(connectorExtensionSent: P2P.Dapp.Version, walletUses: P2P.Dapp.Version) + case incompatibleVersion(connectorExtensionSent: WalletInteractionVersion, walletUses: WalletInteractionVersion) case wrongNetworkID(connectorExtensionSent: NetworkID, walletUses: NetworkID) case invalidDappDefinitionAddress(gotStringWhichIsAnInvalidAccountAddress: String) case invalidOrigin(invalidURLString: String) diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift index 3a8eff9736..dfd7bacb79 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift @@ -24,19 +24,19 @@ extension DappInteractionClient: DependencyKey { addWalletInteraction: { items, interaction in @Dependency(\.gatewaysClient) var gatewaysClient - let id: P2P.Dapp.Request.ID = .walletInteractionID(for: interaction) + let interactionId: WalletInteractionId = .walletInteractionID(for: interaction) let request = await ValidatedDappRequest( route: .wallet, request: .valid( .init( - id: id, + interactionId: interactionId, items: items, metadata: .init( version: P2P.Dapp.currentVersion, networkId: gatewaysClient.getCurrentNetworkID(), - origin: DappOrigin.wallet, - dAppDefinitionAddress: .wallet + origin: DappToWalletInteractionMetadata.Origin.wallet, + dappDefinitionAddress: .wallet ) )) ) @@ -46,7 +46,7 @@ extension DappInteractionClient: DependencyKey { return await interactionResponsesSubject.first(where: { switch $0 { case let .dapp(response): - response.id == id + response.interactionId == interactionId } }) }, @@ -68,7 +68,7 @@ extension DappInteractionClient: DependencyKey { extension DappInteractionClient { /// Validates a received request from Dapp. static func validate( - _ message: P2P.RTCIncomingMessageContainer + _ message: P2P.RTCIncomingMessageContainer ) async -> Result { @Dependency(\.appPreferencesClient) var appPreferencesClient @Dependency(\.gatewaysClient) var gatewaysClient @@ -76,7 +76,7 @@ extension DappInteractionClient { let route = message.route - let nonValidated: P2P.Dapp.RequestUnvalidated + let nonValidated: DappToWalletInteractionUnvalidated do { nonValidated = try message.result.get() @@ -100,37 +100,53 @@ extension DappInteractionClient { let dappDefinitionAddress: DappDefinitionAddress do { dappDefinitionAddress = try DappDefinitionAddress( - validatingAddress: nonValidated.metadata.dAppDefinitionAddress + validatingAddress: nonValidated.metadata.dappDefinitionAddress ) } catch { - return invalidRequest(.invalidDappDefinitionAddress(gotStringWhichIsAnInvalidAccountAddress: nonvalidatedMeta.dAppDefinitionAddress)) + return invalidRequest(.invalidDappDefinitionAddress(gotStringWhichIsAnInvalidAccountAddress: nonvalidatedMeta.dappDefinitionAddress)) } - if case let .request(readRequest) = nonValidated.items { - switch readRequest { - case let .authorized(authorized): - if authorized.oneTimeAccounts?.numberOfAccounts.isValid == false { - return invalidRequest(.badContent(.numberOfAccountsInvalid)) - } - if authorized.ongoingAccounts?.numberOfAccounts.isValid == false { - return invalidRequest(.badContent(.numberOfAccountsInvalid)) - } - case let .unauthorized(unauthorized): - if unauthorized.oneTimeAccounts?.numberOfAccounts.isValid == false { - return invalidRequest(.badContent(.numberOfAccountsInvalid)) - } + switch nonValidated.items { + case let .authorizedRequest(authorized): + if authorized.oneTimeAccounts?.numberOfAccounts.isValid == false { + return invalidRequest(.badContent(.numberOfAccountsInvalid)) } + if authorized.ongoingAccounts?.numberOfAccounts.isValid == false { + return invalidRequest(.badContent(.numberOfAccountsInvalid)) + } + case let .unauthorizedRequest(unauthorized): + if unauthorized.oneTimeAccounts?.numberOfAccounts.isValid == false { + return invalidRequest(.badContent(.numberOfAccountsInvalid)) + } + default: + break } - guard let origin = try? DappOrigin(string: nonvalidatedMeta.origin) else { - return invalidRequest(.invalidOrigin(invalidURLString: nonvalidatedMeta.origin)) - } - - let metadataValidDappDefAddress = P2P.Dapp.Request.Metadata( +// if case let .request(readRequest) = nonValidated.items { +// switch readRequest { +// case let .authorized(authorized): +// if authorized.oneTimeAccounts?.numberOfAccounts.isValid == false { +// return invalidRequest(.badContent(.numberOfAccountsInvalid)) +// } +// if authorized.ongoingAccounts?.numberOfAccounts.isValid == false { +// return invalidRequest(.badContent(.numberOfAccountsInvalid)) +// } +// case let .unauthorized(unauthorized): +// if unauthorized.oneTimeAccounts?.numberOfAccounts.isValid == false { +// return invalidRequest(.badContent(.numberOfAccountsInvalid)) +// } +// } +// } + + // guard let origin = try? DappOrigin(string: nonvalidatedMeta.origin.absoluteString) else { + // return invalidRequest(.invalidOrigin(invalidURLString: nonvalidatedMeta.origin.absoluteString)) +// } + + let metadataValidDappDefAddress = DappToWalletInteractionMetadata( version: nonvalidatedMeta.version, networkId: nonvalidatedMeta.networkId, - origin: origin, - dAppDefinitionAddress: dappDefinitionAddress + origin: nonvalidatedMeta.origin, + dappDefinitionAddress: dappDefinitionAddress ) let isDeveloperModeEnabled = await appPreferencesClient.isDeveloperModeEnabled() @@ -148,7 +164,7 @@ extension DappInteractionClient { .init( route: route, request: .valid(.init( - id: nonValidated.id, + interactionId: nonValidated.interactionId, items: nonValidated.items, metadata: metadataValidDappDefAddress )) diff --git a/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift b/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift index 81aecf37dd..cff21d0934 100644 --- a/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift +++ b/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift @@ -57,15 +57,15 @@ public struct SignTransactionWithLedgerRequest: Sendable, Hashable { public struct SignAuthChallengeWithLedgerRequest: Sendable, Hashable { public let signers: NonEmpty> public let ledger: LedgerHardwareWalletFactorSource - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - public let origin: P2P.Dapp.Request.Metadata.Origin + public let challenge: DappToWalletInteractionAuthChallengeNonce + public let origin: DappToWalletInteractionMetadata.Origin public let dAppDefinitionAddress: AccountAddress public init( ledger: LedgerHardwareWalletFactorSource, signers: NonEmpty>, - challenge: P2P.Dapp.Request.AuthChallengeNonce, - origin: P2P.Dapp.Request.Metadata.Origin, + challenge: DappToWalletInteractionAuthChallengeNonce, + origin: DappToWalletInteractionMetadata.Origin, dAppDefinitionAddress: AccountAddress ) { self.ledger = ledger diff --git a/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift b/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift index e2a13e63f8..41affef02b 100644 --- a/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift +++ b/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift @@ -13,8 +13,8 @@ public struct ROLAClient: Sendable, DependencyKey { // MARK: ROLAClient.PerformWellKnownFileCheck extension ROLAClient { - public typealias PerformDappDefinitionVerification = @Sendable (P2P.Dapp.Request.Metadata) async throws -> Void - public typealias PerformWellKnownFileCheck = @Sendable (P2P.Dapp.Request.Metadata) async throws -> Void + public typealias PerformDappDefinitionVerification = @Sendable (DappToWalletInteractionMetadata) async throws -> Void + public typealias PerformWellKnownFileCheck = @Sendable (DappToWalletInteractionMetadata) async throws -> Void public typealias ManifestForAuthKeyCreation = @Sendable (ManifestForAuthKeyCreationRequest) async throws -> TransactionManifest public typealias AuthenticationDataToSignForChallenge = @Sendable (AuthenticationDataToSignForChallengeRequest) throws -> AuthenticationDataToSignForChallengeResponse } @@ -28,13 +28,13 @@ extension DependencyValues { // MARK: - AuthenticationDataToSignForChallengeRequest public struct AuthenticationDataToSignForChallengeRequest: Sendable, Hashable { - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - public let origin: P2P.Dapp.Request.Metadata.Origin + public let challenge: DappToWalletInteractionAuthChallengeNonce + public let origin: DappToWalletInteractionMetadata.Origin public let dAppDefinitionAddress: DappDefinitionAddress public init( - challenge: P2P.Dapp.Request.AuthChallengeNonce, - origin: P2P.Dapp.Request.Metadata.Origin, + challenge: DappToWalletInteractionAuthChallengeNonce, + origin: DappToWalletInteractionMetadata.Origin, dAppDefinitionAddress: DappDefinitionAddress ) { self.challenge = challenge diff --git a/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift b/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift index 85950ca7e1..51c80b85a4 100644 --- a/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift +++ b/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift @@ -36,14 +36,14 @@ extension ROLAClient { return Self( performDappDefinitionVerification: { metadata async throws in _ = try await onLedgerEntitiesClient.getDappMetadata( - metadata.dAppDefinitionAddress, - validatingWebsite: metadata.origin.url + metadata.dappDefinitionAddress, + validatingWebsite: metadata.origin ) }, performWellKnownFileCheck: { metadata async throws in @Dependency(\.urlSession) var urlSession - let originURL = metadata.origin.url + let originURL = metadata.origin let url = originURL.appending(path: Constants.wellKnownFilePath) @@ -73,7 +73,7 @@ extension ROLAClient { let response = try await fetchWellKnownFile() let dAppDefinitionAddresses = response.dApps.map(\.dAppDefinitionAddress) - guard dAppDefinitionAddresses.contains(metadata.dAppDefinitionAddress) else { + guard dAppDefinitionAddresses.contains(metadata.dappDefinitionAddress) else { throw ROLAFailure.unknownDappDefinitionAddress } }, @@ -115,13 +115,13 @@ extension ROLAClient { extension ROLAClient { /// `0x52 || challenge(32) || L_dda(1) || dda_utf8(L_dda) || origin_utf8` static func payloadToHash( - challenge: P2P.Dapp.Request.AuthChallengeNonce, + challenge: DappToWalletInteractionAuthChallengeNonce, dAppDefinitionAddress accountAddress: AccountAddress, - origin metadataOrigin: P2P.Dapp.Request.Metadata.Origin + origin metadataOrigin: DappToWalletInteractionMetadata.Origin ) -> Data { let rPrefix: UInt8 = 0x52 let dAppDefinitionAddress = accountAddress.address - let origin = metadataOrigin.urlString.rawValue + let origin = metadataOrigin.absoluteString precondition(dAppDefinitionAddress.count <= UInt8.max) let challengeBytes = [UInt8](challenge.data.data) let lengthDappDefinitionAddress = UInt8(dAppDefinitionAddress.count) diff --git a/RadixWallet/Clients/ROLAClient/ROLAFailure.swift b/RadixWallet/Clients/ROLAClient/ROLAFailure.swift index f30e5c449c..38137265d1 100644 --- a/RadixWallet/Clients/ROLAClient/ROLAFailure.swift +++ b/RadixWallet/Clients/ROLAClient/ROLAFailure.swift @@ -1,3 +1,4 @@ +import Sargon public enum ROLAFailure: Sendable, LocalizedError, Equatable { case wrongAccountType @@ -21,7 +22,7 @@ public enum ROLAFailure: Sendable, LocalizedError, Equatable { } } - public var errorKindAndMessage: (errorKind: P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType, message: String?) { + public var errorKindAndMessage: (errorKind: DappWalletInteractionErrorType, message: String?) { switch self { case .wrongAccountType: (errorKind: .wrongAccountType, message: errorDescription) diff --git a/RadixWallet/Clients/RadixConnectClient/RadixConnectClient+Live.swift b/RadixWallet/Clients/RadixConnectClient/RadixConnectClient+Live.swift index 8384a672c4..98fbd8126c 100644 --- a/RadixWallet/Clients/RadixConnectClient/RadixConnectClient+Live.swift +++ b/RadixWallet/Clients/RadixConnectClient/RadixConnectClient+Live.swift @@ -43,8 +43,8 @@ extension RadixConnectClient { func sendAccountListMessage(accounts: Accounts) async throws { let encoder = jsonEncoder() let accounts = accounts.map { - P2P.Dapp.Response.WalletAccount( - accountAddress: $0.address, + WalletInteractionWalletAccount( + address: $0.address, label: $0.displayName, appearanceId: $0.appearanceID ) diff --git a/RadixWallet/Clients/TransactionClient/Models/TransactionFailure.swift b/RadixWallet/Clients/TransactionClient/Models/TransactionFailure.swift index 154bf0928e..2f8ac89b93 100644 --- a/RadixWallet/Clients/TransactionClient/Models/TransactionFailure.swift +++ b/RadixWallet/Clients/TransactionClient/Models/TransactionFailure.swift @@ -24,7 +24,7 @@ public enum TransactionFailure: Sendable, LocalizedError, Equatable { } extension TransactionFailure { - public var errorKindAndMessage: (errorKind: P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType, message: String?) { + public var errorKindAndMessage: (errorKind: DappWalletInteractionErrorType, message: String?) { switch self { case let .failedToPrepareForTXSigning(error), let .failedToPrepareTXReview(.failedSigning(error)): switch error { diff --git a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift index 5351f9f29b..ce719b0564 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift @@ -28,7 +28,7 @@ extension P2P { /// An incoming Dapp Request over RTC from some `route`, might have failed /// or succeeded to receive and decode, which is why this contains a /// `result` and not an `P2P.Dapp.Request` directly. - public typealias RTCIncomingDappNonValidatedRequest = RTCIncomingMessageContainer + public typealias RTCIncomingDappNonValidatedRequest = RTCIncomingMessageContainer /// An incoming message over RTC from some `route`, might have failed /// or succeeded to receive and decode, which is why this contains a diff --git a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift index 249ec7a69c..d4c3d89b89 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift @@ -15,7 +15,7 @@ extension P2P { } public enum Request: Sendable, Hashable, Equatable, Decodable { - case dapp(P2P.Dapp.RequestUnvalidated) + case dapp(DappToWalletInteractionUnvalidated) } } } diff --git a/RadixWallet/Core/SharedModels/P2P/Application/OutgoingMessage/P2P+RTCOutgoingMessage.swift b/RadixWallet/Core/SharedModels/P2P/Application/OutgoingMessage/P2P+RTCOutgoingMessage.swift index 7239b18fa7..1ba65f531b 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/OutgoingMessage/P2P+RTCOutgoingMessage.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/OutgoingMessage/P2P+RTCOutgoingMessage.swift @@ -16,7 +16,7 @@ extension P2P { /// we will use `origin` to identify the RTC channel to send over. public enum Response: Sendable, Hashable, Encodable { /// Response back to Dapps - case dapp(P2P.Dapp.Response) + case dapp(WalletToDappInteractionResponse) } /// A request initiated by us, sent over RTC using `SendStrategy`. diff --git a/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift b/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift index 8289b3da7e..b2c7a7d86b 100644 --- a/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift +++ b/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift @@ -93,15 +93,15 @@ extension P2P.ConnectorExtension.Request { public struct SignAuthChallenge: Sendable, Hashable, Encodable { public let signers: [P2P.LedgerHardwareWallet.KeyParameters] public let ledgerDevice: P2P.LedgerHardwareWallet.LedgerDevice - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - public let origin: P2P.Dapp.Request.Metadata.Origin + public let challenge: DappToWalletInteractionAuthChallengeNonce + public let origin: DappToWalletInteractionMetadata.Origin public let dAppDefinitionAddress: AccountAddress public init( signers: [P2P.LedgerHardwareWallet.KeyParameters], ledgerDevice: P2P.LedgerHardwareWallet.LedgerDevice, - challenge: P2P.Dapp.Request.AuthChallengeNonce, - origin: P2P.Dapp.Request.Metadata.Origin, + challenge: DappToWalletInteractionAuthChallengeNonce, + origin: DappToWalletInteractionMetadata.Origin, dAppDefinitionAddress: AccountAddress ) { self.signers = signers @@ -163,6 +163,6 @@ extension P2P.ConnectorExtension.Request { } public let discriminator: Discriminator - public let accounts: [P2P.Dapp.Response.WalletAccount] + public let accounts: [WalletInteractionWalletAccount] } } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift index eeca320300..ef6c0d6a51 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift @@ -1,4 +1,4 @@ -extension P2P.Dapp.Request { - public typealias NumberOfAccounts = RequestedQuantity -} +// extension P2P.Dapp.Request { +public typealias NumberOfAccounts = RequestedQuantity +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift index de00000ac0..3accb79cc6 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift @@ -1,15 +1,14 @@ - -extension P2P.Dapp.Request { - public struct AccountsRequestItem: Sendable, Hashable, Decodable { - public let numberOfAccounts: NumberOfAccounts - public let challenge: P2P.Dapp.Request.AuthChallengeNonce? - - public init( - numberOfAccounts: NumberOfAccounts, - challenge: P2P.Dapp.Request.AuthChallengeNonce? - ) { - self.numberOfAccounts = numberOfAccounts - self.challenge = challenge - } - } -} +// extension P2P.Dapp.Request { +// public struct AccountsRequestItem: Sendable, Hashable, Decodable { +// public let numberOfAccounts: NumberOfAccounts +// public let challenge: DappToWalletInteraction.AuthChallengeNonce? +// +// public init( +// numberOfAccounts: NumberOfAccounts, +// challenge: DappToWalletInteraction.AuthChallengeNonce? +// ) { +// self.numberOfAccounts = numberOfAccounts +// self.challenge = challenge +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift index 8cf83f640c..aab08d4292 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift @@ -1,61 +1,61 @@ // MARK: - P2P.Dapp.Request.AuthRequestItem -extension P2P.Dapp.Request { - public enum AuthRequestItem: Sendable, Hashable, Decodable { - private enum CodingKeys: String, CodingKey { - case discriminator - } - - enum Discriminator: String, Decodable { - case loginWithoutChallenge - case loginWithChallenge - case usePersona - } - - case login(AuthLoginRequestItem) - case usePersona(AuthUsePersonaRequestItem) - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) - switch discriminator { - case .loginWithoutChallenge: - self = .login(.withoutChallenge) - case .loginWithChallenge: - self = try .login(.withChallenge(.init(from: decoder))) - case .usePersona: - self = try .usePersona(.init(from: decoder)) - } - } - } -} +// extension P2P.Dapp.Request { +// public enum AuthRequestItem: Sendable, Hashable, Decodable { +// private enum CodingKeys: String, CodingKey { +// case discriminator +// } +// +// enum Discriminator: String, Decodable { +// case loginWithoutChallenge +// case loginWithChallenge +// case usePersona +// } +// +// case login(AuthLoginRequestItem) +// case usePersona(AuthUsePersonaRequestItem) +// +// public init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) +// switch discriminator { +// case .loginWithoutChallenge: +// self = .login(.withoutChallenge) +// case .loginWithChallenge: +// self = try .login(.withChallenge(.init(from: decoder))) +// case .usePersona: +// self = try .usePersona(.init(from: decoder)) +// } +// } +// } +// } // MARK: - P2P.Dapp.Request.AuthLoginRequestItem -extension P2P.Dapp.Request { - public enum AuthLoginRequestItem: Sendable, Hashable { - case withoutChallenge - case withChallenge(AuthLoginWithChallengeRequestItem) - } -} +// extension P2P.Dapp.Request { +// public enum AuthLoginRequestItem: Sendable, Hashable { +// case withoutChallenge +// case withChallenge(AuthLoginWithChallengeRequestItem) +// } +// } // MARK: - P2P.Dapp.Request.AuthLoginWithChallengeRequestItem -extension P2P.Dapp.Request { - public struct AuthLoginWithChallengeRequestItem: Sendable, Hashable, Decodable { - /// A 32 bytes nonce used as a challenge - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - - public init(challenge: P2P.Dapp.Request.AuthChallengeNonce) { - self.challenge = challenge - } - } -} +// extension P2P.Dapp.Request { +// public struct AuthLoginWithChallengeRequestItem: Sendable, Hashable, Decodable { +// /// A 32 bytes nonce used as a challenge +// public let challenge: DappToWalletInteraction.AuthChallengeNonce +// +// public init(challenge: DappToWalletInteraction.AuthChallengeNonce) { +// self.challenge = challenge +// } +// } +// } // MARK: - P2P.Dapp.Request.AuthUsePersonaRequestItem -extension P2P.Dapp.Request { - public struct AuthUsePersonaRequestItem: Sendable, Hashable, Decodable { - public let identityAddress: IdentityAddress - - public init(identityAddress: IdentityAddress) { - self.identityAddress = identityAddress - } - } -} +// extension P2P.Dapp.Request { +// public struct AuthUsePersonaRequestItem: Sendable, Hashable, Decodable { +// public let identityAddress: IdentityAddress +// +// public init(identityAddress: IdentityAddress) { +// self.identityAddress = identityAddress +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift index d7bba6264c..375dc0d3ff 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift @@ -1,64 +1,51 @@ import Sargon -// MARK: - P2P.Dapp.Request.PersonaDataRequestItem -extension P2P.Dapp.Request { - public struct PersonaDataRequestItem: Sendable, Hashable, Decodable { - public let isRequestingName: Bool? - public let numberOfRequestedEmailAddresses: RequestedQuantity? - public let numberOfRequestedPhoneNumbers: RequestedQuantity? +// MARK: - DappToWalletInteraction.RequestValidation +// DappToWalletInteractionPersonaDataRequestItem - public init( - isRequestingName: Bool?, - numberOfRequestedEmailAddresses: RequestedQuantity? = nil, - numberOfRequestedPhoneNumbers: RequestedQuantity? = nil - ) { - self.isRequestingName = isRequestingName - self.numberOfRequestedEmailAddresses = numberOfRequestedEmailAddresses - self.numberOfRequestedPhoneNumbers = numberOfRequestedPhoneNumbers - } - - public var kindRequests: [PersonaData.Entry.Kind: KindRequest] { - var result: [PersonaData.Entry.Kind: KindRequest] = [:] - if isRequestingName == true { - result[.fullName] = .entry - } - if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { - result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) - } - if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { - result[.emailAddress] = .number(numberOfRequestedEmailAddresses) - } - return result - } - } -} - -extension P2P.Dapp.Request { - public typealias Response = P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem - - public enum MissingEntry: Sendable, Hashable { - case missingEntry - case missing(Int) - } - - public enum KindRequest: Sendable, Hashable { - case entry - case number(RequestedQuantity) - } -} +// extension P2P.Dapp.Request { +// public struct PersonaDataRequestItem: Sendable, Hashable, Decodable { +// public let isRequestingName: Bool? +// public let numberOfRequestedEmailAddresses: RequestedQuantity? +// public let numberOfRequestedPhoneNumbers: RequestedQuantity? +// +// public init( +// isRequestingName: Bool?, +// numberOfRequestedEmailAddresses: RequestedQuantity? = nil, +// numberOfRequestedPhoneNumbers: RequestedQuantity? = nil +// ) { +// self.isRequestingName = isRequestingName +// self.numberOfRequestedEmailAddresses = numberOfRequestedEmailAddresses +// self.numberOfRequestedPhoneNumbers = numberOfRequestedPhoneNumbers +// } +// +// public var kindRequests: [PersonaData.Entry.Kind: KindRequest] { +// var result: [PersonaData.Entry.Kind: KindRequest] = [:] +// if isRequestingName == true { +// result[.fullName] = .entry +// } +// if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { +// result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) +// } +// if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { +// result[.emailAddress] = .number(numberOfRequestedEmailAddresses) +// } +// return result +// } +// } +// } -// MARK: - P2P.Dapp.Request.RequestValidation -extension P2P.Dapp.Request { +extension DappToWalletInteraction { public struct RequestValidation: Sendable, Hashable { public var missingEntries: [PersonaData.Entry.Kind: MissingEntry] = [:] public var existingRequestedEntries: [PersonaData.Entry.Kind: [PersonaData.Entry]] = [:] - public var response: P2P.Dapp.Request.Response? { + public var response: WalletToDappInteractionPersonaDataRequestResponseItem? { guard missingEntries.isEmpty else { return nil } return try? .init( name: existingRequestedEntries.extract(.fullName), - emailAddresses: existingRequestedEntries.extract(.emailAddress), - phoneNumbers: existingRequestedEntries.extract(.phoneNumber) + emailAddresses: existingRequestedEntries.extract(.emailAddress)?.elements, + phoneNumbers: existingRequestedEntries.extract(.phoneNumber)?.elements ) } } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift index 3ee55e0bc4..a05f71ccbe 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift @@ -1,16 +1,16 @@ // MARK: - P2P.Dapp.Request.ResetRequestItem -extension P2P.Dapp.Request { - public struct ResetRequestItem: Sendable, Hashable, Decodable { - public let accounts: Bool - public let personaData: Bool - - public init( - accounts: Bool, - personaData: Bool - ) { - self.accounts = accounts - self.personaData = personaData - } - } -} +// extension P2P.Dapp.Request { +// public struct ResetRequestItem: Sendable, Hashable, Decodable { +// public let accounts: Bool +// public let personaData: Bool +// +// public init( +// accounts: Bool, +// personaData: Bool +// ) { +// self.accounts = accounts +// self.personaData = personaData +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift index f56eb80f31..c2f5a7c5da 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift @@ -1,85 +1,81 @@ // MARK: - UnvalidatedTransactionManifest -public struct UnvalidatedTransactionManifest: Sendable, Hashable { - public let transactionManifestString: String - public let blobs: Blobs - - public init(transactionManifestString: String, blobsBytes: [Data]) { - self.transactionManifestString = transactionManifestString - self.blobs = Blobs(blobsBytes.map(Blob.init(data:))) - } - - public init(manifest: TransactionManifest) { - self.transactionManifestString = manifest.instructionsString - self.blobs = manifest.blobs - } - - public func transactionManifest( - onNetwork networkID: NetworkID - ) throws -> TransactionManifest { - try .init( - instructionsString: transactionManifestString, - networkID: networkID, - blobs: blobs - ) - } -} +// public struct UnvalidatedTransactionManifest: Sendable, Hashable { +// public let transactionManifestString: String +// public let blobs: Blobs +// +// public init(transactionManifestString: String, blobsBytes: [Data]) { +// self.transactionManifestString = transactionManifestString +// self.blobs = Blobs(blobsBytes.map(Blob.init(data:))) +// } +// +// public init(manifest: TransactionManifest) { +// self.transactionManifestString = manifest.instructionsString +// self.blobs = manifest.blobs +// } +// +// public func transactionManifest( +// onNetwork networkID: NetworkID +// ) throws -> TransactionManifest { +// try .init( +// instructionsString: transactionManifestString, +// networkID: networkID, +// blobs: blobs +// ) +// } +// } // MARK: - P2P.Dapp.Request.SendTransactionItem -extension P2P.Dapp.Request { - public struct SendTransactionItem: Sendable, Hashable, Decodable { - public let unvalidatedManifest: UnvalidatedTransactionManifest - public let version: TXVersion - public let message: String? - - public init( - version: TXVersion, - unvalidatedManifest: UnvalidatedTransactionManifest, - message: String? - ) { - self.version = version - self.unvalidatedManifest = unvalidatedManifest - self.message = message - } - - public init( - version: TXVersion = .default, - transactionManifest: TransactionManifest, - message: String? = nil - ) { - self.init( - version: version, - unvalidatedManifest: .init(manifest: transactionManifest), - message: message - ) - } - - private enum CodingKeys: String, CodingKey { - case transactionManifestString = "transactionManifest" - case version - case blobsHex = "blobs" - case message - } - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - - let manifestString = try container.decode(String.self, forKey: .transactionManifestString) - let blobsHex = try container.decodeIfPresent([String].self, forKey: .blobsHex) ?? [] - let blobsBytes = try blobsHex.map { try Data(hex: $0) } - - try self.init( - version: container.decode(TXVersion.self, forKey: .version), - unvalidatedManifest: .init(transactionManifestString: manifestString, blobsBytes: blobsBytes), - message: container.decodeIfPresent(String.self, forKey: .message) - ) - } - } -} +// extension P2P.Dapp.Request { +// public struct SendTransactionItem: Sendable, Hashable, Decodable { +// public let unvalidatedManifest: UnvalidatedTransactionManifest +// public let version: TXVersion +// public let message: String? +// +// public init( +// version: TXVersion, +// unvalidatedManifest: UnvalidatedTransactionManifest, +// message: String? +// ) { +// self.version = version +// self.unvalidatedManifest = unvalidatedManifest +// self.message = message +// } +// +// public init( +// version: TXVersion = .default, +// transactionManifest: TransactionManifest, +// message: String? = nil +// ) { +// self.init( +// version: version, +// unvalidatedManifest: .init(manifest: transactionManifest), +// message: message +// ) +// } +// +// private enum CodingKeys: String, CodingKey { +// case transactionManifestString = "transactionManifest" +// case version +// case blobsHex = "blobs" +// case message +// } +// +// public init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// +// let manifestString = try container.decode(String.self, forKey: .transactionManifestString) +// let blobsHex = try container.decodeIfPresent([String].self, forKey: .blobsHex) ?? [] +// let blobsBytes = try blobsHex.map { try Data(hex: $0) } +// +// try self.init( +// version: container.decode(TXVersion.self, forKey: .version), +// unvalidatedManifest: .init(transactionManifestString: manifestString, blobsBytes: blobsBytes), +// message: container.decodeIfPresent(String.self, forKey: .message) +// ) +// } +// } +// } // MARK: - TXVersionTag -public enum TXVersionTag: Sendable {} -public typealias TXVersion = Tagged - -extension TXVersion { - public static let `default`: Self = 1 -} +// public enum TXVersionTag: Sendable {} +// public typealias TXVersion = Tagged diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift index 8f41776c79..2caf17c74b 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift @@ -1,38 +1,12 @@ - -#if DEBUG - -extension TransactionManifest { - public static let previewValue = try! TransactionManifest( - instructionsString: complexManifestString, - networkID: NetworkID.mainnet, - blobs: [] - ) -} - -private let complexManifestString = """ -# Withdraw XRD from account - CALL_METHOD - Address("account_rdx12xx2rxz5wtr98x6vxsulvqukawa2xt6te5ahmr50xavll3my4nzxdm") - "lock_fee" - Decimal("10"); -""" - -extension P2P.Dapp.Request.AccountsRequestItem { - public static let previewValue = Self( - numberOfAccounts: .exactly(1), - challenge: nil - ) -} - -extension P2P.Dapp.Request.PersonaDataRequestItem { - public static let previewValue = Self(isRequestingName: true) -} - -extension P2P.Dapp.Request.SendTransactionItem { - public static let previewValue = try! Self(transactionManifest: .previewValue) -} - -extension P2P.Dapp.Request.ID { +// extension DappToWalletInteractionPersonaDataRequestItem { +// public static let previewValue = .sample +// } + +// extension P2P.Dapp.Request.SendTransactionItem { +// public static let previewValue = try! Self(transactionManifest: .previewValue) +// } +// +extension WalletInteractionId { public static let previewValue = Self.previewValue0 public static let previewValue0: Self = "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" public static let previewValue1: Self = "D621E1F8-C36C-495A-93FC-0C247A3E6E5F" @@ -41,71 +15,48 @@ extension P2P.Dapp.Request.ID { public static let previewValue4: Self = "A621E1F8-C36C-495A-93FC-0C247A3E6E5F" } -extension P2P.Dapp.Request.Metadata { - public static let previewValue = try! Self( - version: P2P.Dapp.currentVersion, - networkId: .simulator, - origin: .init(string: "foo.bar"), - dAppDefinitionAddress: .init(validatingAddress: "account_tdx_b_1p8ahenyznrqy2w0tyg00r82rwuxys6z8kmrhh37c7maqpydx7p") - ) -} - -extension P2P.Dapp.Request { - public static func previewValueAllRequests( - auth: P2P.Dapp.Request.AuthRequestItem = .login(.withoutChallenge) - ) -> Self { +// +// extension DappToWalletInteractionMetadata { +// public static let previewValue = try! Self( +// version: P2P.Dapp.currentVersion, +// networkId: .simulator, +// origin: .init(string: "foo.bar"), +// dAppDefinitionAddress: .init(validatingAddress: "account_tdx_b_1p8ahenyznrqy2w0tyg00r82rwuxys6z8kmrhh37c7maqpydx7p") +// ) +// } +// +extension DappToWalletInteraction { + public static func previewValueAllRequests() -> Self { .init( - id: .previewValue0, - items: .request(.authorized(.init( - auth: auth, + interactionId: .previewValue0, + items: .authorizedRequest(.init( + auth: .loginWithChallenge(.init(challenge: .sample)), reset: nil, - ongoingAccounts: .previewValue, - ongoingPersonaData: .previewValue, - oneTimeAccounts: .previewValue, - oneTimePersonaData: .previewValue - ))), - metadata: .previewValue - ) - } - - public static let previewValueOneTimeAccount = Self.previewValueOneTimeAccount() - - public static func previewValueOneTimeAccount( - id: ID = .previewValue0 - ) -> Self { - .init( - id: id, - items: .request( - .unauthorized(.init( - oneTimeAccounts: .previewValue, - oneTimePersonaData: .previewValue - )) - ), - metadata: .previewValue - ) - } - - public static let previewValueSignTX = Self.previewValueSignTX() - - public static func previewValueSignTX( - id: ID = .previewValue0 - ) -> Self { - .init( - id: id, - items: .transaction(.init( - send: .previewValue + ongoingAccounts: nil, + ongoingPersonaData: nil, + oneTimeAccounts: nil, + oneTimePersonaData: nil )), - metadata: .previewValue + metadata: .init(version: .default, networkId: .sample, origin: .wallet, dappDefinitionAddress: .sample) ) } - - public static let previewValueNoRequestItems = Self( - id: .previewValue, - items: .request(.unauthorized(.init( - oneTimeAccounts: nil, - oneTimePersonaData: nil - ))), - metadata: .previewValue - ) +// +// public static let previewValueOneTimeAccount = Self.previewValueOneTimeAccount() +// +// public static func previewValueOneTimeAccount( +// id: ID = .previewValue0 +// ) -> Self { +// .init( +// id: id, +// items: .request( +// .unauthorized(.init( +// oneTimeAccounts: .previewValue, +// oneTimePersonaData: .previewValue +// )) +// ), +// metadata: .previewValue +// ) +// } } -#endif // DEBUG + +// #endif // DEBUG diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift index f0e086d079..38433c4bb9 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift @@ -1,96 +1,95 @@ // MARK: - P2P.Dapp.Request extension P2P.Dapp { - public typealias Version = Tagged +// public typealias Version = Tagged /// Temporarily disables Dapp communication. /// Should be reverted as soon as we implement [ABW-1872](https://radixdlt.atlassian.net/browse/ABW-1872) - public static let currentVersion: Version = 2 + public static let currentVersion: WalletInteractionVersion = 2 - public struct Request: Sendable, Hashable, Identifiable { - public typealias ID = RequestUnvalidated.ID +// public struct Request: Sendable, Hashable, Identifiable { + //// public typealias ID = Tagged +// + //// public let id: ID +// public let items: DappToWalletInteractionItems +// public let metadata: DappToWalletInteractionMetadata +// +// public init(items: DappToWalletInteractionItems, metadata: DappToWalletInteractionMetadata) { +// self.items = items +// self.metadata = metadata +// } +// } - public let id: ID - public let items: Items - public let metadata: Metadata - - public init(id: ID, items: Items, metadata: Metadata) { - self.id = id - self.items = items - self.metadata = metadata - } - } - - public struct RequestUnvalidated: Sendable, Hashable, Decodable, Identifiable { - private enum CodingKeys: String, CodingKey { - case id = "interactionId" - case items - case metadata - } - - public typealias ID = Tagged - - public let id: ID - public let items: P2P.Dapp.Request.Items - public let metadata: P2P.Dapp.Request.MetadataUnvalidated - - public init( - id: ID, - items: P2P.Dapp.Request.Items, - metadata: P2P.Dapp.Request.MetadataUnvalidated - ) { - self.id = id - self.items = items - self.metadata = metadata - } - } +// public struct RequestUnvalidated: Sendable, Hashable, Decodable, Identifiable { +// private enum CodingKeys: String, CodingKey { +// case id = "interactionId" +// case items +// case metadata +// } +// +// public typealias ID = Tagged +// +// public let id: ID +// public let items: P2P.Dapp.Request.Items +// public let metadata: P2P.Dapp.Request.MetadataUnvalidated +// +// public init( +// id: ID, +// items: P2P.Dapp.Request.Items, +// metadata: P2P.Dapp.Request.MetadataUnvalidated +// ) { +// self.id = id +// self.items = items +// self.metadata = metadata +// } +// } } -// MARK: - P2P.Dapp.Request.Metadata -extension P2P.Dapp.Request { - /// The metadata sent with the request from the Dapp. - /// not to be confused with `DappMetadata` which can hold a value of this type - public struct Metadata: Sendable, Hashable, Decodable { - public typealias Origin = DappOrigin - - public let version: P2P.Dapp.Version - public let networkId: NetworkID - public let origin: Origin - public let dAppDefinitionAddress: DappDefinitionAddress - - public init( - version: P2P.Dapp.Version, - networkId: NetworkID, - origin: Origin, - dAppDefinitionAddress: DappDefinitionAddress - ) { - self.version = version - self.networkId = networkId - self.origin = origin - self.dAppDefinitionAddress = dAppDefinitionAddress - } - } -} +// MARK: - DappToWalletInteractionMetadata +// extension P2P.Dapp.Request { +// /// The metadata sent with the request from the Dapp. +// /// not to be confused with `DappMetadata` which can hold a value of this type +// public struct Metadata: Sendable, Hashable, Decodable { +// public typealias Origin = DappOrigin +// +// public let version: P2P.Dapp.Version +// public let networkId: NetworkID +// public let origin: Origin +// public let dAppDefinitionAddress: DappDefinitionAddress +// +// public init( +// version: P2P.Dapp.Version, +// networkId: NetworkID, +// origin: Origin, +// dAppDefinitionAddress: DappDefinitionAddress +// ) { +// self.version = version +// self.networkId = networkId +// self.origin = origin +// self.dAppDefinitionAddress = dAppDefinitionAddress +// } +// } +// } // MARK: - P2P.Dapp.Request.MetadataUnvalidated -extension P2P.Dapp.Request { - public struct MetadataUnvalidated: Sendable, Hashable, Decodable { - public let version: P2P.Dapp.Version - public let networkId: NetworkID - public let origin: String - - /// Non yet validated dAppDefinitionAddresss - public let dAppDefinitionAddress: String - - public init( - version: P2P.Dapp.Version, - networkId: NetworkID, - origin: String, - dAppDefinitionAddress: String - ) { - self.version = version - self.networkId = networkId - self.origin = origin - self.dAppDefinitionAddress = dAppDefinitionAddress - } - } -} +// extension P2P.Dapp.Request { +// public struct MetadataUnvalidated: Sendable, Hashable, Decodable { +// public let version: P2P.Dapp.Version +// public let networkId: NetworkID +// public let origin: String +// +// /// Non yet validated dAppDefinitionAddresss +// public let dAppDefinitionAddress: String +// +// public init( +// version: P2P.Dapp.Version, +// networkId: NetworkID, +// origin: String, +// dAppDefinitionAddress: String +// ) { +// self.version = version +// self.networkId = networkId +// self.origin = origin +// self.dAppDefinitionAddress = dAppDefinitionAddress +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift index 966fcf1a0d..1e160973d0 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift @@ -1,86 +1,86 @@ // MARK: - P2P.Dapp.Request.Items -extension P2P.Dapp.Request { - public enum Items: Sendable, Hashable, Decodable { - private enum CodingKeys: String, CodingKey { - case discriminator - } +// extension P2P.Dapp.Request { +// public enum Items: Sendable, Hashable, Decodable { +// private enum CodingKeys: String, CodingKey { +// case discriminator +// } +// +// enum Discriminator: String, Decodable { +// case unauthorizedRequest +// case authorizedRequest +// case transaction +// } +// +// case request(RequestItems) +// case transaction(TransactionItems) +// +// public init(from decoder: Decoder) throws { +// let container = try decoder.container(keyedBy: CodingKeys.self) +// let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) +// switch discriminator { +// case .unauthorizedRequest: +// self = try .request(.unauthorized(.init(from: decoder))) +// case .authorizedRequest: +// self = try .request(.authorized(.init(from: decoder))) +// case .transaction: +// self = try .transaction(.init(from: decoder)) +// } +// } +// } +// } - enum Discriminator: String, Decodable { - case unauthorizedRequest - case authorizedRequest - case transaction - } - - case request(RequestItems) - case transaction(TransactionItems) - - public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: CodingKeys.self) - let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) - switch discriminator { - case .unauthorizedRequest: - self = try .request(.unauthorized(.init(from: decoder))) - case .authorizedRequest: - self = try .request(.authorized(.init(from: decoder))) - case .transaction: - self = try .transaction(.init(from: decoder)) - } - } - } -} - -extension P2P.Dapp.Request { - public enum RequestItems: Sendable, Hashable { - case unauthorized(UnauthorizedRequestItems) - case authorized(AuthorizedRequestItems) - } - - public struct UnauthorizedRequestItems: Sendable, Hashable, Decodable { - public let oneTimeAccounts: AccountsRequestItem? - public let oneTimePersonaData: PersonaDataRequestItem? - - public init( - oneTimeAccounts: AccountsRequestItem?, - oneTimePersonaData: PersonaDataRequestItem? - ) { - self.oneTimeAccounts = oneTimeAccounts - self.oneTimePersonaData = oneTimePersonaData - } - } - - public struct AuthorizedRequestItems: Sendable, Hashable, Decodable { - public let auth: AuthRequestItem - public let reset: ResetRequestItem? - public let ongoingAccounts: AccountsRequestItem? - public let ongoingPersonaData: PersonaDataRequestItem? - public let oneTimeAccounts: AccountsRequestItem? - public let oneTimePersonaData: PersonaDataRequestItem? - - public init( - auth: AuthRequestItem, - reset: ResetRequestItem? = nil, - ongoingAccounts: AccountsRequestItem? = nil, - ongoingPersonaData: PersonaDataRequestItem? = nil, - oneTimeAccounts: AccountsRequestItem? = nil, - oneTimePersonaData: PersonaDataRequestItem? = nil - ) { - self.auth = auth - self.reset = reset - self.ongoingAccounts = ongoingAccounts - self.ongoingPersonaData = ongoingPersonaData - self.oneTimeAccounts = oneTimeAccounts - self.oneTimePersonaData = oneTimePersonaData - } - } -} +// extension P2P.Dapp.Request { +// public enum RequestItems: Sendable, Hashable { +// case unauthorized(UnauthorizedRequestItems) +// case authorized(AuthorizedRequestItems) +// } +// +// public struct UnauthorizedRequestItems: Sendable, Hashable, Decodable { +// public let oneTimeAccounts: AccountsRequestItem? +// public let oneTimePersonaData: PersonaDataRequestItem? +// +// public init( +// oneTimeAccounts: AccountsRequestItem?, +// oneTimePersonaData: PersonaDataRequestItem? +// ) { +// self.oneTimeAccounts = oneTimeAccounts +// self.oneTimePersonaData = oneTimePersonaData +// } +// } +// +// public struct AuthorizedRequestItems: Sendable, Hashable, Decodable { +// public let auth: AuthRequestItem +// public let reset: ResetRequestItem? +// public let ongoingAccounts: AccountsRequestItem? +// public let ongoingPersonaData: PersonaDataRequestItem? +// public let oneTimeAccounts: AccountsRequestItem? +// public let oneTimePersonaData: PersonaDataRequestItem? +// +// public init( +// auth: AuthRequestItem, +// reset: ResetRequestItem? = nil, +// ongoingAccounts: AccountsRequestItem? = nil, +// ongoingPersonaData: PersonaDataRequestItem? = nil, +// oneTimeAccounts: AccountsRequestItem? = nil, +// oneTimePersonaData: PersonaDataRequestItem? = nil +// ) { +// self.auth = auth +// self.reset = reset +// self.ongoingAccounts = ongoingAccounts +// self.ongoingPersonaData = ongoingPersonaData +// self.oneTimeAccounts = oneTimeAccounts +// self.oneTimePersonaData = oneTimePersonaData +// } +// } +// } // MARK: - P2P.Dapp.Request.TransactionItems -extension P2P.Dapp.Request { - public struct TransactionItems: Sendable, Hashable, Decodable { - public let send: SendTransactionItem - - public init(send: SendTransactionItem) { - self.send = send - } - } -} +// extension P2P.Dapp.Request { +// public struct TransactionItems: Sendable, Hashable, Decodable { +// public let send: SendTransactionItem +// +// public init(send: SendTransactionItem) { +// self.send = send +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift index 0bea3c271d..cbc34cdb62 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift @@ -1,17 +1,15 @@ -import Sargon - -extension P2P.Dapp.Response { - public struct PersonaResponse: Sendable, Hashable, Encodable { - public let identityAddress: IdentityAddress - public let label: String - - public init(identityAddress: IdentityAddress, label: String) { - self.identityAddress = identityAddress - self.label = label - } - - public init(persona: Persona) { - self.init(identityAddress: persona.address, label: persona.displayName.rawValue) - } - } -} +// extension P2P.Dapp.Response { +// public struct PersonaResponse: Sendable, Hashable, Encodable { +// public let identityAddress: IdentityAddress +// public let label: String +// +// public init(identityAddress: IdentityAddress, label: String) { +// self.identityAddress = identityAddress +// self.label = label +// } +// +// public init(persona: Persona) { +// self.init(identityAddress: persona.address, label: persona.displayName.rawValue) +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift index 7248086be2..6db5c05482 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift @@ -1,45 +1,35 @@ // MARK: - P2P.Dapp.Response.WalletAccount -extension P2P.Dapp.Response { - /// Response to Dapp from wallet, info about a users account. - /// - /// Called `AccountAddress` in [CAP21][cap] - /// - /// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages - /// - public struct WalletAccount: Sendable, Hashable, Encodable { - public let address: AccountAddress - public let label: DisplayName - public let appearanceId: AppearanceID +// extension P2P.Dapp.Response { +/// Response to Dapp from wallet, info about a users account. +/// +/// Called `AccountAddress` in [CAP21][cap] +/// +/// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages +/// +// public struct WalletAccount: Sendable, Hashable, Encodable { +// public let address: AccountAddress +// public let label: DisplayName +// public let appearanceId: AppearanceID +// +// public init( +// accountAddress: AccountAddress, +// label: DisplayName, +// appearanceId: AppearanceID +// ) { +// self.address = accountAddress +// self.label = label +// self.appearanceId = appearanceId +// } +// } - public init( - accountAddress: AccountAddress, - label: DisplayName, - appearanceId: AppearanceID - ) { - self.address = accountAddress - self.label = label - self.appearanceId = appearanceId - } - } - - public struct AccountProof: Sendable, Hashable, Encodable { - public let accountAddress: AccountAddress - public let proof: P2P.Dapp.Response.AuthProof - - init(accountWithProof: P2P.Dapp.Response.Accounts.WithProof) { - self.accountAddress = accountWithProof.account.address - self.proof = accountWithProof.proof - } - } -} - -extension P2P.Dapp.Response.WalletAccount { - public init(account: Account) { - self.init( - accountAddress: account.address, - label: account.displayName, - appearanceId: account.appearanceID - ) - } -} +// public struct AccountProof: Sendable, Hashable, Encodable { +// public let accountAddress: AccountAddress +// public let proof: P2P.Dapp.Response.AuthProof +// +// init(accountWithProof: P2P.Dapp.Response.Accounts.WithProof) { +// self.accountAddress = accountWithProof.account.address +// self.proof = accountWithProof.proof +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift index 6d689a791c..5829219eb8 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift @@ -6,112 +6,48 @@ extension P2P { // MARK: - SignedAuthChallenge public struct SignedAuthChallenge: Sendable, Hashable { - public let challenge: P2P.Dapp.Request.AuthChallengeNonce + public let challenge: DappToWalletInteractionAuthChallengeNonce public let entitySignatures: Set - public init(challenge: P2P.Dapp.Request.AuthChallengeNonce, entitySignatures: Set) { + public init(challenge: DappToWalletInteractionAuthChallengeNonce, entitySignatures: Set) { self.challenge = challenge self.entitySignatures = entitySignatures } } -// MARK: - P2P.Dapp.Request.AuthChallengeNonce -extension P2P.Dapp.Request { - /// A 32 bytes nonce used as a challenge - public typealias AuthChallengeNonce = Tagged<(Self, nonce: ()), Exactly32Bytes> -} - // MARK: - P2P.Dapp.Response -extension P2P.Dapp { - public enum Response: Sendable, Hashable, Encodable { - private enum CodingKeys: String, CodingKey { - case discriminator - } - - private enum Discriminator: String, Encodable { - case success - case failure - } - - case success(WalletInteractionSuccessResponse) - case failure(WalletInteractionFailureResponse) - - public var id: P2P.Dapp.Request.ID { - switch self { - case let .success(response): - response.interactionId - case let .failure(response): - response.interactionId - } - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - switch self { - case let .success(success): - try container.encode(Discriminator.success, forKey: .discriminator) - try success.encode(to: encoder) - case let .failure(failure): - try container.encode(Discriminator.failure, forKey: .discriminator) - try failure.encode(to: encoder) - } - } - } -} - -extension P2P.Dapp.Response { - public struct AuthProof: Sendable, Hashable, Codable { - public let publicKey: String - public let curve: SLIP10Curve - public let signature: String - - public init( - publicKey: String, - curve: SLIP10Curve, - signature: String - ) { - self.publicKey = publicKey - self.curve = curve - self.signature = signature - } - - public init(entitySignature: SignatureOfEntity) { - let sigPub = entitySignature.signatureWithPublicKey - let signature = sigPub.signature.data - self.init( - publicKey: sigPub.publicKey.hex, - curve: sigPub.publicKey.curve, - signature: signature.hex - ) - } - } - - public struct ChallengeWithProof: Sendable, Hashable { - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - public let proof: P2P.Dapp.Response.AuthProof - public init(challenge: P2P.Dapp.Request.AuthChallengeNonce, proof: P2P.Dapp.Response.AuthProof) { - self.challenge = challenge - self.proof = proof - } - } - - public enum Accounts: Sendable, Hashable { - case withoutProofOfOwnership(IdentifiedArrayOf) - case withProofOfOwnership(challenge: P2P.Dapp.Request.AuthChallengeNonce, IdentifiedArrayOf) - - public struct WithProof: Sendable, Hashable, Encodable, Identifiable { - public typealias ID = WalletAccount - public var id: ID { account } - public let account: WalletAccount - - public let proof: P2P.Dapp.Response.AuthProof - - public init( - account: WalletAccount, - proof: P2P.Dapp.Response.AuthProof - ) { - self.account = account - self.proof = proof - } - } - } -} +// extension P2P.Dapp { +// public enum Response: Sendable, Hashable, Encodable { +// private enum CodingKeys: String, CodingKey { +// case discriminator +// } +// +// private enum Discriminator: String, Encodable { +// case success +// case failure +// } +// +// case success(WalletInteractionSuccessResponse) +// case failure(WalletInteractionFailureResponse) +// +// public var id: P2P.Dapp.Request.ID { +// switch self { +// case let .success(response): +// response.interactionId +// case let .failure(response): +// response.interactionId +// } +// } +// +// public func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// switch self { +// case let .success(success): +// try container.encode(Discriminator.success, forKey: .discriminator) +// try success.encode(to: encoder) +// case let .failure(failure): +// try container.encode(Discriminator.failure, forKey: .discriminator) +// try failure.encode(to: encoder) +// } +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift index 2ffc1ce378..cdb134129a 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift @@ -1,36 +1,36 @@ -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public struct AccountsRequestResponseItem: Sendable, Hashable, Encodable { - public let accounts: [P2P.Dapp.Response.WalletAccount] - - public let challenge: P2P.Dapp.Request.AuthChallengeNonce? - public let proofs: [P2P.Dapp.Response.AccountProof]? - - public init( - accounts: P2P.Dapp.Response.Accounts - ) { - switch accounts { - case let .withProofOfOwnership(challenge, accountsWithProof): - self.accounts = accountsWithProof.map(\.account) - self.challenge = challenge - self.proofs = accountsWithProof.map(P2P.Dapp.Response.AccountProof.init(accountWithProof:)) - case let .withoutProofOfOwnership(account): - self.accounts = account.map(P2P.Dapp.Response.WalletAccount.init(account:)) - self.challenge = nil - self.proofs = nil - } - } - - /// for tests - private init(withoutProofOfOwnership accounts: [P2P.Dapp.Response.WalletAccount]) { - self.accounts = accounts - self.challenge = nil - self.proofs = nil - } - - /// for tests - static func withoutProofOfOwnership(accounts: [P2P.Dapp.Response.WalletAccount]) -> Self { - Self(withoutProofOfOwnership: accounts) - } - } -} +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public struct AccountsRequestResponseItem: Sendable, Hashable, Encodable { +// public let accounts: [P2P.Dapp.Response.WalletAccount] +// +// public let challenge: DappToWalletInteraction.AuthChallengeNonce? +// public let proofs: [P2P.Dapp.Response.AccountProof]? +// +// public init( +// accounts: P2P.Dapp.Response.Accounts +// ) { +// switch accounts { +// case let .withProofOfOwnership(challenge, accountsWithProof): +// self.accounts = accountsWithProof.map(\.account) +// self.challenge = challenge +// self.proofs = accountsWithProof.map(P2P.Dapp.Response.AccountProof.init(accountWithProof:)) +// case let .withoutProofOfOwnership(account): +// self.accounts = account.map(P2P.Dapp.Response.WalletAccount.init(account:)) +// self.challenge = nil +// self.proofs = nil +// } +// } +// +// /// for tests +// private init(withoutProofOfOwnership accounts: [P2P.Dapp.Response.WalletAccount]) { +// self.accounts = accounts +// self.challenge = nil +// self.proofs = nil +// } +// +// /// for tests +// static func withoutProofOfOwnership(accounts: [P2P.Dapp.Response.WalletAccount]) -> Self { +// Self(withoutProofOfOwnership: accounts) +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift index b31b8ba804..e82097ba87 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift @@ -1,71 +1,74 @@ // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AuthRequestResponseItem -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public enum AuthRequestResponseItem: Sendable, Hashable, Encodable { - case login(AuthLoginRequestResponseItem) - case usePersona(AuthUsePersonaRequestResponseItem) - public func encode(to encoder: Encoder) throws { - switch self { - case let .login(item): - try item.encode(to: encoder) - case let .usePersona(item): - try item.encode(to: encoder) - } - } - } -} +// DappToWalletInteractionAuthRequestItem -// MARK: - P2P.Dapp.Request.AuthLoginRequestItem -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public enum AuthLoginRequestResponseItem: Sendable, Hashable, Encodable { - case withoutChallenge(AuthLoginWithoutChallengeRequestResponseItem) - case withChallenge(AuthLoginWithChallengeRequestResponseItem) - - public func encode(to encoder: Encoder) throws { - switch self { - case let .withoutChallenge(item): - try item.encode(to: encoder) - case let .withChallenge(item): - try item.encode(to: encoder) - } - } - } - - public struct AuthLoginWithoutChallengeRequestResponseItem: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithoutChallenge.rawValue - public let persona: P2P.Dapp.Response.PersonaResponse +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public enum AuthRequestResponseItem: Sendable, Hashable, Encodable { +// case login(AuthLoginRequestResponseItem) +// case usePersona(AuthUsePersonaRequestResponseItem) +// +// public func encode(to encoder: Encoder) throws { +// switch self { +// case let .login(item): +// try item.encode(to: encoder) +// case let .usePersona(item): +// try item.encode(to: encoder) +// } +// } +// } +// } - public init(persona: P2P.Dapp.Response.PersonaResponse) { - self.persona = persona - } - } +// MARK: - P2P.Dapp.Request.AuthLoginRequestItem +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public enum AuthLoginRequestResponseItem: Sendable, Hashable, Encodable { +// case withoutChallenge(AuthLoginWithoutChallengeRequestResponseItem) +// case withChallenge(AuthLoginWithChallengeRequestResponseItem) +// +// public func encode(to encoder: Encoder) throws { +// switch self { +// case let .withoutChallenge(item): +// try item.encode(to: encoder) +// case let .withChallenge(item): +// try item.encode(to: encoder) +// } +// } +// } - public struct AuthLoginWithChallengeRequestResponseItem: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithChallenge.rawValue - public let persona: P2P.Dapp.Response.PersonaResponse - public let challenge: P2P.Dapp.Request.AuthChallengeNonce - public let proof: P2P.Dapp.Response.AuthProof +// public struct AuthLoginWithoutChallengeRequestResponseItem: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithoutChallenge.rawValue +// public let persona: P2P.Dapp.Response.PersonaResponse +// +// public init(persona: P2P.Dapp.Response.PersonaResponse) { +// self.persona = persona +// } +// } - public init( - persona: P2P.Dapp.Response.PersonaResponse, - challenge: P2P.Dapp.Request.AuthChallengeNonce, - proof: P2P.Dapp.Response.AuthProof - ) { - self.persona = persona - self.challenge = challenge - self.proof = proof - } - } -} +// public struct AuthLoginWithChallengeRequestResponseItem: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithChallenge.rawValue +// public let persona: P2P.Dapp.Response.PersonaResponse +// public let challenge: DappToWalletInteraction.AuthChallengeNonce +// public let proof: P2P.Dapp.Response.AuthProof +// +// public init( +// persona: P2P.Dapp.Response.PersonaResponse, +// challenge: DappToWalletInteraction.AuthChallengeNonce, +// proof: P2P.Dapp.Response.AuthProof +// ) { +// self.persona = persona +// self.challenge = challenge +// self.proof = proof +// } +// } +// } // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AuthUsePersonaRequestResponseItem -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public struct AuthUsePersonaRequestResponseItem: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.usePersona.rawValue - public let persona: P2P.Dapp.Response.PersonaResponse - - public init(persona: P2P.Dapp.Response.PersonaResponse) { - self.persona = persona - } - } -} +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public struct AuthUsePersonaRequestResponseItem: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.usePersona.rawValue +// public let persona: P2P.Dapp.Response.PersonaResponse +// +// public init(persona: P2P.Dapp.Response.PersonaResponse) { +// self.persona = persona +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift index b7e4e8d592..139c459c39 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift @@ -1,20 +1,21 @@ // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public struct PersonaDataRequestResponseItem: Sendable, Hashable, Encodable { - public let name: PersonaDataEntryName? - - public let emailAddresses: OrderedSet? - public let phoneNumbers: OrderedSet? - - public init( - name: PersonaDataEntryName? = nil, - emailAddresses: OrderedSet? = nil, - phoneNumbers: OrderedSet? = nil - ) { - self.name = name - self.emailAddresses = emailAddresses - self.phoneNumbers = phoneNumbers - } - } -} +// WalletToDappInteractionPersonaDataRequestResponseItem +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public struct PersonaDataRequestResponseItem: Sendable, Hashable, Encodable { +// public let name: PersonaDataEntryName? +// +// public let emailAddresses: OrderedSet? +// public let phoneNumbers: OrderedSet? +// +// public init( +// name: PersonaDataEntryName? = nil, +// emailAddresses: OrderedSet? = nil, +// phoneNumbers: OrderedSet? = nil +// ) { +// self.name = name +// self.emailAddresses = emailAddresses +// self.phoneNumbers = phoneNumbers +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift index 0c944283ab..807416b22e 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift @@ -1,28 +1,28 @@ -import Sargon - -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - /// Response to Dapp from wallet, info about a signed and submitted transaction, see [CAP21][cap]. - /// - /// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages - /// - public struct SendTransactionResponseItem: Sendable, Hashable, Encodable { - public let transactionIntentHash: IntentHash - - enum CodingKeys: CodingKey { - case transactionIntentHash - } - - public init(txID: IntentHash) { - transactionIntentHash = txID - } - - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode( - // Bech32m encoded transaction ID - transactionIntentHash.bech32EncodedTxId, - forKey: .transactionIntentHash - ) - } - } -} +// import Sargon +// +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// /// Response to Dapp from wallet, info about a signed and submitted transaction, see [CAP21][cap]. +// /// +// /// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages +// /// +// public struct SendTransactionResponseItem: Sendable, Hashable, Encodable { +// public let transactionIntentHash: IntentHash +// +// enum CodingKeys: CodingKey { +// case transactionIntentHash +// } +// +// public init(txID: IntentHash) { +// transactionIntentHash = txID +// } +// +// public func encode(to encoder: Encoder) throws { +// var container = encoder.container(keyedBy: CodingKeys.self) +// try container.encode( +// // Bech32m encoded transaction ID +// transactionIntentHash.bech32EncodedTxId, +// forKey: .transactionIntentHash +// ) +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift index a30955f5fb..8371b45727 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift @@ -1,101 +1,101 @@ // MARK: - P2P.Dapp.Response.WalletInteractionFailureResponse -extension P2P.Dapp.Response { - public struct WalletInteractionFailureResponse: Sendable, Hashable, Encodable { - private enum CodingKeys: String, CodingKey { - case interactionId - case errorType = "error" - case message - } - - /// *MUST* match an ID from an incoming request from Dapp. - public let interactionId: P2P.Dapp.Request.ID - public let errorType: ErrorType - public let message: String? - - public init( - interactionId: P2P.Dapp.Request.ID, - errorType: ErrorType, - message: String? - ) { - self.interactionId = interactionId - self.errorType = errorType - self.message = message - } - } -} +// extension P2P.Dapp.Response { +// public struct WalletInteractionFailureResponse: Sendable, Hashable, Encodable { +// private enum CodingKeys: String, CodingKey { +// case interactionId +// case errorType = "error" +// case message +// } +// +// /// *MUST* match an ID from an incoming request from Dapp. +// public let interactionId: P2P.Dapp.Request.ID +// public let errorType: ErrorType +// public let message: String? +// +// public init( +// interactionId: P2P.Dapp.Request.ID, +// errorType: ErrorType, +// message: String? +// ) { +// self.interactionId = interactionId +// self.errorType = errorType +// self.message = message +// } +// } +// } // MARK: - P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType -extension P2P.Dapp.Response.WalletInteractionFailureResponse { - // TODO: ask if we should do associated values here for `message` construction, - // in which case we'll need to declare discriminators - public enum ErrorType: String, Sendable, LocalizedError, Hashable, Encodable { - case rejectedByUser - case wrongNetwork - case failedToPrepareTransaction - case failedToCompileTransaction - case failedToSignTransaction - case failedToSubmitTransaction - case failedToPollSubmittedTransaction - case failedToFindAccountWithEnoughFundsToLockFee - case submittedTransactionWasDuplicate - case submittedTransactionHasFailedTransactionStatus - case submittedTransactionHasRejectedTransactionStatus - case wrongAccountType - case unknownWebsite - case invalidOriginURL - case radixJsonNotFound - case radixJsonUnknownFileFormat - case unknownDappDefinitionAddress - case invalidPersona - case invalidRequest - case incompatibleVersion - case failedToSignAuthChallenge - - public var errorDescription: String? { - switch self { - case .rejectedByUser: - "Rejected by user" - case .wrongNetwork: - "Wrong network" - case .failedToCompileTransaction: - "Failed to compile transaction" - case .failedToPrepareTransaction: - "Failed to prepare transaction for submission" - case .failedToSignTransaction: - "Failed to sign transaction" - case .failedToSubmitTransaction: - "Failed to submit transaction" - case .failedToPollSubmittedTransaction: - "Failed to poll submitted transaction" - case .failedToFindAccountWithEnoughFundsToLockFee: - "Failed to find an account with enough funds to lock fee" - case .submittedTransactionWasDuplicate: - "Submitted transaction was a duplicate" - case .submittedTransactionHasFailedTransactionStatus: - "Submitted transaction failed" - case .submittedTransactionHasRejectedTransactionStatus: - "Submitted transaction was rejected" - case .wrongAccountType: - "Expected to find dapp definition account type" - case .unknownWebsite: - "Origin does not match any related website" - case .invalidOriginURL: - "Invalid origin URL" - case .radixJsonNotFound: - "radix.json file is missing" - case .radixJsonUnknownFileFormat: - "radix.json file format mismatch " - case .unknownDappDefinitionAddress: - "dApp definition address does not match any well known definition address" - case .invalidPersona: - "Invalid persona specified by dApp" - case .invalidRequest: - "Invalid request" - case .failedToSignAuthChallenge: - "Failed to sign auth challenge" - case .incompatibleVersion: - "Incompatible versions" - } - } - } -} +// extension P2P.Dapp.Response.WalletInteractionFailureResponse { +// TODO: ask if we should do associated values here for `message` construction, +// in which case we'll need to declare discriminators +// public enum ErrorType: String, Sendable, LocalizedError, Hashable, Encodable { +// case rejectedByUser +// case wrongNetwork +// case failedToPrepareTransaction +// case failedToCompileTransaction +// case failedToSignTransaction +// case failedToSubmitTransaction +// case failedToPollSubmittedTransaction +// case failedToFindAccountWithEnoughFundsToLockFee +// case submittedTransactionWasDuplicate +// case submittedTransactionHasFailedTransactionStatus +// case submittedTransactionHasRejectedTransactionStatus +// case wrongAccountType +// case unknownWebsite +// case invalidOriginURL +// case radixJsonNotFound +// case radixJsonUnknownFileFormat +// case unknownDappDefinitionAddress +// case invalidPersona +// case invalidRequest +// case incompatibleVersion +// case failedToSignAuthChallenge +// +// public var errorDescription: String? { +// switch self { +// case .rejectedByUser: +// "Rejected by user" +// case .wrongNetwork: +// "Wrong network" +// case .failedToCompileTransaction: +// "Failed to compile transaction" +// case .failedToPrepareTransaction: +// "Failed to prepare transaction for submission" +// case .failedToSignTransaction: +// "Failed to sign transaction" +// case .failedToSubmitTransaction: +// "Failed to submit transaction" +// case .failedToPollSubmittedTransaction: +// "Failed to poll submitted transaction" +// case .failedToFindAccountWithEnoughFundsToLockFee: +// "Failed to find an account with enough funds to lock fee" +// case .submittedTransactionWasDuplicate: +// "Submitted transaction was a duplicate" +// case .submittedTransactionHasFailedTransactionStatus: +// "Submitted transaction failed" +// case .submittedTransactionHasRejectedTransactionStatus: +// "Submitted transaction was rejected" +// case .wrongAccountType: +// "Expected to find dapp definition account type" +// case .unknownWebsite: +// "Origin does not match any related website" +// case .invalidOriginURL: +// "Invalid origin URL" +// case .radixJsonNotFound: +// "radix.json file is missing" +// case .radixJsonUnknownFileFormat: +// "radix.json file format mismatch " +// case .unknownDappDefinitionAddress: +// "dApp definition address does not match any well known definition address" +// case .invalidPersona: +// "Invalid persona specified by dApp" +// case .invalidRequest: +// "Invalid request" +// case .failedToSignAuthChallenge: +// "Failed to sign auth challenge" +// case .incompatibleVersion: +// "Incompatible versions" +// } +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift index 368ecdce93..c64a646246 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift @@ -1,16 +1,15 @@ - -extension P2P.Dapp.Response { - public struct WalletInteractionSuccessResponse: Sendable, Hashable, Encodable { - /// *MUST* match an ID from an incoming request from Dapp. - public let interactionId: P2P.Dapp.Request.ID - public let items: Items - - public init( - interactionId: P2P.Dapp.Request.ID, - items: Items - ) { - self.interactionId = interactionId - self.items = items - } - } -} +// extension P2P.Dapp.Response { +// public struct WalletInteractionSuccessResponse: Sendable, Hashable, Encodable { +// /// *MUST* match an ID from an incoming request from Dapp. +// public let interactionId: P2P.Dapp.Request.ID +// public let items: Items +// +// public init( +// interactionId: P2P.Dapp.Request.ID, +// items: Items +// ) { +// self.interactionId = interactionId +// self.items = items +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift index 27bf2e6875..523de670db 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift @@ -1,81 +1,81 @@ // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.Items -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public enum Items: Sendable, Hashable, Encodable { - case request(RequestResponseItems) - case transaction(TransactionResponseItems) +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public enum Items: Sendable, Hashable, Encodable { +// case request(RequestResponseItems) +// case transaction(TransactionResponseItems) +// +// public func encode(to encoder: Encoder) throws { +// switch self { +// case let .request(items): +// try items.encode(to: encoder) +// case let .transaction(items): +// try items.encode(to: encoder) +// } +// } +// } +// } - public func encode(to encoder: Encoder) throws { - switch self { - case let .request(items): - try items.encode(to: encoder) - case let .transaction(items): - try items.encode(to: encoder) - } - } - } -} +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public enum RequestResponseItems: Sendable, Hashable, Encodable { +// case unauthorized(UnauthorizedRequestResponseItems) +// case authorized(AuthorizedRequestResponseItems) +// +// public func encode(to encoder: Encoder) throws { +// switch self { +// case let .unauthorized(items): +// try items.encode(to: encoder) +// case let .authorized(items): +// try items.encode(to: encoder) +// } +// } +// } -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public enum RequestResponseItems: Sendable, Hashable, Encodable { - case unauthorized(UnauthorizedRequestResponseItems) - case authorized(AuthorizedRequestResponseItems) +// public struct UnauthorizedRequestResponseItems: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.Items.Discriminator.unauthorizedRequest.rawValue +// public let oneTimeAccounts: AccountsRequestResponseItem? +// public let oneTimePersonaData: PersonaDataRequestResponseItem? +// +// public init( +// oneTimeAccounts: AccountsRequestResponseItem?, +// oneTimePersonaData: PersonaDataRequestResponseItem? +// ) { +// self.oneTimeAccounts = oneTimeAccounts +// self.oneTimePersonaData = oneTimePersonaData +// } +// } - public func encode(to encoder: Encoder) throws { - switch self { - case let .unauthorized(items): - try items.encode(to: encoder) - case let .authorized(items): - try items.encode(to: encoder) - } - } - } - - public struct UnauthorizedRequestResponseItems: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.Items.Discriminator.unauthorizedRequest.rawValue - public let oneTimeAccounts: AccountsRequestResponseItem? - public let oneTimePersonaData: PersonaDataRequestResponseItem? - - public init( - oneTimeAccounts: AccountsRequestResponseItem?, - oneTimePersonaData: PersonaDataRequestResponseItem? - ) { - self.oneTimeAccounts = oneTimeAccounts - self.oneTimePersonaData = oneTimePersonaData - } - } - - public struct AuthorizedRequestResponseItems: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.Items.Discriminator.authorizedRequest.rawValue - public let auth: AuthRequestResponseItem - public let ongoingAccounts: AccountsRequestResponseItem? - public let ongoingPersonaData: PersonaDataRequestResponseItem? - public let oneTimeAccounts: AccountsRequestResponseItem? - public let oneTimePersonaData: PersonaDataRequestResponseItem? - - public init( - auth: AuthRequestResponseItem, - ongoingAccounts: AccountsRequestResponseItem? = nil, - ongoingPersonaData: PersonaDataRequestResponseItem? = nil, - oneTimeAccounts: AccountsRequestResponseItem? = nil, - oneTimePersonaData: PersonaDataRequestResponseItem? = nil - ) { - self.auth = auth - self.ongoingAccounts = ongoingAccounts - self.ongoingPersonaData = ongoingPersonaData - self.oneTimeAccounts = oneTimeAccounts - self.oneTimePersonaData = oneTimePersonaData - } - } -} +// public struct AuthorizedRequestResponseItems: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.Items.Discriminator.authorizedRequest.rawValue +// public let auth: AuthRequestResponseItem +// public let ongoingAccounts: AccountsRequestResponseItem? +// public let ongoingPersonaData: PersonaDataRequestResponseItem? +// public let oneTimeAccounts: AccountsRequestResponseItem? +// public let oneTimePersonaData: PersonaDataRequestResponseItem? +// +// public init( +// auth: AuthRequestResponseItem, +// ongoingAccounts: AccountsRequestResponseItem? = nil, +// ongoingPersonaData: PersonaDataRequestResponseItem? = nil, +// oneTimeAccounts: AccountsRequestResponseItem? = nil, +// oneTimePersonaData: PersonaDataRequestResponseItem? = nil +// ) { +// self.auth = auth +// self.ongoingAccounts = ongoingAccounts +// self.ongoingPersonaData = ongoingPersonaData +// self.oneTimeAccounts = oneTimeAccounts +// self.oneTimePersonaData = oneTimePersonaData +// } +// } +// } // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.TransactionResponseItems -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { - public struct TransactionResponseItems: Sendable, Hashable, Encodable { - public let discriminator = P2P.Dapp.Request.Items.Discriminator.transaction.rawValue - public let send: SendTransactionResponseItem - - public init(send: P2P.Dapp.Response.WalletInteractionSuccessResponse.SendTransactionResponseItem) { - self.send = send - } - } -} +// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +// public struct TransactionResponseItems: Sendable, Hashable, Encodable { +// public let discriminator = P2P.Dapp.Request.Items.Discriminator.transaction.rawValue +// public let send: SendTransactionResponseItem +// +// public init(send: P2P.Dapp.Response.WalletInteractionSuccessResponse.SendTransactionResponseItem) { +// self.send = send +// } +// } +// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift new file mode 100644 index 0000000000..f1e64821a4 --- /dev/null +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift @@ -0,0 +1,158 @@ +import Sargon + +// MARK: - DappToWalletInteractionMetadata.Origin +extension DappToWalletInteractionMetadata { + public typealias Origin = URL +} + +extension DappToWalletInteractionMetadata.Origin { + public static let wallet: Self = { + let walletAppScheme = "com.radixpublishing.radixwallet.ios" + return .init(string: walletAppScheme)! + }() +} + +extension TxVersion { + public static let `default`: Self = 1 +} + +extension WalletToDappInteractionResponse { + public var interactionId: WalletInteractionId { + switch self { + case let .success(response): + response.interactionId + case let .failure(response): + response.interactionId + } + } + + public enum Accounts: Sendable, Hashable { + case withoutProofOfOwnership(IdentifiedArrayOf) + case withProofOfOwnership(challenge: DappToWalletInteractionAuthChallengeNonce, IdentifiedArrayOf) + + public struct WithProof: Sendable, Hashable, Identifiable { + public typealias ID = WalletInteractionWalletAccount + public var id: ID { account } + public let account: WalletInteractionWalletAccount + + public let proof: WalletToDappInteractionAuthProof + + public init( + account: WalletInteractionWalletAccount, + proof: WalletToDappInteractionAuthProof + ) { + self.account = account + self.proof = proof + } + } + } +} + +extension WalletToDappInteractionAccountsRequestResponseItem { + public init( + accounts: WalletToDappInteractionResponse.Accounts + ) { + switch accounts { + case let .withProofOfOwnership(challenge, accountsWithProof): + self.init( + accounts: accountsWithProof.map(\.account), + challenge: challenge, + proofs: accountsWithProof.map { .init(accountAddress: $0.account.address, proof: $0.proof) } + ) + case let .withoutProofOfOwnership(account): + self.init( + accounts: account.map(WalletInteractionWalletAccount.init(account:)), + challenge: nil, + proofs: nil + ) + } + } +} + +extension DappToWalletInteractionSendTransactionItem { + public init( + version: TxVersion = .default, + transactionManifest: TransactionManifest, + message: String? = nil + ) { + self.init( + unvalidatedManifest: .init(manifest: transactionManifest), + version: version, + message: message + ) + } +} + +extension WalletInteractionWalletAccount { + public init(account: Account) { + self.init( + address: account.address, + label: account.displayName, + appearanceId: account.appearanceID + ) + } +} + +extension WalletToDappInteractionAuthProof { + public init(entitySignature: SignatureOfEntity) { + let sigPub = entitySignature.signatureWithPublicKey + let signature = sigPub.signature + self.init( + publicKey: sigPub.publicKey, + curve: sigPub.publicKey.curve, + signature: signature + ) + } +} + +extension DappWalletInteractionPersona { + public init(persona: Persona) { + self.init(identityAddress: persona.address, label: persona.displayName.rawValue) + } +} + +extension WalletInteractionId { + public static func walletInteractionID(for interaction: DappInteractionClient.WalletInteraction) -> Self { + "\(interaction.rawValue)_\(UUID().uuidString)" + } + + public var isWalletAccountDepositSettingsInteraction: Bool { + hasPrefix(DappInteractionClient.WalletInteraction.accountDepositSettings.rawValue) + } + + public var isWalletAccountTransferInteraction: Bool { + hasPrefix(DappInteractionClient.WalletInteraction.accountTransfer.rawValue) + } + + public var isWalletInteraction: Bool { + isWalletAccountTransferInteraction || isWalletAccountDepositSettingsInteraction + } +} + +extension DappToWalletInteraction { + public enum MissingEntry: Sendable, Hashable { + case missingEntry + case missing(Int) + } + + public enum KindRequest: Sendable, Hashable { + case entry + case number(RequestedQuantity) + } +} + +extension DappToWalletInteractionPersonaDataRequestItem { + public var kindRequests: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] { + var result: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] = [:] + if isRequestingName == true { + result[.fullName] = .entry + } + if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { + result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) + } + if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { + result[.emailAddress] = .number(numberOfRequestedEmailAddresses) + } + return result + } +} diff --git a/RadixWallet/Core/SharedModels/P2P/DappOrigin.swift b/RadixWallet/Core/SharedModels/P2P/DappOrigin.swift deleted file mode 100644 index 7fbd286fd4..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/DappOrigin.swift +++ /dev/null @@ -1,40 +0,0 @@ -import Foundation - -// MARK: - DappOrigin -public struct DappOrigin: Sendable, Hashable, Codable { - public static let wallet: DappOrigin = { - let walletAppScheme = "com.radixpublishing.radixwallet.ios" - return .init(urlString: .init(stringLiteral: walletAppScheme), url: .init(string: walletAppScheme)!) - }() - - public let urlString: NonEmptyString - public let url: URL - - public func encode(to encoder: Encoder) throws { - var singleValueContainer = encoder.singleValueContainer() - try singleValueContainer.encode(urlString.rawValue) - } - - public init(urlString: NonEmptyString, url: URL) { - self.urlString = urlString - self.url = url - } - - struct InvalidOriginURL: Error {} - - public init(string: String) throws { - guard - let urlNonEmpty = NonEmptyString(rawValue: string), - let url = URL(string: string) - else { - throw InvalidOriginURL() - } - self.init(urlString: urlNonEmpty, url: url) - } - - public init(from decoder: Decoder) throws { - let singleValueContainer = try decoder.singleValueContainer() - let urlStringString = try singleValueContainer.decode(String.self) - try self.init(string: urlStringString) - } -} diff --git a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift index b81a0eaf67..0a6450a5b6 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift @@ -5,11 +5,11 @@ import SwiftUI struct AccountPermission: Sendable, FeatureReducer { struct State: Sendable, Hashable { let dappMetadata: DappMetadata - let numberOfAccounts: DappInteraction.NumberOfAccounts + let numberOfAccounts: NumberOfAccounts init( dappMetadata: DappMetadata, - numberOfAccounts: DappInteraction.NumberOfAccounts + numberOfAccounts: NumberOfAccounts ) { self.dappMetadata = dappMetadata self.numberOfAccounts = numberOfAccounts diff --git a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift index 222dbae9e0..5b73b9b578 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift @@ -3,7 +3,7 @@ import Sargon import SwiftUI // MARK: - ChooseAccountsResult -typealias AccountPermissionChooseAccountsResult = P2P.Dapp.Response.Accounts +typealias AccountPermissionChooseAccountsResult = WalletToDappInteractionResponse.Accounts // MARK: - AccountPermissionChooseAccounts struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { @@ -14,7 +14,7 @@ struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { } /// if `proofOfOwnership`, sign this challenge - let challenge: P2P.Dapp.Request.AuthChallengeNonce? + let challenge: DappToWalletInteractionAuthChallengeNonce? let accessKind: AccessKind let dappMetadata: DappMetadata @@ -24,7 +24,7 @@ struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { var destination: Destination.State? init( - challenge: P2P.Dapp.Request.AuthChallengeNonce?, + challenge: DappToWalletInteractionAuthChallengeNonce?, accessKind: AccessKind, dappMetadata: DappMetadata, chooseAccounts: ChooseAccounts.State @@ -36,10 +36,10 @@ struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { } init( - challenge: P2P.Dapp.Request.AuthChallengeNonce?, + challenge: DappToWalletInteractionAuthChallengeNonce?, accessKind: AccessKind, dappMetadata: DappMetadata, - numberOfAccounts: DappInteraction.NumberOfAccounts + numberOfAccounts: NumberOfAccounts ) { self.init( challenge: challenge, @@ -167,11 +167,11 @@ struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { state.destination = nil var accountsLeftToVerifyDidSign: Set = Set(selectedAccounts.map(\.id)) - let walletAccountsWithProof: [P2P.Dapp.Response.Accounts.WithProof] = signedAuthChallenge.entitySignatures.map { + let walletAccountsWithProof: [WalletToDappInteractionResponse.Accounts.WithProof] = signedAuthChallenge.entitySignatures.map { let account = try! $0.signerEntity.asAccount() accountsLeftToVerifyDidSign.remove(account.id) - let proof = P2P.Dapp.Response.AuthProof(entitySignature: $0) - return P2P.Dapp.Response.Accounts.WithProof(account: .init(account: account), proof: proof) + let proof = WalletToDappInteractionAuthProof(entitySignature: $0) + return WalletToDappInteractionResponse.Accounts.WithProof(account: .init(account: account), proof: proof) } guard accountsLeftToVerifyDidSign.isEmpty else { loggerGlobal.error("Failed to sign with all accounts..") diff --git a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login+View.swift b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login+View.swift index bdb2b2abe6..9a288baeb6 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login+View.swift @@ -146,7 +146,7 @@ struct Login_Preview: PreviewProvider { extension Login.State { static let previewValue: Self = .init( dappMetadata: .previewValue, - loginRequest: try! .withChallenge(.init(challenge: .init(.sample))) + loginRequest: .loginWithChallenge(.init(challenge: .sample)) ) } #endif diff --git a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift index 59c30e3600..153c80b3c3 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift @@ -6,7 +6,7 @@ import SwiftUI struct Login: Sendable, FeatureReducer { struct State: Sendable, Hashable { let dappMetadata: DappMetadata - let loginRequest: P2P.Dapp.Request.AuthLoginRequestItem + let loginRequest: DappToWalletInteractionAuthRequestItem // P2P.Dapp.Request.AuthLoginRequestItem var personaPrimacy: PersonaPrimacy? = nil @@ -21,7 +21,7 @@ struct Login: Sendable, FeatureReducer { init( dappMetadata: DappMetadata, - loginRequest: P2P.Dapp.Request.AuthLoginRequestItem, + loginRequest: DappToWalletInteractionAuthRequestItem, // P2P.Dapp.Request.AuthLoginRequestItem personaPrimacy: PersonaPrimacy? = nil ) { self.dappMetadata = dappMetadata @@ -91,7 +91,7 @@ struct Login: Sendable, FeatureReducer { case let .continueButtonTapped(persona): let authorizedPersona = state.authorizedDapp?.referencesToAuthorizedPersonas.first(where: { $0.id == persona.id }) - guard case let .withChallenge(loginWithChallenge) = state.loginRequest else { + guard case let .loginWithChallenge(loginWithChallenge) = state.loginRequest else { return .send(.delegate(.continueButtonTapped(persona, state.authorizedDapp, authorizedPersona, nil))) } @@ -199,7 +199,7 @@ extension DappMetadata { var dAppDefinitionAddress: DappDefinitionAddress { switch self { case let .ledger(metadata): metadata.dAppDefinintionAddress - case let .request(metadata): metadata.dAppDefinitionAddress + case let .request(metadata): metadata.dappDefinitionAddress case .wallet: .wallet } } diff --git a/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData+View.swift b/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData+View.swift index 8510ffbb99..1f413d4dab 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData+View.swift @@ -9,7 +9,7 @@ extension OneTimePersonaData { let shouldShowChooseDataToProvideTitle: Bool let availablePersonas: IdentifiedArrayOf let selectedPersona: PersonaDataPermissionBox.State? - let output: P2P.Dapp.Request.Response? + let output: WalletToDappInteractionPersonaDataRequestResponseItem? init(state: OneTimePersonaData.State) { self.thumbnail = state.dappMetadata.thumbnail diff --git a/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData.swift b/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData.swift index 4b592db59f..54f31c9907 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/OneTimePersonaData/OneTimePersonaData.swift @@ -7,7 +7,7 @@ struct OneTimePersonaData: Sendable, FeatureReducer { let dappMetadata: DappMetadata var personas: IdentifiedArrayOf = [] var selectedPersona: PersonaDataPermissionBox.State? - let requested: P2P.Dapp.Request.PersonaDataRequestItem + let requested: DappToWalletInteractionPersonaDataRequestItem var personaPrimacy: PersonaPrimacy? = nil @@ -16,7 +16,7 @@ struct OneTimePersonaData: Sendable, FeatureReducer { init( dappMetadata: DappMetadata, - requested: P2P.Dapp.Request.PersonaDataRequestItem, + requested: DappToWalletInteractionPersonaDataRequestItem, personaPrimacy: PersonaPrimacy? = nil ) { self.dappMetadata = dappMetadata @@ -30,7 +30,7 @@ struct OneTimePersonaData: Sendable, FeatureReducer { case appeared case selectedPersonaChanged(PersonaDataPermissionBox.State?) case createNewPersonaButtonTapped - case continueButtonTapped(P2P.Dapp.Request.Response) + case continueButtonTapped(WalletToDappInteractionPersonaDataRequestResponseItem) } enum InternalAction: Sendable, Equatable { @@ -44,7 +44,7 @@ struct OneTimePersonaData: Sendable, FeatureReducer { enum DelegateAction: Sendable, Equatable { case personaUpdated(Persona) - case continueButtonTapped(P2P.Dapp.Request.Response) + case continueButtonTapped(WalletToDappInteractionPersonaDataRequestResponseItem) } public struct Destination: DestinationReducer { diff --git a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission+View.swift b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission+View.swift index aabeb5e155..7f0c312942 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission+View.swift @@ -18,7 +18,7 @@ extension PersonaDataPermission { let thumbnail: URL? let title: String let subtitle: String - let output: P2P.Dapp.Request.Response? + let output: WalletToDappInteractionPersonaDataRequestResponseItem? } @MainActor diff --git a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission.swift b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission.swift index f40a68ccab..88beb4c694 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermission.swift @@ -7,7 +7,7 @@ struct PersonaDataPermission: Sendable, FeatureReducer { let dappMetadata: DappMetadata let personaID: Persona.ID var persona: PersonaDataPermissionBox.State? - let requested: P2P.Dapp.Request.PersonaDataRequestItem + let requested: DappToWalletInteractionPersonaDataRequestItem @PresentationState var destination: Destination.State? @@ -15,7 +15,7 @@ struct PersonaDataPermission: Sendable, FeatureReducer { init( dappMetadata: DappMetadata, personaID: Persona.ID, - requested: P2P.Dapp.Request.PersonaDataRequestItem + requested: DappToWalletInteractionPersonaDataRequestItem ) { self.dappMetadata = dappMetadata self.personaID = personaID @@ -25,7 +25,7 @@ struct PersonaDataPermission: Sendable, FeatureReducer { enum ViewAction: Sendable, Equatable { case task - case continueButtonTapped(P2P.Dapp.Request.Response) + case continueButtonTapped(WalletToDappInteractionPersonaDataRequestResponseItem) } enum InternalAction: Sendable, Equatable { @@ -38,7 +38,7 @@ struct PersonaDataPermission: Sendable, FeatureReducer { enum DelegateAction: Sendable, Equatable { case personaUpdated(Persona) - case continueButtonTapped(P2P.Dapp.Request.Response) + case continueButtonTapped(WalletToDappInteractionPersonaDataRequestResponseItem) } public struct Destination: DestinationReducer { diff --git a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermissionBox.swift b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermissionBox.swift index 030b1927c7..343fa3b0f2 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermissionBox.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/PersonaDataPermission/PersonaDataPermissionBox.swift @@ -5,12 +5,12 @@ struct PersonaDataPermissionBox: Sendable, FeatureReducer { struct State: Sendable, Hashable, Identifiable { var id: Persona.ID { persona.id } let persona: Persona - let requested: P2P.Dapp.Request.PersonaDataRequestItem - let responseValidation: P2P.Dapp.Request.RequestValidation + let requested: DappToWalletInteractionPersonaDataRequestItem + let responseValidation: DappToWalletInteraction.RequestValidation init( persona: Persona, - requested: P2P.Dapp.Request.PersonaDataRequestItem + requested: DappToWalletInteractionPersonaDataRequestItem ) { self.persona = persona self.requested = requested diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator+View.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator+View.swift index 05f7fcc0f5..d515a29809 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator+View.swift @@ -46,9 +46,7 @@ struct DappInteractionCoordinator_Previews: PreviewProvider { DappInteractionCoordinator.View( store: .init( initialState: .init( - interaction: .previewValueAllRequests( - auth: .login(.withoutChallenge) - ) + interaction: .previewValueAllRequests() ) ) { DappInteractionCoordinator() diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift index 5c85a4f1ff..2e55b8d071 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionCoordinator.swift @@ -8,13 +8,13 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { case flow(DappInteractionFlow.State) } - let interaction: P2P.Dapp.Request + let interaction: DappToWalletInteraction var childState: ChildState @PresentationState var errorAlert: AlertState? = nil - init(interaction: P2P.Dapp.Request) { + init(interaction: DappToWalletInteraction) { self.interaction = interaction self.childState = .loading(.init(interaction: interaction)) } @@ -38,7 +38,7 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { } enum DelegateAction: Sendable, Equatable { - case submit(P2P.Dapp.Response, DappMetadata) + case submit(WalletToDappInteractionResponse, DappMetadata) case dismiss(DappMetadata, IntentHash) case dismissSilently } @@ -62,8 +62,8 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { switch action { case .okButtonTapped: .send(.delegate(.submit(.failure(.init( - interactionId: state.interaction.id, - errorType: .rejectedByUser, + interactionId: state.interaction.interactionId, + error: .rejectedByUser, message: nil )), .request(state.interaction.metadata)))) } @@ -93,8 +93,8 @@ struct DappInteractionCoordinator: Sendable, FeatureReducer { case .loading(.delegate(.dismiss)): return .send(.delegate(.submit(.failure(.init( - interactionId: state.interaction.id, - errorType: .rejectedByUser, + interactionId: state.interaction.interactionId, + error: .rejectedByUser, message: nil )), .request(state.interaction.metadata)))) diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift index 643f420fca..530c7e5021 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift @@ -13,12 +13,12 @@ struct DappInteractionFlow: Sendable, FeatureReducer { case local(LocalInteractionResponseItem) } - typealias RemoteInteraction = P2P.Dapp.Request - typealias RemoteInteractionItem = P2P.Dapp.Request.AnyInteractionItem - typealias RemoteInteractionResponseItem = P2P.Dapp.Response.WalletInteractionSuccessResponse.AnyInteractionResponseItem + typealias RemoteInteraction = DappToWalletInteraction + typealias RemoteInteractionItem = DappToWalletInteraction.AnyInteractionItem + typealias RemoteInteractionResponseItem = WalletToDappInteractionSuccessResponse.AnyInteractionResponseItem enum LocalInteractionItem: Sendable, Hashable { - case accountPermissionRequested(DappInteraction.NumberOfAccounts) + case accountPermissionRequested(NumberOfAccounts) } enum LocalInteractionResponseItem: Sendable, Hashable { @@ -85,7 +85,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { enum InternalAction: Sendable, Equatable { case usePersona( - P2P.Dapp.Request.AuthUsePersonaRequestItem, + DappToWalletInteractionAuthUsePersonaRequestItem, Persona, AuthorizedDapp, AuthorizedPersonaSimple @@ -97,7 +97,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { struct AutofillOngoingResponseItemsPayload: Sendable, Equatable { struct AccountsPayload: Sendable, Equatable { var requestItem: DappInteractionFlow.State.AnyInteractionItem - var numberOfAccountsRequested: DappInteraction.NumberOfAccounts + var numberOfAccountsRequested: NumberOfAccounts var accounts: [Account] } @@ -108,7 +108,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { case failedToUpdatePersonaAtEndOfFlow( persona: Persona, - response: P2P.Dapp.Response.WalletInteractionSuccessResponse, + response: WalletToDappInteractionSuccessResponse, metadata: DappMetadata ) } @@ -119,9 +119,9 @@ struct DappInteractionFlow: Sendable, FeatureReducer { } enum DelegateAction: Sendable, Equatable { - case dismissWithFailure(P2P.Dapp.Response.WalletInteractionFailureResponse) + case dismissWithFailure(WalletToDappInteractionFailureResponse) case dismissWithSuccess(DappMetadata, IntentHash) - case submit(P2P.Dapp.Response.WalletInteractionSuccessResponse, DappMetadata) + case submit(WalletToDappInteractionSuccessResponse, DappMetadata) case dismiss } @@ -316,7 +316,7 @@ extension DappInteractionFlow { state.authorizedDapp = authorizedDapp state.authorizedPersona = authorizedPersona - let responsePersona = P2P.Dapp.Response.PersonaResponse( + let responsePersona = DappWalletInteractionPersona( identityAddress: persona.address, label: persona.displayName.value ) @@ -329,18 +329,18 @@ extension DappInteractionFlow { else { return dismissEffect(for: state, errorKind: .failedToSignAuthChallenge, message: "Failed to serialize signature") } - let proof = P2P.Dapp.Response.AuthProof(entitySignature: entitySignature) + let proof = WalletToDappInteractionAuthProof(entitySignature: entitySignature) - state.responseItems[item] = .remote(.auth(.login(.withChallenge(.init( + state.responseItems[item] = .remote(.auth(.loginWithChallenge(.init( persona: responsePersona, challenge: signedAuthChallenge.challenge, proof: proof - ))))) + )))) } else { - state.responseItems[item] = .remote(.auth(.login(.withoutChallenge(.init( + state.responseItems[item] = .remote(.auth(.loginWithoutChallenge(.init( persona: responsePersona - ))))) + )))) } resetOngoingResponseItemsIfNeeded(for: &state) @@ -376,20 +376,20 @@ extension DappInteractionFlow { return .none } state.persona = persona - let responsePersona = P2P.Dapp.Response.PersonaResponse(persona: persona) + let responsePersona = DappWalletInteractionPersona(persona: persona) for (request, response) in state.responseItems { // NB: native case paths should simplify this mutation logic a lot switch response { - case let .remote(.auth(.login(.withChallenge(item)))): - state.responseItems[request] = .remote(.auth(.login(.withChallenge(.init( + case let .remote(.auth(.loginWithChallenge(item))): + state.responseItems[request] = .remote(.auth(.loginWithChallenge(.init( persona: responsePersona, challenge: item.challenge, proof: item.proof - ))))) - case .remote(.auth(.login(.withoutChallenge))): - state.responseItems[request] = .remote(.auth(.login(.withoutChallenge(.init( + )))) + case .remote(.auth(.loginWithoutChallenge)): + state.responseItems[request] = .remote(.auth(.loginWithoutChallenge(.init( persona: responsePersona - ))))) + )))) case .remote(.auth(.usePersona)): state.responseItems[request] = .remote(.auth(.usePersona(.init( persona: responsePersona @@ -405,7 +405,7 @@ extension DappInteractionFlow { _ item: State.AnyInteractionItem, _ txID: IntentHash ) -> Effect { - state.responseItems[item] = .remote(.send(.init(txID: txID))) + state.responseItems[item] = .remote(.send(.init(transactionIntentHash: txID))) return continueEffect(for: &state) } @@ -535,7 +535,7 @@ extension DappInteractionFlow { guard let persona = allPersonas[id: authorizedPersonaID] else { return nil } guard - let responseItem = try? P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem( + let responseItem = try? WalletToDappInteractionPersonaDataRequestResponseItem( personaDataRequested: personaDataRequested, personaData: persona.personaData ) @@ -575,8 +575,8 @@ extension DappInteractionFlow { // MARK: - DappInteractionFlow.InternalAction.AutofillOngoingResponseItemsPayload.PersonaDataPayload extension DappInteractionFlow.InternalAction.AutofillOngoingResponseItemsPayload { struct PersonaDataPayload: Sendable, Equatable { - var personaDataRequested: P2P.Dapp.Request.PersonaDataRequestItem - var responseItem: P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem + var personaDataRequested: DappToWalletInteractionPersonaDataRequestItem + var responseItem: WalletToDappInteractionPersonaDataRequestResponseItem } } @@ -603,7 +603,7 @@ extension DappInteractionFlow { func setAccountsResponse( to item: State.AnyInteractionItem, accessKind: AccountPermissionChooseAccounts.State.AccessKind, - chosenAccounts: P2P.Dapp.Response.Accounts, + chosenAccounts: WalletToDappInteractionResponse.Accounts, into state: inout State ) { switch accessKind { @@ -640,7 +640,7 @@ extension DappInteractionFlow { } func finishInteractionFlow(_ state: State) -> Effect { - guard let response = P2P.Dapp.Response.WalletInteractionSuccessResponse( + guard let response = WalletToDappInteractionSuccessResponse( for: state.remoteInteraction, with: state.responseItems.values.compactMap(/State.AnyInteractionResponseItem.remote) ) else { @@ -673,7 +673,7 @@ extension DappInteractionFlow { func updatePersona( _ persona: Persona, _ state: State, - responseItems: P2P.Dapp.Response.WalletInteractionSuccessResponse.Items + responseItems: WalletToDappInteractionResponseItems ) async throws { let networkID = await gatewaysClient.getCurrentNetworkID() var authorizedDapp: AuthorizedDapp = state.authorizedDapp ?? AuthorizedDapp( @@ -688,11 +688,11 @@ extension DappInteractionFlow { referencesToAuthorizedPersonas: [] ) // This extraction is really verbose right now, but it should become a lot simpler with native case paths - let sharedAccountsInfo: (P2P.Dapp.Request.NumberOfAccounts, [P2P.Dapp.Response.WalletAccount])? = unwrap( + let sharedAccountsInfo: (NumberOfAccounts, [WalletInteractionWalletAccount])? = unwrap( // request { switch state.remoteInteraction.items { - case let .request(.authorized(items)): + case let .authorizedRequest(items): items.ongoingAccounts?.numberOfAccounts default: nil @@ -701,7 +701,7 @@ extension DappInteractionFlow { // response { switch responseItems { - case let .request(.authorized(items)): + case let .authorizedRequest(items): items.ongoingAccounts?.accounts default: nil @@ -709,11 +709,11 @@ extension DappInteractionFlow { }() ) - let sharedPersonaDataInfo: (P2P.Dapp.Request.PersonaDataRequestItem, P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem)? = unwrap( + let sharedPersonaDataInfo: (DappToWalletInteractionPersonaDataRequestItem, WalletToDappInteractionPersonaDataRequestResponseItem)? = unwrap( // request { switch state.remoteInteraction.items { - case let .request(.authorized(items)): + case let .authorizedRequest(items): items.ongoingPersonaData default: nil } @@ -721,7 +721,7 @@ extension DappInteractionFlow { // response { switch responseItems { - case let .request(.authorized(items)): + case let .authorizedRequest(items): items.ongoingPersonaData default: nil @@ -786,12 +786,12 @@ extension DappInteractionFlow { func dismissEffect( for state: State, - errorKind: P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType, + errorKind: DappWalletInteractionErrorType, message: String? ) -> Effect { .send(.delegate(.dismissWithFailure(.init( - interactionId: state.remoteInteraction.id, - errorType: errorKind, + interactionId: state.remoteInteraction.interactionId, + error: errorKind, message: message )))) } @@ -837,13 +837,16 @@ extension DappInteractionFlow.Path.State { ) { self.item = anyItem switch anyItem { - case .remote(.auth(.usePersona)): - return nil - case let .remote(.auth(.login(loginRequest))): - self.state = .login(.init( - dappMetadata: dappMetadata, - loginRequest: loginRequest - )) + case let .remote(.auth(request)): + switch request { + case .loginWithChallenge, .loginWithoutChallenge: + self.state = .login(.init( + dappMetadata: dappMetadata, + loginRequest: request + )) + case .usePersona: + return nil + } case let .local(.accountPermissionRequested(numberOfAccounts)): self.state = .accountPermission(.init( @@ -893,8 +896,8 @@ extension DappInteractionFlow.Path.State { message: item.message.map { Message.plaintext(string: $0) } ?? Message.none, - waitsForTransactionToBeComitted: interaction.id.isWalletAccountDepositSettingsInteraction, - isWalletTransaction: interaction.id.isWalletInteraction, + waitsForTransactionToBeComitted: interaction.interactionId.isWalletAccountDepositSettingsInteraction, + isWalletTransaction: interaction.interactionId.isWalletInteraction, proposingDappMetadata: dappMetadata.onLedger )) } @@ -902,11 +905,11 @@ extension DappInteractionFlow.Path.State { } extension DappInteractionFlow.State { - var usePersonaRequestItem: P2P.Dapp.Request.AuthUsePersonaRequestItem? { + var usePersonaRequestItem: DappToWalletInteractionAuthUsePersonaRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.auth?.usePersona?] guard - case let .request(.authorized(item)) = remoteInteraction.items, + case let .authorizedRequest(item) = remoteInteraction.items, case let .usePersona(item) = item.auth else { return nil @@ -914,55 +917,55 @@ extension DappInteractionFlow.State { return item } - var resetRequestItem: P2P.Dapp.Request.ResetRequestItem? { + var resetRequestItem: DappToWalletInteractionResetRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.reset] guard - case let .request(.authorized(item)) = remoteInteraction.items + case let .authorizedRequest(item) = remoteInteraction.items else { return nil } return item.reset } - var ongoingAccountsRequestItem: P2P.Dapp.Request.AccountsRequestItem? { + var ongoingAccountsRequestItem: DappToWalletInteractionAccountsRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.ongoingAccounts] guard - case let .request(.authorized(item)) = remoteInteraction.items + case let .authorizedRequest(item) = remoteInteraction.items else { return nil } return item.ongoingAccounts } - var oneTimeAccountsRequestItem: P2P.Dapp.Request.AccountsRequestItem? { + var oneTimeAccountsRequestItem: DappToWalletInteractionAccountsRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.oneTimeAccountsRequestItem] guard - case let .request(.authorized(item)) = remoteInteraction.items + case let .authorizedRequest(item) = remoteInteraction.items else { return nil } return item.oneTimeAccounts } - var oneTimePersonaDataRequestItem: P2P.Dapp.Request.PersonaDataRequestItem? { + var oneTimePersonaDataRequestItem: DappToWalletInteractionPersonaDataRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.oneTimePersonaDataRequestItem] guard - case let .request(.authorized(item)) = remoteInteraction.items + case let .authorizedRequest(item) = remoteInteraction.items else { return nil } return item.oneTimePersonaData } - var ongoingPersonaDataRequestItem: P2P.Dapp.Request.PersonaDataRequestItem? { + var ongoingPersonaDataRequestItem: DappToWalletInteractionPersonaDataRequestItem? { // NB: this should become a one liner with native case paths: // remoteInteractions.items[keyPath: \.request?.authorized?.ongoingPersonaData] guard - case let .request(.authorized(item)) = remoteInteraction.items + case let .authorizedRequest(item) = remoteInteraction.items else { return nil } diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift index e25b23f7df..4cdb493332 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift @@ -64,7 +64,7 @@ struct DappInteractionLoading_Preview: PreviewProvider { extension DappInteractionLoading.State { static let previewValue: Self = .init( - interaction: .previewValueOneTimeAccount + interaction: .previewValueAllRequests() // .previewValueOneTimeAccount ) } #endif diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift index ec4f365527..c335c3f0f7 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift @@ -4,13 +4,13 @@ import SwiftUI // MARK: - DappInteractionLoading struct DappInteractionLoading: Sendable, FeatureReducer { struct State: Sendable, Hashable { - let interaction: P2P.Dapp.Request + let interaction: DappToWalletInteraction var isLoading: Bool = false @PresentationState var errorAlert: AlertState? - init(interaction: P2P.Dapp.Request) { + init(interaction: DappToWalletInteraction) { self.interaction = interaction } } @@ -65,7 +65,7 @@ struct DappInteractionLoading: Sendable, FeatureReducer { func metadataLoadingEffect(with state: inout State) -> Effect { state.isLoading = true - if state.interaction.metadata.origin == .wallet { + if state.interaction.metadata.origin == DappToWalletInteractionMetadata.Origin.wallet { return .send(.internal(.dappMetadataLoadingResult(.success(.wallet(.init()))))) } @@ -73,7 +73,7 @@ struct DappInteractionLoading: Sendable, FeatureReducer { let result: TaskResult = await { let isDeveloperModeEnabled = await appPreferencesClient.getPreferences().security.isDeveloperModeEnabled - let dappDefinitionAddress = request.dAppDefinitionAddress + let dappDefinitionAddress = request.dappDefinitionAddress do { let cachedMetadata = try await cacheClient.withCaching( @@ -153,7 +153,7 @@ extension DappMetadata.Ledger { init( entityMetadataForDapp: GatewayAPI.EntityMetadataCollection, dAppDefinintionAddress: AccountAddress, - origin: P2P.Dapp.Request.Metadata.Origin + origin: DappToWalletInteractionMetadata.Origin ) { let items = entityMetadataForDapp.items let maybeName: String? = items[.name]?.value.asString diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift index c19461914b..11432f1780 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift @@ -4,19 +4,18 @@ import SwiftUI // MARK: - DappInteraction enum DappInteraction {} -// MARK: DappInteraction.NumberOfAccounts -extension DappInteraction { - typealias NumberOfAccounts = P2P.Dapp.Request.NumberOfAccounts -} - // MARK: - DappMetadata +// extension DappInteraction { +// typealias NumberOfAccounts = P2P.Dapp.Request.NumberOfAccounts +// } + /// Metadata for a dapp, either from a request or fetched from ledger. -/// not to be confused with `P2P.Dapp.Request.Metadata` which is the +/// not to be confused with `DappToWalletInteractionMetadata` which is the /// associated value of one of the cases of this enum. public enum DappMetadata: Sendable, Hashable { /// The metadata sent with the request from the Dapp. /// We only allow this case `request` to be passed around if `isDeveloperModeEnabled` is `true`. - case request(P2P.Dapp.Request.Metadata) + case request(DappToWalletInteractionMetadata) /// A detailed DappMetaData fetched from Ledger. case ledger(Ledger) @@ -27,7 +26,7 @@ public enum DappMetadata: Sendable, Hashable { extension DappMetadata { static let wallet: Wallet = .init() public struct Wallet: Sendable, Hashable { - let origin: DappOrigin = .wallet + let origin: DappToWalletInteractionMetadata.Origin = .wallet let name: NonEmptyString = "Radix Wallet" let description: String? = nil let thumbnail: URL? = nil @@ -40,7 +39,7 @@ extension DappMetadata { public struct Ledger: Sendable, Hashable, Codable { static let defaultName = NonEmptyString(rawValue: L10n.DAppRequest.Metadata.unknownName)! - let origin: P2P.Dapp.Request.Metadata.Origin + let origin: DappToWalletInteractionMetadata.Origin let dAppDefinintionAddress: DappDefinitionAddress let name: NonEmptyString? @@ -48,7 +47,7 @@ extension DappMetadata { let thumbnail: URL? init( - origin: P2P.Dapp.Request.Metadata.Origin, + origin: DappToWalletInteractionMetadata.Origin, dAppDefinintionAddress: DappDefinitionAddress, name: NonEmptyString?, description: String? = nil, @@ -64,7 +63,7 @@ extension DappMetadata { } extension DappMetadata { - public var origin: DappOrigin { + public var origin: DappToWalletInteractionMetadata.Origin { switch self { case let .ledger(metadata): metadata.origin case let .request(metadata): metadata.origin @@ -90,7 +89,7 @@ extension DappMetadata { #if DEBUG extension DappMetadata { static let previewValue: Self = try! .ledger(.init( - origin: .init(string: "https://radfi.com"), + origin: .wallet, // .init(string: "https://radfi.com"), dAppDefinintionAddress: .init(validatingAddress: "account_tdx_b_1p95nal0nmrqyl5r4phcspg8ahwnamaduzdd3kaklw3vqeavrwa"), name: "Collabo.Fi", description: "A very collaby finance dapp", @@ -101,18 +100,18 @@ extension DappMetadata { #endif // MARK: - P2P.Dapp.Request.WalletRequestItem -extension P2P.Dapp.Request { +extension DappToWalletInteraction { /// A union type containing all request items allowed in a `WalletInteraction`, for app handling purposes. enum AnyInteractionItem: Sendable, Hashable { // requests - case auth(AuthRequestItem) - case oneTimeAccounts(AccountsRequestItem) - case ongoingAccounts(AccountsRequestItem) - case oneTimePersonaData(PersonaDataRequestItem) - case ongoingPersonaData(PersonaDataRequestItem) + case auth(DappToWalletInteractionAuthRequestItem) + case oneTimeAccounts(DappToWalletInteractionAccountsRequestItem) + case ongoingAccounts(DappToWalletInteractionAccountsRequestItem) + case oneTimePersonaData(DappToWalletInteractionPersonaDataRequestItem) + case ongoingPersonaData(DappToWalletInteractionPersonaDataRequestItem) // transactions - case send(SendTransactionItem) + case send(DappToWalletInteractionSendTransactionItem) var priority: some Comparable { switch self { @@ -140,7 +139,7 @@ extension P2P.Dapp.Request { // implementation simpler and with no need to keep it manually synced up. var erasedItems: [AnyInteractionItem] { switch items { - case let .request(.authorized(items)): + case let .authorizedRequest(items): [ .auth(items.auth), items.oneTimeAccounts.map(AnyInteractionItem.oneTimeAccounts), @@ -149,7 +148,7 @@ extension P2P.Dapp.Request { items.ongoingPersonaData.map(AnyInteractionItem.ongoingPersonaData), ] .compactMap { $0 } - case let .request(.unauthorized(items)): + case let .unauthorizedRequest(items): [ items.oneTimeAccounts.map(AnyInteractionItem.oneTimeAccounts), items.oneTimePersonaData.map(AnyInteractionItem.oneTimePersonaData), @@ -165,31 +164,31 @@ extension P2P.Dapp.Request { } // MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AnyInteractionResponseItem -extension P2P.Dapp.Response.WalletInteractionSuccessResponse { +extension WalletToDappInteractionSuccessResponse { enum AnyInteractionResponseItem: Sendable, Hashable { // request responses - case auth(AuthRequestResponseItem) - case oneTimeAccounts(AccountsRequestResponseItem) - case ongoingAccounts(AccountsRequestResponseItem) - case oneTimePersonaData(PersonaDataRequestResponseItem) - case ongoingPersonaData(PersonaDataRequestResponseItem) + case auth(WalletToDappInteractionAuthRequestResponseItem) + case oneTimeAccounts(WalletToDappInteractionAccountsRequestResponseItem) + case ongoingAccounts(WalletToDappInteractionAccountsRequestResponseItem) + case oneTimePersonaData(WalletToDappInteractionPersonaDataRequestResponseItem) + case ongoingPersonaData(WalletToDappInteractionPersonaDataRequestResponseItem) // transaction responses - case send(SendTransactionResponseItem) + case send(WalletToDappInteractionSendTransactionResponseItem) } init?( - for interaction: P2P.Dapp.Request, - with items: some Collection + for interaction: DappToWalletInteraction, + with items: some Collection ) { switch interaction.items { - case .request: + case .authorizedRequest, .unauthorizedRequest: // NB: variadic generics + native case paths should greatly help to simplify this "picking" logic - var auth: AuthRequestResponseItem? = nil - var oneTimeAccounts: AccountsRequestResponseItem? = nil - var ongoingAccounts: AccountsRequestResponseItem? = nil - var oneTimePersonaData: PersonaDataRequestResponseItem? = nil - var ongoingPersonaData: PersonaDataRequestResponseItem? = nil + var auth: WalletToDappInteractionAuthRequestResponseItem? = nil + var oneTimeAccounts: WalletToDappInteractionAccountsRequestResponseItem? = nil + var ongoingAccounts: WalletToDappInteractionAccountsRequestResponseItem? = nil + var oneTimePersonaData: WalletToDappInteractionPersonaDataRequestResponseItem? = nil + var ongoingPersonaData: WalletToDappInteractionPersonaDataRequestResponseItem? = nil for item in items { switch item { @@ -210,31 +209,31 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse { if let auth { self.init( - interactionId: interaction.id, - items: .request( - .authorized(.init( + interactionId: interaction.interactionId, + items: .authorizedRequest( + .init( auth: auth, ongoingAccounts: ongoingAccounts, ongoingPersonaData: ongoingPersonaData, oneTimeAccounts: oneTimeAccounts, oneTimePersonaData: oneTimePersonaData - )) + ) ) ) } else { self.init( - interactionId: interaction.id, - items: .request( - .unauthorized(.init( + interactionId: interaction.interactionId, + items: .unauthorizedRequest( + .init( oneTimeAccounts: oneTimeAccounts, oneTimePersonaData: oneTimePersonaData - )) + ) ) ) } case .transaction: - var send: SendTransactionResponseItem? = nil + var send: WalletToDappInteractionSendTransactionResponseItem? = nil for item in items { switch item { case .auth, .ongoingAccounts, .ongoingPersonaData, .oneTimeAccounts, .oneTimePersonaData: @@ -250,7 +249,7 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse { } self.init( - interactionId: interaction.id, + interactionId: interaction.interactionId, items: .transaction(.init(send: send)) ) } diff --git a/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift b/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift index 57f802195f..e60fb12ab8 100644 --- a/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift +++ b/RadixWallet/Features/DappInteractionFeature/Interactor/DappInteractor.swift @@ -6,9 +6,9 @@ typealias RequestEnvelope = DappInteractionClient.RequestEnvelope // MARK: Identifiable extension RequestEnvelope: Identifiable { - public typealias ID = P2P.Dapp.Request.ID + public typealias ID = WalletInteractionId public var id: ID { - request.id + request.interactionId } } @@ -36,7 +36,7 @@ struct DappInteractor: Sendable, FeatureReducer { enum ResponseFailureAlertAction: Sendable, Hashable { case cancelButtonTapped(RequestEnvelope) - case retryButtonTapped(P2P.Dapp.Response, for: RequestEnvelope, DappMetadata) + case retryButtonTapped(WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata) } enum InvalidRequestAlertAction: Sendable, Hashable { @@ -48,25 +48,25 @@ struct DappInteractor: Sendable, FeatureReducer { case receivedRequestFromDapp(RequestEnvelope) case presentQueuedRequestIfNeeded case sentResponseToDapp( - P2P.Dapp.Response, + WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata, IntentHash? ) case failedToSendResponseToDapp( - P2P.Dapp.Response, + WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata, reason: String ) case presentResponseFailureAlert( - P2P.Dapp.Response, + WalletToDappInteractionResponse, for: RequestEnvelope, DappMetadata, reason: String ) case presentResponseSuccessView(DappMetadata, IntentHash?) case presentInvalidRequest( - P2P.Dapp.RequestUnvalidated, + DappToWalletInteractionUnvalidated, reason: DappInteractionClient.ValidatedDappRequest.InvalidRequestReason, route: P2P.Route, isDeveloperModeEnabled: Bool @@ -217,9 +217,9 @@ struct DappInteractor: Sendable, FeatureReducer { return .none case let .presentInvalidRequest(invalidRequest, reason, route, isDeveloperModeEnabled): - let response = P2P.Dapp.Response.WalletInteractionFailureResponse( - interactionId: invalidRequest.id, - errorType: reason.interactionResponseError, + let response = WalletToDappInteractionFailureResponse( + interactionId: invalidRequest.interactionId, + error: reason.interactionResponseError, message: reason.responseMessage() ) @@ -257,7 +257,7 @@ struct DappInteractor: Sendable, FeatureReducer { loggerGlobal.error(.init(stringLiteral: message)) return .none } - guard let request = state.requestQueue[id: dappInteraction.interaction.id] else { + guard let request = state.requestQueue[id: dappInteraction.interaction.interactionId] else { let message = "The request for this interaction is missing" assertionFailure(message) loggerGlobal.error(.init(stringLiteral: message)) @@ -300,7 +300,7 @@ struct DappInteractor: Sendable, FeatureReducer { } func sendResponseToDappEffect( - _ responseToDapp: P2P.Dapp.Response, + _ responseToDapp: WalletToDappInteractionResponse, for request: RequestEnvelope, dappMetadata: DappMetadata ) -> Effect { @@ -356,7 +356,7 @@ struct DappInteractor: Sendable, FeatureReducer { } extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason { - var interactionResponseError: P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType { + var interactionResponseError: DappWalletInteractionErrorType { switch self { case .incompatibleVersion: .incompatibleVersion @@ -365,7 +365,7 @@ extension DappInteractionClient.ValidatedDappRequest.InvalidRequestReason { case .invalidDappDefinitionAddress: .unknownDappDefinitionAddress case .invalidOrigin: - .invalidOriginURL + .invalidOriginUrl case .dAppValidationError: .unknownDappDefinitionAddress case .badContent: diff --git a/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift b/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift index a8c99d3ef8..b25526ff8d 100644 --- a/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift +++ b/RadixWallet/Features/TransactionReviewFeature/TransactionReview+View.swift @@ -798,7 +798,7 @@ struct TransactionReview_Previews: PreviewProvider { extension TransactionReview.State { public static let previewValue: Self = .init( - unvalidatedManifest: try! .init(manifest: .previewValue), + unvalidatedManifest: .sample, nonce: .secureRandom(), signTransactionPurpose: .manifestFromDapp, message: .none, diff --git a/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargon+SharedPersonaData.swift b/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargon+SharedPersonaData.swift index b6abbb7eaf..c8bd2aa0ec 100644 --- a/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargon+SharedPersonaData.swift +++ b/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargon+SharedPersonaData.swift @@ -48,15 +48,15 @@ extension SharedPersonaData { extension SharedPersonaData { init( - requested: P2P.Dapp.Request.PersonaDataRequestItem, + requested: DappToWalletInteractionPersonaDataRequestItem, persona: Persona, - provided: P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem + provided: WalletToDappInteractionPersonaDataRequestResponseItem ) throws { func extractSharedCollection( - requestedKeyPath: KeyPath, + requestedKeyPath: KeyPath, personaDataKeyPath: KeyPath, personaDataEntryKind: PersonaData.Entry.Kind, - providedKeyPath: KeyPath?> + providedKeyPath: KeyPath ) throws -> SharedToDappWithPersonaIDsOfPersonaDataEntries? { // Check if incoming Dapp requests the persona data entry kind guard @@ -70,13 +70,13 @@ extension SharedPersonaData { let entriesSavedInPersona: [IdentifiedElement] = persona.personaData[keyPath: personaDataKeyPath] // Ensure the response we plan to send back to Dapp contains the persona data entries as well (else discrepancy in DappInteractionFlow) - guard let providedEntries: OrderedSet = provided[keyPath: providedKeyPath] else { + guard let providedEntries: [IdentifiedElement.Value] = provided[keyPath: providedKeyPath] else { throw SavedPersonaDataInPersonaDoesNotContainRequestedPersonaData(kind: personaDataEntryKind) } // Check all entries in response are found in persona let valuesInPersona: Set = Set(entriesSavedInPersona.map(\.value)) - let providedValues = Set(providedEntries.elements) + let providedValues = Set(providedEntries) let allEntriesInResponseWasFoundInPersona = valuesInPersona.isSuperset(of: providedValues) guard allEntriesInResponseWasFoundInPersona else { throw SavedPersonaDataInPersonaDoesNotMatchWalletInteractionResponseItem( diff --git a/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargpn+PersonaData.swift b/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargpn+PersonaData.swift index 6172f7adce..057d939ada 100644 --- a/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargpn+PersonaData.swift +++ b/RadixWallet/MIGRATE_TO_SARGON/Stage2/Atoms/Stage2MigrateToSargpn+PersonaData.swift @@ -3,11 +3,11 @@ import Sargon extension PersonaData { public func responseValidation( - for request: P2P.Dapp.Request.PersonaDataRequestItem - ) -> P2P.Dapp.Request.RequestValidation { + for request: DappToWalletInteractionPersonaDataRequestItem + ) -> DappToWalletInteraction.RequestValidation { let allExisting = Dictionary(grouping: entries.map(\.value), by: \.discriminator) - var result = P2P.Dapp.Request.RequestValidation() + var result = DappToWalletInteraction.RequestValidation() for (kind, kindRequest) in request.kindRequests { let values = allExisting[kind] ?? [] switch validate(values, for: kindRequest) { @@ -23,9 +23,9 @@ extension PersonaData { private func validate( _ entries: [PersonaData.Entry], - for request: P2P.Dapp.Request.KindRequest + for request: DappToWalletInteraction.KindRequest ) -> Either< - P2P.Dapp.Request.MissingEntry, + DappToWalletInteraction.MissingEntry, [Entry] > { switch request { diff --git a/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift b/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift index c4c91afd66..e547972313 100644 --- a/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift +++ b/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift @@ -2,9 +2,9 @@ import Foundation import OrderedCollections import Sargon -extension P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem { +extension WalletToDappInteractionPersonaDataRequestResponseItem { init( - personaDataRequested requested: P2P.Dapp.Request.PersonaDataRequestItem, + personaDataRequested requested: DappToWalletInteractionPersonaDataRequestItem, personaData: PersonaData ) throws { try self.init( @@ -14,7 +14,7 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestR guard let personaDataEntry = personaData[keyPath: \.name] else { return nil } return personaDataEntry.value }(), - emailAddresses: { () -> OrderedSet? in + emailAddresses: { () -> [PersonaDataEntryEmailAddress]? in // Check if incoming Dapp requests the persona data entry kind guard let numberOfRequestedElements = requested[keyPath: \.numberOfRequestedEmailAddresses], @@ -29,11 +29,11 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestR guard personaDataEntriesOrderedSet.satisfies(numberOfRequestedElements) else { return nil } - return personaDataEntriesOrderedSet + return personaDataEntriesOrderedSet.elements }(), // OH NOOOOOES! TERRIBLE COPY PASTE, alas, we are gonna migrate this into Sargon very soon. // so please do forgive me. - phoneNumbers: { () -> OrderedSet? in + phoneNumbers: { () -> [PersonaDataEntryPhoneNumber]? in // Check if incoming Dapp requests the persona data entry kind guard let numberOfRequestedElements = requested[keyPath: \.numberOfRequestedPhoneNumbers], @@ -48,7 +48,7 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestR guard personaDataEntriesOrderedSet.satisfies(numberOfRequestedElements) else { return nil } - return personaDataEntriesOrderedSet + return personaDataEntriesOrderedSet.elements }() ) } diff --git a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift index 8700bce397..35fc9a54c1 100644 --- a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift +++ b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift @@ -17,7 +17,7 @@ final class ROLAClientTests: TestCase { private func metadata( origin: String, dAppDefinitionAddress: DappDefinitionAddress - ) -> P2P.Dapp.Request.Metadata { + ) -> DappToWalletInteractionMetadata { try! .init( version: 1, networkId: NetworkID.mainnet, origin: .init(string: origin), @@ -82,7 +82,7 @@ final class ROLAClientTests: TestCase { } func omit_test_generate_rola_payload_hash_vectors() throws { - let origins: [P2P.Dapp.Request.Metadata.Origin] = try [ + let origins: [DappToWalletInteractionMetadata.Origin] = try [ "https://dashboard.rdx.works", "https://stella.swap", "https://rola.xrd", From 2e6ddcc40d8179ede1a734e98c086196a67a0531 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:37:08 +0300 Subject: [PATCH 02/11] cleanup --- RadixWallet.xcodeproj/project.pbxproj | 134 +----------------- .../P2P+RTCMessageFromPeer.swift | 12 +- .../Interaction/DTO/NumberOfAccounts.swift | 4 - .../Requests/AccountsRequestItem.swift | 14 -- .../Requests/AuthRequestItem.swift | 61 -------- .../Requests/PersonaDataRequestItem.swift | 68 --------- .../Requests/ResetRequestItem.swift | 16 --- .../Transactions/SendTransactionRequest.swift | 81 ----------- .../Interaction/WalletInteraction.swift | 95 ------------- .../Interaction/WalletInteractionItems.swift | 86 ----------- .../DTO/P2P+Dapp+Response+Persona.swift | 15 -- .../DTO/WalletAccount.swift | 35 ----- .../P2P+Dapp+Response.swift | 53 ------- .../AccountsRequestResponseItem.swift | 36 ----- .../AuthRequestResponseItem.swift | 74 ---------- .../PersonaDataRequestResponseItem.swift | 21 --- .../SendTransactionResponseItem.swift | 28 ---- .../WalletInteractionFailureResponse.swift | 101 ------------- .../WalletInteractionSuccessResponse.swift | 15 -- ...alletInteractionSuccessResponseItems.swift | 81 ----------- .../P2P/Dapp/Models/P2P+Dapp+Response.swift | 23 +++ .../WalletInteraction+PreviewValue.swift | 19 +-- .../Dapp/Models/WalletInteractionTypes.swift | 35 +++++ 23 files changed, 71 insertions(+), 1036 deletions(-) delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift create mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift rename RadixWallet/Core/SharedModels/P2P/Dapp/Models/{Interaction => }/WalletInteraction+PreviewValue.swift (70%) diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index a7da142ab6..7400d5ab54 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -785,24 +785,7 @@ 48CFC6022ADC10DA00E77A5C /* P2P+LedgerHardwareWallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1682ADC10D900E77A5C /* P2P+LedgerHardwareWallet.swift */; }; 48CFC6032ADC10DA00E77A5C /* P2P+ConnectorExtension+Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1692ADC10D900E77A5C /* P2P+ConnectorExtension+Response.swift */; }; 48CFC6042ADC10DA00E77A5C /* ConnectorExtension+Messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC16A2ADC10D900E77A5C /* ConnectorExtension+Messages.swift */; }; - 48CFC6052ADC10DA00E77A5C /* WalletAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC16F2ADC10D900E77A5C /* WalletAccount.swift */; }; - 48CFC6062ADC10DA00E77A5C /* P2P+Dapp+Response+Persona.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1702ADC10D900E77A5C /* P2P+Dapp+Response+Persona.swift */; }; - 48CFC6072ADC10DA00E77A5C /* WalletInteractionFailureResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1712ADC10D900E77A5C /* WalletInteractionFailureResponse.swift */; }; - 48CFC6082ADC10DA00E77A5C /* AccountsRequestResponseItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1732ADC10D900E77A5C /* AccountsRequestResponseItem.swift */; }; - 48CFC6092ADC10DA00E77A5C /* AuthRequestResponseItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1742ADC10D900E77A5C /* AuthRequestResponseItem.swift */; }; - 48CFC60A2ADC10DA00E77A5C /* PersonaDataRequestResponseItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1752ADC10D900E77A5C /* PersonaDataRequestResponseItem.swift */; }; - 48CFC60B2ADC10DA00E77A5C /* SendTransactionResponseItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1772ADC10D900E77A5C /* SendTransactionResponseItem.swift */; }; - 48CFC60C2ADC10DA00E77A5C /* WalletInteractionSuccessResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1782ADC10D900E77A5C /* WalletInteractionSuccessResponse.swift */; }; - 48CFC60D2ADC10DA00E77A5C /* WalletInteractionSuccessResponseItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1792ADC10D900E77A5C /* WalletInteractionSuccessResponseItems.swift */; }; 48CFC60E2ADC10DA00E77A5C /* P2P+Dapp+Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */; }; - 48CFC60F2ADC10DA00E77A5C /* NumberOfAccounts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC17D2ADC10D900E77A5C /* NumberOfAccounts.swift */; }; - 48CFC6102ADC10DA00E77A5C /* WalletInteraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC17E2ADC10D900E77A5C /* WalletInteraction.swift */; }; - 48CFC6112ADC10DA00E77A5C /* WalletInteractionItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC17F2ADC10D900E77A5C /* WalletInteractionItems.swift */; }; - 48CFC6122ADC10DA00E77A5C /* PersonaDataRequestItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1812ADC10D900E77A5C /* PersonaDataRequestItem.swift */; }; - 48CFC6132ADC10DA00E77A5C /* AuthRequestItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1822ADC10D900E77A5C /* AuthRequestItem.swift */; }; - 48CFC6142ADC10DA00E77A5C /* AccountsRequestItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1832ADC10D900E77A5C /* AccountsRequestItem.swift */; }; - 48CFC6152ADC10DA00E77A5C /* ResetRequestItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1842ADC10D900E77A5C /* ResetRequestItem.swift */; }; - 48CFC6162ADC10DA00E77A5C /* SendTransactionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1862ADC10D900E77A5C /* SendTransactionRequest.swift */; }; 48CFC6172ADC10DA00E77A5C /* WalletInteraction+PreviewValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */; }; 48CFC6192ADC10DA00E77A5C /* P2P.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1892ADC10D900E77A5C /* P2P.swift */; }; 48CFC61B2ADC10DA00E77A5C /* P2P+RTCOutgoingMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC18D2ADC10D900E77A5C /* P2P+RTCOutgoingMessage.swift */; }; @@ -1958,24 +1941,7 @@ 48CFC1682ADC10D900E77A5C /* P2P+LedgerHardwareWallet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+LedgerHardwareWallet.swift"; sourceTree = ""; }; 48CFC1692ADC10D900E77A5C /* P2P+ConnectorExtension+Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+ConnectorExtension+Response.swift"; sourceTree = ""; }; 48CFC16A2ADC10D900E77A5C /* ConnectorExtension+Messages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConnectorExtension+Messages.swift"; sourceTree = ""; }; - 48CFC16F2ADC10D900E77A5C /* WalletAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletAccount.swift; sourceTree = ""; }; - 48CFC1702ADC10D900E77A5C /* P2P+Dapp+Response+Persona.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+Dapp+Response+Persona.swift"; sourceTree = ""; }; - 48CFC1712ADC10D900E77A5C /* WalletInteractionFailureResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletInteractionFailureResponse.swift; sourceTree = ""; }; - 48CFC1732ADC10D900E77A5C /* AccountsRequestResponseItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsRequestResponseItem.swift; sourceTree = ""; }; - 48CFC1742ADC10D900E77A5C /* AuthRequestResponseItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthRequestResponseItem.swift; sourceTree = ""; }; - 48CFC1752ADC10D900E77A5C /* PersonaDataRequestResponseItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersonaDataRequestResponseItem.swift; sourceTree = ""; }; - 48CFC1772ADC10D900E77A5C /* SendTransactionResponseItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTransactionResponseItem.swift; sourceTree = ""; }; - 48CFC1782ADC10D900E77A5C /* WalletInteractionSuccessResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletInteractionSuccessResponse.swift; sourceTree = ""; }; - 48CFC1792ADC10D900E77A5C /* WalletInteractionSuccessResponseItems.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletInteractionSuccessResponseItems.swift; sourceTree = ""; }; 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+Dapp+Response.swift"; sourceTree = ""; }; - 48CFC17D2ADC10D900E77A5C /* NumberOfAccounts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberOfAccounts.swift; sourceTree = ""; }; - 48CFC17E2ADC10D900E77A5C /* WalletInteraction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletInteraction.swift; sourceTree = ""; }; - 48CFC17F2ADC10D900E77A5C /* WalletInteractionItems.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletInteractionItems.swift; sourceTree = ""; }; - 48CFC1812ADC10D900E77A5C /* PersonaDataRequestItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersonaDataRequestItem.swift; sourceTree = ""; }; - 48CFC1822ADC10D900E77A5C /* AuthRequestItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthRequestItem.swift; sourceTree = ""; }; - 48CFC1832ADC10D900E77A5C /* AccountsRequestItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsRequestItem.swift; sourceTree = ""; }; - 48CFC1842ADC10D900E77A5C /* ResetRequestItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResetRequestItem.swift; sourceTree = ""; }; - 48CFC1862ADC10D900E77A5C /* SendTransactionRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTransactionRequest.swift; sourceTree = ""; }; 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WalletInteraction+PreviewValue.swift"; sourceTree = ""; }; 48CFC1882ADC10D900E77A5C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 48CFC1892ADC10D900E77A5C /* P2P.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = P2P.swift; sourceTree = ""; }; @@ -5333,91 +5299,10 @@ isa = PBXGroup; children = ( E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */, - 48CFC16D2ADC10D900E77A5C /* InteractionResponse */, - 48CFC17B2ADC10D900E77A5C /* Interaction */, - ); - path = Models; - sourceTree = ""; - }; - 48CFC16D2ADC10D900E77A5C /* InteractionResponse */ = { - isa = PBXGroup; - children = ( - 48CFC16E2ADC10D900E77A5C /* DTO */, - 48CFC1712ADC10D900E77A5C /* WalletInteractionFailureResponse.swift */, - 48CFC1722ADC10D900E77A5C /* RequestResponses */, - 48CFC1762ADC10D900E77A5C /* TransactionResponses */, - 48CFC1782ADC10D900E77A5C /* WalletInteractionSuccessResponse.swift */, - 48CFC1792ADC10D900E77A5C /* WalletInteractionSuccessResponseItems.swift */, 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */, - ); - path = InteractionResponse; - sourceTree = ""; - }; - 48CFC16E2ADC10D900E77A5C /* DTO */ = { - isa = PBXGroup; - children = ( - 48CFC16F2ADC10D900E77A5C /* WalletAccount.swift */, - 48CFC1702ADC10D900E77A5C /* P2P+Dapp+Response+Persona.swift */, - ); - path = DTO; - sourceTree = ""; - }; - 48CFC1722ADC10D900E77A5C /* RequestResponses */ = { - isa = PBXGroup; - children = ( - 48CFC1732ADC10D900E77A5C /* AccountsRequestResponseItem.swift */, - 48CFC1742ADC10D900E77A5C /* AuthRequestResponseItem.swift */, - 48CFC1752ADC10D900E77A5C /* PersonaDataRequestResponseItem.swift */, - ); - path = RequestResponses; - sourceTree = ""; - }; - 48CFC1762ADC10D900E77A5C /* TransactionResponses */ = { - isa = PBXGroup; - children = ( - 48CFC1772ADC10D900E77A5C /* SendTransactionResponseItem.swift */, - ); - path = TransactionResponses; - sourceTree = ""; - }; - 48CFC17B2ADC10D900E77A5C /* Interaction */ = { - isa = PBXGroup; - children = ( - 48CFC17C2ADC10D900E77A5C /* DTO */, - 48CFC17E2ADC10D900E77A5C /* WalletInteraction.swift */, - 48CFC17F2ADC10D900E77A5C /* WalletInteractionItems.swift */, - 48CFC1802ADC10D900E77A5C /* Requests */, - 48CFC1852ADC10D900E77A5C /* Transactions */, 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */, ); - path = Interaction; - sourceTree = ""; - }; - 48CFC17C2ADC10D900E77A5C /* DTO */ = { - isa = PBXGroup; - children = ( - 48CFC17D2ADC10D900E77A5C /* NumberOfAccounts.swift */, - ); - path = DTO; - sourceTree = ""; - }; - 48CFC1802ADC10D900E77A5C /* Requests */ = { - isa = PBXGroup; - children = ( - 48CFC1812ADC10D900E77A5C /* PersonaDataRequestItem.swift */, - 48CFC1822ADC10D900E77A5C /* AuthRequestItem.swift */, - 48CFC1832ADC10D900E77A5C /* AccountsRequestItem.swift */, - 48CFC1842ADC10D900E77A5C /* ResetRequestItem.swift */, - ); - path = Requests; - sourceTree = ""; - }; - 48CFC1852ADC10D900E77A5C /* Transactions */ = { - isa = PBXGroup; - children = ( - 48CFC1862ADC10D900E77A5C /* SendTransactionRequest.swift */, - ); - path = Transactions; + path = Models; sourceTree = ""; }; 48CFC18A2ADC10D900E77A5C /* Application */ = { @@ -6847,12 +6732,10 @@ 5BC82B6D2BED18A1009AC162 /* FactoryReset+Reducer.swift in Sources */, 48CFC45C2ADC10DA00E77A5C /* P2PLinksClient+Interface.swift in Sources */, 48CFC4BA2ADC10DA00E77A5C /* StateNonFungibleDetailsResponseItem.swift in Sources */, - 48CFC60C2ADC10DA00E77A5C /* WalletInteractionSuccessResponse.swift in Sources */, 48CFC4EA2ADC10DA00E77A5C /* StateEntityFungiblesPageResponse.swift in Sources */, 48CFC5822ADC10DA00E77A5C /* URLFormatterClient+Interface.swift in Sources */, 48CFC2762ADC10D900E77A5C /* P2PLinksFeature+Reducer.swift in Sources */, 48CFC4F02ADC10DA00E77A5C /* StateNonFungibleLocationResponseItem.swift in Sources */, - 48CFC6072ADC10DA00E77A5C /* WalletInteractionFailureResponse.swift in Sources */, 48CFC6172ADC10DA00E77A5C /* WalletInteraction+PreviewValue.swift in Sources */, 48CFC50B2ADC10DA00E77A5C /* PublicKeyHashEcdsaSecp256k1.swift in Sources */, 48CFC3F12ADC10D900E77A5C /* RemoteClientID.swift in Sources */, @@ -6877,7 +6760,6 @@ 48CFC4A42ADC10DA00E77A5C /* ValidatorUptimeCollectionItem.swift in Sources */, 83EE47822AF0EE3C00155F03 /* ProgrammaticScryptoSborValueU16.swift in Sources */, 83D663B02B271D0100D1AB9E /* TruncationMask.swift in Sources */, - 48CFC6102ADC10DA00E77A5C /* WalletInteraction.swift in Sources */, 48CFC3462ADC10D900E77A5C /* Completion.swift in Sources */, 48CFC25A2ADC10D900E77A5C /* OnboardingCoordinator+Reducer.swift in Sources */, 83EE5ED72BE3C16F00B1531D /* EntitySchemaCollectionItem.swift in Sources */, @@ -6928,7 +6810,6 @@ 48CFC4EF2ADC10DA00E77A5C /* MetadataDecimalArrayValue.swift in Sources */, E713204C2BCD372600AE6B3C /* UnknownCaseDecodable.swift in Sources */, 48CFC27A2ADC10D900E77A5C /* App+View.swift in Sources */, - 48CFC6152ADC10DA00E77A5C /* ResetRequestItem.swift in Sources */, E7AE2D0E2C07359500830BAA /* FullScreenOverlayCoordinator+Reducer.swift in Sources */, 48CFC3ED2ADC10D900E77A5C /* DataChannelMessage+Codable.swift in Sources */, 48CFC5DA2ADC10DA00E77A5C /* PresentationDetentIntrinsicHeight.swift in Sources */, @@ -7152,7 +7033,6 @@ A4B017F72B4C099D00B42B8E /* TransactionReview+DepositSettingView.swift in Sources */, 834B651F2B972E5100B7E1E8 /* NPSSurvey.swift in Sources */, 48CFC26A2ADC10D900E77A5C /* Signing+View.swift in Sources */, - 48CFC60D2ADC10DA00E77A5C /* WalletInteractionSuccessResponseItems.swift in Sources */, 48CFC3262ADC10D900E77A5C /* LocalNetworkPermission+Reducer.swift in Sources */, E657773D2B0BAB35002DB237 /* RecoverWalletControlWithBDFSOnly.swift in Sources */, 48CFC4482ADC10DA00E77A5C /* AccountsClient+Test.swift in Sources */, @@ -7160,7 +7040,6 @@ 48CFC4B32ADC10DA00E77A5C /* StateEntityDetailsResponseItemDetailsType.swift in Sources */, 83823EA72B722DB000827211 /* HTTPClient+Interface.swift in Sources */, 48CFC5972ADC10DA00E77A5C /* ToggleView.swift in Sources */, - 48CFC6122ADC10DA00E77A5C /* PersonaDataRequestItem.swift in Sources */, 48CFC4892ADC10DA00E77A5C /* EntityMetadata+GWMetadata.swift in Sources */, 48CFC4FC2ADC10DA00E77A5C /* StateNonFungibleDataRequest.swift in Sources */, 48CFC60E2ADC10DA00E77A5C /* P2P+Dapp+Response.swift in Sources */, @@ -7177,7 +7056,6 @@ 48CFC2A92ADC10D900E77A5C /* DappDetails+View.swift in Sources */, 48CFC52B2ADC10DA00E77A5C /* MetadataU64Value.swift in Sources */, 83EE5EDE2BE3C16F00B1531D /* EntitySchemaCollection.swift in Sources */, - 48CFC60B2ADC10DA00E77A5C /* SendTransactionResponseItem.swift in Sources */, 48CFC37C2ADC10D900E77A5C /* PoolUnitDetails+View.swift in Sources */, 48CFC5C52ADC10DA00E77A5C /* LoadingView.swift in Sources */, 48CFC59C2ADC10DA00E77A5C /* Button+Extra.swift in Sources */, @@ -7292,7 +7170,6 @@ 48CFC53D2ADC10DA00E77A5C /* MetadataI32ArrayValue.swift in Sources */, A462B5A42B8384FB00C26D20 /* CoreAPI_PlaintextMessageContent.swift in Sources */, 48CFC4312ADC10DA00E77A5C /* PublicKey+Extensions.swift in Sources */, - 48CFC6092ADC10DA00E77A5C /* AuthRequestResponseItem.swift in Sources */, 48CFC2CE2ADC10D900E77A5C /* ReceivingAccount+Reducer.swift in Sources */, 48CFC3722ADC10D900E77A5C /* LSUDetails+View.swift in Sources */, 48CFC47E2ADC10DA00E77A5C /* OverlayWindowClient+Live.swift in Sources */, @@ -7427,7 +7304,6 @@ 48CFC53F2ADC10DA00E77A5C /* MetadataU8Value.swift in Sources */, 48CFC4CC2ADC10DA00E77A5C /* Models.swift in Sources */, 83EE5ED62BE3C16F00B1531D /* AccountDepositPreValidationResourceSpecificBehaviourItem.swift in Sources */, - 48CFC6162ADC10DA00E77A5C /* SendTransactionRequest.swift in Sources */, 48CFC3132ADC10D900E77A5C /* CompletionMigrateOlympiaAccountsToBabylon+View.swift in Sources */, 48CFC5512ADC10DA00E77A5C /* StateEntityDetailsResponseFungibleResourceDetails.swift in Sources */, 48CFC51C2ADC10DA00E77A5C /* MetadataI64ArrayValue.swift in Sources */, @@ -7473,7 +7349,6 @@ 48CFC4462ADC10DA00E77A5C /* OnboardingClient+Interface.swift in Sources */, 5B758D5C2BCEC3B200348722 /* Troubleshooting+View.swift in Sources */, 5B758D5D2BCEC3B200348722 /* Troubleshooting.swift in Sources */, - 48CFC60A2ADC10DA00E77A5C /* PersonaDataRequestResponseItem.swift in Sources */, 83EE5EDB2BE3C16F00B1531D /* RoyaltyAmount.swift in Sources */, 48CFC5922ADC10DA00E77A5C /* AccountsClient+Live.swift in Sources */, E6A2D9E12AFA6BFE001857EC /* DeviceFactorSourceControlled.swift in Sources */, @@ -7525,7 +7400,6 @@ 48CFC4792ADC10DA00E77A5C /* LocalAuthenticationClient+Live.swift in Sources */, 48CFC4A62ADC10DA00E77A5C /* MetadataPublicKeyHashArrayValue.swift in Sources */, 48CFC2F42ADC10D900E77A5C /* IntroductionToPersonas+View.swift in Sources */, - 48CFC6142ADC10DA00E77A5C /* AccountsRequestItem.swift in Sources */, 48CFC5452ADC10DA00E77A5C /* ResultSetCursorMixin.swift in Sources */, A4ECE2742BEEAFFC00468BF6 /* SecurityCenterClient+Test.swift in Sources */, 48CFC5BB2ADC10DA00E77A5C /* PlainListRow.swift in Sources */, @@ -7601,7 +7475,6 @@ A43F1E282BC96F27001DD3FA /* SecurityCenter+View.swift in Sources */, 48CFC52D2ADC10DA00E77A5C /* InvalidRequestError.swift in Sources */, A462B5B42B8F25BC00C26D20 /* ResourceBalance.swift in Sources */, - 48CFC6052ADC10DA00E77A5C /* WalletAccount.swift in Sources */, 48CFC5CF2ADC10DA00E77A5C /* LinearGradients.swift in Sources */, 83EE478D2AF0EE3C00155F03 /* ProgrammaticScryptoSborValueKind.swift in Sources */, 48CFC3F82ADC10D900E77A5C /* IncomingMessage+Decoding.swift in Sources */, @@ -7633,7 +7506,6 @@ 48CFC5262ADC10DA00E77A5C /* NonFungibleIdsCollection.swift in Sources */, 48CFC4DB2ADC10DA00E77A5C /* MetadataPublicKeyArrayValue.swift in Sources */, 48CFC4AC2ADC10DA00E77A5C /* MetadataGlobalAddressValue.swift in Sources */, - 48CFC6062ADC10DA00E77A5C /* P2P+Dapp+Response+Persona.swift in Sources */, 48CFC4AE2ADC10DA00E77A5C /* TransactionCommittedDetailsRequest.swift in Sources */, 48CFC3012ADC10D900E77A5C /* DebugSettingsCoordinator+Reducer.swift in Sources */, 83377A052B9DDB5C00D8AA36 /* NPSSurveyClient+Live.swift in Sources */, @@ -7660,7 +7532,6 @@ 83856D632B0279080026452A /* VerifyMnemonic.swift in Sources */, 48CFC5332ADC10DA00E77A5C /* StateEntityNonFungibleResourceVaultsPageRequest.swift in Sources */, 48CFC48A2ADC10DA00E77A5C /* OnLedgerEntitiesClient+CreateEntity.swift in Sources */, - 48CFC6132ADC10DA00E77A5C /* AuthRequestItem.swift in Sources */, A4ECE27A2BEEB01800468BF6 /* CloudBackupClient+Live.swift in Sources */, 8338B9E52AFAB20700D1D8EA /* TransactionFee.swift in Sources */, 48CFC28C2ADC10D900E77A5C /* TransactionReviewProofs.swift in Sources */, @@ -7693,7 +7564,6 @@ 48CFC5582ADC10DA00E77A5C /* NonFungibleIdType.swift in Sources */, 48CFC57D2ADC10DA00E77A5C /* StateEntityDetailsResponseItemDetails.swift in Sources */, 48CFC5802ADC10DA00E77A5C /* BackupsClient+Live.swift in Sources */, - 48CFC6082ADC10DA00E77A5C /* AccountsRequestResponseItem.swift in Sources */, 48AE39E82B0CBEA800813CF3 /* SelectInactiveAccountsToAdd.swift in Sources */, 48CFC59A2ADC10DA00E77A5C /* HitTargetSize.swift in Sources */, 48CFC2C12ADC10D900E77A5C /* AssetTransfer+Reducer.swift in Sources */, @@ -7733,7 +7603,6 @@ 48CFC5C22ADC10DA00E77A5C /* Shapes.swift in Sources */, 48CFC5BA2ADC10DA00E77A5C /* RadioButton.swift in Sources */, 48CFC4AB2ADC10DA00E77A5C /* NonFungibleResourcesCollectionItemVaultAggregatedVaultItem.swift in Sources */, - 48CFC60F2ADC10DA00E77A5C /* NumberOfAccounts.swift in Sources */, 48CFC52C2ADC10DA00E77A5C /* PublicKeyEcdsaSecp256k1.swift in Sources */, 48CFC5852ADC10DA00E77A5C /* SecureStorageClient+Live.swift in Sources */, 48CFC2C52ADC10D900E77A5C /* AssetTransferMessage+Reducer.swift in Sources */, @@ -7854,7 +7723,6 @@ 48D5F3932BD8DDB9000DE964 /* DebugSettingsCoordinator+View.swift in Sources */, 48CFC5662ADC10DA00E77A5C /* StateNonFungibleDataResponse.swift in Sources */, 48CFC2512ADC10D900E77A5C /* GatewaySettings+Reducer.swift in Sources */, - 48CFC6112ADC10DA00E77A5C /* WalletInteractionItems.swift in Sources */, 480E50D52B0C881000FC21D5 /* RecoverWalletWithoutProfileCoordinator+View.swift in Sources */, 48CFC45D2ADC10DA00E77A5C /* TransactionClient+TestValue.swift in Sources */, 48CFC2F32ADC10D900E77A5C /* CreatePersonaCoordinator+Models.swift in Sources */, diff --git a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift index d4c3d89b89..6d0b2a1db3 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift @@ -22,7 +22,17 @@ extension P2P { extension P2P.RTCMessageFromPeer.Request { public init(from decoder: Decoder) throws { - self = try .dapp(.init(from: decoder)) + @Dependency(\.jsonEncoder) var jsonEncoder + + let container = try decoder.singleValueContainer() + let jsonValue = try container.decode(JSONValue.self) + let jsonData = try jsonEncoder().encode(jsonValue.dictionary ?? [:]) + + guard let jsonString = String(data: jsonData, encoding: .utf8) else { + throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid data") + } + + self = try .dapp(.init(jsonString: jsonString)) } } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift deleted file mode 100644 index ef6c0d6a51..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/DTO/NumberOfAccounts.swift +++ /dev/null @@ -1,4 +0,0 @@ - -// extension P2P.Dapp.Request { -public typealias NumberOfAccounts = RequestedQuantity -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift deleted file mode 100644 index 3accb79cc6..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AccountsRequestItem.swift +++ /dev/null @@ -1,14 +0,0 @@ -// extension P2P.Dapp.Request { -// public struct AccountsRequestItem: Sendable, Hashable, Decodable { -// public let numberOfAccounts: NumberOfAccounts -// public let challenge: DappToWalletInteraction.AuthChallengeNonce? -// -// public init( -// numberOfAccounts: NumberOfAccounts, -// challenge: DappToWalletInteraction.AuthChallengeNonce? -// ) { -// self.numberOfAccounts = numberOfAccounts -// self.challenge = challenge -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift deleted file mode 100644 index aab08d4292..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/AuthRequestItem.swift +++ /dev/null @@ -1,61 +0,0 @@ -// MARK: - P2P.Dapp.Request.AuthRequestItem -// extension P2P.Dapp.Request { -// public enum AuthRequestItem: Sendable, Hashable, Decodable { -// private enum CodingKeys: String, CodingKey { -// case discriminator -// } -// -// enum Discriminator: String, Decodable { -// case loginWithoutChallenge -// case loginWithChallenge -// case usePersona -// } -// -// case login(AuthLoginRequestItem) -// case usePersona(AuthUsePersonaRequestItem) -// -// public init(from decoder: Decoder) throws { -// let container = try decoder.container(keyedBy: CodingKeys.self) -// let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) -// switch discriminator { -// case .loginWithoutChallenge: -// self = .login(.withoutChallenge) -// case .loginWithChallenge: -// self = try .login(.withChallenge(.init(from: decoder))) -// case .usePersona: -// self = try .usePersona(.init(from: decoder)) -// } -// } -// } -// } - -// MARK: - P2P.Dapp.Request.AuthLoginRequestItem -// extension P2P.Dapp.Request { -// public enum AuthLoginRequestItem: Sendable, Hashable { -// case withoutChallenge -// case withChallenge(AuthLoginWithChallengeRequestItem) -// } -// } - -// MARK: - P2P.Dapp.Request.AuthLoginWithChallengeRequestItem -// extension P2P.Dapp.Request { -// public struct AuthLoginWithChallengeRequestItem: Sendable, Hashable, Decodable { -// /// A 32 bytes nonce used as a challenge -// public let challenge: DappToWalletInteraction.AuthChallengeNonce -// -// public init(challenge: DappToWalletInteraction.AuthChallengeNonce) { -// self.challenge = challenge -// } -// } -// } - -// MARK: - P2P.Dapp.Request.AuthUsePersonaRequestItem -// extension P2P.Dapp.Request { -// public struct AuthUsePersonaRequestItem: Sendable, Hashable, Decodable { -// public let identityAddress: IdentityAddress -// -// public init(identityAddress: IdentityAddress) { -// self.identityAddress = identityAddress -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift deleted file mode 100644 index 375dc0d3ff..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/PersonaDataRequestItem.swift +++ /dev/null @@ -1,68 +0,0 @@ -import Sargon - -// MARK: - DappToWalletInteraction.RequestValidation -// DappToWalletInteractionPersonaDataRequestItem - -// extension P2P.Dapp.Request { -// public struct PersonaDataRequestItem: Sendable, Hashable, Decodable { -// public let isRequestingName: Bool? -// public let numberOfRequestedEmailAddresses: RequestedQuantity? -// public let numberOfRequestedPhoneNumbers: RequestedQuantity? -// -// public init( -// isRequestingName: Bool?, -// numberOfRequestedEmailAddresses: RequestedQuantity? = nil, -// numberOfRequestedPhoneNumbers: RequestedQuantity? = nil -// ) { -// self.isRequestingName = isRequestingName -// self.numberOfRequestedEmailAddresses = numberOfRequestedEmailAddresses -// self.numberOfRequestedPhoneNumbers = numberOfRequestedPhoneNumbers -// } -// -// public var kindRequests: [PersonaData.Entry.Kind: KindRequest] { -// var result: [PersonaData.Entry.Kind: KindRequest] = [:] -// if isRequestingName == true { -// result[.fullName] = .entry -// } -// if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { -// result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) -// } -// if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { -// result[.emailAddress] = .number(numberOfRequestedEmailAddresses) -// } -// return result -// } -// } -// } - -extension DappToWalletInteraction { - public struct RequestValidation: Sendable, Hashable { - public var missingEntries: [PersonaData.Entry.Kind: MissingEntry] = [:] - public var existingRequestedEntries: [PersonaData.Entry.Kind: [PersonaData.Entry]] = [:] - - public var response: WalletToDappInteractionPersonaDataRequestResponseItem? { - guard missingEntries.isEmpty else { return nil } - return try? .init( - name: existingRequestedEntries.extract(.fullName), - emailAddresses: existingRequestedEntries.extract(.emailAddress)?.elements, - phoneNumbers: existingRequestedEntries.extract(.phoneNumber)?.elements - ) - } - } -} - -private extension [PersonaData.Entry.Kind: [PersonaData.Entry]] { - func extract(_ kind: PersonaData.Entry.Kind, as: F.Type = F.self) throws -> F? where F: PersonaDataEntryProtocol { - try self[kind]?.first.map { try $0.extract(as: F.self) } - } - - func extract(_ kind: PersonaData.Entry.Kind, as: F.Type = F.self) throws -> OrderedSet? where F: PersonaDataEntryProtocol { - try self[kind].map { try $0.extract() } - } -} - -private extension [PersonaData.Entry] { - func extract(as _: F.Type = F.self) throws -> OrderedSet where F: PersonaDataEntryProtocol { - try .init(validating: map { try $0.extract() }) - } -} diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift deleted file mode 100644 index a05f71ccbe..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Requests/ResetRequestItem.swift +++ /dev/null @@ -1,16 +0,0 @@ - -// MARK: - P2P.Dapp.Request.ResetRequestItem -// extension P2P.Dapp.Request { -// public struct ResetRequestItem: Sendable, Hashable, Decodable { -// public let accounts: Bool -// public let personaData: Bool -// -// public init( -// accounts: Bool, -// personaData: Bool -// ) { -// self.accounts = accounts -// self.personaData = personaData -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift deleted file mode 100644 index c2f5a7c5da..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/Transactions/SendTransactionRequest.swift +++ /dev/null @@ -1,81 +0,0 @@ -// MARK: - UnvalidatedTransactionManifest -// public struct UnvalidatedTransactionManifest: Sendable, Hashable { -// public let transactionManifestString: String -// public let blobs: Blobs -// -// public init(transactionManifestString: String, blobsBytes: [Data]) { -// self.transactionManifestString = transactionManifestString -// self.blobs = Blobs(blobsBytes.map(Blob.init(data:))) -// } -// -// public init(manifest: TransactionManifest) { -// self.transactionManifestString = manifest.instructionsString -// self.blobs = manifest.blobs -// } -// -// public func transactionManifest( -// onNetwork networkID: NetworkID -// ) throws -> TransactionManifest { -// try .init( -// instructionsString: transactionManifestString, -// networkID: networkID, -// blobs: blobs -// ) -// } -// } - -// MARK: - P2P.Dapp.Request.SendTransactionItem -// extension P2P.Dapp.Request { -// public struct SendTransactionItem: Sendable, Hashable, Decodable { -// public let unvalidatedManifest: UnvalidatedTransactionManifest -// public let version: TXVersion -// public let message: String? -// -// public init( -// version: TXVersion, -// unvalidatedManifest: UnvalidatedTransactionManifest, -// message: String? -// ) { -// self.version = version -// self.unvalidatedManifest = unvalidatedManifest -// self.message = message -// } -// -// public init( -// version: TXVersion = .default, -// transactionManifest: TransactionManifest, -// message: String? = nil -// ) { -// self.init( -// version: version, -// unvalidatedManifest: .init(manifest: transactionManifest), -// message: message -// ) -// } -// -// private enum CodingKeys: String, CodingKey { -// case transactionManifestString = "transactionManifest" -// case version -// case blobsHex = "blobs" -// case message -// } -// -// public init(from decoder: Decoder) throws { -// let container = try decoder.container(keyedBy: CodingKeys.self) -// -// let manifestString = try container.decode(String.self, forKey: .transactionManifestString) -// let blobsHex = try container.decodeIfPresent([String].self, forKey: .blobsHex) ?? [] -// let blobsBytes = try blobsHex.map { try Data(hex: $0) } -// -// try self.init( -// version: container.decode(TXVersion.self, forKey: .version), -// unvalidatedManifest: .init(transactionManifestString: manifestString, blobsBytes: blobsBytes), -// message: container.decodeIfPresent(String.self, forKey: .message) -// ) -// } -// } -// } - -// MARK: - TXVersionTag -// public enum TXVersionTag: Sendable {} -// public typealias TXVersion = Tagged diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift deleted file mode 100644 index 38433c4bb9..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction.swift +++ /dev/null @@ -1,95 +0,0 @@ - -// MARK: - P2P.Dapp.Request -extension P2P.Dapp { -// public typealias Version = Tagged - /// Temporarily disables Dapp communication. - /// Should be reverted as soon as we implement [ABW-1872](https://radixdlt.atlassian.net/browse/ABW-1872) - public static let currentVersion: WalletInteractionVersion = 2 - -// public struct Request: Sendable, Hashable, Identifiable { - //// public typealias ID = Tagged -// - //// public let id: ID -// public let items: DappToWalletInteractionItems -// public let metadata: DappToWalletInteractionMetadata -// -// public init(items: DappToWalletInteractionItems, metadata: DappToWalletInteractionMetadata) { -// self.items = items -// self.metadata = metadata -// } -// } - -// public struct RequestUnvalidated: Sendable, Hashable, Decodable, Identifiable { -// private enum CodingKeys: String, CodingKey { -// case id = "interactionId" -// case items -// case metadata -// } -// -// public typealias ID = Tagged -// -// public let id: ID -// public let items: P2P.Dapp.Request.Items -// public let metadata: P2P.Dapp.Request.MetadataUnvalidated -// -// public init( -// id: ID, -// items: P2P.Dapp.Request.Items, -// metadata: P2P.Dapp.Request.MetadataUnvalidated -// ) { -// self.id = id -// self.items = items -// self.metadata = metadata -// } -// } -} - -// MARK: - DappToWalletInteractionMetadata -// extension P2P.Dapp.Request { -// /// The metadata sent with the request from the Dapp. -// /// not to be confused with `DappMetadata` which can hold a value of this type -// public struct Metadata: Sendable, Hashable, Decodable { -// public typealias Origin = DappOrigin -// -// public let version: P2P.Dapp.Version -// public let networkId: NetworkID -// public let origin: Origin -// public let dAppDefinitionAddress: DappDefinitionAddress -// -// public init( -// version: P2P.Dapp.Version, -// networkId: NetworkID, -// origin: Origin, -// dAppDefinitionAddress: DappDefinitionAddress -// ) { -// self.version = version -// self.networkId = networkId -// self.origin = origin -// self.dAppDefinitionAddress = dAppDefinitionAddress -// } -// } -// } - -// MARK: - P2P.Dapp.Request.MetadataUnvalidated -// extension P2P.Dapp.Request { -// public struct MetadataUnvalidated: Sendable, Hashable, Decodable { -// public let version: P2P.Dapp.Version -// public let networkId: NetworkID -// public let origin: String -// -// /// Non yet validated dAppDefinitionAddresss -// public let dAppDefinitionAddress: String -// -// public init( -// version: P2P.Dapp.Version, -// networkId: NetworkID, -// origin: String, -// dAppDefinitionAddress: String -// ) { -// self.version = version -// self.networkId = networkId -// self.origin = origin -// self.dAppDefinitionAddress = dAppDefinitionAddress -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift deleted file mode 100644 index 1e160973d0..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteractionItems.swift +++ /dev/null @@ -1,86 +0,0 @@ -// MARK: - P2P.Dapp.Request.Items -// extension P2P.Dapp.Request { -// public enum Items: Sendable, Hashable, Decodable { -// private enum CodingKeys: String, CodingKey { -// case discriminator -// } -// -// enum Discriminator: String, Decodable { -// case unauthorizedRequest -// case authorizedRequest -// case transaction -// } -// -// case request(RequestItems) -// case transaction(TransactionItems) -// -// public init(from decoder: Decoder) throws { -// let container = try decoder.container(keyedBy: CodingKeys.self) -// let discriminator = try container.decode(Discriminator.self, forKey: .discriminator) -// switch discriminator { -// case .unauthorizedRequest: -// self = try .request(.unauthorized(.init(from: decoder))) -// case .authorizedRequest: -// self = try .request(.authorized(.init(from: decoder))) -// case .transaction: -// self = try .transaction(.init(from: decoder)) -// } -// } -// } -// } - -// extension P2P.Dapp.Request { -// public enum RequestItems: Sendable, Hashable { -// case unauthorized(UnauthorizedRequestItems) -// case authorized(AuthorizedRequestItems) -// } -// -// public struct UnauthorizedRequestItems: Sendable, Hashable, Decodable { -// public let oneTimeAccounts: AccountsRequestItem? -// public let oneTimePersonaData: PersonaDataRequestItem? -// -// public init( -// oneTimeAccounts: AccountsRequestItem?, -// oneTimePersonaData: PersonaDataRequestItem? -// ) { -// self.oneTimeAccounts = oneTimeAccounts -// self.oneTimePersonaData = oneTimePersonaData -// } -// } -// -// public struct AuthorizedRequestItems: Sendable, Hashable, Decodable { -// public let auth: AuthRequestItem -// public let reset: ResetRequestItem? -// public let ongoingAccounts: AccountsRequestItem? -// public let ongoingPersonaData: PersonaDataRequestItem? -// public let oneTimeAccounts: AccountsRequestItem? -// public let oneTimePersonaData: PersonaDataRequestItem? -// -// public init( -// auth: AuthRequestItem, -// reset: ResetRequestItem? = nil, -// ongoingAccounts: AccountsRequestItem? = nil, -// ongoingPersonaData: PersonaDataRequestItem? = nil, -// oneTimeAccounts: AccountsRequestItem? = nil, -// oneTimePersonaData: PersonaDataRequestItem? = nil -// ) { -// self.auth = auth -// self.reset = reset -// self.ongoingAccounts = ongoingAccounts -// self.ongoingPersonaData = ongoingPersonaData -// self.oneTimeAccounts = oneTimeAccounts -// self.oneTimePersonaData = oneTimePersonaData -// } -// } -// } - -// MARK: - P2P.Dapp.Request.TransactionItems -// extension P2P.Dapp.Request { -// public struct TransactionItems: Sendable, Hashable, Decodable { -// public let send: SendTransactionItem -// -// public init(send: SendTransactionItem) { -// self.send = send -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift deleted file mode 100644 index cbc34cdb62..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/P2P+Dapp+Response+Persona.swift +++ /dev/null @@ -1,15 +0,0 @@ -// extension P2P.Dapp.Response { -// public struct PersonaResponse: Sendable, Hashable, Encodable { -// public let identityAddress: IdentityAddress -// public let label: String -// -// public init(identityAddress: IdentityAddress, label: String) { -// self.identityAddress = identityAddress -// self.label = label -// } -// -// public init(persona: Persona) { -// self.init(identityAddress: persona.address, label: persona.displayName.rawValue) -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift deleted file mode 100644 index 6db5c05482..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/DTO/WalletAccount.swift +++ /dev/null @@ -1,35 +0,0 @@ - -// MARK: - P2P.Dapp.Response.WalletAccount -// extension P2P.Dapp.Response { -/// Response to Dapp from wallet, info about a users account. -/// -/// Called `AccountAddress` in [CAP21][cap] -/// -/// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages -/// -// public struct WalletAccount: Sendable, Hashable, Encodable { -// public let address: AccountAddress -// public let label: DisplayName -// public let appearanceId: AppearanceID -// -// public init( -// accountAddress: AccountAddress, -// label: DisplayName, -// appearanceId: AppearanceID -// ) { -// self.address = accountAddress -// self.label = label -// self.appearanceId = appearanceId -// } -// } - -// public struct AccountProof: Sendable, Hashable, Encodable { -// public let accountAddress: AccountAddress -// public let proof: P2P.Dapp.Response.AuthProof -// -// init(accountWithProof: P2P.Dapp.Response.Accounts.WithProof) { -// self.accountAddress = accountWithProof.account.address -// self.proof = accountWithProof.proof -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift deleted file mode 100644 index 5829219eb8..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/P2P+Dapp+Response.swift +++ /dev/null @@ -1,53 +0,0 @@ -// MARK: - P2P.Dapp -extension P2P { - /// Just a namespace - public enum Dapp {} -} - -// MARK: - SignedAuthChallenge -public struct SignedAuthChallenge: Sendable, Hashable { - public let challenge: DappToWalletInteractionAuthChallengeNonce - public let entitySignatures: Set - public init(challenge: DappToWalletInteractionAuthChallengeNonce, entitySignatures: Set) { - self.challenge = challenge - self.entitySignatures = entitySignatures - } -} - -// MARK: - P2P.Dapp.Response -// extension P2P.Dapp { -// public enum Response: Sendable, Hashable, Encodable { -// private enum CodingKeys: String, CodingKey { -// case discriminator -// } -// -// private enum Discriminator: String, Encodable { -// case success -// case failure -// } -// -// case success(WalletInteractionSuccessResponse) -// case failure(WalletInteractionFailureResponse) -// -// public var id: P2P.Dapp.Request.ID { -// switch self { -// case let .success(response): -// response.interactionId -// case let .failure(response): -// response.interactionId -// } -// } -// -// public func encode(to encoder: Encoder) throws { -// var container = encoder.container(keyedBy: CodingKeys.self) -// switch self { -// case let .success(success): -// try container.encode(Discriminator.success, forKey: .discriminator) -// try success.encode(to: encoder) -// case let .failure(failure): -// try container.encode(Discriminator.failure, forKey: .discriminator) -// try failure.encode(to: encoder) -// } -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift deleted file mode 100644 index cdb134129a..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AccountsRequestResponseItem.swift +++ /dev/null @@ -1,36 +0,0 @@ - -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public struct AccountsRequestResponseItem: Sendable, Hashable, Encodable { -// public let accounts: [P2P.Dapp.Response.WalletAccount] -// -// public let challenge: DappToWalletInteraction.AuthChallengeNonce? -// public let proofs: [P2P.Dapp.Response.AccountProof]? -// -// public init( -// accounts: P2P.Dapp.Response.Accounts -// ) { -// switch accounts { -// case let .withProofOfOwnership(challenge, accountsWithProof): -// self.accounts = accountsWithProof.map(\.account) -// self.challenge = challenge -// self.proofs = accountsWithProof.map(P2P.Dapp.Response.AccountProof.init(accountWithProof:)) -// case let .withoutProofOfOwnership(account): -// self.accounts = account.map(P2P.Dapp.Response.WalletAccount.init(account:)) -// self.challenge = nil -// self.proofs = nil -// } -// } -// -// /// for tests -// private init(withoutProofOfOwnership accounts: [P2P.Dapp.Response.WalletAccount]) { -// self.accounts = accounts -// self.challenge = nil -// self.proofs = nil -// } -// -// /// for tests -// static func withoutProofOfOwnership(accounts: [P2P.Dapp.Response.WalletAccount]) -> Self { -// Self(withoutProofOfOwnership: accounts) -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift deleted file mode 100644 index e82097ba87..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/AuthRequestResponseItem.swift +++ /dev/null @@ -1,74 +0,0 @@ -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AuthRequestResponseItem - -// DappToWalletInteractionAuthRequestItem - -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public enum AuthRequestResponseItem: Sendable, Hashable, Encodable { -// case login(AuthLoginRequestResponseItem) -// case usePersona(AuthUsePersonaRequestResponseItem) -// -// public func encode(to encoder: Encoder) throws { -// switch self { -// case let .login(item): -// try item.encode(to: encoder) -// case let .usePersona(item): -// try item.encode(to: encoder) -// } -// } -// } -// } - -// MARK: - P2P.Dapp.Request.AuthLoginRequestItem -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public enum AuthLoginRequestResponseItem: Sendable, Hashable, Encodable { -// case withoutChallenge(AuthLoginWithoutChallengeRequestResponseItem) -// case withChallenge(AuthLoginWithChallengeRequestResponseItem) -// -// public func encode(to encoder: Encoder) throws { -// switch self { -// case let .withoutChallenge(item): -// try item.encode(to: encoder) -// case let .withChallenge(item): -// try item.encode(to: encoder) -// } -// } -// } - -// public struct AuthLoginWithoutChallengeRequestResponseItem: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithoutChallenge.rawValue -// public let persona: P2P.Dapp.Response.PersonaResponse -// -// public init(persona: P2P.Dapp.Response.PersonaResponse) { -// self.persona = persona -// } -// } - -// public struct AuthLoginWithChallengeRequestResponseItem: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.loginWithChallenge.rawValue -// public let persona: P2P.Dapp.Response.PersonaResponse -// public let challenge: DappToWalletInteraction.AuthChallengeNonce -// public let proof: P2P.Dapp.Response.AuthProof -// -// public init( -// persona: P2P.Dapp.Response.PersonaResponse, -// challenge: DappToWalletInteraction.AuthChallengeNonce, -// proof: P2P.Dapp.Response.AuthProof -// ) { -// self.persona = persona -// self.challenge = challenge -// self.proof = proof -// } -// } -// } - -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AuthUsePersonaRequestResponseItem -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public struct AuthUsePersonaRequestResponseItem: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.AuthRequestItem.Discriminator.usePersona.rawValue -// public let persona: P2P.Dapp.Response.PersonaResponse -// -// public init(persona: P2P.Dapp.Response.PersonaResponse) { -// self.persona = persona -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift deleted file mode 100644 index 139c459c39..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/RequestResponses/PersonaDataRequestResponseItem.swift +++ /dev/null @@ -1,21 +0,0 @@ - -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.PersonaDataRequestResponseItem -// WalletToDappInteractionPersonaDataRequestResponseItem -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public struct PersonaDataRequestResponseItem: Sendable, Hashable, Encodable { -// public let name: PersonaDataEntryName? -// -// public let emailAddresses: OrderedSet? -// public let phoneNumbers: OrderedSet? -// -// public init( -// name: PersonaDataEntryName? = nil, -// emailAddresses: OrderedSet? = nil, -// phoneNumbers: OrderedSet? = nil -// ) { -// self.name = name -// self.emailAddresses = emailAddresses -// self.phoneNumbers = phoneNumbers -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift deleted file mode 100644 index 807416b22e..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/TransactionResponses/SendTransactionResponseItem.swift +++ /dev/null @@ -1,28 +0,0 @@ -// import Sargon -// -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// /// Response to Dapp from wallet, info about a signed and submitted transaction, see [CAP21][cap]. -// /// -// /// [cap]: https://radixdlt.atlassian.net/wiki/spaces/AT/pages/2712895489/CAP-21+Message+format+between+dApp+and+wallet#Wallet-SDK-%E2%86%94%EF%B8%8F-Wallet-messages -// /// -// public struct SendTransactionResponseItem: Sendable, Hashable, Encodable { -// public let transactionIntentHash: IntentHash -// -// enum CodingKeys: CodingKey { -// case transactionIntentHash -// } -// -// public init(txID: IntentHash) { -// transactionIntentHash = txID -// } -// -// public func encode(to encoder: Encoder) throws { -// var container = encoder.container(keyedBy: CodingKeys.self) -// try container.encode( -// // Bech32m encoded transaction ID -// transactionIntentHash.bech32EncodedTxId, -// forKey: .transactionIntentHash -// ) -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift deleted file mode 100644 index 8371b45727..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionFailureResponse.swift +++ /dev/null @@ -1,101 +0,0 @@ -// MARK: - P2P.Dapp.Response.WalletInteractionFailureResponse -// extension P2P.Dapp.Response { -// public struct WalletInteractionFailureResponse: Sendable, Hashable, Encodable { -// private enum CodingKeys: String, CodingKey { -// case interactionId -// case errorType = "error" -// case message -// } -// -// /// *MUST* match an ID from an incoming request from Dapp. -// public let interactionId: P2P.Dapp.Request.ID -// public let errorType: ErrorType -// public let message: String? -// -// public init( -// interactionId: P2P.Dapp.Request.ID, -// errorType: ErrorType, -// message: String? -// ) { -// self.interactionId = interactionId -// self.errorType = errorType -// self.message = message -// } -// } -// } - -// MARK: - P2P.Dapp.Response.WalletInteractionFailureResponse.ErrorType -// extension P2P.Dapp.Response.WalletInteractionFailureResponse { -// TODO: ask if we should do associated values here for `message` construction, -// in which case we'll need to declare discriminators -// public enum ErrorType: String, Sendable, LocalizedError, Hashable, Encodable { -// case rejectedByUser -// case wrongNetwork -// case failedToPrepareTransaction -// case failedToCompileTransaction -// case failedToSignTransaction -// case failedToSubmitTransaction -// case failedToPollSubmittedTransaction -// case failedToFindAccountWithEnoughFundsToLockFee -// case submittedTransactionWasDuplicate -// case submittedTransactionHasFailedTransactionStatus -// case submittedTransactionHasRejectedTransactionStatus -// case wrongAccountType -// case unknownWebsite -// case invalidOriginURL -// case radixJsonNotFound -// case radixJsonUnknownFileFormat -// case unknownDappDefinitionAddress -// case invalidPersona -// case invalidRequest -// case incompatibleVersion -// case failedToSignAuthChallenge -// -// public var errorDescription: String? { -// switch self { -// case .rejectedByUser: -// "Rejected by user" -// case .wrongNetwork: -// "Wrong network" -// case .failedToCompileTransaction: -// "Failed to compile transaction" -// case .failedToPrepareTransaction: -// "Failed to prepare transaction for submission" -// case .failedToSignTransaction: -// "Failed to sign transaction" -// case .failedToSubmitTransaction: -// "Failed to submit transaction" -// case .failedToPollSubmittedTransaction: -// "Failed to poll submitted transaction" -// case .failedToFindAccountWithEnoughFundsToLockFee: -// "Failed to find an account with enough funds to lock fee" -// case .submittedTransactionWasDuplicate: -// "Submitted transaction was a duplicate" -// case .submittedTransactionHasFailedTransactionStatus: -// "Submitted transaction failed" -// case .submittedTransactionHasRejectedTransactionStatus: -// "Submitted transaction was rejected" -// case .wrongAccountType: -// "Expected to find dapp definition account type" -// case .unknownWebsite: -// "Origin does not match any related website" -// case .invalidOriginURL: -// "Invalid origin URL" -// case .radixJsonNotFound: -// "radix.json file is missing" -// case .radixJsonUnknownFileFormat: -// "radix.json file format mismatch " -// case .unknownDappDefinitionAddress: -// "dApp definition address does not match any well known definition address" -// case .invalidPersona: -// "Invalid persona specified by dApp" -// case .invalidRequest: -// "Invalid request" -// case .failedToSignAuthChallenge: -// "Failed to sign auth challenge" -// case .incompatibleVersion: -// "Incompatible versions" -// } -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift deleted file mode 100644 index c64a646246..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponse.swift +++ /dev/null @@ -1,15 +0,0 @@ -// extension P2P.Dapp.Response { -// public struct WalletInteractionSuccessResponse: Sendable, Hashable, Encodable { -// /// *MUST* match an ID from an incoming request from Dapp. -// public let interactionId: P2P.Dapp.Request.ID -// public let items: Items -// -// public init( -// interactionId: P2P.Dapp.Request.ID, -// items: Items -// ) { -// self.interactionId = interactionId -// self.items = items -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift deleted file mode 100644 index 523de670db..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/InteractionResponse/WalletInteractionSuccessResponseItems.swift +++ /dev/null @@ -1,81 +0,0 @@ -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.Items -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public enum Items: Sendable, Hashable, Encodable { -// case request(RequestResponseItems) -// case transaction(TransactionResponseItems) -// -// public func encode(to encoder: Encoder) throws { -// switch self { -// case let .request(items): -// try items.encode(to: encoder) -// case let .transaction(items): -// try items.encode(to: encoder) -// } -// } -// } -// } - -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public enum RequestResponseItems: Sendable, Hashable, Encodable { -// case unauthorized(UnauthorizedRequestResponseItems) -// case authorized(AuthorizedRequestResponseItems) -// -// public func encode(to encoder: Encoder) throws { -// switch self { -// case let .unauthorized(items): -// try items.encode(to: encoder) -// case let .authorized(items): -// try items.encode(to: encoder) -// } -// } -// } - -// public struct UnauthorizedRequestResponseItems: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.Items.Discriminator.unauthorizedRequest.rawValue -// public let oneTimeAccounts: AccountsRequestResponseItem? -// public let oneTimePersonaData: PersonaDataRequestResponseItem? -// -// public init( -// oneTimeAccounts: AccountsRequestResponseItem?, -// oneTimePersonaData: PersonaDataRequestResponseItem? -// ) { -// self.oneTimeAccounts = oneTimeAccounts -// self.oneTimePersonaData = oneTimePersonaData -// } -// } - -// public struct AuthorizedRequestResponseItems: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.Items.Discriminator.authorizedRequest.rawValue -// public let auth: AuthRequestResponseItem -// public let ongoingAccounts: AccountsRequestResponseItem? -// public let ongoingPersonaData: PersonaDataRequestResponseItem? -// public let oneTimeAccounts: AccountsRequestResponseItem? -// public let oneTimePersonaData: PersonaDataRequestResponseItem? -// -// public init( -// auth: AuthRequestResponseItem, -// ongoingAccounts: AccountsRequestResponseItem? = nil, -// ongoingPersonaData: PersonaDataRequestResponseItem? = nil, -// oneTimeAccounts: AccountsRequestResponseItem? = nil, -// oneTimePersonaData: PersonaDataRequestResponseItem? = nil -// ) { -// self.auth = auth -// self.ongoingAccounts = ongoingAccounts -// self.ongoingPersonaData = ongoingPersonaData -// self.oneTimeAccounts = oneTimeAccounts -// self.oneTimePersonaData = oneTimePersonaData -// } -// } -// } - -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.TransactionResponseItems -// extension P2P.Dapp.Response.WalletInteractionSuccessResponse { -// public struct TransactionResponseItems: Sendable, Hashable, Encodable { -// public let discriminator = P2P.Dapp.Request.Items.Discriminator.transaction.rawValue -// public let send: SendTransactionResponseItem -// -// public init(send: P2P.Dapp.Response.WalletInteractionSuccessResponse.SendTransactionResponseItem) { -// self.send = send -// } -// } -// } diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift new file mode 100644 index 0000000000..d0e462df31 --- /dev/null +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift @@ -0,0 +1,23 @@ +// MARK: - P2P.Dapp +extension P2P { + /// Just a namespace + public enum Dapp {} +} + +// From WalletInteraction.swift +extension P2P.Dapp { + // public typealias Version = Tagged + /// Temporarily disables Dapp communication. + /// Should be reverted as soon as we implement [ABW-1872](https://radixdlt.atlassian.net/browse/ABW-1872) + public static let currentVersion: WalletInteractionVersion = 2 +} + +// MARK: - SignedAuthChallenge +public struct SignedAuthChallenge: Sendable, Hashable { + public let challenge: DappToWalletInteractionAuthChallengeNonce + public let entitySignatures: Set + public init(challenge: DappToWalletInteractionAuthChallengeNonce, entitySignatures: Set) { + self.challenge = challenge + self.entitySignatures = entitySignatures + } +} diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift similarity index 70% rename from RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift rename to RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift index 2caf17c74b..14f28bc491 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/Interaction/WalletInteraction+PreviewValue.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift @@ -1,11 +1,4 @@ -// extension DappToWalletInteractionPersonaDataRequestItem { -// public static let previewValue = .sample -// } - -// extension P2P.Dapp.Request.SendTransactionItem { -// public static let previewValue = try! Self(transactionManifest: .previewValue) -// } -// +// #if DEBUG extension WalletInteractionId { public static let previewValue = Self.previewValue0 public static let previewValue0: Self = "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" @@ -15,16 +8,6 @@ extension WalletInteractionId { public static let previewValue4: Self = "A621E1F8-C36C-495A-93FC-0C247A3E6E5F" } -// -// extension DappToWalletInteractionMetadata { -// public static let previewValue = try! Self( -// version: P2P.Dapp.currentVersion, -// networkId: .simulator, -// origin: .init(string: "foo.bar"), -// dAppDefinitionAddress: .init(validatingAddress: "account_tdx_b_1p8ahenyznrqy2w0tyg00r82rwuxys6z8kmrhh37c7maqpydx7p") -// ) -// } -// extension DappToWalletInteraction { public static func previewValueAllRequests() -> Self { .init( diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift index f1e64821a4..795d95a375 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift @@ -16,6 +16,8 @@ extension TxVersion { public static let `default`: Self = 1 } +public typealias NumberOfAccounts = RequestedQuantity + extension WalletToDappInteractionResponse { public var interactionId: WalletInteractionId { switch self { @@ -156,3 +158,36 @@ extension DappToWalletInteractionPersonaDataRequestItem { return result } } + +// MARK: - DappToWalletInteraction.RequestValidation +extension DappToWalletInteraction { + public struct RequestValidation: Sendable, Hashable { + public var missingEntries: [PersonaData.Entry.Kind: MissingEntry] = [:] + public var existingRequestedEntries: [PersonaData.Entry.Kind: [PersonaData.Entry]] = [:] + + public var response: WalletToDappInteractionPersonaDataRequestResponseItem? { + guard missingEntries.isEmpty else { return nil } + return try? .init( + name: existingRequestedEntries.extract(.fullName), + emailAddresses: existingRequestedEntries.extract(.emailAddress)?.elements, + phoneNumbers: existingRequestedEntries.extract(.phoneNumber)?.elements + ) + } + } +} + +private extension [PersonaData.Entry.Kind: [PersonaData.Entry]] { + func extract(_ kind: PersonaData.Entry.Kind, as: F.Type = F.self) throws -> F? where F: PersonaDataEntryProtocol { + try self[kind]?.first.map { try $0.extract(as: F.self) } + } + + func extract(_ kind: PersonaData.Entry.Kind, as: F.Type = F.self) throws -> OrderedSet? where F: PersonaDataEntryProtocol { + try self[kind].map { try $0.extract() } + } +} + +private extension [PersonaData.Entry] { + func extract(as _: F.Type = F.self) throws -> OrderedSet where F: PersonaDataEntryProtocol { + try .init(validating: map { try $0.extract() }) + } +} From 0428f159b943cecff48e8220e113080a7cbd117a Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 08:55:38 +0300 Subject: [PATCH 03/11] cleanup --- .../DappInteractionClient+Live.swift | 20 ------------------- .../Children/Login/Coordinator/Login.swift | 4 ++-- .../Coordinator/DappInteractionModels.swift | 6 +----- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift index dfd7bacb79..c98ce3a62d 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift @@ -122,26 +122,6 @@ extension DappInteractionClient { break } -// if case let .request(readRequest) = nonValidated.items { -// switch readRequest { -// case let .authorized(authorized): -// if authorized.oneTimeAccounts?.numberOfAccounts.isValid == false { -// return invalidRequest(.badContent(.numberOfAccountsInvalid)) -// } -// if authorized.ongoingAccounts?.numberOfAccounts.isValid == false { -// return invalidRequest(.badContent(.numberOfAccountsInvalid)) -// } -// case let .unauthorized(unauthorized): -// if unauthorized.oneTimeAccounts?.numberOfAccounts.isValid == false { -// return invalidRequest(.badContent(.numberOfAccountsInvalid)) -// } -// } -// } - - // guard let origin = try? DappOrigin(string: nonvalidatedMeta.origin.absoluteString) else { - // return invalidRequest(.invalidOrigin(invalidURLString: nonvalidatedMeta.origin.absoluteString)) -// } - let metadataValidDappDefAddress = DappToWalletInteractionMetadata( version: nonvalidatedMeta.version, networkId: nonvalidatedMeta.networkId, diff --git a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift index 153c80b3c3..c2bc314b02 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/Login/Coordinator/Login.swift @@ -6,7 +6,7 @@ import SwiftUI struct Login: Sendable, FeatureReducer { struct State: Sendable, Hashable { let dappMetadata: DappMetadata - let loginRequest: DappToWalletInteractionAuthRequestItem // P2P.Dapp.Request.AuthLoginRequestItem + let loginRequest: DappToWalletInteractionAuthRequestItem var personaPrimacy: PersonaPrimacy? = nil @@ -21,7 +21,7 @@ struct Login: Sendable, FeatureReducer { init( dappMetadata: DappMetadata, - loginRequest: DappToWalletInteractionAuthRequestItem, // P2P.Dapp.Request.AuthLoginRequestItem + loginRequest: DappToWalletInteractionAuthRequestItem, personaPrimacy: PersonaPrimacy? = nil ) { self.dappMetadata = dappMetadata diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift index 11432f1780..828e357176 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift @@ -5,10 +5,6 @@ import SwiftUI enum DappInteraction {} // MARK: - DappMetadata -// extension DappInteraction { -// typealias NumberOfAccounts = P2P.Dapp.Request.NumberOfAccounts -// } - /// Metadata for a dapp, either from a request or fetched from ledger. /// not to be confused with `DappToWalletInteractionMetadata` which is the /// associated value of one of the cases of this enum. @@ -89,7 +85,7 @@ extension DappMetadata { #if DEBUG extension DappMetadata { static let previewValue: Self = try! .ledger(.init( - origin: .wallet, // .init(string: "https://radfi.com"), + origin: .init(string: "https://radfi.com")!, dAppDefinintionAddress: .init(validatingAddress: "account_tdx_b_1p95nal0nmrqyl5r4phcspg8ahwnamaduzdd3kaklw3vqeavrwa"), name: "Collabo.Fi", description: "A very collaby finance dapp", From d503e4234f083cee0143fc91896c8de4e0ce9332 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:03:54 +0300 Subject: [PATCH 04/11] wip --- RadixWallet.xcodeproj/project.pbxproj | 1 - .../xcshareddata/swiftpm/Package.resolved | 2 +- .../DappInteractionClient+Interfce.swift | 18 ++++++++++++++++++ .../Dapp/Models/WalletInteractionTypes.swift | 18 ------------------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 091a663c9b..8511886d15 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -7541,7 +7541,6 @@ 48CFC5582ADC10DA00E77A5C /* NonFungibleIdType.swift in Sources */, 48CFC57D2ADC10DA00E77A5C /* StateEntityDetailsResponseItemDetails.swift in Sources */, 48CFC5802ADC10DA00E77A5C /* TransportProfileClient+Live.swift in Sources */, - 48CFC6082ADC10DA00E77A5C /* AccountsRequestResponseItem.swift in Sources */, 48AE39E82B0CBEA800813CF3 /* SelectInactiveAccountsToAdd.swift in Sources */, 48CFC59A2ADC10DA00E77A5C /* HitTargetSize.swift in Sources */, 48CFC2C12ADC10D900E77A5C /* AssetTransfer+Reducer.swift in Sources */, diff --git a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index eee24e2200..3104c93cd1 100644 --- a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "1d033d2d9728e181322e687c87550e30c6bcdac33f59fe631e1e37780502d076", + "originHash" : "5f630ffa75effc63039120c716322c04a75eafccebb0ba925d9f0ddb618a9efb", "pins" : [ { "identity" : "anycodable", diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift index 5d11d942d0..7b2e72ff08 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Interfce.swift @@ -25,6 +25,24 @@ extension DappInteractionClient { public typealias CompleteInteraction = @Sendable (P2P.RTCOutgoingMessage) async throws -> Void } +extension WalletInteractionId { + public static func walletInteractionID(for interaction: DappInteractionClient.WalletInteraction) -> Self { + "\(interaction.rawValue)_\(UUID().uuidString)" + } + + public var isWalletAccountDepositSettingsInteraction: Bool { + hasPrefix(DappInteractionClient.WalletInteraction.accountDepositSettings.rawValue) + } + + public var isWalletAccountTransferInteraction: Bool { + hasPrefix(DappInteractionClient.WalletInteraction.accountTransfer.rawValue) + } + + public var isWalletInteraction: Bool { + isWalletAccountTransferInteraction || isWalletAccountDepositSettingsInteraction + } +} + extension DappInteractionClient { public struct RequestEnvelope: Sendable, Hashable { public let route: P2P.Route diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift index 795d95a375..c4f7319987 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift @@ -113,24 +113,6 @@ extension DappWalletInteractionPersona { } } -extension WalletInteractionId { - public static func walletInteractionID(for interaction: DappInteractionClient.WalletInteraction) -> Self { - "\(interaction.rawValue)_\(UUID().uuidString)" - } - - public var isWalletAccountDepositSettingsInteraction: Bool { - hasPrefix(DappInteractionClient.WalletInteraction.accountDepositSettings.rawValue) - } - - public var isWalletAccountTransferInteraction: Bool { - hasPrefix(DappInteractionClient.WalletInteraction.accountTransfer.rawValue) - } - - public var isWalletInteraction: Bool { - isWalletAccountTransferInteraction || isWalletAccountDepositSettingsInteraction - } -} - extension DappToWalletInteraction { public enum MissingEntry: Sendable, Hashable { case missingEntry From ffd0fb7659c89f4581c2351d51692a6d2396cced Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:42:48 +0300 Subject: [PATCH 05/11] wip --- RadixWallet.xcodeproj/project.pbxproj | 16 ++--- .../DappInteractionClient+Live.swift | 6 +- .../P2P+RTCIncomingMessage.swift | 2 +- .../P2P/Dapp/Models/P2P+Dapp+Response.swift | 23 ------ ...ift => WalletInteraction+Extensions.swift} | 4 ++ .../WalletInteraction+PreviewValue.swift | 71 ++++++++++++------- .../DappInteractionLoading+View.swift | 2 +- .../Coordinator/DappInteractionModels.swift | 4 +- ...1MigrateToSargon+SignedAuthChallenge.swift | 12 ++++ 9 files changed, 77 insertions(+), 63 deletions(-) delete mode 100644 RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift rename RadixWallet/Core/SharedModels/P2P/Dapp/Models/{WalletInteractionTypes.swift => WalletInteraction+Extensions.swift} (98%) create mode 100644 RadixWallet/MIGRATE_TO_SARGON/Stage1/Stage1MigrateToSargon+SignedAuthChallenge.swift diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 8511886d15..335155e261 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -782,7 +782,6 @@ 48CFC6022ADC10DA00E77A5C /* P2P+LedgerHardwareWallet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1682ADC10D900E77A5C /* P2P+LedgerHardwareWallet.swift */; }; 48CFC6032ADC10DA00E77A5C /* P2P+ConnectorExtension+Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1692ADC10D900E77A5C /* P2P+ConnectorExtension+Response.swift */; }; 48CFC6042ADC10DA00E77A5C /* ConnectorExtension+Messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC16A2ADC10D900E77A5C /* ConnectorExtension+Messages.swift */; }; - 48CFC60E2ADC10DA00E77A5C /* P2P+Dapp+Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */; }; 48CFC6172ADC10DA00E77A5C /* WalletInteraction+PreviewValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */; }; 48CFC6192ADC10DA00E77A5C /* P2P.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC1892ADC10D900E77A5C /* P2P.swift */; }; 48CFC61B2ADC10DA00E77A5C /* P2P+RTCOutgoingMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48CFC18D2ADC10D900E77A5C /* P2P+RTCOutgoingMessage.swift */; }; @@ -1142,10 +1141,11 @@ E6FA984B2B04B9AC00748F20 /* ConfirmSkippingBDFS.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FA98492B04B9AC00748F20 /* ConfirmSkippingBDFS.swift */; }; E6FA984E2B04E3D500748F20 /* NoContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6FA984D2B04E3D500748F20 /* NoContentView.swift */; }; E713204C2BCD372600AE6B3C /* UnknownCaseDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E713204B2BCD372600AE6B3C /* UnknownCaseDecodable.swift */; }; + E75C5F342C1C1632002E3DFF /* Stage1MigrateToSargon+SignedAuthChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = E75C5F332C1C1632002E3DFF /* Stage1MigrateToSargon+SignedAuthChallenge.swift */; }; E7A5AC962C09F447006CB6EC /* ResetWalletClient+Interface.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC952C09F447006CB6EC /* ResetWalletClient+Interface.swift */; }; E7A5AC982C09F44C006CB6EC /* ResetWalletClient+Live.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC972C09F44C006CB6EC /* ResetWalletClient+Live.swift */; }; E7A5AC9A2C09F453006CB6EC /* ResetWalletClient+Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC992C09F453006CB6EC /* ResetWalletClient+Test.swift */; }; - E7A5AC9D2C108F2F006CB6EC /* WalletInteractionTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */; }; + E7A5AC9D2C108F2F006CB6EC /* WalletInteraction+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7A5AC9C2C108F2F006CB6EC /* WalletInteraction+Extensions.swift */; }; E7AE2D052BF7844300830BAA /* Sargon in Frameworks */ = {isa = PBXBuildFile; productRef = E695F2DD2BECDD7C00761ACE /* Sargon */; }; E7AE2D0A2C05F39800830BAA /* ClaimWallet+Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7AE2D092C05F39800830BAA /* ClaimWallet+Reducer.swift */; }; E7AE2D0C2C05F39E00830BAA /* ClaimWallet+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7AE2D0B2C05F39E00830BAA /* ClaimWallet+View.swift */; }; @@ -1934,7 +1934,6 @@ 48CFC1682ADC10D900E77A5C /* P2P+LedgerHardwareWallet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+LedgerHardwareWallet.swift"; sourceTree = ""; }; 48CFC1692ADC10D900E77A5C /* P2P+ConnectorExtension+Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+ConnectorExtension+Response.swift"; sourceTree = ""; }; 48CFC16A2ADC10D900E77A5C /* ConnectorExtension+Messages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ConnectorExtension+Messages.swift"; sourceTree = ""; }; - 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "P2P+Dapp+Response.swift"; sourceTree = ""; }; 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "WalletInteraction+PreviewValue.swift"; sourceTree = ""; }; 48CFC1882ADC10D900E77A5C /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 48CFC1892ADC10D900E77A5C /* P2P.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = P2P.swift; sourceTree = ""; }; @@ -2273,10 +2272,11 @@ E6FA98492B04B9AC00748F20 /* ConfirmSkippingBDFS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfirmSkippingBDFS.swift; sourceTree = ""; }; E6FA984D2B04E3D500748F20 /* NoContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NoContentView.swift; sourceTree = ""; }; E713204B2BCD372600AE6B3C /* UnknownCaseDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnknownCaseDecodable.swift; sourceTree = ""; }; + E75C5F332C1C1632002E3DFF /* Stage1MigrateToSargon+SignedAuthChallenge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stage1MigrateToSargon+SignedAuthChallenge.swift"; sourceTree = ""; }; E7A5AC952C09F447006CB6EC /* ResetWalletClient+Interface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Interface.swift"; sourceTree = ""; }; E7A5AC972C09F44C006CB6EC /* ResetWalletClient+Live.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Live.swift"; sourceTree = ""; }; E7A5AC992C09F453006CB6EC /* ResetWalletClient+Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ResetWalletClient+Test.swift"; sourceTree = ""; }; - E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInteractionTypes.swift; sourceTree = ""; }; + E7A5AC9C2C108F2F006CB6EC /* WalletInteraction+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WalletInteraction+Extensions.swift"; sourceTree = ""; }; E7AE2D092C05F39800830BAA /* ClaimWallet+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ClaimWallet+Reducer.swift"; sourceTree = ""; }; E7AE2D0B2C05F39E00830BAA /* ClaimWallet+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ClaimWallet+View.swift"; sourceTree = ""; }; E7AE2D0D2C07359500830BAA /* FullScreenOverlayCoordinator+Reducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FullScreenOverlayCoordinator+Reducer.swift"; sourceTree = ""; }; @@ -5279,8 +5279,7 @@ 48CFC16C2ADC10D900E77A5C /* Models */ = { isa = PBXGroup; children = ( - E7A5AC9C2C108F2F006CB6EC /* WalletInteractionTypes.swift */, - 48CFC17A2ADC10D900E77A5C /* P2P+Dapp+Response.swift */, + E7A5AC9C2C108F2F006CB6EC /* WalletInteraction+Extensions.swift */, 48CFC1872ADC10D900E77A5C /* WalletInteraction+PreviewValue.swift */, ); path = Models; @@ -5903,6 +5902,7 @@ 4884F3322BD83B4600A19B83 /* Stage1MigrateToSargon+OnLedgerSettings.swift */, 4813B0022BCA4FD60046BCAD /* Stage1MigrateToSargon+Persona.swift */, 4855B1C62BCAC82200DD0A47 /* Stage1MigrateToSargon+SignatureOfEntity.swift */, + E75C5F332C1C1632002E3DFF /* Stage1MigrateToSargon+SignedAuthChallenge.swift */, 4884F3342BD83D9200A19B83 /* Stage1MigrateToSargon+ThirdPartyDeposits.swift */, ); path = Stage1; @@ -6889,6 +6889,7 @@ 48CFC2492ADC10D900E77A5C /* ResourcesList+View.swift in Sources */, 4813AFE22BC9A9AD0046BCAD /* Stage1MigrateToSargon+NetworkDefinition.swift in Sources */, 48D5F38B2BD8DDB9000DE964 /* DebugKeychainContents+View.swift in Sources */, + E75C5F342C1C1632002E3DFF /* Stage1MigrateToSargon+SignedAuthChallenge.swift in Sources */, 48CFC3472ADC10D900E77A5C /* PersonaDataPermissionBox+View.swift in Sources */, 48CFC4882ADC10DA00E77A5C /* EntityBehaviors.swift in Sources */, 5B45E3012BC5A491007C4C84 /* FactorSourceAccess+ViewState.swift in Sources */, @@ -7021,7 +7022,6 @@ 48CFC5972ADC10DA00E77A5C /* ToggleView.swift in Sources */, 48CFC4892ADC10DA00E77A5C /* EntityMetadata+GWMetadata.swift in Sources */, 48CFC4FC2ADC10DA00E77A5C /* StateNonFungibleDataRequest.swift in Sources */, - 48CFC60E2ADC10DA00E77A5C /* P2P+Dapp+Response.swift in Sources */, 48CFC3512ADC10D900E77A5C /* DappHeader.swift in Sources */, 48CFC5C32ADC10DA00E77A5C /* Thumbnails.swift in Sources */, 48CFC5B82ADC10DA00E77A5C /* DeveloperDisclaimerBanner.swift in Sources */, @@ -7398,7 +7398,7 @@ 48CFC65D2ADC10DB00E77A5C /* Profile+AuthorizedDapps+Edit.swift in Sources */, 48CFC5552ADC10DA00E77A5C /* MetadataU64ArrayValue.swift in Sources */, 48CFC5242ADC10DA00E77A5C /* MetadataI32Value.swift in Sources */, - E7A5AC9D2C108F2F006CB6EC /* WalletInteractionTypes.swift in Sources */, + E7A5AC9D2C108F2F006CB6EC /* WalletInteraction+Extensions.swift in Sources */, 48CFC2522ADC10D900E77A5C /* AddNewGateway+Reducer.swift in Sources */, E7B7A0FD2BBBFB6100EEE900 /* HeaderListViewContainer.swift in Sources */, 48CFC3FA2ADC10D900E77A5C /* SignalingClient.swift in Sources */, diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift index c98ce3a62d..53cc127aa8 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift @@ -33,7 +33,7 @@ extension DappInteractionClient: DependencyKey { interactionId: interactionId, items: items, metadata: .init( - version: P2P.Dapp.currentVersion, + version: .current, networkId: gatewaysClient.getCurrentNetworkID(), origin: DappToWalletInteractionMetadata.Origin.wallet, dappDefinitionAddress: .wallet @@ -89,8 +89,8 @@ extension DappInteractionClient { } let nonvalidatedMeta = nonValidated.metadata - guard P2P.Dapp.currentVersion == nonvalidatedMeta.version else { - return invalidRequest(.incompatibleVersion(connectorExtensionSent: nonvalidatedMeta.version, walletUses: P2P.Dapp.currentVersion)) + guard WalletInteractionVersion.current == nonvalidatedMeta.version else { + return invalidRequest(.incompatibleVersion(connectorExtensionSent: nonvalidatedMeta.version, walletUses: .current)) } let currentNetworkID = await gatewaysClient.getCurrentNetworkID() guard currentNetworkID == nonValidated.metadata.networkId else { diff --git a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift index 35f0e188af..5852835dcc 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCIncomingMessage.swift @@ -27,7 +27,7 @@ extension P2P { /// An incoming Dapp Request over RTC from some `route`, might have failed /// or succeeded to receive and decode, which is why this contains a - /// `result` and not an `P2P.Dapp.Request` directly. + /// `result` and not an `DappToWalletInteraction` directly. public typealias RTCIncomingDappNonValidatedRequest = RTCIncomingMessageContainer /// An incoming message over RTC from some `route`, might have failed diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift deleted file mode 100644 index d0e462df31..0000000000 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/P2P+Dapp+Response.swift +++ /dev/null @@ -1,23 +0,0 @@ -// MARK: - P2P.Dapp -extension P2P { - /// Just a namespace - public enum Dapp {} -} - -// From WalletInteraction.swift -extension P2P.Dapp { - // public typealias Version = Tagged - /// Temporarily disables Dapp communication. - /// Should be reverted as soon as we implement [ABW-1872](https://radixdlt.atlassian.net/browse/ABW-1872) - public static let currentVersion: WalletInteractionVersion = 2 -} - -// MARK: - SignedAuthChallenge -public struct SignedAuthChallenge: Sendable, Hashable { - public let challenge: DappToWalletInteractionAuthChallengeNonce - public let entitySignatures: Set - public init(challenge: DappToWalletInteractionAuthChallengeNonce, entitySignatures: Set) { - self.challenge = challenge - self.entitySignatures = entitySignatures - } -} diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift similarity index 98% rename from RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift rename to RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift index c4f7319987..e829490a90 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteractionTypes.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift @@ -16,6 +16,10 @@ extension TxVersion { public static let `default`: Self = 1 } +extension WalletInteractionVersion { + public static let current: Self = 2 +} + public typealias NumberOfAccounts = RequestedQuantity extension WalletToDappInteractionResponse { diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift index 14f28bc491..36459f4d6b 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+PreviewValue.swift @@ -1,4 +1,4 @@ -// #if DEBUG +#if DEBUG extension WalletInteractionId { public static let previewValue = Self.previewValue0 public static let previewValue0: Self = "E621E1F8-C36C-495A-93FC-0C247A3E6E5F" @@ -8,6 +8,30 @@ extension WalletInteractionId { public static let previewValue4: Self = "A621E1F8-C36C-495A-93FC-0C247A3E6E5F" } +extension DappToWalletInteractionAccountsRequestItem { + public static let previewValue = Self( + numberOfAccounts: .exactly(1), + challenge: nil + ) +} + +extension DappToWalletInteractionPersonaDataRequestItem { + public static let previewValue = Self( + isRequestingName: true, + numberOfRequestedEmailAddresses: nil, + numberOfRequestedPhoneNumbers: nil + ) +} + +extension DappToWalletInteractionMetadata { + public static let previewValue = Self( + version: .default, + networkId: .sample, + origin: .wallet, + dappDefinitionAddress: .sample + ) +} + extension DappToWalletInteraction { public static func previewValueAllRequests() -> Self { .init( @@ -15,31 +39,28 @@ extension DappToWalletInteraction { items: .authorizedRequest(.init( auth: .loginWithChallenge(.init(challenge: .sample)), reset: nil, - ongoingAccounts: nil, - ongoingPersonaData: nil, - oneTimeAccounts: nil, - oneTimePersonaData: nil + ongoingAccounts: .previewValue, + ongoingPersonaData: .previewValue, + oneTimeAccounts: .previewValue, + oneTimePersonaData: .previewValue )), - metadata: .init(version: .default, networkId: .sample, origin: .wallet, dappDefinitionAddress: .sample) + metadata: .previewValue ) } -// -// public static let previewValueOneTimeAccount = Self.previewValueOneTimeAccount() -// -// public static func previewValueOneTimeAccount( -// id: ID = .previewValue0 -// ) -> Self { -// .init( -// id: id, -// items: .request( -// .unauthorized(.init( -// oneTimeAccounts: .previewValue, -// oneTimePersonaData: .previewValue -// )) -// ), -// metadata: .previewValue -// ) -// } -} -// #endif // DEBUG + public static let previewValueOneTimeAccount = Self.previewValueOneTimeAccount() + + public static func previewValueOneTimeAccount( + interactionId: WalletInteractionId = .previewValue0 + ) -> Self { + .init( + interactionId: interactionId, + items: .unauthorizedRequest(.init( + oneTimeAccounts: .previewValue, + oneTimePersonaData: .previewValue + )), + metadata: .previewValue + ) + } +} +#endif // DEBUG diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift index 4cdb493332..e25b23f7df 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading+View.swift @@ -64,7 +64,7 @@ struct DappInteractionLoading_Preview: PreviewProvider { extension DappInteractionLoading.State { static let previewValue: Self = .init( - interaction: .previewValueAllRequests() // .previewValueOneTimeAccount + interaction: .previewValueOneTimeAccount ) } #endif diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift index e74985b910..c7bd239a20 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift @@ -95,7 +95,7 @@ extension DappMetadata { } #endif -// MARK: - P2P.Dapp.Request.WalletRequestItem +// MARK: - DappToWalletInteraction extension DappToWalletInteraction { /// A union type containing all request items allowed in a `WalletInteraction`, for app handling purposes. enum AnyInteractionItem: Sendable, Hashable { @@ -158,7 +158,7 @@ extension DappToWalletInteraction { } } -// MARK: - P2P.Dapp.Response.WalletInteractionSuccessResponse.AnyInteractionResponseItem +// MARK: - WalletToDappInteractionSuccessResponse.AnyInteractionResponseItem extension WalletToDappInteractionSuccessResponse { enum AnyInteractionResponseItem: Sendable, Hashable { // request responses diff --git a/RadixWallet/MIGRATE_TO_SARGON/Stage1/Stage1MigrateToSargon+SignedAuthChallenge.swift b/RadixWallet/MIGRATE_TO_SARGON/Stage1/Stage1MigrateToSargon+SignedAuthChallenge.swift new file mode 100644 index 0000000000..77ca17fab5 --- /dev/null +++ b/RadixWallet/MIGRATE_TO_SARGON/Stage1/Stage1MigrateToSargon+SignedAuthChallenge.swift @@ -0,0 +1,12 @@ +import Foundation +import Sargon + +// MARK: - SignedAuthChallenge +public struct SignedAuthChallenge: Sendable, Hashable { + public let challenge: DappToWalletInteractionAuthChallengeNonce + public let entitySignatures: Set + public init(challenge: DappToWalletInteractionAuthChallengeNonce, entitySignatures: Set) { + self.challenge = challenge + self.entitySignatures = entitySignatures + } +} From cca2f80fc7a19b1f2afa2d48511600cd575e9a63 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:46:01 +0300 Subject: [PATCH 06/11] wip --- .../Models/WalletInteraction+Extensions.swift | 120 +----------------- .../AccountPermission/AccountPermission.swift | 4 +- ...ountPermissionChooseAccounts+Reducer.swift | 2 +- .../Coordinator/DappInteractionFlow.swift | 6 +- ...ateToSargon+RadixConnectModels+Logic.swift | 111 ++++++++++++++++ 5 files changed, 122 insertions(+), 121 deletions(-) diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift index e829490a90..f09642f38a 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift @@ -12,69 +12,15 @@ extension DappToWalletInteractionMetadata.Origin { }() } +// MARK: - DappInteractionNumberOfAccounts +public typealias DappInteractionNumberOfAccounts = RequestedQuantity + +// MARK: - TxVersion extension TxVersion { public static let `default`: Self = 1 } -extension WalletInteractionVersion { - public static let current: Self = 2 -} - -public typealias NumberOfAccounts = RequestedQuantity - -extension WalletToDappInteractionResponse { - public var interactionId: WalletInteractionId { - switch self { - case let .success(response): - response.interactionId - case let .failure(response): - response.interactionId - } - } - - public enum Accounts: Sendable, Hashable { - case withoutProofOfOwnership(IdentifiedArrayOf) - case withProofOfOwnership(challenge: DappToWalletInteractionAuthChallengeNonce, IdentifiedArrayOf) - - public struct WithProof: Sendable, Hashable, Identifiable { - public typealias ID = WalletInteractionWalletAccount - public var id: ID { account } - public let account: WalletInteractionWalletAccount - - public let proof: WalletToDappInteractionAuthProof - - public init( - account: WalletInteractionWalletAccount, - proof: WalletToDappInteractionAuthProof - ) { - self.account = account - self.proof = proof - } - } - } -} - -extension WalletToDappInteractionAccountsRequestResponseItem { - public init( - accounts: WalletToDappInteractionResponse.Accounts - ) { - switch accounts { - case let .withProofOfOwnership(challenge, accountsWithProof): - self.init( - accounts: accountsWithProof.map(\.account), - challenge: challenge, - proofs: accountsWithProof.map { .init(accountAddress: $0.account.address, proof: $0.proof) } - ) - case let .withoutProofOfOwnership(account): - self.init( - accounts: account.map(WalletInteractionWalletAccount.init(account:)), - challenge: nil, - proofs: nil - ) - } - } -} - +// MARK: - DappToWalletInteractionSendTransactionItem extension DappToWalletInteractionSendTransactionItem { public init( version: TxVersion = .default, @@ -89,62 +35,6 @@ extension DappToWalletInteractionSendTransactionItem { } } -extension WalletInteractionWalletAccount { - public init(account: Account) { - self.init( - address: account.address, - label: account.displayName, - appearanceId: account.appearanceID - ) - } -} - -extension WalletToDappInteractionAuthProof { - public init(entitySignature: SignatureOfEntity) { - let sigPub = entitySignature.signatureWithPublicKey - let signature = sigPub.signature - self.init( - publicKey: sigPub.publicKey, - curve: sigPub.publicKey.curve, - signature: signature - ) - } -} - -extension DappWalletInteractionPersona { - public init(persona: Persona) { - self.init(identityAddress: persona.address, label: persona.displayName.rawValue) - } -} - -extension DappToWalletInteraction { - public enum MissingEntry: Sendable, Hashable { - case missingEntry - case missing(Int) - } - - public enum KindRequest: Sendable, Hashable { - case entry - case number(RequestedQuantity) - } -} - -extension DappToWalletInteractionPersonaDataRequestItem { - public var kindRequests: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] { - var result: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] = [:] - if isRequestingName == true { - result[.fullName] = .entry - } - if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { - result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) - } - if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { - result[.emailAddress] = .number(numberOfRequestedEmailAddresses) - } - return result - } -} - // MARK: - DappToWalletInteraction.RequestValidation extension DappToWalletInteraction { public struct RequestValidation: Sendable, Hashable { diff --git a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift index 0a6450a5b6..9ffcd45353 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermission/AccountPermission.swift @@ -5,11 +5,11 @@ import SwiftUI struct AccountPermission: Sendable, FeatureReducer { struct State: Sendable, Hashable { let dappMetadata: DappMetadata - let numberOfAccounts: NumberOfAccounts + let numberOfAccounts: DappInteractionNumberOfAccounts init( dappMetadata: DappMetadata, - numberOfAccounts: NumberOfAccounts + numberOfAccounts: DappInteractionNumberOfAccounts ) { self.dappMetadata = dappMetadata self.numberOfAccounts = numberOfAccounts diff --git a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift index 5b73b9b578..930ef27e3d 100644 --- a/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift +++ b/RadixWallet/Features/DappInteractionFeature/Children/AccountPermissionChooseAccounts/AccountPermissionChooseAccounts+Reducer.swift @@ -39,7 +39,7 @@ struct AccountPermissionChooseAccounts: Sendable, FeatureReducer { challenge: DappToWalletInteractionAuthChallengeNonce?, accessKind: AccessKind, dappMetadata: DappMetadata, - numberOfAccounts: NumberOfAccounts + numberOfAccounts: DappInteractionNumberOfAccounts ) { self.init( challenge: challenge, diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift index 530c7e5021..063ad2ac52 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionFlow.swift @@ -18,7 +18,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { typealias RemoteInteractionResponseItem = WalletToDappInteractionSuccessResponse.AnyInteractionResponseItem enum LocalInteractionItem: Sendable, Hashable { - case accountPermissionRequested(NumberOfAccounts) + case accountPermissionRequested(DappInteractionNumberOfAccounts) } enum LocalInteractionResponseItem: Sendable, Hashable { @@ -97,7 +97,7 @@ struct DappInteractionFlow: Sendable, FeatureReducer { struct AutofillOngoingResponseItemsPayload: Sendable, Equatable { struct AccountsPayload: Sendable, Equatable { var requestItem: DappInteractionFlow.State.AnyInteractionItem - var numberOfAccountsRequested: NumberOfAccounts + var numberOfAccountsRequested: DappInteractionNumberOfAccounts var accounts: [Account] } @@ -688,7 +688,7 @@ extension DappInteractionFlow { referencesToAuthorizedPersonas: [] ) // This extraction is really verbose right now, but it should become a lot simpler with native case paths - let sharedAccountsInfo: (NumberOfAccounts, [WalletInteractionWalletAccount])? = unwrap( + let sharedAccountsInfo: (DappInteractionNumberOfAccounts, [WalletInteractionWalletAccount])? = unwrap( // request { switch state.remoteInteraction.items { diff --git a/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift b/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift index e547972313..a393ae4ca6 100644 --- a/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift +++ b/RadixWallet/MIGRATE_TO_SARGON/Stage2/RadixConnect/Stage2MigrateToSargon+RadixConnectModels+Logic.swift @@ -53,3 +53,114 @@ extension WalletToDappInteractionPersonaDataRequestResponseItem { ) } } + +extension WalletInteractionWalletAccount { + public init(account: Account) { + self.init( + address: account.address, + label: account.displayName, + appearanceId: account.appearanceID + ) + } +} + +extension WalletToDappInteractionAuthProof { + public init(entitySignature: SignatureOfEntity) { + let sigPub = entitySignature.signatureWithPublicKey + let signature = sigPub.signature + self.init( + publicKey: sigPub.publicKey, + curve: sigPub.publicKey.curve, + signature: signature + ) + } +} + +extension DappWalletInteractionPersona { + public init(persona: Persona) { + self.init(identityAddress: persona.address, label: persona.displayName.rawValue) + } +} + +extension DappToWalletInteraction { + public enum MissingEntry: Sendable, Hashable { + case missingEntry + case missing(Int) + } + + public enum KindRequest: Sendable, Hashable { + case entry + case number(RequestedQuantity) + } +} + +extension DappToWalletInteractionPersonaDataRequestItem { + public var kindRequests: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] { + var result: [PersonaData.Entry.Kind: DappToWalletInteraction.KindRequest] = [:] + if isRequestingName == true { + result[.fullName] = .entry + } + if let numberOfRequestedPhoneNumbers, numberOfRequestedPhoneNumbers.isValid { + result[.phoneNumber] = .number(numberOfRequestedPhoneNumbers) + } + if let numberOfRequestedEmailAddresses, numberOfRequestedEmailAddresses.isValid { + result[.emailAddress] = .number(numberOfRequestedEmailAddresses) + } + return result + } +} + +// MARK: - WalletToDappInteractionResponse +extension WalletToDappInteractionResponse { + public var interactionId: WalletInteractionId { + switch self { + case let .success(response): + response.interactionId + case let .failure(response): + response.interactionId + } + } + + public enum Accounts: Sendable, Hashable { + case withoutProofOfOwnership(IdentifiedArrayOf) + case withProofOfOwnership(challenge: DappToWalletInteractionAuthChallengeNonce, IdentifiedArrayOf) + + public struct WithProof: Sendable, Hashable, Identifiable { + public typealias ID = WalletInteractionWalletAccount + public var id: ID { account } + public let account: WalletInteractionWalletAccount + + public let proof: WalletToDappInteractionAuthProof + + public init( + account: WalletInteractionWalletAccount, + proof: WalletToDappInteractionAuthProof + ) { + self.account = account + self.proof = proof + } + } + } +} + +// MARK: - WalletToDappInteractionAccountsRequestResponseItem +extension WalletToDappInteractionAccountsRequestResponseItem { + public init( + accounts: WalletToDappInteractionResponse.Accounts + ) { + switch accounts { + case let .withProofOfOwnership(challenge, accountsWithProof): + self.init( + accounts: accountsWithProof.map(\.account), + challenge: challenge, + proofs: accountsWithProof.map { .init(accountAddress: $0.account.address, proof: $0.proof) } + ) + case let .withoutProofOfOwnership(account): + self.init( + accounts: account.map(WalletInteractionWalletAccount.init(account:)), + challenge: nil, + proofs: nil + ) + } + } +} From 1bd648ce09403d0de926f4df6dd3d0d236d71cb2 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:12:05 +0300 Subject: [PATCH 07/11] fix tests --- .../ROLAClientTests/ROLAClientTests.swift | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift index 35fc9a54c1..8296db088e 100644 --- a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift +++ b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift @@ -18,10 +18,11 @@ final class ROLAClientTests: TestCase { origin: String, dAppDefinitionAddress: DappDefinitionAddress ) -> DappToWalletInteractionMetadata { - try! .init( - version: 1, networkId: NetworkID.mainnet, - origin: .init(string: origin), - dAppDefinitionAddress: dAppDefinitionAddress + .init( + version: 1, + networkId: NetworkID.mainnet, + origin: .init(string: origin)!, + dappDefinitionAddress: dAppDefinitionAddress ) } @@ -70,9 +71,9 @@ final class ROLAClientTests: TestCase { ) { (vectors: [TestVector]) in for vector in vectors { let payload = try ROLAClient.payloadToHash( - challenge: .init(rawValue: .init(hex: vector.challenge)), + challenge: .init(hex: vector.challenge), dAppDefinitionAddress: .init(validatingAddress: vector.dAppDefinitionAddress), - origin: .init(string: vector.origin) + origin: .init(string: vector.origin)! ) XCTAssertEqual(payload.hex, vector.payloadToHash) let blakeHashOfPayload = payload.hash() @@ -86,7 +87,7 @@ final class ROLAClientTests: TestCase { "https://dashboard.rdx.works", "https://stella.swap", "https://rola.xrd", - ].map { try .init(string: $0) } + ].map { try .init(string: $0)! } let accounts: [DappDefinitionAddress] = try [ "account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q", "account_sim1cyzfj6p254jy6lhr237s7pcp8qqz6c8ahq9mn6nkdjxxxat5syrgz9", @@ -96,15 +97,15 @@ final class ROLAClientTests: TestCase { try accounts.flatMap { dAppDefinitionAddress -> [TestVector] in try (UInt8.zero ..< 10).map { seed -> TestVector in /// deterministic derivation of a challenge, this is not `blakeHashOfPayload` - let challenge = (Data((origin.urlString.rawValue + dAppDefinitionAddress.address).utf8) + [seed]).hash() + let challenge = (Data((origin.absoluteString + dAppDefinitionAddress.address).utf8) + [seed]).hash() let payload = try ROLAClient.payloadToHash( - challenge: .init(rawValue: challenge.bytes), + challenge: challenge.bytes, dAppDefinitionAddress: dAppDefinitionAddress, origin: origin ) let blakeHashOfPayload = payload.hash() return TestVector( - origin: origin.urlString.rawValue, + origin: origin.absoluteString, challenge: challenge.hex, dAppDefinitionAddress: dAppDefinitionAddress.address, payloadToHash: payload.hex, @@ -127,9 +128,9 @@ final class ROLAClientTests: TestCase { XCTAssertEqual(publicKey.publicKey.hex, "0a4b894208a1f6b1bd7e823b59909f01aae0172b534baa2905b25f1bcbbb4f0a") let hash: Hash = try { let payload = try ROLAClient.payloadToHash( - challenge: .init(rawValue: Exactly32Bytes(hex: "2596b7902d56a32d17ca90ce2a1ee0a18a9cac6a82fb9f186d904e4a3eeeb627")), + challenge: Exactly32Bytes(hex: "2596b7902d56a32d17ca90ce2a1ee0a18a9cac6a82fb9f186d904e4a3eeeb627"), dAppDefinitionAddress: .init(validatingAddress: "account_rdx168fghy4kapzfnwpmq7t7753425lwklk65r82ys7pz2xzleehk2ap0k"), - origin: .init(string: "https://radix-dapp-toolkit-dev.rdx-works-main.extratools.works") + origin: .init(string: "https://radix-dapp-toolkit-dev.rdx-works-main.extratools.works")! ) return payload.hash() }() From 9d6e988e81fdc5ad6330b52ecc36388e8420a0ca Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:18:49 +0300 Subject: [PATCH 08/11] bump sargon to 1.0.11 --- RadixWallet.xcodeproj/project.pbxproj | 19 ++++++++++--------- .../xcshareddata/swiftpm/Package.resolved | 11 ++++++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 335155e261..735f3780a5 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 60; + objectVersion = 56; objects = { /* Begin PBXBuildFile section */ @@ -6540,7 +6540,7 @@ 5B1C4FD32BBB0B0C00B9436F /* XCRemoteSwiftPackageReference "AppsFlyerFramework-Strict" */, 8318BB172BC8403800057BCB /* XCRemoteSwiftPackageReference "swift-custom-dump" */, E6A0B0492BF23C7000617DAC /* XCRemoteSwiftPackageReference "swift-identified-collections" */, - E7A5AC9B2C0F3EBA006CB6EC /* XCLocalSwiftPackageReference "../sargon" */, + E76645A02C1C6C9C00065D9A /* XCRemoteSwiftPackageReference "sargon" */, ); productRefGroup = 48CFBC502ADC106300E77A5C /* Products */; projectDirPath = ""; @@ -8225,13 +8225,6 @@ }; /* End XCConfigurationList section */ -/* Begin XCLocalSwiftPackageReference section */ - E7A5AC9B2C0F3EBA006CB6EC /* XCLocalSwiftPackageReference "../sargon" */ = { - isa = XCLocalSwiftPackageReference; - relativePath = ../sargon; - }; -/* End XCLocalSwiftPackageReference section */ - /* Begin XCRemoteSwiftPackageReference section */ 48FFFA972ADC1EEC00B2B213 /* XCRemoteSwiftPackageReference "AsyncExtensions" */ = { isa = XCRemoteSwiftPackageReference; @@ -8505,6 +8498,14 @@ version = 1.0.2; }; }; + E76645A02C1C6C9C00065D9A /* XCRemoteSwiftPackageReference "sargon" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/radixdlt/sargon"; + requirement = { + kind = exactVersion; + version = 1.0.11; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ diff --git a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3104c93cd1..05333e5d95 100644 --- a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "5f630ffa75effc63039120c716322c04a75eafccebb0ba925d9f0ddb618a9efb", + "originHash" : "7d3590b225945abb1bc0ab6c684b005c28c64bdc204afcc2d34c3e379ef8a3c8", "pins" : [ { "identity" : "anycodable", @@ -109,6 +109,15 @@ "version" : "11.6.4" } }, + { + "identity" : "sargon", + "kind" : "remoteSourceControl", + "location" : "https://github.com/radixdlt/sargon", + "state" : { + "revision" : "4152cd3458aec0eae06aee7376414bcaeb5d9d14", + "version" : "1.0.11" + } + }, { "identity" : "screenshotpreventing-ios", "kind" : "remoteSourceControl", From da60a14288b66bcb8e75deba86ef3f09ded8e172 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:36:31 +0300 Subject: [PATCH 09/11] Update RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift Co-authored-by: matiasbzurovski <164921079+matiasbzurovski@users.noreply.github.com> --- .../DappInteractionClient/DappInteractionClient+Live.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift index 53cc127aa8..9fe709adb3 100644 --- a/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift +++ b/RadixWallet/Clients/DappInteractionClient/DappInteractionClient+Live.swift @@ -35,7 +35,7 @@ extension DappInteractionClient: DependencyKey { metadata: .init( version: .current, networkId: gatewaysClient.getCurrentNetworkID(), - origin: DappToWalletInteractionMetadata.Origin.wallet, + origin: .wallet, dappDefinitionAddress: .wallet ) )) From 9b9c66a48476574546aff9130f26c1dafb26a8a0 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:00:21 +0300 Subject: [PATCH 10/11] Address comments --- .../P2P+RTCMessageFromPeer.swift | 18 +----------------- .../RadixConnect/RTC/RTCClients.swift | 9 ++++----- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift index 6d0b2a1db3..64bff013ff 100644 --- a/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift +++ b/RadixWallet/Core/SharedModels/P2P/Application/IncomingMessage/P2P+RTCMessageFromPeer.swift @@ -14,28 +14,12 @@ extension P2P { case connectorExtension(P2P.ConnectorExtension.Response) } - public enum Request: Sendable, Hashable, Equatable, Decodable { + public enum Request: Sendable, Hashable, Equatable { case dapp(DappToWalletInteractionUnvalidated) } } } -extension P2P.RTCMessageFromPeer.Request { - public init(from decoder: Decoder) throws { - @Dependency(\.jsonEncoder) var jsonEncoder - - let container = try decoder.singleValueContainer() - let jsonValue = try container.decode(JSONValue.self) - let jsonData = try jsonEncoder().encode(jsonValue.dictionary ?? [:]) - - guard let jsonString = String(data: jsonData, encoding: .utf8) else { - throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid data") - } - - self = try .dapp(.init(jsonString: jsonString)) - } -} - extension P2P.RTCMessageFromPeer.Response { public init(from decoder: Decoder) throws { self = try .connectorExtension(.init(from: decoder)) diff --git a/RadixWallet/RadixConnect/RadixConnect/RTC/RTCClients.swift b/RadixWallet/RadixConnect/RadixConnect/RTC/RTCClients.swift index 274d68a6e5..6a412f5f08 100644 --- a/RadixWallet/RadixConnect/RadixConnect/RTC/RTCClients.swift +++ b/RadixWallet/RadixConnect/RadixConnect/RTC/RTCClients.swift @@ -436,11 +436,10 @@ func decode( return messageResult.flatMap { (message: DataChannelClient.AssembledMessage) in let jsonData = message.messageContent do { - let request = try jsonDecoder.decode( - P2P.RTCMessageFromPeer.Request.self, - from: jsonData - ) - return .success(.request(request)) + guard let jsonString = String(data: jsonData, encoding: .utf8) else { + throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "Unable to convert data to UTF-8 string")) + } + return try .success(.request(.dapp(.init(jsonString: jsonString)))) } catch let decodeRequestError { do { let response = try jsonDecoder.decode( From 9f34b1ab612d7aaeec56b5110c0db0eaa282bd33 Mon Sep 17 00:00:00 2001 From: danvleju-rdx <163979791+danvleju-rdx@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:37:32 +0300 Subject: [PATCH 11/11] Use DappOrigin from Sargon and bump Sargon to 1.0.12 --- RadixWallet.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- ...LedgerHardwareWalletClient+Interface.swift | 4 ++-- .../ROLAClient/ROLAClient+Interface.swift | 4 ++-- .../Clients/ROLAClient/ROLAClient+Live.swift | 9 ++++--- .../P2P+ConnectorExtension+Request.swift | 4 ++-- .../Models/WalletInteraction+Extensions.swift | 24 ++++++++++++------- .../Coordinator/DappInteractionLoading.swift | 4 ++-- .../Coordinator/DappInteractionModels.swift | 10 ++++---- .../ROLAClientTests/ROLAClientTests.swift | 16 ++++++------- 10 files changed, 43 insertions(+), 38 deletions(-) diff --git a/RadixWallet.xcodeproj/project.pbxproj b/RadixWallet.xcodeproj/project.pbxproj index 735f3780a5..e6861d5252 100644 --- a/RadixWallet.xcodeproj/project.pbxproj +++ b/RadixWallet.xcodeproj/project.pbxproj @@ -8503,7 +8503,7 @@ repositoryURL = "https://github.com/radixdlt/sargon"; requirement = { kind = exactVersion; - version = 1.0.11; + version = 1.0.12; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 05333e5d95..065ee61551 100644 --- a/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RadixWallet.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -114,8 +114,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/radixdlt/sargon", "state" : { - "revision" : "4152cd3458aec0eae06aee7376414bcaeb5d9d14", - "version" : "1.0.11" + "revision" : "fa0a8dd58149d3bcfa88e4fd161c588f595c13cc", + "version" : "1.0.12" } }, { diff --git a/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift b/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift index cff21d0934..d16337a39b 100644 --- a/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift +++ b/RadixWallet/Clients/LedgerHardwareWalletClient/LedgerHardwareWalletClient+Interface.swift @@ -58,14 +58,14 @@ public struct SignAuthChallengeWithLedgerRequest: Sendable, Hashable { public let signers: NonEmpty> public let ledger: LedgerHardwareWalletFactorSource public let challenge: DappToWalletInteractionAuthChallengeNonce - public let origin: DappToWalletInteractionMetadata.Origin + public let origin: DappOrigin public let dAppDefinitionAddress: AccountAddress public init( ledger: LedgerHardwareWalletFactorSource, signers: NonEmpty>, challenge: DappToWalletInteractionAuthChallengeNonce, - origin: DappToWalletInteractionMetadata.Origin, + origin: DappOrigin, dAppDefinitionAddress: AccountAddress ) { self.ledger = ledger diff --git a/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift b/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift index 41affef02b..2f4fc3f6e9 100644 --- a/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift +++ b/RadixWallet/Clients/ROLAClient/ROLAClient+Interface.swift @@ -29,12 +29,12 @@ extension DependencyValues { // MARK: - AuthenticationDataToSignForChallengeRequest public struct AuthenticationDataToSignForChallengeRequest: Sendable, Hashable { public let challenge: DappToWalletInteractionAuthChallengeNonce - public let origin: DappToWalletInteractionMetadata.Origin + public let origin: DappOrigin public let dAppDefinitionAddress: DappDefinitionAddress public init( challenge: DappToWalletInteractionAuthChallengeNonce, - origin: DappToWalletInteractionMetadata.Origin, + origin: DappOrigin, dAppDefinitionAddress: DappDefinitionAddress ) { self.challenge = challenge diff --git a/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift b/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift index 51c80b85a4..015850bba4 100644 --- a/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift +++ b/RadixWallet/Clients/ROLAClient/ROLAClient+Live.swift @@ -37,13 +37,13 @@ extension ROLAClient { performDappDefinitionVerification: { metadata async throws in _ = try await onLedgerEntitiesClient.getDappMetadata( metadata.dappDefinitionAddress, - validatingWebsite: metadata.origin + validatingWebsite: metadata.origin.url() ) }, performWellKnownFileCheck: { metadata async throws in @Dependency(\.urlSession) var urlSession - let originURL = metadata.origin + let originURL = try metadata.origin.url() let url = originURL.appending(path: Constants.wellKnownFilePath) @@ -117,11 +117,10 @@ extension ROLAClient { static func payloadToHash( challenge: DappToWalletInteractionAuthChallengeNonce, dAppDefinitionAddress accountAddress: AccountAddress, - origin metadataOrigin: DappToWalletInteractionMetadata.Origin + origin metadataOrigin: DappOrigin ) -> Data { let rPrefix: UInt8 = 0x52 let dAppDefinitionAddress = accountAddress.address - let origin = metadataOrigin.absoluteString precondition(dAppDefinitionAddress.count <= UInt8.max) let challengeBytes = [UInt8](challenge.data.data) let lengthDappDefinitionAddress = UInt8(dAppDefinitionAddress.count) @@ -130,7 +129,7 @@ extension ROLAClient { data.append(contentsOf: challengeBytes) data.append(contentsOf: [lengthDappDefinitionAddress]) data.append(contentsOf: [UInt8](dAppDefinitionAddress.utf8)) - data.append(contentsOf: [UInt8](origin.utf8)) + data.append(contentsOf: [UInt8](metadataOrigin.utf8)) return Data(data) } diff --git a/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift b/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift index b2c7a7d86b..157b557ff4 100644 --- a/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift +++ b/RadixWallet/Core/SharedModels/P2P/ConnectorExtension/P2P+ConnectorExtension+Request.swift @@ -94,14 +94,14 @@ extension P2P.ConnectorExtension.Request { public let signers: [P2P.LedgerHardwareWallet.KeyParameters] public let ledgerDevice: P2P.LedgerHardwareWallet.LedgerDevice public let challenge: DappToWalletInteractionAuthChallengeNonce - public let origin: DappToWalletInteractionMetadata.Origin + public let origin: DappOrigin public let dAppDefinitionAddress: AccountAddress public init( signers: [P2P.LedgerHardwareWallet.KeyParameters], ledgerDevice: P2P.LedgerHardwareWallet.LedgerDevice, challenge: DappToWalletInteractionAuthChallengeNonce, - origin: DappToWalletInteractionMetadata.Origin, + origin: DappOrigin, dAppDefinitionAddress: AccountAddress ) { self.signers = signers diff --git a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift index f09642f38a..3bbfd9697f 100644 --- a/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift +++ b/RadixWallet/Core/SharedModels/P2P/Dapp/Models/WalletInteraction+Extensions.swift @@ -1,15 +1,21 @@ import Sargon -// MARK: - DappToWalletInteractionMetadata.Origin -extension DappToWalletInteractionMetadata { - public typealias Origin = URL -} +// MARK: - DappOrigin +// extension DappToWalletInteractionMetadata { +// public typealias Origin = URL +// } + +extension DappOrigin { + public static let wallet = "com.radixpublishing.radixwallet.ios" + + public struct InvalidOriginURL: Error {} -extension DappToWalletInteractionMetadata.Origin { - public static let wallet: Self = { - let walletAppScheme = "com.radixpublishing.radixwallet.ios" - return .init(string: walletAppScheme)! - }() + public func url() throws -> URL { + guard let url = URL(string: self) else { + throw InvalidOriginURL() + } + return url + } } // MARK: - DappInteractionNumberOfAccounts diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift index c335c3f0f7..3685e7319e 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionLoading.swift @@ -65,7 +65,7 @@ struct DappInteractionLoading: Sendable, FeatureReducer { func metadataLoadingEffect(with state: inout State) -> Effect { state.isLoading = true - if state.interaction.metadata.origin == DappToWalletInteractionMetadata.Origin.wallet { + if state.interaction.metadata.origin == DappOrigin.wallet { return .send(.internal(.dappMetadataLoadingResult(.success(.wallet(.init()))))) } @@ -153,7 +153,7 @@ extension DappMetadata.Ledger { init( entityMetadataForDapp: GatewayAPI.EntityMetadataCollection, dAppDefinintionAddress: AccountAddress, - origin: DappToWalletInteractionMetadata.Origin + origin: DappOrigin ) { let items = entityMetadataForDapp.items let maybeName: String? = items[.name]?.value.asString diff --git a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift index c7bd239a20..4ff7155fc5 100644 --- a/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift +++ b/RadixWallet/Features/DappInteractionFeature/Coordinator/DappInteractionModels.swift @@ -22,7 +22,7 @@ public enum DappMetadata: Sendable, Hashable { extension DappMetadata { static let wallet: Wallet = .init() public struct Wallet: Sendable, Hashable { - let origin: DappToWalletInteractionMetadata.Origin = .wallet + let origin: DappOrigin = .wallet let name: NonEmptyString = "Radix Wallet" let description: String? = nil let thumbnail: URL? = nil @@ -35,7 +35,7 @@ extension DappMetadata { public struct Ledger: Sendable, Hashable, Codable { static let defaultName = NonEmptyString(rawValue: L10n.DAppRequest.Metadata.unknownName)! - let origin: DappToWalletInteractionMetadata.Origin + let origin: DappOrigin let dAppDefinintionAddress: DappDefinitionAddress let name: NonEmptyString? @@ -43,7 +43,7 @@ extension DappMetadata { let thumbnail: URL? init( - origin: DappToWalletInteractionMetadata.Origin, + origin: DappOrigin, dAppDefinintionAddress: DappDefinitionAddress, name: NonEmptyString?, description: String? = nil, @@ -59,7 +59,7 @@ extension DappMetadata { } extension DappMetadata { - public var origin: DappToWalletInteractionMetadata.Origin { + public var origin: DappOrigin { switch self { case let .ledger(metadata): metadata.origin case let .request(metadata): metadata.origin @@ -85,7 +85,7 @@ extension DappMetadata { #if DEBUG extension DappMetadata { static let previewValue: Self = try! .ledger(.init( - origin: .init(string: "https://radfi.com")!, + origin: "https://radfi.com", dAppDefinintionAddress: .init(validatingAddress: "account_tdx_b_1p95nal0nmrqyl5r4phcspg8ahwnamaduzdd3kaklw3vqeavrwa"), name: "Collabo.Fi", description: "A very collaby finance dapp", diff --git a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift index 8296db088e..783536f6cc 100644 --- a/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift +++ b/RadixWalletTests/Clients/ROLAClientTests/ROLAClientTests.swift @@ -21,7 +21,7 @@ final class ROLAClientTests: TestCase { .init( version: 1, networkId: NetworkID.mainnet, - origin: .init(string: origin)!, + origin: origin, dappDefinitionAddress: dAppDefinitionAddress ) } @@ -73,7 +73,7 @@ final class ROLAClientTests: TestCase { let payload = try ROLAClient.payloadToHash( challenge: .init(hex: vector.challenge), dAppDefinitionAddress: .init(validatingAddress: vector.dAppDefinitionAddress), - origin: .init(string: vector.origin)! + origin: vector.origin ) XCTAssertEqual(payload.hex, vector.payloadToHash) let blakeHashOfPayload = payload.hash() @@ -83,11 +83,11 @@ final class ROLAClientTests: TestCase { } func omit_test_generate_rola_payload_hash_vectors() throws { - let origins: [DappToWalletInteractionMetadata.Origin] = try [ + let origins: [DappOrigin] = [ "https://dashboard.rdx.works", "https://stella.swap", "https://rola.xrd", - ].map { try .init(string: $0)! } + ] let accounts: [DappDefinitionAddress] = try [ "account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q", "account_sim1cyzfj6p254jy6lhr237s7pcp8qqz6c8ahq9mn6nkdjxxxat5syrgz9", @@ -97,15 +97,15 @@ final class ROLAClientTests: TestCase { try accounts.flatMap { dAppDefinitionAddress -> [TestVector] in try (UInt8.zero ..< 10).map { seed -> TestVector in /// deterministic derivation of a challenge, this is not `blakeHashOfPayload` - let challenge = (Data((origin.absoluteString + dAppDefinitionAddress.address).utf8) + [seed]).hash() - let payload = try ROLAClient.payloadToHash( + let challenge = (Data((origin + dAppDefinitionAddress.address).utf8) + [seed]).hash() + let payload = ROLAClient.payloadToHash( challenge: challenge.bytes, dAppDefinitionAddress: dAppDefinitionAddress, origin: origin ) let blakeHashOfPayload = payload.hash() return TestVector( - origin: origin.absoluteString, + origin: origin, challenge: challenge.hex, dAppDefinitionAddress: dAppDefinitionAddress.address, payloadToHash: payload.hex, @@ -130,7 +130,7 @@ final class ROLAClientTests: TestCase { let payload = try ROLAClient.payloadToHash( challenge: Exactly32Bytes(hex: "2596b7902d56a32d17ca90ce2a1ee0a18a9cac6a82fb9f186d904e4a3eeeb627"), dAppDefinitionAddress: .init(validatingAddress: "account_rdx168fghy4kapzfnwpmq7t7753425lwklk65r82ys7pz2xzleehk2ap0k"), - origin: .init(string: "https://radix-dapp-toolkit-dev.rdx-works-main.extratools.works")! + origin: "https://radix-dapp-toolkit-dev.rdx-works-main.extratools.works" ) return payload.hash() }()