@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.
Files changed (50) hide show
  1. package/README.md +155 -0
  2. package/dist/fraud-engine.cjs +598 -0
  3. package/dist/fraud-engine.cjs.map +1 -0
  4. package/dist/fraud-engine.d.cts +194 -0
  5. package/dist/fraud-engine.d.ts +194 -0
  6. package/dist/fraud-engine.mjs +549 -0
  7. package/dist/fraud-engine.mjs.map +1 -0
  8. package/dist/index.cjs +75 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +49 -0
  11. package/dist/index.d.ts +49 -0
  12. package/dist/index.mjs +46 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/order-routing.cjs +882 -0
  15. package/dist/order-routing.cjs.map +1 -0
  16. package/dist/order-routing.d.cts +68 -0
  17. package/dist/order-routing.d.ts +68 -0
  18. package/dist/order-routing.mjs +854 -0
  19. package/dist/order-routing.mjs.map +1 -0
  20. package/dist/payload.cjs +3164 -0
  21. package/dist/payload.cjs.map +1 -0
  22. package/dist/payload.d.cts +162 -0
  23. package/dist/payload.d.ts +162 -0
  24. package/dist/payload.mjs +3120 -0
  25. package/dist/payload.mjs.map +1 -0
  26. package/dist/profile.cjs +695 -0
  27. package/dist/profile.cjs.map +1 -0
  28. package/dist/profile.d.cts +133 -0
  29. package/dist/profile.d.ts +133 -0
  30. package/dist/profile.mjs +667 -0
  31. package/dist/profile.mjs.map +1 -0
  32. package/dist/qr-parsers.cjs +366 -0
  33. package/dist/qr-parsers.cjs.map +1 -0
  34. package/dist/qr-parsers.d.cts +41 -0
  35. package/dist/qr-parsers.d.ts +41 -0
  36. package/dist/qr-parsers.mjs +338 -0
  37. package/dist/qr-parsers.mjs.map +1 -0
  38. package/dist/react.cjs +4803 -0
  39. package/dist/react.cjs.map +1 -0
  40. package/dist/react.d.cts +511 -0
  41. package/dist/react.d.ts +511 -0
  42. package/dist/react.mjs +4759 -0
  43. package/dist/react.mjs.map +1 -0
  44. package/dist/zkkyc.cjs +868 -0
  45. package/dist/zkkyc.cjs.map +1 -0
  46. package/dist/zkkyc.d.cts +230 -0
  47. package/dist/zkkyc.d.ts +230 -0
  48. package/dist/zkkyc.mjs +824 -0
  49. package/dist/zkkyc.mjs.map +1 -0
  50. package/package.json +130 -0
