facinet 2.0.3 → 2.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.
package/dist/browser.js CHANGED
@@ -22657,26 +22657,27 @@ var Facinet = class _Facinet {
22657
22657
  if (this.wallet) {
22658
22658
  signature = await this.wallet.signTypedData(domain, types, value);
22659
22659
  } else if (typeof window !== "undefined" && window.ethereum) {
22660
- const messageForBrowser = {
22661
- from: payerAddress,
22662
- to: params.recipient,
22663
- value: amount.toString(),
22664
- // Convert BigInt to string for JSON
22665
- validAfter: validAfter.toString(),
22666
- validBefore: validBefore.toString(),
22667
- nonce
22660
+ const typedData = {
22661
+ domain,
22662
+ types,
22663
+ primaryType: "TransferWithAuthorization",
22664
+ message: {
22665
+ from: payerAddress,
22666
+ to: params.recipient,
22667
+ value: amount.toString(),
22668
+ // BigInt to decimal string
22669
+ validAfter: validAfter.toString(),
22670
+ validBefore: validBefore.toString(),
22671
+ nonce
22672
+ }
22668
22673
  };
22674
+ const jsonMessage = JSON.stringify(
22675
+ typedData,
22676
+ (_key, value2) => typeof value2 === "bigint" ? value2.toString() : value2
22677
+ );
22669
22678
  signature = await window.ethereum.request({
22670
22679
  method: "eth_signTypedData_v4",
22671
- params: [
22672
- payerAddress,
22673
- JSON.stringify({
22674
- domain,
22675
- types,
22676
- primaryType: "TransferWithAuthorization",
22677
- message: messageForBrowser
22678
- })
22679
- ]
22680
+ params: [payerAddress, jsonMessage]
22680
22681
  });
22681
22682
  } else {
22682
22683
  throw new Error("No signing method available");
@@ -22692,31 +22693,39 @@ var Facinet = class _Facinet {
22692
22693
  nonce
22693
22694
  }
22694
22695
  };
22695
- const response = await axios_default.post(
22696
- `${this.config.apiUrl}/api/x402/settle-custom`,
22697
- {
22698
- facilitatorId: facilitator.id,
22699
- paymentPayload
22696
+ try {
22697
+ const response = await axios_default.post(
22698
+ `${this.config.apiUrl}/api/x402/settle-custom`,
22699
+ {
22700
+ facilitatorId: facilitator.id,
22701
+ paymentPayload
22702
+ }
22703
+ );
22704
+ if (!response.data.success) {
22705
+ throw new Error(response.data.error || response.data.message || "Payment failed");
22700
22706
  }
22701
- );
22702
- if (!response.data.success) {
22703
- throw new Error("Payment failed: " + (response.data.error || "Unknown error"));
22704
- }
22705
- return {
22706
- success: true,
22707
- txHash: response.data.txHash,
22708
- facilitator: {
22709
- id: facilitator.id,
22710
- name: facilitator.name,
22711
- wallet: facilitator.facilitatorWallet
22712
- },
22713
- payment: {
22714
- from: payerAddress,
22715
- to: params.recipient,
22716
- amount: params.amount,
22717
- network: this.config.network
22707
+ return {
22708
+ success: true,
22709
+ txHash: response.data.txHash,
22710
+ facilitator: {
22711
+ id: facilitator.id,
22712
+ name: facilitator.name,
22713
+ wallet: facilitator.facilitatorWallet
22714
+ },
22715
+ payment: {
22716
+ from: payerAddress,
22717
+ to: params.recipient,
22718
+ amount: params.amount,
22719
+ network: this.config.network
22720
+ }
22721
+ };
22722
+ } catch (error) {
22723
+ if (error.response?.data) {
22724
+ const backendError = error.response.data.message || error.response.data.error;
22725
+ throw new Error(`Payment failed: ${backendError}`);
22718
22726
  }
22719
- };
22727
+ throw error;
22728
+ }
22720
22729
  }
22721
22730
  /**
22722
22731
  * Get all active facilitators