oneid.nonces

Helpful utility functions

oneid.nonces.make_nonce(expiry=None)[source]

Create a nonce with expiration timestamp included

Parameters:expiry – a datetime that indicates when the nonce self-expires, defaults to now + 30 minutes
Returns:nonce
oneid.nonces.set_nonce_handlers(nonce_verifier, nonce_burner)[source]

Sets the functions to verify nonces and record their use.

By default, the nonces are saved in a local file named ~/.oneid/used_nonces.txt (or equivalent)

Parameters:
  • nonce_burner – function to be called to verify. Passed one argument, the nonce
  • nonce_verifier – function to be called to burn. Passed one argument, the nonce
oneid.nonces.verify_nonce(nonce, expiry=None)[source]

Ensure that the nonce is correct, and not from the future

Callers should also store used nonces and reject messages with previously-used ones.

Parameters:
  • nonce – Nonce as created with make_nonce()
  • expiry – If not None, a datetime before which the nonce is not valid
Returns:

True only if nonce meets validation criteria

Return type:

bool