-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from tkey/tkey-mpc-ios-sfa
tKey MPC iOS with SFA
- Loading branch information
Showing
27 changed files
with
3,672 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
tkey-mpc-ios/tkey-ios-mpc/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tkey-mpc-ios/tkey-ios-mpc/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CLIENT_ID</key> | ||
<string>461819774167-r1e9u2gp802tlkro6j3j09eeinh4ptmp.apps.googleusercontent.com</string> | ||
<key>REVERSED_CLIENT_ID</key> | ||
<string>com.googleusercontent.apps.461819774167-r1e9u2gp802tlkro6j3j09eeinh4ptmp</string> | ||
<key>ANDROID_CLIENT_ID</key> | ||
<string>461819774167-93iair46nluf28pdbpmqq65eqktdbb7g.apps.googleusercontent.com</string> | ||
<key>API_KEY</key> | ||
<string>AIzaSyAttkINEO4AWRc2jJDHa5fPYp_1EtujcH0</string> | ||
<key>GCM_SENDER_ID</key> | ||
<string>461819774167</string> | ||
<key>PLIST_VERSION</key> | ||
<string>1</string> | ||
<key>BUNDLE_ID</key> | ||
<string>com.w3a.tkey-ios-mpc</string> | ||
<key>PROJECT_ID</key> | ||
<string>web3auth-oauth-logins</string> | ||
<key>STORAGE_BUCKET</key> | ||
<string>web3auth-oauth-logins.appspot.com</string> | ||
<key>IS_ADS_ENABLED</key> | ||
<false></false> | ||
<key>IS_ANALYTICS_ENABLED</key> | ||
<false></false> | ||
<key>IS_APPINVITE_ENABLED</key> | ||
<true></true> | ||
<key>IS_GCM_ENABLED</key> | ||
<true></true> | ||
<key>IS_SIGNIN_ENABLED</key> | ||
<true></true> | ||
<key>GOOGLE_APP_ID</key> | ||
<string>1:461819774167:ios:6b838a8ee53c76d55b9c92</string> | ||
<key>DATABASE_URL</key> | ||
<string>https://web3auth-oauth-logins-default-rtdb.asia-southeast1.firebasedatabase.app</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// EthereumClient.swift | ||
// tkey-ios-mpc | ||
// | ||
// Created by Ayush B on 27/03/24. | ||
// | ||
|
||
import Foundation | ||
import web3 | ||
import BigInt | ||
import Web3SwiftMpcProvider | ||
|
||
struct EthereumClient { | ||
let web3Client: EthereumHttpClient! | ||
var networkId: String = "11155111" | ||
|
||
init() { | ||
self.web3Client = EthereumHttpClient( | ||
url: URL(string: "https://1rpc.io/sepolia")!, | ||
network: .fromString(networkId) | ||
) | ||
} | ||
|
||
func getNonce(address: EthereumAddress) async throws -> Int{ | ||
do { | ||
let nonce = try await web3Client.eth_getTransactionCount( | ||
address: address, block: .Latest | ||
) | ||
return nonce + 1 | ||
} catch let error { | ||
throw error | ||
} | ||
} | ||
|
||
func getGasPrice() async throws -> BigUInt { | ||
do { | ||
let gasPrice = try await web3Client.eth_gasPrice() | ||
return gasPrice | ||
} catch let error { | ||
throw error | ||
} | ||
} | ||
|
||
func getGasLimit(transaction: EthereumTransaction) async throws -> BigUInt { | ||
do { | ||
let gasLimit = try await web3Client.eth_estimateGas(transaction) | ||
return gasLimit | ||
} catch let error { | ||
throw error | ||
} | ||
} | ||
|
||
func sendRawTransaction( | ||
transaction: EthereumTransaction, | ||
ethTssAccount: EthereumTssAccount | ||
) async throws -> String { | ||
do { | ||
let hash = try await web3Client.eth_sendRawTransaction( | ||
transaction, | ||
withAccount: ethTssAccount | ||
) | ||
|
||
return hash | ||
} catch let error { | ||
throw error | ||
} | ||
} | ||
|
||
func getChainId() -> String { | ||
return networkId | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// KeyChainInterface.swift | ||
// tkey-ios-mpc | ||
// | ||
// Created by Ayush B on 23/03/24. | ||
// | ||
|
||
import Foundation | ||
import Security | ||
|
||
public class KeychainInterface { | ||
// Note: This class is provided for example purposes only, | ||
// it is not intended to be used in a production environment. | ||
|
||
public enum KeychainError: Error { | ||
case itemNotFound | ||
case invalidItemFormat | ||
case unexpectedStatus(OSStatus) | ||
} | ||
|
||
// TODO: add delete function | ||
|
||
public static func save(item: String, key: String, identifier: String = "web3auth.tkey-ios") throws { | ||
let query: [String: AnyObject] = [ | ||
kSecAttrService as String: identifier as AnyObject, | ||
kSecAttrAccount as String: key as AnyObject, | ||
kSecClass as String: kSecClassGenericPassword, | ||
kSecValueData as String: item.data(using: .utf8)! as AnyObject | ||
] | ||
|
||
// First delete item if found | ||
var status = SecItemDelete(query as CFDictionary) | ||
|
||
guard status == errSecSuccess || status == errSecItemNotFound else { | ||
throw KeychainError.unexpectedStatus(status) | ||
} | ||
|
||
// Add new item | ||
status = SecItemAdd( | ||
query as CFDictionary, | ||
nil | ||
) | ||
|
||
guard status == errSecSuccess else { | ||
throw KeychainError.unexpectedStatus(status) | ||
} | ||
} | ||
|
||
public static func fetch(key: String, identifier: String = "web3auth.tkey-ios") throws -> String { | ||
let query: [String: AnyObject] = [ | ||
kSecAttrService as String: identifier as AnyObject, | ||
kSecAttrAccount as String: key as AnyObject, | ||
kSecClass as String: kSecClassGenericPassword, | ||
kSecMatchLimit as String: kSecMatchLimitOne, | ||
kSecReturnData as String: kCFBooleanTrue | ||
] | ||
|
||
var itemCopy: AnyObject? | ||
let status = SecItemCopyMatching( | ||
query as CFDictionary, | ||
&itemCopy | ||
) | ||
|
||
guard status != errSecItemNotFound else { | ||
throw KeychainError.itemNotFound | ||
} | ||
|
||
guard status == errSecSuccess else { | ||
throw KeychainError.unexpectedStatus(status) | ||
} | ||
|
||
guard let item = itemCopy as? Data else { | ||
throw KeychainError.invalidItemFormat | ||
} | ||
|
||
return String(decoding: item, as: UTF8.self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>com.googleusercontent.apps.461819774167-r1e9u2gp802tlkro6j3j09eeinh4ptmp</string> | ||
</array> | ||
</dict> | ||
</array> | ||
</dict> | ||
</plist> |
6 changes: 6 additions & 0 deletions
6
tkey-mpc-ios/tkey-ios-mpc/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Oops, something went wrong.