@p2pdotme/sdk 1.2.1 → 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.cjs CHANGED
@@ -32,12 +32,15 @@ var zkkyc_exports = {};
32
32
  __export(zkkyc_exports, {
33
33
  DEFAULT_RECLAIM_PROVIDER_IDS: () => DEFAULT_RECLAIM_PROVIDER_IDS,
34
34
  RECLAIM_APP_LINKS: () => RECLAIM_APP_LINKS,
35
+ SIMPLE_KYC_DEFAULT_TENANT: () => SIMPLE_KYC_DEFAULT_TENANT,
35
36
  SOCIAL_PLATFORM_NAMES: () => SOCIAL_PLATFORM_NAMES,
36
37
  ZK_PASSPORT_APP_LINKS: () => ZK_PASSPORT_APP_LINKS,
37
38
  ZkkycError: () => ZkkycError,
38
39
  createReclaimFlow: () => createReclaimFlow,
40
+ createSimpleKycFlow: () => createSimpleKycFlow,
39
41
  createZkPassportFlow: () => createZkPassportFlow,
40
- createZkkyc: () => createZkkyc
42
+ createZkkyc: () => createZkkyc,
43
+ resumeSimpleKycFlow: () => resumeSimpleKycFlow
41
44
  });
42
45
  module.exports = __toCommonJS(zkkyc_exports);
43
46
 
@@ -169,6 +172,20 @@ var ZodZkPassportRegisterParamsSchema = import_zod2.z.object({
169
172
  params: ZodSolidityVerifierParametersSchema,
170
173
  isIDCard: import_zod2.z.boolean()
171
174
  });
175
+ var ZodSimpleKycSubmitParamsSchema = import_zod2.z.object({
176
+ /** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
177
+ nullifier: import_zod2.z.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
178
+ message: "nullifier must be a bytes32 hex string"
179
+ }),
180
+ /** Remaining limit in micro-USDC (part of the signed struct). */
181
+ limit: import_zod2.z.bigint(),
182
+ /** Attestation expiry (unix seconds). */
183
+ expiry: import_zod2.z.bigint(),
184
+ /** 65-byte secp256k1 signature (hex). */
185
+ signature: import_zod2.z.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
186
+ message: "signature must be a hex string"
187
+ })
188
+ });
172
189
 
173
190
  // src/contracts/abis/index.ts
174
191
  var import_viem2 = require("viem");
@@ -947,6 +964,32 @@ var reputationManagerAbi = [
947
964
  outputs: [],
948
965
  stateMutability: "nonpayable",
949
966
  type: "function"
967
+ },
968
+ {
969
+ inputs: [
970
+ { internalType: "bytes32", name: "nullifier", type: "bytes32" },
971
+ { internalType: "uint256", name: "limit", type: "uint256" },
972
+ { internalType: "uint256", name: "expiry", type: "uint256" },
973
+ { internalType: "bytes", name: "signature", type: "bytes" }
974
+ ],
975
+ name: "submitKycAttestation",
976
+ outputs: [],
977
+ stateMutability: "nonpayable",
978
+ type: "function"
979
+ },
980
+ {
981
+ inputs: [],
982
+ name: "kycRp",
983
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
984
+ stateMutability: "view",
985
+ type: "function"
986
+ },
987
+ {
988
+ inputs: [{ internalType: "address", name: "", type: "address" }],
989
+ name: "kycVerified",
990
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
991
+ stateMutability: "view",
992
+ type: "function"
950
993
  }
951
994
  ];
952
995
 
@@ -1036,6 +1079,33 @@ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
1036
1079
  )()
1037
1080
  );
1038
1081
  }
1082
+ function prepareSubmitKycAttestation(reputationManagerAddress, params) {
1083
+ return validate(
1084
+ ZodSimpleKycSubmitParamsSchema,
1085
+ params,
1086
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
1087
+ ).andThen(
1088
+ (validated) => import_neverthrow2.Result.fromThrowable(
1089
+ () => ({
1090
+ to: reputationManagerAddress,
1091
+ data: (0, import_viem3.encodeFunctionData)({
1092
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
1093
+ functionName: "submitKycAttestation",
1094
+ args: [
1095
+ validated.nullifier,
1096
+ validated.limit,
1097
+ validated.expiry,
1098
+ validated.signature
1099
+ ]
1100
+ })
1101
+ }),
1102
+ (error) => new ZkkycError("Failed to encode submitKycAttestation", {
1103
+ code: "ENCODE_ERROR",
1104
+ cause: error
1105
+ })
1106
+ )()
1107
+ );
1108
+ }
1039
1109
  function prepareZkPassportRegister(reputationManagerAddress, params) {
1040
1110
  return validate(
1041
1111
  ZodZkPassportRegisterParamsSchema,
@@ -1083,7 +1153,8 @@ function createZkkyc(config) {
1083
1153
  return {
1084
1154
  prepareSocialVerify: (params) => prepareSocialVerify(reputationManagerAddress, params),
1085
1155
  prepareSubmitAnonAadharProof: (params) => prepareSubmitAnonAadharProof(reputationManagerAddress, params),
1086
- prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params)
1156
+ prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params),
1157
+ prepareSubmitKycAttestation: (params) => prepareSubmitKycAttestation(reputationManagerAddress, params)
1087
1158
  };
1088
1159
  }
