Skip to content
Open
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
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ services:
- "/app/node_modules"
# set the environment to development
environment:
- NODE_ENV=development
- NODE_ENV=development
- REACT_APP_NETWORK=mainnet


9 changes: 7 additions & 2 deletions src/components/pages/keyGenerator/KeyGeneratorContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import './keyGeneratorContent.scss';

export interface GeneratedKey {
privateKey: string;
privateKeyWIF: string;
publicKey: string;
words: string[];
}
Expand All @@ -28,6 +29,7 @@ export class KeyGeneratorContent extends React.PureComponent<any, KeyGenerator>
super(props);
this.state = {
privateKey: '',
privateKeyWIF: '',
publicKey: '',
words: [],
publicKeyImgUrl: '',
Expand All @@ -43,6 +45,7 @@ export class KeyGeneratorContent extends React.PureComponent<any, KeyGenerator>
const keys = generateNewKeys();
this.setState({
privateKey: keys.privateKey,
privateKeyWIF: keys.privateKeyWIF,
publicKey: keys.publicKey,
words: keys.words
});
Expand All @@ -60,7 +63,7 @@ export class KeyGeneratorContent extends React.PureComponent<any, KeyGenerator>
}

render() {
const { privateKey, publicKey, words, privateKeyImgUrl, publicKeyImgUrl } = this.state;
const { privateKey, privateKeyWIF, publicKey, words, privateKeyImgUrl, publicKeyImgUrl } = this.state;
return (
<div className="container">
<h2>{en.content.title}</h2>
Expand All @@ -83,6 +86,8 @@ export class KeyGeneratorContent extends React.PureComponent<any, KeyGenerator>
<div className="chip-container">
{words?.map((word, index) => (<Chip key={index} label={`${index + 1}. ${word}`} />))}
</div>
<Label label={en.content.privateKeyWIF} />
<Label label={privateKeyWIF} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it better to place it in a multiline field? It should be easier for users to copy it then, I believe

</div>
<div className="qrcode-container">
<Label label={en.content.privateKeyQrCode} />
Expand All @@ -92,7 +97,7 @@ export class KeyGeneratorContent extends React.PureComponent<any, KeyGenerator>
</Grid>
<div className="buttons-container">
<Button onClick={this.onGenerateNewKey} label={en.content.generateNewKey} />
<div className="flat-button"><PDFDownloadLink document={<KeyGeneratorPdf publicKeyImgUrl={publicKeyImgUrl} privateKeyImgUrl={privateKeyImgUrl} publicKey={publicKey} words={words} privateKey={privateKey} />} fileName={en.content.pdfFileName}><StyledText label={en.content.exportAsPdf} /></PDFDownloadLink></div>
<div className="flat-button"><PDFDownloadLink document={<KeyGeneratorPdf publicKeyImgUrl={publicKeyImgUrl} privateKeyImgUrl={privateKeyImgUrl} publicKey={publicKey} words={words} privateKey={privateKey} privateKeyWIF={privateKeyWIF} />} fileName={en.content.pdfFileName}><StyledText label={en.content.exportAsPdf} /></PDFDownloadLink></div>
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/keyGenerator/KeyGeneratorPdf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const breakWord = (word: string) => {
}

export const KeyGeneratorPdf = (props: KeyGenerator) => {
const { publicKey, publicKeyImgUrl, privateKeyImgUrl, words } = props;
const { publicKey, publicKeyImgUrl, privateKeyImgUrl, words, privateKeyWIF } = props;
return (
<Document>
<Page size="A4" style={styles.body} wrap>
Expand All @@ -68,6 +68,7 @@ export const KeyGeneratorPdf = (props: KeyGenerator) => {
</View>
<View>
<Text style={styles.subtitle}>{en.pdf.privateKey}</Text>
<Text style={styles.text}>{breakWord(privateKeyWIF).map((word) => `${word}\n`)}</Text>
<Image style={styles.image} src={privateKeyImgUrl} />
<View style={styles.chipContainer}>
{words.map((word: string, index: number) => (<Text key={index} style={styles.chip}>{index + 1}. {word}</Text>))}
Expand Down
1 change: 1 addition & 0 deletions src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const en = {
multiline: 'Multiline',
publicKeyQrCode: 'Public key QR code',
privateKey: 'Private key',
privateKeyWIF: 'Private key in WIF',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merge, please add translations or at least placeholders. We don't want the users to see typical for JS "undefined"

phrase: 'Phrase',
privateKeyQrCode: 'Private key QR code',
generateNewKey: 'Generate new key',
Expand Down
9 changes: 9 additions & 0 deletions src/service/KeyGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pbkdf2Sync } from 'pbkdf2';
import * as ecurve from 'ecurve';
import { GeneratedKey } from '../components/pages/keyGenerator/KeyGeneratorContent';
const bigi = require('bigi');
const wif = require('wif');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see wif comes with types, so instead of

const wif = require('wif');

use import


const getBitsFromBytes = (bytes: Buffer) => {
let bits = '';
Expand Down Expand Up @@ -40,9 +41,17 @@ export const generateNewKeys = (): GeneratedKey => {
const privateKey = pbkdf2Sync(random128bits, random132bits.slice(0, 4), 1, 32, 'sha256');
const curve = ecurve.getCurveByName('secp256k1');
const publicKey = curve.G.multiply(bigi.fromBuffer(privateKey)).getEncoded(false).toString('hex');
let networkWIF;
if (process.env.REACT_APP_NETWORK === 'testnet' || process.env.REACT_APP_NETWORK === 'regtest') {
networkWIF = 0xef;
} else {
networkWIF = 0x80;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be clearer to extract it to function?


return {
publicKey,
privateKey: privateKey.toString('hex'),
privateKeyWIF: wif.encode(networkWIF, privateKey, false),
words: generatedWords || []
};
}