Skip to content

Commit

Permalink
make client publishable
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonstreator committed Jan 21, 2025
1 parent ff2292c commit 52a0ee5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ program

// Check if content is a file
try {
const parsed = JSON.parse(result.value);
const parsed = JSON.parse(result.c);
if (parsed.type === 'file') {
console.log('\nFile detected:');
console.log(chalk.blue('File name:'), parsed.name);
console.log(chalk.yellow('File content (base64):'), parsed.content);
} else {
console.log('\nDecrypted content:');
console.log(result.value);
console.log(result.c);
}
} catch {
// Not JSON, print as regular text
console.log('\nDecrypted content:');
console.log(result.value);
console.log(result.c);
}

if (result.burned) {
Expand Down
52 changes: 52 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @crypt.fyi/core

<a href="https://crypt.fyi" target="_blank">
<img src="https://crypt.fyi/logo-dark.svg" style="width: 100px;" alt="logo" />
</a>

Core library for interacting with the [crypt.fyi](https://crypt.fyi) API. This package provides a secure client implementation for creating, reading, and managing encrypted secrets.

## Features

- 🔒 AES-256-GCM encryption
- 🗜️ Content compression using zlib
- 🔑 Password protection support
- ⏰ Time-to-live (TTL) functionality
- 🌐 Webhook integration
- 🔥 Burn after reading capability

## Installation

```bash
npm install @crypt.fyi/core
```

## Usage

```typescript
import { Client } from '@crypt.fyi/core';

// Initialize the client
const client = new Client({
apiUrl: 'https://api.crypt.fyi',
// Optional: custom key length (default: 32)
keyLength: 32,
});

// Create an encrypted vault
const { id, key } = await client.create({
c: 'my secret content', // Content to encrypt
ttl: 3600, // Time-to-live in seconds
b: true, // Burn after reading
p: 'optional-password', // Optional password protection
});

// Read from an encrypted vault
const { c, burned, cd, ttl } = await client.read(id, key, 'optional-password');

// Check if a vault exists
const exists = await client.exists(id);

// Delete a vault
await client.delete(id, 'deletion-token');
```
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist",
"package.json",
"README.md"
],
"sideEffects": false,
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class Client {
const decompressed = this.decompressContent(decrypted);

return {
value: decompressed,
c: decompressed,
burned: data.b,
cd: data.cd,
ttl: data.ttl,
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/pages/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function ViewPage() {

let content = null;
if (decryptMutation.data) {
const decryptedContent = decryptMutation.data.value;
const decryptedContent = decryptMutation.data.c;
let fileData: { type: 'file'; name: string; content: string } | null = null;

try {
Expand Down Expand Up @@ -150,7 +150,7 @@ export function ViewPage() {
variant="outline"
size="icon"
onClick={() => {
clipboardCopy(decryptMutation.data.value);
clipboardCopy(decryptMutation.data.c);
toast.success(t('view.content.copiedToClipboard'));
}}
title={t('view.content.copyToClipboard')}
Expand Down

0 comments on commit 52a0ee5

Please sign in to comment.