@owf/eudi-jades 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # @owf/eudi-jades
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@owf/eudi-jades)](https://npmjs.com/package/@owf/eudi-jades)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/openwallet-foundation-labs/identity-common-ts/blob/main/LICENSE)
5
+
6
+ JAdES (JSON Advanced Electronic Signatures) implementation based on [ETSI TS 119 182-1](https://www.etsi.org/deliver/etsi_ts/119100_119199/11918201/01.02.01_60/ts_11918201v010201p.pdf) standard.
7
+
8
+ ## Features
9
+
10
+ - **JAdES Baseline Profiles**: B-B, B-T, B-LT, B-LTA
11
+ - **Signature Algorithms**: ES256, ES384, ES512, RS256, RS384, RS512, PS256, PS384, PS512
12
+ - **Certificate Handling**: x5c, x5u, x5t#S256, x5t#o, sigX5ts
13
+ - **Output Formats**: Compact JWS, General JWS JSON, Flattened JWS JSON
14
+ - **Detached Signatures**: Support for detached payload signatures
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ # Using npm
20
+ npm install @owf/eudi-jades
21
+
22
+ # Using pnpm
23
+ pnpm add @owf/eudi-jades
24
+
25
+ # Using yarn
26
+ yarn add @owf/eudi-jades
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Basic Signature (B-B Profile)
32
+
33
+ ```typescript
34
+ import { Token, parseCerts } from '@owf/eudi-jades'
35
+ import { ES256 } from '@owf/crypto'
36
+
37
+ // Create payload
38
+ const payload = {
39
+ credentialSubject: {
40
+ id: 'did:example:123',
41
+ name: 'John Doe',
42
+ },
43
+ }
44
+
45
+ // Create token
46
+ const token = new Token(payload)
47
+
48
+ // Set protected header with certificate
49
+ const certs = parseCerts(pemCertificate)
50
+ token
51
+ .setProtectedHeader({ alg: 'ES256' })
52
+ .setX5c(certs)
53
+ .setKid('signer-key-2025')
54
+ .setSignedAt()
55
+
56
+ // Sign
57
+ const signer = await ES256.getSigner(privateKey)
58
+ await token.sign(signer)
59
+
60
+ // Get compact JWS
61
+ const compactJws = token.toString()
62
+ // eyJhbGciOiJFUzI1NiIsIng1YyI6Wy4uLl0sLi4ufQ.eyJjcmVkZW50aWFsU3ViamVjdCI6ey4uLn19.signature
63
+
64
+ // Get General JWS JSON
65
+ const generalJws = token.toJSON()
66
+ // { payload: "...", signatures: [{ protected: "...", signature: "..." }] }
67
+ ```
68
+
69
+ ### Signature with Timestamp (B-T Profile)
70
+
71
+ ```typescript
72
+ import { Token, parseCerts } from '@owf/eudi-jades'
73
+
74
+ const token = new Token(payload)
75
+ const certs = parseCerts(pemCertificate)
76
+
77
+ token
78
+ .setProtectedHeader({ alg: 'ES256' })
79
+ .setX5c(certs)
80
+ .setSigningTime() // ISO 8601 timestamp
81
+
82
+ // Add timestamp token in unprotected header
83
+ token.setUnprotectedHeader({
84
+ etsiU: [
85
+ {
86
+ sigTst: {
87
+ tstTokens: [{ val: 'Base64-encoded-RFC-3161-timestamp' }],
88
+ },
89
+ },
90
+ ],
91
+ })
92
+
93
+ await token.sign(signer)
94
+ ```
95
+
96
+ ### Verification
97
+
98
+ ```typescript
99
+ import { verify, verifyCompact, decode } from '@owf/eudi-jades'
100
+ import { ES256 } from '@owf/crypto'
101
+
102
+ // Verify compact JWS
103
+ const verifier = await ES256.getVerifier(publicKey)
104
+ const result = await verifyCompact(compactJws, verifier)
105
+
106
+ console.log(result.valid) // true
107
+ console.log(result.payload) // decoded payload
108
+ console.log(result.header) // decoded protected header
109
+
110
+ // Auto-detect format and verify
111
+ const result2 = await verify(jwsStringOrObject, verifier)
112
+
113
+ // Decode without verification (for inspection only)
114
+ const decoded = decode(compactJws)
115
+ ```
116
+
117
+ ### Utility Functions
118
+
119
+ ```typescript
120
+ import {
121
+ parseCerts,
122
+ generateX5c,
123
+ generateX5tS256,
124
+ generateX5tO,
125
+ generateKid,
126
+ getSigningTime,
127
+ } from '@owf/eudi-jades'
128
+
129
+ // Parse PEM certificate chain
130
+ const certs = parseCerts(pemString)
131
+
132
+ // Generate x5c header value
133
+ const x5c = generateX5c(pemString)
134
+
135
+ // Generate SHA-256 thumbprint
136
+ const thumbprint = await generateX5tS256(certDer)
137
+
138
+ // Generate thumbprint with other algorithm
139
+ const x5tO = await generateX5tO(certDer, 'SHA-512')
140
+
141
+ // Generate key ID from certificate
142
+ const kid = await generateKid(certDer)
143
+
144
+ // Get current signing time
145
+ const sigT = getSigningTime() // "2025-03-23T14:30:00Z"
146
+ ```
147
+
148
+ ## JAdES Profiles
149
+
150
+ | Profile | Description | Headers Required |
151
+ |---------|-------------|------------------|
152
+ | **B-B** | Basic signature | alg, x5c or x5t#S256 |
153
+ | **B-T** | With timestamp | B-B + sigTst in etsiU |
154
+ | **B-LT** | Long-term validation | B-T + xVals, rVals |
155
+ | **B-LTA** | Archive timestamps | B-LT + arcTst |
156
+
157
+ ## Platform Support
158
+
159
+ This library is **platform agnostic** and works in:
160
+
161
+ - ✅ Node.js (>=20)
162
+ - ✅ Browsers (modern browsers with ES2020 support)
163
+ - ✅ React Native
164
+
165
+ ## References
166
+
167
+ - [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)
168
+ - [RFC 7515 - JSON Web Signature (JWS)](https://datatracker.ietf.org/doc/html/rfc7515)
169
+ - [RFC 7797 - JSON Web Signature Unencoded Payload Option](https://datatracker.ietf.org/doc/html/rfc7797)
170
+
171
+ ## API Reference
172
+
173
+ ### Classes
174
+
175
+ - `Token<T>` - Main class for creating JAdES signatures
176
+
177
+ ### Functions
178
+
179
+ - `verify(jws, verifier)` - Verify JWS (auto-detect format)
180
+ - `verifyCompact(jws, verifier)` - Verify compact JWS
181
+ - `verifyGeneral(jws, verifier)` - Verify General JWS JSON
182
+ - `decode(jws)` - Decode without verification
183
+
184
+ ### Utilities
185
+
186
+ - `parseCerts(pem)` - Parse PEM certificates
187
+ - `generateX5c(certs)` - Generate x5c header
188
+ - `generateX5tS256(cert)` - Generate SHA-256 thumbprint
189
+ - `generateX5tO(cert, alg)` - Generate thumbprint with algorithm
190
+ - `generateKid(cert)` - Generate key ID
191
+ - `getSigningTime()` - Get current ISO timestamp
192
+
193
+ ## Contributing
194
+
195
+ See the [Contributing Guide](https://github.com/openwallet-foundation-labs/identity-common-ts/blob/main/CONTRIBUTING.md) for details on how to contribute to this project.
196
+
197
+ ## License
198
+
199
+ This project is licensed under the [Apache License Version 2.0](https://github.com/openwallet-foundation-labs/identity-common-ts/blob/main/LICENSE) (Apache-2.0).