1import React from 'react'
2import Maybe from 'folktale/maybe'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
5import { Row, Col, H1, P, Warning, H3 } from '../components/Base'
6import { RequiredInput, InnerLabel } from '../components/Base'
8import StatelessTransaction from '../components/StatelessTransaction'
9import { BRIDGE_ERROR } from '../lib/error'
10import { ROUTE_NAMES } from '../lib/router'
11import { attemptSeedDerivation, genKey } from '../lib/keys'
13import saveAs from 'file-saver'
15import { WALLET_NAMES } from '../lib/wallet'
17import * as kg from '../../node_modules/urbit-key-generation/dist/index'
20 sendSignedTransaction,
25 addressFromSecp256k1Public,
29class SetKeys extends React.Component {
33 const point = props.pointCursor.matchWith({
34 Just: (shp) => shp.value,
36 throw BRIDGE_ERROR.MISSING_POINT
45 cryptoSuiteVersion: 1,
48 txError: Maybe.Nothing(),
49 isManagementSeed: false,
53 showGasDetails: false,
59 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
61 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
62 this.handleSubmit = this.handleSubmit.bind(this)
63 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
64 this.handleSetTxn = this.handleSetTxn.bind(this)
65 this.handleSetStx = this.handleSetStx.bind(this)
66 this.handleSetNonce = this.handleSetNonce.bind(this)
67 this.handleSetChainId = this.handleSetChainId.bind(this)
68 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
69 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
70 this.toggleGasDetails = this.toggleGasDetails.bind(this)
75 showGasDetails: !this.state.showGasDetails
80 const { props } = this
84 const addr = props.wallet.matchWith({
85 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
87 throw BRIDGE_ERROR.MISSING_WALLET
91 this.determineManagementSeed(props.contracts.value, addr)
93 props.web3.matchWith({
96 const validWeb3 = w3.value
98 const getTxMetadata = [
99 validWeb3.eth.getTransactionCount(addr),
100 validWeb3.eth.net.getId(),
101 validWeb3.eth.getGasPrice()
104 Promise.all(getTxMetadata).then(r => {
108 gasPrice: fromWei(r[2], 'gwei'),
111 this.setState({...txMetadata})
118 async determineManagementSeed(ctrcs, addr) {
120 await azimuth.azimuth.getManagerFor(ctrcs, addr)
123 isManagementSeed: managing.length !== 0
127 //TODO use web3.utils.randomHex when it gets fixed, see web3.js#1490
131 for (var i = 0; i < len; i++) {
132 hex = hex + ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
133 'C', 'D', 'E', 'F'][Math.floor(Math.random() * 16)]
141 let seed = await attemptSeedDerivation(next, this.props)
143 if (seed.getOrElse('') === '') {
144 seed = Maybe.Just(this.randomHex(64));
148 networkSeed: seed.getOrElse('')
152 handleNetworkSeedInput(networkSeed) {
153 this.setState({ networkSeed })
156 handleCreateUnsignedTxn() {
157 const txn = this.createUnsignedTxn()
158 this.setState({ txn })
162 handleSetUserApproval(){
164 this.setState({ userApproval: !state.userApproval })
170 this.setState({ txn })
184 handleSetNonce(nonce){
185 this.setState({ nonce })
186 this.handleClearStx()
191 handleSetChainId(chainId){
192 this.setState({ chainId })
193 this.handleClearStx()
198 handleSetGasPrice(gasPrice){
199 this.setState({ gasPrice })
200 this.handleClearStx()
205 handleSetGasLimit(gasLimit){
206 this.setState({ gasLimit })
207 this.handleClearStx()
215 stx: Maybe.Nothing(),
225 txn: Maybe.Nothing(),
226 stx: Maybe.Nothing(),
232 handleClearTransaction() {
235 txn: Maybe.Nothing(),
236 stx: Maybe.Nothing(),
240 downloadKeyfile(networkSeed) {
241 const { pointCache } = this.props
242 const { pointCursor } = this.props
244 const point = pointCursor.matchWith({
245 Just: (pt) => pt.value,
247 throw BRIDGE_ERROR.MISSING_POINT
254 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
256 const revision = parseInt(pointDetails.keyRevisionNumber)
257 const keyfile = genKey(networkSeed, point, revision)
258 let blob = new Blob([keyfile], {type:"text/plain;charset=utf-8"});
259 saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
263 const { props, state } = this
264 sendSignedTransaction(props.web3.value, state.stx)
266 props.setNetworkSeedCache(this.state.networkSeed)
267 // this.downloadKeyfile(this.state.networkSeed)
268 props.setTxnHashCursor(sent)
270 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
273 this.setState({ txError: err.map(val => val.merge()) })
279 createUnsignedTxn() {
280 const { state, props } = this
282 const validContracts = props.contracts.matchWith({
283 Just: (cs) => cs.value,
285 throw BRIDGE_ERROR.MISSING_CONTRACTS
289 const validPoint = props.pointCursor.matchWith({
290 Just: (shp) => shp.value,
292 throw BRIDGE_ERROR.MISSING_POINT
296 const hexRegExp = /[0-9A-Fa-f]{64}/g
298 if (hexRegExp.test(state.networkSeed)) {
299 // derive network keys
300 const pair = kg.deriveNetworkKeys(state.networkSeed)
302 const pencr = addHexPrefix(pair.crypt.public)
303 const pauth = addHexPrefix(pair.auth.public)
305 const txn = azimuth.ecliptic.configureKeys(
314 return Maybe.Just(txn)
317 return Maybe.Nothing()
321 const { props, state } = this
324 state.networkSeed.length === 64
325 && state.networkSeed.length === 64
327 const canSign = Maybe.Just.hasInstance(state.txn)
328 const canApprove = Maybe.Just.hasInstance(state.stx)
331 Maybe.Just.hasInstance(state.stx)
332 && state.userApproval === true
335 state.point in props.pointCache
336 ? props.pointCache[state.point]
337 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
343 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
346 <P className="mt-10">
348 `Set new authentication and encryption keys for your Arvo ship.`
354 `Once the transaction is sent, please generate your Arvo keyfile immediately.`
358 { pointDetails.keyRevisionNumber === '0'
360 <h3 className={'mb-2'}>{'Warning'}</h3>
362 'Once these keys have been set, your point is considered ' +
363 "'linked'. This operation cannot be undone."
368 <StatelessTransaction
371 contracts={props.contracts}
372 wallet={props.wallet}
373 walletType={props.walletType}
374 walletHdPath={props.walletHdPath}
375 networkType={props.networkType}
381 gasPrice={state.gasPrice}
382 chainId={state.chainId}
383 gasLimit={state.gasLimit}
384 showGasDetails={state.showGasDetails}
385 toggleGasDetails={this.toggleGasDetails}
387 userApproval={state.userApproval}
388 canGenerate={ canGenerate }
390 canApprove={ canApprove }
393 createUnsignedTxn={this.handleCreateUnsignedTxn}
394 setUserApproval={this.handleSetUserApproval}
395 setTxn={this.handleSetTxn}
396 setStx={this.handleSetStx}
397 setNonce={this.handleSetNonce}
398 setChainId={this.handleSetChainId}
399 setGasPrice={this.handleSetGasPrice}
400 setGasLimit={this.handleSetGasLimit}
401 handleSubmit={this.handleSubmit} />
404 Maybe.Nothing.hasInstance(state.txError)
406 : <Warning className={'mt-8'}>
407 <H3 style={{marginTop: 0, paddingTop: 0}}>
409 'There was an error sending your transaction.'
412 { state.txError.value }
422export default SetKeys
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