Skip to content

Commit

Permalink
Fix SwiftLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiu committed Jun 26, 2024
1 parent 6e2276d commit 1382965
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Sources/NostrSDK/Events/BookmarksListEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public extension EventCreating {
var encryptedContent: String?
if !privateTags.isEmpty {
let rawPrivateTags = privateTags.map { $0.raw }
if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags),
let unencryptedContent = String(data: unencryptedData, encoding: .utf8) {
if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags) {
let unencryptedContent = String(decoding: unencryptedData, as: UTF8.self)
encryptedContent = try legacyEncrypt(content: unencryptedContent,
privateKey: keypair.privateKey,
publicKey: keypair.publicKey)
Expand Down
4 changes: 2 additions & 2 deletions Sources/NostrSDK/Events/GenericRepostEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class GenericRepostEvent: NostrEvent, RelayURLValidating {

/// The note that is being reposted.
var repostedEvent: NostrEvent? {
guard let jsonData = content.data(using: .utf8),
let note: NostrEvent = try? JSONDecoder().decode(NostrEvent.self, from: jsonData) else {
let jsonData = Data(content.utf8)
guard let note: NostrEvent = try? JSONDecoder().decode(NostrEvent.self, from: jsonData) else {
return nil
}
return note
Expand Down
4 changes: 1 addition & 3 deletions Sources/NostrSDK/Events/GiftWrap/GiftWrapEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public extension EventCreating {
signedBy keypair: Keypair
) throws -> GiftWrapEvent {
let jsonData = try JSONEncoder().encode(seal)
guard let stringifiedJSON = String(data: jsonData, encoding: .utf8) else {
throw EventCreatingError.invalidInput
}
let stringifiedJSON = String(decoding: jsonData, as: UTF8.self)

guard let randomKeypair = Keypair() else {
throw GiftWrapError.keypairGenerationFailed
Expand Down
5 changes: 1 addition & 4 deletions Sources/NostrSDK/Events/GiftWrap/SealEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ public extension EventCreating {
}

let jsonData = try JSONEncoder().encode(rumor)
guard let stringifiedJSON = String(data: jsonData, encoding: .utf8) else {
throw EventCreatingError.invalidInput
}

let stringifiedJSON = String(decoding: jsonData, as: UTF8.self)
let encryptedRumor = try encrypt(plaintext: stringifiedJSON, privateKeyA: keypair.privateKey, publicKeyB: recipient)
return try SealEvent(content: encryptedRumor, createdAt: createdAt, signedBy: keypair)
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/NostrSDK/Events/MetadataEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public extension EventCreating {
/// See [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md)
func metadataEvent(withUserMetadata userMetadata: UserMetadata, customEmojis: [CustomEmoji] = [], signedBy keypair: Keypair) throws -> MetadataEvent {
let metadataAsData = try JSONEncoder().encode(userMetadata)
guard let metadataAsString = String(data: metadataAsData, encoding: .utf8) else {
throw EventCreatingError.invalidInput
}
let metadataAsString = String(decoding: metadataAsData, as: UTF8.self)
let customEmojiTags = customEmojis.map { $0.tag }
return try MetadataEvent(content: metadataAsString, tags: customEmojiTags, signedBy: keypair)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NostrSDK/Events/MuteListEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public extension EventCreating {
var encryptedContent: String?
if !privateTags.isEmpty {
let rawPrivateTags = privateTags.map { $0.raw }
if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags),
let unencryptedContent = String(data: unencryptedData, encoding: .utf8) {
if let unencryptedData = try? JSONSerialization.data(withJSONObject: rawPrivateTags) {
let unencryptedContent = String(decoding: unencryptedData, as: UTF8.self)
encryptedContent = try legacyEncrypt(content: unencryptedContent,
privateKey: keypair.privateKey,
publicKey: keypair.publicKey)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NostrSDK/Events/TextNoteRepostEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
/// See [NIP-18](https://github.com/nostr-protocol/nips/blob/master/18.md#reposts).
public final class TextNoteRepostEvent: GenericRepostEvent {

override class var kind: EventKind {
override static var kind: EventKind {
.repost
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/NostrSDK/NIP44v2Encrypting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ extension NIP44v2Encrypting {

guard unpaddedLength > 0,
unpadded.count == unpaddedLength,
padded.count == 2 + paddedLength,
let result = String(data: Data(unpadded), encoding: .utf8) else {
padded.count == 2 + paddedLength
else {
throw NIP44v2EncryptingError.paddingInvalid
}

return result
return String(decoding: Data(unpadded), as: UTF8.self)
}

func decodePayload(_ payload: String) throws -> DecodedPayload {
Expand Down
2 changes: 1 addition & 1 deletion Sources/NostrSDK/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class WebSocket: NSObject, URLSessionWebSocketDelegate {

let reasonString: String?
if let reason {
reasonString = String(data: reason, encoding: .utf8)
reasonString = String(decoding: reason, as: UTF8.self)
} else {
reasonString = nil
}
Expand Down

0 comments on commit 1382965

Please sign in to comment.