@twin.org/trust-verifiers 0.0.3-next.1 → 0.0.3-next.2
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/es/verifiers/jwtVerifiableCredentialVerifier.js +10 -8
- package/dist/es/verifiers/jwtVerifiableCredentialVerifier.js.map +1 -1
- package/dist/types/verifiers/jwtVerifiableCredentialVerifier.d.ts +4 -4
- package/docs/changelog.md +14 -0
- package/docs/reference/classes/JwtVerifiableCredentialVerifier.md +9 -3
- package/package.json +2 -2
|
@@ -38,10 +38,10 @@ export class JwtVerifiableCredentialVerifier {
|
|
|
38
38
|
/**
|
|
39
39
|
* Verify a payload by checking the validity of its structure and content.
|
|
40
40
|
* @param payload The payload to verify.
|
|
41
|
-
* @
|
|
41
|
+
* @param info Information extracted from previous verifiers and to be added by this verifier.
|
|
42
|
+
* @returns Whether the payload is verified and possible verification failures, returns undefined if payload not processed.
|
|
42
43
|
*/
|
|
43
|
-
async verify(payload) {
|
|
44
|
-
const info = [];
|
|
44
|
+
async verify(payload, info) {
|
|
45
45
|
const failures = [];
|
|
46
46
|
if (Is.stringValue(payload)) {
|
|
47
47
|
const jwt = await Jwt.decode(payload);
|
|
@@ -58,6 +58,9 @@ export class JwtVerifiableCredentialVerifier {
|
|
|
58
58
|
if (Is.empty(verifiableCredential)) {
|
|
59
59
|
failures.push(new GeneralError(JwtVerifiableCredentialVerifier.CLASS_NAME, "tokenMissingCredential"));
|
|
60
60
|
}
|
|
61
|
+
else {
|
|
62
|
+
info.push(verifiableCredential);
|
|
63
|
+
}
|
|
61
64
|
const issuer = Is.stringValue(verifiableCredential?.issuer)
|
|
62
65
|
? verifiableCredential?.issuer
|
|
63
66
|
: undefined;
|
|
@@ -76,13 +79,12 @@ export class JwtVerifiableCredentialVerifier {
|
|
|
76
79
|
catch (err) {
|
|
77
80
|
failures.push(BaseError.fromError(err));
|
|
78
81
|
}
|
|
82
|
+
return {
|
|
83
|
+
verified: failures.length === 0,
|
|
84
|
+
failures
|
|
85
|
+
};
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
|
-
return {
|
|
82
|
-
verified: failures.length === 0,
|
|
83
|
-
info,
|
|
84
|
-
failures
|
|
85
|
-
};
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
//# sourceMappingURL=jwtVerifiableCredentialVerifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtVerifiableCredentialVerifier.js","sourceRoot":"","sources":["../../../src/verifiers/jwtVerifiableCredentialVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAe,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAMpG,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,+BAA+B;IAC3C;;OAEG;IACI,MAAM,CAAU,UAAU,qCAAqD;IAEtF;;;OAGG;IACc,iBAAiB,CAAqB;IAEvD;;;OAGG;IACc,kBAAkB,CAAqB;IAExD;;;OAGG;IACH,YAAY,OAA4D;QACvE,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC,WAAW,CACpD,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;QAEF,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAAC,CAAC;IAC9F,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,+BAA+B,CAAC,UAAU,CAAC;IACnD,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"jwtVerifiableCredentialVerifier.js","sourceRoot":"","sources":["../../../src/verifiers/jwtVerifiableCredentialVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAA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I,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;oBAC5B,CAAC;gBACF,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;gBACzC,CAAC;gBAED,OAAO;oBACN,QAAQ,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;oBAC/B,QAAQ;iBACR,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2025 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseError, Coerce, ComponentFactory, GeneralError, type IError, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IIdentityComponent } from \"@twin.org/identity-models\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { ITrustVerifier } from \"@twin.org/trust-models\";\nimport { Jwt } from \"@twin.org/web\";\nimport type { IJwtVerifiableCredentialVerifierConstructorOptions } from \"../models/IJwtVerifiableCredentialVerifierConstructorOptions.js\";\n\n/**\n * Class to verify a JWT Verifiable Credential.\n */\nexport class JwtVerifiableCredentialVerifier implements ITrustVerifier {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JwtVerifiableCredentialVerifier>();\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _loggingComponent?: ILoggingComponent;\n\n\t/**\n\t * The identity component.\n\t * @internal\n\t */\n\tprivate readonly _identityComponent: IIdentityComponent;\n\n\t/**\n\t * Create a new instance of JwtVerifiableCredentialVerifier.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IJwtVerifiableCredentialVerifierConstructorOptions) {\n\t\tthis._loggingComponent = ComponentFactory.getIfExists(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._identityComponent = ComponentFactory.get(options?.identityComponentType ?? \"identity\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn JwtVerifiableCredentialVerifier.CLASS_NAME;\n\t}\n\n\t/**\n\t * Verify a payload by checking the validity of its structure and content.\n\t * @param payload The payload to verify.\n\t * @param info Information extracted from previous verifiers and to be added by this verifier.\n\t * @returns Whether the payload is verified and possible verification failures, returns undefined if payload not processed.\n\t */\n\tpublic async verify(\n\t\tpayload: unknown,\n\t\tinfo: IJsonLdNodeObject[]\n\t): Promise<\n\t\t| {\n\t\t\t\tverified: boolean;\n\t\t\t\tfailures?: IError[];\n\t\t }\n\t\t| undefined\n\t> {\n\t\tconst failures: IError[] = [];\n\n\t\tif (Is.stringValue(payload)) {\n\t\t\tconst jwt = await Jwt.decode(payload);\n\n\t\t\tif (\n\t\t\t\tIs.objectValue(jwt.header) &&\n\t\t\t\tIs.objectValue(jwt.payload) &&\n\t\t\t\tIs.uint8Array(jwt.signature)\n\t\t\t) {\n\t\t\t\ttry {\n\t\t\t\t\tconst expiredMs = (Coerce.number(jwt.payload.exp) ?? 0) * 1000;\n\t\t\t\t\tif (expiredMs > 0 && expiredMs < Date.now()) {\n\t\t\t\t\t\tfailures.push(\n\t\t\t\t\t\t\tnew GeneralError(JwtVerifiableCredentialVerifier.CLASS_NAME, \"tokenExpired\")\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst verificationResult =\n\t\t\t\t\t\tawait this._identityComponent.verifiableCredentialVerify(payload);\n\n\t\t\t\t\tconst verifiableCredential = verificationResult.verifiableCredential;\n\t\t\t\t\tif (Is.empty(verifiableCredential)) {\n\t\t\t\t\t\tfailures.push(\n\t\t\t\t\t\t\tnew GeneralError(JwtVerifiableCredentialVerifier.CLASS_NAME, \"tokenMissingCredential\")\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tinfo.push(verifiableCredential as unknown as IJsonLdNodeObject);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst issuer: string | undefined = Is.stringValue(verifiableCredential?.issuer)\n\t\t\t\t\t\t? verifiableCredential?.issuer\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (Is.empty(issuer)) {\n\t\t\t\t\t\tfailures.push(\n\t\t\t\t\t\t\tnew GeneralError(JwtVerifiableCredentialVerifier.CLASS_NAME, \"tokenMissingIssuer\")\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst subject = verifiableCredential?.credentialSubject;\n\t\t\t\t\tif (Is.empty(subject)) {\n\t\t\t\t\t\tfailures.push(\n\t\t\t\t\t\t\tnew GeneralError(JwtVerifiableCredentialVerifier.CLASS_NAME, \"tokenMissingSubject\")\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst subjectArray = Array.isArray(subject) ? subject : [subject];\n\t\t\t\t\t\tinfo.push(...subjectArray);\n\t\t\t\t\t}\n\t\t\t\t} catch (err) {\n\t\t\t\t\tfailures.push(BaseError.fromError(err));\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tverified: failures.length === 0,\n\t\t\t\t\tfailures\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -23,11 +23,11 @@ export declare class JwtVerifiableCredentialVerifier implements ITrustVerifier {
|
|
|
23
23
|
/**
|
|
24
24
|
* Verify a payload by checking the validity of its structure and content.
|
|
25
25
|
* @param payload The payload to verify.
|
|
26
|
-
* @
|
|
26
|
+
* @param info Information extracted from previous verifiers and to be added by this verifier.
|
|
27
|
+
* @returns Whether the payload is verified and possible verification failures, returns undefined if payload not processed.
|
|
27
28
|
*/
|
|
28
|
-
verify(payload: unknown): Promise<{
|
|
29
|
+
verify(payload: unknown, info: IJsonLdNodeObject[]): Promise<{
|
|
29
30
|
verified: boolean;
|
|
30
|
-
info?: IJsonLdNodeObject[];
|
|
31
31
|
failures?: IError[];
|
|
32
|
-
}>;
|
|
32
|
+
} | undefined>;
|
|
33
33
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.2](https://github.com/twinfoundation/trust/compare/trust-verifiers-v0.0.3-next.1...trust-verifiers-v0.0.3-next.2) (2025-12-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* support pass through of info between verifiers ([1ce64b9](https://github.com/twinfoundation/trust/commit/1ce64b97a949278b447cc12b576ce5de537f30f3))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/trust-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
16
|
+
|
|
3
17
|
## [0.0.3-next.1](https://github.com/twinfoundation/trust/compare/trust-verifiers-v0.0.3-next.0...trust-verifiers-v0.0.3-next.1) (2025-12-02)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -56,7 +56,7 @@ The class name of the component.
|
|
|
56
56
|
|
|
57
57
|
### verify()
|
|
58
58
|
|
|
59
|
-
> **verify**(`payload`): `Promise`\<\{ `verified`: `boolean`; `
|
|
59
|
+
> **verify**(`payload`, `info`): `Promise`\<\{ `verified`: `boolean`; `failures?`: `IError`[]; \} \| `undefined`\>
|
|
60
60
|
|
|
61
61
|
Verify a payload by checking the validity of its structure and content.
|
|
62
62
|
|
|
@@ -68,11 +68,17 @@ Verify a payload by checking the validity of its structure and content.
|
|
|
68
68
|
|
|
69
69
|
The payload to verify.
|
|
70
70
|
|
|
71
|
+
##### info
|
|
72
|
+
|
|
73
|
+
`IJsonLdNodeObject`[]
|
|
74
|
+
|
|
75
|
+
Information extracted from previous verifiers and to be added by this verifier.
|
|
76
|
+
|
|
71
77
|
#### Returns
|
|
72
78
|
|
|
73
|
-
`Promise`\<\{ `verified`: `boolean`; `
|
|
79
|
+
`Promise`\<\{ `verified`: `boolean`; `failures?`: `IError`[]; \} \| `undefined`\>
|
|
74
80
|
|
|
75
|
-
Whether the payload is verified and
|
|
81
|
+
Whether the payload is verified and possible verification failures, returns undefined if payload not processed.
|
|
76
82
|
|
|
77
83
|
#### Implementation of
|
|
78
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/trust-verifiers",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.2",
|
|
4
4
|
"description": "Verifiers for trust",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@twin.org/identity-models": "next",
|
|
20
20
|
"@twin.org/logging-models": "next",
|
|
21
21
|
"@twin.org/nameof": "next",
|
|
22
|
-
"@twin.org/trust-models": "0.0.3-next.
|
|
22
|
+
"@twin.org/trust-models": "0.0.3-next.2",
|
|
23
23
|
"@twin.org/web": "next"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/es/index.js",
|