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(),
47 isManagementSeed: false,
56 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
58 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
59 this.handleSubmit = this.handleSubmit.bind(this)
60 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
61 this.handleSetTxn = this.handleSetTxn.bind(this)
62 this.handleSetStx = this.handleSetStx.bind(this)
63 this.handleSetNonce = this.handleSetNonce.bind(this)
64 this.handleSetChainId = this.handleSetChainId.bind(this)
65 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
66 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 this.determineManagementSeed(props.contracts.value, addr)
83 props.web3.matchWith({
86 const validWeb3 = w3.value
88 const getTxMetadata = [
89 validWeb3.eth.getTransactionCount(addr),
90 validWeb3.eth.net.getId(),
91 validWeb3.eth.getGasPrice()
94 Promise.all(getTxMetadata).then(r => {
98 gasPrice: fromWei(r[2], 'gwei'),
101 this.setState({...txMetadata})
108 async determineManagementSeed(ctrcs, addr) {
110 await azimuth.azimuth.getManagerFor(ctrcs, addr)
113 isManagementSeed: managing.length !== 0
119 const seed = await attemptSeedDerivation(next, this.props)
121 networkSeed: seed.getOrElse('')
127 handleNetworkSeedInput(networkSeed) {
128 this.setState({ networkSeed })
133 handleCreateUnsignedTxn() {
134 const txn = this.createUnsignedTxn()
135 this.setState({ txn })
139 handleSetUserApproval(){
141 this.setState({ userApproval: !state.userApproval })
147 this.setState({ txn })
161 handleSetNonce(nonce){
162 this.setState({ nonce })
163 this.handleClearStx()
168 handleSetChainId(chainId){
169 this.setState({ chainId })
170 this.handleClearStx()
175 handleSetGasPrice(gasPrice){
176 this.setState({ gasPrice })
177 this.handleClearStx()
182 handleSetGasLimit(gasLimit){
183 this.setState({ gasLimit })
184 this.handleClearStx()
192 stx: Maybe.Nothing(),
202 txn: Maybe.Nothing(),
203 stx: Maybe.Nothing(),
209 handleClearTransaction() {
212 txn: Maybe.Nothing(),
213 stx: Maybe.Nothing(),
220 const { props, state } = this
221 sendSignedTransaction(props.web3.value, state.stx)
223 props.setTxnHashCursor(sent)
225 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
228 this.setState({ txError: err.map(val => val.merge()) })
234 createUnsignedTxn() {
235 const { state, props } = this
237 const validContracts = props.contracts.matchWith({
238 Just: (cs) => cs.value,
240 throw BRIDGE_ERROR.MISSING_CONTRACTS
244 const validPoint = props.pointCursor.matchWith({
245 Just: (shp) => shp.value,
247 throw BRIDGE_ERROR.MISSING_POINT
251 const hexRegExp = /[0-9A-Fa-f]{64}/g
253 if (hexRegExp.test(state.networkSeed)) {
254 // derive network keys
255 const pair = kg.deriveNetworkKeys(state.networkSeed)
257 const pencr = addHexPrefix(pair.crypt.public)
258 const pauth = addHexPrefix(pair.auth.public)
260 const txn = azimuth.ecliptic.configureKeys(
269 return Maybe.Just(txn)
272 return Maybe.Nothing()
276 const { props, state } = this
279 state.networkSeed.length === 64
280 && state.networkSeed.length === 64
282 const canSign = Maybe.Just.hasInstance(state.txn)
283 const canApprove = Maybe.Just.hasInstance(state.stx)
286 Maybe.Just.hasInstance(state.stx)
287 && state.userApproval === true
290 state.point in props.pointCache
291 ? props.pointCache[state.point]
292 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
294 const isManagementMnemonic =
295 this.state.isManagementSeed &&
296 props.walletType === WALLET_NAMES.MNEMONIC
298 const isMasterTicket =
299 props.walletType === WALLET_NAMES.TICKET ||
300 props.walletType === WALLET_NAMES.SHARD
302 const networkSeedDisabled = isManagementMnemonic || isMasterTicket;
308 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
313 `Please enter a network seed for generating and setting your public
314 network authentication and encryption keys. Your network seed
315 must be a 32-byte-long hexadecimal string.`
320 `If you've authenticated with a master ticket or management proxy
321 mnemonic, a seed will be generated for you automatically.`
325 { pointDetails.keyRevisionNumber === '0'
327 <h3 className={'mb-2'}>{'Warning'}</h3>
329 'Once these keys have been set, your point is considered ' +
330 "'linked'. This operation cannot be undone."
338 prop-format='innerLabel'
340 disabled= { networkSeedDisabled }
341 value={ state.networkSeed }
342 onChange={ this.handleNetworkSeedInput }>
343 <InnerLabel>{ 'Network seed' }</InnerLabel>
346 <StatelessTransaction
349 contracts={props.contracts}
350 wallet={props.wallet}
351 walletType={props.walletType}
352 walletHdPath={props.walletHdPath}
353 networkType={props.networkType}
359 gasPrice={state.gasPrice}
360 chainId={state.chainId}
361 gasLimit={state.gasLimit}
363 userApproval={state.userApproval}
364 canGenerate={ canGenerate }
366 canApprove={ canApprove }
369 createUnsignedTxn={this.handleCreateUnsignedTxn}
370 setUserApproval={this.handleSetUserApproval}
371 setTxn={this.handleSetTxn}
372 setStx={this.handleSetStx}
373 setNonce={this.handleSetNonce}
374 setChainId={this.handleSetChainId}
375 setGasPrice={this.handleSetGasPrice}
376 setGasLimit={this.handleSetGasLimit}
377 handleSubmit={this.handleSubmit} />
380 Maybe.Nothing.hasInstance(state.txError)
382 : <Warning className={'mt-8'}>
383 <H3 style={{marginTop: 0, paddingTop: 0}}>
385 'There was an error sending your transaction.'
388 { state.txError.value }
398export 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