|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +// NOTE that this is a partial copy from lib.dom.d.ts which is NEEDED because these utils are used in the /common/ |
| 7 | +// layer which has no dependency on the DOM/browser-context. However, `crypto` is available as global in all browsers and |
| 8 | +// in nodejs. Therefore it's OK to spell out its typings here |
| 9 | + |
| 10 | +declare global { |
| 11 | + |
| 12 | + /** |
| 13 | + * This Web Crypto API interface provides a number of low-level cryptographic functions. It is accessed via the Crypto.subtle properties available in a window context (via Window.crypto). |
| 14 | + * Available only in secure contexts. |
| 15 | + * |
| 16 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto) |
| 17 | + */ |
| 18 | + interface SubtleCrypto { |
| 19 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/decrypt) */ |
| 20 | + // decrypt(algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>; |
| 21 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveBits) */ |
| 22 | + // deriveBits(algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, baseKey: CryptoKey, length?: number | null): Promise<ArrayBuffer>; |
| 23 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveKey) */ |
| 24 | + // deriveKey(algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params, baseKey: CryptoKey, derivedKeyType: AlgorithmIdentifier | AesDerivedKeyParams | HmacImportParams | HkdfParams | Pbkdf2Params, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>; |
| 25 | + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/digest) */ |
| 26 | + digest(algorithm: { name: string } | string, data: ArrayBufferView | ArrayBuffer): Promise<ArrayBuffer>; |
| 27 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/encrypt) */ |
| 28 | + // encrypt(algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>; |
| 29 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/exportKey) */ |
| 30 | + // exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>; |
| 31 | + // exportKey(format: Exclude<KeyFormat, "jwk">, key: CryptoKey): Promise<ArrayBuffer>; |
| 32 | + // exportKey(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>; |
| 33 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/generateKey) */ |
| 34 | + // generateKey(algorithm: "Ed25519", extractable: boolean, keyUsages: ReadonlyArray<"sign" | "verify">): Promise<CryptoKeyPair>; |
| 35 | + // generateKey(algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKeyPair>; |
| 36 | + // generateKey(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>; |
| 37 | + // generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair | CryptoKey>; |
| 38 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/importKey) */ |
| 39 | + // importKey(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: ReadonlyArray<KeyUsage>): Promise<CryptoKey>; |
| 40 | + // importKey(format: Exclude<KeyFormat, "jwk">, keyData: BufferSource, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>; |
| 41 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/sign) */ |
| 42 | + // sign(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, key: CryptoKey, data: BufferSource): Promise<ArrayBuffer>; |
| 43 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/unwrapKey) */ |
| 44 | + // unwrapKey(format: KeyFormat, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams, unwrappedKeyAlgorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>; |
| 45 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/verify) */ |
| 46 | + // verify(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams, key: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>; |
| 47 | + // /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/wrapKey) */ |
| 48 | + // wrapKey(format: KeyFormat, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AesGcmParams): Promise<ArrayBuffer>; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives. |
| 53 | + * |
| 54 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto) |
| 55 | + */ |
| 56 | + interface Crypto { |
| 57 | + /** |
| 58 | + * Available only in secure contexts. |
| 59 | + * |
| 60 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/subtle) |
| 61 | + */ |
| 62 | + readonly subtle: SubtleCrypto; |
| 63 | + /** |
| 64 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues) |
| 65 | + */ |
| 66 | + getRandomValues<T extends ArrayBufferView | null>(array: T): T; |
| 67 | + /** |
| 68 | + * Available only in secure contexts. |
| 69 | + * |
| 70 | + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID) |
| 71 | + */ |
| 72 | + randomUUID(): `${string}-${string}-${string}-${string}-${string}`; |
| 73 | + } |
| 74 | + |
| 75 | + var Crypto: { |
| 76 | + prototype: Crypto; |
| 77 | + new(): Crypto; |
| 78 | + }; |
| 79 | + |
| 80 | + var crypto: Crypto; |
| 81 | + |
| 82 | +} |
| 83 | +export { } |
0 commit comments