@usdctofiat/offramp 3.1.0 → 4.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,121 +1,4 @@
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;
1
+ import { PeerMetadataMessage, CuratorSellerCredentialUploadResponse, PeerAuthenticateParams, currencyInfo } from '@zkp2p/sdk';
119
2
 
120
3
  type PlatformId = "venmo" | "cashapp" | "chime" | "revolut" | "wise" | "mercadopago" | "zelle" | "paypal" | "monzo" | "n26" | "luxon";
121
4
  /**
@@ -406,4 +289,4 @@ declare class OfframpError extends Error {
406
289
  });
407
290
  }
408
291
 
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 };
292
+ export { getPlatformLimits as A, isPeerExtensionRegistrationError as B, CURRENCIES as C, type DepositInfo as D, isValidIBAN as E, normalizePaypalMeUsername as F, MakersCreateError as M, OFFRAMP_ERROR_CODES as O, PLATFORMS as P, type CompletePeerExtensionRegistrationInput as a, 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 PeerExtensionRegistrationInfo as s, type PlatformEntry as t, type PlatformKey as u, type PlatformLimits as v, type PlatformTier as w, completePeerExtensionRegistration as x, getPeerExtensionRegistrationAuthParams as y, getPeerExtensionRegistrationInfo as z };
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CURRENCIES: () => CURRENCIES,
34
+ DEFAULT_EXTENSION_INSTALL_URL: () => DEFAULT_EXTENSION_INSTALL_URL,
34
35
  ESCROW_ADDRESS: () => ESCROW_ADDRESS,
35
36
  MakersCreateError: () => MakersCreateError,
36
37
  OFFRAMP_ERROR_CODES: () => OFFRAMP_ERROR_CODES,
@@ -75,7 +76,7 @@ var import_sdk5 = require("@zkp2p/sdk");
75
76
 
76
77
  // src/config.ts
77
78
  var import_sdk = require("@zkp2p/sdk");
78
- var SDK_VERSION = "3.1.0";
79
+ var SDK_VERSION = "4.1.0";
79
80
  var BASE_CHAIN_ID = 8453;
80
81
  var RUNTIME_ENV = "production";
81
82
  var API_BASE_URL = "https://api.zkp2p.xyz";
@@ -573,39 +574,9 @@ function requireSarCredentialCapture(capturedMetadata) {
573
574
  }
574
575
  return capture;
575
576
  }
576
- async function uploadSellerCredentialBundle(processorName, payeeHash, bundle) {
577
- const controller = new AbortController();
578
- const timeout = setTimeout(() => controller.abort(), PAYEE_REGISTRATION_TIMEOUT_MS);
579
- try {
580
- const res = await fetch(
581
- `${API_BASE_URL}/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(payeeHash)}/seller-credential`,
582
- {
583
- method: "POST",
584
- headers: { "Content-Type": "application/json" },
585
- body: JSON.stringify(bundle),
586
- signal: controller.signal
587
- }
588
- );
589
- if (!res.ok) {
590
- const txt = await res.text().catch(() => "");
591
- let detail = txt || res.statusText;
592
- try {
593
- const parsed = JSON.parse(txt);
594
- if (typeof parsed.message === "string" && parsed.message.trim()) {
595
- detail = parsed.message;
596
- }
597
- } catch {
598
- }
599
- throw new Error(`seller-credential upload failed (${res.status}): ${detail}`);
600
- }
601
- const json = await res.json();
602
- if (!json.success || !json.responseObject) {
603
- throw new Error(json.message || "seller-credential upload returned no status.");
604
- }
605
- return json;
606
- } finally {
607
- clearTimeout(timeout);
608
- }
577
+ async function uploadSellerCredentialBundle(processorName, offchainId, bundle) {
578
+ const params = processorName === "wise" ? { platform: "wise", bundle } : { platform: processorName, offchainId, bundle };
579
+ return (0, import_sdk2.apiUploadSellerCredentialBundle)(params, API_BASE_URL, PAYEE_REGISTRATION_TIMEOUT_MS);
609
580
  }
610
581
  async function completePeerExtensionRegistration(input) {
611
582
  const processorName = resolveRegistrationProcessor(input.platform);
@@ -627,13 +598,10 @@ async function completePeerExtensionRegistration(input) {
627
598
  if (payload.offchainId !== validation.normalized) {
628
599
  throw new Error("Seller credential offchainId does not match registration identifier.");
629
600
  }
630
- const hashedOnchainId = processorName === "wise" ? bundle.payeeIdHash : await postMakerCreate(processorName, payload);
631
- if (hashedOnchainId.toLowerCase() !== bundle.payeeIdHash.toLowerCase()) {
632
- throw new Error("Seller credential payee hash does not match registered payee details.");
633
- }
601
+ const hashedOnchainId = bundle.payeeIdHash;
634
602
  const sellerCredentialResponse = await uploadSellerCredentialBundle(
635
603
  processorName,
636
- hashedOnchainId,
604
+ payload.offchainId,
637
605
  bundle
638
606
  );
639
607
  return {
@@ -1699,6 +1667,7 @@ var OFFRAMP_ERROR_CODES = {
1699
1667
 
1700
1668
  // src/extension.ts
1701
1669
  var import_sdk7 = require("@zkp2p/sdk");
1670
+ var DEFAULT_EXTENSION_INSTALL_URL = "https://chromewebstore.google.com/detail/usdctofiat-verify/lfkmdfifolhcfjmhklmckigfngghmpdf";
1702
1671
  var resolveWindow = (options) => {
1703
1672
  if (options?.window) {
1704
1673
  return options.window;
@@ -1739,7 +1708,8 @@ var openPeerExtensionInstallPage = (options) => {
1739
1708
  if (!resolvedWindow) {
1740
1709
  throw new Error("Peer extension SDK requires a browser window.");
1741
1710
  }
1742
- resolvedWindow.open(import_sdk7.PEER_EXTENSION_CHROME_URL, "_blank", "noopener,noreferrer");
1711
+ const installUrl = options?.installUrl ?? DEFAULT_EXTENSION_INSTALL_URL;
1712
+ resolvedWindow.open(installUrl, "_blank", "noopener,noreferrer");
1743
1713
  };
1744
1714
  var getPeerExtensionState = async (options) => {
1745
1715
  if (!isPeerExtensionAvailable(options)) {
@@ -1753,9 +1723,7 @@ var getPeerExtensionState = async (options) => {
1753
1723
  }
1754
1724
  };
1755
1725
  var createPeerExtensionSdk = (options = {}) => {
1756
- const legacySdk = (0, import_sdk7.createPeerExtensionSdk)(
1757
- options
1758
- );
1726
+ const sdk = (0, import_sdk7.createPeerExtensionSdk)(options);
1759
1727
  return {
1760
1728
  isAvailable: () => isPeerExtensionAvailable(options),
1761
1729
  requestConnection: () => requirePeer(options).requestConnection(),
@@ -1763,17 +1731,15 @@ var createPeerExtensionSdk = (options = {}) => {
1763
1731
  getVersion: () => requirePeer(options).getVersion(),
1764
1732
  authenticate: (params) => requirePeerMetadataBridge(options).authenticate(params),
1765
1733
  onMetadataMessage: (callback) => requirePeerMetadataBridge(options).onMetadataMessage(callback),
1766
- openSidebar: (route) => legacySdk.openSidebar(route),
1767
- onramp: (params, callback) => legacySdk.onramp(params, callback),
1768
- getOnrampTransaction: (intentHash) => legacySdk.getOnrampTransaction(intentHash),
1769
1734
  openInstallPage: () => openPeerExtensionInstallPage(options),
1770
- getState: () => getPeerExtensionState(options)
1735
+ getState: () => sdk.getState()
1771
1736
  };
1772
1737
  };
1773
1738
  var peerExtensionSdk = createPeerExtensionSdk();
1774
1739
  // Annotate the CommonJS export names for ESM import in node:
1775
1740
  0 && (module.exports = {
1776
1741
  CURRENCIES,
1742
+ DEFAULT_EXTENSION_INSTALL_URL,
1777
1743
  ESCROW_ADDRESS,
1778
1744
  MakersCreateError,
1779
1745
  OFFRAMP_ERROR_CODES,