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 { WALLET_NAMES } from '../lib/wallet'
15import * as kg from '../../node_modules/urbit-key-generation/dist/index'
18 sendSignedTransaction,
23 addressFromSecp256k1Public,
27class SetKeys extends React.Component {
31 const point = props.pointCursor.matchWith({
32 Just: (shp) => shp.value,
34 throw BRIDGE_ERROR.MISSING_POINT
43 cryptoSuiteVersion: 1,
46 txError: Maybe.Nothing(),
55 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
57 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
58 this.handleSubmit = this.handleSubmit.bind(this)
59 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
60 this.handleSetTxn = this.handleSetTxn.bind(this)
61 this.handleSetStx = this.handleSetStx.bind(this)
62 this.handleSetNonce = this.handleSetNonce.bind(this)
63 this.handleSetChainId = this.handleSetChainId.bind(this)
64 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
65 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
70 const { props } = this
74 const addr = props.wallet.matchWith({
75 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
77 throw BRIDGE_ERROR.MISSING_WALLET
81 props.web3.matchWith({
84 const validWeb3 = w3.value
86 const getTxMetadata = [
87 validWeb3.eth.getTransactionCount(addr),
88 validWeb3.eth.net.getId(),
89 validWeb3.eth.getGasPrice()
92 Promise.all(getTxMetadata).then(r => {
96 gasPrice: fromWei(r[2], 'gwei'),
99 this.setState({...txMetadata})
110 const seed = await attemptSeedDerivation(next, this.props)
112 networkSeed: seed.getOrElse('')
118 handleNetworkSeedInput(networkSeed) {
119 this.setState({ networkSeed })
124 handleCreateUnsignedTxn() {
125 const txn = this.createUnsignedTxn()
126 this.setState({ txn })
130 handleSetUserApproval(){
132 this.setState({ userApproval: !state.userApproval })
138 this.setState({ txn })
152 handleSetNonce(nonce){
153 this.setState({ nonce })
154 this.handleClearStx()
159 handleSetChainId(chainId){
160 this.setState({ chainId })
161 this.handleClearStx()
166 handleSetGasPrice(gasPrice){
167 this.setState({ gasPrice })
168 this.handleClearStx()
173 handleSetGasLimit(gasLimit){
174 this.setState({ gasLimit })
175 this.handleClearStx()
183 stx: Maybe.Nothing(),
193 txn: Maybe.Nothing(),
194 stx: Maybe.Nothing(),
200 handleClearTransaction() {
203 txn: Maybe.Nothing(),
204 stx: Maybe.Nothing(),
211 const { props, state } = this
212 sendSignedTransaction(props.web3.value, state.stx)
214 props.setTxnHashCursor(sent)
216 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
219 this.setState({ txError: err.map(val => val.merge()) })
225 createUnsignedTxn() {
226 const { state, props } = this
228 const validContracts = props.contracts.matchWith({
229 Just: (cs) => cs.value,
231 throw BRIDGE_ERROR.MISSING_CONTRACTS
235 const validPoint = props.pointCursor.matchWith({
236 Just: (shp) => shp.value,
238 throw BRIDGE_ERROR.MISSING_POINT
242 const hexRegExp = /[0-9A-Fa-f]{64}/g
244 if (hexRegExp.test(state.networkSeed)) {
245 // derive network keys
246 const pair = kg.deriveNetworkKeys(state.networkSeed)
248 const pencr = addHexPrefix(pair.crypt.public)
249 const pauth = addHexPrefix(pair.auth.public)
251 const txn = azimuth.ecliptic.configureKeys(
260 return Maybe.Just(txn)
263 return Maybe.Nothing()
267 const { props, state } = this
270 state.networkSeed.length === 64
271 && state.networkSeed.length === 64
273 const canSign = Maybe.Just.hasInstance(state.txn)
274 const canApprove = Maybe.Just.hasInstance(state.stx)
277 Maybe.Just.hasInstance(state.stx)
278 && state.userApproval === true
281 state.point in props.pointCache
282 ? props.pointCache[state.point]
283 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
289 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
294 `Please enter a network seed for generating and setting your public
295 network authentication and encryption keys. Your network seed
296 must be a 32-byte-long hexadecimal string.`
301 `If you've authenticated with a master ticket or management proxy
302 mnemonic, a seed will be generated for you automatically.`
306 { pointDetails.keyRevisionNumber === '0'
308 <h3 className={'mb-2'}>{'Warning'}</h3>
310 'Once these keys have been set, your point is considered ' +
311 "'linked'. This operation cannot be undone."
319 prop-format='innerLabel'
321 disabled= { props.walletType === WALLET_NAMES.TICKET || props.walletType === WALLET_NAMES.SHARD}
322 value={ state.networkSeed }
323 onChange={ this.handleNetworkSeedInput }>
324 <InnerLabel>{ 'Network seed' }</InnerLabel>
327 <StatelessTransaction
330 contracts={props.contracts}
331 wallet={props.wallet}
332 walletType={props.walletType}
333 walletHdPath={props.walletHdPath}
334 networkType={props.networkType}
340 gasPrice={state.gasPrice}
341 chainId={state.chainId}
342 gasLimit={state.gasLimit}
344 userApproval={state.userApproval}
345 canGenerate={ canGenerate }
347 canApprove={ canApprove }
350 createUnsignedTxn={this.handleCreateUnsignedTxn}
351 setUserApproval={this.handleSetUserApproval}
352 setTxn={this.handleSetTxn}
353 setStx={this.handleSetStx}
354 setNonce={this.handleSetNonce}
355 setChainId={this.handleSetChainId}
356 setGasPrice={this.handleSetGasPrice}
357 setGasLimit={this.handleSetGasLimit}
358 handleSubmit={this.handleSubmit} />
361 Maybe.Nothing.hasInstance(state.txError)
363 : <Warning className={'mt-8'}>
364 <H3 style={{marginTop: 0, paddingTop: 0}}>
366 'There was an error sending your transaction.'
369 { state.txError.value }
379export 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