Skip to content

Commit db9daae

Browse files
committed
huge refactoring, generics, remove redudant class et c
1 parent 0a8d7f5 commit db9daae

File tree

13 files changed

+1546
-1216
lines changed

13 files changed

+1546
-1216
lines changed

Example/web3swiftBrowser/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 943 additions & 947 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/web3swiftBrowser/web3swiftBrowser.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
4E682284C32FB121612729BC /* Pods_web3swiftBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70293EAB078119DCD5CCB3AD /* Pods_web3swiftBrowser.framework */; };
1111
4E8234902546F4BF0059F71E /* MainTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E82348F2546F4BF0059F71E /* MainTableViewController.swift */; };
12+
4E8234982546FA4E0059F71E /* PrefferedModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8234972546FA4E0059F71E /* PrefferedModels.swift */; };
1213
81E09B202002623A005DF51D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81E09B1F2002623A005DF51D /* AppDelegate.swift */; };
1314
81E09B222002623A005DF51D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81E09B212002623A005DF51D /* ViewController.swift */; };
1415
81E09B252002623A005DF51D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81E09B232002623A005DF51D /* Main.storyboard */; };
@@ -24,6 +25,7 @@
2425
4E65513525469DA3000BB8A3 /* web3swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = web3swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2526
4E65513E25469E14000BB8A3 /* web3swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = web3swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2627
4E82348F2546F4BF0059F71E /* MainTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTableViewController.swift; sourceTree = "<group>"; };
28+
4E8234972546FA4E0059F71E /* PrefferedModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PrefferedModels.swift; path = web3swiftBrowser/PrefferedModels.swift; sourceTree = "<group>"; };
2729
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>"; };
2830
70293EAB078119DCD5CCB3AD /* Pods_web3swiftBrowser.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3swiftBrowser.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2931
81E09B1C2002623A005DF51D /* web3swiftBrowser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = web3swiftBrowser.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -67,6 +69,7 @@
6769
81E09B132002623A005DF51D = {
6870
isa = PBXGroup;
6971
children = (
72+
4E8234972546FA4E0059F71E /* PrefferedModels.swift */,
7073
81E09B1E2002623A005DF51D /* web3swiftBrowser */,
7174
81E09B362002623B005DF51D /* web3swiftBrowserTests */,
7275
81E09B412002623B005DF51D /* web3swiftBrowserUITests */,
@@ -258,6 +261,7 @@
258261
files = (
259262
4E8234902546F4BF0059F71E /* MainTableViewController.swift in Sources */,
260263
81E09B222002623A005DF51D /* ViewController.swift in Sources */,
264+
4E8234982546FA4E0059F71E /* PrefferedModels.swift in Sources */,
261265
81E09B282002623A005DF51D /* web3swiftBrowser.xcdatamodeld in Sources */,
262266
81E09B202002623A005DF51D /* AppDelegate.swift in Sources */,
263267
);

Example/web3swiftBrowser/web3swiftBrowser/Base.lproj/Main.storyboard

Lines changed: 79 additions & 36 deletions
Large diffs are not rendered by default.

Example/web3swiftBrowser/web3swiftBrowser/MainTableViewController.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,39 @@
77
//
88

99
import UIKit
10+
import web3swift
1011

1112
class MainTableViewController: UITableViewController {
12-
13+
var wallet: Wallet = Wallet(type: .EthereumKeystoreV3)
14+
let password = "web3swift"
15+
1316
override func viewDidLoad() {
1417
super.viewDidLoad()
1518

1619
}
1720

21+
@IBOutlet weak var mnemonic: UILabel!
1822

23+
24+
@IBOutlet weak var accountName: UILabel!
1925

20-
26+
27+
@IBAction func createAccount(_ sender: Any) {
28+
29+
let wallet = Wallet(type: .EthereumKeystoreV3)
30+
31+
accountName.text = wallet.name
32+
mnemonic.text = wallet.address
33+
34+
}
35+
@IBAction func generateBipMnemonic(_ sender: Any) {
36+
37+
let wallet = Wallet(type: .BIP39)
38+
39+
}
40+
41+
@IBOutlet weak var bipMnemonic: UILabel!
42+
@IBOutlet weak var bipKey: UILabel!
43+
2144

2245
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// PrefferedModels.swift
3+
// web3swiftBrowser
4+
//
5+
// Created by Petr Korolev on 26.10.2020.
6+
// Copyright © 2020 Matter Labs. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import web3swift
11+
12+
struct Wallet {
13+
enum walletType: Int {
14+
case EthereumKeystoreV3
15+
case BIP39
16+
}
17+
18+
var name: String = "Wallet"
19+
var bitsOfEntropy: Int = 128 // Entropy is a measure of password strength. Usually used 128 or 256 bits.
20+
var password = "web3swift" // We recommend here and everywhere to use the password set by the user.
21+
22+
var address: String
23+
var keystore: AbstractKeystore
24+
var data: Data
25+
var isHD: Bool
26+
27+
init(type: walletType) {
28+
switch type {
29+
case .EthereumKeystoreV3:
30+
keystore = try! EthereumKeystoreV3(password: password)!
31+
self.address = keystore.addresses!.first!.address
32+
self.data = try! JSONEncoder().encode(keystore.giveKeystoreParams())
33+
self.isHD = false
34+
35+
case .BIP39:
36+
let mnemonics = try! BIP39.generateMnemonics(bitsOfEntropy: bitsOfEntropy)!
37+
keystore = try! BIP32Keystore(
38+
mnemonics: mnemonics,
39+
password: password,
40+
mnemonicsPassword: "",
41+
language: .english)!
42+
self.name = "HD Wallet"
43+
self.data = try! JSONEncoder().encode(keystore.giveKeystoreParams())
44+
self.isHD = true
45+
}
46+
47+
self.address = keystore.addresses!.first!.address
48+
}
49+
}
50+
51+
struct HDKey {
52+
let name: String?
53+
let address: String
54+
}
55+
56+
struct ERC20Token {
57+
var name: String
58+
var address: String
59+
var decimals: String
60+
var symbol: String
61+
}

Sources/web3swift/KeystoreManager/AbstractKeystore.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
//
66

77
import Foundation
8+
89
//import EthereumAddress
910

1011
public protocol AbstractKeystore {
11-
var addresses: [EthereumAddress]? {get}
12-
var isHDKeystore: Bool {get}
12+
public func giveKeystoreParams() -> AbstractKeystoreParams
13+
var addresses: [EthereumAddress]? { get }
14+
var isHDKeystore: Bool { get }
1315
func UNSAFE_getPrivateKeyData(password: String, account: EthereumAddress) throws -> Data
1416
}
1517

0 commit comments

Comments
 (0)