const Path = require('path')
const Keys = require('ssb-keys')
const nest = require('depnest')

exports.needs = nest('config.sync.load', 'first')
exports.gives = nest('keys.sync.load')
exports.create = (api) => {
  return nest('keys.sync.load', () => {
    var keys
    if (!keys) {
      const config = api.config.sync.load()
      const keyPath = Path.join(config.path, 'secret')
      keys = Keys.loadOrCreateSync(keyPath)
    }
    return keys
  })
}

@@ -155,24 +155,28 @@
 ives = nest(
+%7B%0A  
 'keys.sync.l
@@ -177,15 +177,31 @@
 sync
-.load')
+': %5B 'load', 'id' %5D%0A%7D)%0A
 %0Aexp
@@ -225,16 +225,28 @@
 i) =%3E %7B%0A
+  var keys%0A%0A
   return
@@ -251,16 +251,22 @@
 rn nest(
+%7B%0A    
 'keys.sy
@@ -271,36 +271,95 @@
 sync
-.
+': %7B 
 load
-'
 , 
-() =%3E %7B%0A    var keys
+id %7D%0A  %7D)%0A%0A  function id () %7B%0A    return load().id%0A  %7D%0A%0A  function load () %7B
 %0A   
@@ -540,12 +540,11 @@
 keys%0A  %7D
-)
 %0A%7D%0A

fix caching, add keys.sync.id