1import React from 'react';
2import * as need from '../lib/need';
4import { Button } from '../components/old/Base';
5import { H1, P } from '../components/old/Base';
7import * as ob from 'urbit-ob';
8import * as kg from 'urbit-key-generation/dist';
9import saveAs from 'file-saver';
11import { attemptNetworkSeedDerivation, genKey } from '../lib/keys';
12import { addHexPrefix } from '../lib/wallet';
13import { compose } from '../lib/lib';
14import { withWallet } from '../store/wallet';
15import { withPointCursor } from '../store/pointCursor';
16import { withPointCache } from '../store/pointCache';
17import View from 'components/View';
19class GenKeyfile extends React.Component {
30 const point = need.pointCursor(this.props.pointCursor);
31 const pointDetails = need.fromPointCache(this.props.pointCache, point);
33 // in case we did SetKeys earlier this session, make sure to generate the
34 // newer keyfile, rather than the one that will expire soon
35 const revision = this.props.networkRevision.matchWith({
36 Nothing: () => parseInt(pointDetails.keyRevisionNumber),
47 async componentDidMount() {
48 const { point, pointDetails, revision } = this.getPointDetails();
51 const hexRegExp = /[0-9A-Fa-f]{64}/g;
52 const networkSeed = await this.deriveSeed();
54 const keysmatch = this.checkKeysMatch(networkSeed, pointDetails);
55 const seedValid = hexRegExp.test(networkSeed);
57 if (keysmatch && seedValid) {
58 keyfile = genKey(networkSeed, point, revision);
67 checkKeysMatch(networkSeed, pointDetails) {
68 const crypub = pointDetails.encryptionKey;
69 const sgnpub = pointDetails.authenticationKey;
71 const { crypt, auth } = kg.deriveNetworkKeys(networkSeed);
74 crypub === addHexPrefix(crypt.public) &&
75 sgnpub === addHexPrefix(auth.public);
83 const seed = await attemptNetworkSeedDerivation(next, this.props);
85 // either return the derived seed, the cached seed, or empty string
86 return seed.matchWith({
87 Nothing: () => this.props.networkSeed.getOrElse(''),
93 const { point, revision } = this.getPointDetails();
94 const { keyfile, loaded } = this.state;
98 <H1>{'Generate keyfile'}</H1>
100 <P>{'Download a private key file for booting this point in Arvo.'}</P>
102 {keyfile === '' && !loaded && <P>{'Generating keyfile...'}</P>}
104 {keyfile === '' && loaded && (
108 {`No valid network seed detected. To generate a keyfile, you
109 must reset your networking keys, or try logging in with your
110 master ticket or management mnemonic.`}
114 {`If you've just reset your networking keys, you may need to wait for the transaction to go through. Check back shortly.`}
121 <div className="pb-5 text-code keyfile">{keyfile}</div>
124 let blob = new Blob([keyfile], {
125 type: 'text/plain;charset=utf-8',
127 saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`);
138export 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