@sphereon/ssi-sdk-ext.key-utils 0.28.1-feature.oyd.cmsm.improv.21 → 0.28.1-next.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,12 +1,231 @@
1
+ import * as _sphereon_ssi_types from '@sphereon/ssi-types';
2
+ import { JWK, JoseSignatureAlgorithm, ICoseKeyJson, ICoseKeyType, JwkKeyType, JwkKeyTypeString, ICoseSignatureAlgorithm, JoseSignatureAlgorithmString, JoseKeyOperation, JoseKeyOperationString, ICoseKeyOperation, JoseCurve, JoseCurveString, ICoseCurve, JsonWebKey as JsonWebKey$1, HasherSync } from '@sphereon/ssi-types';
3
+ import { MinimalImportableKey, IKey, IAgentContext, IKeyManager, ManagedKeyInfo } from '@veramo/core';
4
+ import { JsonWebKey } from 'did-resolver';
5
+ import { Crypto } from 'node';
6
+ import { ByteView } from 'multiformats/codecs/interface';
7
+
8
+ declare const JWK_JCS_PUB_NAME: "jwk_jcs-pub";
9
+ declare const JWK_JCS_PUB_PREFIX = 60241;
10
+ type TKeyType = 'Ed25519' | 'Secp256k1' | 'Secp256r1' | 'Secp384r1' | 'Secp521r1' | 'X25519' | 'Bls12381G1' | 'Bls12381G2' | 'RSA';
11
+ declare enum Key {
12
+ Ed25519 = "Ed25519",
13
+ Secp256k1 = "Secp256k1",
14
+ Secp256r1 = "Secp256r1"
15
+ }
16
+ declare enum JwkKeyUse {
17
+ Encryption = "enc",
18
+ Signature = "sig"
19
+ }
20
+ declare const SIG_KEY_ALGS: string[];
21
+ declare const ENC_KEY_ALGS: string[];
22
+ type KeyVisibility = 'public' | 'private';
23
+ interface X509Opts {
24
+ cn?: string;
25
+ privateKeyPEM?: string;
26
+ certificatePEM?: string;
27
+ certificateChainURL?: string;
28
+ certificateChainPEM?: string;
29
+ }
30
+ interface IImportProvidedOrGeneratedKeyArgs {
31
+ kms?: string;
32
+ alias?: string;
33
+ options?: IKeyOpts;
34
+ }
35
+ interface IKeyOpts {
36
+ key?: Partial<MinimalImportableKey>;
37
+ type?: Exclude<TKeyType, 'Secp384r1' | 'Secp521r1'>;
38
+ use?: JwkKeyUse;
39
+ x509?: X509Opts;
40
+ }
41
+ type SignatureAlgorithmFromKeyArgs = {
42
+ key: IKey;
43
+ };
44
+ type SignatureAlgorithmFromKeyTypeArgs = {
45
+ type: TKeyType;
46
+ };
47
+ type KeyTypeFromCryptographicSuiteArgs = {
48
+ crv?: string;
49
+ kty?: string;
50
+ alg?: string;
51
+ };
52
+
53
+ declare const logger: _sphereon_ssi_types.ISimpleLogger<unknown>;
1
54
  /**
2
- * Provides `did:jwk` {@link @veramo/did-provider-jwk#JwkDIDProvider | identifier provider }
3
- * for the {@link @veramo/did-manager#DIDManager}
55
+ * Function that returns the provided KMS name or the default KMS name if none is provided.
56
+ * The default KMS is either explicitly defined during agent construction, or the first KMS available in the system
57
+ * @param context
58
+ * @param kms. Optional KMS to use. If provided will be the returned name. Otherwise the default KMS will be returned
59
+ */
60
+ declare const getKms: (context: IAgentContext<any>, kms?: string) => Promise<string>;
61
+ /**
62
+ * Generates a random Private Hex Key for the specified key type
63
+ * @param type The key type
64
+ * @return The private key in Hex form
65
+ */
66
+ declare const generatePrivateKeyHex: (type: TKeyType) => Promise<string>;
67
+ /**
68
+ * We optionally generate and then import our own keys.
69
+ *
70
+ * @param args The key arguments
71
+ * @param context The Veramo agent context
72
+ * @private
73
+ */
74
+ declare function importProvidedOrGeneratedKey(args: IImportProvidedOrGeneratedKeyArgs & {
75
+ kms: string;
76
+ }, context: IAgentContext<IKeyManager>): Promise<IKey>;
77
+ declare const calculateJwkThumbprintForKey: (args: {
78
+ key: IKey | MinimalImportableKey | ManagedKeyInfo;
79
+ digestAlgorithm?: "sha256" | "sha512";
80
+ }) => string;
81
+ declare const toBase64url: (input: string) => string;
82
+ /**
83
+ * Calculate the JWK thumbprint
84
+ * @param args
85
+ */
86
+ declare const calculateJwkThumbprint: (args: {
87
+ jwk: JWK;
88
+ digestAlgorithm?: "sha256" | "sha512";
89
+ }) => string;
90
+ declare const toJwkFromKey: (key: IKey | MinimalImportableKey | ManagedKeyInfo, opts?: {
91
+ use?: JwkKeyUse;
92
+ noKidThumbprint?: boolean;
93
+ }) => JWK;
94
+ /**
95
+ * Converts a public key in hex format to a JWK
96
+ * @param publicKeyHex public key in hex
97
+ * @param type The type of the key (Ed25519, Secp256k1/r1)
98
+ * @param opts. Options, like the optional use for the key (sig/enc)
99
+ * @return The JWK
100
+ */
101
+ declare const toJwk: (publicKeyHex: string, type: TKeyType, opts?: {
102
+ use?: JwkKeyUse;
103
+ key?: IKey | MinimalImportableKey;
104
+ isPrivateKey?: boolean;
105
+ noKidThumbprint?: boolean;
106
+ }) => JWK;
107
+ /**
108
+ * Convert a JWK to a raw hex key.
109
+ * Currently supports `RSA` and `EC` keys. Extendable for other key types.
110
+ * @param jwk - The JSON Web Key object.
111
+ * @returns A string representing the key in raw hexadecimal format.
112
+ */
113
+ declare const jwkToRawHexKey: (jwk: JWK) => Promise<string>;
114
+ /**
115
+ * Convert an RSA JWK to a raw hex key.
116
+ * @param jwk - The RSA JWK object.
117
+ * @returns A string representing the RSA key in raw hexadecimal format.
118
+ */
119
+ declare function rsaJwkToRawHexKey(jwk: JsonWebKey): string;
120
+ /**
121
+ * Determines the use param based upon the key/signature type or supplied use value.
122
+ *
123
+ * @param type The key type
124
+ * @param suppliedUse A supplied use. Will be used in case it is present
125
+ */
126
+ declare const jwkDetermineUse: (type: TKeyType, suppliedUse?: JwkKeyUse) => JwkKeyUse | undefined;
127
+ declare const padLeft: (args: {
128
+ data: string;
129
+ size?: number;
130
+ padString?: string;
131
+ }) => string;
132
+ declare const isAsn1Der: (key: Uint8Array) => boolean;
133
+ declare const asn1DerToRawPublicKey: (derKey: Uint8Array, keyType: TKeyType) => Uint8Array;
134
+ declare const isRawCompressedPublicKey: (key: Uint8Array) => boolean;
135
+ declare const toRawCompressedHexPublicKey: (rawPublicKey: Uint8Array, keyType: TKeyType) => string;
136
+ declare const hexStringFromUint8Array: (value: Uint8Array) => string;
137
+ declare const signatureAlgorithmFromKey: (args: SignatureAlgorithmFromKeyArgs) => Promise<JoseSignatureAlgorithm>;
138
+ declare const signatureAlgorithmFromKeyType: (args: SignatureAlgorithmFromKeyTypeArgs) => JoseSignatureAlgorithm;
139
+ declare const keyTypeFromCryptographicSuite: (args: KeyTypeFromCryptographicSuiteArgs) => TKeyType;
140
+ declare function removeNulls<T>(obj: T | any): any;
141
+ declare const globalCrypto: (setGlobal: boolean, suppliedCrypto?: Crypto) => Crypto;
142
+ declare const sanitizedJwk: (input: JWK | JsonWebKey) => JWK;
143
+ /**
144
+ *
145
+ */
146
+ declare function verifyRawSignature({ data, signature, key: inputKey, opts, }: {
147
+ data: Uint8Array;
148
+ signature: Uint8Array;
149
+ key: JWK;
150
+ opts?: {
151
+ signatureAlg?: JoseSignatureAlgorithm;
152
+ };
153
+ }): Promise<boolean>;
154
+ /**
155
+ * Ensure the given DER‐encoded RSA public key (Uint8Array)
156
+ * is raw PKCS#1. If it's X.509/SPKI‐wrapped, we strip the wrapper.
157
+ *
158
+ * @param derBytes – DER‐encoded public key, either PKCS#1 or X.509/SPKI
159
+ * @returns DER‐encoded PKCS#1 RSAPublicKey
160
+ */
161
+ declare function toPkcs1(derBytes: Uint8Array): Uint8Array;
162
+ /**
163
+ * Ensure the given DER‐encoded RSA public key in Hex
164
+ * is raw PKCS#1. If it's X.509/SPKI‐wrapped, we strip the wrapper.
165
+ *
166
+ * @param derBytes – DER‐encoded public key, either PKCS#1 or X.509/SPKI
167
+ * @returns DER‐encoded PKCS#1 RSAPublicKey in hex
168
+ */
169
+ declare function toPkcs1FromHex(publicKeyHex: string): any;
170
+
171
+ declare function coseKeyToJwk(coseKey: ICoseKeyJson): JWK;
172
+ declare function jwkToCoseKey(jwk: JWK): ICoseKeyJson;
173
+ declare function coseToJoseKty(kty: ICoseKeyType): JwkKeyType;
174
+ declare function joseToCoseKty(kty: JwkKeyType | JwkKeyTypeString): ICoseKeyType;
175
+ declare function coseToJoseSignatureAlg(coseAlg: ICoseSignatureAlgorithm): JoseSignatureAlgorithm;
176
+ declare function joseToCoseSignatureAlg(joseAlg: JoseSignatureAlgorithm | JoseSignatureAlgorithmString): ICoseSignatureAlgorithm;
177
+ declare function joseToCoseKeyOperation(keyOp: JoseKeyOperation | JoseKeyOperationString): ICoseKeyOperation;
178
+ declare function coseToJoseKeyOperation(keyOp: ICoseKeyOperation): JoseKeyOperation;
179
+ declare function joseToCoseCurve(curve: JoseCurve | JoseCurveString): ICoseCurve;
180
+ declare function coseToJoseCurve(curve: ICoseCurve): JoseCurve;
181
+
182
+ /**
183
+ * Checks if the JWK is valid. It must contain all the required members.
184
+ *
185
+ * @see https://www.rfc-editor.org/rfc/rfc7518#section-6
186
+ * @see https://www.rfc-editor.org/rfc/rfc8037#section-2
187
+ *
188
+ * @param jwk - The JWK to check.
189
+ * @param opts
190
+ */
191
+ declare function validateJwk(jwk: any, opts?: {
192
+ crvOptional?: boolean;
193
+ }): void;
194
+ /**
195
+ * Extracts the required members of the JWK and canonicalizes it.
196
+ *
197
+ * @param jwk - The JWK to canonicalize.
198
+ * @returns The JWK with only the required members, ordered lexicographically.
199
+ */
200
+ declare function minimalJwk(jwk: any): JWK;
201
+ /**
202
+ * Encodes a JWK into a Uint8Array. Only the required JWK members are encoded.
203
+ *
204
+ * @see https://www.rfc-editor.org/rfc/rfc7518#section-6
205
+ * @see https://www.rfc-editor.org/rfc/rfc8037#section-2
206
+ * @see https://github.com/panva/jose/blob/3b8aa47b92d07a711bf5c3125276cc9a011794a4/src/jwk/thumbprint.ts#L37
207
+ *
208
+ * @param jwk - JSON Web Key.
209
+ * @returns Uint8Array-encoded JWK.
210
+ */
211
+ declare function jwkJcsEncode(jwk: unknown): Uint8Array;
212
+ /**
213
+ * Decodes an array of bytes into a JWK. Throws an error if the JWK is not valid.
4
214
  *
5
- * @packageDocumentation
215
+ * @param bytes - The array of bytes to decode.
216
+ * @returns The corresponding JSON Web Key.
6
217
  */
7
- export * from './functions';
8
- export * from './conversion';
9
- export * from './jwk-jcs';
10
- export * from './types';
11
- export * from './digest-methods';
12
- //# sourceMappingURL=index.d.ts.map
218
+ declare function jwkJcsDecode(bytes: ByteView<JsonWebKey$1>): JsonWebKey$1;
219
+ declare function jcsCanonicalize(object: any): string;
220
+
221
+ declare const SupportedEncodings: any;
222
+ type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
223
+ type TDigestMethod = (input: string, encoding?: typeof SupportedEncodings) => string;
224
+ declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
225
+ hashAlgorithm: HashAlgorithm;
226
+ digestMethod: TDigestMethod;
227
+ hash: (data: Uint8Array) => Uint8Array;
228
+ };
229
+ declare const shaHasher: HasherSync;
230
+
231
+ export { ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature };