Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix string pad #8

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"ahooks": "^3.7.7",
"react": "^18.2.0",
"vconsole": "^3.15.1",
"@portkey/types": "^1.2.2",
"@portkey/did-ui-react": "^1.2.2"
"@portkey/types": "1.3.0-alpha.3",
"@portkey/did-ui-react": "1.3.0-alpha.3"
},
"devDependencies": {
"@craco/craco": "^6.4.2",
Expand Down
14 changes: 8 additions & 6 deletions packages/login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-web-login",
"version": "1.1.3-alpha",
"version": "1.1.4-alpha",
"main": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
Expand Down Expand Up @@ -48,17 +48,19 @@
},
"dependencies": {
"@aelf-react/core": "^0.1.19",
"@portkey/contracts": "^1.3.0-alpha.3",
"@portkey/contracts": "1.3.0-alpha.3",
"@portkey/detect-provider": "1.0.1-alpha.0",
"@portkey/did-ui-react": "^1.3.0-alpha.3",
"@portkey/did-ui-react": "1.3.0-alpha.3",
"@portkey/provider-types": "1.0.1-alpha.0",
"@portkey/services": "^1.3.0-alpha.3",
"@portkey/types": "^1.3.0-alpha.3",
"@portkey/utils": "^1.3.0-alpha.3",
"@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",
"antd": "^4.24.4",
"bn.js": "^5.2.1",
"typescript": "^4.9.5"
},
"devDependencies": {
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');
}
5 changes: 3 additions & 2 deletions packages/login/src/wallets/discover/useDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DiscoverOptions } from 'src/types';
import useChainIdsSync from './useChainIdsSync';
import { ERR_CODE, makeError } from '../../errors';
import wait from '../../utils/waitForSeconds';
import { zeroFill } from '../../utils/zeroFill';

export type DiscoverDetectState = 'unknown' | 'detected' | 'not-detected';
export type DiscoverInterface = WalletHookInterface & {
Expand Down Expand Up @@ -264,8 +265,8 @@ export function useDiscover({
},
});
const signedMsgString = [
signedMsgObject.r.toString(16, 64),
signedMsgObject.s.toString(16, 64),
zeroFill(signedMsgObject.r),
zeroFill(signedMsgObject.s),
`0${signedMsgObject.recoveryParam!.toString()}`,
].join('');
return {
Expand Down
7 changes: 4 additions & 3 deletions packages/login/src/wallets/elf/useElf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WalletType, WebLoginState, WebLoginEvents } from '../../constants';
import isMobile from '../../utils/isMobile';
import checkSignatureParams from '../../utils/signatureParams';
import detectNightElf from './detectNightElf';
import { zeroFill } from '../../utils/zeroFill';

export function useElf({
options,
Expand Down Expand Up @@ -121,7 +122,7 @@ export function useElf({
setLoginState(WebLoginState.initial);
eventEmitter.emit(WebLoginEvents.LOGIN_ERROR, e);
} finally {
clearTimeout(timer);
clearTimeout(timer as unknown as number);
}
}, [activate, eventEmitter, nodes, setLoading, setLoginError, setLoginState]);

Expand Down Expand Up @@ -235,8 +236,8 @@ export function useElf({
);
}
const signedMsgString = [
signedMsgObject.r.toString(16, 64),
signedMsgObject.s.toString(16, 64),
zeroFill(signedMsgObject.r),
zeroFill(signedMsgObject.s),
`0${signedMsgObject.recoveryParam.toString()}`,
].join('');
return {
Expand Down
Loading