1import ob from 'urbit-ob';
2import kg from 'urbit-key-generation';
3import * as more from 'more-entropy';
4import { chunk, flatMap, zipWith } from 'lodash';
5import { shas } from 'lib/networkCode';
16import Worker from 'worker';
18const worker = new Worker();
20const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8;
22const getTicketBitSize = point =>
27 : PLANET_ENTROPY_BITS;
29// returns a promise for a ticket string
30export const makeTicket = point => {
31 const bits = getTicketBitSize(point);
33 const bytes = bits / 8;
34 const some = new Uint8Array(bytes);
35 window.crypto.getRandomValues(some);
37 const gen = new more.Generator();
39 return new Promise((resolve, reject) => {
40 gen.generate(bits, result => {
41 const chunked = chunk(result, 2);
42 const desired = chunked.slice(0, bytes); // only take required entropy
43 const more = flatMap(desired, arr => arr[0] ^ arr[1]);
44 const entropy = zipWith(some, more, (x, y) => x ^ y);
45 const buf = Buffer.from(entropy);
46 const patq = ob.hex2patq(buf.toString('hex'));
48 reject('Entropy generation failed');
53export const makeDeterministicTicket = (point, seed) => {
54 const bits = getTicketBitSize(point);
56 const bytes = bits / 8;
58 const pointSalt = Buffer.concat([
59 Buffer.from(point.toString()),
60 Buffer.from('invites'),
62 const entropy = shas(Buffer.from(seed, 'hex'), pointSalt);
64 const buf = entropy.slice(0, bytes);
65 const patq = ob.hex2patq(buf.toString('hex'));
69// return a wallet object
70export const generateWallet = async (point, ticket, boot) => {
73 seedSize: SEED_LENGTH_BYTES,
80 // This is here to notify anyone who opens console because the thread
81 // hangs, blocking UI updates so this cannot be done in the UI
82 console.log('Generating Wallet for point address: ', point);
84 return new Promise(async resolve => {
85 // Use a web worker to process the data
86 console.log(1, config)
87 const processed = await worker.generateWallet(JSON.stringify(config));
93export const generateOwnershipWallet = async (ship, ticket) => {
94 return kg.generateOwnershipWallet({ ship, ticket });
97// temporary wallets need to be derivable from just the ticket,
98// so we always use ~zod as the wallet point.
99export const generateTemporaryOwnershipWallet = ticket =>
100 generateOwnershipWallet(ZOD, ticket);
102export const generateTemporaryTicketAndWallet = async point => {
103 const ticket = await makeTicket(point);
104 const owner = await generateOwnershipWallet(ZOD, ticket);
106 return { ticket, owner };
109export const generateTemporaryDeterministicWallet = async (point, seed) => {
110 const ticket = makeDeterministicTicket(point, seed);
111 const owner = await generateOwnershipWallet(ZOD, ticket);
113 return { ticket, owner };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list