Skip to content

Commit

Permalink
Add did:ethr resolver demo
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas committed Nov 21, 2023
1 parent 9cb6b83 commit a027c3d
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.DS_Store
.idea
**/.idea
**/node_modules
.env
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,23 @@ The demo within the Rust crate walks thru the following:

## Run

To setup and run the demo:
1. create your `.env` file in the root of this project. Using `.env.example` as an example.
2. within `anoncreds-smart-contracts-js`: `npm install`
3. within `anoncreds-smart-contracts-js`: use hardhat to run a local ledger in a seperate terminal: `npx hardhat node`
4. within `anoncreds-smart-contracts-js`: use hardhat to deploy the `AnoncredsRegistry` & `EthereumDIDRegistry` contract to the local ledger: `npx hardhat run --network localhost scripts/deploy.ts`
- Lookup value `Contract address` in the output. You need to provide in the next step as env variable.
5. within `eth-anoncreds-rust-demo`: run the demo!: `ANONCRED_REGISTRY_ADDRESS=<the_value_from_previous_step> cargo run`
#### Stage 1 - start local ethereum network
1. Create your `.env` file in the root of this project. Using `.env.example` as an example.
2. In directory `anoncreds-smart-contracts-js` run `npm install`.
3. In directory `anoncreds-smart-contracts-js` run `npx hardhat node` to spin up local ethereum network. You have to keep this console window running.

#### Stage 2 - deploy contracts
1. In directory `anoncreds-smart-contracts-js`: run `npx hardhat run --network localhost scripts/deploy.ts`
- This will deploy the `AnoncredsRegistry` & `EthereumDIDRegistry` contracts to your local network.
- In the output, lookout for the `Contract Address` values for both of these contracts. We are going to need these soon.

#### Stage 3 - run anoncreds demo
1. In directory `eth-anoncreds-rust-demo` run the anoncreds issuance demo `ANONCRED_REGISTRY_ADDRESS=<Your_AnoncredsRegistry> cargo run`
- This will run demo which will register a `did:ethr` DID
- Under that DID, it will create a schema, credential definition and revocation registry definition
- The demo then proceed with issuance of credential and proof presentation

#### Stage 4 - resolve DID Document for your DID
1. In directory `didethr-resolver-js` run `npm install`
2. In directory `didethr-resolver-js` run `DID_REGISTRY_ADDRESS=<Your_Anoncreds_Registry> DID=<Your_DID> npm run demo`
- Make sure to provide correct env variables. You can find your DID in the output of the anoncreds demo from the previous stage.
60 changes: 60 additions & 0 deletions didethr-resolver-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# did:ethr resolver demo

This demo assumes you have already executed `eth-anoncreds-rust-demo` which
creates registers `did:ethr` in DID registry.

This demo resolves the created Did Document for the registered DID using JS `did:ethr`
resolver implementation based on:
- [`did-resolver`](https://github.com/decentralized-identity/did-resolver)
- [`ethr-did-resolver`](https://github.com/decentralized-identity/ethr-did-resolver)

# Instructions
1. Install dependencies
```sh
npm install
```

2. Run demo
```
DID_REGISTRY_ADDRESS=<your_registry_address> DID=<your_did> npm run demo
```

If no env variables are provided, following defaults are used:
- DID_REGISTRY_ADDRESS: `0x5fbdb2315678afecb367f032d93f642f64180aa3`
- DID: `did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266`

The demo should output resolved DID Document, such as:
```json

{
"didDocumentMetadata": {
"versionId": "2",
"updated": "2023-11-21T21:01:40Z"
},
"didResolutionMetadata": {
"contentType": "application/did+ld+json"
},
"didDocument": {
"id": "did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"verificationMethod": [
{
"id": "did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266#controller",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"blockchainAccountId": "eip155:31337:0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
}
],
"authentication": [
"did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266#controller"
],
"assertionMethod": [
"did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266#controller"
],
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/secp256k1recovery-2020/v2",
"https://w3id.org/security/v3-unstable"
]
}
}
```
29 changes: 29 additions & 0 deletions didethr-resolver-js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// import {Resolver} from 'did-resolver'
// import {getResolver} from 'ethr-did-resolver'
const { Resolver } = require('did-resolver');
const { getResolver } = require('ethr-did-resolver');

const did_registry_address = process.env.DID_REGISTRY_ADDRESS | "0x5fbdb2315678afecb367f032d93f642f64180aa3"
const did_url = process.env.DID | "did:ethr:gmtest:0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"

async function run() {
const providerConfig = {
networks: [
{ name: "gmtest", rpcUrl: "http://localhost:8545", registry: did_registry_address },
]
}

const ethrDidResolver = getResolver(providerConfig)
const didResolver = new Resolver(ethrDidResolver)

const doc = await didResolver.resolve(did_url)
console.log(JSON.stringify(doc, null, 2))
}

run()
.catch(err => {
console.error((err))
})
.then(() => {
return 0
})
120 changes: 120 additions & 0 deletions didethr-resolver-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions didethr-resolver-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "didethr-resolver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"demo": "node index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"did-resolver": "^4.1.0",
"ethr-did-resolver": "^10.0.0"
}
}

0 comments on commit a027c3d

Please sign in to comment.