Skip to content

Commit

Permalink
write it
Browse files Browse the repository at this point in the history
  • Loading branch information
lachenmayer committed Apr 3, 2018
1 parent 3d53e95 commit 8a6f7e4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
12 changes: 12 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const hyperdrive = require('hyperdrive')
const storage = require('.')

const archive = hyperdrive(storage('example-archive'), { latest: true })
const content = 'hello! check your keychain :)'
archive.writeFile('/readme.txt', content, function(err) {
if (err) throw err
archive.readFile('/readme.txt', 'utf-8', function(err, data) {
if (err) throw err
console.log(data)
})
})
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const defaultStorage = require('dat-storage')
const randomAccessKeychain = require('random-access-keychain')

module.exports = function keychainStorage() {
const storage = defaultStorage(...arguments)
return {
metadata: function(file, opts) {
if (file === 'secret_key')
return randomAccessKeychain(
'Dat archive secret key',
opts.key.toString('hex')
)
return storage.metadata(...arguments)
},
content: function() {
return storage.content(...arguments)
},
}
}
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"name": "dat-keychain-storage",
"version": "1.0.0",
"description": "",
"description": "Store your Dat archive's secret key in the macOS keychain.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"keywords": ["dat", "macos", "keychain", "hyperdrive"],
"author": "harry lachenmayer <[email protected]>",
"license": "ISC"
"license": "ISC",
"dependencies": {
"dat-storage": "^1.0.4",
"random-access-keychain": "^1.0.0"
},
"devDependencies": {
"hyperdrive": "^9.12.3"
}
}
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# dat-keychain-storage

Store your Dat archive's secret key in the macOS keychain.

This is an extremely simple module wrapping [dat-storage](https://github.com/datproject/dat-storage), which does all the heavy lifting of storing files in the right places.

## Install

```
npm install dat-keychain-storage
```

## Usage

You can use this anywhere that [Dat](https://github.com/datproject/dat) or [Hyperdrive](https://github.com/mafintosh/hyperdrive) expects a "storage".

```js
const hyperdrive = require('hyperdrive')
const storage = require('dat-keychain-storage')
const archive = hyperdrive(storage('example-archive'), {latest: true})
```

Check out [`example.js`](example.js) for a very basic example.

0 comments on commit 8a6f7e4

Please sign in to comment.