Implement NIP-21 URI handling
Changelog-Added: Added nostr: uri handling
This commit is contained in:
31
damus/Util/Bech32Object.swift
Normal file
31
damus/Util/Bech32Object.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Bech32Object.swift
|
||||
// damus
|
||||
//
|
||||
// Created by William Casarin on 2023-01-28.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
enum Bech32Object {
|
||||
case nsec(String)
|
||||
case npub(String)
|
||||
case note(String)
|
||||
|
||||
static func parse(_ str: String) -> Bech32Object? {
|
||||
guard let decoded = try? bech32_decode(str) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if decoded.hrp == "npub" {
|
||||
return .npub(hex_encode(decoded.data))
|
||||
} else if decoded.hrp == "nsec" {
|
||||
return .nsec(hex_encode(decoded.data))
|
||||
} else if decoded.hrp == "note" {
|
||||
return .note(hex_encode(decoded.data))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func create_or_update_list_event(keypair: FullKeypair, mprev: NostrEvent?, to_ad
|
||||
}
|
||||
}
|
||||
|
||||
var tags = [["d", list_name], [list_type, to_add]]
|
||||
let tags = [["d", list_name], [list_type, to_add]]
|
||||
let ev = NostrEvent(content: "", pubkey: pubkey, kind: 30000, tags: tags)
|
||||
|
||||
ev.tags = tags
|
||||
|
||||
Reference in New Issue
Block a user