@credo-ts/core 0.6.2-alpha-20251211122719 → 0.6.2-alpha-20251211125344
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/build/agent/Agent.mjs +2 -2
- package/build/agent/AgentConfig.d.mts +2 -0
- package/build/agent/AgentConfig.d.mts.map +1 -1
- package/build/agent/AgentConfig.mjs +4 -0
- package/build/agent/AgentConfig.mjs.map +1 -1
- package/build/agent/context/DefaultAgentContextProvider.mjs +1 -1
- package/build/crypto/JwsService.mjs +4 -4
- package/build/crypto/KmsKeyPair.mjs +1 -1
- package/build/crypto/index.mjs +1 -1
- package/build/crypto/jose/jwt/Jwt.mjs +1 -1
- package/build/crypto/jose/jwt/JwtPayload.d.mts +5 -0
- package/build/crypto/jose/jwt/JwtPayload.d.mts.map +1 -1
- package/build/crypto/jose/jwt/JwtPayload.mjs +10 -8
- package/build/crypto/jose/jwt/JwtPayload.mjs.map +1 -1
- package/build/index.mjs +12 -12
- package/build/modules/cache/CachedStorageService.mjs +2 -2
- package/build/modules/dcql/DcqlService.mjs +1 -1
- package/build/modules/dids/DidsApi.mjs +1 -1
- package/build/modules/dids/domain/DidDocument.mjs +2 -2
- package/build/modules/dids/domain/service/DidCommV1Service.mjs +2 -2
- package/build/modules/dids/domain/service/DidCommV2Service.mjs +2 -2
- package/build/modules/dids/domain/service/IndyAgentService.mjs +2 -2
- package/build/modules/dids/domain/service/LegacyDidCommV2Service.mjs +2 -2
- package/build/modules/dids/services/DidResolverService.mjs +2 -2
- package/build/modules/dif-presentation-exchange/DifPresentationExchangeService.mjs +2 -2
- package/build/modules/kms/jwk/PublicJwk.mjs +1 -1
- package/build/modules/kms/jwk/alg/encryption.mjs +1 -1
- package/build/modules/kms/jwk/alg/signing.mjs +1 -1
- package/build/modules/kms/jwk/kty/ec/ecPublicKey.mjs +1 -1
- package/build/modules/kms/jwk/kty/rsa/RsaPublicJwk.mjs +1 -1
- package/build/modules/kms/legacy.mjs +1 -1
- package/build/modules/mdoc/Mdoc.mjs +2 -2
- package/build/modules/mdoc/Mdoc.mjs.map +1 -1
- package/build/modules/mdoc/MdocDeviceResponse.mjs +2 -2
- package/build/modules/mdoc/MdocDeviceResponse.mjs.map +1 -1
- package/build/modules/mdoc/mdocSupportedAlgs.d.mts +2 -2
- package/build/modules/mdoc/mdocSupportedAlgs.mjs +3 -3
- package/build/modules/mdoc/mdocSupportedAlgs.mjs.map +1 -1
- package/build/modules/sd-jwt-vc/SdJwtVcService.mjs +6 -6
- package/build/modules/sd-jwt-vc/SdJwtVcService.mjs.map +1 -1
- package/build/modules/sd-jwt-vc/utils.mjs +1 -1
- package/build/modules/vc/data-integrity/W3cJsonLdCredentialService.mjs +3 -3
- package/build/modules/vc/data-integrity/libraries/jsonld.d.mts.map +1 -1
- package/build/modules/vc/data-integrity/models/DataIntegrityProof.mjs +2 -2
- package/build/modules/vc/data-integrity/models/LinkedDataProof.mjs +2 -2
- package/build/modules/vc/data-integrity/models/W3cJsonLdVerifiableCredential.mjs +2 -2
- package/build/modules/vc/data-integrity/models/W3cJsonLdVerifiablePresentation.mjs +2 -2
- package/build/modules/vc/jwt-vc/W3cJwtCredentialService.d.mts.map +1 -1
- package/build/modules/vc/jwt-vc/W3cJwtCredentialService.mjs +5 -5
- package/build/modules/vc/jwt-vc/W3cJwtCredentialService.mjs.map +1 -1
- package/build/modules/vc/jwt-vc/W3cV2JwtCredentialService.d.mts.map +1 -1
- package/build/modules/vc/jwt-vc/W3cV2JwtCredentialService.mjs +5 -5
- package/build/modules/vc/jwt-vc/W3cV2JwtCredentialService.mjs.map +1 -1
- package/build/modules/vc/jwt-vc/credentialTransformer.mjs +1 -1
- package/build/modules/vc/jwt-vc/presentationTransformer.mjs +1 -1
- package/build/modules/vc/models/credential/W3cCredential.mjs +2 -2
- package/build/modules/vc/models/credential/W3cCredentialSchema.mjs +1 -1
- package/build/modules/vc/models/credential/W3cCredentialStatus.mjs +1 -1
- package/build/modules/vc/models/credential/W3cIssuer.mjs +1 -1
- package/build/modules/vc/models/credential/W3cV2Credential.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialSchema.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialStatus.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2CredentialSubject.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2Evidence.mjs +2 -2
- package/build/modules/vc/models/credential/W3cV2Issuer.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cHolder.mjs +1 -1
- package/build/modules/vc/models/presentation/W3cPresentation.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cV2Holder.mjs +2 -2
- package/build/modules/vc/models/presentation/W3cV2Presentation.mjs +2 -2
- package/build/modules/vc/sd-jwt-vc/W3cV2SdJwtCredentialService.d.mts.map +1 -1
- package/build/modules/vc/sd-jwt-vc/W3cV2SdJwtCredentialService.mjs +7 -7
- package/build/modules/vc/sd-jwt-vc/W3cV2SdJwtCredentialService.mjs.map +1 -1
- package/build/modules/vc/v2-jwt-utils.mjs +1 -1
- package/build/storage/BaseRecord.mjs +2 -2
- package/build/types.d.mts +17 -0
- package/build/types.d.mts.map +1 -1
- package/build/types.mjs.map +1 -1
- package/package.json +1 -1
package/build/agent/Agent.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
import { InjectionSymbols } from "../constants.mjs";
|
|
4
|
-
import { AgentConfig } from "./AgentConfig.mjs";
|
|
5
|
-
import { AgentContext } from "./context/AgentContext.mjs";
|
|
6
4
|
import { CredoError } from "../error/CredoError.mjs";
|
|
7
5
|
import "../error/index.mjs";
|
|
6
|
+
import { AgentConfig } from "./AgentConfig.mjs";
|
|
7
|
+
import { AgentContext } from "./context/AgentContext.mjs";
|
|
8
8
|
import { DependencyManager } from "../plugins/DependencyManager.mjs";
|
|
9
9
|
import "../plugins/index.mjs";
|
|
10
10
|
import { DefaultAgentContextProvider } from "./context/DefaultAgentContextProvider.mjs";
|
|
@@ -10,12 +10,14 @@ declare class AgentConfig {
|
|
|
10
10
|
constructor(initConfig: InitConfig, agentDependencies: AgentDependencies);
|
|
11
11
|
get allowInsecureHttpUrls(): boolean;
|
|
12
12
|
get autoUpdateStorageOnStartup(): boolean;
|
|
13
|
+
get validitySkewSeconds(): number;
|
|
13
14
|
extend(config: Partial<InitConfig>): AgentConfig;
|
|
14
15
|
toJSON(): {
|
|
15
16
|
logger: LogLevel;
|
|
16
17
|
agentDependencies: boolean;
|
|
17
18
|
autoUpdateStorageOnStartup?: boolean;
|
|
18
19
|
allowInsecureHttpUrls?: boolean;
|
|
20
|
+
validitySkewSeconds?: number;
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentConfig.d.mts","names":[],"sources":["../../src/agent/AgentConfig.ts"],"sourcesContent":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"AgentConfig.d.mts","names":[],"sources":["../../src/agent/AgentConfig.ts"],"sourcesContent":[],"mappings":";;;;;cAMa,WAAA;;UAEI;EAFJ,SAAA,iBAAW,EAGa,iBAHb;EAEP,WAAA,CAAA,UAAA,EAGgB,UAHhB,EAAA,iBAAA,EAG+C,iBAH/C;EACoB,IAAA,qBAAA,CAAA,CAAA,EAAA,OAAA;EAEJ,IAAA,0BAAA,CAAA,CAAA,EAAA,OAAA;EAA+B,IAAA,mBAAA,CAAA,CAAA,EAAA,MAAA;EAkBhC,MAAA,CAAA,MAAA,EAAR,OAAQ,CAAA,UAAA,CAAA,CAAA,EAAc,WAAd;EAAR,MAAA,CAAA,CAAA,EAAA;IAAsB,MAAA,UAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
import { DEFAULT_SKEW_TIME } from "../crypto/jose/jwt/JwtPayload.mjs";
|
|
3
4
|
import { LogLevel } from "../logger/Logger.mjs";
|
|
4
5
|
import { ConsoleLogger } from "../logger/ConsoleLogger.mjs";
|
|
5
6
|
|
|
@@ -16,6 +17,9 @@ var AgentConfig = class AgentConfig {
|
|
|
16
17
|
get autoUpdateStorageOnStartup() {
|
|
17
18
|
return this.initConfig.autoUpdateStorageOnStartup ?? false;
|
|
18
19
|
}
|
|
20
|
+
get validitySkewSeconds() {
|
|
21
|
+
return this.initConfig.validitySkewSeconds ?? DEFAULT_SKEW_TIME;
|
|
22
|
+
}
|
|
19
23
|
extend(config) {
|
|
20
24
|
return new AgentConfig({
|
|
21
25
|
...this.initConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentConfig.mjs","names":[],"sources":["../../src/agent/AgentConfig.ts"],"sourcesContent":["import type { Logger } from '../logger'\nimport { ConsoleLogger, LogLevel } from '../logger'\nimport type { InitConfig } from '../types'\nimport type { AgentDependencies } from './AgentDependencies'\n\nexport class AgentConfig {\n private initConfig: InitConfig\n public logger: Logger\n public readonly agentDependencies: AgentDependencies\n\n public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) {\n this.initConfig = initConfig\n this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off)\n this.agentDependencies = agentDependencies\n }\n\n public get allowInsecureHttpUrls() {\n return this.initConfig.allowInsecureHttpUrls ?? false\n }\n\n public get autoUpdateStorageOnStartup() {\n return this.initConfig.autoUpdateStorageOnStartup ?? false\n }\n\n public extend(config: Partial<InitConfig>): AgentConfig {\n return new AgentConfig({ ...this.initConfig, logger: this.logger, ...config }, this.agentDependencies)\n }\n\n public toJSON() {\n return {\n ...this.initConfig,\n logger: this.logger.logLevel,\n agentDependencies: Boolean(this.agentDependencies),\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentConfig.mjs","names":[],"sources":["../../src/agent/AgentConfig.ts"],"sourcesContent":["import { DEFAULT_SKEW_TIME } from '../crypto/jose/jwt/JwtPayload'\nimport type { Logger } from '../logger'\nimport { ConsoleLogger, LogLevel } from '../logger'\nimport type { InitConfig } from '../types'\nimport type { AgentDependencies } from './AgentDependencies'\n\nexport class AgentConfig {\n private initConfig: InitConfig\n public logger: Logger\n public readonly agentDependencies: AgentDependencies\n\n public constructor(initConfig: InitConfig, agentDependencies: AgentDependencies) {\n this.initConfig = initConfig\n this.logger = initConfig.logger ?? new ConsoleLogger(LogLevel.off)\n this.agentDependencies = agentDependencies\n }\n\n public get allowInsecureHttpUrls() {\n return this.initConfig.allowInsecureHttpUrls ?? false\n }\n\n public get autoUpdateStorageOnStartup() {\n return this.initConfig.autoUpdateStorageOnStartup ?? false\n }\n\n public get validitySkewSeconds() {\n return this.initConfig.validitySkewSeconds ?? DEFAULT_SKEW_TIME\n }\n\n public extend(config: Partial<InitConfig>): AgentConfig {\n return new AgentConfig({ ...this.initConfig, logger: this.logger, ...config }, this.agentDependencies)\n }\n\n public toJSON() {\n return {\n ...this.initConfig,\n logger: this.logger.logLevel,\n agentDependencies: Boolean(this.agentDependencies),\n }\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAa,cAAb,MAAa,YAAY;CAKvB,AAAO,YAAY,YAAwB,mBAAsC;AAC/E,OAAK,aAAa;AAClB,OAAK,SAAS,WAAW,UAAU,IAAI,cAAc,SAAS,IAAI;AAClE,OAAK,oBAAoB;;CAG3B,IAAW,wBAAwB;AACjC,SAAO,KAAK,WAAW,yBAAyB;;CAGlD,IAAW,6BAA6B;AACtC,SAAO,KAAK,WAAW,8BAA8B;;CAGvD,IAAW,sBAAsB;AAC/B,SAAO,KAAK,WAAW,uBAAuB;;CAGhD,AAAO,OAAO,QAA0C;AACtD,SAAO,IAAI,YAAY;GAAE,GAAG,KAAK;GAAY,QAAQ,KAAK;GAAQ,GAAG;GAAQ,EAAE,KAAK,kBAAkB;;CAGxG,AAAO,SAAS;AACd,SAAO;GACL,GAAG,KAAK;GACR,QAAQ,KAAK,OAAO;GACpB,mBAAmB,QAAQ,KAAK,kBAAkB;GACnD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { AgentContext } from "./AgentContext.mjs";
|
|
4
3
|
import { CredoError } from "../../error/CredoError.mjs";
|
|
5
4
|
import "../../error/index.mjs";
|
|
5
|
+
import { AgentContext } from "./AgentContext.mjs";
|
|
6
6
|
import { injectable } from "../../plugins/index.mjs";
|
|
7
7
|
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
8
8
|
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../error/CredoError.mjs";
|
|
4
4
|
import "../error/index.mjs";
|
|
5
|
-
import { injectable } from "../plugins/index.mjs";
|
|
6
|
-
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
|
-
import { KeyManagementError } from "../modules/kms/error/KeyManagementError.mjs";
|
|
8
5
|
import { TypedArrayEncoder } from "../utils/TypedArrayEncoder.mjs";
|
|
9
6
|
import { JsonEncoder } from "../utils/JsonEncoder.mjs";
|
|
10
7
|
import "../utils/index.mjs";
|
|
8
|
+
import { JwtPayload } from "./jose/jwt/JwtPayload.mjs";
|
|
9
|
+
import { injectable } from "../plugins/index.mjs";
|
|
10
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
11
|
+
import { KeyManagementError } from "../modules/kms/error/KeyManagementError.mjs";
|
|
11
12
|
import { getJwkHumanDescription } from "../modules/kms/jwk/humanDescription.mjs";
|
|
12
13
|
import { asymmetricPublicJwkMatches } from "../modules/kms/jwk/equals.mjs";
|
|
13
14
|
import { isKnownJwaSignatureAlgorithm } from "../modules/kms/jwk/jwa.mjs";
|
|
@@ -20,7 +21,6 @@ import { X509Service } from "../modules/x509/X509Service.mjs";
|
|
|
20
21
|
import "../modules/x509/index.mjs";
|
|
21
22
|
import { isJsonObject } from "../types.mjs";
|
|
22
23
|
import { JWS_COMPACT_FORMAT_MATCHER } from "./JwsTypes.mjs";
|
|
23
|
-
import { JwtPayload } from "./jose/jwt/JwtPayload.mjs";
|
|
24
24
|
import "./jose/jwt/index.mjs";
|
|
25
25
|
|
|
26
26
|
//#region src/crypto/JwsService.ts
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../error/CredoError.mjs";
|
|
4
4
|
import "../error/index.mjs";
|
|
5
|
-
import "../agent/index.mjs";
|
|
6
5
|
import { MessageValidator } from "../utils/MessageValidator.mjs";
|
|
7
6
|
import { JsonTransformer } from "../utils/JsonTransformer.mjs";
|
|
8
7
|
import "../utils/index.mjs";
|
|
8
|
+
import "../agent/index.mjs";
|
|
9
9
|
import { KeyManagementApi } from "../modules/kms/KeyManagementApi.mjs";
|
|
10
10
|
import "../modules/kms/index.mjs";
|
|
11
11
|
import { VerificationMethod } from "../modules/dids/domain/verificationMethod/VerificationMethod.mjs";
|
package/build/crypto/index.mjs
CHANGED
|
@@ -6,11 +6,11 @@ import { Sha384 } from "./hashes/Sha384.mjs";
|
|
|
6
6
|
import { Sha512 } from "./hashes/Sha512.mjs";
|
|
7
7
|
import { Hasher } from "./hashes/Hasher.mjs";
|
|
8
8
|
import "./hashes/index.mjs";
|
|
9
|
+
import { JwtPayload } from "./jose/jwt/JwtPayload.mjs";
|
|
9
10
|
import { CredoWebCryptoKey } from "./webcrypto/CredoWebCryptoKey.mjs";
|
|
10
11
|
import { publicJwkToCryptoKeyAlgorithm } from "./webcrypto/utils/keyAlgorithmConversion.mjs";
|
|
11
12
|
import { CredoWebCrypto } from "./webcrypto/CredoWebCrypto.mjs";
|
|
12
13
|
import "./webcrypto/index.mjs";
|
|
13
|
-
import { JwtPayload } from "./jose/jwt/JwtPayload.mjs";
|
|
14
14
|
import { Jwt } from "./jose/jwt/Jwt.mjs";
|
|
15
15
|
import { JwsService } from "./JwsService.mjs";
|
|
16
16
|
import "./jose/index.mjs";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { replaceError } from "../../../logger/replaceError.mjs";
|
|
4
3
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
5
4
|
import "../../../error/index.mjs";
|
|
6
5
|
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
|
|
7
6
|
import { JsonEncoder } from "../../../utils/JsonEncoder.mjs";
|
|
8
7
|
import "../../../utils/index.mjs";
|
|
9
8
|
import { JwtPayload } from "./JwtPayload.mjs";
|
|
9
|
+
import { replaceError } from "../../../logger/replaceError.mjs";
|
|
10
10
|
|
|
11
11
|
//#region src/crypto/jose/jwt/Jwt.ts
|
|
12
12
|
var Jwt = class Jwt {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/crypto/jose/jwt/JwtPayload.d.ts
|
|
2
|
+
|
|
2
3
|
interface JwtPayloadJson {
|
|
3
4
|
iss?: string;
|
|
4
5
|
sub?: string;
|
|
@@ -94,7 +95,11 @@ declare class JwtPayload {
|
|
|
94
95
|
* - if `exp` is present, it must be greater than now
|
|
95
96
|
*/
|
|
96
97
|
validate(options?: {
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated use `skewSeconds` instead
|
|
100
|
+
*/
|
|
97
101
|
skewTime?: number;
|
|
102
|
+
skewSeconds?: number;
|
|
98
103
|
now?: number;
|
|
99
104
|
}): void;
|
|
100
105
|
toJson(): JwtPayloadJson;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtPayload.d.mts","names":[],"sources":["../../../../src/crypto/jose/jwt/JwtPayload.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JwtPayload.d.mts","names":[],"sources":["../../../../src/crypto/jose/jwt/JwtPayload.ts"],"sourcesContent":[],"mappings":";;AAoKmB,UAxJF,cAAA,CAwJE;EAasB,GAAA,CAAA,EAAA,MAAA;EAAc,GAAA,CAAA,EAAA,MAAA;EAAA,GAAA,CAAA,EAAA,MAAA,GAAA,MAAA,EAAA;;;;;;;UA1JtC,iBAAA;;;;;;;;qBAQI;;cAGR,UAAA;wBACkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAiFJ;;;;;;;;;;;;;;;;;YAgDR;kCAasB,iBAAc"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../error/index.mjs";
|
|
5
|
+
import { dateToSeconds } from "../../../utils/timestamp.mjs";
|
|
6
|
+
import "../../../utils/index.mjs";
|
|
5
7
|
|
|
6
8
|
//#region src/crypto/jose/jwt/JwtPayload.ts
|
|
7
9
|
/**
|
|
@@ -11,7 +13,7 @@ import "../../../error/index.mjs";
|
|
|
11
13
|
*
|
|
12
14
|
* See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5
|
|
13
15
|
*/
|
|
14
|
-
const DEFAULT_SKEW_TIME =
|
|
16
|
+
const DEFAULT_SKEW_TIME = 30;
|
|
15
17
|
var JwtPayload = class JwtPayload {
|
|
16
18
|
constructor(options) {
|
|
17
19
|
this.iss = options?.iss;
|
|
@@ -32,7 +34,7 @@ var JwtPayload = class JwtPayload {
|
|
|
32
34
|
* - if `exp` is present, it must be greater than now
|
|
33
35
|
*/
|
|
34
36
|
validate(options) {
|
|
35
|
-
const { nowSkewedFuture, nowSkewedPast } = getNowSkewed(options?.now, options?.skewTime);
|
|
37
|
+
const { nowSkewedFuture, nowSkewedPast } = getNowSkewed(options?.now, options?.skewSeconds ?? options?.skewTime);
|
|
36
38
|
if (typeof this.nbf !== "number" && typeof this.nbf !== "undefined") throw new CredoError(`JWT payload 'nbf' must be a number if provided. Actual type is ${typeof this.nbf}`);
|
|
37
39
|
if (typeof this.nbf === "number" && this.nbf > nowSkewedFuture) throw new CredoError(`JWT not valid before ${this.nbf}`);
|
|
38
40
|
if (typeof this.iat !== "number" && typeof this.iat !== "undefined") throw new CredoError(`JWT payload 'iat' must be a number if provided. Actual type is ${typeof this.iat}`);
|
|
@@ -73,15 +75,15 @@ var JwtPayload = class JwtPayload {
|
|
|
73
75
|
});
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
|
-
function getNowSkewed(now,
|
|
77
|
-
const _now =
|
|
78
|
-
const
|
|
78
|
+
function getNowSkewed(now, skewSeconds) {
|
|
79
|
+
const _now = now ?? dateToSeconds(/* @__PURE__ */ new Date());
|
|
80
|
+
const _skewSeconds = skewSeconds ?? DEFAULT_SKEW_TIME;
|
|
79
81
|
return {
|
|
80
|
-
nowSkewedPast: _now -
|
|
81
|
-
nowSkewedFuture: _now +
|
|
82
|
+
nowSkewedPast: _now - _skewSeconds,
|
|
83
|
+
nowSkewedFuture: _now + _skewSeconds
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
//#endregion
|
|
86
|
-
export { JwtPayload };
|
|
88
|
+
export { DEFAULT_SKEW_TIME, JwtPayload };
|
|
87
89
|
//# sourceMappingURL=JwtPayload.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtPayload.mjs","names":["aud"],"sources":["../../../../src/crypto/jose/jwt/JwtPayload.ts"],"sourcesContent":["import { CredoError } from '../../../error'\n\n/**\n * The maximum allowed clock skew time in seconds. If an time based validation\n * is performed against current time (`now`), the validation can be of by the skew\n * time.\n *\n * See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5\n */\
|
|
1
|
+
{"version":3,"file":"JwtPayload.mjs","names":["aud"],"sources":["../../../../src/crypto/jose/jwt/JwtPayload.ts"],"sourcesContent":["import { CredoError } from '../../../error'\nimport { dateToSeconds } from '../../../utils'\n\n/**\n * The maximum allowed clock skew time in seconds. If an time based validation\n * is performed against current time (`now`), the validation can be of by the skew\n * time.\n *\n * See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5\n */\nexport const DEFAULT_SKEW_TIME = 30\n\nexport interface JwtPayloadJson {\n iss?: string\n sub?: string\n aud?: string | string[]\n exp?: number\n nbf?: number\n iat?: number\n jti?: string\n [key: string]: unknown\n}\n\nexport interface JwtPayloadOptions {\n iss?: string\n sub?: string\n aud?: string | string[]\n exp?: number\n nbf?: number\n iat?: number\n jti?: string\n additionalClaims?: Record<string, unknown>\n}\n\nexport class JwtPayload {\n public constructor(options?: JwtPayloadOptions) {\n this.iss = options?.iss\n this.sub = options?.sub\n this.aud = options?.aud\n this.exp = options?.exp\n this.nbf = options?.nbf\n this.iat = options?.iat\n this.jti = options?.jti\n this.additionalClaims = options?.additionalClaims ?? {}\n }\n\n /**\n * identifies the principal that issued the JWT.\n * The processing of this claim is generally application specific.\n * The \"iss\" value is a case-sensitive string containing a StringOrURI\n * value.\n */\n public iss?: string\n\n /**\n * identifies the principal that is the\n * subject of the JWT. The Claims in a JWT are normally statements\n * about the subject. The subject value MUST either be scoped to be\n * locally unique in the context of the issuer or be globally unique.\n * The processing of this claim is generally application specific. The\n * \"sub\" value is a case-sensitive string containing a StringOrURI\n * value.\n */\n public sub?: string\n\n /**\n * identifies the recipients that the JWT is\n * intended for. Each principal intended to process the JWT MUST\n * identify itself with a value in the audience claim. If the principal\n * processing the claim does not identify itself with a value in the\n * \"aud\" claim when this claim is present, then the JWT MUST be\n * rejected.In the general case, the \"aud\" value is an array of case-\n * sensitive strings, each containing a StringOrURI value. In the\n * special case when the JWT has one audience, the \"aud\" value MAY be a\n * single case-sensitive string containing a StringOrURI value. The\n * interpretation of audience values is generally application specific.\n */\n public aud?: string | string[]\n\n /**\n * identifies the expiration time on\n * or after which the JWT MUST NOT be accepted for processing. The\n * processing of the \"exp\" claim requires that the current date/time\n * MUST be before the expiration date/time listed in the \"exp\" claim.\n * Implementers MAY provide for some small leeway, usually no more than\n * a few minutes, to account for clock skew. Its value MUST be a number\n * containing a NumericDate value.\n */\n public exp?: number\n\n /**\n * identifies the time at which the JWT was\n * issued. This claim can be used to determine the age of the JWT. Its\n * value MUST be a number containing a NumericDate value.\n */\n public nbf?: number\n\n /**\n * identifies the time at which the JWT was\n * issued. This claim can be used to determine the age of the JWT. Its\n * value MUST be a number containing a NumericDate value.\n */\n public iat?: number\n\n /**\n * provides a unique identifier for the JWT.\n * The identifier value MUST be assigned in a manner that ensures that\n * there is a negligible probability that the same value will be\n * accidentally assigned to a different data object; if the application\n * uses multiple issuers, collisions MUST be prevented among values\n * produced by different issuers as well. The \"jti\" claim can be used\n * to prevent the JWT from being replayed. The \"jti\" value is a case-\n * sensitive string.\n */\n public jti?: string\n\n public additionalClaims: Record<string, unknown>\n\n /**\n * Validate the JWT payload. This does not verify the signature of the JWT itself.\n *\n * The following validations are performed:\n * - if `nbf` is present, it must be greater than now\n * - if `iat` is present, it must be less than now\n * - if `exp` is present, it must be greater than now\n */\n public validate(options?: {\n /**\n * @deprecated use `skewSeconds` instead\n */\n skewTime?: number\n skewSeconds?: number\n now?: number\n }) {\n const { nowSkewedFuture, nowSkewedPast } = getNowSkewed(options?.now, options?.skewSeconds ?? options?.skewTime)\n\n // Validate nbf\n if (typeof this.nbf !== 'number' && typeof this.nbf !== 'undefined') {\n throw new CredoError(`JWT payload 'nbf' must be a number if provided. Actual type is ${typeof this.nbf}`)\n }\n if (typeof this.nbf === 'number' && this.nbf > nowSkewedFuture) {\n throw new CredoError(`JWT not valid before ${this.nbf}`)\n }\n\n // Validate iat\n if (typeof this.iat !== 'number' && typeof this.iat !== 'undefined') {\n throw new CredoError(`JWT payload 'iat' must be a number if provided. Actual type is ${typeof this.iat}`)\n }\n if (typeof this.iat === 'number' && this.iat > nowSkewedFuture) {\n throw new CredoError(`JWT issued in the future at ${this.iat}`)\n }\n\n // Validate exp\n if (typeof this.exp !== 'number' && typeof this.exp !== 'undefined') {\n throw new CredoError(`JWT payload 'exp' must be a number if provided. Actual type is ${typeof this.exp}`)\n }\n if (typeof this.exp === 'number' && this.exp < nowSkewedPast) {\n throw new CredoError(`JWT expired at ${this.exp}`)\n }\n\n // NOTE: nonce and aud are not validated in here. We could maybe add\n // the values as input, so you can provide the expected nonce and aud values\n }\n\n public toJson(): JwtPayloadJson {\n return {\n ...this.additionalClaims,\n iss: this.iss,\n sub: this.sub,\n aud: this.aud,\n exp: this.exp,\n nbf: this.nbf,\n iat: this.iat,\n jti: this.jti,\n }\n }\n\n public static fromJson(jwtPayloadJson: JwtPayloadJson) {\n const { iss, sub, aud, exp, nbf, iat, jti, ...additionalClaims } = jwtPayloadJson\n\n // Validate iss\n if (iss && typeof iss !== 'string') {\n throw new CredoError('JWT payload iss must be a string')\n }\n\n // Validate sub\n if (sub && typeof sub !== 'string') {\n throw new CredoError('JWT payload sub must be a string')\n }\n\n // Validate aud\n if (aud && typeof aud !== 'string' && !(Array.isArray(aud) && aud.every((aud) => typeof aud === 'string'))) {\n throw new CredoError('JWT payload aud must be a string or an array of strings')\n }\n\n // Validate exp\n if (exp && (typeof exp !== 'number' || exp < 0)) {\n throw new CredoError('JWT payload exp must be a positive number')\n }\n\n // Validate nbf\n if (nbf && (typeof nbf !== 'number' || nbf < 0)) {\n throw new CredoError('JWT payload nbf must be a positive number')\n }\n\n // Validate iat\n if (iat && (typeof iat !== 'number' || iat < 0)) {\n throw new CredoError('JWT payload iat must be a positive number')\n }\n\n // Validate jti\n if (jti && typeof jti !== 'string') {\n throw new CredoError('JWT payload jti must be a string')\n }\n\n const jwtPayload = new JwtPayload({\n iss,\n sub,\n aud,\n exp,\n nbf,\n iat,\n jti,\n additionalClaims,\n })\n\n return jwtPayload\n }\n}\n\nfunction getNowSkewed(now?: number, skewSeconds?: number) {\n const _now = now ?? dateToSeconds(new Date())\n const _skewSeconds = skewSeconds ?? DEFAULT_SKEW_TIME\n\n return {\n nowSkewedPast: _now - _skewSeconds,\n nowSkewedFuture: _now + _skewSeconds,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAa,oBAAoB;AAwBjC,IAAa,aAAb,MAAa,WAAW;CACtB,AAAO,YAAY,SAA6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OAAO,OAAO,QAAQ,SACxB,OAAM,IAAI,WAAW,mCAAmC;AAI1D,MAAI,OAAO,OAAO,QAAQ,SACxB,OAAM,IAAI,WAAW,mCAAmC;AAI1D,MAAI,OAAO,OAAO,QAAQ,YAAY,EAAE,MAAM,QAAQ,IAAI,IAAI,IAAI,OAAO,UAAQ,OAAOA,UAAQ,SAAS,EACvG,OAAM,IAAI,WAAW,0DAA0D;AAIjF,MAAI,QAAQ,OAAO,QAAQ,YAAY,MAAM,GAC3C,OAAM,IAAI,WAAW,4CAA4C;AAInE,MAAI,QAAQ,OAAO,QAAQ,YAAY,MAAM,GAC3C,OAAM,IAAI,WAAW,4CAA4C;AAInE,MAAI,QAAQ,OAAO,QAAQ,YAAY,MAAM,GAC3C,OAAM,IAAI,WAAW,4CAA4C;AAInE,MAAI,OAAO,OAAO,QAAQ,SACxB,OAAM,IAAI,WAAW,mCAAmC;AAc1D,SAXmB,IAAI,WAAW;GAChC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;;;AAMN,SAAS,aAAa,KAAc,aAAsB;CACxD,MAAM,OAAO,OAAO,8BAAc,IAAI,MAAM,CAAC;CAC7C,MAAM,eAAe,eAAe;AAEpC,QAAO;EACL,eAAe,OAAO;EACtB,iBAAiB,OAAO;EACzB"}
|
package/build/index.mjs
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import 'reflect-metadata'
|
|
3
3
|
import { InjectionSymbols } from "./constants.mjs";
|
|
4
|
-
import { LogLevel } from "./logger/Logger.mjs";
|
|
5
|
-
import { BaseLogger } from "./logger/BaseLogger.mjs";
|
|
6
|
-
import { replaceError } from "./logger/replaceError.mjs";
|
|
7
|
-
import { ConsoleLogger } from "./logger/ConsoleLogger.mjs";
|
|
8
|
-
import { AgentConfig } from "./agent/AgentConfig.mjs";
|
|
9
|
-
import { AgentContext } from "./agent/context/AgentContext.mjs";
|
|
10
4
|
import { CredoError } from "./error/CredoError.mjs";
|
|
11
5
|
import { ClassValidationError } from "./error/ClassValidationError.mjs";
|
|
12
6
|
import { RecordDuplicateError } from "./error/RecordDuplicateError.mjs";
|
|
13
7
|
import { RecordNotFoundError } from "./error/RecordNotFoundError.mjs";
|
|
14
8
|
import { ZodValidationError } from "./error/ZodValidationError.mjs";
|
|
15
9
|
import "./error/index.mjs";
|
|
16
|
-
import { DependencyManager } from "./plugins/DependencyManager.mjs";
|
|
17
|
-
import { getApiForModuleByName, getRegisteredModuleByInstance, getRegisteredModuleByName } from "./plugins/utils.mjs";
|
|
18
|
-
import { inject, injectAll, injectable } from "./plugins/index.mjs";
|
|
19
|
-
import { DefaultAgentContextProvider } from "./agent/context/DefaultAgentContextProvider.mjs";
|
|
20
|
-
import "./agent/index.mjs";
|
|
21
10
|
import { asArray } from "./utils/array.mjs";
|
|
22
11
|
import { Buffer } from "./utils/buffer.mjs";
|
|
23
12
|
import { areObjectsEqual } from "./utils/objectEquality.mjs";
|
|
@@ -40,6 +29,18 @@ import { Metadata } from "./storage/Metadata.mjs";
|
|
|
40
29
|
import { DateTransformer, IsStringOrStringArray } from "./utils/transformers.mjs";
|
|
41
30
|
import { IsStringOrInstance, IsStringOrInstanceOrArrayOfInstances, IsUri } from "./utils/validators.mjs";
|
|
42
31
|
import "./utils/index.mjs";
|
|
32
|
+
import { JwtPayload } from "./crypto/jose/jwt/JwtPayload.mjs";
|
|
33
|
+
import { LogLevel } from "./logger/Logger.mjs";
|
|
34
|
+
import { BaseLogger } from "./logger/BaseLogger.mjs";
|
|
35
|
+
import { replaceError } from "./logger/replaceError.mjs";
|
|
36
|
+
import { ConsoleLogger } from "./logger/ConsoleLogger.mjs";
|
|
37
|
+
import { AgentConfig } from "./agent/AgentConfig.mjs";
|
|
38
|
+
import { AgentContext } from "./agent/context/AgentContext.mjs";
|
|
39
|
+
import { DependencyManager } from "./plugins/DependencyManager.mjs";
|
|
40
|
+
import { getApiForModuleByName, getRegisteredModuleByInstance, getRegisteredModuleByName } from "./plugins/utils.mjs";
|
|
41
|
+
import { inject, injectAll, injectable } from "./plugins/index.mjs";
|
|
42
|
+
import { DefaultAgentContextProvider } from "./agent/context/DefaultAgentContextProvider.mjs";
|
|
43
|
+
import "./agent/index.mjs";
|
|
43
44
|
import { kms_exports } from "./modules/kms/index.mjs";
|
|
44
45
|
import { CredoWebCryptoKey } from "./crypto/webcrypto/CredoWebCryptoKey.mjs";
|
|
45
46
|
import { publicJwkToCryptoKeyAlgorithm } from "./crypto/webcrypto/utils/keyAlgorithmConversion.mjs";
|
|
@@ -55,7 +56,6 @@ import { X509Api } from "./modules/x509/X509Api.mjs";
|
|
|
55
56
|
import { X509Module } from "./modules/x509/X509Module.mjs";
|
|
56
57
|
import "./modules/x509/index.mjs";
|
|
57
58
|
import { isJsonObject, isNonEmptyArray, mapNonEmptyArray } from "./types.mjs";
|
|
58
|
-
import { JwtPayload } from "./crypto/jose/jwt/JwtPayload.mjs";
|
|
59
59
|
import { Jwt } from "./crypto/jose/jwt/Jwt.mjs";
|
|
60
60
|
import { JwsService } from "./crypto/JwsService.mjs";
|
|
61
61
|
import { BaseRecord } from "./storage/BaseRecord.mjs";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
import { InjectionSymbols } from "../../constants.mjs";
|
|
4
|
+
import { JsonTransformer } from "../../utils/JsonTransformer.mjs";
|
|
5
|
+
import "../../utils/index.mjs";
|
|
4
6
|
import { inject, injectable } from "../../plugins/index.mjs";
|
|
5
7
|
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
8
|
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
9
|
import "../../agent/index.mjs";
|
|
8
|
-
import { JsonTransformer } from "../../utils/JsonTransformer.mjs";
|
|
9
|
-
import "../../utils/index.mjs";
|
|
10
10
|
import "../../storage/BaseRecord.mjs";
|
|
11
11
|
import { __decorateParam } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs";
|
|
12
12
|
import { CacheModuleConfig } from "./CacheModuleConfig.mjs";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
4
3
|
import { asArray } from "../../utils/array.mjs";
|
|
5
4
|
import { TypedArrayEncoder } from "../../utils/TypedArrayEncoder.mjs";
|
|
6
5
|
import "../../utils/index.mjs";
|
|
6
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { X509Certificate } from "../x509/X509Certificate.mjs";
|
|
8
8
|
import "../x509/index.mjs";
|
|
9
9
|
import { isNonEmptyArray, mapNonEmptyArray } from "../../types.mjs";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { AgentContext } from "../../agent/context/AgentContext.mjs";
|
|
4
3
|
import { CredoError } from "../../error/CredoError.mjs";
|
|
5
4
|
import { RecordNotFoundError } from "../../error/RecordNotFoundError.mjs";
|
|
6
5
|
import "../../error/index.mjs";
|
|
6
|
+
import { AgentContext } from "../../agent/context/AgentContext.mjs";
|
|
7
7
|
import { injectable } from "../../plugins/index.mjs";
|
|
8
8
|
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
9
9
|
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../error/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
-
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
5
|
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
|
|
8
6
|
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
|
|
9
7
|
import { IsStringOrStringArray } from "../../../utils/transformers.mjs";
|
|
10
8
|
import "../../../utils/index.mjs";
|
|
9
|
+
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
10
|
+
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
11
11
|
import { X25519PublicJwk } from "../../kms/jwk/kty/okp/X25519PublicJwk.mjs";
|
|
12
12
|
import { Ed25519PublicJwk } from "../../kms/jwk/kty/okp/Ed25519PublicJwk.mjs";
|
|
13
13
|
import { PublicJwk } from "../../kms/jwk/PublicJwk.mjs";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
3
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
4
|
import "../../../../utils/index.mjs";
|
|
5
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { getProtocolScheme } from "../../../../utils/uri.mjs";
|
|
8
8
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
9
9
|
import { ArrayNotEmpty, IsOptional, IsString } from "class-validator";
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../../error/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
5
|
import { IsInstanceOrArrayOfInstances, IsUri } from "../../../../utils/validators.mjs";
|
|
8
6
|
import "../../../../utils/index.mjs";
|
|
7
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
8
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
9
9
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
10
10
|
import { Type } from "class-transformer";
|
|
11
11
|
import { IsOptional, IsString, ValidateNested } from "class-validator";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
3
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
4
|
import "../../../../utils/index.mjs";
|
|
5
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { getProtocolScheme } from "../../../../utils/uri.mjs";
|
|
8
8
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
9
9
|
import { ArrayNotEmpty, IsOptional, IsString } from "class-validator";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
4
|
-
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
5
3
|
import { IsUri } from "../../../../utils/validators.mjs";
|
|
6
4
|
import "../../../../utils/index.mjs";
|
|
5
|
+
import { __decorateMetadata } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
+
import { __decorate } from "../../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
7
|
import { DidDocumentService } from "./DidDocumentService.mjs";
|
|
8
8
|
import { DidCommV2Service, DidCommV2ServiceEndpoint } from "./DidCommV2Service.mjs";
|
|
9
9
|
import { IsOptional, IsString } from "class-validator";
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import { InjectionSymbols } from "../../../constants.mjs";
|
|
4
4
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
5
5
|
import "../../../error/index.mjs";
|
|
6
|
+
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
|
|
7
|
+
import "../../../utils/index.mjs";
|
|
6
8
|
import { inject, injectable } from "../../../plugins/index.mjs";
|
|
7
9
|
import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
8
10
|
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
9
|
-
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
|
|
10
|
-
import "../../../utils/index.mjs";
|
|
11
11
|
import { parseDid } from "../domain/parse.mjs";
|
|
12
12
|
import { DidDocument } from "../domain/DidDocument.mjs";
|
|
13
13
|
import "../domain/index.mjs";
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../error/CredoError.mjs";
|
|
4
4
|
import "../../error/index.mjs";
|
|
5
|
-
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
6
|
-
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
7
5
|
import { JsonTransformer } from "../../utils/JsonTransformer.mjs";
|
|
8
6
|
import "../../utils/index.mjs";
|
|
7
|
+
import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
|
|
8
|
+
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
|
|
9
9
|
import { getJwkHumanDescription } from "../kms/jwk/humanDescription.mjs";
|
|
10
10
|
import "../kms/index.mjs";
|
|
11
11
|
import { getPublicJwkFromVerificationMethod } from "../dids/domain/key-type/keyDidMapping.mjs";
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { CredoError } from "../../../error/CredoError.mjs";
|
|
4
4
|
import "../../../error/index.mjs";
|
|
5
|
-
import { KeyManagementError } from "../error/KeyManagementError.mjs";
|
|
6
5
|
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
|
|
7
6
|
import { MultiBaseEncoder } from "../../../utils/MultiBaseEncoder.mjs";
|
|
8
7
|
import { VarintEncoder } from "../../../utils/VarintEncoder.mjs";
|
|
9
8
|
import "../../../utils/index.mjs";
|
|
9
|
+
import { KeyManagementError } from "../error/KeyManagementError.mjs";
|
|
10
10
|
import { getJwkHumanDescription } from "./humanDescription.mjs";
|
|
11
11
|
import { asymmetricPublicJwkMatches } from "./equals.mjs";
|
|
12
12
|
import { zParseWithErrorHandling } from "../../../utils/zod.mjs";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { KeyManagementError } from "../../error/KeyManagementError.mjs";
|
|
4
3
|
import { TypedArrayEncoder } from "../../../../utils/TypedArrayEncoder.mjs";
|
|
5
4
|
import "../../../../utils/index.mjs";
|
|
5
|
+
import { KeyManagementError } from "../../error/KeyManagementError.mjs";
|
|
6
6
|
import { getJwkHumanDescription } from "../humanDescription.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/kms/jwk/alg/encryption.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { KeyManagementError } from "../../error/KeyManagementError.mjs";
|
|
4
3
|
import { TypedArrayEncoder } from "../../../../utils/TypedArrayEncoder.mjs";
|
|
5
4
|
import "../../../../utils/index.mjs";
|
|
5
|
+
import { KeyManagementError } from "../../error/KeyManagementError.mjs";
|
|
6
6
|
import { getJwkHumanDescription } from "../humanDescription.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/kms/jwk/alg/signing.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { KeyManagementError } from "../../../error/KeyManagementError.mjs";
|
|
4
3
|
import { TypedArrayEncoder } from "../../../../../utils/TypedArrayEncoder.mjs";
|
|
5
4
|
import "../../../../../utils/index.mjs";
|
|
5
|
+
import { KeyManagementError } from "../../../error/KeyManagementError.mjs";
|
|
6
6
|
import { AffinePoint, Secp256k1, Secp256r1, Secp384r1, Secp521r1, isValidCompressedPublicKeyFormat, isValidDecompressedPublicKeyFormat } from "ec-compression";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/kms/jwk/kty/ec/ecPublicKey.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { KeyManagementError } from "../../../error/KeyManagementError.mjs";
|
|
4
3
|
import { TypedArrayEncoder } from "../../../../../utils/TypedArrayEncoder.mjs";
|
|
5
4
|
import "../../../../../utils/index.mjs";
|
|
5
|
+
import { KeyManagementError } from "../../../error/KeyManagementError.mjs";
|
|
6
6
|
import { rsaPublicJwkToPublicKey, rsaPublicKeyToPublicJwk } from "./rsaPublicKey.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/kms/jwk/kty/rsa/RsaPublicJwk.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { KeyManagementError } from "./error/KeyManagementError.mjs";
|
|
4
3
|
import { TypedArrayEncoder } from "../../utils/TypedArrayEncoder.mjs";
|
|
5
4
|
import "../../utils/index.mjs";
|
|
5
|
+
import { KeyManagementError } from "./error/KeyManagementError.mjs";
|
|
6
6
|
import "./jwk/index.mjs";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/kms/legacy.ts
|
|
@@ -15,7 +15,7 @@ import { ClaimFormat } from "../vc/models/ClaimFormat.mjs";
|
|
|
15
15
|
import "../vc/index.mjs";
|
|
16
16
|
import { getMdocContext } from "./MdocContext.mjs";
|
|
17
17
|
import { MdocError } from "./MdocError.mjs";
|
|
18
|
-
import { isMdocSupportedSignatureAlgorithm,
|
|
18
|
+
import { isMdocSupportedSignatureAlgorithm, mdocSupportedSignatureAlgorithms } from "./mdocSupportedAlgs.mjs";
|
|
19
19
|
import { COSEKey, DeviceSignedDocument, Document, Verifier, cborEncode, parseDeviceSigned, parseIssuerSigned } from "@animo-id/mdoc";
|
|
20
20
|
|
|
21
21
|
//#region src/modules/mdoc/Mdoc.ts
|
|
@@ -101,7 +101,7 @@ var Mdoc = class Mdoc {
|
|
|
101
101
|
for (const [namespace, namespaceRecord] of Object.entries(namespaces)) document.addIssuerNameSpace(namespace, namespaceRecord);
|
|
102
102
|
const issuerKey = issuerCertificate.publicJwk;
|
|
103
103
|
const alg = issuerKey.supportedSignatureAlgorithms.find(isMdocSupportedSignatureAlgorithm);
|
|
104
|
-
if (!alg) throw new MdocError(`Unable to create sign mdoc. No supported signature algorithm found to sign mdoc for jwk with key ${issuerKey.jwkTypeHumanDescription}. Key supports algs ${issuerKey.supportedSignatureAlgorithms.join(", ")}. mdoc supports algs ${
|
|
104
|
+
if (!alg) throw new MdocError(`Unable to create sign mdoc. No supported signature algorithm found to sign mdoc for jwk with key ${issuerKey.jwkTypeHumanDescription}. Key supports algs ${issuerKey.supportedSignatureAlgorithms.join(", ")}. mdoc supports algs ${mdocSupportedSignatureAlgorithms.join(", ")}`);
|
|
105
105
|
return new Mdoc(await document.sign({
|
|
106
106
|
issuerPrivateKey: issuerKey.toJson(),
|
|
107
107
|
alg,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mdoc.mjs","names":["issuerSignedDocument: IssuerSignedDocument | DeviceSignedDocument"],"sources":["../../../src/modules/mdoc/Mdoc.ts"],"sourcesContent":["import type { IssuerSignedDocument } from '@animo-id/mdoc'\nimport {\n COSEKey,\n cborEncode,\n DeviceSignedDocument,\n Document,\n parseDeviceSigned,\n parseIssuerSigned,\n Verifier,\n} from '@animo-id/mdoc'\nimport type { AgentContext } from '../../agent'\nimport { TypedArrayEncoder } from './../../utils'\nimport { type KnownJwaSignatureAlgorithm, PublicJwk } from '../kms'\nimport { isKnownJwaSignatureAlgorithm } from '../kms/jwk/jwa'\nimport { ClaimFormat } from '../vc/index'\nimport { X509Certificate, X509ModuleConfig } from '../x509'\nimport { getMdocContext } from './MdocContext'\nimport { MdocError } from './MdocError'\nimport type { MdocNameSpaces, MdocSignOptions, MdocVerifyOptions } from './MdocOptions'\nimport { isMdocSupportedSignatureAlgorithm, mdocSupporteSignatureAlgorithms } from './mdocSupportedAlgs'\n\n/**\n * This class represents a IssuerSigned Mdoc Document,\n * which are the actual credentials being issued to holders.\n */\nexport class Mdoc {\n public base64Url: string\n #deviceKeyId?: string\n\n private constructor(public issuerSignedDocument: IssuerSignedDocument | DeviceSignedDocument) {\n const issuerSigned = issuerSignedDocument.prepare().get('issuerSigned')\n this.base64Url = TypedArrayEncoder.toBase64URL(cborEncode(issuerSigned))\n }\n\n /**\n * claim format is convenience method added to all credential instances\n */\n public get claimFormat() {\n return ClaimFormat.MsoMdoc as const\n }\n\n /**\n * Encoded is convenience method added to all credential instances\n */\n public get encoded() {\n return this.base64Url\n }\n\n /**\n * Get the device key to which the mdoc is bound\n */\n public get deviceKey(): PublicJwk {\n const deviceKeyRaw = this.issuerSignedDocument.issuerSigned.issuerAuth.decodedPayload.deviceKeyInfo?.deviceKey\n if (!deviceKeyRaw) throw new MdocError('Could not extract device key from mdoc')\n\n const publicJwk = PublicJwk.fromUnknown(COSEKey.import(deviceKeyRaw).toJWK())\n if (this.#deviceKeyId) publicJwk.keyId = this.#deviceKeyId\n return publicJwk\n }\n\n public set deviceKeyId(keyId: string | undefined) {\n this.#deviceKeyId = keyId\n }\n\n public get deviceKeyId() {\n const deviceKey = this.deviceKey\n\n if (deviceKey.hasKeyId) return deviceKey.keyId\n return undefined\n }\n\n public static fromBase64Url(mdocBase64Url: string, expectedDocType?: string): Mdoc {\n const issuerSignedDocument = parseIssuerSigned(TypedArrayEncoder.fromBase64(mdocBase64Url), expectedDocType)\n return new Mdoc(issuerSignedDocument)\n }\n\n public static fromIssuerSignedDocument(issuerSignedBase64Url: string, expectedDocType?: string): Mdoc {\n return new Mdoc(parseIssuerSigned(TypedArrayEncoder.fromBase64(issuerSignedBase64Url), expectedDocType))\n }\n\n public static fromDeviceSignedDocument(\n issuerSignedBase64Url: string,\n deviceSignedBase64Url: string,\n expectedDocType?: string\n ): Mdoc {\n return new Mdoc(\n parseDeviceSigned(\n TypedArrayEncoder.fromBase64(deviceSignedBase64Url),\n TypedArrayEncoder.fromBase64(issuerSignedBase64Url),\n expectedDocType\n )\n )\n }\n\n public get docType(): string {\n return this.issuerSignedDocument.docType\n }\n\n public get alg(): KnownJwaSignatureAlgorithm {\n const algName = this.issuerSignedDocument.issuerSigned.issuerAuth.algName\n if (!algName) {\n throw new MdocError('Cannot extract the signature algorithm from the mdoc.')\n }\n if (isKnownJwaSignatureAlgorithm(algName)) {\n return algName\n }\n\n throw new MdocError(`Cannot parse mdoc. The signature algorithm '${algName}' is not supported.`)\n }\n\n public get validityInfo() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.decodedPayload.validityInfo\n }\n\n public get deviceSignedNamespaces(): MdocNameSpaces | null {\n if (this.issuerSignedDocument instanceof DeviceSignedDocument === false) {\n return null\n }\n\n return Object.fromEntries(\n Array.from(this.issuerSignedDocument.allDeviceSignedNamespaces.entries()).map(([namespace, value]) => [\n namespace,\n Object.fromEntries(Array.from(value.entries())),\n ])\n )\n }\n\n public get issuerSignedCertificateChain() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.certificateChain\n }\n\n public get signingCertificate() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.certificate\n }\n\n public get issuerSignedNamespaces(): MdocNameSpaces {\n return Object.fromEntries(\n Array.from(this.issuerSignedDocument.allIssuerSignedNamespaces.entries()).map(([namespace, value]) => [\n namespace,\n Object.fromEntries(Array.from(value.entries())),\n ])\n )\n }\n\n public static async sign(agentContext: AgentContext, options: MdocSignOptions) {\n const { docType, validityInfo, namespaces, holderKey, issuerCertificate } = options\n const mdocContext = getMdocContext(agentContext)\n\n const document = new Document(docType, mdocContext)\n .useDigestAlgorithm('SHA-256')\n .addValidityInfo(validityInfo)\n .addDeviceKeyInfo({ deviceKey: holderKey.toJson() })\n\n for (const [namespace, namespaceRecord] of Object.entries(namespaces)) {\n document.addIssuerNameSpace(namespace, namespaceRecord)\n }\n\n const issuerKey = issuerCertificate.publicJwk\n const alg = issuerKey.supportedSignatureAlgorithms.find(isMdocSupportedSignatureAlgorithm)\n if (!alg) {\n throw new MdocError(\n `Unable to create sign mdoc. No supported signature algorithm found to sign mdoc for jwk with key ${\n issuerKey.jwkTypeHumanDescription\n }. Key supports algs ${issuerKey.supportedSignatureAlgorithms.join(\n ', '\n )}. mdoc supports algs ${mdocSupporteSignatureAlgorithms.join(', ')}`\n )\n }\n\n const issuerSignedDocument = await document.sign(\n {\n issuerPrivateKey: issuerKey.toJson(),\n alg,\n issuerCertificate: issuerCertificate.rawCertificate,\n },\n mdocContext\n )\n\n return new Mdoc(issuerSignedDocument)\n }\n\n public async verify(\n agentContext: AgentContext,\n options?: MdocVerifyOptions\n ): Promise<{ isValid: true } | { isValid: false; error: string }> {\n const x509ModuleConfig = agentContext.dependencyManager.resolve(X509ModuleConfig)\n const certificateChain = this.issuerSignedDocument.issuerSigned.issuerAuth.certificateChain.map((certificate) =>\n X509Certificate.fromRawCertificate(certificate)\n )\n\n let trustedCertificates = options?.trustedCertificates\n if (!trustedCertificates) {\n trustedCertificates =\n (await x509ModuleConfig.getTrustedCertificatesForVerification?.(agentContext, {\n verification: {\n type: 'credential',\n credential: this,\n },\n certificateChain,\n })) ?? x509ModuleConfig.trustedCertificates\n }\n\n if (!trustedCertificates) {\n throw new MdocError('No trusted certificates found. Cannot verify mdoc.')\n }\n\n const mdocContext = getMdocContext(agentContext)\n try {\n const verifier = new Verifier()\n await verifier.verifyIssuerSignature(\n {\n trustedCertificates: trustedCertificates.map(\n (cert) => X509Certificate.fromEncodedCertificate(cert).rawCertificate\n ),\n issuerAuth: this.issuerSignedDocument.issuerSigned.issuerAuth,\n disableCertificateChainValidation: false,\n now: options?.now,\n },\n mdocContext\n )\n\n await verifier.verifyData({ mdoc: this.issuerSignedDocument }, mdocContext)\n return { isValid: true }\n } catch (error) {\n return { isValid: false, error: error.message }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,OAAb,MAAa,KAAK;CAIhB,AAAQ,YAAY,AAAOA,sBAAmE;EAAnE;;EACzB,MAAM,eAAe,qBAAqB,SAAS,CAAC,IAAI,eAAe;AACvE,OAAK,YAAY,kBAAkB,YAAY,WAAW,aAAa,CAAC;;;;;CAM1E,IAAW,cAAc;AACvB,SAAO,YAAY;;;;;CAMrB,IAAW,UAAU;AACnB,SAAO,KAAK;;;;;CAMd,IAAW,YAAuB;EAChC,MAAM,eAAe,KAAK,qBAAqB,aAAa,WAAW,eAAe,eAAe;AACrG,MAAI,CAAC,aAAc,OAAM,IAAI,UAAU,yCAAyC;EAEhF,MAAM,YAAY,UAAU,YAAY,QAAQ,OAAO,aAAa,CAAC,OAAO,CAAC;AAC7E,2CAAI,KAAiB,CAAE,WAAU,6CAAQ,KAAiB;AAC1D,SAAO;;CAGT,IAAW,YAAY,OAA2B;AAChD,6CAAoB,MAAK;;CAG3B,IAAW,cAAc;EACvB,MAAM,YAAY,KAAK;AAEvB,M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KACtC,SAAS,gBAAgB,uBAAuB,KAAK,CAAC,eACxD;IACD,YAAY,KAAK,qBAAqB,aAAa;IACnD,mCAAmC;IACnC,KAAK,SAAS;IACf,EACD,YACD;AAED,SAAM,SAAS,WAAW,EAAE,MAAM,KAAK,sBAAsB,EAAE,YAAY;AAC3E,UAAO,EAAE,SAAS,MAAM;WACjB,OAAO;AACd,UAAO;IAAE,SAAS;IAAO,OAAO,MAAM;IAAS"}
|
|
1
|
+
{"version":3,"file":"Mdoc.mjs","names":["issuerSignedDocument: IssuerSignedDocument | DeviceSignedDocument"],"sources":["../../../src/modules/mdoc/Mdoc.ts"],"sourcesContent":["import type { IssuerSignedDocument } from '@animo-id/mdoc'\nimport {\n COSEKey,\n cborEncode,\n DeviceSignedDocument,\n Document,\n parseDeviceSigned,\n parseIssuerSigned,\n Verifier,\n} from '@animo-id/mdoc'\nimport type { AgentContext } from '../../agent'\nimport { TypedArrayEncoder } from './../../utils'\nimport { type KnownJwaSignatureAlgorithm, PublicJwk } from '../kms'\nimport { isKnownJwaSignatureAlgorithm } from '../kms/jwk/jwa'\nimport { ClaimFormat } from '../vc/index'\nimport { X509Certificate, X509ModuleConfig } from '../x509'\nimport { getMdocContext } from './MdocContext'\nimport { MdocError } from './MdocError'\nimport type { MdocNameSpaces, MdocSignOptions, MdocVerifyOptions } from './MdocOptions'\nimport { isMdocSupportedSignatureAlgorithm, mdocSupportedSignatureAlgorithms } from './mdocSupportedAlgs'\n\n/**\n * This class represents a IssuerSigned Mdoc Document,\n * which are the actual credentials being issued to holders.\n */\nexport class Mdoc {\n public base64Url: string\n #deviceKeyId?: string\n\n private constructor(public issuerSignedDocument: IssuerSignedDocument | DeviceSignedDocument) {\n const issuerSigned = issuerSignedDocument.prepare().get('issuerSigned')\n this.base64Url = TypedArrayEncoder.toBase64URL(cborEncode(issuerSigned))\n }\n\n /**\n * claim format is convenience method added to all credential instances\n */\n public get claimFormat() {\n return ClaimFormat.MsoMdoc as const\n }\n\n /**\n * Encoded is convenience method added to all credential instances\n */\n public get encoded() {\n return this.base64Url\n }\n\n /**\n * Get the device key to which the mdoc is bound\n */\n public get deviceKey(): PublicJwk {\n const deviceKeyRaw = this.issuerSignedDocument.issuerSigned.issuerAuth.decodedPayload.deviceKeyInfo?.deviceKey\n if (!deviceKeyRaw) throw new MdocError('Could not extract device key from mdoc')\n\n const publicJwk = PublicJwk.fromUnknown(COSEKey.import(deviceKeyRaw).toJWK())\n if (this.#deviceKeyId) publicJwk.keyId = this.#deviceKeyId\n return publicJwk\n }\n\n public set deviceKeyId(keyId: string | undefined) {\n this.#deviceKeyId = keyId\n }\n\n public get deviceKeyId() {\n const deviceKey = this.deviceKey\n\n if (deviceKey.hasKeyId) return deviceKey.keyId\n return undefined\n }\n\n public static fromBase64Url(mdocBase64Url: string, expectedDocType?: string): Mdoc {\n const issuerSignedDocument = parseIssuerSigned(TypedArrayEncoder.fromBase64(mdocBase64Url), expectedDocType)\n return new Mdoc(issuerSignedDocument)\n }\n\n public static fromIssuerSignedDocument(issuerSignedBase64Url: string, expectedDocType?: string): Mdoc {\n return new Mdoc(parseIssuerSigned(TypedArrayEncoder.fromBase64(issuerSignedBase64Url), expectedDocType))\n }\n\n public static fromDeviceSignedDocument(\n issuerSignedBase64Url: string,\n deviceSignedBase64Url: string,\n expectedDocType?: string\n ): Mdoc {\n return new Mdoc(\n parseDeviceSigned(\n TypedArrayEncoder.fromBase64(deviceSignedBase64Url),\n TypedArrayEncoder.fromBase64(issuerSignedBase64Url),\n expectedDocType\n )\n )\n }\n\n public get docType(): string {\n return this.issuerSignedDocument.docType\n }\n\n public get alg(): KnownJwaSignatureAlgorithm {\n const algName = this.issuerSignedDocument.issuerSigned.issuerAuth.algName\n if (!algName) {\n throw new MdocError('Cannot extract the signature algorithm from the mdoc.')\n }\n if (isKnownJwaSignatureAlgorithm(algName)) {\n return algName\n }\n\n throw new MdocError(`Cannot parse mdoc. The signature algorithm '${algName}' is not supported.`)\n }\n\n public get validityInfo() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.decodedPayload.validityInfo\n }\n\n public get deviceSignedNamespaces(): MdocNameSpaces | null {\n if (this.issuerSignedDocument instanceof DeviceSignedDocument === false) {\n return null\n }\n\n return Object.fromEntries(\n Array.from(this.issuerSignedDocument.allDeviceSignedNamespaces.entries()).map(([namespace, value]) => [\n namespace,\n Object.fromEntries(Array.from(value.entries())),\n ])\n )\n }\n\n public get issuerSignedCertificateChain() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.certificateChain\n }\n\n public get signingCertificate() {\n return this.issuerSignedDocument.issuerSigned.issuerAuth.certificate\n }\n\n public get issuerSignedNamespaces(): MdocNameSpaces {\n return Object.fromEntries(\n Array.from(this.issuerSignedDocument.allIssuerSignedNamespaces.entries()).map(([namespace, value]) => [\n namespace,\n Object.fromEntries(Array.from(value.entries())),\n ])\n )\n }\n\n public static async sign(agentContext: AgentContext, options: MdocSignOptions) {\n const { docType, validityInfo, namespaces, holderKey, issuerCertificate } = options\n const mdocContext = getMdocContext(agentContext)\n\n const document = new Document(docType, mdocContext)\n .useDigestAlgorithm('SHA-256')\n .addValidityInfo(validityInfo)\n .addDeviceKeyInfo({ deviceKey: holderKey.toJson() })\n\n for (const [namespace, namespaceRecord] of Object.entries(namespaces)) {\n document.addIssuerNameSpace(namespace, namespaceRecord)\n }\n\n const issuerKey = issuerCertificate.publicJwk\n const alg = issuerKey.supportedSignatureAlgorithms.find(isMdocSupportedSignatureAlgorithm)\n if (!alg) {\n throw new MdocError(\n `Unable to create sign mdoc. No supported signature algorithm found to sign mdoc for jwk with key ${\n issuerKey.jwkTypeHumanDescription\n }. Key supports algs ${issuerKey.supportedSignatureAlgorithms.join(\n ', '\n )}. mdoc supports algs ${mdocSupportedSignatureAlgorithms.join(', ')}`\n )\n }\n\n const issuerSignedDocument = await document.sign(\n {\n issuerPrivateKey: issuerKey.toJson(),\n alg,\n issuerCertificate: issuerCertificate.rawCertificate,\n },\n mdocContext\n )\n\n return new Mdoc(issuerSignedDocument)\n }\n\n public async verify(\n agentContext: AgentContext,\n options?: MdocVerifyOptions\n ): Promise<{ isValid: true } | { isValid: false; error: string }> {\n const x509ModuleConfig = agentContext.dependencyManager.resolve(X509ModuleConfig)\n const certificateChain = this.issuerSignedDocument.issuerSigned.issuerAuth.certificateChain.map((certificate) =>\n X509Certificate.fromRawCertificate(certificate)\n )\n\n let trustedCertificates = options?.trustedCertificates\n if (!trustedCertificates) {\n trustedCertificates =\n (await x509ModuleConfig.getTrustedCertificatesForVerification?.(agentContext, {\n verification: {\n type: 'credential',\n credential: this,\n },\n certificateChain,\n })) ?? x509ModuleConfig.trustedCertificates\n }\n\n if (!trustedCertificates) {\n throw new MdocError('No trusted certificates found. Cannot verify mdoc.')\n }\n\n const mdocContext = getMdocContext(agentContext)\n try {\n const verifier = new Verifier()\n await verifier.verifyIssuerSignature(\n {\n trustedCertificates: trustedCertificates.map(\n (cert) => X509Certificate.fromEncodedCertificate(cert).rawCertificate\n ),\n issuerAuth: this.issuerSignedDocument.issuerSigned.issuerAuth,\n disableCertificateChainValidation: false,\n now: options?.now,\n },\n mdocContext\n )\n\n await verifier.verifyData({ mdoc: this.issuerSignedDocument }, mdocContext)\n return { isValid: true }\n } catch (error) {\n return { isValid: false, error: error.message }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,OAAb,MAAa,KAAK;CAIhB,AAAQ,YAAY,AAAOA,sBAAmE;EAAnE;;EACzB,MAAM,eAAe,qBAAqB,SAAS,CAAC,IAAI,eAAe;AACvE,OAAK,YAAY,kBAAkB,YAAY,WAAW,aAAa,CAAC;;;;;CAM1E,IAAW,cAAc;AACvB,SAAO,YAAY;;;;;CAMrB,IAAW,UAAU;AACnB,SAAO,KAAK;;;;;CAMd,IAAW,YAAuB;EAChC,MAAM,eAAe,KAAK,qBAAqB,aAAa,WAAW,eAAe,eAAe;AACrG,MAAI,CAAC,aAAc,OAAM,IAAI,UAAU,yCAAyC;EA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