@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
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # @p2pdotme/sdk
2
+
3
+ Multi-module TypeScript SDK for P2P.me. Published as a single package with subpath exports.
4
+
5
+ - Framework-agnostic core with optional React bindings
6
+ - Wallet-agnostic — consumers bring their own viem client
7
+ - No thrown exceptions — all methods return `Result` / `ResultAsync` via neverthrow
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ bun add @p2pdotme/sdk
13
+ ```
14
+
15
+ Peer dependency (required for React bindings):
16
+
17
+ ```bash
18
+ bun add react
19
+ ```
20
+
21
+ ## Modules
22
+
23
+ | Import | Description |
24
+ |--------|-------------|
25
+ | `@p2pdotme/sdk` | Shared types, `SdkError`, `ORDER_TYPE`, `VERSION` |
26
+ | `@p2pdotme/sdk/order-routing` | [Circle selection](./src/order-routing/README.md) via epsilon-greedy algorithm + on-chain eligibility |
27
+ | `@p2pdotme/sdk/payload` | [Order payload generation](./src/payload/README.md), ECIES encryption, relay identity |
28
+ | `@p2pdotme/sdk/profile` | [Account balances](./src/profile/README.md) (USDC + fiat) and price config reads |
29
+ | `@p2pdotme/sdk/qr-parsers` | [QR code parsers](./src/qr-parsers/README.md) for UPI, QRIS, PIX, MercadoPago, Pago Movil |
30
+ | `@p2pdotme/sdk/fraud-engine` | [Fraud detection](./src/fraud-engine/README.md), device fingerprinting, SEON integration |
31
+ | `@p2pdotme/sdk/zkkyc` | [ZK KYC verification](./src/zkkyc/README.md) — Reclaim, Anon Aadhaar, ZK Passport |
32
+ | `@p2pdotme/sdk/react` | Unified React provider (`SdkProvider`) + hooks |
33
+
34
+ ## Quick Start
35
+
36
+ ```tsx
37
+ import { SdkProvider, useOrderRouter, usePayloadGenerator, useProfile } from "@p2pdotme/sdk/react";
38
+ import { createPublicClient, http, parseUnits } from "viem";
39
+ import { base } from "viem/chains";
40
+
41
+ const publicClient = createPublicClient({ chain: base, transport: http(RPC_URL) });
42
+
43
+ function App() {
44
+ return (
45
+ <SdkProvider
46
+ publicClient={publicClient}
47
+ subgraphUrl={SUBGRAPH_URL}
48
+ diamondAddress={DIAMOND_ADDRESS}
49
+ usdcAddress={USDC_ADDRESS}
50
+ >
51
+ <BuyFlow />
52
+ </SdkProvider>
53
+ );
54
+ }
55
+
56
+ function BuyFlow() {
57
+ const profile = useProfile();
58
+ const payload = usePayloadGenerator();
59
+
60
+ async function handleBuy() {
61
+ // 1. Check balance
62
+ const balances = await profile.getBalances({
63
+ userAddress: "0xUser",
64
+ currency: "INR",
65
+ });
66
+
67
+ // 2. Build order payload (includes circle selection)
68
+ const order = await payload.placeOrder({
69
+ amount: parseUnits("10", 6),
70
+ recipientAddr: "0xRecipient",
71
+ orderType: 0, // BUY
72
+ currency: "INR",
73
+ fiatAmount: parseUnits("850", 6),
74
+ user: "0xUser",
75
+ });
76
+
77
+ order.match(
78
+ (data) => submitOnChain(data),
79
+ (error) => console.error(`[${error.code}] ${error.message}`),
80
+ );
81
+ }
82
+ }
83
+ ```
84
+
85
+ ## React Hooks
86
+
87
+ All hooks read from the nearest `<SdkProvider>`:
88
+
89
+ | Hook | Returns |
90
+ |------|---------|
91
+ | `useProfile()` | `Profile` — balance and price reads |
92
+ | `useOrderRouter()` | `OrderRouter` — circle selection |
93
+ | `usePayloadGenerator()` | `PayloadGenerator` — order payload building |
94
+ | `useZkkyc()` | `Zkkyc` — ZK verification (requires `reputationManagerAddress`) |
95
+ | `useFraudEngine()` | `FraudEngine` — fraud detection (requires `fraudEngine` config) |
96
+ | `useSdk()` | Full `Sdk` object |
97
+
98
+ ## Order Types
99
+
100
+ | Value | Type |
101
+ |-------|------|
102
+ | `0` | Buy |
103
+ | `1` | Sell |
104
+ | `2` | Pay |
105
+
106
+ ## Supported Currencies
107
+
108
+ `INR` | `IDR` | `BRL` | `ARS` | `MEX` | `VEN` | `NGN` | `USD`
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ bun install # install dependencies
114
+ bun run build # tsup → ESM + CJS + DTS into dist/
115
+ bun run dev # tsup --watch
116
+ bun run typecheck # tsc --noEmit
117
+ bun run lint # biome check src/
118
+ bun run test # vitest run
119
+ bun run size # show per-module bundle sizes
120
+ ```
121
+
122
+ ### Example App
123
+
124
+ ```bash
125
+ cd example
126
+ bun install
127
+ bun run dev # http://localhost:5173
128
+ ```
129
+
130
+ ### Git Hooks
131
+
132
+ - **pre-commit** — lint-staged (biome lint + format on staged files)
133
+ - **pre-push** — typecheck + build
134
+
135
+ ### Release
136
+
137
+ ```bash
138
+ bun run changeset # create a changeset
139
+ bun run release # build + publish
140
+ ```
141
+
142
+ ## Dependencies
143
+
144
+ | Package | Purpose |
145
+ |---------|---------|
146
+ | `viem` | Chain abstraction (address utils, hex encoding, contract reads) |
147
+ | `neverthrow` | Result/ResultAsync types (no thrown exceptions) |
148
+ | `zod` v4 | Runtime validation at SDK boundaries |
149
+ | `@fingerprintjs/fingerprintjs` | Browser fingerprinting (fraud-engine) |
150
+ | `@seontechnologies/seon-javascript-sdk` | SEON behavioral signals (fraud-engine) |
151
+ | `react` | Peer dependency (for `./react` export) |
152
+
153
+ ## License
154
+
155
+ Private