New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

oprf

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oprf - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

build/oprf.d.ts

75

package.json
{
"name": "oprf",
"version": "1.0.0",
"version": "2.0.0",
"description": "Oblivious pseudo-random function over an elliptic curve (ED25519)",
"main": "dist/oprf.js",
"types": "dist/oprf.d.ts",
"main": "build/oprf.js",
"types": "build/oprf.d.ts",
"directories": {

@@ -11,6 +11,9 @@ "test": "test"

"files": [
"/dist"
"build/**",
"package.json",
"README.md"
],
"scripts": {
"build": "tsc",
"docs": "typedoc --out docs src",
"build-web": "webpack --mode=production",

@@ -20,13 +23,2 @@ "test": "tslint -c tslint.json --project tsconfig.json && nyc mocha --timeout 200000 -r ts-node/register -r source-map-support/register test/oprf.spec.ts",

},
"nyc": {
"extension": [
".ts"
],
"exclude": [
"**/*.d.ts",
"**/*.js",
"**/*.spec.ts",
"src/tools.ts"
]
},
"repository": {

@@ -37,2 +29,19 @@ "type": "git",

"author": "Boston University - Software & Application Innovation Lab",
"contributors": [
{
"name": "Frederick Jansen",
"email": "fjansen@bu.edu",
"url": "https://prettyplease.me/"
},
{
"name": "Lucy Qin",
"email": "lucyq@brown.edu",
"url": "http://lucyq.in/"
},
{
"name": "Kinan Dak Albab",
"email": "babman@bu.edu",
"url": "http://cs-people.bu.edu/babman/"
}
],
"license": "MIT",

@@ -44,28 +53,22 @@ "bugs": {

"dependencies": {
"bn.js": "^4.11.8",
"coveralls": "^3.0.2",
"elliptic": "^6.4.0"
"libsodium-wrappers-sumo": "^0.7.6"
},
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/mocha": "^5.2.3",
"@types/node": "^10.3.6",
"chai": "^4.1.2",
"libsodium-wrappers-sumo": "^0.7.3",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"sinon": "^6.3.5",
"@types/chai": "^4.1.7",
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.1",
"chai": "^4.2.0",
"coveralls": "^3.0.4",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"source-map-support": "^0.5.6",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.0",
"tslint": "^5.10.0",
"typedoc": "^0.13.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"typedoc": "^0.16.9",
"types-bn": "0.0.1",
"typescript": "^2.9.2",
"webpack": "^4.14.0",
"webpack-cli": "^3.0.8"
},
"peerDependencies": {
"libsodium-wrappers-sumo": "^0.7.3"
"typescript": "^3.7.5",
"webpack": "^4.40.2",
"webpack-cli": "^3.3.9"
}
}

@@ -6,13 +6,38 @@ # OPRF

#### Oblivious pseudo-random function over an elliptic curve (ED25519)
#### Oblivious pseudo-random function over an elliptic curve (Ristretto255)
## Installation
```npm install oprf```
For node.js, use:
```bash
npm install oprf
```
For the browser, include a script tag targeting either `dist/oprf.js` or `dist/oprf.slim.js`.
## Bundle vs slim
For browsers, we provide two built files: `dist/oprf.js` and `dist/oprf.slim.js`.
The first includes both OPRF bundled with [libsodium-wrappers-sumo](https://github.com/jedisct1/libsodium.js) version 0.7.6. The second includes only OPRF.
You can use the slim version for cases where your browser-side code uses a more recent version of libsodium, or if you want
to load libsodium asynchronously to reduce page load time.
The API for both versions is identical, except that the slim OPRF constructor expects a sodium instance to be passed in
as a parameter, while the bundled constructor does not expect any parameters.
In node.js, the slim OPRF is not exposed.
```javascript
const OPRF = require('oprf');
const oprf = new OPRF(); // will require('libsodium-wrappers-sumo');
```
## Initialization
The sumo version of libsodium must be used
OPRF is not safe to use until sodium is done loading.
```Typescript
await _sodium.ready;
const oprf = new OPRF(_sodium);
const oprf = new OPRF();
await oprf.ready; // wait for dependencies to load
```

@@ -23,7 +48,4 @@

The implementation uses [Ristretto255](https://libsodium.gitbook.io/doc/advanced/point-arithmetic/ristretto), and does not suffer from small cofactor attacks.
## Dependencies
* [elliptic](https://github.com/indutny/elliptic)
* [libsodium.js](https://github.com/jedisct1/libsodium.js)
## Public Interface

@@ -33,4 +55,4 @@ Contains a masked point and the mask that was applied to it

export interface IMaskedData {
readonly point: number[];
readonly mask: BN; // big number
readonly point: Uint8Array;
readonly mask: Uint8Array;
}

@@ -40,6 +62,13 @@ ```

## Public Functions
**hashToPoint**: maps string input to a point on the elliptic curve
```Typescript
public hashToPoint(input: string): number[]
public hashToPoint(input: string): Uint8Array
```
**isValidPoint**: returns whether the given point exists on the elliptic curve
```Typescript
public isValidPoint(point: Uint8Array): boolean
```
**maskInput**: hashes string input as a point on an elliptic curve and applies a random mask to it

@@ -49,23 +78,33 @@ ```Typescript

```
**generateRandomScalar**: generates a random 32-byte array of numbers
**maskPoint**: applies a random mask to an elliptic curve point
```Typescript
public generateRandomScalar(): BN
public maskPoint(point: Uint8Array): IMaskedData
```
**isValidPoint**: returns whether the given point exists on the elliptic curve
**unmaskInput**: applies the multiplicative inverse of the mask to the masked point
```Typescript
public isValidPoint(point: number[]): number
public unmaskPoint(maskedPoint: Uint8Array, mask: Uint8Array): Uint8Array
```
**encodePoint**: converts an elliptic.js point representation to number array representation
**generateRandomScalar**: generates a uniform random 32-byte number in [1, order of curve)
```Typescript
public encodePoint(point: any): number[]
public generateRandomScalar(): Uint8Array
```
**decodePoint**: converts a number array to elliptic.js point object representation
**scalarMult**: salts a point using a key as a scalar
```Typescript
public decodePoint(point: number[]): any
public scalarMult(point: Uint8Array, key: Uint8Array): Uint8Array
```
**unmaskInput**: applies the multiplicative inverse of the mask to the masked point
**encodePoint**: encodes a point representation to a string with either 'ASCII' or 'UTF-8' encoding
```Typescript
public unmaskInput(maskedPoint: number[], mask: BN): number[]
public encodePoint(point: Uint8Array, encoding: string): string
```
**decodePoint**: Decode elliptic curve point from a string
```Typescript
public decodePoint(code: string, encoding: string): Uint8Array
```
## OPRF Steps

@@ -77,3 +116,5 @@ 1.) **Client**: hash input and mask it using a randomly generated 32-byte number

// Send masked.point to server. Do not send masked.mask to the server since it can easily unmask your original input.
// Send masked.point to server,
// Do not send masked.mask to the server.
send(oprf.encodePoint(masked.point, 'UTF-8'));
```

@@ -83,7 +124,12 @@

```Typescript
// Note: your actual secret key should be a static 32-byte Uint8Array. Do not generate a new scalar for each OPRF unless you have a specific use case for doing so.
const secretKey = oprf.generateRandomScalar();
// Note: your actual secret key should be fixed.
// Do not generate a new scalar for each OPRF
// application unless you have a specific use case for doing so.
const secretKey = oprf.generateRandomScalar();
const maskedPoint = oprf.decodePoint(receive(), 'UTF-8');
const salted = oprf.scalarMult(maskedPoint, secretKey);
// Send salted back to the client
send(oprf.encodePoint(salted, 'UTF-8'));
```

@@ -94,3 +140,4 @@

// Make sure that masked.mask corresponds to the original mask used.
// Otherwise, this will not give you the correct output.
// Otherwise, this will not give you the correct output.
const salted = oprf.decodePoint(receive(), 'UTF-8');
const unmasked = oprf.unmaskInput(salted, masked.mask);

@@ -97,0 +144,0 @@ ```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc