How it works using OpenID Credential Provisioning

Create a wallet

Create a new wallet

typescript
Copy to clipboard.
1import { create } from "@mattrglobal/wallet-sdk-react-native";
2
3const createWalletResult = await create();
4
5if (createWalletResult.isErr()) {
6    // Handle error from createWalletResult.error 
7    return;
8

Start an OpenID Credential Provisioning flow 

Discover OIDC credential offer 

typescript
Copy to clipboard.
1const uri =
2  "openid-credential-offer://?credential_offer=%7B%22credential_issuer%22
3  %3A%22https%3A%2F%2Fmyissuer.example.com%22%2C%22credentials%22%3A%5B%
4  22707e920a-f342-443b-ae24-6946b7b5033e%22%5D%2C%22request_parameters%22
5  %3A%7B%22login_hint%22%3A%22test.user%40example.com%22%2C%22prompt%22%
6  3A%22login%22%7D%7D";
7
8const offer = unwrap(await wallet.openid.issuance.discover(uri));

or Construct the offer manually

typescript
Copy to clipboard.
1const offer: OpenidIssuanceCredentialOffer = {
2    issuer: "https://example.com/",
3    authorizeEndpoint: "https://example.com/oauth/authorize",
4    tokenEndpoint: "https://example.com/oauth/token",
5    credentialEndpoint: "https://example.com/oauth/credential",
6    credentials: [
7        {
8            profile: "web-semantic",
9            scope: "ldp_vc:UniversityDegreeCredential",
10            credentialDefinition: {
11                "@context": ["https://www.w3.org/2018/credentials/v1"],
12                type: ["VerifiableCredential", "UniversityDegreeCredential"],
13            }
14        },
15        {
16            profile: "compact",
17            scope: "cwt:UniversityDegreeCredential",
18            type: "UniversityDegreeCredential",
19        },
20        {
21            profile: "compact-semantic",
22            scope: "cwt_vc:UniversityDegreeCredential",
23            types: ["UniversityDegreeCredential", "VerifiableCredential"]
24        },
25    ],
26}

Generate an OAuth authorization url to request access token to retrieve the credentials

typescript
Copy to clipboard.
1import { Linking } from "react-native";
2
3const generateAuthorizeUrlResult = await wallet.openid.issuance.generateAuthorizeUrl({ offer, clientId, redirectUri });
4
5if (generateAuthorizeUrlResult.isErr()) {
6    // Handle error from generateAuthorizeUrlResult.error
7    return;
8}
9
10const { url, codeVerifier } = generateAuthorizeUrlResult.value;
11await Linking.openURL(url);

Retrieve the credential on authorization success callback 

typescript
Copy to clipboard.
1const retrieveResult = (retrieveCredential = await wallet.oidc.retrieveCredential({
2    offer,
3    codeVerifier,
4    nonce,
5    code: route.params.code, // code comes from part of the callback url 
6}));
7
8if (retrieveResult.isErr()) {
9    // Handle error from retrieveResult.error 
10    return;
11}
12
13const { credential } = retrieveResult.value; 

Retrieve the token

typescript
Copy to clipboard.
1const retrieveTokenResult = await wallet.openid.issuance.retrieveToken({
2    offer,
3    clientId,
4    redirectUri,
5    codeVerifier,
6    code: route.params.code, // code comes authorization success callback above
7});
8
9if (retrieveTokenResult.isErr()) {
10    // Handle error from retrieveTokenResult.error
11    return;
12}
13
14const { accessToken } = retrieveTokenResult.value;

Retrieve credentials

typescript
Copy to clipboard.
1const retrieveCredentialsResult = await wallet.openid.issuance.retrieveCredentials({
2    offer,
3    accessToken,
4    clientId,
5});
6
7if (retrieveCredentialsResult.isErr()) {
8    // Handle error from retrieveCredentialsResult.error
9    return;
10}
11
12retrieveCredentialsResult.value.credentials.forEach(({ credential, profile, did }) => {
13    // present to user and/or store
14});

Verify a Web credential 

typescript
Copy to clipboard.
1const verifyResult = await wallet.credential.webSemantic.verifyCredential({ credential });
2
3if (verifyResult.isErr()) {
4    // Handle error from verifyResult.error 
5    return;
6}
7
8const { credentialVerified, status } = verifyResult.value; 

Verify a Compact credential 

typescript
Copy to clipboard.
1const verifyResult = await wallet.credential.compact.verifyCredential({ credential });
2
3if (verifyResult.isErr()) {
4    // Handle error from verifyResult.error 
5    return;
6}
7
8const { credentialVerified, status } = verifyResult.value; 

Verify a Compact Semantic credential 

typescript
Copy to clipboard.
1const verifyResult = await wallet.credential.compactSemantic.verifyCredential({ credential });
2
3if (verifyResult.isErr()) {
4    // Handle error from verifyResult.error 
5    return;
6}
7
8const { credentialVerified, status } = verifyResult.value; 

Find the comprehensive SDK interfaces for these examples and others in the documentation https://github.com/mattrglobal/docs-wallet-sdk.

Get in touch if you wish to find out more about using the Wallet SDK in production.