Merge pull request #5336 from paritytech/mh-wordlist-fe
Shared wordlist for frontend
This commit is contained in:
commit
e0d5eedff7
@ -154,6 +154,7 @@
|
||||
"yargs": "6.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@parity/wordlist": "1.0.1",
|
||||
"base32.js": "0.1.0",
|
||||
"bignumber.js": "3.0.1",
|
||||
"blockies": "0.0.2",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,8 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// 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
|
||||
const hasWebWorkers = typeof Worker !== 'undefined';
|
||||
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(' ');
|
||||
}
|
||||
|
@ -14,48 +14,10 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import dictionary from './dictionary';
|
||||
import {
|
||||
phraseToAddress,
|
||||
phraseToWallet,
|
||||
randomNumber,
|
||||
randomWord,
|
||||
randomPhrase
|
||||
} from './';
|
||||
import { randomPhrase } from '@parity/wordlist';
|
||||
import { phraseToAddress, phraseToWallet } from './';
|
||||
|
||||
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 () {
|
||||
this.timeout(10000);
|
||||
|
||||
|
@ -19,7 +19,8 @@ import accounts from './accounts';
|
||||
import transactions from './transactions';
|
||||
import { Middleware } from '../transport';
|
||||
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 {
|
||||
// Maps transaction requests to transaction hashes.
|
||||
|
@ -67,7 +67,7 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: /node_modules\/(material-chip-input|ethereumjs-tx)/,
|
||||
include: /node_modules\/(material-chip-input|ethereumjs-tx|@parity\/wordlist)/,
|
||||
use: 'babel-loader'
|
||||
},
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
include: /node_modules\/ethereumjs-tx/,
|
||||
include: /node_modules\/(ethereumjs-tx|@parity\/wordlist)/,
|
||||
use: 'babel-loader'
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user