@otplib/plugin-crypto-web 13.2.0 → 13.2.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.
- package/README.md +6 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,11 +24,8 @@ This plugin provides HMAC and random byte generation using the Web Crypto API. I
|
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { generateSecret, generate } from "otplib";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
const crypto = new WebCryptoPlugin();
|
|
31
|
-
const base32 = new ScureBase32Plugin();
|
|
27
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
28
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
32
29
|
|
|
33
30
|
// Generate a secret
|
|
34
31
|
const secret = await generateSecret({ crypto, base32 });
|
|
@@ -45,11 +42,8 @@ const token = await generate({
|
|
|
45
42
|
|
|
46
43
|
```typescript
|
|
47
44
|
import { generate } from "otplib";
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
|
|
51
|
-
const crypto = new WebCryptoPlugin();
|
|
52
|
-
const base32 = new ScureBase32Plugin();
|
|
45
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
46
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
53
47
|
|
|
54
48
|
const token = await generate({
|
|
55
49
|
secret: "GEZDGNBVGY3TQOJQGEZDGNBVGY",
|
|
@@ -64,9 +58,7 @@ const token = await generate({
|
|
|
64
58
|
The Web Crypto API only supports asynchronous operations:
|
|
65
59
|
|
|
66
60
|
```typescript
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
const crypto = new WebCryptoPlugin();
|
|
61
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
70
62
|
|
|
71
63
|
// Async HMAC (required by Web Crypto API)
|
|
72
64
|
const digest = await crypto.hmac("SHA-1", key, data);
|
|
@@ -81,11 +73,10 @@ Should also work in runtimes which implements Web Crypto API:
|
|
|
81
73
|
|
|
82
74
|
```typescript
|
|
83
75
|
// Cloudflare Worker example
|
|
84
|
-
import {
|
|
76
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
85
77
|
|
|
86
78
|
export default {
|
|
87
79
|
async fetch(request) {
|
|
88
|
-
const crypto = new WebCryptoPlugin();
|
|
89
80
|
// Use crypto for OTP operations
|
|
90
81
|
},
|
|
91
82
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otplib/plugin-crypto-web",
|
|
3
|
-
"version": "13.2.
|
|
3
|
+
"version": "13.2.1",
|
|
4
4
|
"description": "Web Crypto API adapter for otplib",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Gerald Yeo <support@yeojz.dev>",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"LICENSE"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@otplib/core": "13.2.
|
|
47
|
+
"@otplib/core": "13.2.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"tsup": "^8.0.1",
|