@p2pdotme/sdk 1.2.0 → 1.2.2

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.mjs CHANGED
@@ -126,6 +126,20 @@ var ZodZkPassportRegisterParamsSchema = z2.object({
126
126
  params: ZodSolidityVerifierParametersSchema,
127
127
  isIDCard: z2.boolean()
128
128
  });
129
+ var ZodSimpleKycSubmitParamsSchema = z2.object({
130
+ /** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
131
+ nullifier: z2.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
132
+ message: "nullifier must be a bytes32 hex string"
133
+ }),
134
+ /** Remaining limit in micro-USDC (part of the signed struct). */
135
+ limit: z2.bigint(),
136
+ /** Attestation expiry (unix seconds). */
137
+ expiry: z2.bigint(),
138
+ /** 65-byte secp256k1 signature (hex). */
139
+ signature: z2.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
140
+ message: "signature must be a hex string"
141
+ })
142
+ });
129
143
 
130
144
  // src/contracts/abis/index.ts
131
145
  import { erc20Abi } from "viem";
@@ -904,6 +918,32 @@ var reputationManagerAbi = [
904
918
  outputs: [],
905
919
  stateMutability: "nonpayable",
906
920
  type: "function"
921
+ },
922
+ {
923
+ inputs: [
924
+ { internalType: "bytes32", name: "nullifier", type: "bytes32" },
925
+ { internalType: "uint256", name: "limit", type: "uint256" },
926
+ { internalType: "uint256", name: "expiry", type: "uint256" },
927
+ { internalType: "bytes", name: "signature", type: "bytes" }
928
+ ],
929
+ name: "submitKycAttestation",
930
+ outputs: [],
931
+ stateMutability: "nonpayable",
932
+ type: "function"
933
+ },
934
+ {
935
+ inputs: [],
936
+ name: "kycRp",
937
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
938
+ stateMutability: "view",
939
+ type: "function"
940
+ },
941
+ {
942
+ inputs: [{ internalType: "address", name: "", type: "address" }],
943
+ name: "kycVerified",
944
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
945
+ stateMutability: "view",
946
+ type: "function"
907
947
  }
908
948
  ];
909
949
 
@@ -993,6 +1033,33 @@ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
993
1033
  )()
994
1034
  );
995
1035
  }
1036
+ function prepareSubmitKycAttestation(reputationManagerAddress, params) {
1037
+ return validate(
1038
+ ZodSimpleKycSubmitParamsSchema,
1039
+ params,
1040
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
1041
+ ).andThen(
1042
+ (validated) => Result.fromThrowable(
1043
+ () => ({
1044
+ to: reputationManagerAddress,
1045
+ data: encodeFunctionData({
1046
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
1047
+ functionName: "submitKycAttestation",
1048
+ args: [
1049
+ validated.nullifier,
1050
+ validated.limit,
1051
+ validated.expiry,
1052
+ validated.signature
1053
+ ]
1054
+ })
1055
+ }),
1056
+ (error) => new ZkkycError("Failed to encode submitKycAttestation", {
1057
+ code: "ENCODE_ERROR",
1058
+ cause: error
1059
+ })
1060
+ )()
1061
+ );
1062
+ }
996
1063
  function prepareZkPassportRegister(reputationManagerAddress, params) {
997
1064
  return validate(
998
1065
  ZodZkPassportRegisterParamsSchema,
@@ -1040,7 +1107,8 @@ function createZkkyc(config) {
1040
1107
  return {
1041
1108
  prepareSocialVerify: (params) => prepareSocialVerify(reputationManagerAddress, params),
1042
1109
  prepareSubmitAnonAadharProof: (params) => prepareSubmitAnonAadharProof(reputationManagerAddress, params),
1043
- prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params)
1110
+ prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params),
1111
+ prepareSubmitKycAttestation: (params) => prepareSubmitKycAttestation(reputationManagerAddress, params)
1044
1112
  };
1045
1113
  }
1046
1114
 
@@ -1050,7 +1118,8 @@ var DEFAULT_RECLAIM_PROVIDER_IDS = {
1050
1118
  github: "033f0c06-2eb3-48c8-894c-5599c3356d1c",
1051
1119
  x: "aad95818-f726-4a34-be97-8d1f47631b03",
1052
1120
  instagram: "7e5b59a9-56c5-490c-a169-82a443f9b507",
1053
- facebook: "2701510b-c835-4820-84f0-d9e74569656b"
1121
+ facebook: "2701510b-c835-4820-84f0-d9e74569656b",
1122
+ binance: "7e40c007-f432-4d47-ac00-3e0762f8a7a0"
1054
1123
  };
