@kryklin/darkstar-crypt-node 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/darkstar_crypt.js +51 -1
- package/package.json +1 -1
package/darkstar_crypt.js
CHANGED
|
@@ -233,7 +233,7 @@ export class DarkstarCrypt {
|
|
|
233
233
|
const saltHex = this.buf2hex(salt);
|
|
234
234
|
const ivHex = this.buf2hex(iv);
|
|
235
235
|
const ciphertextBase64 = this.buf2base64(encrypted);
|
|
236
|
-
|
|
236
|
+
|
|
237
237
|
return saltHex + ivHex + ciphertextBase64;
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -557,3 +557,53 @@ export class DarkstarCrypt {
|
|
|
557
557
|
};
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
|
+
|
|
561
|
+
// --- CLI Support ---
|
|
562
|
+
|
|
563
|
+
import { fileURLToPath } from 'node:url';
|
|
564
|
+
import { resolve } from 'node:path';
|
|
565
|
+
|
|
566
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
567
|
+
const isMain = process.argv[1] && resolve(process.argv[1]) === resolve(__filename);
|
|
568
|
+
|
|
569
|
+
if (isMain) {
|
|
570
|
+
const args = process.argv.slice(2);
|
|
571
|
+
const command = args[0];
|
|
572
|
+
const crypt = new DarkstarCrypt();
|
|
573
|
+
|
|
574
|
+
if (command === 'encrypt') {
|
|
575
|
+
const mnemonic = args[1];
|
|
576
|
+
const password = args[2];
|
|
577
|
+
crypt.encrypt(mnemonic, password).then(res => {
|
|
578
|
+
console.log(JSON.stringify(res));
|
|
579
|
+
}).catch(err => {
|
|
580
|
+
console.error(err);
|
|
581
|
+
process.exit(1);
|
|
582
|
+
});
|
|
583
|
+
} else if (command === 'decrypt') {
|
|
584
|
+
const data = args[1];
|
|
585
|
+
const rk = args[2];
|
|
586
|
+
const password = args[3];
|
|
587
|
+
crypt.decrypt(data, rk, password).then(res => {
|
|
588
|
+
console.log(res);
|
|
589
|
+
}).catch(err => {
|
|
590
|
+
console.error(err);
|
|
591
|
+
process.exit(1);
|
|
592
|
+
});
|
|
593
|
+
} else if (command === 'test') {
|
|
594
|
+
const mnemonic = "cat dog fish bird";
|
|
595
|
+
const password = "MySecre!Password123";
|
|
596
|
+
crypt.encrypt(mnemonic, password).then(res => {
|
|
597
|
+
return crypt.decrypt(res.encryptedData, res.reverseKey, password);
|
|
598
|
+
}).then(decrypted => {
|
|
599
|
+
if (decrypted === "cat dog fish bird") {
|
|
600
|
+
console.log("Test Passed!");
|
|
601
|
+
} else {
|
|
602
|
+
console.error("Test Failed!");
|
|
603
|
+
process.exit(1);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
} else {
|
|
607
|
+
console.log("Usage: node darkstar_crypt.js <encrypt|decrypt|test> ...");
|
|
608
|
+
}
|
|
609
|
+
}
|