Skip to content

Commit 381475a

Browse files
committed
0.0.9
1 parent ffbf38d commit 381475a

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

packages/loopring-sdk/src/lib/generateKeyPair.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe('generateKeyPair', () => {
1616
account: '0x2345',
1717
accountId: 1,
1818
chainId: 1,
19+
publicKey: {
20+
x: '0x001b9a7064d6f1b27979170f9a5ce2fa32cefb77e2ac81583404e544943d620948',
21+
y: '0x001bb27243185bc780f46f964ad2011d55d0ff3ed0177b62bbe400d88ce9bc8f65',
22+
},
1923
})
2024
).resolves.toEqual({
2125
keyPair: {

packages/loopring-sdk/src/lib/generateKeyPair.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export interface KeyPairParams {
1414
// accountId?: number;
1515
}
1616

17-
// export function hexEqual(hex1: string, hex2: string) {
18-
// return hex1.toLowerCase() === hex2.toLowerCase();
19-
// }
17+
export function hexEqual(hex1: string, hex2: string) {
18+
return BigInt(hex1) === BigInt(hex2);
19+
}
2020

2121
export async function generateKeyPair({
2222
signMessageAsync,
@@ -36,23 +36,23 @@ export async function generateKeyPair({
3636
chainId
3737
);
3838

39-
const generatedKeyPair = await generateKeyPairWasm(result.signature);
39+
let generatedKeyPair = await generateKeyPairWasm(result.signature);
4040

41-
// if (
42-
// publicKey &&
43-
// result.signature.length > 3 &&
44-
// publicKey.x &&
45-
// publicKey.y &&
46-
// (!hexEqual(generatedKeyPair.formatedPx, publicKey.x) ||
47-
// !hexEqual(generatedKeyPair.formatedPy, publicKey.y))
48-
// ) {
49-
// const value = result.signature.split('');
50-
// let end = value.splice(result.signature.length - 2, 2).join('');
51-
// end = end == '1c' ? '01' : '1c';
52-
// generatedKeyPair = await generateKeyPairWasm(
53-
// value.concat(end.split('')).join('')
54-
// );
55-
// }
41+
if (
42+
publicKey &&
43+
result.signature.length > 3 &&
44+
publicKey.x &&
45+
publicKey.y &&
46+
(!hexEqual(generatedKeyPair.formatedPx, publicKey.x) ||
47+
!hexEqual(generatedKeyPair.formatedPy, publicKey.y))
48+
) {
49+
const value = result.signature.split('');
50+
let end = value.splice(result.signature.length - 2, 2).join('');
51+
end = end == '1c' ? '01' : '1c';
52+
generatedKeyPair = await generateKeyPairWasm(
53+
value.concat(end.split('')).join('')
54+
);
55+
}
5656

5757
return {
5858
counterFactualInfo: result.counterFactualInfo,

0 commit comments

Comments
 (0)