-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d53e95
commit 8a6f7e4
Showing
4 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |