KERI Peer API

keri.peer.exchanging

keri.peer.exchanging module

class keri.peer.exchanging.Exchanger(hby, handlers, cues=None, delta=datetime.timedelta(seconds=300))[source]

Peer to Peer KERI message Exchanger.

__init__(hby, handlers, cues=None, delta=datetime.timedelta(seconds=300))[source]

Initialize instance

Parameters:
  • hby (Haberyu) – database environment

  • handlers (list) – list of Handlers capable of responding to exn messages

  • cues (Deck) – of Cues i.e. notices of requests needing response

  • delta (timedelta) – message timeout window

complete(said)[source]
Parameters:

said (str) – qb64 said of exchange message to check status

Returns:

True means exchange message is has been saved

Return type:

bool

escrowPSEvent(serder, tsgs, pathed)[source]

Escrow event that does not have enough signatures.

Parameters:
  • serder (Serder) – instance of event

  • tsgs (list) – quadlet of prefixer seqner, saider, sigers

  • pathed (list) – list of bytes of attached paths

lead(hab, said)[source]

Determines is current member represented by hab is the lead of an exn message

Lead is the signer of the exn with the lowest signing index

Parameters:
  • hab (Hab) – Habitat for sending of exchange message represented by SAID

  • said (str) – qb64 SAID of exchange message

Returns:

True means hab is the lead

Return type:

bool

processEscrow()[source]

Process all escrows for exn messages

processEscrowPartialSigned()[source]

Process escrow of partially signed messages

processEvent(serder, tsgs=None, cigars=None, ptds=None, essrs=None, **kwa)[source]

Process one serder event with attached indexed signatures representing a Peer to Peer exchange message.

Parameters:
  • serder (Serder) – instance of event to process

  • tsgs (list) – tuples (quadruples) of form (prefixer, seqner, diger, [sigers]) where: prefixer is pre of trans endorser seqner is sequence number of trans endorser’s est evt for keys for sigs diger is digest of trans endorser’s est evt for keys for sigs [sigers] is list of indexed sigs from trans endorser’s keys from est evt

  • cigars (list) – of Cigar instances of attached non-trans sigs

  • ptds (list[bytes]) – pathed Cesr Streams

  • essrs (list[Texter]) – ESSR streams as Texters

keri.peer.exchanging.cloneMessage(hby, said)[source]

Load and verify signatures on message exn

Parameters:
  • hby (Habery) – database environment from which to clone message

  • said (str) – qb64 SAID of message exn to load

Returns:

(serder, list) of message exn and pathed signatures on embedded attachments

Return type:

tuple

keri.peer.exchanging.exchangeOld(*, sender='', receiver='', xid='', prior='', route='', modifiers=None, attributes=None, diger=None, embeds=None, stamp=None, version=(1, 0), pvrsn=None, gvrsn=None, kind='JSON')[source]

Create an exn message with the specified route and payload

Parameters:
  • sender (str) – qb64 of sender identifier (AID)

  • receiver (str) – qb64 of receiver identifier (AID)

  • xid (str) – qb64 of exchange ID which is SAID of exchange inception ‘xip’ if any

  • prior (str) – qb64 of prior exchange event including ‘xip” if any

  • route (str) – ‘/’ delimited path identifier of data flow handler (behavior) to processs the reply if any (equivalent of url path to resource)

  • modifiers (dict) – modifiers field map (equvalent of http query string)

  • attributes (dict) – attributes field map (payload body)

  • stamp (str) – date-time-stamp RFC-3339 profile of ISO-8601 datetime of creation of message or data, default is now.

  • version (Versionage) – KERI protocol default version if psvrsn is None

  • pvrsn (Versionage) – KERI protocol version

  • gvrsn (Versionage) –

    CESR Genus version for attachment group codes or nesting group code (useful when serder.gvrsn < 2) gvrsn = max(svrsn, gvrsn) where svrsn = serder.gvrsn

    if serder.gvrsn else serder.pvrsn

  • kind (str) – serialization for key event message one of Kinds (“json”,”cbor”,”mgpk”,”cesr”)

  • diger (Diger) – qb64 digest of attributes section (payload)

  • embeds (dict) – named embeded KERI event CESR stream with attachments

keri.peer.exchanging.nesting(paths, acc, val)[source]

Nesting Pather parts

Parameters:

paths (list[list]) – list of path parts

keri.peer.exchanging.serializeMessage(hby, said, framed=False)[source]

Fetch message and attachments from hby.db by said and then serialize them

Parameters::

hby (Habery): environment with db said (str): of message framed (bool): True means may assume each message plus its attachments

is isolated as frame when parsing so do not need attachment group when messagizing

False means may not assume eash message plus its attachments

is isolated as frame when parsing so do need attachment group when messagizing

Returns::

msg (bytearray): message by said with attachments

keri.peer.exchanging.specialExchange(*, sender='', receiver='', xid='', prior='', route='', modifiers=None, attributes=None, diger=None, embeds=None, stamp=None, version=(1, 0), pvrsn=None, gvrsn=None, kind='JSON')[source]

Create an exn with either an ESSR attachment or embeds with path attachment as determined by the presence of diger or embeds parameters repectively

Parameters::

sender (str): qb64 of sender identifier (AID) receiver (str): qb64 of receiver identifier (AID) xid (str): qb64 of exchange ID which is SAID of exchange inception ‘xip’

if any

prior (str): qb64 of prior exchange event including ‘xip” if any route (str): ‘/’ delimited path identifier of data flow handler

(behavior) to processs the reply if any (equivalent of url path to resource)

modifiers (dict): modifiers field map (equvalent of http query string) attributes (dict): attributes field map (payload body) stamp (str): date-time-stamp RFC-3339 profile of ISO-8601 datetime of

creation of message or data, default is now.

version (Versionage): KERI protocol default version if psvrsn is None pvrsn (Versionage): KERI protocol version gvrsn (Versionage): CESR Genus version for attachment group codes or

nesting group code (useful when serder.gvrsn < 2) gvrsn = max(svrsn, gvrsn) where svrsn = serder.gvrsn

if serder.gvrsn else serder.pvrsn

kind (str): serialization for key event message

one of Kinds (“json”,”cbor”,”mgpk”,”cesr”)

diger (Diger): qb64 digest of attributes section (payload) embeds (dict): named embeded KERI event CESR stream with attachments

Returns::
embedded (SerderKeri, bytearray): of form (exchange, attachments) where

exchange is serder of exchange message and atc is serialized path attachments of embeds

keri.peer.exchanging.verify(hby, serder)[source]

Verify that the signatures in the database are valid for the provided exn

Parameters:
  • hby (Habery) – database environment from which to verify message

  • serder (Serder) – exn serder to load and verify signatures for

Returns:

True means threshold satisfyig signatures were loaded and verified successfully

Return type:

bool