PrismStateInMemory

fmgp.did.method.prism.PrismStateInMemory
See thePrismStateInMemory companion object
case class PrismStateInMemory(ref: Ref[PrismStateInMemoryData]) extends PrismState

Thread-safe in-memory implementation of PrismState using ZIO Ref.

Stores all events and indices in memory using immutable maps. Suitable for testing, development, and small datasets where persistence is not required. Not recommended for production use with large datasets.

==Event Chain Tracking==

This implementation tracks event chains by recursively following previousEventHash references:

  • Create operations establish the root of a chain
  • Update/Deactivate operations reference previous events
  • Helper methods ssiFromPreviousEventHash and vdrFromPreviousEventHash traverse chains to find roots

==Thread Safety==

All state updates use ZIO Ref for lock-free, thread-safe mutations. Multiple concurrent operations are safely handled without explicit locking.

Value parameters

ref

ZIO Ref containing mutable PrismStateInMemoryData

Attributes

Constructor

Creates in-memory state with ZIO Ref

Example
for {
 state <- PrismStateInMemory.empty
 _ <- state.addEvent(createEvent)
 _ <- state.addEvent(updateEvent)
 ssi <- state.getSSI(didSubject)
 docs <- state.didDocuments
} yield (ssi, docs)
Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait PrismState
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def addEvent(op: MySignedPrismEvent[OP]): ZIO[Any, Nothing, Unit]

We add/index events with out validating them.

We add/index events with out validating them.

Validation is then when it's been resolved.

Attributes

Definition Classes
def cursor: ZIO[Any, Nothing, EventCursor]

Attributes

Returns

EventCursor of the latest Event

def didDocuments: ZIO[Any, Nothing, Seq[DIDDocument]]

Extracts DID Documents from all SSI states.

Extracts DID Documents from all SSI states.

Attributes

override def getEventByHash(refHash: EventHash): ZIO[Any, Nothing, Option[MySignedPrismEvent[OP]]]

Gets a specific event by its EventHash.

Gets a specific event by its EventHash.

Attributes

Definition Classes
override def getEventsIdBySSI(ssi: DIDSubject): ZIO[Any, Nothing, Seq[EventRef]]

Returns event references for a specific SSI DID.

Returns event references for a specific SSI DID.

Attributes

Definition Classes
override def getEventsIdByVDR(id: RefVDR): ZIO[Any, Nothing, Seq[EventRef]]

Returns event references for a specific VDR.

Returns event references for a specific VDR.

Attributes

Definition Classes
def makeSSI: ZIO[Any, Nothing, Seq[SSI]]

Constructs SSI states for all DIDs in memory.

Constructs SSI states for all DIDs in memory.

Builds resolved SSI objects by folding events for each DID in order.

Attributes

override def ssi2eventsRef: ZIO[Any, Nothing, Map[DIDSubject, Seq[EventRef]]]

Returns mapping of all SSI DIDs to their event references.

Returns mapping of all SSI DIDs to their event references.

Attributes

Note

TODO: make it a Stream of (DIDSubject, Seq[EventRef])

Definition Classes
final def ssiFromPreviousEventHash(previousHash: String): ZIO[Any, Nothing, Option[String]]

Recursively traverses event chain to find the root SSI hash.

Recursively traverses event chain to find the root SSI hash.

Follows previousEventHash references backward through Update operations until reaching the Create operation.

Value parameters

previousHash

The event hash to start traversal from

Attributes

Returns

ZIO effect with optional root hash (hash of CreateDidOP)

Note

TODO: @scala.annotation.tailrec - Error 'Cannot rewrite recursive call - not in tail position'

override def vdr2eventsRef: ZIO[Any, Nothing, Map[RefVDR, Seq[EventRef]]]

Returns mapping of all VDRs to their event references.

Returns mapping of all VDRs to their event references.

Attributes

Note

TODO: make it a Stream of (RefVDR, Seq[EventRef])

Definition Classes
final def vdrFromPreviousEventHash(previousHash: String): ZIO[Any, Nothing, Option[RefVDR]]

Recursively traverses event chain to find the root VDR reference.

Recursively traverses event chain to find the root VDR reference.

Follows previousEventHash references backward through Update operations until reaching the Create operation.

Attributes

Note

TODO: @scala.annotation.tailrec - Error 'Cannot rewrite recursive call - not in tail position'

Inherited methods

def addMaybeEvent(maybeEvent: MaybeEvent[OP]): ZIO[Any, Exception, Unit]

Adds an event after filtering out invalid ones.

Adds an event after filtering out invalid ones.

Only valid MySignedPrismEvent instances are added; invalid objects are silently ignored.

Attributes

Inherited from:
PrismState

Fetches all events in the chain for the given DID.

Fetches all events in the chain for the given DID.

Attributes

Returns

ZIO effect that may fail with Throwable (RuntimeException if event hash missing or type validation fails) and succeeds with sequence of DID-related MySignedPrismEvent

Inherited from:
PrismStateRead

Fetches all events in the chain for the given VDR reference.

Fetches all events in the chain for the given VDR reference.

Value parameters

refVDR

The VDR reference to query

Attributes

Returns

ZIO effect that may fail with Throwable (RuntimeException if event hash missing or type validation fails) and succeeds with sequence of storage-related MySignedPrismEvent

Inherited from:
PrismStateRead
def getSSI(ssi: DIDSubject): ZIO[Any, Throwable, SSI]

Gets the current SSI state.

Gets the current SSI state.

Attributes

Inherited from:
PrismStateRead

Gets the full SSIHistory for a SSI.

Gets the full SSIHistory for a SSI.

Attributes

Inherited from:
PrismStateRead
def getVDR(ref: RefVDR): ZIO[Any, Throwable, VDR]

Gets the VDR state with full ownership validation.

Gets the VDR state with full ownership validation.

Attributes

Inherited from:
PrismStateRead

Returns the last synced block timestamp.

Returns the last synced block timestamp.

Attributes

Returns

Tuple of (epoch seconds, nanoseconds)

Note

Current implementation returns current time (FIXME: should track actual sync state)

Inherited from:
PrismStateRead

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product
def ssiCount: ZIO[Any, Nothing, Int]

Returns count of SSI DIDs in the state.

Returns count of SSI DIDs in the state.

Attributes

Note

TODO: improve in specific implementations for better performance

Inherited from:
PrismStateRead
def vdrCount: ZIO[Any, Nothing, Int]

Returns count of VDRs in the state.

Returns count of VDRs in the state.

Attributes

Note

TODO: improve in specific implementations for better performance

Inherited from:
PrismStateRead