1import React from 'react';
2import Maybe from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
4import * as ob from 'urbit-ob';
5import * as need from '../lib/need';
6import * as kg from 'urbit-key-generation/dist';
14} from '../components/old/Base';
16import StatelessTransaction from '../components/old/StatelessTransaction';
17import { attemptNetworkSeedDerivation } from '../lib/keys';
19import { addHexPrefix } from '../lib/wallet';
20import { compose } from '../lib/lib';
22import { withNetwork } from '../store/network';
23import { withWallet } from '../store/wallet';
24import { withPointCursor } from '../store/pointCursor';
25import { withPointCache } from '../store/pointCache';
27class SetKeys extends React.Component {
31 const point = need.pointCursor(props);
37 nondeterministicSeed: false,
39 cryptoSuiteVersion: 1,
41 isManagementSeed: false,
44 this.toggleDiscontinuity = this.toggleDiscontinuity.bind(this);
46 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
49 toggleDiscontinuity() {
50 this.setState({ discontinuity: !this.state.discontinuity });
54 const { props } = this;
58 const addr = need.address(props);
60 this.determineManagementSeed(props.contracts.value, addr);
63 async determineManagementSeed(ctrcs, addr) {
64 const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr);
67 isManagementSeed: managing.length !== 0,
71 //TODO use web3.utils.randomHex when it gets fixed, see web3.js#1490
75 for (var i = 0; i < len; i++) {
95 ][Math.floor(Math.random() * 16)];
103 let nondeterministicSeed = false;
105 const seed = await attemptNetworkSeedDerivation(next, this.props);
106 const newNetworkSeed = seed.matchWith({
108 nondeterministicSeed = true;
109 return this.randomHex(64);
116 nondeterministicSeed,
120 createUnsignedTxn() {
121 const { state, props } = this;
123 const validContracts = need.contracts(props);
125 const validPoint = need.pointCursor(props);
127 // TODO: move this to a lib for validating things
128 const hexRegExp = /[0-9A-Fa-f]{64}/g;
130 if (hexRegExp.test(state.newNetworkSeed)) {
131 // derive network keys
132 const pair = kg.deriveNetworkKeys(state.newNetworkSeed);
134 const pencr = addHexPrefix(pair.crypt.public);
135 const pauth = addHexPrefix(pair.auth.public);
137 const txn = azimuth.ecliptic.configureKeys(
146 return Maybe.Just(txn);
149 return Maybe.Nothing();
153 const { props, state } = this;
156 state.newNetworkSeed.length === 64 && state.newNetworkSeed.length === 64;
158 const pointDetails = need.fromPointCache(props, state.point);
164 {'Set Network Keys For '} <code>{`${ob.patp(state.point)}`}</code>
167 <P className="mt-10">
168 {`Set new authentication and encryption keys for your Arvo ship.`}
171 {state.nondeterministicSeed && (
173 <h3 className={'mb-2'}>{'Warning'}</h3>
174 {`Your network seed could not be derived automatically. We've
175 generated a random one for you, so you must download your Arvo
176 keyfile during this session after setting your keys.`}
180 {pointDetails.keyRevisionNumber === 0 ? (
182 <h3 className={'mb-2'}>{'Warning'}</h3>
183 {'Once these keys have been set, your point is considered ' +
184 "'linked'. This operation cannot be undone."}
192 onToggle={this.toggleDiscontinuity}
193 state={state.discontinuity}
194 label={`I have lost important off-chain data relating to this point
195 and need to do a hard reset.
196 (For example, rebooting an Arvo ship.)`}
199 <StatelessTransaction
203 canGenerate={canGenerate}
204 createUnsignedTxn={this.createUnsignedTxn}
205 newNetworkSeed={state.newNetworkSeed}
206 newRevision={parseInt(pointDetails.keyRevisionNumber) + 1}
214export default compose(
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list