on master help sign in
wallet-gen: add deterministic ticket generator
commit6a7e3db91f0b972ebe3f1adbb38b64bb1b9543e5 authorLiam Fitzgerald <liam@urizen.co> dateTue 31 Mar 2020, 18:01 (7 years ago) parent57ad0ff
2 files changed+23−1
src/lib/networkCode.js+1−1 src/lib/walletgen.js+22
src/lib/networkCode.js+1−1
@@ -18,7 +18,7 @@ function buf2hex(buf) {
1818 .toString('hex');
1919}
2020
21−function shas(buf, salt) {
21+export function shas(buf, salt) {
2222 return shax(xor(salt, shax(buf)));
2323}
2424
src/lib/walletgen.js+22
@@ -2,6 +2,7 @@ import ob from 'urbit-ob';
22import kg from 'urbit-key-generation';
33import * as more from 'more-entropy';
44import { chunk, flatMap, zipWith } from 'lodash';
5+import { shax, shas } from 'lib/networkCode';
56
67import {
78 MIN_STAR,
@@ -44,6 +45,27 @@ export const makeTicket = point => {
4445 });
4546};
4647
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+
4769// return a wallet object
4870export const generateWallet = async (point, ticket, boot) => {
4971 const config = {