Class: AtprotoAuth::Identity::DID

Inherits:
Object
  • Object
show all
Defined in:
lib/atproto_auth/identity/did.rb

Overview

Validates decentralized identifiers (DIDs)

Constant Summary collapse

PREFIXES =
["did:plc:", "did:web:"].freeze

Instance Method Summary collapse

Constructor Details

#initialize(did) ⇒ DID

Returns a new instance of DID.



11
12
13
# File 'lib/atproto_auth/identity/did.rb', line 11

def initialize(did)
  @did = did
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/atproto_auth/identity/did.rb', line 21

def to_s
  @did
end

#validate!Object

Raises:



15
16
17
18
19
# File 'lib/atproto_auth/identity/did.rb', line 15

def validate!
  return if PREFIXES.any? { |prefix| @did.start_with?(prefix) }

  raise Error, "Invalid DID format (must be one of #{PREFIXES.join(", ")}): #{@did}"
end