on master help sign in
test: derive next revision when setting keys
8282b79Matt Condon (shrugs)
src/lib/keys.js+1
@@ -126,6 +126,7 @@ export const deriveNetworkSeedFromManagementMnemonic = async (
126
126
127/**
127/**
128 * @param {string} mnemonic
128 * @param {string} mnemonic
129+ * @param {string} passphrase
129 * @param {number} revision
130 * @param {number} revision
130 * @return {Promise<Maybe<string>>}
131 * @return {Promise<Maybe<string>>}
131 */
132 */
src/lib/useKeyfileGenerator.js+5−1
@@ -38,10 +38,12 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
38 (isOwner || isManagementProxy) && hasNetworkingKeys && !!keyfile;
38 (isOwner || isManagementProxy) && hasNetworkingKeys && !!keyfile;
39
39
40 const generate = useCallback(async () => {
40 const generate = useCallback(async () => {
41− console.log('attempting generation for network revision', networkRevision);
42 if (!hasNetworkingKeys) {
41 if (!hasNetworkingKeys) {
43 setGenerating(false);
42 setGenerating(false);
44 setNotice('Networking keys not yet set.');
43 setNotice('Networking keys not yet set.');
44+ console.log(
45+ `no networking keys available for revision ${networkRevision}`
46+ );
45 return;
47 return;
46 }
48 }
47
49
@@ -60,6 +62,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
60 setNotice(
62 setNotice(
61 'Custom or nondeterministic networking keys cannot be re-downloaded.'
63 'Custom or nondeterministic networking keys cannot be re-downloaded.'
62 );
64 );
65+ console.log(`seed is nondeterminable for revision ${networkRevision}`);
63 return;
66 return;
64 }
67 }
65
68
@@ -70,6 +73,7 @@ export default function useKeyfileGenerator(manualNetworkSeed) {
70 if (!keysMatchChain(pair, _details)) {
73 if (!keysMatchChain(pair, _details)) {
71 setGenerating(false);
74 setGenerating(false);
72 setNotice('Derived networking keys do not match on-chain details.');
75 setNotice('Derived networking keys do not match on-chain details.');
76+ console.log(`keys do not match details for revision ${networkRevision}`);
73 return;
77 return;
74 }
78 }
75
79
src/views/Admin/AdminNetworkingKeys.js+12−9
@@ -59,9 +59,12 @@ function useSetKeys() {
59 const { pointCursor } = usePointCursor();
59 const { pointCursor } = usePointCursor();
60 const { syncOwnedPoint, getDetails } = usePointCache();
60 const { syncOwnedPoint, getDetails } = usePointCache();
61 const { contracts } = useNetwork();
61 const { contracts } = useNetwork();
62+
62 const _point = need.point(pointCursor);
63 const _point = need.point(pointCursor);
63 const _contracts = need.contracts(contracts);
64 const _contracts = need.contracts(contracts);
65+ const _details = need.details(getDetails(_point));
64
66
67+ const networkRevision = parseInt(_details.keyRevisionNumber, 10);
65 const randomSeed = useRef();
68 const randomSeed = useRef();
66
69
67 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
70 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
@@ -92,21 +95,21 @@ function useSetKeys() {
92 }
95 }
93 }, [_point, confirmed, syncOwnedPoint]);
96 }, [_point, confirmed, syncOwnedPoint]);
94
97
95− const getSeed = useCallback(
98+ const buildNetworkSeed = useCallback(
96 async manualSeed => {
99 async manualSeed => {
97− const details = need.details(getDetails(_point));
98− const networkRevision = parseInt(details.keyRevisionNumber, 10);
99−
100 if (manualSeed !== undefined) {
100 if (manualSeed !== undefined) {
101 setNdNetworkSeed(manualSeed);
101 setNdNetworkSeed(manualSeed);
102 return manualSeed;
102 return manualSeed;
103 } else {
103 } else {
104+ const newNetworkRevision = networkRevision + 1;
105+ console.log(`deriving seed with revision ${newNetworkRevision}`);
106+
104 const networkSeed = await attemptNetworkSeedDerivation({
107 const networkSeed = await attemptNetworkSeedDerivation({
105 urbitWallet,
108 urbitWallet,
106 wallet,
109 wallet,
107 authMnemonic,
110 authMnemonic,
108− details,
111+ details: _details,
109− revision: networkRevision,
112+ revision: newNetworkRevision,
110 });
113 });
111
114
112 if (Just.hasInstance(networkSeed)) {
115 if (Just.hasInstance(networkSeed)) {
@@ -119,12 +122,12 @@ function useSetKeys() {
119 return randomSeed.current;
122 return randomSeed.current;
120 }
123 }
121 },
124 },
122− [_point, authMnemonic, getDetails, urbitWallet, wallet]
125+ [_details, authMnemonic, networkRevision, urbitWallet, wallet]
123 );
126 );
124
127
125 const construct = useCallback(
128 const construct = useCallback(
126 async (manualSeed, isDiscontinuity) => {
129 async (manualSeed, isDiscontinuity) => {
127− const seed = await getSeed(manualSeed);
130+ const seed = await buildNetworkSeed(manualSeed);
128 const pair = deriveNetworkKeys(seed);
131 const pair = deriveNetworkKeys(seed);
129
132
130 const txn = azimuth.ecliptic.configureKeys(
133 const txn = azimuth.ecliptic.configureKeys(
@@ -138,7 +141,7 @@ function useSetKeys() {
138
141
139 _construct(txn);
142 _construct(txn);
140 },
143 },
141− [_construct, _contracts, _point, getSeed]
144+ [_construct, _contracts, _point, buildNetworkSeed]
142 );
145 );
143
146
144 return {
147 return {