1055
1124
  var ZK_PASSPORT_APP_LINKS = {
1056
1125
  IOS: "https://apps.apple.com/us/app/zkpassport/id6477371975",
@@ -1059,6 +1128,7 @@ var ZK_PASSPORT_APP_LINKS = {
1059
1128
  var RECLAIM_APP_LINKS = {
1060
1129
  ANDROID: "https://play.google.com/store/apps/details?id=org.reclaimprotocol.app"
1061
1130
  };
1131
+ var SIMPLE_KYC_DEFAULT_TENANT = "p2p-reputation";
1062
1132
 
1063
1133
  // src/zkkyc/orchestrators/reclaim.ts
1064
1134
  import { ResultAsync } from "neverthrow";
@@ -1069,7 +1139,8 @@ var SOCIAL_PLATFORM_NAMES = {
1069
1139
  github: "GitHub",
1070
1140
  x: "X",
1071
1141
  instagram: "Instagram",
1072
- facebook: "Facebook"
1142
+ facebook: "Facebook",
1143
+ binance: "Binance"
1073
1144
  };
1074
1145
 
1075
1146
  // src/zkkyc/orchestrators/reclaim.ts
@@ -1099,12 +1170,19 @@ function createReclaimFlow(params) {
1099
1170
  } = params;
1100
1171
  const socialName = SOCIAL_PLATFORM_NAMES[platform];
1101
1172
  const providerId = providerIds[platform];
1173
+ let reclaimProofRequest = null;
1102
1174
  let sessionId;
1175
+ let requestUrl = "";
1103
1176
  if (existingSessionId) {
1104
1177
  sessionId = existingSessionId;
1105
1178
  } else {
1106
- const reclaimProofRequest = await ReclaimProofRequest.init(appId, appSecret, providerId, {
1107
- launchOptions: { canUseDeferredDeepLinksFlow: true }
1179
+ reclaimProofRequest = await ReclaimProofRequest.init(appId, appSecret, providerId, {
1180
+ launchOptions: {
1181
+ canUseDeferredDeepLinksFlow: true,
1182
+ verificationMode: "app"
1183
+ },
1184
+ useAppClip: true,
1185
+ log: true
1108
1186
  });
1109
1187
  const statusUrl = reclaimProofRequest.getStatusUrl();
1110
1188
  sessionId = statusUrl.split("/").pop() || "";
@@ -1118,54 +1196,72 @@ function createReclaimFlow(params) {
1118
1196
  walletAddress,
1119
1197
  contextDescription ?? `Social verification for ${socialName}`
1120
1198
  );
1121
- const requestUrl = await reclaimProofRequest.getRequestUrl();
1199
+ requestUrl = await reclaimProofRequest.getRequestUrl();
1122
1200
  onStatus?.({ type: "session_created", sessionId, requestUrl });
1123
- if (typeof window !== "undefined") {
1124
- reclaimProofRequest.triggerReclaimFlow();
1125
- }
1126
1201
  }
1127
- onStatus?.({ type: "polling_started", sessionId });
1128
- while (true) {
1129
- if (signal?.aborted) {
1130
- throw new ZkkycError("Reclaim polling aborted", {
1131
- code: "RECLAIM_POLLING_ABORTED"
1132
- });
1202
+ let aborted = false;
1203
+ const pollForProof = async () => {
1204
+ if (reclaimProofRequest && typeof window !== "undefined") {
1205
+ reclaimProofRequest.triggerReclaimFlow({ verificationMode: "app" });
1133
1206
  }
1134
- const response = await fetch(`${RECLAIM_SESSION_API}/${sessionId}`);
1135
- const data = await response.json();
1136
- if (data?.session?.proofs?.length > 0) {
1137
- const proofs = data.session.proofs;
1138
- onStatus?.({ type: "proof_received" });
1139
- if (platform === "github" && proofs.length > 0) {
1140
- const first = proofs[0];
1141
- if (first?.publicData && Object.keys(first.publicData).length === 0) {
1142
- throw new ZkkycError("GitHub verification eligibility criteria not met", {
1143
- code: "RECLAIM_PROOF_INVALID"
1144
- });
1207
+ onStatus?.({ type: "polling_started", sessionId });
1208
+ while (true) {
1209
+ if (aborted || signal?.aborted) {
1210
+ throw new ZkkycError("Reclaim polling aborted", {
1211
+ code: "RECLAIM_POLLING_ABORTED"
1212
+ });
1213
+ }
1214
+ const response = await fetch(`${RECLAIM_SESSION_API}/${sessionId}`);
1215
+ const data = await response.json();
1216
+ if (data?.session?.proofs?.length > 0) {
1217
+ const proofs = data.session.proofs;
1218
+ onStatus?.({ type: "proof_received" });
1219
+ if (platform === "github" && proofs.length > 0) {
1220
+ const first = proofs[0];
1221
+ if (first?.publicData && Object.keys(first.publicData).length === 0) {
1222
+ throw new ZkkycError("GitHub verification eligibility criteria not met", {
1223
+ code: "RECLAIM_PROOF_INVALID"
1224
+ });
1225
+ }
1145
1226
  }
1227
+ const transformedProofs = proofs.map((proof) => transformForOnchain(proof));
1228
+ onStatus?.({ type: "proof_transformed" });
1229
+ return {
1230
+ _socialName: socialName,
1231
+ proofs: transformedProofs,
1232
+ sessionId
1233
+ };
1146
1234
  }
1147
- const transformedProofs = proofs.map((proof) => transformForOnchain(proof));
1148
- onStatus?.({ type: "proof_transformed" });
1149
- return {
1150
- _socialName: socialName,
1151
- proofs: transformedProofs,
1152
- sessionId
1153
- };
1154
- }
1155
- if (data?.message?.includes("Session not found")) {
1156
- throw new ZkkycError("Reclaim session not found", {
1157
- code: "RECLAIM_SESSION_NOT_FOUND",
1158
- context: { sessionId }
1159
- });
1235
+ if (data?.message?.includes("Session not found")) {
1236
+ throw new ZkkycError("Reclaim session not found", {
1237
+ code: "RECLAIM_SESSION_NOT_FOUND",
1238
+ context: { sessionId }
1239
+ });
1240
+ }
1241
+ if (data?.session?.statusV2 === "PROOF_GENERATION_FAILED") {
1242
+ throw new ZkkycError("Reclaim proof generation failed", {
1243
+ code: "RECLAIM_PROOF_GENERATION_FAILED",
1244
+ context: { sessionId }
1245
+ });
1246
+ }
1247
+ await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs));
1160
1248
  }
1161
- if (data?.session?.statusV2 === "PROOF_GENERATION_FAILED") {
1162
- throw new ZkkycError("Reclaim proof generation failed", {
1163
- code: "RECLAIM_PROOF_GENERATION_FAILED",
1164
- context: { sessionId }
1249
+ };
1250
+ const session = {
1251
+ sessionId,
1252
+ requestUrl,
1253
+ start: () => ResultAsync.fromPromise(pollForProof(), (error) => {
1254
+ if (error instanceof ZkkycError) return error;
1255
+ return new ZkkycError("Reclaim verification flow failed", {
1256
+ code: "RECLAIM_INIT_FAILED",
1257
+ cause: error
1165
1258
  });
1259
+ }),
1260
+ abort: () => {
1261
+ aborted = true;
1166
1262
  }
1167
- await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs));
1168
- }
1263
+ };
1264
+ return session;
1169
1265
  })(),
1170
1266
  (error) => {
1171
1267
  if (error instanceof ZkkycError) return error;
@@ -1177,10 +1273,90 @@ function createReclaimFlow(params) {
1177
1273
  );
1178
1274
  }
1179
1275
 
1180
- // src/zkkyc/orchestrators/zk-passport.ts
1276
+ // src/zkkyc/orchestrators/simple-kyc.ts
1181
1277
  import { ResultAsync as ResultAsync2 } from "neverthrow";
1182
- function createZkPassportFlow(params) {
1278
+ function createSimpleKycFlow(params) {
1279
+ const { baseUrl, walletAddress, tenant, redirectUrl, country, state, onStatus } = params;
1183
1280
  return ResultAsync2.fromPromise(
1281
+ (async () => {
1282
+ const res = await fetch(`${baseUrl}/v1/widget/public-sessions`, {
1283
+ method: "POST",
1284
+ headers: { "Content-Type": "application/json" },
1285
+ body: JSON.stringify({
1286
+ wallet_pubkey: walletAddress,
1287
+ redirect_uri: redirectUrl,
1288
+ tenant,
1289
+ country,
1290
+ state
1291
+ })
1292
+ });
1293
+ if (!res.ok) {
1294
+ const body = await res.text();
1295
+ throw new ZkkycError(`simple-kyc session creation failed: ${res.status} ${body}`, {
1296
+ code: "SIMPLE_KYC_SESSION_FAILED",
1297
+ context: { status: res.status }
1298
+ });
1299
+ }
1300
+ const data = await res.json();
1301
+ const widgetUrl = data.widget_url;
1302
+ onStatus?.({ type: "session_created", widgetUrl });
1303
+ return {
1304
+ widgetUrl,
1305
+ redirect: () => {
1306
+ if (typeof window !== "undefined") {
1307
+ onStatus?.({ type: "redirecting", widgetUrl });
1308
+ window.location.href = widgetUrl;
1309
+ }
1310
+ }
1311
+ };
1312
+ })(),
1313
+ (error) => {
1314
+ if (error instanceof ZkkycError) return error;
1315
+ return new ZkkycError("simple-kyc flow failed to start", {
1316
+ code: "SIMPLE_KYC_SESSION_FAILED",
1317
+ cause: error
1318
+ });
1319
+ }
1320
+ );
1321
+ }
1322
+ function resumeSimpleKycFlow(args) {
1323
+ return ResultAsync2.fromPromise(
1324
+ (async () => {
1325
+ const res = await fetch(`${args.baseUrl}/v1/widget/attestation`, {
1326
+ method: "POST",
1327
+ headers: { "Content-Type": "application/json" },
1328
+ body: JSON.stringify({ code: args.code })
1329
+ });
1330
+ if (!res.ok) {
1331
+ const body = await res.text();
1332
+ throw new ZkkycError(`simple-kyc attestation redemption failed: ${res.status} ${body}`, {
1333
+ code: "SIMPLE_KYC_REDEEM_FAILED",
1334
+ context: { status: res.status }
1335
+ });
1336
+ }
1337
+ const d = await res.json();
1338
+ return {
1339
+ nullifier: d.nullifier,
1340
+ limit: BigInt(d.limit),
1341
+ expiry: BigInt(d.expiry),
1342
+ signature: d.signature,
1343
+ identityHash: d.identity_hash
1344
+ };
1345
+ })(),
1346
+ (error) => {
1347
+ if (error instanceof ZkkycError) return error;
1348
+ return new ZkkycError("simple-kyc attestation redemption failed", {
1349
+ code: "SIMPLE_KYC_REDEEM_FAILED",
1350
+ cause: error
1351
+ });
1352
+ }
1353
+ );
1354
+ }
1355
+
1356
+ // src/zkkyc/orchestrators/zk-passport.ts
1357
+ import { ResultAsync as ResultAsync3 } from "neverthrow";
1358
+ function createZkPassportFlow(params) {
1359
+ return ResultAsync3.fromPromise(
1184
1360
  (async () => {
1185
1361
  const mod = await import("@zkpassport/sdk").catch(() => {
1186
1362
  throw new ZkkycError(
@@ -1276,7 +1452,7 @@ function createZkPassportFlow(params) {
1276
1452
  });
1277
1453
  const session = {
1278
1454
  url,
1279
- result: ResultAsync2.fromPromise(resultPromise, (error) => {
1455
+ result: ResultAsync3.fromPromise(resultPromise, (error) => {
1280
1456
  if (error instanceof ZkkycError) return error;
1281
1457
  return new ZkkycError("ZK Passport flow failed", {
1282
1458
  code: "ZK_PASSPORT_VERIFICATION_FAILED",
@@ -1301,11 +1477,14 @@ function createZkPassportFlow(params) {
1301
1477
  export {
1302
1478
  DEFAULT_RECLAIM_PROVIDER_IDS,
1303
1479
  RECLAIM_APP_LINKS,
1480
+ SIMPLE_KYC_DEFAULT_TENANT,
1304
1481
  SOCIAL_PLATFORM_NAMES,
1305
1482
  ZK_PASSPORT_APP_LINKS,
1306
1483
  ZkkycError,
1307
1484
  createReclaimFlow,
1485
+ createSimpleKycFlow,
1308
1486
  createZkPassportFlow,
1309
- createZkkyc
1487
+ createZkkyc,
1488
+ resumeSimpleKycFlow
1310
1489
  };
1311
1490
  //# sourceMappingURL=zkkyc.mjs.map