use @parity/wordlist

This commit is contained in:
maciejhirsz 2017-03-29 19:48:29 +02:00
parent ab2c3468d5
commit 2cc111ad5d
5 changed files with 5 additions and 7862 deletions

View File

@ -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

View File

@ -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(' ');
}

View File

@ -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);

View File

@ -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.