Compare commits

..

8 Commits

Author SHA1 Message Date
f4cda3b8dd Fix note content rendering to not remove whitespace before hashtag
Changelog-Fixed: Fixed note content rendering to not remove whitespace before hashtag

Closes: https://github.com/damus-io/damus/issues/3122
Fixes: f436291209 ("Fix note content rendering to not remove whitespace before hashtag")
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-07-20 01:28:40 -04:00
793970beaf Add relay hints to tags and identifiers
Changelog-Added: Add relay hints to tags and identifiers
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-07-18 15:51:25 -07:00
transifex-integration[bot]
049d9170be Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2025-07-18 14:52:31 -07:00
transifex-integration[bot]
fd10c5672a Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2025-07-18 14:52:31 -07:00
transifex-integration[bot]
37bd9447f0 Translate Localizable.stringsdict in de
100% translated source file: 'Localizable.stringsdict'
on 'de'.
2025-07-18 14:52:31 -07:00
transifex-integration[bot]
e8457d7486 Translate Localizable.stringsdict in de
100% translated source file: 'Localizable.stringsdict'
on 'de'.
2025-07-18 14:52:31 -07:00
transifex-integration[bot]
280297ad35 Translate Localizable.stringsdict in de
100% translated source file: 'Localizable.stringsdict'
on 'de'.
2025-07-18 14:52:31 -07:00
transifex-integration[bot]
7da3ead01e Translate Localizable.strings in de
100% translated source file: 'Localizable.strings'
on 'de'.
2025-07-18 14:52:31 -07:00
35 changed files with 213 additions and 423 deletions

View File

