diff --git a/example.js b/example.js new file mode 100644 index 0000000..2607c9f --- /dev/null +++ b/example.js @@ -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) + }) +}) diff --git a/index.js b/index.js new file mode 100644 index 0000000..71b3da7 --- /dev/null +++ b/index.js @@ -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) + }, + } +} diff --git a/package.json b/package.json index ec3c385..14bc544 100644 --- a/package.json +++ b/package.json @@ -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 ", - "license": "ISC" + "license": "ISC", + "dependencies": { + "dat-storage": "^1.0.4", + "random-access-keychain": "^1.0.0" + }, + "devDependencies": { + "hyperdrive": "^9.12.3" + } } diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6ac5e1a --- /dev/null +++ b/readme.md @@ -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.