1import ob from 'urbit-ob';
2import kg from 'urbit-key-generation';
3// @ts-expect-error no types available for more-entropy
4import * as more from 'more-entropy';
5import { chunk, flatMap, zipWith } from 'lodash';
6import { shas } from 'lib/networkCode';
7import { walletgenWorker } from 'worker/';
18import { stripHexPrefix } from './utils/address';
20const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8;
22const getTicketBitSize = (point: number) =>
27 : PLANET_ENTROPY_BITS;
29// returns a promise for a ticket string
30export const makeTicket = (point: number): Promise<string> => {
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<string>((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: number, seed: string) => {
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 normalizedSeed = stripHexPrefix(seed);
63 const entropy = shas(Buffer.from(normalizedSeed, 'hex'), pointSalt);
65 const buf = entropy.slice(0, bytes);
66 const patq = ob.hex2patq(buf.toString('hex'));
70// return a wallet object
71export const generateWallet = async (
79 seedSize: SEED_LENGTH_BYTES,
86 // This is here to notify anyone who opens console because the thread
87 // hangs, blocking UI updates so this cannot be done in the UI
88 console.log('Generating Wallet for point address: ', point);
90 return new Promise(async (resolve, reject) => {
91 // Use a web worker to process the data
93 const processed = await walletgenWorker.generate(JSON.stringify(config));
101export const generateOwnershipWallet = async (ship: number, ticket: string) => {
102 return kg.generateOwnershipWallet({ ship, ticket });
105// temporary wallets need to be derivable from just the ticket,
106// so we always use ~zod as the wallet point.
107export const generateTemporaryOwnershipWallet = (ticket: string) =>
108 generateOwnershipWallet(ZOD, ticket);
110export const generateTemporaryTicketAndWallet = async (point: number) => {
111 const ticket = await makeTicket(point);
112 const owner = await generateOwnershipWallet(ZOD, ticket);
114 return { ticket, owner };
117export const generateTemporaryDeterministicWallet = async (
121 const ticket = makeDeterministicTicket(point, seed);
122 const owner = await generateOwnershipWallet(ZOD, ticket);
124 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