Nostr/NostrEmbeddedBitChat.swift

bitchat · bitchat/Nostr/NostrEmbeddedBitChat.swift · swift · Unlicense
voice

NostrEmbeddedBitChat.swift from permissionlesstech/bitchat

// Source: https://github.com/permissionlesstech/bitchat | License: Unlicense
// Provided via justclaw.it.com; keep this notice with the code.
import Foundation
import BitFoundation

// MARK: - BitChat-over-Nostr Adapter

struct NostrEmbeddedBitChat {
    /// Build a `bitchat1:` base64url-encoded BitChat packet carrying a private message for Nostr DMs.
    static func encodePMForNostr(content: String, messageID: String, recipientPeerID: PeerID, senderPeerID: PeerID) -> String? {
        // TLV-encode the private message
        let pm = PrivateMessagePacket(messageID: messageID, content: content)
        guard let tlv = pm.encode() else { return nil }

        // Prefix with NoisePayloadType
        var payload = Data([NoisePayloadType.privateMessage.rawValue])
        payload.append(tlv)


... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key