@clonegod/ttd-bsc-common 1.0.75 → 1.0.77

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.
@@ -1,5 +1,7 @@
1
1
  export declare class SoulPointSignature {
2
2
  static generate48SPSignature(privateKey: string, txs: string[]): string;
3
+ static generate48SPSignature_ethersV5(privateKey: string, txs: string[]): string;
4
+ static generate48SPSignature_ethersV6(privateKey: string, txs: string[]): string;
3
5
  static verify48SPSignature(signature: string, txs: string[], expectedSignerAddress: string): boolean;
4
6
  static getSignerAddress(signedTx: string): string;
5
7
  static testSignatureVerification(): Promise<void>;
@@ -13,36 +13,53 @@ exports.SoulPointSignature = void 0;
13
13
  const ethers_1 = require("ethers");
14
14
  class SoulPointSignature {
15
15
  static generate48SPSignature(privateKey, txs) {
16
- var _a;
16
+ try {
17
+ return this.generate48SPSignature_ethersV6(privateKey, txs);
18
+ }
19
+ catch (error) {
20
+ return this.generate48SPSignature_ethersV5(privateKey, txs);
21
+ }
22
+ }
23
+ static generate48SPSignature_ethersV5(privateKey, txs) {
17
24
  try {
18
25
  const wallet = new ethers_1.ethers.Wallet(privateKey);
19
- const keccak256 = ((_a = ethers_1.ethers.utils) === null || _a === void 0 ? void 0 : _a.keccak256) || ethers_1.ethers.keccak256;
20
26
  const txHashes = txs.map(tx => {
21
27
  if (tx.startsWith('0x')) {
22
- return keccak256(tx);
28
+ return ethers_1.ethers.utils.keccak256(tx);
23
29
  }
24
30
  return tx;
25
31
  });
26
- const concatenatedHashes = ethers_1.ethers.utils
27
- ? ethers_1.ethers.utils.concat(txHashes)
28
- : ethers_1.ethers.concat(txHashes);
29
- const messageHash = ethers_1.ethers.utils
30
- ? ethers_1.ethers.utils.keccak256(concatenatedHashes)
31
- : ethers_1.ethers.keccak256(concatenatedHashes);
32
- let signature;
33
- try {
34
- signature = wallet._signingKey().signDigest(messageHash);
35
- }
36
- catch (error) {
37
- signature = wallet.signingKey.signDigest(messageHash);
38
- }
32
+ const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
33
+ const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
34
+ const signature = wallet._signingKey().signDigest(messageHash);
39
35
  const r = signature.r.slice(2).padStart(64, '0');
40
36
  const s = signature.s.slice(2).padStart(64, '0');
41
37
  const v = signature.recoveryParam.toString(16).padStart(2, '0');
42
38
  return '0x' + r + s + v;
43
39
  }
44
40
  catch (error) {
45
- throw new Error(`生成48 SoulPoint签名失败: ${error}`);
41
+ throw new Error(`生成48 SoulPoint签名失败(ethersV5): ${error}`);
42
+ }
43
+ }
44
+ static generate48SPSignature_ethersV6(privateKey, txs) {
45
+ try {
46
+ const wallet = new ethers_1.ethers.Wallet(privateKey);
47
+ const txHashes = txs.map(tx => {
48
+ if (tx.startsWith('0x')) {
49
+ return ethers_1.ethers.keccak256(tx);
50
+ }
51
+ return tx;
52
+ });
53
+ const concatenatedHashes = ethers_1.ethers.concat(txHashes);
54
+ const messageHash = ethers_1.ethers.keccak256(concatenatedHashes);
55
+ const signature = wallet.signingKey.sign(messageHash);
56
+ const r = signature.r.slice(2).padStart(64, '0');
57
+ const s = signature.s.slice(2).padStart(64, '0');
58
+ const v = (signature.v !== undefined ? signature.v : signature.recoveryParam || 0).toString(16).padStart(2, '0');
59
+ return '0x' + r + s + v;
60
+ }
61
+ catch (error) {
62
+ throw new Error(`生成48 SoulPoint签名失败(ethersV6): ${error}`);
46
63
  }
47
64
  }
48
65
  static verify48SPSignature(signature, txs, expectedSignerAddress) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "1.0.75",
3
+ "version": "1.0.77",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",