@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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,252 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@usdctofiat/offramp` will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [2.0.0] - 2026-04-24
11
+
12
+ ### ⚠ BREAKING CHANGES
13
+
14
+ The upstream zkp2p-clients protocol cut curator's maker registration over to a
15
+ new schema and endpoint, and now requires Peer browser-extension
16
+ pre-registration for PayPal and Wise makers. Previous versions of this SDK
17
+ were silently broken against the live API. Upgrading is **mandatory** for any
18
+ integrator still on `1.x` — the old payload shape is rejected by curator.
19
+
20
+ - **Endpoint**: maker registration now hits `POST /v2/makers/create`
21
+ (upstream commit 3243ce5). `/v1/makers/create` is gone.
22
+ - **Payload shape**: `buildDepositData(platform, identifier, telegramUsername?)`
23
+ now returns `{ offchainId, telegramUsername? }` instead of legacy
24
+ platform-specific blobs like `{ paypalEmail, venmoUsername, wisetag, … }`
25
+ (upstream commit e4e5bdd / PR #580). Curator hashes `offchainId + processorName`
26
+ directly, so the old keys are no longer read.
27
+ - **PayPal identifier**: PayPal deposits now use the PayPal.me username as the
28
+ offchainId, not the account email (upstream #649). `PLATFORMS.PAYPAL.validate(...)`
29
+ rejects emails and accepts `paypal.me/user`, `@user`, or the bare username,
30
+ all normalized to a lowercase `paypal.me` username.
31
+ - **New error code**: `OFFRAMP_ERROR_CODES.EXTENSION_REGISTRATION_REQUIRED`.
32
+ `offramp()` throws this when curator rejects a PayPal or Wise maker because
33
+ the user has not yet registered their handle inside the Peer (PeerAuth)
34
+ browser extension. Recover via `usePeerExtensionRegistration(platform)` (React)
35
+ or drive `peerExtensionSdk` manually, then retry the call.
36
+
37
+ ### Added
38
+
39
+ - **Extension handshake helpers** (core entry point):
40
+ - `peerExtensionSdk`, `PEER_EXTENSION_CHROME_URL`, `getPeerExtensionState`,
41
+ `isPeerExtensionAvailable`, `openPeerExtensionInstallPage`,
42
+ `createPeerExtensionSdk` — re-exports from `@zkp2p/sdk` so integrators
43
+ don't need a direct transitive dependency on it.
44
+ - Types: `PeerExtensionApi`, `PeerExtensionSdk`, `PeerExtensionSdkOptions`,
45
+ `PeerExtensionState`, `PeerExtensionWindow`, `PeerConnectionStatus`.
46
+ - **React hook** `usePeerExtensionRegistration(platform)` in
47
+ `@usdctofiat/offramp/react`. Drives the full install → connect → verify
48
+ flow with a phase state machine (`checking | needs_install | needs_connection | ready | unsupported`),
49
+ auto-invoking `requestConnection()` and `openSidebar('/verify/<providerId>')`
50
+ in response to `peerExtensionSdk.getState()`.
51
+ - **Platform metadata**: `PLATFORMS.PAYPAL.extensionRegistration` and
52
+ `PLATFORMS.WISE.extensionRegistration` surface the `providerId`, user-facing
53
+ prompt, CTA copy, and minimum extension version. Access via
54
+ `getPeerExtensionRegistrationInfo(platformId)`.
55
+ - **Error detection helper**: `isPeerExtensionRegistrationError(platformId, message, statusCode)`
56
+ returns true when a failed `/v2/makers/create` response should be treated as
57
+ "maker needs extension registration". Mirrors the upstream heuristic
58
+ (400 status on a registration-required platform, or any response whose
59
+ message contains `creating the maker` / `create the maker`).
60
+ - **MakersCreateError**: thrown by the internal maker-registration fetch,
61
+ preserving the HTTP status and raw response body so callers can inspect the
62
+ failure. Re-raised by `offramp()` as the `cause` on the surfaced `OfframpError`.
63
+ - **PayPal.me normalizer**: `normalizePaypalMeUsername(input)` exported for
64
+ integrators that want to normalize user input before hashing or display.
65
+ - **`PayeeDepositData`** type (the flat shape returned by `buildDepositData`).
66
+
67
+ ### Changed
68
+
69
+ - `PLATFORMS.PAYPAL.identifier` updated to username semantics (`label: "PayPal.me Username"`,
70
+ `placeholder: "paypal.me/your-username"`, `help: "Your PayPal.me username, not your email"`).
71
+ - `PLATFORMS.PAYPAL.validate(...)` enforces `[a-z0-9._-]+` and lowercases the
72
+ normalized value.
73
+ - `PLATFORMS.WISE` now ships `extensionRegistration` metadata (no prompt change
74
+ for the happy path).
75
+
76
+ ### Migration guide
77
+
78
+ If you were on `@usdctofiat/offramp@1.x`:
79
+
80
+ 1. Upgrade to `2.0.0`.
81
+ 2. For PayPal integrations, re-prompt users for their PayPal.me username
82
+ (not email). You can round-trip legacy emails through
83
+ `PLATFORMS.PAYPAL.validate(email)` to detect them — invalid input signals
84
+ the user needs to re-enter.
85
+ 3. Handle the new `EXTENSION_REGISTRATION_REQUIRED` error. Minimum example
86
+ with the React hook:
87
+
88
+ ```tsx
89
+ import { PLATFORMS, OFFRAMP_ERROR_CODES } from "@usdctofiat/offramp";
90
+ import { useOfframp, usePeerExtensionRegistration } from "@usdctofiat/offramp/react";
91
+
92
+ const { offramp, lastError } = useOfframp();
93
+ const peer = usePeerExtensionRegistration(PLATFORMS.PAYPAL);
94
+
95
+ if (lastError?.code === OFFRAMP_ERROR_CODES.EXTENSION_REGISTRATION_REQUIRED) {
96
+ // Render peer.phase-aware CTAs using peer.installExtension /
97
+ // peer.connectExtension / peer.openVerifySidebar, then call offramp() again.
98
+ }
99
+ ```
100
+
101
+ 4. If you hand-rolled a `POST /v1/makers/create` call, switch to
102
+ `POST /v2/makers/create` with `{ processorName, offchainId, telegramUsername? }`.
103
+
104
+ ## [1.3.0] - 2026-04-21
105
+
106
+ ### Removed
107
+
108
+ - Widget entry point. The `@usdctofiat/offramp/widget` subpath and its exports (`OfframpButton`, `OfframpInline`, `OfframpDrawer`), plus the `sdk.widget.view` / `sdk.widget.click` telemetry events. Call `offramp(...)` directly or use `useOfframp` from `@usdctofiat/offramp/react`. The `create-offramp-app` templates were updated to the plain-function flow.
109
+
110
+ ## [1.2.0] - 2026-04-21
111
+
112
+ ### Added
113
+
114
+ - Widget entry point at `@usdctofiat/offramp/widget` with `OfframpButton`, `OfframpInline`, `OfframpDrawer` components and `sdk.widget.*` telemetry events. Reverted in 1.3.0.
115
+ - Anonymous SDK usage telemetry (`sdk.deposit.*`) written to Firestore. Opt out via `new Offramp({ telemetry: false })`.
116
+
117
+ ### Changed
118
+
119
+ - `viem` moved from a direct dependency to a peer dependency so consumers share a single `viem` copy with the SDK, preventing duplicate-module `WalletClient` type clashes.
120
+
121
+ ## [1.1.4] - 2026-04-16
122
+
123
+ ### Fixed
124
+
125
+ - Case-insensitive `rateManagerId` comparison when matching delegated deposits.
126
+
127
+ ## [1.1.3] - 2026-04-09
128
+
129
+ ### Changed
130
+
131
+ - Bump `@zkp2p/sdk` to `0.3.1`. Picks up the curator API migration: the SDK now targets `/v3/intent/sign` (the legacy `/v3/intent` path is still aliased but scheduled for removal on 2026-07-01) and the maker schema is now flat (`offchainId` + `telegramUsername` columns). Transparent to SDK consumers.
132
+
133
+ ## [1.1.2] - 2026-04-06
134
+
135
+ ### Fixed
136
+
137
+ - Widen `viem` dependency from exact `2.45.3` to `^2.45.0`. The exact pin introduced in 1.1.1 forced npm to install a nested copy of `viem` whenever the consumer had any other `viem` version, causing TypeScript `Client is not assignable to Client` errors at the SDK boundary (two structurally identical but distinct module copies).
138
+
139
+ ## [1.1.1] - 2026-04-05
140
+
141
+ ### Fixed
142
+
143
+ - Updated `WhitelistPreIntentHook` address to the redeployed contract. The old hook reverted on OTC intent fulfillment via `OrchestratorV2`.
144
+
145
+ ## [1.1.0] - 2026-04-03
146
+
147
+ ### Added
148
+
149
+ - OTC private orders: restrict a deposit to a single taker wallet.
150
+ - `otcTaker` parameter on `offramp()` for one-call OTC deposit creation.
151
+ - `enableOtc(walletClient, depositId, takerAddress)` to restrict an existing deposit.
152
+ - `disableOtc(walletClient, depositId)` to make a deposit public again.
153
+ - `getOtcLink(depositId)` returns the taker URL without a transaction.
154
+ - `OfframpResult.otcLink` returned when `otcTaker` is provided.
155
+ - `"restricting"` step added to `OfframpStep` for progress callbacks.
156
+
157
+ ## [1.0.1] - 2026-03-29
158
+
159
+ ### Fixed
160
+
161
+ - Resume the most recent undelegated deposit first when a wallet has multiple in flight.
162
+
163
+ ## [1.0.0] - 2026-03-29
164
+
165
+ ### Changed
166
+
167
+ - Minimal surface refactor. The public API is now the `Offramp` class plus `offramp()` function (core) and `useOfframp` (React). This is the first stable release.
168
+
169
+ ### Removed
170
+
171
+ - Pre-1.0 surface area not carried forward. Integrators on 0.2.x should migrate to the new API.
172
+
173
+ ## [0.2.1] - 2026-03-29
174
+
175
+ ### Fixed
176
+
177
+ - Use `defaultIndexerEndpoint` for read-only indexer queries so SDK reads work without additional configuration.
178
+
179
+ ## [0.2.0] - 2026-03-29
180
+
181
+ ### Added
182
+
183
+ - Structured errors (`OfframpError` with `code`, `step`, `txHash`, `depositId`).
184
+ - Deposit recovery: the SDK resumes the most recent undelegated deposit for a wallet instead of creating a new one.
185
+
186
+ ### Fixed
187
+
188
+ - Indexer endpoint resolution.
189
+
190
+ ## [0.1.5] - 2026-03-29
191
+
192
+ ### Added
193
+
194
+ - `delegateDeposit()` for retrying delegation or delegating an existing deposit.
195
+
196
+ ## [0.1.4] - 2026-03-29
197
+
198
+ ### Added
199
+
200
+ - Typed constant maps for platforms and currencies.
201
+ - Currency metadata (symbol, decimals, display name).
202
+
203
+ ## [0.1.3] - 2026-03-29
204
+
205
+ ### Added
206
+
207
+ - Pre-flight USDC balance check before submitting a deposit.
208
+ - Amount truncation to USDC decimals.
209
+ - Wallet validation on deposit inputs.
210
+
211
+ ## [0.1.2] - 2026-03-29
212
+
213
+ ### Changed
214
+
215
+ - Reduced minimum deposit and minimum order to 1 USDC.
216
+
217
+ ## [0.1.1] - 2026-03-29
218
+
219
+ ### Fixed
220
+
221
+ - Resolve currency hashes to ISO codes in error messages and responses.
222
+ - Improved error messages for invalid currency and platform inputs.
223
+
224
+ ## [0.1.0] - 2026-03-29
225
+
226
+ ### Added
227
+
228
+ - Initial release of `@usdctofiat/offramp`.
229
+ - `Offramp` class and `offramp()` function for creating delegated USDC-to-fiat deposits on Base.
230
+ - `useOfframp` React hook (`@usdctofiat/offramp/react`).
231
+ - `getDeposits`, `withdrawDeposit`, `getPlatforms`, `validateIdentifier` helpers.
232
+ - All deposits automatically delegate to the Delegate vault, use `track_market` pricing, and carry Galleon Labs attribution.
233
+ - Dual CJS/ESM build via tsup with type definitions for both entry points.
234
+
235
+ [Unreleased]: https://github.com/ADWilkinson/galleonlabs-zkp2p/compare/main...HEAD
236
+ [1.3.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.3.0
237
+ [1.2.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.2.0
238
+ [1.1.4]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.1.4
239
+ [1.1.3]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.1.3
240
+ [1.1.2]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.1.2
241
+ [1.1.1]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.1.1
242
+ [1.1.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.1.0
243
+ [1.0.1]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.0.1
244
+ [1.0.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v1.0.0
245
+ [0.2.1]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.2.1
246
+ [0.2.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.2.0
247
+ [0.1.5]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.5
248
+ [0.1.4]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.4
249
+ [0.1.3]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.3
250
+ [0.1.2]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.2
251
+ [0.1.1]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.1
252
+ [0.1.0]: https://github.com/ADWilkinson/galleonlabs-zkp2p/releases/tag/offramp-sdk-v0.1.0
package/README.md CHANGED
@@ -111,22 +111,102 @@ getOtcLink("362"); // just the URL, no tx
111
111
  ## Error Handling
112
112
 
113
113
  ```typescript
