Module: BSV::Identity::IdentityParser

Defined in:
lib/bsv/identity/identity_parser.rb

Overview

Parses an IdentityCertificate into a DisplayableIdentity suitable for presentation in a user interface.

Handles all 9 well-known certificate types (xCert, discordCert, phoneCert, emailCert, identiCert, registrant, coolCert, anyone, self) with type-specific field extraction that matches the TS SDK implementation exactly. Unknown certificate types fall through to a generic field-name heuristic.

Constant Summary collapse

EMAIL_AVATAR =

Well-known avatar opaque strings used by specific certificate types.

'XUTZxep7BBghAJbSBwTjNfmcsDdRFs5EaGEgkESGSgjJVYgMEizu'
PHONE_AVATAR =
'XUTLxtX3ELNUwRhLwL7kWNGbdnFM8WG2eSLv84J7654oH8HaJWrU'
ANYONE_AVATAR =
'XUT4bpQ6cpBaXi1oMzZsXfpkWGbtp2JTUYAoN7PzhStFJ6wLfoeR'
SELF_AVATAR =
'XUT9jHGk2qace148jeCX5rDsMftkSGYKmigLwU2PLLBc7Hm63VYR'
BADGE_ICON =
'XUUV39HVPkpmMzYNTx7rpKzJvXfeiVyQWg2vfSpjBAuhunTCA9uG'

Class Method Summary collapse

Class Method Details

.parse(identity_certificate) ⇒ DisplayableIdentity

Parameters:

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bsv/identity/identity_parser.rb', line 24

def self.parse(identity_certificate)
  fields       = identity_certificate.decrypted_fields
  certifier    = identity_certificate.certifier_info
  type_b64     = identity_certificate.certificate[:type]

  name, avatar_url, badge_label, badge_icon_url, badge_click_url =
    extract_fields(type_b64, fields, certifier)

  subject       = identity_certificate.certificate[:subject].to_s
  identity_key  = subject
  abbreviated   = abbreviated_key(subject)

  DisplayableIdentity.new(
    name: name,
    avatar_url: avatar_url,
    abbreviated_key: abbreviated,
    identity_key: identity_key,
    badge_icon_url: badge_icon_url,
    badge_label: badge_label,
    badge_click_url: badge_click_url
  )
end