on master help sign in
test: derive next revision when setting keys
commit8282b799eaaf327b15ecf61e8b6f6ce690a88213 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateThu 18 Jul 2019, 13:42 (7 years ago) parent7bd5ae0
3 files changed+18−10
src/lib/keys.js+1 src/lib/useKeyfileGenerator.js+5−1 src/views/Admin/AdminNetworkingKeys.js+12−9
src/lib/keys.js+1
@@ -126,6 +126,7 @@ export const deriveNetworkSeedFromManagementMnemonic = async (
126126
127127/**
128128 * @param {string} mnemonic
129+ * @param {string} passphrase
129130 * @param {number} revision
130131 * @return {Promise<Maybe<string>>}
131132 */
src/lib/useKeyfileGenerator.js+5−1
@@ -38,10 +38,12 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
3838 (isOwner || isManagementProxy) && hasNetworkingKeys && !!keyfile;
3939
4040 const generate = useCallback(async () => {
41− console.log('attempting generation for network revision', networkRevision);
4241 if (!hasNetworkingKeys) {
4342 setGenerating(false);
4443 setNotice('Networking keys not yet set.');
44+ console.log(
45+ `no networking keys available for revision ${networkRevision}`
46+ );
4547 return;
4648 }
4749
@@ -60,6 +62,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
6062 setNotice(
6163 'Custom or nondeterministic networking keys cannot be re-downloaded.'
6264 );
65+ console.log(`seed is nondeterminable for revision ${networkRevision}`);
6366 return;
6467 }
6568
@@ -70,6 +73,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
7073 if (!keysMatchChain(pair, _details)) {
7174 setGenerating(false);
7275 setNotice('Derived networking keys do not match on-chain details.');
76+ console.log(`keys do not match details for revision ${networkRevision}`);
7377 return;
7478 }
7579
src/views/Admin/AdminNetworkingKeys.js+12−9
@@ -59,9 +59,12 @@ function useSetKeys() {
5959 const { pointCursor } = usePointCursor();
6060 const { syncOwnedPoint, getDetails } = usePointCache();
6161 const { contracts } = useNetwork();
62+
6263 const _point = need.point(pointCursor);
6364 const _contracts = need.contracts(contracts);
65+ const _details = need.details(getDetails(_point));
6466
67+ const networkRevision = parseInt(_details.keyRevisionNumber, 10);
6568 const randomSeed = useRef();
6669
6770 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
@@ -92,21 +95,21 @@ function useSetKeys() {
9295 }
9396 }, [_point, confirmed, syncOwnedPoint]);
9497
95− const getSeed = useCallback(
98+ const buildNetworkSeed = useCallback(
9699 async manualSeed => {
97− const details = need.details(getDetails(_point));
98− const networkRevision = parseInt(details.keyRevisionNumber, 10);
99−
100100 if (manualSeed !== undefined) {
101101 setNdNetworkSeed(manualSeed);
102102 return manualSeed;
103103 } else {
104+ const newNetworkRevision = networkRevision + 1;
105+ console.log(`deriving seed with revision ${newNetworkRevision}`);
106+
104107 const networkSeed = await attemptNetworkSeedDerivation({
105108 urbitWallet,
106109 wallet,
107110 authMnemonic,
108− details,
109− revision: networkRevision,
111+ details: _details,
112+ revision: newNetworkRevision,
110113 });
111114
112115 if (Just.hasInstance(networkSeed)) {
@@ -119,12 +122,12 @@ function useSetKeys() {
119122 return randomSeed.current;
120123 }
121124 },
122− [_point, authMnemonic, getDetails, urbitWallet, wallet]
125+ [_details, authMnemonic, networkRevision, urbitWallet, wallet]
123126 );
124127
125128 const construct = useCallback(
126129 async (manualSeed, isDiscontinuity) => {
127− const seed = await getSeed(manualSeed);
130+ const seed = await buildNetworkSeed(manualSeed);
128131 const pair = deriveNetworkKeys(seed);
129132
130133 const txn = azimuth.ecliptic.configureKeys(
@@ -138,7 +141,7 @@ function useSetKeys() {
138141
139142 _construct(txn);
140143 },
141− [_construct, _contracts, _point, getSeed]
144+ [_construct, _contracts, _point, buildNetworkSeed]
142145 );
143146
144147 return {