Skip to content

Commit 20e5900

Browse files
authored
Add local server (#12)
* Add local server * Fix node-local example * Fix build
1 parent 7c51219 commit 20e5900

39 files changed

+4455
-68
lines changed

.github/workflows/build-js.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
- name: Run tests
3636
run: |
3737
npm test
38+
39+
- name: Run end-to-end tests
40+
run: |
41+
npm run e2e-tests
3842
3943
- name: Upload single-file bundle
4044
uses: actions/upload-artifact@v3

README.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,35 @@
3030
</a>
3131
</h4>
3232

33+
The [Blyss SDK](https://blyss.dev) lets you use homomorphic encryption to [retrieve information privately](https://blintzbase.com/posts/pir-and-fhe-from-scratch/). With it, you can build new kinds of privacy-preserving services, like [private password breach checking](https://playground.blyss.dev/passwords/), [private nameserver resolution](https://sprl.it/), and even [private Wikipedia](https://spiralwiki.com/).
3334

34-
The [Blyss SDK](https://blyss.dev) lets you use homomorphic encryption to make private retrievals from Blyss buckets. This can enable new privacy-preserving apps, like [private nameserver resolution](https://sprl.it/), [private wallets](https://btc.blyss.dev/), and even [private Wikipedia](https://spiralwiki.com/).
35-
36-
Get an API key by [signing up](https://blyss.dev). Detailed documentation is at [docs.blyss.dev](https://docs.blyss.dev).
35+
You can get an API key by [signing up](https://blyss.dev), or run a server locally. Detailed documentation is at [docs.blyss.dev](https://docs.blyss.dev).
3736

3837
> **Warning**
39-
> The SDK has not yet been audited or reviewed, and the public Blyss service is still in beta. Data stored in Blyss should not be considered durable. [Contact us](mailto:[email protected]) for access to a production-ready service.
40-
41-
> _Looking for Spiral?_
42-
> Our new name is Blyss. The core Rust cryptographic library that this repo started as is now in `lib/spiral-rs`.
38+
> The SDK has not yet been security reviewed, and the public Blyss service is still in beta. [Contact us](mailto:[email protected]) for access to a production-ready service.
4339
44-
## Quick start
40+
## Quick start (cloud)
4541

46-
You can quickly try using the SDK without downloading anything. The example code shows how to use Blyss buckets to perform private contact intersection.
42+
You can quickly try using the SDK with our managed service without downloading anything.
4743

48-
1. Get an API key by [signing up](https://blyss.dev).
49-
2. Open [this CodeSandbox](https://codesandbox.io/s/blyss-contact-intersection-example-7qr6r5) and enter your API key where it says `<YOUR API KEY HERE>`. This lets you try using the SDK in your browser.
44+
1. Get an API key by [signing up here](https://blyss.dev).
45+
2. Open [this StackBlitz](https://stackblitz.com/edit/blyss-private-contact-intersection) and enter your API key where it says `<YOUR API KEY HERE>`.
5046
3. Try adding users to the service using the "Add a user" button. As you add more users, the service will _privately_ intersect each new users's contacts and the already existing users.
5147
Every user's list of contacts stays completely private using homomorphic encryption: it never leaves their device unencrypted.
5248

53-
If you prefer a simpler example using vanilla JS, check out [this CodePen](https://codepen.io/blyssprivacy/pen/qByMJwr?editors=0010&layout=left).
49+
We also have [a simpler example using vanilla JS](https://codepen.io/blyssprivacy/pen/qByMJwr?editors=0010&layout=left).
50+
51+
## Quick start (local)
52+
53+
You can also use the Blyss SDK completely locally.
54+
55+
1. Clone this repo with `git clone [email protected]:blyssprivacy/sdk.git`.
56+
2. Run the server by entering `lib/server` and running `cargo run --release`. The server will run on `localhost:8008` by default.
57+
3. Run the client by entering `examples/node-local` and running `npx ts-node main.ts`. This will perform some writes and then a private read to your bucket.
58+
59+
## Installing as a package
60+
61+
To use the Blyss SDK in an existing TypeScript project, install it with `npm install @blyss/sdk`. Then, import the client with `import { Client } from '@blyss/sdk';`. If you're using SDK in Node, and prefer not to use ESM, you can instead import it as `const blyss = require('@blyss/sdk/node')`.
5462

5563
## Examples
5664

@@ -74,25 +82,15 @@ The React example shows how to use the Blyss SDK in modern client-side JS. It al
7482

7583
### Node
7684

77-
The Node.js example shows how to use the Blyss SDK in server-side JS. Node 19+ and ESM support is required.
85+
The Node.js example shows how to use the Blyss SDK in server-side JS. Node 18+ is required.
7886

7987
1. Enter `examples/node`, and run `npm install`.
8088
2. Edit `main.ts` to use your API key.
8189
3. Run `ts-node main.ts`.
8290

8391
### Python
8492

85-
The Blyss SDK for Python is still in development. To build the Python library:
86-
87-
1. Enter `python/` and run `python -m venv .env` (on macOS, use `python3 -m venv .env`)
88-
2. Run `source .env/bin/activate`
89-
3. Run `pip install maturin`
90-
4. Run `maturin develop`
91-
92-
This will install the SDK locally as `blyss`. You can now import `blyss` in scripts you run from this virtual environment. To run the Python example:
93-
94-
1. Enter `examples/python`
95-
2. Run `python main.py`
93+
The Blyss SDK for Python is still in development.
9694

9795
## Documentation
9896

@@ -110,13 +108,16 @@ Steps to building the SDK:
110108
2. Run `npm install`.
111109
3. Run `npm run build`.
112110

113-
This will completely build the SDK, including the core Rust library in `lib/spiral-rs`.
111+
This will build the complete SDK, including the core Rust libraries in `lib/spiral-rs` and `lib/doublepir`
114112

115113
The SDK is structured as:
116114

117-
1. `lib/spiral-rs/`, a Rust crate containing the core cryptographic implementation of the [Spiral PIR scheme](https://eprint.iacr.org/2022/368.pdf).
115+
1. `lib/`,
116+
- `lib/server/`, a Rust project containing the open-source Blyss server.
117+
- `lib/spiral-rs/`, a Rust crate containing the core cryptographic implementation of the [Spiral PIR scheme](https://eprint.iacr.org/2022/368).
118+
- `lib/doublepir/`, a Rust crate containing the core cryptographic implementation of the [DoublePIR scheme](https://eprint.iacr.org/2022/949).
118119
2. `js/`, the TypeScript code that implements the user-facing Blyss SDK.
119-
- `js/bridge/`, a Rust "bridge" crate that exposes key functionality from `spiral-rs` to the TypeScript code.
120+
- `js/bridge/`, a Rust "bridge" crate that exposes key functionality from `spiral-rs` and `doublepir` to the TypeScript code.
120121
3. `python/`, the Python version of the SDK (still in development)
121122
- `python/src/lib.rs`, another Rust "bridge" crate that exposes key functionality from `spiral-rs` to the Python code.
122123

e2e-tests/.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": [
4+
"@typescript-eslint",
5+
"prettier"
6+
],
7+
"extends": [
8+
"eslint:recommended",
9+
"prettier"
10+
],
11+
"rules": {
12+
"no-console": 0,
13+
"prettier/prettier": 1,
14+
"@typescript-eslint/no-explicit-any": 0,
15+
"no-empty-function": 0,
16+
"@typescript-eslint/no-empty-function": 0,
17+
"@typescript-eslint/no-var-requires": 0
18+
},
19+
"env": {
20+
"node": true
21+
}
22+
}

e2e-tests/main.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ChildProcess } from 'child_process';
2+
3+
const simple = require('./tests/simple').default;
4+
const { spawn } = require('child_process');
5+
6+
process.removeAllListeners('warning');
7+
8+
function spawnChildProcess(): Promise<ChildProcess> {
9+
let seen = '';
10+
return new Promise(resolve => {
11+
const child = spawn(process.argv[2]);
12+
process.on('exit', function () {
13+
child.kill();
14+
});
15+
child.stdout.on('data', chunk => {
16+
seen += chunk;
17+
if (seen.includes('Listening')) {
18+
resolve(child);
19+
}
20+
});
21+
});
22+
}
23+
24+
async function main() {
25+
const child = await spawnChildProcess();
26+
27+
await simple();
28+
29+
console.log('Tests completed successfully.');
30+
31+
child.kill();
32+
}
33+
34+
main();

e2e-tests/package-lock.json

Lines changed: 208 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e-tests/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"dependencies": {
3+
"@blyss/sdk": "latest"
4+
},
5+
"devDependencies": {
6+
"ts-node": "^10.9.1",
7+
"typescript": "^4.9.4"
8+
}
9+
}

0 commit comments

Comments
 (0)