Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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"],
Expand All @@ -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#<placeholder>",
"type": "StatusList2021Entry",
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/core/documentBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
18 changes: 18 additions & 0 deletions src/core/documentBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.');
Expand Down