-
Notifications
You must be signed in to change notification settings - Fork 11
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 #39 from torusresearch/feat/revampTorusUtil
Feat/revamp torus util
- Loading branch information
Showing
22 changed files
with
575 additions
and
399 deletions.
There are no files selected for viewing
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
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
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
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,37 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 09/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
// Necessary for decryption | ||
|
||
extension Sequence where Element == UInt8 { | ||
var data: Data { .init(self) } | ||
var hexa: String { map { .init(format: "%02x", $0) }.joined() } | ||
} | ||
|
||
extension Data { | ||
init?(hexString: String) { | ||
let length = hexString.count / 2 | ||
var data = Data(capacity: length) | ||
for i in 0 ..< length { | ||
let j = hexString.index(hexString.startIndex, offsetBy: i * 2) | ||
let k = hexString.index(j, offsetBy: 2) | ||
let bytes = hexString[j ..< k] | ||
if var byte = UInt8(bytes, radix: 16) { | ||
data.append(&byte, count: 1) | ||
} else { | ||
return nil | ||
} | ||
} | ||
self = data | ||
} | ||
|
||
func addLeading0sForLength64() -> Data { | ||
Data(hex: toHexString().addLeading0sForLength64()) | ||
} | ||
} |
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
311 changes: 103 additions & 208 deletions
311
Sources/TorusUtils/Extensions/TorusUtils+extension.swift
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,29 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 30/03/23. | ||
// | ||
|
||
import Foundation | ||
|
||
enum HTTPMethod { | ||
case get | ||
case post | ||
|
||
var name: String { | ||
switch self { | ||
case .get: | ||
return "GET" | ||
case .post: | ||
return "POST" | ||
} | ||
} | ||
} | ||
|
||
extension TorusUtils { | ||
func createURLSession() -> URLSession { | ||
let session = URLSession(configuration: urlSession.configuration) | ||
return session | ||
} | ||
} |
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,34 @@ | ||
public enum Web3Error: Error { | ||
case transactionSerializationError | ||
case connectionError | ||
case dataError | ||
case walletError | ||
case inputError(desc: String) | ||
case nodeError(desc: String) | ||
case processingError(desc: String) | ||
case generalError(err: Error) | ||
case unknownError | ||
|
||
public var errorDescription: String { | ||
switch self { | ||
case .transactionSerializationError: | ||
return "Transaction Serialization Error" | ||
case .connectionError: | ||
return "Connection Error" | ||
case .dataError: | ||
return "Data Error" | ||
case .walletError: | ||
return "Wallet Error" | ||
case let .inputError(desc): | ||
return desc | ||
case let .nodeError(desc): | ||
return desc | ||
case let .processingError(desc): | ||
return desc | ||
case let .generalError(err): | ||
return err.localizedDescription | ||
case .unknownError: | ||
return "Unknown Error" | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Sources/TorusUtils/Models/CommitmentRequestResponseModel.swift
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 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 03/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct CommitmentRequestResponseModel: Decodable { | ||
public var data: String | ||
public var nodepubx: String | ||
public var nodepuby: String | ||
public var signature: String | ||
|
||
public init(data: String, nodepubx: String, nodepuby: String, signature: String) { | ||
self.data = data | ||
self.nodepubx = nodepubx | ||
self.nodepuby = nodepuby | ||
self.signature = signature | ||
} | ||
} | ||
|
||
extension Array where Element == CommitmentRequestResponseModel { | ||
|
||
public func tostringDict() -> [[String: String]] { | ||
var dictArr = [[String: String]]() | ||
for val in self { | ||
var dict = [String: String]() | ||
dict["data"] = val.data | ||
dict["nodepubx"] = val.nodepubx | ||
dict["nodepuby"] = val.nodepuby | ||
dict["signature"] = val.signature | ||
dictArr.append(dict) | ||
} | ||
return dictArr | ||
} | ||
} |
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,57 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 02/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct KeyLookupResponseModel: CustomStringConvertible, Hashable { | ||
|
||
public let pubKeyX: String | ||
public let pubKeyY: String | ||
public let keyIndex: String | ||
public let address: String | ||
public var description: String { | ||
return "public key X is \(pubKeyX) public key Y is \(pubKeyY) address is \(address)" | ||
} | ||
|
||
public init(pubKeyX: String, pubKeyY: String, keyIndex: String, address: String) { | ||
self.pubKeyX = pubKeyX | ||
self.pubKeyY = pubKeyY | ||
self.keyIndex = keyIndex | ||
self.address = address | ||
} | ||
|
||
} | ||
|
||
public enum KeyLookupError: Error { | ||
case verifierNotSupported | ||
case verifierAndVerifierIdNotAssigned | ||
case configError | ||
|
||
static func createErrorFromString(errorString: String) -> Self { | ||
if errorString.contains("Verifier not supported") { | ||
return .verifierNotSupported | ||
} else if errorString.contains("Verifier + VerifierID has not yet been assigned") { | ||
return .verifierAndVerifierIdNotAssigned | ||
} else { | ||
return .configError | ||
} | ||
} | ||
} | ||
|
||
extension KeyLookupError: LocalizedError { | ||
|
||
public var errorDescription: String? { | ||
switch self { | ||
case .verifierNotSupported: | ||
return "Verifier not supported. Check if you: \n1. Are on the right network (Torus testnet/mainnet) \n2. Have setup a verifier on dashboterard.web3auth.io?" | ||
case .verifierAndVerifierIdNotAssigned: | ||
return "Verifier + VerifierID has not yet been assigned" | ||
case .configError: | ||
return "ConfigurationError" | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Sources/TorusUtils/Models/RetrieveDecryptAndReconstuctResponseModel.swift
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,24 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 06/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct RetrieveDecryptAndReconstuctResponseModel { | ||
public let iv: String | ||
public let ephemPublicKey: String | ||
public let share: String | ||
public let pubKeyX: String | ||
public let pubKeyY: String | ||
|
||
public init(iv: String, ephemPublicKey: String, share: String, pubKeyX: String, pubKeyY: String) { | ||
self.iv = iv | ||
self.ephemPublicKey = ephemPublicKey | ||
self.share = share | ||
self.pubKeyX = pubKeyX | ||
self.pubKeyY = pubKeyY | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Sources/TorusUtils/Models/RetrieveSharesResponseModel.swift
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,18 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Dhruv Jaiswal on 08/04/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct RetrieveSharesResponseModel { | ||
public let publicAddress: String | ||
public let privateKey: String | ||
|
||
public init(publicKey: String, privateKey: String) { | ||
self.publicAddress = publicKey | ||
self.privateKey = privateKey | ||
} | ||
} |
Oops, something went wrong.