Skip to content

Commit

Permalink
huge refactoring, generics, remove redudant class et c
Browse files Browse the repository at this point in the history
  • Loading branch information
skywinder committed Oct 26, 2020
1 parent 0a8d7f5 commit db9daae
Show file tree
Hide file tree
Showing 13 changed files with 1,546 additions and 1,216 deletions.
1,890 changes: 943 additions & 947 deletions Example/web3swiftBrowser/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
4E682284C32FB121612729BC /* Pods_web3swiftBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70293EAB078119DCD5CCB3AD /* Pods_web3swiftBrowser.framework */; };
4E8234902546F4BF0059F71E /* MainTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E82348F2546F4BF0059F71E /* MainTableViewController.swift */; };
4E8234982546FA4E0059F71E /* PrefferedModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8234972546FA4E0059F71E /* PrefferedModels.swift */; };
81E09B202002623A005DF51D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81E09B1F2002623A005DF51D /* AppDelegate.swift */; };
81E09B222002623A005DF51D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81E09B212002623A005DF51D /* ViewController.swift */; };
81E09B252002623A005DF51D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81E09B232002623A005DF51D /* Main.storyboard */; };
Expand All @@ -24,6 +25,7 @@
4E65513525469DA3000BB8A3 /* web3swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = web3swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4E65513E25469E14000BB8A3 /* web3swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = web3swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4E82348F2546F4BF0059F71E /* MainTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewController.swift; sourceTree = "<group>"; };
4E8234972546FA4E0059F71E /* PrefferedModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PrefferedModels.swift; path = web3swiftBrowser/PrefferedModels.swift; sourceTree = "<group>"; };
6E58291D3C20D10F47593B54 /* Pods-web3swiftBrowser.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-web3swiftBrowser.release.xcconfig"; path = "Target Support Files/Pods-web3swiftBrowser/Pods-web3swiftBrowser.release.xcconfig"; sourceTree = "<group>"; };
70293EAB078119DCD5CCB3AD /* Pods_web3swiftBrowser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3swiftBrowser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
81E09B1C2002623A005DF51D /* web3swiftBrowser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = web3swiftBrowser.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -67,6 +69,7 @@
81E09B132002623A005DF51D = {
isa = PBXGroup;
children = (
4E8234972546FA4E0059F71E /* PrefferedModels.swift */,
81E09B1E2002623A005DF51D /* web3swiftBrowser */,
81E09B362002623B005DF51D /* web3swiftBrowserTests */,
81E09B412002623B005DF51D /* web3swiftBrowserUITests */,
Expand Down Expand Up @@ -258,6 +261,7 @@
files = (
4E8234902546F4BF0059F71E /* MainTableViewController.swift in Sources */,
81E09B222002623A005DF51D /* ViewController.swift in Sources */,
4E8234982546FA4E0059F71E /* PrefferedModels.swift in Sources */,
81E09B282002623A005DF51D /* web3swiftBrowser.xcdatamodeld in Sources */,
81E09B202002623A005DF51D /* AppDelegate.swift in Sources */,
);
Expand Down
115 changes: 79 additions & 36 deletions Example/web3swiftBrowser/web3swiftBrowser/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,39 @@
//

import UIKit
import web3swift

class MainTableViewController: UITableViewController {

var wallet: Wallet = Wallet(type: .EthereumKeystoreV3)
let password = "web3swift"

override func viewDidLoad() {
super.viewDidLoad()

}

@IBOutlet weak var mnemonic: UILabel!


@IBOutlet weak var accountName: UILabel!



@IBAction func createAccount(_ sender: Any) {

let wallet = Wallet(type: .EthereumKeystoreV3)

accountName.text = wallet.name
mnemonic.text = wallet.address

}
@IBAction func generateBipMnemonic(_ sender: Any) {

let wallet = Wallet(type: .BIP39)

}

@IBOutlet weak var bipMnemonic: UILabel!
@IBOutlet weak var bipKey: UILabel!


}
61 changes: 61 additions & 0 deletions Example/web3swiftBrowser/web3swiftBrowser/PrefferedModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// PrefferedModels.swift
// web3swiftBrowser
//
// Created by Petr Korolev on 26.10.2020.
// Copyright © 2020 Matter Labs. All rights reserved.
//

import Foundation
import web3swift

struct Wallet {
enum walletType: Int {
case EthereumKeystoreV3
case BIP39
}

var name: String = "Wallet"
var bitsOfEntropy: Int = 128 // Entropy is a measure of password strength. Usually used 128 or 256 bits.
var password = "web3swift" // We recommend here and everywhere to use the password set by the user.

var address: String
var keystore: AbstractKeystore
var data: Data
var isHD: Bool

init(type: walletType) {
switch type {
case .EthereumKeystoreV3:
keystore = try! EthereumKeystoreV3(password: password)!
self.address = keystore.addresses!.first!.address
self.data = try! JSONEncoder().encode(keystore.giveKeystoreParams())
self.isHD = false

case .BIP39:
let mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: bitsOfEntropy)!
keystore = try! BIP32Keystore(
mnemonics: mnemonics,
password: password,
mnemonicsPassword: "",
language: .english)!
self.name = "HD Wallet"
self.data = try! JSONEncoder().encode(keystore.giveKeystoreParams())
self.isHD = true
}

self.address = keystore.addresses!.first!.address
}
}

struct HDKey {
let name: String?
let address: String
}

struct ERC20Token {
var name: String
var address: String
var decimals: String
var symbol: String
}
6 changes: 4 additions & 2 deletions Sources/web3swift/KeystoreManager/AbstractKeystore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
//

import Foundation

//import EthereumAddress

public protocol AbstractKeystore {
var addresses: [EthereumAddress]? {get}
var isHDKeystore: Bool {get}
public func giveKeystoreParams() -> AbstractKeystoreParams
var addresses: [EthereumAddress]? { get }
var isHDKeystore: Bool { get }
func UNSAFE_getPrivateKeyData(password: String, account: EthereumAddress) throws -> Data
}

Expand Down
Loading

0 comments on commit db9daae

Please sign in to comment.