Skip to content

Commit

Permalink
Merge pull request #30 from Web3Auth/update_dependencies
Browse files Browse the repository at this point in the history
update dependencies
  • Loading branch information
metalurgical authored Jan 15, 2025
2 parents 5331918 + 2b126ca commit a9d23ff
Show file tree
Hide file tree
Showing 22 changed files with 664 additions and 440 deletions.
72 changes: 18 additions & 54 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"pins" : [
{
"identity" : "anycodable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Flight-School/AnyCodable",
"state" : {
"revision" : "862808b2070cd908cb04f9aafe7de83d35f81b05",
"version" : "0.6.7"
}
},
{
"identity" : "bigint",
"kind" : "remoteSourceControl",
Expand All @@ -23,26 +14,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tkey/curvelib.swift",
"state" : {
"revision" : "9f88bd5e56d1df443a908f7a7e81ae4f4d9170ea",
"version" : "1.0.1"
"revision" : "432bf1abe7ff505fc2ac9fcf697341ff5b2dc6d0",
"version" : "2.0.0"
}
},
{
"identity" : "customauth-swift-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/customauth-swift-sdk",
"state" : {
"revision" : "60b48acb161fb4341c353c27bc6dd96af76887ff",
"version" : "10.0.1"
"revision" : "67f947d087e1c9c6ca37c6627b595fe6913bc558",
"version" : "11.0.2"
}
},
{
"identity" : "fetch-node-details-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/fetch-node-details-swift.git",
"state" : {
"revision" : "22bfadf7491d77a0bc1953af002cadbd61383e7d",
"version" : "6.0.2"
"revision" : "52fb5efaa94e0fe3775913ab00964bcb51601c2a",
"version" : "8.0.0"
}
},
{
Expand All @@ -59,53 +50,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/auth0/JWTDecode.swift.git",
"state" : {
"revision" : "58af7278797871e460d79496621b3e5366b865b2",
"version" : "3.1.0"
}
},
{
"identity" : "keychain-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/evgenyneu/keychain-swift.git",
"state" : {
"revision" : "d108a1fa6189e661f91560548ef48651ed8d93b9",
"version" : "20.0.0"
}
},
{
"identity" : "session-manager-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/session-manager-swift.git",
"state" : {
"revision" : "20cc7bff065d7fe53164d17e7714a3f17d4cea2a",
"version" : "4.0.2"
}
},
{
"identity" : "single-factor-auth-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Web3Auth/single-factor-auth-swift",
"state" : {
"revision" : "73c5066d369c7d2aa1057c56a89b7f1dcdda3270",
"version" : "5.0.0"
"revision" : "1e153ef009969543191970c66b7c60163c0b4a65",
"version" : "3.2.0"
}
},
{
"identity" : "socket.io-client-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/socketio/socket.io-client-swift",
"state" : {
"revision" : "175da8b5156f6b132436f0676cc84c2f6a766b6e",
"version" : "16.1.0"
"revision" : "42da871d9369f290d6ec4930636c40672143905b",
"version" : "16.1.1"
}
},
{
"identity" : "starscream",
"kind" : "remoteSourceControl",
"location" : "https://github.com/daltoniam/Starscream",
"state" : {
"revision" : "ac6c0fc9da221873e01bd1a0d4818498a71eef33",
"version" : "4.0.6"
"revision" : "c6bfd1af48efcc9a9ad203665db12375ba6b145a",
"version" : "4.0.8"
}
},
{
Expand All @@ -122,26 +86,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tkey/tkey-mpc-swift",
"state" : {
"revision" : "2df2d0a6c51afc76909028eb8542fe78e565d106",
"version" : "3.0.1"
"revision" : "74ea5301e316163b48e653ba107fd9edd4fe6bf8",
"version" : "4.0.2"
}
},
{
"identity" : "torus-utils-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/torus-utils-swift.git",
"state" : {
"revision" : "608c28404c506983bfec7bbd957632fc0544db8c",
"version" : "8.1.2"
"revision" : "baa822fc67bdb208ed1a2dc5b3c10485cfca15df",
"version" : "10.0.0"
}
},
{
"identity" : "tss-client-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/torusresearch/tss-client-swift.git",
"state" : {
"revision" : "40246d5e3ff1d2c97d41846576f7a81d58858981",
"version" : "4.0.0"
"revision" : "6f00e4e03184a77eea0330b5b8d092d1452b9eb4",
"version" : "5.0.1"
}
}
],
Expand Down
19 changes: 6 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,26 @@ import PackageDescription