@@ -26,7 +26,7 @@ struct NotificationFormatter {
content.title = NSLocalizedString("Someone posted a note", comment: "Title label for push notification where someone posted a note")
content.body = event.content
break
case .deprecated_dm:
case .dm:
content.title = NSLocalizedString("New message", comment: "Title label for push notifications where a direct message was sent to the user")
content.body = NSLocalizedString("(Contents are encrypted)", comment: "Label on push notification indicating that the contents of the message are encrypted")
break

View File

@@ -12,12 +12,6 @@
3169CAE6294E69C000EE4006 /* EmptyTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3169CAE5294E69C000EE4006 /* EmptyTimelineView.swift */; };
3169CAED294FCCFC00EE4006 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3169CAEC294FCCFC00EE4006 /* Constants.swift */; };
31D2E847295218AF006D67F8 /* Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31D2E846295218AF006D67F8 /* Shimmer.swift */; };
3A04DA252E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA212E1F40AC00449A0B /* NIP17DirectMessage.swift */; };
3A04DA262E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA232E1F40AC00449A0B /* NIP59GiftWrap.swift */; };
3A04DA272E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA212E1F40AC00449A0B /* NIP17DirectMessage.swift */; };
3A04DA282E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA232E1F40AC00449A0B /* NIP59GiftWrap.swift */; };
3A04DA292E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA212E1F40AC00449A0B /* NIP17DirectMessage.swift */; };
3A04DA2A2E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A04DA232E1F40AC00449A0B /* NIP59GiftWrap.swift */; };
3A0A30BB2C21397A00F8C9BC /* EmojiPicker in Frameworks */ = {isa = PBXBuildFile; productRef = 3A0A30BA2C21397A00F8C9BC /* EmojiPicker */; };
3A23838E2A297DD200E5AA2E /* ZapButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A23838D2A297DD200E5AA2E /* ZapButtonModel.swift */; };
3A2BAC5A2DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BAC592DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift */; };
@@ -1868,8 +1862,6 @@
3169CAE5294E69C000EE4006 /* EmptyTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyTimelineView.swift; sourceTree = "<group>"; };
3169CAEC294FCCFC00EE4006 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Constants.swift; path = damus/Util/Constants.swift; sourceTree = SOURCE_ROOT; };
31D2E846295218AF006D67F8 /* Shimmer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shimmer.swift; sourceTree = "<group>"; };
3A04DA212E1F40AC00449A0B /* NIP17DirectMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP17DirectMessage.swift; sourceTree = "<group>"; };
3A04DA232E1F40AC00449A0B /* NIP59GiftWrap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP59GiftWrap.swift; sourceTree = "<group>"; };
3A185A04297F2C3800F4BDC0 /* lv-LV */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "lv-LV"; path = "lv-LV.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
3A185A05297F2C3800F4BDC0 /* lv-LV */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "lv-LV"; path = "lv-LV.lproj/Localizable.strings"; sourceTree = "<group>"; };
3A185A06297F2C3800F4BDC0 /* lv-LV */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "lv-LV"; path = "lv-LV.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
@@ -2792,22 +2784,6 @@
path = "Empty Views";
sourceTree = "<group>";
};
3A04DA222E1F40AC00449A0B /* NIP17 */ = {
isa = PBXGroup;
children = (
3A04DA212E1F40AC00449A0B /* NIP17DirectMessage.swift */,
);
path = NIP17;
sourceTree = "<group>";
};
3A04DA242E1F40AC00449A0B /* NIP59 */ = {
isa = PBXGroup;
children = (
3A04DA232E1F40AC00449A0B /* NIP59GiftWrap.swift */,
);
path = NIP59;
sourceTree = "<group>";
};
3A515C4E2DF4E0E6002D3B34 /* Tips */ = {
isa = PBXGroup;
children = (
@@ -3818,8 +3794,6 @@
4CE6DEE527F7A08100C66700 /* damus */ = {
isa = PBXGroup;
children = (
3A04DA222E1F40AC00449A0B /* NIP17 */,
3A04DA242E1F40AC00449A0B /* NIP59 */,
D76BE18A2E0CF3BF004AD0C6 /* DIP06 */,
D71527FD2E0A3D5800C893D6 /* NIP51 */,
D7DB93082D69478400DA1EE5 /* NIP65 */,
@@ -5098,8 +5072,6 @@
4CA352A82A76B37E003BB08B /* NewMutesNotify.swift in Sources */,
4CFF8F6929CC9ED1008DB934 /* ImageContainerView.swift in Sources */,
7527271E2A93FF0100214108 /* Block.swift in Sources */,
3A04DA252E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */,
3A04DA262E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */,
4C54AA0729A540BA003E4487 /* NotificationsModel.swift in Sources */,
4CE4F0F229D4FCFA005914DB /* DebouncedOnChange.swift in Sources */,
4C32B9592A9AD44700DC3548 /* Table.swift in Sources */,
@@ -5262,8 +5234,6 @@
82D6FAAC2CD99F7900C925F4 /* FlatBufferBuilder.swift in Sources */,
82D6FAAD2CD99F7900C925F4 /* FlatbuffersErrors.swift in Sources */,
82D6FAAE2CD99F7900C925F4 /* Verifier.swift in Sources */,
3A04DA292E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */,
3A04DA2A2E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */,
82D6FAAF2CD99F7900C925F4 /* ByteBuffer.swift in Sources */,
82D6FAB02CD99F7900C925F4 /* TableVerifier.swift in Sources */,
82D6FAB12CD99F7900C925F4 /* Root.swift in Sources */,
@@ -6246,8 +6216,6 @@
D73E5E172C6A962A007EB227 /* ImageUploadModel.swift in Sources */,
D703D76A2C670B2C00A400EA /* Bech32Object.swift in Sources */,
D73E5E162C6A9619007EB227 /* PostView.swift in Sources */,
3A04DA272E1F40AC00449A0B /* NIP17DirectMessage.swift in Sources */,
3A04DA282E1F40AC00449A0B /* NIP59GiftWrap.swift in Sources */,
D703D7872C670C7E00A400EA /* DamusPurpleEnvironment.swift in Sources */,
D703D7892C670C8600A400EA /* DeepLPlan.swift in Sources */,
D73E5E182C6A963D007EB227 /* AttachMediaUtility.swift in Sources */,

View File

@@ -12,7 +12,7 @@ enum NoteContent {
case content(String, TagsSequence?)
init(note: NostrEvent, keypair: Keypair) {
if note.known_kind == .deprecated_dm || note.known_kind == .highlight {
if note.known_kind == .dm || note.known_kind == .highlight {
self = .content(note.get_content(keypair), note.tags)
} else {
self = .note(note)

View File

@@ -205,7 +205,7 @@ class HomeModel: ContactsDelegate {
handle_boost_event(sub_id: sub_id, ev)
case .like:
handle_like_event(ev)
case .deprecated_dm:
case .dm:
handle_dm(ev)
case .delete:
handle_delete_event(ev)
@@ -231,13 +231,6 @@ class HomeModel: ContactsDelegate {
break
case .interest_list:
break // Don't care for now
case .dm:
break // We should never receive a kind 14 DM. It will always be sealed (kind 13) and then gift wrapped (kind 1059).
case .seal:
break // We should never receive a kind 13 seal. It will always be gift wrapped (kind 1059)
case .gift_wrap:
handle_gift_wrap(ev)
break
}
}
@@ -570,9 +563,9 @@ class HomeModel: ContactsDelegate {
var our_blocklist_filter = NostrFilter(kinds: [.mute_list])
our_blocklist_filter.authors = [damus_state.pubkey]
var dms_filter = NostrFilter(kinds: [.deprecated_dm, .gift_wrap])
var dms_filter = NostrFilter(kinds: [.dm])
var our_dms_filter = NostrFilter(kinds: [.deprecated_dm])
var our_dms_filter = NostrFilter(kinds: [.dm])
// friends only?...
//dms_filter.authors = friends
@@ -821,19 +814,6 @@ class HomeModel: ContactsDelegate {
self.incoming_dms = []
}
}
func handle_gift_wrap(_ ev: NostrEvent) {
guard ev.known_kind == .gift_wrap,
let privateKey = damus_state.keypair.privkey else {
return
}
guard let rumor = try? NIP59GiftWrap.unsealedRumor(giftWrapEvent: ev, using: privateKey) else {
return
}
handle_dm(rumor)
}
}

View File

@@ -64,10 +64,35 @@ enum MentionRef: TagKeys, TagConvertible, Equatable, Hashable {
switch self {
case .pubkey(let pubkey): return ["p", pubkey.hex()]
case .note(let noteId): return ["e", noteId.hex()]
case .nevent(let nevent): return ["e", nevent.noteid.hex()]
case .nprofile(let nprofile): return ["p", nprofile.author.hex()]
case .nevent(let nevent):
var tagBuilder = ["e", nevent.noteid.hex()]
let relay = nevent.relays.first
if let author = nevent.author?.hex() {
tagBuilder.append(relay ?? "")
tagBuilder.append(author)
} else if let relay {
tagBuilder.append(relay)
}
return tagBuilder
case .nprofile(let nprofile):
var tagBuilder = ["p", nprofile.author.hex()]
if let relay = nprofile.relays.first {
tagBuilder.append(relay)
}
return tagBuilder
case .nrelay(let url): return ["r", url]
case .naddr(let naddr): return ["a", naddr.kind.description + ":" + naddr.author.hex() + ":" + naddr.identifier.string()]
case .naddr(let naddr):
var tagBuilder = ["a", "\(naddr.kind.description):\(naddr.author.hex()):\(naddr.identifier.string())"]
if let relay = naddr.relays.first {
tagBuilder.append(relay)
}
return tagBuilder
}
}

View File

@@ -51,6 +51,16 @@ class NostrNetworkManager {
func connect() {
self.userRelayList.connect()
}
func relaysForEvent(event: NostrEvent) -> [RelayURL] {
// TODO(tyiu) Ideally this list would be sorted by the event author's outbox relay preferences
// and reliability of relays to maximize chances of others finding this event.
if let relays = pool.seen[event.id] {
return Array(relays)
}
return []
}
}

View File

@@ -76,6 +76,11 @@ func render_note_content(ev: NostrEvent, profiles: Profiles, keypair: Keypair) -
return .separated(render_blocks(blocks: blocks, profiles: profiles, can_hide_last_previewable_refs: true))
}
// FIXME(tyiu): There are a lot of hacks to get this function to render the blocks correctly.
// However, the entire note content rendering logic just needs to be rewritten.
// Block previews should actually be rendered in the position of the note content where it was found.
// Currently, we put some previews at the bottom of the note, which is incorrect as they take things out of
// the author's intended context.
func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewable_refs: Bool = false) -> NoteArtifactsSeparated {
var invoices: [Invoice] = []
var urls: [UrlType] = []
@@ -120,6 +125,7 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa
// We should hide whitespace at the end sequence.
hide_text_index = i
} else if case .hashtag = block {
// SPECIAL CASE:
// We should keep hashtags at the end sequence but hide all the other previewables around it.
hide_text_index = i
} else {
@@ -171,7 +177,14 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa
case .mention(let m):
return str + mention_str(m, profiles: profiles)
case .text(let txt):
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt))
if case .hashtag = blocks[safe: ind+1] {
// SPECIAL CASE:
// Do not trim whitespaces from suffix if the following block is a hashtag.
// This is because of the code further up (see "SPECIAL CASE").
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: -1, txt: txt))
} else {
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt))
}
case .relay(let relay):
return str + CompatibleText(stringLiteral: relay)
case .hashtag(let htag):

