@sd-jwt/sd-jwt-vc 0.3.2-next.94 → 0.3.2-next.96
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/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/index.mjs +7 -0
- package/package.json +5 -5
- package/src/index.ts +10 -20
- package/src/sd-jwt-vc-payload.ts +21 -0
- package/src/test/index.spec.ts +38 -0
- package/test/app-e2e.spec.ts +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -11,8 +11,16 @@ interface SdJwtVcPayload extends SdJwtPayload {
|
|
|
11
11
|
status?: unknown;
|
|
12
12
|
sub?: string;
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
16
|
+
/**
|
|
17
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
18
|
+
*/
|
|
15
19
|
protected type: string;
|
|
20
|
+
/**
|
|
21
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
22
|
+
* @param disclosureFrame
|
|
23
|
+
*/
|
|
16
24
|
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcPayload>): void;
|
|
17
25
|
}
|
|
18
26
|
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,16 @@ interface SdJwtVcPayload extends SdJwtPayload {
|
|
|
11
11
|
status?: unknown;
|
|
12
12
|
sub?: string;
|
|
13
13
|
}
|
|
14
|
+
|
|
14
15
|
declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
16
|
+
/**
|
|
17
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
18
|
+
*/
|
|
15
19
|
protected type: string;
|
|
20
|
+
/**
|
|
21
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
22
|
+
* @param disclosureFrame
|
|
23
|
+
*/
|
|
16
24
|
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcPayload>): void;
|
|
17
25
|
}
|
|
18
26
|
|
package/dist/index.js
CHANGED
|
@@ -428,8 +428,15 @@ var import_dist = __toESM(require_dist());
|
|
|
428
428
|
var SDJwtVcInstance = class extends import_core.SDJwtInstance {
|
|
429
429
|
constructor() {
|
|
430
430
|
super(...arguments);
|
|
431
|
+
/**
|
|
432
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
433
|
+
*/
|
|
431
434
|
this.type = "sd-jwt-vc";
|
|
432
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
438
|
+
* @param disclosureFrame
|
|
439
|
+
*/
|
|
433
440
|
validateReservedFields(disclosureFrame) {
|
|
434
441
|
if ((disclosureFrame == null ? void 0 : disclosureFrame._sd) && Array.isArray(disclosureFrame._sd) && disclosureFrame._sd.length > 0) {
|
|
435
442
|
const reservedNames = [
|
package/dist/index.mjs
CHANGED
|
@@ -417,8 +417,15 @@ import { SDJwtInstance } from "@sd-jwt/core";
|
|
|
417
417
|
var SDJwtVcInstance = class extends SDJwtInstance {
|
|
418
418
|
constructor() {
|
|
419
419
|
super(...arguments);
|
|
420
|
+
/**
|
|
421
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
422
|
+
*/
|
|
420
423
|
this.type = "sd-jwt-vc";
|
|
421
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
427
|
+
* @param disclosureFrame
|
|
428
|
+
*/
|
|
422
429
|
validateReservedFields(disclosureFrame) {
|
|
423
430
|
if ((disclosureFrame == null ? void 0 : disclosureFrame._sd) && Array.isArray(disclosureFrame._sd) && disclosureFrame._sd.length > 0) {
|
|
424
431
|
const reservedNames = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/sd-jwt-vc",
|
|
3
|
-
"version": "0.3.2-next.
|
|
3
|
+
"version": "0.3.2-next.96+bfb8f73",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
},
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@sd-jwt/core": "0.3.2-next.
|
|
42
|
+
"@sd-jwt/core": "0.3.2-next.96+bfb8f73"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@sd-jwt/crypto-nodejs": "0.3.2-next.
|
|
46
|
-
"@sd-jwt/types": "0.3.2-next.
|
|
45
|
+
"@sd-jwt/crypto-nodejs": "0.3.2-next.96+bfb8f73",
|
|
46
|
+
"@sd-jwt/types": "0.3.2-next.96+bfb8f73"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"esm"
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "bfb8f73d22bf3c5f400f83a97a94677d8875a63f"
|
|
65
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SDJwtInstance } from '@sd-jwt/core';
|
|
2
2
|
import { DisclosureFrame } from '@sd-jwt/types';
|
|
3
3
|
import { SDJWTException } from '../../utils/dist';
|
|
4
|
+
import { SdJwtVcPayload } from './sd-jwt-vc-payload';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
// The Issuer of the Verifiable Credential. The value of iss MUST be a URI. See [RFC7519] for more information.
|
|
7
|
-
iss: string;
|
|
8
|
-
// The time of issuance of the Verifiable Credential. See [RFC7519] for more information.
|
|
9
|
-
iat: number;
|
|
10
|
-
// OPTIONAL. The time before which the Verifiable Credential MUST NOT be accepted before validating. See [RFC7519] for more information.
|
|
11
|
-
nbf?: number;
|
|
12
|
-
//OPTIONAL. The expiry time of the Verifiable Credential after which the Verifiable Credential is no longer valid. See [RFC7519] for more information.
|
|
13
|
-
exp?: number;
|
|
14
|
-
// REQUIRED when Cryptographic Key Binding is to be supported. Contains the confirmation method as defined in [RFC7800]. It is RECOMMENDED that this contains a JWK as defined in Section 3.2 of [RFC7800]. For Cryptographic Key Binding, the Key Binding JWT in the Combined Format for Presentation MUST be signed by the key identified in this claim.
|
|
15
|
-
cnf?: unknown;
|
|
16
|
-
//REQUIRED. The type of the Verifiable Credential, e.g., https://credentials.example.com/identity_credential, as defined in Section 3.2.2.1.1.
|
|
17
|
-
vct: string;
|
|
18
|
-
// OPTIONAL. The information on how to read the status of the Verifiable Credential. See [I-D.looker-oauth-jwt-cwt-status-list] for more information.
|
|
19
|
-
status?: unknown;
|
|
20
|
-
|
|
21
|
-
//The identifier of the Subject of the Verifiable Credential. The Issuer MAY use it to provide the Subject identifier known by the Issuer. There is no requirement for a binding to exist between sub and cnf claims.
|
|
22
|
-
sub?: string;
|
|
23
|
-
}
|
|
6
|
+
export { SdJwtVcPayload } from './sd-jwt-vc-payload';
|
|
24
7
|
|
|
25
8
|
export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
9
|
+
/**
|
|
10
|
+
* The type of the SD-JWT-VC set in the header.typ field.
|
|
11
|
+
*/
|
|
26
12
|
protected type = 'sd-jwt-vc';
|
|
27
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
16
|
+
* @param disclosureFrame
|
|
17
|
+
*/
|
|
28
18
|
protected validateReservedFields(
|
|
29
19
|
disclosureFrame: DisclosureFrame<SdJwtVcPayload>,
|
|
30
20
|
): void {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SdJwtPayload } from '@sd-jwt/core';
|
|
2
|
+
|
|
3
|
+
export interface SdJwtVcPayload extends SdJwtPayload {
|
|
4
|
+
// The Issuer of the Verifiable Credential. The value of iss MUST be a URI. See [RFC7519] for more information.
|
|
5
|
+
iss: string;
|
|
6
|
+
// The time of issuance of the Verifiable Credential. See [RFC7519] for more information.
|
|
7
|
+
iat: number;
|
|
8
|
+
// OPTIONAL. The time before which the Verifiable Credential MUST NOT be accepted before validating. See [RFC7519] for more information.
|
|
9
|
+
nbf?: number;
|
|
10
|
+
//OPTIONAL. The expiry time of the Verifiable Credential after which the Verifiable Credential is no longer valid. See [RFC7519] for more information.
|
|
11
|
+
exp?: number;
|
|
12
|
+
// REQUIRED when Cryptographic Key Binding is to be supported. Contains the confirmation method as defined in [RFC7800]. It is RECOMMENDED that this contains a JWK as defined in Section 3.2 of [RFC7800]. For Cryptographic Key Binding, the Key Binding JWT in the Combined Format for Presentation MUST be signed by the key identified in this claim.
|
|
13
|
+
cnf?: unknown;
|
|
14
|
+
//REQUIRED. The type of the Verifiable Credential, e.g., https://credentials.example.com/identity_credential, as defined in Section 3.2.2.1.1.
|
|
15
|
+
vct: string;
|
|
16
|
+
// OPTIONAL. The information on how to read the status of the Verifiable Credential. See [I-D.looker-oauth-jwt-cwt-status-list] for more information.
|
|
17
|
+
status?: unknown;
|
|
18
|
+
|
|
19
|
+
//The identifier of the Subject of the Verifiable Credential. The Issuer MAY use it to provide the Subject identifier known by the Issuer. There is no requirement for a binding to exist between sub and cnf claims.
|
|
20
|
+
sub?: string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
2
|
+
import { DisclosureFrame } from '@sd-jwt/types';
|
|
3
|
+
import { describe, test, expect } from 'vitest';
|
|
4
|
+
import { SDJwtVcInstance } from '..';
|
|
5
|
+
import { createSignerVerifier } from '../../test/app-e2e.spec';
|
|
6
|
+
import { SdJwtVcPayload } from '../sd-jwt-vc-payload';
|
|
7
|
+
|
|
8
|
+
const iss = 'ExampleIssuer';
|
|
9
|
+
const vct = 'https://example.com/schema/1';
|
|
10
|
+
const iat = new Date().getTime() / 1000;
|
|
11
|
+
|
|
12
|
+
describe('App', () => {
|
|
13
|
+
test('Example', async () => {
|
|
14
|
+
const { signer, verifier } = createSignerVerifier();
|
|
15
|
+
const sdjwt = new SDJwtVcInstance({
|
|
16
|
+
signer,
|
|
17
|
+
signAlg: 'EdDSA',
|
|
18
|
+
verifier,
|
|
19
|
+
hasher: digest,
|
|
20
|
+
hashAlg: 'SHA-256',
|
|
21
|
+
saltGenerator: generateSalt,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const claims = {
|
|
25
|
+
firstname: 'John',
|
|
26
|
+
};
|
|
27
|
+
const disclosureFrame = {
|
|
28
|
+
_sd: ['firstname', 'iss'],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const expectedPayload: SdJwtVcPayload = { iat, iss, vct, ...claims };
|
|
32
|
+
const encodedSdjwt = sdjwt.issue(
|
|
33
|
+
expectedPayload,
|
|
34
|
+
disclosureFrame as unknown as DisclosureFrame<SdJwtVcPayload>,
|
|
35
|
+
);
|
|
36
|
+
expect(encodedSdjwt).rejects.toThrowError();
|
|
37
|
+
});
|
|
38
|
+
});
|
package/test/app-e2e.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Crypto from 'node:crypto';
|
|
2
|
-
import { SDJwtVcInstance } from '../src';
|
|
2
|
+
import { SDJwtVcInstance, SdJwtVcPayload } from '../src/index';
|
|
3
3
|
import { DisclosureFrame, Signer, Verifier } from '@sd-jwt/types';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
@@ -72,7 +72,7 @@ describe('App', () => {
|
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
const expectedPayload = { iat, iss, vct, ...claims };
|
|
75
|
+
const expectedPayload: SdJwtVcPayload = { iat, iss, vct, ...claims };
|
|
76
76
|
const encodedSdjwt = await sdjwt.issue(expectedPayload, disclosureFrame);
|
|
77
77
|
expect(encodedSdjwt).toBeDefined();
|
|
78
78
|
const validated = await sdjwt.validate(encodedSdjwt);
|