-
Notifications
You must be signed in to change notification settings - Fork 9
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 #388 from Concordium/feature/web3-id
Feature/web3
- Loading branch information
Showing
178 changed files
with
8,268 additions
and
491 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,18 @@ | ||
# Add example Web3Id web page | ||
|
||
The example project included in this repository, serves as a working example of how to interact with web3Id parts of the Concordium browser wallet. | ||
|
||
## Prerequisites | ||
|
||
- Browser wallet extension must be installed in google chrome. | ||
- A web3Id-issuer running (https://github.com/Concordium/concordium-web3id/tree/main/services/web3id-issuer) | ||
|
||
## Installing | ||
|
||
- Run `yarn` in package root. | ||
- Build concordium helpers by running `yarn build:api-helpers`. | ||
|
||
## Running the example | ||
|
||
- Run `yarn start` in a terminal | ||
- Open URL logged in console (typically http://127.0.0.1:8080) |
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,205 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Example Web3Id</title> | ||
<script src="/sdk.js"></script> | ||
<script src="/helpers.js"></script> | ||
<script src="https://unpkg.com/cbor-web"></script> | ||
<meta charset="utf-8" /> | ||
<script> | ||
let currentAccountAddress = ''; | ||
async function setupPage() { | ||
const provider = await concordiumHelpers.detectConcordiumProvider(); | ||
document.getElementById('requestAccounts').addEventListener('click', () => { | ||
provider.requestAccounts().then((accountAddresses) => { | ||
currentAccountAddress = accountAddresses[0]; | ||
document.getElementById('accountAddress').innerHTML = currentAccountAddress; | ||
}); | ||
}); | ||
|
||
function sendStatement(statement) { | ||
// Should be not be hardcoded | ||
console.log(statement); | ||
const challenge = '94d3e85bbc8ff0091e562ad8ef6c30d57f29b19f17c98ce155df2a30100dAAAA'; | ||
provider | ||
.requestVerifiablePresentation(challenge, statement) | ||
.then((proof) => { | ||
console.log(proof); | ||
alert('Proof received! (check the console)'); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
alert(error); | ||
}); | ||
} | ||
|
||
provider.on('accountDisconnected', (accountAddress) => (currentAccountAddress = undefined)); | ||
provider.on('accountChanged', (accountAddress) => (currentAccountAddress = accountAddress)); | ||
provider.on('chainChanged', (chain) => alert(chain)); | ||
// Request proofs | ||
document.getElementById('web3ProofWeb3IdOnly').addEventListener('click', () => { | ||
const statement = new concordiumSDK.Web3StatementBuilder() | ||
.addForVerifiableCredentials([{ index: 6105n, subindex: 0n }], (b) => | ||
b | ||
.revealAttribute('degreeType') | ||
.revealAttribute('degreeName') | ||
.revealAttribute('graduationDate') | ||
.revealAttribute('test') | ||
) | ||
.addForVerifiableCredentials([{ index: 6105n, subindex: 0n }], (b) => | ||
b | ||
.addNonMembership('degreeType', ['test', 'test2']) | ||
.addMembership('degreeName', ['Bachelor of Science and Arts', 'Bachelor of Finance']) | ||
.addRange( | ||
'graduationDate', | ||
new Date('1900-08-28T00:00:00.000Z'), | ||
new Date('2030-08-28T00:00:00.000Z') | ||
) | ||
) | ||
|
||
.getStatements(); | ||
sendStatement(statement); | ||
}); | ||
document.getElementById('web3ProofIdOnly').addEventListener('click', () => { | ||
const statement = new concordiumSDK.Web3StatementBuilder() | ||
.addForIdentityCredentials([0, 1, 2], (b) => | ||
b | ||
.revealAttribute('idDocType') | ||
.revealAttribute('firstName') | ||
.revealAttribute('lastName') | ||
.revealAttribute('countryOfResidence') | ||
.addRange('dob', '19410101', '20050202') | ||
.addMembership('nationality', ['FR', 'ES', 'DK']) | ||
) | ||
.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']) | ||
) | ||
.addForVerifiableCredentials([{ index: 6105n, subindex: 0n }], (b) => | ||
b.revealAttribute('graduationDate') | ||
) | ||
|
||
.getStatements(); | ||
sendStatement(statement); | ||
}); | ||
// Add credential | ||
document.getElementById('addWeb3Id').addEventListener('click', () => { | ||
const values = { | ||
degreeType: degreeType.value, | ||
degreeName: degreeName.value, | ||
graduationDate: { type: 'date-time', timestamp: graduationDate.valueAsDate.toISOString() }, | ||
}; | ||
const metadataUrl = { | ||
url: web3metadataUrl.value, | ||
}; | ||
provider.addWeb3IdCredential( | ||
{ | ||
$schema: './JsonSchema2023-education-certificate.json', | ||
type: [ | ||
'VerifiableCredential', | ||
'ConcordiumVerifiableCredential', | ||
'UniversityDegreeCredential', | ||
], | ||
issuer: 'did:ccd:testnet:sci:' + issuerIndex.value + ':0/issuer', | ||
credentialSubject: { | ||
attributes: values, | ||
}, | ||
credentialSchema: { | ||
id: web3Schema.value, | ||
type: 'JsonSchema2023', | ||
}, | ||
}, | ||
metadataUrl, | ||
async (id) => { | ||
const body = { | ||
credentialSubject: { | ||
attributes: { | ||
degreeType: degreeType.value, | ||
degreeName: degreeName.value, | ||
graduationDate: { | ||
timestamp: graduationDate.valueAsDate.toISOString(), | ||
type: 'date-time', | ||
}, | ||
}, | ||
id, | ||
}, | ||
validFrom: new Date().toISOString(), | ||
holderRevocable: true, | ||
metadataUrl, | ||
}; | ||
const response = await fetch(web3IssuerUrl.value, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(body), | ||
}); | ||
const { credential } = await response.json(); | ||
const { proof, randomness } = credential; | ||
return { proof, randomness }; | ||
} | ||
); | ||
}); | ||
document.getElementById('graduationDate').valueAsDate = new Date(); | ||
} | ||
setupPage(); | ||
</script> | ||
</head> | ||
<style> | ||
input { | ||
width: 80%; | ||
} | ||
</style> | ||
<body> | ||
<div> | ||
<button id="requestAccounts">Request accounts</button> | ||
<h3 id="accountAddress">Account address:</h3> | ||
</div> | ||
<br /> | ||
<a href="https://github.com/Concordium/concordium-web3id/tree/web3id-revision/services/web3id-issuer" | ||
>Web3IdIssuer Endpoint:</a | ||
><input type="text" id="web3IssuerUrl" value="http://localhost:8082/v0/issue" /> | ||
<br /> | ||
Web3Id MetadataUrl: | ||
<input | ||
type="text" | ||
id="web3metadataUrl" | ||
value="https://raw.githubusercontent.com/Concordium/concordium-web3id/credential-metadata-example/examples/json-schemas/metadata/credential-metadata.json" | ||
/> | ||
<br /> | ||
Web3Id Schema: | ||
<input | ||
type="text" | ||
id="web3Schema" | ||
value="https://gist.githubusercontent.com/shjortConcordium/a2dc69761d2007c308f6511abaa3eb70/raw/11ad6745dcfa57e7049b08be146858a928a7aa82/gistfile1.txt" | ||
/> | ||
<br /> | ||
issuer Index: <input type="number" id="issuerIndex" value="6105" /> | ||
<br /> | ||
<h3>Attribute values:</h3> | ||
degreeType: <input type="text" id="degreeType" value="BachelorDegree" /> | ||
<br /> | ||
degreeName: <input type="text" id="degreeName" value="Bachelor of Science and Arts" /> | ||
<br /> | ||
graduationDate: <input type="date" id="graduationDate" value="" /> | ||
<br /> | ||
<br /> | ||
<button id="addWeb3Id">Add web3IdCredential Example to wallet</button> | ||
<br /> | ||
<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> | ||
</body> | ||
</html> |
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,13 @@ | ||
{ | ||
"name": "add-example-web3-id", | ||
"packageManager": "[email protected]", | ||
"devDependencies": { | ||
"live-server": "^1.2.2" | ||
}, | ||
"scripts": { | ||
"start": "live-server ./index.html --mount=/sdk.js:../../node_modules/@concordium/web-sdk/lib/concordium.min.js --mount=/helpers.js:../../packages/browser-wallet-api-helpers/lib/concordiumHelpers.min.js" | ||
}, | ||
"dependencies": { | ||
"@concordium/web-sdk": "^6.3.0" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@concordium/browser-wallet-api-helpers": "workspace:^", | ||
"@concordium/web-sdk": "^3.3.1", | ||
"@concordium/web-sdk": "^6.3.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.18.1", | ||
"express-fileupload": "^1.4.0", | ||
|
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@concordium/browser-wallet-api-helpers": "workspace:^", | ||
"@concordium/web-sdk": "^3.3.1", | ||
"@concordium/web-sdk": "^6.3.0", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0" | ||
}, | ||
|
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@concordium/browser-wallet-api-helpers": "^2.0.0", | ||
"@concordium/web-sdk": "^6.0.0", | ||
"@concordium/web-sdk": "^6.3.0", | ||
"bootstrap": "^5.2.1", | ||
"cross-env": "^7.0.3", | ||
"moment": "^2.29.4", | ||
|
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 |
---|---|---|
|
@@ -9,4 +9,3 @@ | |
### Fixed | ||
|
||
- CCDScan URL to work for mainnet and testnet | ||
|
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
Oops, something went wrong.