@zyphe-sdk/core 0.1.5 → 0.1.7

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.
@@ -0,0 +1,45 @@
1
+ # Integrate with ExpressJs
2
+
3
+ ```typescript
4
+ import express from "express";
5
+ import { expressWebhookSignatureVerifierMiddleware } from "@zyphe-sdk/core/webhook/middlewares/express";
6
+ import dotenv from "dotenv";
7
+
8
+ dotenv.config();
9
+ const app = express();
10
+ const port = 3001;
11
+ const secretHex = process.env.WEBHOOK_SECRET ?? "";
12
+
13
+ // Use the webhook signature verification middleware
14
+ app.post(
15
+ "/webhook",
16
+ express.raw({ type: "application/json" }), // Make sure you extract the raw body that is required for proper signature validation
17
+ expressWebhookSignatureVerifierMiddleware({
18
+ secretHex,
19
+ signatureHeader: "x-signature",
20
+ }),
21
+ (req, res) => {
22
+ // At this point, the webhook signature has been verified
23
+ // and the request body is available as req.body (parsed JSON)
24
+ // and req.rawBody (raw string) if exposeRawBody is true (default)
25
+
26
+ console.log("Webhook received with a valid signature");
27
+
28
+ res.json({
29
+ success: true,
30
+ message: "Webhook processed successfully",
31
+ receivedData: req.body,
32
+ });
33
+ }
34
+ );
35
+
36
+ // Health check endpoint
37
+ app.get("/health", (req, res) => {
38
+ res.json({ status: "ok", service: "express-webhook-example" });
39
+ });
40
+
41
+ app.listen(port, () => {
42
+ console.log(`Express server is running on http://localhost:${port}`);
43
+ console.log(`Send POST requests to http://localhost:${port}/webhook`);
44
+ console.log(`Health check available at http://localhost:${port}/health`);
45
+ });
@@ -0,0 +1,85 @@
1
+ # Integrate with FastifyJs
2
+
3
+ ```typescript
4
+ import Fastify from "fastify";
5
+ import fastifyWebhookSignatureVerifierPlugin from "@zyphe-sdk/core/webhook/middlewares/fastify";
6
+ import dotenv from "dotenv";
7
+
8
+ dotenv.config();
9
+ const secretHex = process.env.WEBHOOK_SECRET ?? "";
10
+ console.log("Starting with secret:", secretHex);
11
+
12
+ // Extend FastifyRequest interface to include rawBody
13
+ declare module "fastify" {
14
+ interface FastifyRequest {
15
+ rawBody?: string;
16
+ }
17
+ }
18
+
19
+ const fastify = Fastify({
20
+ logger: true,
21
+ });
22
+
23
+ // Register the webhook signature verification plugin
24
+ await fastify.register(fastifyWebhookSignatureVerifierPlugin, {
25
+ secretHex,
26
+ signatureHeader: "x-signature",
27
+ });
28
+
29
+ // Webhook endpoint
30
+ fastify.post("/webhook", async (request, reply) => {
31
+ // At this point, the webhook signature has been verified
32
+ // and the request body is available as request.body (parsed JSON)
33
+ // and request.rawBody (raw string) if exposeRawBody is true (default)
34
+
35
+ fastify.log.info("Webhook received:", request.body);
36
+ fastify.log.info("Raw body:", request.rawBody);
37
+
38
+ return {
39
+ success: true,
40
+ message: "Webhook processed successfully",
41
+ receivedData: request.body,
42
+ };
43
+ });
44
+
45
+ // Health check endpoint
46
+ fastify.get("/health", async (request, reply) => {
47
+ return { status: "ok", service: "fastify-webhook-example" };
48
+ });
49
+
50
+ // Start the server
51
+ try {
52
+ await fastify.listen({ port: 3001, host: "0.0.0.0" });
53
+ console.log("Fastify server is running on http://localhost:3000");
54
+ console.log("Send POST requests to http://localhost:3000/webhook");
55
+ console.log("Health check available at http://localhost:3000/health");
56
+ } catch (err) {
57
+ fastify.log.error(err);
58
+ process.exit(1);
59
+ }
60
+ ```
61
+
62
+ ## Features
63
+
64
+ - Automatic webhook signature verification
65
+ - Raw body access for request processing
66
+ - Customizable unauthorized handler
67
+ - Support for route-specific middleware application
68
+ - TypeScript support out of the box
69
+
70
+ ## Configuration Options
71
+
72
+ The webhook verifier plugin accepts the following options:
73
+
74
+ - `secretHex` (required): The hex-encoded secret key used to verify the signature
75
+ - `signatureHeader` (optional): The name of the header containing the signature (defaults to "x-signature")
76
+ - `exposeRawBody` (optional): Whether to make the raw body available on request.rawBody (defaults to true)
77
+ - `onUnauthorized` (optional): Custom function to handle unauthorized requests
78
+
79
+ ## Security Notes
80
+
81
+ - Always use a strong, randomly generated secret key
82
+ - Keep your secret key secure and never expose it in client-side code
83
+ - The middleware uses constant-time comparison to prevent timing attacks
84
+ - The raw body is preserved for signature verification before any parsing occurs
85
+
package/docs/hono.md ADDED
@@ -0,0 +1,32 @@
1
+ # Integrate with Hono
2
+
3
+ ```typescript
4
+ import { serve } from "@hono/node-server";
5
+ import { Hono } from "hono";
6
+ import { honoWebhookSignatureVerifierMiddleware } from "@zyphe-sdk/core/webhook/middlewares/hono";
7
+ import dotenv from "dotenv";
8
+
9
+ dotenv.config();
10
+ const secretHex = process.env.WEBHOOK_SECRET ?? "";
11
+ console.log("Starting with secret:", secretHex);
12
+
13
+ const app = new Hono();
14
+
15
+ app.post(
16
+ "/webhook",
17
+ honoWebhookSignatureVerifierMiddleware({
18
+ secretHex,
19
+ signatureHeader: "x-signature",
20
+ }),
21
+ async (c) => c.text("Hello Hono!")
22
+ );
23
+
24
+ serve(
25
+ {
26
+ fetch: app.fetch,
27
+ port: 3001,
28
+ },
29
+ (info) => {
30
+ console.log(`Server is running on http://localhost:${info.port}`);
31
+ }
32
+ );
package/package.json CHANGED
@@ -1,53 +1,32 @@
1
1
  {
2
2
  "name": "@zyphe-sdk/core",
3
+ "version": "0.1.7",
3
4
  "description": "Simplifies interaction with the Zyphe platform for creating and managing digital identities and digital onboarding flows with ease",
4
- "version": "0.1.5",
5
+ "author": "Zyphe",
6
+ "license": "MIT",
5
7
  "type": "module",
8
+ "sideEffects": false,
9
+ "main": "dist/index.js",
6
10
  "exports": {
7
11
  ".": {
8
12
  "import": "./dist/index.js",
9
13
  "require": "./dist/index.cjs"
10
14
  },
11
- "./*": {
12
- "import": "./dist/*.js",
13
- "require": "./dist/*.cjs"
14
- },
15
- "./webhook/*": {
16
- "import": "./dist/webhook/*.js",
17
- "require": "./dist/webhook/*.cjs"
18
- },
19
- "./webhook/middlewares/*": {
20
- "import": "./dist/webhook/middlewares/*.js",
21
- "require": "./dist/webhook/middlewares/*.cjs"
22
- }
23
- },
24
- "typesVersions": {
25
- "*": {
26
- "*": [
27
- "dist/*",
28
- "dist/index.d.ts"
29
- ]
15
+ "./openapi": {
16
+ "types": "./dist/openapi.d.ts",
17
+ "default": "./dist/openapi.json"
30
18
  }
31
19
  },
32
- "main": "./dist/index.cjs",
33
- "types": "./dist/index.d.ts",
34
- "files": [
35
- "dist"
36
- ],
37
20
  "scripts": {
38
- "build": "tsup",
39
21
  "dev": "tsup --watch",
40
- "check": "biome check --write",
41
- "format": "biome format --write",
42
- "test": "vitest run"
43
- },
44
- "devDependencies": {
45
- "@changesets/cli": "^2.29.5",
46
- "@types/node": "^24.0.4",
47
- "typescript": "^5.8.3"
48
- },
49
- "engines": {
50
- "node": ">=18"
22
+ "build": "tsup",
23
+ "\n============== Gen ===============": "",
24
+ "gen": "pnpm run '/^gen:.*/'",
25
+ "gen:openapi": "tsx scripts/generate-openapi.ts",
26
+ "\n=========== Lint/Test ============": "",
27
+ "check-exports": "attw --profile node16 --pack ."
51
28
  },
52
- "license": "MIT"
29
+ "dependencies": {
30
+ "openapi-fetch": "^0.14.0"
31
+ }
53
32
  }