From 6c7516909271a77e757bb2a37f6a2cadce40a9e7 Mon Sep 17 00:00:00 2001 From: "I. Dan Calinescu" Date: Thu, 15 Feb 2018 07:52:48 +0200 Subject: [PATCH] added full documentation --- README.md | 3 +- docs/README.md | 6 ++-- docs/vault/README.md | 75 +++++++++++++++----------------------------- src/Vault.js | 8 ++--- 4 files changed, 32 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 5cb26b4..b54723c 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,9 @@ const vault = new cassi.Vault({ name: 'my-vault' }) // Create the vault with password 'hello' vault.create('hello') - .then(({ vault }) => { + .then(({ vault, mnemonic }) => { // Good stuff, enjoy your new vault + // Store the mnemonic somewhere safe }) .catch((error) => { // Something happened and the vault could not be created diff --git a/docs/README.md b/docs/README.md index 461e35d..bb38dba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,13 +17,13 @@ const vault = new cassi.Vault({ name: 'my-vault' }) // Create the vault with password 'hello' vault.create('hello') - .then((vault) => { + .then(({ vault, mnemonic }) => { // Good stuff, enjoy your new vault + // Store the mnemonic somewhere sage }) .catch((error) => { // Something happened and the vault could not be created - }) the vault could not be created or locked - }) + }) ``` Read The Full Vault Documentation for more details about creating, locking, unlocking and reading and writing from a vault. diff --git a/docs/vault/README.md b/docs/vault/README.md index b93e853..f59348c 100644 --- a/docs/vault/README.md +++ b/docs/vault/README.md @@ -20,36 +20,36 @@ const vault = new cassi.Vault({ name: 'my-vault' }) ### Functions -### create (vaultName, password) +### create (password) + +Create a Cassi Vault in your home directory (~/.cassi), with the given password *Returns a promise* **Example:** -Create a Cassi Vault named '.cassi' in your home directory (~/.cassi), -with password 'hello' - ``` -vault.create('.cassi', 'hello') - .then((data) => { - // do something with the vault +vault.create('hello') + .then(({ vault, mnemonic }) => { + // Have fun using your new vault. + // Remember to keep the mnemonic somewhere safe. }) .catch((error) => { // the vault could not be created }) ``` -### lock (vaultName, password) +### lock (password) + +Lock a Cassi Vault with the given password *Returns a promise* **Example:** -Attempt to lock a Cassi Vault named '.cassi', with password 'hello' - ``` -vault.lock('.cassi', 'hello') - .then(() => { +vault.lock('hello') + .then(({ vault }) => { // the vault is successfully locked now }) .catch((error) => { @@ -57,17 +57,17 @@ vault.lock('.cassi', 'hello') }) ``` -### unlock (vaultName, password) +### unlock (password) + +Unlock a Cassi Vault with the given password *Returns a promise* **Example:** -Attempt to unlock a Cassi Vault named '.cassi', with password 'hello' - ``` -vault.unlock('.cassi', 'hello') - .then((data) => { +vault.unlock('hello') + .then(({ vault }) => { // you may use the vault now }) .catch((error) => { @@ -75,32 +75,24 @@ vault.unlock('.cassi', 'hello') }) ``` -### exists (vaultName) +### read (key) -*Returns true or false* +Read secure data from an unlocked vault **Example:** ``` -const cassiVaultExists = cassi.vault.exists('.cassi') +const name = vault.read('name') ``` -### open (vaultName) +### write (key, value) -*Returns a promise* +Write secure data from to an unlocked vault **Example:** -Attempt to open an unlocked Cassi Vault named '.cassi' - ``` -cassi.vault.open('.cassi') - .then((data) => { - // you may use the vault now - }) - .catch((error) => { - // the vault could not be opened for some reason - }) +vault.write('name', 'Johnny') ``` ### Fields @@ -117,10 +109,6 @@ The original options passed at instantiation. The root directory where all vaults are to be found. -**```index```** - -The filename of the vault index file. - **```name```** The name of the vault. @@ -147,7 +135,7 @@ The name of the vault. *Examples:* - ```my-vault``` -- ```www.mydomain.com``` +- ```mydomain.com``` **```root```** *type: String* @@ -159,17 +147,4 @@ The root directory where all vaults will be stored *Examples:* - ```myvaults``` -- ```/home/users/cassi/vaults/``` - -**```index```** -*type: String* - -The filename that holds the primary vault information - -*Default: index* - - -*Examples:* - -- ```newindex``` -- ```myvaultindex``` +- ```/home/users/johnny/myVaults/``` diff --git a/src/Vault.js b/src/Vault.js index 9d476cc..3389770 100644 --- a/src/Vault.js +++ b/src/Vault.js @@ -13,10 +13,6 @@ class Vault { this._cipher = new Cipher() } - get cipher () { - return this._cipher - } - get id () { return this._id } @@ -74,7 +70,7 @@ class Vault { return this._verify(lockFile, indexFile, true) .then(() => { var data = fs.readFileSync(indexFile, 'utf8') - return this.cipher.encrypt(data, password) + return this._cipher.encrypt(data, password) }) .then(({ payload, mnemonic }) => fs.writeFile(lockFile, JSON.stringify(payload), 'utf8') @@ -91,7 +87,7 @@ class Vault { return this._verify(lockFile, indexFile) .then(() => { let data = fs.readFileSync(lockFile, 'utf8') - return this.cipher.decrypt(data, password) + return this._cipher.decrypt(data, password) }) .then((dec) => fs.writeFile(indexFile, JSON.stringify(dec), 'utf8')) .then(() => fs.remove(lockFile))