Package: oprfs
Easy-to-deploy oblivious pseudo-random function (OPRF) service that allows other parties (typically participants in some secure multi-party computation protocol) to maintain a persistent mask which they cannot decrypt but which they can safely apply (via requests to the service) to private data values of their choice.PurposeThis library makes it possible to deploy a service that allows other parties to request an encrypted mask (which they cannot decrypt themselves but the service can decrypt) for an obliviouspseudo-random function(OPRF) protocol. Those other parties can then ask the service to apply the mask to their own private, encrypted data values (which the service cannot decrypt). Thanks to the underlyingobliviouslibrary, method implementations rely on cryptographic primitives found within thelibsodiumlibrary.Installation and UsageThis library is available as apackage on PyPI:python -m pip install oprfsThe library can be imported in the usual ways:import oprfs
from oprfs import *Deployment Example: HTTP Server and ClientBelow is in illustration of how an instance of the OPRF service might be deployed usingFlask:import oprfs
import flask
app = flask.Flask(__name__)

# Normally, a persistent key should be retrieved from secure storage.
# Here, a new key is created each time so older masks cannot be reused
# once the service is restarted.
key = oprfs.key()

@app.route('/', methods=['POST'])
def endpoint():
    # Call the handler with the key and request, then return the response.
    return flask.jsonify(oprfs.handler(key, flask.request.get_json()))

app.run()Once an instance of the above service is running, a client might interact with it as illustrated in the example below. Note the use of the distinctoprflibrary to represent a data instance (which is itself a wrapper for anEd25519group element as represented by an instance of thepointclass in theobliviouslibrary):import json
import requests
import oprf

# Request an encrypted mask.
response = requests.post('http://localhost:5000', json={})
mask_encrypted = json.loads(response.text)['mask'][0]

# Mask some data.
data = oprf.data.hash('abc').to_base64()
response = requests.post(
    'http://localhost:5000',
    json={'mask': [mask_encrypted], 'data': [data]}
)
data_masked = oprf.data.from_base64(json.loads(response.text)['data'][0])DevelopmentAll installation and development dependencies are fully specified inpyproject.toml. Theproject.optional-dependenciesobject is used tospecify optional requirementsfor various development tasks. This makes it possible to specify additional options (such asdocs,lint, and so on) when performing installation usingpip:python -m pip install .[docs,lint]DocumentationThe documentation can be generated automatically from the source files usingSphinx:python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make htmlTesting and ConventionsAll unit tests are executed and their coverage is measured when usingpytest(see thepyproject.tomlfile for configuration details):python -m pip install .[test]
python -m pytestAlternatively, all unit tests are included in the module itself and can be executed usingdoctest:python src/oprfs/oprfs.py -vStyle conventions are enforced usingPylint:python -m pip install .[lint]
python -m pylint src/oprfsContributionsIn order to contribute to the source code, open an issue or submit a pull request on theGitHub pagefor this library.VersioningThe version number format for this library and the changes to the library associated with version number increments conform withSemantic Versioning 2.0.0.PublishingThis library can be published as apackage on PyPIby a package maintainer. First, install the dependencies required for packaging and publishing:python -m pip install .[publish]Ensure that the correct version number appears inpyproject.toml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has anautomation rulethat activates and sets as the default all tagged versions. Create and push a tag for this version (replacing?.?.?with the version number):git tag ?.?.?
git push origin ?.?.?Remove any old build/distribution files. Then, package the source into a distribution archive:rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .Finally, upload the package distribution archive toPyPI:python -m twine upload dist/*