token
NUC tokens.
- class Did(public_key: bytes)[source]
Bases:
objectA class representing a Decentralized Identifier (DID).
- static nil(public_key: bytes) Did[source]
Construct a new DID for the “nil” method.
- Parameters:
public_key – The public key in compressed form.
- __delattr__(name)
Implement delattr(self, name).
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- __setattr__(name, value)
Implement setattr(self, name, value).
- class Command(segments: List[str])[source]
Bases:
objectA command to be invoked.
- static parse(data: str) Command[source]
Parse a command from a string.
Example
from nuc.token import Command command = Command.parse("/nil/db/read")
- is_attenuation_of(other: Command) bool[source]
Check if this command is an attenuation of another one.
Example
from nuc.token import Command parent = Command.parse("/nil/db") child = Command.parse("/nil/db/read") assert child.is_attenuation_of(parent)
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- class InvocationBody(args: Dict[str, Any])[source]
Bases:
objectThe body of an invocation.
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- class DelegationBody(policies: List[Policy])[source]
Bases:
objectThe body of a delegation.
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- class NucToken(issuer: Did, audience: Did, subject: Did, not_before: datetime | None, expires_at: datetime | None, command: Command, body: InvocationBody | DelegationBody, meta: Dict[str, Any] | None, nonce: bytes, proofs: List[bytes])[source]
Bases:
objectA class representing a NUC token.
- body: InvocationBody | DelegationBody
- static parse(raw_json: str | bytes) NucToken[source]
Parse a NUC token from a string.
- Parameters:
raw_json – The raw JSON to be parsed.
Example
from nuc.token import NucToken token = NucToken.parse( { "iss": "did:nil:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aud": "did:nil:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "sub": "did:nil:cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", "cmd": "/nil/db/read", "pol": [["==", ".foo", 42]], "nonce": "beef", } )
- __eq__(other)
Return self==value.
- __repr__()
Return repr(self).
- exception MalformedDidException[source]
Bases:
ExceptionAn exception raised when a malformed DID is parsed.