@usdctofiat/offramp 1.1.4 → 2.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.
@@ -0,0 +1,236 @@
1
+ import { currencyInfo } from '@zkp2p/sdk';
2
+
3
+ type PlatformId = "venmo" | "cashapp" | "chime" | "revolut" | "wise" | "mercadopago" | "zelle" | "paypal" | "monzo" | "n26";
4
+ /**
5
+ * Describes the Peer browser-extension pre-registration requirement for a
6
+ * platform. When present, curator's `/v2/makers/create` will reject the maker
7
+ * until the user has registered their handle inside the Peer (PeerAuth)
8
+ * extension at `/verify/<providerId>`.
9
+ *
10
+ * Drives the {@link isPeerExtensionRegistrationError} check and the React
11
+ * `usePeerExtensionRegistration` hook in `@usdctofiat/offramp/react`.
12
+ */
13
+ interface PeerExtensionRegistrationInfo {
14
+ /**
15
+ * Upstream provider id — matches the Peer extension verify handler. Used
16
+ * to build the sidebar route (`/verify/<providerId>`).
17
+ */
18
+ readonly providerId: string;
19
+ /** Human-readable message surfaced when curator rejects the maker. */
20
+ readonly requiredPrompt: string;
21
+ /** Label for the install / connect / verify CTA. */
22
+ readonly ctaLabel: string;
23
+ /** Optional subtext (e.g. PayPal Business disclaimer). */
24
+ readonly ctaSubtext?: string;
25
+ /** Minimum Peer extension version expected for this provider. */
26
+ readonly minExtensionVersion: string;
27
+ }
28
+ interface PlatformEntry {
29
+ readonly id: PlatformId;
30
+ readonly name: string;
31
+ readonly currencies: readonly string[];
32
+ readonly identifier: {
33
+ readonly label: string;
34
+ readonly placeholder: string;
35
+ readonly help: string;
36
+ };
37
+ /**
38
+ * Present when curator requires the maker to first register this handle in
39
+ * the Peer extension before `/v2/makers/create` will succeed. Today this
40
+ * applies to PayPal and Wise. See `@usdctofiat/offramp/react` for the
41
+ * `usePeerExtensionRegistration` hook that drives the handshake.
42
+ */
43
+ readonly extensionRegistration?: PeerExtensionRegistrationInfo;
44
+ validate(input: string): {
45
+ valid: boolean;
46
+ normalized: string;
47
+ error?: string;
48
+ };
49
+ }
50
+ /**
51
+ * Extracts the bare PayPal.me username from any accepted input shape
52
+ * (`paypal.me/user`, `https://paypal.me/user`, `@user`, `user`). Mirrors the
53
+ * upstream zkp2p-clients normalizer so our offchainId hashes identically.
54
+ */
55
+ declare function normalizePaypalMeUsername(value: string): string;
56
+ /** All supported payment platforms. Access via `PLATFORMS.REVOLUT`, `PLATFORMS.WISE`, etc. */
57
+ declare const PLATFORMS: {
58
+ readonly VENMO: PlatformEntry;
59
+ readonly CASHAPP: PlatformEntry;
60
+ readonly CHIME: PlatformEntry;
61
+ readonly REVOLUT: PlatformEntry;
62
+ readonly WISE: PlatformEntry;
63
+ readonly MERCADO_PAGO: PlatformEntry;
64
+ readonly ZELLE: PlatformEntry;
65
+ readonly PAYPAL: PlatformEntry;
66
+ readonly MONZO: PlatformEntry;
67
+ readonly N26: PlatformEntry;
68
+ };
69
+ /** Platform key type for PLATFORMS constant. */
70
+ type PlatformKey = keyof typeof PLATFORMS;
71
+ /**
72
+ * Shape curator's `/v2/makers/create` expects since the flat-offchainId
73
+ * migration (upstream #580). The endpoint hashes `offchainId + processorName`
74
+ * directly — legacy platform-specific keys (`paypalEmail`, `venmoUsername`,
75
+ * `wisetag`, …) are no longer accepted.
76
+ */
77
+ interface PayeeDepositData {
78
+ offchainId: string;
79
+ telegramUsername?: string;
80
+ metadata?: Record<string, string>;
81
+ }
82
+ /**
83
+ * Returns the extension-registration metadata for a platform, or `null` if
84
+ * the platform does not require Peer-extension pre-registration. Use this to
85
+ * decide whether to surface an "Install / Connect Peer Extension" CTA in
86
+ * your UI before calling `offramp()` for PayPal or Wise.
87
+ */
88
+ declare function getPeerExtensionRegistrationInfo(platform: string): PeerExtensionRegistrationInfo | null;
89
+ /**
90
+ * True when a failed `/v2/makers/create` response should be interpreted as
91
+ * "maker needs to register in the Peer extension first". Platforms without
92
+ * an `extensionRegistration` config always return false.
93
+ *
94
+ * Mirrors upstream `isExtensionRegistrationRequiredPostError`: a 400 status
95
+ * on a registration-required platform is treated as registration required,
96
+ * and so is any response whose message contains the curator phrasing.
97
+ */
98
+ declare function isPeerExtensionRegistrationError(platform: string, message?: string | null, statusCode?: number | null): boolean;
99
+
100
+ interface CurrencyEntry {
101
+ readonly code: string;
102
+ readonly name: string;
103
+ readonly symbol: string;
104
+ readonly countryCode: string;
105
+ }
106
+ type CurrencyMap = {
107
+ readonly [K in keyof typeof currencyInfo]: CurrencyEntry;
108
+ };
109
+ /** All supported currencies with metadata. Access via `CURRENCIES.EUR.symbol` etc. */
110
+ declare const CURRENCIES: CurrencyMap;
111
+
112
+ declare const OFFRAMP_ERROR_CODES: {
113
+ readonly VALIDATION: "VALIDATION";
114
+ readonly APPROVAL_FAILED: "APPROVAL_FAILED";
115
+ readonly REGISTRATION_FAILED: "REGISTRATION_FAILED";
116
+ /**
117
+ * Curator rejected the maker because the user has not registered this
118
+ * handle in the Peer extension yet. Thrown from `offramp()` for PayPal
119
+ * and Wise when `/v2/makers/create` returns 400 or a "creating the maker"
120
+ * message. Recover by prompting the user through the Peer extension via
121
+ * `usePeerExtensionRegistration(platform)` (React) or `peerExtensionSdk`
122
+ * directly, then call `offramp()` again.
123
+ */
124
+ readonly EXTENSION_REGISTRATION_REQUIRED: "EXTENSION_REGISTRATION_REQUIRED";
125
+ readonly DEPOSIT_FAILED: "DEPOSIT_FAILED";
126
+ readonly CONFIRMATION_FAILED: "CONFIRMATION_FAILED";
127
+ readonly DELEGATION_FAILED: "DELEGATION_FAILED";
128
+ readonly USER_CANCELLED: "USER_CANCELLED";
129
+ readonly UNSUPPORTED: "UNSUPPORTED";
130
+ };
131
+ type OfframpErrorCode = (typeof OFFRAMP_ERROR_CODES)[keyof typeof OFFRAMP_ERROR_CODES];
132
+ interface OfframpParams {
133
+ /** USDC amount as decimal string, min 1. */
134
+ amount: string;
135
+ /** Payment platform — use `PLATFORMS.REVOLUT` etc. */
136
+ platform: PlatformEntry;
137
+ /** Fiat currency — use `CURRENCIES.EUR` etc. */
138
+ currency: CurrencyEntry;
139
+ /** Platform-specific identifier (username, email, IBAN). */
140
+ identifier: string;
141
+ /** Optional: restrict the deposit to this taker wallet (OTC private order). */
142
+ otcTaker?: string;
143
+ /** Optional SDK-only referral metadata for telemetry attribution. */
144
+ referralId?: string;
145
+ /** Optional SDK-only integrator metadata for telemetry attribution. */
146
+ integratorId?: string;
147
+ /** Optional per-wallet key to replay the first successful result for 10 minutes. */
148
+ idempotencyKey?: string;
149
+ }
150
+ interface OfframpResult {
151
+ depositId: string;
152
+ txHash: string;
153
+ /** Whether an existing undelegated deposit was resumed. */
154
+ resumed: boolean;
155
+ /** OTC link for the taker, present when `otcTaker` was provided. */
156
+ otcLink?: string;
157
+ }
158
+ type OfframpStep = "approving" | "registering" | "depositing" | "confirming" | "delegating" | "restricting" | "resuming" | "done";
159
+ type OfframpState = "idle" | "approving" | "registering" | "depositing" | "confirming" | "delegating" | "done" | "error";
160
+ interface OfframpProgress {
161
+ step: OfframpStep;
162
+ txHash?: string;
163
+ depositId?: string;
164
+ }
165
+ type OnProgress = (progress: OfframpProgress) => void;
166
+ type DepositStatus = "active" | "empty" | "closed";
167
+ interface OfframpQuoteInput {
168
+ amount: string;
169
+ currency: CurrencyEntry;
170
+ platform: PlatformEntry;
171
+ }
172
+ interface OfframpQuote {
173
+ amountUsdc: number;
174
+ expectedFiat: number;
175
+ effectiveRate: number;
176
+ vaultSpreadBps: number;
177
+ }
178
+ interface OfframpVaultStatus {
179
+ rateManagerId: string;
180
+ rateManagerAddress: string;
181
+ feeRateBps: number;
182
+ escrow: string;
183
+ isActive: boolean;
184
+ }
185
+ interface OfframpCreateOptions {
186
+ integratorId?: string;
187
+ referralId?: string;
188
+ telemetry?: boolean;
189
+ }
190
+ interface DepositInfo {
191
+ /** Numeric deposit ID. Pass this to `close()`. */
192
+ depositId: string;
193
+ /** Composite ID (escrowAddress_depositId). */
194
+ compositeId: string;
195
+ /** Creation transaction hash. */
196
+ txHash?: string;
197
+ status: DepositStatus;
198
+ remainingUsdc: number;
199
+ outstandingUsdc: number;
200
+ totalTakenUsdc: number;
201
+ fulfilledIntents: number;
202
+ paymentMethods: string[];
203
+ currencies: string[];
204
+ rateSource: string;
205
+ delegated: boolean;
206
+ escrowAddress: string;
207
+ }
208
+
209
+ /**
210
+ * Error thrown when curator's `/v2/makers/create` returns a non-success
211
+ * response. Preserves the HTTP status so callers can distinguish a
212
+ * "needs Peer-extension registration" 400 from a transient server error.
213
+ *
214
+ * `offramp()` re-raises this as an {@link OfframpError} with code
215
+ * `EXTENSION_REGISTRATION_REQUIRED` (for PayPal/Wise 400s) or
216
+ * `REGISTRATION_FAILED` (for any other curator error); `MakersCreateError`
217
+ * is attached as the `cause`.
218
+ */
219
+ declare class MakersCreateError extends Error {
220
+ readonly status: number | null;
221
+ readonly body: string;
222
+ constructor(message: string, status: number | null, body: string);
223
+ }
224
+ declare class OfframpError extends Error {
225
+ readonly code: OfframpErrorCode;
226
+ readonly step?: OfframpStep;
227
+ readonly cause?: unknown;
228
+ readonly txHash?: string;
229
+ readonly depositId?: string;
230
+ constructor(message: string, code: OfframpErrorCode, step?: OfframpStep, cause?: unknown, details?: {
231
+ txHash?: string;
232
+ depositId?: string;
233
+ });
234
+ }
235
+
236
+ export { type CurrencyEntry as C, type DepositInfo as D, MakersCreateError as M, type OfframpParams as O, type PlatformEntry as P, type OnProgress as a, type OfframpResult as b, type OfframpCreateOptions as c, type OfframpQuoteInput as d, type OfframpQuote as e, type OfframpVaultStatus as f, CURRENCIES as g, type DepositStatus as h, OFFRAMP_ERROR_CODES as i, OfframpError as j, type OfframpErrorCode as k, type OfframpProgress as l, type OfframpState as m, type OfframpStep as n, PLATFORMS as o, type PayeeDepositData as p, type PeerExtensionRegistrationInfo as q, type PlatformKey as r, getPeerExtensionRegistrationInfo as s, isPeerExtensionRegistrationError as t, normalizePaypalMeUsername as u };