@p2pdotme/sdk 1.2.21 → 1.2.23

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/zkkyc.d.cts CHANGED
@@ -13,7 +13,7 @@ declare class SdkError<TCode extends string = string> extends Error {
13
13
  });
14
14
  }
15
15
 
16
- type ZkkycErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "ENCODE_ERROR" | "RECLAIM_INIT_FAILED" | "RECLAIM_SESSION_NOT_FOUND" | "RECLAIM_PROOF_GENERATION_FAILED" | "RECLAIM_PROOF_INVALID" | "RECLAIM_POLLING_ABORTED" | "ZK_PASSPORT_INIT_FAILED" | "ZK_PASSPORT_REJECTED" | "ZK_PASSPORT_VERIFICATION_FAILED" | "ZK_PASSPORT_ABORTED" | "SIMPLE_KYC_SESSION_FAILED" | "SIMPLE_KYC_REDEEM_FAILED" | "LIVENESS_SESSION_FAILED" | "LIVENESS_REDEEM_FAILED" | "BVN_ONBOARD_FAILED" | "BVN_SUBMIT_FAILED" | "BVN_OTP_SEND_FAILED" | "BVN_OTP_CONFIRM_FAILED" | "BVN_ATTESTATION_FAILED" | "BVN_SESSION_EXPIRED" | "PEER_DEPENDENCY_MISSING";
16
+ type ZkkycErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "ENCODE_ERROR" | "RECLAIM_INIT_FAILED" | "RECLAIM_SESSION_ENDPOINT_FAILED" | "RECLAIM_SESSION_NOT_FOUND" | "RECLAIM_PROOF_GENERATION_FAILED" | "RECLAIM_PROOF_INVALID" | "RECLAIM_POLLING_ABORTED" | "ZK_PASSPORT_INIT_FAILED" | "ZK_PASSPORT_REJECTED" | "ZK_PASSPORT_VERIFICATION_FAILED" | "ZK_PASSPORT_ABORTED" | "SIMPLE_KYC_SESSION_FAILED" | "SIMPLE_KYC_REDEEM_FAILED" | "LIVENESS_SESSION_FAILED" | "LIVENESS_REDEEM_FAILED" | "BVN_ONBOARD_FAILED" | "BVN_SUBMIT_FAILED" | "BVN_OTP_SEND_FAILED" | "BVN_OTP_CONFIRM_FAILED" | "BVN_ATTESTATION_FAILED" | "BVN_SESSION_EXPIRED" | "PEER_DEPENDENCY_MISSING";
17
17
  declare class ZkkycError extends SdkError<ZkkycErrorCode> {
18
18
  constructor(message: string, options: {
19
19
  code: ZkkycErrorCode;
@@ -147,23 +147,38 @@ declare function createZkkyc(config: ZkkycConfig): Zkkyc;
147
147
  type SocialPlatform = "linkedin" | "github" | "x" | "instagram" | "facebook" | "binance";
148
148
  /** Maps SocialPlatform to the capitalized name the contract expects for _socialName. */
149
149
  declare const SOCIAL_PLATFORM_NAMES: Record<SocialPlatform, string>;
150
+ /** Locales the session service can render the Reclaim context message in. */
151
+ type ReclaimLocale = "en" | "es" | "hi" | "id" | "pt";
152
+ /** Tenants the session service knows, one per consuming app. */
153
+ type ReclaimTenant = "p2p" | "coinsme";
150
154
  /**
151
155
  * Single-object params for `createReclaimFlow`. Merges the app-level config
152
- * (appId, appSecret, providerIds) with the per-call options (platform,
153
- * walletAddress, callbacks, …) into one argument.
156
+ * (sessionEndpoint, tenant) with the per-call options (platform, walletAddress,
157
+ * callbacks, …) into one argument.
154
158
  */
155
159
  interface ReclaimFlowParams {
156
- readonly appId: string;
157
- readonly appSecret: string;
158
- readonly providerIds: Record<SocialPlatform, string>;
160
+ /**
161
+ * Base URL of the reclaim-session-service, which holds the Reclaim app
162
+ * secret and mints proof-request configs (e.g. https://reclaim.p2p.me).
163
+ *
164
+ * The secret must never reach the browser: it is a private key whose address
165
+ * is the appId, and bundlers inline build-time env vars into shipped JS.
166
+ */
167
+ readonly sessionEndpoint: string;
168
+ /** Selects the app's branding/copy on the session service. */
169
+ readonly tenant: ReclaimTenant;
159
170
  readonly platform: SocialPlatform;
160
171
  readonly walletAddress: Address;
161
- /** Base URL for redirect after Reclaim flow. SDK appends ?sessionId={id}&socialPlatform={Name}. */
172
+ /** Base URL for redirect after Reclaim flow. Service appends ?sessionId={id}&socialPlatform={Name}. */
162
173
  readonly redirectUrl?: string;
163
174
  /** Resume polling for an existing session (redirect-back case). */
164
175
  readonly sessionId?: string;
165
- /** Description added to Reclaim context. */
166
- readonly contextDescription?: string;
176
+ /**
177
+ * Locale for the message shown inside the Reclaim Verifier app. The wording
178
+ * itself is owned by the service — that string renders under our app
179
+ * identity, so callers choose a language, not the words.
180
+ */
181
+ readonly locale?: ReclaimLocale;
167
182
  /** Called with status updates during the flow. */
168
183
  readonly onStatus?: (status: ReclaimStatus) => void;
169
184
  /** AbortSignal to cancel polling. */
@@ -495,9 +510,12 @@ declare function resumeLivenessFlow(args: {
495
510
  }): ResultAsync<LivenessAttestation, ZkkycError>;
496
511
 
497
512
  /**
498
- * Initializes a Reclaim social verification flow and returns a session. `init()`
499
- * runs eagerly here, so call this on page load; the returned session's `start()`
500
- * triggers the in-app flow and polls for the proof, so call that on user action.
513
+ * Initializes a Reclaim social verification flow and returns a session. The
514
+ * proof request is minted by reclaim-session-service (which holds the app
515
+ * secret) and rebuilt here with `fromJsonString`, so the secret never reaches
516
+ * the browser. That network call runs eagerly, so call this on page load; the
517
+ * returned session's `start()` triggers the in-app flow and polls for the proof,
518
+ * so call that on user action.
501
519
  */
502
520
  declare function createReclaimFlow(params: ReclaimFlowParams): ResultAsync<ReclaimSession, ZkkycError>;
503
521
 
@@ -525,4 +543,4 @@ declare function resumeSimpleKycFlow(args: {
525
543
  /** Initializes a ZK Passport verification flow and returns a session. */
526
544
  declare function createZkPassportFlow(params: ZkPassportFlowParams): ResultAsync<ZkPassportSession, ZkkycError>;
527
545
 
528
- export { type AnonAadharProofParams, BVN_OTP_METHODS, type BvnAttestation, type BvnDecision, type BvnFlow, type BvnFlowConfig, type BvnMethod, type BvnOnboardParams, type BvnOtpMethod, type BvnScope, type BvnSendOtpParams, type BvnSession, type BvnSubmitParams, DEFAULT_RECLAIM_PROVIDER_IDS, LIVENESS_DEFAULT_TENANT, type LivenessAttestation, type LivenessFlowParams, type LivenessSession, type LivenessStatus, type LivenessSubmitParams, RECLAIM_APP_LINKS, type ReclaimFlowParams, type ReclaimProofResult, type ReclaimSession, type ReclaimStatus, SIMPLE_KYC_DEFAULT_TENANT, SOCIAL_PLATFORM_NAMES, type SimpleKycAttestation, type SimpleKycFlowParams, type SimpleKycSession, type SimpleKycStatus, type SimpleKycSubmitParams, type SocialPlatform, type SocialVerifyParams, ZK_PASSPORT_APP_LINKS, type ZkPassportFlowParams, type ZkPassportProofResult, type ZkPassportRegisterParams, type ZkPassportSession, type ZkPassportStatus, type Zkkyc, type ZkkycConfig, ZkkycError, type ZkkycErrorCode, createBvnFlow, createLivenessFlow, createReclaimFlow, createSimpleKycFlow, createZkPassportFlow, createZkkyc, resumeLivenessFlow, resumeSimpleKycFlow };
546
+ export { type AnonAadharProofParams, BVN_OTP_METHODS, type BvnAttestation, type BvnDecision, type BvnFlow, type BvnFlowConfig, type BvnMethod, type BvnOnboardParams, type BvnOtpMethod, type BvnScope, type BvnSendOtpParams, type BvnSession, type BvnSubmitParams, DEFAULT_RECLAIM_PROVIDER_IDS, LIVENESS_DEFAULT_TENANT, type LivenessAttestation, type LivenessFlowParams, type LivenessSession, type LivenessStatus, type LivenessSubmitParams, RECLAIM_APP_LINKS, type ReclaimFlowParams, type ReclaimLocale, type ReclaimProofResult, type ReclaimSession, type ReclaimStatus, type ReclaimTenant, SIMPLE_KYC_DEFAULT_TENANT, SOCIAL_PLATFORM_NAMES, type SimpleKycAttestation, type SimpleKycFlowParams, type SimpleKycSession, type SimpleKycStatus, type SimpleKycSubmitParams, type SocialPlatform, type SocialVerifyParams, ZK_PASSPORT_APP_LINKS, type ZkPassportFlowParams, type ZkPassportProofResult, type ZkPassportRegisterParams, type ZkPassportSession, type ZkPassportStatus, type Zkkyc, type ZkkycConfig, ZkkycError, type ZkkycErrorCode, createBvnFlow, createLivenessFlow, createReclaimFlow, createSimpleKycFlow, createZkPassportFlow, createZkkyc, resumeLivenessFlow, resumeSimpleKycFlow };
package/dist/zkkyc.d.ts CHANGED
@@ -13,7 +13,7 @@ declare class SdkError<TCode extends string = string> extends Error {
13
13
  });
14
14
  }
15
15
 
16
- type ZkkycErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "ENCODE_ERROR" | "RECLAIM_INIT_FAILED" | "RECLAIM_SESSION_NOT_FOUND" | "RECLAIM_PROOF_GENERATION_FAILED" | "RECLAIM_PROOF_INVALID" | "RECLAIM_POLLING_ABORTED" | "ZK_PASSPORT_INIT_FAILED" | "ZK_PASSPORT_REJECTED" | "ZK_PASSPORT_VERIFICATION_FAILED" | "ZK_PASSPORT_ABORTED" | "SIMPLE_KYC_SESSION_FAILED" | "SIMPLE_KYC_REDEEM_FAILED" | "LIVENESS_SESSION_FAILED" | "LIVENESS_REDEEM_FAILED" | "BVN_ONBOARD_FAILED" | "BVN_SUBMIT_FAILED" | "BVN_OTP_SEND_FAILED" | "BVN_OTP_CONFIRM_FAILED" | "BVN_ATTESTATION_FAILED" | "BVN_SESSION_EXPIRED" | "PEER_DEPENDENCY_MISSING";
16
+ type ZkkycErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR" | "ENCODE_ERROR" | "RECLAIM_INIT_FAILED" | "RECLAIM_SESSION_ENDPOINT_FAILED" | "RECLAIM_SESSION_NOT_FOUND" | "RECLAIM_PROOF_GENERATION_FAILED" | "RECLAIM_PROOF_INVALID" | "RECLAIM_POLLING_ABORTED" | "ZK_PASSPORT_INIT_FAILED" | "ZK_PASSPORT_REJECTED" | "ZK_PASSPORT_VERIFICATION_FAILED" | "ZK_PASSPORT_ABORTED" | "SIMPLE_KYC_SESSION_FAILED" | "SIMPLE_KYC_REDEEM_FAILED" | "LIVENESS_SESSION_FAILED" | "LIVENESS_REDEEM_FAILED" | "BVN_ONBOARD_FAILED" | "BVN_SUBMIT_FAILED" | "BVN_OTP_SEND_FAILED" | "BVN_OTP_CONFIRM_FAILED" | "BVN_ATTESTATION_FAILED" | "BVN_SESSION_EXPIRED" | "PEER_DEPENDENCY_MISSING";
17
17
  declare class ZkkycError extends SdkError<ZkkycErrorCode> {
18
18
  constructor(message: string, options: {
19
19
  code: ZkkycErrorCode;
@@ -147,23 +147,38 @@ declare function createZkkyc(config: ZkkycConfig): Zkkyc;
147
147
  type SocialPlatform = "linkedin" | "github" | "x" | "instagram" | "facebook" | "binance";
148
148
  /** Maps SocialPlatform to the capitalized name the contract expects for _socialName. */
149
149
  declare const SOCIAL_PLATFORM_NAMES: Record<SocialPlatform, string>;
150
+ /** Locales the session service can render the Reclaim context message in. */
151
+ type ReclaimLocale = "en" | "es" | "hi" | "id" | "pt";
152
+ /** Tenants the session service knows, one per consuming app. */
153
+ type ReclaimTenant = "p2p" | "coinsme";
150
154
  /**
151
155
  * Single-object params for `createReclaimFlow`. Merges the app-level config
152
- * (appId, appSecret, providerIds) with the per-call options (platform,
153
- * walletAddress, callbacks, …) into one argument.
156
+ * (sessionEndpoint, tenant) with the per-call options (platform, walletAddress,
157
+ * callbacks, …) into one argument.
154
158
  */
155
159
  interface ReclaimFlowParams {
156
- readonly appId: string;
157
- readonly appSecret: string;
158
- readonly providerIds: Record<SocialPlatform, string>;
160
+ /**
161
+ * Base URL of the reclaim-session-service, which holds the Reclaim app
162
+ * secret and mints proof-request configs (e.g. https://reclaim.p2p.me).
163
+ *
164
+ * The secret must never reach the browser: it is a private key whose address
165
+ * is the appId, and bundlers inline build-time env vars into shipped JS.
166
+ */
167
+ readonly sessionEndpoint: string;
168
+ /** Selects the app's branding/copy on the session service. */
169
+ readonly tenant: ReclaimTenant;
159
170
  readonly platform: SocialPlatform;
160
171
  readonly walletAddress: Address;
161
- /** Base URL for redirect after Reclaim flow. SDK appends ?sessionId={id}&socialPlatform={Name}. */
172
+ /** Base URL for redirect after Reclaim flow. Service appends ?sessionId={id}&socialPlatform={Name}. */
162
173
  readonly redirectUrl?: string;
163
174
  /** Resume polling for an existing session (redirect-back case). */
164
175
  readonly sessionId?: string;
165
- /** Description added to Reclaim context. */
166
- readonly contextDescription?: string;
176
+ /**
177
+ * Locale for the message shown inside the Reclaim Verifier app. The wording
178
+ * itself is owned by the service — that string renders under our app
179
+ * identity, so callers choose a language, not the words.
180
+ */
181
+ readonly locale?: ReclaimLocale;
167
182
  /** Called with status updates during the flow. */
168
183
  readonly onStatus?: (status: ReclaimStatus) => void;
169
184
  /** AbortSignal to cancel polling. */
@@ -495,9 +510,12 @@ declare function resumeLivenessFlow(args: {
495
510
  }): ResultAsync<LivenessAttestation, ZkkycError>;
496
511
 
497
512
  /**
498
- * Initializes a Reclaim social verification flow and returns a session. `init()`
499
- * runs eagerly here, so call this on page load; the returned session's `start()`
500
- * triggers the in-app flow and polls for the proof, so call that on user action.
513
+ * Initializes a Reclaim social verification flow and returns a session. The
514
+ * proof request is minted by reclaim-session-service (which holds the app
515
+ * secret) and rebuilt here with `fromJsonString`, so the secret never reaches
516
+ * the browser. That network call runs eagerly, so call this on page load; the
517
+ * returned session's `start()` triggers the in-app flow and polls for the proof,
518
+ * so call that on user action.
501
519
  */
502
520
  declare function createReclaimFlow(params: ReclaimFlowParams): ResultAsync<ReclaimSession, ZkkycError>;
503
521
 
@@ -525,4 +543,4 @@ declare function resumeSimpleKycFlow(args: {
525
543
  /** Initializes a ZK Passport verification flow and returns a session. */
526
544
  declare function createZkPassportFlow(params: ZkPassportFlowParams): ResultAsync<ZkPassportSession, ZkkycError>;
527
545
 
528
- export { type AnonAadharProofParams, BVN_OTP_METHODS, type BvnAttestation, type BvnDecision, type BvnFlow, type BvnFlowConfig, type BvnMethod, type BvnOnboardParams, type BvnOtpMethod, type BvnScope, type BvnSendOtpParams, type BvnSession, type BvnSubmitParams, DEFAULT_RECLAIM_PROVIDER_IDS, LIVENESS_DEFAULT_TENANT, type LivenessAttestation, type LivenessFlowParams, type LivenessSession, type LivenessStatus, type LivenessSubmitParams, RECLAIM_APP_LINKS, type ReclaimFlowParams, type ReclaimProofResult, type ReclaimSession, type ReclaimStatus, SIMPLE_KYC_DEFAULT_TENANT, SOCIAL_PLATFORM_NAMES, type SimpleKycAttestation, type SimpleKycFlowParams, type SimpleKycSession, type SimpleKycStatus, type SimpleKycSubmitParams, type SocialPlatform, type SocialVerifyParams, ZK_PASSPORT_APP_LINKS, type ZkPassportFlowParams, type ZkPassportProofResult, type ZkPassportRegisterParams, type ZkPassportSession, type ZkPassportStatus, type Zkkyc, type ZkkycConfig, ZkkycError, type ZkkycErrorCode, createBvnFlow, createLivenessFlow, createReclaimFlow, createSimpleKycFlow, createZkPassportFlow, createZkkyc, resumeLivenessFlow, resumeSimpleKycFlow };
546
+ export { type AnonAadharProofParams, BVN_OTP_METHODS, type BvnAttestation, type BvnDecision, type BvnFlow, type BvnFlowConfig, type BvnMethod, type BvnOnboardParams, type BvnOtpMethod, type BvnScope, type BvnSendOtpParams, type BvnSession, type BvnSubmitParams, DEFAULT_RECLAIM_PROVIDER_IDS, LIVENESS_DEFAULT_TENANT, type LivenessAttestation, type LivenessFlowParams, type LivenessSession, type LivenessStatus, type LivenessSubmitParams, RECLAIM_APP_LINKS, type ReclaimFlowParams, type ReclaimLocale, type ReclaimProofResult, type ReclaimSession, type ReclaimStatus, type ReclaimTenant, SIMPLE_KYC_DEFAULT_TENANT, SOCIAL_PLATFORM_NAMES, type SimpleKycAttestation, type SimpleKycFlowParams, type SimpleKycSession, type SimpleKycStatus, type SimpleKycSubmitParams, type SocialPlatform, type SocialVerifyParams, ZK_PASSPORT_APP_LINKS, type ZkPassportFlowParams, type ZkPassportProofResult, type ZkPassportRegisterParams, type ZkPassportSession, type ZkPassportStatus, type Zkkyc, type ZkkycConfig, ZkkycError, type ZkkycErrorCode, createBvnFlow, createLivenessFlow, createReclaimFlow, createSimpleKycFlow, createZkPassportFlow, createZkkyc, resumeLivenessFlow, resumeSimpleKycFlow };
package/dist/zkkyc.mjs CHANGED
@@ -1530,46 +1530,51 @@ function createReclaimFlow(params) {
1530
1530
  });
1531
1531
  const { ReclaimProofRequest, transformForOnchain } = mod;
1532
1532
  const {
1533
- appId,
1534
- appSecret,
1535
- providerIds,
1533
+ sessionEndpoint,
1534
+ tenant,
1536
1535
  platform,
1537
1536
  walletAddress,
1538
1537
  redirectUrl,
1539
1538
  sessionId: existingSessionId,
1540
- contextDescription,
1539
+ locale,
1541
1540
  onStatus,
1542
1541
  signal,
1543
1542
  pollingIntervalMs = 5e3
1544
1543
  } = params;
1545
1544
  const socialName = SOCIAL_PLATFORM_NAMES[platform];
1546
- const providerId = providerIds[platform];
1547
1545
  let reclaimProofRequest = null;
1548
1546
  let sessionId;
1549
1547
  let requestUrl = "";
1550
1548
  if (existingSessionId) {
1551
1549
  sessionId = existingSessionId;
1552
1550
  } else {
1553
- reclaimProofRequest = await ReclaimProofRequest.init(appId, appSecret, providerId, {
1554
- launchOptions: {
1555
- canUseDeferredDeepLinksFlow: true,
1556
- verificationMode: "app"
1557
- },
1558
- useAppClip: true,
1559
- log: true
1551
+ if (!redirectUrl) {
1552
+ throw new ZkkycError("redirectUrl is required to start a Reclaim session", {
1553
+ code: "VALIDATION_ERROR"
1554
+ });
1555
+ }
1556
+ const response = await fetch(`${sessionEndpoint.replace(/\/$/, "")}/v1/reclaim/sessions`, {
1557
+ method: "POST",
1558
+ headers: { "Content-Type": "application/json" },
1559
+ body: JSON.stringify({ tenant, platform, walletAddress, redirectUrl, locale }),
1560
+ signal
1560
1561
  });
1561
- const statusUrl = reclaimProofRequest.getStatusUrl();
1562
- sessionId = statusUrl.split("/").pop() || "";
1563
- if (redirectUrl) {
1564
- const separator = redirectUrl.includes("?") ? "&" : "?";
1565
- reclaimProofRequest.setRedirectUrl(
1566
- `${redirectUrl}${separator}sessionId=${sessionId}&socialPlatform=${socialName}`
1567
- );
1562
+ if (!response.ok) {
1563
+ const body = await response.text().catch(() => "");
1564
+ throw new ZkkycError(`Reclaim session creation failed: ${response.status} ${body}`, {
1565
+ code: "RECLAIM_SESSION_ENDPOINT_FAILED",
1566
+ context: { status: response.status, platform }
1567
+ });
1568
1568
  }
1569
- reclaimProofRequest.addContext(
1570
- walletAddress,
1571
- contextDescription ?? `Social verification for ${socialName}`
1572
- );
1569
+ const data = await response.json();
1570
+ if (!data?.config || !data?.sessionId) {
1571
+ throw new ZkkycError("Reclaim session service returned an incomplete response", {
1572
+ code: "RECLAIM_SESSION_ENDPOINT_FAILED",
1573
+ context: { platform }
1574
+ });
1575
+ }
1576
+ reclaimProofRequest = await ReclaimProofRequest.fromJsonString(data.config);
1577
+ sessionId = data.sessionId;
1573
1578
  requestUrl = await reclaimProofRequest.getRequestUrl();
1574
1579
  onStatus?.({ type: "session_created", sessionId, requestUrl });
1575
1580
  }