@usdctofiat/offramp 3.0.3 → 3.1.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.
@@ -1,4 +1,121 @@
1
- import { currencyInfo } from '@zkp2p/sdk';
1
+ import { PeerOnrampPreparedTransactionCallback, PeerOnrampPreparedTransactionResult, PeerExtensionOnrampParams, CuratorSellerCredentialUploadResponse, currencyInfo } from '@zkp2p/sdk';
2
+
3
+ /**
4
+ * Peer browser-extension surface for PayPal + Wise makers. Drive the
5
+ * headless metadata bridge via `usePeerExtensionRegistration` in
6
+ * `@usdctofiat/offramp/react`, or manually:
7
+ *
8
+ * ```ts
9
+ * import {
10
+ * completePeerExtensionRegistration,
11
+ * isPeerExtensionMetadataBridgeAvailable,
12
+ * peerExtensionSdk,
13
+ * } from "@usdctofiat/offramp";
14
+ *
15
+ * const state = await peerExtensionSdk.getState();
16
+ * if (state === "needs_install" || !isPeerExtensionMetadataBridgeAvailable()) {
17
+ * peerExtensionSdk.openInstallPage();
18
+ * } else if (state === "needs_connection") {
19
+ * await peerExtensionSdk.requestConnection();
20
+ * } else {
21
+ * peerExtensionSdk.authenticate({
22
+ * actionType: "transfer_paypal",
23
+ * captureMode: "sellerCredential",
24
+ * platform: "paypal",
25
+ * });
26
+ * // Pass the captured metadata to completePeerExtensionRegistration(...), then retry.
27
+ * }
28
+ * ```
29
+ */
30
+
31
+ type PeerConnectionStatus = "connected" | "disconnected" | "pending";
32
+ type PeerMetadataCaptureMode = "buyerTee" | "sellerCredential";
33
+ type PeerMetadataProviderConfig = Record<string, unknown>;
34
+ type PeerAuthenticateParams = {
35
+ actionType: string;
36
+ attestationActionType?: string | null;
37
+ attestationServiceUrl?: string | null;
38
+ captureMode?: PeerMetadataCaptureMode;
39
+ platform: string;
40
+ providerConfig?: PeerMetadataProviderConfig;
41
+ };
42
+ type PeerBuyerTeePaymentParams = Record<string, string | number | boolean>;
43
+ type PeerBuyerTeePaymentCapture = {
44
+ encryptedSessionMaterial: string;
45
+ params?: PeerBuyerTeePaymentParams[];
46
+ };
47
+ type PeerSarCredentialBundle = {
48
+ bundleSignature: string;
49
+ credentialExpiresAt: string | null;
50
+ credentialType: string;
51
+ credentialValidatedAt: string;
52
+ encryptedBlob: string;
53
+ encryptedDataKey: string;
54
+ nonce: string;
55
+ payeeIdHash: `0x${string}`;
56
+ platform: string;
57
+ };
58
+ type PeerSarCredentialCapture = {
59
+ credentialBundle: PeerSarCredentialBundle;
60
+ offchainId: string;
61
+ };
62
+ type PeerMetadataRow = {
63
+ amount?: string;
64
+ currency?: string;
65
+ date?: string;
66
+ hidden: boolean;
67
+ originalIndex: number;
68
+ params?: PeerBuyerTeePaymentParams;
69
+ paymentId?: string;
70
+ recipient?: string;
71
+ [key: string]: unknown;
72
+ };
73
+ type PeerMetadataMessage = {
74
+ buyerTeeCapture?: PeerBuyerTeePaymentCapture | null;
75
+ errorMessage?: string;
76
+ expiresAt: number;
77
+ metadata: PeerMetadataRow[];
78
+ platform: string;
79
+ requestId: string;
80
+ sarCredentialCapture?: PeerSarCredentialCapture | null;
81
+ };
82
+ type PeerMetadataMessageCallback = (message: PeerMetadataMessage) => void;
83
+ type PeerExtensionApi = {
84
+ requestConnection(): Promise<boolean>;
85
+ checkConnectionStatus(): Promise<PeerConnectionStatus>;
86
+ getVersion(): Promise<string>;
87
+ authenticate?: (params: PeerAuthenticateParams) => void;
88
+ onMetadataMessage?: (callback: PeerMetadataMessageCallback) => () => void;
89
+ openSidebar?: (route: string) => void;
90
+ onramp?: (queryString: string, callback: PeerOnrampPreparedTransactionCallback) => void;
91
+ getOnrampTransaction?: (intentHash: string) => Promise<PeerOnrampPreparedTransactionResult | null>;
92
+ };
93
+ type PeerExtensionWindow = Window & {
94
+ peer?: PeerExtensionApi;
95
+ };
96
+ type PeerExtensionSdkOptions = {
97
+ window?: PeerExtensionWindow;
98
+ };
99
+ type PeerExtensionSdk = {
100
+ requestConnection(): Promise<boolean>;
101
+ checkConnectionStatus(): Promise<PeerConnectionStatus>;
102
+ getVersion(): Promise<string>;
103
+ authenticate(params: PeerAuthenticateParams): void;
104
+ onMetadataMessage(callback: PeerMetadataMessageCallback): () => void;
105
+ openSidebar(route: string): void;
106
+ onramp(params: PeerExtensionOnrampParams, callback: PeerOnrampPreparedTransactionCallback): void;
107
+ getOnrampTransaction(intentHash: string): Promise<PeerOnrampPreparedTransactionResult | null>;
108
+ isAvailable(): boolean;
109
+ openInstallPage(): void;
110
+ getState(): Promise<PeerExtensionState>;
111
+ };
112
+ type PeerExtensionState = "needs_install" | "needs_connection" | "ready";
113
+ declare const isPeerExtensionAvailable: (options?: PeerExtensionSdkOptions) => boolean;
114
+ declare const isPeerExtensionMetadataBridgeAvailable: (options?: PeerExtensionSdkOptions) => boolean;
115
+ declare const openPeerExtensionInstallPage: (options?: PeerExtensionSdkOptions) => void;
116
+ declare const getPeerExtensionState: (options?: PeerExtensionSdkOptions) => Promise<PeerExtensionState>;
117
+ declare const createPeerExtensionSdk: (options?: PeerExtensionSdkOptions) => PeerExtensionSdk;
118
+ declare const peerExtensionSdk: PeerExtensionSdk;
2
119
 
