@sd-jwt/core 0.19.1-next.1 → 0.19.1-next.11
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 +68 -5
- package/dist/index.d.mts +364 -16
- package/dist/index.d.ts +364 -16
- package/dist/index.js +803 -148
- package/dist/index.mjs +744 -133
- package/package.json +4 -7
- package/src/decode/decode.ts +366 -0
- package/src/decode/index.ts +1 -0
- package/src/decoy.ts +2 -2
- package/src/flattenJSON.ts +3 -3
- package/src/generalJSON.ts +3 -3
- package/src/index.ts +230 -14
- package/src/jwt.ts +10 -15
- package/src/kbjwt.ts +19 -15
- package/src/present/index.ts +1 -0
- package/src/present/present.ts +210 -0
- package/src/sdjwt.ts +11 -10
- package/src/test/decode/decode.spec.ts +202 -0
- package/src/test/decoy.spec.ts +2 -2
- package/src/test/generalJSON.spec.ts +1 -1
- package/src/test/index.spec.ts +288 -2
- package/src/test/jwt.spec.ts +7 -13
- package/src/test/kbjwt.spec.ts +216 -5
- package/src/test/present/present.spec.ts +305 -0
- package/src/test/sdjwt.spec.ts +4 -4
- package/src/test/types/type.spec.ts +88 -0
- package/src/test/utils/base64url.spec.ts +33 -0
- package/src/test/utils/disclosure.spec.ts +170 -0
- package/src/test/utils/error.spec.ts +15 -0
- package/src/types/index.ts +2 -0
- package/src/types/type.ts +249 -0
- package/src/types/verification-error.ts +55 -0
- package/src/utils/base64url.ts +6 -0
- package/src/utils/disclosure.ts +98 -0
- package/src/utils/error.ts +25 -0
- package/src/utils/index.ts +3 -0
- package/test/app-e2e.spec.ts +8 -8
- package/test/rfc9901-validation.spec.ts +150 -0
- package/CHANGELOG.md +0 -240
package/README.md
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
### About
|
|
11
11
|
|
|
12
|
-
Core library for
|
|
12
|
+
Core library for [Selective Disclosure for JWTs (SD-JWT) — RFC 9901](https://www.rfc-editor.org/rfc/rfc9901.html).
|
|
13
|
+
|
|
14
|
+
This package provides types, utilities, encoding/decoding, presentation, and the main `SDJwtInstance` class — everything needed to issue, present, and verify SD-JWTs.
|
|
13
15
|
|
|
14
16
|
Check the detail description in our github [repo](https://github.com/openwallet-foundation/sd-jwt-js).
|
|
15
17
|
|
|
@@ -37,7 +39,68 @@ If you want to use the pure sd-jwt class or implement your own sd-jwt credential
|
|
|
37
39
|
|
|
38
40
|
### Dependencies
|
|
39
41
|
|
|
40
|
-
- @
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
- [@owf/identity-common](https://www.npmjs.com/package/@owf/identity-common)
|
|
43
|
+
|
|
44
|
+
### Verification
|
|
45
|
+
|
|
46
|
+
The library provides two verification approaches:
|
|
47
|
+
|
|
48
|
+
#### Standard Verification (Fail-Fast)
|
|
49
|
+
|
|
50
|
+
The `verify()` method throws an error immediately when the first validation failure is encountered:
|
|
51
|
+
|
|
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
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Safe Verification (Collect All Errors)
|
|
62
|
+
|
|
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:
|
|
64
|
+
|
|
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
|
+
```
|
|
87
|
+
|
|
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 |
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,224 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { base64UrlToUint8Array, base64urlDecode, base64urlEncode, uint8ArrayToBase64Url } from '@owf/identity-common';
|
|
2
|
+
|
|
3
|
+
declare const SD_SEPARATOR = "~";
|
|
4
|
+
declare const SD_LIST_KEY = "...";
|
|
5
|
+
declare const SD_DIGEST = "_sd";
|
|
6
|
+
declare const SD_DECOY = "_sd_decoy";
|
|
7
|
+
declare const KB_JWT_TYP = "kb+jwt";
|
|
8
|
+
type SDJWTCompact = string;
|
|
9
|
+
type Base64urlString = string;
|
|
10
|
+
type DisclosureData<T> = [string, string, T] | [string, T];
|
|
11
|
+
declare const IANA_HASH_ALGORITHMS: readonly ["sha-256", "sha-256-128", "sha-256-120", "sha-256-96", "sha-256-64", "sha-256-32", "sha-384", "sha-512", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "blake2s-256", "blake2b-256", "blake2b-512", "k12-256", "k12-512"];
|
|
12
|
+
type HashAlgorithm = (typeof IANA_HASH_ALGORITHMS)[number];
|
|
13
|
+
type SDJWTConfig<T = unknown> = {
|
|
14
|
+
omitTyp?: boolean;
|
|
15
|
+
hasher?: Hasher;
|
|
16
|
+
hashAlg?: HashAlgorithm;
|
|
17
|
+
saltGenerator?: SaltGenerator;
|
|
18
|
+
signer?: Signer;
|
|
19
|
+
signAlg?: string;
|
|
20
|
+
verifier?: Verifier<T>;
|
|
21
|
+
kbSigner?: Signer;
|
|
22
|
+
kbSignAlg?: string;
|
|
23
|
+
kbVerifier?: KbVerifier;
|
|
24
|
+
};
|
|
25
|
+
type kbHeader = {
|
|
26
|
+
typ: 'kb+jwt';
|
|
27
|
+
alg: string;
|
|
28
|
+
};
|
|
29
|
+
type kbPayload = {
|
|
30
|
+
iat: number;
|
|
31
|
+
aud: string;
|
|
32
|
+
nonce: string;
|
|
33
|
+
sd_hash: string;
|
|
34
|
+
};
|
|
35
|
+
type KBOptions = {
|
|
36
|
+
payload: Omit<kbPayload, 'sd_hash'>;
|
|
37
|
+
};
|
|
38
|
+
interface RsaOtherPrimesInfo {
|
|
39
|
+
d?: string;
|
|
40
|
+
r?: string;
|
|
41
|
+
t?: string;
|
|
42
|
+
}
|
|
43
|
+
interface JsonWebKey {
|
|
44
|
+
alg?: string;
|
|
45
|
+
crv?: string;
|
|
46
|
+
d?: string;
|
|
47
|
+
dp?: string;
|
|
48
|
+
dq?: string;
|
|
49
|
+
e?: string;
|
|
50
|
+
ext?: boolean;
|
|
51
|
+
k?: string;
|
|
52
|
+
key_ops?: string[];
|
|
53
|
+
kty?: string;
|
|
54
|
+
n?: string;
|
|
55
|
+
oth?: RsaOtherPrimesInfo[];
|
|
56
|
+
p?: string;
|
|
57
|
+
q?: string;
|
|
58
|
+
qi?: string;
|
|
59
|
+
use?: string;
|
|
60
|
+
x?: string;
|
|
61
|
+
y?: string;
|
|
62
|
+
}
|
|
63
|
+
interface JwtPayload {
|
|
64
|
+
cnf?: {
|
|
65
|
+
jwk: JsonWebKey;
|
|
66
|
+
};
|
|
67
|
+
exp?: number;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
type OrPromise<T> = T | Promise<T>;
|
|
71
|
+
type Signer = (data: string) => OrPromise<string>;
|
|
72
|
+
type Verifier<T = unknown> = (data: string, sig: string, options?: T) => OrPromise<boolean>;
|
|
73
|
+
type KbVerifier = (data: string, sig: string, payload: JwtPayload) => OrPromise<boolean>;
|
|
74
|
+
type Hasher = (data: string | ArrayBuffer, alg: string) => OrPromise<Uint8Array>;
|
|
75
|
+
type SaltGenerator = (length: number) => OrPromise<string>;
|
|
76
|
+
type HasherAndAlg = {
|
|
77
|
+
hasher: Hasher;
|
|
78
|
+
alg: string;
|
|
79
|
+
};
|
|
80
|
+
type SignerSync = (data: string) => string;
|
|
81
|
+
type VerifierSync = (data: string, sig: string) => boolean;
|
|
82
|
+
type HasherSync = (data: string, alg: string) => Uint8Array;
|
|
83
|
+
type SaltGeneratorSync = (length: number) => string;
|
|
84
|
+
type HasherAndAlgSync = {
|
|
85
|
+
hasher: HasherSync;
|
|
86
|
+
alg: string;
|
|
87
|
+
};
|
|
88
|
+
type NonNever<T> = {
|
|
89
|
+
[P in keyof T as T[P] extends never ? never : P]: T[P];
|
|
90
|
+
};
|
|
91
|
+
type SD<Payload> = {
|
|
92
|
+
[SD_DIGEST]?: Array<keyof Payload>;
|
|
93
|
+
};
|
|
94
|
+
type DECOY = {
|
|
95
|
+
[SD_DECOY]?: number;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* This is a disclosureFrame type that is used to represent the structure of what is being disclosed.
|
|
99
|
+
* DisclosureFrame is made from the payload type.
|
|
100
|
+
*
|
|
101
|
+
* For example, if the payload is
|
|
102
|
+
* {
|
|
103
|
+
* foo: 'bar',
|
|
104
|
+
* test: {
|
|
105
|
+
* zzz: 'yyy',
|
|
106
|
+
* }
|
|
107
|
+
* arr: ['1', '2', {a: 'b'}]
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* The disclosureFrame can be subset of:
|
|
111
|
+
* {
|
|
112
|
+
* _sd: ["foo", "test", "arr"],
|
|
113
|
+
* test: {
|
|
114
|
+
* _sd: ["zzz"],
|
|
115
|
+
* },
|
|
116
|
+
* arr: {
|
|
117
|
+
* _sd: ["0", "1", "2"],
|
|
118
|
+
* "2": {
|
|
119
|
+
* _sd: ["a"],
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* The disclosureFrame can be used with decoy.
|
|
125
|
+
* Decoy can be used like this:
|
|
126
|
+
* {
|
|
127
|
+
* ...
|
|
128
|
+
* _sd: ...
|
|
129
|
+
* _sd_decoy: 1 // number of decoy in this layer
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
*/
|
|
133
|
+
type Frame<Payload> = Payload extends Array<infer U> ? U extends object ? Record<number, Frame<U>> & SD<Payload> & DECOY : SD<Payload> & DECOY : Payload extends Record<string, unknown> ? NonNever<{
|
|
134
|
+
[K in keyof Payload]?: NonNullable<Payload[K]> extends object ? Frame<Payload[K]> : never;
|
|
135
|
+
} & SD<Payload> & DECOY> : SD<Payload> & DECOY;
|
|
136
|
+
/**
|
|
137
|
+
* This is a disclosureFrame type that is used to represent the structure of what is being disclosed.
|
|
138
|
+
*/
|
|
139
|
+
type Extensible = Record<string, unknown | boolean>;
|
|
140
|
+
type DisclosureFrame<T extends Extensible> = Frame<T>;
|
|
141
|
+
/**
|
|
142
|
+
* This is a presentationFrame type that is used to represent the structure of what is being presented.
|
|
143
|
+
* PresentationFrame is made from the payload type.
|
|
144
|
+
* const claims = {
|
|
145
|
+
firstname: 'John',
|
|
146
|
+
lastname: 'Doe',
|
|
147
|
+
ssn: '123-45-6789',
|
|
148
|
+
id: '1234',
|
|
149
|
+
data: {
|
|
150
|
+
firstname: 'John',
|
|
151
|
+
lastname: 'Doe',
|
|
152
|
+
ssn: '123-45-6789',
|
|
153
|
+
list: [{ r: 'd' }, 'b', 'c'],
|
|
154
|
+
list2: ['1', '2', '3'],
|
|
155
|
+
list3: ['1', null, 2],
|
|
156
|
+
},
|
|
157
|
+
data2: {
|
|
158
|
+
hi: 'bye',
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
Example of a presentationFrame:
|
|
163
|
+
const presentationFrame: PresentationFrame<typeof claims> = {
|
|
164
|
+
firstname: true,
|
|
165
|
+
lastname: true,
|
|
166
|
+
ssn: true,
|
|
167
|
+
id: 'true',
|
|
168
|
+
data: {
|
|
169
|
+
firstname: true,
|
|
170
|
+
list: {
|
|
171
|
+
1: true,
|
|
172
|
+
0: {
|
|
173
|
+
r: true,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
list2: {
|
|
177
|
+
1: true,
|
|
178
|
+
},
|
|
179
|
+
list3: true,
|
|
180
|
+
},
|
|
181
|
+
data2: true,
|
|
182
|
+
};
|
|
183
|
+
*/
|
|
184
|
+
type PFrame<Payload> = Payload extends Array<infer U> ? U extends object ? Record<number, PFrame<U> | boolean> | boolean : Record<number, boolean> | boolean : {
|
|
185
|
+
[K in keyof Payload]?: NonNullable<Payload[K]> extends object ? PFrame<Payload[K]> | boolean : boolean;
|
|
186
|
+
};
|
|
187
|
+
type PresentationFrame<T extends Extensible> = PFrame<T>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Error codes for SD-JWT verification errors.
|
|
191
|
+
*/
|
|
192
|
+
type VerificationErrorCode = 'HASHER_NOT_FOUND' | 'VERIFIER_NOT_FOUND' | 'INVALID_SD_JWT' | 'INVALID_JWT_FORMAT' | 'JWT_NOT_YET_VALID' | 'JWT_EXPIRED' | 'INVALID_JWT_SIGNATURE' | 'MISSING_REQUIRED_CLAIMS' | 'KEY_BINDING_JWT_MISSING' | 'KEY_BINDING_VERIFIER_NOT_FOUND' | 'KEY_BINDING_SIGNATURE_INVALID' | 'KEY_BINDING_SD_HASH_INVALID' | 'STATUS_VERIFICATION_FAILED' | 'STATUS_INVALID' | 'VCT_VERIFICATION_FAILED' | 'UNKNOWN_ERROR';
|
|
193
|
+
/**
|
|
194
|
+
* Represents a single verification error.
|
|
195
|
+
*/
|
|
196
|
+
type VerificationError = {
|
|
197
|
+
/**
|
|
198
|
+
* The error code identifying the type of error.
|
|
199
|
+
*/
|
|
200
|
+
code: VerificationErrorCode;
|
|
201
|
+
/**
|
|
202
|
+
* Human-readable error message.
|
|
203
|
+
*/
|
|
204
|
+
message: string;
|
|
205
|
+
/**
|
|
206
|
+
* Optional additional details about the error.
|
|
207
|
+
*/
|
|
208
|
+
details?: unknown;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Result type for safe verification that collects all errors.
|
|
212
|
+
*/
|
|
213
|
+
type SafeVerifyResult<T> = {
|
|
214
|
+
success: true;
|
|
215
|
+
data: T;
|
|
216
|
+
errors?: never;
|
|
217
|
+
} | {
|
|
218
|
+
success: false;
|
|
219
|
+
data?: never;
|
|
220
|
+
errors: VerificationError[];
|
|
221
|
+
};
|
|
4
222
|
|
|
5
223
|
type FlattenJSONData = {
|
|
6
224
|
jwtData: {
|
|
@@ -156,8 +374,13 @@ declare class Jwt<Header extends Record<string, unknown> = Record<string, unknow
|
|
|
156
374
|
declare class KBJwt<Header extends kbHeader = kbHeader, Payload extends kbPayload = kbPayload> extends Jwt<Header, Payload> {
|
|
157
375
|
verifyKB(values: {
|
|
158
376
|
verifier: KbVerifier;
|
|
159
|
-
payload:
|
|
377
|
+
payload: Record<string, unknown>;
|
|
160
378
|
nonce: string;
|
|
379
|
+
/**
|
|
380
|
+
* Options forwarded to the common JWT verification, e.g. currentDate and
|
|
381
|
+
* skewSeconds used to validate the iat, nbf and exp claims.
|
|
382
|
+
*/
|
|
383
|
+
options?: VerifierOptions;
|
|
161
384
|
}): Promise<{
|
|
162
385
|
payload: Payload;
|
|
163
386
|
header: Header;
|
|
@@ -165,6 +388,38 @@ declare class KBJwt<Header extends kbHeader = kbHeader, Payload extends kbPayloa
|
|
|
165
388
|
static fromKBEncode<Header extends kbHeader = kbHeader, Payload extends kbPayload = kbPayload>(encodedJwt: string): KBJwt<Header, Payload>;
|
|
166
389
|
}
|
|
167
390
|
|
|
391
|
+
declare class Disclosure<T = unknown> {
|
|
392
|
+
salt: string;
|
|
393
|
+
key?: string;
|
|
394
|
+
value: T;
|
|
395
|
+
_digest: string | undefined;
|
|
396
|
+
private _encoded;
|
|
397
|
+
constructor(data: DisclosureData<T>, _meta?: {
|
|
398
|
+
digest: string;
|
|
399
|
+
encoded: string;
|
|
400
|
+
});
|
|
401
|
+
static fromEncode<T>(s: string, hash: HasherAndAlg): Promise<Disclosure<T>>;
|
|
402
|
+
static fromEncodeSync<T>(s: string, hash: HasherAndAlgSync): Disclosure<T>;
|
|
403
|
+
static fromArray<T>(item: DisclosureData<T>, _meta?: {
|
|
404
|
+
digest: string;
|
|
405
|
+
encoded: string;
|
|
406
|
+
}): Disclosure<T>;
|
|
407
|
+
encode(): string;
|
|
408
|
+
decode(): DisclosureData<T>;
|
|
409
|
+
digest(hash: HasherAndAlg): Promise<string>;
|
|
410
|
+
digestSync(hash: HasherAndAlgSync): string;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
declare class SDJWTException extends Error {
|
|
414
|
+
details?: unknown;
|
|
415
|
+
constructor(message: string, details?: unknown);
|
|
416
|
+
getFullMessage(): string;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Narrows an unknown caught value to an Error instance.
|
|
420
|
+
*/
|
|
421
|
+
declare function ensureError(value: unknown): Error;
|
|
422
|
+
|
|
168
423
|
type SDJwtData<Header extends Record<string, unknown>, Payload extends Record<string, unknown>, KBHeader extends kbHeader = kbHeader, KBPayload extends kbPayload = kbPayload> = {
|
|
169
424
|
jwt?: Jwt<Header, Payload>;
|
|
170
425
|
disclosures?: Array<Disclosure>;
|
|
@@ -195,8 +450,85 @@ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFra
|
|
|
195
450
|
disclosures: Array<Disclosure>;
|
|
196
451
|
}>;
|
|
197
452
|
|
|
453
|
+
declare const decodeJwt: <H extends Record<string, unknown>, T extends Record<string, unknown>>(jwt: string) => {
|
|
454
|
+
header: H;
|
|
455
|
+
payload: T;
|
|
456
|
+
signature: string;
|
|
457
|
+
};
|
|
458
|
+
declare const splitSdJwt: (sdjwt: string) => {
|
|
459
|
+
jwt: string;
|
|
460
|
+
disclosures: string[];
|
|
461
|
+
kbJwt?: string;
|
|
462
|
+
};
|
|
463
|
+
declare const decodeSdJwt: (sdjwt: string, hasher: Hasher) => Promise<DecodedSDJwt>;
|
|
464
|
+
declare const decodeSdJwtSync: (sdjwt: string, hasher: HasherSync) => DecodedSDJwt;
|
|
465
|
+
declare const getClaims: <T = Record<string, unknown>>(rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: Hasher) => Promise<T>;
|
|
466
|
+
declare const getClaimsSync: <T = Record<string, unknown>>(rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: HasherSync) => T;
|
|
467
|
+
declare const unpackObj: (obj: unknown, map: Record<string, Disclosure>) => {
|
|
468
|
+
unpackedObj: unknown;
|
|
469
|
+
disclosureKeymap: Record<string, string>;
|
|
470
|
+
};
|
|
471
|
+
declare const createHashMapping: (disclosures: Array<Disclosure>, hash: HasherAndAlg) => Promise<Record<string, Disclosure<unknown>>>;
|
|
472
|
+
declare const createHashMappingSync: (disclosures: Array<Disclosure>, hash: HasherAndAlgSync) => Record<string, Disclosure<unknown>>;
|
|
473
|
+
declare const getSDAlgAndPayload: (SdJwtPayload: Record<string, unknown>) => {
|
|
474
|
+
_sd_alg: string;
|
|
475
|
+
payload: {
|
|
476
|
+
[x: string]: unknown;
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
declare const unpack: (SdJwtPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: Hasher) => Promise<{
|
|
480
|
+
unpackedObj: unknown;
|
|
481
|
+
disclosureKeymap: Record<string, string>;
|
|
482
|
+
}>;
|
|
483
|
+
declare const unpackSync: (SdJwtPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: HasherSync) => {
|
|
484
|
+
unpackedObj: unknown;
|
|
485
|
+
disclosureKeymap: Record<string, string>;
|
|
486
|
+
};
|
|
487
|
+
type DecodedSDJwt = {
|
|
488
|
+
jwt: {
|
|
489
|
+
header: Record<string, unknown>;
|
|
490
|
+
payload: Record<string, unknown>;
|
|
491
|
+
signature: string;
|
|
492
|
+
};
|
|
493
|
+
disclosures: Array<Disclosure>;
|
|
494
|
+
kbJwt?: {
|
|
495
|
+
header: Record<string, unknown>;
|
|
496
|
+
payload: Record<string, unknown>;
|
|
497
|
+
signature: string;
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
|
|
198
501
|
declare const createDecoy: (hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<string>;
|
|
199
502
|
|
|
503
|
+
declare const presentableKeys: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: Hasher) => Promise<string[]>;
|
|
504
|
+
declare const presentableKeysSync: (rawPayload: Record<string, unknown>, disclosures: Array<Disclosure>, hasher: HasherSync) => string[];
|
|
505
|
+
declare const present: <T extends Record<string, unknown>>(sdJwt: string, presentFrame: PresentationFrame<T>, hasher: Hasher) => Promise<string>;
|
|
506
|
+
declare const presentSync: <T extends Record<string, unknown>>(sdJwt: string, presentFrame: PresentationFrame<T>, hasher: HasherSync) => string;
|
|
507
|
+
/**
|
|
508
|
+
* Transform the object keys into an array of strings. We are not sorting the array in any way.
|
|
509
|
+
* @param obj The object to transform
|
|
510
|
+
* @param prefix The prefix to add to the keys
|
|
511
|
+
* @returns
|
|
512
|
+
*/
|
|
513
|
+
declare const transformPresentationFrame: (obj: PresentationFrame<Extensible>, prefix?: string) => string[];
|
|
514
|
+
type SerializedDisclosure = {
|
|
515
|
+
digest: string;
|
|
516
|
+
encoded: string;
|
|
517
|
+
salt: string;
|
|
518
|
+
key: string | undefined;
|
|
519
|
+
value: unknown;
|
|
520
|
+
};
|
|
521
|
+
declare const createHashMappingForSerializedDisclosure: (disclosures: SerializedDisclosure[]) => Record<string, Disclosure<unknown>>;
|
|
522
|
+
/**
|
|
523
|
+
* This function selects the serialized disclosures from the payload
|
|
524
|
+
* and array of serialized disclosure based on the presentation frame.
|
|
525
|
+
* If you want to know what is serialized disclosures, check type SerializedDisclosure.
|
|
526
|
+
* @param payload: Record<string, unknown>
|
|
527
|
+
* @param disclosures: SerializedDisclosure[]
|
|
528
|
+
* @param presentationFrame: PresentationFrame<T>
|
|
529
|
+
*/
|
|
530
|
+
declare const selectDisclosures: <T extends Record<string, unknown>>(payload: Record<string, unknown>, disclosures: SerializedDisclosure[], presentationFrame: PresentationFrame<T>) => SerializedDisclosure[];
|
|
531
|
+
|
|
200
532
|
type SdJwtPayload = Record<string, unknown>;
|
|
201
533
|
declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
|
|
202
534
|
protected type?: string;
|
|
@@ -219,17 +551,33 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
|
|
|
219
551
|
kb?: KBOptions;
|
|
220
552
|
}): Promise<SDJWTCompact>;
|
|
221
553
|
verify(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
|
|
222
|
-
payload:
|
|
554
|
+
payload: ExtendedPayload;
|
|
223
555
|
header: Record<string, unknown> | undefined;
|
|
224
556
|
kb?: undefined;
|
|
225
557
|
} | {
|
|
226
|
-
payload:
|
|
558
|
+
payload: ExtendedPayload;
|
|
227
559
|
header: Record<string, unknown> | undefined;
|
|
228
560
|
kb: {
|
|
229
|
-
payload:
|
|
230
|
-
header:
|
|
561
|
+
payload: kbPayload;
|
|
562
|
+
header: kbHeader;
|
|
231
563
|
};
|
|
232
564
|
}>;
|
|
565
|
+
/**
|
|
566
|
+
* Safe verification that collects all errors instead of failing fast.
|
|
567
|
+
* Returns a result object with either the verified data or an array of all errors.
|
|
568
|
+
*
|
|
569
|
+
* @param encodedSDJwt - The encoded SD-JWT to verify
|
|
570
|
+
* @param options - Verification options
|
|
571
|
+
* @returns A SafeVerifyResult containing either success data or collected errors
|
|
572
|
+
*/
|
|
573
|
+
safeVerify(encodedSDJwt: string, options?: T & VerifierOptions): Promise<SafeVerifyResult<{
|
|
574
|
+
payload: ExtendedPayload;
|
|
575
|
+
header: Record<string, unknown> | undefined;
|
|
576
|
+
kb?: {
|
|
577
|
+
payload: Record<string, unknown>;
|
|
578
|
+
header: Record<string, unknown>;
|
|
579
|
+
};
|
|
580
|
+
}>>;
|
|
233
581
|
private calculateSDHash;
|
|
234
582
|
/**
|
|
235
583
|
* This function is for validating the SD JWT
|
|
@@ -239,12 +587,12 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
|
|
|
239
587
|
* @returns
|
|
240
588
|
*/
|
|
241
589
|
validate(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
|
|
242
|
-
payload:
|
|
590
|
+
payload: ExtendedPayload;
|
|
243
591
|
header: Record<string, unknown> | undefined;
|
|
244
592
|
}>;
|
|
245
593
|
config(newConfig: SDJWTConfig): void;
|
|
246
594
|
encode(sdJwt: SDJwt): SDJWTCompact;
|
|
247
|
-
decode(endcodedSDJwt: SDJWTCompact): Promise<SDJwt<Record<string, unknown>, Record<string, unknown>,
|
|
595
|
+
decode(endcodedSDJwt: SDJWTCompact): Promise<SDJwt<Record<string, unknown>, Record<string, unknown>, kbHeader, kbPayload>>;
|
|
248
596
|
keys(endcodedSDJwt: SDJWTCompact): Promise<string[]>;
|
|
249
597
|
presentableKeys(endcodedSDJwt: SDJWTCompact): Promise<string[]>;
|
|
250
598
|
getClaims(endcodedSDJwt: SDJWTCompact): Promise<unknown>;
|
|
@@ -276,20 +624,20 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
|
|
|
276
624
|
kb?: KBOptions;
|
|
277
625
|
}): Promise<GeneralJSON>;
|
|
278
626
|
verify(generalJSON: GeneralJSON, options?: VerifierOptions): Promise<{
|
|
279
|
-
payload:
|
|
627
|
+
payload: ExtendedPayload;
|
|
280
628
|
headers: any[];
|
|
281
629
|
kb?: undefined;
|
|
282
630
|
} | {
|
|
283
|
-
payload:
|
|
631
|
+
payload: ExtendedPayload;
|
|
284
632
|
headers: any[];
|
|
285
633
|
kb: {
|
|
286
|
-
payload:
|
|
287
|
-
header:
|
|
634
|
+
payload: kbPayload;
|
|
635
|
+
header: kbHeader;
|
|
288
636
|
};
|
|
289
637
|
}>;
|
|
290
638
|
private calculateSDHash;
|
|
291
639
|
validate(generalJSON: GeneralJSON): Promise<{
|
|
292
|
-
payload:
|
|
640
|
+
payload: ExtendedPayload;
|
|
293
641
|
headers: any[];
|
|
294
642
|
}>;
|
|
295
643
|
config(newConfig: SDJWTConfig): void;
|
|
@@ -300,4 +648,4 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
|
|
|
300
648
|
getClaims(generalSdjwt: GeneralJSON): Promise<unknown>;
|
|
301
649
|
}
|
|
302
650
|
|
|
303
|
-
export { FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, Jwt, type JwtData, KBJwt, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, type SdJwtPayload, type VerifierOptions, createDecoy, listKeys, pack };
|
|
651
|
+
export { type Base64urlString, type DECOY, type DecodedSDJwt, Disclosure, type DisclosureData, type DisclosureFrame, type Extensible, FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, type HashAlgorithm, type Hasher, type HasherAndAlg, type HasherAndAlgSync, type HasherSync, IANA_HASH_ALGORITHMS, Jwt, type JwtData, type JwtPayload, KBJwt, type KBOptions, KB_JWT_TYP, type KbVerifier, type OrPromise, type PresentationFrame, type SD, type SDJWTCompact, type SDJWTConfig, SDJWTException, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, SD_DECOY, SD_DIGEST, SD_LIST_KEY, SD_SEPARATOR, type SafeVerifyResult, type SaltGenerator, type SaltGeneratorSync, type SdJwtPayload, type SerializedDisclosure, type Signer, type SignerSync, type VerificationError, type VerificationErrorCode, type Verifier, type VerifierOptions, type VerifierSync, createDecoy, createHashMapping, createHashMappingForSerializedDisclosure, createHashMappingSync, decodeJwt, decodeSdJwt, decodeSdJwtSync, ensureError, getClaims, getClaimsSync, getSDAlgAndPayload, type kbHeader, type kbPayload, listKeys, pack, present, presentSync, presentableKeys, presentableKeysSync, selectDisclosures, splitSdJwt, transformPresentationFrame, unpack, unpackObj, unpackSync };
|