Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Commit b3f2129

Browse files
ts-jest
1 parent 0f77388 commit b3f2129

File tree

12 files changed

+5704
-1511
lines changed

12 files changed

+5704
-1511
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5"
5+
}

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ cache:
88
directories:
99
- node_modules
1010
script:
11-
- yarn lint
1211
- yarn build
1312
- yarn test

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"editor.formatOnSave": true
4+
}

README.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Node.js One-Time Password library
77

88
## Features
9+
910
- Zero Dependency
1011
- TypeScript Definitions
1112
- RFC4226 (HMAC One-Time Password)
@@ -14,6 +15,7 @@ Node.js One-Time Password library
1415
---
1516

1617
## Installation
18+
1719
```bash
1820
yarn add node-otp
1921
```
@@ -25,15 +27,20 @@ npm install --save node-otp
2527
```
2628

2729
## Examples
30+
2831
```javascript
29-
otp.hotp({
30-
secret: '12345678901234567890'
32+
const { hotp } = require('node-otp')
33+
34+
hotp({
35+
secret: '12345678901234567890',
3136
})
3237
```
3338

3439
```javascript
35-
otp.totp({
36-
secret: '12345678901234567890'
40+
const { totp } = require('node-otp')
41+
42+
totp({
43+
secret: '12345678901234567890',
3744
})
3845
```
3946

@@ -42,30 +49,53 @@ otp.totp({
4249
### `hotp: (parameters: Parameters) => string`
4350

4451
### `Parameters`
52+
4553
#### `secret: string | Buffer`
54+
4655
#### `movingFactor?: number`
56+
4757
Default value of `movingFactor` is 0
58+
4859
#### `codeDigits?: number`
60+
4961
Default value of `codeDigits` is 6
62+
5063
#### `addChecksum?: boolean`
64+
5165
Default value of `addChecksum` is false
66+
5267
#### `truncationOffset?: number`
68+
5369
Default value of `truncationOffset` is -1
70+
5471
#### `hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'`
72+
5573
Default value of `hmacAlgorithm` is sha1
5674

5775
---
5876

5977
### `totp: (parameters: Parameters) => string`
78+
6079
### `Parameters`
80+
6181
#### `secret: string | Buffer`
82+
6283
#### `step?: number`
84+
6385
Default value of `step` is 30
86+
6487
#### `time?: number`
88+
6589
Default value of `time` is 6
90+
6691
#### `initialTime?: number`
92+
6793
Default value of `initialTime` is 0
94+
6895
#### `codeDigits?: number`
96+
6997
Default value of `codeDigits` is 6
98+
7099
#### `hmacAlgorithm?: 'sha1' | 'sha256' | 'sha512'`
100+
71101
Default value of `hmacAlgorithm` is sha256
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,127 @@
1-
const otp = require('../lib')
1+
import { hotp } from '../src'
22

33
test('algorithm not supported', function() {
44
expect(() => {
5-
otp.hotp({
5+
hotp({
66
secret: '12345678901234567890',
7-
hmacAlgorithm: 'sha522'
7+
// @ts-ignore
8+
hmacAlgorithm: 'sha522',
89
})
910
}).toThrow()
1011
})
1112

1213
test('no secret value', function() {
1314
expect(() => {
14-
otp.hotp({
15-
secret: undefined
15+
hotp({
16+
// @ts-ignore
17+
secret: undefined,
1618
})
1719
}).toThrow()
1820
})
1921

2022
test('truncation offset', function() {
2123
expect(
22-
otp.hotp({
24+
hotp({
2325
secret: '12345678901234567890',
24-
truncationOffset: 1
26+
truncationOffset: 1,
2527
})
2628
).toBe('339280')
2729
})
2830

2931
test('add checksum', function() {
3032
expect(
31-
otp.hotp({
33+
hotp({
3234
secret: '12345678901234567890',
33-
addChecksum: true
35+
addChecksum: true,
3436
})
3537
)
3638
})
3739

3840
test('hotp 0', function() {
3941
expect(
40-
otp.hotp({
41-
secret: '12345678901234567890'
42+
hotp({
43+
secret: '12345678901234567890',
4244
})
4345
).toBe('755224')
4446
})
4547

4648
test('hotp 1', function() {
4749
expect(
48-
otp.hotp({
50+
hotp({
4951
secret: '12345678901234567890',
50-
movingFactor: 1
52+
movingFactor: 1,
5153
})
5254
).toBe('287082')
5355
})
5456

5557
test('hotp 2', function() {
5658
expect(
57-
otp.hotp({
59+
hotp({
5860
secret: '12345678901234567890',
59-
movingFactor: 2
61+
movingFactor: 2,
6062
})
6163
).toBe('359152')
6264
})
6365

6466
test('hotp 3', function() {
6567
expect(
66-
otp.hotp({
68+
hotp({
6769
secret: '12345678901234567890',
68-
movingFactor: 3
70+
movingFactor: 3,
6971
})
7072
).toBe('969429')
7173
})
7274

7375
test('hotp 4', function() {
7476
expect(
75-
otp.hotp({
77+
hotp({
7678
secret: '12345678901234567890',
77-
movingFactor: 4
79+
movingFactor: 4,
7880
})
7981
).toBe('338314')
8082
})
8183

8284
test('hotp 5', function() {
8385
expect(
84-
otp.hotp({
86+
hotp({
8587
secret: '12345678901234567890',
86-
movingFactor: 5
88+
movingFactor: 5,
8789
})
8890
).toBe('254676')
8991
})
9092

9193
test('hotp 6', function() {
9294
expect(
93-
otp.hotp({
95+
hotp({
9496
secret: '12345678901234567890',
95-
movingFactor: 6
97+
movingFactor: 6,
9698
})
9799
).toBe('287922')
98100
})
99101

100102
test('hotp 7', function() {
101103
expect(
102-
otp.hotp({
104+
hotp({
103105
secret: '12345678901234567890',
104-
movingFactor: 7
106+
movingFactor: 7,
105107
})
106108
).toBe('162583')
107109
})
108110

109111
test('hotp 8', function() {
110112
expect(
111-
otp.hotp({
113+
hotp({
112114
secret: '12345678901234567890',
113-
movingFactor: 8
115+
movingFactor: 8,
114116
})
115117
).toBe('399871')
116118
})
117119

118120
test('hotp 9', function() {
119121
expect(
120-
otp.hotp({
122+
hotp({
121123
secret: '12345678901234567890',
122-
movingFactor: 9
124+
movingFactor: 9,
123125
})
124126
).toBe('520489')
125127
})

0 commit comments

Comments
 (0)