@zyphe-sdk/core 0.2.2 → 0.3.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/dist/index.js CHANGED
@@ -48,73 +48,62 @@ var ZypheError = class _ZypheError extends Error {
48
48
  // src/complete-step.ts
49
49
  async function completeDvStep({ verificationSession, countryCode, images }, options) {
50
50
  const client = zypheApiClient(options);
51
- const response = await client.POST(
52
- "/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-document",
53
- {
54
- body: {
55
- countryCode,
56
- images: images.type === "SINGLE_SIDED_DOCUMENT" ? [
57
- {
58
- pageIndex: "front",
59
- source: "file",
60
- value: images.image
61
- }
62
- ] : [
63
- {
64
- pageIndex: "front",
65
- source: "file",
66
- value: images.frontImage
67
- },
68
- {
69
- pageIndex: "back",
70
- source: "file",
71
- value: images.backImage
72
- }
73
- ]
74
- },
75
- headers: {
76
- [API_KEY_HEADER]: options.apiKey
77
- },
78
- params: {
79
- path: {
80
- flow_id: verificationSession.verificationRequest.flowId,
81
- verification_request_id: verificationSession.verificationRequest.id
51
+ const response = await client.POST("/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-document", {
52
+ body: {
53
+ countryCode,
54
+ images: images.type === "SINGLE_SIDED_DOCUMENT" ? [
55
+ {
56
+ pageIndex: "front",
57
+ source: "file",
58
+ value: images.image
59
+ }
60
+ ] : [
61
+ {
62
+ pageIndex: "front",
63
+ source: "file",
64
+ value: images.frontImage
82
65
  },
83
- query: {
84
- sandbox: verificationSession.isSandbox
66
+ {
67
+ pageIndex: "back",
68
+ source: "file",
69
+ value: images.backImage
85
70
  }
71
+ ]
72
+ },
73
+ headers: {
74
+ [API_KEY_HEADER]: options.apiKey
75
+ },
76
+ params: {
77
+ path: {
78
+ flow_id: verificationSession.verificationRequest.flowId,
79
+ verification_request_id: verificationSession.verificationRequest.id
80
+ },
81
+ query: {
82
+ sandbox: verificationSession.isSandbox
86
83
  }
87
84
  }
88
- );
85
+ });
89
86
  if (response.error) {
90
87
  throw ZypheError.fromBaxeError(response.error);
91
88
  }
92
89
  return response.data;
93
90
  }
94
- async function completeLivenessStep({
95
- verificationSession,
96
- frontImage,
97
- movementImages = [],
98
- video
99
- }, options) {
91
+ async function completeLivenessStep({ verificationSession, frontImage, movementImages = [], video }, options) {
100
92
  const client = zypheApiClient(options);
101
- const challengeResponse = await client.GET(
102
- "/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/liveness-challenge",
103
- {
104
- headers: {
105
- [API_KEY_HEADER]: options.apiKey
93
+ const challengeResponse = await client.GET("/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/liveness-challenge", {
94
+ headers: {
95
+ [API_KEY_HEADER]: options.apiKey
96
+ },
97
+ params: {
98
+ path: {
99
+ flow_id: verificationSession.verificationRequest.flowId,
100
+ verification_request_id: verificationSession.verificationRequest.id
106
101
  },
107
- params: {
108
- path: {
109
- flow_id: verificationSession.verificationRequest.flowId,
110
- verification_request_id: verificationSession.verificationRequest.id
111
- },
112
- query: {
113
- sandbox: verificationSession.isSandbox
114
- }
102
+ query: {
103
+ sandbox: verificationSession.isSandbox
115
104
  }
116
105
  }
117
- );
106
+ });
118
107
  if (challengeResponse.error) {
119
108
  throw ZypheError.fromBaxeError(challengeResponse.error);
120
109
  }
@@ -124,18 +113,13 @@ async function completeLivenessStep({
124
113
  throw new ZypheError("Missing liveness video for active challenge");
125
114
  }
126
115
  if (movementImages.length !== challenge.movementImages.length) {
127
- throw new ZypheError(
128
- "Movement image count does not match active challenge"
129
- );
116
+ throw new ZypheError("Movement image count does not match active challenge");
130
117
  }
131
118
  }
132
- const calibrationUploadResponse = await fetch(
133
- challenge.calibrationImage.presignedUrl,
134
- {
135
- method: "PUT",
136
- body: frontImage
137
- }
138
- );
119
+ const calibrationUploadResponse = await fetch(challenge.calibrationImage.presignedUrl, {
120
+ method: "PUT",
121
+ body: frontImage
122
+ });
139
123
  if (!calibrationUploadResponse.ok) {
140
124
  throw new ZypheError("Failed to upload front image");
141
125
  }
@@ -157,27 +141,24 @@ async function completeLivenessStep({
157
141
  }
158
142
  }
159
143
  }
160
- const processDvLivenessResponse = await client.POST(
161
- "/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-liveness",
162
- {
163
- headers: {
164
- [API_KEY_HEADER]: options.apiKey
165
- },
166
- body: {
167
- challengeId: challenge.id,
168
- movementImagesQuantity: movementImages.length
144
+ const processDvLivenessResponse = await client.POST("/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-liveness", {
145
+ headers: {
146
+ [API_KEY_HEADER]: options.apiKey
147
+ },
148
+ body: {
149
+ challengeId: challenge.id,
150
+ movementImagesQuantity: movementImages.length
151
+ },
152
+ params: {
153
+ path: {
154
+ flow_id: verificationSession.verificationRequest.flowId,
155
+ verification_request_id: verificationSession.verificationRequest.id
169
156
  },
170
- params: {
171
- path: {
172
- flow_id: verificationSession.verificationRequest.flowId,
173
- verification_request_id: verificationSession.verificationRequest.id
174
- },
175
- query: {
176
- sandbox: verificationSession.isSandbox
177
- }
157
+ query: {
158
+ sandbox: verificationSession.isSandbox
178
159
  }
179
160
  }
180
- );
161
+ });
181
162
  if (processDvLivenessResponse.error) {
182
163
  throw ZypheError.fromBaxeError(processDvLivenessResponse.error);
183
164
  }
@@ -185,24 +166,21 @@ async function completeLivenessStep({
185
166
  }
186
167
  async function completeDocumentSelectionStep({ verificationSession, payload }, options) {
187
168
  const client = zypheApiClient(options);
188
- const processDocumentSelectionResponse = await client.POST(
189
- "/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-selection",
190
- {
191
- headers: {
192
- [API_KEY_HEADER]: options.apiKey
193
- },
194
- params: {
195
- path: {
196
- flow_id: verificationSession.verificationRequest.flowId,
197
- verification_request_id: verificationSession.verificationRequest.id
198
- },
199
- query: {
200
- sandbox: verificationSession.isSandbox
201
- }
169
+ const processDocumentSelectionResponse = await client.POST("/sdk/flow/{flow_id}/vr/{verification_request_id}/dv/process-dv-selection", {
170
+ headers: {
171
+ [API_KEY_HEADER]: options.apiKey
172
+ },
173
+ params: {
174
+ path: {
175
+ flow_id: verificationSession.verificationRequest.flowId,
176
+ verification_request_id: verificationSession.verificationRequest.id
202
177
  },
203
- body: payload
204
- }
205
- );
178
+ query: {
179
+ sandbox: verificationSession.isSandbox
180
+ }
181
+ },
182
+ body: payload
183
+ });
206
184
  if (processDocumentSelectionResponse.error) {
207
185
  throw ZypheError.fromBaxeError(processDocumentSelectionResponse.error);
208
186
  }
@@ -216,11 +194,7 @@ var ApiKeyTypes = {
216
194
  };
217
195
  function ensureApiKeyType(apiKey, types) {
218
196
  if (!types.some((type) => apiKey.startsWith(ApiKeyTypes[type]))) {
219
- throw new Error(
220
- `Invalid API key. This function is only available for ${types.join(
221
- ", "
222
- )} keys`
223
- );
197
+ throw new Error(`Invalid API key. This function is only available for ${types.join(", ")} keys`);
224
198
  }
225
199
  }
226
200
 
@@ -1320,55 +1294,43 @@ function readVarint(buffer) {
1320
1294
  }
1321
1295
 
1322
1296
  // src/flow-results.ts
1323
- async function listFlowResults({
1324
- organizationId,
1325
- flowSlug,
1326
- isSandbox,
1327
- pagination,
1328
- locale
1329
- }, opts) {
1297
+ async function listFlowResults({ organizationId, flowSlug, isSandbox, pagination, locale }, opts) {
1330
1298
  ensureApiKeyType(opts.apiKey, ["SECRET"]);
1331
1299
  const client = zypheApiClient(opts);
1332
- return client.GET(
1333
- "/sdk/organizations/{organization_id}/flow-results/flow/{flow_slug}/list",
1334
- {
1335
- params: {
1336
- path: {
1337
- organization_id: organizationId,
1338
- flow_slug: flowSlug
1339
- },
1340
- query: {
1341
- pagination,
1342
- sandbox: isSandbox,
1343
- locale
1344
- }
1300
+ return client.GET("/sdk/organizations/{organization_id}/flow-results/flow/{flow_slug}/list", {
1301
+ params: {
1302
+ path: {
1303
+ organization_id: organizationId,
1304
+ flow_slug: flowSlug
1345
1305
  },
1346
- headers: {
1347
- [API_KEY_HEADER]: opts.apiKey
1306
+ query: {
1307
+ pagination,
1308
+ sandbox: isSandbox,
1309
+ locale
1348
1310
  }
1311
+ },
1312
+ headers: {
1313
+ [API_KEY_HEADER]: opts.apiKey
1349
1314
  }
1350
- );
1315
+ });
1351
1316
  }
1352
1317
  async function getFlowResult({ organizationId, flowResultId, isSandbox }, opts) {
1353
1318
  ensureApiKeyType(opts.apiKey, ["SECRET"]);
1354
1319
  const client = zypheApiClient(opts);
1355
- const response = await client.GET(
1356
- "/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/details",
1357
- {
1358
- params: {
1359
- path: {
1360
- organization_id: organizationId,
1361
- flow_result_id: flowResultId
1362
- },
1363
- query: {
1364
- sandbox: isSandbox
1365
- }
1320
+ const response = await client.GET("/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/details", {
1321
+ params: {
1322
+ path: {
1323
+ organization_id: organizationId,
1324
+ flow_result_id: flowResultId
1366
1325
  },
1367
- headers: {
1368
- [API_KEY_HEADER]: opts.apiKey
1326
+ query: {
1327
+ sandbox: isSandbox
1369
1328
  }
1329
+ },
1330
+ headers: {
1331
+ [API_KEY_HEADER]: opts.apiKey
1370
1332
  }
1371
- );
1333
+ });
1372
1334
  const { data, ...rest } = response;
1373
1335
  return {
1374
1336
  ...rest,
@@ -1389,26 +1351,23 @@ async function getFlowResult({ organizationId, flowResultId, isSandbox }, opts)
1389
1351
  async function getDvResult({ organizationId, flowResultId, dvResultId, isSandbox }, opts) {
1390
1352
  ensureApiKeyType(opts.apiKey, ["SECRET"]);
1391
1353
  const client = zypheApiClient(opts);
1392
- const response = await client.GET(
1393
- "/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/dv/{dv_result_id}/details",
1394
- {
1395
- params: {
1396
- path: {
1397
- organization_id: organizationId,
1398
- flow_result_id: flowResultId,
1399
- dv_result_id: dvResultId
1400
- },
1401
- query: {
1402
- sandbox: isSandbox
1403
- }
1404
- },
1405
- headers: {
1406
- [API_KEY_HEADER]: opts.apiKey,
1407
- Accept: "application/x-protobuf"
1354
+ const response = await client.GET("/sdk/organizations/{organization_id}/flow-results/{flow_result_id}/dv/{dv_result_id}/details", {
1355
+ params: {
1356
+ path: {
1357
+ organization_id: organizationId,
1358
+ flow_result_id: flowResultId,
1359
+ dv_result_id: dvResultId
1408
1360
  },
1409
- parseAs: "arrayBuffer"
1410
- }
1411
- );
1361
+ query: {
1362
+ sandbox: isSandbox
1363
+ }
1364
+ },
1365
+ headers: {
1366
+ [API_KEY_HEADER]: opts.apiKey,
1367
+ Accept: "application/x-protobuf"
1368
+ },
1369
+ parseAs: "arrayBuffer"
1370
+ });
1412
1371
  const { data, ...rest } = response;
1413
1372
  return {
1414
1373
  ...rest,
@@ -1424,16 +1383,10 @@ var DocumentType = {
1424
1383
  };
1425
1384
 
1426
1385
  // src/verification-session.ts
1427
- function createVerificationSession({
1428
- email,
1429
- flowId,
1430
- flowStepId,
1431
- isSandbox,
1432
- customData
1433
- }, opts) {
1386
+ function createVerificationSession({ email, flowId, isSandbox, credentials, customData }, opts) {
1434
1387
  const client = zypheApiClient(opts);
1435
1388
  return client.POST("/sdk/flow/{flow_id}/vr/create", {
1436
- body: { email, flowStepId, customData },
1389
+ body: { email, customData, credentials },
1437
1390
  headers: {
1438
1391
  [API_KEY_HEADER]: opts.apiKey
1439
1392
  },
@@ -1456,13 +1409,16 @@ function constructVerificationSessionUrl({
1456
1409
  opts
1457
1410
  }) {
1458
1411
  const origin = getFlowUrlOrigin(opts.environment);
1459
- const { email, isSandbox, product } = flowParams;
1412
+ const { email, isSandbox } = flowParams;
1460
1413
  const { handoffBaseUrl, primaryColor, secondaryColor, isFullscreen } = opts;
1461
1414
  if (!verificationSession) {
1462
1415
  throw new Error("Failed to create verification session");
1463
1416
  }
1464
1417
  const zypheEmail = verificationSession.email || email;
1465
- let baseUrl = `${origin}${isSandbox ? "/sandbox" : ""}/flow/${verificationSession.flowSlug}/${product}/${verificationSession.flowStepSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheEmail=${encodeURIComponent(zypheEmail)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;
1418
+ let baseUrl = `${origin}${isSandbox ? "/sandbox" : ""}/flow/${verificationSession.flowSlug}?zypheVr=${encodeURIComponent(verificationSession.verificationRequest.id)}&zypheToken=${encodeURIComponent(verificationSession.zypheToken)}`;
1419
+ if (zypheEmail) {
1420
+ baseUrl += `&zypheEmail=${encodeURIComponent(zypheEmail)}`;
1421
+ }
1466
1422
  if (handoffBaseUrl) {
1467
1423
  baseUrl += `&zypheHandoffBaseUrl=${encodeURIComponent(handoffBaseUrl)}`;
1468
1424
  }
@@ -1482,6 +1438,8 @@ function constructVerificationSessionUrl({
1482
1438
  }
1483
1439
  function getNextStepDetails(flowParams, opts) {
1484
1440
  const client = zypheApiClient(opts);
1441
+ const wallet = flowParams.credential?.type === "WALLET" ? flowParams.credential : void 0;
1442
+ const externalId = flowParams.credential?.type === "EXTERNAL_ID" ? flowParams.credential.externalId : void 0;
1485
1443
  return client.GET("/sdk/flow/{flow_id}/vr/next-step", {
1486
1444
  headers: {
1487
1445
  [API_KEY_HEADER]: opts.apiKey
@@ -1492,7 +1450,11 @@ function getNextStepDetails(flowParams, opts) {
1492
1450
  },
1493
1451
  query: {
1494
1452
  sandbox: flowParams.isSandbox,
1495
- email: flowParams.email
1453
+ email: flowParams.email,
1454
+ address: wallet?.address,
1455
+ chain: wallet?.chain,
1456
+ externalId,
1457
+ credentialType: flowParams.credential?.type
1496
1458
  }
1497
1459
  }
1498
1460
  });
@@ -1511,7 +1473,9 @@ function parseSignatureHeader(signatureHeader) {
1511
1473
  return { timestamp, signatureHex };
1512
1474
  }
1513
1475
  function hexToBytes(hex) {
1514
- if (hex.length % 2 !== 0) throw new Error("Invalid hex string");
1476
+ if (hex.length % 2 !== 0) {
1477
+ throw new Error("Invalid hex string");
1478
+ }
1515
1479
  const bytes = new Uint8Array(hex.length / 2);
1516
1480
  for (let i = 0; i < hex.length; i += 2) {
1517
1481
  bytes[i / 2] = parseInt(hex.slice(i, i + 2), 16);
@@ -1522,7 +1486,9 @@ function bufferToHex(buffer) {
1522
1486
  return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
1523
1487
  }
1524
1488
  function timingSafeEqual(a, b) {
1525
- if (a.length !== b.length) return false;
1489
+ if (a.length !== b.length) {
1490
+ return false;
1491
+ }
1526
1492
  let result = 0;
1527
1493
  for (let i = 0; i < a.length; i++) {
1528
1494
  result |= a.charCodeAt(i) ^ b.charCodeAt(i);