auth-verify 1.9.0 → 1.11.0

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.
@@ -0,0 +1,102 @@
1
+ window.AuthVerify = class AuthVerify {
2
+ constructor(options = {}){
3
+ this.apiBase = options.apiBase || 'http://localhost:3000';
4
+ this.qrContainer = options.qrEl || null;
5
+ }
6
+
7
+ // Fetch QR code from backend and display
8
+ post(url){
9
+ this.fetchPostUrl = url;
10
+ return this;
11
+ }
12
+
13
+ get(url){
14
+ this.fetchGetUrl = url;
15
+ return this;
16
+ }
17
+
18
+ async qr() {
19
+ if (!this.qrContainer) return;
20
+ try {
21
+ const res = await fetch(`${this.apiBase}${this.fetchGetUrl}`);
22
+ const data = await res.json();
23
+ if (data.qr) {
24
+ this.qrContainer.src = data.qr;
25
+ } else {
26
+ this.showResponse('No QR received');
27
+ }
28
+ } catch (err) {
29
+ console.error(err);
30
+ this.showResponse('Error fetching QR');
31
+ }
32
+ }
33
+
34
+ showResponse(msg){
35
+ console.log("[AuthVerify]", msg);
36
+ }
37
+
38
+ async data(payload){
39
+ try {
40
+ const res = await fetch(`${this.apiBase}${this.fetchPostUrl}`, {
41
+ method: 'POST',
42
+ headers: { 'Content-Type': 'application/json' },
43
+ body: JSON.stringify(payload)
44
+ });
45
+
46
+ const data = await res.json();
47
+
48
+ // if backend returned jwt we store it but still return whole data
49
+ if (data.token) {
50
+ this.jwt = data.token;
51
+ }
52
+
53
+ return data;
54
+
55
+ } catch(err){
56
+ console.error(err);
57
+ return { error: true, message: err.message };
58
+ }
59
+ }
60
+
61
+ header(){
62
+ if(!this.jwt) return {};
63
+ return {
64
+ Authorization: `Bearer ${this.jwt}`
65
+ };
66
+ }
67
+
68
+ async verify(code){
69
+ return this.data({code});
70
+ }
71
+
72
+ // -----------------------------
73
+ // Helper: decode Base64URL to Uint8Array
74
+ // -----------------------------
75
+ base64urlToUint8Array(base64url) {
76
+ if (!base64url) throw new Error("Missing Base64URL data");
77
+ let base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
78
+ while (base64.length % 4) base64 += '=';
79
+ const str = atob(base64);
80
+ return new Uint8Array([...str].map(c => c.charCodeAt(0)));
81
+ }
82
+
83
+ async issue(publicKey){
84
+ publicKey.challenge = this.base64urlToUint8Array(publicKey.challenge);
85
+ publicKey.user.id = this.base64urlToUint8Array(publicKey.user.id);
86
+
87
+ const credential = await navigator.credentials.create({ publicKey });
88
+
89
+ const data = {
90
+ id: credential.id,
91
+ rawId: btoa(String.fromCharCode(...new Uint8Array(credential.rawId))),
92
+ type: credential.type,
93
+ response: {
94
+ clientDataJSON: btoa(String.fromCharCode(...new Uint8Array(credential.response.clientDataJSON))),
95
+ attestationObject: btoa(String.fromCharCode(...new Uint8Array(credential.response.attestationObject))),
96
+ },
97
+ };
98
+
99
+ return data;
100
+ }
101
+
102
+ }
package/index.js CHANGED
@@ -5,6 +5,7 @@ const OAuthManager = require("./src/oauth");
5
5
  const TOTPManager = require("./src/totp");
6
6
  const PasskeyManager = require("./src/passkey");
7
7
  const MagicLinkManager = require("./src/magiclink");
8
+ const CryptoManager = require("./src/crypto");
8
9
 
9
10
  class AuthVerify {
10
11
  constructor(options = {}) {
@@ -26,7 +27,10 @@ class AuthVerify {
26
27
  passExp = "2m",
27
28
  mlSecret = "ml_secret",
28
29
  mlExpiry = "5m",
29
- appUrl = "https://yourapp.com"
30
+ appUrl = "https://yourapp.com",
31
+ hashAlg = "pbkdf2",
32
+ iterations = 100000,
33
+ keyLen = 64
30
34
  } = options;
31
35
 
32
36
  // ✅ Ensure cookieName and secret always exist
@@ -54,7 +58,8 @@ class AuthVerify {
54
58
  this.senders = new Map();
55
59
 
56
60
  this.passkey = new PasskeyManager({rpName, storeTokens, saveBy, passExp});
57
- this.magic = new MagicLinkManager({mlSecret, mlExpiry, appUrl, storeTokens})
61
+ this.magic = new MagicLinkManager({mlSecret, mlExpiry, appUrl, storeTokens});
62
+ this.crypto = new CryptoManager({hashAlg, iterations, keyLen});
58
63
  }
59
64
 
60
65
  // --- Session helpers ---
package/package.json CHANGED
@@ -3,20 +3,24 @@
3
3
  "axios": "^1.12.2",
4
4
  "base64url": "^3.0.1",
5
5
  "cbor": "^10.0.11",
6
+ "cors": "^2.8.5",
6
7
  "crypto": "^1.0.1",
8
+ "express": "^5.1.0",
7
9
  "ioredis": "^5.8.1",
8
10
  "jsonwebtoken": "^9.0.2",
9
11
  "node-telegram-bot-api": "^0.66.0",
10
12
  "nodemailer": "^7.0.6",
13
+ "path": "^0.12.7",
11
14
  "qrcode": "^1.5.4",
12
15
  "uuid": "^9.0.1"
13
16
  },
14
17
  "name": "auth-verify",
15
- "version": "1.9.0",
18
+ "version": "1.11.0",
16
19
  "description": "A simple Node.js library for sending and verifying OTP via email, SMS and Telegram bot. And generating TOTP codes and QR codes. And handling JWT with Cookies. And also handling passwordless logins with passkeys/webauth. And handling magiclink passwordless logins",
17
20
  "main": "index.js",
18
21
  "scripts": {
19
- "test": "jest --runInBand"
22
+ "test": "jest --runInBand",
23
+ "start:api": "node rest-api/index.js"
20
24
  },
21
25
  "repository": {
22
26
  "type": "git",
@@ -49,7 +53,11 @@
49
53
  "webauthn",
50
54
  "passkey",
51
55
  "passwordless",
52
- "magiclink"
56
+ "magiclink",
57
+ "hash",
58
+ "password_hashing",
59
+ "api",
60
+ "rest-api"
53
61
  ],
54
62
  "author": "Jahongir Sobirov",
55
63
  "license": "MIT",