@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/react.d.cts CHANGED
@@ -16,7 +16,7 @@ declare class SdkError<TCode extends string = string> extends Error {
16
16
  });
17
17
  }
18
18
 
19
- 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" | "PEER_DEPENDENCY_MISSING";
19
+ 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" | "PEER_DEPENDENCY_MISSING";
20
20
  declare class ZkkycError extends SdkError<ZkkycErrorCode> {
21
21
  constructor(message: string, options: {
22
22
  code: ZkkycErrorCode;
@@ -73,6 +73,13 @@ declare const ZodZkPassportRegisterParamsSchema: z.ZodObject<{
73
73
  isIDCard: z.ZodBoolean;
74
74
  }, z.core.$strip>;
75
75
  type ZkPassportRegisterParams = z.infer<typeof ZodZkPassportRegisterParamsSchema>;
76
+ declare const ZodSimpleKycSubmitParamsSchema: z.ZodObject<{
77
+ nullifier: z.ZodString;
78
+ limit: z.ZodBigInt;
79
+ expiry: z.ZodBigInt;
80
+ signature: z.ZodString;
81
+ }, z.core.$strip>;
82
+ type SimpleKycSubmitParams = z.infer<typeof ZodSimpleKycSubmitParamsSchema>;
76
83
 
77
84
  interface Zkkyc {
78
85
  prepareSocialVerify(params: SocialVerifyParams): Result<{
@@ -87,6 +94,10 @@ interface Zkkyc {
87
94
  to: Address;
88
95
  data: `0x${string}`;
89
96
  }, ZkkycError>;
97
+ prepareSubmitKycAttestation(params: SimpleKycSubmitParams): Result<{
98
+ to: Address;
99
+ data: `0x${string}`;
100
+ }, ZkkycError>;
90
101
  }
91
102
 
92
103
  /**
package/dist/react.d.ts CHANGED
@@ -16,7 +16,7 @@ declare class SdkError<TCode extends string = string> extends Error {
16
16
  });
17
17
  }
18
18
 
19
- 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" | "PEER_DEPENDENCY_MISSING";
19
+ 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" | "PEER_DEPENDENCY_MISSING";
20
20
  declare class ZkkycError extends SdkError<ZkkycErrorCode> {
21
21
  constructor(message: string, options: {
22
22
  code: ZkkycErrorCode;
@@ -73,6 +73,13 @@ declare const ZodZkPassportRegisterParamsSchema: z.ZodObject<{
73
73
  isIDCard: z.ZodBoolean;
74
74
  }, z.core.$strip>;
75
75
  type ZkPassportRegisterParams = z.infer<typeof ZodZkPassportRegisterParamsSchema>;
76
+ declare const ZodSimpleKycSubmitParamsSchema: z.ZodObject<{
77
+ nullifier: z.ZodString;
78
+ limit: z.ZodBigInt;
79
+ expiry: z.ZodBigInt;
80
+ signature: z.ZodString;
81
+ }, z.core.$strip>;
82
+ type SimpleKycSubmitParams = z.infer<typeof ZodSimpleKycSubmitParamsSchema>;
76
83
 
77
84
  interface Zkkyc {
78
85
  prepareSocialVerify(params: SocialVerifyParams): Result<{
@@ -87,6 +94,10 @@ interface Zkkyc {
87
94
  to: Address;
88
95
  data: `0x${string}`;
89
96
  }, ZkkycError>;
97
+ prepareSubmitKycAttestation(params: SimpleKycSubmitParams): Result<{
98
+ to: Address;
99
+ data: `0x${string}`;
100
+ }, ZkkycError>;
90
101
  }
91
102
 
92
103
  /**
package/dist/react.mjs CHANGED
@@ -1424,6 +1424,32 @@ var reputationManagerAbi = [
1424
1424
  outputs: [],
1425
1425
  stateMutability: "nonpayable",
1426
1426
  type: "function"
1427
+ },
1428
+ {
1429
+ inputs: [
1430
+ { internalType: "bytes32", name: "nullifier", type: "bytes32" },
1431
+ { internalType: "uint256", name: "limit", type: "uint256" },
1432
+ { internalType: "uint256", name: "expiry", type: "uint256" },
1433
+ { internalType: "bytes", name: "signature", type: "bytes" }
1434
+ ],
1435
+ name: "submitKycAttestation",
1436
+ outputs: [],
1437
+ stateMutability: "nonpayable",
1438
+ type: "function"
1439
+ },
1440
+ {
1441
+ inputs: [],
1442
+ name: "kycRp",
1443
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
1444
+ stateMutability: "view",
1445
+ type: "function"
1446
+ },
1447
+ {
1448
+ inputs: [{ internalType: "address", name: "", type: "address" }],
1449
+ name: "kycVerified",
1450
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1451
+ stateMutability: "view",
1452
+ type: "function"
1427
1453
  }
1428
1454
  ];
1429
1455
 
@@ -5397,7 +5423,8 @@ var OrderRoutingError = class extends SdkError {
5397
5423
  // src/orders/internal/routing/validation.ts
5398
5424
  import { z as z6 } from "zod";
5399
5425
  var ZodCircleScoreStateSchema = z6.object({
5400
- activeMerchantsCount: z6.coerce.number()
5426
+ activeMerchantsCount: z6.coerce.number(),
5427
+ availableMerchantsCount: z6.coerce.number()
5401
5428
  });
5402
5429
  var ZodCircleMetricsForRoutingSchema = z6.object({
5403
5430
  circleScore: z6.coerce.number(),
@@ -5754,6 +5781,20 @@ var ZodZkPassportRegisterParamsSchema = z9.object({
5754
5781
  params: ZodSolidityVerifierParametersSchema,
5755
5782
  isIDCard: z9.boolean()
5756
5783
  });
5784
+ var ZodSimpleKycSubmitParamsSchema = z9.object({
5785
+ /** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
5786
+ nullifier: z9.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
5787
+ message: "nullifier must be a bytes32 hex string"
5788
+ }),
5789
+ /** Remaining limit in micro-USDC (part of the signed struct). */
5790
+ limit: z9.bigint(),
5791
+ /** Attestation expiry (unix seconds). */
5792
+ expiry: z9.bigint(),
5793
+ /** 65-byte secp256k1 signature (hex). */
5794
+ signature: z9.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
5795
+ message: "signature must be a hex string"
5796
+ })
5797
+ });
5757
5798
 
