Skip to content

Commit ccbfb5d

Browse files
authored
Merge pull request #16 from almasen/dev
2.2.2
2 parents 2ec9548 + 52988cf commit ccbfb5d

File tree

8 files changed

+137
-151
lines changed

8 files changed

+137
-151
lines changed

.github/workflows/test-and-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272

7373
- name: Publish test coverage
7474
uses: easingthemes/ssh-deploy@v2.1.4
75-
env:
75+
with:
7676
SOURCE: "coverage"
7777
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
7878
REMOTE_HOST: ${{ secrets.SSH_HOST }}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## Change log
22

3+
## 2.2.2 - 2023-12-30
4+
5+
### Added
6+
7+
* Bump development dependencies
8+
9+
### Fixed
10+
11+
* Unsupported JS constructs for legacy node versions
12+
313
## 2.2.1 - 2023-09-13
414

515
### Added

README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,6 @@ You can read more about this [here](https://nodejs.org/api/crypto.html#crypto_cr
149149

150150
As `n-digit-token` is dependent on `crypto.randomBytes()` it uses libuv's threadpool, which can have performance implications for some applications. Please refer to the documentation [here](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback) for more information.
151151

152-
#### Time complexity chart
153-
154-
To test the consistency of the speed of the algorithm on a modern CPU, `n-digit-token` was called to generate a token of length `1` to `1000` on an `AMD EPYC 7000` clocked at `2.2 GHz`. This test was repeated a `1000` times on different occasions and the times were averaged.
155-
156-
The below chart represents the time it takes (in nanoseconds) to generate a token of length `x`:
157-
158-
<p align="center">
159-
Time taken per token length
160-
</p>
161-
162-
[![Time complexity](./img/time-complexity.svg)](https://raw.githubusercontent.com/almasen/n-digit-token/c3a66bbf99516da413a757433c6ed2ee9d8e76c4/img/time-complexity.svg)
163-
164-
<p align="center">
165-
<small>
166-
y-axis shows time in nanoseconds / token length (AMD EPYC 7000 @ 2.2 GHz)
167-
</small>
168-
</p>
169-
170-
From this test and the diagram above it is shown that for up to `~100` digits the running time is constant, for larger tokens, the time taken is growing by gradually more.
171-
172-
As this algorithm is not designed to be used as a pseudo random digit stream, but to generate fixed-size tokens, this matches expectations. That said, it would be technically feasible to generate a large number of short tokens via this module that still runs in constant time, and then concatenate the tokens to a large stream.
173-
174152
### Memory usage
175153

176154
By default the algorithm ensures modulo precision whilst also balancing performance and memory usage.
@@ -405,10 +383,6 @@ const token = gen(6, { customByteStream: randomBytes });
405383

406384
Please note that this is option has only been tested with `crypto-browserify` and inappropriate use may lead to various unintended consequences.
407385

408-
### options.avoidModuloBias (deprecated)
409-
410-
This setting has been deprecated as of `n-digit-token@v2.x` since the algorithm avoids modulo bias by default. Therefore, the use of this option is now unnecessary and ignored by the application.
411-
412386
## Test
413387

414388
Install the `devDependencies` and run `npm test` for the module tests.

img/time-complexity.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 123 additions & 120 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n-digit-token",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "Cryptographically secure pseudo-random token of n digits",
55
"keywords": [
66
"token",

src/library/calculateByteSize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import type { Options } from './types';
88
* @return {number} required number of bytes
99
*/
1010
export const calculateByteSize = (length: number, options?: Options): number =>
11-
options?.customMemory || DEFAULT_BYTE_SIZE + length;
11+
options && options.customMemory || DEFAULT_BYTE_SIZE + length;

src/library/generateSecureBytes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Options } from './types';
77
* @return {Buffer} bytes in buffer
88
*/
99
const generateSecureBytesBuffer = (length: number, options?: Options): Buffer =>
10-
options?.customByteStream
10+
options && options.customByteStream
1111
? options.customByteStream(length)
1212
: randomBytes(length);
1313

0 commit comments

Comments
 (0)