Skip to content
This repository was archived by the owner on Oct 31, 2020. It is now read-only.

Commit 9430eba

Browse files
committed
Upgrade supergenpass-lib to 3
1 parent 160b37f commit 9430eba

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"jquery": "^3.1.1",
18-
"supergenpass-lib": "^1.0.0"
18+
"supergenpass-lib": "^3.0.1"
1919
},
2020
"devDependencies": {
2121
"eslint": "^3.3.1",

src/lib/hash.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
var supergenpass = require('supergenpass-lib');
22

33
module.exports = function(text){
4-
return supergenpass(text, 'chromegenpass-chrome-extension', {
5-
length: 16
4+
return new Promise(function(resolve){
5+
return supergenpass.generate(text, 'chromegenpass-chrome-extension', {
6+
length: 16
7+
}, resolve);
68
});
79
};

src/lib/storage.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,29 @@ var addRaw = function(newPasswords){
109109
// see manifest background/persistent key.
110110
var cache = {};
111111

112+
var getPassword = function(pass){
113+
var currentHash = passwordSettingsHash(pass);
114+
if (cache[currentHash])
115+
return Promise.resolve(cache[currentHash]);
116+
117+
return new Promise(function(resolve, reject){
118+
var tryThis = function(attempt){
119+
if (!attempt) {
120+
return reject(new Error('User did not authenticate'));
121+
}
122+
hash(attempt).then(function(hashedAttempt){
123+
if (hashedAttempt === pass.hash) {
124+
cache[currentHash] = attempt;
125+
return resolve(attempt);
126+
}
127+
tryThis(window.prompt(i18n('unlock_prompt_retry', pass.name)));
128+
});
129+
};
130+
var attempt = window.prompt(i18n('unlock_prompt', pass.name));
131+
tryThis(attempt);
132+
});
133+
};
134+
112135
var api = {
113136
passwords: {
114137
add: function(pass) {
@@ -117,25 +140,15 @@ var api = {
117140
return addRaw([pass]);
118141
},
119142
get: function(pass, domain) {
120-
var currentHash = passwordSettingsHash(pass);
121-
if (!cache[currentHash]) {
122-
var attempt = window.prompt(i18n('unlock_prompt', pass.name));
123-
for(;;){
124-
if (!attempt) {
125-
return Promise.reject(new Error('User did not authenticate'));
126-
}
127-
if (hash(attempt) === pass.hash) {
128-
cache[currentHash] = attempt;
129-
break;
130-
}
131-
attempt = window.prompt(i18n('unlock_prompt_retry', pass.name));
132-
}
133-
}
134-
return Promise.resolve(supergenpass(cache[currentHash], domain, {
135-
length: pass.len,
136-
method: pass.method,
137-
secret: pass.secret
138-
}));
143+
return getPassword(pass).then(function(password){
144+
return new Promise(function(resolve){
145+
supergenpass.generate(password, domain, {
146+
length: pass.len,
147+
method: pass.method,
148+
secret: pass.secret
149+
}, resolve);
150+
});
151+
});
139152
},
140153
list: list,
141154
remove: function(pass) {

0 commit comments

Comments
 (0)