let package = Package(
name: "mpc-core-kit-swift",
platforms: [ .iOS(.v14) ],
platforms: [ .iOS(.v14), .macOS(.v11) ],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "mpc-core-kit-swift",
targets: ["mpc-core-kit-swift"]),
],
dependencies: [
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
.package(url: "https://github.com/torusresearch/tss-client-swift.git", from: "4.0.0"),
.package(url: "https://github.com/tkey/tkey-mpc-swift", from: "3.0.1"),
.package(url: "https://github.com/torusresearch/customauth-swift-sdk", from: "10.0.1"),
.package(url: "https://github.com/Web3Auth/single-factor-auth-swift", from: "5.0.0"),
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
.package(url: "https://github.com/torusresearch/tss-client-swift.git", from: "5.0.1"),
.package(url: "https://github.com/tkey/tkey-mpc-swift", from: "4.0.2"),
.package(url: "https://github.com/torusresearch/customauth-swift-sdk", from: "11.0.2"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0")
],

targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "mpc-core-kit-swift",
dependencies: [
.product(name: "CustomAuth", package: "customauth-swift-sdk"),
.product(name: "SingleFactorAuth", package: "single-factor-auth-swift"),
.product(name: "tkey", package: "tkey-mpc-swift" ),
.product(name: "tssClientSwift", package: "tss-client-swift" ),
.product(name: "JWTDecode", package: "JWTDecode.swift")
.product(name: "tssClientSwift", package: "tss-client-swift" )
]
),
.testTarget(
Expand Down
18 changes: 15 additions & 3 deletions Sources/mpc-core-kit-swift/CoreKitError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum CoreKitError: Error {
case invalidInput
case notFound(msg: String)
case factorKeyUnavailable
case tssIndexUnavailable
case metadataPubKeyUnavailable
case shareIndexNotFound
case notLoggedIn
Expand All @@ -18,7 +19,6 @@ public enum CoreKitError: Error {
case invalidTKey
case nodeDetailsMissing
case invalidMetadataUrl
case invalidOAuthKey
case invalidHashKey
case invalidAuthSignatures
case invalidFactorKey
Expand All @@ -28,6 +28,10 @@ public enum CoreKitError: Error {
case requireUncompressedPublicKey
case invalidStore
case noTssTags
case invalidDeviceFactorKey
case invalidTssPubKey
case invalidClientId
case runtime(_ msg: String)

public var errorDescription: String {
switch self {
Expand All @@ -41,6 +45,8 @@ public enum CoreKitError: Error {
return "Invalid input"
case .factorKeyUnavailable:
return "Factor key unavailable"
case .tssIndexUnavailable:
return "TSS index unavailable"
case .shareIndexNotFound:
return "Share index not found"
case .notLoggedIn:
Expand All @@ -65,8 +71,6 @@ public enum CoreKitError: Error {
return "Node details absent"
case .invalidMetadataUrl:
return "Invalid metadata url"
case .invalidOAuthKey:
return "Invalid OAuthKey"
case .invalidHashKey:
return "Invalid hash key"
case .invalidAuthSignatures:
Expand All @@ -85,6 +89,14 @@ public enum CoreKitError: Error {
return "Invalid Store"
case .noTssTags:
return "No Tss tags have been set"
case .invalidDeviceFactorKey:
return "Device factor key not found"
case let .runtime(msg: msg):
return msg
case .invalidTssPubKey:
return "Invalid tss public key"
case .invalidClientId:
return "Invalid client id"
}
}
}
20 changes: 10 additions & 10 deletions Sources/mpc-core-kit-swift/CoreKitStorage.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

public class CoreKitStorage {
public var storage: ILocalStorage
public var storage: IStorage
private var storeKey: String

public init(storeKey: String, storage: ILocalStorage) {
public init(storeKey: String, storage: IStorage) {
self.storage = storage
self.storeKey = storeKey
}
Expand All @@ -27,28 +27,28 @@ public class CoreKitStorage {
return resultStr
}

public func getStore() async throws -> [String: Any] {
public func getStore() async throws -> [String: String] {
let result = try await storage.get(key: storeKey)
if result.isEmpty { return [:] }
let store = try JSONSerialization.jsonObject(with: result) as? [String: Any]
let store = try JSONSerialization.jsonObject(with: result) as? [String: String]
guard let storeUnwrapped = store else {
throw CoreKitError.invalidStore
}
return storeUnwrapped
}

public func get<T>(key: String) async throws -> T {
public func get(key: String) async throws -> Data {
let store = try await getStore()
guard let item = store[key] as? T else {
guard let item = store[key] else {
throw CoreKitError.notFound(msg: "key \(key) value not found")
}
return item
return Data(base64Encoded: item) ?? Data()
}

public func set<T>(key: String, payload: T) async throws {
public func set(key: String, payload: Data) async throws {
var store: [String: Any] = try await getStore()
store.updateValue(payload, forKey: key)
let jsonData = try JSONSerialization.data(withJSONObject: store)
store.updateValue(payload.base64EncodedString(), forKey: key)
let jsonData = try JSONSerialization.data(withJSONObject: store, options: [])
try await storage.set(key: storeKey, payload: jsonData)
}

Expand Down
16 changes: 6 additions & 10 deletions Sources/mpc-core-kit-swift/DeviceFactorStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ public class DeviceFactorStorage: IFactorStorage {
}

public func setFactor(metadataPubKey: String, factorKey: String) async throws {
var localMetadata: [String: Any] = try await storage.get(key: metadataPubKey)

localMetadata["factorKey"] = factorKey
try await storage.set(key: metadataPubKey, payload: localMetadata)
guard let factorKeyData = Data(hexString: factorKey) else {
throw CoreKitError.invalidFactorKey
}
try await storage.set(key: metadataPubKey, payload: factorKeyData)
}

public func getFactor(metadataPubKey: String) async throws -> String {
let localMetadata: [String: Any] = try await storage.get(key: metadataPubKey)
guard let deviceFactor = localMetadata["factorKey"] as? String else {
throw CoreKitError.notFound(msg: "device factor not found")
}
return deviceFactor
let localMetadata: Data = try await storage.get(key: metadataPubKey)
return localMetadata.hexString
}
}

47 changes: 17 additions & 30 deletions Sources/mpc-core-kit-swift/Helper.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BigInt
import FetchNodeDetails
import Foundation
import SingleFactorAuth

#if canImport(tkey)
import tkey
Expand All @@ -15,40 +14,28 @@ import SingleFactorAuth
import tssClientSwift
#endif

public class FactorDescription: Codable {
public let module: FactorType
public let tssIndex: TssShareType
public let description: String?
public let dateAdded: Int

public init(module: FactorType, tssIndex: TssShareType, description: String?, dateAdded: Int) {
self.module = module
self.tssIndex = tssIndex
self.description = description
self.dateAdded = dateAdded
}
}

public func createCoreKitFactorDescription(module: FactorType, tssIndex: TssShareType, additional: [String: Any] = [:]) -> [String: Any] {
var description = additional

description["module"] = module
description["tssShareIndex"] = tssIndex
description["dateAdded"] = Date().timeIntervalSince1970

return description
public func createCoreKitFactorDescription(module: FactorType, tssIndex: TssShareType, dateAdded: Int, description: String? = nil) -> FactorDescription {
return FactorDescription(module: module, tssIndex: tssIndex, description: description, dateAdded: dateAdded)
}

func factorDescriptionToJsonStr(dataObj: [String: Any]) throws -> String {
let json = try JSONSerialization.data(withJSONObject: dataObj)
func factorDescriptionToJsonStr(dataObj: FactorDescription) throws -> String {
let json = try JSONEncoder().encode(dataObj)
guard let jsonStr = String(data: json, encoding: .utf8) else {
throw CoreKitError.invalidResult
}
return jsonStr
}

func convertWeb3AuthNetworkToTorusNetWork(network: Web3AuthNetwork) -> TorusNetwork {
switch network {
case Web3AuthNetwork.SAPPHIRE_DEVNET: return .sapphire(.SAPPHIRE_DEVNET)
case Web3AuthNetwork.SAPPHIRE_MAINNET: return .sapphire(.SAPPHIRE_MAINNET)
case Web3AuthNetwork.MAINNET: return .legacy(.MAINNET)
case Web3AuthNetwork.TESTNET: return .legacy(.TESTNET)
case Web3AuthNetwork.CYAN: return .legacy(.CYAN)
case Web3AuthNetwork.AQUA: return .legacy(.AQUA)
case Web3AuthNetwork.CELESTE: return .legacy(.CELESTE)
case Web3AuthNetwork.CUSTOM: return .sapphire(.SAPPHIRE_MAINNET)
}
}

public extension Web3AuthNetwork {
func toTorusNetwork() -> TorusNetwork {
return convertWeb3AuthNetworkToTorusNetWork(network: self)
}
}
Loading

0 comments on commit a9d23ff

Please sign in to comment.