@sip-protocol/sdk 0.2.6 → 0.2.8

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");
@@ -2372,20 +2457,43 @@ var DEFAULT_ASSET_MAPPINGS = {
2372
2457
  // NEAR assets
2373
2458
  "near:NEAR": "nep141:wrap.near",
2374
2459
  "near:wNEAR": "nep141:wrap.near",
2460
+ "near:USDC": "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
2375
2461
  // Ethereum assets (via OMFT bridge)
2376
2462
  "ethereum:ETH": "nep141:eth.omft.near",
2377
- "ethereum:USDC": "nep141:17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1",
2378
- "ethereum:USDT": "nep141:usdt.tether-token.near",
2463
+ "ethereum:USDC": "nep141:eth-0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.omft.near",
2464
+ "ethereum:USDT": "nep141:eth-0xdac17f958d2ee523a2206206994597c13d831ec7.omft.near",
2379
2465
  // Solana assets (via OMFT bridge)
2380
2466
  "solana:SOL": "nep141:sol.omft.near",
2467
+ "solana:USDC": "nep141:sol-5ce3bf3a31af18be40ba30f721101b4341690186.omft.near",
2468
+ "solana:USDT": "nep141:sol-c800a4bd850783ccb82c2b2c7e84175443606352.omft.near",
2381
2469
  // Zcash assets
2382
2470
  "zcash:ZEC": "nep141:zec.omft.near",
2383
2471
  // Arbitrum assets
2384
2472
  "arbitrum:ETH": "nep141:arb.omft.near",
2473
+ "arbitrum:ARB": "nep141:arb-0x912ce59144191c1204e64559fe8253a0e49e6548.omft.near",
2474
+ "arbitrum:USDC": "nep141:arb-0xaf88d065e77c8cc2239327c5edb3a432268e5831.omft.near",
2385
2475
  // Base assets
2386
2476
  "base:ETH": "nep141:base.omft.near",
2387
- // Polygon assets
2388
- "polygon:MATIC": "nep141:matic.omft.near"
2477
+ "base:USDC": "nep141:base-0x833589fcd6edb6e08f4c7c32d4f71b54bda02913.omft.near",
2478
+ // Optimism assets (via HOT bridge - uses nep245)
2479
+ "optimism:ETH": "nep245:v2_1.omni.hot.tg:10_11111111111111111111",
2480
+ "optimism:OP": "nep245:v2_1.omni.hot.tg:10_vLAiSt9KfUGKpw5cD3vsSyNYBo7",
2481
+ "optimism:USDC": "nep245:v2_1.omni.hot.tg:10_A2ewyUyDp6qsue1jqZsGypkCxRJ",
2482
+ // Polygon assets (via HOT bridge - uses nep245)
2483
+ "polygon:POL": "nep245:v2_1.omni.hot.tg:137_11111111111111111111",
2484
+ "polygon:MATIC": "nep245:v2_1.omni.hot.tg:137_11111111111111111111",
2485
+ // POL is the rebranded MATIC
2486
+ "polygon:USDC": "nep245:v2_1.omni.hot.tg:137_qiStmoQJDQPTebaPjgx5VBxZv6L",
2487
+ // BNB Chain assets (via HOT bridge - uses nep245)
2488
+ "bsc:BNB": "nep245:v2_1.omni.hot.tg:56_11111111111111111111",
2489
+ "bsc:USDC": "nep245:v2_1.omni.hot.tg:56_2w93GqMcEmQFDru84j3HZZWt557r",
2490
+ // Avalanche assets (via HOT bridge - uses nep245)
2491
+ "avalanche:AVAX": "nep245:v2_1.omni.hot.tg:43114_11111111111111111111",
2492
+ "avalanche:USDC": "nep245:v2_1.omni.hot.tg:43114_3atVJH3r5c4GqiSYmg9fECvjc47o",
2493
+ // Bitcoin
2494
+ "bitcoin:BTC": "nep141:btc.omft.near",
2495
+ // Aptos
2496
+ "aptos:APT": "nep141:aptos.omft.near"
2389
2497
  };
