/
files-by-format.js
83 lines (75 loc) · 2.53 KB
/
files-by-format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { spFiles, nmFiles } from '../lib/constants';
import securityPersonalizer from './security-personalizer';
import nodeSketchFiles from './node-sketch-files';
import platformioIni from './platformioini';
const fileContents = ({ key }) => JSON.parse(window.localStorage.getItem(key)).text;
const readme = `
Instructions to flash your node:
tl;dr:
* Flash the SecurityPersonalizer to your node first.
* Then flash the main sketch next.
Details:
Flashing the SecurityPersonalizer sketch to your node prepares it for signing
and encryption. It writes the necessary security keys to your node's EEPROM
(in case of software signing) or to the ATSHA204 (in case you are using the
ATSHA204 chip). This ensures that your sensor data isn't visible to your
neighbours, and that snoopers can't snoop.
`.trim();
export const arduino = nodeParams => {
const sketchName = nodeParams.network.nodes.find(n => n.id === nodeParams.nodeId).name.trim();
return [
{
path: `${sketchName}/README.md`,
contents: readme
},
...spFiles.map(file => ({
path: `${sketchName}/SecurityPersonalizer/${file.name}`,
contents: (
file.key === 'sp-ino'
? securityPersonalizer(nodeParams, fileContents(file))
: fileContents(file)
)
})),
...nmFiles.map(file => ({
path: `${sketchName}/${sketchName}/${file.name}`,
contents: fileContents(file)
})),
...nodeSketchFiles(nodeParams, sketchName).map(file => ({
path: `${sketchName}/${sketchName}/${file.name}`,
contents: file.contents
}))
];
}
export const platformio = nodeParams => {
const sketchName = nodeParams.network.nodes.find(n => n.id === nodeParams.nodeId).name.trim();
return [
{
path: `${sketchName}/README.md`,
contents: readme
},
...spFiles.map(file => ({
path: `${sketchName}/SecurityPersonalizer/src/${file.name}`,
contents: (
file.key === 'sp-ino'
? securityPersonalizer(nodeParams, fileContents(file))
: fileContents(file)
)
})),
{
path: `${sketchName}/SecurityPersonalizer/platformio.ini`,
contents: platformioIni(nodeParams)
},
...nmFiles.map(file => ({
path: `${sketchName}/${sketchName}/src/${file.name}`,
contents: fileContents(file)
})),
...nodeSketchFiles(nodeParams, sketchName).map(file => ({
path: `${sketchName}/${sketchName}/src/${file.name}`,
contents: file.contents
})),
{
path: `${sketchName}/${sketchName}/platformio.ini`,
contents: platformioIni(nodeParams)
}
]
};