View File

@@ -113,7 +113,7 @@ func generate_local_notification_object(from ev: NostrEvent, state: HeadlessDamu
return LocalNotification(type: .like, event: ev, target: .note_id(evid), content: "")
}
}
else if type == .deprecated_dm,
else if type == .dm,
state.settings.dm_notification {
let convo = ev.decrypted(keypair: state.keypair) ?? NSLocalizedString("New encrypted direct message", comment: "Notification that the user has received a new direct message")
return LocalNotification(type: .dm, event: ev, target: .note(ev), content: convo)

View File

@@ -22,8 +22,6 @@ class ProfileModel: ObservableObject, Equatable {
}
return nil
}
private let MAX_SHARE_RELAYS = 4
var events: EventHolder
let pubkey: Pubkey
@@ -222,7 +220,7 @@ class ProfileModel: ObservableObject, Equatable {
}
func getCappedRelayStrings() -> [String] {
return self.relay_urls?.prefix(MAX_SHARE_RELAYS).map { $0.absoluteString } ?? []
return self.relay_urls?.prefix(Constants.MAX_SHARE_RELAYS).map { $0.absoluteString } ?? []
}
}

View File

@@ -1,27 +0,0 @@
//
// NIP17.swift
// damus
//
// Created by Terry Yiu on 6/6/25.
//
import Foundation
/// Functions and utilities for the NIP-04 spec
struct NIP17 {}
extension NIP17 {
/// Creates a sealed and gift wrapped kind 14 direct message event. The kind 14 direct message will not be signed because the message might leak to relays and become fully public.
static func giftWrappedDirectMessage(message: String, senderKeypair: FullKeypair, receiverPubkey: Pubkey) -> NostrEvent? {
let tags = [
["p", receiverPubkey.hex()] // TODO add receiver relay URL
]
guard let unsignedDM = NostrEvent(content: message, keypair: .just_pubkey(senderKeypair.pubkey), kind: NostrKind.dm.rawValue, tags: tags)
else {
return nil;
}
return try? NIP59GiftWrap.giftWrap(withRumor: unsignedDM, toRecipient: receiverPubkey, signedBy: senderKeypair)
}
}

View File

