Comparing version 1.0.0 to 2.0.0
{ | ||
"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" | ||
} | ||
} |
101
README.md
@@ -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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
16
142
18528
7
277
1
- Removedbn.js@^4.11.8
- Removedcoveralls@^3.0.2
- Removedelliptic@^6.4.0
- Removedajv@6.12.6(transitive)
- Removedargparse@1.0.10(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbn.js@4.12.1(transitive)
- Removedbrorand@1.1.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removedcoveralls@3.1.1(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedelliptic@6.6.1(transitive)
- Removedesprima@4.0.1(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhash.js@1.1.7(transitive)
- Removedhmac-drbg@1.0.1(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlcov-parse@1.0.0(transitive)
- Removedlog-driver@1.2.7(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimalistic-assert@1.0.1(transitive)
- Removedminimalistic-crypto-utils@1.0.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)