Merge pull request #5336 from paritytech/mh-wordlist-fe

Shared wordlist for frontend
This commit is contained in:
Maciej Hirsz 2017-03-30 12:28:52 +02:00 committed by GitHub
commit e0d5eedff7
7 changed files with 7 additions and 7864 deletions

View File

@ -154,6 +154,7 @@
"yargs": "6.6.0" "yargs": "6.6.0"
}, },
"dependencies": { "dependencies": {
"@parity/wordlist": "1.0.1",
"base32.js": "0.1.0", "base32.js": "0.1.0",
"bignumber.js": "3.0.1", "bignumber.js": "3.0.1",
"blockies": "0.0.2", "blockies": "0.0.2",

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import dictionary from './dictionary';
// Allow a web worker in the browser, with a fallback for Node.js // Allow a web worker in the browser, with a fallback for Node.js
const hasWebWorkers = typeof Worker !== 'undefined'; const hasWebWorkers = typeof Worker !== 'undefined';
const KeyWorker = hasWebWorkers ? require('worker-loader!./worker') const KeyWorker = hasWebWorkers ? require('worker-loader!./worker')
@ -44,44 +42,3 @@ export function phraseToWallet (phrase) {
}; };
}); });
} }
export function randomBytes (length) {
if (keythereum) {
return keythereum.crypto.randomBytes(length);
}
const buf = Buffer.alloc(length);
for (let i = 0; i < length; i++) {
buf[i] = Math.random() * 255;
}
return buf;
}
export function randomNumber (max) {
// Use 24 bits to avoid the integer becoming signed via bitshifts
const rand = randomBytes(3);
const integer = (rand[0] << 16) | (rand[1] << 8) | rand[2];
// floor to integer value via bitor 0
return ((integer / 0xFFFFFF) * max) | 0;
}
export function randomWord () {
// TODO mh: use better entropy
const index = randomNumber(dictionary.length);
return dictionary[index];
}
export function randomPhrase (length) {
const words = [];
while (length--) {
words.push(randomWord());
}
return words.join(' ');
}

View File

@ -14,48 +14,10 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import dictionary from './dictionary'; import { randomPhrase } from '@parity/wordlist';
import { import { phraseToAddress, phraseToWallet } from './';
phraseToAddress,
phraseToWallet,
randomNumber,
randomWord,
randomPhrase
} from './';
describe('api/local/ethkey', () => { describe('api/local/ethkey', () => {
describe('randomNumber', () => {
it('generates numbers in range', () => {
for (let i = 0; i < 100; i++) {
const number = randomNumber(7777);
expect(number).to.be.at.least(0);
expect(number).to.be.below(7777);
expect(number % 1).to.be.equal(0);
}
});
});
describe('randomWord', () => {
it('generates a random word from the dictionary', () => {
const word = randomWord();
expect(dictionary.includes(word)).to.be.equal(true);
});
});
describe('randomPhrase', () => {
it('generates a random phrase from the dictionary', () => {
const phrase = randomPhrase(7).split(' ');
expect(phrase.length).to.be.equal(7);
phrase.forEach((word) => {
expect(dictionary.includes(word)).to.be.equal(true);
});
});
});
describe.skip('phraseToAddress', function () { describe.skip('phraseToAddress', function () {
this.timeout(10000); this.timeout(10000);

View File

@ -19,7 +19,8 @@ import accounts from './accounts';
import transactions from './transactions'; import transactions from './transactions';
import { Middleware } from '../transport'; import { Middleware } from '../transport';
import { inNumber16 } from '../format/input'; import { inNumber16 } from '../format/input';
import { phraseToWallet, phraseToAddress, randomPhrase } from './ethkey'; import { phraseToWallet, phraseToAddress } from './ethkey';
import { randomPhrase } from '@parity/wordlist';
export default class LocalAccountsMiddleware extends Middleware { export default class LocalAccountsMiddleware extends Middleware {
// Maps transaction requests to transaction hashes. // Maps transaction requests to transaction hashes.

View File

@ -67,7 +67,7 @@ module.exports = {
}, },
{ {
test: /\.js$/, test: /\.js$/,
include: /node_modules\/(material-chip-input|ethereumjs-tx)/, include: /node_modules\/(material-chip-input|ethereumjs-tx|@parity\/wordlist)/,
use: 'babel-loader' use: 'babel-loader'
}, },
{ {

View File

@ -58,7 +58,7 @@ module.exports = {
}, },
{ {
test: /\.js$/, test: /\.js$/,
include: /node_modules\/ethereumjs-tx/, include: /node_modules\/(ethereumjs-tx|@parity\/wordlist)/,
use: 'babel-loader' use: 'babel-loader'
}, },
{ {