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(),
53 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
55 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
56 this.handleSubmit = this.handleSubmit.bind(this)
57 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
58 this.handleSetTxn = this.handleSetTxn.bind(this)
59 this.handleSetStx = this.handleSetStx.bind(this)
60 this.handleSetNonce = this.handleSetNonce.bind(this)
61 this.handleSetChainId = this.handleSetChainId.bind(this)
62 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
63 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
68 const { props } = this
72 const addr = props.wallet.matchWith({
73 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
75 throw BRIDGE_ERROR.MISSING_WALLET
79 props.web3.matchWith({
82 const validWeb3 = w3.value
84 const getTxMetadata = [
85 validWeb3.eth.getTransactionCount(addr),
86 validWeb3.eth.net.getId(),
87 validWeb3.eth.getGasPrice()
90 Promise.all(getTxMetadata).then(r => {
94 gasPrice: fromWei(r[2], 'gwei'),
97 this.setState({...txMetadata})
108 const seed = await attemptSeedDerivation(next, this.props)
110 networkSeed: seed.getOrElse('')
116 handleNetworkSeedInput(networkSeed) {
117 this.setState({ networkSeed })
122 handleCreateUnsignedTxn() {
123 const txn = this.createUnsignedTxn()
124 this.setState({ txn })
128 handleSetUserApproval(){
130 this.setState({ userApproval: !state.userApproval })
136 this.setState({ txn })
150 handleSetNonce(nonce){
151 this.setState({ nonce })
152 this.handleClearStx()
157 handleSetChainId(chainId){
158 this.setState({ chainId })
159 this.handleClearStx()
164 handleSetGasPrice(gasPrice){
165 this.setState({ gasPrice })
166 this.handleClearStx()
171 handleSetGasLimit(gasLimit){
172 this.setState({ gasLimit })
173 this.handleClearStx()
181 stx: Maybe.Nothing(),
191 txn: Maybe.Nothing(),
192 stx: Maybe.Nothing(),
198 handleClearTransaction() {
201 txn: Maybe.Nothing(),
202 stx: Maybe.Nothing(),
209 const { props, state } = this
210 sendSignedTransaction(props.web3.value, state.stx)
212 props.setTxnHashCursor(sent)
214 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
217 this.setState({ txError: err.map(val => val.merge()) })
223 createUnsignedTxn() {
224 const { state, props } = this
226 const validContracts = props.contracts.matchWith({
227 Just: (cs) => cs.value,
229 throw BRIDGE_ERROR.MISSING_CONTRACTS
233 const validPoint = props.pointCursor.matchWith({
234 Just: (shp) => shp.value,
236 throw BRIDGE_ERROR.MISSING_POINT
240 const hexRegExp = /[0-9A-Fa-f]{64}/g
242 if (hexRegExp.test(state.networkSeed)) {
243 // derive network keys
244 const pair = kg.deriveNetworkKeys(state.networkSeed)
246 const pencr = addHexPrefix(pair.crypt.public)
247 const pauth = addHexPrefix(pair.auth.public)
249 const txn = azimuth.ecliptic.configureKeys(
258 return Maybe.Just(txn)
261 return Maybe.Nothing()
265 const { props, state } = this
268 state.networkSeed.length === 64
269 && state.networkSeed.length === 64
271 const canSign = Maybe.Just.hasInstance(state.txn)
272 const canApprove = Maybe.Just.hasInstance(state.stx)
275 Maybe.Just.hasInstance(state.stx)
276 && state.userApproval === true
279 state.point in props.pointCache
280 ? props.pointCache[state.point]
281 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
288 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
293 `Please enter a network seed for generating and setting your public
294 network authentication and encryption keys. Your network seed
295 must be a 32-byte-long hexadecimal string.`
300 `If you've authenticated with a master ticket or management proxy
301 mnemonic, a seed will be generated for you automatically.`
305 { pointDetails.keyRevisionNumber === '0'
307 <h3 className={'mb-2'}>{'Warning'}</h3>
309 'Once these keys have been set, your point is considered ' +
310 "'linked'. This operation cannot be undone."
318 prop-format='innerLabel'
320 value={ state.networkSeed }
321 onChange={ this.handleNetworkSeedInput }>
322 <InnerLabel>{ 'Network seed' }</InnerLabel>
325 <StatelessTransaction
328 contracts={props.contracts}
329 wallet={props.wallet}
330 walletType={props.walletType}
331 walletHdPath={props.walletHdPath}
332 networkType={props.networkType}
338 gasPrice={state.gasPrice}
339 chainId={state.chainId}
340 gasLimit={state.gasLimit}
342 userApproval={state.userApproval}
343 canGenerate={ canGenerate }
345 canApprove={ canApprove }
348 createUnsignedTxn={this.handleCreateUnsignedTxn}
349 setUserApproval={this.handleSetUserApproval}
350 setTxn={this.handleSetTxn}
351 setStx={this.handleSetStx}
352 setNonce={this.handleSetNonce}
353 setChainId={this.handleSetChainId}
354 setGasPrice={this.handleSetGasPrice}
355 setGasLimit={this.handleSetGasLimit}
356 handleSubmit={this.handleSubmit} />
359 Maybe.Nothing.hasInstance(state.txError)
361 : <Warning className={'mt-8'}>
362 <H3 style={{marginTop: 0, paddingTop: 0}}>
364 'There was an error sending your transaction.'
367 { state.txError.value }
377export 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