on master help sign in
keyfiles: make all keyfiles deterministic
f6b288dLiam Fitzgerald
migrations/1_migration.js+3
@@ -119,6 +119,7 @@ module.exports = async function(deployer) {
119 await lsr.deposit(user1, offset);
119 await lsr.deposit(user1, offset);
120 await csr.deposit(user1, offset + 1);
120 await csr.deposit(user1, offset + 1);
121 }
121 }
122+ break;
122 case 'INVITES':
123 case 'INVITES':
123 await ecliptic.createGalaxy(0, own);
124 await ecliptic.createGalaxy(0, own);
124 await ecliptic.configureKeys(0, '0x123', '0x456', 1, false);
125 await ecliptic.configureKeys(0, '0x123', '0x456', 1, false);
@@ -130,6 +131,7 @@ module.exports = async function(deployer) {
130 await ecliptic.spawn(131328, own);
131 await ecliptic.spawn(131328, own);
131 await ecliptic.spawn(512, own);
132 await ecliptic.spawn(512, own);
132 await sending.setPoolSize(256, 65792, 1000);
133 await sending.setPoolSize(256, 65792, 1000);
134+ break;
133 case 'RESIDENTS':
135 case 'RESIDENTS':
134 await ecliptic.createGalaxy(0, own);
136 await ecliptic.createGalaxy(0, own);
135 await ecliptic.configureKeys(0, '0x123', '0x456', 1, false);
137 await ecliptic.configureKeys(0, '0x123', '0x456', 1, false);
@@ -141,6 +143,7 @@ module.exports = async function(deployer) {
141 await ecliptic.spawn(offset + 256, own);
143 await ecliptic.spawn(offset + 256, own);
142 await ecliptic.transferPoint(offset + 256, user1, false);
144 await ecliptic.transferPoint(offset + 256, user1, false);
143 }
145 }
146+ break;
144
147
145 default:
148 default:
146 return;
149 return;
src/lib/keys.js+17−10
@@ -6,6 +6,7 @@ import * as serial from '../nockjs/serial';
6import * as kg from 'urbit-key-generation';
6import * as kg from 'urbit-key-generation';
7
7
8import { eqAddr, addHexPrefix } from './wallet';
8import { eqAddr, addHexPrefix } from './wallet';
9+import { shas } from './networkCode';
9
10
10// the curve param for the network keys
11// the curve param for the network keys
11export const NETWORK_KEY_CURVE_PARAMETER = '42';
12export const NETWORK_KEY_CURVE_PARAMETER = '42';
@@ -141,27 +142,33 @@ const deriveNetworkSeedFromMnemonic = async (
141 return Just(await kg.deriveNetworkSeed(mnemonic, passphrase, revision - 1));
142 return Just(await kg.deriveNetworkSeed(mnemonic, passphrase, revision - 1));
142};
143};
143
144
145+/**
146+ * @param {string} authToken
147+ * @param {number} number
148+ * @return {Maybe<string>}
149+ */
150+export const deriveNetworkSeedFromAuthToken = (authToken, revision, point) => {
151+ const networkSeed = shas(authToken, `revision-${point}-${revision}`)
152+ .toString('hex')
153+ .slice(0, 32);
154+ return Just(networkSeed);
155+};
156+
144/**
157/**
145 * @return {Promise<Maybe<string>>}
158 * @return {Promise<Maybe<string>>}
146 */
159 */
147export const attemptNetworkSeedDerivation = async ({
160export const attemptNetworkSeedDerivation = async ({
148 urbitWallet,
161 urbitWallet,
149− wallet,
162+ point,
150− authMnemonic,
163+ authToken,
151− details,
152 revision,
164 revision,
153}) => {
165}) => {
154 if (Just.hasInstance(urbitWallet)) {
166 if (Just.hasInstance(urbitWallet)) {
155 return await deriveNetworkSeedFromUrbitWallet(urbitWallet.value, revision);
167 return await deriveNetworkSeedFromUrbitWallet(urbitWallet.value, revision);
156 }
168 }
157
169
158− if (Just.hasInstance(wallet) && Just.hasInstance(authMnemonic)) {
170+ if (Just.hasInstance(authToken)) {
159− return await deriveNetworkSeedFromManagementMnemonic(
171+ return deriveNetworkSeedFromAuthToken(authToken.value, point, revision);
160− wallet.value,
161− authMnemonic.value,
162− details,
163− revision
164− );
165 }
172 }
166
173
167 return Nothing();
174 return Nothing();
src/lib/useInviter.js+1
@@ -204,6 +204,7 @@ const useInviter = () => {
204 return { invites: confirmedInvites };
204 return { invites: confirmedInvites };
205 },
205 },
206 [
206 [
207+ authToken,
207 contracts,
208 contracts,
208 gasPrice,
209 gasPrice,
209 networkType,
210 networkType,
src/lib/useKeyfileGenerator.js+4−6
@@ -20,7 +20,7 @@ import useCurrentPermissions from './useCurrentPermissions';
20import convertToInt from './convertToInt';
20import convertToInt from './convertToInt';
21
21
22export default function useKeyfileGenerator(manualNetworkSeed) {
22export default function useKeyfileGenerator(manualNetworkSeed) {
23− const { urbitWallet, wallet, authMnemonic } = useWallet();
23+ const { urbitWallet, wallet, authMnemonic, authToken } = useWallet();
24 const { pointCursor } = usePointCursor();
24 const { pointCursor } = usePointCursor();
25 const { getDetails } = usePointCache();
25 const { getDetails } = usePointCache();
26
26
@@ -60,9 +60,8 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
60 ? Just(manualNetworkSeed)
60 ? Just(manualNetworkSeed)
61 : await attemptNetworkSeedDerivation({
61 : await attemptNetworkSeedDerivation({
62 urbitWallet,
62 urbitWallet,
63− wallet,
63+ authToken,
64− authMnemonic,
64+ point: _point,
65− details: _details,
66 revision: networkRevision,
65 revision: networkRevision,
67 });
66 });
68
67
@@ -95,11 +94,10 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
95 hasNetworkingKeys,
94 hasNetworkingKeys,
96 manualNetworkSeed,
95 manualNetworkSeed,
97 urbitWallet,
96 urbitWallet,
98− wallet,
99− authMnemonic,
100 setCode,
97 setCode,
101 details,
98 details,
102 _point,
99 _point,
100+ authToken,
103 ]);
101 ]);
104
102
105 const filename = useMemo(() => {
103 const filename = useMemo(() => {
src/views/Invite/Cohort.js+1−1
@@ -205,7 +205,7 @@ function CohortMemberExpanded({ point, className, ...rest }) {
205 }
205 }
206 };
206 };
207 fetchWallet();
207 fetchWallet();
208− }, [codeVisible]);
208+ }, [authToken, codeVisible, contracts, details, point]);
209
209
210 useEffect(() => {
210 useEffect(() => {
211 setCodeVisible(false);
211 setCodeVisible(false);
src/views/IssueChild.js+1−1
@@ -117,7 +117,7 @@ export default function IssueChild() {
117 },
117 },
118 validateForm
118 validateForm
119 ),
119 ),
120− [validateForm]
120+ [_point, validateForm]
121 );
121 );
122
122
123 const onValues = useCallback(
123 const onValues = useCallback(
src/views/UrbitOS/NetworkingKeys.js+4−12
@@ -38,7 +38,7 @@ import FormError from 'form/FormError';
38import convertToInt from 'lib/convertToInt';
38import convertToInt from 'lib/convertToInt';
39
39
40function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
40function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
41− const { urbitWallet, wallet, authMnemonic } = useWallet();
41+ const { urbitWallet, wallet, authMnemonic, authToken } = useWallet();
42 const { pointCursor } = usePointCursor();
42 const { pointCursor } = usePointCursor();
43 const { syncDetails, syncRekeyDate, getDetails } = usePointCache();
43 const { syncDetails, syncRekeyDate, getDetails } = usePointCache();
44 const { contracts } = useNetwork();
44 const { contracts } = useNetwork();
@@ -68,9 +68,8 @@ function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
68
68
69 const networkSeed = await attemptNetworkSeedDerivation({
69 const networkSeed = await attemptNetworkSeedDerivation({
70 urbitWallet,
70 urbitWallet,
71− wallet,
71+ point: _point,
72− authMnemonic,
72+ authToken,
73− details: _details,
74 revision: newNetworkRevision,
73 revision: newNetworkRevision,
75 });
74 });
76
75
@@ -84,14 +83,7 @@ function useSetKeys(manualNetworkSeed, setManualNetworkSeed) {
84 return randomSeed.current;
83 return randomSeed.current;
85 }
84 }
86 },
85 },
87− [
86+ [setManualNetworkSeed, networkRevision, urbitWallet, _point, authToken]
88− _details,
89− authMnemonic,
90− networkRevision,
91− setManualNetworkSeed,
92− urbitWallet,
93− wallet,
94− ]
95 );
87 );
96
88
97 const { completed: _completed, ...rest } = useEthereumTransaction(
89 const { completed: _completed, ...rest } = useEthereumTransaction(