@@ -0,0 +1,194 @@
1
+ import * as neverthrow from 'neverthrow';
2
+
3
+ declare class SdkError<TCode extends string = string> extends Error {
4
+ readonly code: TCode;
5
+ readonly cause?: unknown;
6
+ readonly context?: Record<string, unknown>;
7
+ constructor(message: string, options: {
8
+ code: TCode;
9
+ cause?: unknown;
10
+ context?: Record<string, unknown>;
11
+ });
12
+ }
13
+
14
+ type FraudEngineErrorCode = "API_ERROR" | "ENCRYPTION_ERROR" | "SIGNING_ERROR" | "VALIDATION_ERROR" | "NETWORK_ERROR" | "PLACE_ORDER_ERROR";
15
+ declare class FraudEngineError extends SdkError<FraudEngineErrorCode> {
16
+ constructor(message: string, options: {
17
+ code: FraudEngineErrorCode;
18
+ cause?: unknown;
19
+ context?: Record<string, unknown>;
20
+ });
21
+ }
22
+
23
+ interface Logger {
24
+ debug(message: string, data?: Record<string, unknown>): void;
25
+ info(message: string, data?: Record<string, unknown>): void;
26
+ warn(message: string, data?: Record<string, unknown>): void;
27
+ error(message: string, data?: Record<string, unknown>): void;
28
+ }
29
+ declare const noopLogger: Logger;
30
+
31
+ interface FraudEngineSigner {
32
+ /**
33
+ * The subject address tracked by the fraud engine — the wallet that places
34
+ * on-chain orders and appears in reports, watchlist, and risk scoring.
35
+ *
36
+ * - For thirdweb smart wallets (ERC-4337 / account abstraction) this is the
37
+ * smart account address.
38
+ * - For plain EOA wallets this is the same address that produces signatures.
39
+ */
40
+ readonly address: string;
41
+ /**
42
+ * The address of the key that actually produces the EIP-191 signature.
43
+ * Defaults to {@link address} when omitted.
44
+ *
45
+ * Set this only when the tracked subject is a smart wallet whose admin EOA
46
+ * is the real signer (smart wallet contracts cannot sign EIP-191 directly).
47
+ * In that case, {@link address} is the smart wallet and `signerAddress` is
48
+ * the admin EOA.
49
+ */
50
+ readonly signerAddress?: string;
51
+ signMessage(message: string): Promise<string>;
52
+ }
53
+ interface FraudEngineConfig {
54
+ readonly apiUrl: string;
55
+ readonly encryptionKey: string;
56
+ readonly seonRegion?: string;
57
+ readonly logger?: Logger;
58
+ }
59
+ type ActivityType = "buy_order" | "fingerprint";
60
+ interface DeviceDetails {
61
+ readonly userAgent: string;
62
+ readonly platform: string;
63
+ readonly language: string;
64
+ readonly languages: string[];
65
+ readonly screenWidth: number;
66
+ readonly screenHeight: number;
67
+ readonly devicePixelRatio: number;
68
+ readonly timezone: string;
69
+ readonly timezoneOffset: number;
70
+ readonly cookiesEnabled: boolean;
71
+ readonly doNotTrack: string | null;
72
+ readonly online: boolean;
73
+ readonly connectionType?: string;
74
+ readonly deviceMemory?: number;
75
+ readonly hardwareConcurrency?: number;
76
+ readonly touchSupport: boolean;
77
+ readonly maxTouchPoints: number;
78
+ readonly vendor: string;
79
+ readonly appVersion: string;
80
+ readonly colorDepth: number;
81
+ readonly pixelDepth: number;
82
+ readonly ip?: string;
83
+ readonly seonSession?: string;
84
+ }
85
+ interface BuyOrderDetails {
86
+ readonly cryptoAmount: number;
87
+ readonly fiatAmount: number;
88
+ readonly currency: string;
89
+ readonly recipientAddress: string;
90
+ readonly fee: number;
91
+ readonly amountAfterFee: number;
92
+ readonly paymentMethod?: string;
93
+ readonly estimatedProcessingTime?: string;
94
+ }
95
+ interface UserDetails {
96
+ readonly currency?: string;
97
+ readonly country?: string;
98
+ readonly language?: string;
99
+ readonly loginMethod?: "email" | "google" | "phone" | "passkey" | "unknown";
100
+ readonly loginEmail?: string;
101
+ readonly loginPhone?: string;
102
+ }
103
+ interface FraudCheckApiResponse {
104
+ readonly success: boolean;
105
+ readonly approved: boolean;
106
+ readonly activity_log_id: number;
107
+ readonly message: string;
108
+ }
109
+ interface FraudCheckResult {
110
+ readonly approved: boolean;
111
+ readonly activityLogId: number;
112
+ readonly message: string;
113
+ /**
114
+ * Link an on-chain order ID to this activity log record.
115
+ * Call after the buy order is placed on-chain (fire-and-forget).
116
+ * The signer and activityLogId are captured internally — just pass the orderId.
117
+ */
118
+ linkOrder(orderId: string): neverthrow.ResultAsync<LinkOrderResult, FraudEngineError>;
119
+ }
120
+ interface LinkOrderResult {
121
+ readonly success: boolean;
122
+ readonly message: string;
123
+ }
124
+ interface FingerprintLogResult {
125
+ readonly success: boolean;
126
+ readonly message: string;
127
+ }
128
+ type ProcessBuyOrderResult = {
129
+ readonly status: "placed";
130
+ readonly orderId: string;
131
+ } | {
132
+ readonly status: "rejected";
133
+ readonly message: string;
134
+ };
135
+ interface FraudEngine {
136
+ init(): Promise<void>;
137
+ /**
138
+ * Low-level: run fraud check only. Returns result with `linkOrder()` for manual linking.
139
+ * For most consumers, prefer `processBuyOrder()` which handles the full flow.
140
+ */
141
+ checkBuyOrder(params: {
142
+ signer: FraudEngineSigner;
143
+ orderDetails: BuyOrderDetails;
144
+ userDetails?: UserDetails;
145
+ orderSource?: string;
146
+ }): neverthrow.ResultAsync<FraudCheckResult, FraudEngineError>;
147
+ /**
148
+ * Full orchestration: fraud check → place order → auto-link.
149
+ *
150
+ * - Runs fraud check on all buy orders (backend handles currency-specific logic).
151
+ * If rejected, returns `{ status: "rejected" }` without calling `placeOrder`.
152
+ * If approved, calls `placeOrder`, auto-links activity log, returns `{ status: "placed", orderId }`.
153
+ * - Fail-open: if fraud check API errors, still calls `placeOrder` (no linking since no activityLogId).
154
+ * - Linking is fire-and-forget: if link fails, order is already placed — error is logged, not propagated.
155
+ */
156
+ processBuyOrder(params: {
157
+ signer: FraudEngineSigner;
158
+ orderDetails: BuyOrderDetails;
159
+ userDetails?: UserDetails;
160
+ orderSource?: string;
161
+ placeOrder: () => Promise<string>;
162
+ }): neverthrow.ResultAsync<ProcessBuyOrderResult, FraudEngineError>;
163
+ logFingerprint(params: {
164
+ signer: FraudEngineSigner;
165
+ }): neverthrow.ResultAsync<FingerprintLogResult | null, FraudEngineError>;
166
+ getFingerprint(): Promise<{
167
+ visitorId: string;
168
+ confidence: number;
169
+ } | null>;
170
+ getDeviceDetails(): Promise<DeviceDetails>;
171
+ cleanupSeonStorage(): void;
172
+ }
173
+
174
+ declare function createFraudEngine(config: FraudEngineConfig): FraudEngine;
175
+
176
+ declare function getBasicDeviceDetails(): Omit<DeviceDetails, "ip" | "seonSession">;
177
+ declare function fetchIpAddress(): Promise<string | undefined>;
178
+ declare function getDeviceDetails(seonSession?: string): Promise<DeviceDetails>;
179
+
180
+ declare function encryptPayload(payload: string, aad: string, encryptionKeyHex: string): Promise<string>;
181
+
182
+ declare function loadFingerprintAgent(): Promise<void>;
183
+ declare function getFingerprint(timeoutMs?: number): Promise<{
184
+ visitorId: string;
185
+ confidence: number;
186
+ } | null>;
187
+
188
+ declare function initSeon(): void;
189
+ declare function getSeonSession(region: string): Promise<string | undefined>;
190
+ declare function cleanupSeonStorage(): void;
191
+
192
+ declare function getSignedHeaders(signer: FraudEngineSigner, action: "activity-log" | "link-order" | "fingerprint-log"): Promise<Record<string, string>>;
193
+
194
+ export { type ActivityType, type BuyOrderDetails, type DeviceDetails, type FingerprintLogResult, type FraudCheckApiResponse, type FraudCheckResult, type FraudEngine, type FraudEngineConfig, FraudEngineError, type FraudEngineErrorCode, type FraudEngineSigner, type LinkOrderResult, type Logger, type ProcessBuyOrderResult, type UserDetails, cleanupSeonStorage, createFraudEngine, encryptPayload, fetchIpAddress, getBasicDeviceDetails, getDeviceDetails, getFingerprint, getSeonSession, getSignedHeaders, initSeon, loadFingerprintAgent, noopLogger };
@@ -0,0 +1,194 @@
1
+ import * as neverthrow from 'neverthrow';
2
+
3
+ declare class SdkError<TCode extends string = string> extends Error {
4
+ readonly code: TCode;
5
+ readonly cause?: unknown;
6
+ readonly context?: Record<string, unknown>;
7
+ constructor(message: string, options: {
8
+ code: TCode;
9
+ cause?: unknown;
10
+ context?: Record<string, unknown>;
11
+ });
12
+ }
13
+
14
+ type FraudEngineErrorCode = "API_ERROR" | "ENCRYPTION_ERROR" | "SIGNING_ERROR" | "VALIDATION_ERROR" | "NETWORK_ERROR" | "PLACE_ORDER_ERROR";
15
+ declare class FraudEngineError extends SdkError<FraudEngineErrorCode> {
16
+ constructor(message: string, options: {
17
+ code: FraudEngineErrorCode;
18
+ cause?: unknown;
19
+ context?: Record<string, unknown>;
20
+ });
21
+ }
22
+
23
+ interface Logger {
24
+ debug(message: string, data?: Record<string, unknown>): void;
25
+ info(message: string, data?: Record<string, unknown>): void;
26
+ warn(message: string, data?: Record<string, unknown>): void;
27
+ error(message: string, data?: Record<string, unknown>): void;
28
+ }
29
+ declare const noopLogger: Logger;
30
+
31
+ interface FraudEngineSigner {
32
+ /**
33
+ * The subject address tracked by the fraud engine — the wallet that places
34
+ * on-chain orders and appears in reports, watchlist, and risk scoring.
35
+ *
36
+ * - For thirdweb smart wallets (ERC-4337 / account abstraction) this is the
37
+ * smart account address.
38
+ * - For plain EOA wallets this is the same address that produces signatures.
39
+ */
40
+ readonly address: string;
41
+ /**
42
+ * The address of the key that actually produces the EIP-191 signature.
43
+ * Defaults to {@link address} when omitted.
44
+ *
45
+ * Set this only when the tracked subject is a smart wallet whose admin EOA
46
+ * is the real signer (smart wallet contracts cannot sign EIP-191 directly).
47
+ * In that case, {@link address} is the smart wallet and `signerAddress` is
48
+ * the admin EOA.
49
+ */
50
+ readonly signerAddress?: string;
51
+ signMessage(message: string): Promise<string>;
52
+ }
53
+ interface FraudEngineConfig {
54
+ readonly apiUrl: string;
55
+ readonly encryptionKey: string;
56
+ readonly seonRegion?: string;
57
+ readonly logger?: Logger;
58
+ }
59
+ type ActivityType = "buy_order" | "fingerprint";
60
+ interface DeviceDetails {
61
+ readonly userAgent: string;
62
+ readonly platform: string;
63
+ readonly language: string;
64
+ readonly languages: string[];
65
+ readonly screenWidth: number;
66
+ readonly screenHeight: number;
67
+ readonly devicePixelRatio: number;
68
+ readonly timezone: string;
69
+ readonly timezoneOffset: number;
70
+ readonly cookiesEnabled: boolean;
71
+ readonly doNotTrack: string | null;
72
+ readonly online: boolean;
73
+ readonly connectionType?: string;
74
+ readonly deviceMemory?: number;
75
+ readonly hardwareConcurrency?: number;
76
+ readonly touchSupport: boolean;
77
+ readonly maxTouchPoints: number;
78
+ readonly vendor: string;
79
+ readonly appVersion: string;
80
+ readonly colorDepth: number;
81
+ readonly pixelDepth: number;
82
+ readonly ip?: string;
83
+ readonly seonSession?: string;
84
+ }
85
+ interface BuyOrderDetails {
86
+ readonly cryptoAmount: number;
87
+ readonly fiatAmount: number;
88
+ readonly currency: string;
89
+ readonly recipientAddress: string;
90
+ readonly fee: number;
91
+ readonly amountAfterFee: number;
92
+ readonly paymentMethod?: string;
93
+ readonly estimatedProcessingTime?: string;
94
+ }
95
+ interface UserDetails {
96
+ readonly currency?: string;
97
+ readonly country?: string;
98
+ readonly language?: string;
99
+ readonly loginMethod?: "email" | "google" | "phone" | "passkey" | "unknown";
100
+ readonly loginEmail?: string;
101
+ readonly loginPhone?: string;
102
+ }
103
+ interface FraudCheckApiResponse {
104
+ readonly success: boolean;
105
+ readonly approved: boolean;
106
+ readonly activity_log_id: number;
107
+ readonly message: string;
108
+ }
109
+ interface FraudCheckResult {
110
+ readonly approved: boolean;
111
+ readonly activityLogId: number;
112
+ readonly message: string;
113
+ /**
114
+ * Link an on-chain order ID to this activity log record.
115
+ * Call after the buy order is placed on-chain (fire-and-forget).
116
+ * The signer and activityLogId are captured internally — just pass the orderId.
117
+ */
118
+ linkOrder(orderId: string): neverthrow.ResultAsync<LinkOrderResult, FraudEngineError>;
119
+ }
120
+ interface LinkOrderResult {
121
+ readonly success: boolean;
122
+ readonly message: string;
123
+ }
124
+ interface FingerprintLogResult {
125
+ readonly success: boolean;
126
+ readonly message: string;
127
+ }
128
+ type ProcessBuyOrderResult = {
129
+ readonly status: "placed";
130
+ readonly orderId: string;
131
+ } | {
132
+ readonly status: "rejected";
133
+ readonly message: string;
134
+ };
135
+ interface FraudEngine {
136
+ init(): Promise<void>;
137
+ /**
138
+ * Low-level: run fraud check only. Returns result with `linkOrder()` for manual linking.
139
+ * For most consumers, prefer `processBuyOrder()` which handles the full flow.
140
+ */
141
+ checkBuyOrder(params: {
142
+ signer: FraudEngineSigner;
143
+ orderDetails: BuyOrderDetails;
144
+ userDetails?: UserDetails;
145
+ orderSource?: string;
146
+ }): neverthrow.ResultAsync<FraudCheckResult, FraudEngineError>;
147
+ /**
148
+ * Full orchestration: fraud check → place order → auto-link.
149
+ *
150
+ * - Runs fraud check on all buy orders (backend handles currency-specific logic).
151
+ * If rejected, returns `{ status: "rejected" }` without calling `placeOrder`.
152
+ * If approved, calls `placeOrder`, auto-links activity log, returns `{ status: "placed", orderId }`.
153
+ * - Fail-open: if fraud check API errors, still calls `placeOrder` (no linking since no activityLogId).
154
+ * - Linking is fire-and-forget: if link fails, order is already placed — error is logged, not propagated.
155
+ */
156
+ processBuyOrder(params: {
157
+ signer: FraudEngineSigner;
158
+ orderDetails: BuyOrderDetails;
159
+ userDetails?: UserDetails;
160
+ orderSource?: string;
161
+ placeOrder: () => Promise<string>;
162
+ }): neverthrow.ResultAsync<ProcessBuyOrderResult, FraudEngineError>;
163
+ logFingerprint(params: {
164
+ signer: FraudEngineSigner;
165
+ }): neverthrow.ResultAsync<FingerprintLogResult | null, FraudEngineError>;
166
+ getFingerprint(): Promise<{
167
+ visitorId: string;
168
+ confidence: number;
169
+ } | null>;
170
+ getDeviceDetails(): Promise<DeviceDetails>;
171
+ cleanupSeonStorage(): void;
172
+ }
173
+
174
+ declare function createFraudEngine(config: FraudEngineConfig): FraudEngine;
175
+
176
+ declare function getBasicDeviceDetails(): Omit<DeviceDetails, "ip" | "seonSession">;
177
+ declare function fetchIpAddress(): Promise<string | undefined>;
178
+ declare function getDeviceDetails(seonSession?: string): Promise<DeviceDetails>;
179
+
180
+ declare function encryptPayload(payload: string, aad: string, encryptionKeyHex: string): Promise<string>;
181
+
182
+ declare function loadFingerprintAgent(): Promise<void>;
183
+ declare function getFingerprint(timeoutMs?: number): Promise<{
184
+ visitorId: string;
185
+ confidence: number;
186
+ } | null>;
187
+
188
+ declare function initSeon(): void;
189
+ declare function getSeonSession(region: string): Promise<string | undefined>;
190
+ declare function cleanupSeonStorage(): void;
191
+
192
+ declare function getSignedHeaders(signer: FraudEngineSigner, action: "activity-log" | "link-order" | "fingerprint-log"): Promise<Record<string, string>>;
193
+
194
+ export { type ActivityType, type BuyOrderDetails, type DeviceDetails, type FingerprintLogResult, type FraudCheckApiResponse, type FraudCheckResult, type FraudEngine, type FraudEngineConfig, FraudEngineError, type FraudEngineErrorCode, type FraudEngineSigner, type LinkOrderResult, type Logger, type ProcessBuyOrderResult, type UserDetails, cleanupSeonStorage, createFraudEngine, encryptPayload, fetchIpAddress, getBasicDeviceDetails, getDeviceDetails, getFingerprint, getSeonSession, getSignedHeaders, initSeon, loadFingerprintAgent, noopLogger };