diff --git a/README.md b/README.md index db66274..2aaffb3 100644 --- a/README.md +++ b/README.md @@ -666,6 +666,16 @@ builder.renderMethod({ }); ``` +##### Define QR Code Method +Set the qrcode method to be used for the document. + +```ts +builder.qrCode({ + uri: 'https://example.com/qrcode', + type: 'TrustVCQRCode', +}); +``` + ##### Sign the Document To sign the document, provide a `PrivateKeyPair` from `@trustvc/trustvc`. @@ -690,6 +700,7 @@ Example Output After Signing "https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v1.jsonld", "https://w3id.org/vc/status-list/2021/v1", "https://trustvc.io/context/render-method-context.json", + "https://trustvc.io/context/qrcode-context.json", "https://w3id.org/security/bbs/v1" ], "type": ["VerifiableCredential"], @@ -705,6 +716,10 @@ Example Output After Signing "templateName": "BILL_OF_LADING" } ], + "qrCode": { + "uri": "https://example.com/qrcode", + "type": "TrustVCQRCode" + }, "credentialStatus": { "id": "https://example.com/status-list#", "type": "StatusList2021Entry", diff --git a/package-lock.json b/package-lock.json index 28289be..b85d25c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,10 +15,10 @@ "@tradetrust-tt/tradetrust": "^6.10.1", "@tradetrust-tt/tradetrust-utils": "^2.3.0", "@tradetrust-tt/tt-verify": "^9.4.0", - "@trustvc/w3c-context": "^1.2.5", - "@trustvc/w3c-credential-status": "^1.2.5", + "@trustvc/w3c-context": "^1.2.8", + "@trustvc/w3c-credential-status": "^1.2.8", "@trustvc/w3c-issuer": "^1.2.2", - "@trustvc/w3c-vc": "^1.2.9", + "@trustvc/w3c-vc": "^1.2.12", "ethers": "^5.8.0", "ethersV6": "npm:ethers@^6.13.6", "js-sha3": "^0.9.3", @@ -4060,9 +4060,9 @@ "integrity": "sha512-Eeo2F524VM5N3W4GwglZrnul2y6TLTwMQP3In62JdG34NZoqihYyOZLk+5wUW8sSgvIYIcJM8Dlt3xsdKZZ3tg==" }, "node_modules/@trustvc/w3c-context": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@trustvc/w3c-context/-/w3c-context-1.2.5.tgz", - "integrity": "sha512-AT7PMovU5dx+BysDzH4BRJi8b03owYnGxIaYJ5+T+tWbHlNHhB1AGvCIZb2YN5pX3ylkTs/aksVo4TI6tTgdqg==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@trustvc/w3c-context/-/w3c-context-1.2.8.tgz", + "integrity": "sha512-31TWP1+cjfeEJz7/J6cuxpMieoMZL6jDjrRRFC0qr1gIVuz9n5yQFDScQdi0R1vfgtEfUfygUecAnFuf9RR7/A==", "dependencies": { "did-resolver": "^4.1.0" }, @@ -4071,11 +4071,11 @@ } }, "node_modules/@trustvc/w3c-credential-status": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@trustvc/w3c-credential-status/-/w3c-credential-status-1.2.5.tgz", - "integrity": "sha512-H/KauNFseR855coNMP/M+NrM9BAeTmlKuYvTSeUMdNXqYntfaBcsgBMWuVieoA2epUWUnPxpDBAQTb3Z97sJ1g==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@trustvc/w3c-credential-status/-/w3c-credential-status-1.2.8.tgz", + "integrity": "sha512-8K6DAwHPv4LImA44Pe1vhe4pGIzQAre98MZAZE21x2o+fie/4cUqdtC97qcn2H95hAlF0/th5OjtBREb2rohAQ==", "dependencies": { - "@trustvc/w3c-context": "^1.2.5", + "@trustvc/w3c-context": "^1.2.8", "@trustvc/w3c-issuer": "^1.2.2", "base64url-universal": "^2.0.0", "pako": "^2.1.0" @@ -4100,12 +4100,12 @@ } }, "node_modules/@trustvc/w3c-vc": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/@trustvc/w3c-vc/-/w3c-vc-1.2.9.tgz", - "integrity": "sha512-KYeHzPTYmgAy04iYMY3rfDxKDju/O/JC1CVrDoRmb/M3pIBqRfyVudlI64LfygcaCBv9sIffNj5rSkezdzQ3eg==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/@trustvc/w3c-vc/-/w3c-vc-1.2.12.tgz", + "integrity": "sha512-YGV8AJQfebV+QqNoVhfidBrO0Mqc2tbLAQzQT8XTTd7XqP7Ollf+1QGIFxLitKr+szq+EM88q7jCsMOcRtohwQ==", "dependencies": { "@mattrglobal/jsonld-signatures-bbs": "^1.2.0", - "@trustvc/w3c-credential-status": "^1.2.5", + "@trustvc/w3c-credential-status": "^1.2.8", "@trustvc/w3c-issuer": "^1.2.2", "did-resolver": "^4.1.0", "jsonld": "^6.0.0", diff --git a/package.json b/package.json index f12c538..149ff7a 100644 --- a/package.json +++ b/package.json @@ -116,10 +116,10 @@ "@tradetrust-tt/tradetrust": "^6.10.1", "@tradetrust-tt/tradetrust-utils": "^2.3.0", "@tradetrust-tt/tt-verify": "^9.4.0", - "@trustvc/w3c-context": "^1.2.5", - "@trustvc/w3c-credential-status": "^1.2.5", + "@trustvc/w3c-context": "^1.2.8", + "@trustvc/w3c-credential-status": "^1.2.8", "@trustvc/w3c-issuer": "^1.2.2", - "@trustvc/w3c-vc": "^1.2.9", + "@trustvc/w3c-vc": "^1.2.12", "ethers": "^5.8.0", "ethersV6": "npm:ethers@^6.13.6", "js-sha3": "^0.9.3", diff --git a/src/__tests__/core/documentBuilder.test.ts b/src/__tests__/core/documentBuilder.test.ts index 6f14be5..9956020 100644 --- a/src/__tests__/core/documentBuilder.test.ts +++ b/src/__tests__/core/documentBuilder.test.ts @@ -214,4 +214,19 @@ describe('DocumentBuilder', () => { expect(documentBuilder['document'].renderMethod).toEqual([method]); }); }); + + describe('qrCode', () => { + it('should set the qrcode method', async () => { + const method = { + uri: 'https://localhost:3000/qrcode', + type: 'TrustVCQRCode', + }; + + documentBuilder.qrCode({ + uri: 'https://localhost:3000/qrcode', + type: 'TrustVCQRCode', + }); + expect(documentBuilder['document'].qrCode).toEqual(method); + }); + }); }); diff --git a/src/core/documentBuilder.ts b/src/core/documentBuilder.ts index 35e73c1..bfe4b87 100644 --- a/src/core/documentBuilder.ts +++ b/src/core/documentBuilder.ts @@ -54,6 +54,16 @@ export interface RenderMethod { templateName: string; } +/** + * Configuration for the qrcoode used in a Verifiable Credential document. + * @property {string} uri - A unique identifier for the qrcode, typically a URL or URI. + * @property {string} type - The type of the qrcode method (e.g., 'TrustVCQRCode'). + */ +export interface qrCode { + uri: string; + type: string; +} + /** * Main class responsible for building, configuring, and signing documents with credential statuses. */ @@ -136,6 +146,14 @@ export class DocumentBuilder { return this; } + // Defines the qrcode for the document. + qrCode(method: qrCode) { + if (this.isSigned) throw new Error('Configuration Error: Document is already signed.'); + this.document.qrCode = method; + this.addContext('https://trustvc.io/context/qrcode-context.json'); // Add qrcode context to document. + return this; + } + // Sign the document using the provided private key and an optional cryptographic suite. async sign(privateKey: PrivateKeyPair, cryptoSuite?: string) { if (this.isSigned) throw new Error('Configuration Error: Document is already signed.');