@credo-ts/core 0.8.0-alpha-20261020190607 → 0.8.0-alpha-20261021192900
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/crypto/webcrypto/CredoWalletWebCrypto.d.mts +1 -1
- package/build/modules/dids/domain/verificationMethod/JsonWebKey2020.d.mts +24 -24
- package/build/modules/dids/methods/jwk/DidJwk.d.mts +24 -24
- package/build/modules/dif-presentation-exchange/DifPresentationExchangeService.d.mts +1 -1
- package/build/modules/dif-presentation-exchange/DifPresentationExchangeService.d.mts.map +1 -1
- package/build/modules/kms/KeyManagementApi.d.mts +14 -14
- package/build/modules/kms/KeyManagementApi.d.mts.map +1 -1
- package/build/modules/kms/KeyManagementApi.mjs +7 -2
- package/build/modules/kms/KeyManagementApi.mjs.map +1 -1
- package/build/modules/kms/index.d.mts +6 -6
- package/build/modules/kms/index.mjs +3 -2
- package/build/modules/kms/jwk/alg/keyDerivation.d.mts.map +1 -1
- package/build/modules/kms/jwk/alg/keyDerivation.mjs +5 -0
- package/build/modules/kms/jwk/alg/keyDerivation.mjs.map +1 -1
- package/build/modules/kms/jwk/assertSupported.d.mts +1 -1
- package/build/modules/kms/jwk/jwa.d.mts +3 -1
- package/build/modules/kms/jwk/jwa.d.mts.map +1 -1
- package/build/modules/kms/jwk/jwa.mjs +1 -0
- package/build/modules/kms/jwk/jwa.mjs.map +1 -1
- package/build/modules/kms/jwk/knownJwk.d.mts +4 -4
- package/build/modules/kms/jwk/kty/ec/P256PublicJwk.d.mts +1 -1
- package/build/modules/kms/jwk/kty/ec/P384PublicJwk.d.mts +1 -1
- package/build/modules/kms/jwk/kty/ec/P521PublicJwk.d.mts +1 -1
- package/build/modules/kms/jwk/kty/ec/Secp256k1PublicJwk.d.mts +1 -1
- package/build/modules/kms/jwk/kty/okp/Ed25519PublicJwk.d.mts +3 -3
- package/build/modules/kms/jwk/kty/okp/X25519PublicJwk.d.mts +1 -1
- package/build/modules/kms/jwk/kty/okp/okpJwk.d.mts +2 -2
- package/build/modules/kms/jwk/kty/rsa/RsaPublicJwk.d.mts +1 -1
- package/build/modules/kms/options/KmsCreateKeyOptions.d.mts +3 -3
- package/build/modules/kms/options/KmsDecryptOptions.d.mts +85 -5
- package/build/modules/kms/options/KmsDecryptOptions.d.mts.map +1 -1
- package/build/modules/kms/options/KmsDecryptOptions.mjs +9 -0
- package/build/modules/kms/options/KmsDecryptOptions.mjs.map +1 -1
- package/build/modules/kms/options/KmsEncryptOptions.d.mts +110 -53
- package/build/modules/kms/options/KmsEncryptOptions.d.mts.map +1 -1
- package/build/modules/kms/options/KmsEncryptOptions.mjs +74 -20
- package/build/modules/kms/options/KmsEncryptOptions.mjs.map +1 -1
- package/build/modules/kms/options/KmsKeyAgreementDecryptOptions.d.mts +215 -9
- package/build/modules/kms/options/KmsKeyAgreementDecryptOptions.d.mts.map +1 -1
- package/build/modules/kms/options/KmsKeyAgreementDecryptOptions.mjs +25 -7
- package/build/modules/kms/options/KmsKeyAgreementDecryptOptions.mjs.map +1 -1
- package/build/modules/kms/options/KmsKeyAgreementEncryptOptions.d.mts +173 -83
- package/build/modules/kms/options/KmsKeyAgreementEncryptOptions.d.mts.map +1 -1
- package/build/modules/kms/options/KmsKeyAgreementEncryptOptions.mjs +18 -19
- package/build/modules/kms/options/KmsKeyAgreementEncryptOptions.mjs.map +1 -1
- package/build/modules/kms/options/KmsOperation.d.mts +6 -3
- package/build/modules/kms/options/KmsOperation.d.mts.map +1 -1
- package/build/modules/kms/options/KmsOperation.mjs +12 -1
- package/build/modules/kms/options/KmsOperation.mjs.map +1 -1
- package/build/modules/kms/options/KmsSignOptions.d.mts +1 -1
- package/build/modules/kms/options/KmsVerifyOptions.d.mts +2 -2
- package/build/modules/kms/options/index.d.mts +5 -5
- package/build/modules/kms/options/index.mjs +2 -2
- package/build/modules/mdoc/repository/MdocRecord.d.mts +1 -1
- package/build/modules/sd-jwt-vc/repository/SdJwtVcRecord.d.mts +1 -1
- package/build/modules/vc/models/credential/W3cV2EnvelopedVerifiableCredential.d.mts +1 -1
- package/build/modules/vc/models/credential/W3cV2EnvelopedVerifiableCredential.d.mts.map +1 -1
- package/build/modules/vc/models/credential/W3cV2VerifiableCredential.d.mts +1 -1
- package/build/modules/vc/models/credential/W3cV2VerifiableCredential.d.mts.map +1 -1
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ export declare class CredoWalletWebCrypto {
|
|
|
29
29
|
modulusLength?: undefined;
|
|
30
30
|
} | {
|
|
31
31
|
kty: "RSA";
|
|
32
|
-
modulusLength:
|
|
32
|
+
modulusLength: 4096 | 3072 | 2048;
|
|
33
33
|
crv?: undefined;
|
|
34
34
|
}>>;
|
|
35
35
|
importKey(format: KeyFormat, keyData: Uint8Array | JsonWebKey, algorithm: KeyImportParams, extractable: boolean, keyUsages: Array<KeyUsage>): Promise<CredoWebCryptoKey>;
|
|
@@ -15,7 +15,27 @@ export declare function getJsonWebKey2020(options: GetJsonWebKey2020Options): {
|
|
|
15
15
|
id: string;
|
|
16
16
|
type: string;
|
|
17
17
|
controller: string;
|
|
18
|
-
publicKeyJwk:
|
|
18
|
+
publicKeyJwk: {
|
|
19
|
+
kty: "RSA";
|
|
20
|
+
n: string;
|
|
21
|
+
e: string;
|
|
22
|
+
d?: undefined;
|
|
23
|
+
p?: undefined;
|
|
24
|
+
q?: undefined;
|
|
25
|
+
dp?: undefined;
|
|
26
|
+
dq?: undefined;
|
|
27
|
+
qi?: undefined;
|
|
28
|
+
oth?: undefined;
|
|
29
|
+
kid?: string | undefined;
|
|
30
|
+
alg?: string | undefined;
|
|
31
|
+
key_ops?: string[] | undefined;
|
|
32
|
+
use?: string | undefined;
|
|
33
|
+
ext?: boolean | undefined;
|
|
34
|
+
x5c?: string[] | undefined;
|
|
35
|
+
x5t?: string | undefined;
|
|
36
|
+
'x5t#S256'?: string | undefined;
|
|
37
|
+
x5u?: string | undefined;
|
|
38
|
+
} | ({
|
|
19
39
|
kty: "EC";
|
|
20
40
|
crv: "P-256" | "P-384" | "P-521" | "secp256k1";
|
|
21
41
|
x: string;
|
|
@@ -85,7 +105,7 @@ export declare function getJsonWebKey2020(options: GetJsonWebKey2020Options): {
|
|
|
85
105
|
crv: "secp256k1";
|
|
86
106
|
}) | ({
|
|
87
107
|
kty: "OKP";
|
|
88
|
-
crv: "
|
|
108
|
+
crv: "Ed25519" | "X25519";
|
|
89
109
|
x: string;
|
|
90
110
|
d?: string | undefined;
|
|
91
111
|
kid?: string | undefined;
|
|
@@ -99,29 +119,9 @@ export declare function getJsonWebKey2020(options: GetJsonWebKey2020Options): {
|
|
|
99
119
|
x5u?: string | undefined;
|
|
100
120
|
} & {
|
|
101
121
|
crv: "Ed25519";
|
|
102
|
-
}) | {
|
|
103
|
-
kty: "RSA";
|
|
104
|
-
n: string;
|
|
105
|
-
e: string;
|
|
106
|
-
d?: undefined;
|
|
107
|
-
p?: undefined;
|
|
108
|
-
q?: undefined;
|
|
109
|
-
dp?: undefined;
|
|
110
|
-
dq?: undefined;
|
|
111
|
-
qi?: undefined;
|
|
112
|
-
oth?: undefined;
|
|
113
|
-
kid?: string | undefined;
|
|
114
|
-
alg?: string | undefined;
|
|
115
|
-
key_ops?: string[] | undefined;
|
|
116
|
-
use?: string | undefined;
|
|
117
|
-
ext?: boolean | undefined;
|
|
118
|
-
x5c?: string[] | undefined;
|
|
119
|
-
x5t?: string | undefined;
|
|
120
|
-
'x5t#S256'?: string | undefined;
|
|
121
|
-
x5u?: string | undefined;
|
|
122
|
-
} | ({
|
|
122
|
+
}) | ({
|
|
123
123
|
kty: "OKP";
|
|
124
|
-
crv: "
|
|
124
|
+
crv: "Ed25519" | "X25519";
|
|
125
125
|
x: string;
|
|
126
126
|
d?: string | undefined;
|
|
127
127
|
kid?: string | undefined;
|
|
@@ -16,7 +16,27 @@ export declare class DidJwk {
|
|
|
16
16
|
*/
|
|
17
17
|
get verificationMethodId(): string;
|
|
18
18
|
static fromPublicJwk(publicJwk: PublicJwk): DidJwk;
|
|
19
|
-
get jwkJson():
|
|
19
|
+
get jwkJson(): {
|
|
20
|
+
kty: "RSA";
|
|
21
|
+
n: string;
|
|
22
|
+
e: string;
|
|
23
|
+
d?: undefined;
|
|
24
|
+
p?: undefined;
|
|
25
|
+
q?: undefined;
|
|
26
|
+
dp?: undefined;
|
|
27
|
+
dq?: undefined;
|
|
28
|
+
qi?: undefined;
|
|
29
|
+
oth?: undefined;
|
|
30
|
+
kid?: string | undefined;
|
|
31
|
+
alg?: string | undefined;
|
|
32
|
+
key_ops?: string[] | undefined;
|
|
33
|
+
use?: string | undefined;
|
|
34
|
+
ext?: boolean | undefined;
|
|
35
|
+
x5c?: string[] | undefined;
|
|
36
|
+
x5t?: string | undefined;
|
|
37
|
+
'x5t#S256'?: string | undefined;
|
|
38
|
+
x5u?: string | undefined;
|
|
39
|
+
} | ({
|
|
20
40
|
kty: "EC";
|
|
21
41
|
crv: "P-256" | "P-384" | "P-521" | "secp256k1";
|
|
22
42
|
x: string;
|
|
@@ -86,7 +106,7 @@ export declare class DidJwk {
|
|
|
86
106
|
crv: "secp256k1";
|
|
87
107
|
}) | ({
|
|
88
108
|
kty: "OKP";
|
|
89
|
-
crv: "
|
|
109
|
+
crv: "Ed25519" | "X25519";
|
|
90
110
|
x: string;
|
|
91
111
|
d?: string | undefined;
|
|
92
112
|
kid?: string | undefined;
|
|
@@ -100,29 +120,9 @@ export declare class DidJwk {
|
|
|
100
120
|
x5u?: string | undefined;
|
|
101
121
|
} & {
|
|
102
122
|
crv: "Ed25519";
|
|
103
|
-
}) | {
|
|
104
|
-
kty: "RSA";
|
|
105
|
-
n: string;
|
|
106
|
-
e: string;
|
|
107
|
-
d?: undefined;
|
|
108
|
-
p?: undefined;
|
|
109
|
-
q?: undefined;
|
|
110
|
-
dp?: undefined;
|
|
111
|
-
dq?: undefined;
|
|
112
|
-
qi?: undefined;
|
|
113
|
-
oth?: undefined;
|
|
114
|
-
kid?: string | undefined;
|
|
115
|
-
alg?: string | undefined;
|
|
116
|
-
key_ops?: string[] | undefined;
|
|
117
|
-
use?: string | undefined;
|
|
118
|
-
ext?: boolean | undefined;
|
|
119
|
-
x5c?: string[] | undefined;
|
|
120
|
-
x5t?: string | undefined;
|
|
121
|
-
'x5t#S256'?: string | undefined;
|
|
122
|
-
x5u?: string | undefined;
|
|
123
|
-
} | ({
|
|
123
|
+
}) | ({
|
|
124
124
|
kty: "OKP";
|
|
125
|
-
crv: "
|
|
125
|
+
crv: "Ed25519" | "X25519";
|
|
126
126
|
x: string;
|
|
127
127
|
d?: string | undefined;
|
|
128
128
|
kid?: string | undefined;
|
|
@@ -51,7 +51,7 @@ export declare class DifPresentationExchangeService {
|
|
|
51
51
|
*/
|
|
52
52
|
mdocSessionTranscript?: MdocSessionTranscriptOptions;
|
|
53
53
|
}): Promise<{
|
|
54
|
-
verifiablePresentations: (
|
|
54
|
+
verifiablePresentations: (MdocDeviceResponse | W3cJwtVerifiablePresentation | W3cJsonLdVerifiablePresentation | SdJwtVc<SdJwtVcHeader, import("@sd-jwt/sd-jwt-vc").SdJwtVcPayload>)[];
|
|
55
55
|
encodedVerifiablePresentations: (string | W3cJsonPresentation)[];
|
|
56
56
|
presentationSubmission: import("@sphereon/pex-models").PresentationSubmission;
|
|
57
57
|
presentationSubmissionLocation: DifPresentationExchangeSubmissionLocation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DifPresentationExchangeService.d.mts","names":["_$___vc0.W3cJwtVerifiablePresentation","_$___vc0.W3cJsonLdVerifiablePresentation","_$___sd_jwt_vc0.SdJwtVcHeader","_$___sd_jwt_vc0.SdJwtVc"],"sources":["../../../src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBA4Da;UAGgB;UAFnB;EAEmB,YAAA,sBAAsB;EAEpC,yBACX,cAAc,cACd,wBAAwB,oCACvB,QAAQ;;;;;EASJ,4BACL,uBAAuB,8BACtB;EAsBI,+BAA+B,wBAAwB;EASvD,+BAA+B,wBAAwB;EAQvD,qBACL,wBAAwB,mCACxB,eAAe,yBAAyB,0BACxC,yBAAyB;UAmBnB;EAQK,mBACX,cAAc,cACd;IACE,+BAA+B;IAC/B,wBAAwB;;;;IAIxB,iCAAiC;;;;IAIjC;;;;IAKA;;;;IAKA,wBAAwB;MACzB;
|
|
1
|
+
{"version":3,"file":"DifPresentationExchangeService.d.mts","names":["_$___vc0.W3cJwtVerifiablePresentation","_$___vc0.W3cJsonLdVerifiablePresentation","_$___sd_jwt_vc0.SdJwtVcHeader","_$___sd_jwt_vc0.SdJwtVc"],"sources":["../../../src/modules/dif-presentation-exchange/DifPresentationExchangeService.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBA4Da;UAGgB;UAFnB;EAEmB,YAAA,sBAAsB;EAEpC,yBACX,cAAc,cACd,wBAAwB,oCACvB,QAAQ;;;;;EASJ,4BACL,uBAAuB,8BACtB;EAsBI,+BAA+B,wBAAwB;EASvD,+BAA+B,wBAAwB;EAQvD,qBACL,wBAAwB,mCACxB,eAAe,yBAAyB,0BACxC,yBAAyB;UAmBnB;EAQK,mBACX,cAAc,cACd;IACE,+BAA+B;IAC/B,wBAAwB;;;;IAIxB,iCAAiC;;;;IAIjC;;;;IAKA;;;;IAKA,wBAAwB;MACzB;;;;;;UAkKK;UA0BA;UAyCA;UAkBA;;;;;;UAuDA;UAuBA;UA8HM;;;;;UA2BA;UAqEN;UAIA"}
|
|
@@ -83,20 +83,6 @@ export declare class KeyManagementApi {
|
|
|
83
83
|
x5t?: string | undefined;
|
|
84
84
|
'x5t#S256'?: string | undefined;
|
|
85
85
|
x5u?: string | undefined;
|
|
86
|
-
} | {
|
|
87
|
-
kty: "OKP";
|
|
88
|
-
crv: "X25519" | "Ed25519";
|
|
89
|
-
x: string;
|
|
90
|
-
d?: string | undefined;
|
|
91
|
-
kid?: string | undefined;
|
|
92
|
-
alg?: string | undefined;
|
|
93
|
-
key_ops?: string[] | undefined;
|
|
94
|
-
use?: string | undefined;
|
|
95
|
-
ext?: boolean | undefined;
|
|
96
|
-
x5c?: string[] | undefined;
|
|
97
|
-
x5t?: string | undefined;
|
|
98
|
-
'x5t#S256'?: string | undefined;
|
|
99
|
-
x5u?: string | undefined;
|
|
100
86
|
} | {
|
|
101
87
|
kty: "RSA";
|
|
102
88
|
n: string;
|
|
@@ -129,6 +115,20 @@ export declare class KeyManagementApi {
|
|
|
129
115
|
x5t?: string | undefined;
|
|
130
116
|
'x5t#S256'?: string | undefined;
|
|
131
117
|
x5u?: string | undefined;
|
|
118
|
+
} | {
|
|
119
|
+
kty: "OKP";
|
|
120
|
+
crv: "Ed25519" | "X25519";
|
|
121
|
+
x: string;
|
|
122
|
+
d?: string | undefined;
|
|
123
|
+
kid?: string | undefined;
|
|
124
|
+
alg?: string | undefined;
|
|
125
|
+
key_ops?: string[] | undefined;
|
|
126
|
+
use?: string | undefined;
|
|
127
|
+
ext?: boolean | undefined;
|
|
128
|
+
x5c?: string[] | undefined;
|
|
129
|
+
x5t?: string | undefined;
|
|
130
|
+
'x5t#S256'?: string | undefined;
|
|
131
|
+
x5u?: string | undefined;
|
|
132
132
|
}>;
|
|
133
133
|
/**
|
|
134
134
|
* Delete a key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyManagementApi.d.mts","names":["_$__options0.KmsSignReturn","_$__options0.KmsVerifyReturn","_$__options0.KmsEncryptReturn","_$__options0.KmsDecryptReturn","_$__options0.KmsRandomBytesReturn"],"sources":["../../../src/modules/kms/KeyManagementApi.ts"],"mappings":";;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"KeyManagementApi.d.mts","names":["_$__options0.KmsSignReturn","_$__options0.KmsVerifyReturn","_$__options0.KmsEncryptReturn","_$__options0.KmsDecryptReturn","_$__options0.KmsRandomBytesReturn"],"sources":["../../../src/modules/kms/KeyManagementApi.ts"],"mappings":";;;;;;;;;;;;;;;;;;;qBA8Ca;UAED;UACA;EADA,YAAA,qBAAqB,2BACrB,cAAc;;;;;;;EASjB,8BAA8B,WAAW;;;;;;;EA0BzC,gCAAgC;IACrC;MACE;;;;EAaS,UAAU,aAAa,kBAClC,SAAS,YAAY,oBAAoB,SACxC,QAAQ,mBAAmB;;;;EAyBjB,+BACX,SAAS,YAAY,4CACpB,QAAQ,mBAAmB;;;;EA0BjB,KAAK,SAAS,YAAY,kBAAe,QAA3BA;;;;EAqBd,OAAO,SAAS,YAAY,oBAAiB,QAA7BC;;;;EAoBhB,QAAQ,SAAS,YAAY,qBAAkB,QAA9BC;;;;EAwBjB,QAAQ,SAAS,YAAY,qBAAkB,QAA9BC;;;;EAwBjB,UAAU,YAAY,eACjC,SAAS,YAAY,oBAAoB,QACxC,QAAQ,mBAAmB;;;;EAyBjB,aAAa,SAAS,YAAY,0BAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuBzD,UAAU,SAAS,YAAY,uBAAoB;;;;EAiBzD,YAAY,SAAS,YAAY,yBAAZC;;;;;;;;;;;;UAyBd;;;;;;;;;;;UA+BN"}
|
|
@@ -11,7 +11,7 @@ import { createKeyTypeForSigningAlgorithm } from "./jwk/alg/signing.mjs";
|
|
|
11
11
|
import { zParseWithErrorHandling } from "../../utils/zod.mjs";
|
|
12
12
|
import "./jwk/index.mjs";
|
|
13
13
|
import { KeyManagementModuleConfig } from "./KeyManagementModuleConfig.mjs";
|
|
14
|
-
import { zKmsEncryptOptions } from "./options/KmsEncryptOptions.mjs";
|
|
14
|
+
import { ecdhContentEncryptionAlgorithmsFor, zKmsEncryptOptions } from "./options/KmsEncryptOptions.mjs";
|
|
15
15
|
import { getKmsOperationHumanDescription } from "./options/KmsOperation.mjs";
|
|
16
16
|
import "./options/index.mjs";
|
|
17
17
|
import { zWithBackend } from "./options/backend.mjs";
|
|
@@ -36,6 +36,11 @@ let KeyManagementApi = class KeyManagementApi {
|
|
|
36
36
|
* no backends are supported it returns an empty array
|
|
37
37
|
*/
|
|
38
38
|
supportedBackendsForOperation(operation) {
|
|
39
|
+
if ((operation.operation === "encrypt" || operation.operation === "decrypt") && operation.keyAgreement) {
|
|
40
|
+
const encryption = operation.operation === "encrypt" ? operation.encryption : operation.decryption;
|
|
41
|
+
const ecdhEncryptionAlgorithms = ecdhContentEncryptionAlgorithmsFor(operation.keyAgreement.algorithm);
|
|
42
|
+
if (ecdhEncryptionAlgorithms && !ecdhEncryptionAlgorithms.includes(encryption.algorithm)) return [];
|
|
43
|
+
}
|
|
39
44
|
const supportedBackends = [];
|
|
40
45
|
for (const kms of this.keyManagementConfig.backends) if (kms.isOperationSupported(this.agentContext, operation)) supportedBackends.push(kms.backend);
|
|
41
46
|
return supportedBackends;
|
|
@@ -115,7 +120,7 @@ let KeyManagementApi = class KeyManagementApi {
|
|
|
115
120
|
encryption: options.encryption,
|
|
116
121
|
keyAgreement: options.key.keyAgreement
|
|
117
122
|
};
|
|
118
|
-
const keyId = routingKeyId(
|
|
123
|
+
const keyId = routingKeyId(kmsOptions.key);
|
|
119
124
|
return await (backend || !keyId ? this.getKms(this.agentContext, backend, operation) : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms).encrypt(this.agentContext, kmsOptions);
|
|
120
125
|
}
|
|
121
126
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyManagementApi.mjs","names":[],"sources":["../../../src/modules/kms/KeyManagementApi.ts"],"sourcesContent":["import { AgentContext } from '../../agent'\nimport { injectable } from '../../plugins'\nimport { zParseWithErrorHandling } from '../../utils/zod'\nimport { KeyManagementError } from './error/KeyManagementError'\nimport { KeyManagementKeyNotFoundError } from './error/KeyManagementKeyNotFoundError'\nimport {\n getJwkHumanDescription,\n type KmsJwkPrivate,\n type KnownJwaSignatureAlgorithm,\n KnownJwaSignatureAlgorithms,\n} from './jwk'\nimport { createKeyTypeForSigningAlgorithm } from './jwk/alg/signing'\nimport { KeyManagementModuleConfig } from './KeyManagementModuleConfig'\nimport {\n getKmsOperationHumanDescription,\n type KmsDecryptOptions,\n type KmsDeleteKeyOptions,\n type KmsGetPublicKeyOptions,\n type KmsImportKeyOptions,\n type KmsOperation,\n type KmsRandomBytesOptions,\n} from './options'\nimport { type WithBackend, zWithBackend } from './options/backend'\nimport {\n type KmsCreateKeyForSignatureAlgorithmOptions,\n type KmsCreateKeyOptions,\n type KmsCreateKeyReturn,\n type KmsCreateKeyType,\n type KmsCreateKeyTypeAsymmetric,\n zKmsCreateKeyForSignatureAlgorithmOptions,\n zKmsCreateKeyOptions,\n} from './options/KmsCreateKeyOptions'\nimport { zKmsDecryptOptions } from './options/KmsDecryptOptions'\nimport { zKmsDeleteKeyOptions } from './options/KmsDeleteKeyOptions'\nimport { type KmsEncryptOptions, zKmsEncryptOptions } from './options/KmsEncryptOptions'\nimport { zKmsGetPublicKeyOptions } from './options/KmsGetPublicKeyOptions'\nimport { type KmsImportKeyReturn, zKmsImportKeyOptions } from './options/KmsImportKeyOptions'\nimport { zKmsRandomBytesOptions } from './options/KmsRandomBytesOptions'\nimport { type KmsSignOptions, zKmsSignOptions } from './options/KmsSignOptions'\nimport { type KmsVerifyOptions, zKmsVerifyOptions } from './options/KmsVerifyOptions'\n\n@injectable()\nexport class KeyManagementApi {\n public constructor(\n private keyManagementConfig: KeyManagementModuleConfig,\n private agentContext: AgentContext\n ) {}\n\n /**\n * Whether an operation is supported.\n *\n * @returns a list of backends that support the operation. In case\n * no backends are supported it returns an empty array\n */\n public supportedBackendsForOperation(operation: KmsOperation): string[] {\n const supportedBackends: string[] = []\n\n for (const kms of this.keyManagementConfig.backends) {\n const isOperationSupported = kms.isOperationSupported(this.agentContext, operation)\n if (isOperationSupported) {\n supportedBackends.push(kms.backend)\n }\n }\n\n return supportedBackends\n }\n\n /**\n * The JWA signature algorithms that at least one backend can sign with.\n *\n * Symmetric (HMAC) algorithms are excluded by default, since in most cases signatures are\n * verified by another party using a public key.\n */\n public supportedJwaSignatureAlgorithms(options?: {\n includeSymmetricAlgorithms?: boolean\n }): KnownJwaSignatureAlgorithm[] {\n const includeSymmetricAlgorithms = options?.includeSymmetricAlgorithms ?? false\n\n return Object.values(KnownJwaSignatureAlgorithms).filter(\n (algorithm) =>\n (includeSymmetricAlgorithms || createKeyTypeForSigningAlgorithm(algorithm).kty !== 'oct') &&\n this.supportedBackendsForOperation({ operation: 'sign', algorithm }).length > 0\n )\n }\n\n /**\n * Create a key.\n */\n public async createKey<Type extends KmsCreateKeyType>(\n options: WithBackend<KmsCreateKeyOptions<Type>>\n ): Promise<KmsCreateKeyReturn<Type>> {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsCreateKeyOptions),\n options,\n 'Invalid options provided to createKey method'\n )\n\n const kms = this.getKms(this.agentContext, backend, {\n operation: 'createKey',\n type: options.type,\n })\n\n const key = await kms.createKey(this.agentContext, kmsOptions)\n key.publicJwk.kid = key.keyId\n\n this.agentContext.config.logger.debug(\n `Created key ${getJwkHumanDescription(key.publicJwk)} with key id '${key.keyId}'`\n )\n\n return key\n }\n\n /**\n * Create a key.\n */\n public async createKeyForSignatureAlgorithm(\n options: WithBackend<KmsCreateKeyForSignatureAlgorithmOptions>\n ): Promise<KmsCreateKeyReturn<KmsCreateKeyTypeAsymmetric>> {\n const { backend, algorithm, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsCreateKeyForSignatureAlgorithmOptions),\n options,\n 'Invalid options provided to createKeyForSignatureAlgorithm method'\n )\n\n const type = createKeyTypeForSigningAlgorithm(algorithm)\n const kms = this.getKms(this.agentContext, backend, {\n operation: 'createKey',\n type,\n })\n\n // Ensure the kid is set to the keyId\n const key = await kms.createKey(this.agentContext, {\n ...kmsOptions,\n type,\n })\n key.publicJwk.kid = key.keyId\n\n return key\n }\n\n /**\n * Sign using a key.\n */\n public async sign(options: WithBackend<KmsSignOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsSignOptions),\n options,\n 'Invalid options provided to sign method'\n )\n\n const operation = {\n operation: 'sign',\n algorithm: options.algorithm,\n } as const\n\n const kms = backend\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, options.keyId, operation)).kms\n return await kms.sign(this.agentContext, kmsOptions)\n }\n\n /**\n * Verify using a key.\n */\n public async verify(options: WithBackend<KmsVerifyOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsVerifyOptions),\n options,\n 'Invalid options provided to verify method'\n )\n\n const operation = { operation: 'verify', algorithm: options.algorithm } as const\n const keyId = options.key.keyId\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.verify(this.agentContext, kmsOptions)\n }\n\n /**\n * Encrypt.\n */\n public async encrypt(options: WithBackend<KmsEncryptOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsEncryptOptions),\n options,\n 'Invalid options provided to encrypt method'\n )\n\n const operation = {\n operation: 'encrypt',\n encryption: options.encryption,\n keyAgreement: options.key.keyAgreement,\n } as const\n const keyId = routingKeyId(options.key)\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.encrypt(this.agentContext, kmsOptions)\n }\n\n /**\n * Decrypt.\n */\n public async decrypt(options: WithBackend<KmsDecryptOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsDecryptOptions),\n options,\n 'Invalid options provided to decrypt method'\n )\n\n const operation = {\n operation: 'decrypt',\n decryption: options.decryption,\n keyAgreement: options.key.keyAgreement,\n } as const\n const keyId = routingKeyId(options.key)\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.decrypt(this.agentContext, kmsOptions)\n }\n\n /**\n * Import a key.\n */\n public async importKey<Jwk extends KmsJwkPrivate>(\n options: WithBackend<KmsImportKeyOptions<Jwk>>\n ): Promise<KmsImportKeyReturn<Jwk>> {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsImportKeyOptions),\n options,\n 'Invalid options provided to importKey method'\n )\n\n const operation = {\n operation: 'importKey',\n privateJwk: options.privateJwk,\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n\n const key = await kms.importKey(this.agentContext, kmsOptions)\n\n this.agentContext.config.logger.trace(\n `Imported key ${getJwkHumanDescription(key.publicJwk)} with key id '${key.keyId}'`\n )\n\n return key\n }\n\n /**\n * Get a public key.\n */\n public async getPublicKey(options: WithBackend<KmsGetPublicKeyOptions>) {\n const { backend, keyId } = zParseWithErrorHandling(\n zWithBackend(zKmsGetPublicKeyOptions),\n options,\n 'Invalid options provided to getPublicKey method'\n )\n\n if (backend) {\n const kms = this.getKms(this.agentContext, backend)\n const publicKey = await kms.getPublicKey(this.agentContext, keyId)\n\n if (!publicKey) {\n throw new KeyManagementKeyNotFoundError(keyId, [backend])\n }\n }\n\n const { publicKey } = await this.getKmsForOperationAndKeyId(this.agentContext, options.keyId)\n return publicKey\n }\n\n /**\n * Delete a key.\n */\n public async deleteKey(options: WithBackend<KmsDeleteKeyOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsDeleteKeyOptions),\n options,\n 'Invalid options provided to deleteKey method'\n )\n\n const operation = {\n operation: 'deleteKey',\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n return await kms.deleteKey(this.agentContext, kmsOptions)\n }\n\n /**\n * Generate random bytes\n */\n public randomBytes(options: WithBackend<KmsRandomBytesOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsRandomBytesOptions),\n options,\n 'Invalid options provided to randomBytes method'\n )\n\n const operation = {\n operation: 'randomBytes',\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n return kms.randomBytes(this.agentContext, kmsOptions)\n }\n\n /**\n * Get the kms associated with a specific `keyId`.\n *\n * This uses a naive approach of fetching the key for each configured kms\n * until it finds the registered key.\n *\n * In the future this approach might be optimized based on:\n * - caching\n * - keeping a registry\n * - backend specific key prefixes\n */\n private async getKmsForOperationAndKeyId(agentContext: AgentContext, keyId: string, operation?: KmsOperation) {\n for (const kms of this.keyManagementConfig.backends) {\n if (operation && !kms.isOperationSupported(agentContext, operation)) continue\n\n const publicKey = await kms.getPublicKey(this.agentContext, keyId)\n if (publicKey)\n return {\n publicKey,\n kms,\n }\n }\n\n throw new KeyManagementKeyNotFoundError(\n keyId,\n this.keyManagementConfig.backends.map((b) => b.backend),\n operation\n ? `The key may exist in one of the key management services in which case the key management service does not support the ${getKmsOperationHumanDescription(operation)}`\n : undefined\n )\n }\n\n /**\n * Get the kms backend for a specific operation.\n *\n * If a backend is provided, it will be checked if the backend supports\n * the operation. Otherwise the default backend (the `defaultBackend` from\n * the `KeyManagementModuleConfig`, or the first registered backend if no\n * `defaultBackend` was configured) will be used if it supports the operation.\n * If the default backend does not support the operation, the first other\n * backend that supports the operation will be used and a warning will be logged.\n */\n private getKms(agentContext: AgentContext, backend?: string, operation?: KmsOperation) {\n const backends = this.keyManagementConfig.backends\n\n if (backend) {\n const kms = backends.find((kms) => kms.backend === backend)\n if (!kms) {\n const availableBackends = backends.map((kms) => `'${kms.backend}'`)\n throw new KeyManagementError(\n `No key management service is configured for backend '${backend}'. Available backends are ${availableBackends.join(\n ', '\n )}`\n )\n }\n\n if (operation && !kms.isOperationSupported(agentContext, operation)) {\n throw new KeyManagementError(\n `Key management service backend '${backend}' does not support ${getKmsOperationHumanDescription(operation)}`\n )\n }\n\n return kms\n }\n\n if (backends.length > 0) {\n const defaultKms = this.keyManagementConfig.defaultBackend\n if (!operation || defaultKms.isOperationSupported(agentContext, operation)) return defaultKms\n\n const fallbackKms = backends.find(\n (kms) => kms !== defaultKms && kms.isOperationSupported(agentContext, operation)\n )\n\n if (fallbackKms) {\n return fallbackKms\n }\n }\n\n throw new KeyManagementError(\n operation\n ? `No key management service backend found that supports ${getKmsOperationHumanDescription(operation)}`\n : 'No key management service backend found.'\n )\n }\n}\n\nfunction routingKeyId(key: KmsEncryptOptions['key'] | KmsDecryptOptions['key']): string | undefined {\n if (key.keyId) return key.keyId\n if (key.keyAgreement && 'keyId' in key.keyAgreement) return key.keyAgreement.keyId\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,IAAM,mBAAN,MAAM,iBAAiB;CAC5B,YACE,qBACA,cACA;EAFQ,KAAA,sBAAA;EACA,KAAA,eAAA;CACP;;;;;;;CAQH,8BAAqC,WAAmC;EACtE,MAAM,oBAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,KAAK,oBAAoB,UAEzC,IAD6B,IAAI,qBAAqB,KAAK,cAAc,SAClD,GACrB,kBAAkB,KAAK,IAAI,OAAO;EAItC,OAAO;CACT;;;;;;;CAQA,gCAAuC,SAEN;EAC/B,MAAM,6BAA6B,SAAS,8BAA8B;EAE1E,OAAO,OAAO,OAAO,2BAA2B,CAAC,CAAC,QAC/C,eACE,8BAA8B,iCAAiC,SAAS,CAAC,CAAC,QAAQ,UACnF,KAAK,8BAA8B;GAAE,WAAW;GAAQ;EAAU,CAAC,CAAC,CAAC,SAAS,CAClF;CACF;;;;CAKA,MAAa,UACX,SACmC;EACnC,MAAM,EAAE,SAAS,GAAG,eAAe,wBACjC,aAAa,oBAAoB,GACjC,SACA,8CACF;EAOA,MAAM,MAAM,MALA,KAAK,OAAO,KAAK,cAAc,SAAS;GAClD,WAAW;GACX,MAAM,QAAQ;EAChB,CAEoB,CAAC,CAAC,UAAU,KAAK,cAAc,UAAU;EAC7D,IAAI,UAAU,MAAM,IAAI;EAExB,KAAK,aAAa,OAAO,OAAO,MAC9B,eAAe,uBAAuB,IAAI,SAAS,EAAE,gBAAgB,IAAI,MAAM,EACjF;EA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AEA,IAAI,aAAa,CAAC,IAAI,qBAAqB,cAAc,SAAS,GAChE,MAAM,IAAI,mBACR,mCAAmC,QAAQ,qBAAqB,gCAAgC,SAAS,GAC3G;GAGF,OAAO;EACT;EAEA,IAAI,SAAS,SAAS,GAAG;GACvB,MAAM,aAAa,KAAK,oBAAoB;GAC5C,IAAI,CAAC,aAAa,WAAW,qBAAqB,cAAc,SAAS,GAAG,OAAO;GAEnF,MAAM,cAAc,SAAS,MAC1B,QAAQ,QAAQ,cAAc,IAAI,qBAAqB,cAAc,SAAS,CACjF;GAEA,IAAI,aACF,OAAO;EAEX;EAEA,MAAM,IAAI,mBACR,YACI,yDAAyD,gCAAgC,SAAS,MAClG,0CACN;CACF;AACF;AApWC,mBAAA,WAAA,CAAA,WAAW,GAAA,mBAAA,qBAAA,CAAA,OAAA,8BAAA,cAAA,SAAA,2BAAA,OAAA,iBAAA,cAAA,SAAA,YAAA,CAAA,CAAA,GAAA,gBAAA;AAsWZ,SAAS,aAAa,KAA8E;CAClG,IAAI,IAAI,OAAO,OAAO,IAAI;CAC1B,IAAI,IAAI,gBAAgB,WAAW,IAAI,cAAc,OAAO,IAAI,aAAa;AAE/E"}
|
|
1
|
+
{"version":3,"file":"KeyManagementApi.mjs","names":[],"sources":["../../../src/modules/kms/KeyManagementApi.ts"],"sourcesContent":["import { AgentContext } from '../../agent'\nimport { injectable } from '../../plugins'\nimport { zParseWithErrorHandling } from '../../utils/zod'\nimport { KeyManagementError } from './error/KeyManagementError'\nimport { KeyManagementKeyNotFoundError } from './error/KeyManagementKeyNotFoundError'\nimport {\n getJwkHumanDescription,\n type KmsJwkPrivate,\n type KnownJwaSignatureAlgorithm,\n KnownJwaSignatureAlgorithms,\n} from './jwk'\nimport { createKeyTypeForSigningAlgorithm } from './jwk/alg/signing'\nimport { KeyManagementModuleConfig } from './KeyManagementModuleConfig'\nimport {\n getKmsOperationHumanDescription,\n type KmsDecryptOptions,\n type KmsDeleteKeyOptions,\n type KmsGetPublicKeyOptions,\n type KmsImportKeyOptions,\n type KmsOperation,\n type KmsRandomBytesOptions,\n} from './options'\nimport { type WithBackend, zWithBackend } from './options/backend'\nimport {\n type KmsCreateKeyForSignatureAlgorithmOptions,\n type KmsCreateKeyOptions,\n type KmsCreateKeyReturn,\n type KmsCreateKeyType,\n type KmsCreateKeyTypeAsymmetric,\n zKmsCreateKeyForSignatureAlgorithmOptions,\n zKmsCreateKeyOptions,\n} from './options/KmsCreateKeyOptions'\nimport { zKmsDecryptOptions } from './options/KmsDecryptOptions'\nimport { zKmsDeleteKeyOptions } from './options/KmsDeleteKeyOptions'\nimport {\n ecdhContentEncryptionAlgorithmsFor,\n type KmsEncryptOptions,\n zKmsEncryptOptions,\n} from './options/KmsEncryptOptions'\nimport { zKmsGetPublicKeyOptions } from './options/KmsGetPublicKeyOptions'\nimport { type KmsImportKeyReturn, zKmsImportKeyOptions } from './options/KmsImportKeyOptions'\nimport { zKmsRandomBytesOptions } from './options/KmsRandomBytesOptions'\nimport { type KmsSignOptions, zKmsSignOptions } from './options/KmsSignOptions'\nimport { type KmsVerifyOptions, zKmsVerifyOptions } from './options/KmsVerifyOptions'\n\n@injectable()\nexport class KeyManagementApi {\n public constructor(\n private keyManagementConfig: KeyManagementModuleConfig,\n private agentContext: AgentContext\n ) {}\n\n /**\n * Whether an operation is supported.\n *\n * @returns a list of backends that support the operation. In case\n * no backends are supported it returns an empty array\n */\n public supportedBackendsForOperation(operation: KmsOperation): string[] {\n // Backends report what they can compute, the ECDH content encryption rules live in the encrypt and decrypt schemas\n if ((operation.operation === 'encrypt' || operation.operation === 'decrypt') && operation.keyAgreement) {\n const encryption = operation.operation === 'encrypt' ? operation.encryption : operation.decryption\n const ecdhEncryptionAlgorithms = ecdhContentEncryptionAlgorithmsFor(operation.keyAgreement.algorithm)\n if (ecdhEncryptionAlgorithms && !ecdhEncryptionAlgorithms.includes(encryption.algorithm)) return []\n }\n\n const supportedBackends: string[] = []\n\n for (const kms of this.keyManagementConfig.backends) {\n const isOperationSupported = kms.isOperationSupported(this.agentContext, operation)\n if (isOperationSupported) {\n supportedBackends.push(kms.backend)\n }\n }\n\n return supportedBackends\n }\n\n /**\n * The JWA signature algorithms that at least one backend can sign with.\n *\n * Symmetric (HMAC) algorithms are excluded by default, since in most cases signatures are\n * verified by another party using a public key.\n */\n public supportedJwaSignatureAlgorithms(options?: {\n includeSymmetricAlgorithms?: boolean\n }): KnownJwaSignatureAlgorithm[] {\n const includeSymmetricAlgorithms = options?.includeSymmetricAlgorithms ?? false\n\n return Object.values(KnownJwaSignatureAlgorithms).filter(\n (algorithm) =>\n (includeSymmetricAlgorithms || createKeyTypeForSigningAlgorithm(algorithm).kty !== 'oct') &&\n this.supportedBackendsForOperation({ operation: 'sign', algorithm }).length > 0\n )\n }\n\n /**\n * Create a key.\n */\n public async createKey<Type extends KmsCreateKeyType>(\n options: WithBackend<KmsCreateKeyOptions<Type>>\n ): Promise<KmsCreateKeyReturn<Type>> {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsCreateKeyOptions),\n options,\n 'Invalid options provided to createKey method'\n )\n\n const kms = this.getKms(this.agentContext, backend, {\n operation: 'createKey',\n type: options.type,\n })\n\n const key = await kms.createKey(this.agentContext, kmsOptions)\n key.publicJwk.kid = key.keyId\n\n this.agentContext.config.logger.debug(\n `Created key ${getJwkHumanDescription(key.publicJwk)} with key id '${key.keyId}'`\n )\n\n return key\n }\n\n /**\n * Create a key.\n */\n public async createKeyForSignatureAlgorithm(\n options: WithBackend<KmsCreateKeyForSignatureAlgorithmOptions>\n ): Promise<KmsCreateKeyReturn<KmsCreateKeyTypeAsymmetric>> {\n const { backend, algorithm, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsCreateKeyForSignatureAlgorithmOptions),\n options,\n 'Invalid options provided to createKeyForSignatureAlgorithm method'\n )\n\n const type = createKeyTypeForSigningAlgorithm(algorithm)\n const kms = this.getKms(this.agentContext, backend, {\n operation: 'createKey',\n type,\n })\n\n // Ensure the kid is set to the keyId\n const key = await kms.createKey(this.agentContext, {\n ...kmsOptions,\n type,\n })\n key.publicJwk.kid = key.keyId\n\n return key\n }\n\n /**\n * Sign using a key.\n */\n public async sign(options: WithBackend<KmsSignOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsSignOptions),\n options,\n 'Invalid options provided to sign method'\n )\n\n const operation = {\n operation: 'sign',\n algorithm: options.algorithm,\n } as const\n\n const kms = backend\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, options.keyId, operation)).kms\n return await kms.sign(this.agentContext, kmsOptions)\n }\n\n /**\n * Verify using a key.\n */\n public async verify(options: WithBackend<KmsVerifyOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsVerifyOptions),\n options,\n 'Invalid options provided to verify method'\n )\n\n const operation = { operation: 'verify', algorithm: options.algorithm } as const\n const keyId = options.key.keyId\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.verify(this.agentContext, kmsOptions)\n }\n\n /**\n * Encrypt.\n */\n public async encrypt(options: WithBackend<KmsEncryptOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsEncryptOptions),\n options,\n 'Invalid options provided to encrypt method'\n )\n\n const operation = {\n operation: 'encrypt',\n encryption: options.encryption,\n keyAgreement: options.key.keyAgreement,\n } as const\n const keyId = routingKeyId(kmsOptions.key)\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.encrypt(this.agentContext, kmsOptions)\n }\n\n /**\n * Decrypt.\n */\n public async decrypt(options: WithBackend<KmsDecryptOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsDecryptOptions),\n options,\n 'Invalid options provided to decrypt method'\n )\n\n const operation = {\n operation: 'decrypt',\n decryption: options.decryption,\n keyAgreement: options.key.keyAgreement,\n } as const\n const keyId = routingKeyId(options.key)\n const kms =\n backend || !keyId\n ? this.getKms(this.agentContext, backend, operation)\n : (await this.getKmsForOperationAndKeyId(this.agentContext, keyId, operation)).kms\n\n return await kms.decrypt(this.agentContext, kmsOptions)\n }\n\n /**\n * Import a key.\n */\n public async importKey<Jwk extends KmsJwkPrivate>(\n options: WithBackend<KmsImportKeyOptions<Jwk>>\n ): Promise<KmsImportKeyReturn<Jwk>> {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsImportKeyOptions),\n options,\n 'Invalid options provided to importKey method'\n )\n\n const operation = {\n operation: 'importKey',\n privateJwk: options.privateJwk,\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n\n const key = await kms.importKey(this.agentContext, kmsOptions)\n\n this.agentContext.config.logger.trace(\n `Imported key ${getJwkHumanDescription(key.publicJwk)} with key id '${key.keyId}'`\n )\n\n return key\n }\n\n /**\n * Get a public key.\n */\n public async getPublicKey(options: WithBackend<KmsGetPublicKeyOptions>) {\n const { backend, keyId } = zParseWithErrorHandling(\n zWithBackend(zKmsGetPublicKeyOptions),\n options,\n 'Invalid options provided to getPublicKey method'\n )\n\n if (backend) {\n const kms = this.getKms(this.agentContext, backend)\n const publicKey = await kms.getPublicKey(this.agentContext, keyId)\n\n if (!publicKey) {\n throw new KeyManagementKeyNotFoundError(keyId, [backend])\n }\n }\n\n const { publicKey } = await this.getKmsForOperationAndKeyId(this.agentContext, options.keyId)\n return publicKey\n }\n\n /**\n * Delete a key.\n */\n public async deleteKey(options: WithBackend<KmsDeleteKeyOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsDeleteKeyOptions),\n options,\n 'Invalid options provided to deleteKey method'\n )\n\n const operation = {\n operation: 'deleteKey',\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n return await kms.deleteKey(this.agentContext, kmsOptions)\n }\n\n /**\n * Generate random bytes\n */\n public randomBytes(options: WithBackend<KmsRandomBytesOptions>) {\n const { backend, ...kmsOptions } = zParseWithErrorHandling(\n zWithBackend(zKmsRandomBytesOptions),\n options,\n 'Invalid options provided to randomBytes method'\n )\n\n const operation = {\n operation: 'randomBytes',\n } as const\n const kms = this.getKms(this.agentContext, backend, operation)\n return kms.randomBytes(this.agentContext, kmsOptions)\n }\n\n /**\n * Get the kms associated with a specific `keyId`.\n *\n * This uses a naive approach of fetching the key for each configured kms\n * until it finds the registered key.\n *\n * In the future this approach might be optimized based on:\n * - caching\n * - keeping a registry\n * - backend specific key prefixes\n */\n private async getKmsForOperationAndKeyId(agentContext: AgentContext, keyId: string, operation?: KmsOperation) {\n for (const kms of this.keyManagementConfig.backends) {\n if (operation && !kms.isOperationSupported(agentContext, operation)) continue\n\n const publicKey = await kms.getPublicKey(this.agentContext, keyId)\n if (publicKey)\n return {\n publicKey,\n kms,\n }\n }\n\n throw new KeyManagementKeyNotFoundError(\n keyId,\n this.keyManagementConfig.backends.map((b) => b.backend),\n operation\n ? `The key may exist in one of the key management services in which case the key management service does not support the ${getKmsOperationHumanDescription(operation)}`\n : undefined\n )\n }\n\n /**\n * Get the kms backend for a specific operation.\n *\n * If a backend is provided, it will be checked if the backend supports\n * the operation. Otherwise the default backend (the `defaultBackend` from\n * the `KeyManagementModuleConfig`, or the first registered backend if no\n * `defaultBackend` was configured) will be used if it supports the operation.\n * If the default backend does not support the operation, the first other\n * backend that supports the operation will be used and a warning will be logged.\n */\n private getKms(agentContext: AgentContext, backend?: string, operation?: KmsOperation) {\n const backends = this.keyManagementConfig.backends\n\n if (backend) {\n const kms = backends.find((kms) => kms.backend === backend)\n if (!kms) {\n const availableBackends = backends.map((kms) => `'${kms.backend}'`)\n throw new KeyManagementError(\n `No key management service is configured for backend '${backend}'. Available backends are ${availableBackends.join(\n ', '\n )}`\n )\n }\n\n if (operation && !kms.isOperationSupported(agentContext, operation)) {\n throw new KeyManagementError(\n `Key management service backend '${backend}' does not support ${getKmsOperationHumanDescription(operation)}`\n )\n }\n\n return kms\n }\n\n if (backends.length > 0) {\n const defaultKms = this.keyManagementConfig.defaultBackend\n if (!operation || defaultKms.isOperationSupported(agentContext, operation)) return defaultKms\n\n const fallbackKms = backends.find(\n (kms) => kms !== defaultKms && kms.isOperationSupported(agentContext, operation)\n )\n\n if (fallbackKms) {\n return fallbackKms\n }\n }\n\n throw new KeyManagementError(\n operation\n ? `No key management service backend found that supports ${getKmsOperationHumanDescription(operation)}`\n : 'No key management service backend found.'\n )\n }\n}\n\nfunction routingKeyId(key: KmsEncryptOptions['key'] | KmsDecryptOptions['key']): string | undefined {\n if (key.keyId) return key.keyId\n if (key.keyAgreement && 'keyId' in key.keyAgreement) return key.keyAgreement.keyId\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA8CO,IAAM,mBAAN,MAAM,iBAAiB;CAC5B,YACE,qBACA,cACA;EAFQ,KAAA,sBAAA;EACA,KAAA,eAAA;CACP;;;;;;;CAQH,8BAAqC,WAAmC;EAEtE,KAAK,UAAU,cAAc,aAAa,UAAU,cAAc,cAAc,UAAU,cAAc;GACtG,MAAM,aAAa,UAAU,cAAc,YAAY,UAAU,aAAa,UAAU;GACxF,MAAM,2BAA2B,mCAAmC,UAAU,aAAa,SAAS;GACpG,IAAI,4BAA4B,CAAC,yBAAyB,SAAS,WAAW,SAAS,GAAG,OAAO,CAAC;EACpG;EAEA,MAAM,oBAA8B,CAAC;EAErC,KAAK,MAAM,OAAO,KAAK,oBAAoB,UAEzC,IAD6B,IAAI,qBAAqB,KAAK,cAAc,SAClD,GACrB,kBAAkB,KAAK,IAAI,OAAO;EAItC,OAAO;CACT;;;;;;;CAQA,gCAAuC,SAEN;EAC/B,MAAM,6BAA6B,SAAS,8BAA8B;EAE1E,OAAO,OAAO,OAAO,2BAA2B,CAAC,CAAC,QAC/C,eACE,8BAA8B,iCA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import { KeyManagementKeyNotFoundError } from "./error/KeyManagementKeyNotFoundE
|
|
|
8
8
|
import { KmsCreateKeyForSignatureAlgorithmOptions, KmsCreateKeyOptions, KmsCreateKeyReturn, KmsCreateKeyType, KmsCreateKeyTypeAsymmetric, KmsCreateKeyTypeEc, KmsCreateKeyTypeOct, KmsCreateKeyTypeOkp, KmsCreateKeyTypeRsa } from "./options/KmsCreateKeyOptions.mjs";
|
|
9
9
|
import { KmsDecryptDataContentDecryption, KmsDecryptDataDecryption, KmsDecryptDataDecryptionAesCbc, KmsDecryptDataDecryptionAesGcm, KmsDecryptDataDecryptionC20p, KmsDecryptDataDecryptionHpke, KmsDecryptOptions, KmsDecryptReturn } from "./options/KmsDecryptOptions.mjs";
|
|
10
10
|
import { KmsDeleteKeyOptions } from "./options/KmsDeleteKeyOptions.mjs";
|
|
11
|
-
import {
|
|
11
|
+
import { KmsJwkPublicEcdh, KmsKeyAgreementEncryptEcdh1Pu, KmsKeyAgreementEncryptEcdhEs, KmsKeyAgreementEncryptEcdhEsKw, KmsKeyAgreementEncryptEcdhHsalsa20, KmsKeyAgreementEncryptHpke, KmsKeyAgreementEncryptOptions, isKmsKeyAgreementEncryptHpke } from "./options/KmsKeyAgreementEncryptOptions.mjs";
|
|
12
|
+
import { KmsEncryptAad, KmsEncryptAadContext, KmsEncryptDataContentEncryption, KmsEncryptDataEncryption, KmsEncryptDataEncryptionAesCbc, KmsEncryptDataEncryptionAesGcm, KmsEncryptDataEncryptionHpke, KmsEncryptDataEncryptionX20c, KmsEncryptOptions, KmsEncryptReturn, KmsEncryptedKey } from "./options/KmsEncryptOptions.mjs";
|
|
12
13
|
import { KmsGetPublicKeyOptions } from "./options/KmsGetPublicKeyOptions.mjs";
|
|
13
14
|
import { KmsImportKeyOptions, KmsImportKeyReturn } from "./options/KmsImportKeyOptions.mjs";
|
|
14
|
-
import { KmsKeyAgreementDecryptEcdhEsKw, KmsKeyAgreementDecryptEcdhHsalsa20, KmsKeyAgreementDecryptHpke, KmsKeyAgreementDecryptOptions, isKmsKeyAgreementDecryptHpke } from "./options/KmsKeyAgreementDecryptOptions.mjs";
|
|
15
|
-
import {
|
|
16
|
-
import { KmsOperation, KmsOperationCreateKey, KmsOperationDecrypt, KmsOperationDeleteKey, KmsOperationEncrypt, KmsOperationImportKey, KmsOperationSign, KmsOperationVerify, getKmsOperationHumanDescription } from "./options/KmsOperation.mjs";
|
|
15
|
+
import { KmsKeyAgreementDecryptEcdh1Pu, KmsKeyAgreementDecryptEcdhEs, KmsKeyAgreementDecryptEcdhEsKw, KmsKeyAgreementDecryptEcdhHsalsa20, KmsKeyAgreementDecryptHpke, KmsKeyAgreementDecryptOptions, isKmsKeyAgreementDecryptHpke } from "./options/KmsKeyAgreementDecryptOptions.mjs";
|
|
16
|
+
import { KmsOperation, KmsOperationCreateKey, KmsOperationDecrypt, KmsOperationDeleteKey, KmsOperationEncrypt, KmsOperationImportKey, KmsOperationSign, KmsOperationVerify, getKmsOperationHumanDescription, keyAgreementPublicJwks } from "./options/KmsOperation.mjs";
|
|
17
17
|
import { KmsRandomBytesOptions, KmsRandomBytesReturn } from "./options/KmsRandomBytesOptions.mjs";
|
|
18
18
|
import { KmsSignOptions, KmsSignReturn } from "./options/KmsSignOptions.mjs";
|
|
19
19
|
import { KmsVerifyOptions, KmsVerifyReturn } from "./options/KmsVerifyOptions.mjs";
|
|
@@ -47,8 +47,8 @@ import { KeyManagementApi } from "./KeyManagementApi.mjs";
|
|
|
47
47
|
import { KeyManagementModule } from "./KeyManagementModule.mjs";
|
|
48
48
|
import { legacyKeyIdFromPublicJwk } from "./legacy.mjs";
|
|
49
49
|
declare namespace index_d_exports {
|
|
50
|
-
export { Ed25519PublicJwk, Jwk, JwkCommon, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KeyManagementModuleConfigOptions, KeyManagementService, KmsCreateKeyForSignatureAlgorithmOptions, KmsCreateKeyOptions, KmsCreateKeyReturn, KmsCreateKeyType, KmsCreateKeyTypeAsymmetric, KmsCreateKeyTypeEc, KmsCreateKeyTypeOct, KmsCreateKeyTypeOkp, KmsCreateKeyTypeRsa, KmsDecryptDataContentDecryption, KmsDecryptDataDecryption, KmsDecryptDataDecryptionAesCbc, KmsDecryptDataDecryptionAesGcm, KmsDecryptDataDecryptionC20p, KmsDecryptDataDecryptionHpke, KmsDecryptOptions, KmsDecryptReturn, KmsDeleteKeyOptions, KmsEncryptDataContentEncryption, KmsEncryptDataEncryption, KmsEncryptDataEncryptionAesCbc, KmsEncryptDataEncryptionAesGcm, KmsEncryptDataEncryptionHpke, KmsEncryptDataEncryptionX20c, KmsEncryptOptions, KmsEncryptReturn, KmsEncryptedKey, KmsGetPublicKeyOptions, KmsImportKeyOptions, KmsImportKeyReturn, KmsJwkPrivate, KmsJwkPrivateAsymmetric, KmsJwkPrivateEc, KmsJwkPrivateFromKmsJwkPublic, KmsJwkPrivateOct, KmsJwkPrivateOkp, KmsJwkPrivateRsa, KmsJwkPublic, KmsJwkPublicAsymmetric, KmsJwkPublicEc, KmsJwkPublicEcdh, KmsJwkPublicFromCreateType, KmsJwkPublicFromKmsJwkPrivate, KmsJwkPublicOct, KmsJwkPublicOkp, KmsJwkPublicRsa, KmsKeyAgreementDecryptEcdhEsKw, KmsKeyAgreementDecryptEcdhHsalsa20, KmsKeyAgreementDecryptHpke, KmsKeyAgreementDecryptOptions,
|
|
50
|
+
export { Ed25519PublicJwk, Jwk, JwkCommon, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KeyManagementModuleConfigOptions, KeyManagementService, KmsCreateKeyForSignatureAlgorithmOptions, KmsCreateKeyOptions, KmsCreateKeyReturn, KmsCreateKeyType, KmsCreateKeyTypeAsymmetric, KmsCreateKeyTypeEc, KmsCreateKeyTypeOct, KmsCreateKeyTypeOkp, KmsCreateKeyTypeRsa, KmsDecryptDataContentDecryption, KmsDecryptDataDecryption, KmsDecryptDataDecryptionAesCbc, KmsDecryptDataDecryptionAesGcm, KmsDecryptDataDecryptionC20p, KmsDecryptDataDecryptionHpke, KmsDecryptOptions, KmsDecryptReturn, KmsDeleteKeyOptions, KmsEncryptAad, KmsEncryptAadContext, KmsEncryptDataContentEncryption, KmsEncryptDataEncryption, KmsEncryptDataEncryptionAesCbc, KmsEncryptDataEncryptionAesGcm, KmsEncryptDataEncryptionHpke, KmsEncryptDataEncryptionX20c, KmsEncryptOptions, KmsEncryptReturn, KmsEncryptedKey, KmsGetPublicKeyOptions, KmsImportKeyOptions, KmsImportKeyReturn, KmsJwkPrivate, KmsJwkPrivateAsymmetric, KmsJwkPrivateEc, KmsJwkPrivateFromKmsJwkPublic, KmsJwkPrivateOct, KmsJwkPrivateOkp, KmsJwkPrivateRsa, KmsJwkPublic, KmsJwkPublicAsymmetric, KmsJwkPublicEc, KmsJwkPublicEcdh, KmsJwkPublicFromCreateType, KmsJwkPublicFromKmsJwkPrivate, KmsJwkPublicOct, KmsJwkPublicOkp, KmsJwkPublicRsa, KmsKeyAgreementDecryptEcdh1Pu, KmsKeyAgreementDecryptEcdhEs, KmsKeyAgreementDecryptEcdhEsKw, KmsKeyAgreementDecryptEcdhHsalsa20, KmsKeyAgreementDecryptHpke, KmsKeyAgreementDecryptOptions, KmsKeyAgreementEncryptEcdh1Pu, KmsKeyAgreementEncryptEcdhEs, KmsKeyAgreementEncryptEcdhEsKw, KmsKeyAgreementEncryptEcdhHsalsa20, KmsKeyAgreementEncryptHpke, KmsKeyAgreementEncryptOptions, KmsOperation, KmsOperationCreateKey, KmsOperationDecrypt, KmsOperationDeleteKey, KmsOperationEncrypt, KmsOperationImportKey, KmsOperationSign, KmsOperationVerify, KmsRandomBytesOptions, KmsRandomBytesReturn, KmsSignOptions, KmsSignReturn, KmsVerifyOptions, KmsVerifyReturn, KnownCoseSignatureAlgorithm, KnownCoseSignatureAlgorithms, KnownJwaContentEncryptionAlgorithm, KnownJwaContentEncryptionAlgorithms, KnownJwaHpkeAlgorithm, KnownJwaHpkeAlgorithms, KnownJwaKeyAgreementAlgorithm, KnownJwaKeyAgreementAlgorithms, KnownJwaKeyEncryptionAlgorithm, KnownJwaKeyEncryptionAlgorithms, KnownJwaSignatureAlgorithm, KnownJwaSignatureAlgorithms, P256PublicJwk, P384PublicJwk, P521PublicJwk, PublicJwk, RsaPublicJwk, Secp256k1PublicJwk, X25519PublicJwk, allowedEncryptionAlgsForKey, allowedKeyDerivationAlgsForKey, allowedSigningAlgsForSigningKey, assertAllowedEncryptionAlgForKey, assertAllowedKeyDerivationAlgForKey, assertAllowedSigningAlgForKey, assertAsymmetricJwkKeyTypeMatches, assertJwkAsymmetric, assertJwkHasNoPrivateKeyMaterial, assertKeyAllowsDecrypt, assertKeyAllowsDerive, assertKeyAllowsEncrypt, assertKeyAllowsSign, assertKeyAllowsVerify, assertSupportedEncryptionAlgorithm, assertSupportedKeyAgreementAlgorithm, asymmetricJwkKeyTypeMatches, asymmetricPublicJwkMatches, derEcSignatureToRaw, getJwkHumanDescription, getKmsOperationHumanDescription, isJwaHpkeAlgorithm, isJwkAsymmetric, isKmsKeyAgreementDecryptHpke, isKmsKeyAgreementEncryptHpke, isKnownCoseSignatureAlgorithm, isKnownJwaSignatureAlgorithm, keyAgreementPublicJwks, keyAllowsDecrypt, keyAllowsEncrypt, keyAllowsSign, keyAllowsVerify, knownJwaFromCoseSignatureAlgorithm, legacyKeyIdFromPublicJwk, publicJwkFromPrivateJwk, rawEcSignatureToDer, supportedEncryptionAlgsForKey, supportedKeyDerivationAlgsForKey, supportedSigningAlgsForKey };
|
|
51
51
|
}
|
|
52
52
|
//#endregion
|
|
53
|
-
export { Ed25519PublicJwk, type Jwk, type JwkCommon, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KeyManagementModuleConfigOptions, KeyManagementService, type KmsCreateKeyForSignatureAlgorithmOptions, type KmsCreateKeyOptions, type KmsCreateKeyReturn, type KmsCreateKeyType, type KmsCreateKeyTypeAsymmetric, type KmsCreateKeyTypeEc, type KmsCreateKeyTypeOct, type KmsCreateKeyTypeOkp, type KmsCreateKeyTypeRsa, type KmsDecryptDataContentDecryption, type KmsDecryptDataDecryption, type KmsDecryptDataDecryptionAesCbc, type KmsDecryptDataDecryptionAesGcm, type KmsDecryptDataDecryptionC20p, type KmsDecryptDataDecryptionHpke, type KmsDecryptOptions, type KmsDecryptReturn, type KmsDeleteKeyOptions, type KmsEncryptDataContentEncryption, type KmsEncryptDataEncryption, type KmsEncryptDataEncryptionAesCbc, type KmsEncryptDataEncryptionAesGcm, type KmsEncryptDataEncryptionHpke, type KmsEncryptDataEncryptionX20c, type KmsEncryptOptions, type KmsEncryptReturn, type KmsEncryptedKey, type KmsGetPublicKeyOptions, type KmsImportKeyOptions, type KmsImportKeyReturn, type KmsJwkPrivate, type KmsJwkPrivateAsymmetric, type KmsJwkPrivateEc, type KmsJwkPrivateFromKmsJwkPublic, type KmsJwkPrivateOct, type KmsJwkPrivateOkp, type KmsJwkPrivateRsa, type KmsJwkPublic, type KmsJwkPublicAsymmetric, type KmsJwkPublicEc, type KmsJwkPublicEcdh, type KmsJwkPublicFromCreateType, type KmsJwkPublicFromKmsJwkPrivate, type KmsJwkPublicOct, type KmsJwkPublicOkp, type KmsJwkPublicRsa, type KmsKeyAgreementDecryptEcdhEsKw, type KmsKeyAgreementDecryptEcdhHsalsa20, type KmsKeyAgreementDecryptHpke, type KmsKeyAgreementDecryptOptions, type
|
|
53
|
+
export { Ed25519PublicJwk, type Jwk, type JwkCommon, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KeyManagementModuleConfigOptions, KeyManagementService, type KmsCreateKeyForSignatureAlgorithmOptions, type KmsCreateKeyOptions, type KmsCreateKeyReturn, type KmsCreateKeyType, type KmsCreateKeyTypeAsymmetric, type KmsCreateKeyTypeEc, type KmsCreateKeyTypeOct, type KmsCreateKeyTypeOkp, type KmsCreateKeyTypeRsa, type KmsDecryptDataContentDecryption, type KmsDecryptDataDecryption, type KmsDecryptDataDecryptionAesCbc, type KmsDecryptDataDecryptionAesGcm, type KmsDecryptDataDecryptionC20p, type KmsDecryptDataDecryptionHpke, type KmsDecryptOptions, type KmsDecryptReturn, type KmsDeleteKeyOptions, type KmsEncryptAad, type KmsEncryptAadContext, type KmsEncryptDataContentEncryption, type KmsEncryptDataEncryption, type KmsEncryptDataEncryptionAesCbc, type KmsEncryptDataEncryptionAesGcm, type KmsEncryptDataEncryptionHpke, type KmsEncryptDataEncryptionX20c, type KmsEncryptOptions, type KmsEncryptReturn, type KmsEncryptedKey, type KmsGetPublicKeyOptions, type KmsImportKeyOptions, type KmsImportKeyReturn, type KmsJwkPrivate, type KmsJwkPrivateAsymmetric, type KmsJwkPrivateEc, type KmsJwkPrivateFromKmsJwkPublic, type KmsJwkPrivateOct, type KmsJwkPrivateOkp, type KmsJwkPrivateRsa, type KmsJwkPublic, type KmsJwkPublicAsymmetric, type KmsJwkPublicEc, type KmsJwkPublicEcdh, type KmsJwkPublicFromCreateType, type KmsJwkPublicFromKmsJwkPrivate, type KmsJwkPublicOct, type KmsJwkPublicOkp, type KmsJwkPublicRsa, type KmsKeyAgreementDecryptEcdh1Pu, type KmsKeyAgreementDecryptEcdhEs, type KmsKeyAgreementDecryptEcdhEsKw, type KmsKeyAgreementDecryptEcdhHsalsa20, type KmsKeyAgreementDecryptHpke, type KmsKeyAgreementDecryptOptions, type KmsKeyAgreementEncryptEcdh1Pu, type KmsKeyAgreementEncryptEcdhEs, type KmsKeyAgreementEncryptEcdhEsKw, type KmsKeyAgreementEncryptEcdhHsalsa20, type KmsKeyAgreementEncryptHpke, type KmsKeyAgreementEncryptOptions, type KmsOperation, type KmsOperationCreateKey, type KmsOperationDecrypt, type KmsOperationDeleteKey, type KmsOperationEncrypt, type KmsOperationImportKey, type KmsOperationSign, type KmsOperationVerify, type KmsRandomBytesOptions, type KmsRandomBytesReturn, type KmsSignOptions, type KmsSignReturn, type KmsVerifyOptions, type KmsVerifyReturn, type KnownCoseSignatureAlgorithm, KnownCoseSignatureAlgorithms, type KnownJwaContentEncryptionAlgorithm, KnownJwaContentEncryptionAlgorithms, type KnownJwaHpkeAlgorithm, KnownJwaHpkeAlgorithms, type KnownJwaKeyAgreementAlgorithm, KnownJwaKeyAgreementAlgorithms, type KnownJwaKeyEncryptionAlgorithm, KnownJwaKeyEncryptionAlgorithms, type KnownJwaSignatureAlgorithm, KnownJwaSignatureAlgorithms, P256PublicJwk, P384PublicJwk, P521PublicJwk, PublicJwk, RsaPublicJwk, Secp256k1PublicJwk, X25519PublicJwk, allowedEncryptionAlgsForKey, allowedKeyDerivationAlgsForKey, allowedSigningAlgsForSigningKey, assertAllowedEncryptionAlgForKey, assertAllowedKeyDerivationAlgForKey, assertAllowedSigningAlgForKey, assertAsymmetricJwkKeyTypeMatches, assertJwkAsymmetric, assertJwkHasNoPrivateKeyMaterial, assertKeyAllowsDecrypt, assertKeyAllowsDerive, assertKeyAllowsEncrypt, assertKeyAllowsSign, assertKeyAllowsVerify, assertSupportedEncryptionAlgorithm, assertSupportedKeyAgreementAlgorithm, asymmetricJwkKeyTypeMatches, asymmetricPublicJwkMatches, derEcSignatureToRaw, getJwkHumanDescription, getKmsOperationHumanDescription, index_d_exports, isJwaHpkeAlgorithm, isJwkAsymmetric, isKmsKeyAgreementDecryptHpke, isKmsKeyAgreementEncryptHpke, isKnownCoseSignatureAlgorithm, isKnownJwaSignatureAlgorithm, keyAgreementPublicJwks, keyAllowsDecrypt, keyAllowsEncrypt, keyAllowsSign, keyAllowsVerify, knownJwaFromCoseSignatureAlgorithm, legacyKeyIdFromPublicJwk, publicJwkFromPrivateJwk, rawEcSignatureToDer, supportedEncryptionAlgsForKey, supportedKeyDerivationAlgsForKey, supportedSigningAlgsForKey };
|
|
54
54
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -28,7 +28,7 @@ import "./jwk/index.mjs";
|
|
|
28
28
|
import { KeyManagementModuleConfig } from "./KeyManagementModuleConfig.mjs";
|
|
29
29
|
import { isKmsKeyAgreementEncryptHpke } from "./options/KmsKeyAgreementEncryptOptions.mjs";
|
|
30
30
|
import { isKmsKeyAgreementDecryptHpke } from "./options/KmsKeyAgreementDecryptOptions.mjs";
|
|
31
|
-
import { getKmsOperationHumanDescription } from "./options/KmsOperation.mjs";
|
|
31
|
+
import { getKmsOperationHumanDescription, keyAgreementPublicJwks } from "./options/KmsOperation.mjs";
|
|
32
32
|
import "./options/index.mjs";
|
|
33
33
|
import { KeyManagementApi } from "./KeyManagementApi.mjs";
|
|
34
34
|
import { KeyManagementModule } from "./KeyManagementModule.mjs";
|
|
@@ -82,6 +82,7 @@ var kms_exports = /* @__PURE__ */ __exportAll({
|
|
|
82
82
|
isKmsKeyAgreementEncryptHpke: () => isKmsKeyAgreementEncryptHpke,
|
|
83
83
|
isKnownCoseSignatureAlgorithm: () => isKnownCoseSignatureAlgorithm,
|
|
84
84
|
isKnownJwaSignatureAlgorithm: () => isKnownJwaSignatureAlgorithm,
|
|
85
|
+
keyAgreementPublicJwks: () => keyAgreementPublicJwks,
|
|
85
86
|
keyAllowsDecrypt: () => keyAllowsDecrypt,
|
|
86
87
|
keyAllowsEncrypt: () => keyAllowsEncrypt,
|
|
87
88
|
keyAllowsSign: () => keyAllowsSign,
|
|
@@ -95,6 +96,6 @@ var kms_exports = /* @__PURE__ */ __exportAll({
|
|
|
95
96
|
supportedSigningAlgsForKey: () => supportedSigningAlgsForKey
|
|
96
97
|
});
|
|
97
98
|
//#endregion
|
|
98
|
-
export { Ed25519PublicJwk, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KnownCoseSignatureAlgorithms, KnownJwaContentEncryptionAlgorithms, KnownJwaHpkeAlgorithms, KnownJwaKeyAgreementAlgorithms, KnownJwaKeyEncryptionAlgorithms, KnownJwaSignatureAlgorithms, P256PublicJwk, P384PublicJwk, P521PublicJwk, PublicJwk, RsaPublicJwk, Secp256k1PublicJwk, X25519PublicJwk, allowedEncryptionAlgsForKey, allowedKeyDerivationAlgsForKey, allowedSigningAlgsForSigningKey, assertAllowedEncryptionAlgForKey, assertAllowedKeyDerivationAlgForKey, assertAllowedSigningAlgForKey, assertAsymmetricJwkKeyTypeMatches, assertJwkAsymmetric, assertJwkHasNoPrivateKeyMaterial, assertKeyAllowsDecrypt, assertKeyAllowsDerive, assertKeyAllowsEncrypt, assertKeyAllowsSign, assertKeyAllowsVerify, assertSupportedEncryptionAlgorithm, assertSupportedKeyAgreementAlgorithm, asymmetricJwkKeyTypeMatches, asymmetricPublicJwkMatches, derEcSignatureToRaw, getJwkHumanDescription, getKmsOperationHumanDescription, isJwaHpkeAlgorithm, isJwkAsymmetric, isKmsKeyAgreementDecryptHpke, isKmsKeyAgreementEncryptHpke, isKnownCoseSignatureAlgorithm, isKnownJwaSignatureAlgorithm, keyAllowsDecrypt, keyAllowsEncrypt, keyAllowsSign, keyAllowsVerify, kms_exports, knownJwaFromCoseSignatureAlgorithm, legacyKeyIdFromPublicJwk, publicJwkFromPrivateJwk, rawEcSignatureToDer, supportedEncryptionAlgsForKey, supportedKeyDerivationAlgsForKey, supportedSigningAlgsForKey };
|
|
99
|
+
export { Ed25519PublicJwk, KeyManagementAlgorithmNotSupportedError, KeyManagementApi, KeyManagementError, KeyManagementKeyExistsError, KeyManagementKeyNotFoundError, KeyManagementModule, KeyManagementModuleConfig, KnownCoseSignatureAlgorithms, KnownJwaContentEncryptionAlgorithms, KnownJwaHpkeAlgorithms, KnownJwaKeyAgreementAlgorithms, KnownJwaKeyEncryptionAlgorithms, KnownJwaSignatureAlgorithms, P256PublicJwk, P384PublicJwk, P521PublicJwk, PublicJwk, RsaPublicJwk, Secp256k1PublicJwk, X25519PublicJwk, allowedEncryptionAlgsForKey, allowedKeyDerivationAlgsForKey, allowedSigningAlgsForSigningKey, assertAllowedEncryptionAlgForKey, assertAllowedKeyDerivationAlgForKey, assertAllowedSigningAlgForKey, assertAsymmetricJwkKeyTypeMatches, assertJwkAsymmetric, assertJwkHasNoPrivateKeyMaterial, assertKeyAllowsDecrypt, assertKeyAllowsDerive, assertKeyAllowsEncrypt, assertKeyAllowsSign, assertKeyAllowsVerify, assertSupportedEncryptionAlgorithm, assertSupportedKeyAgreementAlgorithm, asymmetricJwkKeyTypeMatches, asymmetricPublicJwkMatches, derEcSignatureToRaw, getJwkHumanDescription, getKmsOperationHumanDescription, isJwaHpkeAlgorithm, isJwkAsymmetric, isKmsKeyAgreementDecryptHpke, isKmsKeyAgreementEncryptHpke, isKnownCoseSignatureAlgorithm, isKnownJwaSignatureAlgorithm, keyAgreementPublicJwks, keyAllowsDecrypt, keyAllowsEncrypt, keyAllowsSign, keyAllowsVerify, kms_exports, knownJwaFromCoseSignatureAlgorithm, legacyKeyIdFromPublicJwk, publicJwkFromPrivateJwk, rawEcSignatureToDer, supportedEncryptionAlgsForKey, supportedKeyDerivationAlgsForKey, supportedSigningAlgsForKey };
|
|
99
100
|
|
|
100
101
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyDerivation.d.mts","names":[],"sources":["../../../../../src/modules/kms/jwk/alg/keyDerivation.ts"],"mappings":";;;;wBAagB,iCACd,KAAK,gBAAgB,QAAQ,cAAc,mBAC1C;;;;;;;
|
|
1
|
+
{"version":3,"file":"keyDerivation.d.mts","names":[],"sources":["../../../../../src/modules/kms/jwk/alg/keyDerivation.ts"],"mappings":";;;;wBAagB,iCACd,KAAK,gBAAgB,QAAQ,cAAc,mBAC1C;;;;;;;wBAoCa,+BACd,KAAK,gBAAgB,QAAQ,cAAc,mBAC1C;wBAca,oCACd,KAAK,gBAAgB,QAAQ,cAAc,kBAC3C,WAAW"}
|
|
@@ -13,6 +13,11 @@ function supportedKeyDerivationAlgsForKey(jwk) {
|
|
|
13
13
|
"X25519",
|
|
14
14
|
"secp256k1"
|
|
15
15
|
].includes(jwk.crv)) algs.push("ECDH-ES", "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW");
|
|
16
|
+
if (isCrvJwk(jwk) && [
|
|
17
|
+
"P-256",
|
|
18
|
+
"P-384",
|
|
19
|
+
"X25519"
|
|
20
|
+
].includes(jwk.crv)) algs.push("ECDH-1PU+A256KW");
|
|
16
21
|
if (isCrvJwk(jwk) && jwk.crv === "P-256") algs.push("HPKE-0", "HPKE-7");
|
|
17
22
|
if (isCrvJwk(jwk) && jwk.crv === "X25519") algs.push("HPKE-3");
|
|
18
23
|
if (jwk.kty === "OKP" && (jwk.crv === "X25519" || jwk.crv === "Ed25519")) algs.push("ECDH-HSALSA20");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyDerivation.mjs","names":[],"sources":["../../../../../src/modules/kms/jwk/alg/keyDerivation.ts"],"sourcesContent":["import { KeyManagementError } from '../../error/KeyManagementError'\nimport { getJwkHumanDescription } from '../humanDescription'\nimport type { KnownJwaKeyAgreementAlgorithm } from '../jwa'\nimport type { KmsJwkPrivate, KmsJwkPublic, KmsJwkPublicCrv } from '../knownJwk'\nimport type { KmsJwkPrivateOct, KmsJwkPublicOct } from '../kty/oct/octJwk'\nimport type { KmsJwkPrivateRsa, KmsJwkPublicRsa } from '../kty/rsa/rsaJwk'\n\nfunction isCrvJwk<Jwk extends KmsJwkPrivate | KmsJwkPublic>(\n jwk: Jwk\n): jwk is Exclude<Jwk, KmsJwkPrivateOct | KmsJwkPrivateRsa | KmsJwkPublicOct | KmsJwkPublicRsa> {\n return jwk.kty === 'EC' || jwk.kty === 'OKP'\n}\n\nexport function supportedKeyDerivationAlgsForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>\n): KnownJwaKeyAgreementAlgorithm[] {\n const algs: KnownJwaKeyAgreementAlgorithm[] = []\n\n const allowedCurves: KmsJwkPublicCrv['crv'][] = ['P-256', 'P-384', 'P-521', 'X25519', 'secp256k1']\n if (isCrvJwk(jwk) && allowedCurves.includes(jwk.crv)) {\n algs.push('ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW')\n }\n\n // The HPKE suites bind a specific KEM, so each is only valid for its own curve.\n if (isCrvJwk(jwk) && jwk.crv === 'P-256') {\n algs.push('HPKE-0', 'HPKE-7')\n }\n if (isCrvJwk(jwk) && jwk.crv === 'X25519') {\n algs.push('HPKE-3')\n }\n\n // Special case where we allow Ed25519 for X25519 based operation, since that is\n // how DIDComm v1 works.\n if (jwk.kty === 'OKP' && (jwk.crv === 'X25519' || jwk.crv === 'Ed25519')) {\n algs.push('ECDH-HSALSA20')\n }\n\n return algs\n}\n\n/**\n * Get the allowed key derivation algs for a key. If takes all the known supported\n * algs and will filter these based on the optional `alg` key in the JWK.\n *\n * This does not handle the intended key `use` and `key_ops`.\n */\nexport function allowedKeyDerivationAlgsForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>\n): KnownJwaKeyAgreementAlgorithm[] {\n const supportedAlgs = supportedKeyDerivationAlgsForKey(jwk)\n const allowedAlg = jwk.alg\n\n return !allowedAlg\n ? // If no `alg` specified on jwk, return all supported algs\n supportedAlgs\n : // If `alg` is specified and supported, return the allowed alg\n allowedAlg && supportedAlgs.includes(allowedAlg as KnownJwaKeyAgreementAlgorithm)\n ? [allowedAlg as KnownJwaKeyAgreementAlgorithm]\n : // Otherwise nothing is allowed (`alg` is specified but not supported)\n []\n}\n\nexport function assertAllowedKeyDerivationAlgForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>,\n algorithm: KnownJwaKeyAgreementAlgorithm\n) {\n const allowedAlgs = allowedKeyDerivationAlgsForKey(jwk)\n if (!allowedAlgs.includes(algorithm)) {\n const allowedAlgsText =\n allowedAlgs.length > 0 ? ` Allowed algs are ${allowedAlgs.map((alg) => `'${alg}'`).join(', ')}` : ''\n throw new KeyManagementError(\n `${getJwkHumanDescription(\n jwk\n )} cannot be used with algorithm '${algorithm}' for key derivation.${allowedAlgsText}`\n )\n }\n}\n"],"mappings":";;;AAOA,SAAS,SACP,KAC8F;CAC9F,OAAO,IAAI,QAAQ,QAAQ,IAAI,QAAQ;AACzC;AAEA,SAAgB,iCACd,KACiC;CACjC,MAAM,OAAwC,CAAC;CAG/C,IAAI,SAAS,GAAG,KAAK;EAD4B;EAAS;EAAS;EAAS;EAAU;CACrD,CAAC,CAAC,SAAS,IAAI,GAAG,GACjD,KAAK,KAAK,WAAW,kBAAkB,kBAAkB,gBAAgB;CAI3E,IAAI,SAAS,GAAG,KAAK,IAAI,QAAQ,SAC/B,KAAK,KAAK,UAAU,QAAQ;CAE9B,IAAI,SAAS,GAAG,KAAK,IAAI,QAAQ,UAC/B,KAAK,KAAK,QAAQ;CAKpB,IAAI,IAAI,QAAQ,UAAU,IAAI,QAAQ,YAAY,IAAI,QAAQ,YAC5D,KAAK,KAAK,eAAe;CAG3B,OAAO;AACT;;;;;;;AAQA,SAAgB,+BACd,KACiC;CACjC,MAAM,gBAAgB,iCAAiC,GAAG;CAC1D,MAAM,aAAa,IAAI;CAEvB,OAAO,CAAC,aAEJ,gBAEA,cAAc,cAAc,SAAS,UAA2C,IAC9E,CAAC,UAA2C,IAE5C,CAAC;AACT;AAEA,SAAgB,oCACd,KACA,WACA;CACA,MAAM,cAAc,+BAA+B,GAAG;CACtD,IAAI,CAAC,YAAY,SAAS,SAAS,GAAG;EACpC,MAAM,kBACJ,YAAY,SAAS,IAAI,qBAAqB,YAAY,KAAK,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,MAAM;EACpG,MAAM,IAAI,mBACR,GAAG,uBACD,GACF,EAAE,kCAAkC,UAAU,uBAAuB,iBACvE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"keyDerivation.mjs","names":[],"sources":["../../../../../src/modules/kms/jwk/alg/keyDerivation.ts"],"sourcesContent":["import { KeyManagementError } from '../../error/KeyManagementError'\nimport { getJwkHumanDescription } from '../humanDescription'\nimport type { KnownJwaKeyAgreementAlgorithm } from '../jwa'\nimport type { KmsJwkPrivate, KmsJwkPublic, KmsJwkPublicCrv } from '../knownJwk'\nimport type { KmsJwkPrivateOct, KmsJwkPublicOct } from '../kty/oct/octJwk'\nimport type { KmsJwkPrivateRsa, KmsJwkPublicRsa } from '../kty/rsa/rsaJwk'\n\nfunction isCrvJwk<Jwk extends KmsJwkPrivate | KmsJwkPublic>(\n jwk: Jwk\n): jwk is Exclude<Jwk, KmsJwkPrivateOct | KmsJwkPrivateRsa | KmsJwkPublicOct | KmsJwkPublicRsa> {\n return jwk.kty === 'EC' || jwk.kty === 'OKP'\n}\n\nexport function supportedKeyDerivationAlgsForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>\n): KnownJwaKeyAgreementAlgorithm[] {\n const algs: KnownJwaKeyAgreementAlgorithm[] = []\n\n const allowedCurves: KmsJwkPublicCrv['crv'][] = ['P-256', 'P-384', 'P-521', 'X25519', 'secp256k1']\n if (isCrvJwk(jwk) && allowedCurves.includes(jwk.crv)) {\n algs.push('ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW')\n }\n\n const ecdh1PuCurves: KmsJwkPublicCrv['crv'][] = ['P-256', 'P-384', 'X25519']\n if (isCrvJwk(jwk) && ecdh1PuCurves.includes(jwk.crv)) {\n algs.push('ECDH-1PU+A256KW')\n }\n\n // The HPKE suites bind a specific KEM, so each is only valid for its own curve.\n if (isCrvJwk(jwk) && jwk.crv === 'P-256') {\n algs.push('HPKE-0', 'HPKE-7')\n }\n if (isCrvJwk(jwk) && jwk.crv === 'X25519') {\n algs.push('HPKE-3')\n }\n\n // Special case where we allow Ed25519 for X25519 based operation, since that is\n // how DIDComm v1 works.\n if (jwk.kty === 'OKP' && (jwk.crv === 'X25519' || jwk.crv === 'Ed25519')) {\n algs.push('ECDH-HSALSA20')\n }\n\n return algs\n}\n\n/**\n * Get the allowed key derivation algs for a key. If takes all the known supported\n * algs and will filter these based on the optional `alg` key in the JWK.\n *\n * This does not handle the intended key `use` and `key_ops`.\n */\nexport function allowedKeyDerivationAlgsForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>\n): KnownJwaKeyAgreementAlgorithm[] {\n const supportedAlgs = supportedKeyDerivationAlgsForKey(jwk)\n const allowedAlg = jwk.alg\n\n return !allowedAlg\n ? // If no `alg` specified on jwk, return all supported algs\n supportedAlgs\n : // If `alg` is specified and supported, return the allowed alg\n allowedAlg && supportedAlgs.includes(allowedAlg as KnownJwaKeyAgreementAlgorithm)\n ? [allowedAlg as KnownJwaKeyAgreementAlgorithm]\n : // Otherwise nothing is allowed (`alg` is specified but not supported)\n []\n}\n\nexport function assertAllowedKeyDerivationAlgForKey(\n jwk: KmsJwkPrivate | Exclude<KmsJwkPublic, KmsJwkPublicOct>,\n algorithm: KnownJwaKeyAgreementAlgorithm\n) {\n const allowedAlgs = allowedKeyDerivationAlgsForKey(jwk)\n if (!allowedAlgs.includes(algorithm)) {\n const allowedAlgsText =\n allowedAlgs.length > 0 ? ` Allowed algs are ${allowedAlgs.map((alg) => `'${alg}'`).join(', ')}` : ''\n throw new KeyManagementError(\n `${getJwkHumanDescription(\n jwk\n )} cannot be used with algorithm '${algorithm}' for key derivation.${allowedAlgsText}`\n )\n }\n}\n"],"mappings":";;;AAOA,SAAS,SACP,KAC8F;CAC9F,OAAO,IAAI,QAAQ,QAAQ,IAAI,QAAQ;AACzC;AAEA,SAAgB,iCACd,KACiC;CACjC,MAAM,OAAwC,CAAC;CAG/C,IAAI,SAAS,GAAG,KAAK;EAD4B;EAAS;EAAS;EAAS;EAAU;CACrD,CAAC,CAAC,SAAS,IAAI,GAAG,GACjD,KAAK,KAAK,WAAW,kBAAkB,kBAAkB,gBAAgB;CAI3E,IAAI,SAAS,GAAG,KAAK;EAD4B;EAAS;EAAS;CAClC,CAAC,CAAC,SAAS,IAAI,GAAG,GACjD,KAAK,KAAK,iBAAiB;CAI7B,IAAI,SAAS,GAAG,KAAK,IAAI,QAAQ,SAC/B,KAAK,KAAK,UAAU,QAAQ;CAE9B,IAAI,SAAS,GAAG,KAAK,IAAI,QAAQ,UAC/B,KAAK,KAAK,QAAQ;CAKpB,IAAI,IAAI,QAAQ,UAAU,IAAI,QAAQ,YAAY,IAAI,QAAQ,YAC5D,KAAK,KAAK,eAAe;CAG3B,OAAO;AACT;;;;;;;AAQA,SAAgB,+BACd,KACiC;CACjC,MAAM,gBAAgB,iCAAiC,GAAG;CAC1D,MAAM,aAAa,IAAI;CAEvB,OAAO,CAAC,aAEJ,gBAEA,cAAc,cAAc,SAAS,UAA2C,IAC9E,CAAC,UAA2C,IAE5C,CAAC;AACT;AAEA,SAAgB,oCACd,KACA,WACA;CACA,MAAM,cAAc,+BAA+B,GAAG;CACtD,IAAI,CAAC,YAAY,SAAS,SAAS,GAAG;EACpC,MAAM,kBACJ,YAAY,SAAS,IAAI,qBAAqB,YAAY,KAAK,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,IAAI,MAAM;EACpG,MAAM,IAAI,mBACR,GAAG,uBACD,GACF,EAAE,kCAAkC,UAAU,uBAAuB,iBACvE;CACF;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { KnownJwaContentEncryptionAlgorithm, KnownJwaKeyAgreementAlgorithm, KnownJwaKeyEncryptionAlgorithm } from "./jwa.mjs";
|
|
2
2
|
import { KmsDecryptDataDecryption } from "../options/KmsDecryptOptions.mjs";
|
|
3
|
+
import { KmsKeyAgreementEncryptOptions } from "../options/KmsKeyAgreementEncryptOptions.mjs";
|
|
3
4
|
import { KmsEncryptDataEncryption } from "../options/KmsEncryptOptions.mjs";
|
|
4
5
|
import { KmsKeyAgreementDecryptOptions } from "../options/KmsKeyAgreementDecryptOptions.mjs";
|
|
5
|
-
import { KmsKeyAgreementEncryptOptions } from "../options/KmsKeyAgreementEncryptOptions.mjs";
|
|
6
6
|
import "../options/index.mjs";
|
|
7
7
|
//#region src/modules/kms/jwk/assertSupported.d.ts
|
|
8
8
|
export declare function assertSupportedKeyAgreementAlgorithm<KeyAgreement extends KmsKeyAgreementEncryptOptions | KmsKeyAgreementDecryptOptions, SupportedAlgorithms extends KnownJwaKeyAgreementAlgorithm[]>(keyAgreement: KeyAgreement, supportedAlgorithms: SupportedAlgorithms, backend: string): asserts keyAgreement is KeyAgreement & {
|
|
@@ -18,7 +18,6 @@ export declare const KnownJwaSignatureAlgorithms: {
|
|
|
18
18
|
readonly ES256K: "ES256K";
|
|
19
19
|
};
|
|
20
20
|
export declare const zKnownJwaSignatureAlgorithm: z$1.ZodEnum<{
|
|
21
|
-
Ed25519: "Ed25519";
|
|
22
21
|
HS256: "HS256";
|
|
23
22
|
HS384: "HS384";
|
|
24
23
|
HS512: "HS512";
|
|
@@ -32,6 +31,7 @@ export declare const zKnownJwaSignatureAlgorithm: z$1.ZodEnum<{
|
|
|
32
31
|
PS384: "PS384";
|
|
33
32
|
PS512: "PS512";
|
|
34
33
|
EdDSA: "EdDSA";
|
|
34
|
+
Ed25519: "Ed25519";
|
|
35
35
|
ES256K: "ES256K";
|
|
36
36
|
}>;
|
|
37
37
|
export type KnownJwaSignatureAlgorithm = z$1.output<typeof zKnownJwaSignatureAlgorithm>;
|
|
@@ -83,6 +83,7 @@ export declare const KnownJwaKeyAgreementAlgorithms: {
|
|
|
83
83
|
readonly ECDH_ES_A192KW: "ECDH-ES+A192KW";
|
|
84
84
|
readonly ECDH_ES_A256KW: "ECDH-ES+A256KW";
|
|
85
85
|
readonly ECDH_HSALSA20: "ECDH-HSALSA20";
|
|
86
|
+
readonly ECDH_1PU_A256KW: "ECDH-1PU+A256KW";
|
|
86
87
|
readonly HPKE_0: "HPKE-0";
|
|
87
88
|
readonly HPKE_3: "HPKE-3";
|
|
88
89
|
readonly HPKE_7: "HPKE-7";
|
|
@@ -92,6 +93,7 @@ declare const zKnownJwaKeyAgreementAlgorithm: z$1.ZodEnum<{
|
|
|
92
93
|
"ECDH-ES+A128KW": "ECDH-ES+A128KW";
|
|
93
94
|
"ECDH-ES+A192KW": "ECDH-ES+A192KW";
|
|
94
95
|
"ECDH-ES+A256KW": "ECDH-ES+A256KW";
|
|
96
|
+
"ECDH-1PU+A256KW": "ECDH-1PU+A256KW";
|
|
95
97
|
"ECDH-HSALSA20": "ECDH-HSALSA20";
|
|
96
98
|
"HPKE-0": "HPKE-0";
|
|
97
99
|
"HPKE-3": "HPKE-3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwa.d.mts","names":["z"],"sources":["../../../../src/modules/kms/jwk/jwa.ts"],"mappings":";;qBAUa;;;;;;;;;;;;;;;;;qBAkBA,6BAA2BA,IAAA;;;;;;;;;;;;;;;;;YAC5B,6BAA6BA,IAAE,cAAc;wBAEzC,6BAA6B,cAAc,OAAO;qBAKrD;;;;;;;;;;;;;;;;qBAuBA,qCAAmCA,IAAA;;;;;;;;;;;;;YACpC,qCAAqCA,IAAE,cAAc;qBAEpD;;;;;cAMP,iCAA+BA,IAAA;;;;;YACzB,iCAAiCA,IAAE,cAAc;qBAGhD
|
|
1
|
+
{"version":3,"file":"jwa.d.mts","names":["z"],"sources":["../../../../src/modules/kms/jwk/jwa.ts"],"mappings":";;qBAUa;;;;;;;;;;;;;;;;;qBAkBA,6BAA2BA,IAAA;;;;;;;;;;;;;;;;;YAC5B,6BAA6BA,IAAE,cAAc;wBAEzC,6BAA6B,cAAc,OAAO;qBAKrD;;;;;;;;;;;;;;;;qBAuBA,qCAAmCA,IAAA;;;;;;;;;;;;;YACpC,qCAAqCA,IAAE,cAAc;qBAEpD;;;;;cAMP,iCAA+BA,IAAA;;;;;YACzB,iCAAiCA,IAAE,cAAc;qBAGhD;;;;;;;;;;;cAsBP,gCAA8BA,IAAA;;;;;;;;;;;YACxB,gCAAgCA,IAAE,cAAc;qBAE/C;qBAKA,wBAAsBA,IAAA;;;;;YACvB,wBAAwBA,IAAE,cAAc;wBAEpC,mBAAmB,oBAAoB,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwa.mjs","names":["z"],"sources":["../../../../src/modules/kms/jwk/jwa.ts"],"sourcesContent":["import { z } from 'zod'\n\nfunction recordToUnion<T>(record: Record<string, T>) {\n return Object.values(record) as [\n (typeof record)[keyof typeof record],\n (typeof record)[keyof typeof record],\n ...(typeof record)[keyof typeof record][],\n ]\n}\n\nexport const KnownJwaSignatureAlgorithms = {\n HS256: 'HS256',\n HS384: 'HS384',\n HS512: 'HS512',\n RS256: 'RS256',\n RS384: 'RS384',\n RS512: 'RS512',\n ES256: 'ES256',\n ES384: 'ES384',\n ES512: 'ES512',\n PS256: 'PS256',\n PS384: 'PS384',\n PS512: 'PS512',\n EdDSA: 'EdDSA',\n Ed25519: 'Ed25519',\n ES256K: 'ES256K',\n} as const\n\nexport const zKnownJwaSignatureAlgorithm = z.enum(recordToUnion(KnownJwaSignatureAlgorithms))\nexport type KnownJwaSignatureAlgorithm = z.output<typeof zKnownJwaSignatureAlgorithm>\n\nexport function isKnownJwaSignatureAlgorithm(alg: string): alg is KnownJwaSignatureAlgorithm {\n return Object.values(KnownJwaSignatureAlgorithms).includes(alg as keyof typeof KnownJwaSignatureAlgorithms)\n}\n\n// Content encryption algorithms (\"enc\" parameter)\nexport const KnownJwaContentEncryptionAlgorithms = {\n // AES-GCM Content Encryption\n A128GCM: 'A128GCM',\n A192GCM: 'A192GCM',\n A256GCM: 'A256GCM',\n\n // AES-CBC Content Encryption\n A128CBC: 'A128CBC',\n A256CBC: 'A256CBC',\n\n // (X)ChaCha20-Poly1305\n C20P: 'C20P',\n XC20P: 'XC20P',\n\n /**\n * As is used in DIDComm v1\n */\n 'XSALSA20-POLY1305': 'XSALSA20-POLY1305',\n\n A128CBC_HS256: 'A128CBC-HS256',\n A192CBC_HS384: 'A192CBC-HS384',\n A256CBC_HS512: 'A256CBC-HS512',\n} as const\nexport const zKnownJwaContentEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaContentEncryptionAlgorithms))\nexport type KnownJwaContentEncryptionAlgorithm = z.output<typeof zKnownJwaContentEncryptionAlgorithm>\n\nexport const KnownJwaKeyEncryptionAlgorithms = {\n // AES Key Wrapping\n A128KW: 'A128KW',\n A192KW: 'A192KW',\n A256KW: 'A256KW',\n} as const\nconst zKnownJwaKeyEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaKeyEncryptionAlgorithms))\nexport type KnownJwaKeyEncryptionAlgorithm = z.output<typeof zKnownJwaKeyEncryptionAlgorithm>\n\n// Key derivation / wrapping algorithms (\"alg\" parameter)\nexport const KnownJwaKeyAgreementAlgorithms = {\n // ECDH-ES with P-256/P-384/P-521\n ECDH_ES: 'ECDH-ES',\n ECDH_ES_A128KW: 'ECDH-ES+A128KW',\n ECDH_ES_A192KW: 'ECDH-ES+A192KW',\n ECDH_ES_A256KW: 'ECDH-ES+A256KW',\n\n ECDH_HSALSA20: 'ECDH-HSALSA20',\n\n // HPKE (RFC 9180) in integrated encryption mode, named after\n // draft-ietf-jose-hpke-encrypt. The suite fixes the AEAD, so no separate content encryption\n // algorithm is used:\n // - HPKE-0: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-3: DHKEM(X25519, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-7: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM\n HPKE_0: 'HPKE-0',\n HPKE_3: 'HPKE-3',\n HPKE_7: 'HPKE-7',\n} as const\nconst zKnownJwaKeyAgreementAlgorithm = z.enum(recordToUnion(KnownJwaKeyAgreementAlgorithms))\nexport type KnownJwaKeyAgreementAlgorithm = z.output<typeof zKnownJwaKeyAgreementAlgorithm>\n\nexport const KnownJwaHpkeAlgorithms = [\n KnownJwaKeyAgreementAlgorithms.HPKE_0,\n KnownJwaKeyAgreementAlgorithms.HPKE_3,\n KnownJwaKeyAgreementAlgorithms.HPKE_7,\n] as const\nexport const zKnownJwaHpkeAlgorithm = z.enum(KnownJwaHpkeAlgorithms)\nexport type KnownJwaHpkeAlgorithm = z.output<typeof zKnownJwaHpkeAlgorithm>\n\nexport function isJwaHpkeAlgorithm(algorithm: string): algorithm is KnownJwaHpkeAlgorithm {\n return (KnownJwaHpkeAlgorithms as readonly string[]).includes(algorithm)\n}\n"],"mappings":";;AAEA,SAAS,cAAiB,QAA2B;CACnD,OAAO,OAAO,OAAO,MAAM;AAK7B;AAEA,MAAa,8BAA8B;CACzC,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,SAAS;CACT,QAAQ;AACV;AAEA,MAAa,8BAA8BA,IAAE,KAAK,cAAc,2BAA2B,CAAC;AAG5F,SAAgB,6BAA6B,KAAgD;CAC3F,OAAO,OAAO,OAAO,2BAA2B,CAAC,CAAC,SAAS,GAA+C;AAC5G;AAGA,MAAa,sCAAsC;CAEjD,SAAS;CACT,SAAS;CACT,SAAS;CAGT,SAAS;CACT,SAAS;CAGT,MAAM;CACN,OAAO;;;;CAKP,qBAAqB;CAErB,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AACmDA,IAAE,KAAK,cAAc,mCAAmC,CAAC;AAG5G,MAAa,kCAAkC;CAE7C,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AACwCA,IAAE,KAAK,cAAc,+BAA+B,CAAC;AAI7F,MAAa,iCAAiC;CAE5C,SAAS;CACT,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAEhB,eAAe;
|
|
1
|
+
{"version":3,"file":"jwa.mjs","names":["z"],"sources":["../../../../src/modules/kms/jwk/jwa.ts"],"sourcesContent":["import { z } from 'zod'\n\nfunction recordToUnion<T>(record: Record<string, T>) {\n return Object.values(record) as [\n (typeof record)[keyof typeof record],\n (typeof record)[keyof typeof record],\n ...(typeof record)[keyof typeof record][],\n ]\n}\n\nexport const KnownJwaSignatureAlgorithms = {\n HS256: 'HS256',\n HS384: 'HS384',\n HS512: 'HS512',\n RS256: 'RS256',\n RS384: 'RS384',\n RS512: 'RS512',\n ES256: 'ES256',\n ES384: 'ES384',\n ES512: 'ES512',\n PS256: 'PS256',\n PS384: 'PS384',\n PS512: 'PS512',\n EdDSA: 'EdDSA',\n Ed25519: 'Ed25519',\n ES256K: 'ES256K',\n} as const\n\nexport const zKnownJwaSignatureAlgorithm = z.enum(recordToUnion(KnownJwaSignatureAlgorithms))\nexport type KnownJwaSignatureAlgorithm = z.output<typeof zKnownJwaSignatureAlgorithm>\n\nexport function isKnownJwaSignatureAlgorithm(alg: string): alg is KnownJwaSignatureAlgorithm {\n return Object.values(KnownJwaSignatureAlgorithms).includes(alg as keyof typeof KnownJwaSignatureAlgorithms)\n}\n\n// Content encryption algorithms (\"enc\" parameter)\nexport const KnownJwaContentEncryptionAlgorithms = {\n // AES-GCM Content Encryption\n A128GCM: 'A128GCM',\n A192GCM: 'A192GCM',\n A256GCM: 'A256GCM',\n\n // AES-CBC Content Encryption\n A128CBC: 'A128CBC',\n A256CBC: 'A256CBC',\n\n // (X)ChaCha20-Poly1305\n C20P: 'C20P',\n XC20P: 'XC20P',\n\n /**\n * As is used in DIDComm v1\n */\n 'XSALSA20-POLY1305': 'XSALSA20-POLY1305',\n\n A128CBC_HS256: 'A128CBC-HS256',\n A192CBC_HS384: 'A192CBC-HS384',\n A256CBC_HS512: 'A256CBC-HS512',\n} as const\nexport const zKnownJwaContentEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaContentEncryptionAlgorithms))\nexport type KnownJwaContentEncryptionAlgorithm = z.output<typeof zKnownJwaContentEncryptionAlgorithm>\n\nexport const KnownJwaKeyEncryptionAlgorithms = {\n // AES Key Wrapping\n A128KW: 'A128KW',\n A192KW: 'A192KW',\n A256KW: 'A256KW',\n} as const\nconst zKnownJwaKeyEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaKeyEncryptionAlgorithms))\nexport type KnownJwaKeyEncryptionAlgorithm = z.output<typeof zKnownJwaKeyEncryptionAlgorithm>\n\n// Key derivation / wrapping algorithms (\"alg\" parameter)\nexport const KnownJwaKeyAgreementAlgorithms = {\n // ECDH-ES with P-256/P-384/P-521\n ECDH_ES: 'ECDH-ES',\n ECDH_ES_A128KW: 'ECDH-ES+A128KW',\n ECDH_ES_A192KW: 'ECDH-ES+A192KW',\n ECDH_ES_A256KW: 'ECDH-ES+A256KW',\n\n ECDH_HSALSA20: 'ECDH-HSALSA20',\n\n // https://datatracker.ietf.org/doc/html/draft-madden-jose-ecdh-1pu-04\n ECDH_1PU_A256KW: 'ECDH-1PU+A256KW',\n\n // HPKE (RFC 9180) in integrated encryption mode, named after\n // draft-ietf-jose-hpke-encrypt. The suite fixes the AEAD, so no separate content encryption\n // algorithm is used:\n // - HPKE-0: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-3: DHKEM(X25519, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-7: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM\n HPKE_0: 'HPKE-0',\n HPKE_3: 'HPKE-3',\n HPKE_7: 'HPKE-7',\n} as const\nconst zKnownJwaKeyAgreementAlgorithm = z.enum(recordToUnion(KnownJwaKeyAgreementAlgorithms))\nexport type KnownJwaKeyAgreementAlgorithm = z.output<typeof zKnownJwaKeyAgreementAlgorithm>\n\nexport const KnownJwaHpkeAlgorithms = [\n KnownJwaKeyAgreementAlgorithms.HPKE_0,\n KnownJwaKeyAgreementAlgorithms.HPKE_3,\n KnownJwaKeyAgreementAlgorithms.HPKE_7,\n] as const\nexport const zKnownJwaHpkeAlgorithm = z.enum(KnownJwaHpkeAlgorithms)\nexport type KnownJwaHpkeAlgorithm = z.output<typeof zKnownJwaHpkeAlgorithm>\n\nexport function isJwaHpkeAlgorithm(algorithm: string): algorithm is KnownJwaHpkeAlgorithm {\n return (KnownJwaHpkeAlgorithms as readonly string[]).includes(algorithm)\n}\n"],"mappings":";;AAEA,SAAS,cAAiB,QAA2B;CACnD,OAAO,OAAO,OAAO,MAAM;AAK7B;AAEA,MAAa,8BAA8B;CACzC,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,SAAS;CACT,QAAQ;AACV;AAEA,MAAa,8BAA8BA,IAAE,KAAK,cAAc,2BAA2B,CAAC;AAG5F,SAAgB,6BAA6B,KAAgD;CAC3F,OAAO,OAAO,OAAO,2BAA2B,CAAC,CAAC,SAAS,GAA+C;AAC5G;AAGA,MAAa,sCAAsC;CAEjD,SAAS;CACT,SAAS;CACT,SAAS;CAGT,SAAS;CACT,SAAS;CAGT,MAAM;CACN,OAAO;;;;CAKP,qBAAqB;CAErB,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AACmDA,IAAE,KAAK,cAAc,mCAAmC,CAAC;AAG5G,MAAa,kCAAkC;CAE7C,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AACwCA,IAAE,KAAK,cAAc,+BAA+B,CAAC;AAI7F,MAAa,iCAAiC;CAE5C,SAAS;CACT,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAEhB,eAAe;CAGf,iBAAiB;CAQjB,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AACuCA,IAAE,KAAK,cAAc,8BAA8B,CAAC;AAG3F,MAAa,yBAAyB;CACpC,+BAA+B;CAC/B,+BAA+B;CAC/B,+BAA+B;AACjC;AACA,MAAa,yBAAyBA,IAAE,KAAK,sBAAsB;AAGnE,SAAgB,mBAAmB,WAAuD;CACxF,OAAQ,uBAA6C,SAAS,SAAS;AACzE"}
|
|
@@ -49,8 +49,8 @@ export declare const zKmsJwkPublicAsymmetric: z$1.ZodDiscriminatedUnion<[z$1.Zod
|
|
|
49
49
|
}, z$1.core.$strip>, z$1.ZodObject<{
|
|
50
50
|
kty: z$1.ZodLiteral<"OKP">;
|
|
51
51
|
crv: z$1.ZodEnum<{
|
|
52
|
-
X25519: "X25519";
|
|
53
52
|
Ed25519: "Ed25519";
|
|
53
|
+
X25519: "X25519";
|
|
54
54
|
}>;
|
|
55
55
|
x: z$1.ZodString;
|
|
56
56
|
d: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -122,8 +122,8 @@ export declare const zKmsJwkPublic: z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
|
|
|
122
122
|
}, z$1.core.$strip>, z$1.ZodObject<{
|
|
123
123
|
kty: z$1.ZodLiteral<"OKP">;
|
|
124
124
|
crv: z$1.ZodEnum<{
|
|
125
|
-
X25519: "X25519";
|
|
126
125
|
Ed25519: "Ed25519";
|
|
126
|
+
X25519: "X25519";
|
|
127
127
|
}>;
|
|
128
128
|
x: z$1.ZodString;
|
|
129
129
|
d: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -199,8 +199,8 @@ export declare const zKmsJwkPrivate: z$1.ZodDiscriminatedUnion<[z$1.ZodObject<{
|
|
|
199
199
|
d: z$1.ZodString;
|
|
200
200
|
kty: z$1.ZodLiteral<"OKP">;
|
|
201
201
|
crv: z$1.ZodEnum<{
|
|
202
|
-
X25519: "X25519";
|
|
203
202
|
Ed25519: "Ed25519";
|
|
203
|
+
X25519: "X25519";
|
|
204
204
|
}>;
|
|
205
205
|
x: z$1.ZodString;
|
|
206
206
|
kid: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -262,8 +262,8 @@ export declare const zKmsJwkPrivateAsymmetric: z$1.ZodDiscriminatedUnion<[z$1.Zo
|
|
|
262
262
|
d: z$1.ZodString;
|
|
263
263
|
kty: z$1.ZodLiteral<"OKP">;
|
|
264
264
|
crv: z$1.ZodEnum<{
|
|
265
|
-
X25519: "X25519";
|
|
266
265
|
Ed25519: "Ed25519";
|
|
266
|
+
X25519: "X25519";
|
|
267
267
|
}>;
|
|
268
268
|
x: z$1.ZodString;
|
|
269
269
|
kid: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -11,7 +11,7 @@ export declare class P256PublicJwk implements PublicJwkType<Jwk> {
|
|
|
11
11
|
static supportedEncryptionKeyAgreementAlgorithms: "ECDH-ES"[];
|
|
12
12
|
static multicodecPrefix: number;
|
|
13
13
|
supportedEncryptionKeyAgreementAlgorithms: "ECDH-ES"[];
|
|
14
|
-
supportedSignatureAlgorithms: ("
|
|
14
|
+
supportedSignatureAlgorithms: ("HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "ES256" | "ES384" | "ES512" | "PS256" | "PS384" | "PS512" | "EdDSA" | "Ed25519" | "ES256K")[];
|
|
15
15
|
multicodecPrefix: number;
|
|
16
16
|
constructor(jwk: Jwk);
|
|
17
17
|
get publicKey(): {
|