@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/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/orders.cjs +61 -7
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.mjs +61 -7
- package/dist/orders.mjs.map +1 -1
- package/dist/prices.cjs +42 -1
- package/dist/prices.cjs.map +1 -1
- package/dist/prices.mjs +42 -1
- package/dist/prices.mjs.map +1 -1
- package/dist/profile.cjs +42 -1
- package/dist/profile.cjs.map +1 -1
- package/dist/profile.mjs +42 -1
- package/dist/profile.mjs.map +1 -1
- package/dist/react.cjs +90 -8
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +12 -1
- package/dist/react.d.ts +12 -1
- package/dist/react.mjs +90 -8
- package/dist/react.mjs.map +1 -1
- package/dist/stake.cjs +26 -0
- package/dist/stake.cjs.map +1 -1
- package/dist/stake.mjs +26 -0
- package/dist/stake.mjs.map +1 -1
- package/dist/zkkyc.cjs +232 -50
- package/dist/zkkyc.cjs.map +1 -1
- package/dist/zkkyc.d.cts +106 -5
- package/dist/zkkyc.d.ts +106 -5
- package/dist/zkkyc.mjs +228 -49
- package/dist/zkkyc.mjs.map +1 -1
- package/package.json +32 -12
package/dist/react.cjs
CHANGED
|
@@ -1469,6 +1469,32 @@ var reputationManagerAbi = [
|
|
|
1469
1469
|
outputs: [],
|
|
1470
1470
|
stateMutability: "nonpayable",
|
|
1471
1471
|
type: "function"
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
inputs: [
|
|
1475
|
+
{ internalType: "bytes32", name: "nullifier", type: "bytes32" },
|
|
1476
|
+
{ internalType: "uint256", name: "limit", type: "uint256" },
|
|
1477
|
+
{ internalType: "uint256", name: "expiry", type: "uint256" },
|
|
1478
|
+
{ internalType: "bytes", name: "signature", type: "bytes" }
|
|
1479
|
+
],
|
|
1480
|
+
name: "submitKycAttestation",
|
|
1481
|
+
outputs: [],
|
|
1482
|
+
stateMutability: "nonpayable",
|
|
1483
|
+
type: "function"
|
|
1484
|
+
},
|
|
1485
|
+
{
|
|
1486
|
+
inputs: [],
|
|
1487
|
+
name: "kycRp",
|
|
1488
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
1489
|
+
stateMutability: "view",
|
|
1490
|
+
type: "function"
|
|
1491
|
+
},
|
|
1492
|
+
{
|
|
1493
|
+
inputs: [{ internalType: "address", name: "", type: "address" }],
|
|
1494
|
+
name: "kycVerified",
|
|
1495
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
1496
|
+
stateMutability: "view",
|
|
1497
|
+
type: "function"
|
|
1472
1498
|
}
|
|
1473
1499
|
];
|
|
1474
1500
|
|
|
@@ -5442,7 +5468,8 @@ var OrderRoutingError = class extends SdkError {
|
|
|
5442
5468
|
// src/orders/internal/routing/validation.ts
|
|
5443
5469
|
var import_zod6 = require("zod");
|
|
5444
5470
|
var ZodCircleScoreStateSchema = import_zod6.z.object({
|
|
5445
|
-
activeMerchantsCount: import_zod6.z.coerce.number()
|
|
5471
|
+
activeMerchantsCount: import_zod6.z.coerce.number(),
|
|
5472
|
+
availableMerchantsCount: import_zod6.z.coerce.number()
|
|
5446
5473
|
});
|
|
5447
5474
|
var ZodCircleMetricsForRoutingSchema = import_zod6.z.object({
|
|
5448
5475
|
circleScore: import_zod6.z.coerce.number(),
|
|
@@ -5799,6 +5826,20 @@ var ZodZkPassportRegisterParamsSchema = import_zod9.z.object({
|
|
|
5799
5826
|
params: ZodSolidityVerifierParametersSchema,
|
|
5800
5827
|
isIDCard: import_zod9.z.boolean()
|
|
5801
5828
|
});
|
|
5829
|
+
var ZodSimpleKycSubmitParamsSchema = import_zod9.z.object({
|
|
5830
|
+
/** Per-(tenant, identity) Sybil nullifier (bytes32 hex). */
|
|
5831
|
+
nullifier: import_zod9.z.string().refine((v) => /^0x[a-fA-F0-9]{64}$/.test(v), {
|
|
5832
|
+
message: "nullifier must be a bytes32 hex string"
|
|
5833
|
+
}),
|
|
5834
|
+
/** Remaining limit in micro-USDC (part of the signed struct). */
|
|
5835
|
+
limit: import_zod9.z.bigint(),
|
|
5836
|
+
/** Attestation expiry (unix seconds). */
|
|
5837
|
+
expiry: import_zod9.z.bigint(),
|
|
5838
|
+
/** 65-byte secp256k1 signature (hex). */
|
|
5839
|
+
signature: import_zod9.z.string().refine((v) => /^0x[a-fA-F0-9]+$/.test(v), {
|
|
5840
|
+
message: "signature must be a hex string"
|
|
5841
|
+
})
|
|
5842
|
+
});
|
|
5802
5843
|
|
|
5803
5844
|
// src/contracts/reputation-manager/writes.ts
|
|
5804
5845
|
function prepareSocialVerify(reputationManagerAddress, params) {
|
|
@@ -5865,6 +5906,33 @@ function prepareSubmitAnonAadharProof(reputationManagerAddress, params) {
|
|
|
5865
5906
|
)()
|
|
5866
5907
|
);
|
|
5867
5908
|
}
|
|
5909
|
+
function prepareSubmitKycAttestation(reputationManagerAddress, params) {
|
|
5910
|
+
return validate(
|
|
5911
|
+
ZodSimpleKycSubmitParamsSchema,
|
|
5912
|
+
params,
|
|
5913
|
+
(message, cause, data) => new ZkkycError(message, { code: "VALIDATION_ERROR", cause, context: { params: data } })
|
|
5914
|
+
).andThen(
|
|
5915
|
+
(validated) => import_neverthrow12.Result.fromThrowable(
|
|
5916
|
+
() => ({
|
|
5917
|
+
to: reputationManagerAddress,
|
|
5918
|
+
data: (0, import_viem14.encodeFunctionData)({
|
|
5919
|
+
abi: ABIS.EXTERNAL.REPUTATION_MANAGER,
|
|
5920
|
+
functionName: "submitKycAttestation",
|
|
5921
|
+
args: [
|
|
5922
|
+
validated.nullifier,
|
|
5923
|
+
validated.limit,
|
|
5924
|
+
validated.expiry,
|
|
5925
|
+
validated.signature
|
|
5926
|
+
]
|
|
5927
|
+
})
|
|
5928
|
+
}),
|
|
5929
|
+
(error) => new ZkkycError("Failed to encode submitKycAttestation", {
|
|
5930
|
+
code: "ENCODE_ERROR",
|
|
5931
|
+
cause: error
|
|
5932
|
+
})
|
|
5933
|
+
)()
|
|
5934
|
+
);
|
|
5935
|
+
}
|
|
5868
5936
|
function prepareZkPassportRegister(reputationManagerAddress, params) {
|
|
5869
5937
|
return validate(
|
|
5870
5938
|
ZodZkPassportRegisterParamsSchema,
|
|
@@ -6024,8 +6092,9 @@ var import_neverthrow15 = require("neverthrow");
|
|
|
6024
6092
|
var EPSILON = 0.25;
|
|
6025
6093
|
var RECOVERY_SCALE = 0.3;
|
|
6026
6094
|
var BOOTSTRAP_MAX_WEIGHT = 25;
|
|
6095
|
+
var BOOTSTRAP_RESERVE = 0.1;
|
|
6027
6096
|
var MAX_VALIDATION_ATTEMPTS = 3;
|
|
6028
|
-
function
|
|
6097
|
+
function baseScore(c) {
|
|
6029
6098
|
const score = c.metrics.circleScore;
|
|
6030
6099
|
if (c.metrics.circleStatus === "paused") {
|
|
6031
6100
|
return score * RECOVERY_SCALE;
|
|
@@ -6035,8 +6104,13 @@ function circleWeight(c) {
|
|
|
6035
6104
|
}
|
|
6036
6105
|
return score;
|
|
6037
6106
|
}
|
|
6107
|
+
function circleWeight(c) {
|
|
6108
|
+
return baseScore(c) * c.metrics.scoreState.availableMerchantsCount;
|
|
6109
|
+
}
|
|
6038
6110
|
function filterEligibleCircles(circles, orderCurrency) {
|
|
6039
|
-
return circles.filter(
|
|
6111
|
+
return circles.filter(
|
|
6112
|
+
(c) => c.currency.toLowerCase() === orderCurrency.toLowerCase() && c.metrics.scoreState.availableMerchantsCount > 0
|
|
6113
|
+
);
|
|
6040
6114
|
}
|
|
6041
6115
|
function weightedRandomChoice(arr, weights) {
|
|
6042
6116
|
const totalWeight = weights.reduce((sum, w) => sum + w, 0);
|
|
@@ -6056,8 +6130,14 @@ function selectCircle(eligible) {
|
|
|
6056
6130
|
if (eligible.length === 0) {
|
|
6057
6131
|
return null;
|
|
6058
6132
|
}
|
|
6133
|
+
const bootstrapCircles = eligible.filter((c) => c.metrics.circleStatus === "bootstrap");
|
|
6059
6134
|
const activeCircles = eligible.filter((c) => c.metrics.circleStatus === "active");
|
|
6060
|
-
const
|
|
6135
|
+
const r = Math.random();
|
|
6136
|
+
if (r < BOOTSTRAP_RESERVE && bootstrapCircles.length > 0) {
|
|
6137
|
+
const weights2 = bootstrapCircles.map(circleWeight);
|
|
6138
|
+
return weightedRandomChoice(bootstrapCircles, weights2);
|
|
6139
|
+
}
|
|
6140
|
+
const isExplore = r < BOOTSTRAP_RESERVE + EPSILON;
|
|
6061
6141
|
if (isExplore) {
|
|
6062
6142
|
const weights2 = eligible.map(circleWeight);
|
|
6063
6143
|
return weightedRandomChoice(eligible, weights2);
|
|
@@ -6066,7 +6146,7 @@ function selectCircle(eligible) {
|
|
|
6066
6146
|
const weights2 = eligible.map(circleWeight);
|
|
6067
6147
|
return weightedRandomChoice(eligible, weights2);
|
|
6068
6148
|
}
|
|
6069
|
-
const weights = activeCircles.map(
|
|
6149
|
+
const weights = activeCircles.map(circleWeight);
|
|
6070
6150
|
return weightedRandomChoice(activeCircles, weights);
|
|
6071
6151
|
}
|
|
6072
6152
|
function selectCircleForOrderAsync(circles, orderCurrency, validateCircle, logger = noopLogger) {
|
|
@@ -6151,6 +6231,7 @@ var CIRCLES_FOR_ROUTING_QUERY = (
|
|
|
6151
6231
|
circleStatus
|
|
6152
6232
|
scoreState {
|
|
6153
6233
|
activeMerchantsCount
|
|
6234
|
+
availableMerchantsCount
|
|
6154
6235
|
}
|
|
6155
6236
|
}
|
|
6156
6237
|
}
|
|
@@ -6177,11 +6258,11 @@ function getCirclesForRouting(subgraphUrl, currency, logger = noopLogger) {
|
|
|
6177
6258
|
(message, cause, d) => new OrderRoutingError(message, { code: "VALIDATION_ERROR", cause, context: { data: d } })
|
|
6178
6259
|
).map((validated) => {
|
|
6179
6260
|
const circles = validated.circles.filter(
|
|
6180
|
-
(item) => Number(item.metrics.scoreState.
|
|
6261
|
+
(item) => Number(item.metrics.scoreState.availableMerchantsCount) > 0
|
|
6181
6262
|
);
|
|
6182
6263
|
logger.info("fetched circles from subgraph", {
|
|
6183
6264
|
total: validated.circles.length,
|
|
6184
|
-
|
|
6265
|
+
withAvailableMerchants: circles.length,
|
|
6185
6266
|
circles
|
|
6186
6267
|
});
|
|
6187
6268
|
return circles;
|
|
@@ -6943,7 +7024,8 @@ function createZkkyc(config) {
|
|
|
6943
7024
|
return {
|
|
6944
7025
|
prepareSocialVerify: (params) => prepareSocialVerify(reputationManagerAddress, params),
|
|
6945
7026
|
prepareSubmitAnonAadharProof: (params) => prepareSubmitAnonAadharProof(reputationManagerAddress, params),
|
|
6946
|
-
prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params)
|
|
7027
|
+
prepareZkPassportRegister: (params) => prepareZkPassportRegister(reputationManagerAddress, params),
|
|
7028
|
+
prepareSubmitKycAttestation: (params) => prepareSubmitKycAttestation(reputationManagerAddress, params)
|
|
6947
7029
|
};
|
|
6948
7030
|
}
|
|
6949
7031
|
|