@sip-protocol/sdk 0.2.5 → 0.2.7

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
@@ -645,6 +645,91 @@ function validateScalar(value, field) {
645
645
  );
646
646
  }
647
647
  }
648
+ function isValidEvmAddress(address) {
649
+ if (typeof address !== "string") return false;
650
+ return /^0x[0-9a-fA-F]{40}$/.test(address);
651
+ }
652
+ function isValidSolanaAddressFormat(address) {
653
+ if (typeof address !== "string") return false;
654
+ return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
655
+ }
656
+ function isValidNearAddressFormat(address) {
657
+ if (typeof address !== "string") return false;
658
+ if (/^[0-9a-f]{64}$/.test(address)) return true;
659
+ if (address.length < 2 || address.length > 64) return false;
660
+ if (!/^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$/.test(address)) return false;
661
+ if (address.includes("..")) return false;
662
+ return true;
663
+ }
664
+ function getChainAddressType(chain) {
665
+ switch (chain) {
666
+ case "ethereum":
667
+ case "polygon":
668
+ case "arbitrum":
669
+ case "optimism":
670
+ case "base":
671
+ return "evm";
672
+ case "solana":
673
+ return "solana";
674
+ case "near":
675
+ return "near";
676
+ case "zcash":
677
+ return "zcash";
678
+ default:
679
+ return "unknown";
680
+ }
681
+ }
682
+ function validateAddressForChain(address, chain, field = "address") {
683
+ const addressType = getChainAddressType(chain);
684
+ switch (addressType) {
685
+ case "evm":
686
+ if (!isValidEvmAddress(address)) {
687
+ throw new ValidationError(
688
+ `Invalid address format for ${chain}. Expected EVM address (0x + 40 hex chars), got: ${address.slice(0, 20)}...`,
689
+ field,
690
+ { chain, expectedFormat: "0x...", receivedFormat: address.startsWith("0x") ? "hex but wrong length" : "not hex" }
691
+ );
692
+ }
693
+ break;
694
+ case "solana":
695
+ if (!isValidSolanaAddressFormat(address)) {
696
+ throw new ValidationError(
697
+ `Invalid address format for ${chain}. Expected Solana address (base58, 32-44 chars), got: ${address.slice(0, 20)}...`,
698
+ field,
699
+ { chain, expectedFormat: "base58", receivedFormat: address.startsWith("0x") ? "looks like EVM" : "unknown" }
700
+ );
701
+ }
702
+ break;
703
+ case "near":
704
+ if (!isValidNearAddressFormat(address)) {
705
+ throw new ValidationError(
706
+ `Invalid address format for ${chain}. Expected NEAR account ID (named or implicit), got: ${address.slice(0, 20)}...`,
707
+ field,
708
+ { chain, expectedFormat: "alice.near or 64 hex chars" }
709
+ );
710
+ }
711
+ break;
712
+ case "zcash":
713
+ if (!address || address.length === 0) {
714
+ throw new ValidationError(
715
+ `Invalid address format for ${chain}. Expected Zcash address.`,
716
+ field,
717
+ { chain }
718
+ );
719
+ }
720
+ break;
721
+ default:
722
+ break;
723
+ }
724
+ }
725
+ function isAddressValidForChain(address, chain) {
726
+ try {
727
+ validateAddressForChain(address, chain);
728
+ return true;
729
+ } catch {
730
+ return false;
731
+ }
732
+ }
648
733
 
649
734
  // src/secure-memory.ts
650
735
  var import_utils = require("@noble/hashes/utils");
