@clonegod/ttd-bsc-send-tx 1.0.0 → 1.0.1

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.
@@ -22,7 +22,9 @@ class _48ClubTrade {
22
22
  }
23
23
  sendPrivateTransactionWith48SP(signedTx) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
+ console.log(`[48Club-HTTP] sendPrivateTransaction: tx type=${typeof signedTx}, length=${signedTx === null || signedTx === void 0 ? void 0 : signedTx.length}, prefix=${signedTx === null || signedTx === void 0 ? void 0 : signedTx.substring(0, 10)}`);
25
26
  const spSign = yield this.get48SPSignature([signedTx]);
27
+ console.log(`[48Club-HTTP] spSign type=${typeof spSign}, length=${spSign === null || spSign === void 0 ? void 0 : spSign.length}, value=${spSign === null || spSign === void 0 ? void 0 : spSign.substring(0, 20)}...`);
26
28
  const response = yield axios_1.default.post(this.rpcUrl, {
27
29
  jsonrpc: "2.0", id: 1,
28
30
  method: "eth_sendPrivateTransaction",
@@ -38,8 +40,10 @@ class _48ClubTrade {
38
40
  }
39
41
  sendBundle(params) {
40
42
  return __awaiter(this, void 0, void 0, function* () {
43
+ console.log(`[48Club-HTTP] sendBundle: txs count=${params.txs.length}, lengths=${params.txs.map(t => t === null || t === void 0 ? void 0 : t.length).join(',')}`);
41
44
  const currentTimestamp = Math.floor(Date.now() / 1000);
42
45
  const spSign = yield this.get48SPSignature(params.txs);
46
+ console.log(`[48Club-HTTP] bundle spSign type=${typeof spSign}, length=${spSign === null || spSign === void 0 ? void 0 : spSign.length}`);
43
47
  const response = yield axios_1.default.post(this.rpcUrl, {
44
48
  jsonrpc: "2.0", id: 1,
45
49
  method: "eth_sendBundle",
@@ -1,23 +1,53 @@
1
1
  "use strict";
2
+ var _a, _b, _c;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.SoulPointSignature = void 0;
4
5
  const ethers_1 = require("ethers");
6
+ const _ethers = ethers_1.ethers;
7
+ const keccak256 = ((_a = _ethers.utils) === null || _a === void 0 ? void 0 : _a.keccak256) || _ethers.keccak256;
8
+ const concat = ((_b = _ethers.utils) === null || _b === void 0 ? void 0 : _b.concat) || _ethers.concat;
9
+ const recoverAddress = ((_c = _ethers.utils) === null || _c === void 0 ? void 0 : _c.recoverAddress) || _ethers.recoverAddress;
5
10
  class SoulPointSignature {
6
11
  static generate48SPSignature(privateKey, txs) {
12
+ var _a, _b, _c, _d, _e;
13
+ console.log(`[48SP] ethers version: ${ethers_1.ethers.version}`);
14
+ console.log(`[48SP] keccak256 source: ${((_a = _ethers.utils) === null || _a === void 0 ? void 0 : _a.keccak256) ? 'v5(utils)' : 'v6(top-level)'}`);
15
+ console.log(`[48SP] txs count: ${txs.length}, lengths: ${txs.map(t => t.length).join(',')}`);
7
16
  const wallet = new ethers_1.ethers.Wallet(privateKey);
8
- const txHashes = txs.map(tx => tx.startsWith('0x') ? ethers_1.ethers.utils.keccak256(tx) : tx);
9
- const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
10
- const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
11
- const signature = wallet._signingKey().signDigest(messageHash);
12
- return signature.compact;
17
+ console.log(`[48SP] wallet._signingKey: ${typeof wallet._signingKey}, wallet.signingKey: ${typeof wallet.signingKey}`);
18
+ try {
19
+ const txHashes = txs.map(tx => tx.startsWith('0x') ? keccak256(tx) : tx);
20
+ console.log(`[48SP] txHashes: ${txHashes.map(h => h.substring(0, 20) + '...').join(', ')}`);
21
+ const concatenatedHashes = concat(txHashes);
22
+ console.log(`[48SP] concatenated type: ${typeof concatenatedHashes}, isUint8Array: ${concatenatedHashes instanceof Uint8Array}`);
23
+ const messageHash = keccak256(concatenatedHashes);
24
+ console.log(`[48SP] messageHash: ${messageHash}`);
25
+ if (typeof wallet._signingKey === 'function') {
26
+ console.log(`[48SP] using v5 signing path`);
27
+ const signature = wallet._signingKey().signDigest(messageHash);
28
+ console.log(`[48SP] signature.compact: ${(_b = signature.compact) === null || _b === void 0 ? void 0 : _b.substring(0, 20)}..., length: ${(_c = signature.compact) === null || _c === void 0 ? void 0 : _c.length}`);
29
+ return signature.compact;
30
+ }
31
+ else {
32
+ console.log(`[48SP] using v6 signing path`);
33
+ const signature = wallet.signingKey.sign(messageHash);
34
+ console.log(`[48SP] signature.compactSerialized: ${(_d = signature.compactSerialized) === null || _d === void 0 ? void 0 : _d.substring(0, 20)}..., length: ${(_e = signature.compactSerialized) === null || _e === void 0 ? void 0 : _e.length}`);
35
+ return signature.compactSerialized;
36
+ }
37
+ }
38
+ catch (err) {
39
+ console.error(`[48SP] ERROR in generate48SPSignature: ${err.message}`);
40
+ console.error(`[48SP] stack: ${err.stack}`);
41
+ throw err;
42
+ }
13
43
  }
14
44
  static verify48SPSignature(signature, txs, expectedSignerAddress) {
15
45
  try {
16
- const txHashes = txs.map(tx => tx.startsWith('0x') ? ethers_1.ethers.utils.keccak256(tx) : tx);
17
- const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
18
- const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
19
- const recoveredAddress = ethers_1.ethers.utils.recoverAddress(messageHash, signature);
20
- return recoveredAddress.toLowerCase() === expectedSignerAddress.toLowerCase();
46
+ const txHashes = txs.map(tx => tx.startsWith('0x') ? keccak256(tx) : tx);
47
+ const concatenatedHashes = concat(txHashes);
48
+ const messageHash = keccak256(concatenatedHashes);
49
+ const recoveredAddr = recoverAddress(messageHash, signature);
50
+ return recoveredAddr.toLowerCase() === expectedSignerAddress.toLowerCase();
21
51
  }
22
52
  catch (_a) {
23
53
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-send-tx",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "BSC 交易发送模块(HTTP直发 + WS bundle 转发)",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,9 @@ export class _48ClubTrade {
14
14
  }
15
15
 
16
16
  async sendPrivateTransactionWith48SP(signedTx: string): Promise<string> {
17
+ console.log(`[48Club-HTTP] sendPrivateTransaction: tx type=${typeof signedTx}, length=${signedTx?.length}, prefix=${signedTx?.substring(0, 10)}`);
17
18
  const spSign = await this.get48SPSignature([signedTx]);
19
+ console.log(`[48Club-HTTP] spSign type=${typeof spSign}, length=${spSign?.length}, value=${spSign?.substring(0, 20)}...`);
18
20
 
19
21
  const response = await axios.post(this.rpcUrl, {
20
22
  jsonrpc: "2.0", id: 1,
@@ -31,8 +33,10 @@ export class _48ClubTrade {
31
33
  }
32
34
 
33
35
  async sendBundle(params: { txs: string[] }): Promise<string> {
36
+ console.log(`[48Club-HTTP] sendBundle: txs count=${params.txs.length}, lengths=${params.txs.map(t => t?.length).join(',')}`);
34
37
  const currentTimestamp = Math.floor(Date.now() / 1000);
35
38
  const spSign = await this.get48SPSignature(params.txs);
39
+ console.log(`[48Club-HTTP] bundle spSign type=${typeof spSign}, length=${spSign?.length}`);
36
40
 
37
41
  const response = await axios.post(this.rpcUrl, {
38
42
  jsonrpc: "2.0", id: 1,
@@ -1,26 +1,62 @@
1
1
  import { ethers } from 'ethers';
2
2
 
3
+ const _ethers = ethers as any;
4
+
5
+ // ethers v5/v6 兼容
6
+ const keccak256 = _ethers.utils?.keccak256 || _ethers.keccak256;
7
+ const concat = _ethers.utils?.concat || _ethers.concat;
8
+ const recoverAddress = _ethers.utils?.recoverAddress || _ethers.recoverAddress;
9
+
3
10
  /**
4
11
  * 48 SoulPoint 签名
5
12
  * https://docs.48.club/puissant-builder/48-soulpoint-benefits
6
13
  */
7
14
  export class SoulPointSignature {
8
15
  static generate48SPSignature(privateKey: string, txs: string[]): string {
16
+ console.log(`[48SP] ethers version: ${(ethers as any).version}`);
17
+ console.log(`[48SP] keccak256 source: ${_ethers.utils?.keccak256 ? 'v5(utils)' : 'v6(top-level)'}`);
18
+ console.log(`[48SP] txs count: ${txs.length}, lengths: ${txs.map(t => t.length).join(',')}`);
19
+
9
20
  const wallet = new ethers.Wallet(privateKey);
10
- const txHashes = txs.map(tx => tx.startsWith('0x') ? ethers.utils.keccak256(tx) : tx);
11
- const concatenatedHashes = ethers.utils.concat(txHashes);
12
- const messageHash = ethers.utils.keccak256(concatenatedHashes);
13
- const signature = wallet._signingKey().signDigest(messageHash);
14
- return signature.compact;
21
+ console.log(`[48SP] wallet._signingKey: ${typeof (wallet as any)._signingKey}, wallet.signingKey: ${typeof (wallet as any).signingKey}`);
22
+
23
+ try {
24
+ const txHashes = txs.map(tx => tx.startsWith('0x') ? keccak256(tx) : tx);
25
+ console.log(`[48SP] txHashes: ${txHashes.map(h => h.substring(0, 20) + '...').join(', ')}`);
26
+
27
+ const concatenatedHashes = concat(txHashes);
28
+ console.log(`[48SP] concatenated type: ${typeof concatenatedHashes}, isUint8Array: ${concatenatedHashes instanceof Uint8Array}`);
29
+
30
+ const messageHash = keccak256(concatenatedHashes);
31
+ console.log(`[48SP] messageHash: ${messageHash}`);
32
+
33
+ // v5: wallet._signingKey().signDigest(hash).compact
34
+ // v6: wallet.signingKey.sign(hash).compactSerialized
35
+ if (typeof (wallet as any)._signingKey === 'function') {
36
+ console.log(`[48SP] using v5 signing path`);
37
+ const signature = (wallet as any)._signingKey().signDigest(messageHash);
38
+ console.log(`[48SP] signature.compact: ${signature.compact?.substring(0, 20)}..., length: ${signature.compact?.length}`);
39
+ return signature.compact;
40
+ } else {
41
+ console.log(`[48SP] using v6 signing path`);
42
+ const signature = (wallet as any).signingKey.sign(messageHash);
43
+ console.log(`[48SP] signature.compactSerialized: ${signature.compactSerialized?.substring(0, 20)}..., length: ${signature.compactSerialized?.length}`);
44
+ return signature.compactSerialized;
45
+ }
46
+ } catch (err: any) {
47
+ console.error(`[48SP] ERROR in generate48SPSignature: ${err.message}`);
48
+ console.error(`[48SP] stack: ${err.stack}`);
49
+ throw err;
50
+ }
15
51
  }
16
52
 
17
53
  static verify48SPSignature(signature: string, txs: string[], expectedSignerAddress: string): boolean {
18
54
  try {
19
- const txHashes = txs.map(tx => tx.startsWith('0x') ? ethers.utils.keccak256(tx) : tx);
20
- const concatenatedHashes = ethers.utils.concat(txHashes);
21
- const messageHash = ethers.utils.keccak256(concatenatedHashes);
22
- const recoveredAddress = ethers.utils.recoverAddress(messageHash, signature);
23
- return recoveredAddress.toLowerCase() === expectedSignerAddress.toLowerCase();
55
+ const txHashes = txs.map(tx => tx.startsWith('0x') ? keccak256(tx) : tx);
56
+ const concatenatedHashes = concat(txHashes);
57
+ const messageHash = keccak256(concatenatedHashes);
58
+ const recoveredAddr = recoverAddress(messageHash, signature);
59
+ return recoveredAddr.toLowerCase() === expectedSignerAddress.toLowerCase();
24
60
  } catch {
25
61
  return false;
26
62
  }