Telehashname v0.0.2 Telehashname

Telehash hashname handling

https://github.com/telehash/telehash.org/blob/master/v3/hashname.md

Summary

Types

Cipher Set ID

A list of CSIDs

A list of CSKs

Cipher Set Key

Sort direction control

Functions

Find the highest rated match among two CSK lists

Generate a hashname from a list of CSKs

Generate a hashname from intermediates

Validate and sort a CSID list

Determine if something looks like a valid hashname

Determine if something looks like a valid CSID

Types

csid :: <<_::2 * 8>>

Cipher Set ID

As an affordance, many functions will take a 4-byte CSID (the CSID with a pre-pended cs.) These will be normalized in most return values. It is not recommended to depend upon this behavior.

csid_list :: csk_list | [csid]

A list of CSIDs

csk_list :: [csk_tuple] | map

A list of CSKs

Maps will generally be transformed to a list of CSK tuples in the return values.

csk_tuple :: {csid, binary}

Cipher Set Key

sort_dir :: :asc | :dsc

Sort direction control

  • :asc == ascending
  • :dsc == descending

Functions

best_match(check, outs)

Specs

best_match(csid_list, csid_list) ::
  csid |
  csk_tuple |
  nil

Find the highest rated match among two CSK lists

The values returned from the outs list. Selecting which list to use for check and outs may provide some useful information “for free.”

from_csks(csks, im \\ %{})

Specs

from_csks(csk_list, map) :: {binary, map} | nil

Generate a hashname from a list of CSKs

As an affordance, an intermediates map may also be provided.

The return value is a tuple with the hashname and a map of the intermediate values used for generation.

nil is returned when no valid CSKs are found in the list.

from_intermediates(ims)

Specs

from_intermediates(csk_list | map) ::
  {binary, map} |
  nil

Generate a hashname from intermediates

ids(ids, dir \\ :dsc)

Specs

Validate and sort a CSID list

This can handle multiple forms of provided CSIDs. The return value will be appropriate to the input parameter.

Invalid CSIDs are removed, remaining IDs are normalized and sorted in the requested order.

is_valid?(hn)

Specs

is_valid?(term) :: boolean

Determine if something looks like a valid hashname

Confirms form only, not validity

is_valid_csid?(id)

Specs

is_valid_csid?(term) :: boolean

Determine if something looks like a valid CSID

Confirms form only, not validity. Some functions be more liberal in what they accept, but confirming validity is always better.