cloudflare / voprf-ts

A TypeScript library for Oblivious Pseudorandom Functions
BSD 3-Clause "New" or "Revised" License
28 stars 12 forks source link

Refactor to avoid use of global #46

Closed sublimator closed 10 months ago

sublimator commented 1 year ago

Consider something like the following (fair amount of work - may not be worth it)

import { Oprf } from '@cloudflare/voprf-ts'
import { CryptoNoble } from '@cloudflare/voprf-ts/crypto-noble';

// Configure OprfNoble with a custom crypto provider
const OprfNoble = Oprf.withConfig({ cryptoProvider: CryptoNoble });
const suite = OprfNoble.makeSuite({mode: Oprf.Mode.OPRF, suite: Oprf.Suite.RISTRETTO255_SHA512});

// Generate a key pair
const { privateKey, publicKey } = suite.generateKeyPair();
// Create server and client instances using the suite's factory methods
const server = suite.makeServer(privateKey);
const client = suite.makeClient(publicKey);

// Do something with the group
const scalar = suite.group.newScalar()

Could do like this:

  1. Draft new interfaces encapsulating desired functionality.
  2. Adjust existing code minimally to comply with new interfaces.
  3. Incorporate new tests validating the updated structures.
  4. Expose the new interfaces while keeping the old ones internal.
  5. Progressively refactor the internal code, ensuring continuous compliance with the new interfaces and passing tests.
armfazh commented 1 year ago

cc: @thibmeu @cdrubin

sublimator commented 1 year ago

see #49, can keep exiting api and expose a minimal facade as well.