misc: don't immediately hex encode event commitment

keep it separate for now, since we're moving to more low level. We
probably won't even use this, but this is cleaner logicwise anyway.
This commit is contained in:
William Casarin
2023-07-22 15:40:22 -07:00
parent 0263c11a94
commit af7ea7024f
5 changed files with 12 additions and 12 deletions

View File

@@ -822,7 +822,7 @@ func process_metadata_profile(our_pubkey: String, profiles: Profiles, profile: P
}
func guard_valid_event(events: EventCache, ev: NostrEvent, callback: @escaping () -> Void) {
guard ev.id==calculate_event_id(ev: ev) else {
guard ev.id == hex_encode(calculate_event_id(ev: ev)) else {
return
}
let validated = events.is_event_valid(ev.id)

View File

@@ -64,7 +64,7 @@ func create_report_event(privkey: String, report: Report) -> NostrEvent? {
let tags = create_report_tags(target: report.target, type: report.type)
let ev = NostrEvent(content: report.message, pubkey: pubkey, kind: kind, tags: tags)
ev.id = calculate_event_id(ev: ev)
ev.id = hex_encode(calculate_event_id(ev: ev))
ev.sig = sign_event(privkey: privkey, ev: ev)
return ev

View File

@@ -136,7 +136,7 @@ extension NostrEvent {
}
var is_valid_id: Bool {
return calculate_event_id(ev: self) == self.id
return hex_encode(calculate_event_id(ev: self)) == self.id
}
func blocks(_ privkey: String?) -> Blocks {
@@ -311,7 +311,7 @@ extension NostrEvent {
}
func calculate_id() {
self.id = calculate_event_id(ev: self)
self.id = hex_encode(calculate_event_id(ev: self))
}
func sign(privkey: String) {
@@ -414,11 +414,11 @@ func calculate_event_commitment(ev: NostrEvent) -> Data {
return target_data
}
func calculate_event_id(ev: NostrEvent) -> String {
func calculate_event_id(ev: NostrEvent) -> Data {
let commitment = calculate_event_commitment(ev: ev)
let hash = sha256(commitment)
return hex_encode(hash)
return hash
}
@@ -584,7 +584,7 @@ func make_private_zap_request_event(identity: FullKeypair, enc_key: FullKeypair,
let tags = zap_target_to_tags(target)
let note = NostrEvent(content: message, pubkey: identity.pubkey, kind: 9733, tags: tags)
note.id = calculate_event_id(ev: note)
note.id = hex_encode(calculate_event_id(ev: note))
note.sig = sign_event(privkey: identity.privkey, ev: note)
guard let note_json = encode_json(note),
@@ -715,7 +715,7 @@ func make_zap_request_event(keypair: FullKeypair, content: String, relays: [Rela
}
let ev = NostrEvent(content: message, pubkey: kp.pubkey, kind: 9734, tags: tags, createdAt: now)
ev.id = calculate_event_id(ev: ev)
ev.id = hex_encode(calculate_event_id(ev: ev))
ev.sig = sign_event(privkey: kp.privkey, ev: ev)
let zapreq = ZapRequest(ev: ev)
if let privzap_req {

View File

@@ -16,7 +16,7 @@ func created_deleted_account_profile(keypair: FullKeypair) -> NostrEvent {
let content = encode_json(profile)!
let ev = NostrEvent(content: content, pubkey: keypair.pubkey, kind: 0)
ev.id = calculate_event_id(ev: ev)
ev.id = hex_encode(calculate_event_id(ev: ev))
ev.sig = sign_event(privkey: keypair.privkey, ev: ev)
return ev
}

View File

@@ -28,7 +28,7 @@ func create_or_update_list_event(keypair: FullKeypair, mprev: NostrEvent?, to_ad
let ev = NostrEvent(content: "", pubkey: pubkey, kind: 30000, tags: tags)
ev.tags = tags
ev.id = calculate_event_id(ev: ev)
ev.id = hex_encode(calculate_event_id(ev: ev))
ev.sig = sign_event(privkey: keypair.privkey, ev: ev)
return ev
@@ -52,7 +52,7 @@ func remove_from_list_event(keypair: FullKeypair, prev: NostrEvent, to_remove: S
}
let ev = NostrEvent(content: prev.content, pubkey: keypair.pubkey, kind: 30000, tags: new_tags)
ev.id = calculate_event_id(ev: ev)
ev.id = hex_encode(calculate_event_id(ev: ev))
ev.sig = sign_event(privkey: keypair.privkey, ev: ev)
return ev
@@ -68,7 +68,7 @@ func add_to_list_event(keypair: FullKeypair, prev: NostrEvent, to_add: String, t
let new = NostrEvent(content: prev.content, pubkey: keypair.pubkey, kind: 30000, tags: prev.tags)
new.tags.append([tag_type, to_add])
new.id = calculate_event_id(ev: new)
new.id = hex_encode(calculate_event_id(ev: new))
new.sig = sign_event(privkey: keypair.privkey, ev: new)
return new