Files
Morgan Pretty 5e384eb7fb Moved and renamed remaining API definitions
• Cleaned up API structures to be more consistent
• Moved OpenGroupAPI into SessionNetworkingKit
• Moved PushNotificationAPI into SessionNetworkingKit
• Renamed to OpenGroupAPI to SOGSAPI
2025-09-15 14:22:39 +10:00

52 lines
2.0 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionUtilitiesKit
extension Network.SnodeAPI {
class RevokeSubaccountRequest: SnodeAuthenticatedRequestBody {
enum CodingKeys: String, CodingKey {
case subaccountsToRevoke = "revoke"
}
let subaccountsToRevoke: [[UInt8]]
override var verificationBytes: [UInt8] {
/// Ed25519 signature of `("revoke_subaccount" || timestamp || SUBACCOUNT_TAG_BYTES...)`; this
/// signs the subaccount token, using `pubkey` to sign. Must be base64 encoded for json requests; binary for OMQ requests.
Network.SnodeAPI.Endpoint.revokeSubaccount.path.bytes
.appending(contentsOf: timestampMs.map { "\($0)" }?.data(using: .ascii)?.bytes)
.appending(contentsOf: Array(subaccountsToRevoke.joined()))
}
// MARK: - Init
public init(
subaccountsToRevoke: [[UInt8]],
authMethod: AuthenticationMethod,
timestampMs: UInt64
) {
self.subaccountsToRevoke = subaccountsToRevoke
super.init(
authMethod: authMethod,
timestampMs: timestampMs
)
}
// MARK: - Coding
override public func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
/// The `subaccountToRevoke` should be sent as either a single hex string or an array of them
switch subaccountsToRevoke.count {
case 1: try container.encode(subaccountsToRevoke[0].toHexString(), forKey: .subaccountsToRevoke)
default: try container.encode(subaccountsToRevoke.map { $0.toHexString() }, forKey: .subaccountsToRevoke)
}
try super.encode(to: encoder)
}
}
}