@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.
Files changed (2) hide show
  1. package/README.md +39 -15
  2. 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 backend module for verifying crypto signatures and managing nonces for wallet-based authentication.
3
+ A backend Micro-CMS module for verifying crypto wallet signatures (Solana and EVM) and issuing JWT tokens.
4
4
 
5
5
  ## Features
6
- - **Capabilities**: Provides `authentication` and `route-provider` abilities.
7
- - **Multichain**: Verifies Solana and EVM (Ethereum/Base) signatures.
8
- - **Provisioning**: Supports `onVerified` hooks for user database provisioning.
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
- ## Integration
16
+ ## Usage
11
17
 
12
- ### Initialization
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: 'your-secret',
21
- onVerified: async ({ address, network, req }) => {
22
- // Look up or create user in DB
23
- return { id: 1, email: `${address}@${network}.com` };
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
- await cms.start();
38
+ cms.start().then(() => {
39
+ bindExpressRoutes({ app, cms });
40
+ });
28
41
  ```
29
42
 
30
- ### Endpoints (Automatic)
31
- The module provides the following endpoints via the `route-provider` capability:
32
- - `POST /api/auth/crypto/nonce`: Generates a unique nonce for signing.
33
- - `POST /api/auth/crypto/verify`: Verifies the signature and returns a JWT.
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 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-cms/crypto-auth-node",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Node.js Crypto Authentication Module for Micro-CMS",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",