Skip to content

Commit 3256f9d

Browse files
committed
fix
1 parent 4d68d4f commit 3256f9d

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { cryptoMessage } from "./lib/crypto/message.ts";
5656
// ...
5757

5858
const message = await getMessage();
59+
5960
const encryptedMessage = await cryptoMessage.encrypt(message); // Now you can safely store it in an HttpOnly cookie
6061
// ...
6162
const decryptedMessage = await cryptoMessage.decrypt(encryptedMessage);
@@ -145,6 +146,7 @@ import { encryptMessage, decryptMessage } from "./lib/crypto/message.ts";
145146
// ...
146147

147148
const message = await getMessage();
149+
148150
const encryptedMessage = await encryptMessage(message); // Now you can safely store it in an HttpOnly cookie
149151
// ...
150152
const decryptedMessage = await decryptMessage(encryptedMessage);

index.d.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @async
66
* @function createSymmetricKeyFromText
77
* @param {string} text - Text key to be hashed. A 32-byte high entropy string is recommended.
8-
* @param {boolean} [extractable] - Indicates if the key can be exported.
8+
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
99
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
1010
* @returns {Promise<CryptoKey>} A `CryptoKey` containing a SHA-256 hash used to encrypt and decrypt strings.
1111
* @throws {TypeError} Thrown if `text` is invalid.
@@ -46,13 +46,13 @@ export function decryptTextSymmetrically(key: CryptoKey, encryptedText: string,
4646
/**
4747
* Class that simplifies the encryption and decryption using the same key.
4848
*/
49-
export default class SingleCryptText {
49+
export class SingleCryptText {
5050
/**
5151
* Create an instance using a text as a key.
5252
*
5353
* @param {string} text - Text key to be hashed. A 32-byte high entropy string is recommended.
5454
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
55-
* @param {boolean} [extractable] - Indicates if the key can be exported.
55+
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
5656
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
5757
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
5858
* @throws {TypeError} Thrown if `text` is invalid.
@@ -76,26 +76,23 @@ export default class SingleCryptText {
7676
*
7777
* @async
7878
* @param {string} text - String value to be encrypted.
79-
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
80-
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
8179
* @returns {Promise<string>} The value encrypted and encoded as a Base64 string.
8280
* @throws {DOMException} Raised when:
8381
* - The provided key is not valid.
8482
* - The operation failed (e.g., AES-GCM plaintext longer than 2^39−256 bytes).
8583
*/
86-
encrypt(text: string, urlSafe?: boolean, textEncoder?: TextEncoder): Promise<string>;
84+
encrypt(text: string): Promise<string>;
8785
/**
8886
* @async
8987
* @param {string} encryptedText - Encrypted value to be decrypted.
90-
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
91-
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
9288
* @returns {Promise<string>} The value decrypted.
9389
* @throws {TypeError} Thrown if `value` is not a string.
9490
* @throws {SyntaxError} Thrown if `value` contains characters outside Base64 alphabet.
9591
* @throws {DOMException} Raised when:
9692
* - The provided key is not valid.
9793
* - The operation failed.
9894
*/
99-
decrypt(encryptedText: string, urlSafe?: boolean, textDecoder?: TextDecoder): Promise<string>;
95+
decrypt(encryptedText: string): Promise<string>;
10096
#private;
10197
}
98+
export default SingleCryptText;

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const base64UrlOptions = Object.freeze({
2323
* @async
2424
* @function createSymmetricKeyFromText
2525
* @param {string} text - Text key to be hashed. A 32-byte high entropy string is recommended.
26-
* @param {boolean} [extractable] - Indicates if the key can be extractable.
26+
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
2727
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
2828
* @returns {Promise<CryptoKey>} A `CryptoKey` containing a SHA-256 hash used to encrypt and decrypt strings.
2929
* @throws {TypeError} Thrown if `text` is invalid.
@@ -156,7 +156,7 @@ export class SingleCryptText {
156156
*
157157
* @param {string} text - Text key to be hashed. A 32-byte high entropy string is recommended.
158158
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
159-
* @param {boolean} [extractable] - Indicates if the key can be extractable.
159+
* @param {boolean} [extractable] - Whether the generated key is extractable. Defaults to `false`..
160160
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
161161
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
162162
* @throws {TypeError} Thrown if `text` is invalid.

0 commit comments

Comments
 (0)