@clonegod/ttd-bsc-common 1.0.77 → 1.0.79
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,7 +1,8 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
1
2
|
export declare class SoulPointSignature {
|
|
2
3
|
static generate48SPSignature(privateKey: string, txs: string[]): string;
|
|
3
|
-
static generate48SPSignature_ethersV5(
|
|
4
|
-
static generate48SPSignature_ethersV6(
|
|
4
|
+
static generate48SPSignature_ethersV5(wallet: ethers.Wallet, txs: string[]): string;
|
|
5
|
+
static generate48SPSignature_ethersV6(wallet: ethers.Wallet, txs: string[]): string;
|
|
5
6
|
static verify48SPSignature(signature: string, txs: string[], expectedSignerAddress: string): boolean;
|
|
6
7
|
static getSignerAddress(signedTx: string): string;
|
|
7
8
|
static testSignatureVerification(): Promise<void>;
|
|
@@ -13,16 +13,16 @@ exports.SoulPointSignature = void 0;
|
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
14
|
class SoulPointSignature {
|
|
15
15
|
static generate48SPSignature(privateKey, txs) {
|
|
16
|
+
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
16
17
|
try {
|
|
17
|
-
return this.
|
|
18
|
+
return this.generate48SPSignature_ethersV5(wallet, txs);
|
|
18
19
|
}
|
|
19
20
|
catch (error) {
|
|
20
|
-
return this.
|
|
21
|
+
return this.generate48SPSignature_ethersV6(wallet, txs);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
static generate48SPSignature_ethersV5(
|
|
24
|
+
static generate48SPSignature_ethersV5(wallet, txs) {
|
|
24
25
|
try {
|
|
25
|
-
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
26
26
|
const txHashes = txs.map(tx => {
|
|
27
27
|
if (tx.startsWith('0x')) {
|
|
28
28
|
return ethers_1.ethers.utils.keccak256(tx);
|
|
@@ -41,9 +41,8 @@ class SoulPointSignature {
|
|
|
41
41
|
throw new Error(`生成48 SoulPoint签名失败(ethersV5): ${error}`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
static generate48SPSignature_ethersV6(
|
|
44
|
+
static generate48SPSignature_ethersV6(wallet, txs) {
|
|
45
45
|
try {
|
|
46
|
-
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
47
46
|
const txHashes = txs.map(tx => {
|
|
48
47
|
if (tx.startsWith('0x')) {
|
|
49
48
|
return ethers_1.ethers.keccak256(tx);
|
|
@@ -52,10 +51,23 @@ class SoulPointSignature {
|
|
|
52
51
|
});
|
|
53
52
|
const concatenatedHashes = ethers_1.ethers.concat(txHashes);
|
|
54
53
|
const messageHash = ethers_1.ethers.keccak256(concatenatedHashes);
|
|
55
|
-
const
|
|
54
|
+
const signingKey = wallet.signingKey;
|
|
55
|
+
const signature = signingKey.signDigest ? signingKey.signDigest(messageHash) : signingKey.sign(messageHash);
|
|
56
56
|
const r = signature.r.slice(2).padStart(64, '0');
|
|
57
57
|
const s = signature.s.slice(2).padStart(64, '0');
|
|
58
|
-
|
|
58
|
+
let recoveryId;
|
|
59
|
+
if (signature.recoveryParam !== undefined) {
|
|
60
|
+
recoveryId = Number(signature.recoveryParam);
|
|
61
|
+
}
|
|
62
|
+
else if (signature.v !== undefined) {
|
|
63
|
+
const v = Number(signature.v);
|
|
64
|
+
recoveryId = v >= 27 ? v - 27 : v;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
recoveryId = 0;
|
|
68
|
+
}
|
|
69
|
+
recoveryId = recoveryId % 2;
|
|
70
|
+
const v = recoveryId.toString(16).padStart(2, '0');
|
|
59
71
|
return '0x' + r + s + v;
|
|
60
72
|
}
|
|
61
73
|
catch (error) {
|