Skip to content

Commit

Permalink
added full documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
idancali committed Feb 15, 2018
1 parent 03c3a32 commit 6c75169
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 60 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
75 changes: 25 additions & 50 deletions docs/vault/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,87 +20,79 @@ 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) => {
// the vault could not be locked for some reason
})
```

### 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) => {
// the vault could not be unlocked for some reason
})
```

### 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
Expand All @@ -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.
Expand All @@ -147,7 +135,7 @@ The name of the vault.
*Examples:*

- ```my-vault```
- ```www.mydomain.com```
- ```mydomain.com```

**```root```**
*type: String*
Expand All @@ -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/```
8 changes: 2 additions & 6 deletions src/Vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class Vault {
this._cipher = new Cipher()
}

get cipher () {
return this._cipher
}

get id () {
return this._id
}
Expand Down Expand Up @@ -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')
Expand All @@ -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))
Expand Down

0 comments on commit 6c75169

Please sign in to comment.