2021-02-26 12:06:26 -05:00
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
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" />
declare var crypto : Crypto ;
2021-07-06 08:16:04 -04:00
interface Algorithm {
name : string ;
}
interface KeyAlgorithm {
name : string ;
}
type AlgorithmIdentifier = string | Algorithm ;
type HashAlgorithmIdentifier = AlgorithmIdentifier ;
type KeyType = "private" | "public" | "secret" ;
type KeyUsage =
| "decrypt"
| "deriveBits"
| "deriveKey"
| "encrypt"
| "sign"
| "unwrapKey"
| "verify"
| "wrapKey" ;
2021-08-29 08:23:51 -04:00
type KeyFormat = "jwk" | "pkcs8" | "raw" | "spki" ;
2021-07-06 08:16:04 -04:00
type NamedCurve = string ;
2021-08-27 07:19:41 -04:00
interface RsaOtherPrimesInfo {
d? : string ;
r? : string ;
t? : string ;
}
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 ;
}
2021-10-11 10:37:51 -04:00
interface AesCbcParams extends Algorithm {
iv : BufferSource ;
}
2021-07-06 08:16:04 -04:00
interface HmacKeyGenParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
length? : number ;
}
interface EcKeyGenParams extends Algorithm {
namedCurve : NamedCurve ;
}
2021-12-16 11:28:43 -05:00
interface EcImportParams extends Algorithm {
namedCurve : NamedCurve ;
}
2021-07-06 08:16:04 -04:00
interface EcdsaParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
}
2021-09-14 09:21:20 -04:00
interface RsaHashedImportParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
}
2021-07-06 08:16:04 -04:00
interface RsaHashedKeyGenParams extends RsaKeyGenParams {
hash : HashAlgorithmIdentifier ;
}
interface RsaKeyGenParams extends Algorithm {
modulusLength : number ;
publicExponent : Uint8Array ;
}
interface RsaPssParams extends Algorithm {
saltLength : number ;
}
2021-08-24 15:59:02 -04:00
interface RsaOaepParams extends Algorithm {
label? : Uint8Array ;
}
2021-08-03 15:24:02 -04:00
interface HmacImportParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
length? : number ;
}
2021-12-14 11:02:14 -05:00
interface RsaHashedImportParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
}
2021-08-24 09:15:25 -04:00
interface EcKeyAlgorithm extends KeyAlgorithm {
namedCurve : NamedCurve ;
}
interface HmacKeyAlgorithm extends KeyAlgorithm {
hash : KeyAlgorithm ;
length : number ;
}
interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm {
hash : KeyAlgorithm ;
}
interface RsaKeyAlgorithm extends KeyAlgorithm {
modulusLength : number ;
publicExponent : Uint8Array ;
}
2021-09-12 17:02:49 -04:00
interface HkdfParams extends Algorithm {
hash : HashAlgorithmIdentifier ;
info : BufferSource ;
salt : BufferSource ;
}
interface Pbkdf2Params extends Algorithm {
hash : HashAlgorithmIdentifier ;
iterations : number ;
salt : BufferSource ;
}
2021-10-12 06:39:46 -04:00
interface AesDerivedKeyParams extends Algorithm {
length : number ;
}
2021-10-08 11:29:36 -04:00
interface EcdhKeyDeriveParams extends Algorithm {
public : CryptoKey ;
}
2021-10-03 09:24:46 -04:00
interface AesKeyGenParams extends Algorithm {
length : number ;
}
interface AesKeyAlgorithm extends KeyAlgorithm {
length : number ;
}
2021-07-06 08:16:04 -04:00
/** The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. */
interface CryptoKey {
readonly algorithm : KeyAlgorithm ;
readonly extractable : boolean ;
readonly type : KeyType ;
readonly usages : KeyUsage [ ] ;
}
declare var CryptoKey : {
prototype : CryptoKey ;
new ( ) : CryptoKey ;
} ;
/** The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for an asymmetric cryptography algorithm, also known as a public-key algorithm. */
interface CryptoKeyPair {
privateKey : CryptoKey ;
publicKey : CryptoKey ;
}
declare var CryptoKeyPair : {
prototype : CryptoKeyPair ;
new ( ) : CryptoKeyPair ;
} ;
/** 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). */
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
| EcImportParams ,
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
| EcImportParams ,
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 (
2021-10-11 10:37:51 -04:00
algorithm : AlgorithmIdentifier | RsaOaepParams | AesCbcParams ,
2021-08-24 15:59:02 -04:00
key : CryptoKey ,
data : BufferSource ,
) : Promise < ArrayBuffer > ;
decrypt (
2021-10-11 10:37:51 -04:00
algorithm : AlgorithmIdentifier | RsaOaepParams | AesCbcParams ,
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 (
algorithm : AlgorithmIdentifier | HkdfParams | Pbkdf2Params ,
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 ,
wrapAlgorithm : AlgorithmIdentifier | RsaOaepParams ,
) : Promise < ArrayBuffer > ;
2021-12-04 22:55:11 -05:00
unwrapKey (
format : KeyFormat ,
wrappedKey : BufferSource ,
unwrappingKey : CryptoKey ,
unwrapAlgorithm :
| AlgorithmIdentifier
| RsaOaepParams
| AesCbcParams ,
unwrappedKeyAlgorithm :
| AlgorithmIdentifier
| RsaHashedImportParams
| HmacImportParams
| AesKeyAlgorithm ,
extractable : boolean ,
keyUsages : KeyUsage [ ] ,
) : Promise < CryptoKey > ;
2021-06-06 06:57:10 -04:00
}
2021-07-06 08:16:04 -04:00
declare interface Crypto {
readonly subtle : SubtleCrypto ;
getRandomValues <
T extends
| Int8Array
| Int16Array
| Int32Array
| Uint8Array
| Uint16Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array
| DataView
| null ,
> (
array : T ,
) : T ;
randomUUID ( ) : string ;
}
2021-06-06 06:57:10 -04:00
declare var SubtleCrypto : {
prototype : SubtleCrypto ;
new ( ) : SubtleCrypto ;
} ;