Skip to content

Commit

Permalink
Merge pull request #40 from liuqiang1357/master
Browse files Browse the repository at this point in the history
add identity claim api
  • Loading branch information
liuqiang1357 authored Sep 5, 2020
2 parents dd24fd1 + 352b0bc commit 901c665
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 50 deletions.
6 changes: 3 additions & 3 deletions PRIVACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<p>Effective date: November 17, 2018</p>

<p>Cyano wallet ("us", "we", or "our") operates the Chrome extension "Cyano wallet" with homepage at https://github.com/OntologyCommunityDevelopers/cyano-wallet website (hereinafter referred to as the "Service").</p>
<p>Cyano wallet ("us", "we", or "our") operates the Chrome extension "Cyano wallet" with homepage at https://github.com/ontio/cyano-wallet website (hereinafter referred to as the "Service").</p>

<p>This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.</p>

<p>We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy. Unless otherwise defined in this Privacy Policy, the terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, accessible from https://github.com/OntologyCommunityDevelopers/cyano-wallet</p>
<p>We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy. Unless otherwise defined in this Privacy Policy, the terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, accessible from https://github.com/ontio/cyano-wallet</p>

<h2>Definitions</h2>
<ul>
Expand Down Expand Up @@ -123,5 +123,5 @@
<h2>Contact Us</h2>
<p>If you have any questions about this Privacy Policy, please contact us:</p>
<ul>
<li>By creating issue on our website: https://github.com/OntologyCommunityDevelopers/cyano-wallet/issues</li>
<li>By creating issue on our website: https://github.com/ontio/cyano-wallet/issues</li>
</ul>
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ npm install --global yarn
#### Download

```
git clone 'https://github.com/OntologyCommunityDevelopers/cyano-wallet.git'
git clone 'https://github.com/ontio/cyano-wallet.git'
```

#### Start the extension in watch mode
Expand All @@ -86,7 +86,7 @@ yarn build

#### Ledger support

Ledger support is provided by the Ontology TS SDK extension https://github.com/OntologyCommunityDevelopers/ontology-ts-sdk-ledger. Because Chrome allows communication with the Ledger only from HTTPS loaded page (which extension is not), there is used a HTTPS iframe embedded. The iframe is hosted on https://drxwrxomfjdx5.cloudfront.net/forwarder.html and the source codes are at https://github.com/OntologyCommunityDevelopers/ledger-forwarder . To change the Iframe address navigate to index.tsx and change the call to
Ledger support is provided by the Ontology TS SDK extension https://github.com/ontio/ontology-ts-sdk-ledger. Because Chrome allows communication with the Ledger only from HTTPS loaded page (which extension is not), there is used a HTTPS iframe embedded. The iframe is hosted on https://drxwrxomfjdx5.cloudfront.net/forwarder.html and the source codes are at https://github.com/ontio/ledger-forwarder . To change the Iframe address navigate to index.tsx and change the call to

