3.0.ipv8.attestation.tokentree.token ==================================== .. py:module:: 3.0.ipv8.attestation.tokentree.token Classes ------- .. autoapisummary:: 3.0.ipv8.attestation.tokentree.token.Token Module Contents --------------- .. py:class:: Token(previous_token_hash: bytes, content: bytes | None = None, content_hash: bytes | None = None, private_key: 3.0.ipv8.types.PrivateKey | None = None, signature: bytes | None = None) Bases: :py:obj:`3.0.ipv8.attestation.signed_object.AbstractSignedObject` A double pointer, pointing to a previous token and content. The contents belonging to the content pointer can be added to a Token object. Tokens do not and should not contain an index (but occupy one in a chain). Tokens do not and should not contain a reference to the public key (but are signed by one). .. py:attribute:: previous_token_hash .. py:method:: get_plaintext() -> bytes Return the double pointer of this Token in plain text format, being the concatenation of two hashes. .. py:method:: unserialize(data: bytes, public_key: 3.0.ipv8.keyvault.keys.PublicKey, offset: int = 0) -> Token :classmethod: Unserialize a token from the given binary data. .. py:method:: receive_content(content: bytes) -> bool Attempt to receive some content, only add it if its hash matches what we expect. :param content: the content potentially belonging to the hash pointed to by this Token. :returns: whether we accepted the content. .. py:method:: create(previous_token: Token, content: bytes, private_key: 3.0.ipv8.types.PrivateKey) -> Token :classmethod: Create an sign a token that exists in a token tree. .. py:method:: to_database_tuple() -> tuple[bytes, bytes, bytes, bytes | None] Get a representation of this Token as four byte strings (previous hash, signature, content hash and content). :returns: the four byte strings for database insertion. .. py:method:: from_database_tuple(previous_token_hash: bytes, signature: bytes, content_hash: bytes, content: bytes | None) -> Token :classmethod: Create a Token from a four-byte-string representation (previous hash, signature, content hash and content). :param previous_token_hash: the hash of the preceding Token. :param signature: the signature over the plaintext Token. :param content_hash: the content hash of this Token. :param content: optionally the content belonging to this Token. .. py:method:: __str__() -> str Represent this token as a human-readable string.