networking.node.tokens
tokens
¶
Classes:
| Name | Description |
|---|---|
TokenVerifier |
|
Classes¶
TokenVerifier
¶
Initializes the TokenVerifier with a public key.
This key is essential for securely decoding and verifying JSON Web Tokens (JWTs) issued by a corresponding private key. The public key can be provided as either a string or a bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
public_key
|
str | bytes
|
The public key used for decoding and verification. |
required |
Methods:
| Name | Description |
|---|---|
verify_token |
Verifies a JSON Web Token (JWT) against a set of criteria. |
Source code in unaiverse/networking/node/tokens.py
Methods:¶
verify_token
¶
verify_token(token: str | bytes, node_id: str | None = None, ip: str | None = None, hostname: str | None = None, port: int | None = None, p2p_peer: str | None = None)
Verifies a JSON Web Token (JWT) against a set of criteria.
The method first attempts to decode the token using the provided public key and the RS256 algorithm,
handling DecodeError and ExpiredSignatureError. It then performs optional checks to ensure that
the token's payload matches specific network identifiers, such as node_id, ip, hostname, and port.
It can also verify if a specific peer is present in the token's list of p2p_peers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str | bytes
|
The JWT to verify, as a string or bytes object. |
required |
node_id
|
str | None
|
Optional |
None
|
ip
|
str | None
|
Optional IP address to check. |
None
|
hostname
|
str | None
|
Optional hostname to check. |
None
|
port
|
int | None
|
Optional port number to check. |
None
|
p2p_peer
|
str | None
|
Optional peer identifier to check within the |
None
|
Returns:
| Type | Description |
|---|---|
|
A tuple containing the |
|
|
it returns a tuple of |