Files: 4344e616c4767fdd5bacd1c85e19b506fb8d8772 / local-storage.js
734 bytesRaw
1 | |
2 | var u = require('./util') |
3 | |
4 | function isFunction (f) { |
5 | return 'function' == typeof f |
6 | } |
7 | |
8 | module.exports = function (generate) { |
9 | |
10 | function create (filename, curve, legacy) { |
11 | var keys = generate(curve, legacy) |
12 | localStorage[filename] = JSON.stringify(keys) |
13 | return keys |
14 | } |
15 | |
16 | function load (filename) { |
17 | return JSON.parse(localStorage[filename]) |
18 | } |
19 | |
20 | return { |
21 | createSync: create, |
22 | create: function(filename, curve, legacy, cb) { |
23 | if(isFunction(legacy)) |
24 | cb = legacy, legacy = null |
25 | if(isFunction(curve)) |
26 | cb = curve, curve = null |
27 | cb(null, create(filename, curve, legacy)) |
28 | }, |
29 | loadSync: load, |
30 | load: function (filename, cb) { |
31 | cb(null, load(filename)) |
32 | } |
33 | } |
34 | |
35 | } |
36 | |
37 | |
38 |
Built with git-ssb-web