diff --git a/lib/didkit/resolver.rb b/lib/didkit/resolver.rb index 5426634..ef889b5 100644 --- a/lib/didkit/resolver.rb +++ b/lib/didkit/resolver.rb @@ -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 @@ -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 @@ -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)