Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle change for Firefox #386

Merged
merged 6 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions app/api/ada/lib/cardanoCrypto/cryptoWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Utility functions for handling the private master key

import bip39 from 'bip39';
import { validateMnemonic, generateMnemonic } from 'bip39';

import { Logger, stringifyError } from '../../../../utils/logging';

Expand All @@ -17,17 +17,30 @@ import { RustModule } from './rustLoader';
declare var CONFIG : ConfigType;

/** Generate a random mnemonic based on 160-bits of entropy (15 words) */
export const generateAdaMnemonic = () => bip39.generateMnemonic(160).split(' ');
export const generateAdaMnemonic = () => generateMnemonic(160).split(' ');

/** Check validty of mnemonic (including checksum) */
export const isValidEnglishAdaMnemonic = (
phrase: string,
numberOfWords: ?number = 15
) => (
) => {
// Note: splitting on spaces will not work for Japanese-encoded mnemonics who use \u3000 instead
// We only use English mnemonics in Yoroi so this is okay.
phrase.split(' ').length === numberOfWords && bip39.validateMnemonic(phrase)
);
const split = phrase.split(' ');
if (split.length !== numberOfWords) {
return false;
}
/**
* Redemption mnemonics use 0-word menmonics.
* However, 9-word mnemonics were disallowed in a later version of BIP39
* Since our bip39 library now considers all 9-word mnemonics invalid
* we just return true for backwards compatibility
*/
if (split.length === 9) {
return true;
}
return validateMnemonic(phrase);
};

/** Check validty of paper mnemonic (including checksum) */
export const isValidEnglishAdaPaperMnemonic = (
Expand Down
30 changes: 8 additions & 22 deletions app/api/ada/lib/decrypt.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import aesjs from 'aes-js';
import bip39 from 'bip39';
import { validateMnemonic } from 'bip39';
import blakejs from 'blakejs';
import crypto from 'crypto';
import validWords from 'bip39/wordlists/english.json';
import validWords from 'bip39/src/wordlists/english.json';
import { RustModule } from './cardanoCrypto/rustLoader';

const isBase64 = (string) => {
const criteria = '(?:^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$)';
Expand All @@ -17,30 +18,15 @@ function decryptWithAES(aesKey, bytes) {
return new aesjs.ModeOfOperation.ctr(aesKey, new aesjs.Counter(iv)).decrypt(bytes); // eslint-disable-line
}

const hexChar = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];

const hexToBytes = (s) => {
const arr = [];
if (s.length & 1 === 1) { // eslint-disable-line
throw new Error(`Wrong hex: ${s}`);
}
for (let i = 0; i < s.length / 2; ++i) {
const c1 = s[2 * i];
const c2 = s[(2 * i) + 1];
const i1 = hexChar.indexOf(c1);
const i2 = hexChar.indexOf(c2);
if (i1 === -1 || i2 === -1) throw new Error(`Wrong hex: ${s}`);
arr[i] = (i1 << 4) + i2;
}
return new Uint8Array(arr);
};

const blake2b = (data) => blakejs.blake2b(data, null, 32);

const fromMnemonic = (words) => hexToBytes(bip39.mnemonicToEntropy(words, validWords));
const fromMnemonic = (words) => {
const entropy = RustModule.Wallet.Entropy.from_english_mnemonics(words);
return new Uint8Array(entropy.to_array());
};

export const isValidMnemonic = (phrase, numberOfWords = 9) => (
(phrase.split(' ').length === numberOfWords && bip39.validateMnemonic(phrase, validWords))
(phrase.split(' ').length === numberOfWords && validateMnemonic(phrase, validWords))
);

const hashData = (data) => {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/transfer/DaedalusTransferPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { intlShape, defineMessages } from 'react-intl';
import validWords from 'bip39/wordlists/english.json';
import validWords from 'bip39/src/wordlists/english.json';
import type { InjectedProps } from '../../types/injectedPropsType';
import StaticTopbarTitle from '../../components/topbar/StaticTopbarTitle';
import TopBar from '../../components/topbar/TopBar';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/wallet/AdaRedemptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AdaRedemptionNoWallets from '../../components/wallet/ada-redemption/AdaRe
import LoadingSpinner from '../../components/widgets/LoadingSpinner';
import { ADA_REDEMPTION_TYPES } from '../../types/redemptionTypes';
import { AdaRedemptionCertificateParseError } from '../../i18n/errors';
import validWords from 'bip39/wordlists/english.json';
import validWords from 'bip39/src/wordlists/english.json';
import { ROUTES } from '../../routes-config';
import environment from '../../environment';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import validWords from 'bip39/wordlists/english.json';
import validWords from 'bip39/src/wordlists/english.json';
import WalletRestoreDialog from '../../../components/wallet/WalletRestoreDialog';
import type { InjectedDialogContainerProps } from '../../../types/injectedPropsType';
import environment from '../../../environment';
Expand Down
4 changes: 2 additions & 2 deletions app/i18n/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import LocalizableError from './LocalizableError';
export class InvalidMnemonicError extends LocalizableError {
constructor() {
super({
id: 'global.errors.invalidMnemonic',
id: 'api.errors.invalidMnemonicError',
defaultMessage: '!!!Invalid phrase entered, please check.',
});
}
Expand All @@ -30,7 +30,7 @@ export class FieldRequiredError extends LocalizableError {
export class AdaRedemptionCertificateParseError extends LocalizableError {
constructor() {
super({
id: 'global.errors.AdaRedemptionCertificateParseError',
id: 'api.errors.AdaRedemptionCertificateParseError',
defaultMessage: '!!!The ADA redemption code could not be parsed from the given document.',
});
}
Expand Down
1 change: 1 addition & 0 deletions app/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"environment.apiVersion.cardano": "1.0.4",
"environment.currency.ada": "ADA",
"global.errors.fieldIsRequired": "This field is required.",
"global.errors.invalidEmail": "Invalid email entered, please check.",
"global.errors.invalidMasterKey": "Invalid master key entered, please check.",
"global.errors.invalidRepeatPassword": "Doesn't match.",
"global.errors.invalidWalletName": "Wallet name requires at least 1 and at most 40 letters.",
Expand Down
6 changes: 6 additions & 0 deletions chrome/views/background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html
><html>
<head>
<script src="./js/vendor.js" charset="UTF-8" ></script>
</head>
</html>
6 changes: 0 additions & 6 deletions chrome/views/background.pug

This file was deleted.

16 changes: 16 additions & 0 deletions chrome/views/main_window.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head
><meta charset="UTF-8">
<title>Yoroi</title>
<style>
body { width: 500px; }
</style>
</head>
<body>
<div id="root">

</div>
<script src="./js/vendor.js" charset="UTF-8"></script>
</body>
</html>
15 changes: 0 additions & 15 deletions chrome/views/main_window.pug

This file was deleted.

Loading