@otplib/plugin-base32-scure 13.1.1 → 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 +13 -32
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,11 +20,8 @@ This plugin provides Base32 encoding and decoding using `@scure/base`, a cryptog
|
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
import { generateSecret, generate } from "otplib";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
const base32 = new ScureBase32Plugin();
|
|
27
|
-
const crypto = new NodeCryptoPlugin();
|
|
23
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
24
|
+
import { crypto } from "@otplib/plugin-crypto-node";
|
|
28
25
|
|
|
29
26
|
// Generate a secret
|
|
30
27
|
const secret = generateSecret({ crypto, base32 });
|
|
@@ -40,9 +37,7 @@ const token = await generate({
|
|
|
40
37
|
### Encoding and Decoding
|
|
41
38
|
|
|
42
39
|
```typescript
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
const base32 = new ScureBase32Plugin();
|
|
40
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
46
41
|
|
|
47
42
|
// Encode binary data to Base32
|
|
48
43
|
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
@@ -57,9 +52,7 @@ const decoded = base32.decode("AEBAGBAF");
|
|
|
57
52
|
### With Custom Options
|
|
58
53
|
|
|
59
54
|
```typescript
|
|
60
|
-
import {
|
|
61
|
-
|
|
62
|
-
const base32 = new ScureBase32Plugin();
|
|
55
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
63
56
|
|
|
64
57
|
// Encode without padding
|
|
65
58
|
const encoded = base32.encode(data, { padding: false });
|
|
@@ -96,11 +89,8 @@ Works in all environments:
|
|
|
96
89
|
|
|
97
90
|
```typescript
|
|
98
91
|
import { generateSecret, generate } from "otplib";
|
|
99
|
-
import {
|
|
100
|
-
import {
|
|
101
|
-
|
|
102
|
-
const base32 = new ScureBase32Plugin();
|
|
103
|
-
const crypto = new NodeCryptoPlugin();
|
|
92
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
93
|
+
import { crypto } from "@otplib/plugin-crypto-node";
|
|
104
94
|
|
|
105
95
|
const secret = generateSecret({ crypto, base32 });
|
|
106
96
|
console.log(secret); // Base32-encoded secret
|
|
@@ -113,11 +103,8 @@ console.log(token); // 6-digit token
|
|
|
113
103
|
|
|
114
104
|
```typescript
|
|
115
105
|
import { generateSecret, generate } from "otplib";
|
|
116
|
-
import {
|
|
117
|
-
import {
|
|
118
|
-
|
|
119
|
-
const base32 = new ScureBase32Plugin();
|
|
120
|
-
const crypto = new WebCryptoPlugin();
|
|
106
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
107
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
121
108
|
|
|
122
109
|
const secret = await generateSecret({ crypto, base32 });
|
|
123
110
|
const token = await generate({ secret, crypto, base32 });
|
|
@@ -126,11 +113,8 @@ const token = await generate({ secret, crypto, base32 });
|
|
|
126
113
|
### Manual Secret Generation
|
|
127
114
|
|
|
128
115
|
```typescript
|
|
129
|
-
import {
|
|
130
|
-
import {
|
|
131
|
-
|
|
132
|
-
const base32 = new ScureBase32Plugin();
|
|
133
|
-
const crypto = new NodeCryptoPlugin();
|
|
116
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
117
|
+
import { crypto } from "@otplib/plugin-crypto-node";
|
|
134
118
|
|
|
135
119
|
// Generate random secret
|
|
136
120
|
const secretBytes = crypto.randomBytes(20);
|
|
@@ -142,14 +126,11 @@ console.log(secret); // Base32 secret for TOTP
|
|
|
142
126
|
### Edge Runtime (Cloudflare Worker)
|
|
143
127
|
|
|
144
128
|
```typescript
|
|
145
|
-
import {
|
|
146
|
-
import {
|
|
129
|
+
import { base32 } from "@otplib/plugin-base32-scure";
|
|
130
|
+
import { crypto } from "@otplib/plugin-crypto-web";
|
|
147
131
|
|
|
148
132
|
export default {
|
|
149
133
|
async fetch(request) {
|
|
150
|
-
const base32 = new ScureBase32Plugin();
|
|
151
|
-
const crypto = new WebCryptoPlugin();
|
|
152
|
-
|
|
153
134
|
// Generate secret
|
|
154
135
|
const secretBytes = await crypto.randomBytes(20);
|
|
155
136
|
const secret = base32.encode(secretBytes, { padding: false });
|
|
@@ -181,7 +162,7 @@ function validateAndDecode(input: string): Uint8Array | null {
|
|
|
181
162
|
}
|
|
182
163
|
}
|
|
183
164
|
|
|
184
|
-
const valid = validateAndDecode("
|
|
165
|
+
const valid = validateAndDecode("GEZDGNBVGY3TQOJQGEZDGNBVGY");
|
|
185
166
|
const invalid = validateAndDecode("invalid@base32!");
|
|
186
167
|
```
|
|
187
168
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otplib/plugin-base32-scure",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.1",
|
|
4
4
|
"description": "Base32 plugin for otplib using @scure/base",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Gerald Yeo <support@yeojz.dev>",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@scure/base": "^2.0.0",
|
|
46
|
-
"@otplib/core": "13.
|
|
46
|
+
"@otplib/core": "13.2.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^25.0.
|
|
49
|
+
"@types/node": "^25.0.10",
|
|
50
50
|
"tsup": "^8.5.1",
|
|
51
51
|
"typescript": "^5.9.3",
|
|
52
|
-
"vitest": "^4.0.
|
|
52
|
+
"vitest": "^4.0.18"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|