git ssb

2+

mixmix / ticktack



Tree: 3fa3e23c4b756580c6cf49253941a9e7d55b9023

Files: 3fa3e23c4b756580c6cf49253941a9e7d55b9023 / backup / async / exportIdentity.js

1302 bytesRaw
1const nest = require('depnest')
2const { onceTrue } = require('mutant')
3const path = require('path')
4const fs = require('fs')
5const os = require('os')
6const homedir = os.homedir()
7const ssbPath = `${homedir}/.ssb/`
8const peersFile = path.join(homedir, ".ssb", "gossip.json")
9const secretFile = path.join(homedir, ".ssb", "secret")
10
11
12exports.gives = nest('backup.async.exportIdentity')
13
14
15exports.needs = nest({
16 'keys.sync.id': 'first',
17 'sbot.obs.connection': 'first'
18})
19
20exports.create = function (api) {
21 return nest('backup.async.exportIdentity', (password, filename, cb) => {
22 if ("undefined" == typeof filename) {
23 cb()
24 } else {
25
26 console.log(`should export identity to file ${filename}`)
27
28 let peers = JSON.parse(fs.readFileSync(peersFile))
29 let secret = fs.readFileSync(secretFile, "utf8")
30
31 onceTrue(api.sbot.obs.connection, sbot => {
32
33 let feedId = api.keys.sync.id()
34
35 sbot.latestSequence(feedId, (err, sequence) => {
36
37 if (err) throw err
38
39 let data = {
40 exportDate: new Date(),
41 latestSequence: sequence,
42 peers: peers,
43 secret: secret
44 }
45
46 fs.writeFileSync(filename, JSON.stringify(data), "utf8")
47
48 cb()
49 })
50 })
51 }
52 return true
53 })
54}
55

Built with git-ssb-web