@@ -2121,7 +2206,21 @@ var OneClickClient = class {
2121
2206
  */
2122
2207
  async quote(request) {
2123
2208
  this.validateQuoteRequest(request);
2124
- return this.post("/v0/quote", request);
2209
+ const rawResponse = await this.post("/v0/quote", request);
2210
+ return {
2211
+ quoteId: rawResponse.timestamp,
2212
+ // Use timestamp as quoteId since API doesn't provide one
2213
+ depositAddress: rawResponse.quote.depositAddress,
2214
+ amountIn: rawResponse.quote.amountIn,
2215
+ amountInFormatted: rawResponse.quote.amountInFormatted,
2216
+ amountOut: rawResponse.quote.amountOut,
2217
+ amountOutFormatted: rawResponse.quote.amountOutFormatted,
2218
+ amountOutUsd: rawResponse.quote.amountOutUsd,
2219
+ deadline: rawResponse.quote.deadline,
2220
+ timeEstimate: rawResponse.quote.timeEstimate,
2221
+ signature: rawResponse.signature,
2222
+ request: rawResponse.quoteRequest
2223
+ };
2125
2224
  }
2126
2225
  /**
2127
2226
  * Request a dry quote (preview without deposit address)
@@ -2370,8 +2469,10 @@ var DEFAULT_ASSET_MAPPINGS = {
2370
2469
  "arbitrum:ETH": "nep141:arb.omft.near",
2371
2470
  // Base assets
2372
2471
  "base:ETH": "nep141:base.omft.near",
2373
- // Polygon assets
2374
- "polygon:MATIC": "nep141:matic.omft.near"
2472
+ // Polygon assets (support both MATIC and POL symbols)
2473
+ "polygon:MATIC": "nep141:matic.omft.near",
2474
+ "polygon:POL": "nep141:matic.omft.near"
2475
+ // POL is the rebranded MATIC
2375
2476
  };
2376
2477
  var CHAIN_BLOCKCHAIN_MAP = {
2377
2478
  near: "near",
@@ -2419,6 +2520,23 @@ var NEARIntentsAdapter = class {
2419
2520
  */
2420
2521
  async prepareSwap(request, recipientMetaAddress, senderAddress) {
2421
2522
  this.validateRequest(request);
2523
+ const inputChain = request.inputAsset.chain;
2524
+ if (senderAddress) {
2525
+ if (!isAddressValidForChain(senderAddress, inputChain)) {
2526
+ const inputChainType = getChainAddressType(inputChain);
2527
+ const senderFormat = senderAddress.startsWith("0x") ? "EVM" : /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(senderAddress) ? "Solana" : /^[0-9a-f]{64}$/.test(senderAddress) || /^[a-z0-9._-]+$/.test(senderAddress) ? "NEAR" : "unknown";
2528
+ throw new ValidationError(
2529
+ `Wallet address format doesn't match input chain. You're swapping FROM ${inputChain} (${inputChainType} format) but your connected wallet uses ${senderFormat} format. Please connect a wallet that matches the source chain (${inputChain}).`,
2530
+ "senderAddress",
2531
+ {
2532
+ inputChain,
2533
+ expectedFormat: inputChainType,
2534
+ receivedFormat: senderFormat,
2535
+ hint: `For ${inputChain} swaps, connect a ${inputChainType === "evm" ? "MetaMask or EVM" : inputChainType} wallet.`
2536
+ }
2537
+ );
2538
+ }
2539
+ }
2422
2540
  let recipientAddress;
2423
2541
  let refundAddress = senderAddress;
2424
2542
  let stealthData;
@@ -2483,22 +2601,22 @@ var NEARIntentsAdapter = class {
2483
2601
  );
2484
2602
  }
2485
2603
  if (!senderAddress) {
2486
- const inputChain = request.inputAsset.chain;
2487
- const inputChainType = CHAIN_BLOCKCHAIN_MAP[inputChain];
2488
- if (isEd25519Chain(inputChain)) {
2604
+ const inputChain2 = request.inputAsset.chain;
2605
+ const inputChainType = CHAIN_BLOCKCHAIN_MAP[inputChain2];
2606
+ if (isEd25519Chain(inputChain2)) {
2489
2607
  const inputKeyBytes = (metaAddr.spendingKey.length - 2) / 2;
2490
2608
  if (inputKeyBytes === 32) {
2491
2609
  const refundStealth = generateEd25519StealthAddress(metaAddr);
2492
- if (inputChain === "solana") {
2610
+ if (inputChain2 === "solana") {
2493
2611
  refundAddress = ed25519PublicKeyToSolanaAddress(refundStealth.stealthAddress.address);
2494
- } else if (inputChain === "near") {
2612
+ } else if (inputChain2 === "near") {
2495
2613
  refundAddress = ed25519PublicKeyToNearAddress(refundStealth.stealthAddress.address);
2496
2614
  }
2497
2615
  } else {
2498
2616
  throw new ValidationError(
2499
- `Cross-curve refunds not supported: input chain ${inputChain} requires ed25519 but meta-address uses secp256k1. Please provide a senderAddress for refunds, or use matching curves for input/output chains.`,
2617
+ `Cross-curve refunds not supported: input chain ${inputChain2} requires ed25519 but meta-address uses secp256k1. Please provide a senderAddress for refunds, or use matching curves for input/output chains.`,
2500
2618
  "senderAddress",
2501
- { inputChain, inputChainType, metaAddressCurve: "secp256k1" }
2619
+ { inputChain: inputChain2, inputChainType, metaAddressCurve: "secp256k1" }
2502
2620
  );
2503
2621
  }
2504
2622
  } else if (inputChainType === "evm") {
@@ -2508,16 +2626,16 @@ var NEARIntentsAdapter = class {
2508
2626
  refundAddress = publicKeyToEthAddress(refundStealth.stealthAddress.address);
2509
2627
  } else {
2510
2628
  throw new ValidationError(
2511
- `Cross-curve refunds not supported: input chain ${inputChain} requires secp256k1 but meta-address uses ed25519. Please provide a senderAddress for refunds, or use matching curves for input/output chains.`,
2629
+ `Cross-curve refunds not supported: input chain ${inputChain2} requires secp256k1 but meta-address uses ed25519. Please provide a senderAddress for refunds, or use matching curves for input/output chains.`,
2512
2630
  "senderAddress",
2513
- { inputChain, inputChainType, metaAddressCurve: "ed25519" }
2631
+ { inputChain: inputChain2, inputChainType, metaAddressCurve: "ed25519" }
2514
2632
  );
2515
2633
  }
2516
2634
  } else {
2517
2635
  throw new ValidationError(
2518
- `senderAddress is required for refunds on ${inputChain}. Automatic refund address generation is only supported for EVM, Solana, and NEAR chains.`,
2636
+ `senderAddress is required for refunds on ${inputChain2}. Automatic refund address generation is only supported for EVM, Solana, and NEAR chains.`,
2519
2637
  "senderAddress",
2520
- { inputChain, inputChainType }
2638
+ { inputChain: inputChain2, inputChainType }
2521
2639
  );
2522
2640
  }
2523
2641
  }
package/dist/browser.mjs CHANGED
@@ -197,7 +197,7 @@ import {
197
197
  walletRegistry,
198
198
  withSecureBuffer,
199
199
  withSecureBufferSync
200
- } from "./chunk-MR7HRCRS.mjs";
200
+ } from "./chunk-5BAS4D44.mjs";
201
201
  import {
202
202
  fulfillment_proof_default,
203
203
  funding_proof_default,