@authcraft/totp-js 0.9.1 → 0.9.3
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/README.md +17 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
**Security-hardened TOTP/2FA library for JavaScript and TypeScript**
|
|
8
8
|
|
|
9
|
-
[](https://www.npmjs.com/package/totp-js)
|
|
9
|
+
[](https://www.npmjs.com/package/@authcraft/totp-js)
|
|
10
10
|
[](https://github.com/Pratiyush/totp-js/actions)
|
|
11
11
|
[](https://codecov.io/gh/Pratiyush/totp-js)
|
|
12
|
-
[](https://www.npmjs.com/package/totp-js)
|
|
12
|
+
[](https://www.npmjs.com/package/@authcraft/totp-js)
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
[](CONTRIBUTING.md)
|
|
15
15
|
|
|
16
16
|
RFC 6238 (TOTP) and RFC 4226 (HOTP) compliant. Zero runtime dependencies.
|
|
17
17
|
Built-in replay protection. Constant-time verification. Works with Node.js 18+.
|
|
18
18
|
|
|
19
|
-
[Documentation](https://pratiyush.github.io/totp-js/) | [npm](https://www.npmjs.com/package/totp-js) | [API Reference](#api-reference)
|
|
19
|
+
[Documentation](https://pratiyush.github.io/totp-js/) | [npm](https://www.npmjs.com/package/@authcraft/totp-js) | [API Reference](#api-reference)
|
|
20
20
|
|
|
21
21
|
</div>
|
|
22
22
|
|
|
@@ -37,19 +37,19 @@ totp-js is the TypeScript counterpart to [totp-impl](https://github.com/Pratiyus
|
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# npm
|
|
40
|
-
npm install totp-js
|
|
40
|
+
npm install @authcraft/totp-js
|
|
41
41
|
|
|
42
42
|
# yarn
|
|
43
|
-
yarn add totp-js
|
|
43
|
+
yarn add @authcraft/totp-js
|
|
44
44
|
|
|
45
45
|
# pnpm
|
|
46
|
-
pnpm add totp-js
|
|
46
|
+
pnpm add @authcraft/totp-js
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
## Quick Start
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
import { TOTP, generateSecret } from 'totp-js';
|
|
52
|
+
import { TOTP, generateSecret } from '@authcraft/totp-js';
|
|
53
53
|
|
|
54
54
|
// Generate a secret for the user
|
|
55
55
|
const secret = generateSecret();
|
|
@@ -71,7 +71,7 @@ console.log(isValid); // true
|
|
|
71
71
|
Prevent the same OTP from being used twice within its validity window:
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
import { TOTP, generateSecret, InMemoryReplayGuard } from 'totp-js';
|
|
74
|
+
import { TOTP, generateSecret, InMemoryReplayGuard } from '@authcraft/totp-js';
|
|
75
75
|
|
|
76
76
|
const guard = InMemoryReplayGuard.withDefaultRetention();
|
|
77
77
|
const totp = TOTP.create({ replayGuard: guard });
|
|
@@ -94,7 +94,7 @@ guard.destroy();
|
|
|
94
94
|
Generate `otpauth://` URIs for QR code scanning with Google Authenticator, Authy, etc.:
|
|
95
95
|
|
|
96
96
|
```typescript
|
|
97
|
-
import { buildOtpauthUri, generateSecret } from 'totp-js';
|
|
97
|
+
import { buildOtpauthUri, generateSecret } from '@authcraft/totp-js';
|
|
98
98
|
|
|
99
99
|
const secret = generateSecret();
|
|
100
100
|
const uri = buildOtpauthUri(secret, 'user@example.com', 'MyApp');
|
|
@@ -106,7 +106,7 @@ const uri = buildOtpauthUri(secret, 'user@example.com', 'MyApp');
|
|
|
106
106
|
### Preset Configurations
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
|
-
import { TOTP, defaultConfig, sha256Config, highSecurityConfig } from 'totp-js';
|
|
109
|
+
import { TOTP, defaultConfig, sha256Config, highSecurityConfig } from '@authcraft/totp-js';
|
|
110
110
|
|
|
111
111
|
// Default: SHA1, 6 digits, 30s period, drift ±1
|
|
112
112
|
const standard = TOTP.create({ ...defaultConfig() });
|
|
@@ -121,7 +121,7 @@ const highSec = TOTP.create({ ...highSecurityConfig() });
|
|
|
121
121
|
### Custom Configuration
|
|
122
122
|
|
|
123
123
|
```typescript
|
|
124
|
-
import { TOTP, Algorithm } from 'totp-js';
|
|
124
|
+
import { TOTP, Algorithm } from '@authcraft/totp-js';
|
|
125
125
|
|
|
126
126
|
const totp = TOTP.create({
|
|
127
127
|
algorithm: Algorithm.SHA256,
|
|
@@ -157,7 +157,7 @@ console.log(result);
|
|
|
157
157
|
|
|
158
158
|
```typescript
|
|
159
159
|
import express from 'express';
|
|
160
|
-
import { TOTP, generateSecret, InMemoryReplayGuard, buildOtpauthUri } from 'totp-js';
|
|
160
|
+
import { TOTP, generateSecret, InMemoryReplayGuard, buildOtpauthUri } from '@authcraft/totp-js';
|
|
161
161
|
|
|
162
162
|
const app = express();
|
|
163
163
|
app.use(express.json());
|
|
@@ -186,7 +186,7 @@ app.post('/2fa/verify', (req, res) => {
|
|
|
186
186
|
```typescript
|
|
187
187
|
// app/api/2fa/verify/route.ts
|
|
188
188
|
import { NextResponse } from 'next/server';
|
|
189
|
-
import { TOTP, InMemoryReplayGuard } from 'totp-js';
|
|
189
|
+
import { TOTP, InMemoryReplayGuard } from '@authcraft/totp-js';
|
|
190
190
|
|
|
191
191
|
const guard = InMemoryReplayGuard.withDefaultRetention();
|
|
192
192
|
const totp = TOTP.create({ replayGuard: guard });
|
|
@@ -202,7 +202,7 @@ export async function POST(request: Request) {
|
|
|
202
202
|
|
|
203
203
|
```typescript
|
|
204
204
|
import { Injectable } from '@nestjs/common';
|
|
205
|
-
import { TOTP, generateSecret, InMemoryReplayGuard, buildOtpauthUri } from 'totp-js';
|
|
205
|
+
import { TOTP, generateSecret, InMemoryReplayGuard, buildOtpauthUri } from '@authcraft/totp-js';
|
|
206
206
|
|
|
207
207
|
@Injectable()
|
|
208
208
|
export class TwoFactorService {
|
|
@@ -230,7 +230,7 @@ export class TwoFactorService {
|
|
|
230
230
|
|
|
231
231
|
```typescript
|
|
232
232
|
import Fastify from 'fastify';
|
|
233
|
-
import { TOTP, generateSecret, InMemoryReplayGuard } from 'totp-js';
|
|
233
|
+
import { TOTP, generateSecret, InMemoryReplayGuard } from '@authcraft/totp-js';
|
|
234
234
|
|
|
235
235
|
const app = Fastify();
|
|
236
236
|
const guard = InMemoryReplayGuard.withDefaultRetention();
|
|
@@ -246,7 +246,7 @@ app.post('/2fa/verify', async (request, reply) => {
|
|
|
246
246
|
## Secret Generation
|
|
247
247
|
|
|
248
248
|
```typescript
|
|
249
|
-
import { generateSecret, generateRawSecret, isValidSecret, Algorithm } from 'totp-js';
|
|
249
|
+
import { generateSecret, generateRawSecret, isValidSecret, Algorithm } from '@authcraft/totp-js';
|
|
250
250
|
|
|
251
251
|
// Default (SHA1, 20 bytes)
|
|
252
252
|
const secret = generateSecret();
|
|
@@ -316,7 +316,7 @@ npm test
|
|
|
316
316
|
## Links
|
|
317
317
|
|
|
318
318
|
- [Documentation](https://pratiyush.github.io/totp-js/) — GitHub Pages with interactive demo
|
|
319
|
-
- [npm](https://www.npmjs.com/package/totp-js) — `npm install totp-js`
|
|
319
|
+
- [npm](https://www.npmjs.com/package/@authcraft/totp-js) — `npm install @authcraft/totp-js`
|
|
320
320
|
- [GitHub](https://github.com/Pratiyush/totp-js) — Source code, issues, PRs
|
|
321
321
|
- [totp-impl](https://github.com/Pratiyush/totp-impl) — Java counterpart ([Maven Central](https://central.sonatype.com/artifact/io.github.pratiyush/totp-lib))
|
|
322
322
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authcraft/totp-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Security-hardened TOTP/2FA library for JavaScript and TypeScript. RFC 6238 compliant with replay protection, constant-time verification, and zero runtime dependencies.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|