5758
5799
  // src/contracts/reputation-manager/writes.ts
5759
5800
  function prepareSocialVerify(reputationManagerAddress, params) {
@@ -5820,6 +5861,33 @@ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
5820
5861
  )()
5821
5862
  );
5822
5863
  }
5864
+ function prepareSubmitKycAttestation(reputationManagerAddress, params) {
5865
+ return validate(
5866
+ ZodSimpleKycSubmitParamsSchema,
5867
+ params,
5868
+ (message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
5869
+ ).andThen(
5870
+ (validated) => Result2.fromThrowable(
5871
+ () => ({
5872
+ to: reputationManagerAddress,
5873
+ data: encodeFunctionData7({
5874
+ abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
5875
+ functionName: "submitKycAttestation",
5876
+ args: [
5877
+ validated.nullifier,
5878
+ validated.limit,
5879
+ validated.expiry,
5880
+ validated.signature
5881
+ ]
5882
+ })
5883
+ }),
5884
+ (error) => new ZkkycError("Failed to encode submitKycAttestation", {
5885
+ code: "ENCODE_ERROR",
5886
+ cause: error
5887
+ })
5888
+ )()
5889
+ );
5890
+ }
5823
5891
  function prepareZkPassportRegister(reputationManagerAddress, params) {
5824
5892
  return validate(
5825
5893
  ZodZkPassportRegisterParamsSchema,
@@ -5979,8 +6047,9 @@ import { errAsync as errAsync3, okAsync as okAsync3 } from "neverthrow";
5979
6047
  var EPSILON = 0.25;
5980
6048
  var RECOVERY_SCALE = 0.3;
5981
6049
  var BOOTSTRAP_MAX_WEIGHT = 25;
6050
+ var BOOTSTRAP_RESERVE = 0.1;
5982
6051
  var MAX_VALIDATION_ATTEMPTS = 3;
5983
- function circleWeight(c) {
6052
+ function baseScore(c) {
5984
6053
  const score = c.metrics.circleScore;
5985
6054
  if (c.metrics.circleStatus === "paused") {
5986
6055
  return score * RECOVERY_SCALE;
@@ -5990,8 +6059,13 @@ function circleWeight(c) {
5990
6059
  }
5991
6060
  return score;
5992
6061
  }
6062
+ function circleWeight(c) {
6063
+ return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
6064
+ }
5993
6065
  function filterEligibleCircles(circles, orderCurrency) {
5994
- return circles.filter((c) => c.currency.toLowerCase() === orderCurrency.toLowerCase());
6066
+ return circles.filter(
6067
+ (c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
6068
+ );
5995
6069
  }
5996
6070
  function weightedRandomChoice(arr, weights) {
5997
6071
  const totalWeight = weights.reduce((sum, w) => sum + w, 0);
@@ -6011,8 +6085,14 @@ function selectCircle(eligible) {
6011
6085
  if (eligible.length === 0) {
6012
6086
  return null;
6013
6087
  }
6088
+ const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
6014
6089
  const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
6015
- const isExplore = Math.random() < EPSILON;
6090
+ const r = Math.random();
6091
+ if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
6092
+ const weights2 = bootstrapCircles.map(circleWeight);
6093
+ return weightedRandomChoice(bootstrapCircles, weights2);
6094
+ }
6095
+ const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
6016
6096
  if (isExplore) {
6017
6097
  const weights2 = eligible.map(circleWeight);
6018
6098
  return weightedRandomChoice(eligible, weights2);
@@ -6021,7 +6101,7 @@ function selectCircle(eligible) {
6021
6101
  const weights2 = eligible.map(circleWeight);
6022
6102
  return weightedRandomChoice(eligible, weights2);
6023
6103
  }
6024
- const weights = activeCircles.map((c) => c.metrics.circleScore);
6104
+ const weights = activeCircles.map(circleWeight);
6025
6105
  return weightedRandomChoice(activeCircles, weights);
6026
6106
  }
6027
6107
  function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
@@ -6106,6 +6186,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
6106
6186
  circleStatus
6107
6187
  scoreState {
6108
6188
  activeMerchantsCount
6189
+ availableMerchantsCount
6109
6190
  }
6110
6191
  }
6111
6192
  }
@@ -6132,11 +6213,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
6132
6213
  (message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
6133
6214
  ).map((validated) => {
6134
6215
  const circles = validated.circles.filter(
6135
- (item) => Number(item.metrics.scoreState.activeMerchantsCount) > 0
6216
+ (item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
6136
6217
  );
6137
6218
  logger.info("fetched circles from subgraph", {
6138
6219
  total: validated.circles.length,
6139
- withActiveMerchants: circles.length,
6220
+ withAvailableMerchants: circles.length,
6140
6221
  circles
6141
6222
  });
6142
6223
  return circles;
@@ -6898,7 +6979,8 @@ function createZkkyc(config) {
6898
6979
  return {
6899
6980
  prepareSocialVerify: (params) => prepareSocialVerify(reputationManagerAddress, params),
6900
6981
  prepareSubmitAnonAadharProof: (params) => prepareSubmitAnonAadharProof(reputationManagerAddress, params),
6901
- prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params)
6982
+ prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params),
6983
+ prepareSubmitKycAttestation: (params) => prepareSubmitKycAttestation(reputationManagerAddress, params)
6902
6984
  };
6903
6985
  }
6904
6986