@micro-cms/crypto-auth-node 1.0.32 → 1.0.33
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 +39 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,33 +1,57 @@
|
|
|
1
1
|
# @micro-cms/crypto-auth-node
|
|
2
2
|
|
|
3
|
-
A Micro-CMS
|
|
3
|
+
A backend Micro-CMS module for verifying crypto wallet signatures (Solana and EVM) and issuing JWT tokens.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
|
-
- **
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
6
|
+
- **Multi-Chain Verification**: Supports Solana (ed25519) and EVM (personal_sign) signature verification.
|
|
7
|
+
- **Nonce Management**: Generates and manages short-lived nonces to prevent replay attacks.
|
|
8
|
+
- **JWT Issuance**: Issues signed JWT tokens upon successful verification.
|
|
9
|
+
- **Composable**: Integrates seamlessly with `@micro-cms/core` and `@micro-cms/express-adapter`.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @micro-cms/crypto-auth-node
|
|
14
|
+
```
|
|
9
15
|
|
|
10
|
-
##
|
|
16
|
+
## Usage
|
|
11
17
|
|
|
12
|
-
###
|
|
18
|
+
### Integrating with Micro-CMS App
|
|
13
19
|
```typescript
|
|
14
20
|
import { createApp } from '@micro-cms/core';
|
|
21
|
+
import { bindExpressRoutes } from '@micro-cms/express-adapter';
|
|
15
22
|
import CryptoAuthModule from '@micro-cms/crypto-auth-node';
|
|
23
|
+
import express from 'express';
|
|
16
24
|
|
|
25
|
+
const app = express();
|
|
17
26
|
const cms = createApp();
|
|
18
27
|
|
|
19
28
|
cms.use(CryptoAuthModule, {
|
|
20
|
-
jwtSecret:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
jwtSecret: process.env.JWT_SECRET,
|
|
30
|
+
jwtExpiresIn: '24h',
|
|
31
|
+
// Optional hook to provision or find users in your DB
|
|
32
|
+
onVerified: async ({ address, network, token, req }) => {
|
|
33
|
+
// Return user object to be included in the response
|
|
34
|
+
return { id: 1, address, network };
|
|
24
35
|
}
|
|
25
36
|
});
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
cms.start().then(() => {
|
|
39
|
+
bindExpressRoutes({ app, cms });
|
|
40
|
+
});
|
|
28
41
|
```
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- `POST /api/auth/crypto/
|
|
43
|
+
## Provided Endpoints
|
|
44
|
+
When bound to an Express app, this module provides:
|
|
45
|
+
|
|
46
|
+
- `POST /api/auth/crypto/nonce`: Generates a nonce for a wallet address.
|
|
47
|
+
- Body: `{ "address": "..." }`
|
|
48
|
+
- `POST /api/auth/crypto/verify`: Verifies a signature and returns a token.
|
|
49
|
+
- Body: `{ "address": "...", "signature": "...", "network": "solana" | "evm" }`
|
|
50
|
+
|
|
51
|
+
## Configuration Options
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
| :--- | :--- | :--- | :--- |
|
|
55
|
+
| `jwtSecret` | `string` | 'fallback-secret' | Secret used to sign JWT tokens |
|
|
56
|
+
| `jwtExpiresIn` | `string` | '24h' | JWT expiration time (e.g., '1h', '7d') |
|
|
57
|
+
| `onVerified` | `Function` | - | Async hook called after successful verification |
|