114
- import { OfframpError } from "@usdctofiat/offramp";
114
+ import { OfframpError, OFFRAMP_ERROR_CODES } from "@usdctofiat/offramp";
115
115
 
116
116
  try {
117
117
  await offramp(walletClient, params);
118
118
  } catch (err) {
119
119
  if (err instanceof OfframpError) {
120
120
  if (err.code === "USER_CANCELLED") return;
121
- // For any failure: call offramp() again to resume
121
+ if (err.code === OFFRAMP_ERROR_CODES.EXTENSION_REGISTRATION_REQUIRED) {
122
+ // User needs to register in the Peer extension first — see below.
123
+ return;
124
+ }
125
+ // For any other failure: call offramp() again to resume
122
126
  }
123
127
  }
124
128
  ```
125
129
 
130
+ ## Peer Extension Registration (PayPal, Wise)
131
+
132
+ PayPal and Wise makers must register their handle inside the Peer (PeerAuth)
133
+ browser extension before the first deposit. The SDK throws `OfframpError`
134
+ with code `EXTENSION_REGISTRATION_REQUIRED` when curator rejects a maker for
135
+ this reason. Drive the three-step handshake via the React hook:
136
+
137
+ ```tsx
138
+ import { PLATFORMS, CURRENCIES, OFFRAMP_ERROR_CODES } from "@usdctofiat/offramp";
139
+ import { useOfframp, usePeerExtensionRegistration } from "@usdctofiat/offramp/react";
140
+
141
+ function PayPalSellButton({ walletClient }) {
142
+ const { offramp, lastError } = useOfframp();
143
+ const peer = usePeerExtensionRegistration(PLATFORMS.PAYPAL);
144
+
145
+ const needsExtension = lastError?.code === OFFRAMP_ERROR_CODES.EXTENSION_REGISTRATION_REQUIRED;
146
+
147
+ return (
148
+ <>
149
+ <button
150
+ onClick={() =>
151
+ offramp(walletClient, {
152
+ amount: "100",
153
+ platform: PLATFORMS.PAYPAL,
154
+ currency: CURRENCIES.USD,
155
+ identifier: "alicepay", // PayPal.me username, NOT email
156
+ })
157
+ }
158
+ >
159
+ Sell USDC
160
+ </button>
161
+
162
+ {needsExtension && (
163
+ <div>
164
+ <p>{peer.info?.requiredPrompt}</p>
165
+ {peer.phase === "needs_install" && (
166
+ <button onClick={peer.installExtension}>Install Peer Extension</button>
167
+ )}
168
+ {peer.phase === "needs_connection" && (
169
+ <button onClick={peer.connectExtension} disabled={peer.busy}>
170
+ Connect Peer Extension
171
+ </button>
172
+ )}
173
+ {peer.phase === "ready" && (
174
+ <button onClick={peer.openVerifySidebar}>Verify in Peer</button>
175
+ )}
176
+ {peer.info?.ctaSubtext && <small>{peer.info.ctaSubtext}</small>}
177
+ </div>
178
+ )}
179
+ </>
180
+ );
181
+ }
182
+ ```
183
+
184
+ Or drive the handshake manually via `peerExtensionSdk`:
185
+
186
+ ```typescript
187
+ import { peerExtensionSdk } from "@usdctofiat/offramp";
188
+
189
+ const state = await peerExtensionSdk.getState();
190
+ if (state === "needs_install") {
191
+ peerExtensionSdk.openInstallPage();
192
+ } else if (state === "needs_connection") {
193
+ const approved = await peerExtensionSdk.requestConnection();
194
+ if (approved) peerExtensionSdk.openSidebar("/verify/paypal");
195
+ } else {
196
+ peerExtensionSdk.openSidebar("/verify/paypal");
197
+ }
198
+ ```
199
+
200
+ After the user completes the flow in the extension, call `offramp()` again.
201
+
126
202
  ## How It Works
127
203
 
128
204
  Every deposit is automatically delegated to the Delegate vault for oracle-based rate management, auto-closes when filled, and is attributed to Galleon Labs via ERC-8021.
129
205
 
206
+ ## Webhooks
207
+
208
+ Subscribe to `deposit.created`, `deposit.filled`, `deposit.partially_filled`, `deposit.closed`, `otc.enabled`, `otc.disabled`, and `otc.taken` events for your attributed deposits. Register endpoints at [usdctofiat.xyz/developers](https://usdctofiat.xyz/developers) with your Peerlytics API key. HMAC-SHA256 signed deliveries use the `X-Usdctofiat-Signature: t=<unix>,v1=<hex>` header. Reference HMAC receiver in the [starters repo](https://github.com/ADWilkinson/usdctofiat-peerlytics-starters).
209
+
130
210
  ## Links
131
211
 
132
212
  [usdctofiat.xyz](https://usdctofiat.xyz) · [delegate.usdctofiat.xyz](https://delegate.usdctofiat.xyz) · [peerlytics.xyz](https://peerlytics.xyz) · [orderbook.peerlytics.xyz](https://orderbook.peerlytics.xyz)