@p2pdotme/sdk 1.0.0
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/README.md +155 -0
- package/dist/fraud-engine.cjs +598 -0
- package/dist/fraud-engine.cjs.map +1 -0
- package/dist/fraud-engine.d.cts +194 -0
- package/dist/fraud-engine.d.ts +194 -0
- package/dist/fraud-engine.mjs +549 -0
- package/dist/fraud-engine.mjs.map +1 -0
- package/dist/index.cjs +75 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.mjs +46 -0
- package/dist/index.mjs.map +1 -0
- package/dist/order-routing.cjs +882 -0
- package/dist/order-routing.cjs.map +1 -0
- package/dist/order-routing.d.cts +68 -0
- package/dist/order-routing.d.ts +68 -0
- package/dist/order-routing.mjs +854 -0
- package/dist/order-routing.mjs.map +1 -0
- package/dist/payload.cjs +3164 -0
- package/dist/payload.cjs.map +1 -0
- package/dist/payload.d.cts +162 -0
- package/dist/payload.d.ts +162 -0
- package/dist/payload.mjs +3120 -0
- package/dist/payload.mjs.map +1 -0
- package/dist/profile.cjs +695 -0
- package/dist/profile.cjs.map +1 -0
- package/dist/profile.d.cts +133 -0
- package/dist/profile.d.ts +133 -0
- package/dist/profile.mjs +667 -0
- package/dist/profile.mjs.map +1 -0
- package/dist/qr-parsers.cjs +366 -0
- package/dist/qr-parsers.cjs.map +1 -0
- package/dist/qr-parsers.d.cts +41 -0
- package/dist/qr-parsers.d.ts +41 -0
- package/dist/qr-parsers.mjs +338 -0
- package/dist/qr-parsers.mjs.map +1 -0
- package/dist/react.cjs +4803 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +511 -0
- package/dist/react.d.ts +511 -0
- package/dist/react.mjs +4759 -0
- package/dist/react.mjs.map +1 -0
- package/dist/zkkyc.cjs +868 -0
- package/dist/zkkyc.cjs.map +1 -0
- package/dist/zkkyc.d.cts +230 -0
- package/dist/zkkyc.d.ts +230 -0
- package/dist/zkkyc.mjs +824 -0
- package/dist/zkkyc.mjs.map +1 -0
- package/package.json +130 -0
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import * as neverthrow from 'neverthrow';
|
|
2
|
+
import { Result, ResultAsync } from 'neverthrow';
|
|
3
|
+
import { Address } from 'viem';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
import { ReactNode } from 'react';
|
|
7
|
+
|
|
8
|
+
declare class SdkError<TCode extends string = string> extends Error {
|
|
9
|
+
readonly code: TCode;
|
|
10
|
+
readonly cause?: unknown;
|
|
11
|
+
readonly context?: Record<string, unknown>;
|
|
12
|
+
constructor(message: string, options: {
|
|
13
|
+
code: TCode;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
context?: Record<string, unknown>;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare const ZodCurrencySchema: z.ZodEnum<{
|
|
20
|
+
IDR: "IDR";
|
|
21
|
+
INR: "INR";
|
|
22
|
+
BRL: "BRL";
|
|
23
|
+
ARS: "ARS";
|
|
24
|
+
MEX: "MEX";
|
|
25
|
+
VEN: "VEN";
|
|
26
|
+
EUR: "EUR";
|
|
27
|
+
NGN: "NGN";
|
|
28
|
+
USD: "USD";
|
|
29
|
+
}>;
|
|
30
|
+
type CurrencyType = z.infer<typeof ZodCurrencySchema>;
|
|
31
|
+
|
|
32
|
+
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";
|
|
33
|
+
declare class ZkkycError extends SdkError<ZkkycErrorCode> {
|
|
34
|
+
constructor(message: string, options: {
|
|
35
|
+
code: ZkkycErrorCode;
|
|
36
|
+
cause?: unknown;
|
|
37
|
+
context?: Record<string, unknown>;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare const ZodAnonAadharProofParamsSchema: z.ZodObject<{
|
|
42
|
+
nullifierSeed: z.ZodBigInt;
|
|
43
|
+
nullifier: z.ZodBigInt;
|
|
44
|
+
timestamp: z.ZodBigInt;
|
|
45
|
+
signal: z.ZodBigInt;
|
|
46
|
+
revealArray: z.ZodTuple<[z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt], null>;
|
|
47
|
+
packedGroth16Proof: z.ZodTuple<[z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt, z.ZodBigInt], null>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
type AnonAadharProofParams = z.infer<typeof ZodAnonAadharProofParamsSchema>;
|
|
50
|
+
declare const ZodSocialVerifyParamsSchema: z.ZodObject<{
|
|
51
|
+
_socialName: z.ZodString;
|
|
52
|
+
proofs: z.ZodArray<z.ZodObject<{
|
|
53
|
+
claimInfo: z.ZodObject<{
|
|
54
|
+
provider: z.ZodString;
|
|
55
|
+
parameters: z.ZodString;
|
|
56
|
+
context: z.ZodString;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
signedClaim: z.ZodObject<{
|
|
59
|
+
claim: z.ZodObject<{
|
|
60
|
+
identifier: z.ZodString;
|
|
61
|
+
owner: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
62
|
+
timestampS: z.ZodNumber;
|
|
63
|
+
epoch: z.ZodNumber;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
signatures: z.ZodArray<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
type SocialVerifyParams = z.infer<typeof ZodSocialVerifyParamsSchema>;
|
|
70
|
+
declare const ZodZkPassportRegisterParamsSchema: z.ZodObject<{
|
|
71
|
+
params: z.ZodObject<{
|
|
72
|
+
version: z.ZodString;
|
|
73
|
+
proofVerificationData: z.ZodObject<{
|
|
74
|
+
vkeyHash: z.ZodString;
|
|
75
|
+
proof: z.ZodString;
|
|
76
|
+
publicInputs: z.ZodArray<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
committedInputs: z.ZodString;
|
|
79
|
+
serviceConfig: z.ZodObject<{
|
|
80
|
+
validityPeriodInSeconds: z.ZodNumber;
|
|
81
|
+
domain: z.ZodString;
|
|
82
|
+
scope: z.ZodString;
|
|
83
|
+
devMode: z.ZodBoolean;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
isIDCard: z.ZodBoolean;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
type ZkPassportRegisterParams = z.infer<typeof ZodZkPassportRegisterParamsSchema>;
|
|
89
|
+
|
|
90
|
+
interface Zkkyc {
|
|
91
|
+
prepareSocialVerify(params: SocialVerifyParams): Result<{
|
|
92
|
+
to: Address;
|
|
93
|
+
data: `0x${string}`;
|
|
94
|
+
}, ZkkycError>;
|
|
95
|
+
prepareSubmitAnonAadharProof(params: AnonAadharProofParams): Result<{
|
|
96
|
+
to: Address;
|
|
97
|
+
data: `0x${string}`;
|
|
98
|
+
}, ZkkycError>;
|
|
99
|
+
prepareZkPassportRegister(params: ZkPassportRegisterParams): Result<{
|
|
100
|
+
to: Address;
|
|
101
|
+
data: `0x${string}`;
|
|
102
|
+
}, ZkkycError>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type PayloadErrorCode = "VALIDATION_ERROR" | "CIRCLE_SELECTION_ERROR" | "ENCRYPTION_ERROR" | "DECRYPTION_ERROR";
|
|
106
|
+
declare class PayloadError extends SdkError<PayloadErrorCode> {
|
|
107
|
+
constructor(message: string, options: {
|
|
108
|
+
code: PayloadErrorCode;
|
|
109
|
+
cause?: unknown;
|
|
110
|
+
context?: Record<string, unknown>;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type OrderRoutingErrorCode = "NO_ELIGIBLE_CIRCLES" | "SUBGRAPH_ERROR" | "SUBGRAPH_NOT_CONFIGURED" | "VALIDATION_ERROR" | "CONTRACT_READ_ERROR";
|
|
115
|
+
declare class OrderRoutingError extends SdkError<OrderRoutingErrorCode> {
|
|
116
|
+
constructor(message: string, options: {
|
|
117
|
+
code: OrderRoutingErrorCode;
|
|
118
|
+
cause?: unknown;
|
|
119
|
+
context?: Record<string, unknown>;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface Logger {
|
|
124
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
125
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
126
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
127
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Minimal viem PublicClient interface — consumers pass their own client.
|
|
132
|
+
* The SDK only needs `readContract` for on-chain reads.
|
|
133
|
+
*/
|
|
134
|
+
interface PublicClientLike {
|
|
135
|
+
readContract(args: {
|
|
136
|
+
address: Address;
|
|
137
|
+
abi: readonly unknown[];
|
|
138
|
+
functionName: string;
|
|
139
|
+
args: readonly unknown[];
|
|
140
|
+
}): Promise<unknown>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
interface SelectCircleParams {
|
|
144
|
+
readonly currency: string;
|
|
145
|
+
readonly user: Address;
|
|
146
|
+
readonly usdtAmount: bigint;
|
|
147
|
+
readonly fiatAmount: bigint;
|
|
148
|
+
readonly orderType: bigint;
|
|
149
|
+
readonly preferredPCConfigId: bigint;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
interface OrderRouter {
|
|
153
|
+
/**
|
|
154
|
+
* Full flow: fetch circles from subgraph → epsilon-greedy selection →
|
|
155
|
+
* on-chain eligibility validation → return circleId.
|
|
156
|
+
*/
|
|
157
|
+
selectCircle(params: SelectCircleParams): ResultAsync<bigint, OrderRoutingError>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface PlaceOrderPayload {
|
|
161
|
+
readonly pubKey: string;
|
|
162
|
+
readonly amount: bigint;
|
|
163
|
+
readonly recipientAddr: `0x${string}`;
|
|
164
|
+
readonly orderType: number;
|
|
165
|
+
readonly userUpi: string;
|
|
166
|
+
readonly userPubKey: string;
|
|
167
|
+
readonly currency: CurrencyType;
|
|
168
|
+
readonly preferredPaymentChannelConfigId: bigint;
|
|
169
|
+
readonly fiatAmountLimit: bigint;
|
|
170
|
+
readonly circleId: bigint;
|
|
171
|
+
}
|
|
172
|
+
interface SetSellOrderUpiPayload {
|
|
173
|
+
readonly orderId: number;
|
|
174
|
+
readonly userEncUpi: string;
|
|
175
|
+
readonly updatedAmount: bigint;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
declare const ZodPlaceOrderParamsSchema: z.ZodObject<{
|
|
179
|
+
amount: z.ZodBigInt;
|
|
180
|
+
recipientAddr: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
181
|
+
orderType: z.ZodNumber;
|
|
182
|
+
currency: z.ZodEnum<{
|
|
183
|
+
IDR: "IDR";
|
|
184
|
+
INR: "INR";
|
|
185
|
+
BRL: "BRL";
|
|
186
|
+
ARS: "ARS";
|
|
187
|
+
MEX: "MEX";
|
|
188
|
+
VEN: "VEN";
|
|
189
|
+
EUR: "EUR";
|
|
190
|
+
NGN: "NGN";
|
|
191
|
+
USD: "USD";
|
|
192
|
+
}>;
|
|
193
|
+
fiatAmount: z.ZodBigInt;
|
|
194
|
+
user: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
195
|
+
pubKey: z.ZodOptional<z.ZodString>;
|
|
196
|
+
preferredPaymentChannelConfigId: z.ZodOptional<z.ZodBigInt>;
|
|
197
|
+
fiatAmountLimit: z.ZodDefault<z.ZodOptional<z.ZodBigInt>>;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
type PlaceOrderParams = z.input<typeof ZodPlaceOrderParamsSchema>;
|
|
200
|
+
declare const ZodSetSellOrderUpiParamsSchema: z.ZodObject<{
|
|
201
|
+
orderId: z.ZodNumber;
|
|
202
|
+
paymentAddress: z.ZodString;
|
|
203
|
+
merchantPublicKey: z.ZodString;
|
|
204
|
+
updatedAmount: z.ZodBigInt;
|
|
205
|
+
}, z.core.$strip>;
|
|
206
|
+
type SetSellOrderUpiParams = z.infer<typeof ZodSetSellOrderUpiParamsSchema>;
|
|
207
|
+
|
|
208
|
+
interface PayloadGenerator {
|
|
209
|
+
placeOrder(params: PlaceOrderParams): ResultAsync<PlaceOrderPayload, PayloadError>;
|
|
210
|
+
setSellOrderUpi(params: SetSellOrderUpiParams): ResultAsync<SetSellOrderUpiPayload, PayloadError>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
type ProfileErrorCode = "VALIDATION_ERROR" | "CONTRACT_READ_ERROR";
|
|
214
|
+
declare class ProfileError extends SdkError<ProfileErrorCode> {
|
|
215
|
+
constructor(message: string, options: {
|
|
216
|
+
code: ProfileErrorCode;
|
|
217
|
+
cause?: unknown;
|
|
218
|
+
context?: Record<string, unknown>;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
declare const ZodUsdcBalanceParamsSchema: z.ZodObject<{
|
|
223
|
+
address: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
224
|
+
}, z.core.$strip>;
|
|
225
|
+
type UsdcBalanceParams = z.infer<typeof ZodUsdcBalanceParamsSchema>;
|
|
226
|
+
declare const ZodGetBalancesParamsSchema: z.ZodObject<{
|
|
227
|
+
address: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
228
|
+
currency: z.ZodEnum<{
|
|
229
|
+
IDR: "IDR";
|
|
230
|
+
INR: "INR";
|
|
231
|
+
BRL: "BRL";
|
|
232
|
+
ARS: "ARS";
|
|
233
|
+
MEX: "MEX";
|
|
234
|
+
VEN: "VEN";
|
|
235
|
+
EUR: "EUR";
|
|
236
|
+
NGN: "NGN";
|
|
237
|
+
USD: "USD";
|
|
238
|
+
}>;
|
|
239
|
+
}, z.core.$strip>;
|
|
240
|
+
type GetBalancesParams = z.infer<typeof ZodGetBalancesParamsSchema>;
|
|
241
|
+
declare const ZodTxLimitsParamsSchema: z.ZodObject<{
|
|
242
|
+
address: z.ZodString & z.ZodType<`0x${string}`, string, z.core.$ZodTypeInternals<`0x${string}`, string>>;
|
|
243
|
+
currency: z.ZodEnum<{
|
|
244
|
+
IDR: "IDR";
|
|
245
|
+
INR: "INR";
|
|
246
|
+
BRL: "BRL";
|
|
247
|
+
ARS: "ARS";
|
|
248
|
+
MEX: "MEX";
|
|
249
|
+
VEN: "VEN";
|
|
250
|
+
EUR: "EUR";
|
|
251
|
+
NGN: "NGN";
|
|
252
|
+
USD: "USD";
|
|
253
|
+
}>;
|
|
254
|
+
}, z.core.$strip>;
|
|
255
|
+
type TxLimitsParams = z.infer<typeof ZodTxLimitsParamsSchema>;
|
|
256
|
+
declare const ZodPriceConfigParamsSchema: z.ZodObject<{
|
|
257
|
+
currency: z.ZodEnum<{
|
|
258
|
+
IDR: "IDR";
|
|
259
|
+
INR: "INR";
|
|
260
|
+
BRL: "BRL";
|
|
261
|
+
ARS: "ARS";
|
|
262
|
+
MEX: "MEX";
|
|
263
|
+
VEN: "VEN";
|
|
264
|
+
EUR: "EUR";
|
|
265
|
+
NGN: "NGN";
|
|
266
|
+
USD: "USD";
|
|
267
|
+
}>;
|
|
268
|
+
}, z.core.$strip>;
|
|
269
|
+
type PriceConfigParams = z.infer<typeof ZodPriceConfigParamsSchema>;
|
|
270
|
+
|
|
271
|
+
interface TxLimits {
|
|
272
|
+
readonly buyLimit: number;
|
|
273
|
+
readonly sellLimit: number;
|
|
274
|
+
}
|
|
275
|
+
interface RpPerUsdtLimit {
|
|
276
|
+
readonly numerator: bigint;
|
|
277
|
+
readonly denominator: bigint;
|
|
278
|
+
/** The USDC multiplier per RP: denominator / numerator. */
|
|
279
|
+
readonly multiplier: number;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
interface Balances {
|
|
283
|
+
/** USDC balance formatted to a number. */
|
|
284
|
+
readonly usdc: number;
|
|
285
|
+
/** Fiat equivalent: usdc * sellPrice. */
|
|
286
|
+
readonly fiat: number;
|
|
287
|
+
/** The sell price used for conversion. */
|
|
288
|
+
readonly sellPrice: number;
|
|
289
|
+
}
|
|
290
|
+
interface PriceConfig {
|
|
291
|
+
readonly buyPrice: bigint;
|
|
292
|
+
readonly sellPrice: bigint;
|
|
293
|
+
readonly buyPriceOffset: bigint;
|
|
294
|
+
readonly baseSpread: bigint;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
interface Profile {
|
|
298
|
+
/** Reads the USDC balance for a given address (raw bigint, 6 decimals). */
|
|
299
|
+
getUsdcBalance(params: UsdcBalanceParams): ResultAsync<bigint, ProfileError>;
|
|
300
|
+
/** Reads buy/sell price config for a given currency (raw bigint, 6 decimals). */
|
|
301
|
+
getPriceConfig(params: PriceConfigParams): ResultAsync<PriceConfig, ProfileError>;
|
|
302
|
+
/** Fetches USDC and fiat balance in parallel for a given address and currency. */
|
|
303
|
+
getBalances(params: GetBalancesParams): ResultAsync<Balances, ProfileError>;
|
|
304
|
+
/** Reads buy and sell transaction limits for a given address and currency. */
|
|
305
|
+
getTxLimits(params: TxLimitsParams): ResultAsync<TxLimits, ProfileError>;
|
|
306
|
+
/** Reads the RP-to-USDC limit ratio for a given currency. */
|
|
307
|
+
getRpPerUsdtLimitRational(params: PriceConfigParams): ResultAsync<RpPerUsdtLimit, ProfileError>;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
type FraudEngineErrorCode = "API_ERROR" | "ENCRYPTION_ERROR" | "SIGNING_ERROR" | "VALIDATION_ERROR" | "NETWORK_ERROR" | "PLACE_ORDER_ERROR";
|
|
311
|
+
declare class FraudEngineError extends SdkError<FraudEngineErrorCode> {
|
|
312
|
+
constructor(message: string, options: {
|
|
313
|
+
code: FraudEngineErrorCode;
|
|
314
|
+
cause?: unknown;
|
|
315
|
+
context?: Record<string, unknown>;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface FraudEngineSigner {
|
|
320
|
+
/**
|
|
321
|
+
* The subject address tracked by the fraud engine — the wallet that places
|
|
322
|
+
* on-chain orders and appears in reports, watchlist, and risk scoring.
|
|
323
|
+
*
|
|
324
|
+
* - For thirdweb smart wallets (ERC-4337 / account abstraction) this is the
|
|
325
|
+
* smart account address.
|
|
326
|
+
* - For plain EOA wallets this is the same address that produces signatures.
|
|
327
|
+
*/
|
|
328
|
+
readonly address: string;
|
|
329
|
+
/**
|
|
330
|
+
* The address of the key that actually produces the EIP-191 signature.
|
|
331
|
+
* Defaults to {@link address} when omitted.
|
|
332
|
+
*
|
|
333
|
+
* Set this only when the tracked subject is a smart wallet whose admin EOA
|
|
334
|
+
* is the real signer (smart wallet contracts cannot sign EIP-191 directly).
|
|
335
|
+
* In that case, {@link address} is the smart wallet and `signerAddress` is
|
|
336
|
+
* the admin EOA.
|
|
337
|
+
*/
|
|
338
|
+
readonly signerAddress?: string;
|
|
339
|
+
signMessage(message: string): Promise<string>;
|
|
340
|
+
}
|
|
341
|
+
interface DeviceDetails {
|
|
342
|
+
readonly userAgent: string;
|
|
343
|
+
readonly platform: string;
|
|
344
|
+
readonly language: string;
|
|
345
|
+
readonly languages: string[];
|
|
346
|
+
readonly screenWidth: number;
|
|
347
|
+
readonly screenHeight: number;
|
|
348
|
+
readonly devicePixelRatio: number;
|
|
349
|
+
readonly timezone: string;
|
|
350
|
+
readonly timezoneOffset: number;
|
|
351
|
+
readonly cookiesEnabled: boolean;
|
|
352
|
+
readonly doNotTrack: string | null;
|
|
353
|
+
readonly online: boolean;
|
|
354
|
+
readonly connectionType?: string;
|
|
355
|
+
readonly deviceMemory?: number;
|
|
356
|
+
readonly hardwareConcurrency?: number;
|
|
357
|
+
readonly touchSupport: boolean;
|
|
358
|
+
readonly maxTouchPoints: number;
|
|
359
|
+
readonly vendor: string;
|
|
360
|
+
readonly appVersion: string;
|
|
361
|
+
readonly colorDepth: number;
|
|
362
|
+
readonly pixelDepth: number;
|
|
363
|
+
readonly ip?: string;
|
|
364
|
+
readonly seonSession?: string;
|
|
365
|
+
}
|
|
366
|
+
interface BuyOrderDetails {
|
|
367
|
+
readonly cryptoAmount: number;
|
|
368
|
+
readonly fiatAmount: number;
|
|
369
|
+
readonly currency: string;
|
|
370
|
+
readonly recipientAddress: string;
|
|
371
|
+
readonly fee: number;
|
|
372
|
+
readonly amountAfterFee: number;
|
|
373
|
+
readonly paymentMethod?: string;
|
|
374
|
+
readonly estimatedProcessingTime?: string;
|
|
375
|
+
}
|
|
376
|
+
interface UserDetails {
|
|
377
|
+
readonly currency?: string;
|
|
378
|
+
readonly country?: string;
|
|
379
|
+
readonly language?: string;
|
|
380
|
+
readonly loginMethod?: "email" | "google" | "phone" | "passkey" | "unknown";
|
|
381
|
+
readonly loginEmail?: string;
|
|
382
|
+
readonly loginPhone?: string;
|
|
383
|
+
}
|
|
384
|
+
interface FraudCheckResult {
|
|
385
|
+
readonly approved: boolean;
|
|
386
|
+
readonly activityLogId: number;
|
|
387
|
+
readonly message: string;
|
|
388
|
+
/**
|
|
389
|
+
* Link an on-chain order ID to this activity log record.
|
|
390
|
+
* Call after the buy order is placed on-chain (fire-and-forget).
|
|
391
|
+
* The signer and activityLogId are captured internally — just pass the orderId.
|
|
392
|
+
*/
|
|
393
|
+
linkOrder(orderId: string): neverthrow.ResultAsync<LinkOrderResult, FraudEngineError>;
|
|
394
|
+
}
|
|
395
|
+
interface LinkOrderResult {
|
|
396
|
+
readonly success: boolean;
|
|
397
|
+
readonly message: string;
|
|
398
|
+
}
|
|
399
|
+
interface FingerprintLogResult {
|
|
400
|
+
readonly success: boolean;
|
|
401
|
+
readonly message: string;
|
|
402
|
+
}
|
|
403
|
+
type ProcessBuyOrderResult = {
|
|
404
|
+
readonly status: "placed";
|
|
405
|
+
readonly orderId: string;
|
|
406
|
+
} | {
|
|
407
|
+
readonly status: "rejected";
|
|
408
|
+
readonly message: string;
|
|
409
|
+
};
|
|
410
|
+
interface FraudEngine {
|
|
411
|
+
init(): Promise<void>;
|
|
412
|
+
/**
|
|
413
|
+
* Low-level: run fraud check only. Returns result with `linkOrder()` for manual linking.
|
|
414
|
+
* For most consumers, prefer `processBuyOrder()` which handles the full flow.
|
|
415
|
+
*/
|
|
416
|
+
checkBuyOrder(params: {
|
|
417
|
+
signer: FraudEngineSigner;
|
|
418
|
+
orderDetails: BuyOrderDetails;
|
|
419
|
+
userDetails?: UserDetails;
|
|
420
|
+
orderSource?: string;
|
|
421
|
+
}): neverthrow.ResultAsync<FraudCheckResult, FraudEngineError>;
|
|
422
|
+
/**
|
|
423
|
+
* Full orchestration: fraud check → place order → auto-link.
|
|
424
|
+
*
|
|
425
|
+
* - Runs fraud check on all buy orders (backend handles currency-specific logic).
|
|
426
|
+
* If rejected, returns `{ status: "rejected" }` without calling `placeOrder`.
|
|
427
|
+
* If approved, calls `placeOrder`, auto-links activity log, returns `{ status: "placed", orderId }`.
|
|
428
|
+
* - Fail-open: if fraud check API errors, still calls `placeOrder` (no linking since no activityLogId).
|
|
429
|
+
* - Linking is fire-and-forget: if link fails, order is already placed — error is logged, not propagated.
|
|
430
|
+
*/
|
|
431
|
+
processBuyOrder(params: {
|
|
432
|
+
signer: FraudEngineSigner;
|
|
433
|
+
orderDetails: BuyOrderDetails;
|
|
434
|
+
userDetails?: UserDetails;
|
|
435
|
+
orderSource?: string;
|
|
436
|
+
placeOrder: () => Promise<string>;
|
|
437
|
+
}): neverthrow.ResultAsync<ProcessBuyOrderResult, FraudEngineError>;
|
|
438
|
+
logFingerprint(params: {
|
|
439
|
+
signer: FraudEngineSigner;
|
|
440
|
+
}): neverthrow.ResultAsync<FingerprintLogResult | null, FraudEngineError>;
|
|
441
|
+
getFingerprint(): Promise<{
|
|
442
|
+
visitorId: string;
|
|
443
|
+
confidence: number;
|
|
444
|
+
} | null>;
|
|
445
|
+
getDeviceDetails(): Promise<DeviceDetails>;
|
|
446
|
+
cleanupSeonStorage(): void;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
interface FraudEngineSdkConfig {
|
|
450
|
+
readonly apiUrl: string;
|
|
451
|
+
readonly encryptionKey: string;
|
|
452
|
+
readonly seonRegion?: string;
|
|
453
|
+
}
|
|
454
|
+
interface SdkConfig {
|
|
455
|
+
readonly publicClient: PublicClientLike;
|
|
456
|
+
readonly subgraphUrl: string;
|
|
457
|
+
readonly diamondAddress: Address;
|
|
458
|
+
readonly usdcAddress: Address;
|
|
459
|
+
readonly reputationManagerAddress?: Address;
|
|
460
|
+
readonly fraudEngine?: FraudEngineSdkConfig;
|
|
461
|
+
readonly logger?: Logger;
|
|
462
|
+
}
|
|
463
|
+
interface Sdk {
|
|
464
|
+
readonly profile: Profile;
|
|
465
|
+
readonly orderRouter: OrderRouter;
|
|
466
|
+
readonly payload: PayloadGenerator;
|
|
467
|
+
readonly zkkyc?: Zkkyc;
|
|
468
|
+
readonly fraudEngine?: FraudEngine;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Provides Profile, OrderRouter, PayloadGenerator, Zkkyc, and FraudEngine instances to all children.
|
|
473
|
+
*
|
|
474
|
+
* Object props (`publicClient`, `logger`) are captured on mount and do **not** trigger
|
|
475
|
+
* re-instantiation on subsequent renders. To swap them (e.g. switching chains), remount
|
|
476
|
+
* the provider with a React `key`:
|
|
477
|
+
*
|
|
478
|
+
* ```tsx
|
|
479
|
+
* <SdkProvider key={chainId} publicClient={client} ...>
|
|
480
|
+
* ```
|
|
481
|
+
*
|
|
482
|
+
* Primitive props (`subgraphUrl`, `diamondAddress`, etc.) are compared by value and will
|
|
483
|
+
* trigger re-instantiation when they actually change.
|
|
484
|
+
*/
|
|
485
|
+
declare function SdkProvider({ children, ...config }: SdkConfig & {
|
|
486
|
+
readonly children: ReactNode;
|
|
487
|
+
}): react_jsx_runtime.JSX.Element;
|
|
488
|
+
/** Returns the full SDK object from the nearest SdkProvider. */
|
|
489
|
+
declare function useSdk(): Sdk;
|
|
490
|
+
/** Returns the Profile instance from the nearest SdkProvider. */
|
|
491
|
+
declare function useProfile(): Profile;
|
|
492
|
+
/** Returns the OrderRouter instance from the nearest SdkProvider. */
|
|
493
|
+
declare function useOrderRouter(): OrderRouter;
|
|
494
|
+
/** Returns the PayloadGenerator instance from the nearest SdkProvider. */
|
|
495
|
+
declare function usePayloadGenerator(): PayloadGenerator;
|
|
496
|
+
/** Returns the Zkkyc instance from the nearest SdkProvider. */
|
|
497
|
+
declare function useZkkyc(): Zkkyc;
|
|
498
|
+
/** Returns the FraudEngine instance from the nearest SdkProvider. */
|
|
499
|
+
declare function useFraudEngine(): FraudEngine;
|
|
500
|
+
|
|
501
|
+
interface UseFingerprintResult {
|
|
502
|
+
data: {
|
|
503
|
+
visitorId: string;
|
|
504
|
+
confidence: number;
|
|
505
|
+
} | null;
|
|
506
|
+
error: Error | null;
|
|
507
|
+
isLoading: boolean;
|
|
508
|
+
}
|
|
509
|
+
declare function useFingerprint(enabled: boolean): UseFingerprintResult;
|
|
510
|
+
|
|
511
|
+
export { type FraudEngineSdkConfig, type SdkConfig, SdkProvider, useFingerprint, useFraudEngine, useOrderRouter, usePayloadGenerator, useProfile, useSdk, useZkkyc };
|