@opentdf/sdk 0.9.0-beta.91 → 0.9.0-beta.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/access/access-fetch.js +1 -2
- package/dist/cjs/src/access/access-rpc.js +1 -3
- package/dist/cjs/src/access.js +1 -14
- package/dist/cjs/src/auth/auth.js +13 -10
- package/dist/cjs/src/auth/dpop.js +121 -0
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +37 -3
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +37 -3
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +37 -3
- package/dist/cjs/src/auth/oidc.js +10 -8
- package/dist/cjs/src/auth/providers.js +35 -12
- package/dist/cjs/src/crypto/index.js +16 -2
- package/dist/cjs/src/crypto/pemPublicToCrypto.js +17 -11
- package/dist/cjs/src/opentdf.js +40 -10
- package/dist/cjs/tdf3/index.js +4 -2
- package/dist/cjs/tdf3/src/assertions.js +71 -31
- package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +4 -2
- package/dist/cjs/tdf3/src/client/index.js +23 -33
- package/dist/cjs/tdf3/src/crypto/crypto-utils.js +12 -5
- package/dist/cjs/tdf3/src/crypto/declarations.js +1 -1
- package/dist/cjs/tdf3/src/crypto/index.js +849 -88
- package/dist/cjs/tdf3/src/crypto/jose/jwt-claims-set.js +11 -0
- package/dist/cjs/tdf3/src/crypto/jose/validate-crit.js +8 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/buffer_utils.js +41 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/epoch.js +6 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/is_object.js +21 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.js +112 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/secs.js +60 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/validate_crit.js +38 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/util/errors.js +135 -0
- package/dist/cjs/tdf3/src/crypto/jwt.js +183 -0
- package/dist/cjs/tdf3/src/crypto/salt.js +14 -8
- package/dist/cjs/tdf3/src/models/encryption-information.js +17 -20
- package/dist/cjs/tdf3/src/models/key-access.js +43 -63
- package/dist/cjs/tdf3/src/tdf.js +75 -75
- package/dist/cjs/tdf3/src/utils/index.js +5 -39
- package/dist/types/src/access/access-fetch.d.ts.map +1 -1
- package/dist/types/src/access/access-rpc.d.ts.map +1 -1
- package/dist/types/src/access.d.ts +0 -5
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/auth.d.ts +9 -6
- package/dist/types/src/auth/auth.d.ts.map +1 -1
- package/dist/types/src/auth/dpop.d.ts +60 -0
- package/dist/types/src/auth/dpop.d.ts.map +1 -0
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc.d.ts +6 -4
- package/dist/types/src/auth/oidc.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts +5 -4
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/crypto/index.d.ts +2 -1
- package/dist/types/src/crypto/index.d.ts.map +1 -1
- package/dist/types/src/crypto/pemPublicToCrypto.d.ts +18 -0
- package/dist/types/src/crypto/pemPublicToCrypto.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +13 -4
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/tdf3/index.d.ts +3 -3
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +23 -8
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts +3 -3
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts.map +1 -1
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts +4 -4
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +2 -2
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +6 -5
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts +14 -4
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/declarations.d.ts +283 -18
- package/dist/types/tdf3/src/crypto/declarations.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/index.d.ts +105 -28
- package/dist/types/tdf3/src/crypto/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/jose/jwt-claims-set.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/jwt-claims-set.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/validate-crit.d.ts +5 -0
- package/dist/types/tdf3/src/crypto/jose/validate-crit.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/buffer_utils.d.ts +6 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/buffer_utils.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/epoch.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/epoch.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/is_object.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/is_object.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/secs.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/secs.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/validate_crit.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/validate_crit.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/util/errors.d.ts +76 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/util/errors.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jwt.d.ts +76 -0
- package/dist/types/tdf3/src/crypto/jwt.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/salt.d.ts +6 -1
- package/dist/types/tdf3/src/crypto/salt.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/encryption-information.d.ts +4 -4
- package/dist/types/tdf3/src/models/encryption-information.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/key-access.d.ts +8 -5
- package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts +8 -8
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/index.d.ts +4 -3
- package/dist/types/tdf3/src/utils/index.d.ts.map +1 -1
- package/dist/web/src/access/access-fetch.js +3 -4
- package/dist/web/src/access/access-rpc.js +3 -5
- package/dist/web/src/access.js +1 -13
- package/dist/web/src/auth/auth.js +13 -10
- package/dist/web/src/auth/dpop.js +118 -0
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +4 -3
- package/dist/web/src/auth/oidc-externaljwt-provider.js +4 -3
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +4 -3
- package/dist/web/src/auth/oidc.js +11 -9
- package/dist/web/src/auth/providers.js +13 -12
- package/dist/web/src/crypto/index.js +4 -2
- package/dist/web/src/crypto/pemPublicToCrypto.js +11 -9
- package/dist/web/src/opentdf.js +7 -10
- package/dist/web/tdf3/index.js +3 -2
- package/dist/web/tdf3/src/assertions.js +71 -31
- package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +4 -2
- package/dist/web/tdf3/src/client/index.js +25 -35
- package/dist/web/tdf3/src/crypto/crypto-utils.js +12 -5
- package/dist/web/tdf3/src/crypto/declarations.js +1 -1
- package/dist/web/tdf3/src/crypto/index.js +830 -84
- package/dist/web/tdf3/src/crypto/jose/jwt-claims-set.js +5 -0
- package/dist/web/tdf3/src/crypto/jose/validate-crit.js +3 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/buffer_utils.js +35 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/epoch.js +4 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/is_object.js +19 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.js +107 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/secs.js +58 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/validate_crit.js +36 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/util/errors.js +117 -0
- package/dist/web/tdf3/src/crypto/jwt.js +174 -0
- package/dist/web/tdf3/src/crypto/salt.js +13 -7
- package/dist/web/tdf3/src/models/encryption-information.js +11 -14
- package/dist/web/tdf3/src/models/key-access.js +44 -31
- package/dist/web/tdf3/src/tdf.js +71 -71
- package/dist/web/tdf3/src/utils/index.js +5 -6
- package/package.json +11 -4
- package/src/access/access-fetch.ts +2 -8
- package/src/access/access-rpc.ts +0 -7
- package/src/access.ts +0 -17
- package/src/auth/auth.ts +21 -12
- package/src/auth/dpop.ts +222 -0
- package/src/auth/oidc-clientcredentials-provider.ts +23 -15
- package/src/auth/oidc-externaljwt-provider.ts +23 -15
- package/src/auth/oidc-refreshtoken-provider.ts +23 -15
- package/src/auth/oidc.ts +21 -10
- package/src/auth/providers.ts +46 -29
- package/src/crypto/index.ts +21 -1
- package/src/crypto/pemPublicToCrypto.ts +11 -9
- package/src/opentdf.ts +19 -14
- package/tdf3/index.ts +32 -5
- package/tdf3/src/assertions.ts +99 -30
- package/tdf3/src/ciphers/aes-gcm-cipher.ts +7 -2
- package/tdf3/src/ciphers/symmetric-cipher-base.ts +7 -4
- package/tdf3/src/client/builders.ts +2 -2
- package/tdf3/src/client/index.ts +60 -59
- package/tdf3/src/crypto/crypto-utils.ts +15 -8
- package/tdf3/src/crypto/declarations.ts +338 -22
- package/tdf3/src/crypto/index.ts +1021 -118
- package/tdf3/src/crypto/jose/jwt-claims-set.ts +10 -0
- package/tdf3/src/crypto/jose/validate-crit.ts +9 -0
- package/tdf3/src/crypto/jose/vendor/lib/buffer_utils.ts +34 -0
- package/tdf3/src/crypto/jose/vendor/lib/epoch.ts +3 -0
- package/tdf3/src/crypto/jose/vendor/lib/is_object.ts +18 -0
- package/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.ts +106 -0
- package/tdf3/src/crypto/jose/vendor/lib/secs.ts +57 -0
- package/tdf3/src/crypto/jose/vendor/lib/validate_crit.ts +35 -0
- package/tdf3/src/crypto/jose/vendor/util/errors.ts +101 -0
- package/tdf3/src/crypto/jwt.ts +256 -0
- package/tdf3/src/crypto/salt.ts +16 -8
- package/tdf3/src/models/encryption-information.ts +14 -21
- package/tdf3/src/models/key-access.ts +57 -41
- package/tdf3/src/tdf.ts +110 -93
- package/tdf3/src/utils/index.ts +5 -6
|
@@ -14,18 +14,152 @@ export type DecryptResult = {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* PEM formatted keypair.
|
|
17
|
+
* Used for import/export compatibility. Internal code should use KeyPair (opaque keys).
|
|
17
18
|
*/
|
|
18
19
|
export type PemKeyPair = {
|
|
19
20
|
publicKey: string;
|
|
20
21
|
privateKey: string;
|
|
21
22
|
};
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Key algorithm identifier combining key type and parameters.
|
|
26
|
+
*/
|
|
27
|
+
export type KeyAlgorithm =
|
|
28
|
+
| 'rsa:2048'
|
|
29
|
+
| 'rsa:4096'
|
|
30
|
+
| 'ec:secp256r1'
|
|
31
|
+
| 'ec:secp384r1'
|
|
32
|
+
| 'ec:secp521r1';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for key generation and import.
|
|
36
|
+
*/
|
|
37
|
+
export type KeyOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Key usage: 'encrypt' for RSA-OAEP, 'sign' for RSA/ECDSA signing, 'derive' for ECDH.
|
|
40
|
+
* If not specified, defaults based on the generation method or key type.
|
|
41
|
+
*/
|
|
42
|
+
usage?: 'encrypt' | 'sign' | 'derive';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether keys can be exported. Defaults to true.
|
|
46
|
+
* HSM-backed implementations may force false for private keys.
|
|
47
|
+
*/
|
|
48
|
+
extractable?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Optional algorithm hint for import validation.
|
|
52
|
+
* Helps disambiguate or validate imported keys.
|
|
53
|
+
*/
|
|
54
|
+
algorithmHint?: KeyAlgorithm;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Opaque public key - internal representation hidden.
|
|
59
|
+
* Code outside CryptoService treats this as a token.
|
|
60
|
+
*
|
|
61
|
+
* Includes metadata for algorithm selection without needing CryptoService calls.
|
|
62
|
+
*/
|
|
63
|
+
export type PublicKey = {
|
|
64
|
+
readonly _brand: 'PublicKey';
|
|
65
|
+
/** Algorithm identifier (e.g., 'rsa:2048', 'ec:secp256r1') */
|
|
66
|
+
readonly algorithm: KeyAlgorithm;
|
|
67
|
+
/** RSA modulus bit length (only for RSA keys) */
|
|
68
|
+
readonly modulusBits?: number;
|
|
69
|
+
/** EC curve name (only for EC keys) */
|
|
70
|
+
readonly curve?: ECCurve;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Opaque private key - internal representation hidden.
|
|
75
|
+
* Code outside CryptoService treats this as a token.
|
|
76
|
+
*
|
|
77
|
+
* Includes metadata for algorithm selection without needing CryptoService calls.
|
|
78
|
+
*/
|
|
79
|
+
export type PrivateKey = {
|
|
80
|
+
readonly _brand: 'PrivateKey';
|
|
81
|
+
/** Algorithm identifier (e.g., 'rsa:2048', 'ec:secp256r1') */
|
|
82
|
+
readonly algorithm: KeyAlgorithm;
|
|
83
|
+
/** RSA modulus bit length (only for RSA keys) */
|
|
84
|
+
readonly modulusBits?: number;
|
|
85
|
+
/** EC curve name (only for EC keys) */
|
|
86
|
+
readonly curve?: ECCurve;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Opaque key pair with matching algorithms.
|
|
91
|
+
*/
|
|
92
|
+
export type KeyPair = {
|
|
93
|
+
readonly publicKey: PublicKey;
|
|
94
|
+
readonly privateKey: PrivateKey;
|
|
95
|
+
};
|
|
96
|
+
|
|
23
97
|
/**
|
|
24
98
|
* The minimum acceptable asymetric key size, currently 2^11.
|
|
25
99
|
*/
|
|
26
100
|
export const MIN_ASYMMETRIC_KEY_SIZE_BITS = 2048;
|
|
27
101
|
|
|
28
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Opaque symmetric key - internal representation hidden.
|
|
104
|
+
* Code outside CryptoService treats this as a token.
|
|
105
|
+
* Used for AES encryption/decryption.
|
|
106
|
+
*
|
|
107
|
+
* Includes metadata for key length without needing CryptoService calls.
|
|
108
|
+
*/
|
|
109
|
+
export type SymmetricKey = {
|
|
110
|
+
readonly _brand: 'SymmetricKey';
|
|
111
|
+
/** Key length in bits (e.g., 256 for AES-256) */
|
|
112
|
+
readonly length: number;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Elliptic curves supported for ECDH/ECDSA operations.
|
|
117
|
+
*/
|
|
118
|
+
export type ECCurve = 'P-256' | 'P-384' | 'P-521';
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Asymmetric signing algorithms (require PEM keys).
|
|
122
|
+
*/
|
|
123
|
+
export type AsymmetricSigningAlgorithm = 'RS256' | 'ES256' | 'ES384' | 'ES512';
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Symmetric signing algorithm (requires raw key bytes).
|
|
127
|
+
*/
|
|
128
|
+
export type SymmetricSigningAlgorithm = 'HS256';
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* All supported signing algorithms.
|
|
132
|
+
*/
|
|
133
|
+
export type SigningAlgorithm = AsymmetricSigningAlgorithm | SymmetricSigningAlgorithm;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Supported hash algorithms.
|
|
137
|
+
*/
|
|
138
|
+
export type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Parameters for HKDF key derivation.
|
|
142
|
+
*/
|
|
143
|
+
export type HkdfParams = {
|
|
144
|
+
/** Hash algorithm to use for HKDF. */
|
|
145
|
+
hash: HashAlgorithm;
|
|
146
|
+
/** Salt for HKDF (can be empty Uint8Array). */
|
|
147
|
+
salt: Uint8Array;
|
|
148
|
+
/** Optional info/context for HKDF. */
|
|
149
|
+
info?: Uint8Array;
|
|
150
|
+
/** Desired key length in bits. Defaults to 256. */
|
|
151
|
+
keyLength?: number;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Public key information returned from parsePublicKeyPem.
|
|
156
|
+
*/
|
|
157
|
+
export type PublicKeyInfo = {
|
|
158
|
+
/** Detected algorithm of the key. */
|
|
159
|
+
algorithm: 'rsa:2048' | 'rsa:4096' | 'ec:secp256r1' | 'ec:secp384r1' | 'ec:secp521r1';
|
|
160
|
+
/** Normalized PEM string. */
|
|
161
|
+
pem: string;
|
|
162
|
+
};
|
|
29
163
|
|
|
30
164
|
export type CryptoService = {
|
|
31
165
|
/** Track which crypto implementation we are using */
|
|
@@ -34,56 +168,238 @@ export type CryptoService = {
|
|
|
34
168
|
/** Default algorithm identifier. */
|
|
35
169
|
method: AlgorithmUrn;
|
|
36
170
|
|
|
37
|
-
/** Convert or narrow from AnyKeyPair to PemKeyPair */
|
|
38
|
-
cryptoToPemPair: (keys: AnyKeyPair) => Promise<PemKeyPair>;
|
|
39
|
-
|
|
40
171
|
/**
|
|
41
172
|
* Try to decrypt content with the default or handed algorithm. Throws on
|
|
42
173
|
* most failure, if auth tagging is implemented for example.
|
|
43
174
|
*/
|
|
44
175
|
decrypt: (
|
|
45
176
|
payload: Binary,
|
|
46
|
-
key:
|
|
177
|
+
key: SymmetricKey,
|
|
47
178
|
iv: Binary,
|
|
48
179
|
algorithm?: AlgorithmUrn,
|
|
49
180
|
authTag?: Binary
|
|
50
181
|
) => Promise<DecryptResult>;
|
|
51
182
|
|
|
52
|
-
decryptWithPrivateKey: (encryptedPayload: Binary, privateKey:
|
|
183
|
+
decryptWithPrivateKey: (encryptedPayload: Binary, privateKey: PrivateKey) => Promise<Binary>;
|
|
53
184
|
|
|
54
185
|
/**
|
|
55
186
|
* Encrypt content with the default or handed algorithm.
|
|
187
|
+
* Accepts Binary or SymmetricKey as payload (for key wrapping with symmetric keys).
|
|
56
188
|
*/
|
|
57
189
|
encrypt: (
|
|
58
|
-
payload: Binary,
|
|
59
|
-
key:
|
|
190
|
+
payload: Binary | SymmetricKey,
|
|
191
|
+
key: SymmetricKey,
|
|
60
192
|
iv: Binary,
|
|
61
193
|
algorithm?: AlgorithmUrn
|
|
62
194
|
) => Promise<EncryptResult>;
|
|
63
195
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Encrypt with asymmetric public key (RSA-OAEP).
|
|
198
|
+
* Accepts Binary or SymmetricKey for key wrapping.
|
|
199
|
+
*/
|
|
200
|
+
encryptWithPublicKey: (payload: Binary | SymmetricKey, publicKey: PublicKey) => Promise<Binary>;
|
|
68
201
|
|
|
69
|
-
/**
|
|
70
|
-
generateKey: (length?: number) => Promise<
|
|
202
|
+
/** Generate symmetric AES key (opaque, never hex string). */
|
|
203
|
+
generateKey: (length?: number) => Promise<SymmetricKey>;
|
|
71
204
|
|
|
72
205
|
/**
|
|
73
|
-
* Generate an RSA key pair
|
|
206
|
+
* Generate an RSA key pair for encryption/decryption.
|
|
74
207
|
* @param size in bits, defaults to a reasonable size for the default method
|
|
208
|
+
* @returns Opaque key pair
|
|
75
209
|
*/
|
|
76
|
-
generateKeyPair: (size?: number) => Promise<
|
|
77
|
-
|
|
78
|
-
generateSigningKeyPair: () => Promise<AnyKeyPair>;
|
|
210
|
+
generateKeyPair: (size?: number) => Promise<KeyPair>;
|
|
79
211
|
|
|
80
212
|
/**
|
|
81
|
-
*
|
|
213
|
+
* Generate an RSA key pair for signing/verification.
|
|
214
|
+
* @returns Opaque key pair
|
|
82
215
|
*/
|
|
83
|
-
|
|
216
|
+
generateSigningKeyPair: () => Promise<KeyPair>;
|
|
84
217
|
|
|
85
218
|
randomBytes: (byteLength: number) => Promise<Uint8Array>;
|
|
86
219
|
|
|
87
|
-
/**
|
|
88
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Sign data with an asymmetric private key.
|
|
222
|
+
* @param data - Data to sign
|
|
223
|
+
* @param privateKey - Opaque private key
|
|
224
|
+
* @param algorithm - Signing algorithm (RS256, ES256, ES384, ES512)
|
|
225
|
+
*/
|
|
226
|
+
sign: (
|
|
227
|
+
data: Uint8Array,
|
|
228
|
+
privateKey: PrivateKey,
|
|
229
|
+
algorithm: AsymmetricSigningAlgorithm
|
|
230
|
+
) => Promise<Uint8Array>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Verify signature with an asymmetric public key.
|
|
234
|
+
* @param data - Original data that was signed
|
|
235
|
+
* @param signature - Signature to verify
|
|
236
|
+
* @param publicKey - Opaque public key
|
|
237
|
+
* @param algorithm - Must match algorithm used for signing
|
|
238
|
+
*/
|
|
239
|
+
verify: (
|
|
240
|
+
data: Uint8Array,
|
|
241
|
+
signature: Uint8Array,
|
|
242
|
+
publicKey: PublicKey,
|
|
243
|
+
algorithm: AsymmetricSigningAlgorithm
|
|
244
|
+
) => Promise<boolean>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Compute HMAC-SHA256 of data with a symmetric key.
|
|
248
|
+
* @param data - Data to authenticate
|
|
249
|
+
* @param key - Opaque symmetric key
|
|
250
|
+
* @returns Raw HMAC bytes
|
|
251
|
+
*/
|
|
252
|
+
hmac: (data: Uint8Array, key: SymmetricKey) => Promise<Uint8Array>;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Verify HMAC-SHA256.
|
|
256
|
+
* @param data - Original data that was authenticated
|
|
257
|
+
* @param signature - HMAC to verify
|
|
258
|
+
* @param key - Opaque symmetric key
|
|
259
|
+
*/
|
|
260
|
+
verifyHmac: (data: Uint8Array, signature: Uint8Array, key: SymmetricKey) => Promise<boolean>;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Compute hash digest.
|
|
264
|
+
* @param algorithm - Hash algorithm to use (SHA-256, SHA-384, SHA-512)
|
|
265
|
+
* @param data - Data to hash
|
|
266
|
+
*/
|
|
267
|
+
digest: (algorithm: HashAlgorithm, data: Uint8Array) => Promise<Uint8Array>;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Generate an EC key pair for ECDH key agreement.
|
|
271
|
+
* @param curve - Elliptic curve to use (defaults to P-256)
|
|
272
|
+
* @throws ConfigurationError if EC operations not supported
|
|
273
|
+
*/
|
|
274
|
+
generateECKeyPair: (curve?: ECCurve) => Promise<KeyPair>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Perform ECDH key agreement followed by HKDF key derivation.
|
|
278
|
+
* Returns opaque symmetric key suitable for symmetric encryption.
|
|
279
|
+
*
|
|
280
|
+
* @param privateKey - Opaque EC private key
|
|
281
|
+
* @param publicKey - Opaque EC public key of other party
|
|
282
|
+
* @param hkdfParams - Parameters for HKDF derivation
|
|
283
|
+
* @returns Opaque symmetric key
|
|
284
|
+
* @throws ConfigurationError if EC operations not supported
|
|
285
|
+
*/
|
|
286
|
+
deriveKeyFromECDH: (
|
|
287
|
+
privateKey: PrivateKey,
|
|
288
|
+
publicKey: PublicKey,
|
|
289
|
+
hkdfParams: HkdfParams
|
|
290
|
+
) => Promise<SymmetricKey>;
|
|
291
|
+
|
|
292
|
+
// === Key Import (PEM → opaque) ===
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Import a PEM public key as an opaque key.
|
|
296
|
+
* @param pem - PEM-encoded public key
|
|
297
|
+
* @param options - Import options (usage required for RSA keys to disambiguate encrypt vs sign)
|
|
298
|
+
* @returns Opaque public key with metadata
|
|
299
|
+
*/
|
|
300
|
+
importPublicKey: (pem: string, options: KeyOptions) => Promise<PublicKey>;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Import a PEM private key as an opaque key.
|
|
304
|
+
* Optional - intended for use in tests or by downstream integrators who need to bring
|
|
305
|
+
* their own PEM key material. Main SDK code should use opaque PrivateKey objects directly.
|
|
306
|
+
* @param pem - PEM-encoded private key
|
|
307
|
+
* @param options - Import options (usage required for RSA keys to disambiguate encrypt vs sign)
|
|
308
|
+
* @returns Opaque private key with metadata
|
|
309
|
+
*/
|
|
310
|
+
importPrivateKey?: (pem: string, options: KeyOptions) => Promise<PrivateKey>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Parse and validate a PEM public key, returning algorithm info.
|
|
314
|
+
*
|
|
315
|
+
* @param pem - PEM-encoded public key or X.509 certificate
|
|
316
|
+
* @returns Validated PEM and detected algorithm
|
|
317
|
+
* @throws ConfigurationError if key format invalid or algorithm not supported
|
|
318
|
+
*/
|
|
319
|
+
parsePublicKeyPem: (pem: string) => Promise<PublicKeyInfo>;
|
|
320
|
+
|
|
321
|
+
// === Key Export (opaque → PEM/JWK) ===
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Export an opaque public key to PEM format.
|
|
325
|
+
* @param key - Opaque public key
|
|
326
|
+
* @returns PEM-encoded public key (SPKI format)
|
|
327
|
+
*/
|
|
328
|
+
exportPublicKeyPem: (key: PublicKey) => Promise<string>;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* OPTIONAL -- ONLY USE FOR TESTING/DEVELOPMENT. Private keys should NOT be exportable in secure environments.
|
|
332
|
+
* Export an opaque private key to PEM format.
|
|
333
|
+
* @param key - Opaque private key
|
|
334
|
+
* @returns PEM-encoded private key (PKCS8 format)
|
|
335
|
+
*/
|
|
336
|
+
exportPrivateKeyPem?: (key: PrivateKey) => Promise<string>;
|
|
337
|
+
/**
|
|
338
|
+
* Export an opaque public key to JWK format.
|
|
339
|
+
* @param key - Opaque public key
|
|
340
|
+
* @returns JWK representation
|
|
341
|
+
*/
|
|
342
|
+
exportPublicKeyJwk: (key: PublicKey) => Promise<JsonWebKey>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Extract PEM public key from X.509 certificate or return PEM key as-is.
|
|
346
|
+
*
|
|
347
|
+
* Used to normalize KAS public keys which may be provided as either:
|
|
348
|
+
* - X.509 certificates (-----BEGIN CERTIFICATE-----)
|
|
349
|
+
* - Raw PEM public keys (-----BEGIN PUBLIC KEY-----)
|
|
350
|
+
*
|
|
351
|
+
* For certificates, jwaAlgorithm must be provided to correctly parse the key
|
|
352
|
+
* (e.g., 'RS256', 'RS512', 'ES256', 'ES384', 'ES512'). For raw PEM keys,
|
|
353
|
+
* the algorithm parameter is ignored.
|
|
354
|
+
*
|
|
355
|
+
* @param certOrPem - PEM-encoded public key or X.509 certificate
|
|
356
|
+
* @param jwaAlgorithm - JWA algorithm for certificate parsing (required for certificates)
|
|
357
|
+
* @returns PEM-encoded public key (SPKI format)
|
|
358
|
+
* @throws Error if input is not valid PEM or certificate
|
|
359
|
+
*/
|
|
360
|
+
extractPublicKeyPem: (certOrPem: string, jwaAlgorithm?: string) => Promise<string>;
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Convert a JWK (JSON Web Key) public key to PEM format.
|
|
364
|
+
* Supports both RSA and EC keys.
|
|
365
|
+
*
|
|
366
|
+
* @param jwk - JSON Web Key object
|
|
367
|
+
* @returns PEM-encoded public key
|
|
368
|
+
* @throws ConfigurationError if JWK format invalid
|
|
369
|
+
*/
|
|
370
|
+
jwkToPublicKeyPem: (jwk: JsonWebKey) => Promise<string>;
|
|
371
|
+
|
|
372
|
+
// === Symmetric Key Operations ===
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Import raw key bytes as an opaque symmetric key.
|
|
376
|
+
* Used for external keys (e.g., unwrapped from KAS).
|
|
377
|
+
* @param keyBytes - Raw key bytes
|
|
378
|
+
* @returns Opaque symmetric key
|
|
379
|
+
*/
|
|
380
|
+
importSymmetricKey: (keyBytes: Uint8Array) => Promise<SymmetricKey>;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Split a symmetric key into N shares using XOR secret sharing.
|
|
384
|
+
*
|
|
385
|
+
* DefaultCryptoService: Uses keySplit() utility (extracts bytes internally)
|
|
386
|
+
* HSM implementations: Must use native splitting OR throw ConfigurationError
|
|
387
|
+
*
|
|
388
|
+
* @param key - Symmetric key to split
|
|
389
|
+
* @param numShares - Number of shares to create
|
|
390
|
+
* @returns Array of opaque key shares
|
|
391
|
+
* @throws ConfigurationError if not supported by the implementation
|
|
392
|
+
*
|
|
393
|
+
* Note: Multi-KAS may not be available in all secure environments (single KAS only)
|
|
394
|
+
*/
|
|
395
|
+
splitSymmetricKey: (key: SymmetricKey, numShares: number) => Promise<SymmetricKey[]>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Merge symmetric key shares back into the original key using XOR.
|
|
399
|
+
*
|
|
400
|
+
* @param shares - Array of key shares (from splitSymmetricKey)
|
|
401
|
+
* @returns Merged symmetric key
|
|
402
|
+
* @throws ConfigurationError if not supported by the implementation
|
|
403
|
+
*/
|
|
404
|
+
mergeSymmetricKeys: (shares: SymmetricKey[]) => Promise<SymmetricKey>;
|
|
89
405
|
};
|