@@ -1,190 +0,0 @@
//
// NIP59GiftWrap.swift
// damus
//
// Created by Terry Yiu on 6/6/25.
//
import Foundation
struct NIP59GiftWrap {
/// Creates a ``NostrEvent`` gift wrap of kind 1059 that takes a rumor, an unsigned ``NostrEvent``, and seals it in a signed ``NostrEvent`` seal event of kind 13, and then wraps that seal encrypted in the content of the gift wrap.
///
/// - Parameters:
/// - rumor: a ``NostrEvent`` that is not signed.
/// - recipient: the ``Pubkey`` of the receiver of the event. This pubkey will be used to encrypt the rumor. If `recipientAlias` is not provided, this pubkey will automatically be added as a tag to the ``NostrEvent`` gift wrap event.
/// - recipientAlias: optional ``Pubkey`` of the receiver's alias used to receive gift wraps without exposing the receiver's identity. It is not used to encrypt the rumor. If it is provided, this pubkey will automatically be added as a tag to the ``NostrEvent`` gift wrap event.
/// - tags: the list of tags to add to the ``NostrEvent`` gift wrap event in addition to the pubkey tag from `toRecipient`. This list should include any information needed to route the event to its intended recipient, such as [NIP-13 Proof of Work](https://github.com/nostr-protocol/nips/blob/master/13.md).
/// - createdAt: the creation timestamp of the seal. Note that this timestamp SHOULD be tweaked to thwart time-analysis attacks. Note that some relays don't serve events dated in the future, so all timestamps SHOULD be in the past. By default, if `createdAt` is not provided, a random timestamp within 2 days in the past will be chosen.
/// - keypair: The real ``FullKeypair`` to encrypt the rumor and sign the seal with. Note that a different random one-time use key is used to sign the gift wrap.
static func giftWrap(
withRumor rumor: NostrEvent,
toRecipient recipient: Pubkey,
recipientAlias: Pubkey? = nil,
tags: [Tag] = [],
createdAt: UInt32 = UInt32(max(0, Date.now.timeIntervalSince1970 - TimeInterval.random(in: 0...172800))),
signedBy fullKeypair: FullKeypair
) throws -> NostrEvent? {
guard let seal = try seal(withRumor: rumor, toRecipient: recipient, signedBy: fullKeypair) else {
throw SealEventError.sealFailed
}
return try giftWrap(withSeal: seal, toRecipient: recipient, recipientAlias: recipientAlias, tags: tags, createdAt: createdAt)
}
/// Creates a ``NostrEvent`` gift wrap of kind 1059 that takes a signed ``NostrEvent`` of kind 13, and then wraps that seal encrypted in the content of the gift wrap.
///
/// - Parameters:
/// - seal: a signed ``NostrEvent`` seal event of kind 13.
/// - recipient: the ``Pubkey`` of the receiver of the event. This pubkey will be used to encrypt the rumor. If `recipientAlias` is not provided, this pubkey will automatically be added as a tag to the ``GiftWrapEvent``.
/// - recipientAlias: optional ``Pubkey`` of the receiver's alias used to receive gift wraps without exposing the receiver's identity. It is not used to encrypt the rumor. If it is provided, this pubkey will automatically be added as a tag to the ``GiftWrapEvent``.
/// - tags: the list of tags.
/// - createdAt: the creation timestamp of the seal. Note that this timestamp SHOULD be tweaked to thwart time-analysis attacks. Note that some relays don't serve events dated in the future, so all timestamps SHOULD be in the past. By default, if `createdAt` is not provided, a random timestamp within 2 days in the past will be chosen.
static func giftWrap(
withSeal seal: NostrEvent,
toRecipient recipient: Pubkey,
recipientAlias: Pubkey? = nil,
tags: [Tag] = [],
createdAt: UInt32 = UInt32(max(0, Date.now.timeIntervalSince1970 - TimeInterval.random(in: 0...172800))),
) throws -> NostrEvent? {
guard seal.known_kind == .seal else {
throw GiftWrapError.sealInvalid
}
let jsonData = try JSONEncoder().encode(seal)
guard let stringifiedJSON = String(data: jsonData, encoding: .utf8) else {
throw GiftWrapError.utf8EncodingFailed
}
let randomFullKeypair = generate_new_keypair()
let combinedTags = [["p", (recipientAlias ?? recipient).hex()]] + tags.map { $0.strings() }
let encryptedSeal = try NIP44v2Encryption.encrypt(plaintext: stringifiedJSON, privateKeyA: randomFullKeypair.privkey, publicKeyB: recipient)
return NostrEvent(content: encryptedSeal, keypair: randomFullKeypair.to_keypair(), kind: NostrKind.gift_wrap.rawValue, tags: combinedTags, createdAt: createdAt)
}
/// Unwraps the content of the gift wrap event and decrypts it into a ``NostrEvent`` seal event.
/// - Parameters:
/// - giftWrapEvent: The ``NostrEvent`` gift wrap kind 1059 to unwrap.
/// - privateKey: The ``Privkey`` to decrypt the content.
/// - Returns: The ``SealEvent``.
static func unwrappedSeal(giftWrapEvent: NostrEvent, using privateKey: Privkey) throws -> NostrEvent? {
guard giftWrapEvent.known_kind == .gift_wrap else {
throw GiftWrapError.giftWrapInvalid
}
guard let unwrappedSeal = try? NIP44v2Encryption.decrypt(payload: giftWrapEvent.content, privateKeyA: privateKey, publicKeyB: giftWrapEvent.pubkey) else {
throw GiftWrapError.decryptionFailed
}
guard let sealJSONData = unwrappedSeal.data(using: .utf8) else {
throw GiftWrapError.utf8EncodingFailed
}
guard let sealEvent = try? JSONDecoder().decode(NostrEvent.self, from: sealJSONData) else {
throw GiftWrapError.jsonDecodingFailed
}
return sealEvent
}
/// Creates a ``NostrEvent`` seal event of kind 13 that encrypts a rumor with the sender's private key and receiver's public key.
/// There is no p tag pointing to the receiver. There is no way to know who the rumor is for without the receiver's or the sender's private key.
/// The only public information in this event is who is signing it.
///
/// - Parameters:
/// - withRumor: a ``NostrEvent`` that is not signed.
/// - toRecipient: the ``PublicKey`` of the receiver of the event.
/// - createdAt: the creation timestamp of the seal. Note that this timestamp SHOULD be tweaked to thwart time-analysis attacks. Note that some relays don't serve events dated in the future, so all timestamps SHOULD be in the past. By default, if `createdAt` is not provided, a random timestamp within 2 days in the past will be chosen.
/// - keypair: The ``FullKeypair`` to sign with.
static func seal(
withRumor rumor: NostrEvent,
toRecipient recipient: Pubkey,
createdAt: UInt32 = UInt32(max(0, Date.now.timeIntervalSince1970 - TimeInterval.random(in: 0...172800))),
signedBy fullKeypair: FullKeypair
) throws -> NostrEvent? {
guard rumor.isRumor else {
throw SealEventError.sealSignedEvent
}
let jsonData = try JSONEncoder().encode(rumor)
guard let stringifiedJSON = String(data: jsonData, encoding: .utf8) else {
throw SealEventError.utf8EncodingFailed
}
let encryptedRumor = try NIP44v2Encryption.encrypt(plaintext: stringifiedJSON, privateKeyA: fullKeypair.privkey, publicKeyB: recipient)
return NostrEvent(content: encryptedRumor, keypair: fullKeypair.to_keypair(), kind: NostrKind.seal.rawValue, createdAt: createdAt)
}
/// Unseals the content of this seal event into a decrypted rumor.
/// - Parameters:
/// - giftWrapEvent: The ``NostrEvent`` gift wrap kind 1059 to unwrap into a seal, and then unseal to reveal the decrypted rumor.
/// - privateKey: The `PrivateKey` to decrypt the rumor.
/// - Returns: The decrypted ``NostrEvent`` rumor, where its `signature` is absent.
static func unsealedRumor(giftWrapEvent: NostrEvent, using privateKey: Privkey) throws -> NostrEvent? {
guard let sealEvent = try unwrappedSeal(giftWrapEvent: giftWrapEvent, using: privateKey) else {
return nil
}
return try unsealedRumor(sealEvent: sealEvent, using: privateKey)
}
static func unsealedRumor(
sealEvent: NostrEvent,
using privateKey: Privkey
) throws -> NostrEvent? {
guard let unsealedRumor = try? NIP44v2Encryption.decrypt(payload: sealEvent.content, privateKeyA: privateKey, publicKeyB: sealEvent.pubkey) else {
throw SealEventError.decryptionFailed
}
guard let data = unsealedRumor.data(using: .utf8) else {
throw SealEventError.rumorInvalid
}
guard let dict = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any],
let content = dict["content"] as? String,
let pubkey = dict["pubkey"] as? String,
let author = Pubkey(hex: pubkey),
let kind = dict["kind"] as? UInt32,
let tags = dict["tags"] as? [[String]],
let createdAt = dict["created_at"] as? UInt32,
let id = dict["id"] as? String,
let noteId = NoteId(hex: id) else {
return nil
}
// guard let ev = NostrEvent(content: content, author: author, kind: kind, tags: tags, createdAt: createdAt, id: noteId, sig: Signature(Data())) else {
// return nil
// }
guard let ev = NostrEvent(content: content, keypair: .just_pubkey(author), kind: kind, tags: tags, createdAt: createdAt) else {
return nil
}
return ev
}
}
extension NostrEvent {
var isRumor: Bool {
return sig.data == Data(repeating: 0, count: 128)
}
}
enum GiftWrapError: Error {
case decryptionFailed
case jsonDecodingFailed
case keypairGenerationFailed
case pubkeyInvalid
case utf8EncodingFailed
case sealInvalid
case giftWrapInvalid
}
enum SealEventError: Error {
case decryptionFailed
case jsonDecodingFailed
case pubkeyInvalid
case sealSignedEvent
case utf8EncodingFailed
case sealFailed
case rumorInvalid
}

