|
| 1 | +# SD JWT VCDM Typescript |
| 2 | + |
| 3 | +> ⚠️ **Platform Support**: This package currently supports Node.js environments only. |
| 4 | +
|
| 5 | +Typescript implementation of SD JWT VCDM profile. |
| 6 | + |
| 7 | +A library that integrates SD-JWT with W3C Verifiable Credentials Data Model and implements JAdES digital signature standards. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +### SD-JWT VCDM Data Model Profile |
| 12 | + |
| 13 | +This library provides interoperability between SD-JWT (Selective Disclosure JWT) and W3C Verifiable Credentials Data Model: |
| 14 | + |
| 15 | +- Issue Verifiable Digital Credentials in SD-JWT VC format while maintaining W3C VCDM compliance |
| 16 | +- Support for Selective Disclosure capabilities |
| 17 | +- Seamless integration with standard VC verification processes |
| 18 | + |
| 19 | +### JAdES Digital Signature Integration |
| 20 | + |
| 21 | +Implements JAdES (JSON Advanced Electronic Signatures) standard for SD-JWT with support for the following signature profiles: |
| 22 | + |
| 23 | +- **B-B (Basic - Baseline)**: Basic signature format |
| 24 | +- **B-T (Basic with Time)**: Signatures with timestamp |
| 25 | +- **B-LT (Basic Long-Term)**: Signatures with validation data for long-term preservation |
| 26 | +- **B-LTA (Basic Long-Term with Archive timestamps)**: Long-term preservation with periodic timestamp renewal |
| 27 | + |
| 28 | +## Installation |
| 29 | + |
| 30 | +```bash |
| 31 | +pnpm add sd-jwt-vcdm |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### B-B |
| 37 | + |
| 38 | +```typescript |
| 39 | +import { JAdES, parseCerts, createKidFromCert } from 'sd-jwt-jades'; |
| 40 | +import * as fs from 'fs'; |
| 41 | +import { createPrivateKey } from 'node:crypto'; |
| 42 | + |
| 43 | +(async () => { |
| 44 | + const jades = new JAdES.Sign({ data: 'data 1', target: 'data 2' }); |
| 45 | + |
| 46 | + const certPem = fs.readFileSync('./fixtures/certificate.crt', 'utf-8'); |
| 47 | + const certs = parseCerts(certPem); |
| 48 | + const kid = createKidFromCert(certs[0]); |
| 49 | + |
| 50 | + const keyPem = fs.readFileSync('./fixtures/private.pem', 'utf-8'); |
| 51 | + const privateKey = createPrivateKey(keyPem); |
| 52 | + |
| 53 | + await jades |
| 54 | + .setProtectedHeader({ |
| 55 | + alg: 'RS256', |
| 56 | + typ: 'jades', |
| 57 | + }) |
| 58 | + .setX5c(certs) |
| 59 | + .setDisclosureFrame({ |
| 60 | + _sd: ['data'], |
| 61 | + }) |
| 62 | + .setSignedAt() |
| 63 | + .sign(privateKey, kid); |
| 64 | + |
| 65 | + const serialized = jades.toJSON(); |
| 66 | + console.log(serialized); |
| 67 | +})(); |
| 68 | +``` |
| 69 | + |
| 70 | +### B-T |
| 71 | + |
| 72 | +```typescript |
| 73 | +import { JAdES, parseCerts, createKidFromCert } from 'sd-jwt-jades'; |
| 74 | +import * as fs from 'fs'; |
| 75 | +import { createPrivateKey } from 'node:crypto'; |
| 76 | + |
| 77 | +(async () => { |
| 78 | + const jades = new JAdES.Sign({ data: 'data 1', target: 'data 2' }); |
| 79 | + |
| 80 | + const certPem = fs.readFileSync('./fixtures/certificate.crt', 'utf-8'); |
| 81 | + const certs = parseCerts(certPem); |
| 82 | + const kid = createKidFromCert(certs[0]); |
| 83 | + |
| 84 | + const keyPem = fs.readFileSync('./fixtures/private.pem', 'utf-8'); |
| 85 | + const privateKey = createPrivateKey(keyPem); |
| 86 | + |
| 87 | + await jades |
| 88 | + .setProtectedHeader({ |
| 89 | + alg: 'RS256', |
| 90 | + typ: 'jades', |
| 91 | + }) |
| 92 | + .setX5c(certs) |
| 93 | + .setDisclosureFrame({ |
| 94 | + _sd: ['data'], |
| 95 | + }) |
| 96 | + .setSignedAt() |
| 97 | + .setUnprotectedHeader({ |
| 98 | + etsiU: [ |
| 99 | + { |
| 100 | + sigTst: { |
| 101 | + tstTokens: [ |
| 102 | + { |
| 103 | + val: 'Base64-encoded RFC 3161 Timestamp Token', |
| 104 | + }, |
| 105 | + ], |
| 106 | + }, |
| 107 | + }, |
| 108 | + ], |
| 109 | + }) |
| 110 | + .sign(privateKey, kid); |
| 111 | + |
| 112 | + const serialized = jades.toJSON(); |
| 113 | + console.log(serialized); |
| 114 | +})(); |
| 115 | +``` |
| 116 | + |
| 117 | +### B-LT |
| 118 | + |
| 119 | +```typescript |
| 120 | +import { JAdES, parseCerts, createKidFromCert } from 'sd-jwt-jades'; |
| 121 | +import * as fs from 'fs'; |
| 122 | +import { createPrivateKey } from 'node:crypto'; |
| 123 | + |
| 124 | +(async () => { |
| 125 | + const jades = new JAdES.Sign({ data: 'data 1', target: 'data 2' }); |
| 126 | + |
| 127 | + const certPem = fs.readFileSync('./fixtures/certificate.crt', 'utf-8'); |
| 128 | + const certs = parseCerts(certPem); |
| 129 | + const kid = createKidFromCert(certs[0]); |
| 130 | + |
| 131 | + const keyPem = fs.readFileSync('./fixtures/private.pem', 'utf-8'); |
| 132 | + const privateKey = createPrivateKey(keyPem); |
| 133 | + |
| 134 | + await jades |
| 135 | + .setProtectedHeader({ |
| 136 | + alg: 'RS256', |
| 137 | + typ: 'jades', |
| 138 | + }) |
| 139 | + .setX5c(certs) |
| 140 | + .setDisclosureFrame({ |
| 141 | + _sd: ['data'], |
| 142 | + }) |
| 143 | + .setSignedAt() |
| 144 | + .setUnprotectedHeader({ |
| 145 | + etsiU: [ |
| 146 | + { |
| 147 | + sigTst: { |
| 148 | + tstTokens: [ |
| 149 | + { |
| 150 | + val: 'Base64-encoded RFC 3161 Timestamp Token', |
| 151 | + }, |
| 152 | + ], |
| 153 | + }, |
| 154 | + }, |
| 155 | + { |
| 156 | + xVals: [ |
| 157 | + { x509Cert: 'Base64-encoded Trust Anchor' }, |
| 158 | + { x509Cert: 'Base64-encoded CA Certificate' }, |
| 159 | + ], |
| 160 | + }, |
| 161 | + { |
| 162 | + rVals: { |
| 163 | + crlVals: ['Base64-encoded CRL'], |
| 164 | + ocspVals: ['Base64-encoded OCSP Response'], |
| 165 | + }, |
| 166 | + }, |
| 167 | + ], |
| 168 | + }) |
| 169 | + .sign(privateKey, kid); |
| 170 | + |
| 171 | + const serialized = jades.toJSON(); |
| 172 | + console.log(serialized); |
| 173 | +})(); |
| 174 | +``` |
| 175 | + |
| 176 | +### B-LTA |
| 177 | + |
| 178 | +```typescript |
| 179 | +import { JAdES, parseCerts, createKidFromCert } from 'sd-jwt-jades'; |
| 180 | +import * as fs from 'fs'; |
| 181 | +import { createPrivateKey } from 'node:crypto'; |
| 182 | + |
| 183 | +(async () => { |
| 184 | + const jades = new JAdES.Sign({ data: 'data 1', target: 'data 2' }); |
| 185 | + |
| 186 | + const certPem = fs.readFileSync('./fixtures/certificate.crt', 'utf-8'); |
| 187 | + const certs = parseCerts(certPem); |
| 188 | + const kid = createKidFromCert(certs[0]); |
| 189 | + |
| 190 | + const keyPem = fs.readFileSync('./fixtures/private.pem', 'utf-8'); |
| 191 | + const privateKey = createPrivateKey(keyPem); |
| 192 | + |
| 193 | + await jades |
| 194 | + .setProtectedHeader({ |
| 195 | + alg: 'RS256', |
| 196 | + typ: 'jades', |
| 197 | + }) |
| 198 | + .setX5c(certs) |
| 199 | + .setDisclosureFrame({ |
| 200 | + _sd: ['data'], |
| 201 | + }) |
| 202 | + .setSignedAt() |
| 203 | + .sign(privateKey, kid); |
| 204 | + |
| 205 | + const serialized = jades.toJSON(); |
| 206 | + console.log(serialized); |
| 207 | +})(); |
| 208 | +``` |
| 209 | + |
| 210 | +## License |
| 211 | + |
| 212 | +Apache License 2.0 |
| 213 | + |
| 214 | +## References |
| 215 | + |
| 216 | +- [SD-JWT VC Data Model](https://github.com/danielfett/sd-jwt-vc-dm) |
| 217 | +- [OpenID4VC HAIP Profile](https://github.com/openid/oid4vc-haip/pull/147/files#diff-762ef65fd82909517226ac1bb7e8855792bb57021abc1637c15b8557154dbbf1) |
| 218 | +- [ETSI TS 119 182-1 - JAdES Baseline Signatures](https://www.etsi.org/deliver/etsi_ts/119100_119199/11918201/01.02.01_60/ts_11918201v010201p.pdf) |
0 commit comments