@typinghare/trick
Advanced tools
+7
-11
@@ -11,3 +11,3 @@ import { Command } from 'commander'; | ||
| const program = new Command(); | ||
| program.version('2.1.0'); | ||
| program.version('2.1.2'); | ||
| program.description('Save credential files to remote safely and easily.'); | ||
@@ -117,3 +117,2 @@ program | ||
| const rootDirectory = getRootDirectory(); | ||
| const trickRootDirectory = path.resolve(rootDirectory, config.trickRootDirectory); | ||
| for (const targetName of targetNames) { | ||
@@ -123,4 +122,3 @@ const target = getTargetFromConfig(config, targetName); | ||
| const srcFilePaths = target.files; | ||
| fsExtra.ensureDir(trickRootDirectory); | ||
| encryptFiles(srcFilePaths, trickRootDirectory, passphrase, config.encryption.iterationCount); | ||
| encryptFiles(config, rootDirectory, srcFilePaths, passphrase); | ||
| } | ||
@@ -143,3 +141,2 @@ }); | ||
| const rootDirectory = getRootDirectory(); | ||
| const trickRootDirectory = path.resolve(rootDirectory, config.trickRootDirectory); | ||
| for (const targetName of targetNames) { | ||
@@ -149,4 +146,3 @@ const target = getTargetFromConfig(config, targetName); | ||
| const srcFilePaths = target.files; | ||
| fsExtra.ensureDir(trickRootDirectory); | ||
| decryptFiles(srcFilePaths, trickRootDirectory, passphrase, config.encryption.iterationCount); | ||
| decryptFiles(config, rootDirectory, srcFilePaths, passphrase); | ||
| } | ||
@@ -180,3 +176,3 @@ }); | ||
| .command('list-defaults') | ||
| .description('Display the default target name.') | ||
| .description('Display the default target name.') | ||
| .action(function () { | ||
@@ -211,3 +207,3 @@ updateConfig((config) => { | ||
| fsExtra.ensureDirSync(passphraseDirectory); | ||
| console.log(success(`Created passphrase directory: ${passphraseDirectory}`)); | ||
| console.log(success(`Created passphrase directory: ${colorFilePath(passphraseDirectory)}`)); | ||
| } | ||
@@ -218,7 +214,7 @@ const passphraseFile = path.join(passphraseDirectory, targetName); | ||
| fsExtra.chmodSync(passphraseFile, 0o600); | ||
| console.log(success(`Created passphrase file: ${passphraseFile}`)); | ||
| console.log(success(`Created passphrase file: ${colorFilePath(passphraseFile)}`)); | ||
| console.log(success(`You have to edit the file to set the passphrase.`)); | ||
| } | ||
| else { | ||
| console.log(warning(`Passphrase file already exists: ${passphraseFile}`)); | ||
| console.log(warning(`Passphrase file already exists: ${colorFilePath(passphraseFile)}`)); | ||
| } | ||
@@ -225,0 +221,0 @@ }); |
+2
-0
| export declare function colorTargetName(targetName: string): string; | ||
| export declare function colorFilePath(filePath: string): string; | ||
| export declare function colorSourceFilePath(filePath: string): string; | ||
| export declare function colorTargetFilePath(message: string): string; |
+6
-0
@@ -8,1 +8,7 @@ import chalk from 'chalk'; | ||
| } | ||
| export function colorSourceFilePath(filePath) { | ||
| return chalk.italic.green(filePath); | ||
| } | ||
| export function colorTargetFilePath(message) { | ||
| return chalk.italic.magenta(message); | ||
| } |
@@ -0,1 +1,2 @@ | ||
| import { Config } from './config.js'; | ||
| /** | ||
@@ -39,11 +40,10 @@ * Encrypts a file using OpenSSL with AES-256-CBC and PBKDF2 key derivation. | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of file paths to be encrypted. | ||
| * @param destDir The directory where the encrypted files will be saved. | ||
| * @param passphrase The passphrase used for encryption. | ||
| * @param iterationCount The number of iterations to use for PBKDF2. | ||
| * @returns Resolves when all files are successfully encrypted. | ||
| * @throws {FailToEncryptFileError} If any file fails to encrypt. | ||
| */ | ||
| export declare function encryptFiles(srcFilePaths: string[], destDir: string, passphrase: string, iterationCount: number): Promise<void>; | ||
| /** | ||
| export declare function encryptFiles(config: Config, rootDir: string, srcFilePaths: string[], passphrase: string): Promise<void>; /** | ||
| * Decrypts multiple files using OpenSSL with AES-256-CBC and PBKDF2 key derivation. | ||
@@ -54,9 +54,9 @@ * | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of original file paths that were encrypted. | ||
| * @param destDir The directory containing the encrypted files. | ||
| * @param passphrase The passphrase used for decryption. | ||
| * @param iterationCount The number of iterations used for PBKDF2. | ||
| * @returns Resolves when all files are successfully decrypted. | ||
| * @throws {FailToDecryptFileError} If any file fails to decrypt. | ||
| */ | ||
| export declare function decryptFiles(srcFilePaths: string[], destDir: string, passphrase: string, iterationCount: number): Promise<void>; | ||
| export declare function decryptFiles(config: Config, rootDir: string, srcFilePaths: string[], passphrase: string): Promise<void>; |
+23
-14
@@ -6,2 +6,3 @@ import { execa } from 'execa'; | ||
| import { success } from './console.js'; | ||
| import { colorSourceFilePath, colorTargetFilePath } from './color.js'; | ||
| /** | ||
@@ -110,17 +111,21 @@ * Encrypts a file using OpenSSL with AES-256-CBC and PBKDF2 key derivation. | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of file paths to be encrypted. | ||
| * @param destDir The directory where the encrypted files will be saved. | ||
| * @param passphrase The passphrase used for encryption. | ||
| * @param iterationCount The number of iterations to use for PBKDF2. | ||
| * @returns Resolves when all files are successfully encrypted. | ||
| * @throws {FailToEncryptFileError} If any file fails to encrypt. | ||
| */ | ||
| export async function encryptFiles(srcFilePaths, destDir, passphrase, iterationCount) { | ||
| export async function encryptFiles(config, rootDir, srcFilePaths, passphrase) { | ||
| const iterationCount = config.encryption.iterationCount; | ||
| const trickRootDirectory = config.trickRootDirectory; | ||
| fsExtra.ensureDir(path.join(rootDir, trickRootDirectory)); | ||
| for (const srcFilePath of srcFilePaths) { | ||
| const destFilePath = path.join(destDir, srcFilePath + '.enc'); | ||
| await encryptFile(srcFilePath, destFilePath, passphrase, iterationCount); | ||
| console.log(success(`Encrypted: ${srcFilePath} -> ${destFilePath}`)); | ||
| const destFilePath = path.join(trickRootDirectory, srcFilePath + '.enc'); | ||
| const absoluteDestFilePath = path.join(rootDir, destFilePath); | ||
| const absoluteSrcFilePath = path.resolve(rootDir, srcFilePath); | ||
| await encryptFile(absoluteSrcFilePath, absoluteDestFilePath, passphrase, iterationCount); | ||
| console.log(success(`Encrypted: ${colorSourceFilePath(srcFilePath)} -> ${colorTargetFilePath(destFilePath)}`)); | ||
| } | ||
| } | ||
| /** | ||
| } /** | ||
| * Decrypts multiple files using OpenSSL with AES-256-CBC and PBKDF2 key derivation. | ||
@@ -131,15 +136,19 @@ * | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of original file paths that were encrypted. | ||
| * @param destDir The directory containing the encrypted files. | ||
| * @param passphrase The passphrase used for decryption. | ||
| * @param iterationCount The number of iterations used for PBKDF2. | ||
| * @returns Resolves when all files are successfully decrypted. | ||
| * @throws {FailToDecryptFileError} If any file fails to decrypt. | ||
| */ | ||
| export async function decryptFiles(srcFilePaths, destDir, passphrase, iterationCount) { | ||
| export async function decryptFiles(config, rootDir, srcFilePaths, passphrase) { | ||
| const iterationCount = config.encryption.iterationCount; | ||
| const trickRootDirectory = config.trickRootDirectory; | ||
| for (const srcFilePath of srcFilePaths) { | ||
| const destFilePath = path.join(destDir, srcFilePath + '.enc'); | ||
| await decryptFile(srcFilePath, destFilePath, passphrase, iterationCount); | ||
| console.log(success(`Decrypted: ${destFilePath} -> ${srcFilePath}`)); | ||
| const destFilePath = path.join(trickRootDirectory, srcFilePath + '.enc'); | ||
| const absoluteDestFilePath = path.join(rootDir, destFilePath); | ||
| const absoluteSrcFilePath = path.resolve(rootDir, srcFilePath); | ||
| await decryptFile(absoluteSrcFilePath, absoluteDestFilePath, passphrase, iterationCount); | ||
| console.log(success(`Decrypted: ${colorTargetFilePath(destFilePath)} -> ${colorSourceFilePath(srcFilePath)}`)); | ||
| } | ||
| } |
+6
-5
| { | ||
| "name": "@typinghare/trick", | ||
| "description": "Save credential files to remote safely and easily.", | ||
| "version": "2.1.1", | ||
| "version": "2.1.2", | ||
| "main": "dist/index.js", | ||
@@ -11,2 +11,5 @@ "types": "dist/index.d.ts", | ||
| }, | ||
| "scripts": { | ||
| "build": "node_modules/typescript/bin/tsc" | ||
| }, | ||
| "author": { | ||
@@ -55,5 +58,3 @@ "name": "James Chen", | ||
| }, | ||
| "scripts": { | ||
| "build": "node_modules/typescript/bin/tsc" | ||
| } | ||
| } | ||
| "packageManager": "pnpm@10.27.0" | ||
| } |
+7
-11
@@ -18,3 +18,3 @@ import { Command } from 'commander' | ||
| const program = new Command() | ||
| program.version('2.1.0') | ||
| program.version('2.1.2') | ||
| program.description('Save credential files to remote safely and easily.') | ||
@@ -140,3 +140,2 @@ | ||
| const rootDirectory = getRootDirectory() | ||
| const trickRootDirectory = path.resolve(rootDirectory, config.trickRootDirectory) | ||
| for (const targetName of targetNames) { | ||
@@ -147,4 +146,3 @@ const target: Target = getTargetFromConfig(config, targetName) | ||
| fsExtra.ensureDir(trickRootDirectory) | ||
| encryptFiles(srcFilePaths, trickRootDirectory, passphrase, config.encryption.iterationCount) | ||
| encryptFiles(config, rootDirectory, srcFilePaths, passphrase) | ||
| } | ||
@@ -170,3 +168,2 @@ }) | ||
| const rootDirectory = getRootDirectory() | ||
| const trickRootDirectory = path.resolve(rootDirectory, config.trickRootDirectory) | ||
| for (const targetName of targetNames) { | ||
@@ -177,4 +174,3 @@ const target: Target = getTargetFromConfig(config, targetName) | ||
| fsExtra.ensureDir(trickRootDirectory) | ||
| decryptFiles(srcFilePaths, trickRootDirectory, passphrase, config.encryption.iterationCount) | ||
| decryptFiles(config, rootDirectory, srcFilePaths, passphrase) | ||
| } | ||
@@ -213,3 +209,3 @@ }) | ||
| .command('list-defaults') | ||
| .description('Display the default target name.') | ||
| .description('Display the default target name.') | ||
| .action(function (): void { | ||
@@ -246,3 +242,3 @@ updateConfig((config) => { | ||
| fsExtra.ensureDirSync(passphraseDirectory) | ||
| console.log(success(`Created passphrase directory: ${passphraseDirectory}`)) | ||
| console.log(success(`Created passphrase directory: ${colorFilePath(passphraseDirectory)}`)) | ||
| } | ||
@@ -254,6 +250,6 @@ | ||
| fsExtra.chmodSync(passphraseFile, 0o600) | ||
| console.log(success(`Created passphrase file: ${passphraseFile}`)) | ||
| console.log(success(`Created passphrase file: ${colorFilePath(passphraseFile)}`)) | ||
| console.log(success(`You have to edit the file to set the passphrase.`)) | ||
| } else { | ||
| console.log(warning(`Passphrase file already exists: ${passphraseFile}`)) | ||
| console.log(warning(`Passphrase file already exists: ${colorFilePath(passphraseFile)}`)) | ||
| } | ||
@@ -260,0 +256,0 @@ }) |
+8
-0
@@ -10,1 +10,9 @@ import chalk from 'chalk' | ||
| } | ||
| export function colorSourceFilePath(filePath: string): string { | ||
| return chalk.italic.green(filePath) | ||
| } | ||
| export function colorTargetFilePath(message: string): string { | ||
| return chalk.italic.magenta(message) | ||
| } |
+38
-19
@@ -6,2 +6,4 @@ import { execa } from 'execa' | ||
| import { success } from './console.js' | ||
| import { colorSourceFilePath, colorTargetFilePath } from './color.js' | ||
| import { Config } from './config.js' | ||
@@ -125,6 +127,6 @@ /** | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of file paths to be encrypted. | ||
| * @param destDir The directory where the encrypted files will be saved. | ||
| * @param passphrase The passphrase used for encryption. | ||
| * @param iterationCount The number of iterations to use for PBKDF2. | ||
| * @returns Resolves when all files are successfully encrypted. | ||
@@ -134,15 +136,23 @@ * @throws {FailToEncryptFileError} If any file fails to encrypt. | ||
| export async function encryptFiles( | ||
| config: Config, | ||
| rootDir: string, | ||
| srcFilePaths: string[], | ||
| destDir: string, | ||
| passphrase: string, | ||
| iterationCount: number | ||
| passphrase: string | ||
| ): Promise<void> { | ||
| const iterationCount: number = config.encryption.iterationCount | ||
| const trickRootDirectory: string = config.trickRootDirectory | ||
| fsExtra.ensureDir(path.join(rootDir, trickRootDirectory)) | ||
| for (const srcFilePath of srcFilePaths) { | ||
| const destFilePath: string = path.join(destDir, srcFilePath + '.enc') | ||
| await encryptFile(srcFilePath, destFilePath, passphrase, iterationCount) | ||
| console.log(success(`Encrypted: ${srcFilePath} -> ${destFilePath}`)) | ||
| const destFilePath: string = path.join(trickRootDirectory, srcFilePath + '.enc') | ||
| const absoluteDestFilePath: string = path.join(rootDir, destFilePath) | ||
| const absoluteSrcFilePath: string = path.resolve(rootDir, srcFilePath) | ||
| await encryptFile(absoluteSrcFilePath, absoluteDestFilePath, passphrase, iterationCount) | ||
| console.log( | ||
| success( | ||
| `Encrypted: ${colorSourceFilePath(srcFilePath)} -> ${colorTargetFilePath(destFilePath)}` | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| /** | ||
| } /** | ||
| * Decrypts multiple files using OpenSSL with AES-256-CBC and PBKDF2 key derivation. | ||
@@ -153,6 +163,6 @@ * | ||
| * | ||
| * @param config The configuration object. | ||
| * @param rootDir The root directory where the trick configuration is located. | ||
| * @param srcFilePaths An array of original file paths that were encrypted. | ||
| * @param destDir The directory containing the encrypted files. | ||
| * @param passphrase The passphrase used for decryption. | ||
| * @param iterationCount The number of iterations used for PBKDF2. | ||
| * @returns Resolves when all files are successfully decrypted. | ||
@@ -162,12 +172,21 @@ * @throws {FailToDecryptFileError} If any file fails to decrypt. | ||
| export async function decryptFiles( | ||
| config: Config, | ||
| rootDir: string, | ||
| srcFilePaths: string[], | ||
| destDir: string, | ||
| passphrase: string, | ||
| iterationCount: number | ||
| passphrase: string | ||
| ): Promise<void> { | ||
| const iterationCount: number = config.encryption.iterationCount | ||
| const trickRootDirectory: string = config.trickRootDirectory | ||
| for (const srcFilePath of srcFilePaths) { | ||
| const destFilePath: string = path.join(destDir, srcFilePath + '.enc') | ||
| await decryptFile(srcFilePath, destFilePath, passphrase, iterationCount) | ||
| console.log(success(`Decrypted: ${destFilePath} -> ${srcFilePath}`)) | ||
| const destFilePath: string = path.join(trickRootDirectory, srcFilePath + '.enc') | ||
| const absoluteDestFilePath: string = path.join(rootDir, destFilePath) | ||
| const absoluteSrcFilePath: string = path.resolve(rootDir, srcFilePath) | ||
| await decryptFile(absoluteSrcFilePath, absoluteDestFilePath, passphrase, iterationCount) | ||
| console.log( | ||
| success( | ||
| `Decrypted: ${colorTargetFilePath(destFilePath)} -> ${colorSourceFilePath(srcFilePath)}` | ||
| ) | ||
| ) | ||
| } | ||
| } |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
68258
2.4%1694
1.99%9
-10%