2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-02-26 12:06:26 -05:00
|
|
|
|
2021-12-09 17:12:21 -05:00
|
|
|
// deno-lint-ignore-file no-var
|
|
|
|
|
2021-02-26 12:06:26 -05:00
|
|
|
/// <reference no-default-lib="true" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-02-26 12:06:26 -05:00
|
|
|
declare var crypto: Crypto;
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface Algorithm {
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface KeyAlgorithm {
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
type AlgorithmIdentifier = string | Algorithm;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
type HashAlgorithmIdentifier = AlgorithmIdentifier;
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
type KeyType = "private" | "public" | "secret";
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
type KeyUsage =
|
|
|
|
| "decrypt"
|
|
|
|
| "deriveBits"
|
|
|
|
| "deriveKey"
|
|
|
|
| "encrypt"
|
|
|
|
| "sign"
|
|
|
|
| "unwrapKey"
|
|
|
|
| "verify"
|
|
|
|
| "wrapKey";
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-29 08:23:51 -04:00
|
|
|
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki";
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
type NamedCurve = string;
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-27 07:19:41 -04:00
|
|
|
interface RsaOtherPrimesInfo {
|
|
|
|
d?: string;
|
|
|
|
r?: string;
|
|
|
|
t?: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-27 07:19:41 -04:00
|
|
|
interface JsonWebKey {
|
|
|
|
alg?: string;
|
|
|
|
crv?: string;
|
|
|
|
d?: string;
|
|
|
|
dp?: string;
|
|
|
|
dq?: string;
|
|
|
|
e?: string;
|
|
|
|
ext?: boolean;
|
|
|
|
k?: string;
|
|
|
|
// deno-lint-ignore camelcase
|
|
|
|
key_ops?: string[];
|
|
|
|
kty?: string;
|
|
|
|
n?: string;
|
|
|
|
oth?: RsaOtherPrimesInfo[];
|
|
|
|
p?: string;
|
|
|
|
q?: string;
|
|
|
|
qi?: string;
|
|
|
|
use?: string;
|
|
|
|
x?: string;
|
|
|
|
y?: string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-10-11 10:37:51 -04:00
|
|
|
interface AesCbcParams extends Algorithm {
|
|
|
|
iv: BufferSource;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2022-01-05 10:12:30 -05:00
|
|
|
interface AesGcmParams extends Algorithm {
|
|
|
|
iv: BufferSource;
|
|
|
|
additionalData?: BufferSource;
|
|
|
|
tagLength?: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2022-01-03 06:27:28 -05:00
|
|
|
interface AesCtrParams extends Algorithm {
|
|
|
|
counter: BufferSource;
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface HmacKeyGenParams extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
length?: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface EcKeyGenParams extends Algorithm {
|
|
|
|
namedCurve: NamedCurve;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2022-03-11 09:05:40 -05:00
|
|
|
interface EcKeyImportParams extends Algorithm {
|
2021-12-16 11:28:43 -05:00
|
|
|
namedCurve: NamedCurve;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface EcdsaParams extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-09-14 09:21:20 -04:00
|
|
|
interface RsaHashedImportParams extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface RsaHashedKeyGenParams extends RsaKeyGenParams {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface RsaKeyGenParams extends Algorithm {
|
|
|
|
modulusLength: number;
|
|
|
|
publicExponent: Uint8Array;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
interface RsaPssParams extends Algorithm {
|
|
|
|
saltLength: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-24 15:59:02 -04:00
|
|
|
interface RsaOaepParams extends Algorithm {
|
|
|
|
label?: Uint8Array;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-03 15:24:02 -04:00
|
|
|
interface HmacImportParams extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
length?: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-24 09:15:25 -04:00
|
|
|
interface EcKeyAlgorithm extends KeyAlgorithm {
|
|
|
|
namedCurve: NamedCurve;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-24 09:15:25 -04:00
|
|
|
interface HmacKeyAlgorithm extends KeyAlgorithm {
|
|
|
|
hash: KeyAlgorithm;
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-24 09:15:25 -04:00
|
|
|
interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm {
|
|
|
|
hash: KeyAlgorithm;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-08-24 09:15:25 -04:00
|
|
|
interface RsaKeyAlgorithm extends KeyAlgorithm {
|
|
|
|
modulusLength: number;
|
|
|
|
publicExponent: Uint8Array;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-09-12 17:02:49 -04:00
|
|
|
interface HkdfParams extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
info: BufferSource;
|
|
|
|
salt: BufferSource;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-09-12 17:02:49 -04:00
|
|
|
interface Pbkdf2Params extends Algorithm {
|
|
|
|
hash: HashAlgorithmIdentifier;
|
|
|
|
iterations: number;
|
|
|
|
salt: BufferSource;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-10-12 06:39:46 -04:00
|
|
|
interface AesDerivedKeyParams extends Algorithm {
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-10-08 11:29:36 -04:00
|
|
|
interface EcdhKeyDeriveParams extends Algorithm {
|
|
|
|
public: CryptoKey;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-10-03 09:24:46 -04:00
|
|
|
interface AesKeyGenParams extends Algorithm {
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-10-03 09:24:46 -04:00
|
|
|
interface AesKeyAlgorithm extends KeyAlgorithm {
|
|
|
|
length: number;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** The CryptoKey dictionary of the Web Crypto API represents a cryptographic
|
|
|
|
* key.
|
|
|
|
*
|
|
|
|
* @category Web Crypto API
|
|
|
|
*/
|
2021-07-06 08:16:04 -04:00
|
|
|
interface CryptoKey {
|
|
|
|
readonly algorithm: KeyAlgorithm;
|
|
|
|
readonly extractable: boolean;
|
|
|
|
readonly type: KeyType;
|
|
|
|
readonly usages: KeyUsage[];
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
declare var CryptoKey: {
|
|
|
|
prototype: CryptoKey;
|
|
|
|
new (): CryptoKey;
|
|
|
|
};
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for
|
|
|
|
* an asymmetric cryptography algorithm, also known as a public-key algorithm.
|
|
|
|
*
|
|
|
|
* @category Web Crypto API
|
|
|
|
*/
|
2021-07-06 08:16:04 -04:00
|
|
|
interface CryptoKeyPair {
|
|
|
|
privateKey: CryptoKey;
|
|
|
|
publicKey: CryptoKey;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
declare var CryptoKeyPair: {
|
|
|
|
prototype: CryptoKeyPair;
|
|
|
|
new (): CryptoKeyPair;
|
|
|
|
};
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** 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).
|
|
|
|
*
|
|
|
|
* @category Web Crypto API
|
|
|
|
*/
|
2021-07-06 08:16:04 -04:00
|
|
|
interface SubtleCrypto {
|
|
|
|
generateKey(
|
|
|
|
algorithm: RsaHashedKeyGenParams | EcKeyGenParams,
|
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKeyPair>;
|
|
|
|
generateKey(
|
2021-10-03 09:24:46 -04:00
|
|
|
algorithm: AesKeyGenParams | HmacKeyGenParams,
|
2021-07-06 08:16:04 -04:00
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKey>;
|
|
|
|
generateKey(
|
|
|
|
algorithm: AlgorithmIdentifier,
|
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKeyPair | CryptoKey>;
|
2021-08-27 07:19:41 -04:00
|
|
|
importKey(
|
|
|
|
format: "jwk",
|
|
|
|
keyData: JsonWebKey,
|
2021-12-16 11:28:43 -05:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| HmacImportParams
|
|
|
|
| RsaHashedImportParams
|
2022-03-11 09:05:40 -05:00
|
|
|
| EcKeyImportParams,
|
2021-08-27 07:19:41 -04:00
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKey>;
|
2021-08-03 15:24:02 -04:00
|
|
|
importKey(
|
2021-09-14 09:21:20 -04:00
|
|
|
format: Exclude<KeyFormat, "jwk">,
|
2021-08-03 15:24:02 -04:00
|
|
|
keyData: BufferSource,
|
2021-12-16 11:28:43 -05:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| HmacImportParams
|
|
|
|
| RsaHashedImportParams
|
2022-03-11 09:05:40 -05:00
|
|
|
| EcKeyImportParams,
|
2021-08-03 15:24:02 -04:00
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKey>;
|
2021-08-29 08:23:51 -04:00
|
|
|
exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>;
|
|
|
|
exportKey(
|
|
|
|
format: Exclude<KeyFormat, "jwk">,
|
|
|
|
key: CryptoKey,
|
|
|
|
): Promise<ArrayBuffer>;
|
2021-07-06 08:16:04 -04:00
|
|
|
sign(
|
|
|
|
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams,
|
|
|
|
key: CryptoKey,
|
2021-07-26 08:00:19 -04:00
|
|
|
data: BufferSource,
|
2021-07-06 08:16:04 -04:00
|
|
|
): Promise<ArrayBuffer>;
|
2021-07-12 08:45:36 -04:00
|
|
|
verify(
|
2021-09-11 16:49:53 -04:00
|
|
|
algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams,
|
2021-07-12 08:45:36 -04:00
|
|
|
key: CryptoKey,
|
2021-07-26 08:00:19 -04:00
|
|
|
signature: BufferSource,
|
|
|
|
data: BufferSource,
|
2021-07-12 08:45:36 -04:00
|
|
|
): Promise<boolean>;
|
2021-06-06 06:57:10 -04:00
|
|
|
digest(
|
|
|
|
algorithm: AlgorithmIdentifier,
|
2021-07-26 08:00:19 -04:00
|
|
|
data: BufferSource,
|
2021-06-06 06:57:10 -04:00
|
|
|
): Promise<ArrayBuffer>;
|
2021-08-24 15:59:02 -04:00
|
|
|
encrypt(
|
2022-01-03 06:27:28 -05:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| RsaOaepParams
|
|
|
|
| AesCbcParams
|
2022-01-05 10:12:30 -05:00
|
|
|
| AesGcmParams
|
2022-01-03 06:27:28 -05:00
|
|
|
| AesCtrParams,
|
2021-08-24 15:59:02 -04:00
|
|
|
key: CryptoKey,
|
|
|
|
data: BufferSource,
|
|
|
|
): Promise<ArrayBuffer>;
|
|
|
|
decrypt(
|
2022-01-03 06:27:28 -05:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| RsaOaepParams
|
|
|
|
| AesCbcParams
|
2022-01-14 03:48:53 -05:00
|
|
|
| AesGcmParams
|
2022-01-03 06:27:28 -05:00
|
|
|
| AesCtrParams,
|
2021-08-24 15:59:02 -04:00
|
|
|
key: CryptoKey,
|
|
|
|
data: BufferSource,
|
|
|
|
): Promise<ArrayBuffer>;
|
2021-09-12 17:02:49 -04:00
|
|
|
deriveBits(
|
2021-10-08 11:29:36 -04:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| HkdfParams
|
|
|
|
| Pbkdf2Params
|
|
|
|
| EcdhKeyDeriveParams,
|
2021-09-12 17:02:49 -04:00
|
|
|
baseKey: CryptoKey,
|
|
|
|
length: number,
|
|
|
|
): Promise<ArrayBuffer>;
|
2021-10-12 06:39:46 -04:00
|
|
|
deriveKey(
|
2022-06-30 01:53:05 -04:00
|
|
|
algorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| HkdfParams
|
|
|
|
| Pbkdf2Params
|
|
|
|
| EcdhKeyDeriveParams,
|
2021-10-12 06:39:46 -04:00
|
|
|
baseKey: CryptoKey,
|
|
|
|
derivedKeyType:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| AesDerivedKeyParams
|
|
|
|
| HmacImportParams
|
|
|
|
| HkdfParams
|
|
|
|
| Pbkdf2Params,
|
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKey>;
|
2021-10-01 05:39:49 -04:00
|
|
|
wrapKey(
|
|
|
|
format: KeyFormat,
|
|
|
|
key: CryptoKey,
|
|
|
|
wrappingKey: CryptoKey,
|
2022-01-10 23:44:47 -05:00
|
|
|
wrapAlgorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| RsaOaepParams
|
|
|
|
| AesCbcParams
|
|
|
|
| AesCtrParams,
|
2021-10-01 05:39:49 -04:00
|
|
|
): Promise<ArrayBuffer>;
|
2021-12-04 22:55:11 -05:00
|
|
|
unwrapKey(
|
|
|
|
format: KeyFormat,
|
|
|
|
wrappedKey: BufferSource,
|
|
|
|
unwrappingKey: CryptoKey,
|
|
|
|
unwrapAlgorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| RsaOaepParams
|
2022-01-10 23:44:47 -05:00
|
|
|
| AesCbcParams
|
|
|
|
| AesCtrParams,
|
2021-12-04 22:55:11 -05:00
|
|
|
unwrappedKeyAlgorithm:
|
|
|
|
| AlgorithmIdentifier
|
|
|
|
| HmacImportParams
|
2022-01-10 23:44:47 -05:00
|
|
|
| RsaHashedImportParams
|
2022-03-11 09:05:40 -05:00
|
|
|
| EcKeyImportParams,
|
2021-12-04 22:55:11 -05:00
|
|
|
extractable: boolean,
|
|
|
|
keyUsages: KeyUsage[],
|
|
|
|
): Promise<CryptoKey>;
|
2021-06-06 06:57:10 -04:00
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-07-06 08:16:04 -04:00
|
|
|
declare interface Crypto {
|
|
|
|
readonly subtle: SubtleCrypto;
|
|
|
|
getRandomValues<
|
|
|
|
T extends
|
|
|
|
| Int8Array
|
|
|
|
| Int16Array
|
|
|
|
| Int32Array
|
|
|
|
| Uint8Array
|
|
|
|
| Uint16Array
|
|
|
|
| Uint32Array
|
|
|
|
| Uint8ClampedArray
|
2022-06-02 09:15:46 -04:00
|
|
|
| BigInt64Array
|
2022-07-11 15:43:57 -04:00
|
|
|
| BigUint64Array,
|
2021-07-06 08:16:04 -04:00
|
|
|
>(
|
|
|
|
array: T,
|
|
|
|
): T;
|
|
|
|
randomUUID(): string;
|
|
|
|
}
|
|
|
|
|
2022-08-16 23:12:24 -04:00
|
|
|
/** @category Web Crypto API */
|
2021-06-06 06:57:10 -04:00
|
|
|
declare var SubtleCrypto: {
|
|
|
|
prototype: SubtleCrypto;
|
|
|
|
new (): SubtleCrypto;
|
|
|
|
};
|