Merge pull request #6991 from AlphaWallet/refactor-so-alphawalletattestation-no-longer-depends-on-alphawalletfoundation-to-support-future-work-which-requires-alphawallettokenscript-to-be-dependent-on-alphawalletattestation

Refactor so AlphaWalletAttestation no longer depends on AlphaWalletFoundation (to support future work which requires AlphaWalletTokenScript to be dependent on AlphaWalletAttestation)
pull/6992/head
Hwee-Boon Yar 1 year ago committed by GitHub
commit 50af615ba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      AlphaWalletAttestation.podspec
  2. 5
      Podfile.lock
  3. 16
      modules/AlphaWalletAttestation/AlphaWalletAttestation/Attestation.swift
  4. 9
      modules/AlphaWalletCore/AlphaWalletCore/Types/RPCServer.swift
  5. 1
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/ImportedTypes.swift
  6. 7
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/RPCServers.swift
  7. 47
      modules/AlphaWalletWeb3/AlphaWalletWeb3/Types/EIP712TypedData.swift

@ -25,9 +25,10 @@ s.source_files = 'modules/AlphaWalletAttestation/AlphaWalletAttestation/**/*
s.public_header_files = "AlphaWalletAttestation/**/*.{h}"
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.dependency 'AlphaWalletFoundation'
s.dependency 'AlphaWalletAddress'
s.dependency 'AlphaWalletCore'
s.dependency 'AlphaWalletWeb3'
s.dependency 'BigInt'
s.dependency 'GzipSwift'
end
end

@ -9,7 +9,8 @@ PODS:
- EthereumAddress
- TrustKeystore
- AlphaWalletAttestation (0.0.1):
- AlphaWalletFoundation
- AlphaWalletAddress
- AlphaWalletCore
- AlphaWalletWeb3
- BigInt
- GzipSwift
@ -442,7 +443,7 @@ SPEC CHECKSUMS:
Alamofire: 4e95d97098eacb88856099c4fc79b526a299e48c
AlphaWalletABI: 5a4303eba7e575cf6ca11b70bb06f1b1d05b0d19
AlphaWalletAddress: b1689336d5b2560d4f0993aa680e758c49068f87
AlphaWalletAttestation: 64970455862b55785a04d7f3da556e781e1ae9a5
AlphaWalletAttestation: e81a973d468ff941569ba5f0b3c279b8b1d902b9
AlphaWalletCore: 5b06f12b96578c533585bb1c06acf255a9f98bec
AlphaWalletENS: 8f611f655728c8f2a6b91fb8f1417144d33a4915
AlphaWalletFoundation: fecb0317a9f6b55dd736416660830a1145b9cd0c

@ -2,8 +2,8 @@
import Foundation
import Gzip
//TODO remove AlphaWalletFoundation if possible, It's only needed for `EIP712TypedData`. At this point, it's too tedious to move `EIP712TypedData` out to `AlphaWalletWeb3` because there is a circular dependency
import AlphaWalletFoundation
import AlphaWalletAddress
import AlphaWalletCore
import AlphaWalletWeb3
import BigInt
@ -25,7 +25,6 @@ public enum AttestationPropertyValue: Codable, Hashable {
}
enum CodingError: Error {
case cannotEncode(AssetInternalValue)
case cannotDecode
}
@ -603,3 +602,14 @@ extension EasAttestation {
return RPCServer(chainID: chainId)
}
}
fileprivate struct Constants {
static let nullAddress = AlphaWallet.Address(uncheckedAgainstNullAddress: "0x0000000000000000000000000000000000000000")!
}
fileprivate extension Data {
//TODO: Duplicated here. Move to Core
var hexString: String {
return map({ String(format: "%02x", $0) }).joined()
}
}

@ -131,9 +131,16 @@ public enum RPCServer: Hashable, CaseIterable {
allCases + Self.customServers
}
public init?(chainIdOptional chainID: Int) {
guard let server = Self.availableServers.first(where: { $0.chainID == chainID }) else {
return nil
}
self = server
}
public init(chainID: Int) {
//TODO defaulting to .main is bad
self = Self.availableServers.first { $0.chainID == chainID } ?? .main
self = .init(chainIdOptional: chainID) ?? .main
}
private static func convertJsonToCustomRpcs(_ json: String?) -> [CustomRPC] {

@ -31,6 +31,7 @@ public typealias EtherNumberFormatter = AlphaWalletWeb3.EtherNumberFormatter
public typealias DecodedFunctionCall = AlphaWalletWeb3.DecodedFunctionCall
public typealias GasPrice = AlphaWalletWeb3.GasPrice
public typealias EthereumTransaction = AlphaWalletWeb3.EthereumTransaction
public typealias EIP712TypedData = AlphaWalletWeb3.EIP712TypedData
import AlphaWalletENS
public typealias AddressOrDomainName = AlphaWalletENS.AddressOrDomainName

@ -448,13 +448,6 @@ extension RPCServer: Hashable, CaseIterable {
}
}
public init?(chainIdOptional chainID: Int) {
guard let server = Self.availableServers.first(where: { $0.chainID == chainID }) else {
return nil
}
self = server
}
public init?(withMagicLinkHost magicLinkHost: String) {
var server: RPCServer?
//Special case to support legacy host name

@ -7,6 +7,8 @@
/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md
import Foundation
import AlphaWalletABI
import AlphaWalletAddress
import AlphaWalletCore
import BigInt
/// A struct represents EIP712 type tuple
@ -81,8 +83,8 @@ extension EIP712TypedData {
let primaryType = primaryType.dropTrailingSquareBrackets
var found = dependencies
guard !found.contains(primaryType),
let primaryTypes = types[primaryType] else {
return found
let primaryTypes = types[primaryType] else {
return found
}
found.insert(primaryType)
for type in primaryTypes {
@ -98,10 +100,10 @@ extension EIP712TypedData {
depSet.remove(primaryType)
let sorted = [primaryType] + Array(depSet).sorted()
let encoded = sorted.compactMap { type in
guard let values = types[type] else { return nil }
let param = values.map { "\($0.type) \($0.name)" }.joined(separator: ",")
return "\(type)(\(param))"
}.joined()
guard let values = types[type] else { return nil }
let param = values.map { "\($0.type) \($0.name)" }.joined(separator: ",")
return "\(type)(\(param))"
}.joined()
return encoded.data(using: .utf8) ?? Data()
}
@ -210,7 +212,7 @@ extension EIP712TypedData {
/// Helper func for encoding uint / int types
private func parseIntSize(type: String, prefix: String) -> Int {
guard type.starts(with: prefix),
let size = Int(type.dropFirst(prefix.count)) else {
let size = Int(type.dropFirst(prefix.count)) else {
return -1
}
@ -458,3 +460,34 @@ extension EIP712TypedData.JSON {
return nil
}
}
fileprivate extension Data {
init?(hexString: String) {
let string: Substring
if hexString.hasPrefix("0x") {
string = hexString.dropFirst(2)
} else {
string = Substring(hexString)
}
self.init(capacity: string.count / 2)
for offset in stride(from: 0, to: string.count, by: 2) {
let start = string.index(string.startIndex, offsetBy: offset)
guard string.distance(from: start, to: string.endIndex) >= 2 else {
let byte = string[start...]
guard let number = UInt8(byte, radix: 16) else {
return nil
}
append(number)
break
}
let end = string.index(string.startIndex, offsetBy: offset + 2)
let byte = string[start ..< end]
guard let number = UInt8(byte, radix: 16) else {
return nil
}
append(number)
}
}
}
Loading…
Cancel
Save