@korala/auth 1.0.0 → 1.0.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 +71 -0
- package/package.json +4 -7
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @korala/auth
|
|
2
|
+
|
|
3
|
+
HMAC authentication utilities for the [Korala](https://korala.ai) document signing API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @korala/auth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Sign API requests
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { signRequest } from '@korala/auth';
|
|
17
|
+
|
|
18
|
+
const { signature, timestamp } = signRequest({
|
|
19
|
+
method: 'POST',
|
|
20
|
+
path: '/api/v1/documents',
|
|
21
|
+
body: JSON.stringify({ name: 'Contract' }),
|
|
22
|
+
secret: 'your-api-secret',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Use in request headers
|
|
26
|
+
fetch('https://api.korala.ai/api/v1/documents', {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: {
|
|
29
|
+
'X-API-Key': 'your-api-key-id',
|
|
30
|
+
'X-Timestamp': String(timestamp),
|
|
31
|
+
'X-Signature': signature,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({ name: 'Contract' }),
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Verify webhook signatures
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { verifyWebhookSignature } from '@korala/auth';
|
|
42
|
+
|
|
43
|
+
const isValid = verifyWebhookSignature({
|
|
44
|
+
payload: rawBody,
|
|
45
|
+
signature: headers['x-signature'],
|
|
46
|
+
timestamp: headers['x-timestamp'],
|
|
47
|
+
secret: webhookSecret,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> **Note:** Most users should use `@korala/api-client` which handles authentication automatically. This package is for advanced use cases or custom HTTP clients.
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
| Function | Description |
|
|
56
|
+
|----------|-------------|
|
|
57
|
+
| `signRequest(opts)` | Generate HMAC signature + timestamp for an API request |
|
|
58
|
+
| `verifySignature(opts)` | Verify an incoming API request signature |
|
|
59
|
+
| `signWebhookPayload(payload, secret)` | Sign a webhook payload |
|
|
60
|
+
| `verifyWebhookSignature(opts)` | Verify a webhook delivery signature |
|
|
61
|
+
| `computeSignature(message, secret)` | Low-level HMAC-SHA256 computation |
|
|
62
|
+
| `getTimestamp()` | Get current Unix timestamp in seconds |
|
|
63
|
+
| `isTimestampValid(timestamp, maxAge?)` | Check if a timestamp is within the allowed window |
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
Full documentation at [docs.korala.ai](https://docs.korala.ai).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@korala/auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "HMAC authentication utilities for the Korala document signing API",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/korala-ai/korala.git",
|
|
9
|
-
"directory": "packages/auth"
|
|
10
|
-
},
|
|
6
|
+
"homepage": "https://docs.korala.ai",
|
|
11
7
|
"main": "./dist/index.js",
|
|
12
8
|
"types": "./dist/index.d.ts",
|
|
13
9
|
"exports": {
|
|
@@ -30,7 +26,8 @@
|
|
|
30
26
|
}
|
|
31
27
|
},
|
|
32
28
|
"files": [
|
|
33
|
-
"dist"
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
34
31
|
],
|
|
35
32
|
"publishConfig": {
|
|
36
33
|
"access": "public"
|