Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 5052253

Browse files
committed
Lint
1 parent 217527a commit 5052253

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

src/keystore.js

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* globals localStorage */
12
'use strict'
23

34
const EC = require('elliptic').ec
@@ -11,7 +12,9 @@ class Keystore {
1112
}
1213

1314
hasKey (id) {
14-
if (!id) throw new Error('id needed to check a key')
15+
if (!id) {
16+
throw new Error('id needed to check a key')
17+
}
1518
let hasKey = false
1619
let storedKey = this._cache.get(id) || this._storage.getItem(id)
1720
try {
@@ -24,13 +27,15 @@ class Keystore {
2427
}
2528

2629
createKey (id) {
27-
if (!id) throw new Error('id needed to create a key')
30+
if (!id) {
31+
throw new Error('id needed to create a key')
32+
}
2833

2934
const keyPair = ec.genKeyPair()
3035

3136
const key = {
3237
publicKey: keyPair.getPublic('hex'),
33-
privateKey: keyPair.getPrivate('hex'),
38+
privateKey: keyPair.getPrivate('hex')
3439
}
3540

3641
this._storage.setItem(id, JSON.stringify(key))
@@ -40,7 +45,9 @@ class Keystore {
4045
}
4146

4247
getKey (id) {
43-
if (!id) throw new Error('id needed to get a key')
48+
if (!id) {
49+
throw new Error('id needed to get a key')
50+
}
4451
const cachedKey = this._cache.get(id)
4552
let storedKey
4653
try {
@@ -49,46 +56,59 @@ class Keystore {
4956
// ignore ENOENT error
5057
}
5158

52-
if (!storedKey)
59+
if (!storedKey) {
5360
return
61+
}
5462

5563
const deserializedKey = cachedKey || JSON.parse(storedKey)
5664

57-
if (!deserializedKey)
65+
if (!deserializedKey) {
5866
return
67+
}
5968

60-
if (!cachedKey)
69+
if (!cachedKey) {
6170
this._cache.set(id, deserializedKey)
71+
}
6272

6373
const key = ec.keyPair({
64-
pub: deserializedKey.publicKey,
74+
pub: deserializedKey.publicKey,
6575
priv: deserializedKey.privateKey,
6676
pubEnc: 'hex',
67-
privEnc: 'hex',
77+
privEnc: 'hex'
6878
})
6979

7080
return key
7181
}
7282

73-
sign(key, data) {
74-
if (!key) throw new Error('No signing key given')
75-
if (!data) throw new Error('Given input data was undefined')
83+
sign (key, data) {
84+
if (!key) {
85+
throw new Error('No signing key given')
86+
}
87+
if (!data) {
88+
throw new Error('Given input data was undefined')
89+
}
7690
const sig = ec.sign(data, key)
7791
return Promise.resolve(sig.toDER('hex'))
7892
}
7993

80-
verify(signature, publicKey, data) {
94+
verify (signature, publicKey, data) {
8195
return Keystore.verify(signature, publicKey, data)
8296
}
8397

84-
static verify(signature, publicKey, data) {
85-
if (!signature) throw new Error('No signature given')
86-
if (!publicKey) throw new Error('Given publicKey was undefined')
87-
if (!data) throw new Error('Given input data was undefined')
98+
static verify (signature, publicKey, data) {
99+
if (!signature) {
100+
throw new Error('No signature given')
101+
}
102+
if (!publicKey) {
103+
throw new Error('Given publicKey was undefined')
104+
}
105+
if (!data) {
106+
throw new Error('Given input data was undefined')
107+
}
88108
let res = false
89109
const key = ec.keyPair({
90-
pub: publicKey,
91-
pubEnc: 'hex',
110+
pub: publicKey,
111+
pubEnc: 'hex'
92112
})
93113
try {
94114
res = ec.verify(data, signature, key)

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
Buffer: true
1818
},
1919
plugins: [
20-
new Uglify(),
20+
new Uglify()
2121
],
2222
resolve: {
2323
modules: [
@@ -31,5 +31,5 @@ module.exports = {
3131
path.resolve(__dirname, '../node_modules')
3232
],
3333
moduleExtensions: ['-loader']
34-
},
34+
}
3535
}

0 commit comments

Comments
 (0)