Skip to content

Commit

Permalink
feat: openid4vc guides (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoGlastra committed Jun 6, 2024
1 parent 8467ebf commit 71899a3
Show file tree
Hide file tree
Showing 27 changed files with 742 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/documentation-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ body:
description: You may select more than one.
options:
- label: React Native
- label: Node.JS
- label: Node.js
- type: checkboxes
id: contribute
attributes:
Expand Down
2 changes: 1 addition & 1 deletion guides/concepts/platform-and-environment.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Platform and Environment

[Credo](https://github.com/openwallet-foundation/credo-ts) is developed to support a [Node.JS](https://nodejs.org) and [React Native](https://reactnative.dev) environment. With this it is entirely possible to build an entire SSI ecosystem with Credo. This would use Node.JS as an issuer as a verifier, and uses React Native as a holder.
[Credo](https://github.com/openwallet-foundation/credo-ts) is developed to support a [Node.js](https://nodejs.org) and [React Native](https://reactnative.dev) environment. With this it is entirely possible to build an entire SSI ecosystem with Credo. This would use Node.js as an issuer as a verifier, and uses React Native as a holder.
2 changes: 1 addition & 1 deletion guides/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import DocCardList from '@theme/DocCardList';

# Getting started

In this section we will go over everything you need to get started on a technical level. First there are some general prerequisites for Node.JS and React Native. Credo works for creating both server-side applications (commonly but not always for creating issuer and verifier agents) and mobile applications (commonly holder agents).
In this section we will go over everything you need to get started on a technical level. First there are some general prerequisites for Node.js and React Native. Credo works for creating both server-side applications (commonly but not always for creating issuer and verifier agents) and mobile applications (commonly holder agents).

Based on the platform you want to work on, the installation guides you should follow are the same, but some steps may differ.

Expand Down
18 changes: 9 additions & 9 deletions guides/getting-started/prerequisites.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Prerequisites

To work with [Credo](https://github.com/openwallet-foundation/credo-ts) we need to install some dependencies and set-up our Node.JS environment. Even when creating a mobile app in React Native, we need Node.JS installed. We will go over the specific installation process for each platform. Go ahead and pick your system of choice to get started!
To work with [Credo](https://github.com/openwallet-foundation/credo-ts) we need to install some dependencies and set-up our Node.js environment. Even when creating a mobile app in React Native, we need Node.js installed. We will go over the specific installation process for each platform. Go ahead and pick your system of choice to get started!

The specific items that we set-up:

- [Node.JS](https://nodejs.org) - v16 or v18
- [Node.js](https://nodejs.org) - v16 or v18
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install) or [npm](https://www.npmjs.com/)
- Node.JS or React Native project.
- Node.js or React Native project.

### Node.JS
### Node.js

NodeJS is the most popular JavaScript runtime environment excluding browsers. It can run on your desktop or even a server.

<!--tabs-->

#### Windows

You can download it from the [Node.JS Website](https://nodejs.org/en/download/)
You can download it from the [Node.js Website](https://nodejs.org/en/download/)

#### macOS

Expand All @@ -26,17 +26,17 @@ Make sure you have [Homebrew](https://brew.sh/) installed. If not you can instal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

Then install Node.JS with the following command:
Then install Node.js with the following command:

```console
brew install nodejs
```

Alternatively, you can download it from the [Node.JS Website](https://nodejs.org/en/download/)
Alternatively, you can download it from the [Node.js Website](https://nodejs.org/en/download/)

#### Linux

Either follow one of the specific steps for installing Node.JS on linux below, or you can download it directly from the [Node.JS Website](https://nodejs.org/en/download/)
Either follow one of the specific steps for installing Node.js on linux below, or you can download it directly from the [Node.js Website](https://nodejs.org/en/download/)

##### Arch Linux

Expand Down Expand Up @@ -76,4 +76,4 @@ npm install --global yarn

### Project Setup

Finally, you need to make sure you have a project set-up using Node.JS or React Native. If you're not familiar with setting up a project, we suggest following the [Introduction to Node.JS](https://nodejs.dev/en/learn/) or [React Native Quickstart](https://reactnative.dev/docs/environment-setup) guides.
Finally, you need to make sure you have a project set-up using Node.js or React Native. If you're not familiar with setting up a project, we suggest following the [Introduction to Node.js](https://nodejs.dev/en/learn/) or [React Native Quickstart](https://reactnative.dev/docs/environment-setup) guides.
6 changes: 3 additions & 3 deletions guides/getting-started/set-up/anoncreds.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ The AnonCreds module provides functionality for issuing and verifying [AnonCreds

### Installing

When using Credo with AnonCreds, there are a few extra dependencies that need to be installed. We need to install `@credo-ts/anoncreds` package, which contains the interfaces, and `@hyperledger/anoncreds-<platform>` package which is an implementation which depends on a wrapper of anoncreds-rs. Currently there are bindings for Node.JS, as `@hyperledger/anoncreds-nodejs`, and React Native as `@hyperlegder/anoncreds-react-native`.
When using Credo with AnonCreds, there are a few extra dependencies that need to be installed. We need to install `@credo-ts/anoncreds` package, which contains the interfaces, and `@hyperledger/anoncreds-<platform>` package which is an implementation which depends on a wrapper of anoncreds-rs. Currently there are bindings for Node.js, as `@hyperledger/anoncreds-nodejs`, and React Native as `@hyperlegder/anoncreds-react-native`.

<!--tabs-->

# Node.JS
# Node.js

```console
yarn add @credo-ts/anoncreds@^0.5.3 @hyperledger/anoncreds-nodejs@^0.2.2
Expand All @@ -28,7 +28,7 @@ After installing the dependencies, we should register the `AnonCredsModule` on t

<!--tabs-->

# Node.JS
# Node.js

```typescript showLineNumbers set-up-anoncreds.ts section-1

Expand Down
6 changes: 3 additions & 3 deletions guides/getting-started/set-up/aries-askar.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ If you're upgrading from the Indy SDK to Aries Askar, see [Migrating from an Ind

### Installing Aries Askar

When using Credo with Aries Askar, there are a few extra dependencies that need to be installed. We need to install the `@credo-ts/askar` package, which implements the needed interfaces for the agent. Secondly, we need to add native bindings for the specific platform `@hyperledger/aries-askar-<platform>`. Currently there are bindings for Node.JS, as `@hyperledger/aries-askar-nodejs`, and React Native as `@hyperlegder/aries-askar-react-native`.
When using Credo with Aries Askar, there are a few extra dependencies that need to be installed. We need to install the `@credo-ts/askar` package, which implements the needed interfaces for the agent. Secondly, we need to add native bindings for the specific platform `@hyperledger/aries-askar-<platform>`. Currently there are bindings for Node.js, as `@hyperledger/aries-askar-nodejs`, and React Native as `@hyperlegder/aries-askar-react-native`.

<!--tabs-->

# Node.JS
# Node.js

```console
yarn add @credo-ts/askar@^0.5.3 @hyperledger/aries-askar-nodejs@^0.2.1
Expand All @@ -34,7 +34,7 @@ After installing the dependencies, we can register the Askar Module on the agent

<!--tabs-->

# Node.JS
# Node.js

```typescript showLineNumbers set-up-askar.ts section-1

Expand Down
2 changes: 1 addition & 1 deletion guides/getting-started/set-up/cheqd/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ The cosmosPayerSeed can be a 32-bit seed value or a mnemonic, which can be manag

- [Cheqd DID Module](../../../tutorials/cheqd/index.md)
- [Register Schema and Credential Definition](../../../tutorials/registering-schema-and-credential-definition.md)
- [Issue a Credential](../../../tutorials/issue-a-credential.md)
- [Issue an AnonCreds Credential over DIDComm](../../../tutorials/issue-an-anoncreds-credential-over-didcomm.md)
8 changes: 4 additions & 4 deletions guides/getting-started/set-up/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DocCardList from '@theme/DocCardList';
:::info

This guide assumes you have followed the [Prerequisites](./prerequisites), and you have a valid
[Node.JS](https://nodejs.org) or [React Native](https://reactnative.dev) project setup.
[Node.js](https://nodejs.org) or [React Native](https://reactnative.dev) project setup.

:::

Expand All @@ -31,7 +31,7 @@ First we have to install the minimal amount of dependencies that are required fo

<!--tabs-->

# Node.JS
# Node.js

```console
yarn add @credo-ts/core@^0.5.3 @credo-ts/node@^0.5.3
Expand All @@ -51,7 +51,7 @@ yarn add @credo-ts/core@^0.5.3 @credo-ts/react-native@^0.5.3 react-native-fs rea

# Node.js

No additional setup is required for Node.JS
No additional setup is required for Node.js

# React Native

Expand Down Expand Up @@ -113,7 +113,7 @@ enough for your specific use cases. Please refer to the

<!--tabs-->

# Node.JS
# Node.js

```typescript showLineNumbers set-up.ts section-1

Expand Down
6 changes: 3 additions & 3 deletions guides/getting-started/set-up/indy-vdr.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

### Installing Indy VDR

When using Credo with Indy VDR, there are a few extra dependencies that need to be installed. We need to install the `@hyperledger/indy-vdr`, which contains all the functionality to register objects on an Hyperledger Indy VDR. Secondly, we need to add native bindings for the specific platform `@hyperledger/indy-vdr-<platform>`. Currently there are bindings for Node.JS, as `@hyperledger/indy-vdr-nodejs`, and React Native as `@hyperlegder/indy-vdr-react-native`.
When using Credo with Indy VDR, there are a few extra dependencies that need to be installed. We need to install the `@hyperledger/indy-vdr`, which contains all the functionality to register objects on an Hyperledger Indy VDR. Secondly, we need to add native bindings for the specific platform `@hyperledger/indy-vdr-<platform>`. Currently there are bindings for Node.js, as `@hyperledger/indy-vdr-nodejs`, and React Native as `@hyperlegder/indy-vdr-react-native`.

<!--tabs-->

# Node.JS
# Node.js

```console
yarn add @credo-ts/indy-vdr@^0.5.3 @hyperledger/indy-vdr-nodejs@^0.2.2
Expand All @@ -28,7 +28,7 @@ After installing the dependencies, we can register the Indy VDR module on the ag

<!--tabs-->

# Node.JS
# Node.js

```typescript showLineNumbers set-up-indy-vdr.ts section-1

Expand Down
37 changes: 37 additions & 0 deletions guides/getting-started/set-up/openid4vc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# OpenID for Verifiable Credentials

The OpenID4VC module provides support for the [OpenID for Verifiable Credentials group of protocols](https://openid.net/sg/openid4vc/) defined under the OpenID Foundation. Currently this includes the [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html), [Self-Issued OpenID Provider v2](https://openid.net/specs/openid-connect-self-issued-v2-1_0.html), and [OpenID for Verifiable Presentations](https://openid.net/specs/openid-4-verifiable-presentations-1_0.html).

For the current supported versions for any of the OpenID4VC protocols, please refer to the [OpenID4VC Feature](../../features/openid4vc.md) page.

The OpenID4VC Module in Credo currently exposes three modules, one for each role in the triangle trust: `OpenId4VcIssuerModule`, `OpenId4VcHolderModule`, and `OpenId4VcVerifierModule`. The issuer and verifier modules are expected to run in a cloud environment, as they require several endpoints to be exposed to the public internet. The holder module can run in a cloud environment or on a mobile device.

### Installing OpenID4VC Module

When using Credo with OpenID4VC you need to install the `@credo-ts/openid4vc` module:

```console
yarn add @credo-ts/openid4vc@0.5.3
```

### Adding OpenID4VC Modules to the Agent

After installing the dependencies, we can register the the different modules on the agent.

#### Issuer and Verifier

If you want to issue or verify credentials using OpenID for Verifiable Credentials, you can add the `OpenId4VcIssuerModule` and the `OpenId4VcVerifierModule`. These modules can only run on the server, in Node.js and don't work in a React Native environment. These modules can be added separately, it's not required to use both modules. The set up for the issuer and verifier module can be combined with the set up for the holder module below to support issuance, holding, and verification OpenID4VC flows within the same agent.

In the example we haven't implemented the `credentialRequestToCredentialMapper` method for the issuer module yet, this is covered in the [OpenID4VC Guides](/guides/tutorials/openid4vc).

```typescript showLineNumbers set-up-openid4vc-issuer-verifier.ts section-1

```

### Holder

If you want to receive and present credentials using OpenID for Verifiable Credentials, you can add the `OpenId4VcHolderModule`. This module can run in both Node.js and React Native.

```typescript showLineNumbers set-up-openid4vc-holder.ts section-1

```
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Issue a credential
# Issue an AnonCreds credential over DIDComm

In this tutorial we will issue a credential from the _Issuer_ to a _Holder_. We will start with setting up both their agents with the minimal configuration required to follow this tutorial. It is assumed that there is a connection between the _Issuer_ and the _Holder_ and the _Issuer_ also has a registered schema and credential definition. After initializing the _Issuer_ will send a credential to the _holder_, and will then accept this credential and automatically store it in their wallet.
In this tutorial we will issue an AnonCreds credential from the _Issuer_ to a _Holder_ over DIDComm. We will start with setting up both their agents with the minimal configuration required to follow this tutorial. It is assumed that there is a connection between the _Issuer_ and the _Holder_ and the _Issuer_ also has a registered schema and credential definition. After initializing the _Issuer_ will send a credential to the _holder_, and will then accept this credential and automatically store it in their wallet.

_Using [AnonCreds](https://anoncreds-wg.github.io/anoncreds-spec/) and the [Issue Credential V2 Protocol](https://github.com/hyperledger/aries-rfcs/blob/main/features/0453-issue-credential-v2/README.md) or the [Issue Credential V1 Protocol](https://github.com/hyperledger/aries-rfcs/blob/main/features/0036-issue-credential/README.md)._

:::info

This section assumes that

1. You have [set-up your develoment environment](../getting-started).
1. You have [set-up your development environment](../getting-started).
1. You have basic knowledge of the required fields in the [Agent Config](./agent-config)
1. You have completed the [Create a Connection tutorial](./create-a-connection)
1. You have a registered schema and credential definition. This can be done by following the [Registering on a AnonCreds Registry](./registering-schema-and-credential-definition)
Expand Down Expand Up @@ -53,7 +53,7 @@ ngrok http <PORT>

:::issuer

```typescript showLineNumbers issue-a-credential.ts section-1
```typescript showLineNumbers issue-anoncreds-credential-didcomm.ts section-1

```

Expand All @@ -70,7 +70,7 @@ For the _Holder_ we need to setup a basic agent with a wallet, mediator, outboun
:::holder

```typescript showLineNumbers issue-a-credential.ts section-2
```typescript showLineNumbers issue-anoncreds-credential-didcomm.ts section-2

```

Expand All @@ -82,7 +82,7 @@ When we want to accept a credential, we have to listen to incoming credentials a

:::holder

```typescript showLineNumbers issue-a-credential.ts section-3
```typescript showLineNumbers issue-anoncreds-credential-didcomm.ts section-3

```

Expand All @@ -100,7 +100,7 @@ Now that everything is setup on both sides, the _Issuer_ can now offer a credent

:::issuer

```typescript showLineNumbers issue-a-credential.ts section-4
```typescript showLineNumbers issue-anoncreds-credential-didcomm.ts section-4

```

Expand All @@ -110,7 +110,7 @@ Now that everything is setup on both sides, the _Issuer_ can now offer a credent

:::issuer

```typescript showLineNumbers issue-a-credential.ts section-5
```typescript showLineNumbers issue-anoncreds-credential-didcomm.ts section-5

```

Expand Down
7 changes: 7 additions & 0 deletions guides/tutorials/openid4vc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DocCardList from '@theme/DocCardList';

# OpenID for Verifiable Credentials Tutorials

This section covers all tutorials related to the OpenID for Verifiable Credentials module in Credo. Before you start, make sure you have configured the required OpenID4VC modules on your agent according to the [OpenID4VC Setup Guide](/guides/getting-started/set-up/openid4vc.md)

<DocCardList />
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Issuing Credentials using the OpenID4VC Issuer Module

This tutorial will guide you through the process of issuing credentials using the OpenID4VC Issuer Module. Before starting this tutorial, make sure you have completed the [OpenID4VC Issuer Module Setup](/guides/getting-started/set-up/openid4vc.md).

This guides only covers the issuance of credentials using the OpenID4VC Issuer Module. Follow the [Receiving and Proving Credentials using the OpenID4VC Holder Module](/guides/tutorials/openid4vc/receiving-and-proving-credentials-using-openid4vc-holder-module.md) guide to learn how to receive and prove credentials using the OpenID4VC Holder Module.

## Creating the issuer

Once you have set-up your agent (under `issuer` variable), we first need to configure your issuer and the credentials you want to issue.

```typescript showLineNumbers sd-jwt-vc-openid4vc.ts section-2

```

If you want to update the display metadata or the credentials supported by the issuer, you can use the `issuer.modules.openId4VcIssuer.updateIssuer` method.

## Creating a credential offer

Once you have configured the issuer, you can create a credential offer. The credential offer method will generate a credential offer URI that you can share with a holder.

```typescript showLineNumbers sd-jwt-vc-openid4vc.ts section-3

```

We have also added an event listener that listens for state changed events, this allows us to know when the issuance session is done.

## Implementing the credential mapper

The OpenID4VC Issuer Module setup didn't cover the implementation of the `credentialRequestToCredentialMapper` yet. When you create a credential offer with the OpenID4VC Issuer Module in Credo, you don't have to provide the credential data directly.

Instead, you provide a `credentialRequestToCredentialMapper` function in the agent configuration, that will be called when the holder requests the credential.

This allows you to dynamically generate the credential data based on the holder's request, and means you also don't have to store any credential data in the agent.

Below is an example `credentialRequestToCredentialMapper` function that generates a credential based on the holder's request. Make sure to register this function in the agent configuration `modules.openId4VcIssuer.endpoints.credential.credentialsRequestToCredentialMapper`.

```typescript showLineNumbers sd-jwt-vc-openid4vc.ts section-4

```
Loading

0 comments on commit 71899a3

Please sign in to comment.