Skip to content

Commit 5fe9d30

Browse files
authored
Merge pull request #119 from cipherstash/bulk-models
2 parents 33ac5e5 + 35c4821 commit 5fe9d30

19 files changed

+2656
-1305
lines changed

.changeset/every-dryers-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cipherstash/protect": major
3+
---
4+
5+
Replaced bulk operations with model operations.

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The documentation for Protect.js is organized into the following sections:
1111
## Reference
1212

1313
- [Configuration and production deployment](./reference/configuration.md)
14-
- [Bulk encryption and decryption](./reference/bulk-encryption-decryption.md)
1514
- [Searchable encryption with PostgreSQL](./reference/searchable-encryption-postgres.md)
1615
- [Protect.js schemas](./reference/schema.md)
16+
- [Model operations with bulk crypto functions](./reference/model-operations.md)
1717

1818
## How-to guides
1919

docs/getting-started.md

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ This getting started guide steps you through:
55
1. Installing and configuring Protect.js in a standalone project
66
2. Encrypting, searching, and decrypting data in a PostgreSQL database
77

8-
> [!IMPORTANT]
8+
> [!IMPORTANT]
99
> **Prerequisites:** Before you start you need to have this software installed:
10-
> - [Node.js](https://nodejs.org/)
11-
> - [TypeScript](https://www.typescriptlang.org/)
12-
> - [PostgreSQL](https://www.postgresql.org/) — see PostgreSQL's [documentation for installing](https://www.postgresql.org/download/)
10+
>
11+
> - [Node.js](https://nodejs.org/)
12+
> - [TypeScript](https://www.typescriptlang.org/)
13+
> - [PostgreSQL](https://www.postgresql.org/) — see PostgreSQL's [documentation for installing](https://www.postgresql.org/download/)
1314
1415
### Step 0: Basic file structure
1516

@@ -65,10 +66,10 @@ Lastly, install the CipherStash CLI:
6566
```
6667

6768
- On Linux, download the binary for your platform, and put it on your `PATH`:
68-
- [Linux ARM64](https://github.com/cipherstash/cli-releases/releases/latest/download/stash-aarch64-unknown-linux-gnu)
69-
- [Linux x86_64](https://github.com/cipherstash/cli-releases/releases/latest/download/stash-x86_64-unknown-linux-gnu)
69+
- [Linux ARM64](https://github.com/cipherstash/cli-releases/releases/latest/download/stash-aarch64-unknown-linux-gnu)
70+
- [Linux x86_64](https://github.com/cipherstash/cli-releases/releases/latest/download/stash-x86_64-unknown-linux-gnu)
7071

71-
> [!NOTE]
72+
> [!NOTE]
7273
> **You need to opt out of bundling when using Protect.js.**
7374
>
7475
> Protect.js uses Node.js specific features and requires the use of the [native Node.js `require`](https://nodejs.org/api/modules.html#requireid).
@@ -108,31 +109,31 @@ Protect.js uses a schema to define the tables and columns that you want to encry
108109
To define your tables and columns, add the following to `src/protect/schema.ts`:
109110

110111
```ts
111-
import { csTable, csColumn } from '@cipherstash/protect'
112+
import { csTable, csColumn } from "@cipherstash/protect";
112113

113-
export const users = csTable('users', {
114-
email: csColumn('email'),
115-
})
114+
export const users = csTable("users", {
115+
email: csColumn("email"),
116+
});
116117

117-
export const orders = csTable('orders', {
118-
address: csColumn('address'),
119-
})
118+
export const orders = csTable("orders", {
119+
address: csColumn("address"),
120+
});
120121
```
121122

122123
**Searchable encryption:**
123124

124125
If you want to search encrypted data in your PostgreSQL database, you must declare the indexes in schema in `src/protect/schema.ts`:
125126

126127
```ts
127-
import { csTable, csColumn } from '@cipherstash/protect'
128+
import { csTable, csColumn } from "@cipherstash/protect";
128129

129-
export const users = csTable('users', {
130-
email: csColumn('email').freeTextSearch().equality().orderAndRange(),
131-
})
130+
export const users = csTable("users", {
131+
email: csColumn("email").freeTextSearch().equality().orderAndRange(),
132+
});
132133

133-
export const orders = csTable('orders', {
134-
address: csColumn('address'),
135-
})
134+
export const orders = csTable("orders", {
135+
address: csColumn("address"),
136+
});
136137
```
137138

138139
Read more about [defining your schema](./docs/reference/schema.md).
@@ -142,11 +143,11 @@ Read more about [defining your schema](./docs/reference/schema.md).
142143
To import the `protect` function and initialize a client with your defined schema, add the following to `src/protect/index.ts`:
143144

144145
```ts
145-
import { protect } from '@cipherstash/protect'
146-
import { users, orders } from './schema'
146+
import { protect } from "@cipherstash/protect";
147+
import { users, orders } from "./schema";
147148

148149
// Pass all your tables to the protect function to initialize the client
149-
export const protectClient = await protect(users, orders)
150+
export const protectClient = await protect(users, orders);
150151
```
151152

152153
The `protect` function requires at least one `csTable` to be provided.
@@ -159,21 +160,25 @@ Protect.js provides the `encrypt` function on `protectClient` to encrypt data.
159160
Start encrypting data by adding this to `src/index.ts`:
160161

161162
```typescript
162-
import { users } from './protect/schema'
163-
import { protectClient } from './protect'
163+
import { users } from "./protect/schema";
164+
import { protectClient } from "./protect";
164165

165-
const encryptResult = await protectClient.encrypt('secret@squirrel.example', {
166+
const encryptResult = await protectClient.encrypt("secret@squirrel.example", {
166167
column: users.email,
167168
table: users,
168-
})
169+
});
169170

170171
if (encryptResult.failure) {
171172
// Handle the failure
172-
console.log("error when encrypting:", encryptResult.failure.type, encryptResult.failure.message)
173+
console.log(
174+
"error when encrypting:",
175+
encryptResult.failure.type,
176+
encryptResult.failure.message
177+
);
173178
}
174179

175-
const ciphertext = encryptResult.data
176-
console.log("ciphertext:", ciphertext)
180+
const ciphertext = encryptResult.data;
181+
console.log("ciphertext:", ciphertext);
177182
```
178183

179184
Run this with:
@@ -203,23 +208,23 @@ The `encryptResult` will return one of the following:
203208
```
204209

205210
> [!TIP]
206-
> Get significantly better encryption performance by using the [`bulkEncrypt` function](#bulk-encrypting-data) for large payloads.
211+
> Working with large payloads? Check out the [model operations with bulk cryptography functions](./reference/model-operations.md) docs.
207212
208213
### Step 6: Decrypt data
209214

210215
Use the `decrypt` function to decrypt data.
211216
`decrypt` takes an encrypted data object as a parameter.
212217

213218
```typescript
214-
import { protectClient } from './protect'
219+
import { protectClient } from "./protect";
215220

216-
const decryptResult = await protectClient.decrypt(ciphertext)
221+
const decryptResult = await protectClient.decrypt(ciphertext);
217222

218223
if (decryptResult.failure) {
219224
// Handle the failure
220225
}
221226

222-
const plaintext = decryptResult.data
227+
const plaintext = decryptResult.data;
223228
```
224229

225230
The `decrypt` function returns a `Result` object with either a `data` key, or a `failure` key.
@@ -241,7 +246,7 @@ The `decryptResult` will return one of the following:
241246
```
242247

243248
> [!TIP]
244-
> Get significantly better decryption performance by using the [`bulkDecrypt` function](#bulk-decrypting-data) for large payloads.
249+
> Working with large payloads? Check out the [model operations with bulk cryptography functions](./reference/model-operations.md) docs.
245250
246251
### Step 7: Store encrypted data in a database
247252

docs/reference/bulk-encryption-decryption.md

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)