git ssb

2+

mixmix / ticktack



Commit 98233c821a36cfebd65825ed3c2c4e9474f43e6e

wip of exporting identity, missing password and sequence #122

andre alves garzia committed on 5/21/2018, 12:03:21 AM
Parent: e58c4d2da8898b7d5899788712c73b904e3f7350

Files changed

app/page/settings.jschanged
backup/html/backup.jschanged
backup/index.jschanged
backup/async/exportIdentity.jsadded
app/page/settings.jsView
@@ -3,8 +3,9 @@
33 const electron = require('electron')
44 const path = require('path')
55 const { version } = require('../../package.json')
66
7+
78 exports.gives = nest('app.page.settings')
89
910 exports.needs = nest({
1011 'about.html.image': 'first',
@@ -101,9 +102,8 @@
101102 h('section -version', [
102103 h('div.left', strings.settingsPage.section.version),
103104 h('div.right', version)
104105 ]),
105- h('h1', ""),
106106 h('section -backup', [
107107 h('div.left', 'Backup'),
108108 h('div.right', [
109109 exportIdentityButton,
backup/html/backup.jsView
@@ -1,7 +1,8 @@
11 const nest = require('depnest')
2-const { h, computed, Value } = require('mutant')
2+const { h, computed, Value, resolve } = require('mutant')
33 const electron = require('electron')
4+const { dialog } = require('electron').remote;
45 const path = require('path')
56 const fs = require('fs')
67
78 exports.gives = nest({
@@ -10,9 +11,10 @@
1011
1112 exports.needs = nest({
1213 'app.html.lightbox': 'first',
1314 'keys.sync.id': 'first',
14- 'translations.sync.strings': 'first'
15+ 'translations.sync.strings': 'first',
16+ 'backup.async.exportIdentity': 'first'
1517 })
1618
1719 exports.create = (api) => {
1820 return nest('backup.html', { exportIdentityButton, importIdentityButton })
@@ -22,9 +24,9 @@
2224
2325 function exportIdentityButton() {
2426 let isOpen = Value(false)
2527 let encryptionKeyRaw = Value('')
26- let msg = "Your identity is represented by an ed25519 key pair. Please backup your private key file very carefully. If your private key is hacked, all your private messages will be retrieved by third party, and your identity will be faked on the network"
28+
2729 let encryptionKeyInput = h('textarea#encryptionKey', {
2830 style: {
2931 width: '90%'
3032 },
@@ -32,22 +34,42 @@
3234 value: encryptionKeyRaw,
3335 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value),
3436 })
3537
36- let dialog = h('div.dialog', [
37- h('div.message', [
38- h('p', msg),
39- ]),
40- h('div.form', [
41- encryptionKeyInput
42- ]),
43- h('div.actions', [
44- h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'),
45- h('Button -primary', { 'ev-click': () => exportKey(resolve(encryptionKeyRaw), () => isOpen.set(false)) }, 'Export Keys')
38+ let exportDialog = h('div.dialog', {
39+ style: {
40+ 'text-align': 'left'
41+ }
42+ },
43+ [
44+ h('div.message', [
45+ h('h1', 'Export Identity'),
46+ h('p', 'Please backup your private key file very carefully.'),
47+ h('p', 'If your private key is hacked, all your private messages will be retrieved by third party, and your identity will be faked on the network')
48+ ]),
49+ h('div.form', [
50+ encryptionKeyInput
51+ ]),
52+ h('div.actions', [
53+ h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'),
54+ h('Button -primary', {
55+ 'ev-click': () => {
56+ dialog.showSaveDialog(
57+ {
58+ title: 'Export Identity',
59+ butttonLabel: 'Export Identity',
60+ defaultPath: 'ticktack-identity.backup',
61+ },
62+ (filename) => api.backup.async.exportIdentity(
63+ resolve(encryptionKeyRaw), filename, () => isOpen.set(false)
64+ )
65+ )
66+ }
67+ }, 'Export Identity')
68+ ])
4669 ])
47- ])
4870
49- let lb = api.app.html.lightbox(dialog, isOpen)
71+ let lb = api.app.html.lightbox(exportDialog, isOpen)
5072
5173 return h('div.backupKeys', [
5274 h('Button -backup', { 'ev-click': () => isOpen.set(true) }, 'Export Keys'),
5375 lb
backup/index.jsView
@@ -1,5 +1,8 @@
11 module.exports = {
22 html: {
33 backup: require('./html/backup')
4+ },
5+ async: {
6+ exportIdentity: require('./async/exportIdentity')
47 }
58 }
backup/async/exportIdentity.jsView
@@ -1,0 +1,38 @@
1+const nest = require('depnest')
2+const path = require('path')
3+const fs = require('fs')
4+const os = require('os')
5+const homedir = os.homedir()
6+const ssbPath = `${homedir}/.ssb/`
7+const peersFile = path.join(homedir, ".ssb", "gossip.json")
8+const secretFile = path.join(homedir, ".ssb", "secret")
9+
10+
11+exports.gives = nest('backup.async.exportIdentity')
12+
13+exports.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+}

Built with git-ssb-web