@otp-service/core 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +72 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @otp-service/core
2
+
3
+ Framework-agnostic OTP challenge lifecycle for Node.js: generate a challenge, deliver the OTP out-of-band, verify attempts with policy (TTL, length, max attempts), and persist state behind a small store interface.
4
+
5
+ **ESM only** · **Node.js ≥ 22** · **License:** MIT
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @otp-service/core
11
+ ```
12
+
13
+ ## When to use this package
14
+
15
+ Use `**@otp-service/core**` when you want full control over storage, delivery, signing, and OTP generation. Pair it with:
16
+
17
+ - `[@otp-service/redis-store](https://www.npmjs.com/package/@otp-service/redis-store)` for Redis persistence
18
+ - `[@otp-service/provider-email-resend](https://www.npmjs.com/package/@otp-service/provider-email-resend)` or `[@otp-service/provider-sms-twilio](https://www.npmjs.com/package/@otp-service/provider-sms-twilio)` for delivery
19
+ - `[@otp-service/express](https://www.npmjs.com/package/@otp-service/express)`, `[@otp-service/fastify](https://www.npmjs.com/package/@otp-service/fastify)`, or `[@otp-service/nest](https://www.npmjs.com/package/@otp-service/nest)` for HTTP routes
20
+
21
+ For a pre-wired Redis + provider path, see `[@otp-service/starter](https://www.npmjs.com/package/@otp-service/starter)`.
22
+
23
+ ## Minimal usage
24
+
25
+ You must supply a `**ChallengeStore**`, `**OtpDelivery**`, `**OtpSigner**`, and `**OtpPolicy**`. The service exposes `**generateChallenge**` and `**verifyChallenge**`.
26
+
27
+ ```ts
28
+ import { createOtpService, hmacOtpSigner } from "@otp-service/core";
29
+
30
+ const otpService = createOtpService({
31
+ delivery: myDelivery,
32
+ otpGenerator: (length) => {
33
+ /* return numeric string of length */
34
+ },
35
+ policy: {
36
+ maxVerifyAttempts: 3,
37
+ otpLength: 6,
38
+ ttlSeconds: 600
39
+ },
40
+ signer: hmacOtpSigner({ secret: process.env.OTP_SECRET! }),
41
+ store: myStore
42
+ });
43
+
44
+ await otpService.generateChallenge({
45
+ channel: "email",
46
+ purpose: "LOGIN",
47
+ recipient: "user@example.com"
48
+ });
49
+ ```
50
+
51
+ ## Main exports
52
+
53
+
54
+ | Export | Role |
55
+ | ------------------------------------------------------- | ------------------------------------ |
56
+ | `createOtpService` | Build the headless OTP service |
57
+ | `hmacOtpSigner` | HMAC-based OTP hashing for storage |
58
+ | `OtpDeliveryError` | Typed delivery failure from adapters |
59
+ | Types: `ChallengeStore`, `OtpDelivery`, `OtpService`, … | Implement or consume contracts |
60
+
61
+
62
+ See **TypeScript definitions** in the published `dist/` for full shapes.
63
+
64
+ ## Documentation
65
+
66
+ - Monorepo overview: [github.com/Suraj-H/otp-service-package-v2](https://github.com/Suraj-H/otp-service-package-v2)
67
+ - Security notes: [docs/guides/security.md](https://github.com/Suraj-H/otp-service-package-v2/blob/main/docs/guides/security.md)
68
+ - Issues: [github.com/Suraj-H/otp-service-package-v2/issues](https://github.com/Suraj-H/otp-service-package-v2/issues)
69
+
70
+ ## Stability
71
+
72
+ **0.x** — APIs may evolve; pin versions in production until you are comfortable with upgrades.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otp-service/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "Framework-agnostic OTP domain logic for Node.js services.",
6
6
  "license": "MIT",
@@ -22,7 +22,8 @@
22
22
  }
23
23
  },
24
24
  "files": [
25
- "dist"
25
+ "dist",
26
+ "README.md"
26
27
  ],
27
28
  "engines": {
28
29
  "node": ">=22.0.0"