@zyphe-sdk/core 0.1.15 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # Zyphe SDK – Core
2
2
 
3
3
  > **⚠️ This package is now [ESM-only](https://nodejs.org/api/esm.html).**
4
- >
4
+ >
5
5
  > - You must use `import` syntax, not `require()`.
6
6
  > - Node.js v16.17+ or v18+ is recommended.
7
7
  > - CommonJS (`require()`) is **not supported**.
@@ -20,7 +20,10 @@ pnpm install @zyphe-sdk/core
20
20
 
21
21
  ```ts
22
22
  // Correct: ESM import
23
- import { createVerificationSession, verifyWebhookSignature } from "@zyphe-sdk/core";
23
+ import {
24
+ createVerificationSession,
25
+ verifyWebhookSignature,
26
+ } from "@zyphe-sdk/core";
24
27
 
25
28
  // ❌ Not supported:
26
29
  // const sdk = require("@zyphe-sdk/core");
@@ -43,7 +46,11 @@ const secretHex = "<your-hex-encoded-secret>";
43
46
  const rawBodyString = "..."; // The raw request body as a string
44
47
  const signatureHeader = "t=1234567890,v0=abcdef..."; // The signature header from the webhook
45
48
 
46
- const isValid = await verifyWebhookSignature(secretHex, rawBodyString, signatureHeader);
49
+ const isValid = await verifyWebhookSignature(
50
+ secretHex,
51
+ rawBodyString,
52
+ signatureHeader,
53
+ );
47
54
  if (isValid) {
48
55
  // Signature is valid
49
56
  } else {
@@ -57,6 +64,7 @@ if (isValid) {
57
64
  - Returns: A Promise that resolves to `true` if the signature is valid, or `false` otherwise.
58
65
 
59
66
  #### Advanced Utilities
67
+
60
68
  - `parseSignatureHeader(signatureHeader)` – Parse the signature header into timestamp and signature.
61
69
  - `hexToBytes(hex)` / `bufferToHex(buffer)` – Convert between hex and bytes.
62
70
  - `timingSafeEqual(a, b)` – Constant-time string comparison.
@@ -69,16 +77,18 @@ if (isValid) {
69
77
  You can programmatically create verification sessions and construct user-facing URLs for onboarding flows.
70
78
 
71
79
  ### Create a Verification Session
80
+
72
81
  ```ts
73
82
  import { createVerificationSession } from "@zyphe-sdk/core";
74
83
 
75
84
  const response = await createVerificationSession(
76
85
  {
77
86
  email: "user@example.com", // required
78
- flowId: "<flowId>", // required
79
- flowStepId: "<flowStepId>",// required
80
- isSandbox: false, // required
81
- customData: { // optional
87
+ flowId: "<flowId>", // required
88
+ flowStepId: "<flowStepId>", // required
89
+ isSandbox: false, // required
90
+ customData: {
91
+ // optional
82
92
  walletAddress: "0x123...",
83
93
  // ...any extra data you want to pass
84
94
  },
@@ -87,16 +97,18 @@ const response = await createVerificationSession(
87
97
  apiKey: "<your-api-key>",
88
98
  environment: "staging", // or "production", "local"
89
99
  handoffBaseUrl: "https://your-app.com", // optional
90
- primaryColor: "#000000", // optional
91
- secondaryColor: "#ffffff", // optional
92
- isFullscreen: true, // optional
93
- }
100
+ primaryColor: "#000000", // optional
101
+ secondaryColor: "#ffffff", // optional
102
+ isFullscreen: true, // optional
103
+ },
94
104
  );
95
105
  ```
106
+
96
107
  - `customData` (optional): Pass any extra data you want to associate with the verification session. This will be available in the webhook payload and session data.
97
108
  - The function returns a Promise resolving to the API response. Handle errors as needed (e.g., try/catch or checking for error fields).
98
109
 
99
110
  ### Construct a Verification Session URL
111
+
100
112
  ```ts
101
113
  import { constructVerificationSessionUrl } from "@zyphe-sdk/core";
102
114
 
@@ -114,23 +126,27 @@ const url = constructVerificationSessionUrl({
114
126
  apiKey: "<your-api-key>",
115
127
  environment: "staging",
116
128
  handoffBaseUrl: "https://your-app.com", // optional
117
- primaryColor: "#000000", // optional
118
- secondaryColor: "#ffffff", // optional
119
- isFullscreen: true, // optional
129
+ primaryColor: "#000000", // optional
130
+ secondaryColor: "#ffffff", // optional
131
+ isFullscreen: true, // optional
120
132
  },
121
133
  });
122
134
  ```
135
+
123
136
  - The constructed URL includes all relevant parameters and can be used to embed or redirect users to the verification flow.
124
137
  - Optional fields (like `handoffBaseUrl`, `primaryColor`, etc.) will be appended as query parameters if provided.
125
138
 
126
139
  #### Types
140
+
127
141
  - `InitializeZypheFlowParams`: Parameters for initializing a verification flow (see [types.ts](./src/types.ts)).
128
142
  - `SDKOptions`: Configuration for the SDK (see [types.ts](./src/types.ts)).
129
143
  - `SdkCreateVerificationRequestResponse`: API response type for session creation.
130
144
 
131
145
  #### Error Handling
146
+
132
147
  - If session creation fails, the function may throw or return an error object depending on usage context. Always check for errors and handle them appropriately.
133
148
  - Example:
149
+
134
150
  ```ts
135
151
  try {
136
152
  const response = await createVerificationSession(...);
@@ -156,7 +172,9 @@ try {
156
172
  ---
157
173
 
158
174
  ## Resources
175
+
159
176
  - See the dedicated middleware packages for Express, Fastify, Hono, and NestJS for webhook signature verification in those frameworks.
160
177
 
161
178
  ---
162
- Made with ❤️ by Zyphe Inc
179
+
180
+ Made with ❤️ by Zyphe Inc