Skip to content

Commit

Permalink
Adding DocC Comments to decrypt and encrypt Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joelklabo committed Aug 12, 2023
1 parent 809e519 commit f906b0f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/NostrSDK/DirectMessageEncrypting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public enum DirectMessageEncryptingError: Error {
public protocol DirectMessageEncrypting {}
public extension DirectMessageEncrypting {

/// Produces a `String` containing `content`that has been encrypted using a sender's`privateKey` and a recipients `publicKey` .
/// This function can `throw` in the case of a failure to create a shared secret, a failure to successfully encrypt, or an invalid `publicKey`.
///
/// - Parameters:
/// - content: The content to encrypt.
/// - privateKey: The private key of the sender.
/// - publicKey: The public key of the intended recipient.
/// - Returns: Encrypted content..
func encrypt(content: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String {

let sharedSecret = try getSharedSecret(privateKey: privateKey, recipient: publicKey)
Expand All @@ -34,6 +42,14 @@ public extension DirectMessageEncrypting {
return encodeDMBase64(content: encryptedMessage.bytes, iv: iv)
}

/// Produces a `String` containing `encryptedContent`that has been decrypted using a recipient's`privateKey` and a sender's `publicKey` .
/// This function can `throw` in the case of a failure to create a shared secret, a failure to successfully encrypt, or an invalid `publicKey`.

/// - Parameters:
/// - encryptedContent: The content to decrypt.
/// - privateKey: The private key of the receiver.
/// - publicKey: The public key of the sender.
/// - Returns: The un-encrypted message.
func decrypt(encryptedContent message: String, privateKey: PrivateKey, publicKey: PublicKey) throws -> String {
guard let sharedSecret = try? getSharedSecret(privateKey: privateKey, recipient: publicKey) else {
throw EventCreatingError.invalidInput
Expand Down

0 comments on commit f906b0f

Please sign in to comment.