2390
2498
  var CHAIN_BLOCKCHAIN_MAP = {
2391
2499
  near: "near",
@@ -2433,6 +2541,23 @@ var NEARIntentsAdapter = class {
2433
2541
  */
2434
2542
  async prepareSwap(request, recipientMetaAddress, senderAddress) {
2435
2543
  this.validateRequest(request);
2544
+ const inputChain = request.inputAsset.chain;
2545
+ if (senderAddress) {
2546
+ if (!isAddressValidForChain(senderAddress, inputChain)) {
2547
+ const inputChainType = getChainAddressType(inputChain);
2548
+ 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";
2549
+ throw new ValidationError(
2550
+ `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}).`,
2551
+ "senderAddress",
2552
+ {
2553
+ inputChain,
2554
+ expectedFormat: inputChainType,
2555
+ receivedFormat: senderFormat,
2556
+ hint: `For ${inputChain} swaps, connect a ${inputChainType === "evm" ? "MetaMask or EVM" : inputChainType} wallet.`
2557
+ }
2558
+ );
2559
+ }
2560
+ }
2436
2561
  let recipientAddress;
2437
2562
  let refundAddress = senderAddress;
2438
2563
  let stealthData;
@@ -2497,22 +2622,22 @@ var NEARIntentsAdapter = class {
2497
2622
  );
2498
2623
  }
2499
2624
  if (!senderAddress) {
2500
- const inputChain = request.inputAsset.chain;
2501
- const inputChainType = CHAIN_BLOCKCHAIN_MAP[inputChain];
2502
- if (isEd25519Chain(inputChain)) {
2625
+ const inputChain2 = request.inputAsset.chain;
2626
+ const inputChainType = CHAIN_BLOCKCHAIN_MAP[inputChain2];
2627
+ if (isEd25519Chain(inputChain2)) {
2503
2628
  const inputKeyBytes = (metaAddr.spendingKey.length - 2) / 2;
2504
2629
  if (inputKeyBytes === 32) {
2505
2630
  const refundStealth = generateEd25519StealthAddress(metaAddr);
2506
- if (inputChain === "solana") {
2631
+ if (inputChain2 === "solana") {
2507
2632
  refundAddress = ed25519PublicKeyToSolanaAddress(refundStealth.stealthAddress.address);
2508
- } else if (inputChain === "near") {
2633
+ } else if (inputChain2 === "near") {
2509
2634
  refundAddress = ed25519PublicKeyToNearAddress(refundStealth.stealthAddress.address);
2510
2635
  }
2511
2636
  } else {
2512
2637
  throw new ValidationError(
2513
- `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.`,
2638
+ `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.`,
2514
2639
  "senderAddress",
2515
- { inputChain, inputChainType, metaAddressCurve: "secp256k1" }
2640
+ { inputChain: inputChain2, inputChainType, metaAddressCurve: "secp256k1" }
2516
2641
  );
2517
2642
  }
2518
2643
  } else if (inputChainType === "evm") {
@@ -2522,16 +2647,16 @@ var NEARIntentsAdapter = class {
2522
2647
  refundAddress = publicKeyToEthAddress(refundStealth.stealthAddress.address);
2523
2648
  } else {
2524
2649
  throw new ValidationError(
2525
- `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.`,
2650
+ `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.`,
2526
2651
  "senderAddress",
2527
- { inputChain, inputChainType, metaAddressCurve: "ed25519" }
2652
+ { inputChain: inputChain2, inputChainType, metaAddressCurve: "ed25519" }
2528
2653
  );
2529
2654
  }
2530
2655
  } else {
2531
2656
  throw new ValidationError(
2532
- `senderAddress is required for refunds on ${inputChain}. Automatic refund address generation is only supported for EVM, Solana, and NEAR chains.`,
2657
+ `senderAddress is required for refunds on ${inputChain2}. Automatic refund address generation is only supported for EVM, Solana, and NEAR chains.`,
2533
2658
  "senderAddress",
2534
- { inputChain, inputChainType }
2659
+ { inputChain: inputChain2, inputChainType }
2535
2660
  );
2536
2661
  }
2537
2662
  }
package/dist/browser.mjs CHANGED
@@ -197,7 +197,7 @@ import {
197
197
  walletRegistry,
198
198
  withSecureBuffer,
199
199
  withSecureBufferSync
200
- } from "./chunk-6WOV2YNG.mjs";
200
+ } from "./chunk-UPTISVCY.mjs";
201
201
  import {
202
202
  fulfillment_proof_default,
203
203
  funding_proof_default,