Skip to content

Commit

Permalink
accept handles with well-known having a trailing newline
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Mar 9, 2024
1 parent 66110d1 commit 92b0f03
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/didkit/resolver.rb
Expand Up @@ -29,9 +29,7 @@ def resolve_handle_by_dns(domain)

if record = dns_records.first
if string = record.strings.first
if string =~ /^did\=(did\:\w+\:.*)$/
return $1
end
return parse_did_from_dns(string)
end
end

Expand All @@ -48,9 +46,7 @@ def resolve_handle_by_well_known(domain)

if response.is_a?(Net::HTTPSuccess)
if text = response.body
if text.lines.length == 1 && text.start_with?('did:')
return text
end
return parse_did_from_well_known(text)
end
end

Expand All @@ -59,6 +55,15 @@ def resolve_handle_by_well_known(domain)
nil
end

def parse_did_from_dns(txt)
txt =~ /\Adid\=(did\:\w+\:.*)\z/ ? $1 : nil
end

def parse_did_from_well_known(text)
text = text.strip
text.lines.length == 1 && text.start_with?('did:') ? text : nil
end

def resolve_did(did)
did = DID.new(did) if did.is_a?(String)

Expand Down

0 comments on commit 92b0f03

Please sign in to comment.