@p2pdotme/sdk 1.0.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.
Files changed (50) hide show
  1. package/README.md +155 -0
  2. package/dist/fraud-engine.cjs +598 -0
  3. package/dist/fraud-engine.cjs.map +1 -0
  4. package/dist/fraud-engine.d.cts +194 -0
  5. package/dist/fraud-engine.d.ts +194 -0
  6. package/dist/fraud-engine.mjs +549 -0
  7. package/dist/fraud-engine.mjs.map +1 -0
  8. package/dist/index.cjs +75 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +49 -0
  11. package/dist/index.d.ts +49 -0
  12. package/dist/index.mjs +46 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/order-routing.cjs +882 -0
  15. package/dist/order-routing.cjs.map +1 -0
  16. package/dist/order-routing.d.cts +68 -0
  17. package/dist/order-routing.d.ts +68 -0
  18. package/dist/order-routing.mjs +854 -0
  19. package/dist/order-routing.mjs.map +1 -0
  20. package/dist/payload.cjs +3164 -0
  21. package/dist/payload.cjs.map +1 -0
  22. package/dist/payload.d.cts +162 -0
  23. package/dist/payload.d.ts +162 -0
  24. package/dist/payload.mjs +3120 -0
  25. package/dist/payload.mjs.map +1 -0
  26. package/dist/profile.cjs +695 -0
  27. package/dist/profile.cjs.map +1 -0
  28. package/dist/profile.d.cts +133 -0
  29. package/dist/profile.d.ts +133 -0
  30. package/dist/profile.mjs +667 -0
  31. package/dist/profile.mjs.map +1 -0
  32. package/dist/qr-parsers.cjs +366 -0
  33. package/dist/qr-parsers.cjs.map +1 -0
  34. package/dist/qr-parsers.d.cts +41 -0
  35. package/dist/qr-parsers.d.ts +41 -0
  36. package/dist/qr-parsers.mjs +338 -0
  37. package/dist/qr-parsers.mjs.map +1 -0
  38. package/dist/react.cjs +4803 -0
  39. package/dist/react.cjs.map +1 -0
  40. package/dist/react.d.cts +511 -0
  41. package/dist/react.d.ts +511 -0
  42. package/dist/react.mjs +4759 -0
  43. package/dist/react.mjs.map +1 -0
  44. package/dist/zkkyc.cjs +868 -0
  45. package/dist/zkkyc.cjs.map +1 -0
  46. package/dist/zkkyc.d.cts +230 -0
  47. package/dist/zkkyc.d.ts +230 -0
  48. package/dist/zkkyc.mjs +824 -0
  49. package/dist/zkkyc.mjs.map +1 -0
  50. package/package.json +130 -0
