Module: Nostrb::Names
- Defined in:
- lib/nostrb/names.rb
Overview
NIP-05
Constant Summary collapse
- LOCAL =
/\A[_a-z0-0\-.]+\z/i
- DOMAIN =
/\A[a-z0-9\-.]+\z/i
Class Method Summary collapse
-
.extract_names(json) ⇒ Object
look for a pubkey: “names”:{“bob”:“b0b0…b0”} the pubkey at the URL should match the pubkey from the profile event.
-
.extract_nip05(json) ⇒ Object
content: <JSON> kind: 0 (set_metadata) JSON: name: about: picture: nip05: [email protected].
-
.extract_relays(json) ⇒ Object
or even relays too: “names”:{“bob”:“b0b0…b0” “relays”:{ “b0b0…b0”: } }.
-
.identifier(str) ⇒ Object
given [email protected], return [bob, example.com].
-
.well_known_url(local, domain) ⇒ Object
when we get bob’s profile back, if it has a nip05 field visit: example.com/.well-known/nostr.json?name=bob.
Class Method Details
.extract_names(json) ⇒ Object
look for a pubkey: “names”:{“bob”:“b0b0…b0”} the pubkey at the URL should match the pubkey from the profile event
40 41 42 43 44 45 46 47 |
# File 'lib/nostrb/names.rb', line 40 def self.extract_names(json) hsh = Nostrb.parse(json).fetch("names") hsh.each { |name, pubkey| Nostrb.txt!(name) Nostrb.pubkey!(pubkey) } hsh end |
.extract_nip05(json) ⇒ Object
content: <JSON> kind: 0 (set_metadata) JSON:
name:
about:
picture:
nip05: [email protected]
25 26 27 28 |
# File 'lib/nostrb/names.rb', line 25 def self.extract_nip05(json) addr = Nostrb.parse(json)['nip05'] identifier(addr) if addr end |
.extract_relays(json) ⇒ Object
or even relays too: “names”:{“bob”:“b0b0…b0”
"relays":{
"b0b0...b0":["wss://relay.example.com/","wss://relay2.example.com/"]
}
}
55 56 57 58 59 60 61 62 63 |
# File 'lib/nostrb/names.rb', line 55 def self.extract_relays(json) hsh = Nostrb.parse(json).fetch("relays") hsh.each { |pubkey, urls| Nostrb.pubkey!(pubkey) Nostrb.ary!(urls) urls.each { |u| Nostrb.txt!(u) } } hsh end |
.identifier(str) ⇒ Object
given [email protected], return [bob, example.com]
10 11 12 13 14 15 16 |
# File 'lib/nostrb/names.rb', line 10 def self.identifier(str) a = str.split('@') raise "unexpected #{a.inspect}" unless a.length == 2 raise "bad local: #{a[0]}" unless LOCAL.match a[0] raise "bad domain #{a[1]}" unless DOMAIN.match a[1] a end |
.well_known_url(local, domain) ⇒ Object
when we get bob’s profile back, if it has a nip05 field visit: example.com/.well-known/nostr.json?name=bob
33 34 35 |
# File 'lib/nostrb/names.rb', line 33 def self.well_known_url(local, domain) format("https://%s/.well-known/nostr.json?name=%s", domain, local) end |