1import ob from 'urbit-ob';
2import kg from 'urbit-key-generation';
3import * as more from 'more-entropy';
4import { chunk, flatMap, zipWith } from 'lodash';
5import { shax, shas } from 'lib/networkCode';
17const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8;
19const getTicketBitSize = point =>
24 : PLANET_ENTROPY_BITS;
26// returns a promise for a ticket string
27export const makeTicket = point => {
28 const bits = getTicketBitSize(point);
30 const bytes = bits / 8;
31 const some = new Uint8Array(bytes);
32 window.crypto.getRandomValues(some);
34 const gen = new more.Generator();
36 return new Promise((resolve, reject) => {
37 gen.generate(bits, result => {
38 const chunked = chunk(result, 2);
39 const desired = chunked.slice(0, bytes); // only take required entropy
40 const more = flatMap(desired, arr => arr[0] ^ arr[1]);
41 const entropy = zipWith(some, more, (x, y) => x ^ y);
42 const buf = Buffer.from(entropy);
43 const patq = ob.hex2patq(buf.toString('hex'));
45 reject('Entropy generation failed');
50export const makeDeterministicTicket = (point, seed) => {
51 const bits = getTicketBitSize(point);
53 const bytes = bits / 8;
55 const pointSalt = Buffer.concat([
56 Buffer.from(point.toString()),
57 Buffer.from('invites'),
59 const entropy = shas(Buffer.from(seed, 'hex'), pointSalt);
61 const buf = entropy.slice(0, bytes);
62 const patq = ob.hex2patq(buf.toString('hex'));
66// return a wallet object
67export const generateWallet = async (point, ticket, boot) => {
70 seedSize: SEED_LENGTH_BYTES,
77 // This is here to notify anyone who opens console because the thread
78 // hangs, blocking UI updates so this cannot be done in the UI
79 console.log('Generating Wallet for point address: ', point);
81 const wallet = await kg.generateWallet(config);
86export const generateOwnershipWallet = (ship, ticket) =>
87 kg.generateOwnershipWallet({ ship, ticket });
89// temporary wallets need to be derivable from just the ticket,
90// so we always use ~zod as the wallet point.
91export const generateTemporaryOwnershipWallet = ticket =>
92 generateOwnershipWallet(ZOD, ticket);
94export const generateTemporaryTicketAndWallet = async point => {
95 const ticket = await makeTicket(point);
96 const owner = await generateOwnershipWallet(ZOD, ticket);
98 return { ticket, owner };
101export const generateTemporaryDeterministicWallet = async (point, seed) => {
102 const ticket = makeDeterministicTicket(point, seed);
103 const owner = await generateOwnershipWallet(ZOD, ticket);
105 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