forked from PeculiarVentures/webcrypto-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
236 lines (208 loc) · 11.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
declare type NativeCrypto = Crypto;
declare type NativeSubtleCrypto = SubtleCrypto;
declare type NativeCryptoKey = CryptoKey;
declare type NativeCryptoKeyPair = CryptoKeyPair;
declare namespace WebcryptoCore {
const AlgorithmNames: {
RsaSSA: string;
RsaPSS: string;
RsaOAEP: string;
AesECB: string;
AesCTR: string;
AesCMAC: string;
AesGCM: string;
AesCBC: string;
AesKW: string;
Sha1: string;
Sha256: string;
Sha384: string;
Sha512: string;
EcDSA: string;
EcDH: string;
Hmac: string;
Pbkdf2: string;
};
function PrepareAlgorithm(alg: AlgorithmIdentifier | string): Algorithm;
function PrepareData(data: BufferSource, paramName: string): Uint8Array;
class BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
public static checkAlgorithmParams(alg: Algorithm): void;
public static checkKey(key: CryptoKey, alg?: string, type?: string | null, usage?: string | null): void;
public static checkWrappedKey(key: CryptoKey): void;
public static checkKeyUsages(keyUsages: string[]): void;
public static checkFormat(format: string, type?: string): void;
public static generateKey(algorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey | CryptoKeyPair>;
public static digest(algorithm: Algorithm, data: Uint8Array): PromiseLike<ArrayBuffer>;
public static sign(algorithm: Algorithm, key: CryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer>;
public static verify(algorithm: Algorithm, key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean>;
public static encrypt(algorithm: Algorithm, key: CryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer>;
public static decrypt(algorithm: Algorithm, key: CryptoKey, data: Uint8Array): PromiseLike<ArrayBuffer>;
public static deriveBits(algorithm: Algorithm, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer>;
public static deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public static exportKey(format: string, key: CryptoKey): PromiseLike<JsonWebKey | ArrayBuffer>;
public static importKey(format: string, keyData: JsonWebKey | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public static wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): PromiseLike<ArrayBuffer>;
public static unwrapKey(format: string, wrappedKey: Uint8Array, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
}
class Base64Url {
public static encode(value: Uint8Array): string;
public static decode(base64url: string): Uint8Array;
protected static buffer2string(buffer: Uint8Array): string;
protected static string2buffer(binaryString: string): Uint8Array;
}
class WebCryptoError extends Error {
public static NOT_SUPPORTED: string;
public code: number;
public stack: string;
constructor(template: string, ...args: any[]);
}
class AlgorithmError extends WebCryptoError {
public static PARAM_REQUIRED: string;
public static PARAM_WRONG_TYPE: string;
public static PARAM_WRONG_VALUE: string;
public static WRONG_ALG_NAME: string;
public static UNSUPPORTED_ALGORITHM: string;
public code: number;
}
class CryptoKeyError extends WebCryptoError {
public static EMPTY_KEY: string;
public static WRONG_KEY_ALG: string;
public static WRONG_KEY_TYPE: string;
public static WRONG_KEY_USAGE: string;
public static NOT_EXTRACTABLE: string;
public static WRONG_FORMAT: string;
public static UNKNOWN_FORMAT: string;
public static ALLOWED_FORMAT: string;
public code: number;
}
class SubtleCrypto implements NativeSubtleCrypto {
public generateKey(algorithm: string, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKeyPair | CryptoKey>;
public generateKey(algorithm: RsaHashedKeyGenParams | EcKeyGenParams | DhKeyGenParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKeyPair>;
public generateKey(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public digest(algorithm: AlgorithmIdentifier, data: BufferSource): PromiseLike<ArrayBuffer>;
public sign(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer>;
public verify(algorithm: string | RsaPssParams | EcdsaParams | AesCmacParams, key: CryptoKey, signature: BufferSource, data: BufferSource): PromiseLike<boolean>;
public encrypt(algorithm: string | RsaOaepParams | AesCtrParams | AesCbcParams | AesCmacParams | AesGcmParams | AesCfbParams, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer>;
public decrypt(algorithm: string | RsaOaepParams | AesCtrParams | AesCbcParams | AesCmacParams | AesGcmParams | AesCfbParams, key: CryptoKey, data: BufferSource): PromiseLike<ArrayBuffer>;
public deriveBits(algorithm: string | EcdhKeyDeriveParams | DhKeyDeriveParams | ConcatParams | HkdfCtrParams | Pbkdf2Params, baseKey: CryptoKey, length: number): PromiseLike<ArrayBuffer>;
public deriveKey(algorithm: string | EcdhKeyDeriveParams | DhKeyDeriveParams | ConcatParams | HkdfCtrParams | Pbkdf2Params, baseKey: CryptoKey, derivedKeyType: string | AesDerivedKeyParams | HmacImportParams | ConcatParams | HkdfCtrParams | Pbkdf2Params, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public exportKey(format: "jwk", key: CryptoKey): PromiseLike<JsonWebKey>;
public exportKey(format: "raw" | "pkcs8" | "spki", key: CryptoKey): PromiseLike<ArrayBuffer>;
public exportKey(format: string, key: CryptoKey): PromiseLike<JsonWebKey | ArrayBuffer>;
public importKey(format: "jwk", keyData: JsonWebKey, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public importKey(format: "raw" | "pkcs8" | "spki", keyData: BufferSource, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public importKey(format: string, keyData: JsonWebKey | BufferSource, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
public wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: AlgorithmIdentifier): PromiseLike<ArrayBuffer>;
public unwrapKey(format: string, wrappedKey: BufferSource, unwrappingKey: CryptoKey, unwrapAlgorithm: AlgorithmIdentifier, unwrappedKeyAlgorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: string[]): PromiseLike<CryptoKey>;
}
export class Aes extends BaseCrypto {
public static checkKeyUsages(keyUsages: string[]): void;
public static checkAlgorithm(alg: Algorithm): void;
public static checkKeyGenParams(alg: AesKeyGenParams): void;
public static checkKeyGenUsages(keyUsages: string[]): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
export class AesAlgorithmError extends AlgorithmError {
public code: number;
}
export class AesWrapKey extends Aes {
}
export class AesEncrypt extends AesWrapKey {
protected static KEY_USAGES: string[];
}
export class AesCBC extends AesEncrypt {
public static checkAlgorithmParams(alg: AesCbcParams): void;
protected static ALG_NAME: string;
}
export class AesCTR extends AesEncrypt {
public static checkAlgorithmParams(alg: AesCtrParams): void;
protected static ALG_NAME: string;
}
export class AesGCM extends AesEncrypt {
public static checkAlgorithmParams(alg: AesGcmParams): void;
protected static ALG_NAME: string;
}
export class AesKW extends AesWrapKey {
public static checkAlgorithmParams(alg: AesGcmParams): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class EcKeyGenParamsError extends AlgorithmError {
public code: number;
}
class Ec extends BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
public static checkKeyGenParams(alg: EcKeyGenParams): void;
public static checkKeyGenUsages(keyUsages: string[]): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class EcAlgorithmError extends AlgorithmError {
public code: number;
}
class EcDSA extends Ec {
public static checkAlgorithmParams(alg: EcdsaParams): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class EcDH extends Ec {
public static checkDeriveParams(algorithm: EcdhKeyDeriveParams): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class RsaKeyGenParamsError extends AlgorithmError {
public code: number;
}
class RsaHashedImportParamsError extends AlgorithmError {
public code: number;
}
class Rsa extends BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
public static checkImportAlgorithm(alg: RsaHashedImportParams): void;
public static checkKeyGenParams(alg: RsaHashedKeyGenParams): void;
public static checkKeyGenUsages(keyUsages: string[]): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class RsaSSA extends Rsa {
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class RsaPSSParamsError extends AlgorithmError {
public code: number;
}
class RsaPSS extends RsaSSA {
public static checkRsaPssParams(alg: RsaPssParams): RsaPSSParamsError | undefined;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
class RsaOAEPParamsError extends AlgorithmError {
public code: number;
}
class RsaOAEP extends Rsa {
public static checkAlgorithmParams(alg: RsaOaepParams): RsaOAEPParamsError | undefined;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
const ShaAlgorithms: string;
class Sha extends BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
}
export class Hmac extends BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
public static checkKeyGenParams(alg: AesKeyGenParams): void;
public static checkKeyGenUsages(keyUsages: string[]): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
export class Pbkdf2 extends BaseCrypto {
public static checkAlgorithm(alg: Algorithm): void;
public static checkDeriveParams(alg: Pbkdf2Params): void;
protected static ALG_NAME: string;
protected static KEY_USAGES: string[];
}
}
declare module "webcrypto-core" {
export = WebcryptoCore;
}