Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tony-go/crypto-storage
A light & secure way to store data in browser.
https://github.com/tony-go/crypto-storage
Last synced: 23 days ago
JSON representation
A light & secure way to store data in browser.
- Host: GitHub
- URL: https://github.com/tony-go/crypto-storage
- Owner: tony-go
- License: mit
- Created: 2019-08-08T21:19:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-06T13:41:18.000Z (over 3 years ago)
- Last Synced: 2024-10-04T09:41:02.616Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 356 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# crypto-storage
![logo][logo]
A light & secure way to store data in a browser.
Build for create server less front end application in a safe way.
## Install
```
yarn add crypto-storage
```## Usage
```javascript
const CryptoStorage = require('crypto-storage')// create a storage
const safeStorage = CryptoStorage({name: 'tester', password: 'super-pw'})
safeStorage.create()// create an item and get it
await safeStorage.setItem('foo', 'bar')
const foo = await safeStorage.getItem('foo')
console.log(foo) // => 'bar'// close your session
safeStorage.close()// open it again (.use() this time)
let safeStorage2 = CryptoStorage({name: 'tester', password: 'super-pw'})
safeStorage2.use()const newFoo = await safeStorage2.getItem('foo')
console.log(newFoo) // => 'bar'// if you try to create the session again
safeStorage2.create() // => throw!!// if the storage is garbage collected whitout have been closed
// ex: in case of refresh in the browser
safeStorage2 = null;let safeStorage3 = CryptoStorage()
safeStorage3.use() // the last session will be recoveredconst newFoo = await safeStorage3.getItem('foo')
console.log(newFoo) // => 'bar'// close your session
safeStorage3.close()
```## API
### Methods
#### const storage = CryptoStorage({name: String, password: String})
Init a new storage instance.
#### await storage.create()
Create a new safe storage session.
#### await storage.use()
Open an existing session or recover the last one (in case of refresh in the browser).
#### await storage.setItem(key: String, value: String|Array|Object):{[key]: value}
Set an item in the storage.
#### await storage.getItem(key: String): {[key]: value}
Get an item from the storage.
#### storage.removeItem(key: String): String|Array|Object)
Remove an item from the storage and return the key.
#### storage.close()
Close access to CryptoStorage disabling set/get/removeItem.
[logo]:
https://user-images.githubusercontent.com/22824417/63122825-eb526500-bfa7-11e9-9e6d-d7f8e95b361b.png