four-flap-meme-sdk 1.2.32 → 1.2.34
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/flap/portal-bundle-merkle/core.d.ts +6 -1
- package/dist/flap/portal-bundle-merkle/core.js +42 -1
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
- package/dist/flap/portal-bundle-merkle/encryption.js +51 -0
- package/dist/flap/portal-bundle-merkle/index.d.ts +1 -1
- package/dist/flap/portal-bundle-merkle/index.js +3 -1
- package/dist/flap/portal-bundle-merkle/types.d.ts +27 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { FlapCreateWithBundleBuySignParams, FlapCreateWithBundleBuyMerkleResult, FlapBatchBuySignParams, FlapBatchBuyMerkleResult, FlapBatchSellSignParams, FlapBatchSellMerkleResult } from './types.js';
|
|
1
|
+
import { FlapCreateWithBundleBuySignParams, FlapCreateWithBundleBuyMerkleResult, FlapBatchBuySignParams, FlapBatchBuyMerkleResult, FlapBatchSellSignParams, FlapBatchSellMerkleResult, FlapBatchBuyEncryptedParams, FlapBatchBuyEncryptedResult } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Flap Protocol: 创建代币 + 捆绑购买(仅签名版本 - 不依赖 Merkle)
|
|
4
4
|
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
5
5
|
*/
|
|
6
6
|
export declare function createTokenWithBundleBuyMerkle(params: FlapCreateWithBundleBuySignParams): Promise<FlapCreateWithBundleBuyMerkleResult>;
|
|
7
|
+
/**
|
|
8
|
+
* Flap Protocol: 批量购买(加密版本 - 用服务器公钥加密)
|
|
9
|
+
* ✅ 返回加密的签名交易,只有服务器能解密
|
|
10
|
+
*/
|
|
11
|
+
export declare function batchBuyWithBundleMerkleEncrypted(params: FlapBatchBuyEncryptedParams): Promise<FlapBatchBuyEncryptedResult>;
|
|
7
12
|
/**
|
|
8
13
|
* Flap Protocol: 批量购买(仅签名版本 - 不依赖 Merkle)
|
|
9
14
|
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers, Wallet } from 'ethers';
|
|
2
|
-
|
|
2
|
+
import { encryptWithPublicKey, validatePublicKey } from './encryption.js';
|
|
3
3
|
import { NonceManager, getOptimizedGasPrice } from '../../utils/bundle-helpers.js';
|
|
4
4
|
import { FLAP_PORTAL_ADDRESSES, FLAP_ORIGINAL_PORTAL_ADDRESSES } from '../constants.js';
|
|
5
5
|
import { CHAIN_ID_MAP, PORTAL_ABI, getErrorMessage, getTxType, getGasPriceConfig, shouldExtractProfit, calculateProfit } from './config.js';
|
|
@@ -196,6 +196,47 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
196
196
|
} : undefined
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Flap Protocol: 批量购买(加密版本 - 用服务器公钥加密)
|
|
201
|
+
* ✅ 返回加密的签名交易,只有服务器能解密
|
|
202
|
+
*/
|
|
203
|
+
export async function batchBuyWithBundleMerkleEncrypted(params) {
|
|
204
|
+
const { sessionId, publicKey, chain, privateKeys, buyAmounts, tokenAddress, config } = params;
|
|
205
|
+
// ✅ 验证必须有会话ID和公钥
|
|
206
|
+
if (!sessionId) {
|
|
207
|
+
throw new Error('❌ 缺少会话ID (sessionId)');
|
|
208
|
+
}
|
|
209
|
+
if (!publicKey) {
|
|
210
|
+
throw new Error('❌ 缺少服务器公钥 (publicKey)');
|
|
211
|
+
}
|
|
212
|
+
// 验证公钥格式
|
|
213
|
+
if (!validatePublicKey(publicKey)) {
|
|
214
|
+
throw new Error('❌ 无效的公钥格式');
|
|
215
|
+
}
|
|
216
|
+
// 1. 调用原有的签名逻辑
|
|
217
|
+
const signResult = await batchBuyWithBundleMerkle({
|
|
218
|
+
chain,
|
|
219
|
+
privateKeys,
|
|
220
|
+
buyAmounts,
|
|
221
|
+
tokenAddress,
|
|
222
|
+
config
|
|
223
|
+
});
|
|
224
|
+
console.log('✅ 交易签名完成,准备加密...');
|
|
225
|
+
// 2. 用服务器公钥加密签名交易
|
|
226
|
+
const encryptedPayload = encryptWithPublicKey(signResult.signedTransactions, publicKey);
|
|
227
|
+
console.log('✅ 已用服务器公钥加密,前端无法解密');
|
|
228
|
+
// 3. 返回加密结果
|
|
229
|
+
return {
|
|
230
|
+
sessionId,
|
|
231
|
+
encryptedPayload,
|
|
232
|
+
metadata: signResult.metadata ? {
|
|
233
|
+
totalBuyAmount: signResult.metadata.totalBuyAmount,
|
|
234
|
+
profitAmount: signResult.metadata.profitAmount,
|
|
235
|
+
profitRecipient: signResult.metadata.profitRecipient,
|
|
236
|
+
buyerCount: signResult.metadata.buyerCount
|
|
237
|
+
} : undefined
|
|
238
|
+
};
|
|
239
|
+
}
|
|
199
240
|
/**
|
|
200
241
|
* Flap Protocol: 批量购买(仅签名版本 - 不依赖 Merkle)
|
|
201
242
|
* ✅ 精简版:只负责签名交易,不提交到 Merkle
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSA 加密工具
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 用服务器公钥加密签名交易
|
|
7
|
+
*
|
|
8
|
+
* @param signedTransactions 签名后的交易数组
|
|
9
|
+
* @param publicKeyPem 服务器提供的公钥(PEM格式)
|
|
10
|
+
* @returns Base64 编码的密文
|
|
11
|
+
*/
|
|
12
|
+
export declare function encryptWithPublicKey(signedTransactions: string[], publicKeyPem: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 解析公钥(验证格式)
|
|
15
|
+
*/
|
|
16
|
+
export declare function validatePublicKey(publicKeyPem: string): boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSA 加密工具
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
import { publicEncrypt, constants, randomBytes } from 'crypto';
|
|
6
|
+
/**
|
|
7
|
+
* 用服务器公钥加密签名交易
|
|
8
|
+
*
|
|
9
|
+
* @param signedTransactions 签名后的交易数组
|
|
10
|
+
* @param publicKeyPem 服务器提供的公钥(PEM格式)
|
|
11
|
+
* @returns Base64 编码的密文
|
|
12
|
+
*/
|
|
13
|
+
export function encryptWithPublicKey(signedTransactions, publicKeyPem) {
|
|
14
|
+
// 1. 准备数据(包含签名交易和元数据)
|
|
15
|
+
const payload = {
|
|
16
|
+
signedTransactions,
|
|
17
|
+
timestamp: Date.now(),
|
|
18
|
+
nonce: randomBytes(8).toString('hex')
|
|
19
|
+
};
|
|
20
|
+
const plaintext = JSON.stringify(payload);
|
|
21
|
+
// 2. 用服务器公钥加密(RSA-OAEP)
|
|
22
|
+
try {
|
|
23
|
+
const encrypted = publicEncrypt({
|
|
24
|
+
key: publicKeyPem,
|
|
25
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
26
|
+
oaepHash: 'sha256'
|
|
27
|
+
}, Buffer.from(plaintext, 'utf-8'));
|
|
28
|
+
// 3. 返回 Base64 编码的密文
|
|
29
|
+
return encrypted.toString('base64');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new Error(`加密失败: ${error?.message || String(error)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 解析公钥(验证格式)
|
|
37
|
+
*/
|
|
38
|
+
export function validatePublicKey(publicKeyPem) {
|
|
39
|
+
try {
|
|
40
|
+
if (!publicKeyPem)
|
|
41
|
+
return false;
|
|
42
|
+
if (!publicKeyPem.includes('-----BEGIN PUBLIC KEY-----'))
|
|
43
|
+
return false;
|
|
44
|
+
if (!publicKeyPem.includes('-----END PUBLIC KEY-----'))
|
|
45
|
+
return false;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from './config.js';
|
|
6
6
|
export * from './types.js';
|
|
7
|
-
export { createTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle, batchSellWithBundleMerkle } from './core.js';
|
|
7
|
+
export { createTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle, batchSellWithBundleMerkle, batchBuyWithBundleMerkleEncrypted } from './core.js';
|
|
8
8
|
export { flapBundleBuyFirstMerkle, type FlapChain, type FlapBuyFirstSignConfig, type FlapBuyFirstConfig, type FlapBundleBuyFirstSignParams, type FlapBundleBuyFirstParams, type FlapBuyFirstResult } from './swap-buy-first.js';
|
|
9
9
|
export { flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle } from './private.js';
|
|
10
10
|
export { pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch } from './pancake-proxy.js';
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
export * from './config.js';
|
|
7
7
|
export * from './types.js';
|
|
8
8
|
// 核心交易方法(使用 Flap Portal)
|
|
9
|
-
export { createTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle, batchSellWithBundleMerkle
|
|
9
|
+
export { createTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle, batchSellWithBundleMerkle,
|
|
10
|
+
// ✅ 加密版本(用服务器公钥加密)
|
|
11
|
+
batchBuyWithBundleMerkleEncrypted } from './core.js';
|
|
10
12
|
// BuyFirst 换手方法
|
|
11
13
|
export { flapBundleBuyFirstMerkle } from './swap-buy-first.js';
|
|
12
14
|
// 私有交易方法(使用 Flap Portal)
|
|
@@ -278,3 +278,30 @@ export type PancakeProxyApprovalBatchResult = {
|
|
|
278
278
|
bundleHash?: string;
|
|
279
279
|
message: string;
|
|
280
280
|
};
|
|
281
|
+
/**
|
|
282
|
+
* 批量买入参数(加密版)
|
|
283
|
+
* 使用服务器提供的公钥加密签名交易
|
|
284
|
+
*/
|
|
285
|
+
export type FlapBatchBuyEncryptedParams = {
|
|
286
|
+
sessionId: string;
|
|
287
|
+
publicKey: string;
|
|
288
|
+
chain: FlapChainForMerkleBundle;
|
|
289
|
+
privateKeys: string[];
|
|
290
|
+
buyAmounts: string[];
|
|
291
|
+
tokenAddress: string;
|
|
292
|
+
config: FlapSignConfig;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* 批量买入结果(加密版)
|
|
296
|
+
* 返回加密的签名交易,只有服务器能解密
|
|
297
|
+
*/
|
|
298
|
+
export type FlapBatchBuyEncryptedResult = {
|
|
299
|
+
sessionId: string;
|
|
300
|
+
encryptedPayload: string;
|
|
301
|
+
metadata?: {
|
|
302
|
+
totalBuyAmount: string;
|
|
303
|
+
profitAmount?: string;
|
|
304
|
+
profitRecipient?: string;
|
|
305
|
+
buyerCount: number;
|
|
306
|
+
};
|
|
307
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export { createTokenWithBundleBuy as fourCreateTokenWithBundleBuy, batchBuyWithB
|
|
|
25
25
|
export { createTokenWithBundleBuy as flapCreateTokenWithBundleBuy, batchBuyWithBundle as flapBatchBuyWithBundle, batchSellWithBundle as flapBatchSellWithBundle, type FlapBundleConfig, type FlapChainForBundle, type FlapCreateWithBundleBuyParams, type FlapCreateWithBundleBuyResult, type FlapBatchBuyParams, type FlapBatchBuyResult, type FlapBatchSellParams, type FlapBatchSellResult } from './flap/portal-bundle.js';
|
|
26
26
|
export { fourPrivateBuy, fourPrivateSell, fourBatchPrivateBuy, fourBatchPrivateSell, type FourPrivateBuyParams, type FourPrivateSellParams, type FourBatchPrivateBuyParams, type FourBatchPrivateSellParams } from './contracts/tm-bundle.js';
|
|
27
27
|
export { flapPrivateBuy, flapPrivateSell, flapBatchPrivateBuy, flapBatchPrivateSell, type FlapPrivateBuyParams, type FlapPrivateSellParams, type FlapBatchPrivateBuyParams, type FlapBatchPrivateSellParams, type FlapBatchPrivateSellResult } from './flap/portal-bundle.js';
|
|
28
|
-
export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch, type FlapBundleMerkleConfig, type FlapSignConfig, type FlapChainForMerkleBundle, type FlapCreateWithBundleBuySignParams, type FlapCreateWithBundleBuyMerkleParams, type FlapCreateWithBundleBuyMerkleResult, type FlapBatchBuySignParams, type FlapBatchBuyMerkleParams, type FlapBatchBuyMerkleResult, type FlapBatchSellSignParams, type FlapBatchSellMerkleParams, type FlapBatchSellMerkleResult, type MerkleTransactionStatus, type MerkleBundleStatus, type FlapPrivateBuyMerkleParams, type FlapPrivateSellMerkleParams, type FlapBatchPrivateBuyMerkleParams, type FlapBatchPrivateSellMerkleParams, type FlapBatchPrivateMerkleResult, type FlapPrivateTransactionResult, type PancakeProxyBatchBuyParams, type PancakeProxyBatchBuyResult, type PancakeProxyBatchSellParams, type PancakeProxyBatchSellResult, type PancakeProxyApprovalParams, type PancakeProxyApprovalBatchParams, type PancakeProxyApprovalBatchResult } from './flap/portal-bundle-merkle/index.js';
|
|
28
|
+
export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, batchBuyWithBundleMerkleEncrypted as flapBatchBuyWithBundleMerkleEncrypted, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch, type FlapBundleMerkleConfig, type FlapSignConfig, type FlapChainForMerkleBundle, type FlapCreateWithBundleBuySignParams, type FlapCreateWithBundleBuyMerkleParams, type FlapCreateWithBundleBuyMerkleResult, type FlapBatchBuySignParams, type FlapBatchBuyMerkleParams, type FlapBatchBuyMerkleResult, type FlapBatchSellSignParams, type FlapBatchSellMerkleParams, type FlapBatchSellMerkleResult, type FlapBatchBuyEncryptedParams, type FlapBatchBuyEncryptedResult, type MerkleTransactionStatus, type MerkleBundleStatus, type FlapPrivateBuyMerkleParams, type FlapPrivateSellMerkleParams, type FlapBatchPrivateBuyMerkleParams, type FlapBatchPrivateSellMerkleParams, type FlapBatchPrivateMerkleResult, type FlapPrivateTransactionResult, type PancakeProxyBatchBuyParams, type PancakeProxyBatchBuyResult, type PancakeProxyBatchSellParams, type PancakeProxyBatchSellResult, type PancakeProxyApprovalParams, type PancakeProxyApprovalBatchParams, type PancakeProxyApprovalBatchResult } from './flap/portal-bundle-merkle/index.js';
|
|
29
29
|
export { createTokenWithBundleBuyMerkle as fourCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as fourBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as fourBatchSellWithBundleMerkle, fourPrivateBuyMerkle, fourPrivateSellMerkle, fourBatchPrivateBuyMerkle, fourBatchPrivateSellMerkle, disperseWithBundleMerkle, sweepWithBundleMerkle, fourPancakeProxyBatchBuyMerkle, fourPancakeProxyBatchSellMerkle, approveFourPancakeProxy, approveFourPancakeProxyBatch, approveFourTokenManagerBatch, submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, type MerkleSubmitConfig, type SubmitBundleResult, type FourBundleMerkleConfig, type FourSignConfig, type FourCreateWithBundleBuySignParams, type FourBatchBuySignParams, type FourBatchSellSignParams, type FourPrivateBuySignParams, type FourPrivateSellSignParams, type FourBatchPrivateBuySignParams, type FourBatchPrivateSellSignParams, type FourPancakeProxyBatchBuySignParams, type FourPancakeProxyBatchSellSignParams, type DisperseSignParams as FourDisperseSignParams, type SweepSignParams as FourSweepSignParams, type FourCreateWithBundleBuyMerkleParams, type FourCreateWithBundleBuyMerkleResult, type FourBatchBuyMerkleParams, type FourBatchBuyMerkleResult, type FourBatchSellMerkleParams, type FourBatchSellMerkleResult, type FourPrivateBuyMerkleParams, type FourPrivateSellMerkleParams, type FourBatchPrivateBuyMerkleParams, type FourBatchPrivateSellMerkleParams, type FourBatchPrivateMerkleResult, type FourPrivateTransactionResult, type DisperseMerkleParams, type DisperseMerkleResult, type SweepMerkleParams, type SweepMerkleResult, type FourPancakeProxyBatchBuyParams, type FourPancakeProxyBatchBuyResult, type FourPancakeProxyBatchSellParams, type FourPancakeProxyBatchSellResult, type FourPancakeProxyApprovalParams, type FourPancakeProxyApprovalBatchParams, type FourPancakeProxyApprovalBatchResult, type ApproveFourTokenManagerBatchParams, type ApproveFourTokenManagerBatchResult } from './contracts/tm-bundle-merkle/index.js';
|
|
30
30
|
export { PinataClient, type PinataConfig } from './flap/pinata.js';
|
|
31
31
|
export { pinFileToIPFSWithJWT, pinImageByPath, pinFileToIPFSWithJWTWeb, pinDataURLWithJWTWeb, dataURLToBlob, type PinataPinResp } from './flap/pinata.js';
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ export { createTokenWithBundleBuy as fourCreateTokenWithBundleBuy, batchBuyWithB
|
|
|
33
33
|
export { createTokenWithBundleBuy as flapCreateTokenWithBundleBuy, batchBuyWithBundle as flapBatchBuyWithBundle, batchSellWithBundle as flapBatchSellWithBundle } from './flap/portal-bundle.js';
|
|
34
34
|
export { fourPrivateBuy, fourPrivateSell, fourBatchPrivateBuy, fourBatchPrivateSell } from './contracts/tm-bundle.js';
|
|
35
35
|
export { flapPrivateBuy, flapPrivateSell, flapBatchPrivateBuy, flapBatchPrivateSell } from './flap/portal-bundle.js';
|
|
36
|
-
export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch } from './flap/portal-bundle-merkle/index.js';
|
|
36
|
+
export { createTokenWithBundleBuyMerkle as flapCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as flapBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as flapBatchSellWithBundleMerkle, batchBuyWithBundleMerkleEncrypted as flapBatchBuyWithBundleMerkleEncrypted, flapPrivateBuyMerkle, flapPrivateSellMerkle, flapBatchPrivateBuyMerkle, flapBatchPrivateSellMerkle, pancakeProxyBatchBuyMerkle, pancakeProxyBatchSellMerkle, approvePancakeProxy, approvePancakeProxyBatch } from './flap/portal-bundle-merkle/index.js';
|
|
37
37
|
export { createTokenWithBundleBuyMerkle as fourCreateTokenWithBundleBuyMerkle, batchBuyWithBundleMerkle as fourBatchBuyWithBundleMerkle, batchSellWithBundleMerkle as fourBatchSellWithBundleMerkle, fourPrivateBuyMerkle, fourPrivateSellMerkle, fourBatchPrivateBuyMerkle, fourBatchPrivateSellMerkle, disperseWithBundleMerkle, sweepWithBundleMerkle, fourPancakeProxyBatchBuyMerkle, fourPancakeProxyBatchSellMerkle, approveFourPancakeProxy, approveFourPancakeProxyBatch, approveFourTokenManagerBatch, submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel } from './contracts/tm-bundle-merkle/index.js';
|
|
38
38
|
export { PinataClient } from './flap/pinata.js';
|
|
39
39
|
export { pinFileToIPFSWithJWT, pinImageByPath, pinFileToIPFSWithJWTWeb, pinDataURLWithJWTWeb, dataURLToBlob } from './flap/pinata.js';
|