Skip to content

Commit

Permalink
Merge pull request #11 from torusresearch/feat/argentweb3
Browse files Browse the repository at this point in the history
Feat/argentweb3
  • Loading branch information
rathishubham7 authored Aug 29, 2021
2 parents 0f23062 + 45b6a1c commit 449d13c
Show file tree
Hide file tree
Showing 445 changed files with 1,254 additions and 134,622 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ playground.xcworkspace
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm
.swiftpm/

.build/

Expand All @@ -59,7 +59,7 @@ playground.xcworkspace
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
Expand Down
70 changes: 44 additions & 26 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"pins": [
{
"package": "BigInt",
"repositoryURL": "https://github.com/attaswift/BigInt.git",
"repositoryURL": "https://github.com/attaswift/BigInt",
"state": {
"branch": null,
"revision": "889a1ecacd73ccc189c5cb29288048f186c44ed9",
Expand All @@ -24,71 +24,89 @@
"repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git",
"state": {
"branch": null,
"revision": "5669f222e46c8134fb1f399c745fa6882b43532e",
"version": "1.3.8"
"revision": "8d4f6384e0a8cc41f2005247241dd553963a492a",
"version": "1.4.1"
}
},
{
"package": "FetchNodeDetails",
"repositoryURL": "https://github.com/torusresearch/fetch-node-details-swift",
"state": {
"branch": null,
"revision": "7d93d8c98d45c723d4836e9406282dda237e48cb",
"version": "0.1.2"
"branch": "feat/argentweb3",
"revision": "94e8385fafe8ecd52465043c12e9da38a98f7fa2",
"version": null
}
},
{
"package": "PMKFoundation",
"repositoryURL": "https://github.com/PromiseKit/Foundation.git",
"state": {
"branch": null,
"revision": "1a276e598dac59489ed904887e0740fa75e571e0",
"version": "3.3.4"
"revision": "985f17fa69ee0e5b7eb3ff9be87ffc4e05fc0927",
"version": "3.4.0"
}
},
{
"package": "GenericJSON",
"repositoryURL": "https://github.com/zoul/generic-json-swift",
"state": {
"branch": null,
"revision": "a137894b2a217abe489cdf1ea287e6f7819b1051",
"version": "2.0.1"
}
},
{
"package": "jwt-kit",
"repositoryURL": "https://github.com/vapor/jwt-kit.git",
"state": {
"branch": null,
"revision": "df7955305940ea0fcd1626a0a6d1a1556623f95e",
"version": "4.2.3"
}
},
{
"package": "PromiseKit",
"repositoryURL": "https://github.com/mxcl/PromiseKit.git",
"state": {
"branch": null,
"revision": "aea48ea1855f5d82e2dffa6027afce3aab8f3dd7",
"version": "6.13.3"
"revision": "d2f7ba14bcdc45e18f4f60ad9df883fb9055f081",
"version": "6.15.3"
}
},
{
"package": "Starscream",
"repositoryURL": "https://github.com/daltoniam/Starscream.git",
"package": "secp256k1",
"repositoryURL": "https://github.com/Boilertalk/secp256k1.swift",
"state": {
"branch": null,
"revision": "e6b65c6d9077ea48b4a7bdda8994a1d3c6969c8d",
"version": "3.1.1"
"revision": "823281fe9def21b384099b72a9a53ca988317b20",
"version": "0.1.4"
}
},
{
"package": "BestLogger",
"repositoryURL": "https://github.com/rathishubham7/swift-logger",
"package": "swift-crypto",
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "e1e2fa0a6ee9f572432835b70f980a8b36449575",
"version": "0.0.3"
"revision": "3bea268b223651c4ab7b7b9ad62ef9b2d4143eb6",
"version": "1.1.6"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"package": "BestLogger",
"repositoryURL": "https://github.com/rathishubham7/swift-logger",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
"revision": "e1e2fa0a6ee9f572432835b70f980a8b36449575",
"version": "0.0.3"
}
},
{
"package": "Web3swift",
"repositoryURL": "https://github.com/rathishubham7/web3swift",
"package": "web3.swift",
"repositoryURL": "https://github.com/argentlabs/web3.swift",
"state": {
"branch": null,
"revision": "95c8cb18bc8a664963f55e095318c1a180c3f5ec",
"version": "2.2.2"
"revision": "8205d3f671e0248af7d2e0537664d1a85d1ee11e",
"version": "0.8.1"
}
}
]
Expand Down
27 changes: 17 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
// swift-tools-version:5.1
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "TorusUtils",
platforms: [
.iOS(.v13),
],
products: [
.library(
name: "TorusUtils",
targets: ["TorusUtils"]),
],
dependencies: [
.package(url: "https://github.com/rathishubham7/web3swift", from:"2.0.0"),
.package(url: "https://github.com/rathishubham7/swift-logger", from:"0.0.1"),
.package(url: "https://github.com/torusresearch/fetch-node-details-swift", from:"0.1.0"),
.package(url: "https://github.com/PromiseKit/Foundation.git", from: "3.0.0"),
.package(url: "https://github.com/IBM-Swift/BlueECC.git", from: "1.2.4"),
// .package(url: "https://github.com/skywinder/web3swift", .branch("master")),
.package(name:"BestLogger", url: "https://github.com/rathishubham7/swift-logger", from:"0.0.1"),
// .package(name:"FetchNodeDetails", path: "../fetch-node-details-swift"),
.package(name:"PromiseKit", url: "https://github.com/mxcl/PromiseKit.git", from: "6.0.0"),
.package(name:"PMKFoundation", url: "https://github.com/PromiseKit/Foundation.git", from: "3.0.0"),
.package(name:"CryptorECC", url: "https://github.com/IBM-Swift/BlueECC.git", from: "1.2.4"),
.package(name:"CryptoSwift", url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.0.0"),
.package(name:"jwt-kit", url: "https://github.com/vapor/jwt-kit.git", from: "4.0.0"),
.package(name:"FetchNodeDetails", url: "https://github.com/torusresearch/fetch-node-details-swift", .branch("feat/argentweb3")),
.package(name:"web3.swift", url: "https://github.com/argentlabs/web3.swift", from:"0.7.0"),
.package(name:"secp256k1", url: "https://github.com/Boilertalk/secp256k1.swift", from: "0.1.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "TorusUtils",
dependencies: ["FetchNodeDetails", "web3swift", "PMKFoundation", "CryptorECC", "BestLogger"]),
dependencies: [.product(name: "FetchNodeDetails", package: "FetchNodeDetails"), "CryptoSwift", "web3.swift", "CryptorECC", "secp256k1", "PMKFoundation", "PromiseKit", "BestLogger"]),
.testTarget(
name: "torus-utils-swiftTests",
dependencies: ["TorusUtils"]),
dependencies: ["TorusUtils", .product(name: "JWTKit", package: "jwt-kit"), .product(name: "FetchNodeDetails", package: "FetchNodeDetails"), "web3.swift", "PMKFoundation", "PromiseKit", "CryptorECC", "BestLogger"]),
]
)
19 changes: 19 additions & 0 deletions Sources/TorusUtils/AbstractTorusUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// File.swift
//
//
// Created by Shubham on 1/8/21.
//

