1import React from 'react';
2import { Just, Nothing } 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 { H1, P, Warning, CheckboxButton } from '../components/old/Base';
9import StatelessTransaction from '../components/old/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';
19import View from 'components/View';
21class SetKeys extends React.Component {
25 const point = need.point(props.pointCursor);
31 nondeterministicSeed: false,
33 cryptoSuiteVersion: 1,
35 isManagementSeed: false,
38 this.toggleDiscontinuity = this.toggleDiscontinuity.bind(this);
40 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
43 toggleDiscontinuity() {
44 this.setState({ discontinuity: !this.state.discontinuity });
48 const { props } = this;
52 const addr = need.addressFromWallet(props.wallet);
54 this.determineManagementSeed(props.contracts.value, addr);
57 async determineManagementSeed(ctrcs, addr) {
58 const managing = await azimuth.azimuth.getManagerFor(ctrcs, addr);
61 isManagementSeed: managing.length !== 0,
65 //TODO use web3.utils.randomHex when it gets fixed, see web3.js#1490
69 for (var i = 0; i < len; i++) {
89 ][Math.floor(Math.random() * 16)];
97 let nondeterministicSeed = false;
99 const seed = await attemptNetworkSeedDerivation(next, this.props);
100 const newNetworkSeed = seed.matchWith({
102 nondeterministicSeed = true;
103 return this.randomHex(64);
110 nondeterministicSeed,
114 createUnsignedTxn() {
115 const { state, props } = this;
117 const validContracts = need.contracts(props.contracts);
118 const validPoint = need.point(props.pointCursor);
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(
146 const { props, state } = this;
149 state.newNetworkSeed.length === 64 && state.newNetworkSeed.length === 64;
151 const pointDetails = need.fromPointCache(props.pointCache, state.point);
156 {'Set Network Keys For '} <code>{`${ob.patp(state.point)}`}</code>
159 <P className="mt-10">
160 {`Set new authentication and encryption keys for your Arvo ship.`}
163 {state.nondeterministicSeed && (
165 <h3 className={'mb-2'}>{'Warning'}</h3>
166 {`Your network seed could not be derived automatically. We've
167 generated a random one for you, so you must download your Arvo
168 keyfile during this session after setting your keys.`}
172 {pointDetails.keyRevisionNumber === 0 ? (
174 <h3 className={'mb-2'}>{'Warning'}</h3>
175 {'Once these keys have been set, your point is considered ' +
176 "'linked'. This operation cannot be undone."}
184 onToggle={this.toggleDiscontinuity}
185 state={state.discontinuity}
186 label={`I have lost important off-chain data relating to this point
187 and need to do a hard reset.
188 (For example, rebooting an Arvo ship.)`}
191 <StatelessTransaction
195 canGenerate={canGenerate}
196 createUnsignedTxn={this.createUnsignedTxn}
197 newNetworkSeed={state.newNetworkSeed}
198 newRevision={parseInt(pointDetails.keyRevisionNumber) + 1}
205export 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