@sd-jwt/core 0.3.2-next.76 → 0.3.2-next.94
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 +1 -38
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -1
- package/dist/index.mjs +5 -3
- package/package.json +6 -6
- package/src/index.ts +16 -4
- package/src/test/index.spec.ts +100 -14
- package/test/app-e2e.spec.ts +7 -6
package/README.md
CHANGED
|
@@ -32,44 +32,7 @@ Ensure you have Node.js installed as a prerequisite.
|
|
|
32
32
|
|
|
33
33
|
### Usage
|
|
34
34
|
|
|
35
|
-
|
|
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)
|
|
35
|
+
This library can not be used on it's own, it is a dependency for other implementations like `@sd-jwt/sd-jwt-vc`.
|
|
73
36
|
|
|
74
37
|
### Dependencies
|
|
75
38
|
|
package/dist/index.d.mts
CHANGED
|
@@ -66,16 +66,19 @@ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFra
|
|
|
66
66
|
|
|
67
67
|
declare const createDecoy: (hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<string>;
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
type SdJwtPayload = Record<string, unknown>;
|
|
70
|
+
declare abstract class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
71
|
+
protected abstract type: string;
|
|
70
72
|
static DEFAULT_hashAlg: string;
|
|
71
73
|
private userConfig;
|
|
72
74
|
constructor(userConfig?: SDJWTConfig);
|
|
73
75
|
private createKBJwt;
|
|
74
76
|
private SignJwt;
|
|
75
77
|
private VerifyJwt;
|
|
76
|
-
issue<Payload extends
|
|
78
|
+
issue<Payload extends ExtendedPayload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
77
79
|
header?: object;
|
|
78
80
|
}): Promise<SDJWTCompact>;
|
|
81
|
+
protected abstract validateReservedFields<T extends ExtendedPayload>(disclosureFrame: DisclosureFrame<T>): void;
|
|
79
82
|
present(encodedSDJwt: string, presentationKeys?: string[], options?: {
|
|
80
83
|
kb?: KBOptions;
|
|
81
84
|
}): Promise<SDJWTCompact>;
|
|
@@ -104,4 +107,4 @@ declare class SDJwtInstance {
|
|
|
104
107
|
getClaims(endcodedSDJwt: SDJWTCompact): Promise<unknown>;
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
export { Jwt, type JwtData, KBJwt, SDJwt, type SDJwtData, SDJwtInstance, createDecoy, listKeys, pack };
|
|
110
|
+
export { Jwt, type JwtData, KBJwt, SDJwt, type SDJwtData, SDJwtInstance, type SdJwtPayload, createDecoy, listKeys, pack };
|
package/dist/index.d.ts
CHANGED
|
@@ -66,16 +66,19 @@ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFra
|
|
|
66
66
|
|
|
67
67
|
declare const createDecoy: (hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<string>;
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
type SdJwtPayload = Record<string, unknown>;
|
|
70
|
+
declare abstract class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
71
|
+
protected abstract type: string;
|
|
70
72
|
static DEFAULT_hashAlg: string;
|
|
71
73
|
private userConfig;
|
|
72
74
|
constructor(userConfig?: SDJWTConfig);
|
|
73
75
|
private createKBJwt;
|
|
74
76
|
private SignJwt;
|
|
75
77
|
private VerifyJwt;
|
|
76
|
-
issue<Payload extends
|
|
78
|
+
issue<Payload extends ExtendedPayload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
77
79
|
header?: object;
|
|
78
80
|
}): Promise<SDJWTCompact>;
|
|
81
|
+
protected abstract validateReservedFields<T extends ExtendedPayload>(disclosureFrame: DisclosureFrame<T>): void;
|
|
79
82
|
present(encodedSDJwt: string, presentationKeys?: string[], options?: {
|
|
80
83
|
kb?: KBOptions;
|
|
81
84
|
}): Promise<SDJWTCompact>;
|
|
@@ -104,4 +107,4 @@ declare class SDJwtInstance {
|
|
|
104
107
|
getClaims(endcodedSDJwt: SDJWTCompact): Promise<unknown>;
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
export { Jwt, type JwtData, KBJwt, SDJwt, type SDJwtData, SDJwtInstance, createDecoy, listKeys, pack };
|
|
110
|
+
export { Jwt, type JwtData, KBJwt, SDJwt, type SDJwtData, SDJwtInstance, type SdJwtPayload, createDecoy, listKeys, pack };
|
package/dist/index.js
CHANGED
|
@@ -460,6 +460,9 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
460
460
|
if (!this.userConfig.signAlg) {
|
|
461
461
|
throw new import_utils5.SDJWTException("sign alogrithm not specified");
|
|
462
462
|
}
|
|
463
|
+
if (disclosureFrame) {
|
|
464
|
+
this.validateReservedFields(disclosureFrame);
|
|
465
|
+
}
|
|
463
466
|
const hasher = this.userConfig.hasher;
|
|
464
467
|
const hashAlg = (_a = this.userConfig.hashAlg) != null ? _a : _SDJwtInstance.DEFAULT_hashAlg;
|
|
465
468
|
const { packedClaims, disclosures } = yield pack(
|
|
@@ -470,7 +473,7 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
470
473
|
);
|
|
471
474
|
const alg = this.userConfig.signAlg;
|
|
472
475
|
const OptionHeader = (_b = options == null ? void 0 : options.header) != null ? _b : {};
|
|
473
|
-
const CustomHeader = this.userConfig.omitTyp ? OptionHeader : __spreadValues({ typ:
|
|
476
|
+
const CustomHeader = this.userConfig.omitTyp ? OptionHeader : __spreadValues({ typ: this.type }, OptionHeader);
|
|
474
477
|
const header = __spreadProps(__spreadValues({}, CustomHeader), { alg });
|
|
475
478
|
const jwt = new Jwt({
|
|
476
479
|
header,
|
package/dist/index.mjs
CHANGED
|
@@ -381,8 +381,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
|
|
|
381
381
|
|
|
382
382
|
// src/index.ts
|
|
383
383
|
import {
|
|
384
|
-
KB_JWT_TYP as KB_JWT_TYP2
|
|
385
|
-
SD_JWT_TYP
|
|
384
|
+
KB_JWT_TYP as KB_JWT_TYP2
|
|
386
385
|
} from "@sd-jwt/types";
|
|
387
386
|
import { getSDAlgAndPayload as getSDAlgAndPayload2 } from "@sd-jwt/decode";
|
|
388
387
|
var _SDJwtInstance = class _SDJwtInstance {
|
|
@@ -441,6 +440,9 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
441
440
|
if (!this.userConfig.signAlg) {
|
|
442
441
|
throw new SDJWTException4("sign alogrithm not specified");
|
|
443
442
|
}
|
|
443
|
+
if (disclosureFrame) {
|
|
444
|
+
this.validateReservedFields(disclosureFrame);
|
|
445
|
+
}
|
|
444
446
|
const hasher = this.userConfig.hasher;
|
|
445
447
|
const hashAlg = (_a = this.userConfig.hashAlg) != null ? _a : _SDJwtInstance.DEFAULT_hashAlg;
|
|
446
448
|
const { packedClaims, disclosures } = yield pack(
|
|
@@ -451,7 +453,7 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
451
453
|
);
|
|
452
454
|
const alg = this.userConfig.signAlg;
|
|
453
455
|
const OptionHeader = (_b = options == null ? void 0 : options.header) != null ? _b : {};
|
|
454
|
-
const CustomHeader = this.userConfig.omitTyp ? OptionHeader : __spreadValues({ typ:
|
|
456
|
+
const CustomHeader = this.userConfig.omitTyp ? OptionHeader : __spreadValues({ typ: this.type }, OptionHeader);
|
|
455
457
|
const header = __spreadProps(__spreadValues({}, CustomHeader), { alg });
|
|
456
458
|
const jwt = new Jwt({
|
|
457
459
|
header,
|
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.94+32af6cf",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@sd-jwt/crypto-nodejs": "0.3.2-next.
|
|
42
|
+
"@sd-jwt/crypto-nodejs": "0.3.2-next.94+32af6cf"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@sd-jwt/decode": "0.3.2-next.
|
|
46
|
-
"@sd-jwt/types": "0.3.2-next.
|
|
47
|
-
"@sd-jwt/utils": "0.3.2-next.
|
|
45
|
+
"@sd-jwt/decode": "0.3.2-next.94+32af6cf",
|
|
46
|
+
"@sd-jwt/types": "0.3.2-next.94+32af6cf",
|
|
47
|
+
"@sd-jwt/utils": "0.3.2-next.94+32af6cf"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"esm"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "32af6cfa150fceb440fc9225bcaf2791a6aeee90"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
KB_JWT_TYP,
|
|
10
10
|
SDJWTCompact,
|
|
11
11
|
SDJWTConfig,
|
|
12
|
-
SD_JWT_TYP,
|
|
13
12
|
} from '@sd-jwt/types';
|
|
14
13
|
import { getSDAlgAndPayload } from '@sd-jwt/decode';
|
|
15
14
|
|
|
@@ -18,7 +17,12 @@ export * from './kbjwt';
|
|
|
18
17
|
export * from './jwt';
|
|
19
18
|
export * from './decoy';
|
|
20
19
|
|
|
21
|
-
export
|
|
20
|
+
export type SdJwtPayload = Record<string, unknown>;
|
|
21
|
+
|
|
22
|
+
export abstract class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
23
|
+
//header type
|
|
24
|
+
protected abstract type: string;
|
|
25
|
+
|
|
22
26
|
public static DEFAULT_hashAlg = 'sha-256';
|
|
23
27
|
|
|
24
28
|
private userConfig: SDJWTConfig = {};
|
|
@@ -68,7 +72,7 @@ export class SDJwtInstance {
|
|
|
68
72
|
return jwt.verify(this.userConfig.verifier);
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
public async issue<Payload extends
|
|
75
|
+
public async issue<Payload extends ExtendedPayload>(
|
|
72
76
|
payload: Payload,
|
|
73
77
|
disclosureFrame?: DisclosureFrame<Payload>,
|
|
74
78
|
options?: {
|
|
@@ -87,6 +91,10 @@ export class SDJwtInstance {
|
|
|
87
91
|
throw new SDJWTException('sign alogrithm not specified');
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
if (disclosureFrame) {
|
|
95
|
+
this.validateReservedFields<Payload>(disclosureFrame);
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
const hasher = this.userConfig.hasher;
|
|
91
99
|
const hashAlg = this.userConfig.hashAlg ?? SDJwtInstance.DEFAULT_hashAlg;
|
|
92
100
|
|
|
@@ -100,7 +108,7 @@ export class SDJwtInstance {
|
|
|
100
108
|
const OptionHeader = options?.header ?? {};
|
|
101
109
|
const CustomHeader = this.userConfig.omitTyp
|
|
102
110
|
? OptionHeader
|
|
103
|
-
: { typ:
|
|
111
|
+
: { typ: this.type, ...OptionHeader };
|
|
104
112
|
const header = { ...CustomHeader, alg };
|
|
105
113
|
const jwt = new Jwt({
|
|
106
114
|
header,
|
|
@@ -119,6 +127,10 @@ export class SDJwtInstance {
|
|
|
119
127
|
return sdJwt.encodeSDJwt();
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
protected abstract validateReservedFields<T extends ExtendedPayload>(
|
|
131
|
+
disclosureFrame: DisclosureFrame<T>,
|
|
132
|
+
): void;
|
|
133
|
+
|
|
122
134
|
public async present(
|
|
123
135
|
encodedSDJwt: string,
|
|
124
136
|
presentationKeys?: string[],
|
package/src/test/index.spec.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { SDJwtInstance } from '../index';
|
|
2
|
-
import { Signer, Verifier } from '@sd-jwt/types';
|
|
1
|
+
import { SDJwtInstance, SdJwtPayload } from '../index';
|
|
2
|
+
import { DisclosureFrame, Signer, Verifier } from '@sd-jwt/types';
|
|
3
3
|
import Crypto from 'node:crypto';
|
|
4
4
|
import { describe, expect, test } from 'vitest';
|
|
5
5
|
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
6
6
|
|
|
7
|
+
export class TestInstance extends SDJwtInstance<SdJwtPayload> {
|
|
8
|
+
protected type = 'sd-jwt';
|
|
9
|
+
|
|
10
|
+
protected validateReservedFields(
|
|
11
|
+
disclosureFrame: DisclosureFrame<SdJwtPayload>,
|
|
12
|
+
): void {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
export const createSignerVerifier = () => {
|
|
8
18
|
const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
|
|
9
19
|
const signer: Signer = async (data: string) => {
|
|
@@ -23,13 +33,13 @@ export const createSignerVerifier = () => {
|
|
|
23
33
|
|
|
24
34
|
describe('index', () => {
|
|
25
35
|
test('create', async () => {
|
|
26
|
-
const sdjwt = new
|
|
36
|
+
const sdjwt = new TestInstance();
|
|
27
37
|
expect(sdjwt).toBeDefined();
|
|
28
38
|
});
|
|
29
39
|
|
|
30
40
|
test('kbJwt', async () => {
|
|
31
41
|
const { signer, verifier } = createSignerVerifier();
|
|
32
|
-
const sdjwt = new
|
|
42
|
+
const sdjwt = new TestInstance({
|
|
33
43
|
signer,
|
|
34
44
|
signAlg: 'EdDSA',
|
|
35
45
|
verifier,
|
|
@@ -41,6 +51,9 @@ describe('index', () => {
|
|
|
41
51
|
const credential = await sdjwt.issue(
|
|
42
52
|
{
|
|
43
53
|
foo: 'bar',
|
|
54
|
+
iss: 'Issuer',
|
|
55
|
+
iat: new Date().getTime(),
|
|
56
|
+
vct: '',
|
|
44
57
|
},
|
|
45
58
|
{
|
|
46
59
|
_sd: ['foo'],
|
|
@@ -64,7 +77,7 @@ describe('index', () => {
|
|
|
64
77
|
|
|
65
78
|
test('issue', async () => {
|
|
66
79
|
const { signer, verifier } = createSignerVerifier();
|
|
67
|
-
const sdjwt = new
|
|
80
|
+
const sdjwt = new TestInstance({
|
|
68
81
|
signer,
|
|
69
82
|
signAlg: 'EdDSA',
|
|
70
83
|
verifier,
|
|
@@ -74,6 +87,9 @@ describe('index', () => {
|
|
|
74
87
|
const credential = await sdjwt.issue(
|
|
75
88
|
{
|
|
76
89
|
foo: 'bar',
|
|
90
|
+
iss: 'Issuer',
|
|
91
|
+
iat: new Date().getTime(),
|
|
92
|
+
vct: '',
|
|
77
93
|
},
|
|
78
94
|
{
|
|
79
95
|
_sd: ['foo'],
|
|
@@ -95,7 +111,7 @@ describe('index', () => {
|
|
|
95
111
|
);
|
|
96
112
|
};
|
|
97
113
|
|
|
98
|
-
const sdjwt = new
|
|
114
|
+
const sdjwt = new TestInstance({
|
|
99
115
|
signer,
|
|
100
116
|
signAlg: 'EdDSA',
|
|
101
117
|
verifier: failedverifier,
|
|
@@ -106,6 +122,9 @@ describe('index', () => {
|
|
|
106
122
|
const credential = await sdjwt.issue(
|
|
107
123
|
{
|
|
108
124
|
foo: 'bar',
|
|
125
|
+
iss: 'Issuer',
|
|
126
|
+
iat: new Date().getTime(),
|
|
127
|
+
vct: '',
|
|
109
128
|
},
|
|
110
129
|
{
|
|
111
130
|
_sd: ['foo'],
|
|
@@ -130,7 +149,7 @@ describe('index', () => {
|
|
|
130
149
|
Buffer.from(sig, 'base64url'),
|
|
131
150
|
);
|
|
132
151
|
};
|
|
133
|
-
const sdjwt = new
|
|
152
|
+
const sdjwt = new TestInstance({
|
|
134
153
|
signer,
|
|
135
154
|
signAlg: 'EdDSA',
|
|
136
155
|
verifier,
|
|
@@ -144,6 +163,9 @@ describe('index', () => {
|
|
|
144
163
|
const credential = await sdjwt.issue(
|
|
145
164
|
{
|
|
146
165
|
foo: 'bar',
|
|
166
|
+
iss: 'Issuer',
|
|
167
|
+
iat: new Date().getTime(),
|
|
168
|
+
vct: '',
|
|
147
169
|
},
|
|
148
170
|
{
|
|
149
171
|
_sd: ['foo'],
|
|
@@ -169,7 +191,7 @@ describe('index', () => {
|
|
|
169
191
|
|
|
170
192
|
test('verify with kbJwt', async () => {
|
|
171
193
|
const { signer, verifier } = createSignerVerifier();
|
|
172
|
-
const sdjwt = new
|
|
194
|
+
const sdjwt = new TestInstance({
|
|
173
195
|
signer,
|
|
174
196
|
signAlg: 'EdDSA',
|
|
175
197
|
verifier,
|
|
@@ -183,6 +205,9 @@ describe('index', () => {
|
|
|
183
205
|
const credential = await sdjwt.issue(
|
|
184
206
|
{
|
|
185
207
|
foo: 'bar',
|
|
208
|
+
iss: 'Issuer',
|
|
209
|
+
iat: new Date().getTime(),
|
|
210
|
+
vct: '',
|
|
186
211
|
},
|
|
187
212
|
{
|
|
188
213
|
_sd: ['foo'],
|
|
@@ -204,11 +229,14 @@ describe('index', () => {
|
|
|
204
229
|
});
|
|
205
230
|
|
|
206
231
|
test('Hasher not found', async () => {
|
|
207
|
-
const sdjwt = new
|
|
232
|
+
const sdjwt = new TestInstance({});
|
|
208
233
|
try {
|
|
209
234
|
const credential = await sdjwt.issue(
|
|
210
235
|
{
|
|
211
236
|
foo: 'bar',
|
|
237
|
+
iss: 'Issuer',
|
|
238
|
+
iat: new Date().getTime(),
|
|
239
|
+
vct: '',
|
|
212
240
|
},
|
|
213
241
|
{
|
|
214
242
|
_sd: ['foo'],
|
|
@@ -222,13 +250,16 @@ describe('index', () => {
|
|
|
222
250
|
});
|
|
223
251
|
|
|
224
252
|
test('SaltGenerator not found', async () => {
|
|
225
|
-
const sdjwt = new
|
|
253
|
+
const sdjwt = new TestInstance({
|
|
226
254
|
hasher: digest,
|
|
227
255
|
});
|
|
228
256
|
try {
|
|
229
257
|
const credential = await sdjwt.issue(
|
|
230
258
|
{
|
|
231
259
|
foo: 'bar',
|
|
260
|
+
iss: 'Issuer',
|
|
261
|
+
iat: new Date().getTime(),
|
|
262
|
+
vct: '',
|
|
232
263
|
},
|
|
233
264
|
{
|
|
234
265
|
_sd: ['foo'],
|
|
@@ -242,7 +273,7 @@ describe('index', () => {
|
|
|
242
273
|
});
|
|
243
274
|
|
|
244
275
|
test('Signer not found', async () => {
|
|
245
|
-
const sdjwt = new
|
|
276
|
+
const sdjwt = new TestInstance({
|
|
246
277
|
hasher: digest,
|
|
247
278
|
saltGenerator: generateSalt,
|
|
248
279
|
});
|
|
@@ -250,6 +281,9 @@ describe('index', () => {
|
|
|
250
281
|
const credential = await sdjwt.issue(
|
|
251
282
|
{
|
|
252
283
|
foo: 'bar',
|
|
284
|
+
iss: 'Issuer',
|
|
285
|
+
iat: new Date().getTime(),
|
|
286
|
+
vct: '',
|
|
253
287
|
},
|
|
254
288
|
{
|
|
255
289
|
_sd: ['foo'],
|
|
@@ -264,7 +298,7 @@ describe('index', () => {
|
|
|
264
298
|
|
|
265
299
|
test('Verifier not found', async () => {
|
|
266
300
|
const { signer, verifier } = createSignerVerifier();
|
|
267
|
-
const sdjwt = new
|
|
301
|
+
const sdjwt = new TestInstance({
|
|
268
302
|
signer,
|
|
269
303
|
hasher: digest,
|
|
270
304
|
saltGenerator: generateSalt,
|
|
@@ -277,6 +311,9 @@ describe('index', () => {
|
|
|
277
311
|
const credential = await sdjwt.issue(
|
|
278
312
|
{
|
|
279
313
|
foo: 'bar',
|
|
314
|
+
iss: 'Issuer',
|
|
315
|
+
iat: new Date().getTime(),
|
|
316
|
+
vct: '',
|
|
280
317
|
},
|
|
281
318
|
{
|
|
282
319
|
_sd: ['foo'],
|
|
@@ -301,7 +338,7 @@ describe('index', () => {
|
|
|
301
338
|
|
|
302
339
|
test('kbSigner not found', async () => {
|
|
303
340
|
const { signer, verifier } = createSignerVerifier();
|
|
304
|
-
const sdjwt = new
|
|
341
|
+
const sdjwt = new TestInstance({
|
|
305
342
|
signer,
|
|
306
343
|
verifier,
|
|
307
344
|
hasher: digest,
|
|
@@ -314,6 +351,9 @@ describe('index', () => {
|
|
|
314
351
|
const credential = await sdjwt.issue(
|
|
315
352
|
{
|
|
316
353
|
foo: 'bar',
|
|
354
|
+
iss: 'Issuer',
|
|
355
|
+
iat: new Date().getTime(),
|
|
356
|
+
vct: '',
|
|
317
357
|
},
|
|
318
358
|
{
|
|
319
359
|
_sd: ['foo'],
|
|
@@ -336,7 +376,7 @@ describe('index', () => {
|
|
|
336
376
|
|
|
337
377
|
test('kbVerifier not found', async () => {
|
|
338
378
|
const { signer, verifier } = createSignerVerifier();
|
|
339
|
-
const sdjwt = new
|
|
379
|
+
const sdjwt = new TestInstance({
|
|
340
380
|
signer,
|
|
341
381
|
verifier,
|
|
342
382
|
hasher: digest,
|
|
@@ -349,6 +389,9 @@ describe('index', () => {
|
|
|
349
389
|
const credential = await sdjwt.issue(
|
|
350
390
|
{
|
|
351
391
|
foo: 'bar',
|
|
392
|
+
iss: 'Issuer',
|
|
393
|
+
iat: new Date().getTime(),
|
|
394
|
+
vct: '',
|
|
352
395
|
},
|
|
353
396
|
{
|
|
354
397
|
_sd: ['foo'],
|
|
@@ -370,4 +413,47 @@ describe('index', () => {
|
|
|
370
413
|
expect(e).toBeDefined();
|
|
371
414
|
}
|
|
372
415
|
});
|
|
416
|
+
|
|
417
|
+
test('kbSignAlg not found', async () => {
|
|
418
|
+
const { signer, verifier } = createSignerVerifier();
|
|
419
|
+
const sdjwt = new TestInstance({
|
|
420
|
+
signer,
|
|
421
|
+
verifier,
|
|
422
|
+
hasher: digest,
|
|
423
|
+
saltGenerator: generateSalt,
|
|
424
|
+
kbSigner: signer,
|
|
425
|
+
signAlg: 'EdDSA',
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const credential = await sdjwt.issue(
|
|
429
|
+
{
|
|
430
|
+
foo: 'bar',
|
|
431
|
+
iss: 'Issuer',
|
|
432
|
+
iat: new Date().getTime(),
|
|
433
|
+
vct: '',
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
_sd: ['foo'],
|
|
437
|
+
},
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
const presentation = sdjwt.present(credential, ['foo'], {
|
|
441
|
+
kb: {
|
|
442
|
+
payload: {
|
|
443
|
+
sd_hash: 'sha-256',
|
|
444
|
+
aud: '1',
|
|
445
|
+
iat: 1,
|
|
446
|
+
nonce: '342',
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
expect(presentation).rejects.toThrow(
|
|
451
|
+
'Key Binding sign algorithm not specified',
|
|
452
|
+
);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
test('hasher is not found', () => {
|
|
456
|
+
const sdjwt = new TestInstance({});
|
|
457
|
+
expect(sdjwt.keys('')).rejects.toThrow('Hasher not found');
|
|
458
|
+
});
|
|
373
459
|
});
|
package/test/app-e2e.spec.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Crypto from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { DisclosureFrame, Signer, Verifier } from '@sd-jwt/types';
|
|
2
|
+
import { SdJwtPayload } from '../src';
|
|
3
|
+
import { DisclosureFrame, SD, Signer, Verifier } from '@sd-jwt/types';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
8
|
+
import { TestInstance } from '../src/test/index.spec';
|
|
8
9
|
|
|
9
10
|
export const createSignerVerifier = () => {
|
|
10
11
|
const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
|
|
@@ -26,7 +27,7 @@ export const createSignerVerifier = () => {
|
|
|
26
27
|
describe('App', () => {
|
|
27
28
|
test('Example', async () => {
|
|
28
29
|
const { signer, verifier } = createSignerVerifier();
|
|
29
|
-
const sdjwt = new
|
|
30
|
+
const sdjwt = new TestInstance({
|
|
30
31
|
signer,
|
|
31
32
|
signAlg: 'EdDSA',
|
|
32
33
|
verifier,
|
|
@@ -192,7 +193,7 @@ describe('App', () => {
|
|
|
192
193
|
async function JSONtest(filename: string) {
|
|
193
194
|
const test = loadTestJsonFile(filename);
|
|
194
195
|
const { signer, verifier } = createSignerVerifier();
|
|
195
|
-
const sdjwt = new
|
|
196
|
+
const sdjwt = new TestInstance({
|
|
196
197
|
signer,
|
|
197
198
|
signAlg: 'EdDSA',
|
|
198
199
|
verifier,
|
|
@@ -234,8 +235,8 @@ async function JSONtest(filename: string) {
|
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
type TestJson = {
|
|
237
|
-
claims:
|
|
238
|
-
disclosureFrame: DisclosureFrame<
|
|
238
|
+
claims: SdJwtPayload;
|
|
239
|
+
disclosureFrame: DisclosureFrame<SdJwtPayload>;
|
|
239
240
|
presentationKeys: string[];
|
|
240
241
|
presenatedClaims: object;
|
|
241
242
|
requiredClaimKeys: string[];
|