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,
51 showGasDetails: false,
57 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
59 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
60 this.handleSubmit = this.handleSubmit.bind(this)
61 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
62 this.handleSetTxn = this.handleSetTxn.bind(this)
63 this.handleSetStx = this.handleSetStx.bind(this)
64 this.handleSetNonce = this.handleSetNonce.bind(this)
65 this.handleSetChainId = this.handleSetChainId.bind(this)
66 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
67 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
68 this.toggleGasDetails = this.toggleGasDetails.bind(this)
73 showGasDetails: !this.state.showGasDetails
78 const { props } = this
82 const addr = props.wallet.matchWith({
83 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
85 throw BRIDGE_ERROR.MISSING_WALLET
89 this.determineManagementSeed(props.contracts.value, addr)
91 props.web3.matchWith({
94 const validWeb3 = w3.value
96 const getTxMetadata = [
97 validWeb3.eth.getTransactionCount(addr),
98 validWeb3.eth.net.getId(),
99 validWeb3.eth.getGasPrice()
102 Promise.all(getTxMetadata).then(r => {
106 gasPrice: fromWei(r[2], 'gwei'),
109 this.setState({...txMetadata})
116 async determineManagementSeed(ctrcs, addr) {
118 await azimuth.azimuth.getManagerFor(ctrcs, addr)
121 isManagementSeed: managing.length !== 0
127 const seed = await attemptSeedDerivation(next, this.props)
129 networkSeed: seed.getOrElse('')
135 handleNetworkSeedInput(networkSeed) {
136 this.setState({ networkSeed })
141 handleCreateUnsignedTxn() {
142 const txn = this.createUnsignedTxn()
143 this.setState({ txn })
147 handleSetUserApproval(){
149 this.setState({ userApproval: !state.userApproval })
155 this.setState({ txn })
169 handleSetNonce(nonce){
170 this.setState({ nonce })
171 this.handleClearStx()
176 handleSetChainId(chainId){
177 this.setState({ chainId })
178 this.handleClearStx()
183 handleSetGasPrice(gasPrice){
184 this.setState({ gasPrice })
185 this.handleClearStx()
190 handleSetGasLimit(gasLimit){
191 this.setState({ gasLimit })
192 this.handleClearStx()
200 stx: Maybe.Nothing(),
210 txn: Maybe.Nothing(),
211 stx: Maybe.Nothing(),
217 handleClearTransaction() {
220 txn: Maybe.Nothing(),
221 stx: Maybe.Nothing(),
228 const { props, state } = this
229 sendSignedTransaction(props.web3.value, state.stx)
231 props.setTxnHashCursor(sent)
233 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
236 this.setState({ txError: err.map(val => val.merge()) })
242 createUnsignedTxn() {
243 const { state, props } = this
245 const validContracts = props.contracts.matchWith({
246 Just: (cs) => cs.value,
248 throw BRIDGE_ERROR.MISSING_CONTRACTS
252 const validPoint = props.pointCursor.matchWith({
253 Just: (shp) => shp.value,
255 throw BRIDGE_ERROR.MISSING_POINT
259 const hexRegExp = /[0-9A-Fa-f]{64}/g
261 if (hexRegExp.test(state.networkSeed)) {
262 // derive network keys
263 const pair = kg.deriveNetworkKeys(state.networkSeed)
265 const pencr = addHexPrefix(pair.crypt.public)
266 const pauth = addHexPrefix(pair.auth.public)
268 const txn = azimuth.ecliptic.configureKeys(
277 return Maybe.Just(txn)
280 return Maybe.Nothing()
284 const { props, state } = this
287 state.networkSeed.length === 64
288 && state.networkSeed.length === 64
290 const canSign = Maybe.Just.hasInstance(state.txn)
291 const canApprove = Maybe.Just.hasInstance(state.stx)
294 Maybe.Just.hasInstance(state.stx)
295 && state.userApproval === true
298 state.point in props.pointCache
299 ? props.pointCache[state.point]
300 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
302 const isManagementMnemonic =
303 this.state.isManagementSeed &&
304 props.walletType === WALLET_NAMES.MNEMONIC
306 const isMasterTicket =
307 props.walletType === WALLET_NAMES.TICKET ||
308 props.walletType === WALLET_NAMES.SHARD
310 const networkSeedDisabled = isManagementMnemonic || isMasterTicket;
316 { 'Set Network Keys For ' } <code>{ `${ob.patp(state.point)}` }</code>
321 `Please enter a network seed for generating and setting your public
322 network authentication and encryption keys. Your network seed
323 must be a string of 64 characters (containing 0-9, A-Z, a-z).`
328 `If you've authenticated with a master ticket or management proxy
329 mnemonic, a seed will be generated for you automatically.`
333 { pointDetails.keyRevisionNumber === '0'
335 <h3 className={'mb-2'}>{'Warning'}</h3>
337 'Once these keys have been set, your point is considered ' +
338 "'linked'. This operation cannot be undone."
346 prop-format='innerLabel'
348 disabled= { networkSeedDisabled }
349 value={ state.networkSeed }
350 onChange={ this.handleNetworkSeedInput }>
351 <InnerLabel>{ 'Network seed' }</InnerLabel>
354 <StatelessTransaction
357 contracts={props.contracts}
358 wallet={props.wallet}
359 walletType={props.walletType}
360 walletHdPath={props.walletHdPath}
361 networkType={props.networkType}
367 gasPrice={state.gasPrice}
368 chainId={state.chainId}
369 gasLimit={state.gasLimit}
370 showGasDetails={state.showGasDetails}
371 toggleGasDetails={this.toggleGasDetails}
373 userApproval={state.userApproval}
374 canGenerate={ canGenerate }
376 canApprove={ canApprove }
379 createUnsignedTxn={this.handleCreateUnsignedTxn}
380 setUserApproval={this.handleSetUserApproval}
381 setTxn={this.handleSetTxn}
382 setStx={this.handleSetStx}
383 setNonce={this.handleSetNonce}
384 setChainId={this.handleSetChainId}
385 setGasPrice={this.handleSetGasPrice}
386 setGasLimit={this.handleSetGasLimit}
387 handleSubmit={this.handleSubmit} />
390 Maybe.Nothing.hasInstance(state.txError)
392 : <Warning className={'mt-8'}>
393 <H3 style={{marginTop: 0, paddingTop: 0}}>
395 'There was an error sending your transaction.'
398 { state.txError.value }
408export 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