Skip to content

Commit f9c70d3

Browse files
committed
docs: fix
1 parent 7b469de commit f9c70d3

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# SingleCrypt Text
22

33
> [!WARNING]
4-
> This package uses [`Uint8Array.prototype.toBase64()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64) and [`Uint8Array.fromBase64()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64), which, as of November 2025, are only supported by the latest versions of browsers, [Bun](https://bun.com/), [Deno 2.5 or later](https://deno.com/) and [Node.js 25 or later](https://nodejs.org/en). See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64#browser_compatibility) for compatibility.
5-
6-
A simple, secure, and fast symmetric encryption library that makes use of [AES-GCM](https://en.wikipedia.org/wiki/Galois/Counter_Mode) and modern platform features. It leverages the native [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API), so it works both in browsers (in secure contexts) and JavaScript runtimes.
4+
> This package uses
5+
> [`Uint8Array.prototype.toBase64()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64)
6+
> and [`Uint8Array.fromBase64()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64),
7+
> which, as of November 2025, are only supported by the latest versions of browsers, [Bun](https://bun.com/),
8+
> [Deno 2.5 or later](https://deno.com/) and [Node.js 25 or later](https://nodejs.org/en).
9+
> See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64#browser_compatibility)
10+
> for compatibility.
11+
12+
A simple, secure, and fast symmetric encryption library that makes use of
13+
[AES-GCM](https://en.wikipedia.org/wiki/Galois/Counter_Mode) and modern platform features.
14+
It leverages the native [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API),
15+
so it works both in browsers (in secure contexts) and JavaScript runtimes.
716

817
## Why AES-GCM?
918

10-
AES-GCM is extremely fast on modern CPUs, which have dedicated hardware acceleration ([AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set)), in addition to being highly secure and even quantum-resistant (AES-256-GCM).
19+
AES-GCM is extremely fast on modern CPUs,
20+
which have dedicated hardware acceleration ([AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set)),
21+
in addition to being highly secure and even quantum-resistant (AES-256-GCM).
1122

1223
## Installation
1324

@@ -179,11 +190,11 @@ new SingleCryptText(
179190

180191
#### Instance methods
181192

182-
- `async encrypt(text: string, urlSafe?: boolean): Promise<string>`
193+
- `async encrypt(text: string, urlSafe?: boolean, additionalData?: BufferSource): Promise<string>`
183194

184195
Encrypt a string using the instance's key. Optionally specify `urlSafe` (`true` by default) to use `base64url` encoding.
185196

186-
- `async decrypt(ciphertext: string): Promise<string>`
197+
- `async decrypt(ciphertext: string, additionalData?: BufferSource): Promise<string>`
187198

188199
Decrypt a string previously encrypted by this or any compatible instance.
189200

@@ -233,13 +244,15 @@ encryptTextSymmetrically(
233244
key: CryptoKey,
234245
text: string,
235246
urlSafe?: boolean,
236-
textEncoder?: TextEncoder
247+
textEncoder?: TextEncoder,
248+
additionalData?: BufferSource
237249
): Promise<string>
238250
```
239251
- `key`: A symmetric key previously generated with `createSymmetricKeyFromText`.
240252
- `text`: String value to encrypt.
241253
- `urlSafe` (optional): Use `base64url` encoding if `true` (default: `true`). If `false`, uses regular `base64`.
242254
- `textEncoder` (optional): Optionally reuse your own `TextEncoder` instance.
255+
- `additionalData` (optional): Additional data for authentication. Defaults to `undefined`.
243256

244257
Returns a `Promise<string>` containing the encrypted value as a Base64 string.
245258

@@ -252,13 +265,15 @@ Returns a `Promise<string>` containing the encrypted value as a Base64 string.
252265
decryptTextSymmetrically(
253266
key: CryptoKey,
254267
ciphertext: string,
255-
textDecoder?: TextDecoder
268+
textDecoder?: TextDecoder,
269+
additionalData?: BufferSource
256270
): Promise<string>
257271
```
258272

259273
- `key`: A symmetric key previously generated with `createSymmetricKeyFromText`.
260274
- `ciphertext`: The string value to decrypt (encrypted with compatible methods/settings).
261275
- `textDecoder` (optional): Optionally reuse your own `TextDecoder` instance.
276+
- `additionalData` (optional): Additional data for authentication. Defaults to `undefined`.
262277

263278
Returns a `Promise<string>` containing the decrypted value.
264279

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function createSymmetricKeyFromText(
5656
* @param {string} text - String value to be encrypted.
5757
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
5858
* @param {TextEncoder} [textEncoder] - If you have an instance of a `TextEncoder`, you can reuse it.
59-
* @param {BufferSource} [additionalData] - Additional data to be included in the encryption process (authentication tag).
59+
* @param {BufferSource} [additionalData] - Additional data for authentication.
6060
* @returns {Promise<string>} The value encrypted and encoded as a Base64 string.
6161
* @throws {DOMException} Raised when:
6262
* - The provided key is not valid.
@@ -99,7 +99,7 @@ export async function encryptTextSymmetrically(
9999
* @param {CryptoKey} key - Symmetric key used to encrypt the value.
100100
* @param {string} ciphertext - Encrypted value to be decrypted.
101101
* @param {TextDecoder} [textDecoder] - If you have an instance of a `TextDecoder`, you can reuse it.
102-
* @param {BufferSource} [additionalData] - Additional data to be included in the encryption process (authentication tag).
102+
* @param {BufferSource} [additionalData] - Additional data for authentication.
103103
* @returns {Promise<string>} The value decrypted.
104104
* @throws {TypeError} Thrown if `ciphertext` is not a string.
105105
* @throws {SyntaxError} Thrown if `ciphertext` contains characters outside Base64 alphabet.
@@ -211,7 +211,7 @@ export class SingleCryptText {
211211
* @async
212212
* @param {string} text - String value to be encrypted.
213213
* @param {boolean} [urlSafe] - The encrypted values default to `base64` alphabet; this property enables the `base64url` alphabet. Enabled by default.
214-
* @param {BufferSource} [additionalData] - Additional data to be included in the encryption process (authentication tag).
214+
* @param {BufferSource} [additionalData] - Additional data for authentication.
215215
* @returns {Promise<string>} The value encrypted and encoded as a Base64 string.
216216
* @throws {DOMException} Raised when:
217217
* - The provided key is not valid.
@@ -230,7 +230,7 @@ export class SingleCryptText {
230230
/**
231231
* @async
232232
* @param {string} ciphertext - Encrypted value to be decrypted.
233-
* @param {BufferSource} [additionalData] - Additional data to be included in the encryption process (authentication tag).
233+
* @param {BufferSource} [additionalData] - Additional data for authentication.
234234
* @returns {Promise<string>} The value decrypted.
235235
* @throws {TypeError} Thrown if `ciphertext` is not a string.
236236
* @throws {SyntaxError} Thrown if `ciphertext` contains characters outside Base64 alphabet.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "singlecrypt-text",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"author": "Stefan Samson <ss42701@outlook.com> (https://ssbit01.github.io/)",
55
"repository": "github:SSbit01/singlecrypt-text",
66
"main": "index.js",
@@ -47,7 +47,8 @@
4747
"test:random": "bun test --randomize",
4848
"build": "bun build ./index.js --minify --target browser --outdir ./dist --entry-naming [dir]/[name].min.[ext]",
4949
"build:cjs": "bun build ./index.js --minify --format cjs --outdir ./dist --entry-naming [dir]/[name].node.min.[ext]",
50-
"build:types": "tsc"
50+
"build:types": "tsc",
51+
"docs": "typedoc"
5152
},
5253
"type": "module",
5354
"types": "index.d.ts",

0 commit comments

Comments
 (0)