git ssb

2+

mixmix / ticktack



Tree: c24946ad74bf65f4ff10b27c737cc02628f88c75

Files: c24946ad74bf65f4ff10b27c737cc02628f88c75 / backup / async / exportIdentity.js

938 bytesRaw
1const nest = require('depnest')
2const path = require('path')
3const fs = require('fs')
4const os = require('os')
5const homedir = os.homedir()
6const ssbPath = `${homedir}/.ssb/`
7const peersFile = path.join(homedir, ".ssb", "gossip.json")
8const secretFile = path.join(homedir, ".ssb", "secret")
9
10
11exports.gives = nest('backup.async.exportIdentity')
12
13exports.create = function (api) {
14 return nest('backup.async.exportIdentity', (password, filename, cb) => {
15 if ("undefined" == typeof filename) {
16 cb()
17 } else {
18
19 console.log(`should export identity to file ${filename}`)
20
21 let peers = JSON.parse(fs.readFileSync(peersFile))
22 let secret = fs.readFileSync(secretFile, "utf8")
23
24
25 let data = {
26 exportDate: new Date(),
27 latestSequence: "",
28 peers: peers,
29 secret: secret
30 }
31
32 fs.writeFileSync(filename, JSON.stringify(data), "utf8")
33
34 cb()
35 }
36 return true
37 })
38}
39

Built with git-ssb-web