on master help sign in
Make /lib/invite use wallet generator library

instead of re-implementing its logic locally. Also corrects some types in the wallet generator library.

commitcc050b66222240caeba4258c6284d35777b17169 authorFang <git@fang.io> dateFri 31 May 2019, 18:30 (7 years ago) parentd2c43d4
2 files changed+5−53
src/bridge/lib/invite.js+3−51 src/walletgen/lib/lib.js+2−2
src/bridge/lib/invite.js+3−51
@@ -6,6 +6,7 @@ import * as azimuth from 'azimuth-js'
66import * as more from 'more-entropy'
77import * as ob from 'urbit-ob'
88import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
9+import * as wg from '../../walletgen/lib/lib.js'
910import * as tank from './tank'
1011import { MIN_STAR, MIN_PLANET, SEED_ENTROPY_BITS,
1112 GALAXY_ENTROPY_BITS, STAR_ENTROPY_BITS, PLANET_ENTROPY_BITS,
@@ -79,58 +80,9 @@ const TRANSACTION_STATES = {
7980 },
8081}
8182
82−//TODO should be moved to lib/walletgen
8383async function generateWallet(point) {
84− const makeTicket = point => {
85−
86− const bits = point < MIN_STAR
87− ? GALAXY_ENTROPY_BITS
88− : point < MIN_PLANET
89− ? STAR_ENTROPY_BITS
90− : PLANET_ENTROPY_BITS
91−
92− const bytes = bits / 8
93− const some = new Uint8Array(bytes)
94− window.crypto.getRandomValues(some)
95−
96− const gen = new more.Generator()
97−
98− return new Promise((resolve, reject) => {
99− gen.generate(bits, result => {
100− const chunked = lodash.chunk(result, 2)
101− const desired = chunked.slice(0, bytes) // only take required entropy
102− const more = lodash.flatMap(desired, arr => arr[0] ^ arr[1])
103− const entropy = lodash.zipWith(some, more, (x, y) => x ^ y)
104− const buf = Buffer.from(entropy)
105− const patq = ob.hex2patq(buf.toString('hex'))
106− resolve(patq)
107− reject('Entropy generation failed')
108− })
109− })
110− }
111−
112− const genWallet = async (point, ticket, cb) => {
113−
114− const config = {
115− ticket: ticket,
116− seedSize: SEED_LENGTH_BYTES,
117− ship: point,
118− password: '',
119− revisions: {},
120− boot: false //TODO should this generate networking keys here already?
121− };
122−
123− const wallet = await kg.generateWallet(config);
124−
125− // This is here to notify the anyone who opens console because the thread
126− // hangs, blocking UI updates so this cannot be doen in the UI
127− console.log('Generating Wallet for point address: ', point);
128−
129− return wallet;
130− }
131−
132− const ticket = await makeTicket(point);
133− const wallet = await genWallet(point, ticket);
84+ const ticket = await wg.makeTicket(point);
85+ const wallet = await wg.generateWallet(point, ticket);
13486 return wallet;
13587}
13688
src/walletgen/lib/lib.js+2−2
@@ -53,8 +53,8 @@ const generateWallet = async (point, ticket, boot) => {
5353
5454 const wallet = await kg.generateWallet(config);
5555
56− // This is here to notify the anyone who opens console because the thread
57− // hangs, blocking UI updates so this cannot be doen in the UI
56+ // This is here to notify anyone who opens console because the thread
57+ // hangs, blocking UI updates so this cannot be done in the UI
5858 console.log('Generating Wallet for point address: ', point);
5959
6060 return wallet;