Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing version v1.0.0 #57

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 20, 18 ]
node: [ 22, 20 ]
crypto_arg_required: [ true, false ]
steps:
- name: Checking out
Expand Down
53 changes: 32 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![NPM](https://nodei.co/npm/@cloudflare/voprf-ts.png)](https://www.npmjs.com/package/@cloudflare/voprf-ts)

# voprf-ts: A TypeScript Library for Oblivious Pseudorandom Functions (OPRF).
# voprf-ts: A TypeScript Library for Oblivious Pseudorandom Functions (OPRF)

An **Oblivious Pseudorandom Function (OPRF)** is a two-party protocol between a client and server for computing the output of a Pseudorandom Function (PRF).

Expand All @@ -13,26 +13,37 @@ A **verifiable OPRF (VOPRF)** ensures clients can verify that the server used a

A **partially-oblivious (POPRF)** extends a VOPRF allowing the client and server to provide public shared input to the PRF computation.

|Specification: [RFC 9497](https://doi.org/10.17487/RFC9497)|
|--|

This library supports all three modes:

```js
Oprf.Mode.OPRF
Oprf.Mode.VOPRF
Oprf.Mode.POPRF
```
and supports three suites corresponding to the underlying group and hash used:

and supports the following suites corresponding to the underlying group and hash used:

```js
Oprf.Suite.P256_SHA256
Oprf.Suite.P384_SHA384
Oprf.Suite.P521_SHA512
```

**Specification:** Compliant with IETF [draft-irtf-cfrg-voprf](https://datatracker.ietf.org/doc/draft-irtf-cfrg-voprf/) and tests vectors match with [v21](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-voprf-21).
Additional suites are also supported when using the [@noble/curves](https://www.npmjs.com/package/@noble/curves) library as the `CryptoProvider`. See [examples/facade/index.ts](examples/facade/index.ts) to setup this `CryptoProvider`.

```js
Oprf.Suite.RISTRETTO255_SHA512
Oprf.Suite.DECAF448_SHAKE256
```

### Usage
## Usage

#### Step 1
### Step 1

First set up a client and a server. In this case, we use the VOPRF mode with suite P384-SHA384.
First set up a client and a server. In this example, we use the VOPRF mode with suite P384-SHA384.

```js
import {
Expand All @@ -47,37 +58,33 @@ const server = new VOPRFServer(suite, privateKey);
const client = new VOPRFClient(suite, publicKey);
```

#### Step 2
### Step 2

The client prepares arbitrary input[s] that will be batch evaluated by the server. The blinding method produces an evaluation request, and some finalization data to be used later. Then, the client sends the evaluation request to the server.
The client prepares arbitrary input(s) that will be batch evaluated by the server. The blinding method produces an evaluation request, and some finalization data to be used later. Then, the client sends the evaluation request to the server.

```js
const input = new TextEncoder().encode("This is the client's input");
const input = new TextEncoder().encode('This is the client's input');
const batch = [input]
const [finData, evalReq] = await client.blind(batch);
```

#### Step 3
### Step 3

Once the server received the evaluation request, it responds to the client with an evaluation.

```js
const evaluation = await server.blindEvaluate(evalReq);
```

#### Step 4
### Step 4

Finally, the client can produce the output[s] of the OPRF protocol using the server's evaluation and the finalization data from the second step. If the mode is verifiable, this step allows the client to check the proof that the server used the expected private key for the evaluation.
Finally, the client can produce the output(s) of the OPRF protocol using the server's evaluation and the finalization data from the second step. If the mode is verifiable, this step also checks the proof that the server used the expected private key for the evaluation.

```js
// Get output matching first input of batch
const [output] = await client.finalize(finData, evaluation);
```

### Facade API

See [examples](examples/facade/index.ts)

### Development

| Task | NPM scripts |
Expand All @@ -90,14 +97,18 @@ See [examples](examples/facade/index.ts)
| Code Linting | `$ npm run lint` |
| Code Formatting | `$ npm run format` |

## Security Disclaimer

**Dependencies**
🚨 This library is offered as-is, and without a guarantee. Therefore, it is expected that changes in the code, repository, and API occur in the future. We recommend to take caution before using this library in a production application since part of its content is experimental. All security issues must be reported, please notify us immediately following the instructions given in our [Security Policy](https://github.com/cloudflare/voprf-ts/security/policy).

This project uses the Stanford Javascript Crypto Library [sjcl](https://github.com/bitwiseshiftleft/sjcl). Support for elliptic curves must be enabled by this compilation step, which produces the necessary files inside the [src/sjcl](./src/sjcl) folder.
### Cryptography Providers

```sh
$ make -f sjcl.Makefile
```
Although this library relies on the standard [Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) for high-level operations, prime field and elliptic curve operations are not covered by the standard API. For this reason, this library can be configured to use one of the following providers:

* The Stanford JavaScript Crypto Library [sjcl](https://github.com/bitwiseshiftleft/sjcl).
* The [@noble/curves](https://www.npmjs.com/package/@noble/curves) library.

⚠️ **Note:** Running operations in constant time is a basic requirement to prevent against timing attacks. However in JavaScript, constant-time execution is not guaranteed. These providers have made different choices towards addressing this goal.

### License

Expand Down
4 changes: 1 addition & 3 deletions mockCrypto/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "../tsconfig.cjs.json",
"include": [
"."
]
"include": ["."]
}
6 changes: 2 additions & 4 deletions mockCrypto/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "../tsconfig.json",
"include": [
"."
]
}
"include": ["."]
}
68 changes: 34 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflare/voprf-ts",
"version": "0.21.2",
"version": "1.0.0",
"description": "voprf-ts: A TypeScript Library for Oblivious Pseudorandom Functions (OPRF)",
"author": "Armando Faz <[email protected]>",
"maintainers": [
Expand Down Expand Up @@ -45,26 +45,26 @@
"homepage": "https://github.com/cloudflare/voprf-ts#readme",
"repository": "github:cloudflare/voprf-ts",
"engines": {
"node": ">=18"
"node": ">=20"
},
"devDependencies": {
"@eslint/js": "9.6.0",
"@noble/curves": "1.4.2",
"@eslint/js": "9.8.0",
"@noble/curves": "1.5.0",
"@noble/hashes": "1.4.0",
"@types/benchmark": "2.1.5",
"@types/eslint__js": "8.42.3",
"@types/jest": "29.5.12",
"benchmark": "2.1.4",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "28.6.0",
"eslint-plugin-jest": "28.8.0",
"eslint-plugin-jest-formatting": "3.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-security": "3.0.1",
"jest": "29.7.0",
"prettier": "3.3.2",
"prettier": "3.3.3",
"sjcl": "1.0.8",
"typescript": "5.5.3",
"typescript": "5.5.4",
"typescript-eslint": "7.15.0"
},
"scripts": {
Expand All @@ -85,7 +85,7 @@
"format:json": "prettier './**/*.json' '!./node_modules/**' '!./package-lock.json' '!./test/testdata/allVectors_v20.json' --write"
},
"optionalDependencies": {
"@noble/curves": "1.4.2",
"@noble/curves": "1.5.0",
"@noble/hashes": "1.4.0"
}
}
4 changes: 1 addition & 3 deletions src/sjcl/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": ["../../tsconfig.json", "./tsconfig.compilerOptions.json"],
"files": [
"index.js"
]
"files": ["index.js"]
}
5 changes: 1 addition & 4 deletions src/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "../tsconfig.cjs.json",
"include": [
"."
]

"include": ["."]
}
4 changes: 1 addition & 3 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "../tsconfig.json",
"include": [
"."
]
"include": ["."]
}
5 changes: 1 addition & 4 deletions test/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extends": "../tsconfig.cjs.json",
"include": [
".",
"testdata/*.json"
],
"include": [".", "testdata/*.json"],
"compilerOptions": {
"resolveJsonModule": true
},
Expand Down
Loading
Loading