Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to export seed phrase or private key for hot signers #1665

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/dash/Signer/SignerStatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class SignerStatus extends React.Component {
unlockSubmit() {
link.rpc('unlockSigner', this.props.signer.id, this.state.unlockInput, (err) => {
if (err) this.shake()
else {
if (this.props.exportCb) this.props.exportCb()
this.setState({ unlockInput: '' })
}
})
}

Expand Down Expand Up @@ -84,7 +88,7 @@ class SignerStatus extends React.Component {

const signer = this.props.signer || {}

return !isHardwareSigner(signer) && signer.id && signer.status === 'locked' ? (
return !isHardwareSigner(signer) && signer.id && (signer.status === 'locked' || this.props.exportCb) ? (
<div className={shake ? 'signerStatus headShake' : 'signerStatus'} ref={this.statusRef}>
<div className='signerStatusWrap'>
<div className='signerStatusMain'>
Expand All @@ -103,9 +107,11 @@ class SignerStatus extends React.Component {
}
}}
/>
<div className='signerUnlockInputLabel'>{'Enter password to unlock'}</div>
<div className='signerUnlockInputLabel'>
{'Enter password to ' + (this.props.exportCb ? 'export' : 'unlock')}
</div>
<div className='signerUnlockSubmit' onClick={this.unlockSubmit.bind(this)}>
{'Unlock'}
{this.props.exportCb ? 'Export' : 'Unlock'}
</div>
</div>
</div>
Expand Down
257 changes: 161 additions & 96 deletions app/dash/Signer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class Signer extends React.Component {
addressLimit: 5,
latticePairCode: '',
tPin: '',
tPhrase: ''
tPhrase: '',
exportIndex: null,
exportCb: null,
exportSecret: null
}
}

Expand Down Expand Up @@ -202,7 +205,15 @@ class Signer extends React.Component {
statusText() {
const status = this.getStatus()

if (status === 'ok') {
if (this.state.exportCb) {
const signer = this.store('main.signers', this.props.id)
return (
<div className='signerStatusText signerStatusIssue'>
{'exporting ' +
(this.state.exportIndex === null ? 'seed phrase' : signer.addresses[this.state.exportIndex])}
</div>
)
} else if (status === 'ok') {
return <div className='signerStatusText signerStatusReady'>{'ready to sign'}</div>
} else if (status === 'locked') {
const hwSigner = isHardwareSigner(this.props.type)
Expand Down Expand Up @@ -350,7 +361,13 @@ class Signer extends React.Component {
renderSignerStatus() {
const signer = this.store('main.signers', this.props.id)

return <SignerStatus signer={signer} />
return <SignerStatus signer={signer} exportCb={this.state.exportCb} />
}

showSecret() {
link.rpc('getSecret', this.props.id, this.state.exportIndex, (err, secret) => {
if (!err) this.setState({ exportSecret: secret, exportCb: null })
})
}

renderExpanded() {
Expand All @@ -375,108 +392,156 @@ class Signer extends React.Component {
const zIndex = 1000 - index

return (
<div className={'expandedSigner cardShow'} style={{ zIndex }}>
{<div style={{ height: '22px' }} />}
{this.statusText()}
{type === 'lattice' && status === 'pair' ? (
<div className='signerLatticePair'>
<div className='signerLatticePairTitle'>Please input your Lattice&apos;s pairing code</div>
<div className='signerLatticePairInput'>
<input
autoFocus
tabIndex='1'
value={this.state.latticePairCode}
onChange={(e) => this.setState({ latticePairCode: (e.target.value || '').toUpperCase() })}
onKeyPress={(e) => {
if (e.key === 'Enter') this.pairToLattice()
}}
/>
</div>
<div onMouseDown={() => this.pairToLattice()} className='signerLatticePairSubmit'>
Pair
<div>
<div className={'expandedSigner cardShow'} style={{ zIndex }}>
{<div style={{ height: '22px' }} />}
{this.statusText()}
{type === 'lattice' && status === 'pair' ? (
<div className='signerLatticePair'>
<div className='signerLatticePairTitle'>Please input your Lattice&apos;s pairing code</div>
<div className='signerLatticePairInput'>
<input
autoFocus
tabIndex='1'
value={this.state.latticePairCode}
onChange={(e) => this.setState({ latticePairCode: (e.target.value || '').toUpperCase() })}
onKeyPress={(e) => {
if (e.key === 'Enter') this.pairToLattice()
}}
/>
</div>
<div onMouseDown={() => this.pairToLattice()} className='signerLatticePairSubmit'>
Pair
</div>
</div>
</div>
) : status === 'ok' || isLocked ? (
<>
{this.renderSignerStatus()}
<div className='signerAddedAccountTitle'>{'available accounts'}</div>
<div className='signerAccounts'>
{signer.addresses.slice(startIndex, startIndex + addressLimit).map((address, index) => {
const added = this.store('main.accounts', address.toLowerCase())
const checkSummedAddress = getAddress(address)
return (
<div
key={address}
className={!added ? 'signerAccount' : 'signerAccount signerAccountAdded'}
onClick={() => {
if (this.store('main.accounts', address.toLowerCase())) {
link.rpc('removeAccount', address, {}, () => {})
} else {
const type = getSignerDisplayType(signer)
link.rpc(
'createAccount',
address,
`${capitalize(type)} Account`,
{ type: signer.type },
(e) => {
if (e) console.error(e)
}
)
}
}}
>
<div className='signerAccountIndex'>{index + 1 + startIndex}</div>
<div className='signerAccountAddress'>
{checkSummedAddress.substr(0, 11)} {svg.octicon('kebab-horizontal', { height: 20 })}{' '}
{checkSummedAddress.substr(address.length - 10)}
) : status === 'ok' || isLocked ? (
<>
{this.renderSignerStatus()}
<div className='signerAddedAccountTitle'>{'available accounts'}</div>
<div className='signerAccounts'>
{signer.addresses.slice(startIndex, startIndex + addressLimit).map((address, index) => {
const added = this.store('main.accounts', address.toLowerCase())
const checkSummedAddress = getAddress(address)
return (
<div
key={address}
className={!added ? 'signerAccount' : 'signerAccount signerAccountAdded'}
onClick={() => {
if (this.store('main.accounts', address.toLowerCase())) {
link.rpc('removeAccount', address, {}, () => {})
} else {
const type = getSignerDisplayType(signer)
link.rpc(
'createAccount',
address,
`${capitalize(type)} Account`,
{ type: signer.type },
(e) => {
if (e) console.error(e)
}
)
}
}}
>
<div className='signerAccountIndex'>{index + 1 + startIndex}</div>
<div className='signerAccountAddress'>
{checkSummedAddress.substr(0, 11)} {svg.octicon('kebab-horizontal', { height: 20 })}{' '}
{checkSummedAddress.substr(address.length - 10)}
</div>
{status === 'ok' && (
<div
className='signerAccountExport'
onClick={(e) => {
e.stopPropagation()
if (this.state.exportCb && this.state.exportIndex === index + startIndex) {
this.setState({ exportCb: null })
} else {
this.setState({
exportIndex: index + startIndex,
exportCb: this.showSecret.bind(this)
})
}
}}
>
{svg.export(15)}
</div>
)}
<div className='signerAccountCheck' />
</div>
<div className='signerAccountCheck' />
</div>
)
})}
</div>
<div className='signerBottom'>
<div className='signerBottomPageBack' onMouseDown={() => this.nextPage(true)}>
{svg.triangleLeft(20)}
)
})}
</div>
<div className='signerBottom'>
<div className='signerBottomPageBack' onMouseDown={() => this.nextPage(true)}>
{svg.triangleLeft(20)}
</div>
<div className='signerBottomPages'>
{page + 1 + ' / ' + Math.ceil(signer.addresses.length / addressLimit)}
</div>
<div className='signerBottomPageNext' onMouseDown={() => this.nextPage()}>
{svg.triangleLeft(20)}
</div>
</div>
<div className='signerBottomPages'>
{page + 1 + ' / ' + Math.ceil(signer.addresses.length / addressLimit)}
</>
) : type === 'trezor' && (status === 'need pin' || status === 'enter passphrase') ? (
<div className='signerInterface'>
{this.renderTrezorPin(this.props.type === 'trezor' && status === 'need pin')}
{this.renderTrezorPhrase(this.props.type === 'trezor' && status === 'enter passphrase')}
</div>
) : loading ? (
<div className='signerLoading'>
<div className='signerLoadingLoader' />
</div>
) : (
<></>
)}
<div className='signerControls'>
{permissionId ? (
<div className='signerControlDetail'>
<div className='signerControlDetailKey'>{'PERMISSION ID:'}</div>
<div className='signerControlDetailValue'>{permissionId}</div>
</div>
<div className='signerBottomPageNext' onMouseDown={() => this.nextPage()}>
{svg.triangleLeft(20)}
) : null}
{canReconnect && <ReloadSignerButton id={id} />}
{this.props.type === 'seed' && status === 'ok' && (
<div
className='signerControlOption signerControlOptionImportant'
onClick={() => {
if (this.state.exportCb && this.state.exportIndex === null) {
this.setState({ exportCb: null })
} else {
this.setState({ exportIndex: null, exportCb: this.showSecret.bind(this) })
}
}}
>
Export Seed Phrase
</div>
)}
<div
className='signerControlOption signerControlOptionImportant'
onClick={() => {
link.send('dash:removeSigner', id)
link.send('tray:action', 'backDash')
}}
>
Remove Signer
</div>
</>
) : type === 'trezor' && (status === 'need pin' || status === 'enter passphrase') ? (
<div className='signerInterface'>
{this.renderTrezorPin(this.props.type === 'trezor' && status === 'need pin')}
{this.renderTrezorPhrase(this.props.type === 'trezor' && status === 'enter passphrase')}
</div>
) : loading ? (
<div className='signerLoading'>
<div className='signerLoadingLoader' />
</div>
) : (
<></>
)}
<div className='signerControls'>
{permissionId ? (
<div className='signerControlDetail'>
<div className='signerControlDetailKey'>{'PERMISSION ID:'}</div>
<div className='signerControlDetailValue'>{permissionId}</div>
</div>
{this.state.exportSecret && (
<div className='signerSecretExport'>
<textarea readOnly value={this.state.exportSecret} />
<div
className='signerSecretOption'
onClick={() => link.send('tray:clipboardData', this.state.exportSecret)}
>
Copy
</div>
<div className='signerSecretOption' onClick={() => this.setState({ exportSecret: null })}>
Hide
</div>
) : null}
{canReconnect && <ReloadSignerButton id={id} />}
<div
className='signerControlOption signerControlOptionImportant'
onClick={() => {
link.send('dash:removeSigner', id)
link.send('tray:action', 'backDash')
}}
>
Remove Signer
</div>
</div>
)}
</div>
)
}
Expand Down
Loading