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

Revoke credentials #337

Merged
merged 18 commits into from
Aug 17, 2023
Merged
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
2 changes: 1 addition & 1 deletion examples/add-example-Web3Id/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The example project included in this repository, serves as a working example of
## Installing

- Run `yarn` in package root.
- Build concordium helpers by running `yarn build:api-helpers`.
- Build concordium helpers by running `yarn build:api-helpers`.

## Running the example

Expand Down
33 changes: 18 additions & 15 deletions examples/add-example-Web3Id/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,29 @@
b
.revealAttribute('degreeType')
.addMembership('degreeName', ['Bachelor of Science and Arts', 'Bachelor of Finance'])
).getStatements();
)
.getStatements();
sendStatement(statement);
});
document.getElementById('web3ProofIdOnly').addEventListener('click', () => {
const statement = new concordiumSDK.Web3StatementBuilder()
.addForIdentityCredentials([0, 1, 2], (b) =>
b.revealAttribute('firstName').addRange('dob', '08000101', '20000101')
).getStatements();
.addForIdentityCredentials([0, 1, 2], (b) =>
b.revealAttribute('firstName').addRange('dob', '08000101', '20000101')
)
.getStatements();
sendStatement(statement);
});
document.getElementById('web3ProofMixed').addEventListener('click', () => {
const statement = new concordiumSDK.Web3StatementBuilder()
.addForIdentityCredentials([0, 1, 2], (b) =>
b.revealAttribute('firstName').addRange('dob', '08000101', '20000101')
)
.addForVerifiableCredentials([{ index: 5463n, subindex: 0n }], (b) =>
b
.revealAttribute('degreeType')
.addMembership('degreeName', ['Bachelor of Science and Arts', 'Bachelor of Finance'])
).getStatements();
.addForIdentityCredentials([0, 1, 2], (b) =>
b.revealAttribute('firstName').addRange('dob', '08000101', '20000101')
)
.addForVerifiableCredentials([{ index: 5463n, subindex: 0n }], (b) =>
b
.revealAttribute('degreeType')
.addMembership('degreeName', ['Bachelor of Science and Arts', 'Bachelor of Finance'])
)
.getStatements();
sendStatement(statement);
});
// Add credential
Expand Down Expand Up @@ -157,8 +160,8 @@ <h3>Attribute values:</h3>
<h3>Request Proofs:</h3>
<button id="web3ProofWeb3IdOnly">Request a Proof using web3Id</button>
<br />
<button id="web3ProofIdOnly">Request a Proof using account credentials</button>
<br />
<button id="web3ProofMixed">Request a Proof using both web3Id and account credentials</button>
<button id="web3ProofIdOnly">Request a Proof using account credentials</button>
<br />
<button id="web3ProofMixed">Request a Proof using both web3Id and account credentials</button>
</body>
</html>
6 changes: 6 additions & 0 deletions packages/browser-wallet/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ module.exports = {

return config;
},
babel: async (options) => {
return {
...options,
plugins: options.plugins.filter((x) => !(typeof x === 'string' && x.includes('plugin-transform-classes'))),
};
},
};
1 change: 1 addition & 0 deletions packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@concordium/browser-wallet-api": "workspace:^",
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@noble/ed25519": "^1.7.0",
"@protobuf-ts/runtime-rpc": "^2.8.2",
"@scure/bip39": "^1.1.0",
"axios": "^0.27.2",
Expand Down
15 changes: 15 additions & 0 deletions packages/browser-wallet/src/assets/svg/archive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions packages/browser-wallet/src/assets/svg/back-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/browser-wallet/src/assets/svg/more.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/browser-wallet/src/assets/svg/revoke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
.verifiable-credential-list {
height: calc(100% - 56px);
background-color: $color-bg;
overflow-y: auto;

&__card {
margin: rem(16px);
margin-left: rem(16px);
margin-right: rem(16px);
margin-bottom: rem(16px);

&:not(:first-child) {
margin-top: rem(16px);
}
orhoj marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React, { useCallback, useMemo } from 'react';
import { useAtomValue } from 'jotai';
import { VerifiableCredential, VerifiableCredentialSchema, VerifiableCredentialStatus } from '@shared/storage/types';
import Topbar, { ButtonTypes, MenuButton } from '@popup/shared/Topbar/Topbar';
import { useTranslation } from 'react-i18next';
import { AccountTransactionType } from '@concordium/web-sdk';
import { useLocation, useNavigate } from 'react-router-dom';
import { grpcClientAtom } from '@popup/store/settings';
import { absoluteRoutes } from '@popup/constants/routes';
import { useHdWallet } from '@popup/shared/utils/account-helpers';
import {
VerifiableCredentialMetadata,
buildRevokeTransaction,
buildRevokeTransactionParameters,
getCredentialHolderId,
getCredentialRegistryContractAddress,
getRevokeTransactionExecutionEnergyEstimate,
} from '@shared/utils/verifiable-credential-helpers';
import { fetchContractName } from '@shared/utils/token-helpers';
import { ClassName } from 'wallet-common-helpers';
import { accountRoutes } from '../Account/routes';
import { ConfirmGenericTransferState } from '../Account/ConfirmGenericTransfer';
import RevokeIcon from '../../../assets/svg/revoke.svg';
import { useCredentialEntry } from './VerifiableCredentialHooks';
import { VerifiableCredentialCard } from './VerifiableCredentialCard';

interface CredentialDetailsProps extends ClassName {
credential: VerifiableCredential;
status: VerifiableCredentialStatus;
metadata: VerifiableCredentialMetadata;
schema: VerifiableCredentialSchema;
backButtonOnClick: () => void;
}

export default function VerifiableCredentialDetails({
credential,
status,
metadata,
schema,
backButtonOnClick,
className,
}: CredentialDetailsProps) {
const nav = useNavigate();
const { pathname } = useLocation();
const { t } = useTranslation('verifiableCredential');
const client = useAtomValue(grpcClientAtom);
const hdWallet = useHdWallet();
const credentialEntry = useCredentialEntry(credential);

const goToConfirmPage = useCallback(async () => {
if (credentialEntry === undefined || hdWallet === undefined) {
return;
}

const contractAddress = getCredentialRegistryContractAddress(credential.id);
const credentialId = getCredentialHolderId(credential.id);
const contractName = await fetchContractName(client, contractAddress.index, contractAddress.subindex);
if (contractName === undefined) {
throw new Error(`Unable to find contract name for address: ${contractAddress}`);
}

const signingKey = hdWallet
.getVerifiableCredentialSigningKey(contractAddress, credential.index)
.toString('hex');

const parameters = await buildRevokeTransactionParameters(
contractAddress,
credentialId,
credentialEntry.revocationNonce,
signingKey
);
const maxExecutionEnergy = await getRevokeTransactionExecutionEnergyEstimate(client, contractName, parameters);
const payload = await buildRevokeTransaction(
contractAddress,
contractName,
credentialId,
maxExecutionEnergy,
parameters
);

const confirmTransferState: ConfirmGenericTransferState = {
payload,
type: AccountTransactionType.Update,
};

nav(`${absoluteRoutes.home.account.path}/${accountRoutes.confirmTransfer}`, {
state: confirmTransferState,
});
}, [client, credential, hdWallet, credentialEntry, nav, pathname]);

const menuButton: MenuButton | undefined = useMemo(() => {
if (
credentialEntry === undefined ||
!credentialEntry.credentialInfo.holderRevocable ||
status === VerifiableCredentialStatus.Revoked
) {
return undefined;
}

return {
type: ButtonTypes.More,
items: [
{
title: t('menu.revoke'),
icon: <RevokeIcon />,
onClick: goToConfirmPage,
},
],
};
}, [credentialEntry, goToConfirmPage]);

// Wait for the credential entry to be loaded from the chain, and for the HdWallet
// to be loaded to be ready to derive keys.
if (credentialEntry === undefined || hdWallet === undefined) {
return null;
}

return (
<>
<Topbar title={t('topbar.details')} onBackButtonClick={backButtonOnClick} menuButton={menuButton} />
<div className="verifiable-credential-list">
<VerifiableCredentialCard
className={className}
credentialSubject={credential.credentialSubject}
schema={schema}
credentialStatus={status}
metadata={metadata}
/>
</div>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AsyncWrapper } from '@popup/store/utils';
import { ConcordiumGRPCClient } from '@concordium/web-sdk';

/**
* Retrieve the on-chain credential status for a verifiable credential in a registry contract.
* Retrieve the on-chain credential status for a verifiable credential in a CIS-4 credential registry contract.
* @param credential the verifiable credential to lookup the status for
* @returns the status for the given credential
*/
Expand Down
Loading
Loading