Yes, that is possible - just strange it works on testnet. But moving on to verify the proof we get POST https://web3id-verifier.mainnet.concordium.software/v0/verify 400 (Bad Request)
.
Interestingly, this works on the testnet as expected. Below is the code snippet and console:
let account = await walletProvider.connect();
// Define the attributes to be revealed
const attributesToReveal = [
AttributeKeyString.legalName,
AttributeKeyString.legalCountry,
AttributeKeyString.businessNumber,
AttributeKeyString.registrationAuth,
];
// Create the reveal statement for each attribute
const statement = attributesToReveal.map((attributeTag) => ({
type: StatementTypes.RevealAttribute,
attributeTag,
}));
const credentialStatement = {
statement,
idQualifier: {
type: ‘cred’,
issuers: [issuerId],
},
};
const challenge = […crypto.getRandomValues(new Uint8Array(32))]
.map((b) => b.toString(16).padStart(2, ‘0’))
.join(‘’);
const proof = await walletProvider.requestVerifiablePresentation(challenge, [credentialStatement]);
if (!proof) {
throw new Error(‘Failed to retrieve proof from wallet provider.’);
}
// Base64 encode the proof JSON
const proofBase64 = btoa(JSON.stringify(proof));
const revealedAttributes = { account, proofBase64 };
const verifiableCredential = proof?.verifiableCredential?.[0];
const proofValues = verifiableCredential?.credentialSubject?.proof?.proofValue;
if (proofValues) {
attributesToReveal.forEach((attributeTag, index) => {
const proofValue = proofValues[index];
const attributeValue = proofValue?.attribute || ‘No value provided’;
revealedAttributes[attributeTag] = attributeValue;
});
} else {
throw new Error(‘No proof values found.’);
}
console.log(‘Proof:’, proof);
console.log(‘Revealed attributes:’, revealedAttributes);
console.log(‘Backend API:’, backendAPI);
// Submit the proof to the backend
const resp = await fetch(${backendAPI}
, {
method: ‘POST’,
headers: { ‘Content-Type’: ‘application/json’ },
body: JSON.stringify(proof),
});
if (!resp.ok) {
const errorBody = await resp.json();
throw new Error(Proof submission failed: ${resp.status} - ${errorBody.message}
);
}
console of the Proof: Proof:
-
Yu {presentationContext: ‘4b1d8b82b5dc653ffc7cb24457cb5ae8b1122f59a35ce24f61fb15a22aa16e90’, proof: {…}, type: ‘VerifiablePresentation’, verifiableCredential: Array(1)}
-
presentationContext: “4b1d8b82b5dc653ffc7cb24457cb5ae8b1122f59a35ce24f61fb15a22aa16e90”
-
proof:
1. created: "2024-10-24T13:19:57.598545422Z"
2. proofValue: Array(0)
1. length: 0
2. [[Prototype]]: Array(0)
3. type: "ConcordiumWeakLinkingProofV1"
- type: “VerifiablePresentation”
- verifiableCredential: Array(1)
1. 0: {credentialSubject: {…}, issuer: 'did:ccd:mainnet:idp:3', type: Array(2)}
2. length: 1
3. [[Prototype]]: Array(0)
- [[Prototype]]: Object
1. constructor: class Yu
2. toString: ƒ toString()
3. [[Prototype]]: Object