We get the following error:
We have build a test component to add a web3 id credential and our contract has a schema embedded. We are stuck, we can’t find any documentation.
import {
AttributeType,
ConcordiumGRPCClient,
ConcordiumGRPCWebClient,
CredentialWithMetadata,
Network,
createWeb3CommitmentInput,
createWeb3IdDID,
verifyCredentialMetadata,
} from "@concordium/web-sdk";
import {
CredentialProof,
detectConcordiumProvider,
} from "@concordium/browser-wallet-api-helpers";
import React, { useState } from "react";
import Heading from "@/components/BestBank/Heading";
interface IssuerResponse {
txHash: string;
credential: {
proof: CredentialProof;
randomness: Record<string, string>;
};
}
interface CredentialInfo {
holderId: string;
holderRevocable: boolean;
validFrom: string;
metadataUrl: { url: string };
}
interface IssueRequest {
credential: CredentialInfo;
}
const index = () => {
const network = "Testnet";
const publicKey = "hidden";
const schema = "https://json-schema.org/draft/2020-12/schema";
const metadataUrl = {
url: "hidden",
};
const ISSUER_URL = "https://localhost:3000";
const createweb3ID = () => {
if (publicKey) {
const id = createWeb3IdDID(network, publicKey, BigInt(10189), BigInt(0));
return id;
}
};
const credential = {
$schema: schema,
type: [
"demoCredential",
"VerifiableCredential",
"ConcordiumVerifiableCredential",
"SoMeCredential",
],
issuer: createweb3ID() || "",
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: "hidden",
attributes: {
CountryOfIssue: "US",
CardType: "Driving License",
Issuer: "DMV",
CardNumber: "123456789",
LastName: "Doe",
FirstName: "John",
MiddleName: "A",
DOB: "1990-01-01",
Sex: "Male",
Nationality: "American",
Address: "123 Main St",
Street: "Main St",
City: "Somewhere",
State: "CA",
ZipCode: "90210",
LicenceNumber: "D1234567",
LicenceClass: "C",
LicenceCondition: "None",
LicenceType: "Full",
LicenceVersion: "V1",
Donor: "No",
Entitlements: "None",
IssueDate: "2020-01-01",
ExpiryDate: "2030-01-01",
},
},
credentialSchema: {
id: "hidden",
type: "object",
},
};
const addCredential = async () => {
let txHash: string | undefined;
const api = await detectConcordiumProvider();
await api.addWeb3IdCredential(credential, metadataUrl, async (id) => {
const parts = id.split(":");
const holderId = parts[parts.length - 1];
const body: IssueRequest = {
credential: {
holderId,
holderRevocable: true,
validFrom: new Date().toISOString(),
metadataUrl,
},
};
const endpoint = ISSUER_URL + "credential";
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify(body),
});
if (!response.ok) {
if (response.status == 429)
throw new Error(
"Sorry, too many credentials have been issued for this account."
);
throw new Error("Error getting credential: " + (await response.text()));
}
const { txHash: hash, credential } =
(await response.json()) as IssuerResponse;
txHash = hash;
const { proof, randomness } = credential;
return { proof, randomness };
});
};
return (
<>
<button
className="bg-BestBank-primary p-6 rounded-xl"
onClick={addCredential}
>
test button 2
</button>
</>
);
};
export default index;