```
Ledger.setLedgerTransport(new Ledger.LedgerTransportIframe('https://drxwrxomfjdx5.cloudfront.net/forwarder.html', true));
Expand All @@ -96,7 +96,7 @@ To use your Ledger, you also need the Official Ontology Ledger App installed on

#### Trezor support

Trezor support is provided by the Ontology TS SDK extension https://github.com/OntologyCommunityDevelopers/ontology-ts-sdk-trezor. Trezor allows communication with the Trezor Bridge v2 only from https://*.trezor.io page and Node environment, therefore it is not usable from web pages. But it is usable from Web extensions using WebRequest API.
Trezor support is provided by the Ontology TS SDK extension https://github.com/ontio/ontology-ts-sdk-trezor. Trezor allows communication with the Trezor Bridge v2 only from https://*.trezor.io page and Node environment, therefore it is not usable from web pages. But it is usable from Web extensions using WebRequest API.

To use your Trezor, you also needs custom firmware located at https://github.com/backslash47/trezor-core . Ontology support is not yet in official firmware.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cyano-wallet",
"version": "0.8.6",
"version": "0.8.7",
"private": true,
"scripts": {
"lint": "tslint -p .",
Expand All @@ -14,7 +14,7 @@
"@bugsnag/plugin-react": "^5.1.0",
"@ont-community/hdkey-secp256r1": "^1.0.1",
"@ont-community/ontology-ts-sdk-ledger": "^1.0.8",
"@ont-dev/ontology-dapi": "^0.5.1",
"@ont-dev/ontology-dapi": "^0.5.3-alpha.9",
"@toruslabs/torus-direct-web-sdk": "^3.0.0",
"autoprefixer": "7.1.6",
"axios": "^0.18.0",
Expand All @@ -32,7 +32,7 @@
"lodash": "^4.17.10",
"long": "^4.0.0",
"object-assign": "4.1.1",
"ontology-ts-sdk": "^1.1.2",
"ontology-ts-sdk": "^1.1.14-alpha.1",
"ontology-ts-test": "^0.2.37",
"postcss-flexbugs-fixes": "3.2.0",
"promise": "8.0.1",
Expand Down
29 changes: 29 additions & 0 deletions src/api/extraApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2018 Matus Zamborsky
* This file is part of Cyano Wallet.
*
* Cyano Wallet 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.
*
* Cyano Wallet 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 Cyano Wallet. If not, see <http://www.gnu.org/licenses/>.
*/
import { Wallet } from 'ontology-ts-sdk';

import { getWallet } from './authApi';

export function getCredentialRecords(wallet: string | Wallet) {
if (typeof wallet === 'string') {
wallet = getWallet(wallet);
}
const { credentialRecords } = wallet.extra || {} as any;
return credentialRecords || [];
}

7 changes: 5 additions & 2 deletions src/api/identityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ export function identityDelete(ontId: string, wallet: string | Wallet) {
};
}

export function getIdentity(walletEncoded: string) {
const wallet = getWallet(walletEncoded);
export function getIdentity(wallet: string | Wallet) {
if (typeof wallet === 'string') {
wallet = getWallet(wallet);
}

if (wallet.defaultOntid !== '') {
return wallet.defaultOntid;
} else {
Expand Down
44 changes: 43 additions & 1 deletion src/background/dapp/identity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IdentityApi, OntIdDDO } from '@ont-dev/ontology-dapi';
import { DDO, OntidContract } from 'ontology-ts-sdk';
import { DDO, OntidContract, SimpleMessage } from 'ontology-ts-sdk';
import { encodeWallet, getWallet } from '../../api/authApi';
import { getCredentialRecords } from '../../api/extraApi';
import { getIdentity } from '../../api/identityApi';
import { setWallet } from '../../redux/wallet'
import { getClient } from '../network';
import { getStore } from '../redux';

Expand Down Expand Up @@ -37,4 +40,43 @@ export const identityApi: IdentityApi = {
removeAttribute({ key }): Promise<void> {
throw new Error('UNSUPPORTED');
},

async addCredential({ tags, credential }): Promise<void> {
const state = getStore().getState();
const wallet = getWallet(state.wallet.wallet!);

const identity = getIdentity(wallet);
if (identity === null) {
return Promise.reject('NO_IDENTITY');
}

try {
SimpleMessage.deserialize(credential);
} catch {
return Promise.reject('INVALID_CREDENTIAL');
}

const credentialRecords = getCredentialRecords(wallet).slice();
credentialRecords.unshift({ identity, tags, credential });
wallet.extra = { ...(wallet.extra || {}), credentialRecords };

getStore().dispatch(setWallet(encodeWallet(wallet)));
},

async getCredentials(): Promise<Array<{ tags: string[], credential: string }>> {
const state = getStore().getState();
const wallet = getWallet(state.wallet.wallet!);

const identity = getIdentity(wallet);
if (identity === null) {
return Promise.reject('NO_IDENTITY');
}

const credentialRecords = getCredentialRecords(wallet);
const result = credentialRecords
.filter((record: any) => record.identity === identity)
.map((record: any) => ({ tags: record.tags, credential: record.credential }));

return result;
}
};
2 changes: 1 addition & 1 deletion src/background/dapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { stateChannelApi as stateChannel } from './stateChannel';

export function initDApiProvider() {
provider.registerProvider({
logMessages: false,
logMessages: true,
provider: {
asset,
identity,
Expand Down
2 changes: 1 addition & 1 deletion src/background/redux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const globalReducer = combineReducers({
settings: settingsReducer,
status: statusReducer,
transactionRequests: transactionRequestsReducer,
wallet: walletReducer
wallet: walletReducer,
});

export const aliases = {
Expand Down
47 changes: 39 additions & 8 deletions src/popup/pages/identity/dashboard/identityDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,56 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Cyano Wallet. If not, see <http://www.gnu.org/licenses/>.
*/
import { SimpleMessage } from 'ontology-ts-sdk';
import * as React from 'react';
import { RouterProps } from 'react-router';
import { bindActionCreators, Dispatch } from 'redux';
import { encodeWallet, getWallet } from '../../../../api/authApi';
import { getCredentialRecords } from '../../../../api/extraApi';
import { getIdentity } from '../../../../api/identityApi';
import { dummy, reduxConnect, withProps } from '../../../compose';
import { GlobalState } from '../../../redux';
import { reduxConnect, withProps } from '../../../compose';
import { Actions, GlobalState } from '../../../redux';
import { IdentityDashboardView, Props } from './identityDashboardView';

const mapStateToProps = (state: GlobalState) => ({
walletEncoded: state.wallet.wallet
walletEncoded: state.wallet.wallet,
});

const mapDispatchToProps = (dispatch: Dispatch) =>
bindActionCreators(
{
setWallet: Actions.wallet.setWallet,
},
dispatch,
);

const enhancer = (Component: React.ComponentType<Props>) => (props: RouterProps) => (
reduxConnect(mapStateToProps, dummy, (reduxProps) => (
withProps({
ontId: getIdentity(reduxProps.walletEncoded!)!
reduxConnect(mapStateToProps, mapDispatchToProps, (reduxProps, actions) => {
const wallet = getWallet(reduxProps.walletEncoded!);
const ontId = getIdentity(wallet)!;
const credentialRecords = getCredentialRecords(wallet);

const filteredCredentialRecords = credentialRecords
.filter((item: any) => item.identity === ontId);

const mappedCredentialRecords = filteredCredentialRecords
.map((item: any) => ({ tags: item.tags, credential: SimpleMessage.deserialize(item.credential) }));

return withProps({
credentialRecords: mappedCredentialRecords,
handleDelClick: (index: number) => {
const credentialRecord = filteredCredentialRecords[index];
const indexInOrigin = credentialRecords.indexOf(credentialRecord);
const newCredentialRecords = credentialRecords.slice();
newCredentialRecords.splice(indexInOrigin, 1);
wallet.extra = { ...(wallet.extra || {}), credentialRecords: newCredentialRecords };
actions.setWallet(encodeWallet(wallet));
},
ontId,
}, (injectedProps) => (
<Component {...injectedProps} />
))
))
));
})
);

export const IdentityDashboard = enhancer(IdentityDashboardView);
66 changes: 50 additions & 16 deletions src/popup/pages/identity/dashboard/identityDashboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,63 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Cyano Wallet. If not, see <http://www.gnu.org/licenses/>.
*/
import { format } from 'date-fns';
import { SimpleMessage } from 'ontology-ts-sdk';
import * as React from 'react';
import { List } from 'semantic-ui-react';
import { Filler, IdentityLogoHeader, Spacer, StatusBar, View } from '../../../components';

export interface Props {
credentialRecords: Array<{ tags: string[], credential: SimpleMessage }>;
handleDelClick: (index: number) => void;
ontId: string;
}

export const IdentityDashboardView: React.SFC<Props> = (props) => (
<View orientation="column" fluid={true}>
<View orientation="column" className="part gradient">
<IdentityLogoHeader title="My Identity" />
<View content={true}>
<View orientation="column">
<h4>Registered ONT ID</h4>
<label>{props.ontId}</label>
export const IdentityDashboardView: React.SFC<Props> = (props) => {
return (
<View orientation="column" fluid={true}>
<View orientation="column" className="part gradient">
<IdentityLogoHeader title="My Identity" />
<View content={true}>
<View orientation="column">
<h4>Registered ONT ID</h4>
<label>{props.ontId}</label>
</View>
</View>
</View>
<View orientation="column" fluid={true} content={true} className="spread-around">
<h2>Verifiable Credentials</h2>
<Spacer />
<View orientation="column" className="scrollView">
<List divided={true}>
{props.credentialRecords.map((record, i) => (
<List.Item key={i}>
<List.Icon
name="times circle outline"
size="large"
verticalAlign="middle"
onClick={(e: React.MouseEvent) => {
e.stopPropagation();
props.handleDelClick(i);
}}
/>
<List.Content className="breakWords">
<List.Header>Tags: {record.tags.join(' ')}</List.Header>
<List.Description>Issuer: {record.credential.metadata.issuer}</List.Description>
<List.Description>MessageId: {record.credential.metadata.messageId}</List.Description>
<List.Description>Issued At: {format(record.credential.metadata.issuedAt * 1000, 'MMM Do YYYY HH:mm:ss')}</List.Description>
{record.credential.metadata.expireAt &&
<List.Description>Expire At: {format(record.credential.metadata.expireAt * 1000, 'MMM Do YYYY HH:mm:ss')}</List.Description>
}
</List.Content>
</List.Item>
))}
</List>
</View>
<Spacer />
<Filler />
</View>
<StatusBar />
</View>
<View orientation="column" fluid={true} content={true} className="spread-around">
<h1>Verifiable claims</h1>
<Spacer />
<Filler />
</View>
<StatusBar />
</View>
);
)
};
3 changes: 2 additions & 1 deletion src/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { addToken, addTrustedSc, delToken, delTrustedSc, setSettings } from './s
import { changeNetworkState } from './status';
import { addRequest, resolveRequest, submitRequest, updateRequest } from './transactionRequests';
import { clearIdentity, clearWallet, setWallet } from './wallet';

export default {
loader: {
finishLoading,
Expand Down Expand Up @@ -60,5 +61,5 @@ export default {
clearIdentity,
clearWallet,
setWallet
}
},
};
1 change: 1 addition & 0 deletions src/redux/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SettingsState } from './settings';
import { StatusState } from './status';
import { TransactionRequestsState } from './transactionRequests';
import { WalletState } from './wallet';

export interface GlobalState {
loader: LoaderState;
password: PasswordState;
Expand Down
Loading

0 comments on commit 901c665

Please sign in to comment.