3
120
  type PlatformId = "venmo" | "cashapp" | "chime" | "revolut" | "wise" | "mercadopago" | "zelle" | "paypal" | "monzo" | "n26" | "luxon";
4
121
  /**
@@ -97,7 +214,19 @@ declare function getPlatformLimits(platform: string): PlatformLimits | null;
97
214
  interface PayeeDepositData {
98
215
  offchainId: string;
99
216
  telegramUsername?: string;
100
- metadata?: Record<string, string>;
217
+ metadata?: Record<string, unknown>;
218
+ }
219
+ interface CompletePeerExtensionRegistrationInput {
220
+ readonly platform: PlatformEntry;
221
+ readonly identifier: string;
222
+ readonly capturedMetadata: PeerMetadataMessage;
223
+ }
224
+ interface CompletePeerExtensionRegistrationResult {
225
+ readonly processorName: "paypal" | "wise";
226
+ readonly offchainId: string;
227
+ readonly hashedOnchainId: string;
228
+ readonly sellerCredentialResponse: CuratorSellerCredentialUploadResponse;
229
+ readonly sellerCredentialStatus: CuratorSellerCredentialUploadResponse["responseObject"];
101
230
  }
102
231
  /**
103
232
  * Returns the extension-registration metadata for a platform, or `null` if
@@ -106,6 +235,10 @@ interface PayeeDepositData {
106
235
  * your UI before calling `offramp()` for PayPal or Wise.
107
236
  */
108
237
  declare function getPeerExtensionRegistrationInfo(platform: string): PeerExtensionRegistrationInfo | null;
238
+ declare function getPeerExtensionRegistrationAuthParams(platform: string, options?: {
239
+ attestationServiceUrl?: string | null;
240
+ }): PeerAuthenticateParams | null;
241
+ declare function completePeerExtensionRegistration(input: CompletePeerExtensionRegistrationInput): Promise<CompletePeerExtensionRegistrationResult>;
109
242
  /**
110
243
  * True when a failed `/v2/makers/create` response should be treated as
111
244
  * "maker needs to register in the Peer extension first". Platforms without
@@ -136,8 +269,8 @@ declare const OFFRAMP_ERROR_CODES: {
136
269
  * handle in the Peer extension yet. Thrown from `offramp()` for PayPal
137
270
  * and Wise when `/v2/makers/create` returns 400 or a "creating the maker"
138
271
  * message. Recover by prompting the user through the Peer extension via
139
- * `usePeerExtensionRegistration(platform)` (React) or `peerExtensionSdk`
140
- * directly, then call `offramp()` again.
272
+ * `usePeerExtensionRegistration(platform)` (React) or
273
+ * `completePeerExtensionRegistration(...)`, then retrying `offramp()`.
141
274
  */
142
275
  readonly EXTENSION_REGISTRATION_REQUIRED: "EXTENSION_REGISTRATION_REQUIRED";
143
276
  readonly DEPOSIT_FAILED: "DEPOSIT_FAILED";
@@ -162,7 +295,16 @@ interface OfframpParams {
162
295
  referralId?: string;
163
296
  /** Optional SDK-only integrator metadata for telemetry attribution. */
164
297
  integratorId?: string;
165
- /** Optional per-wallet key to replay the first successful result for 10 minutes. */
298
+ /**
299
+ * Optional per-wallet key to replay the first successful result for 10 minutes.
300
+ *
301
+ * Browser-only: the replay cache is backed by `sessionStorage` and is a no-op
302
+ * in Node/worker runtimes (no duplicate protection there). It is honored only
303
+ * by the `Offramp` class (`createDeposit`) / the `useOfframp` hook — the
304
+ * standalone `offramp()` function ignores it. For server-side dedup, call
305
+ * `deposits(walletAddress)` and reuse an existing open deposit before creating
306
+ * a new one (the SDK's own resume behavior does this for the delegation step).
307
+ */
166
308
  idempotencyKey?: string;
167
309
  }
