Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Data Models For Public use #790

Merged
merged 24 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db0ac33
bug fix
pharms-eth Nov 11, 2022
d9fd03c
cleanup
pharms-eth Nov 11, 2022
bcebcb0
cleanup
pharms-eth Nov 11, 2022
0127132
fix bug
pharms-eth Nov 13, 2022
915bcd9
Mnemonic Wallet Creation Cleanup
pharms-eth Nov 16, 2022
efba907
Merge branch 'develop' into pr/2
pharms-eth Nov 16, 2022
f6f86b3
cleanup post merge
pharms-eth Nov 16, 2022
56b0d59
Merge pull request #3 from pharms-eth/test-1115629
pharms-eth Nov 16, 2022
e968d2f
fix bug
pharms-eth Nov 16, 2022
1fff2c6
improve test code
pharms-eth Nov 16, 2022
b5e9fb4
Merge remote-tracking branch 'upstream/develop' into develop
pharms-eth Nov 26, 2022
037f227
Merge branch 'develop' of https://github.com/pharms-eth/web3swift int…
pharms-eth Mar 6, 2023
a9b4a46
Update EthereumKeystoreV3.swift
pharms-eth Mar 6, 2023
2244902
Update Data+Extension.swift
pharms-eth Mar 6, 2023
4108edd
Update Encodable+Extensions.swift
pharms-eth Mar 6, 2023
0847410
Update String+Extension.swift
pharms-eth Mar 6, 2023
dd93a0c
Update WriteOperation.swift
pharms-eth Mar 6, 2023
c3abf93
chore: fixed spacing; KeystoreParamsV3 init - removed local names of …
JeneaVranceanu Mar 9, 2023
95214d9
chore: removed pathToAddress; replaced En/Decodable with Codable
JeneaVranceanu Mar 9, 2023
4ff3f35
chore: fixed trailing whitespaces
JeneaVranceanu Mar 9, 2023
c8827b6
chore: ran swiftlint --fix
JeneaVranceanu Mar 9, 2023
2e7a37b
Merge pull request #4 from web3swift-team/develop
pharms-eth Mar 9, 2023
bf93168
chore: merged with develop
JeneaVranceanu Apr 2, 2023
62b7437
fix: marked pathAddressPairs as public internal(set) var
JeneaVranceanu Apr 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 41 additions & 30 deletions Sources/Web3Core/KeystoreManager/KeystoreParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,69 @@

import Foundation

public struct KdfParamsV3: Decodable, Encodable {
public struct KdfParamsV3: Codable {
var salt: String
var dklen: Int
var n: Int?
var p: Int?
var r: Int?
var c: Int?
var prf: String?

public init(salt: String, dklen: Int, n: Int? = nil, p: Int? = nil, r: Int? = nil, c: Int? = nil, prf: String? = nil) {
self.salt = salt
self.dklen = dklen
self.n = n
self.p = p
self.r = r
self.c = c
self.prf = prf
}
}

public struct CipherParamsV3: Decodable, Encodable {
public struct CipherParamsV3: Codable {
var iv: String

public init(iv: String) {
self.iv = iv
}
}

public struct CryptoParamsV3: Decodable, Encodable {
public struct CryptoParamsV3: Codable {
var ciphertext: String
var cipher: String
var cipherparams: CipherParamsV3
var kdf: String
var kdfparams: KdfParamsV3
var mac: String
var version: String?

public init(ciphertext: String, cipher: String, cipherparams: CipherParamsV3, kdf: String, kdfparams: KdfParamsV3, mac: String, version: String? = nil) {
self.ciphertext = ciphertext
self.cipher = cipher
self.cipherparams = cipherparams
self.kdf = kdf
self.kdfparams = kdfparams
self.mac = mac
self.version = version
}
}

public protocol AbstractKeystoreParams: Codable {
var crypto: CryptoParamsV3 { get }
var id: String? { get }
var version: Int { get }
var isHDWallet: Bool { get }

}

public struct PathAddressPair: Codable {
let path: String
let address: String
public let path: String
public let address: String

public init(path: String, address: String) {
self.path = path
self.address = address
}
}

public struct KeystoreParamsBIP32: AbstractKeystoreParams {
Expand All @@ -47,21 +75,7 @@ public struct KeystoreParamsBIP32: AbstractKeystoreParams {
public var version: Int
public var isHDWallet: Bool

@available(*, deprecated, message: "Please use pathAddressPairs instead")
var pathToAddress: [String: String] {
get {
return self.pathAddressPairs.reduce(into: [String: String]()) {
$0[$1.path] = $1.address
}
}
set {
for pair in newValue {
self.pathAddressPairs.append(PathAddressPair(path: pair.0, address: pair.1))
}
}
}
pharms-eth marked this conversation as resolved.
Show resolved Hide resolved

var pathAddressPairs: [PathAddressPair]
public internal(set) var pathAddressPairs: [PathAddressPair]
var rootPath: String?

public init(crypto cr: CryptoParamsV3, id i: String, version ver: Int = 32, rootPath: String? = nil) {
Expand All @@ -72,23 +86,20 @@ public struct KeystoreParamsBIP32: AbstractKeystoreParams {
self.rootPath = rootPath
self.isHDWallet = true
}

}

public struct KeystoreParamsV3: AbstractKeystoreParams {
public var address: String?
public var crypto: CryptoParamsV3
public var id: String?
public var version: Int
public var isHDWallet: Bool

var address: String?

public init(address ad: String?, crypto cr: CryptoParamsV3, id i: String, version ver: Int) {
address = ad
self.crypto = cr
self.id = i
self.version = ver
public init(address: String?, crypto: CryptoParamsV3, id: String, version: Int) {
self.address = address
self.crypto = crypto
self.id = id
self.version = version
self.isHDWallet = false
}

}
2 changes: 1 addition & 1 deletion Sources/Web3Core/Utility/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension String {
return String(self[start..<end])
}

func leftPadding(toLength: Int, withPad character: Character) -> String {
public func leftPadding(toLength: Int, withPad character: Character) -> String {
let stringLength = self.count
if stringLength < toLength {
return String(repeatElement(character, count: toLength - stringLength)) + self
Expand Down