Skip to content

Commit

Permalink
Merge pull request #40 from tkey/tkey-mpc-ios-sfa
Browse files Browse the repository at this point in the history
tKey MPC iOS with SFA
  • Loading branch information
shahbaz17 authored Apr 8, 2024
2 parents 9f62b84 + f891130 commit 072b80c
Show file tree
Hide file tree
Showing 27 changed files with 3,672 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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
}
}
6 changes: 6 additions & 0 deletions tkey-mpc-ios/tkey-ios-mpc/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
38 changes: 38 additions & 0 deletions tkey-mpc-ios/tkey-ios-mpc/GoogleService-Info.plist
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>
72 changes: 72 additions & 0 deletions tkey-mpc-ios/tkey-ios-mpc/Helpers/EthereumClient.swift
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
}
}
78 changes: 78 additions & 0 deletions tkey-mpc-ios/tkey-ios-mpc/Helpers/KeyChainInterface.swift
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)
}
}
17 changes: 17 additions & 0 deletions tkey-mpc-ios/tkey-ios-mpc/Info.plist
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit 072b80c

Please sign in to comment.