-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from MickWang/layer2-login
Layer2 login
- Loading branch information
Showing
13 changed files
with
1,527 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import HDKey from '@ont-community/hdkey-secp256r1'; | ||
import { decryptAccount } from '../../api/accountApi'; | ||
import { getWallet } from '../../api/authApi'; | ||
import { StateChannelLoginRequest } from '../../redux/transactionRequests'; | ||
import { getStore } from '../redux'; | ||
|
||
export async function stateChannelLogin(request: StateChannelLoginRequest, password: string): Promise<string> { | ||
const state = getStore().getState(); | ||
const wallet = getWallet(state.wallet.wallet!); | ||
|
||
const privateKey = decryptAccount(wallet, password); | ||
|
||
const seed = privateKey.key; | ||
const hdk = HDKey.fromMasterSeed(Buffer.from(seed, 'hex')); | ||
const path = "m/44'/1024'/0'/0/0"; | ||
const derive = hdk.derive(path); | ||
const derivedPrv = Buffer.from(derive.privateKey).toString('hex'); | ||
|
||
return derivedPrv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Signature, StateChannelApi } from 'ontology-dapi'; | ||
import { getRequestsManager } from '../requestsManager'; | ||
|
||
|
||
export const stateChannelApi: StateChannelApi = { | ||
login(): Promise<string> { | ||
return getRequestsManager().initStateChannelLogin(); | ||
}, | ||
sign(): Promise<Signature> { | ||
throw new Error(('Not supported now')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2018 Matus Zamborsky | ||
* This file is part of The Ontology Wallet&ID. | ||
* | ||
* The The Ontology Wallet&ID is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Ontology Wallet&ID is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with The Ontology Wallet&ID. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { get } from 'lodash'; | ||
import * as React from 'react'; | ||
import { RouteComponentProps } from 'react-router'; | ||
import { bindActionCreators, Dispatch } from 'redux'; | ||
import { dummy, reduxConnect, withProps } from '../../compose'; | ||
import { Actions } from '../../redux'; | ||
import { Props, StateChannelLoginView } from './stateChannelLoginView'; | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => | ||
bindActionCreators( | ||
{ | ||
resolveRequest: Actions.transactionRequests.resolveRequest, | ||
}, | ||
dispatch, | ||
); | ||
|
||
const enhancer = (Component: React.ComponentType<Props>) => (props: RouteComponentProps<any>) => | ||
reduxConnect(dummy, mapDispatchToProps, (reduxProps, actions) => | ||
withProps( | ||
{ | ||
handleCancel: async () => { | ||
props.history.goBack(); | ||
|
||
const requestId: string = get(props.location, 'state.requestId'); | ||
await actions.resolveRequest(requestId, 'CANCELED'); | ||
}, | ||
handleConfirm: async () => { | ||
const requestId: string = get(props.location, 'state.requestId'); | ||
|
||
props.history.push('/confirm', { requestId, redirectSucess: '/dashboard', redirectFail: '/dashboard' }); | ||
}, | ||
locked: get(props.location, 'state.locked', false) | ||
}, | ||
(injectedProps) => <Component {...injectedProps} />, | ||
), | ||
); | ||
|
||
export const StateChannelLogin = enhancer(StateChannelLoginView); |
46 changes: 46 additions & 0 deletions
46
src/popup/pages/stateChannelLogin/stateChannelLoginView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2018 Matus Zamborsky | ||
* This file is part of The Ontology Wallet&ID. | ||
* | ||
* The The Ontology Wallet&ID is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Ontology Wallet&ID is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with The Ontology Wallet&ID. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import * as React from 'react'; | ||
import { Button } from 'semantic-ui-react'; | ||
import { AccountLogoHeader, Filler, StatusBar, View } from '../../components'; | ||
|
||
|
||
export interface Props { | ||
locked: boolean; | ||
handleConfirm: () => void; | ||
handleCancel: () => void; | ||
} | ||
|
||
export const StateChannelLoginView: React.SFC<Props> = (props) => ( | ||
<View orientation="column" fluid={true}> | ||
<View orientation="column" className="part gradient"> | ||
<AccountLogoHeader title="Login State Channel Client" /> | ||
<View content={true} className="spread-around"> | ||
<View>You are about to login a state channel client.</View> | ||
</View> | ||
</View> | ||
<View orientation="column" fluid={true} content={true}> | ||
<Filler /> | ||
<View className="buttons"> | ||
<Button onClick={props.handleConfirm}>Continue</Button> | ||
<Button onClick={props.handleCancel}>Cancel</Button> | ||
</View> | ||
</View> | ||
<StatusBar /> | ||
</View> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.