You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/SessionSnodeKit/Models/RevokeSubkeyRequest.swift

47 lines
1.6 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionUtilitiesKit
extension SnodeAPI {
public class RevokeSubkeyRequest: SnodeAuthenticatedRequestBody {
enum CodingKeys: String, CodingKey {
case subkeyToRevoke = "revoke_subkey"
}
let subkeyToRevoke: String
// MARK: - Init
public init(
subkeyToRevoke: String,
authInfo: AuthenticationInfo
) {
self.subkeyToRevoke = subkeyToRevoke
super.init(authInfo: authInfo)
}
// MARK: - Coding
override public func encode(to encoder: Encoder) throws {
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
try container.encode(subkeyToRevoke, forKey: .subkeyToRevoke)
try super.encode(to: encoder)
}
// MARK: - Abstract Methods
override func generateSignature(using dependencies: Dependencies) throws -> [UInt8] {
/// Ed25519 signature of `("revoke_subkey" || subkey)`; this signs the subkey tag,
/// using `pubkey` to sign. Must be base64 encoded for json requests; binary for OMQ requests.
let verificationBytes: [UInt8] = SnodeAPI.Endpoint.revokeSubkey.path.bytes
.appending(contentsOf: subkeyToRevoke.bytes)
return try authInfo.generateSignature(with: verificationBytes, using: dependencies)
}
}
}