This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add verifiable presentation method (#59)
- Loading branch information
Showing
22 changed files
with
397 additions
and
7 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
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,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 @@ | ||
build/ |
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,45 @@ | ||
{ | ||
"name": "concordium-dapp-request-verifiable-presentation", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@concordium/react-components": "workspace:^", | ||
"@concordium/web-sdk": "^7.1.0", | ||
"@types/node": "^16.18.16", | ||
"@types/react": "^18.0.28", | ||
"@types/react-dom": "^18.0.11", | ||
"bootstrap": "^5.2.3", | ||
"react": "^18.2.0", | ||
"react-bootstrap": "^2.7.2", | ||
"react-dom": "^18.2.0", | ||
"react-scripts": "^5.0.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"devDependencies": { | ||
"prettier": "2.8.1" | ||
} | ||
} |
Binary file not shown.
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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<title>Identity proofs | Sample Concordium dApp</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,25 @@ | ||
{ | ||
"short_name": "Sample dApp", | ||
"name": "Sample Concordium dApp", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
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,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
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,116 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { Alert, Button, Card, Col, Container, Form, Row, Spinner } from 'react-bootstrap'; | ||
import { | ||
TESTNET, | ||
WalletConnectionProps, | ||
WithWalletConnector, | ||
useConnect, | ||
useConnection, | ||
} from '@concordium/react-components'; | ||
import { | ||
AttributeKeyString, | ||
MIN_DATE, | ||
VerifiablePresentation, | ||
Web3StatementBuilder, | ||
getPastDate, | ||
} from '@concordium/web-sdk'; | ||
import { WalletConnectorButton } from './WalletConnectorButton'; | ||
import { BROWSER_WALLET, WALLET_CONNECT } from './config'; | ||
|
||
export default function App() { | ||
return ( | ||
<Container> | ||
<h1>Identity proofs</h1> | ||
<WithWalletConnector network={TESTNET}>{(props) => <Main {...props} />}</WithWalletConnector> | ||
</Container> | ||
); | ||
} | ||
|
||
function Main(props: WalletConnectionProps) { | ||
const { activeConnectorType, activeConnector, activeConnectorError, connectedAccounts, genesisHashes } = props; | ||
const { connection, setConnection, account } = useConnection(connectedAccounts, genesisHashes); | ||
const { connect, isConnecting, connectError } = useConnect(activeConnector, setConnection); | ||
|
||
const [verifiablePresentation, setVerifiablePresentation] = useState<VerifiablePresentation>(); | ||
const [error, setError] = useState(''); | ||
const [isWaiting, setIsWaiting] = useState(false); | ||
|
||
const handleSubmit = useCallback(() => { | ||
setVerifiablePresentation(undefined); | ||
setError(''); | ||
setIsWaiting(true); | ||
|
||
const statementBuilder = new Web3StatementBuilder().addForIdentityCredentials([0, 1, 2, 3, 4, 5], (b) => | ||
b.addRange(AttributeKeyString.dob, MIN_DATE, getPastDate(18, 1)) | ||
); | ||
const statement = statementBuilder.getStatements(); | ||
// In a production scenario the challenge should not be hardcoded, in order to avoid accepting proofs created for other contexts. | ||
const challenge = 'beefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef'; | ||
|
||
connection | ||
?.requestVerifiablePresentation(challenge, statement) | ||
.then((res) => setVerifiablePresentation(res)) | ||
.catch((e: Error) => setError(`Failed to get verifiable presentation: ${e.message}`)) | ||
.finally(() => setIsWaiting(false)); | ||
}, [connection]); | ||
|
||
return ( | ||
<> | ||
<Row className="mt-3 mb-3"> | ||
<Col> | ||
<WalletConnectorButton | ||
connectorType={BROWSER_WALLET} | ||
connectorName="Browser Wallet" | ||
connection={connection} | ||
{...props} | ||
/> | ||
</Col> | ||
<Col> | ||
<WalletConnectorButton | ||
connectorType={WALLET_CONNECT} | ||
connectorName="WalletConnect" | ||
connection={connection} | ||
{...props} | ||
/> | ||
</Col> | ||
</Row> | ||
<Row className="mt-3 mb-3"> | ||
<Col> | ||
{activeConnectorError && <Alert variant="danger">Connector error: {activeConnectorError}.</Alert>} | ||
{!activeConnectorError && activeConnectorType && !activeConnector && <Spinner />} | ||
{connectError && <Alert variant="danger">Connection error: {connectError}.</Alert>} | ||
{activeConnector && !account && ( | ||
<Button type="button" onClick={connect} disabled={isConnecting}> | ||
{isConnecting && 'Connecting...'} | ||
{!isConnecting && activeConnectorType === BROWSER_WALLET && 'Connect Browser Wallet'} | ||
{!isConnecting && activeConnectorType === WALLET_CONNECT && 'Connect Mobile Wallet'} | ||
</Button> | ||
)} | ||
</Col> | ||
</Row> | ||
{account && ( | ||
<Row className="mt-3 mb-3"> | ||
<Col> | ||
Connected to account <code>{account}</code>. | ||
</Col> | ||
</Row> | ||
)} | ||
<Form.Group as={Row} className="mb-3"> | ||
<Col sm={3}> | ||
<Button variant="primary" onClick={handleSubmit} disabled={!connection || isWaiting}> | ||
{isWaiting ? 'Waiting for proof...' : 'Request proof'} | ||
</Button> | ||
</Col> | ||
</Form.Group> | ||
{error && <Alert variant="danger">{error}</Alert>} | ||
{verifiablePresentation && ( | ||
<Card> | ||
<Card.Header>Verifiable presentation</Card.Header> | ||
<Card.Body> | ||
<Card.Text>{JSON.stringify(verifiablePresentation)}</Card.Text> | ||
</Card.Body> | ||
</Card> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.