Skip to content

Commit

Permalink
feat: zero fill
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Oct 24, 2023
1 parent 28e7be5 commit f73d355
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@portkey/services": "1.3.0-alpha.3",
"@portkey/types": "1.3.0-alpha.3",
"@portkey/utils": "1.3.0-alpha.3",
"@types/bn.js": "^5.1.3",
"aelf-bridge": "^0.0.10",
"aelf-sdk": "^3.2.40",
"ahooks": "^3.7.7",
Expand Down
4 changes: 4 additions & 0 deletions packages/login/src/utils/zeroFill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import BN, { isBN } from 'bn.js';
export function zeroFill(str: string | BN) {
return isBN(str) ? str.toString(16, 64) : str.padStart(64, '0');
}
14 changes: 7 additions & 7 deletions packages/login/src/wallets/discover/useDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { DiscoverOptions } from 'src/types';
import useChainIdsSync from './useChainIdsSync';
import { ERR_CODE, makeError } from '../../errors';
import wait from '../../utils/waitForSeconds';
import BN from 'bn.js';
import { zeroFill } from '../../utils/zeroFill';

export type DiscoverDetectState = 'unknown' | 'detected' | 'not-detected';
export type DiscoverInterface = WalletHookInterface & {
discoverDetected: DiscoverDetectState;
Expand Down Expand Up @@ -263,12 +264,11 @@ export function useDiscover({
data: signInfo || params.hexToBeSign,
},
});
signedMsgObject.r = '1';
signedMsgObject.s = '2';
const r = BN.isBN(signedMsgObject.r) ? signedMsgObject.r.toString(16, 64) : signedMsgObject.r.padStart(64, '0');
const s = BN.isBN(signedMsgObject.s) ? signedMsgObject.s.toString(16, 64) : signedMsgObject.s.padStart(64, '0');
const signedMsgString = [r, s, `0${signedMsgObject.recoveryParam!.toString()}`].join('');

const signedMsgString = [
zeroFill(signedMsgObject.r),
zeroFill(signedMsgObject.s),
`0${signedMsgObject.recoveryParam!.toString()}`,
].join('');
return {
error: 0,
errorMessage: '',
Expand Down
10 changes: 6 additions & 4 deletions packages/login/src/wallets/elf/useElf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { WalletType, WebLoginState, WebLoginEvents } from '../../constants';
import isMobile from '../../utils/isMobile';
import checkSignatureParams from '../../utils/signatureParams';
import detectNightElf from './detectNightElf';
import BN from 'bn.js';
import { zeroFill } from '../../utils/zeroFill';

export function useElf({
options,
Expand Down Expand Up @@ -235,9 +235,11 @@ export function useElf({
signedMsgObject.errorMessage.message || signedMsgObject.errorMessage || signedMsgObject.message,
);
}
const r = BN.isBN(signedMsgObject.r) ? signedMsgObject.r.toString(16, 64) : signedMsgObject.r.padStart(64, '0');
const s = BN.isBN(signedMsgObject.s) ? signedMsgObject.s.toString(16, 64) : signedMsgObject.s.padStart(64, '0');
const signedMsgString = [r, s, `0${signedMsgObject.recoveryParam.toString()}`].join('');
const signedMsgString = [
zeroFill(signedMsgObject.r),
zeroFill(signedMsgObject.s),
`0${signedMsgObject.recoveryParam.toString()}`,
].join('');
return {
error: 0,
errorMessage: '',
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f73d355

Please sign in to comment.