Signing Documents (Code)
For the current step, you can either opt to use the CLI or Code.
Only while using
bitstringfor Credential Status, the list can be configured as either a revocation list or a suspension list, depending on the use case.
Each documents will be signed individually, and the proof of the signature will be appended into the signed documents.
Installation
npm install @trustvc/trustvc
Usage
Signing a document
signW3C takes a document, a wallet (public and private key pair) or an Ethers.js Signer.
The method will sign the merkle root from the document, append the signature to the document and return it. Currently, it supports the following sign algorithm:
ecdsa-sd-2023
Example with Wallet
import { signW3C, VerificationType } from "@trustvc/trustvc";
const rawDocument = {
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://w3id.org/security/data-integrity/v2",
"https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld",
],
credentialStatus: {
id: "https://trustvc.github.io/did/credentials/statuslist/1#1",
type: "BitstringStatusListEntry",
statusPurpose: "revocation",
statusListIndex: "10",
statusListCredential: "https://trustvc.github.io/did/credentials/statuslist/1",
},
credentialSubject: {
name: "TrustVC",
birthDate: "2024-04-01T12:19:52Z",
type: ["PermanentResident", "Person"],
},
validUntil: "2029-12-03T12:19:52Z",
issuer: "did:web:trustvc.github.io:did:1",
type: ["VerifiableCredential"],
validFrom: "2024-04-01T12:19:52Z",
};
// Sign the credential
const signingResult = await signW3C(rawDocument, {
"@context": "https://w3id.org/security/multikey/v1",
id: "did:web:trustvc.github.io:did:1#keys-1",
controller: "did:web:trustvc.github.io:did:1",
type: VerificationType.Multikey,
publicKeyMultibase: "<publicKeyMultibase>",
secretKeyMultibase: "<secretKeyMultibase>",
});
console.log(`Signed Document: ${JSON.stringify(signedDocument)}`);
// Signed Document:
{
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://w3id.org/security/data-integrity/v2",
"https://w3c-ccg.github.io/citizenship-vocab/contexts/citizenship-v2.jsonld",
],
"credentialStatus": {
"id": "https://trustvc.github.io/did/credentials/statuslist/1#1",
"type": "BitstringStatusListEntry",
"statusPurpose": "revocation",
"statusListIndex": "10",
"statusListCredential": "https://trustvc.github.io/did/credentials/statuslist/1"
},
"credentialSubject": {
"name": "TrustVC",
"birthDate": "2024-04-01T12:19:52Z",
"type": ["PermanentResident", "Person"]
},
"validUntil": "2029-12-03T12:19:52Z",
"issuer": "did:web:trustvc.github.io:did:1",
"type": ["VerifiableCredential"],
"validFrom": "2024-04-01T12:19:52Z",
"id": "urn:bnid:_:01947f6a-8c2c-7117-9f9b-f990ec638dbb",
"proof": {
"type": "DataIntegrityProof",
"cryptosuite": "ecdsa-sd-2023",
"created": "2025-01-19T16:34:40Z",
"proofPurpose": "assertionMethod",
"proofValue": "uS/VAIsquT7QifmvtJ2Mx3TBbTl7O6eLBk3GXaVfiimKJMM18Q9YQ5+vcGFhXoYfDuZ1Lbue0sgpSrxPGO2hH48UNpEIR5BaAwS1+Cjut+wpXov0rRg5MOLf/uTFLwjn1Luf7vd0bnRxI8zLq5Rv5g==",
"verificationMethod": "did:web:github.com:TrustVC:did:blob:main:1#keys-1"
}
}