Skip to content

Commit

Permalink
Merge pull request #388 from Concordium/feature/web3-id
Browse files Browse the repository at this point in the history
Feature/web3
  • Loading branch information
shjortConcordium authored Sep 7, 2023
2 parents 0841689 + e6fd0a8 commit 9df8c23
Show file tree
Hide file tree
Showing 178 changed files with 8,268 additions and 491 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Build, lint and test
on:
# Triggers the workflow on push or pull request events but only for the main branch and release branches
push:
branches: [main, release**]
branches: [main, release**, feature/**]
pull_request:
branches: [main, release**]
branches: [main, release**, feature/**]

# Allows us to run the workflow manually from the Actions tab
workflow_dispatch:
Expand Down
18 changes: 18 additions & 0 deletions examples/add-example-Web3Id/README.md
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)
205 changes: 205 additions & 0 deletions examples/add-example-Web3Id/index.html
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>
13 changes: 13 additions & 0 deletions examples/add-example-Web3Id/package.json
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"
}
}
1 change: 1 addition & 0 deletions examples/eSealing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.3.0",
"@concordium/web-sdk": "^6.3.0",
"@thi.ng/leb128": "^2.1.18",
"@types/sha256": "^0.2.0",
"@walletconnect/types": "^2.1.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-minting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/piggybank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
31 changes: 30 additions & 1 deletion examples/two-step-transfer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
document.getElementById('accountAddress').innerHTML = accountAddress;
});
});

document.getElementById('requestAccounts').addEventListener('click', () => {
provider.requestAccounts().then((accountAddresses) => {
currentAccountAddress = accountAddresses[0];
document.getElementById('accountAddress').innerHTML = accountAddress;
});
});
document.getElementById('sendTransfer').addEventListener('click', () =>
provider
.sendTransaction(currentAccountAddress, concordiumSDK.AccountTransactionType.Transfer, {
Expand Down Expand Up @@ -207,14 +214,34 @@
})
.catch(alert);
});
document.getElementById('web3Proof').addEventListener('click', () => {
const statement = new concordiumSDK.Web3StatementBuilder()
.addForIdentityCredentials([0, 1, 2], (b) =>
b.revealAttribute('firstName').addRange('dob', '08000101', '20000101')
)
.addForVerifiableCredentials([{ index: 5463, subindex: 0 }], (b) =>
b.revealAttribute('degreeName').addMembership('graduationDate', ['2010-06-01T00:00:00Z'])
)
.getStatements();
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);
});
});
document.getElementById('addWCCD').addEventListener('click', () => {
provider
.addCIS2Tokens(currentAccountAddress, [''], 2059n, 0n)
.then((added) => alert('Added tokens: ' + added.map((id) => '"' + id + '"')))
.catch(alert);
});
}

setupPage();
</script>
</head>
Expand All @@ -224,6 +251,7 @@
<h3 id="accountAddress">Account address:</h3>
</div>
<button id="connect">Connect</button>
<button id="requestAccounts">Request accounts</button>
<button id="deployModule">Deploy module</button>
ModuleSource (base64): <input type="text" id="moduleSource" value="" />
<button id="sendInit">Initiate two step transfer contract</button>
Expand All @@ -236,6 +264,7 @@ <h3 id="accountAddress">Account address:</h3>
<option value="parameter">Parameter</option>
</select>
<button id="idProof">Request an ID Proof</button>
<button id="web3Proof">Request an ID 3 Proof</button>
<br />
Message: <input type="text" id="message" value="I believe in miracles" />
<button id="signMessage">SignMessage</button>
Expand Down
2 changes: 1 addition & 1 deletion examples/two-step-transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "live-server ../two-step-transfer/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": "^3.3.1"
"@concordium/web-sdk": "^6.3.0"
}
}
2 changes: 1 addition & 1 deletion examples/voting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion examples/wCCD/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
### Fixed

- CCDScan URL to work for mainnet and testnet

2 changes: 1 addition & 1 deletion examples/wCCD/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.2.0",
"@concordium/web-sdk": "^3.3.1",
"@concordium/web-sdk": "^6.3.0",
"@thi.ng/leb128": "^2.1.18",
"@walletconnect/types": "^2.1.4",
"mathjs": "^11.4.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/browser-wallet-api-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.6.0

### Added

- `requestAccounts` entrypoint to connect to a list of accounts.
- `addWeb3IdCredential` entrypoint to add verifiable credentials.
- `requestVerifiablePresentation`entrypoint to prove statements about identities and verifiable credentials.

## 2.5.1

### Changed
Expand Down
Loading

0 comments on commit 9df8c23

Please sign in to comment.