From d413c45ed214d075d47927f8c81fbad91b3da9fb Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Wed, 18 Sep 2024 10:56:29 +0530 Subject: [PATCH] update mpc ios examples --- .../project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 35 +++---- .../Helpers/EthereumClient.swift | 8 +- .../Helpers/Extensions.swift | 30 +++--- .../Models/MainViewModel.swift | 98 +++++++++---------- .../Views/HomeView.swift | 4 +- .../project.pbxproj | 57 +++++++---- .../xcshareddata/swiftpm/Package.resolved | 84 +++++++--------- .../Helpers/EthereumHelper.swift | 7 +- .../Helpers/Extension.swift | 30 +++--- .../Models/MainViewModel.swift | 76 ++++++++------ .../Views/HomeView.swift | 4 +- 12 files changed, 214 insertions(+), 221 deletions(-) diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.pbxproj b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.pbxproj index a128c8aa..30d85004 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.pbxproj +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.pbxproj @@ -694,7 +694,7 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/tkey/mpc-core-kit-swift"; requirement = { - branch = main; + branch = update_dependencies; kind = branch; }; }; diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 657bb4e1..5b3ebc88 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,15 +1,6 @@ { - "originHash" : "6eb679ca10e6ba273c0a4c520af3222830fe4d28810a355d4409ece0c2cf4329", + "originHash" : "4d094b864a39c380b5e848611658ba8bd3cac9cdcd330d5fac7b11f59399ea97", "pins" : [ - { - "identity" : "anycodable", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Flight-School/AnyCodable", - "state" : { - "revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05", - "version" : "0.6.7" - } - }, { "identity" : "auth0.swift", "kind" : "remoteSourceControl", @@ -42,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/customauth-swift-sdk", "state" : { - "revision" : "60b48acb161fb4341c353c27bc6dd96af76887ff", - "version" : "10.0.1" + "branch" : "features_update", + "revision" : "576139ce446e397bce4f2b68b9b7d28ab5b0082f" } }, { @@ -51,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", "state" : { - "revision" : "22bfadf7491d77a0bc1953af002cadbd61383e7d", - "version" : "6.0.2" + "revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656", + "version" : "6.0.3" } }, { @@ -87,8 +78,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/mpc-core-kit-swift", "state" : { - "branch" : "main", - "revision" : "183f205cb24ff8aa9c6c59bea905f365fe03d34e" + "branch" : "update_dependencies", + "revision" : "37cc49d743f7e4b211ec6168bdaf3110288bdd88" } }, { @@ -132,8 +123,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Web3Auth/single-factor-auth-swift", "state" : { - "revision" : "73c5066d369c7d2aa1057c56a89b7f1dcdda3270", - "version" : "5.0.0" + "branch" : "7.0.0", + "revision" : "d9a8fd7885e37e74e61010f8fb240cbbafd1e577" } }, { @@ -249,8 +240,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/tkey-mpc-swift", "state" : { - "revision" : "8fe0cc8d5cc2ad5d38bf068bc29f6af7e3146d08", - "version" : "3.0.0" + "branch" : "update_features", + "revision" : "00ed189447df83681092aabd5c64e65671ccd0d1" } }, { @@ -258,8 +249,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "ff85c3e96bfa29013309b487875c4d9383e4ac80", - "version" : "8.1.1" + "revision" : "23083bf8196d1f78c05b085ba8347f94734b1a16", + "version" : "9.0.1" } }, { diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/EthereumClient.swift b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/EthereumClient.swift index 0f2b0236..37b6f895 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/EthereumClient.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/EthereumClient.swift @@ -50,15 +50,11 @@ struct EthereumClient { } } - func broadcastSignedTransaction(transaction: SignedTransaction) async throws -> String { + func broadcastSignedTransaction(transactionHex: String) async throws -> String { do { - guard let transactionHex = transaction.raw?.web3.hexString else { - throw EthereumClientError.encodeIssue - } - let data = try await web3Client.networkProvider.send( method: "eth_sendRawTransaction", - params: [transactionHex], + params: ["0x" + transactionHex], receive: String.self ) diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/Extensions.swift b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/Extensions.swift index 2baf860b..287e227b 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/Extensions.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Helpers/Extensions.swift @@ -11,19 +11,19 @@ import tkey import MpcProviderSwift import web3 -extension MpcCoreKit : EvmSigner { - public func sign(message: Data) throws -> Data { - let data = try self.tssSign(message: message) - return data - } - - public var publicKey: Data { - let fullAddress = try! KeyPoint( - address: self.getTssPubKey().hexString - ).getPublicKey(format: .FullAddress) - - return Data(hex: fullAddress).suffix(64) - } - -} +//extension MpcCoreKit : EvmSigner { +// public func sign(message: Data) throws -> Data { +// let data = try self.tssSign(message: message) +// return data +// } +// +// public var publicKey: Data { +// let fullAddress = try! KeyPoint( +// address: self.getTssPubKey().hexString +// ).getPublicKey(format: .FullAddress) +// +// return Data(hex: fullAddress).suffix(64) +// } +// +//} diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Models/MainViewModel.swift b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Models/MainViewModel.swift index 545feb22..9cc84f72 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Models/MainViewModel.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Models/MainViewModel.swift @@ -21,22 +21,24 @@ class MainViewModel: ObservableObject { @Published var showAlert: Bool = false @Published var isLoaderVisible: Bool = false - var publicAddress: String! - + var publicAddress: EthereumAddress! private var mpcCoreKit: MpcCoreKit! private var ethereumClient: EthereumClient! - private var mpcEthereumProvider: MPCEthereumProvider! private var webAuth: WebAuth! var userInfo: [String: Any]! var alertContent: String = "" var loaderContent: String = "" func initialize() { - mpcCoreKit = MpcCoreKit( - web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", - web3AuthNetwork: .SAPPHIRE_MAINNET, - localStorage: UserStorage() + mpcCoreKit = try! MpcCoreKit( + options: .init( + web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", + manualSync: false, + web3AuthNetwork: .sapphire(.SAPPHIRE_MAINNET), + localStorage: UserStorage(), + overwriteMetadataUrl: "http://127.0.0.1:5051" + ) ) webAuth = Auth0.webAuth(clientId: "hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O", domain: "web3auth.au.auth0.com") @@ -72,7 +74,7 @@ class MainViewModel: ObservableObject { if(!self.isRecoveryRequired) { try await login() - + } hideLoader() @@ -131,12 +133,17 @@ class MainViewModel: ObservableObject { func signMessage(onSigned: @escaping (_ signedMessage: String?, _ error: String?) -> ()){ Task { do { - showLoader("Signing Message") - let signature = try mpcEthereumProvider.signMessage( - message: "Welcome to Web3Auth".data(using: .ascii)! - ) + let message = "YOUR_MESSAGE".data(using: .ascii)! + let prefix = "\u{19}Ethereum Signed Message:\n\(String(message.count))" + guard var data = prefix.data(using: .ascii) else { + throw "Incorrect Data" + } + + data.append(message) + let hash = data.web3.keccak256 + let signature = try await mpcCoreKit.tssSign(message: hash) hideLoader() - onSigned(signature, nil) + onSigned(signature.hexString, nil) } catch let error { hideLoader() onSigned(nil, error.localizedDescription) @@ -149,23 +156,20 @@ class MainViewModel: ObservableObject { Task { do { showLoader("Sending Transaction") - let address = EthereumAddress( - stringLiteral: self.publicAddress - ) let transaction = EthereumTransaction.init( - to: address, - data: Data.init(hex: "0x00") + to: self.publicAddress, + data: Data.init(hex: "0x00")! ) let gasLimit = try await self.ethereumClient.getGasLimit( transaction: transaction ) let gasPrice = try await self.ethereumClient.getGasPrice() - let nonce = try await self.ethereumClient.getNonce(address: address) + let nonce = try await self.ethereumClient.getNonce(address: self.publicAddress) let finalTransaction = EthereumTransaction( - from: address, - to: address, + from: self.publicAddress, + to: self.publicAddress, value: 1000000000000, data: transaction.data, nonce: nonce, @@ -174,12 +178,10 @@ class MainViewModel: ObservableObject { chainId: Int(self.ethereumClient.getChainId()) ) - let signedTransaction = try mpcEthereumProvider.sign( - transaction: finalTransaction - ) + let signedTransaction = try await mpcCoreKit.tssSign(message: finalTransaction.raw!.web3.keccak256) let hash = try await ethereumClient.broadcastSignedTransaction( - transaction: signedTransaction + transactionHex: signedTransaction.hexString ) hideLoader() onSend(hash, nil) @@ -199,18 +201,15 @@ class MainViewModel: ObservableObject { do { showLoader("Adding new factor") let factor = try await mpcCoreKit.createFactor( - tssShareIndex: .RECOVERY, + tssShareIndex: .recovery, factorKey: nil, factorDescription: .SeedPhrase ) - guard let seedPhrase = mpcCoreKit.keyToMnemonic( + let seedPhrase = try mpcCoreKit.keyToMnemonic( factorKey: factor, format: "mnemonic" - ) else { - return - } - + ) print(seedPhrase) UIPasteboard.general.string = seedPhrase @@ -228,13 +227,10 @@ class MainViewModel: ObservableObject { Task { do { showLoader("Recovering account") - guard let factorKey = mpcCoreKit.mnemonicToKey( + let factorKey = try mpcCoreKit.mnemonicToKey( shareMnemonic: seedPhrase, format: "mnemonic" - ) else { - hideLoader() - return - } + ) try await mpcCoreKit.inputFactor( factorKey: factorKey @@ -258,19 +254,16 @@ class MainViewModel: ObservableObject { Task { do { showLoader("Enabling MFA") - let recoveryFactorKey = try await mpcCoreKit.enableMFA() - guard let seedPhrase = mpcCoreKit.keyToMnemonic( - factorKey: recoveryFactorKey!, - format: "mnemonic" - ) else { - hideLoader() - return - } - - print(seedPhrase) - - UIPasteboard.general.string = seedPhrase - showAlert(message: "MFA is enabled, and seedphrase is copied to clipboard. \(seedPhrase)") + let recoveryFactorKey = try await mpcCoreKit.enableMFAWithRecoveryFactor() +// let seedPhrase = try mpcCoreKit.keyToMnemonic( +// factorKey: recoveryFactorKey, +// format: "mnemonic" +// ) +// +// print(seedPhrase) +// +// UIPasteboard.general.string = seedPhrase +// showAlert(message: "MFA is enabled, and seedphrase is copied to clipboard. \(seedPhrase)") hideLoader() await refreshFactorPubs() } catch let error { @@ -286,19 +279,16 @@ class MainViewModel: ObservableObject { let keyDetails = try await mpcCoreKit.getKeyDetails() print(keyDetails.requiredFactors) - mpcEthereumProvider = MPCEthereumProvider(evmSigner: mpcCoreKit) let fullAddress = try KeyPoint( address: pubKey.hexString ).getPublicKey(format: .FullAddress) - let address = KeyUtil.generateAddress( - from: Data(hex: fullAddress).suffix(64) + publicAddress = KeyUtil.generateAddress( + from: Data(hex: fullAddress)!.suffix(64) ) - print(address) - publicAddress = mpcEthereumProvider.address.toChecksumAddress() await refreshFactorPubs() toggleIsLoggedIn() } diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Views/HomeView.swift b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Views/HomeView.swift index 6ddab027..00ce86a3 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Views/HomeView.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-auth0/mpc-core-kit-ios-auth0/Views/HomeView.swift @@ -23,9 +23,9 @@ struct HomeView: View { Button( action: { viewModel.showAlert(message: "Address is copied to clipboard") - UIPasteboard.general.string = viewModel.publicAddress + UIPasteboard.general.string = viewModel.publicAddress.toChecksumAddress() }, label: { - Text(viewModel.publicAddress) + Text(viewModel.publicAddress.toChecksumAddress()) }) Button( diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.pbxproj b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.pbxproj index 9574f6c3..64380cb6 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.pbxproj +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.pbxproj @@ -7,9 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 284712222BFB94220088411D /* MpcProviderSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 284712212BFB94220088411D /* MpcProviderSwift */; }; 284712242BFB94450088411D /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284712232BFB94450088411D /* Extension.swift */; }; - 284712272BFB97FE0088411D /* mpc-core-kit-swift in Frameworks */ = {isa = PBXBuildFile; productRef = 284712262BFB97FE0088411D /* mpc-core-kit-swift */; }; 284BE5FE2BC509500049C203 /* mpc_core_kit_ios_quick_startApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284BE5FD2BC509500049C203 /* mpc_core_kit_ios_quick_startApp.swift */; }; 284BE6002BC509500049C203 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284BE5FF2BC509500049C203 /* ContentView.swift */; }; 284BE6022BC509520049C203 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 284BE6012BC509520049C203 /* Assets.xcassets */; }; @@ -23,6 +21,9 @@ 284BE6342BC512A80049C203 /* RecoveryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284BE6332BC512A80049C203 /* RecoveryView.swift */; }; 284BE6362BC512B20049C203 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284BE6352BC512B20049C203 /* HomeView.swift */; }; 284BE63E2BC55A080049C203 /* EthereumHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 284BE63D2BC55A080049C203 /* EthereumHelper.swift */; }; + 28CC81D62C96B44B0041F724 /* mpc-core-kit-swift in Frameworks */ = {isa = PBXBuildFile; productRef = 28CC81D52C96B44B0041F724 /* mpc-core-kit-swift */; }; + 28CC81D92C97F7B40041F724 /* Web3SwiftMpcProvider in Frameworks */ = {isa = PBXBuildFile; productRef = 28CC81D82C97F7B40041F724 /* Web3SwiftMpcProvider */; }; + 28CC81DC2C97FC850041F724 /* web3.swift in Frameworks */ = {isa = PBXBuildFile; productRef = 28CC81DB2C97FC850041F724 /* web3.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -67,8 +68,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 284712222BFB94220088411D /* MpcProviderSwift in Frameworks */, - 284712272BFB97FE0088411D /* mpc-core-kit-swift in Frameworks */, + 28CC81D62C96B44B0041F724 /* mpc-core-kit-swift in Frameworks */, + 28CC81DC2C97FC850041F724 /* web3.swift in Frameworks */, + 28CC81D92C97F7B40041F724 /* Web3SwiftMpcProvider in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -193,8 +195,9 @@ ); name = "mpc-core-kit-ios-quick-start"; packageProductDependencies = ( - 284712212BFB94220088411D /* MpcProviderSwift */, - 284712262BFB97FE0088411D /* mpc-core-kit-swift */, + 28CC81D52C96B44B0041F724 /* mpc-core-kit-swift */, + 28CC81D82C97F7B40041F724 /* Web3SwiftMpcProvider */, + 28CC81DB2C97FC850041F724 /* web3.swift */, ); productName = "mpc-core-kit-ios-quick-start"; productReference = 284BE5FA2BC509500049C203 /* mpc-core-kit-ios-quick-start.app */; @@ -269,8 +272,9 @@ ); mainGroup = 284BE5F12BC509500049C203; packageReferences = ( - 284712202BFB94220088411D /* XCRemoteSwiftPackageReference "MpcProviderSwift" */, - 284712252BFB97FE0088411D /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */, + 28CC81D42C96B44B0041F724 /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */, + 28CC81D72C97F7B40041F724 /* XCRemoteSwiftPackageReference "web3-swift-mpc-provider" */, + 28CC81DA2C97FC850041F724 /* XCRemoteSwiftPackageReference "web3" */, ); productRefGroup = 284BE5FB2BC509500049C203 /* Products */; projectDirPath = ""; @@ -654,34 +658,47 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 284712202BFB94220088411D /* XCRemoteSwiftPackageReference "MpcProviderSwift" */ = { + 28CC81D42C96B44B0041F724 /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/tkey/MpcProviderSwift"; + repositoryURL = "https://github.com/tkey/mpc-core-kit-swift"; requirement = { - branch = main; - kind = branch; + kind = revision; + revision = 37cc49d743f7e4b211ec6168bdaf3110288bdd88; }; }; - 284712252BFB97FE0088411D /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */ = { + 28CC81D72C97F7B40041F724 /* XCRemoteSwiftPackageReference "web3-swift-mpc-provider" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/tkey/mpc-core-kit-swift"; + repositoryURL = "https://github.com/tkey/web3-swift-mpc-provider"; requirement = { branch = main; kind = branch; }; }; + 28CC81DA2C97FC850041F724 /* XCRemoteSwiftPackageReference "web3" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/argentlabs/web3.swift"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.6.1; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 284712212BFB94220088411D /* MpcProviderSwift */ = { + 28CC81D52C96B44B0041F724 /* mpc-core-kit-swift */ = { + isa = XCSwiftPackageProductDependency; + package = 28CC81D42C96B44B0041F724 /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */; + productName = "mpc-core-kit-swift"; + }; + 28CC81D82C97F7B40041F724 /* Web3SwiftMpcProvider */ = { isa = XCSwiftPackageProductDependency; - package = 284712202BFB94220088411D /* XCRemoteSwiftPackageReference "MpcProviderSwift" */; - productName = MpcProviderSwift; + package = 28CC81D72C97F7B40041F724 /* XCRemoteSwiftPackageReference "web3-swift-mpc-provider" */; + productName = Web3SwiftMpcProvider; }; - 284712262BFB97FE0088411D /* mpc-core-kit-swift */ = { + 28CC81DB2C97FC850041F724 /* web3.swift */ = { isa = XCSwiftPackageProductDependency; - package = 284712252BFB97FE0088411D /* XCRemoteSwiftPackageReference "mpc-core-kit-swift" */; - productName = "mpc-core-kit-swift"; + package = 28CC81DA2C97FC850041F724 /* XCRemoteSwiftPackageReference "web3" */; + productName = web3.swift; }; /* End XCSwiftPackageProductDependency section */ }; diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6c08f666..1a502013 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,15 +1,6 @@ { - "originHash" : "d4e2e31ed5983dc7f95752b5f7cec96879f6838af173debe46909665a1b9adab", + "originHash" : "8b174dfbe030966e4aeb0978f2c1b429534a610c68d874fa48f4b632675e3f60", "pins" : [ - { - "identity" : "anycodable", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Flight-School/AnyCodable", - "state" : { - "revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05", - "version" : "0.6.7" - } - }, { "identity" : "bigint", "kind" : "remoteSourceControl", @@ -33,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/customauth-swift-sdk", "state" : { - "revision" : "60b48acb161fb4341c353c27bc6dd96af76887ff", - "version" : "10.0.1" + "branch" : "features_update", + "revision" : "576139ce446e397bce4f2b68b9b7d28ab5b0082f" } }, { @@ -42,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/fetch-node-details-swift.git", "state" : { - "revision" : "22bfadf7491d77a0bc1953af002cadbd61383e7d", - "version" : "6.0.2" + "revision" : "4bd96c33ba8d02d9e27190c5c7cedf09cfdfd656", + "version" : "6.0.3" } }, { @@ -78,17 +69,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/mpc-core-kit-swift", "state" : { - "branch" : "main", - "revision" : "183f205cb24ff8aa9c6c59bea905f365fe03d34e" - } - }, - { - "identity" : "mpcproviderswift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/tkey/MpcProviderSwift", - "state" : { - "branch" : "main", - "revision" : "f087b89ee543710fc23b35dc05fa233b1d16b7e1" + "revision" : "37cc49d743f7e4b211ec6168bdaf3110288bdd88" } }, { @@ -114,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Web3Auth/single-factor-auth-swift", "state" : { - "revision" : "73c5066d369c7d2aa1057c56a89b7f1dcdda3270", - "version" : "5.0.0" + "branch" : "7.0.0", + "revision" : "d9a8fd7885e37e74e61010f8fb240cbbafd1e577" } }, { @@ -150,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", - "version" : "1.1.0" + "revision" : "9bf03ff58ce34478e66aaee630e491823326fd06", + "version" : "1.1.3" } }, { @@ -159,8 +140,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-http-types", "state" : { - "revision" : "9bee2fdb79cc740081abd8ebd80738063d632286", - "version" : "1.1.0" + "revision" : "ae67c8178eb46944fd85e4dc6dd970e1f3ed6ccd", + "version" : "1.3.0" } }, { @@ -168,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5", - "version" : "1.5.4" + "revision" : "9cb486020ebf03bfa5b5df985387a14a98744537", + "version" : "1.6.1" } }, { @@ -177,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "359c461e5561d22c6334828806cc25d759ca7aa6", - "version" : "2.65.0" + "revision" : "9746cf80e29edfef2a39924a66731249223f42a3", + "version" : "2.72.0" } }, { @@ -186,8 +167,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-extras.git", "state" : { - "revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", - "version" : "1.22.0" + "revision" : "d1ead62745cc3269e482f1c51f27608057174379", + "version" : "1.24.0" } }, { @@ -195,8 +176,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-http2.git", "state" : { - "revision" : "c6afe04165c865faaa687b42c32ed76dfcc91076", - "version" : "1.31.0" + "revision" : "b5f7062b60e4add1e8c343ba4eb8da2e324b3a94", + "version" : "1.34.0" } }, { @@ -204,8 +185,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5", - "version" : "2.26.0" + "revision" : "7b84abbdcef69cc3be6573ac12440220789dcd69", + "version" : "2.27.2" } }, { @@ -222,8 +203,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "f9266c85189c2751589a50ea5aec72799797e471", - "version" : "1.3.0" + "revision" : "d2ba781702a1d8285419c15ee62fd734a9437ff5", + "version" : "1.3.2" } }, { @@ -231,8 +212,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/tkey/tkey-mpc-swift", "state" : { - "revision" : "8fe0cc8d5cc2ad5d38bf068bc29f6af7e3146d08", - "version" : "3.0.0" + "branch" : "update_features", + "revision" : "00ed189447df83681092aabd5c64e65671ccd0d1" } }, { @@ -240,8 +221,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "ff85c3e96bfa29013309b487875c4d9383e4ac80", - "version" : "8.1.1" + "revision" : "23083bf8196d1f78c05b085ba8347f94734b1a16", + "version" : "9.0.1" } }, { @@ -253,6 +234,15 @@ "version" : "4.0.0" } }, + { + "identity" : "web3-swift-mpc-provider", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tkey/web3-swift-mpc-provider", + "state" : { + "branch" : "main", + "revision" : "5e8d0c51ff84080d4ed385df1dc69172f4d57228" + } + }, { "identity" : "web3.swift", "kind" : "remoteSourceControl", diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/EthereumHelper.swift b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/EthereumHelper.swift index 639b68a1..fa4775cd 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/EthereumHelper.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/EthereumHelper.swift @@ -50,12 +50,9 @@ struct EthereumClient { } } - func broadcastSignedTransaction(transaction: SignedTransaction) async throws -> String { + func broadcastSignedTransaction(transactionHex: String) async throws -> String { do { - guard let transactionHex = transaction.raw?.web3.hexString else { - throw EthereumClientError.encodeIssue - } - + let data = try await web3Client.networkProvider.send( method: "eth_sendRawTransaction", params: [transactionHex], diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/Extension.swift b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/Extension.swift index 2f100462..0b2c7f7a 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/Extension.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Helpers/Extension.swift @@ -11,18 +11,18 @@ import tkey import MpcProviderSwift import web3 -extension MpcCoreKit : EvmSigner { - public func sign(message: Data) throws -> Data { - let data = try self.tssSign(message: message) - return data - } - - public var publicKey: Data { - let fullAddress = try! KeyPoint( - address: self.getTssPubKey().hexString - ).getPublicKey(format: .FullAddress) - - return Data(hex: fullAddress).suffix(64) - } - -} +//extension MpcCoreKit : EvmSigner { +// public func sign(message: Data) throws -> Data { +// let data = try self.tssSign(message: message) +// return data +// } +// +// public var publicKey: Data { +// let fullAddress = try! KeyPoint( +// address: self.getTssPubKey().hexString +// ).getPublicKey(format: .FullAddress) +// +// return Data(hex: fullAddress).suffix(64) +// } +// +//} diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Models/MainViewModel.swift b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Models/MainViewModel.swift index 291c5fee..946f782c 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Models/MainViewModel.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Models/MainViewModel.swift @@ -7,7 +7,7 @@ import Foundation import mpc_core_kit_swift -import MpcProviderSwift +import Web3SwiftMpcProvider import web3 import UIKit @@ -16,18 +16,20 @@ class MainViewModel: ObservableObject { @Published var isRecoveryRequired: Bool = false @Published var factorPubs: [String] = [] - var publicAddress: String! + var publicAddress: EthereumAddress! private var mpcCoreKit: MpcCoreKit! private var ethereumClient: EthereumClient! - private var mpcEthereumProvider: MPCEthereumProvider! func initialize() { - mpcCoreKit = MpcCoreKit( - web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", - web3AuthNetwork: .SAPPHIRE_MAINNET, - localStorage: UserStorage() + mpcCoreKit = try! MpcCoreKit( + options: Web3AuthOptions( + web3AuthClientId: "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ", + manualSync: false, + web3AuthNetwork: .sapphire(.SAPPHIRE_MAINNET), + localStorage: UserStorage() + ) ) ethereumClient = EthereumClient() @@ -57,10 +59,11 @@ class MainViewModel: ObservableObject { Task { do { let result = try await mpcCoreKit.loginWithOAuth( - loginProvider: .google, - clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com", - verifier: "w3a-google-demo" - + singleLoginParams: .init( + typeOfLogin: .google, + verifier: "w3a-google-demo", + clientId: "519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com" + ) ) DispatchQueue.main.async { @@ -83,6 +86,7 @@ class MainViewModel: ObservableObject { DispatchQueue.main.async { self.isRecoveryRequired.toggle() } + toggleIsLoggedIn() } catch let error { print(error.localizedDescription) } @@ -104,9 +108,17 @@ class MainViewModel: ObservableObject { func signMessage(onSigned: @escaping (_ signedMessage: String?, _ error: String?) -> ()){ Task { do { - print(mpcCoreKit.debugDescription) - let signature = try mpcEthereumProvider.signMessage(message: "YOUR_MESSAGE".data(using: .ascii)!) - onSigned(signature, nil) + let message = "YOUR_MESSAGE".data(using: .ascii)! + let prefix = "\u{19}Ethereum Signed Message:\n\(String(message.count))" + guard var data = prefix.data(using: .ascii) else { + throw "Incorrect Data" + } + + data.append(message) + let hash = data.web3.keccak256 + let signature = try await mpcCoreKit.tssSign(message: hash) + + onSigned(signature.web3.hexString, nil) } catch let error { onSigned(nil, error.localizedDescription) } @@ -118,11 +130,11 @@ class MainViewModel: ObservableObject { do { let address = EthereumAddress( - stringLiteral: self.publicAddress + stringLiteral: self.publicAddress.toChecksumAddress() ) let transaction = EthereumTransaction.init( to: address, - data: Data.init(hex: "0x") + data: Data.init(hex: "0x")! ) let gasLimit = try await self.ethereumClient.getGasLimit( @@ -142,12 +154,12 @@ class MainViewModel: ObservableObject { chainId: Int(self.ethereumClient.getChainId()) ) - let signedTransaction = try mpcEthereumProvider.sign( - transaction: finalTransaction - ) + + + let signedTransaction = try await mpcCoreKit.tssSign(message: finalTransaction.raw!.web3.keccak256) let hash = try await ethereumClient.broadcastSignedTransaction( - transaction: signedTransaction + transactionHex: signedTransaction.hexString ) onSend(hash, nil) @@ -164,22 +176,22 @@ class MainViewModel: ObservableObject { Task { do { let factor = try await mpcCoreKit.createFactor( - tssShareIndex: .RECOVERY, + tssShareIndex: .recovery, factorKey: nil, factorDescription: .SeedPhrase ) - guard let seedPhrase = mpcCoreKit.keyToMnemonic( + let seedPhrase = try mpcCoreKit.keyToMnemonic( factorKey: factor, format: "mnemonic" - ) else { - return - } + ) print(seedPhrase) UIPasteboard.general.string = seedPhrase try await refreshFactorPubs() + } catch let error { + print(error.localizedDescription) } } } @@ -187,12 +199,10 @@ class MainViewModel: ObservableObject { func recoverUsingSeedPhrase(seedPhrase: String) { Task { do { - guard let factorKey = mpcCoreKit.mnemonicToKey( + let factorKey = try mpcCoreKit.mnemonicToKey( shareMnemonic: seedPhrase, format: "mnemonic" - ) else { - return - } + ) print(factorKey.count) @@ -214,7 +224,7 @@ class MainViewModel: ObservableObject { func enableMFA() { Task { do { - _ = try await mpcCoreKit.enableMFA() + _ = try await mpcCoreKit.enableMFAWithRecoveryFactor() try await refreshFactorPubs() } catch let error { print(error.localizedDescription) @@ -223,8 +233,10 @@ class MainViewModel: ObservableObject { } private func login() async throws { - mpcEthereumProvider = MPCEthereumProvider(evmSigner: mpcCoreKit) - publicAddress = mpcEthereumProvider.address.toChecksumAddress() + let extendedPubKey = try await mpcCoreKit.getTssPubKey() + + + publicAddress = KeyUtil.generateAddress(from: extendedPubKey) try await refreshFactorPubs() toggleIsLoggedIn() } diff --git a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Views/HomeView.swift b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Views/HomeView.swift index 357b354e..de642f87 100644 --- a/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Views/HomeView.swift +++ b/mpc-core-kit-ios/mpc-core-kit-ios-quick-start/mpc-core-kit-ios-quick-start/Views/HomeView.swift @@ -21,9 +21,9 @@ struct HomeView: View { Section(header: Text("Public Address")) { Button( action: { - UIPasteboard.general.string = viewModel.publicAddress + UIPasteboard.general.string = viewModel.publicAddress.toChecksumAddress() }, label: { - Text(viewModel.publicAddress) + Text(viewModel.publicAddress.toChecksumAddress()) }) }