Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Basic example of using @cipherstash/protect
# Basic example of using @cipherstash/stack

This basic example demonstrates how to use the `@cipherstash/protect` package to encrypt arbitrary input.
This basic example demonstrates how to use the `@cipherstash/stack` package and the **Encryption SDK** to encrypt and decrypt arbitrary input.

## Installing the basic example

Expand All @@ -16,7 +16,7 @@ git clone https://github.com/cipherstash/protectjs
Install dependencies:

```bash
# Build Project.js
# Build the repo (including @cipherstash/stack)
cd protectjs
pnpm build

Expand All @@ -43,7 +43,7 @@ Lastly, install the CipherStash CLI:
> [!IMPORTANT]
> Make sure you have [installed the CipherStash CLI](#installation) before following these steps.

Set up all the configuration and credentials required for Protect.js:
Set up all the configuration and credentials required for the Encryption SDK:

```bash
stash setup
Expand All @@ -53,8 +53,8 @@ If you have not already signed up for a CipherStash account, this will prompt yo

At the end of `stash setup`, you will have two files in your project:

- `cipherstash.toml` which contains the configuration for Protect.js
- `cipherstash.secret.toml` which contains the credentials for Protect.js
- `cipherstash.toml` which contains the configuration for the Encryption SDK
- `cipherstash.secret.toml` which contains the credentials for the Encryption SDK

> [!WARNING]
> Do not commit `cipherstash.secret.toml` to git, because it contains sensitive credentials.
Expand All @@ -68,8 +68,4 @@ Run the example:
pnpm start
```

The application will log the plaintext to the console that has been encrypted using the CipherStash, decrypted, and logged the original plaintext.

## Next steps

Check out the [Protect.js + Next.js + Clerk example app](../nextjs-clerk) to see how to add end-user identity as an extra control when encrypting data.
The application will prompt for a name, encrypt it with CipherStash, log the ciphertext, decrypt it, and log the original plaintext. It then runs a short bulk-encryption demo.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

"log the original plaintext" describes a guideline violation in index.ts.

The description here is consistent with index.ts Line 44 (console.log('The plaintext is:', plaintext)), which actively logs plaintext. See the index.ts comment for the fix. Once that is resolved, update this line to remove the reference to logging plaintext.

As per coding guidelines: "Do not log plaintext at any time in example apps".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/basic/README.md` at line 71, Remove the prohibited plaintext logging
in the example: in index.ts stop calling console.log('The plaintext is:',
plaintext) (replace with a non-sensitive confirmation or remove entirely) so the
app never prints plaintext, and then update the README sentence that says "log
the original plaintext" to instead describe decrypting or verifying the value
without claiming it is logged; reference the console.log call in index.ts to
locate the code to change and update the README description accordingly.

14 changes: 14 additions & 0 deletions examples/basic/encrypt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dotenv/config'
import {
Encryption,
encryptedTable,
encryptedColumn,
} from '@cipherstash/stack'

export const users = encryptedTable('users', {
name: encryptedColumn('name'),
})

export const client = await Encryption({
schemas: [users],
})
15 changes: 7 additions & 8 deletions examples/basic/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dotenv/config'
import readline from 'node:readline'
import { protectClient, users } from './protect'
import { client, users } from './encrypt'

const rl = readline.createInterface({
input: process.stdin,
Expand All @@ -18,24 +18,24 @@ const askQuestion = (): Promise<string> => {
async function main() {
const input = await askQuestion()

const encryptResult = await protectClient.encrypt(input, {
const encryptResult = await client.encrypt(input, {
column: users.name,
table: users,
})

if (encryptResult.failure) {
throw new Error(`[protect]: ${encryptResult.failure.message}`)
throw new Error(`[encryption]: ${encryptResult.failure.message}`)
}

const ciphertext = encryptResult.data

console.log('Encrypting your name...')
console.log('The ciphertext is:', ciphertext)

const decryptResult = await protectClient.decrypt(ciphertext)
const decryptResult = await client.decrypt(ciphertext)

if (decryptResult.failure) {
throw new Error(`[protect]: ${decryptResult.failure.message}`)
throw new Error(`[encryption]: ${decryptResult.failure.message}`)
}

const plaintext = decryptResult.data
Expand All @@ -50,21 +50,20 @@ async function main() {
{ id: '1', plaintext: 'Alice' },
{ id: '2', plaintext: 'Bob' },
{ id: '3', plaintext: 'Charlie' },
{ id: '4', plaintext: null },
]

console.log(
'Bulk encrypting names:',
bulkPlaintexts.map((p) => p.plaintext),
)

const bulkEncryptResult = await protectClient.bulkEncrypt(bulkPlaintexts, {
const bulkEncryptResult = await client.bulkEncrypt(bulkPlaintexts, {
column: users.name,
table: users,
})

if (bulkEncryptResult.failure) {
throw new Error(`[protect]: ${bulkEncryptResult.failure.message}`)
throw new Error(`[encryption]: ${bulkEncryptResult.failure.message}`)
}

console.log('Bulk encrypted data:', bulkEncryptResult.data)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"@cipherstash/protect": "workspace:*",
"@cipherstash/stack": "workspace:*",
"dotenv": "^16.4.7"
},
"devDependencies": {
Expand Down
17 changes: 0 additions & 17 deletions examples/basic/protect.ts

This file was deleted.

5 changes: 0 additions & 5 deletions examples/drizzle/.env.example

This file was deleted.

Loading