latest.ipv8.attestation.tokentree.token
Module Contents
Classes
A double pointer, pointing to a previous token and content. |
- class latest.ipv8.attestation.tokentree.token.Token(previous_token_hash: bytes, content: bytes | None = None, content_hash: bytes | None = None, private_key: latest.ipv8.types.PrivateKey | None = None, signature: bytes | None = None)
Bases:
latest.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).
- get_plaintext() bytes
Return the double pointer of this Token in plain text format, being the concatenation of two hashes.
- classmethod unserialize(data: bytes, public_key: latest.ipv8.keyvault.keys.PublicKey, offset: int = 0) Token
Unserialize a token from the given binary data.
- receive_content(content: bytes) bool
Attempt to receive some content, only add it if its hash matches what we expect.
- Parameters:
content – the content potentially belonging to the hash pointed to by this Token.
- Returns:
whether we accepted the content.
- classmethod create(previous_token: Token, content: bytes, private_key: latest.ipv8.types.PrivateKey) Token
Create an sign a token that exists in a token tree.
- 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.
- classmethod from_database_tuple(previous_token_hash: bytes, signature: bytes, content_hash: bytes, content: bytes | None) Token
Create a Token from a four-byte-string representation (previous hash, signature, content hash and content).
- Parameters:
previous_token_hash – the hash of the preceding Token.
signature – the signature over the plaintext Token.
content_hash – the content hash of this Token.
content – optionally the content belonging to this Token.