nilauth

nilauth client.

class BlindModule(value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: StrEnum

A Nillion blind module.

NILAI = 'nilai'

The nilai blind module

NILDB = 'nildb'

The nildb blind module

__new__(value)
__format__(format_spec, /)

Return a formatted version of the string as described by format_spec.

__str__()

Return str(self).

class NilauthAbout(public_key: PublicKey)[source]

Bases: object

Information about a nilauth server.

public_key: PublicKey

The server’s public key.

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

class SubscriptionDetails(expires_at: datetime, renewable_at: datetime)[source]

Bases: object

Information about a subscription.

expires_at: datetime

The timestamp at which this subscription expires.

renewable_at: datetime

The timestamp at which this subscription can be renewed.

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

class Subscription(subscribed: bool, details: SubscriptionDetails | None)[source]

Bases: object

Information about a subscription.

subscribed: bool

Whether there is an active subscription

details: SubscriptionDetails | None

The details about the subscription.

__eq__(other)

Return self==value.

__repr__()

Return repr(self).

class RevokedToken(token_hash: bytes, revoked_at: datetime)[source]

Bases: object

A revoked token.

token_hash: bytes
revoked_at: datetime
__eq__(other)

Return self==value.

__repr__()

Return repr(self).

class NilauthClient(base_url: str, timeout_seconds=DEFAULT_REQUEST_TIMEOUT)[source]

Bases: object

A class to interact with nilauth.

Example

from secp256k1 import PrivateKey
from nuc.nilauth import NilauthClient

# Create a client to talk to nilauth at the given url.
client = NilauthClient(base_url)

# Create a private key.
key = PrivateKey()

# Request a token for it.
token = client.request_token(key)
request_token(key: PrivateKey, blind_module: BlindModule) str[source]

Request a token, issued to the public key tied to the given private key.

Requesting tokens can only be done if a subscription has been paid for the blind module ahead of time.

Parameters:
  • key – The key for which the token should be issued to.

  • blind_module – The blind module to get a token for.

  • note: (..) – The private key is only used to sign a payload to prove ownership and is: never transmitted anywhere.

pay_subscription(pubkey: PublicKey, payer: Payer, blind_module: BlindModule) None[source]

Pay for a subscription for a blind module.

Parameters:
  • pubkey – The public key the subscription is for.

  • payer – The payer that will be used.

  • blind_module – The blind module that the subscription is for.

subscription_status(pubkey: PublicKey, blind_module: BlindModule) Subscription[source]

Get the status of a subscription to a blind module.

Parameters:
  • pubkey – The public key for which to get the subscription information.

  • blind_module – The blind module to get the subscription status for.

  • note: (..) – The private key is only used to sign a payload to prove ownership and is: never transmitted anywhere.

about() NilauthAbout[source]

Get information about the nilauth server.

subscription_cost(blind_module: BlindModule) int[source]

Get the subscription cost in unils.

Parameters:

blind_module – The blind module to get the subscription cost for.

revoke_token(auth_token: NucTokenEnvelope, token: NucTokenEnvelope, key: PrivateKey) None[source]

Revoke a token.

Parameters:
  • auth_token – The token to be used as a base for authentication.

  • token – The token to be revoked.

  • key – The private key to use to mint the token.

lookup_revoked_tokens(envelope: NucTokenEnvelope) List[RevokedToken][source]

Lookup revoked tokens that would invalidate the given token.

Parameters:

envelope – The token envelope to do lookups for.

exception RequestException(message: str, error_code: str)[source]

Bases: Exception

An exception raised when a request fails.

message: str
error_code: str
exception PaymentValidationException(tx_hash: str, payload: bytes)[source]

Bases: Exception

An exception raised when the validation for a payment fails.

tx_hash: str
payload: bytes
exception CannotRenewSubscription(renewable_at: datetime)[source]

Bases: Exception

An exception raised when a subscription cannot be renewed yet.

renewable_at: datetime