@sd-jwt/core 0.3.2-next.63 → 0.3.2-next.65
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 +78 -0
- package/package.json +6 -6
- package/src/sdjwt.ts +17 -1
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
# SD-JWT Implementation in JavaScript (TypeScript)
|
|
7
|
+
|
|
8
|
+
## SD-JWT Core
|
|
9
|
+
|
|
10
|
+
### About
|
|
11
|
+
|
|
12
|
+
Core library for selective disclosure JWTs
|
|
13
|
+
|
|
14
|
+
Check the detail description in our github [repo](https://github.com/openwallet-foundation-labs/sd-jwt-js).
|
|
15
|
+
|
|
16
|
+
### Installation
|
|
17
|
+
|
|
18
|
+
To install this project, run the following command:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# using npm
|
|
22
|
+
npm install @sd-jwt/core
|
|
23
|
+
|
|
24
|
+
# using yarn
|
|
25
|
+
yarn add @sd-jwt/core
|
|
26
|
+
|
|
27
|
+
# using pnpm
|
|
28
|
+
pnpm install @sd-jwt/core
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Ensure you have Node.js installed as a prerequisite.
|
|
32
|
+
|
|
33
|
+
### Usage
|
|
34
|
+
|
|
35
|
+
Here's a basic example of how to use this library:
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
import { DisclosureFrame } from '@sd-jwt/core';
|
|
39
|
+
|
|
40
|
+
// Issuer defines the claims object with the user's information
|
|
41
|
+
const claims = {
|
|
42
|
+
firstname: 'John',
|
|
43
|
+
lastname: 'Doe',
|
|
44
|
+
ssn: '123-45-6789',
|
|
45
|
+
id: '1234',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Issuer defines the disclosure frame to specify which claims can be disclosed/undisclosed
|
|
49
|
+
const disclosureFrame: DisclosureFrame<typeof claims> = {
|
|
50
|
+
_sd: ['firstname', 'lastname', 'ssn'],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Issuer issues a signed JWT credential with the specified claims and disclosure frame
|
|
54
|
+
// returns an encoded JWT
|
|
55
|
+
const credential = await sdjwt.issue(claims, disclosureFrame);
|
|
56
|
+
|
|
57
|
+
// Holder may validate the credential from the issuer
|
|
58
|
+
const valid = await sdjwt.validate(credential);
|
|
59
|
+
|
|
60
|
+
// Holder defines the presentation frame to specify which claims should be presented
|
|
61
|
+
// The list of presented claims must be a subset of the disclosed claims
|
|
62
|
+
const presentationFrame = ['firstname', 'ssn'];
|
|
63
|
+
|
|
64
|
+
// Holder creates a presentation using the issued credential and the presentation frame
|
|
65
|
+
// returns an encoded SD JWT.
|
|
66
|
+
const presentation = await sdjwt.present(credential, presentationFrame);
|
|
67
|
+
|
|
68
|
+
// Verifier can verify the presentation using the Issuer's public key
|
|
69
|
+
const verified = await sdjwt.verify(presentation);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Check out more details in our [documentation](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/next/docs) or [examples](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/next/examples)
|
|
73
|
+
|
|
74
|
+
### Dependencies
|
|
75
|
+
|
|
76
|
+
- @sd-jwt/decode
|
|
77
|
+
- @sd-jwt/types
|
|
78
|
+
- @sd-jwt/utils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/core",
|
|
3
|
-
"version": "0.3.2-next.
|
|
3
|
+
"version": "0.3.2-next.65+622c8dc",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@sd-jwt/crypto-nodejs": "0.3.2-next.
|
|
39
|
+
"@sd-jwt/crypto-nodejs": "0.3.2-next.65+622c8dc"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@sd-jwt/decode": "0.3.2-next.
|
|
43
|
-
"@sd-jwt/types": "0.3.2-next.
|
|
44
|
-
"@sd-jwt/utils": "0.3.2-next.
|
|
42
|
+
"@sd-jwt/decode": "0.3.2-next.65+622c8dc",
|
|
43
|
+
"@sd-jwt/types": "0.3.2-next.65+622c8dc",
|
|
44
|
+
"@sd-jwt/utils": "0.3.2-next.65+622c8dc"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"esm"
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "622c8dc2001c4ca6cc3e6da75f7516d4c70a73db"
|
|
63
63
|
}
|
package/src/sdjwt.ts
CHANGED
|
@@ -250,7 +250,23 @@ export const pack = async <T extends Record<string, unknown>>(
|
|
|
250
250
|
const claim = recursivePackedClaims[i]
|
|
251
251
|
? recursivePackedClaims[i]
|
|
252
252
|
: claims[i];
|
|
253
|
-
|
|
253
|
+
/** This part is set discloure for array items.
|
|
254
|
+
* The example of disclosureFrame of an Array is
|
|
255
|
+
*
|
|
256
|
+
* const claims = {
|
|
257
|
+
* array: ['a', 'b', 'c']
|
|
258
|
+
* }
|
|
259
|
+
*
|
|
260
|
+
* diclosureFrame: DisclosureFrame<typeof claims> = {
|
|
261
|
+
* array: {
|
|
262
|
+
* _sd: [0, 2]
|
|
263
|
+
* }
|
|
264
|
+
* }
|
|
265
|
+
*
|
|
266
|
+
* It means that we want to disclose the first and the third item of the array
|
|
267
|
+
*
|
|
268
|
+
* So If the index `i` is in the disclosure list(sd), then we create a disclosure for the claim
|
|
269
|
+
*/
|
|
254
270
|
// @ts-ignore
|
|
255
271
|
if (sd.includes(i)) {
|
|
256
272
|
const salt = await saltGenerator(16);
|