Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.
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
Binary file modified .docs/figure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ npm i image-shield
import ImageShield from "image-shield";
```

### 🔀 Shuffle Mode

**Fragment**
**Shuffle**

```ts
await ImageShield.encrypt({
await ImageShield.shuffle({
// config: { /** FragmentationConfig */ },
imagePaths: [
"./input_1.png",
Expand Down Expand Up @@ -81,7 +79,7 @@ output
**Restore**

```ts
await ImageShield.decrypt({
await ImageShield.restore({
manifestPath: "./output/fragmented/manifest.json",
imagePaths: [
"./output/fragmented/img_1_fragmented.png",
Expand Down Expand Up @@ -191,5 +189,5 @@ manifest.json:

## Clients

- [Raycast Extension](https://github.com/tuki0918/raycast-image-shield)
- [Raycast Extension (legacy)](https://github.com/tuki0918/raycast-image-shield)

36 changes: 18 additions & 18 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install @image-shield/cli

## Usage

The CLI provides two main commands: `encrypt` and `decrypt`.
The CLI provides two main commands: `shuffle` and `restore`.

### Global Help

Expand All @@ -28,17 +28,17 @@ Options:
-h, --help display help for command

Commands:
encrypt [options] <images...> Fragment images
decrypt [options] <fragments...> Restore fragmented images
shuffle [options] <images...> Fragment images
restore [options] <fragments...> Restore fragmented images
help [command] display help for command
```

### Encrypt Command
### Shuffle Command

Fragment images into multiple pieces.

```bash
image-shield encrypt <images...> -o <output_directory> [options]
image-shield shuffle <images...> -o <output_directory> [options]
```

#### Options
Expand All @@ -55,17 +55,17 @@ image-shield encrypt <images...> -o <output_directory> [options]

**Basic fragmentation:**
```bash
image-shield encrypt image1.jpg image2.png -o ./fragments
image-shield shuffle image1.jpg image2.png -o ./fragments
```

**Custom configuration:**
```bash
image-shield encrypt *.jpg -o ./output -b 20 -p "my_fragment" --restore-filename
image-shield shuffle *.jpg -o ./output -b 20 -p "my_fragment" --restore-filename
```

**With seed for reproducible results:**
```bash
image-shield encrypt image.png -o ./output -s 12345
image-shield shuffle image.png -o ./output -s 12345
```

#### Output Structure
Expand All @@ -79,12 +79,12 @@ output/
└── ...
```

### Decrypt Command
### Restore Command

Restore fragmented images using the manifest file.

```bash
image-shield decrypt <fragments...> -m <manifest_path> -o <output_directory> [options]
image-shield restore <fragments...> -m <manifest_path> -o <output_directory> [options]
```

#### Options
Expand All @@ -98,12 +98,12 @@ image-shield decrypt <fragments...> -m <manifest_path> -o <output_directory> [op

**Basic restoration:**
```bash
image-shield decrypt ./fragments/*.png -m ./fragments/manifest.json -o ./restored
image-shield restore ./fragments/*.png -m ./fragments/manifest.json -o ./restored
```

**Specific fragments:**
```bash
image-shield decrypt fragment_0000.png fragment_0001.png fragment_0002.png -m manifest.json -o ./output
image-shield restore fragment_0000.png fragment_0001.png fragment_0002.png -m manifest.json -o ./output
```

## Error Handling
Expand All @@ -127,7 +127,7 @@ The CLI provides clear error messages for common issues:

2. **Fragment images:**
```bash
image-shield encrypt images/photo1.jpg images/photo2.png -o ./backup --restore-filename
image-shield shuffle images/photo1.jpg images/photo2.png -o ./backup --restore-filename
```
```
🔀 Starting image fragmentation...
Expand All @@ -142,7 +142,7 @@ The CLI provides clear error messages for common issues:

4. **Restore images:**
```bash
image-shield decrypt backup/*.png -m backup/manifest.json -o ./restored
image-shield restore backup/*.png -m backup/manifest.json -o ./restored
```
```
🔀 Starting image restoration...
Expand All @@ -161,7 +161,7 @@ For custom fragmentation:

```bash
# Fragment with custom settings
image-shield encrypt sensitive/*.jpg \
image-shield shuffle sensitive/*.jpg \
-o ./vault \
-b 5 \
-p "secure_chunk" \
Expand All @@ -184,7 +184,7 @@ BACKUP_DIR="./backup"

# Create backup
echo "Creating backup..."
image-shield encrypt "$IMAGES_DIR"/*.{jpg,png} \
image-shield shuffle "$IMAGES_DIR"/*.{jpg,png} \
-o "$BACKUP_DIR" \
--restore-filename

Expand All @@ -208,7 +208,7 @@ RESTORE_DIR="./recovered_photos"

# Restore from backup
echo "Restoring from backup..."
image-shield decrypt "$BACKUP_DIR"/fragment_*.png \
image-shield restore "$BACKUP_DIR"/fragment_*.png \
-m "$BACKUP_DIR/manifest.json" \
-o "$RESTORE_DIR"

Expand Down Expand Up @@ -244,7 +244,7 @@ npm test

```bash
cd packages/cli
npm run dev -- encrypt --help
npm run dev -- shuffle --help
```

## Related Packages
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import { Command } from "commander";
import { registerDecryptCommand } from "./commands/decrypt";
import { registerEncryptCommand } from "./commands/encrypt";
import { registerRestoreCommand } from "./commands/restore";
import { registerShuffleCommand } from "./commands/shuffle";

const program = new Command();

Expand All @@ -12,8 +12,8 @@ program
.version("0.8.1");

// Register commands
registerEncryptCommand(program);
registerDecryptCommand(program);
registerShuffleCommand(program);
registerRestoreCommand(program);

// Error handling
program.on("command:*", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import ImageShield from "@image-shield/node";
import type { Command } from "commander";
import type { DecryptOptions } from "../types";
import type { RestoreOptions } from "../types";
import {
validateImagePaths,
validateManifestPath,
validateOutputDirectory,
} from "../validators";

/**
* Configures and registers the decrypt command
* Configures and registers the restore command
* @param program Commander program instance
*/
export function registerDecryptCommand(program: Command): void {
export function registerRestoreCommand(program: Command): void {
program
.command("decrypt")
.command("restore")
.description("Restore fragmented images")
.argument("<fragments...>", "Fragment file paths")
.requiredOption("-m, --manifest <path>", "Manifest file path")
.requiredOption("-o, --output <dir>", "Output directory")
.action(handleDecryptCommand);
.action(handleRestoreCommand);
}

/**
* Handles the decrypt command execution
* Handles the restore command execution
* @param fragments Array of fragment file paths
* @param options Command options
*/
async function handleDecryptCommand(
async function handleRestoreCommand(
fragments: string[],
options: DecryptOptions,
options: RestoreOptions,
): Promise<void> {
try {
console.log("🔀 Starting image restoration...");
Expand All @@ -37,7 +37,7 @@ async function handleDecryptCommand(
const manifestPath = validateManifestPath(options.manifest);
const outputDir = validateOutputDirectory(options.output);

await ImageShield.decrypt({
await ImageShield.restore({
imagePaths,
manifestPath,
outputDir,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { FragmentationConfig } from "@image-shield/core";
import ImageShield from "@image-shield/node";
import type { Command } from "commander";
import type { EncryptOptions } from "../types";
import type { ShuffleOptions } from "../types";
import { validateImagePaths, validateOutputDirectory } from "../validators";

/**
* Configures and registers the encrypt command
* Configures and registers the shuffle command
* @param program Commander program instance
*/
export function registerEncryptCommand(program: Command): void {
export function registerShuffleCommand(program: Command): void {
program
.command("encrypt")
.command("shuffle")
.description("Fragment images")
.argument("<images...>", "Input image file paths")
.requiredOption("-o, --output <dir>", "Output directory")
Expand All @@ -30,17 +30,17 @@ export function registerEncryptCommand(program: Command): void {
return num;
})
.option("--restore-filename", "Restore original file names")
.action(handleEncryptCommand);
.action(handleShuffleCommand);
}

/**
* Handles the encrypt command execution
* Handles the shuffle command execution
* @param images Array of image file paths
* @param options Command options
*/
async function handleEncryptCommand(
async function handleShuffleCommand(
images: string[],
options: EncryptOptions,
options: ShuffleOptions,
): Promise<void> {
try {
console.log("🔀 Starting image fragmentation...");
Expand All @@ -54,7 +54,7 @@ async function handleEncryptCommand(
if (options.seed !== undefined) config.seed = options.seed;
if (options.restoreFilename) config.restoreFileName = true;

await ImageShield.encrypt({
await ImageShield.shuffle({
imagePaths,
outputDir,
config: Object.keys(config).length > 0 ? config : undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Export CLI functionality for programmatic usage if needed
export { default as ImageShield } from "@image-shield/node";
export type { FragmentationConfig } from "@image-shield/core";
export type { EncryptOptions, DecryptOptions } from "./types";
export type { RestoreOptions, ShuffleOptions } from "./types";
4 changes: 2 additions & 2 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface EncryptOptions {
export interface ShuffleOptions {
output: string;
blockSize?: number;
prefix?: string;
seed?: number;
restoreFilename?: boolean;
}

export interface DecryptOptions {
export interface RestoreOptions {
manifest: string;
output: string;
}
4 changes: 2 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface EncryptOptions {
export interface ShuffleOptions {
/** Image paths (e.g., ["image1.png", "image2.png"]) */
imagePaths: string[];
/** Fragmentation config */
Expand All @@ -7,7 +7,7 @@ export interface EncryptOptions {
outputDir: string;
}

export interface DecryptOptions {
export interface RestoreOptions {
/** Image paths (e.g., ["fragment1.png", "fragment2.png"]) */
imagePaths: string[];
/** Manifest path (e.g., "./output/fragments/manifest.json") */
Expand Down
16 changes: 8 additions & 8 deletions packages/node/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe("ImageShield (integration)", () => {
await image.write(filePath, JimpMime.png);
imagePaths.push(filePath);
}
// Fragment images using ImageShield.encrypt
await ImageShield.encrypt({
// Fragment images using ImageShield.shuffle
await ImageShield.shuffle({
imagePaths,
config: { blockSize, prefix },
outputDir: tmpDir,
Expand All @@ -65,8 +65,8 @@ describe("ImageShield (integration)", () => {
path.join(tmpDir, generateFragmentFileName(manifestDataForFragment, i)),
);
}
// Restore images using ImageShield.decrypt
await ImageShield.decrypt({
// Restore images using ImageShield.restore
await ImageShield.restore({
imagePaths: fragmentPaths,
manifestPath,
outputDir: tmpDir,
Expand Down Expand Up @@ -168,8 +168,8 @@ describe("ImageShield (restoreFileName integration)", () => {
await image.write(filePath, JimpMime.png);
imagePaths.push(filePath);
}
// Fragment images using ImageShield.encrypt (with restoreFileName)
await ImageShield.encrypt({
// Fragment images using ImageShield.shuffle (with restoreFileName)
await ImageShield.shuffle({
imagePaths,
config: { blockSize, prefix, restoreFileName: true },
outputDir: tmpDir,
Expand All @@ -188,8 +188,8 @@ describe("ImageShield (restoreFileName integration)", () => {
path.join(tmpDir, generateFragmentFileName(manifest, i)),
);
}
// Restore images using ImageShield.decrypt
await ImageShield.decrypt({
// Restore images using ImageShield.restore
await ImageShield.restore({
imagePaths: fragmentPaths,
manifestPath,
outputDir: tmpDir,
Expand Down
Loading
Loading