1089
1160
 
@@ -1093,7 +1164,8 @@ var DEFAULT_RECLAIM_PROVIDER_IDS = {
1093
1164
  github: "033f0c06-2eb3-48c8-894c-5599c3356d1c",
1094
1165
  x: "aad95818-f726-4a34-be97-8d1f47631b03",
1095
1166
  instagram: "7e5b59a9-56c5-490c-a169-82a443f9b507",
1096
- facebook: "2701510b-c835-4820-84f0-d9e74569656b"
1167
+ facebook: "2701510b-c835-4820-84f0-d9e74569656b",
1168
+ binance: "7e40c007-f432-4d47-ac00-3e0762f8a7a0"
1097
1169
  };
1098
1170
  var ZK_PASSPORT_APP_LINKS = {
1099
1171
  IOS: "https://apps.apple.com/us/app/zkpassport/id6477371975",
@@ -1102,6 +1174,7 @@ var ZK_PASSPORT_APP_LINKS = {
1102
1174
  var RECLAIM_APP_LINKS = {
1103
1175
  ANDROID: "https://play.google.com/store/apps/details?id=org.reclaimprotocol.app"
1104
1176
  };
1177
+ var SIMPLE_KYC_DEFAULT_TENANT = "p2p-reputation";
1105
1178
 
1106
1179
  // src/zkkyc/orchestrators/reclaim.ts
1107
1180
  var import_neverthrow3 = require("neverthrow");
@@ -1112,7 +1185,8 @@ var SOCIAL_PLATFORM_NAMES = {
1112
1185
  github: "GitHub",
1113
1186
  x: "X",
1114
1187
  instagram: "Instagram",
1115
- facebook: "Facebook"
1188
+ facebook: "Facebook",
1189
+ binance: "Binance"
1116
1190
  };
1117
1191
 
1118
1192
  // src/zkkyc/orchestrators/reclaim.ts
@@ -1142,12 +1216,19 @@ function createReclaimFlow(params) {
1142
1216
  } = params;
1143
1217
  const socialName = SOCIAL_PLATFORM_NAMES[platform];
1144
1218
  const providerId = providerIds[platform];
1219
+ let reclaimProofRequest = null;
1145
1220
  let sessionId;
1221
+ let requestUrl = "";
1146
1222
  if (existingSessionId) {
1147
1223
  sessionId = existingSessionId;
1148
1224
  } else {
1149
- const reclaimProofRequest = await ReclaimProofRequest.init(appId, appSecret, providerId, {
1150
- launchOptions: { canUseDeferredDeepLinksFlow: true }
1225
+ reclaimProofRequest = await ReclaimProofRequest.init(appId, appSecret, providerId, {
1226
+ launchOptions: {
1227
+ canUseDeferredDeepLinksFlow: true,
1228
+ verificationMode: "app"
1229
+ },
1230
+ useAppClip: true,
1231
+ log: true
1151
1232
  });
1152
1233
  const statusUrl = reclaimProofRequest.getStatusUrl();
1153
1234
  sessionId = statusUrl.split("/").pop() || "";
@@ -1161,54 +1242,72 @@ function createReclaimFlow(params) {
1161
1242
  walletAddress,
1162
1243
  contextDescription ?? `Social verification for ${socialName}`
1163
1244
  );
1164
- const requestUrl = await reclaimProofRequest.getRequestUrl();
1245
+ requestUrl = await reclaimProofRequest.getRequestUrl();
1165
1246
  onStatus?.({ type: "session_created", sessionId, requestUrl });
1166
- if (typeof window !== "undefined") {
1167
- reclaimProofRequest.triggerReclaimFlow();
1168
- }
1169
1247
  }
1170
- onStatus?.({ type: "polling_started", sessionId });
1171
- while (true) {
1172
- if (signal?.aborted) {
1173
- throw new ZkkycError("Reclaim polling aborted", {
1174
- code: "RECLAIM_POLLING_ABORTED"
1175
- });
1248
+ let aborted = false;
1249
+ const pollForProof = async () => {
1250
+ if (reclaimProofRequest && typeof window !== "undefined") {
1251
+ reclaimProofRequest.triggerReclaimFlow({ verificationMode: "app" });
1176
1252
  }
1177
- const response = await fetch(`${RECLAIM_SESSION_API}/${sessionId}`);
1178
- const data = await response.json();
1179
- if (data?.session?.proofs?.length > 0) {
1180
- const proofs = data.session.proofs;
1181
- onStatus?.({ type: "proof_received" });
1182
- if (platform === "github" && proofs.length > 0) {
1183
- const first = proofs[0];
1184
- if (first?.publicData && Object.keys(first.publicData).length === 0) {
1185
- throw new ZkkycError("GitHub verification eligibility criteria not met", {
1186
- code: "RECLAIM_PROOF_INVALID"
1187
- });
1253
+ onStatus?.({ type: "polling_started", sessionId });
1254
+ while (true) {
1255
+ if (aborted || signal?.aborted) {
1256
+ throw new ZkkycError("Reclaim polling aborted", {
1257
+ code: "RECLAIM_POLLING_ABORTED"
1258
+ });
1259
+ }
1260
+ const response = await fetch(`${RECLAIM_SESSION_API}/${sessionId}`);
1261
+ const data = await response.json();
1262
+ if (data?.session?.proofs?.length > 0) {
1263
+ const proofs = data.session.proofs;
1264
+ onStatus?.({ type: "proof_received" });
1265
+ if (platform === "github" && proofs.length > 0) {
1266
+ const first = proofs[0];
1267
+ if (first?.publicData && Object.keys(first.publicData).length === 0) {
1268
+ throw new ZkkycError("GitHub verification eligibility criteria not met", {
1269
+ code: "RECLAIM_PROOF_INVALID"
1270
+ });
1271
+ }
1188
1272
  }
1273
+ const transformedProofs = proofs.map((proof) => transformForOnchain(proof));
1274
+ onStatus?.({ type: "proof_transformed" });
1275
+ return {
1276
+ _socialName: socialName,
1277
+ proofs: transformedProofs,
1278
+ sessionId
1279
+ };
1189
1280
  }
1190
- const transformedProofs = proofs.map((proof) => transformForOnchain(proof));
1191
- onStatus?.({ type: "proof_transformed" });
1192
- return {
1193
- _socialName: socialName,
1194
- proofs: transformedProofs,
1195
- sessionId
1196
- };
1197
- }
1198
- if (data?.message?.includes("Session not found")) {
1199
- throw new ZkkycError("Reclaim session not found", {
1200
- code: "RECLAIM_SESSION_NOT_FOUND",
1201
- context: { sessionId }
1202
- });
1281
+ if (data?.message?.includes("Session not found")) {
1282
+ throw new ZkkycError("Reclaim session not found", {
1283
+ code: "RECLAIM_SESSION_NOT_FOUND",
1284
+ context: { sessionId }
1285
+ });
1286
+ }
1287
+ if (data?.session?.statusV2 === "PROOF_GENERATION_FAILED") {
1288
+ throw new ZkkycError("Reclaim proof generation failed", {
1289
+ code: "RECLAIM_PROOF_GENERATION_FAILED",
1290
+ context: { sessionId }
1291
+ });
1292
+ }
1293
+ await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs));
1203
1294
  }
1204
- if (data?.session?.statusV2 === "PROOF_GENERATION_FAILED") {
1205
- throw new ZkkycError("Reclaim proof generation failed", {
1206
- code: "RECLAIM_PROOF_GENERATION_FAILED",
1207
- context: { sessionId }
1295
+ };
1296
+ const session = {
1297
+ sessionId,
1298
+ requestUrl,
1299
+ start: () => import_neverthrow3.ResultAsync.fromPromise(pollForProof(), (error) => {
1300
+ if (error instanceof ZkkycError) return error;
1301
+ return new ZkkycError("Reclaim verification flow failed", {
1302
+ code: "RECLAIM_INIT_FAILED",
1303
+ cause: error
1208
1304
  });
1305
+ }),
1306
+ abort: () => {
1307
+ aborted = true;
1209
1308
  }
1210
- await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs));
1211
- }
1309
+ };
1310
+ return session;
1212
1311
  })(),
1213
1312
  (error) => {
1214
1313
  if (error instanceof ZkkycError) return error;
@@ -1220,10 +1319,90 @@ function createReclaimFlow(params) {
1220
1319
  );
1221
1320
  }
1222
1321
 
1223
- // src/zkkyc/orchestrators/zk-passport.ts
1322
+ // src/zkkyc/orchestrators/simple-kyc.ts
1224
1323
  var import_neverthrow4 = require("neverthrow");
1225
- function createZkPassportFlow(params) {
1324
+ function createSimpleKycFlow(params) {
1325
+ const { baseUrl, walletAddress, tenant, redirectUrl, country, state, onStatus } = params;
1226
1326
  return import_neverthrow4.ResultAsync.fromPromise(
1327
+ (async () => {
1328
+ const res = await fetch(`${baseUrl}/v1/widget/public-sessions`, {
1329
+ method: "POST",
1330
+ headers: { "Content-Type": "application/json" },
1331
+ body: JSON.stringify({
1332
+ wallet_pubkey: walletAddress,
1333
+ redirect_uri: redirectUrl,
1334
+ tenant,
1335
+ country,
1336
+ state
1337
+ })
1338
+ });
1339
+ if (!res.ok) {
1340
+ const body = await res.text();
1341
+ throw new ZkkycError(`simple-kyc session creation failed: ${res.status} ${body}`, {
1342
+ code: "SIMPLE_KYC_SESSION_FAILED",
1343
+ context: { status: res.status }
1344
+ });
1345
+ }
1346
+ const data = await res.json();
1347
+ const widgetUrl = data.widget_url;
1348
+ onStatus?.({ type: "session_created", widgetUrl });
1349
+ return {
1350
+ widgetUrl,
1351
+ redirect: () => {
1352
+ if (typeof window !== "undefined") {
1353
+ onStatus?.({ type: "redirecting", widgetUrl });
1354
+ window.location.href = widgetUrl;
1355
+ }
1356
+ }
1357
+ };
1358
+ })(),
1359
+ (error) => {
1360
+ if (error instanceof ZkkycError) return error;
1361
+ return new ZkkycError("simple-kyc flow failed to start", {
1362
+ code: "SIMPLE_KYC_SESSION_FAILED",
1363
+ cause: error
1364
+ });
1365
+ }
1366
+ );
1367
+ }
1368
+ function resumeSimpleKycFlow(args) {
1369
+ return import_neverthrow4.ResultAsync.fromPromise(
1370
+ (async () => {
1371
+ const res = await fetch(`${args.baseUrl}/v1/widget/attestation`, {
1372
+ method: "POST",
1373
+ headers: { "Content-Type": "application/json" },
1374
+ body: JSON.stringify({ code: args.code })
1375
+ });
1376
+ if (!res.ok) {
1377
+ const body = await res.text();
1378
+ throw new ZkkycError(`simple-kyc attestation redemption failed: ${res.status} ${body}`, {
1379
+ code: "SIMPLE_KYC_REDEEM_FAILED",
1380
+ context: { status: res.status }
1381
+ });
1382
+ }
1383
+ const d = await res.json();
1384
+ return {
1385
+ nullifier: d.nullifier,
1386
+ limit: BigInt(d.limit),
1387
+ expiry: BigInt(d.expiry),
1388
+ signature: d.signature,
1389
+ identityHash: d.identity_hash
1390
+ };
1391
+ })(),
1392
+ (error) => {
1393
+ if (error instanceof ZkkycError) return error;
1394
+ return new ZkkycError("simple-kyc attestation redemption failed", {
1395
+ code: "SIMPLE_KYC_REDEEM_FAILED",
1396
+ cause: error
1397
+ });
1398
+ }
1399
+ );
1400
+ }
1401
+
1402
+ // src/zkkyc/orchestrators/zk-passport.ts
1403
+ var import_neverthrow5 = require("neverthrow");
1404
+ function createZkPassportFlow(params) {
1405
+ return import_neverthrow5.ResultAsync.fromPromise(
1227
1406
  (async () => {
1228
1407
  const mod = await import("@zkpassport/sdk").catch(() => {
1229
1408
  throw new ZkkycError(
@@ -1319,7 +1498,7 @@ function createZkPassportFlow(params) {
1319
1498
  });
1320
1499
  const session = {
1321
1500
  url,
1322
- result: import_neverthrow4.ResultAsync.fromPromise(resultPromise, (error) => {
1501
+ result: import_neverthrow5.ResultAsync.fromPromise(resultPromise, (error) => {
1323
1502
  if (error instanceof ZkkycError) return error;
1324
1503
  return new ZkkycError("ZK Passport flow failed", {
1325
1504
  code: "ZK_PASSPORT_VERIFICATION_FAILED",
@@ -1345,11 +1524,14 @@ function createZkPassportFlow(params) {
1345
1524
  0 && (module.exports = {
1346
1525
  DEFAULT_RECLAIM_PROVIDER_IDS,
1347
1526
  RECLAIM_APP_LINKS,
1527
+ SIMPLE_KYC_DEFAULT_TENANT,
1348
1528
  SOCIAL_PLATFORM_NAMES,
1349
1529
  ZK_PASSPORT_APP_LINKS,
1350
1530
  ZkkycError,
1351
1531
  createReclaimFlow,
1532
+ createSimpleKycFlow,
1352
1533
  createZkPassportFlow,
1353
- createZkkyc
1534
+ createZkkyc,
1535
+ resumeSimpleKycFlow
1354
1536
  });
1355
1537
  //# sourceMappingURL=zkkyc.cjs.map