git ssb

2+

mixmix / ticktack



Commit c24946ad74bf65f4ff10b27c737cc02628f88c75

wip of exporting identity, missing password and sequence #122

andre alves garzia committed on 5/7/2018, 9:12:03 PM
Parent: 992639a1213cadc35e523df588f878128718bc5b

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',
@@ -94,9 +95,8 @@
9495 h('section -version', [
9596 h('div.left', strings.settingsPage.section.version),
9697 h('div.right', version)
9798 ]),
98- h('h1', ""),
9999 h('section -backup', [
100100 h('div.left', 'Backup'),
101101 h('div.right', [
102102 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