@pgpm/totp 0.15.3 → 0.15.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +1 -1
- package/README.md +1 -1
- package/package.json +5 -5
- package/pgpm-totp.control +1 -1
- package/__tests__/__snapshots__/algo.test.ts.snap +0 -25
- package/__tests__/algo.test.ts +0 -142
- package/__tests__/totp.test.ts +0 -26
- package/jest.config.js +0 -15
- /package/sql/{pgpm-totp--0.15.2.sql → pgpm-totp--0.15.3.sql} +0 -0
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<img height="20" src="https://github.com/constructive-io/pgpm-modules/actions/workflows/ci.yml/badge.svg" />
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://github.com/constructive-io/pgpm-modules/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/@pgpm/totp"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/pgpm-modules?filename=packages%
|
|
12
|
+
<a href="https://www.npmjs.com/package/@pgpm/totp"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/pgpm-modules?filename=packages%2Ftotp%2Fpackage.json"/></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
TOTP implementation in pure PostgreSQL plpgsql
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/totp",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.5",
|
|
4
4
|
"description": "Time-based One-Time Password (TOTP) authentication",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"test:watch": "jest --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@pgpm/base32": "0.15.
|
|
25
|
-
"@pgpm/verify": "0.15.
|
|
24
|
+
"@pgpm/base32": "0.15.5",
|
|
25
|
+
"@pgpm/verify": "0.15.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"pgpm": "^1.
|
|
28
|
+
"pgpm": "^1.3.0"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/constructive-io/pgpm-modules/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f6bbdfb20760e308b02968038b6f54191a9fd527"
|
|
39
39
|
}
|
package/pgpm-totp.control
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`issue case: 1 1`] = `"476240"`;
|
|
4
|
-
|
|
5
|
-
exports[`issue case: 2 1`] = `"788648"`;
|
|
6
|
-
|
|
7
|
-
exports[`issue case: 3 1`] = `"080176"`;
|
|
8
|
-
|
|
9
|
-
exports[`rfc6238 case: 1 1`] = `"94287082"`;
|
|
10
|
-
|
|
11
|
-
exports[`rfc6238 case: 2 1`] = `"07081804"`;
|
|
12
|
-
|
|
13
|
-
exports[`rfc6238 case: 3 1`] = `"14050471"`;
|
|
14
|
-
|
|
15
|
-
exports[`rfc6238 case: 4 1`] = `"89005924"`;
|
|
16
|
-
|
|
17
|
-
exports[`rfc6238 case: 5 1`] = `"69279037"`;
|
|
18
|
-
|
|
19
|
-
exports[`rfc6238 case: 6 1`] = `"65353130"`;
|
|
20
|
-
|
|
21
|
-
exports[`speakeasy test case: 1 1`] = `"287082"`;
|
|
22
|
-
|
|
23
|
-
exports[`speakeasy test case: 2 1`] = `"081804"`;
|
|
24
|
-
|
|
25
|
-
exports[`speakeasy test case: 3 1`] = `"360094"`;
|
package/__tests__/algo.test.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { getConnections, PgTestClient } from 'pgsql-test';
|
|
2
|
-
import cases from 'jest-in-case';
|
|
3
|
-
|
|
4
|
-
let pg: PgTestClient;
|
|
5
|
-
let teardown: () => Promise<void>;
|
|
6
|
-
|
|
7
|
-
beforeAll(async () => {
|
|
8
|
-
({ pg, teardown } = await getConnections());
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
afterAll(async () => {
|
|
12
|
-
await teardown();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
cases(
|
|
17
|
-
'rfc6238',
|
|
18
|
-
async (opts: { date: string; len: number; algo: string; result: string }) => {
|
|
19
|
-
const { generate } = await pg.one(
|
|
20
|
-
`SELECT totp.generate(
|
|
21
|
-
secret := $1,
|
|
22
|
-
period := 30,
|
|
23
|
-
digits := $2,
|
|
24
|
-
time_from := $3,
|
|
25
|
-
hash := $4,
|
|
26
|
-
encoding := NULL
|
|
27
|
-
)`,
|
|
28
|
-
['12345678901234567890', opts.len, opts.date, opts.algo]
|
|
29
|
-
);
|
|
30
|
-
expect(generate).toEqual(opts.result);
|
|
31
|
-
expect(generate).toMatchSnapshot();
|
|
32
|
-
},
|
|
33
|
-
[
|
|
34
|
-
{ date: '1970-01-01 00:00:59', len: 8, algo: 'sha1', result: '94287082' },
|
|
35
|
-
{ date: '2005-03-18 01:58:29', len: 8, algo: 'sha1', result: '07081804' },
|
|
36
|
-
{ date: '2005-03-18 01:58:31', len: 8, algo: 'sha1', result: '14050471' },
|
|
37
|
-
{ date: '2009-02-13 23:31:30', len: 8, algo: 'sha1', result: '89005924' },
|
|
38
|
-
{ date: '2033-05-18 03:33:20', len: 8, algo: 'sha1', result: '69279037' },
|
|
39
|
-
{ date: '2603-10-11 11:33:20', len: 8, algo: 'sha1', result: '65353130' }
|
|
40
|
-
]
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
cases(
|
|
44
|
-
'speakeasy test',
|
|
45
|
-
async (opts: { date: string; len: number; algo: string; step: number; result: string }) => {
|
|
46
|
-
const { generate } = await pg.one(
|
|
47
|
-
`SELECT totp.generate(
|
|
48
|
-
secret := $1,
|
|
49
|
-
period := $5,
|
|
50
|
-
digits := $2,
|
|
51
|
-
time_from := $3,
|
|
52
|
-
hash := $4,
|
|
53
|
-
encoding := NULL
|
|
54
|
-
)`,
|
|
55
|
-
['12345678901234567890', opts.len, opts.date, opts.algo, opts.step]
|
|
56
|
-
);
|
|
57
|
-
expect(generate).toEqual(opts.result);
|
|
58
|
-
expect(generate).toMatchSnapshot();
|
|
59
|
-
},
|
|
60
|
-
[
|
|
61
|
-
{ date: '1970-01-01 00:00:59', len: 6, step: 30, algo: 'sha1', result: '287082' },
|
|
62
|
-
{ date: '2005-03-18 01:58:29', len: 6, step: 30, algo: 'sha1', result: '081804' },
|
|
63
|
-
{ date: '2005-03-18 01:58:29', len: 6, step: 60, algo: 'sha1', result: '360094' }
|
|
64
|
-
]
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
cases(
|
|
68
|
-
'verify',
|
|
69
|
-
async (opts: { date: string; len: number; algo?: string; step: number; result: string }) => {
|
|
70
|
-
const [{ verified }] = await pg.any(
|
|
71
|
-
`SELECT * FROM totp.verify(
|
|
72
|
-
secret := $1,
|
|
73
|
-
check_totp := $2,
|
|
74
|
-
period := $3,
|
|
75
|
-
digits := $4,
|
|
76
|
-
time_from := $5,
|
|
77
|
-
encoding := NULL
|
|
78
|
-
) as verified`,
|
|
79
|
-
['12345678901234567890', opts.result, opts.step, opts.len, opts.date]
|
|
80
|
-
);
|
|
81
|
-
expect(verified).toBe(true);
|
|
82
|
-
},
|
|
83
|
-
[
|
|
84
|
-
{ date: '1970-01-01 00:00:59', len: 6, step: 30, algo: 'sha1', result: '287082' },
|
|
85
|
-
{ date: '2005-03-18 01:58:29', len: 6, step: 30, algo: 'sha1', result: '081804' },
|
|
86
|
-
{ date: '2005-03-18 01:58:29', len: 6, step: 60, algo: 'sha1', result: '360094' },
|
|
87
|
-
{ date: '1970-01-01 00:00:59', len: 8, step: 30, algo: 'sha1', result: '94287082' },
|
|
88
|
-
{ date: '2005-03-18 01:58:29', len: 8, step: 30, algo: 'sha1', result: '07081804' },
|
|
89
|
-
{ date: '2005-03-18 01:58:31', len: 8, step: 30, algo: 'sha1', result: '14050471' },
|
|
90
|
-
{ date: '2009-02-13 23:31:30', len: 8, step: 30, algo: 'sha1', result: '89005924' },
|
|
91
|
-
{ date: '2033-05-18 03:33:20', len: 8, algo: 'sha1', step: 30, result: '69279037' },
|
|
92
|
-
{ date: '2603-10-11 11:33:20', len: 8, algo: 'sha1', step: 30, result: '65353130' }
|
|
93
|
-
]
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
cases(
|
|
97
|
-
'issue',
|
|
98
|
-
async (opts: { encoding: string | null; secret: string; date: string; len: number; step: number; algo: string; result: string }) => {
|
|
99
|
-
const { generate } = await pg.one(
|
|
100
|
-
`SELECT totp.generate(
|
|
101
|
-
secret := $1,
|
|
102
|
-
period := $2,
|
|
103
|
-
digits := $3,
|
|
104
|
-
time_from := $4,
|
|
105
|
-
hash := $5,
|
|
106
|
-
encoding := $6
|
|
107
|
-
)`,
|
|
108
|
-
[opts.secret, opts.step, opts.len, opts.date, opts.algo, opts.encoding]
|
|
109
|
-
);
|
|
110
|
-
expect(generate).toEqual(opts.result);
|
|
111
|
-
expect(generate).toMatchSnapshot();
|
|
112
|
-
},
|
|
113
|
-
[
|
|
114
|
-
{
|
|
115
|
-
encoding: null,
|
|
116
|
-
secret: 'OH3NUPO3WOGOZZQ4',
|
|
117
|
-
date: '2020-11-14 07:46:37.212048+00',
|
|
118
|
-
len: 6,
|
|
119
|
-
step: 30,
|
|
120
|
-
algo: 'sha1',
|
|
121
|
-
result: '476240'
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
encoding: 'base32',
|
|
125
|
-
secret: 'OH3NUPO3WOGOZZQ4',
|
|
126
|
-
date: '2020-11-14 07:46:37.212048+00',
|
|
127
|
-
len: 6,
|
|
128
|
-
step: 30,
|
|
129
|
-
algo: 'sha1',
|
|
130
|
-
result: '788648'
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
encoding: 'base32',
|
|
134
|
-
secret: 'OH3NUPO',
|
|
135
|
-
date: '2020-11-14 07:46:37.212048+00',
|
|
136
|
-
len: 6,
|
|
137
|
-
step: 30,
|
|
138
|
-
algo: 'sha1',
|
|
139
|
-
result: '080176'
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
);
|
package/__tests__/totp.test.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { getConnections, PgTestClient } from 'pgsql-test';
|
|
2
|
-
|
|
3
|
-
let pg: PgTestClient;
|
|
4
|
-
let teardown: () => Promise<void>;
|
|
5
|
-
|
|
6
|
-
beforeAll(async () => {
|
|
7
|
-
({ pg, teardown } = await getConnections());
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
afterAll(async () => {
|
|
11
|
-
await teardown();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
it('totp.generate + totp.verify basic', async () => {
|
|
16
|
-
const { generate } = await pg.one(
|
|
17
|
-
`SELECT totp.generate($1::text) AS generate`,
|
|
18
|
-
['secret']
|
|
19
|
-
);
|
|
20
|
-
const { verify } = await pg.one(
|
|
21
|
-
`SELECT totp.verify($1::text, $2::text) AS verify`,
|
|
22
|
-
['secret', generate]
|
|
23
|
-
);
|
|
24
|
-
expect(typeof generate).toBe('string');
|
|
25
|
-
expect(verify).toBe(true);
|
|
26
|
-
});
|
package/jest.config.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
preset: 'ts-jest',
|
|
4
|
-
testEnvironment: 'node',
|
|
5
|
-
|
|
6
|
-
// Match both __tests__ and colocated test files
|
|
7
|
-
testMatch: ['**/?(*.)+(test|spec).{ts,tsx,js,jsx}'],
|
|
8
|
-
|
|
9
|
-
// Ignore build artifacts and type declarations
|
|
10
|
-
testPathIgnorePatterns: ['/dist/', '\\.d\\.ts$'],
|
|
11
|
-
modulePathIgnorePatterns: ['<rootDir>/dist/'],
|
|
12
|
-
watchPathIgnorePatterns: ['/dist/'],
|
|
13
|
-
|
|
14
|
-
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
15
|
-
};
|
|
File without changes
|