diff --git a/types/k6/experimental/webcrypto.d.ts b/types/k6/experimental/webcrypto.d.ts index 45c30b8f065825..4f45f989eef5b2 100644 --- a/types/k6/experimental/webcrypto.d.ts +++ b/types/k6/experimental/webcrypto.d.ts @@ -91,14 +91,14 @@ export interface SubtleCrypto { * * To export a key, the key must have `CryptoKey.extractable` set to `true`. * - * @param format the format in which to export the key. Currently, only "raw" is supported. + * @param format the format in which to export the key. Currently, only "raw" and "jwk" are supported. * @param key the key to export. * @throws {InvalidAccessError} - if the key is not extractable. * @throws {NotSupportedError} - if the format is not supported. * @throws {TypeError} - when trying to use an invalid format. * @returns A promise that resolves with the exported key. */ - exportKey(format: "raw", key: CryptoKey): Promise; + exportKey(format: "raw" | "jwk", key: CryptoKey): Promise; /** * Use the `generateKey()` method to generate a new key (for symmetric @@ -121,7 +121,7 @@ export interface SubtleCrypto { * It takes as input a key in an external, portable format and gives you * a `CryptoKey` object that can be used in the Web Crypto API. * - * @param format the format of the key to import. Currently, only "raw" is supported. + * @param format the format of the key to import. Currently, only "raw" and "jwk" are supported. * @param keyData the key data to import. * @param algorithm defines the algorithm to use and any extra-parameters. * @param extractable indicates whether it will be possible to export the key using `SubtleCrypto.exportKey()` or `SubtleCrypto.wrapKey`. @@ -131,8 +131,8 @@ export interface SubtleCrypto { * @returns A promise that resolves with the imported `CryptoKey`. */ importKey( - format: "raw", - keyData: ArrayBuffer | ArrayBufferView | DataView, + format: "raw" | "jwk", + keyData: ArrayBuffer | ArrayBufferView | DataView | JWK, algorithm: "AES-CBC" | "AES-CTR" | "AES-GCM" | Algorithm<"AES-CBC" | "AES-CTR" | "AES-GCM"> | HmacImportParams, extractable: boolean, keyUsages: Array<"encrypt" | "decrypt" | "sign" | "verify">, @@ -395,3 +395,16 @@ export type TypedArray = | Uint16Array | Int32Array | Uint32Array; + +/** + * JSON Web Key Value. + * JWKs are not supported for now, since webcrypto doesn't support exporting key/pairs + */ +export type JWKValue = null | boolean | number | string | JWK; + +/** + * Object representable with JSON Web Key. + */ +export interface JWK { + [key: string]: JWKValue; +} diff --git a/types/k6/options.d.ts b/types/k6/options.d.ts index 39f058453c54bd..44e67c71dcffbb 100644 --- a/types/k6/options.d.ts +++ b/types/k6/options.d.ts @@ -47,6 +47,9 @@ export interface Options { /** Third party collector configuration. */ ext?: { [name: string]: CollectorOptions }; + /** Cloud options */ + options?: CloudOptions; + /** Static hostname mapping. */ hosts?: { [name: string]: string }; @@ -139,6 +142,13 @@ export interface CollectorOptions { [name: string]: any; } +/** + * Options for the cloud. + */ +export interface CloudOptions { + [name: string]: any; +} + /** * Test stage. */ diff --git a/types/k6/test/options.ts b/types/k6/test/options.ts index 744b2fb80fdeeb..fabe693add9c7b 100644 --- a/types/k6/test/options.ts +++ b/types/k6/test/options.ts @@ -126,3 +126,9 @@ const browserScenariosBad: Scenario[] = [ }, }, ]; + +const optionsWithCloud: Options = { + cloud: { + name: "My cloud test", + }, +}; diff --git a/types/k6/test/webcrypto.ts b/types/k6/test/webcrypto.ts index 770326917c1bfe..b3497059159297 100644 --- a/types/k6/test/webcrypto.ts +++ b/types/k6/test/webcrypto.ts @@ -72,6 +72,9 @@ crypto.subtle.encrypt({ name: "AES-CBC" }, aesCryptoKey, null); // crypto.subtle.exportKey // +crypto.subtle.exportKey("raw", aesCryptoKey); +crypto.subtle.exportKey("jwk", aesCryptoKey); + // @ts-expect-error crypto.subtle.exportKey(); // @ts-expect-error @@ -92,6 +95,19 @@ crypto.subtle.generateKey(8); // crypto.subtle.importKey // +crypto.subtle.importKey("raw", new Uint8Array([ + 109, 151, 76, 33, 232, 253, 176, 90, 94, 40, 146, 227, 139, 208, 245, 139, + 69, 215, 55, 197, 43, 122, 160, 178, 228, 104, 4, 115, 138, 159, 119, 49, + ]), { name: "AES-GCM", length: "256" }, true, ["decrypt"]); + +crypto.subtle.importKey("jwk", { + kty: "oct", + ext: true, + key_ops: ["decrypt", "encrypt"], + alg: "A256GCM", + k: "9Id_8iG6FkGOWmc1S203vGVnTExtpDGxdQN7v7OV9Uc", + }, { name: "AES-GCM", length: "256" }, true, ["decrypt"]); + // @ts-expect-error crypto.subtle.importKey(); // @ts-expect-error