Class: SecID::DTI

Inherits:
Base
  • Object
show all
Includes:
Checkable
Defined in:
lib/sec_id/dti.rb

Overview

Digital Token Identifier (DTI, ISO 24165) - a 9-character alphanumeric code that identifies digital tokens (e.g. cryptocurrencies) for regulatory reporting.

Format: 8-character base + 1 check character, drawn from a 30-symbol alphabet (digits 0-9 plus consonants; vowels and 'Y' never appear). Validated fully offline via ISO 7064 hybrid MOD 31,30 over the base.

Examples:

Validate a DTI

SecID::DTI.valid?('X9J9K872S')  #=> true

Restore check digit

SecID::DTI.restore('X9J9K872')  #=> 'X9J9K872S'

See Also:

Constant Summary collapse

FULL_NAME =

Human-readable name of the standard.

'Digital Token Identifier'
ID_LENGTH =

Valid length(s) of a normalized identifier.

9
EXAMPLE =

A representative valid identifier.

'X9J9K872S'
VALID_CHARS_REGEX =

Pattern matching the identifier's permitted character set (digits + consonants, no vowels/Y).

/\A[0-9B-DF-HJ-NP-TV-XZ]+\z/
ID_REGEX =

Regular expression for parsing DTI components. First character of the base is never '0'.

/\A
  (?<identifier>
    [1-9B-DF-HJ-NP-TV-XZ]
    [0-9B-DF-HJ-NP-TV-XZ]{7})
  (?<check_digit>[0-9B-DF-HJ-NP-TV-XZ])?
\z/x
ALPHABET =

The 30-symbol DTI alphabet, ordered by check-character value (0-29).

'0123456789BCDFGHJKLMNPQRSTVWXZ'.chars.freeze
ALPHABET_VALUE =

Maps each alphabet character to its check-character value (0-29).

ALPHABET.each_with_index.to_h.freeze
GENERATE_CHARSET =

Characters valid in a DTI base (same alphabet as VALID_CHARS_REGEX).

ALPHANUMERIC.grep(VALID_CHARS_REGEX).freeze
GRANDFATHERED_CODES =

Registry-assigned codes whose stored check character differs from the algorithmic ISO 7064 MOD 31,30 computation. Base (8 chars) => registered code (9 chars).

{ '4H95J0R2' => '4H95J0R2X' }.freeze

Constants included from Checkable

Checkable::CHAR_TO_DIGIT, Checkable::CHAR_TO_DIGITS

Constants included from Generatable

Generatable::ALPHA, Generatable::ALPHANUMERIC, Generatable::DIGITS

Constants included from Validatable

Validatable::ERROR_MAP

Constants included from Normalizable

Normalizable::SEPARATORS

Instance Attribute Summary

Attributes inherited from Base

#full_id, #identifier

Instance Method Summary collapse

Methods included from Checkable

#restore, #restore!, #to_s, #valid?

Methods inherited from Base

#==, #as_json, example, full_name, has_check_digit?, #hash, id_length, length_specificity, length_values, short_name, #to_h

Methods included from Validatable

#errors, #valid?, #validate, #validate!

Methods included from Normalizable

#normalize!, #normalized, #to_pretty_s, #to_s, #to_str

Constructor Details

#initialize(dti) ⇒ DTI

Returns a new instance of DTI.

Parameters:

  • dti (String)

    the DTI string to parse



55
56
57
58
59
# File 'lib/sec_id/dti.rb', line 55

def initialize(dti)
  dti_parts = parse dti
  @identifier = dti_parts[:identifier]
  @check_digit = dti_parts[:check_digit]
end

Instance Method Details

#calculate_check_digitString

Returns the calculated or grandfathered check character.

Returns:

  • (String)

    the calculated or grandfathered check character

Raises:



63
64
65
66
# File 'lib/sec_id/dti.rb', line 63

def calculate_check_digit
  validate_format_for_calculation!
  grandfathered_check_digit(identifier) || iso7064_mod31_30_check_char(identifier)
end