@sd-jwt/core 0.20.2-next.0 → 0.21.0-alpha-20260916100701
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/LICENSE +2 -2
- package/README.md +82 -80
- package/dist/index.cjs +1526 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +696 -0
- package/dist/index.d.mts +537 -527
- package/dist/index.mjs +1422 -1998
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -49
- package/CHANGELOG.md +0 -39
- package/dist/index.d.ts +0 -686
- package/dist/index.js +0 -2100
- package/src/decode/decode.ts +0 -407
- package/src/decode/index.ts +0 -1
- package/src/decoy.ts +0 -15
- package/src/flattenJSON.ts +0 -99
- package/src/generalJSON.ts +0 -157
- package/src/index.ts +0 -1000
- package/src/jwt.ts +0 -286
- package/src/kbjwt.ts +0 -101
- package/src/present/index.ts +0 -1
- package/src/present/present.ts +0 -216
- package/src/sdjwt.ts +0 -384
- package/src/test/decode/decode.spec.ts +0 -197
- package/src/test/decoy.spec.ts +0 -30
- package/src/test/flattenJSON.spec.ts +0 -122
- package/src/test/generalJSON.spec.ts +0 -198
- package/src/test/index.spec.ts +0 -986
- package/src/test/jwt.spec.ts +0 -301
- package/src/test/kbjwt.spec.ts +0 -555
- package/src/test/pass.spec.ts +0 -7
- package/src/test/present/present.spec.ts +0 -305
- package/src/test/sdjwt.spec.ts +0 -384
- package/src/test/types/type.spec.ts +0 -88
- package/src/test/utils/base64url.spec.ts +0 -33
- package/src/test/utils/disclosure.spec.ts +0 -170
- package/src/test/utils/error.spec.ts +0 -15
- package/src/types/index.ts +0 -2
- package/src/types/type.ts +0 -270
- package/src/types/verification-error.ts +0 -55
- package/src/utils/base64url.ts +0 -6
- package/src/utils/disclosure.ts +0 -121
- package/src/utils/error.ts +0 -25
- package/src/utils/index.ts +0 -3
- package/src/utils/strict-json.ts +0 -17
- package/test/app-e2e.spec.ts +0 -292
- package/test/array_data_types.json +0 -31
- package/test/array_full_sd.json +0 -21
- package/test/array_in_sd.json +0 -13
- package/test/array_nested_in_plain.json +0 -29
- package/test/array_none_disclosed.json +0 -17
- package/test/array_of_nulls.json +0 -15
- package/test/array_of_objects.json +0 -65
- package/test/array_of_scalars.json +0 -19
- package/test/array_recursive_sd.json +0 -35
- package/test/array_recursive_sd_some_disclosed.json +0 -63
- package/test/complex.json +0 -43
- package/test/header_mod.json +0 -48
- package/test/json_serialization.json +0 -48
- package/test/key_binding.json +0 -48
- package/test/no_sd.json +0 -36
- package/test/object_data_types.json +0 -62
- package/test/recursions.json +0 -117
- package/test/rfc9901-audit-fixes.spec.ts +0 -252
- package/test/rfc9901-validation.spec.ts +0 -150
- package/test/tsconfig.json +0 -4
- package/tsconfig.json +0 -7
- package/vitest.config.mts +0 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
2
|
-

|
|
3
|
-

|
|
4
|
-

|
|
1
|
+
# @sd-jwt/core
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## SD-JWT Core
|
|
9
|
-
|
|
10
|
-
### About
|
|
3
|
+
[](https://npmjs.com/package/@sd-jwt/core)
|
|
4
|
+
[](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
|
-
|
|
10
|
+
## Installation
|
|
21
11
|
|
|
22
12
|
```bash
|
|
23
|
-
#
|
|
13
|
+
# Using npm
|
|
24
14
|
npm install @sd-jwt/core
|
|
25
15
|
|
|
26
|
-
#
|
|
16
|
+
# Using pnpm
|
|
17
|
+
pnpm add @sd-jwt/core
|
|
18
|
+
|
|
19
|
+
# Using yarn
|
|
27
20
|
yarn add @sd-jwt/core
|
|
21
|
+
```
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
62
|
+
## Examples
|
|
34
63
|
|
|
35
|
-
|
|
64
|
+
Runnable examples are available in [`examples/sd-jwt/core`](../../examples/sd-jwt/core). Run them from the repository root:
|
|
36
65
|
|
|
37
|
-
|
|
38
|
-
|
|
66
|
+
```bash
|
|
67
|
+
pnpm tsx examples/sd-jwt/core/basic.ts
|
|
68
|
+
```
|
|
39
69
|
|
|
40
|
-
|
|
70
|
+
See the [SD-JWT examples overview](../../examples/sd-jwt/README.md) for the full list.
|
|
41
71
|
|
|
42
|
-
|
|
72
|
+
## Security
|
|
43
73
|
|
|
44
|
-
|
|
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
|
-
|
|
90
|
+
## Platform Support
|
|
47
91
|
|
|
48
|
-
|
|
92
|
+
This library is **platform agnostic** and works in:
|
|
49
93
|
|
|
50
|
-
|
|
94
|
+
- ✅ Node.js (>=20)
|
|
95
|
+
- ✅ Browsers (modern browsers with ES2020 support)
|
|
96
|
+
- ✅ React Native
|
|
51
97
|
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
## Contributing
|
|
64
103
|
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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).
|