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 } from '../lib/keys'
13import * as kg from '../../node_modules/urbit-key-generation/dist/index'
16 sendSignedTransaction,
21 addressFromSecp256k1Public,
25class SetKeys extends React.Component {
29 const point = props.pointCursor.matchWith({
30 Just: (shp) => shp.value,
32 throw BRIDGE_ERROR.MISSING_POINT
41 cryptoSuiteVersion: 1,
44 txError: Maybe.Nothing(),
48 showGasDetails: false,
54 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
56 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
57 this.handleSubmit = this.handleSubmit.bind(this)
58 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
59 this.handleSetTxn = this.handleSetTxn.bind(this)
60 this.handleSetStx = this.handleSetStx.bind(this)
61 this.handleSetNonce = this.handleSetNonce.bind(this)
62 this.handleSetChainId = this.handleSetChainId.bind(this)
63 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
64 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
65 this.toggleGasDetails = this.toggleGasDetails.bind(this)
70 showGasDetails: !this.state.showGasDetails
75 const { props } = this
79 const addr = props.wallet.matchWith({
80 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
82 throw BRIDGE_ERROR.MISSING_WALLET
86 props.web3.matchWith({
89 const validWeb3 = w3.value
91 const getTxMetadata = [
92 validWeb3.eth.getTransactionCount(addr),
93 validWeb3.eth.net.getId(),
94 validWeb3.eth.getGasPrice()
97 Promise.all(getTxMetadata).then(r => {
101 gasPrice: fromWei(r[2], 'gwei'),
104 this.setState({...txMetadata})
115 const seed = await attemptSeedDerivation(next, this.props)
117 networkSeed: seed.getOrElse('')
123 handleNetworkSeedInput(networkSeed) {
124 this.setState({ networkSeed })
129 handleCreateUnsignedTxn() {
130 const txn = this.createUnsignedTxn()
131 this.setState({ txn })
135 handleSetUserApproval(){
137 this.setState({ userApproval: !state.userApproval })
143 this.setState({ txn })
157 handleSetNonce(nonce){
158 this.setState({ nonce })
159 this.handleClearStx()
164 handleSetChainId(chainId){
165 this.setState({ chainId })
166 this.handleClearStx()
171 handleSetGasPrice(gasPrice){
172 this.setState({ gasPrice })
173 this.handleClearStx()
178 handleSetGasLimit(gasLimit){
179 this.setState({ gasLimit })
180 this.handleClearStx()
188 stx: Maybe.Nothing(),
198 txn: Maybe.Nothing(),
199 stx: Maybe.Nothing(),
205 handleClearTransaction() {
208 txn: Maybe.Nothing(),
209 stx: Maybe.Nothing(),
216 const { props, state } = this
217 sendSignedTransaction(props.web3.value, state.stx)
219 props.setTxnHashCursor(sent)
221 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
224 this.setState({ txError: err.map(val => val.merge()) })
230 createUnsignedTxn() {
231 const { state, props } = this
233 const validContracts = props.contracts.matchWith({
234 Just: (cs) => cs.value,
236 throw BRIDGE_ERROR.MISSING_CONTRACTS
240 const validPoint = props.pointCursor.matchWith({
241 Just: (shp) => shp.value,
243 throw BRIDGE_ERROR.MISSING_POINT
247 const hexRegExp = /[0-9A-Fa-f]{64}/g
249 if (hexRegExp.test(state.networkSeed)) {
250 // derive network keys
251 const pair = kg.deriveNetworkKeys(state.networkSeed)
253 const pencr = addHexPrefix(pair.crypt.public)
254 const pauth = addHexPrefix(pair.auth.public)
256 const txn = azimuth.ecliptic.configureKeys(
265 return Maybe.Just(txn)
268 return Maybe.Nothing()
272 const { props, state } = this
275 state.networkSeed.length === 64
276 && state.networkSeed.length === 64
278 const canSign = Maybe.Just.hasInstance(state.txn)
279 const canApprove = Maybe.Just.hasInstance(state.stx)
282 Maybe.Just.hasInstance(state.stx)
283 && state.userApproval === true
286 state.point in props.pointCache
287 ? props.pointCache[state.point]
288 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
295 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
300 `Please enter a network seed for generating and setting your public
301 network authentication and encryption keys. Your network seed
302 must be a string of 64 characters (containing 0-9, A-Z, a-z).`
307 `If you've authenticated with a master ticket or management proxy
308 mnemonic, a seed will be generated for you automatically.`
312 { pointDetails.keyRevisionNumber === '0'
314 <h3 className={'mb-2'}>{'Warning'}</h3>
316 'Once these keys have been set, your point is considered ' +
317 "'linked'. This operation cannot be undone."
325 prop-format='innerLabel'
327 value={ state.networkSeed }
328 onChange={ this.handleNetworkSeedInput }>
329 <InnerLabel>{ 'Network seed' }</InnerLabel>
332 <StatelessTransaction
335 contracts={props.contracts}
336 wallet={props.wallet}
337 walletType={props.walletType}
338 walletHdPath={props.walletHdPath}
339 networkType={props.networkType}
345 gasPrice={state.gasPrice}
346 chainId={state.chainId}
347 gasLimit={state.gasLimit}
348 showGasDetails={state.showGasDetails}
349 toggleGasDetails={this.toggleGasDetails}
351 userApproval={state.userApproval}
352 canGenerate={ canGenerate }
354 canApprove={ canApprove }
357 createUnsignedTxn={this.handleCreateUnsignedTxn}
358 setUserApproval={this.handleSetUserApproval}
359 setTxn={this.handleSetTxn}
360 setStx={this.handleSetStx}
361 setNonce={this.handleSetNonce}
362 setChainId={this.handleSetChainId}
363 setGasPrice={this.handleSetGasPrice}
364 setGasLimit={this.handleSetGasLimit}
365 handleSubmit={this.handleSubmit} />
368 Maybe.Nothing.hasInstance(state.txError)
370 : <Warning className={'mt-8'}>
371 <H3 style={{marginTop: 0, paddingTop: 0}}>
373 'There was an error sending your transaction.'
376 { state.txError.value }
386export 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