Fix crash

This commit is contained in:
Niels Andriesse 2019-05-03 14:16:22 +10:00
parent 69d3703f4c
commit b70f1810b2
6 changed files with 39 additions and 43 deletions

View File

@ -481,7 +481,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.loki-network.Loki-Messenger.LokiKit";
PRODUCT_BUNDLE_IDENTIFIER = "com.niels-andriesse.loki-network.Loki-Messenger.LokiKit";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -509,7 +509,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.loki-network.Loki-Messenger.LokiKit";
PRODUCT_BUNDLE_IDENTIFIER = "com.niels-andriesse.loki-network.Loki-Messenger.LokiKit";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;

View File

@ -24,7 +24,8 @@ public enum Mnemonic {
if let cachedResult = Language.wordSetCache[self] {
return cachedResult
} else {
let url = Bundle.main.url(forResource: filename, withExtension: "txt")!
let bundleID = "com.niels-andriesse.loki-network.Loki-Messenger.LokiKit"
let url = Bundle(identifier: bundleID)!.url(forResource: filename, withExtension: "txt")!
let contents = try! String(contentsOf: url)
let result = contents.split(separator: ",").map { String($0) }
Language.wordSetCache[self] = result

View File

@ -18,30 +18,30 @@ private extension UInt64 {
}
}
// UInt8 Array specific stuff we need
private extension Array where Element == UInt8 {
/// Increment the UInt8 array by a given amount
private extension MutableCollection where Element == UInt8, Index == Int {
/// Increment every element by the given amount
///
/// - Parameter amount: The amount to increment by
/// - Returns: The incrememnted array
func increment(by amount: Int) -> [UInt8] {
var newNonce = self
/// - Returns: The incremented collection
func increment(by amount: Int) -> Self {
var result = self
var increment = amount
for i in (0..<newNonce.count).reversed() {
for i in (0..<result.count).reversed() {
guard increment > 0 else { break }
let sum = Int(newNonce[i]) + increment
newNonce[i] = UInt8(sum % 256)
let sum = Int(result[i]) + increment
result[i] = UInt8(sum % 256)
increment = sum / 256
}
return newNonce
return result
}
}
/**
* The main logic which handles proof of work.
* The main proof of work logic.
*
* This was copied from the messenger desktop.
* Ref: libloki/proof-of-work.js
* This was copied from the desktop messenger.
* Ref: libloki/proof-of-work.js
*/
public enum ProofOfWork {
@ -60,28 +60,27 @@ public enum ProofOfWork {
var data: String
var timestamp: Date
var ttl: Int
public init(pubKey: String, data: String, timestamp: Date, ttl: Int) {
self.pubKey = pubKey
self.data = data
self.timestamp = timestamp
self.ttl = ttl
}
var payload: [UInt8] {
let timestampString = String(Int(timestamp.timeIntervalSince1970))
let ttlString = String(ttl)
let payloadString = timestampString + ttlString + pubKey + data
return payloadString.bytes
}
public init(pubKey: String, data: String, timestamp: Date, ttl: Int) {
self.pubKey = pubKey
self.data = data
self.timestamp = timestamp
self.ttl = ttl
}
}
/// Calculate a proof of work for the given configuration
/// Calculate a proof of work with the given configuration
///
/// Ref: https://bitmessage.org/wiki/Proof_of_work
///
/// - Parameter config: The configuration data
/// - Parameter config: The configuration
/// - Returns: A nonce string or nil if it failed
public static func calculate(with config: Configuration) -> String? {
let payload = config.payload
@ -96,7 +95,7 @@ public enum ProofOfWork {
while trialValue > target {
nonce = nonce.increment(by: 1)
// This is different to the bitmessage pow
// This is different to the bitmessage POW
// resultHash = hash(nonce + hash(data)) ==> hash(nonce + initialHash)
let resultHash = (nonce + initialHash).sha512()
let trialValueArray = Array(resultHash[0..<8])
@ -106,7 +105,7 @@ public enum ProofOfWork {
return nonce.toBase64()
}
/// Calculate the UInt8 target we need to reach
/// Calculate the target we need to reach
private static func calcTarget(ttl: Int, payloadLength: Int, nonceTrials: Int) -> UInt64 {
let two16 = UInt64(pow(2, 16) - 1)
let two64 = UInt64(pow(2, 64) - 1)

View File

@ -44,11 +44,11 @@ PODS:
- CocoaLumberjack
- SignalCoreKit
- libPhoneNumber-iOS (0.9.13)
- LokiKit (0.0.1):
- LokiKit (1.0.0):
- CryptoSwift
- Curve25519Kit
- SignalCoreKit
- LokiKit/Tests (0.0.1):
- LokiKit/Tests (1.0.0):
- CryptoSwift
- Curve25519Kit
- SignalCoreKit
@ -304,7 +304,7 @@ SPEC CHECKSUMS:
GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e
HKDFKit: 3b6dbbb9d59c221cc6c52c3aa915700cbf24e376
libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa
LokiKit: e18a5ac18b9f2b788b0fa7d0619d9a2a0511dd54
LokiKit: 75ed73c7fcc09fef1f2ec053c7eabf139e015890
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
PromiseKit: c609029bdd801f792551a504c695c7d3098b42cd
PureLayout: f08c01b8dec00bb14a1fefa3de4c7d9c265df85e
@ -312,7 +312,7 @@ SPEC CHECKSUMS:
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
SignalCoreKit: c2d8132cdedb95d35eb2f8ae7eac0957695d0a8b
SignalMetadataKit: 6fa5e9a53c7f104568662521a2f3874672ff7a02
SignalServiceKit: 81b569196f3da6c3964f33b688f7b9ea2bc9a271
SignalServiceKit: 001d38050259216a4478a0a485d761d38add073d
SQLCipher: efbdb52cdbe340bcd892b1b14297df4e07241b7f
SSZipArchive: cefe1364104a0231268a5deb8495bdf2861f52f0
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
@ -322,4 +322,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: c2f870c82713a0d73cf24dfe89e1a37ade0bc166
COCOAPODS: 1.5.3
COCOAPODS: 1.6.1

2
Pods

@ -1 +1 @@
Subproject commit cd96e7f7fc60e82a3e70392800105b542057194e
Subproject commit 0089714d28c67530fced6131c527c58b3a4302d1

View File

@ -3245,7 +3245,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Signal/Pods-Signal-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Signal/Pods-Signal-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
"${BUILT_PRODUCTS_DIR}/AxolotlKit/AxolotlKit.framework",
"${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework",
@ -3253,7 +3253,6 @@
"${BUILT_PRODUCTS_DIR}/Curve25519Kit/Curve25519Kit.framework",
"${PODS_ROOT}/GRKOpenSSLFramework/OpenSSL-iOS/bin/openssl.framework",
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/LokiKit/LokiKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
@ -3279,7 +3278,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Curve25519Kit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LokiKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
@ -3298,7 +3296,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Signal/Pods-Signal-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Signal/Pods-Signal-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
6565655F4068F9E5CDC5687F /* [CP] Check Pods Manifest.lock */ = {
@ -3325,7 +3323,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-SignalTests/Pods-SignalTests-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-SignalTests/Pods-SignalTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
"${BUILT_PRODUCTS_DIR}/AxolotlKit/AxolotlKit.framework",
"${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework",
@ -3333,7 +3331,6 @@
"${BUILT_PRODUCTS_DIR}/Curve25519Kit/Curve25519Kit.framework",
"${PODS_ROOT}/GRKOpenSSLFramework/OpenSSL-iOS/bin/openssl.framework",
"${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework",
"${BUILT_PRODUCTS_DIR}/LokiKit/LokiKit.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework",
@ -3358,7 +3355,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Curve25519Kit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/LokiKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework",
@ -3376,7 +3372,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-SignalTests/Pods-SignalTests-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SignalTests/Pods-SignalTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F4C416F20E3CB0B25DC10C56 /* [CP] Check Pods Manifest.lock */ = {