-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
92 lines (92 loc) · 4.85 KB
/
index.d.ts
File metadata and controls
92 lines (92 loc) · 4.85 KB
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
/**
* Before encrypting and decrypting values, a symmetric `CryptoKey` must be created.
* This method also converts your value key to a SHA-256 hash.
*
* @async
* @function createSymmetricKeyFromText
* @param {string} key - Text key to be hashed. A 32-byte high entropy string is recommended.
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
* @returns {Promise<CryptoKey>} A `CryptoKey` containing a SHA-256 hash used to encrypt and decrypt strings.
* @throws {TypeError} Thrown if `text` is invalid.
*/
export function createSymmetricKeyFromText(key: string, extractable?: boolean, textEncoder?: TextEncoder): Promise<CryptoKey>;
/**
* Encrypts a value with a `CryptoKey` previously generated with `createSymmetricKeyFromText`.
*
* @async
* @function encryptTextSymmetrically
* @param {CryptoKey} key - Symmetric key generated with `createSymmetricKeyFromText`.
* @param {string} text - String value to be encrypted.
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
* @param {BufferSource} [additionalData] - Additional data for authentication.
* @returns {Promise<string>} The value encrypted and encoded as a Base64 string.
* @throws {DOMException} Raised when:
* - The provided key is not valid.
* - The operation failed (e.g., AES-GCM plaintext longer than 2^39−256 bytes).
*/
export function encryptTextSymmetrically(key: CryptoKey, text: string, urlSafe?: boolean, textEncoder?: TextEncoder, additionalData?: BufferSource): Promise<string>;
/**
* Decrypts a value with a `CryptoKey` previously generated with `createSymmetricKeyFromText`.
*
* @async
* @function decryptTextSymmetrically
* @param {CryptoKey} key - Symmetric key used to encrypt the value.
* @param {string} ciphertext - Encrypted value to be decrypted.
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
* @param {BufferSource} [additionalData] - Additional data for authentication.
* @returns {Promise<string>} The value decrypted.
* @throws {TypeError} Thrown if `ciphertext` is not a string.
* @throws {SyntaxError} Thrown if `ciphertext` contains characters outside Base64 alphabet.
* @throws {DOMException} Raised when:
* - The provided key is not valid.
* - The operation failed.
*/
export function decryptTextSymmetrically(key: CryptoKey, ciphertext: string, textDecoder?: TextDecoder, additionalData?: BufferSource): Promise<string>;
/**
* Class that simplifies the encryption and decryption using the same key.
*/
export class SingleCryptText {
/**
* Create an instance using a text as a key.
*
* @param {string} key - Text key to be hashed. A 32-byte high entropy string is recommended.
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
* @throws {TypeError} Thrown if `key` is invalid.
*/
constructor(key: string, extractable?: boolean, textEncoder?: TextEncoder, textDecoder?: TextDecoder);
/**
* @async
* @function getKey
* @returns {Promise<CryptoKey>}
*/
getKey(): Promise<CryptoKey>;
/**
* @async
* @param {string} text - String value to be encrypted.
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
* @param {BufferSource} [additionalData] - Additional data for authentication.
* @returns {Promise<string>} The value encrypted and encoded as a Base64 string.
* @throws {DOMException} Raised when:
* - The provided key is not valid.
* - The operation failed (e.g., AES-GCM plaintext longer than 2^39−256 bytes).
*/
encrypt(text: string, urlSafe?: boolean, additionalData?: BufferSource): Promise<string>;
/**
* @async
* @param {string} ciphertext - Encrypted value to be decrypted.
* @param {BufferSource} [additionalData] - Additional data for authentication.
* @returns {Promise<string>} The value decrypted.
* @throws {TypeError} Thrown if `ciphertext` is not a string.
* @throws {SyntaxError} Thrown if `ciphertext` contains characters outside Base64 alphabet.
* @throws {DOMException} Raised when:
* - The provided key is not valid.
* - The operation failed.
*/
decrypt(ciphertext: string, additionalData?: BufferSource): Promise<string>;
#private;
}
export default SingleCryptText;