@@ -5,11 +5,12 @@ This getting started guide steps you through:
551 . Installing and configuring Protect.js in a standalone project
662 . 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
108109To 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
124125If 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
138139Read more about [ defining your schema] ( ./docs/reference/schema.md ) .
@@ -142,11 +143,11 @@ Read more about [defining your schema](./docs/reference/schema.md).
142143To 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
152153The ` 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.
159160Start 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
170171if (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
179184Run 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
210215Use 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
218223if (decryptResult .failure ) {
219224 // Handle the failure
220225}
221226
222- const plaintext = decryptResult .data
227+ const plaintext = decryptResult .data ;
223228```
224229
225230The ` 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
0 commit comments