envelope

NUC envelope.

class DecodedNucToken(raw_header: str, raw_payload: str, signature: bytes, token: NucToken)[source]

Bases: object

A decoded NUC token.

raw_header: str
raw_payload: str
signature: bytes
token: NucToken
static parse(data: str) DecodedNucToken[source]

Parse a token from its serialized JWT form.

Note that this only parses the token and ensures it is structurally correct. This does not perform any form of signature validation.

Note

Users should use NucTokenEnvelope to parse tokens.

serialize() str[source]

Serialize this token as a JWT.

validate_signature() None[source]

Validate the signature in this token.

compute_hash() bytes[source]

Compute the hash for this token.

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

class NucTokenEnvelope(token: DecodedNucToken, proofs: List[DecodedNucToken])[source]

Bases: object

A NUC token envelope, containing a parsed token along with all its proofs

static parse(data: str) NucTokenEnvelope[source]

Parse a NUC token envelope from its serialized JWT form.

Note that this only parses the envelope and ensures it is structurally correct. This does not perform any form of signature validation.

Example

from nuc.envelope import NucTokenEnvelope

raw_token = "....."

token = NucTokenEnvelope.parse(raw_token)
validate_signatures() None[source]

Validate the signature in this envelope.

This will raise an exception is the token or any of its proofs is not signed by its issuer.

serialize() str[source]

Serialize this envelope as a JWT-like string.

exception MalformedNucJwtException[source]

Bases: Exception

An exception thrown when a malformed NUC JWT is parsed.

exception InvalidSignatureException[source]

Bases: Exception

An exception thrown when signature verification fails.

urlsafe_base64_decode(data: str) bytes[source]

Encode an input as URL safe base64.

urlsafe_base64_encode(data: bytes) str[source]

Encode URL safe base64.