nskd-lbr 1.1.2 → 1.1.4
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 +18 -146
- package/package.json +23 -23
- package/src/nskd-lbr.js +18 -766
- package/src/nskd-lbr.min.js +2 -438
- package/src/login.svg +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# NoSkid Certificate Library
|
|
2
2
|
|
|
3
|
-
A modern JavaScript library for verifying NoSkid certificates
|
|
3
|
+
A modern JavaScript library for verifying NoSkid certificates.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
|
|
@@ -8,7 +8,6 @@ A modern JavaScript library for verifying NoSkid certificates and implementing c
|
|
|
8
8
|
- [Quick Start](#quick-start)
|
|
9
9
|
- [Constructor Options](#constructor-options)
|
|
10
10
|
- [Methods](#methods)
|
|
11
|
-
- [Login with NoSkid](#login-with-noskid)
|
|
12
11
|
- [Response Objects](#response-objects)
|
|
13
12
|
- [Examples](#examples)
|
|
14
13
|
- [Error Handling](#error-handling)
|
|
@@ -38,7 +37,7 @@ import NskdLbr from 'nskd-lbr';
|
|
|
38
37
|
|
|
39
38
|
```js
|
|
40
39
|
// Initialize the library
|
|
41
|
-
const noskid = new NskdLbr();
|
|
40
|
+
const noskid = new NskdLbr();
|
|
42
41
|
|
|
43
42
|
// Verify a certificate from file upload
|
|
44
43
|
const fileInput = document.getElementById('certificate-file');
|
|
@@ -65,13 +64,9 @@ const noskid = new NskdLbr({
|
|
|
65
64
|
debug: false, // Enable debug logging
|
|
66
65
|
timeout: 10000, // Request timeout (ms)
|
|
67
66
|
strictCheck: true, // Validate local vs API data
|
|
67
|
+
allowAchievements: true, // Allow achievement-boosted certificates
|
|
68
68
|
useLegacyAPI: false, // Use legacy API format
|
|
69
69
|
|
|
70
|
-
// Login feature options
|
|
71
|
-
loginEndpoint: '', // Login API endpoint
|
|
72
|
-
onLoginSuccess: null, // Success callback function
|
|
73
|
-
onLoginFail: null, // Failure callback function
|
|
74
|
-
|
|
75
70
|
// Logging
|
|
76
71
|
onLog: null // Custom logging function
|
|
77
72
|
});
|
|
@@ -85,10 +80,8 @@ const noskid = new NskdLbr({
|
|
|
85
80
|
| `debug` | `boolean` | `false` | Enable console debug messages |
|
|
86
81
|
| `timeout` | `number` | `10000` | API request timeout in milliseconds |
|
|
87
82
|
| `strictCheck` | `boolean` | `true` | Compare local certificate data with API response |
|
|
83
|
+
| `allowAchievements` | `boolean` | `true` | Allow certificates that used achievement boosts |
|
|
88
84
|
| `useLegacyAPI` | `boolean` | `false` | Use legacy API format (affects username/nickname field) |
|
|
89
|
-
| `loginEndpoint` | `string` | `''` | Login API endpoint (required for login feature) |
|
|
90
|
-
| `onLoginSuccess` | `function` | `null` | `(result, certData) => {}` - Called on successful login |
|
|
91
|
-
| `onLoginFail` | `function` | `null` | `(error, certData) => {}` - Called on failed login |
|
|
92
85
|
| `onLog` | `function` | `null` | `(message, level) => {}` - Custom logging function |
|
|
93
86
|
|
|
94
87
|
## Methods
|
|
@@ -97,7 +90,7 @@ const noskid = new NskdLbr({
|
|
|
97
90
|
|
|
98
91
|
#### `loadFromFile(file)`
|
|
99
92
|
|
|
100
|
-
Load and verify a certificate from a PNG file.
|
|
93
|
+
Load and verify a certificate from a PNG file.
|
|
101
94
|
|
|
102
95
|
**Parameters:**
|
|
103
96
|
- `file` (`File`) - PNG certificate file from file input
|
|
@@ -168,7 +161,7 @@ console.log(details);
|
|
|
168
161
|
|
|
169
162
|
#### `reset()`
|
|
170
163
|
|
|
171
|
-
Reset all certificate data
|
|
164
|
+
Reset all certificate data.
|
|
172
165
|
|
|
173
166
|
**Returns:** `void`
|
|
174
167
|
|
|
@@ -182,79 +175,6 @@ Log messages with different levels (when debug is enabled).
|
|
|
182
175
|
|
|
183
176
|
**Returns:** `void`
|
|
184
177
|
|
|
185
|
-
## Login with NoSkid
|
|
186
|
-
|
|
187
|
-
The library provides a complete login system with a responsive modal interface.
|
|
188
|
-
|
|
189
|
-
If you want a clean login button, please use this one:
|
|
190
|
-

|
|
191
|
-
|
|
192
|
-
### `showLoginModal()`
|
|
193
|
-
|
|
194
|
-
Display a login modal for certificate-based authentication.
|
|
195
|
-
|
|
196
|
-
**Requirements:**
|
|
197
|
-
- Browser environment only
|
|
198
|
-
- `loginEndpoint` must be configured
|
|
199
|
-
- Valid login API endpoint that accepts POST requests
|
|
200
|
-
|
|
201
|
-
**Returns:** `Promise<LoginResult>`
|
|
202
|
-
|
|
203
|
-
**Example:**
|
|
204
|
-
```js
|
|
205
|
-
const noskid = new NskdLbr({
|
|
206
|
-
loginEndpoint: 'https://your-api.com/login',
|
|
207
|
-
onLoginSuccess: (result, certData) => {
|
|
208
|
-
console.log('Welcome', certData.localUsername);
|
|
209
|
-
// Redirect user, update UI, etc.
|
|
210
|
-
},
|
|
211
|
-
onLoginFail: (error, certData) => {
|
|
212
|
-
console.error('Login failed:', error.message);
|
|
213
|
-
// Show error message, etc.
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// Show login modal
|
|
218
|
-
try {
|
|
219
|
-
const loginResult = await noskid.showLoginModal();
|
|
220
|
-
console.log('Login successful:', loginResult);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.log('Login cancelled:', error.message);
|
|
223
|
-
}
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### Login API Format
|
|
227
|
-
|
|
228
|
-
Your login endpoint should accept POST requests with this format:
|
|
229
|
-
|
|
230
|
-
**Request:**
|
|
231
|
-
```json
|
|
232
|
-
{
|
|
233
|
-
"certificate": {
|
|
234
|
-
"key": "a1b2c3d4e5f6789...",
|
|
235
|
-
"username": "john_doe",
|
|
236
|
-
"certificate_number": "12345",
|
|
237
|
-
"percentage": 95,
|
|
238
|
-
"country": "United States",
|
|
239
|
-
"countryCode": "US",
|
|
240
|
-
"creationDate": "2024-01-15 14:30:25"
|
|
241
|
-
},
|
|
242
|
-
"password": "user_password"
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
**Response:**
|
|
247
|
-
```json
|
|
248
|
-
{
|
|
249
|
-
"success": true,
|
|
250
|
-
"message": "Login successful",
|
|
251
|
-
"data": {
|
|
252
|
-
"token": "jwt_token_here",
|
|
253
|
-
"user": {...}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
178
|
## Response Objects
|
|
259
179
|
|
|
260
180
|
### VerificationResult
|
|
@@ -286,16 +206,6 @@ interface CertificateData {
|
|
|
286
206
|
}
|
|
287
207
|
```
|
|
288
208
|
|
|
289
|
-
### LoginResult
|
|
290
|
-
|
|
291
|
-
```js
|
|
292
|
-
interface LoginResult {
|
|
293
|
-
success: boolean; // Whether login was successful
|
|
294
|
-
data: CertificateData; // Certificate data
|
|
295
|
-
response: any; // API response from login endpoint
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
209
|
## Examples
|
|
300
210
|
|
|
301
211
|
### Basic Certificate Verification
|
|
@@ -330,45 +240,6 @@ try {
|
|
|
330
240
|
}
|
|
331
241
|
```
|
|
332
242
|
|
|
333
|
-
### Complete Login Implementation
|
|
334
|
-
|
|
335
|
-
```js
|
|
336
|
-
const noskid = new NskdLbr({
|
|
337
|
-
debug: true,
|
|
338
|
-
loginEndpoint: 'https://api.yoursite.com/auth/noskid',
|
|
339
|
-
onLoginSuccess: (result, certData) => {
|
|
340
|
-
// Store authentication token
|
|
341
|
-
localStorage.setItem('auth_token', result.response.token);
|
|
342
|
-
|
|
343
|
-
// Update UI
|
|
344
|
-
document.getElementById('login-btn').style.display = 'none';
|
|
345
|
-
document.getElementById('user-info').textContent =
|
|
346
|
-
`Welcome, ${certData.localUsername}!`;
|
|
347
|
-
|
|
348
|
-
// Redirect or update application state
|
|
349
|
-
window.location.href = '/dashboard';
|
|
350
|
-
},
|
|
351
|
-
onLoginFail: (error, certData) => {
|
|
352
|
-
// Show error message
|
|
353
|
-
alert(`Login failed: ${error.message}`);
|
|
354
|
-
|
|
355
|
-
// Log for debugging
|
|
356
|
-
console.error('Login error:', error);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// Add login button event
|
|
361
|
-
document.getElementById('noskid-login-btn').addEventListener('click', async () => {
|
|
362
|
-
try {
|
|
363
|
-
await noskid.showLoginModal();
|
|
364
|
-
} catch (error) {
|
|
365
|
-
if (error.message !== 'Login cancelled') {
|
|
366
|
-
console.error('Login error:', error);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
```
|
|
371
|
-
|
|
372
243
|
### Custom Configuration
|
|
373
244
|
|
|
374
245
|
```js
|
|
@@ -395,25 +266,25 @@ try {
|
|
|
395
266
|
const result = await noskid.loadFromFile(file);
|
|
396
267
|
|
|
397
268
|
if (result.valid) {
|
|
398
|
-
console.log('
|
|
269
|
+
console.log('Certificate is valid');
|
|
399
270
|
} else {
|
|
400
271
|
// Handle different failure reasons
|
|
401
272
|
if (result.strictCheck && result.message.includes('mismatch')) {
|
|
402
|
-
console.log('
|
|
273
|
+
console.log('Certificate data mismatch - try disabling strict check');
|
|
403
274
|
} else {
|
|
404
|
-
console.log('
|
|
275
|
+
console.log('Certificate verification failed:', result.message);
|
|
405
276
|
}
|
|
406
277
|
}
|
|
407
278
|
} catch (error) {
|
|
408
279
|
// Handle different error types
|
|
409
280
|
if (error.message.includes('timeout')) {
|
|
410
|
-
console.log('
|
|
281
|
+
console.log('Request timed out - server may be slow');
|
|
411
282
|
} else if (error.message.includes('PNG')) {
|
|
412
|
-
console.log('
|
|
283
|
+
console.log('Invalid file format - please upload a PNG certificate');
|
|
413
284
|
} else if (error.message.includes('verification key')) {
|
|
414
|
-
console.log('
|
|
285
|
+
console.log('Invalid verification key format');
|
|
415
286
|
} else {
|
|
416
|
-
console.log('
|
|
287
|
+
console.log('Unexpected error:', error.message);
|
|
417
288
|
}
|
|
418
289
|
}
|
|
419
290
|
```
|
|
@@ -424,15 +295,16 @@ The library provides detailed error messages for different failure scenarios:
|
|
|
424
295
|
|
|
425
296
|
### Common Errors
|
|
426
297
|
|
|
298
|
+
### 5. Common Errors table - add new row:
|
|
299
|
+
```markdown
|
|
427
300
|
| Error Type | Cause | Solution |
|
|
428
301
|
|------------|-------|----------|
|
|
429
302
|
| `"No file provided"` | File input is empty | Check file selection |
|
|
430
303
|
| `"File must be a PNG image"` | Wrong file format | Upload a PNG certificate |
|
|
431
304
|
| `"No valid verification key found"` | Certificate missing key | Check certificate validity |
|
|
305
|
+
| `"Certificate uses achievements boost"` | Achievement boost not allowed | Set `allowAchievements: true` or use non-boosted certificate |
|
|
432
306
|
| `"Request timeout"` | Network/server issues | Check connection, increase timeout |
|
|
433
307
|
| `"Data mismatch"` | Local vs API data differs | Disable `strictCheck` or verify certificate |
|
|
434
|
-
| `"Login endpoint is not configured"` | Missing login endpoint | Set `loginEndpoint` option |
|
|
435
|
-
| `"Login modal is only available in browser"` | Node.js environment | Use in browser only |
|
|
436
308
|
|
|
437
309
|
### Best Practices
|
|
438
310
|
|
|
@@ -455,7 +327,7 @@ if (noskid.isValidCertificate()) {
|
|
|
455
327
|
}
|
|
456
328
|
|
|
457
329
|
// Reset state when needed
|
|
458
|
-
noskid.reset(); // Clears all data
|
|
330
|
+
noskid.reset(); // Clears all data
|
|
459
331
|
```
|
|
460
332
|
|
|
461
333
|
## Browser Support
|
|
@@ -488,7 +360,7 @@ This library is licensed under the NSDv1.0 License. See the [LICENSE](LICENSE) f
|
|
|
488
360
|
---
|
|
489
361
|
|
|
490
362
|
**Need Help?**
|
|
491
|
-
-
|
|
363
|
+
- Issues: [GitHub Issues](https://github.com/dpipstudio/noskid.today/issues)
|
|
492
364
|
|
|
493
365
|
<a align="center" href="https://github.com/douxxtech" target="_blank">
|
|
494
366
|
<img src="https://madeby.douxx.tech"></img>
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "nskd-lbr",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A JavaScript library for working with NoSkid certificates.",
|
|
5
|
-
"main": "src/nskd-lbr.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"noskid",
|
|
15
|
-
"certificate"
|
|
16
|
-
],
|
|
17
|
-
"author": "Douxx",
|
|
18
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/
|
|
21
|
-
},
|
|
22
|
-
"homepage": "https://github.com/
|
|
23
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "nskd-lbr",
|
|
3
|
+
"version": "1.1.4",
|
|
4
|
+
"description": "A JavaScript library for working with NoSkid certificates.",
|
|
5
|
+
"main": "src/nskd-lbr.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/dpipstudio/noskid.today.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"noskid",
|
|
15
|
+
"certificate"
|
|
16
|
+
],
|
|
17
|
+
"author": "Douxx",
|
|
18
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dpipstudio/noskid.today/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/dpipstudio/noskid.today#readme"
|
|
23
|
+
}
|