@@ -14,20 +14,10 @@ import Actions from './Point/Actions'
14import { BRIDGE_ERROR } from '../lib/error'
14import { BRIDGE_ERROR } from '../lib/error'
15import { Row, Col, Warning, Button, H1, H3 } from '../components/Base'
15import { Row, Col, Warning, Button, H1, H3 } from '../components/Base'
17+import { generateWallet, downloadWallet } from '../lib/invite'
17// for wallet generation
19// for wallet generation
18−import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
19−import * as more from 'more-entropy'
20−import lodash from 'lodash'
21import PaperCollateralRenderer from 'PaperCollateralRenderer'
20import PaperCollateralRenderer from 'PaperCollateralRenderer'
22−import JSZip from 'jszip'
23−import saveAs from 'file-saver'
24−import { MAX_GALAXY, MIN_STAR, MAX_STAR, MIN_PLANET,
25− GALAXY_ENTROPY_BITS, STAR_ENTROPY_BITS, PLANET_ENTROPY_BITS,
28− } from '../../walletgen/lib/constants'
29−const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8
30−const NEXT_STEP_NUM = 6;
32class InviteWallet extends React.Component {
22class InviteWallet extends React.Component {
@@ -46,7 +36,7 @@ class InviteWallet extends React.Component {
46 this.proceed = this.proceed.bind(this)
36 this.proceed = this.proceed.bind(this)
49− componentDidMount() {
39+ async componentDidMount() {
50 const { web3, wallet, contracts, setPointCursor } = this.props
40 const { web3, wallet, contracts, setPointCursor } = this.props
52 web3.chain(_ =>
42 web3.chain(_ =>
@@ -58,15 +48,17 @@ class InviteWallet extends React.Component {
58 console.log('incoming', incoming)
48 console.log('incoming', incoming)
60 let point = Nothing();
50 let point = Nothing();
51+ let wallet = Nothing();
61 if (incoming.length > 0) {
53 if (incoming.length > 0) {
62 let pointNum = parseInt(incoming[0]);
54 let pointNum = parseInt(incoming[0]);
63 point = Just(pointNum);
55 point = Just(pointNum);
64− this.generateWallet(pointNum);
56+ wallet = await generateWallet(pointNum);
65 if (incoming.length > 1) {
57 if (incoming.length > 1) {
66 //TODO notify user "...and others / ticket reusable"
58 //TODO notify user "...and others / ticket reusable"
69− this.setState({loaded: true, point: point})
61+ this.setState({loaded: true, point: point, wallet: Just(wallet)})
@@ -74,91 +66,11 @@ class InviteWallet extends React.Component {
77− //TODO pulled from walletgen/views/Generate and Download, put into lib
78− async generateWallet(point) {
79− const makeTicket = point => {
81− const bits = point < MIN_STAR
82− ? GALAXY_ENTROPY_BITS
85− : PLANET_ENTROPY_BITS
87− const bytes = bits / 8
88− const some = new Uint8Array(bytes)
89− window.crypto.getRandomValues(some)
91− const gen = new more.Generator()
93− return new Promise((resolve, reject) => {
94− gen.generate(bits, result => {
95− const chunked = lodash.chunk(result, 2)
96− const desired = chunked.slice(0, bytes) // only take required entropy
97− const more = lodash.flatMap(desired, arr => arr[0] ^ arr[1])
98− const entropy = lodash.zipWith(some, more, (x, y) => x ^ y)
99− const buf = Buffer.from(entropy)
100− const patq = ob.hex2patq(buf.toString('hex'))
102− reject('Entropy generation failed')
107− const genWallet = async (point, ticket, cb) => {
111− seedSize: SEED_LENGTH_BYTES,
115− boot: false //TODO should this generate networking keys here already?
118− const wallet = await kg.generateWallet(config);
120− // This is here to notify the anyone who opens console because the thread
121− // hangs, blocking UI updates so this cannot be doen in the UI
122− console.log('Generating Wallet for point address: ', point);
127− const ticket = await makeTicket(point);
129− const wallet = await genWallet(point, ticket);
131− this.setState({ wallet: Just(wallet) });
132− console.log('got wallet', wallet);
133− console.log('should start rendering now');
136− download() {
69+ async download() {
137− const zip = new JSZip();
70+ let result = await downloadWallet(this.state.paper)
138− //TODO the categories here aren't explained in bridge at all...
71+ this.setState({
140− const bin0 = this.state.paper.filter(item => item.bin === '0');
141− const bin1 = this.state.paper.filter(item => item.bin === '1');
142− const bin2 = this.state.paper.filter(item => item.bin === '2');
143− const bin3 = this.state.paper.filter(item => item.bin === '3');
144− const bin4 = this.state.paper.filter(item => item.bin === '4');
146− const bin0Folder = zip.folder("0. Public");
147− const bin1Folder = zip.folder("1. Very High Friction Custody");
148− const bin2Folder = zip.folder("2. High Friction Custody");
149− const bin3Folder = zip.folder("3. Medium Friction Custody");
150− const bin4Folder = zip.folder("4. Low Friction Custody");
152− bin0.forEach(item => bin0Folder.file(`${item.pageTitle}.png`, item.png))
153− bin1.forEach(item => bin1Folder.file(`${item.pageTitle}.png`, item.png));
154− bin2.forEach(item => bin2Folder.file(`${item.pageTitle}.png`, item.png));
155− bin3.forEach(item => bin3Folder.file(`${item.pageTitle}.png`, item.png));
156− bin4.forEach(item => bin4Folder.file(`${item.pageTitle}.png`, item.png));
158− zip.generateAsync({type:"blob"}).then((content) => {
159− saveAs(content, 'urbit-wallet.zip');
160− this.setState({ downloaded: true });
72+ downloaded: true
164 proceed() {
76 proceed() {
@@ -169,7 +81,6 @@ class InviteWallet extends React.Component {
171 render() {
83 render() {
173 const { loaded, point, wallet, paper, downloaded } = this.state;
84 const { loaded, point, wallet, paper, downloaded } = this.state;
175 let loading;
86 let loading;
@@ -189,24 +100,24 @@ class InviteWallet extends React.Component {
192− let pointOverview;
103+ // let pointOverview;
193− if (loaded && Just.hasInstance(point)) {
104+ // if (loaded && Just.hasInstance(point)) {
194− const name = ob.patp(point.value);
105+ // const name = ob.patp(point.value);
195− const sigil = pour({
106+ // const sigil = pour({
196− patp: name,
107+ // patp: name,
197− renderer: ReactSVGComponents,
108+ // renderer: ReactSVGComponents,
198− size: 256
109+ // size: 256
200− pointOverview = (
111+ // pointOverview = (
201− //TODO Passport display component
112+ // //TODO Passport display component
203− <div className={'mt-12 pt-6'}>
114+ // <div className={'mt-12 pt-6'}>
204− { sigil }
115+ // { sigil }
205− </div>
116+ // </div>
206− <H3><code>{ name }</code></H3>
117+ // <H3><code>{ name }</code></H3>
211 let downloadButtonContents = 'Download wallet';
122 let downloadButtonContents = 'Download wallet';
212 if ( Nothing.hasInstance(this.state.wallet) ||
123 if ( Nothing.hasInstance(this.state.wallet) ||
@@ -267,18 +178,7 @@ class InviteWallet extends React.Component {
275− <p>{'TODO copy. you need a wallet to receive the point into. download it below. also explanation of wallet files/storage'}</p>
280 { paperRenderer }
181 { paperRenderer }