Skip to content

Commit

Permalink
Namecoin: Handle id/ names in identifier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Oct 1, 2018
1 parent 4c9a25a commit 1e32ab2
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions electrum_nmc/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ def format_name_identifier(identifier_bytes):

is_identity_namespace = identifier.startswith("id/")
if is_identity_namespace:
# TODO: handle identities
return format_name_identifier_unknown(identifier)
return format_name_identifier_identity(identifier)

return format_name_identifier_unknown(identifier)

Expand Down Expand Up @@ -129,6 +128,26 @@ def format_name_identifier_domain(identifier):

return "Domain " + label + ".bit"


def format_name_identifier_identity(identifier):
label = identifier[len("id/"):]

if len(label) < 1:
return format_name_identifier_unknown(identifier)

# Max id/ identifier length is 255 chars according to wiki spec. But we
# don't need to check for this, because that's also the max length of an
# identifier under the Namecoin consensus rules.

# Same as d/ regex but without IDN prefix.
# TODO: this doesn't exactly match the https://wiki.namecoin.org spec.
label_regex = r"^[a-z0-9]+(-[a-z0-9]+)*$"
label_match = re.match(label_regex, label)
if label_match is None:
return format_name_identifier_unknown(identifier)

return "Identity " + label

def format_name_identifier_unknown(identifier):
# Check for non-printable characters, and print ASCII if none are found.
if identifier.isprintable():
Expand Down

0 comments on commit 1e32ab2

Please sign in to comment.