mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			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.
		
		
		
		
		
			
		
			
				
	
	
		
			58 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			58 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Swift
		
	
| // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
 | |
| 
 | |
| import Foundation
 | |
| 
 | |
| extension SnodeAPI {
 | |
|     public class DeleteMessagesRequest: SnodeAuthenticatedRequestBody {
 | |
|         enum CodingKeys: String, CodingKey {
 | |
|             case messageHashes = "messages"
 | |
|             case requireSuccessfulDeletion = "required"
 | |
|         }
 | |
|         
 | |
|         let messageHashes: [String]
 | |
|         let requireSuccessfulDeletion: Bool
 | |
|         
 | |
|         override var verificationBytes: [UInt8] {
 | |
|             /// Ed25519 signature of `("delete" || messages...)`; this signs the value constructed
 | |
|             /// by concatenating "delete" and all `messages` values, using `pubkey` to sign.  Must be base64
 | |
|             /// encoded for json requests; binary for OMQ requests.
 | |
|             SnodeAPI.Endpoint.deleteMessages.path.bytes
 | |
|                 .appending(contentsOf: messageHashes.joined().bytes)
 | |
|         }
 | |
|         
 | |
|         // MARK: - Init
 | |
|         
 | |
|         public init(
 | |
|             messageHashes: [String],
 | |
|             requireSuccessfulDeletion: Bool,
 | |
|             swarmPublicKey: String,
 | |
|             ed25519PublicKey: [UInt8],
 | |
|             ed25519SecretKey: [UInt8]
 | |
|         ) {
 | |
|             self.messageHashes = messageHashes
 | |
|             self.requireSuccessfulDeletion = requireSuccessfulDeletion
 | |
|             
 | |
|             super.init(
 | |
|                 pubkey: swarmPublicKey,
 | |
|                 ed25519PublicKey: ed25519PublicKey,
 | |
|                 ed25519SecretKey: ed25519SecretKey
 | |
|             )
 | |
|         }
 | |
|         
 | |
|         // MARK: - Coding
 | |
|         
 | |
|         override public func encode(to encoder: Encoder) throws {
 | |
|             var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
 | |
|             
 | |
|             try container.encode(messageHashes, forKey: .messageHashes)
 | |
|             
 | |
|             // Omitting the value is the same as false so omit to save data
 | |
|             if requireSuccessfulDeletion {
 | |
|                 try container.encode(requireSuccessfulDeletion, forKey: .requireSuccessfulDeletion)
 | |
|             }
 | |
|             
 | |
|             try super.encode(to: encoder)
 | |
|         }
 | |
|     }
 | |
| }
 |