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';
7import { Row, Col, H1, P, Warning, CheckboxButton } from '../components/Base';
9import StatelessTransaction from '../components/StatelessTransaction';
10import { attemptNetworkSeedDerivation } from '../lib/keys';
12import { addHexPrefix } from '../lib/wallet';
13import { compose } from '../lib/lib';
15import { withNetwork } from '../store/network';
16import { withWallet } from '../store/wallet';
17import { withPointCursor } from '../store/pointCursor';
18import { withPointCache } from '../store/pointCache';
20class SetKeys extends React.Component {
24 const point = need.pointCursor(props);
30 nondeterministicSeed: false,
32 cryptoSuiteVersion: 1,
34 isManagementSeed: false,
37 this.toggleDiscontinuity = this.toggleDiscontinuity.bind(this);
39 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
42 toggleDiscontinuity() {
43 this.setState({ discontinuity: !this.state.discontinuity });
47 const { props } = this;
51 const addr = need.address(props);
53 this.determineManagementSeed(props.contracts.value, addr);
56 async determineManagementSeed(ctrcs, addr) {
57 const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr);
60 isManagementSeed: managing.length !== 0,
64 //TODO use web3.utils.randomHex when it gets fixed, see web3.js#1490
68 for (var i = 0; i < len; i++) {
88 ][Math.floor(Math.random() * 16)];
96 let nondeterministicSeed = false;
98 const seed = await attemptNetworkSeedDerivation(next, this.props);
99 const newNetworkSeed = seed.matchWith({
101 nondeterministicSeed = true;
102 return this.randomHex(64);
109 nondeterministicSeed,
113 createUnsignedTxn() {
114 const { state, props } = this;
116 const validContracts = need.contracts(props);
118 const validPoint = need.pointCursor(props);
120 // TODO: move this to a lib for validating things
121 const hexRegExp = /[0-9A-Fa-f]{64}/g;
123 if (hexRegExp.test(state.newNetworkSeed)) {
124 // derive network keys
125 const pair = kg.deriveNetworkKeys(state.newNetworkSeed);
127 const pencr = addHexPrefix(pair.crypt.public);
128 const pauth = addHexPrefix(pair.auth.public);
130 const txn = azimuth.ecliptic.configureKeys(
139 return Maybe.Just(txn);
142 return Maybe.Nothing();
146 const { props, state } = this;
149 state.newNetworkSeed.length === 64 && state.newNetworkSeed.length === 64;
151 const pointDetails = need.fromPointCache(props, state.point);
157 {'Set Network Keys For '} <code>{`${ob.patp(state.point)}`}</code>
160 <P className="mt-10">
161 {`Set new authentication and encryption keys for your Arvo ship.`}
164 {state.nondeterministicSeed && (
166 <h3 className={'mb-2'}>{'Warning'}</h3>
167 {`Your network seed could not be derived automatically. We've
168 generated a random one for you, so you must download your Arvo
169 keyfile during this session after setting your keys.`}
173 {pointDetails.keyRevisionNumber === 0 ? (
175 <h3 className={'mb-2'}>{'Warning'}</h3>
176 {'Once these keys have been set, your point is considered ' +
177 "'linked'. This operation cannot be undone."}
185 onToggle={this.toggleDiscontinuity}
186 state={state.discontinuity}
187 label={`I have lost important off-chain data relating to this point
188 and need to do a hard reset.
189 (For example, rebooting an Arvo ship.)`}
192 <StatelessTransaction
196 canGenerate={canGenerate}
197 createUnsignedTxn={this.createUnsignedTxn}
198 newNetworkSeed={state.newNetworkSeed}
199 newRevision={parseInt(pointDetails.keyRevisionNumber) + 1}
207export 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