@sd-jwt/core 0.20.1 → 0.21.0-alpha-20260916100413

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.
Files changed (68) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +82 -80
  3. package/dist/index.cjs +1526 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +696 -0
  6. package/dist/index.d.mts +537 -527
  7. package/dist/index.mjs +1422 -1998
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +29 -49
  10. package/CHANGELOG.md +0 -39
  11. package/dist/index.d.ts +0 -686
  12. package/dist/index.js +0 -2100
  13. package/src/decode/decode.ts +0 -407
  14. package/src/decode/index.ts +0 -1
  15. package/src/decoy.ts +0 -15
  16. package/src/flattenJSON.ts +0 -99
  17. package/src/generalJSON.ts +0 -157
  18. package/src/index.ts +0 -1000
  19. package/src/jwt.ts +0 -286
  20. package/src/kbjwt.ts +0 -101
  21. package/src/present/index.ts +0 -1
  22. package/src/present/present.ts +0 -216
  23. package/src/sdjwt.ts +0 -384
  24. package/src/test/decode/decode.spec.ts +0 -197
  25. package/src/test/decoy.spec.ts +0 -30
  26. package/src/test/flattenJSON.spec.ts +0 -122
  27. package/src/test/generalJSON.spec.ts +0 -198
  28. package/src/test/index.spec.ts +0 -986
  29. package/src/test/jwt.spec.ts +0 -301
  30. package/src/test/kbjwt.spec.ts +0 -555
  31. package/src/test/pass.spec.ts +0 -7
  32. package/src/test/present/present.spec.ts +0 -305
  33. package/src/test/sdjwt.spec.ts +0 -384
  34. package/src/test/types/type.spec.ts +0 -88
  35. package/src/test/utils/base64url.spec.ts +0 -33
  36. package/src/test/utils/disclosure.spec.ts +0 -170
  37. package/src/test/utils/error.spec.ts +0 -15
  38. package/src/types/index.ts +0 -2
  39. package/src/types/type.ts +0 -270
  40. package/src/types/verification-error.ts +0 -55
  41. package/src/utils/base64url.ts +0 -6
  42. package/src/utils/disclosure.ts +0 -121
  43. package/src/utils/error.ts +0 -25
  44. package/src/utils/index.ts +0 -3
  45. package/src/utils/strict-json.ts +0 -17
  46. package/test/app-e2e.spec.ts +0 -292
  47. package/test/array_data_types.json +0 -31
  48. package/test/array_full_sd.json +0 -21
  49. package/test/array_in_sd.json +0 -13
  50. package/test/array_nested_in_plain.json +0 -29
  51. package/test/array_none_disclosed.json +0 -17
  52. package/test/array_of_nulls.json +0 -15
  53. package/test/array_of_objects.json +0 -65
  54. package/test/array_of_scalars.json +0 -19
  55. package/test/array_recursive_sd.json +0 -35
  56. package/test/array_recursive_sd_some_disclosed.json +0 -63
  57. package/test/complex.json +0 -43
  58. package/test/header_mod.json +0 -48
  59. package/test/json_serialization.json +0 -48
  60. package/test/key_binding.json +0 -48
  61. package/test/no_sd.json +0 -36
  62. package/test/object_data_types.json +0 -62
  63. package/test/recursions.json +0 -117
  64. package/test/rfc9901-audit-fixes.spec.ts +0 -252
  65. package/test/rfc9901-validation.spec.ts +0 -150
  66. package/test/tsconfig.json +0 -4
  67. package/tsconfig.json +0 -7
  68. package/vitest.config.mts +0 -4
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Apache License
1
+ Apache License
2
2
  Version 2.0, January 2004
3
3
  http://www.apache.org/licenses/
4
4
 
