moltspay 0.8.1 → 0.8.2

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/index.js CHANGED
@@ -2905,7 +2905,7 @@ function alphabet(letters) {
2905
2905
  };
2906
2906
  }
2907
2907
  // @__NO_SIDE_EFFECTS__
2908
- function join3(separator = "") {
2908
+ function join4(separator = "") {
2909
2909
  astr("join", separator);
2910
2910
  return {
2911
2911
  encode: (from) => {
@@ -3112,10 +3112,10 @@ var init_esm = __esm({
3112
3112
  convertRadix2,
3113
3113
  radix,
3114
3114
  radix2,
3115
- join: join3,
3115
+ join: join4,
3116
3116
  padding
3117
3117
  };
3118
- genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join3(""));
3118
+ genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join4(""));
3119
3119
  base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
3120
3120
  createBase58check = (sha2566) => /* @__PURE__ */ chain(checksum(4, (data) => sha2566(sha2566(data))), base58);
3121
3121
  }
@@ -3263,14 +3263,14 @@ var init_esm2 = __esm({
3263
3263
  }
3264
3264
  this.pubHash = hash160(this.pubKey);
3265
3265
  }
3266
- derive(path2) {
3267
- if (!/^[mM]'?/.test(path2)) {
3266
+ derive(path3) {
3267
+ if (!/^[mM]'?/.test(path3)) {
3268
3268
  throw new Error('Path must start with "m" or "M"');
3269
3269
  }
3270
- if (/^[mM]'?$/.test(path2)) {
3270
+ if (/^[mM]'?$/.test(path3)) {
3271
3271
  return this;
3272
3272
  }
3273
- const parts = path2.replace(/^[mM]'?\//, "").split("/");
3273
+ const parts = path3.replace(/^[mM]'?\//, "").split("/");
3274
3274
  let child = this;
3275
3275
  for (const c of parts) {
3276
3276
  const m = /^(\d+)('?)$/.exec(c);
@@ -9631,8 +9631,8 @@ var init_privateKeyToAccount = __esm({
9631
9631
  });
9632
9632
 
9633
9633
  // node_modules/viem/_esm/accounts/hdKeyToAccount.js
9634
- function hdKeyToAccount(hdKey_, { accountIndex = 0, addressIndex = 0, changeIndex = 0, path: path2, ...options } = {}) {
9635
- const hdKey = hdKey_.derive(path2 || `m/44'/60'/${accountIndex}'/${changeIndex}/${addressIndex}`);
9634
+ function hdKeyToAccount(hdKey_, { accountIndex = 0, addressIndex = 0, changeIndex = 0, path: path3, ...options } = {}) {
9635
+ const hdKey = hdKey_.derive(path3 || `m/44'/60'/${accountIndex}'/${changeIndex}/${addressIndex}`);
9636
9636
  const account = privateKeyToAccount(toHex(hdKey.privateKey), options);
9637
9637
  return {
9638
9638
  ...account,
@@ -30369,84 +30369,7 @@ init_cjs_shims();
30369
30369
  init_cjs_shims();
30370
30370
  var import_fs = require("fs");
30371
30371
  var import_http = require("http");
30372
-
30373
- // src/chains/index.ts
30374
- init_cjs_shims();
30375
- var CHAINS = {
30376
- // ============ Mainnet ============
30377
- base: {
30378
- name: "Base",
30379
- chainId: 8453,
30380
- rpc: "https://mainnet.base.org",
30381
- usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
30382
- explorer: "https://basescan.org/address/",
30383
- explorerTx: "https://basescan.org/tx/",
30384
- avgBlockTime: 2
30385
- },
30386
- polygon: {
30387
- name: "Polygon",
30388
- chainId: 137,
30389
- rpc: "https://polygon-rpc.com",
30390
- usdc: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
30391
- explorer: "https://polygonscan.com/address/",
30392
- explorerTx: "https://polygonscan.com/tx/",
30393
- avgBlockTime: 2
30394
- },
30395
- ethereum: {
30396
- name: "Ethereum",
30397
- chainId: 1,
30398
- rpc: "https://eth.llamarpc.com",
30399
- usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
30400
- explorer: "https://etherscan.io/address/",
30401
- explorerTx: "https://etherscan.io/tx/",
30402
- avgBlockTime: 12
30403
- },
30404
- // ============ Testnet ============
30405
- base_sepolia: {
30406
- name: "Base Sepolia",
30407
- chainId: 84532,
30408
- rpc: "https://sepolia.base.org",
30409
- usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
30410
- explorer: "https://sepolia.basescan.org/address/",
30411
- explorerTx: "https://sepolia.basescan.org/tx/",
30412
- avgBlockTime: 2
30413
- },
30414
- sepolia: {
30415
- name: "Sepolia",
30416
- chainId: 11155111,
30417
- rpc: "https://rpc.sepolia.org",
30418
- usdc: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
30419
- explorer: "https://sepolia.etherscan.io/address/",
30420
- explorerTx: "https://sepolia.etherscan.io/tx/",
30421
- avgBlockTime: 12
30422
- }
30423
- };
30424
- function getChain(name) {
30425
- const config = CHAINS[name];
30426
- if (!config) {
30427
- throw new Error(`Unsupported chain: ${name}. Supported: ${Object.keys(CHAINS).join(", ")}`);
30428
- }
30429
- return config;
30430
- }
30431
- function listChains() {
30432
- return Object.keys(CHAINS);
30433
- }
30434
- function getChainById(chainId) {
30435
- return Object.values(CHAINS).find((c) => c.chainId === chainId);
30436
- }
30437
- var ERC20_ABI = [
30438
- "function balanceOf(address owner) view returns (uint256)",
30439
- "function transfer(address to, uint256 amount) returns (bool)",
30440
- "function approve(address spender, uint256 amount) returns (bool)",
30441
- "function allowance(address owner, address spender) view returns (uint256)",
30442
- "function decimals() view returns (uint8)",
30443
- "function symbol() view returns (string)",
30444
- "function name() view returns (string)",
30445
- "function nonces(address owner) view returns (uint256)",
30446
- "function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)",
30447
- "event Transfer(address indexed from, address indexed to, uint256 value)",
30448
- "event Approval(address indexed owner, address indexed spender, uint256 value)"
30449
- ];
30372
+ var path = __toESM(require("path"));
30450
30373
 
30451
30374
  // src/server/types.ts
30452
30375
  init_cjs_shims();
@@ -30456,24 +30379,90 @@ var X402_VERSION = 2;
30456
30379
  var PAYMENT_REQUIRED_HEADER = "x-payment-required";
30457
30380
  var PAYMENT_HEADER = "x-payment";
30458
30381
  var PAYMENT_RESPONSE_HEADER = "x-payment-response";
30459
- var DEFAULT_FACILITATOR_URL = "https://x402.org/facilitator";
30382
+ var FACILITATOR_TESTNET = "https://www.x402.org/facilitator";
30383
+ var FACILITATOR_MAINNET = "https://api.cdp.coinbase.com/platform/v2/x402";
30384
+ function loadEnvFiles() {
30385
+ try {
30386
+ const dotenv = require("dotenv");
30387
+ const envPaths = [
30388
+ path.join(process.cwd(), ".env"),
30389
+ path.join(process.env.HOME || "", ".moltspay", ".env")
30390
+ ];
30391
+ for (const envPath of envPaths) {
30392
+ if ((0, import_fs.existsSync)(envPath)) {
30393
+ dotenv.config({ path: envPath });
30394
+ console.log(`[MoltsPay] Loaded config from ${envPath}`);
30395
+ break;
30396
+ }
30397
+ }
30398
+ } catch {
30399
+ }
30400
+ }
30401
+ function getCDPConfig() {
30402
+ loadEnvFiles();
30403
+ return {
30404
+ useMainnet: process.env.USE_MAINNET?.toLowerCase() === "true",
30405
+ apiKeyId: process.env.CDP_API_KEY_ID,
30406
+ apiKeySecret: process.env.CDP_API_KEY_SECRET
30407
+ };
30408
+ }
30409
+ async function getCDPAuthHeaders(method, urlPath, body) {
30410
+ const config = getCDPConfig();
30411
+ if (!config.apiKeyId || !config.apiKeySecret) {
30412
+ throw new Error("CDP_API_KEY_ID and CDP_API_KEY_SECRET required for mainnet");
30413
+ }
30414
+ try {
30415
+ const { getAuthHeaders } = await import("@coinbase/cdp-sdk/auth");
30416
+ const headers = await getAuthHeaders({
30417
+ apiKeyId: config.apiKeyId,
30418
+ apiKeySecret: config.apiKeySecret,
30419
+ requestMethod: method,
30420
+ requestHost: "api.cdp.coinbase.com",
30421
+ requestPath: urlPath,
30422
+ requestBody: body
30423
+ });
30424
+ return headers;
30425
+ } catch (err) {
30426
+ console.error("[MoltsPay] Failed to generate CDP auth headers:", err.message);
30427
+ throw err;
30428
+ }
30429
+ }
30460
30430
  var MoltsPayServer = class {
30461
30431
  manifest;
30462
30432
  skills = /* @__PURE__ */ new Map();
30463
30433
  options;
30434
+ cdpConfig;
30464
30435
  facilitatorUrl;
30436
+ networkId;
30465
30437
  constructor(servicesPath, options = {}) {
30438
+ this.cdpConfig = getCDPConfig();
30466
30439
  const content = (0, import_fs.readFileSync)(servicesPath, "utf-8");
30467
30440
  this.manifest = JSON.parse(content);
30468
30441
  this.options = {
30469
30442
  port: options.port || 3e3,
30470
30443
  host: options.host || "0.0.0.0"
30471
30444
  };
30472
- this.facilitatorUrl = options.facilitatorUrl || DEFAULT_FACILITATOR_URL;
30445
+ if (this.cdpConfig.useMainnet) {
30446
+ if (!this.cdpConfig.apiKeyId || !this.cdpConfig.apiKeySecret) {
30447
+ console.warn("[MoltsPay] WARNING: USE_MAINNET=true but CDP keys not set!");
30448
+ console.warn("[MoltsPay] Set CDP_API_KEY_ID and CDP_API_KEY_SECRET in ~/.moltspay/.env");
30449
+ }
30450
+ this.facilitatorUrl = FACILITATOR_MAINNET;
30451
+ this.networkId = "eip155:8453";
30452
+ } else {
30453
+ this.facilitatorUrl = options.facilitatorUrl || FACILITATOR_TESTNET;
30454
+ this.networkId = "eip155:84532";
30455
+ }
30456
+ const networkName = this.cdpConfig.useMainnet ? "Base mainnet" : "Base Sepolia (testnet)";
30457
+ const facilitatorName = this.cdpConfig.useMainnet ? "CDP" : "x402.org";
30473
30458
  console.log(`[MoltsPay] Loaded ${this.manifest.services.length} services from ${servicesPath}`);
30474
30459
  console.log(`[MoltsPay] Provider: ${this.manifest.provider.name}`);
30475
30460
  console.log(`[MoltsPay] Receive wallet: ${this.manifest.provider.wallet}`);
30476
- console.log(`[MoltsPay] Facilitator: ${this.facilitatorUrl}`);
30461
+ console.log(`[MoltsPay] Network: ${this.networkId} (${networkName})`);
30462
+ console.log(`[MoltsPay] Facilitator: ${facilitatorName} (${this.facilitatorUrl})`);
30463
+ if (this.cdpConfig.useMainnet && this.cdpConfig.apiKeyId) {
30464
+ console.log(`[MoltsPay] CDP API Key: ${this.cdpConfig.apiKeyId.slice(0, 8)}...`);
30465
+ }
30477
30466
  console.log(`[MoltsPay] Protocol: x402 (gasless for both client AND server)`);
30478
30467
  }
30479
30468
  /**
@@ -30534,7 +30523,6 @@ var MoltsPayServer = class {
30534
30523
  * GET /services - List available services
30535
30524
  */
30536
30525
  handleGetServices(res) {
30537
- const chain2 = getChain(this.manifest.provider.chain);
30538
30526
  const services = this.manifest.services.map((s) => ({
30539
30527
  id: s.id,
30540
30528
  name: s.name,
@@ -30550,16 +30538,15 @@ var MoltsPayServer = class {
30550
30538
  services,
30551
30539
  x402: {
30552
30540
  version: X402_VERSION,
30553
- network: `eip155:${chain2.chainId}`,
30541
+ network: this.networkId,
30554
30542
  schemes: ["exact"],
30555
- facilitator: this.facilitatorUrl
30543
+ facilitator: this.cdpConfig.useMainnet ? "cdp" : "x402.org",
30544
+ mainnet: this.cdpConfig.useMainnet
30556
30545
  }
30557
30546
  });
30558
30547
  }
30559
30548
  /**
30560
30549
  * POST /execute - Execute service with x402 payment
30561
- * Body: { service: string, params: object }
30562
- * Header: X-Payment (optional - if missing, returns 402)
30563
30550
  */
30564
30551
  async handleExecute(body, paymentHeader, res) {
30565
30552
  const { service, params } = body;
@@ -30634,16 +30621,17 @@ var MoltsPayServer = class {
30634
30621
  * Return 402 with x402 payment requirements
30635
30622
  */
30636
30623
  sendPaymentRequired(config, res) {
30637
- const chain2 = getChain(this.manifest.provider.chain);
30638
30624
  const amountInUnits = Math.floor(config.price * 1e6).toString();
30639
30625
  const requirements = [{
30640
30626
  scheme: "exact",
30641
- network: `eip155:${chain2.chainId}`,
30627
+ network: this.networkId,
30642
30628
  maxAmountRequired: amountInUnits,
30643
30629
  resource: this.manifest.provider.wallet,
30644
30630
  description: `${config.name} - $${config.price} ${config.currency}`,
30645
- // Include facilitator info for client
30646
- extra: JSON.stringify({ facilitator: this.facilitatorUrl })
30631
+ extra: JSON.stringify({
30632
+ facilitator: this.cdpConfig.useMainnet ? "cdp" : "x402.org",
30633
+ mainnet: this.cdpConfig.useMainnet
30634
+ })
30647
30635
  }];
30648
30636
  const encoded = Buffer.from(JSON.stringify(requirements)).toString("base64");
30649
30637
  res.writeHead(402, {
@@ -30657,7 +30645,7 @@ var MoltsPayServer = class {
30657
30645
  }, null, 2));
30658
30646
  }
30659
30647
  /**
30660
- * Basic payment validation (before calling facilitator)
30648
+ * Basic payment validation
30661
30649
  */
30662
30650
  validatePayment(payment, config) {
30663
30651
  if (payment.x402Version !== X402_VERSION) {
@@ -30666,37 +30654,45 @@ var MoltsPayServer = class {
30666
30654
  if (payment.scheme !== "exact") {
30667
30655
  return { valid: false, error: `Unsupported scheme: ${payment.scheme}` };
30668
30656
  }
30669
- const chain2 = getChain(this.manifest.provider.chain);
30670
- const expectedNetwork = `eip155:${chain2.chainId}`;
30671
- if (payment.network !== expectedNetwork) {
30672
- return { valid: false, error: `Network mismatch: expected ${expectedNetwork}` };
30657
+ if (payment.network !== this.networkId) {
30658
+ return { valid: false, error: `Network mismatch: expected ${this.networkId}, got ${payment.network}` };
30673
30659
  }
30674
30660
  return { valid: true };
30675
30661
  }
30676
30662
  /**
30677
- * Verify payment with facilitator
30663
+ * Verify payment with facilitator (testnet or CDP)
30678
30664
  */
30679
30665
  async verifyWithFacilitator(payment, config) {
30680
30666
  try {
30681
- const chain2 = getChain(this.manifest.provider.chain);
30682
30667
  const amountInUnits = Math.floor(config.price * 1e6).toString();
30683
30668
  const requirements = {
30684
30669
  scheme: "exact",
30685
- network: `eip155:${chain2.chainId}`,
30670
+ network: this.networkId,
30686
30671
  maxAmountRequired: amountInUnits,
30687
- resource: this.manifest.provider.wallet
30672
+ resource: this.manifest.provider.wallet,
30673
+ payTo: this.manifest.provider.wallet
30674
+ };
30675
+ const requestBody = {
30676
+ paymentPayload: payment,
30677
+ paymentRequirements: requirements
30688
30678
  };
30679
+ let headers = { "Content-Type": "application/json" };
30680
+ if (this.cdpConfig.useMainnet) {
30681
+ const authHeaders = await getCDPAuthHeaders(
30682
+ "POST",
30683
+ "/platform/v2/x402/verify",
30684
+ requestBody
30685
+ );
30686
+ headers = { ...headers, ...authHeaders };
30687
+ }
30689
30688
  const response = await fetch(`${this.facilitatorUrl}/verify`, {
30690
30689
  method: "POST",
30691
- headers: { "Content-Type": "application/json" },
30692
- body: JSON.stringify({
30693
- paymentPayload: payment,
30694
- paymentRequirements: requirements
30695
- })
30690
+ headers,
30691
+ body: JSON.stringify(requestBody)
30696
30692
  });
30697
30693
  const result = await response.json();
30698
30694
  if (!response.ok || !result.isValid) {
30699
- return { valid: false, error: result.invalidReason || "Verification failed" };
30695
+ return { valid: false, error: result.invalidReason || result.error || "Verification failed" };
30700
30696
  }
30701
30697
  return { valid: true };
30702
30698
  } catch (err) {
@@ -30707,25 +30703,35 @@ var MoltsPayServer = class {
30707
30703
  * Settle payment with facilitator (execute on-chain transfer)
30708
30704
  */
30709
30705
  async settleWithFacilitator(payment, config) {
30710
- const chain2 = getChain(this.manifest.provider.chain);
30711
30706
  const amountInUnits = Math.floor(config.price * 1e6).toString();
30712
30707
  const requirements = {
30713
30708
  scheme: "exact",
30714
- network: `eip155:${chain2.chainId}`,
30709
+ network: this.networkId,
30715
30710
  maxAmountRequired: amountInUnits,
30716
- resource: this.manifest.provider.wallet
30711
+ resource: this.manifest.provider.wallet,
30712
+ payTo: this.manifest.provider.wallet
30717
30713
  };
30714
+ const requestBody = {
30715
+ paymentPayload: payment,
30716
+ paymentRequirements: requirements
30717
+ };
30718
+ let headers = { "Content-Type": "application/json" };
30719
+ if (this.cdpConfig.useMainnet) {
30720
+ const authHeaders = await getCDPAuthHeaders(
30721
+ "POST",
30722
+ "/platform/v2/x402/settle",
30723
+ requestBody
30724
+ );
30725
+ headers = { ...headers, ...authHeaders };
30726
+ }
30718
30727
  const response = await fetch(`${this.facilitatorUrl}/settle`, {
30719
30728
  method: "POST",
30720
- headers: { "Content-Type": "application/json" },
30721
- body: JSON.stringify({
30722
- paymentPayload: payment,
30723
- paymentRequirements: requirements
30724
- })
30729
+ headers,
30730
+ body: JSON.stringify(requestBody)
30725
30731
  });
30726
30732
  const result = await response.json();
30727
- if (!response.ok) {
30728
- throw new Error(result.error || "Settlement failed");
30733
+ if (!response.ok || !result.success) {
30734
+ throw new Error(result.error || result.errorReason || "Settlement failed");
30729
30735
  }
30730
30736
  return {
30731
30737
  transaction: result.transaction,
@@ -30763,6 +30769,84 @@ var import_os = require("os");
30763
30769
  var import_path = require("path");
30764
30770
  var import_ethers = require("ethers");
30765
30771
 
30772
+ // src/chains/index.ts
30773
+ init_cjs_shims();
30774
+ var CHAINS = {
30775
+ // ============ Mainnet ============
30776
+ base: {
30777
+ name: "Base",
30778
+ chainId: 8453,
30779
+ rpc: "https://mainnet.base.org",
30780
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
30781
+ explorer: "https://basescan.org/address/",
30782
+ explorerTx: "https://basescan.org/tx/",
30783
+ avgBlockTime: 2
30784
+ },
30785
+ polygon: {
30786
+ name: "Polygon",
30787
+ chainId: 137,
30788
+ rpc: "https://polygon-rpc.com",
30789
+ usdc: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
30790
+ explorer: "https://polygonscan.com/address/",
30791
+ explorerTx: "https://polygonscan.com/tx/",
30792
+ avgBlockTime: 2
30793
+ },
30794
+ ethereum: {
30795
+ name: "Ethereum",
30796
+ chainId: 1,
30797
+ rpc: "https://eth.llamarpc.com",
30798
+ usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
30799
+ explorer: "https://etherscan.io/address/",
30800
+ explorerTx: "https://etherscan.io/tx/",
30801
+ avgBlockTime: 12
30802
+ },
30803
+ // ============ Testnet ============
30804
+ base_sepolia: {
30805
+ name: "Base Sepolia",
30806
+ chainId: 84532,
30807
+ rpc: "https://sepolia.base.org",
30808
+ usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
30809
+ explorer: "https://sepolia.basescan.org/address/",
30810
+ explorerTx: "https://sepolia.basescan.org/tx/",
30811
+ avgBlockTime: 2
30812
+ },
30813
+ sepolia: {
30814
+ name: "Sepolia",
30815
+ chainId: 11155111,
30816
+ rpc: "https://rpc.sepolia.org",
30817
+ usdc: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
30818
+ explorer: "https://sepolia.etherscan.io/address/",
30819
+ explorerTx: "https://sepolia.etherscan.io/tx/",
30820
+ avgBlockTime: 12
30821
+ }
30822
+ };
30823
+ function getChain(name) {
30824
+ const config = CHAINS[name];
30825
+ if (!config) {
30826
+ throw new Error(`Unsupported chain: ${name}. Supported: ${Object.keys(CHAINS).join(", ")}`);
30827
+ }
30828
+ return config;
30829
+ }
30830
+ function listChains() {
30831
+ return Object.keys(CHAINS);
30832
+ }
30833
+ function getChainById(chainId) {
30834
+ return Object.values(CHAINS).find((c) => c.chainId === chainId);
30835
+ }
30836
+ var ERC20_ABI = [
30837
+ "function balanceOf(address owner) view returns (uint256)",
30838
+ "function transfer(address to, uint256 amount) returns (bool)",
30839
+ "function approve(address spender, uint256 amount) returns (bool)",
30840
+ "function allowance(address owner, address spender) view returns (uint256)",
30841
+ "function decimals() view returns (uint8)",
30842
+ "function symbol() view returns (string)",
30843
+ "function name() view returns (string)",
30844
+ "function nonces(address owner) view returns (uint256)",
30845
+ "function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)",
30846
+ "event Transfer(address indexed from, address indexed to, uint256 value)",
30847
+ "event Approval(address indexed owner, address indexed spender, uint256 value)"
30848
+ ];
30849
+
30766
30850
  // src/client/types.ts
30767
30851
  init_cjs_shims();
30768
30852
 
@@ -31145,20 +31229,20 @@ function loadWallet(options = {}) {
31145
31229
  }
31146
31230
  }
31147
31231
  function getWalletAddress(storagePath) {
31148
- const path2 = storagePath || (0, import_path2.join)(DEFAULT_STORAGE_DIR, DEFAULT_STORAGE_FILE);
31149
- if (!(0, import_fs3.existsSync)(path2)) {
31232
+ const path3 = storagePath || (0, import_path2.join)(DEFAULT_STORAGE_DIR, DEFAULT_STORAGE_FILE);
31233
+ if (!(0, import_fs3.existsSync)(path3)) {
31150
31234
  return null;
31151
31235
  }
31152
31236
  try {
31153
- const data = JSON.parse((0, import_fs3.readFileSync)(path2, "utf8"));
31237
+ const data = JSON.parse((0, import_fs3.readFileSync)(path3, "utf8"));
31154
31238
  return data.address;
31155
31239
  } catch {
31156
31240
  return null;
31157
31241
  }
31158
31242
  }
31159
31243
  function walletExists(storagePath) {
31160
- const path2 = storagePath || (0, import_path2.join)(DEFAULT_STORAGE_DIR, DEFAULT_STORAGE_FILE);
31161
- return (0, import_fs3.existsSync)(path2);
31244
+ const path3 = storagePath || (0, import_path2.join)(DEFAULT_STORAGE_DIR, DEFAULT_STORAGE_FILE);
31245
+ return (0, import_fs3.existsSync)(path3);
31162
31246
  }
31163
31247
 
31164
31248
  // src/verify/index.ts
@@ -31301,8 +31385,8 @@ async function waitForTransaction(txHash, chain2 = "base", confirmations = 1, ti
31301
31385
  // src/cdp/index.ts
31302
31386
  init_cjs_shims();
31303
31387
  var fs = __toESM(require("fs"));
31304
- var path = __toESM(require("path"));
31305
- var DEFAULT_STORAGE_DIR2 = path.join(process.env.HOME || ".", ".moltspay");
31388
+ var path2 = __toESM(require("path"));
31389
+ var DEFAULT_STORAGE_DIR2 = path2.join(process.env.HOME || ".", ".moltspay");
31306
31390
  var CDP_CONFIG_FILE = "cdp-wallet.json";
31307
31391
  function isCDPAvailable() {
31308
31392
  try {
@@ -31324,7 +31408,7 @@ function getCDPCredentials(config) {
31324
31408
  async function initCDPWallet(config = {}) {
31325
31409
  const storageDir = config.storageDir || DEFAULT_STORAGE_DIR2;
31326
31410
  const chain2 = config.chain || "base";
31327
- const storagePath = path.join(storageDir, CDP_CONFIG_FILE);
31411
+ const storagePath = path2.join(storageDir, CDP_CONFIG_FILE);
31328
31412
  if (fs.existsSync(storagePath)) {
31329
31413
  try {
31330
31414
  const data = JSON.parse(fs.readFileSync(storagePath, "utf-8"));
@@ -31386,7 +31470,7 @@ async function initCDPWallet(config = {}) {
31386
31470
  }
31387
31471
  function loadCDPWallet(config = {}) {
31388
31472
  const storageDir = config.storageDir || DEFAULT_STORAGE_DIR2;
31389
- const storagePath = path.join(storageDir, CDP_CONFIG_FILE);
31473
+ const storagePath = path2.join(storageDir, CDP_CONFIG_FILE);
31390
31474
  if (!fs.existsSync(storagePath)) {
31391
31475
  return null;
31392
31476
  }