latest.ipv8.attestation.tokentree.tree
Module Contents
Classes
Raw datatype for chains of double pointers (Tokens). |
- class latest.ipv8.attestation.tokentree.tree.TokenTree(public_key: latest.ipv8.types.PublicKey | None = None, private_key: latest.ipv8.types.PrivateKey | None = None)
Raw datatype for chains of double pointers (Tokens).
It takes the following form:
SHA3-256(PUBLIC KEY) <- TOKEN <- TOKEN <- …
Each token also has a SHA3-256 pointer to external content.
Note that the public key has to be known to fulfil the genesis pointer to the SHA3-256 hash (the public key is not stored in the Tokens themselves).
- add(content: bytes, after: latest.ipv8.attestation.tokentree.token.Token | None = None) latest.ipv8.attestation.tokentree.token.Token
Tokenize new content and add it to this chain.
- Parameters:
content – the content to tokenize and add to this chain.
after – the token to succeed.
- Returns:
the newly added Token.
- add_by_hash(content_hash: bytes, after: latest.ipv8.attestation.tokentree.token.Token | None = None) latest.ipv8.attestation.tokentree.token.Token
Add the promise of tokenized content to this chain.
- Parameters:
content_hash – the hash of the content to add to this chain.
after – the token to succeed.
- Returns:
the newly added Token.
- gather_token(token: latest.ipv8.attestation.tokentree.token.Token) latest.ipv8.attestation.tokentree.token.Token | None
Attempt to add received data to this chain. Data may be pending missing Tokens before being added to the chain structure.
- Parameters:
token – the token to attempt to add.
- Returns:
the newly added token or None if the operation was not successful.
- get_missing() Set[bytes]
Gather all the preceding hashes that have been specified but not collected.
- Returns:
the set of missing hashes.
- verify(token: latest.ipv8.attestation.tokentree.token.Token, maxdepth: int = 1000) bool
Verify the chain integrity: all preceding tokens are correctly signed and stored.
Should only be done when loading from database or direct writing (don’t do that) by programmers.
- Parameters:
token – the token to start checking from.
maxdepth – the maximum amount of steps to verify (after which this returns False).
- Returns:
whether all preceding tokens were correct and signed.
- get_root_path(token: latest.ipv8.attestation.tokentree.token.Token, maxdepth: int = 1000) list[latest.ipv8.attestation.tokentree.token.Token]
Calculate the path back to the root, including this token.
- Parameters:
token – the token to start checking from.
maxdepth – the maximum amount of steps (after which this returns an empty list).
- Returns:
the length of the path back to the root or an empty list if it doesn’t exist.
- serialize_public(up_to: latest.ipv8.attestation.tokentree.token.Token | None = None) bytes
Serialize all the signed double pointers of this chain.
- Parameters:
up_to – the token to work back from to the root of the tree.
- unserialize_public(s: bytes) bool
Given a serialized tree format, unserialize with the tree’s public key.
- Parameters:
s – the serialized tree data.
- Returns:
if all information was correctly unserialized.
- _append(token: latest.ipv8.attestation.tokentree.token.Token) latest.ipv8.attestation.tokentree.token.Token
Append a token to this tree. Never call this directly: use add() instead!
- Parameters:
token – the token to append to the chain.
- Returns:
the appended token.
- _append_chain_reaction_token(token: latest.ipv8.attestation.tokentree.token.Token) None
Append the given token and wake up any tokens stored in unchained that pointed to it.
- Parameters:
token – the token to append to the chain.