168
310
  interface OfframpResult {
@@ -196,6 +338,11 @@ interface OfframpQuote {
196
338
  interface OfframpVaultStatus {
197
339
  rateManagerId: string;
198
340
  rateManagerAddress: string;
341
+ /**
342
+ * Delegate vault manager fee in basis points (currently 10 = 0.10%). Charged
343
+ * by the vault's rate manager on each fill and deducted from the USDC released
344
+ * to the buyer; not added to the maker's deposit cost. See the README "Fees".
345
+ */
199
346
  feeRateBps: number;
200
347
  escrow: string;
201
348
  isActive: boolean;
@@ -204,6 +351,14 @@ interface OfframpCreateOptions {
204
351
  integratorId?: string;
205
352
  referralId?: string;
206
353
  telemetry?: boolean;
354
+ /**
355
+ * Override the curator REST base URL (default `https://api.zkp2p.xyz`) used
356
+ * for maker registration/validation and the SDK's REST calls. For
357
+ * testing/proxying/mocking only — the indexer and Base RPC always target
358
+ * mainnet. Honored by the `Offramp` class (`createDeposit`); absent ⇒ default
359
+ * behavior is unchanged.
360
+ */
361
+ apiBaseUrl?: string;
207
362
  }
208
363
  interface DepositInfo {
209
364
  /** Numeric deposit ID. Pass this to `close()`. */
@@ -251,4 +406,4 @@ declare class OfframpError extends Error {
251
406
  });
252
407
  }
253
408
 
254
- export { CURRENCIES as C, type DepositInfo as D, MakersCreateError as M, OFFRAMP_ERROR_CODES as O, PLATFORMS as P, type CurrencyEntry as a, type DepositStatus as b, type OfframpCreateOptions as c, OfframpError as d, type OfframpErrorCode as e, type OfframpParams as f, type OfframpProgress as g, type OfframpQuote as h, type OfframpQuoteInput as i, type OfframpResult as j, type OfframpState as k, type OfframpStep as l, type OfframpVaultStatus as m, type OnProgress as n, PLATFORM_LIMITS as o, type PayeeDepositData as p, type PeerExtensionRegistrationInfo as q, type PlatformEntry as r, type PlatformKey as s, type PlatformLimits as t, type PlatformTier as u, getPeerExtensionRegistrationInfo as v, getPlatformLimits as w, isPeerExtensionRegistrationError as x, isValidIBAN as y, normalizePaypalMeUsername as z };
409
+ export { isValidIBAN as $, type PeerExtensionState as A, type PeerExtensionWindow as B, CURRENCIES as C, type DepositInfo as D, type PeerMetadataCaptureMode as E, type PeerMetadataMessage as F, type PeerMetadataMessageCallback as G, type PeerMetadataProviderConfig as H, type PeerMetadataRow as I, type PeerSarCredentialBundle as J, type PeerSarCredentialCapture as K, type PlatformEntry as L, MakersCreateError as M, type PlatformKey as N, OFFRAMP_ERROR_CODES as O, PLATFORMS as P, type PlatformLimits as Q, type PlatformTier as R, completePeerExtensionRegistration as S, createPeerExtensionSdk as T, getPeerExtensionRegistrationAuthParams as U, getPeerExtensionRegistrationInfo as V, getPeerExtensionState as W, getPlatformLimits as X, isPeerExtensionAvailable as Y, isPeerExtensionMetadataBridgeAvailable as Z, isPeerExtensionRegistrationError as _, type CompletePeerExtensionRegistrationInput as a, normalizePaypalMeUsername as a0, openPeerExtensionInstallPage as a1, peerExtensionSdk as a2, type CompletePeerExtensionRegistrationResult as b, type CurrencyEntry as c, type DepositStatus as d, type OfframpCreateOptions as e, OfframpError as f, type OfframpErrorCode as g, type OfframpParams as h, type OfframpProgress as i, type OfframpQuote as j, type OfframpQuoteInput as k, type OfframpResult as l, type OfframpState as m, type OfframpStep as n, type OfframpVaultStatus as o, type OnProgress as p, PLATFORM_LIMITS as q, type PayeeDepositData as r, type PeerAuthenticateParams as s, type PeerBuyerTeePaymentCapture as t, type PeerBuyerTeePaymentParams as u, type PeerConnectionStatus as v, type PeerExtensionApi as w, type PeerExtensionRegistrationInfo as x, type PeerExtensionSdk as y, type PeerExtensionSdkOptions as z };