@@ -198,4 +198,4 @@
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
- limitations under the License.
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,106 +1,108 @@
1
- ![License](https://img.shields.io/github/license/openwallet-foundation/sd-jwt-js.svg)
2
- ![NPM](https://img.shields.io/npm/v/%40sd-jwt%2Fcore)
3
- ![Release](https://img.shields.io/github/v/release/openwallet-foundation/sd-jwt-js)
4
- ![Stars](https://img.shields.io/github/stars/openwallet-foundation/sd-jwt-js)
1
+ # @sd-jwt/core
5
2
 
6
- # SD-JWT Implementation in JavaScript (TypeScript)
7
-
8
- ## SD-JWT Core
9
-
10
- ### About
3
+ [![npm version](https://img.shields.io/npm/v/@sd-jwt/core)](https://npmjs.com/package/@sd-jwt/core)
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)
11
5
 
12
6
  Core library for [Selective Disclosure for JWTs (SD-JWT) — RFC 9901](https://www.rfc-editor.org/rfc/rfc9901.html).
13
7
 
14
- This package provides types, utilities, encoding/decoding, presentation, and the main `SDJwtInstance` class — everything needed to issue, present, and verify SD-JWTs.
15
-
16
- Check the detail description in our github [repo](https://github.com/openwallet-foundation/sd-jwt-js).
17
-
18
- ### Installation
8
+ This package provides types, utilities, encoding/decoding, presentation, and the main `SDJwtInstance` class — everything needed to issue, present, and verify SD-JWTs. For [SD-JWT-based Verifiable Credentials](https://datatracker.ietf.org/doc/draft-ietf-oauth-sd-jwt-vc/), use [`@sd-jwt/sd-jwt-vc`](../sd-jwt-vc), which is built on top of this package.
19
9
 
20
- To install this project, run the following command:
10
+ ## Installation
21
11
 
22
12
  ```bash
23
- # using npm
13
+ # Using npm
24
14
  npm install @sd-jwt/core
25
15
 
26
- # using yarn
16
+ # Using pnpm
17
+ pnpm add @sd-jwt/core
18
+
19
+ # Using yarn
27
20
  yarn add @sd-jwt/core
21
+ ```
28
22
 
29
- # using pnpm
30
- pnpm install @sd-jwt/core
23
+ ## Quick Start
24
+
25
+ ```typescript
26
+ import Crypto from 'node:crypto'
27
+ import { SDJwtInstance } from '@sd-jwt/core'
28
+
29
+ // Bring your own crypto – any Signer / Verifier / Hasher that fits the interface
30
+ const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519')
31
+
32
+ const sdjwt = new SDJwtInstance({
33
+ signer: async (data) => {
34
+ const sig = Crypto.sign(null, Buffer.from(data), privateKey)
35
+ return Buffer.from(sig).toString('base64url')
36
+ },
37
+ verifier: async (data, sig) => {
38
+ return Crypto.verify(null, Buffer.from(data), publicKey, Buffer.from(sig, 'base64url'))
39
+ },
40
+ signAlg: 'EdDSA',
41
+ hasher: async (data, alg) => {
42
+ return new Uint8Array(Crypto.createHash(alg.replace('-', '')).update(data).digest())
43
+ },
44
+ hashAlg: 'sha-256',
45
+ saltGenerator: async () => Crypto.randomBytes(16).toString('base64url'),
46
+ })
47
+
48
+ // Issue
49
+ const credential = await sdjwt.issue(
50
+ { firstname: 'John', lastname: 'Doe', ssn: '123-45-6789' },
51
+ { _sd: ['firstname', 'lastname', 'ssn'] }
52
+ )
53
+
54
+ // Present (disclose only firstname)
55
+ const presentation = await sdjwt.present(credential, { firstname: true })
56
+
57
+ // Verify
58
+ const { payload } = await sdjwt.verify(presentation)
59
+ console.log(payload) // { firstname: 'John', ... }
31
60
  ```
32
61
 
33
- Ensure you have Node.js installed as a prerequisite.
62
+ ## Examples
34
63
 
35
- ### Usage
64
+ Runnable examples are available in [`examples/sd-jwt/core`](../../examples/sd-jwt/core). Run them from the repository root:
36
65
 
37
- The library can be used to create sd-jwt based credentials. To be compliant with the `sd-jwt-vc` standard, you can use the `@sd-jwt/sd-jwt-vc` that is implementing this spec.
38
- If you want to use the pure sd-jwt class or implement your own sd-jwt credential approach, you can use this library.
66
+ ```bash
67
+ pnpm tsx examples/sd-jwt/core/basic.ts
68
+ ```
39
69
 
40
- ### Dependencies
70
+ See the [SD-JWT examples overview](../../examples/sd-jwt/README.md) for the full list.
41
71
 
42
- - [@owf/identity-common](https://www.npmjs.com/package/@owf/identity-common)
72
+ ## Security
43
73
 
44
- ### Verification
74
+ - [x] [Mandatory Signing of the Issuer-signed JWT](https://www.rfc-editor.org/rfc/rfc9901.html#name-mandatory-signing-of-the-is)
75
+ - [x] [Manipulation of Disclosures](https://www.rfc-editor.org/rfc/rfc9901.html#name-manipulation-of-disclosures)
76
+ - [x] [Entropy of the salt](https://www.rfc-editor.org/rfc/rfc9901.html#name-entropy-of-the-salt)
77
+ - [x] [Minimum length of the salt](https://www.rfc-editor.org/rfc/rfc9901.html#name-minimum-length-of-the-salt)
78
+ - [x] [Choice of a Hash Algorithm](https://www.rfc-editor.org/rfc/rfc9901.html#name-choice-of-a-hash-algorithm)
79
+ - [x] [Key Binding](https://www.rfc-editor.org/rfc/rfc9901.html#name-key-binding)
80
+ - [x] [Blinding Claim Names](https://www.rfc-editor.org/rfc/rfc9901.html#name-blinding-claim-names)
81
+ - [x] [Selectively-Disclosable Validity Claims](https://www.rfc-editor.org/rfc/rfc9901.html#name-selectively-disclosable-val)
82
+ - [x] [Issuer Signature Key Distribution and Rotation](https://www.rfc-editor.org/rfc/rfc9901.html#name-issuer-signature-key-distri)
83
+ - [x] [Forwarding Credentials](https://www.rfc-editor.org/rfc/rfc9901.html#name-forwarding-credentials)
84
+ - [x] [Integrity of Presentation](https://www.rfc-editor.org/rfc/rfc9901.html#name-integrity-of-presentation)
85
+ - [x] [Explicit Typing](https://www.rfc-editor.org/rfc/rfc9901.html#name-explicit-typing)
86
+ - [x] [Duplicate Digest Rejection (Section 7.1 step 4)](https://www.rfc-editor.org/rfc/rfc9901.html#section-7.1)
87
+ - [x] [Unreferenced Disclosure Rejection (Section 7.1 step 5)](https://www.rfc-editor.org/rfc/rfc9901.html#section-7.1)
88
+ - [x] [Claim Name Collision Detection (Section 7.1 step 3c.ii.3)](https://www.rfc-editor.org/rfc/rfc9901.html#section-7.1)
45
89
 
46
- The library provides two verification approaches:
90
+ ## Platform Support
47
91
 
48
- #### Standard Verification (Fail-Fast)
92
+ This library is **platform agnostic** and works in:
49
93
 
50
- The `verify()` method throws an error immediately when the first validation failure is encountered:
94
+ - ✅ Node.js (>=20)
95
+ - ✅ Browsers (modern browsers with ES2020 support)
96
+ - ✅ React Native
51
97
 
52
- ```typescript
53
- try {
54
- const result = await sdjwt.verify(credential);
55
- console.log('Verified payload:', result.payload);
56
- } catch (error) {
57
- console.error('Verification failed:', error.message);
58
- }
59
- ```
98
+ A global `TextEncoder` and `TextDecoder` must be available. See the [React Native notes](../identity-common/README.md#react-native) if you need a polyfill.
60
99
 
61
- #### Safe Verification (Collect All Errors)
100
+ Cryptographic operations (signing, verification, hashing, salt generation) are provided as callbacks. [`@owf/crypto`](https://github.com/openwallet-foundation-labs/identity-common-ts/tree/main/packages/crypto) provides Web Crypto based implementations.
62
101
 
63
- The `safeVerify()` method collects all validation errors instead of failing on the first one. This is useful when you want to show users all issues with a credential at once:
102
+ ## Contributing
64
103
 
65
- ```typescript
66
- import type { SafeVerifyResult, VerificationError } from '@sd-jwt/core';
67
-
68
- const result = await sdjwt.safeVerify(credential);
69
-
70
- if (result.success) {
71
- // Verification succeeded
72
- console.log('Verified payload:', result.data.payload);
73
- console.log('Header:', result.data.header);
74
- if (result.data.kb) {
75
- console.log('Key binding:', result.data.kb);
76
- }
77
- } else {
78
- // Verification failed - inspect all errors
79
- for (const error of result.errors) {
80
- console.error(`[${error.code}] ${error.message}`);
81
- if (error.details) {
82
- console.error('Details:', error.details);
83
- }
84
- }
85
- }
86
- ```
104
+ 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.
105
+
106
+ ## License
87
107
 
88
- ##### Error Codes
89
-
90
- The `safeVerify()` method returns errors with the following codes:
91
-
92
- | Code | Description |
93
- |------|-------------|
94
- | `HASHER_NOT_FOUND` | Hasher function not configured |
95
- | `VERIFIER_NOT_FOUND` | Verifier function not configured |
96
- | `INVALID_SD_JWT` | SD-JWT structure is invalid or cannot be decoded |
97
- | `INVALID_JWT_FORMAT` | JWT format is malformed |
98
- | `JWT_NOT_YET_VALID` | JWT `iat` or `nbf` claim is in the future |
99
- | `JWT_EXPIRED` | JWT `exp` claim is in the past |
100
- | `INVALID_JWT_SIGNATURE` | Signature verification failed |
101
- | `MISSING_REQUIRED_CLAIMS` | Required claim keys are not present |
102
- | `KEY_BINDING_JWT_MISSING` | Key binding JWT required but not present |
103
- | `KEY_BINDING_VERIFIER_NOT_FOUND` | Key binding verifier not configured |
104
- | `KEY_BINDING_SIGNATURE_INVALID` | Key binding signature verification failed |
105
- | `KEY_BINDING_SD_HASH_INVALID` | Key binding `sd_hash` does not match |
106
- | `UNKNOWN_ERROR` | An unexpected error occurred |
108
+ 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).