on master help sign in
wallet-gen: add deterministic ticket generator
6a7e3dbLiam Fitzgerald
src/lib/networkCode.js+1−1
@@ -18,7 +18,7 @@ function buf2hex(buf) {
18 .toString('hex');
18 .toString('hex');
19}
19}
20
20
21−function shas(buf, salt) {
21+export function shas(buf, salt) {
22 return shax(xor(salt, shax(buf)));
22 return shax(xor(salt, shax(buf)));
23}
23}
24
24
src/lib/walletgen.js+22
@@ -2,6 +2,7 @@ import ob from 'urbit-ob';
2import kg from 'urbit-key-generation';
2import kg from 'urbit-key-generation';
3import * as more from 'more-entropy';
3import * as more from 'more-entropy';
4import { chunk, flatMap, zipWith } from 'lodash';
4import { chunk, flatMap, zipWith } from 'lodash';
5+import { shax, shas } from 'lib/networkCode';
5
6
6import {
7import {
7 MIN_STAR,
8 MIN_STAR,
@@ -44,6 +45,27 @@ export const makeTicket = point => {
44 });
45 });
45};
46};
46
47
48+export const makeDeterministicTicket = (point, seed) => {
49+ const bits =
50+ point < MIN_STAR
51+ ? GALAXY_ENTROPY_BITS
52+ : point < MIN_PLANET
53+ ? STAR_ENTROPY_BITS
54+ : PLANET_ENTROPY_BITS;
55+
56+ const bytes = bits / 8;
57+
58+ const pointSalt = Buffer.concat([
59+ Buffer.from(point.toString()),
60+ Buffer.from('invites'),
61+ ]);
62+ const entropy = shas(seed, pointSalt);
63+
64+ const buf = entropy.slice(0, bytes);
65+ const patq = ob.hex2patq(buf.toString('hex'));
66+ return patq;
67+};
68+
47// return a wallet object
69// return a wallet object
48export const generateWallet = async (point, ticket, boot) => {
70export const generateWallet = async (point, ticket, boot) => {
49 const config = {
71 const config = {