View File

@@ -448,17 +448,26 @@ func random_bytes(count: Int) -> Data {
return Data(bytes: bytes, count: count)
}
func make_boost_event(keypair: FullKeypair, boosted: NostrEvent) -> NostrEvent? {
func make_boost_event(keypair: FullKeypair, boosted: NostrEvent, relayURL: RelayURL?) -> NostrEvent? {
var tags = Array(boosted.referenced_pubkeys).map({ pk in pk.tag })
tags.append(["e", boosted.id.hex(), "", "root"])
tags.append(["p", boosted.pubkey.hex()])
var eTagBuilder = ["e", boosted.id.hex()]
var pTagBuilder = ["p", boosted.pubkey.hex()]
let relayURLString = relayURL?.absoluteString
if let relayURLString {
pTagBuilder.append(relayURLString)
}
eTagBuilder.append(contentsOf: [relayURLString ?? "", "root", boosted.pubkey.hex()])
tags.append(eTagBuilder)
tags.append(pTagBuilder)
let content = event_to_json(ev: boosted)
return NostrEvent(content: content, keypair: keypair.to_keypair(), kind: 6, tags: tags)
}
func make_like_event(keypair: FullKeypair, liked: NostrEvent, content: String = "🤙") -> NostrEvent? {
func make_like_event(keypair: FullKeypair, liked: NostrEvent, content: String = "🤙", relayURL: RelayURL?) -> NostrEvent? {
var tags = liked.tags.reduce(into: [[String]]()) { ts, tag in
guard tag.count >= 2,
(tag[0].matches_char("e") || tag[0].matches_char("p")) else {
@@ -467,8 +476,17 @@ func make_like_event(keypair: FullKeypair, liked: NostrEvent, content: String =
ts.append(tag.strings())
}
tags.append(["e", liked.id.hex()])
tags.append(["p", liked.pubkey.hex()])
var eTagBuilder = ["e", liked.id.hex()]
var pTagBuilder = ["p", liked.pubkey.hex()]
let relayURLString = relayURL?.absoluteString
if let relayURLString {
pTagBuilder.append(relayURLString)
}
eTagBuilder.append(contentsOf: [relayURLString ?? "", liked.pubkey.hex()])
tags.append(eTagBuilder)
tags.append(pTagBuilder)
return NostrEvent(content: content, keypair: keypair.to_keypair(), kind: 7, tags: tags)
}

View File

@@ -13,12 +13,10 @@ enum NostrKind: UInt32, Codable {
case metadata = 0
case text = 1
case contacts = 3
case deprecated_dm = 4
case dm = 4
case delete = 5
case boost = 6
case like = 7
case seal = 13
case dm = 14
case chat = 42
case mute_list = 10000
case relay_list = 10002
@@ -29,7 +27,6 @@ enum NostrKind: UInt32, Codable {
case zap = 9735
case zap_request = 9734
case highlight = 9802
case gift_wrap = 1059
case nwc_request = 23194
case nwc_response = 23195
case http_auth = 27235

View File

@@ -19,17 +19,12 @@ struct QueuedRequest {
let skip_ephemeral: Bool
}
struct SeenEvent: Hashable {
let relay_id: RelayURL
let evid: NoteId
}
/// Establishes and manages connections and subscriptions to a list of relays.
class RelayPool {
private(set) var relays: [Relay] = []
var handlers: [RelayHandler] = []
var request_queue: [QueuedRequest] = []
var seen: Set<SeenEvent> = Set()
var seen: [NoteId: Set<RelayURL>] = [:]
var counts: [RelayURL: UInt64] = [:]
var ndb: Ndb
/// The keypair used to authenticate with relays
@@ -357,15 +352,11 @@ class RelayPool {
func record_seen(relay_id: RelayURL, event: NostrConnectionEvent) {
if case .nostr_event(let ev) = event {
if case .event(_, let nev) = ev {
let k = SeenEvent(relay_id: relay_id, evid: nev.id)
if !seen.contains(k) {
seen.insert(k)
if counts[relay_id] == nil {
counts[relay_id] = 1
} else {
counts[relay_id] = (counts[relay_id] ?? 0) + 1
}
if seen[nev.id]?.contains(relay_id) == true {
return
}
seen[nev.id, default: Set()].insert(relay_id)
counts[relay_id, default: 0] += 1
}
}
}

View File

@@ -47,6 +47,10 @@ struct NEvent : Equatable, Hashable {
self.author = author
self.kind = kind
}
init(event: NostrEvent, relays: [String]) {
self.init(noteid: event.id, relays: relays, author: event.pubkey, kind: event.kind)
}
}
struct NProfile : Equatable, Hashable {

View File

@@ -45,4 +45,5 @@ class Constants {
// MARK: General constants
static let GIF_IMAGE_TYPE: String = "com.compuserve.gif"
static let MAX_SHARE_RELAYS = 4
}

View File

@@ -87,7 +87,7 @@ enum LocalNotificationType: String {
switch nostr_kind {
case .text:
return .mention
case .deprecated_dm:
case .dm:
return .dm
case .like:
return .like

View File

@@ -165,12 +165,6 @@ class PostBox {
return
}
// Don't add event if it's a NIP-17 direct message kind or a NIP-59 seal event kind to avoid leaking private information.
// DMs should be sealed and gift wrapped.
if event.known_kind == .dm || event.known_kind == .seal {
return
}
let remaining = to ?? pool.our_descriptors.map { $0.url }
let after = delay.map { d in Date.now.addingTimeInterval(d) }
let posted_ev = PostedEvent(event: event, remaining: remaining, skip_ephemeral: skip_ephemeral, flush_after: after, on_flush: on_flush)

View File

@@ -217,7 +217,16 @@ struct EventActionBar: View {
AnyView(self.action_bar_content)
}
}
var event_relay_url_strings: [String] {
let relays = damus_state.nostrNetwork.relaysForEvent(event: event)
if !relays.isEmpty {
return relays.prefix(Constants.MAX_SHARE_RELAYS).map { $0.absoluteString }
}
return userProfile.getCappedRelayStrings()
}
var body: some View {
self.content
.onAppear {
@@ -233,7 +242,9 @@ struct EventActionBar: View {
}
}
.sheet(isPresented: $show_share_sheet, onDismiss: { self.show_share_sheet = false }) {
ShareSheet(activityItems: [URL(string: "https://damus.io/" + event.id.bech32)!])
if let url = URL(string: "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(event: event, relays: event_relay_url_strings)))) {
ShareSheet(activityItems: [url])
}
}
.sheet(isPresented: $show_repost_action, onDismiss: { self.show_repost_action = false }) {
@@ -262,7 +273,7 @@ struct EventActionBar: View {
func send_like(emoji: String) {
guard let keypair = damus_state.keypair.to_full(),
let like_ev = make_like_event(keypair: keypair, liked: event, content: emoji) else {
let like_ev = make_like_event(keypair: keypair, liked: event, content: emoji, relayURL: damus_state.nostrNetwork.relaysForEvent(event: event).first) else {
return
}

View File

@@ -21,7 +21,7 @@ struct RepostAction: View {
dismiss()
guard let keypair = self.damus_state.keypair.to_full(),
let boost = make_boost_event(keypair: keypair, boosted: self.event) else {
let boost = make_boost_event(keypair: keypair, boosted: self.event, relayURL: damus_state.nostrNetwork.relaysForEvent(event: self.event).first) else {
return
}

View File

@@ -26,7 +26,16 @@ struct ShareAction: View {
self.userProfile = userProfile
self._show_share = show_share
}
var event_relay_url_strings: [String] {
let relays = userProfile.damus.nostrNetwork.relaysForEvent(event: event)
if !relays.isEmpty {
return relays.prefix(Constants.MAX_SHARE_RELAYS).map { $0.absoluteString }
}
return userProfile.getCappedRelayStrings()
}
var body: some View {
VStack {
@@ -40,7 +49,7 @@ struct ShareAction: View {
ShareActionButton(img: "link", text: NSLocalizedString("Copy Link", comment: "Button to copy link to note")) {
dismiss()
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(noteid: event.id, relays: userProfile.getCappedRelayStrings())))
UIPasteboard.general.string = "https://damus.io/" + Bech32Object.encode(.nevent(NEvent(event: event, relays: event_relay_url_strings)))
}
let bookmarkImg = isBookmarked ? "bookmark.fill" : "bookmark"

View File

@@ -235,7 +235,7 @@ struct ChatEventView: View {
func send_like(emoji: String) {
guard let keypair = damus_state.keypair.to_full(),
let like_ev = make_like_event(keypair: keypair, liked: event, content: emoji) else {
let like_ev = make_like_event(keypair: keypair, liked: event, content: emoji, relayURL: damus_state.nostrNetwork.relaysForEvent(event: event).first) else {
return
}

View File

@@ -108,7 +108,7 @@ struct DMChatView: View, KeyboardReadable {
Button(
role: .none,
action: {
send_message_nip04()
send_message()
}
) {
Label("", image: "send")
@@ -124,33 +124,7 @@ struct DMChatView: View, KeyboardReadable {
*/
}
func send_message_nip17() {
guard let fullKeypair = damus_state.keypair.to_full() else {
return
}
let tags = [["p", pubkey.hex()]]
let post_blocks = parse_post_blocks(content: dms.draft)
let content = post_blocks
.map(\.asString)
.joined(separator: "")
guard let fullKeypair = damus_state.keypair.to_full(),
let dm = NIP17.giftWrappedDirectMessage(message: content, senderKeypair: fullKeypair, receiverPubkey: pubkey)
else {
return
}
dms.draft = ""
damus_state.nostrNetwork.postbox.send(dm)
handle_incoming_dm(ev: dm, our_pubkey: damus_state.pubkey, dms: damus_state.dms, prev_events: NewEventsBits())
end_editing()
}
func send_message_nip04() {
func send_message() {
let tags = [["p", pubkey.hex()]]
let post_blocks = parse_post_blocks(content: dms.draft)
let content = post_blocks

View File

@@ -63,7 +63,16 @@ struct MenuItems: View {
self.target_pubkey = target_pubkey
self.profileModel = profileModel
}
var event_relay_url_strings: [String] {
let relays = damus_state.nostrNetwork.relaysForEvent(event: event)
if !relays.isEmpty {
return relays.prefix(Constants.MAX_SHARE_RELAYS).map { $0.absoluteString }
}
return profileModel.getCappedRelayStrings()
}
var body: some View {
Group {
Button {
@@ -79,7 +88,7 @@ struct MenuItems: View {
}
Button {
UIPasteboard.general.string = event.id.bech32
UIPasteboard.general.string = Bech32Object.encode(.nevent(NEvent(event: event, relays: event_relay_url_strings)))
} label: {
Label(NSLocalizedString("Copy note ID", comment: "Context menu option for copying the ID of the note."), image: "note-book")
}
@@ -108,7 +117,7 @@ struct MenuItems: View {
Label(NSLocalizedString("Broadcast", comment: "Context menu option for broadcasting the user's note to all of the user's connected relay servers."), image: "globe")
}
// Mute thread - relocated to below Broadcast, as to move further away from Add Bookmark to prevent accidental muted threads
if event.known_kind != .deprecated_dm && event.known_kind != .dm && event.known_kind != .seal {
if event.known_kind != .dm {
MuteDurationMenu { duration in
if let full_keypair = self.damus_state.keypair.to_full(),
let new_mutelist_ev = toggle_from_mutelist(keypair: full_keypair, prev: damus_state.mutelist_manager.event, to_toggle: .thread(event.thread_id(), duration?.date_from_now)) {

View File

@@ -64,7 +64,7 @@ class LoadableNostrEventViewModel: ObservableObject {
switch known_kind {
case .text, .highlight:
return .loaded(route: Route.Thread(thread: ThreadModel(event: ev, damus_state: damus_state)))
case .deprecated_dm: // FIXME(tyiu)
case .dm:
let dm_model = damus_state.dms.lookup_or_create(ev.pubkey)
return .loaded(route: Route.DMChat(dms: dm_model))
case .like:
@@ -74,7 +74,7 @@ class LoadableNostrEventViewModel: ObservableObject {
case .zap, .zap_request:
guard let zap = await get_zap(from: ev, state: damus_state) else { return .not_found }
return .loaded(route: Route.Zaps(target: zap.target))
case .contacts, .metadata, .delete, .boost, .chat, .mute_list, .list_deprecated, .draft, .longform, .nwc_request, .nwc_response, .http_auth, .status, .relay_list, .follow_list, .interest_list, .dm, .seal, .gift_wrap:
case .contacts, .metadata, .delete, .boost, .chat, .mute_list, .list_deprecated, .draft, .longform, .nwc_request, .nwc_response, .http_auth, .status, .relay_list, .follow_list, .interest_list:
return .unknown_or_unsupported_kind
}
case .naddr(let naddr):

View File

@@ -798,18 +798,18 @@ private func isAlphanumeric(_ char: Character) -> Bool {
return char.isLetter || char.isNumber
}
func nip10_reply_tags(replying_to: NostrEvent, keypair: Keypair) -> [[String]] {
func nip10_reply_tags(replying_to: NostrEvent, keypair: Keypair, relayURL: RelayURL?) -> [[String]] {
guard let nip10 = replying_to.thread_reply() else {
// we're replying to a post that isn't in a thread,
// just add a single reply-to-root tag
return [["e", replying_to.id.hex(), "", "root"]]
return [["e", replying_to.id.hex(), relayURL?.absoluteString ?? "", "root"]]
}
// otherwise use the root tag from the parent's nip10 reply and include the note
// that we are replying to's note id.
let tags = [
["e", nip10.root.note_id.hex(), nip10.root.relay ?? "", "root"],
["e", replying_to.id.hex(), "", "reply"]
["e", replying_to.id.hex(), relayURL?.absoluteString ?? "", "reply"]
]
return tags
@@ -902,15 +902,19 @@ func build_post(state: DamusState, post: NSAttributedString, action: PostAction,
switch action {
case .replying_to(let replying_to):
// start off with the reply tags
tags = nip10_reply_tags(replying_to: replying_to, keypair: state.keypair)
tags = nip10_reply_tags(replying_to: replying_to, keypair: state.keypair, relayURL: state.nostrNetwork.relaysForEvent(event: replying_to).first)
case .quoting(let ev):
content.append("\n\nnostr:" + bech32_note_id(ev.id))
let relay_urls = state.nostrNetwork.relaysForEvent(event: ev)
let nevent = Bech32Object.encode(.nevent(NEvent(event: ev, relays: relay_urls.prefix(4).map { $0.absoluteString })))
content.append("\n\nnostr:\(nevent)")
tags.append(["q", ev.id.hex()]);
if let quoted_ev = state.events.lookup(ev.id) {
tags.append(["p", quoted_ev.pubkey.hex()])
if let first_relay = relay_urls.first?.absoluteString {
tags.append(["q", ev.id.hex(), first_relay, ev.pubkey.hex()]);
tags.append(["p", ev.pubkey.hex(), first_relay])
} else {
tags.append(["q", ev.id.hex(), "", ev.pubkey.hex()]);
tags.append(["p", ev.pubkey.hex()])
}
case .posting, .highlighting, .sharing:
break

Binary file not shown.

View File

@@ -2,6 +2,22 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>follow_pack_user_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@FOLLOW_PACK_USERS@</string>
<key>FOLLOW_PACK_USERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Nutzer</string>
<key>other</key>
<string>Nutzer</string>
</dict>
</dict>
<key>followed_by_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
@@ -82,6 +98,22 @@
<string>Imporieren</string>
</dict>
</dict>
<key>notes_from_three_and_others</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@OTHERS@</string>
<key>OTHERS</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Notizen von %2$@, %3$@, %4$@ &amp; %1$d weiterem aus deinem vertrauenswürdigen Netzwerk</string>
<key>other</key>
<string>Notizen von %2$@, %3$@, %4$@ &amp; %1$d weiteren aus deinem vertrauenswürdigen Netzwerk</string>
</dict>
</dict>
<key>people_reposted_count</key>
<dict>
<key>NSStringLocalizedFormatKey</key>

View File

@@ -167,7 +167,23 @@ class Bech32ObjectTests: XCTestCase {
XCTAssertEqual(expectedEncoding, actualEncoding)
}
func testTLVEncoding_NeventFromNostrEvent_ValidContent() throws {
let relays = ["wss://relay.damus.io", "wss://relay.nostr.band"]
let nevent = NEvent(event: test_note, relays: relays)
XCTAssertEqual(nevent.noteid, test_note.id)
XCTAssertEqual(nevent.relays, relays)
XCTAssertEqual(nevent.author, test_note.pubkey)
XCTAssertEqual(nevent.kind, test_note.kind)
let expectedEncoding = "nevent1qqsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpz3mhxue69uhhyetvv9ujuerpd46hxtnfduq3vamnwvaz7tmjv4kxz7fwdehhxarj9e3xzmnyqgsgydql3q4ka27d9wnlrmus4tvkrnc8ftc4h8h5fgyln54gl0a7dgsrqsqqqqqpppe7n6"
let actualEncoding = Bech32Object.encode(.nevent(NEvent(event: test_note, relays: relays)))
XCTAssertEqual(expectedEncoding, actualEncoding)
}
func testTLVEncoding_NProfileExample_ValidContent() throws {
guard let author = try bech32_decode("npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6") else {
XCTFail()

View File

@@ -25,7 +25,7 @@ class LikeTests: XCTestCase {
keypair: test_keypair,
tags: [cindy.tag, bob.tag])!
let id = liked.id
let like_ev = make_like_event(keypair: test_keypair_full, liked: liked)!
let like_ev = make_like_event(keypair: test_keypair_full, liked: liked, relayURL: nil)!
XCTAssertTrue(like_ev.referenced_pubkeys.contains(test_keypair.pubkey))
XCTAssertTrue(like_ev.referenced_pubkeys.contains(cindy))
@@ -36,12 +36,12 @@ class LikeTests: XCTestCase {
func testToReactionEmoji() {
let liked = NostrEvent(content: "awesome #[0] post", keypair: test_keypair, tags: [["p", "cindy"], ["e", "bob"]])!
let emptyReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "")!
let plusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "+")!
let minusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "-")!
let heartReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "❤️")!
let thumbsUpReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "👍")!
let shakaReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "🤙")!
let emptyReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "", relayURL: nil)!
let plusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "+", relayURL: nil)!
let minusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "-", relayURL: nil)!
let heartReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "❤️", relayURL: nil)!
let thumbsUpReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "👍", relayURL: nil)!
let shakaReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "🤙", relayURL: nil)!
XCTAssertEqual(to_reaction_emoji(ev: emptyReaction), "❤️")
XCTAssertEqual(to_reaction_emoji(ev: plusReaction), "❤️")

View File

@@ -40,17 +40,4 @@ final class NostrEventTests: XCTestCase {
let urlInContent2 = "https://cdn.nostr.build/i/5c1d3296f66c2630131bf123106486aeaf051ed8466031c0e0532d70b33cddb2.jpg"
XCTAssert(testEvent2.content.contains(urlInContent2), "Issue parsing event. Expected to see '\(urlInContent2)' inside \(testEvent2.content)")
}
func testNostrEventWithoutPrivateKey() throws {
let event = NostrEvent(
content: "Test",
keypair: .just_pubkey(test_pubkey),
kind: NostrKind.dm.rawValue,
tags: []
)
let nonNilEvent = try XCTUnwrap(event)
let json = try JSONEncoder().encode(nonNilEvent)
print(json)
}
}

View File

@@ -174,7 +174,7 @@ final class PostViewTests: XCTestCase {
func testQuoteRepost() {
let post = build_post(state: test_damus_state, post: .init(), action: .quoting(test_note), uploadedMedias: [], pubkeys: [])
XCTAssertEqual(post.tags, [["q", test_note.id.hex()]])
XCTAssertEqual(post.tags, [["q", test_note.id.hex(), "", jack_keypair.pubkey.hex()], ["p", jack_keypair.pubkey.hex()]])
}
func testBuildPostRecognizesStringsAsNpubs() throws {

View File

@@ -174,9 +174,9 @@ class NdbNote: Codable, Equatable, Hashable {
let tags = try container.decode([[String]].self, forKey: .tags)
let createdAt = try container.decode(UInt32.self, forKey: .created_at)
let noteId = try container.decode(NoteId.self, forKey: .id)
let signature = try? container.decode(Signature.self, forKey: .sig)
guard let note = NdbNote.init(content: content, author: pubkey, kind: kind, tags: tags, createdAt: createdAt, id: noteId, sig: signature ?? Signature(Data(repeating: 0, count: 128))) else {
let signature = try container.decode(Signature.self, forKey: .sig)
guard let note = NdbNote.init(content: content, author: pubkey, kind: kind, tags: tags, createdAt: createdAt, id: noteId, sig: signature) else {
throw DecodingError.initializationFailed
}
@@ -456,7 +456,7 @@ extension NdbNote {
}
func get_content(_ keypair: Keypair) -> String {
if known_kind == .deprecated_dm {
if known_kind == .dm {
return decrypted(keypair: keypair) ?? "*failed to decrypt content*"
}
else if known_kind == .highlight {
@@ -467,7 +467,7 @@ extension NdbNote {
}
func maybe_get_content(_ keypair: Keypair) -> String? {
if known_kind == .deprecated_dm {
if known_kind == .dm {
return decrypted(keypair: keypair)
}

View File

@@ -3628,39 +3628,6 @@ int ndb_builder_finalize(struct ndb_builder *builder, struct ndb_note **note,
return total_size;
}
int ndb_builder_finalize_just_pubkey(struct ndb_builder *builder, struct ndb_note **note,
unsigned char pubkey[32])
{
int strings_len = builder->strings.p - builder->strings.start;
unsigned char *note_end = builder->note_cur.p + strings_len;
int total_size = note_end - builder->note_cur.start;
// move the strings buffer next to the end of our ndb_note
memmove(builder->note_cur.p, builder->strings.start, strings_len);
// set the strings location
builder->note->strings = builder->note_cur.p - builder->note_cur.start;
// record the total size
//builder->note->size = total_size;
*note = builder->note;
// use the remaining memory for building our id buffer
unsigned char *end = builder->mem.end;
unsigned char *start = (unsigned char*)(*note) + total_size;
ndb_builder_set_pubkey(builder, pubkey);
if (!ndb_calculate_id(builder->note, start, end - start))
return 0;
// make sure we're aligned as a whole
total_size = (total_size + 7) & ~7;
assert((total_size % 8) == 0);
return total_size;
}
struct ndb_note * ndb_builder_note(struct ndb_builder *builder)
{
return builder->note;

View File

@@ -366,7 +366,6 @@ int ndb_ws_event_from_json(const char *json, int len, struct ndb_tce *tce, unsig
int ndb_note_from_json(const char *json, int len, struct ndb_note **, unsigned char *buf, int buflen);
int ndb_builder_init(struct ndb_builder *builder, unsigned char *buf, int bufsize);
int ndb_builder_finalize(struct ndb_builder *builder, struct ndb_note **note, struct ndb_keypair *privkey);
int ndb_builder_finalize_just_pubkey(struct ndb_builder *builder, struct ndb_note **note, unsigned char pubkey[32]);
int ndb_builder_set_content(struct ndb_builder *builder, const char *content, int len);
void ndb_builder_set_created_at(struct ndb_builder *builder, uint64_t created_at);
void ndb_builder_set_sig(struct ndb_builder *builder, unsigned char *sig);