Files
Morgan Pretty c25071f73f Fixed more QA issues
• Added more details to profile update logs (also added debug logs for updating other users profiles)
• Added a delay before killing the app after clearing data to give the libSession logger more time to shutdown (false crash reports)
• Removed some emoji encoding which is no longer needed
• Fixed a couple of cases where we were trying to access the libSession cache for new accounts before it had been created
• Fixed a bug where we could try to render a profile picture for the current user even if it hadn't been downloaded yet (resulting in nothing being rendered)
• Fixed a bug where restoring an account would clear the users display picture
• Fixed a bug where we wouldn't immediately download the users display picture after restoring an account
• Fixed a bug where video attachments weren't getting their metadata extracted correctly (preventing them from being sent correctly)
• Fixed a bug where some video formats might not be recognised as video
• Fixed a bug preventing emoji reactions in communities
• Fixed a bug where portrait images wouldn't crop correctly
2025-10-21 12:51:14 +11:00

125 lines
4.4 KiB
Swift

// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
//
// stringlint:disable
import Foundation
import Combine
import SessionUtilitiesKit
public extension Network.SessionNetwork {
// MARK: - Info
/// General token info. This endpoint combines the `/price` and `/token` endpoint information.
///
/// `GET/info`
static func prepareInfo(
using dependencies: Dependencies
) throws -> Network.PreparedRequest<Info> {
return try Network.PreparedRequest(
request: Request<NoBody, Network.SessionNetwork.Endpoint>(
endpoint: Network.SessionNetwork.Endpoint.info,
destination: .server(
method: .get,
server: Network.SessionNetwork.networkAPIServer,
queryParameters: [:],
fragmentParameters: [:],
x25519PublicKey: Network.SessionNetwork.networkAPIServerPublicKey
)
),
responseType: Info.self,
requestAndPathBuildTimeout: Network.defaultTimeout,
using: dependencies
)
.signed(with: Network.SessionNetwork.signRequest, using: dependencies)
}
// MARK: - Authentication
fileprivate static func signatureHeaders(
method: HTTPMethod,
pathAndParamsString: String,
body: Data?,
using dependencies: Dependencies
) throws -> [HTTPHeader: String] {
let timestamp: UInt64 = UInt64(floor(dependencies.dateNow.timeIntervalSince1970))
let signResult: (publicKey: String, signature: [UInt8]) = try sign(
timestamp: timestamp,
method: method.rawValue,
pathAndParamsString: pathAndParamsString,
body: body,
using: dependencies
)
return [
HTTPHeader.tokenServerPubKey: signResult.publicKey,
HTTPHeader.tokenServerTimestamp: "\(timestamp)",
HTTPHeader.tokenServerSignature: signResult.signature.toBase64()
]
}
private static func sign(
timestamp: UInt64,
method: String,
pathAndParamsString: String,
body: Data?,
using dependencies: Dependencies
) throws -> (publicKey: String, signature: [UInt8]) {
let bodyString: String? = {
guard let bodyData: Data = body else { return nil }
return String(data: bodyData, encoding: .utf8)
}()
guard
!dependencies[cache: .general].ed25519SecretKey.isEmpty,
let blinded07KeyPair: KeyPair = dependencies[singleton: .crypto].generate(
.versionBlinded07KeyPair(
ed25519SecretKey: dependencies[cache: .general].ed25519SecretKey
)
),
let signatureResult: [UInt8] = dependencies[singleton: .crypto].generate(
.signatureVersionBlind07(
timestamp: timestamp,
method: method,
path: pathAndParamsString,
body: bodyString,
ed25519SecretKey: dependencies[cache: .general].ed25519SecretKey
)
)
else { throw CryptoError.signatureGenerationFailed }
return (
publicKey: SessionId(.versionBlinded07, publicKey: blinded07KeyPair.publicKey).hexString,
signature: signatureResult
)
}
private static func signRequest<R>(
preparedRequest: Network.PreparedRequest<R>,
using dependencies: Dependencies
) throws -> Network.Destination {
guard case let .server(info) = preparedRequest.destination else {
throw NetworkError.invalidPreparedRequest
}
return .server(
info: Network.Destination.ServerInfo(
method: info.method,
server: info.server,
queryParameters: info.queryParameters,
fragmentParameters: info.fragmentParameters,
headers: info.headers.updated(
with: try signatureHeaders(
method: preparedRequest.method,
pathAndParamsString: preparedRequest.path,
body: preparedRequest.body,
using: dependencies
)
),
x25519PublicKey: info.x25519PublicKey
)
)
}
}