-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Vaultio/refactorSecurity
Major refactor to KeyManager + Addition of BIP32 support.
- Loading branch information
Showing
36 changed files
with
2,165 additions
and
708 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Data+Extensions.swift | ||
// EtherKit | ||
// | ||
// Created by Cole Potrocky on 4/26/18. | ||
// | ||
|
||
import CryptoSwift | ||
|
||
extension Data { | ||
public var bits: [Bit] { | ||
return bytes.flatMap { $0.bits() } | ||
} | ||
|
||
public var paddedHexString: String { | ||
return reduce("0x") { "\($0)\(String(format: "%02x", $1))" } | ||
} | ||
|
||
public static func randomBytes(count: Int) -> Data { | ||
var bytes = Data(count: count) | ||
_ = bytes.withUnsafeMutableBytes { SecRandomCopyBytes(kSecRandomDefault, count, $0) } | ||
return bytes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Int+Bytes.swift | ||
// EtherKit | ||
// | ||
// Created by Cole Potrocky on 8/13/18. | ||
// | ||
|
||
import Foundation | ||
|
||
// Adapted from: | ||
// https://stackoverflow.com/questions/29970204/split-uint32-into-uint8-in-swift | ||
protocol ByteConvertibleType: BinaryInteger { | ||
var bytes: Data { get } | ||
} | ||
|
||
extension ByteConvertibleType { | ||
var bytes: Data { | ||
var num = self | ||
|
||
let size = MemoryLayout<Self>.size | ||
let ptr = withUnsafePointer(to: &num) { | ||
$0.withMemoryRebound(to: UInt8.self, capacity: size) { | ||
UnsafeBufferPointer(start: $0, count: size) | ||
} | ||
} | ||
|
||
return Data(bytes: [UInt8](ptr)) | ||
} | ||
} | ||
|
||
extension UInt16: ByteConvertibleType {} | ||
extension UInt32: ByteConvertibleType {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Device.swift | ||
// EtherKit | ||
// | ||
// Created by Cole Potrocky on 8/8/18. | ||
// | ||
|
||
import LocalAuthentication | ||
|
||
public enum Device { | ||
public static var hasSecureEnclave: Bool { | ||
return !isSimulator && hasBiometricSupport | ||
} | ||
|
||
public static var isSimulator: Bool { | ||
return TARGET_OS_SIMULATOR == 1 | ||
} | ||
|
||
public static var hasBiometricSupport: Bool { | ||
var error: NSError? | ||
var hasBiometricSupport = LAContext().canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) | ||
guard error == nil else { | ||
guard #available(iOS 11, *) else { | ||
return error?.code != LAError.touchIDNotAvailable.rawValue | ||
} | ||
return error?.code != LAError.biometryNotAvailable.rawValue | ||
} | ||
return hasBiometricSupport | ||
} | ||
} |
Oops, something went wrong.