Class: BSV::Auth::PeerSession

Inherits:
Object
  • Object
show all
Defined in:
lib/bsv/auth/peer_session.rb

Overview

Represents the state of an authentication session with a peer.

Sessions are indexed by session_nonce (our nonce for the session), which is the primary key in SessionManager. The peer_identity_key is a secondary index used to look up sessions by peer.

Examples:

Creating a session

session = PeerSession.new(session_nonce: nonce)
session.peer_identity_key = 'abc123...'
session.peer_nonce = 'xyz...'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_nonce:) ⇒ PeerSession

Returns a new instance of PeerSession.

Parameters:

  • session_nonce (String)

    our nonce for this session (base64)



38
39
40
41
42
43
44
45
46
# File 'lib/bsv/auth/peer_session.rb', line 38

def initialize(session_nonce:)
  @session_nonce          = session_nonce
  @peer_identity_key      = nil
  @peer_nonce             = nil
  @is_authenticated       = false
  @last_update            = current_time_ms
  @certificates_required  = false
  @certificates_validated = true
end

Instance Attribute Details

#certificates_requiredBoolean

Returns whether certificates are required from this peer.

Returns:

  • (Boolean)

    whether certificates are required from this peer



32
33
34
# File 'lib/bsv/auth/peer_session.rb', line 32

def certificates_required
  @certificates_required
end

#certificates_validatedBoolean

Returns whether required certificates have been validated.

Returns:

  • (Boolean)

    whether required certificates have been validated



35
36
37
# File 'lib/bsv/auth/peer_session.rb', line 35

def certificates_validated
  @certificates_validated
end

#is_authenticatedBoolean

Returns whether mutual authentication is complete.

Returns:

  • (Boolean)

    whether mutual authentication is complete



26
27
28
# File 'lib/bsv/auth/peer_session.rb', line 26

def is_authenticated
  @is_authenticated
end

#last_updateInteger

Returns Unix timestamp (milliseconds) of last update.

Returns:

  • (Integer)

    Unix timestamp (milliseconds) of last update



29
30
31
# File 'lib/bsv/auth/peer_session.rb', line 29

def last_update
  @last_update
end

#peer_identity_keyString?

Returns the peer’s identity key (public key hex).

Returns:

  • (String, nil)

    the peer’s identity key (public key hex)



20
21
22
# File 'lib/bsv/auth/peer_session.rb', line 20

def peer_identity_key
  @peer_identity_key
end

#peer_nonceString?

Returns the nonce we received from the peer (base64).

Returns:

  • (String, nil)

    the nonce we received from the peer (base64)



23
24
25
# File 'lib/bsv/auth/peer_session.rb', line 23

def peer_nonce
  @peer_nonce
end

#session_nonceString (readonly)

Returns our nonce for this session (base64) — primary key.

Returns:

  • (String)

    our nonce for this session (base64) — primary key



17
18
19
# File 'lib/bsv/auth/peer_session.rb', line 17

def session_nonce
  @session_nonce
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/bsv/auth/peer_session.rb', line 49

def authenticated?
  @is_authenticated
end