package/dist/zkkyc.mjs ADDED
@@ -0,0 +1,824 @@
1
+ // src/contracts/reputation-manager/writes.ts
2
+ import { Result } from "neverthrow";
3
+ import { encodeFunctionData } from "viem";
4
+
5
+ // src/validation/errors.ts
6
+ var SdkError = class extends Error {
7
+ code;
8
+ cause;
9
+ context;
10
+ constructor(message, options) {
11
+ super(message);
12
+ this.name = "SdkError";
13
+ this.code = options.code;
14
+ this.cause = options.cause;
15
+ this.context = options.context;
16
+ }
17
+ };
18
+
19
+ // src/validation/schemas.ts
20
+ import { err, ok } from "neverthrow";
21
+ import { isAddress } from "viem";
22
+ import { z } from "zod";
23
+ var ZodAddressSchema = z.string().refine((s) => isAddress(s), { message: "Invalid Ethereum address" });
24
+ var ZodCurrencySchema = z.enum([
25
+ "IDR",
26
+ "INR",
27
+ "BRL",
28
+ "ARS",
29
+ "MEX",
30
+ "VEN",
31
+ "EUR",
32
+ "NGN",
33
+ "USD"
34
+ ]);
35
+ function validate(schema, data, toError) {
36
+ const result = schema.safeParse(data);
37
+ if (result.success) {
38
+ return ok(result.data);
39
+ }
40
+ return err(toError(z.prettifyError(result.error), result.error, data));
41
+ }
42
+
43
+ // src/zkkyc/errors.ts
44
+ var ZkkycError = class extends SdkError {
45
+ constructor(message, options) {
46
+ super(message, options);
47
+ this.name = "ZkkycError";
48
+ }
49
+ };
50
+
51
+ // src/zkkyc/validation.ts
52
+ import { z as z2 } from "zod";
53
+ var ZodAnonAadharProofParamsSchema = z2.object({
54
+ nullifierSeed: z2.bigint(),
55
+ nullifier: z2.bigint(),
56
+ timestamp: z2.bigint(),
57
+ signal: z2.bigint(),
58
+ revealArray: z2.tuple([z2.bigint(), z2.bigint(), z2.bigint(), z2.bigint()]),
59
+ packedGroth16Proof: z2.tuple([
60
+ z2.bigint(),
61
+ z2.bigint(),
62
+ z2.bigint(),
63
+ z2.bigint(),
64
+ z2.bigint(),
65
+ z2.bigint(),
66
+ z2.bigint(),
67
+ z2.bigint()
68
+ ])
69
+ });
70
+ var ZodSocialVerifyParamsSchema = z2.object({
71
+ _socialName: z2.string(),
72
+ proofs: z2.array(
73
+ z2.object({
74
+ claimInfo: z2.object({
75
+ provider: z2.string(),
76
+ parameters: z2.string(),
77
+ context: z2.string()
78
+ }),
79
+ signedClaim: z2.object({
80
+ claim: z2.object({
81
+ identifier: z2.string(),
82
+ owner: ZodAddressSchema,
83
+ timestampS: z2.number(),
84
+ epoch: z2.number()
85
+ }),
86
+ signatures: z2.array(z2.string())
87
+ })
88
+ })
89
+ )
90
+ });
91
+ var ZodSolidityVerifierParametersSchema = z2.object({
92
+ version: z2.string().refine((val) => val.startsWith("0x"), {
93
+ message: "Version must be a hex string"
94
+ }),
95
+ proofVerificationData: z2.object({
96
+ vkeyHash: z2.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
97
+ message: "Invalid bytes32 hex string"
98
+ }),
99
+ proof: z2.string().refine((val) => val.startsWith("0x"), {
100
+ message: "Proof must be a hex string"
101
+ }),
102
+ publicInputs: z2.array(
103
+ z2.string().refine((val) => /^0x[a-fA-F0-9]{64}$/.test(val), {
104
+ message: "Each public input must be a valid bytes32 hex string"
105
+ })
106
+ )
107
+ }),
108
+ committedInputs: z2.string().refine((val) => val.startsWith("0x"), {
109
+ message: "Committed inputs must be a hex string"
110
+ }),
111
+ serviceConfig: z2.object({
112
+ validityPeriodInSeconds: z2.number().int().nonnegative(),
113
+ domain: z2.string(),
114
+ scope: z2.string(),
115
+ devMode: z2.boolean()
116
+ })
117
+ });
118
+ var ZodZkPassportRegisterParamsSchema = z2.object({
119
+ params: ZodSolidityVerifierParametersSchema,
120
+ isIDCard: z2.boolean()
121
+ });
122
+
123
+ // src/contracts/abis/index.ts
124
+ import { erc20Abi } from "viem";
125
+
126
+ // src/contracts/abis/order-flow-facet.ts
127
+ var orderFlowFacetAbi = [
128
+ {
129
+ inputs: [
130
+ { internalType: "uint256", name: "circleId", type: "uint256" },
131
+ { internalType: "uint256", name: "assignUpto", type: "uint256" },
132
+ { internalType: "bytes32", name: "currency", type: "bytes32" },
133
+ { internalType: "address", name: "user", type: "address" },
134
+ { internalType: "uint256", name: "usdtAmount", type: "uint256" },
135
+ { internalType: "uint256", name: "fiatAmount", type: "uint256" },
136
+ { internalType: "int256", name: "orderType", type: "int256" },
137
+ { internalType: "uint256", name: "preferredPCConfigId", type: "uint256" }
138
+ ],
139
+ name: "getAssignableMerchantsFromCircle",
140
+ outputs: [{ internalType: "address[]", name: "", type: "address[]" }],
141
+ stateMutability: "view",
142
+ type: "function"
143
+ },
144
+ {
145
+ inputs: [
146
+ { internalType: "address", name: "_user", type: "address" },
147
+ { internalType: "bytes32", name: "_nativeCurrency", type: "bytes32" }
148
+ ],
149
+ name: "userTxLimit",
150
+ outputs: [
151
+ { internalType: "uint256", name: "", type: "uint256" },
152
+ { internalType: "uint256", name: "", type: "uint256" }
153
+ ],
154
+ stateMutability: "view",
155
+ type: "function"
156
+ }
157
+ ];
158
+
159
+ // src/contracts/abis/p2p-config-facet.ts
160
+ var p2pConfigFacetAbi = [
161
+ {
162
+ inputs: [
163
+ {
164
+ internalType: "bytes32",
165
+ name: "_currency",
166
+ type: "bytes32"
167
+ }
168
+ ],
169
+ name: "getPriceConfig",
170
+ outputs: [
171
+ {
172
+ components: [
173
+ {
174
+ internalType: "uint256",
175
+ name: "buyPrice",
176
+ type: "uint256"
177
+ },
178
+ {
179
+ internalType: "uint256",
180
+ name: "sellPrice",
181
+ type: "uint256"
182
+ },
183
+ {
184
+ internalType: "int256",
185
+ name: "buyPriceOffset",
186
+ type: "int256"
187
+ },
188
+ {
189
+ internalType: "uint256",
190
+ name: "baseSpread",
191
+ type: "uint256"
192
+ }
193
+ ],
194
+ internalType: "struct P2pConfigStorage.PriceConfig",
195
+ name: "",
196
+ type: "tuple"
197
+ }
198
+ ],
199
+ stateMutability: "view",
200
+ type: "function"
201
+ },
202
+ {
203
+ inputs: [
204
+ {
205
+ internalType: "bytes32",
206
+ name: "_nativeCurrency",
207
+ type: "bytes32"
208
+ }
209
+ ],
210
+ name: "getRpPerUsdtLimitRational",
211
+ outputs: [
212
+ {
213
+ internalType: "uint256",
214
+ name: "numerator",
215
+ type: "uint256"
216
+ },
217
+ {
218
+ internalType: "uint256",
219
+ name: "denominator",
220
+ type: "uint256"
221
+ }
222
+ ],
223
+ stateMutability: "view",
224
+ type: "function"
225
+ }
226
+ ];
227
+
228
+ // src/contracts/abis/reputation-manager.ts
229
+ var reputationManagerAbi = [
230
+ {
231
+ inputs: [
232
+ {
233
+ internalType: "string",
234
+ name: "_socialName",
235
+ type: "string"
236
+ },
237
+ {
238
+ components: [
239
+ {
240
+ components: [
241
+ {
242
+ internalType: "string",
243
+ name: "provider",
244
+ type: "string"
245
+ },
246
+ {
247
+ internalType: "string",
248
+ name: "parameters",
249
+ type: "string"
250
+ },
251
+ {
252
+ internalType: "string",
253
+ name: "context",
254
+ type: "string"
255
+ }
256
+ ],
257
+ internalType: "struct IReclaimSDK.ClaimInfo",
258
+ name: "claimInfo",
259
+ type: "tuple"
260
+ },
261
+ {
262
+ components: [
263
+ {
264
+ components: [
265
+ {
266
+ internalType: "bytes32",
267
+ name: "identifier",
268
+ type: "bytes32"
269
+ },
270
+ {
271
+ internalType: "address",
272
+ name: "owner",
273
+ type: "address"
274
+ },
275
+ {
276
+ internalType: "uint32",
277
+ name: "timestampS",
278
+ type: "uint32"
279
+ },
280
+ {
281
+ internalType: "uint32",
282
+ name: "epoch",
283
+ type: "uint32"
284
+ }
285
+ ],
286
+ internalType: "struct IReclaimSDK.CompleteClaimData",
287
+ name: "claim",
288
+ type: "tuple"
289
+ },
290
+ {
291
+ internalType: "bytes[]",
292
+ name: "signatures",
293
+ type: "bytes[]"
294
+ }
295
+ ],
296
+ internalType: "struct IReclaimSDK.SignedClaim",
297
+ name: "signedClaim",
298
+ type: "tuple"
299
+ }
300
+ ],
301
+ internalType: "struct IReclaimSDK.Proof[]",
302
+ name: "proofs",
303
+ type: "tuple[]"
304
+ }
305
+ ],
306
+ name: "socialVerify",
307
+ outputs: [],
308
+ stateMutability: "nonpayable",
309
+ type: "function"
310
+ },
311
+ {
312
+ inputs: [
313
+ {
314
+ internalType: "uint256",
315
+ name: "nullifierSeed",
316
+ type: "uint256"
317
+ },
318
+ {
319
+ internalType: "uint256",
320
+ name: "nullifier",
321
+ type: "uint256"
322
+ },
323
+ {
324
+ internalType: "uint256",
325
+ name: "timestamp",
326
+ type: "uint256"
327
+ },
328
+ {
329
+ internalType: "uint256",
330
+ name: "signal",
331
+ type: "uint256"
332
+ },
333
+ {
334
+ internalType: "uint256[4]",
335
+ name: "revealArray",
336
+ type: "uint256[4]"
337
+ },
338
+ {
339
+ internalType: "uint256[8]",
340
+ name: "groth16Proof",
341
+ type: "uint256[8]"
342
+ }
343
+ ],
344
+ name: "submitAnonAadharProof",
345
+ outputs: [],
346
+ stateMutability: "nonpayable",
347
+ type: "function"
348
+ },
349
+ {
350
+ inputs: [
351
+ {
352
+ components: [
353
+ {
354
+ internalType: "bytes32",
355
+ name: "version",
356
+ type: "bytes32"
357
+ },
358
+ {
359
+ components: [
360
+ {
361
+ internalType: "bytes32",
362
+ name: "vkeyHash",
363
+ type: "bytes32"
364
+ },
365
+ {
366
+ internalType: "bytes",
367
+ name: "proof",
368
+ type: "bytes"
369
+ },
370
+ {
371
+ internalType: "bytes32[]",
372
+ name: "publicInputs",
373
+ type: "bytes32[]"
374
+ }
375
+ ],
376
+ internalType: "struct ProofVerificationData",
377
+ name: "proofVerificationData",
378
+ type: "tuple"
379
+ },
380
+ {
381
+ internalType: "bytes",
382
+ name: "committedInputs",
383
+ type: "bytes"
384
+ },
385
+ {
386
+ components: [
387
+ {
388
+ internalType: "uint256",
389
+ name: "validityPeriodInSeconds",
390
+ type: "uint256"
391
+ },
392
+ {
393
+ internalType: "string",
394
+ name: "domain",
395
+ type: "string"
396
+ },
397
+ {
398
+ internalType: "string",
399
+ name: "scope",
400
+ type: "string"
401
+ },
402
+ {
403
+ internalType: "bool",
404
+ name: "devMode",
405
+ type: "bool"
406
+ }
407
+ ],
408
+ internalType: "struct ServiceConfig",
409
+ name: "serviceConfig",
410
+ type: "tuple"
411
+ }
412
+ ],
413
+ internalType: "struct ProofVerificationParams",
414
+ name: "params",
415
+ type: "tuple"
416
+ },
417
+ {
418
+ internalType: "bool",
419
+ name: "isIDCard",
420
+ type: "bool"
421
+ }
422
+ ],
423
+ name: "zkPassportRegister",
424
+ outputs: [],
425
+ stateMutability: "nonpayable",
426
+ type: "function"
427
+ }
428
+ ];
429
+
430
+ // src/contracts/abis/index.ts
431
+ var DIAMOND_ABI = [...orderFlowFacetAbi, ...p2pConfigFacetAbi];
432
+ var ABIS = {
433
+ DIAMOND: DIAMOND_ABI,
434
+ FACETS: {
435
+ ORDER_FLOW: orderFlowFacetAbi,
436
+ CONFIG: p2pConfigFacetAbi
437
+ },
438
+ EXTERNAL: {
439
+ USDC: erc20Abi,
440
+ REPUTATION_MANAGER: reputationManagerAbi
441
+ }
442
+ };
443
+
444
+ // src/contracts/reputation-manager/writes.ts
445
+ function prepareSocialVerify(reputationManagerAddress, params) {
446
+ return validate(
447
+ ZodSocialVerifyParamsSchema,
448
+ params,
449
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
450
+ ).andThen(
451
+ (validated) => Result.fromThrowable(
452
+ () => ({
453
+ to: reputationManagerAddress,
454
+ data: encodeFunctionData({
455
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
456
+ functionName: "socialVerify",
457
+ args: [
458
+ validated._socialName,
459
+ validated.proofs.map((proof) => ({
460
+ ...proof,
461
+ signedClaim: {
462
+ ...proof.signedClaim,
463
+ claim: {
464
+ ...proof.signedClaim.claim,
465
+ identifier: proof.signedClaim.claim.identifier
466
+ },
467
+ signatures: proof.signedClaim.signatures
468
+ }
469
+ }))
470
+ ]
471
+ })
472
+ }),
473
+ (error) => new ZkkycError("Failed to encode socialVerify", {
474
+ code: "ENCODE_ERROR",
475
+ cause: error
476
+ })
477
+ )()
478
+ );
479
+ }
480
+ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
481
+ return validate(
482
+ ZodAnonAadharProofParamsSchema,
483
+ params,
484
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
485
+ ).andThen(
486
+ (validated) => Result.fromThrowable(
487
+ () => ({
488
+ to: reputationManagerAddress,
489
+ data: encodeFunctionData({
490
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
491
+ functionName: "submitAnonAadharProof",
492
+ args: [
493
+ validated.nullifierSeed,
494
+ validated.nullifier,
495
+ validated.timestamp,
496
+ validated.signal,
497
+ validated.revealArray,
498
+ validated.packedGroth16Proof
499
+ ]
500
+ })
501
+ }),
502
+ (error) => new ZkkycError("Failed to encode submitAnonAadharProof", {
503
+ code: "ENCODE_ERROR",
504
+ cause: error
505
+ })
506
+ )()
507
+ );
508
+ }
509
+ function prepareZkPassportRegister(reputationManagerAddress, params) {
510
+ return validate(
511
+ ZodZkPassportRegisterParamsSchema,
512
+ params,
513
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
514
+ ).andThen(
515
+ (validated) => Result.fromThrowable(
516
+ () => {
517
+ const { proofVerificationData, serviceConfig, committedInputs, version } = validated.params;
518
+ const proofVerificationParams = {
519
+ version,
520
+ proofVerificationData: {
521
+ vkeyHash: proofVerificationData.vkeyHash,
522
+ proof: proofVerificationData.proof,
523
+ publicInputs: proofVerificationData.publicInputs
524
+ },
525
+ committedInputs,
526
+ serviceConfig: {
527
+ validityPeriodInSeconds: BigInt(serviceConfig.validityPeriodInSeconds),
528
+ domain: serviceConfig.domain,
529
+ scope: serviceConfig.scope,
530
+ devMode: serviceConfig.devMode
531
+ }
532
+ };
533
+ return {
534
+ to: reputationManagerAddress,
535
+ data: encodeFunctionData({
536
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
537
+ functionName: "zkPassportRegister",
538
+ args: [proofVerificationParams, validated.isIDCard]
539
+ })
540
+ };
541
+ },
542
+ (error) => new ZkkycError("Failed to encode zkPassportRegister", {
543
+ code: "ENCODE_ERROR",
544
+ cause: error
545
+ })
546
+ )()
547
+ );
548
+ }
549
+
550
+ // src/zkkyc/client.ts
551
+ function createZkkyc(config) {
552
+ const { reputationManagerAddress } = config;
553
+ return {
554
+ prepareSocialVerify: (params) => prepareSocialVerify(reputationManagerAddress, params),
555
+ prepareSubmitAnonAadharProof: (params) => prepareSubmitAnonAadharProof(reputationManagerAddress, params),
556
+ prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params)
557
+ };
558
+ }
559
+
560
+ // src/zkkyc/orchestrators/constants.ts
561
+ var DEFAULT_RECLAIM_PROVIDER_IDS = {
562
+ linkedin: "6a86edbe-a0fe-420b-8db2-3155220cc949",
563
+ github: "033f0c06-2eb3-48c8-894c-5599c3356d1c",
564
+ x: "aad95818-f726-4a34-be97-8d1f47631b03",
565
+ instagram: "7e5b59a9-56c5-490c-a169-82a443f9b507",
566
+ facebook: "2701510b-c835-4820-84f0-d9e74569656b"
567
+ };
568
+ var ZK_PASSPORT_APP_LINKS = {
569
+ IOS: "https://apps.apple.com/us/app/zkpassport/id6477371975",
570
+ ANDROID: "https://play.google.com/store/apps/details?id=app.zkpassport.zkpassport"
571
+ };
572
+ var RECLAIM_APP_LINKS = {
573
+ ANDROID: "https://play.google.com/store/apps/details?id=org.reclaimprotocol.app"
574
+ };
575
+
576
+ // src/zkkyc/orchestrators/reclaim.ts
577
+ import { ResultAsync } from "neverthrow";
578
+
579
+ // src/zkkyc/orchestrators/types.ts
580
+ var SOCIAL_PLATFORM_NAMES = {
581
+ linkedin: "LinkedIn",
582
+ github: "GitHub",
583
+ x: "X",
584
+ instagram: "Instagram",
585
+ facebook: "Facebook"
586
+ };
587
+
588
+ // src/zkkyc/orchestrators/reclaim.ts
589
+ var RECLAIM_SESSION_API = "https://api.reclaimprotocol.org/api/sdk/session";
590
+ function createReclaimFlow(config, options) {
591
+ return ResultAsync.fromPromise(
592
+ (async () => {
593
+ const mod = await import("@reclaimprotocol/js-sdk").catch(() => {
594
+ throw new ZkkycError(
595
+ "Missing peer dependency: @reclaimprotocol/js-sdk. Install it with: npm install @reclaimprotocol/js-sdk",
596
+ { code: "PEER_DEPENDENCY_MISSING" }
597
+ );
598
+ });
599
+ const { ReclaimProofRequest, transformForOnchain } = mod;
600
+ const {
601
+ platform,
602
+ walletAddress,
603
+ redirectUrl,
604
+ sessionId: existingSessionId,
605
+ contextDescription,
606
+ onStatus,
607
+ signal,
608
+ pollingIntervalMs = 5e3
609
+ } = options;
610
+ const socialName = SOCIAL_PLATFORM_NAMES[platform];
611
+ const providerId = config.providerIds[platform];
612
+ let sessionId;
613
+ if (existingSessionId) {
614
+ sessionId = existingSessionId;
615
+ } else {
616
+ const reclaimProofRequest = await ReclaimProofRequest.init(
617
+ config.appId,
618
+ config.appSecret,
619
+ providerId,
620
+ { launchOptions: { canUseDeferredDeepLinksFlow: true } }
621
+ );
622
+ const statusUrl = reclaimProofRequest.getStatusUrl();
623
+ sessionId = statusUrl.split("/").pop() || "";
624
+ if (redirectUrl) {
625
+ const separator = redirectUrl.includes("?") ? "&" : "?";
626
+ reclaimProofRequest.setRedirectUrl(
627
+ `${redirectUrl}${separator}sessionId=${sessionId}&socialPlatform=${socialName}`
628
+ );
629
+ }
630
+ reclaimProofRequest.addContext(
631
+ walletAddress,
632
+ contextDescription ?? `Social verification for ${socialName}`
633
+ );
634
+ const requestUrl = await reclaimProofRequest.getRequestUrl();
635
+ onStatus?.({ type: "session_created", sessionId, requestUrl });
636
+ if (typeof window !== "undefined") {
637
+ reclaimProofRequest.triggerReclaimFlow();
638
+ }
639
+ }
640
+ onStatus?.({ type: "polling_started", sessionId });
641
+ while (true) {
642
+ if (signal?.aborted) {
643
+ throw new ZkkycError("Reclaim polling aborted", {
644
+ code: "RECLAIM_POLLING_ABORTED"
645
+ });
646
+ }
647
+ const response = await fetch(`${RECLAIM_SESSION_API}/${sessionId}`);
648
+ const data = await response.json();
649
+ if (data?.session?.proofs?.length > 0) {
650
+ const proofs = data.session.proofs;
651
+ onStatus?.({ type: "proof_received" });
652
+ if (platform === "github" && proofs.length > 0) {
653
+ const first = proofs[0];
654
+ if (first?.publicData && Object.keys(first.publicData).length === 0) {
655
+ throw new ZkkycError("GitHub verification eligibility criteria not met", {
656
+ code: "RECLAIM_PROOF_INVALID"
657
+ });
658
+ }
659
+ }
660
+ const transformedProofs = proofs.map((proof) => transformForOnchain(proof));
661
+ onStatus?.({ type: "proof_transformed" });
662
+ return {
663
+ _socialName: socialName,
664
+ proofs: transformedProofs,
665
+ sessionId
666
+ };
667
+ }
668
+ if (data?.message?.includes("Session not found")) {
669
+ throw new ZkkycError("Reclaim session not found", {
670
+ code: "RECLAIM_SESSION_NOT_FOUND",
671
+ context: { sessionId }
672
+ });
673
+ }
674
+ if (data?.session?.statusV2 === "PROOF_GENERATION_FAILED") {
675
+ throw new ZkkycError("Reclaim proof generation failed", {
676
+ code: "RECLAIM_PROOF_GENERATION_FAILED",
677
+ context: { sessionId }
678
+ });
679
+ }
680
+ await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs));
681
+ }
682
+ })(),
683
+ (error) => {
684
+ if (error instanceof ZkkycError) return error;
685
+ return new ZkkycError("Reclaim verification flow failed", {
686
+ code: "RECLAIM_INIT_FAILED",
687
+ cause: error
688
+ });
689
+ }
690
+ );
691
+ }
692
+
693
+ // src/zkkyc/orchestrators/zk-passport.ts
694
+ import { ResultAsync as ResultAsync2 } from "neverthrow";
695
+ function createZkPassportFlow(config, options) {
696
+ return ResultAsync2.fromPromise(
697
+ (async () => {
698
+ const mod = await import("@zkpassport/sdk").catch(() => {
699
+ throw new ZkkycError(
700
+ "Missing peer dependency: @zkpassport/sdk. Install it with: npm install @zkpassport/sdk",
701
+ { code: "PEER_DEPENDENCY_MISSING" }
702
+ );
703
+ });
704
+ const { ZKPassport } = mod;
705
+ const zkPassport = new ZKPassport(config.domain ?? "app.p2p.me");
706
+ const queryBuilder = await zkPassport.request({
707
+ name: config.name ?? "ZKPassport",
708
+ logo: config.logo ?? "https://app.p2p.lol/favicon.svg",
709
+ purpose: config.purpose ?? "Prove your personhood",
710
+ scope: "personhood",
711
+ mode: "compressed-evm"
712
+ });
713
+ const {
714
+ url,
715
+ onRequestReceived,
716
+ onGeneratingProof,
717
+ onProofGenerated,
718
+ onResult,
719
+ onReject,
720
+ onError
721
+ } = queryBuilder.gte("age", 18).disclose("document_type").disclose("nationality").bind("user_address", options.walletAddress).done();
722
+ options.onStatus?.({ type: "request_created", url });
723
+ let aborted = false;
724
+ const resultPromise = new Promise((resolve, reject) => {
725
+ let proof = null;
726
+ onRequestReceived(() => {
727
+ if (aborted) return;
728
+ options.onStatus?.({ type: "request_received" });
729
+ });
730
+ onGeneratingProof(() => {
731
+ if (aborted) return;
732
+ options.onStatus?.({ type: "generating_proof" });
733
+ });
734
+ onProofGenerated(async (result) => {
735
+ if (aborted) return;
736
+ options.onStatus?.({ type: "proof_generated" });
737
+ proof = result;
738
+ });
739
+ onResult(
740
+ async ({
741
+ result,
742
+ uniqueIdentifier,
743
+ verified
744
+ }) => {
745
+ if (aborted) return;
746
+ options.onStatus?.({ type: "result_received" });
747
+ if (!verified || !proof || !uniqueIdentifier) {
748
+ reject(
749
+ new ZkkycError("ZK Passport verification failed", {
750
+ code: "ZK_PASSPORT_VERIFICATION_FAILED"
751
+ })
752
+ );
753
+ return;
754
+ }
755
+ try {
756
+ const verifierParams = zkPassport.getSolidityVerifierParameters({
757
+ proof,
758
+ scope: "personhood",
759
+ devMode: false
760
+ });
761
+ const isIDCard = result.document_type?.disclose?.result !== "passport";
762
+ resolve({ params: verifierParams, isIDCard });
763
+ } catch (error) {
764
+ reject(
765
+ new ZkkycError("Failed to extract ZK Passport verifier parameters", {
766
+ code: "ZK_PASSPORT_VERIFICATION_FAILED",
767
+ cause: error
768
+ })
769
+ );
770
+ }
771
+ }
772
+ );
773
+ onReject(() => {
774
+ options.onStatus?.({ type: "rejected" });
775
+ reject(
776
+ new ZkkycError("User rejected ZK Passport verification", {
777
+ code: "ZK_PASSPORT_REJECTED"
778
+ })
779
+ );
780
+ });
781
+ onError((error) => {
782
+ reject(
783
+ new ZkkycError(typeof error === "string" ? error : "ZK Passport verification error", {
784
+ code: "ZK_PASSPORT_VERIFICATION_FAILED",
785
+ cause: error
786
+ })
787
+ );
788
+ });
789
+ });
790
+ const session = {
791
+ url,
792
+ result: ResultAsync2.fromPromise(resultPromise, (error) => {
793
+ if (error instanceof ZkkycError) return error;
794
+ return new ZkkycError("ZK Passport flow failed", {
795
+ code: "ZK_PASSPORT_VERIFICATION_FAILED",
796
+ cause: error
797
+ });
798
+ }),
799
+ abort: () => {
800
+ aborted = true;
801
+ }
802
+ };
803
+ return session;
804
+ })(),
805
+ (error) => {
806
+ if (error instanceof ZkkycError) return error;
807
+ return new ZkkycError("Failed to initialize ZK Passport", {
808
+ code: "ZK_PASSPORT_INIT_FAILED",
809
+ cause: error
810
+ });
811
+ }
812
+ );
813
+ }
814
+ export {
815
+ DEFAULT_RECLAIM_PROVIDER_IDS,
816
+ RECLAIM_APP_LINKS,
817
+ SOCIAL_PLATFORM_NAMES,
818
+ ZK_PASSPORT_APP_LINKS,
819
+ ZkkycError,
820
+ createReclaimFlow,
821
+ createZkPassportFlow,
822
+ createZkkyc
823
+ };
824
+ //# sourceMappingURL=zkkyc.mjs.map