import Foundation
import PromiseKit
import FetchNodeDetails

public protocol AbstractTorusUtils {

func setTorusNodePubKeys(nodePubKeys: Array<TorusNodePub>)

func retrieveShares(endpoints : Array<String>, verifierIdentifier: String, verifierId:String, idToken: String, extraParams: Data) -> Promise<[String:String]>

func getPublicAddress(endpoints : Array<String>, torusNodePubs : Array<TorusNodePub>, verifier : String, verifierId : String, isExtended: Bool) -> Promise<[String:String]>
}
30 changes: 15 additions & 15 deletions Sources/TorusUtils/Convenience/CryptoExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
// Created by Alex Vlasov.
// Copyright © 2018 Alex Vlasov. All rights reserved.
//

import Foundation
import CryptoSwift

func toByteArray<T>(_ value: T) -> [UInt8] {
var value = value
return withUnsafeBytes(of: &value) { Array($0) }
}

func scrypt (password: String, salt: Data, length: Int, N: Int, R: Int, P: Int) -> Data? {
guard let passwordData = password.data(using: .utf8) else {return nil}
guard let deriver = try? Scrypt(password: passwordData.bytes, salt: salt.bytes, dkLen: length, N: N, r: R, p: P) else {return nil}
guard let result = try? deriver.calculate() else {return nil}
return Data(result)
}
//
//import Foundation
//import CryptoSwift
//
//func toByteArray<T>(_ value: T) -> [UInt8] {
// var value = value
// return withUnsafeBytes(of: &value) { Array($0) }
//}
//
//func scrypt (password: String, salt: Data, length: Int, N: Int, R: Int, P: Int) -> Data? {
// guard let passwordData = password.data(using: .utf8) else {return nil}
// guard let deriver = try? Scrypt(password: passwordData.bytes, salt: salt.bytes, dkLen: length, N: N, r: R, p: P) else {return nil}
// guard let result = try? deriver.calculate() else {return nil}
// return Data(result)
//}
12 changes: 12 additions & 0 deletions Sources/TorusUtils/Convenience/Data+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ public extension Data {
return uintRepresentation
}

static func randomOfLength(_ length: Int) -> Data? {
var data = [UInt8](repeating: 0, count: length)
let result = SecRandomCopyBytes(kSecRandomDefault,
data.count,
&data)
if result == errSecSuccess {
return Data(data)
}

return nil
}

// func bitsInRange(_ startingBit:Int, _ length:Int) -> UInt64? { //return max of 8 bytes for simplicity, non-public
// if startingBit + length / 8 > self.count, length > 64, startingBit > 0, length >= 1 {return nil}
// let bytes = self[(startingBit/8) ..< (startingBit+length+7)/8]
Expand Down
Loading

0 comments on commit 449d13c

Please sign in to comment.