fix retrieve from default inbox

pull/622/head
ryanzhao 2 years ago
parent fb65173b06
commit 7cc887267f

@ -395,6 +395,9 @@ public enum OnionRequestAPI {
if statusCode == 406 { // Clock out of sync
SNLog("The user's clock is out of sync with the service node network.")
seal.reject(SnodeAPI.Error.clockOutOfSync)
} else if statusCode == 401 { // Signature verification failed
SNLog("Failed to verify the signature.")
seal.reject(SnodeAPI.Error.signatureVerificationFailed)
} else if let bodyAsString = json["body"] as? String {
guard let bodyAsData = bodyAsString.data(using: .utf8),
let body = try JSONSerialization.jsonObject(with: bodyAsData, options: [ .fragmentsAllowed ]) as? JSON else { return seal.reject(HTTP.Error.invalidJSON) }

@ -49,6 +49,7 @@ public final class SnodeAPI : NSObject {
case inconsistentSnodePools
case noKeyPair
case signingFailed
case signatureVerificationFailed
// ONS
case decryptionFailed
case hashingFailed
@ -62,6 +63,7 @@ public final class SnodeAPI : NSObject {
case .inconsistentSnodePools: return "Received inconsistent Service Node pool information from the Service Node network."
case .noKeyPair: return "Missing user key pair."
case .signingFailed: return "Couldn't sign message."
case . signatureVerificationFailed: return "Failed to verify the signature."
// ONS
case .decryptionFailed: return "Couldn't decrypt ONS name."
case .hashingFailed: return "Couldn't compute ONS name hash."
@ -456,7 +458,8 @@ public final class SnodeAPI : NSObject {
// Construct signature
let timestamp = UInt64(Int64(NSDate.millisecondTimestamp()) + SnodeAPI.clockOffset)
let ed25519PublicKey = userED25519KeyPair.publicKey.toHexString()
guard let verificationData = ("retrieve" + String(namespace) + String(timestamp)).data(using: String.Encoding.utf8),
let namespaceVerificationString = namespace == defaultNamespace ? "" : String(namespace)
guard let verificationData = ("retrieve" + namespaceVerificationString + String(timestamp)).data(using: String.Encoding.utf8),
let signature = sodium.sign.signature(message: Bytes(verificationData), secretKey: userED25519KeyPair.secretKey)
else { return Promise(error: Error.signingFailed) }
// Make the request

Loading…
Cancel
Save