four-flap-meme-sdk 1.5.75 → 1.5.76
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/xlayer/bundle.js +66 -22
- package/dist/xlayer/constants.d.ts +3 -1
- package/dist/xlayer/constants.js +6 -0
- package/dist/xlayer/dex-bundle.js +40 -7
- package/dist/xlayer/dex.d.ts +24 -0
- package/dist/xlayer/dex.js +12 -1
- package/dist/xlayer/portal-ops.d.ts +27 -0
- package/dist/xlayer/portal-ops.js +38 -0
- package/dist/xlayer/types.d.ts +5 -1
- package/package.json +2 -2
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +0 -16
- package/dist/flap/portal-bundle-merkle/encryption.js +0 -146
package/dist/xlayer/bundle.js
CHANGED
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
* - OKB 归集:将 sender 的 OKB 转回 owner
|
|
9
9
|
*/
|
|
10
10
|
import { Wallet, Interface, Contract, ethers } from 'ethers';
|
|
11
|
-
import { FLAP_PORTAL, ENTRYPOINT_ABI, PORTAL_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, } from './constants.js';
|
|
11
|
+
import { FLAP_PORTAL, ENTRYPOINT_ABI, PORTAL_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, WOKB, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, } from './constants.js';
|
|
12
12
|
import { AAAccountManager, encodeExecute, encodeExecuteBatch, createWallet } from './aa-account.js';
|
|
13
|
-
import { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, encodeCreateCallV2, encodeCreateCallV3, encodeCreateCallV4, PortalQuery, parseOkb, formatOkb, } from './portal-ops.js';
|
|
13
|
+
import { encodeBuyCall, encodeSellCall, encodeApproveCall, encodeTransferCall, encodeCreateCallV2, encodeCreateCallV3, encodeCreateCallV4, PortalQuery, parseOkb, formatOkb, lpFeeProfileToV3Fee, } from './portal-ops.js';
|
|
14
14
|
import { mapWithConcurrency } from '../utils/concurrency.js';
|
|
15
15
|
import { PROFIT_CONFIG, ZERO_ADDRESS } from '../utils/constants.js';
|
|
16
16
|
import { DexQuery } from './dex.js';
|
|
17
|
+
import { encodeSwapExactETHForTokensSupportingFee, encodeSwapExactETHForTokensV3, } from './dex.js';
|
|
17
18
|
// ============================================================================
|
|
18
19
|
// AA Nonce(EntryPoint nonce)本地分配器
|
|
19
20
|
// ============================================================================
|
|
@@ -1458,8 +1459,8 @@ export class BundleExecutor {
|
|
|
1458
1459
|
return info;
|
|
1459
1460
|
});
|
|
1460
1461
|
const ops2 = [];
|
|
1461
|
-
const deadline = Math.floor(Date.now() / 1000) +
|
|
1462
|
-
|
|
1462
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200; // 20 min
|
|
1463
|
+
const dexType = (params.lpFeeProfile !== undefined && params.lpFeeProfile >= 0) ? 'V3' : 'V2';
|
|
1463
1464
|
// ✅ 预计算所有外盘买入金额
|
|
1464
1465
|
const dexBuyData = dexBuyerWallets.map((wallet, i) => {
|
|
1465
1466
|
const buyWei = parseOkb(dexBuyAmounts[i]);
|
|
@@ -1469,11 +1470,26 @@ export class BundleExecutor {
|
|
|
1469
1470
|
// ✅ 并行构建和签名所有外盘买入 UserOps
|
|
1470
1471
|
const signedDexBuyOps = await mapWithConcurrency(dexBuyData, 5, async (data) => {
|
|
1471
1472
|
const { wallet, info, buyWei } = data;
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1473
|
+
let swapData;
|
|
1474
|
+
let routerAddress;
|
|
1475
|
+
if (dexType === 'V3') {
|
|
1476
|
+
routerAddress = POTATOSWAP_V3_ROUTER;
|
|
1477
|
+
swapData = encodeSwapExactETHForTokensV3({
|
|
1478
|
+
tokenIn: WOKB,
|
|
1479
|
+
tokenOut: tokenAddress,
|
|
1480
|
+
fee: lpFeeProfileToV3Fee(params.lpFeeProfile ?? 0),
|
|
1481
|
+
recipient: info.sender,
|
|
1482
|
+
deadline,
|
|
1483
|
+
amountIn: buyWei,
|
|
1484
|
+
amountOutMinimum: 0n,
|
|
1485
|
+
sqrtPriceLimitX96: 0n
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
else {
|
|
1489
|
+
routerAddress = POTATOSWAP_V2_ROUTER;
|
|
1490
|
+
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1491
|
+
}
|
|
1492
|
+
const dexBuyCallData = encodeExecute(routerAddress, buyWei, swapData);
|
|
1477
1493
|
const dexBuyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1478
1494
|
ownerWallet: wallet,
|
|
1479
1495
|
sender: info.sender,
|
|
@@ -1481,7 +1497,7 @@ export class BundleExecutor {
|
|
|
1481
1497
|
nonce: nonceMap.next(info.sender),
|
|
1482
1498
|
initCode: '0x', // HandleOps1 已部署
|
|
1483
1499
|
deployed: true,
|
|
1484
|
-
fixedGas: { callGasLimit:
|
|
1500
|
+
fixedGas: { callGasLimit: 600000n }
|
|
1485
1501
|
});
|
|
1486
1502
|
const signedDexBuyOp = await aaManager.signUserOp(dexBuyOpRes.userOp, wallet);
|
|
1487
1503
|
return signedDexBuyOp.userOp;
|
|
@@ -1539,13 +1555,24 @@ export class BundleExecutor {
|
|
|
1539
1555
|
const { tokenAddress, privateKeys, payerPrivateKey, amountMode, totalBuyAmount, minAmount, maxAmount, walletAmounts, enableDexBuy = false, config = {} } = params;
|
|
1540
1556
|
const aaManager = this.getAAManager();
|
|
1541
1557
|
const provider = aaManager.getProvider();
|
|
1542
|
-
// 1.
|
|
1543
|
-
const tokenState = await this.portalQuery.
|
|
1558
|
+
// 1. 获取代币状态,动态计算毕业容量
|
|
1559
|
+
const tokenState = await this.portalQuery.getTokenV7(tokenAddress);
|
|
1560
|
+
// ✅ 内联曲线公式计算毕业容量
|
|
1561
|
+
// 公式:graduationReserve = h * k(曲线参数从合约读取)
|
|
1562
|
+
const r = tokenState.r; // 衰减因子
|
|
1563
|
+
const h = tokenState.h; // 初始高度
|
|
1564
|
+
const k = tokenState.k; // 缩放系数
|
|
1565
|
+
// 毕业储备 = h * k (wei)
|
|
1566
|
+
const graduationReserveWei = h * k / (10n ** 18n);
|
|
1567
|
+
const graduationReserve = ethers.formatEther(graduationReserveWei);
|
|
1544
1568
|
const poolReserveOkb = ethers.formatEther(tokenState.reserve);
|
|
1545
|
-
const graduateCapacity =
|
|
1546
|
-
|
|
1569
|
+
const graduateCapacity = parseFloat(graduationReserve);
|
|
1570
|
+
// 剩余毕业金额 = 毕业阈值 - 当前储备(加 0.5% 手续费缓冲)
|
|
1571
|
+
const remaining = Math.max(0, graduateCapacity - parseFloat(poolReserveOkb));
|
|
1572
|
+
const remainingWithFee = remaining * 1.005; // 0.5% 手续费缓冲
|
|
1573
|
+
const remainingToGraduate = remainingWithFee;
|
|
1547
1574
|
const remainingToGraduateWei = ethers.parseEther(remainingToGraduate.toFixed(18));
|
|
1548
|
-
console.log(`[GraduateBuy] Pool Reserve: ${poolReserveOkb} OKB, Remaining: ${remainingToGraduate} OKB`);
|
|
1575
|
+
console.log(`[GraduateBuy] Pool Reserve: ${poolReserveOkb} OKB, Graduation: ${graduationReserve} OKB, Remaining: ${remainingToGraduate.toFixed(4)} OKB`);
|
|
1549
1576
|
// 2. 准备钱包
|
|
1550
1577
|
const sharedProvider = this.aaManager.getProvider();
|
|
1551
1578
|
const wallets = privateKeys.map(pk => new Wallet(pk, sharedProvider));
|
|
@@ -1635,16 +1662,33 @@ export class BundleExecutor {
|
|
|
1635
1662
|
nonceMap.init(info.sender, info.nonce);
|
|
1636
1663
|
return info;
|
|
1637
1664
|
});
|
|
1638
|
-
|
|
1639
|
-
|
|
1665
|
+
const deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
1666
|
+
const dexType = (tokenState.lpFeeProfile >= 0 && tokenState.tokenVersion >= 4) ? 'V3' : 'V2';
|
|
1640
1667
|
const signedDexBuyOps = await mapWithConcurrency(dexBuyers, 5, async (data, i) => {
|
|
1641
1668
|
const { wallet, amount } = data;
|
|
1642
1669
|
const info = dexBuyerInfos[i];
|
|
1643
1670
|
totalDexBuyWei += amount;
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1671
|
+
let swapData;
|
|
1672
|
+
let routerAddress;
|
|
1673
|
+
if (dexType === 'V3') {
|
|
1674
|
+
routerAddress = POTATOSWAP_V3_ROUTER;
|
|
1675
|
+
swapData = encodeSwapExactETHForTokensV3({
|
|
1676
|
+
tokenIn: WOKB,
|
|
1677
|
+
tokenOut: tokenAddress,
|
|
1678
|
+
fee: lpFeeProfileToV3Fee(tokenState.lpFeeProfile),
|
|
1679
|
+
recipient: info.sender,
|
|
1680
|
+
deadline,
|
|
1681
|
+
amountIn: amount,
|
|
1682
|
+
amountOutMinimum: 0n,
|
|
1683
|
+
sqrtPriceLimitX96: 0n
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
else {
|
|
1687
|
+
routerAddress = POTATOSWAP_V2_ROUTER;
|
|
1688
|
+
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], info.sender, deadline);
|
|
1689
|
+
}
|
|
1690
|
+
// ✅ 简化为单次 execute,不需要 executeBatch
|
|
1691
|
+
const dexBuyCallData = encodeExecute(routerAddress, amount, swapData);
|
|
1648
1692
|
const dexBuyOpRes = await aaManager.buildUserOpWithFixedGas({
|
|
1649
1693
|
ownerWallet: wallet,
|
|
1650
1694
|
sender: info.sender,
|
|
@@ -1652,7 +1696,7 @@ export class BundleExecutor {
|
|
|
1652
1696
|
nonce: nonceMap.next(info.sender),
|
|
1653
1697
|
initCode: info.deployed ? '0x' : (await aaManager.generateInitCode(wallet.address)),
|
|
1654
1698
|
deployed: info.deployed,
|
|
1655
|
-
fixedGas: { callGasLimit: effConfig.fixedGas?.callGasLimit ??
|
|
1699
|
+
fixedGas: { callGasLimit: effConfig.fixedGas?.callGasLimit ?? 600000n }
|
|
1656
1700
|
});
|
|
1657
1701
|
const signedDexBuyOp = await aaManager.signUserOp(dexBuyOpRes.userOp, wallet);
|
|
1658
1702
|
return signedDexBuyOp.userOp;
|
|
@@ -69,9 +69,11 @@ export declare const ENTRYPOINT_ABI: readonly ["function getNonce(address sender
|
|
|
69
69
|
/** SimpleAccount ABI */
|
|
70
70
|
export declare const SIMPLE_ACCOUNT_ABI: readonly ["function execute(address dest, uint256 value, bytes func) external", "function executeBatch(address[] calldata dest, bytes[] calldata func) external", "function executeBatch(address[] calldata dest, uint256[] calldata values, bytes[] calldata func) external"];
|
|
71
71
|
/** Flap Portal ABI */
|
|
72
|
-
export declare const PORTAL_ABI: readonly ["function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)", "function buy(address token, address to, uint256 minAmount) external payable returns (uint256)", "function sell(address token, uint256 amount, uint256 minEth) external returns (uint256)", "function quoteExactInput((address inputToken,address outputToken,uint256 inputAmount)) external returns (uint256)", "function previewBuy(address token, uint256 ethAmount) external view returns (uint256)", "function previewSell(address token, uint256 tokenAmount) external view returns (uint256)", "function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))", "function newTokenV2((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData) params) external payable returns (address)", "function newTokenV3((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData) params) external payable returns (address)", "function newTokenV4((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData,uint8 dexId,uint8 lpFeeProfile) params) external payable returns (address)"];
|
|
72
|
+
export declare const PORTAL_ABI: readonly ["function swapExactInput((address inputToken,address outputToken,uint256 inputAmount,uint256 minOutputAmount,bytes permitData) params) payable returns (uint256)", "function buy(address token, address to, uint256 minAmount) external payable returns (uint256)", "function sell(address token, uint256 amount, uint256 minEth) external returns (uint256)", "function quoteExactInput((address inputToken,address outputToken,uint256 inputAmount)) external returns (uint256)", "function previewBuy(address token, uint256 ethAmount) external view returns (uint256)", "function previewSell(address token, uint256 tokenAmount) external view returns (uint256)", "function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))", "function getTokenV7(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32,uint8,uint8))", "function newTokenV2((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData) params) external payable returns (address)", "function newTokenV3((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData) params) external payable returns (address)", "function newTokenV4((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData,uint8 dexId,uint8 lpFeeProfile) params) external payable returns (address)"];
|
|
73
73
|
/** ERC20 ABI */
|
|
74
74
|
export declare const ERC20_ABI: readonly ["function balanceOf(address account) view returns (uint256)", "function allowance(address owner, address spender) view returns (uint256)", "function approve(address spender, uint256 amount) returns (bool)", "function transfer(address to, uint256 amount) returns (bool)", "function decimals() view returns (uint8)", "function symbol() view returns (string)", "function name() view returns (string)"];
|
|
75
75
|
/** PotatoSwap V2 Router ABI */
|
|
76
76
|
export declare const POTATOSWAP_V2_ROUTER_ABI: readonly ["function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)", "function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)", "function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)", "function swapExactETHForTokensSupportingFeeOnTransferTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable", "function swapExactTokensForETHSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external", "function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external", "function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts)", "function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts)", "function WETH() external pure returns (address)"];
|
|
77
|
+
/** PotatoSwap V3 Router ABI (SwapRouter02) */
|
|
78
|
+
export declare const POTATOSWAP_V3_ROUTER_ABI: readonly ["function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountOut)", "function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)"];
|
|
77
79
|
export type HexString = `0x${string}`;
|
package/dist/xlayer/constants.js
CHANGED
|
@@ -113,6 +113,7 @@ export const PORTAL_ABI = [
|
|
|
113
113
|
'function previewBuy(address token, uint256 ethAmount) external view returns (uint256)',
|
|
114
114
|
'function previewSell(address token, uint256 tokenAmount) external view returns (uint256)',
|
|
115
115
|
'function getTokenV5(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32))',
|
|
116
|
+
'function getTokenV7(address token) external view returns ((uint8,uint256,uint256,uint256,uint8,uint256,uint256,uint256,uint256,address,bool,bytes32,uint8,uint8))',
|
|
116
117
|
'function newTokenV2((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData) params) external payable returns (address)',
|
|
117
118
|
'function newTokenV3((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData) params) external payable returns (address)',
|
|
118
119
|
'function newTokenV4((string name,string symbol,string meta,uint8 dexThresh,bytes32 salt,uint16 taxRate,uint8 migratorType,address quoteToken,uint256 quoteAmt,address beneficiary,bytes permitData,bytes32 extensionID,bytes extensionData,uint8 dexId,uint8 lpFeeProfile) params) external payable returns (address)',
|
|
@@ -142,3 +143,8 @@ export const POTATOSWAP_V2_ROUTER_ABI = [
|
|
|
142
143
|
'function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts)',
|
|
143
144
|
'function WETH() external pure returns (address)',
|
|
144
145
|
];
|
|
146
|
+
/** PotatoSwap V3 Router ABI (SwapRouter02) */
|
|
147
|
+
export const POTATOSWAP_V3_ROUTER_ABI = [
|
|
148
|
+
'function exactInputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountOut)',
|
|
149
|
+
'function exactOutputSingle((address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96) params) external payable returns (uint256 amountIn)',
|
|
150
|
+
];
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* - ✅ 支持“刮取利润”:在归集时从可转出金额中按 bps 拆分转到 PROFIT_CONFIG.RECIPIENT
|
|
8
8
|
*/
|
|
9
9
|
import { Wallet, Contract, Interface, ethers } from 'ethers';
|
|
10
|
-
import { ENTRYPOINT_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, POTATOSWAP_V2_ROUTER, WOKB, } from './constants.js';
|
|
10
|
+
import { ENTRYPOINT_ABI, DEFAULT_CALL_GAS_LIMIT_SELL, DEFAULT_WITHDRAW_RESERVE, POTATOSWAP_V2_ROUTER, POTATOSWAP_V3_ROUTER, WOKB, } from './constants.js';
|
|
11
11
|
import { AAAccountManager, encodeExecute } from './aa-account.js';
|
|
12
|
-
import { DexQuery, encodeSwapExactETHForTokensSupportingFee, encodeSwapExactTokensForETHSupportingFee } from './dex.js';
|
|
13
|
-
import { PortalQuery, encodeApproveCall, parseOkb, formatOkb } from './portal-ops.js';
|
|
12
|
+
import { DexQuery, encodeSwapExactETHForTokensSupportingFee, encodeSwapExactTokensForETHSupportingFee, encodeSwapExactETHForTokensV3, encodeSwapExactTokensForETHV3, } from './dex.js';
|
|
13
|
+
import { PortalQuery, encodeApproveCall, parseOkb, formatOkb, lpFeeProfileToV3Fee } from './portal-ops.js';
|
|
14
14
|
import { mapWithConcurrency } from '../utils/concurrency.js';
|
|
15
15
|
import { PROFIT_CONFIG } from '../utils/constants.js';
|
|
16
16
|
import { AANonceMap } from './types.js';
|
|
@@ -48,6 +48,8 @@ export class DexBundleExecutor {
|
|
|
48
48
|
getEffectiveRouter(params) {
|
|
49
49
|
if (params.routerAddress)
|
|
50
50
|
return params.routerAddress;
|
|
51
|
+
if (params.dexType === 'V3')
|
|
52
|
+
return POTATOSWAP_V3_ROUTER;
|
|
51
53
|
if (params.dexKey === 'DYORSWAP') {
|
|
52
54
|
return '0xfb001fbbace32f09cb6d3c449b935183de53ee96';
|
|
53
55
|
}
|
|
@@ -196,7 +198,8 @@ export class DexBundleExecutor {
|
|
|
196
198
|
if (privateKeys.length !== buyAmounts.length) {
|
|
197
199
|
throw new Error('私钥数量和购买金额数量必须一致');
|
|
198
200
|
}
|
|
199
|
-
const effectiveRouter = this.getEffectiveRouter({ dexKey, routerAddress });
|
|
201
|
+
const effectiveRouter = this.getEffectiveRouter({ dexKey, routerAddress, dexType: params.dexType });
|
|
202
|
+
const isV3 = params.dexType === 'V3';
|
|
200
203
|
const deadline = getDexDeadline(this.getDeadlineMinutes({ deadlineMinutes }));
|
|
201
204
|
const sharedProvider = this.aaManager.getProvider();
|
|
202
205
|
const wallets = privateKeys.map((pk) => new Wallet(pk, sharedProvider));
|
|
@@ -204,7 +207,7 @@ export class DexBundleExecutor {
|
|
|
204
207
|
const beneficiary = bundlerSigner.address;
|
|
205
208
|
const reserveWei = parseOkb(withdrawReserve);
|
|
206
209
|
console.log('=== XLayer DEX Bundle Buy -> Sell ===');
|
|
207
|
-
console.log('router:', effectiveRouter);
|
|
210
|
+
console.log('router:', effectiveRouter, isV3 ? '(V3)' : '(V2)');
|
|
208
211
|
console.log('token:', tokenAddress);
|
|
209
212
|
console.log('owners:', wallets.length);
|
|
210
213
|
console.log('sellPercent:', sellPercent);
|
|
@@ -226,7 +229,22 @@ export class DexBundleExecutor {
|
|
|
226
229
|
});
|
|
227
230
|
const buyCallDatas = buyWeis.map((buyWei, i) => {
|
|
228
231
|
const sender = senders[i];
|
|
229
|
-
|
|
232
|
+
let swapData;
|
|
233
|
+
if (isV3) {
|
|
234
|
+
swapData = encodeSwapExactETHForTokensV3({
|
|
235
|
+
tokenIn: WOKB,
|
|
236
|
+
tokenOut: tokenAddress,
|
|
237
|
+
fee: lpFeeProfileToV3Fee(params.lpFeeProfile ?? 0),
|
|
238
|
+
recipient: sender,
|
|
239
|
+
deadline,
|
|
240
|
+
amountIn: buyWei,
|
|
241
|
+
amountOutMinimum: 0n,
|
|
242
|
+
sqrtPriceLimitX96: 0n,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
swapData = encodeSwapExactETHForTokensSupportingFee(0n, [WOKB, tokenAddress], sender, deadline);
|
|
247
|
+
}
|
|
230
248
|
return encodeExecute(effectiveRouter, buyWei, swapData);
|
|
231
249
|
});
|
|
232
250
|
const initCodes = accountInfos.map((ai, i) => (ai.deployed ? '0x' : this.aaManager.generateInitCode(wallets[i].address)));
|
|
@@ -286,7 +304,22 @@ export class DexBundleExecutor {
|
|
|
286
304
|
if (sellAmount === 0n)
|
|
287
305
|
return out;
|
|
288
306
|
const sellNonce = nonceMap.next(sender);
|
|
289
|
-
|
|
307
|
+
let sellSwapData;
|
|
308
|
+
if (isV3) {
|
|
309
|
+
sellSwapData = encodeSwapExactTokensForETHV3({
|
|
310
|
+
tokenIn: tokenAddress,
|
|
311
|
+
tokenOut: WOKB,
|
|
312
|
+
fee: lpFeeProfileToV3Fee(params.lpFeeProfile ?? 0),
|
|
313
|
+
recipient: sender,
|
|
314
|
+
deadline,
|
|
315
|
+
amountIn: sellAmount,
|
|
316
|
+
amountOutMinimum: 0n,
|
|
317
|
+
sqrtPriceLimitX96: 0n,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
sellSwapData = encodeSwapExactTokensForETHSupportingFee(sellAmount, 0n, [tokenAddress, WOKB], sender, deadline);
|
|
322
|
+
}
|
|
290
323
|
const sellCallData = encodeExecute(effectiveRouter, 0n, sellSwapData);
|
|
291
324
|
const signedSell = await this.aaManager.buildUserOpWithState({
|
|
292
325
|
ownerWallet: w,
|
package/dist/xlayer/dex.d.ts
CHANGED
|
@@ -7,6 +7,30 @@
|
|
|
7
7
|
* - 通过 AA 账户执行
|
|
8
8
|
*/
|
|
9
9
|
import type { XLayerConfig, DexSwapResult } from './types.js';
|
|
10
|
+
export declare function encodeSwapExactETHForTokensV3(params: {
|
|
11
|
+
tokenIn: string;
|
|
12
|
+
tokenOut: string;
|
|
13
|
+
fee: number;
|
|
14
|
+
recipient: string;
|
|
15
|
+
deadline: number;
|
|
16
|
+
amountIn: bigint;
|
|
17
|
+
amountOutMinimum: bigint;
|
|
18
|
+
sqrtPriceLimitX96: bigint;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* 编码 swapExactTokensForETHV3 调用
|
|
22
|
+
* 对齐 Uniswap V3 的 exactInputSingle 逻辑
|
|
23
|
+
*/
|
|
24
|
+
export declare function encodeSwapExactTokensForETHV3(params: {
|
|
25
|
+
tokenIn: string;
|
|
26
|
+
tokenOut: string;
|
|
27
|
+
fee: number;
|
|
28
|
+
recipient: string;
|
|
29
|
+
deadline: number;
|
|
30
|
+
amountIn: bigint;
|
|
31
|
+
amountOutMinimum: bigint;
|
|
32
|
+
sqrtPriceLimitX96: bigint;
|
|
33
|
+
}): string;
|
|
10
34
|
/**
|
|
11
35
|
* 编码 swapExactETHForTokens 调用
|
|
12
36
|
*/
|
package/dist/xlayer/dex.js
CHANGED
|
@@ -7,13 +7,24 @@
|
|
|
7
7
|
* - 通过 AA 账户执行
|
|
8
8
|
*/
|
|
9
9
|
import { ethers, Contract, Interface, JsonRpcProvider } from 'ethers';
|
|
10
|
-
import { POTATOSWAP_V2_ROUTER, POTATOSWAP_V2_ROUTER_ABI, WOKB, DEFAULT_RPC_URL, XLAYER_CHAIN_ID, ERC20_ABI, } from './constants.js';
|
|
10
|
+
import { POTATOSWAP_V2_ROUTER, POTATOSWAP_V2_ROUTER_ABI, POTATOSWAP_V3_ROUTER_ABI, WOKB, DEFAULT_RPC_URL, XLAYER_CHAIN_ID, ERC20_ABI, } from './constants.js';
|
|
11
11
|
import { AAAccountManager, encodeExecute, createWallet } from './aa-account.js';
|
|
12
12
|
import { encodeApproveCall, parseOkb, formatOkb } from './portal-ops.js';
|
|
13
13
|
// ============================================================================
|
|
14
14
|
// DEX 交易编码器
|
|
15
15
|
// ============================================================================
|
|
16
16
|
const routerIface = new Interface(POTATOSWAP_V2_ROUTER_ABI);
|
|
17
|
+
const v3RouterIface = new Interface(POTATOSWAP_V3_ROUTER_ABI);
|
|
18
|
+
export function encodeSwapExactETHForTokensV3(params) {
|
|
19
|
+
return v3RouterIface.encodeFunctionData('exactInputSingle', [params]);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 编码 swapExactTokensForETHV3 调用
|
|
23
|
+
* 对齐 Uniswap V3 的 exactInputSingle 逻辑
|
|
24
|
+
*/
|
|
25
|
+
export function encodeSwapExactTokensForETHV3(params) {
|
|
26
|
+
return v3RouterIface.encodeFunctionData('exactInputSingle', [params]);
|
|
27
|
+
}
|
|
17
28
|
/**
|
|
18
29
|
* 编码 swapExactETHForTokens 调用
|
|
19
30
|
*/
|
|
@@ -165,6 +165,25 @@ export declare class PortalQuery {
|
|
|
165
165
|
nativeToQuoteSwapEnabled: boolean;
|
|
166
166
|
extensionID: string;
|
|
167
167
|
}>;
|
|
168
|
+
/**
|
|
169
|
+
* 获取代币状态 V7 (包含 lpFeeProfile)
|
|
170
|
+
*/
|
|
171
|
+
getTokenV7(tokenAddress: string): Promise<{
|
|
172
|
+
status: number;
|
|
173
|
+
reserve: bigint;
|
|
174
|
+
circulatingSupply: bigint;
|
|
175
|
+
price: bigint;
|
|
176
|
+
tokenVersion: number;
|
|
177
|
+
r: bigint;
|
|
178
|
+
h: bigint;
|
|
179
|
+
k: bigint;
|
|
180
|
+
dexSupplyThresh: bigint;
|
|
181
|
+
quoteTokenAddress: string;
|
|
182
|
+
nativeToQuoteSwapEnabled: boolean;
|
|
183
|
+
extensionID: string;
|
|
184
|
+
dexId: number;
|
|
185
|
+
lpFeeProfile: number;
|
|
186
|
+
}>;
|
|
168
187
|
/**
|
|
169
188
|
* 批量获取多个账户的代币余额
|
|
170
189
|
*/
|
|
@@ -185,6 +204,14 @@ export declare class PortalQuery {
|
|
|
185
204
|
* @param slippageBps 滑点基点(如 100 = 1%)
|
|
186
205
|
*/
|
|
187
206
|
export declare function applySlippage(expectedOutput: bigint, slippageBps: number): bigint;
|
|
207
|
+
/**
|
|
208
|
+
* 将 Portal 的 lpFeeProfile 转换为 V3 Router 所需的 fee (100万分比)
|
|
209
|
+
*
|
|
210
|
+
* STANDARD = 0.25% (2500)
|
|
211
|
+
* LOW = 0.01% (100)
|
|
212
|
+
* HIGH = 1% (10000)
|
|
213
|
+
*/
|
|
214
|
+
export declare function lpFeeProfileToV3Fee(profile: number): number;
|
|
188
215
|
/**
|
|
189
216
|
* 创建 Portal 查询器
|
|
190
217
|
*/
|
|
@@ -198,6 +198,28 @@ export class PortalQuery {
|
|
|
198
198
|
extensionID: raw[11],
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* 获取代币状态 V7 (包含 lpFeeProfile)
|
|
203
|
+
*/
|
|
204
|
+
async getTokenV7(tokenAddress) {
|
|
205
|
+
const raw = await this.portal.getTokenV7(tokenAddress);
|
|
206
|
+
return {
|
|
207
|
+
status: Number(raw[0]),
|
|
208
|
+
reserve: raw[1],
|
|
209
|
+
circulatingSupply: raw[2],
|
|
210
|
+
price: raw[3],
|
|
211
|
+
tokenVersion: Number(raw[4]),
|
|
212
|
+
r: raw[5],
|
|
213
|
+
h: raw[6],
|
|
214
|
+
k: raw[7],
|
|
215
|
+
dexSupplyThresh: raw[8],
|
|
216
|
+
quoteTokenAddress: raw[9],
|
|
217
|
+
nativeToQuoteSwapEnabled: raw[10],
|
|
218
|
+
extensionID: raw[11],
|
|
219
|
+
dexId: Number(raw[12]),
|
|
220
|
+
lpFeeProfile: Number(raw[13]),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
201
223
|
/**
|
|
202
224
|
* 批量获取多个账户的代币余额
|
|
203
225
|
*/
|
|
@@ -343,6 +365,22 @@ export function applySlippage(expectedOutput, slippageBps) {
|
|
|
343
365
|
const keep = BigInt(10000 - Math.max(0, Math.min(5000, slippageBps)));
|
|
344
366
|
return (expectedOutput * keep) / 10000n;
|
|
345
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* 将 Portal 的 lpFeeProfile 转换为 V3 Router 所需的 fee (100万分比)
|
|
370
|
+
*
|
|
371
|
+
* STANDARD = 0.25% (2500)
|
|
372
|
+
* LOW = 0.01% (100)
|
|
373
|
+
* HIGH = 1% (10000)
|
|
374
|
+
*/
|
|
375
|
+
export function lpFeeProfileToV3Fee(profile) {
|
|
376
|
+
switch (profile) {
|
|
377
|
+
case 1: return 100; // 0.01%
|
|
378
|
+
case 2: return 10000; // 1%
|
|
379
|
+
case 0:
|
|
380
|
+
default:
|
|
381
|
+
return 2500; // 0.25%
|
|
382
|
+
}
|
|
383
|
+
}
|
|
346
384
|
/**
|
|
347
385
|
* 创建 Portal 查询器
|
|
348
386
|
*/
|
package/dist/xlayer/types.d.ts
CHANGED
|
@@ -203,7 +203,7 @@ export interface BundleBuySellParams {
|
|
|
203
203
|
tokenAddress: string;
|
|
204
204
|
/** Owner 私钥列表 */
|
|
205
205
|
privateKeys: string[];
|
|
206
|
-
/** 每个 owner
|
|
206
|
+
/** 每个 owner 的買入金额(OKB 或 quoteToken,取决于 quoteToken 参数) */
|
|
207
207
|
buyAmounts: string[];
|
|
208
208
|
/** 买入使用的代币地址(零地址表示使用原生代币 OKB,非零地址表示使用 ERC20 代币如 USDC) */
|
|
209
209
|
quoteToken?: string;
|
|
@@ -217,6 +217,10 @@ export interface BundleBuySellParams {
|
|
|
217
217
|
withdrawReserve?: string;
|
|
218
218
|
/** 配置覆盖 */
|
|
219
219
|
config?: Partial<XLayerConfig>;
|
|
220
|
+
/** LP 费率档位 (V3 专用): 0=STANDARD, 1=LOW, 2=HIGH */
|
|
221
|
+
lpFeeProfile?: number;
|
|
222
|
+
/** DEX 类型: 'V2' | 'V3' */
|
|
223
|
+
dexType?: 'V2' | 'V3';
|
|
220
224
|
}
|
|
221
225
|
/**
|
|
222
226
|
* 捆绑发射签名参数
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "four-flap-meme-sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.76",
|
|
4
4
|
"description": "SDK for Flap bonding curve and four.meme TokenManager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.6.3"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
-
* 用于将签名交易用服务器公钥加密
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
7
|
-
*
|
|
8
|
-
* @param signedTransactions 签名后的交易数组
|
|
9
|
-
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
10
|
-
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
11
|
-
*/
|
|
12
|
-
export declare function encryptWithPublicKey(signedTransactions: string[], publicKeyBase64: string): Promise<string>;
|
|
13
|
-
/**
|
|
14
|
-
* 验证公钥格式(Base64)
|
|
15
|
-
*/
|
|
16
|
-
export declare function validatePublicKey(publicKeyBase64: string): boolean;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
-
* 用于将签名交易用服务器公钥加密
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* 获取全局 crypto 对象(最简单直接的方式)
|
|
7
|
-
*/
|
|
8
|
-
function getCryptoAPI() {
|
|
9
|
-
// 尝试所有可能的全局对象,优先浏览器环境
|
|
10
|
-
const cryptoObj = (typeof window !== 'undefined' && window.crypto) ||
|
|
11
|
-
(typeof self !== 'undefined' && self.crypto) ||
|
|
12
|
-
(typeof global !== 'undefined' && global.crypto) ||
|
|
13
|
-
(typeof globalThis !== 'undefined' && globalThis.crypto);
|
|
14
|
-
if (!cryptoObj) {
|
|
15
|
-
const env = typeof window !== 'undefined' ? 'Browser' : 'Node.js';
|
|
16
|
-
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
17
|
-
throw new Error(`❌ Crypto API 不可用。环境: ${env}, 协议: ${protocol}. ` +
|
|
18
|
-
'请确保在 HTTPS 或 localhost 下运行');
|
|
19
|
-
}
|
|
20
|
-
return cryptoObj;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 获取 SubtleCrypto(用于加密操作)
|
|
24
|
-
*/
|
|
25
|
-
function getSubtleCrypto() {
|
|
26
|
-
const crypto = getCryptoAPI();
|
|
27
|
-
if (!crypto.subtle) {
|
|
28
|
-
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
29
|
-
const hostname = typeof location !== 'undefined' ? location.hostname : 'unknown';
|
|
30
|
-
throw new Error(`❌ SubtleCrypto API 不可用。协议: ${protocol}, 主机: ${hostname}. ` +
|
|
31
|
-
'请确保:1) 使用 HTTPS (或 localhost);2) 浏览器支持 Web Crypto API;' +
|
|
32
|
-
'3) 不在无痕/隐私浏览模式下');
|
|
33
|
-
}
|
|
34
|
-
return crypto.subtle;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Base64 转 ArrayBuffer(优先使用浏览器 API)
|
|
38
|
-
*/
|
|
39
|
-
function base64ToArrayBuffer(base64) {
|
|
40
|
-
// 浏览器环境(优先)
|
|
41
|
-
if (typeof atob !== 'undefined') {
|
|
42
|
-
const binaryString = atob(base64);
|
|
43
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
44
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
45
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
46
|
-
}
|
|
47
|
-
return bytes.buffer;
|
|
48
|
-
}
|
|
49
|
-
// Node.js 环境(fallback)
|
|
50
|
-
if (typeof Buffer !== 'undefined') {
|
|
51
|
-
return Buffer.from(base64, 'base64').buffer;
|
|
52
|
-
}
|
|
53
|
-
throw new Error('❌ Base64 解码不可用');
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* ArrayBuffer 转 Base64(优先使用浏览器 API)
|
|
57
|
-
*/
|
|
58
|
-
function arrayBufferToBase64(buffer) {
|
|
59
|
-
// 浏览器环境(优先)
|
|
60
|
-
if (typeof btoa !== 'undefined') {
|
|
61
|
-
const bytes = new Uint8Array(buffer);
|
|
62
|
-
let binary = '';
|
|
63
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
64
|
-
binary += String.fromCharCode(bytes[i]);
|
|
65
|
-
}
|
|
66
|
-
return btoa(binary);
|
|
67
|
-
}
|
|
68
|
-
// Node.js 环境(fallback)
|
|
69
|
-
if (typeof Buffer !== 'undefined') {
|
|
70
|
-
return Buffer.from(buffer).toString('base64');
|
|
71
|
-
}
|
|
72
|
-
throw new Error('❌ Base64 编码不可用');
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* 生成随机 Hex 字符串
|
|
76
|
-
*/
|
|
77
|
-
function randomHex(length) {
|
|
78
|
-
const crypto = getCryptoAPI();
|
|
79
|
-
const array = new Uint8Array(length);
|
|
80
|
-
crypto.getRandomValues(array);
|
|
81
|
-
return Array.from(array)
|
|
82
|
-
.map(b => b.toString(16).padStart(2, '0'))
|
|
83
|
-
.join('');
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
87
|
-
*
|
|
88
|
-
* @param signedTransactions 签名后的交易数组
|
|
89
|
-
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
90
|
-
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
91
|
-
*/
|
|
92
|
-
export async function encryptWithPublicKey(signedTransactions, publicKeyBase64) {
|
|
93
|
-
try {
|
|
94
|
-
// 0. 获取 SubtleCrypto 和 Crypto API
|
|
95
|
-
const subtle = getSubtleCrypto();
|
|
96
|
-
const crypto = getCryptoAPI();
|
|
97
|
-
// 1. 准备数据
|
|
98
|
-
const payload = {
|
|
99
|
-
signedTransactions,
|
|
100
|
-
timestamp: Date.now(),
|
|
101
|
-
nonce: randomHex(8)
|
|
102
|
-
};
|
|
103
|
-
const plaintext = JSON.stringify(payload);
|
|
104
|
-
// 2. 生成临时 ECDH 密钥对
|
|
105
|
-
const ephemeralKeyPair = await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveKey']);
|
|
106
|
-
// 3. 导入服务器公钥
|
|
107
|
-
const publicKeyBuffer = base64ToArrayBuffer(publicKeyBase64);
|
|
108
|
-
const publicKey = await subtle.importKey('raw', publicKeyBuffer, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
|
|
109
|
-
// 4. 派生共享密钥(AES-256)
|
|
110
|
-
const sharedKey = await subtle.deriveKey({ name: 'ECDH', public: publicKey }, ephemeralKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
|
|
111
|
-
// 5. AES-GCM 加密
|
|
112
|
-
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
113
|
-
const encrypted = await subtle.encrypt({ name: 'AES-GCM', iv }, sharedKey, new TextEncoder().encode(plaintext));
|
|
114
|
-
// 6. 导出临时公钥
|
|
115
|
-
const ephemeralPublicKeyRaw = await subtle.exportKey('raw', ephemeralKeyPair.publicKey);
|
|
116
|
-
// 7. 返回加密包(JSON 格式)
|
|
117
|
-
return JSON.stringify({
|
|
118
|
-
e: arrayBufferToBase64(ephemeralPublicKeyRaw), // 临时公钥
|
|
119
|
-
i: arrayBufferToBase64(iv.buffer), // IV
|
|
120
|
-
d: arrayBufferToBase64(encrypted) // 密文
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
throw new Error(`加密失败: ${error?.message || String(error)}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* 验证公钥格式(Base64)
|
|
129
|
-
*/
|
|
130
|
-
export function validatePublicKey(publicKeyBase64) {
|
|
131
|
-
try {
|
|
132
|
-
if (!publicKeyBase64)
|
|
133
|
-
return false;
|
|
134
|
-
// Base64 字符集验证
|
|
135
|
-
if (!/^[A-Za-z0-9+/=]+$/.test(publicKeyBase64))
|
|
136
|
-
return false;
|
|
137
|
-
// ECDH P-256 公钥固定长度 65 字节(未压缩)
|
|
138
|
-
// Base64 编码后约 88 字符
|
|
139
|
-
if (publicKeyBase64.length < 80 || publicKeyBase64.length > 100)
|
|
140
|
-
return false;
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
}
|