add toEIP55, checkPersionalSign
This commit is contained in:
parent
e842df426c
commit
b5f10e3d21
1931
dist/utils/chain.util.cjs
vendored
1931
dist/utils/chain.util.cjs
vendored
File diff suppressed because it is too large
Load Diff
2
dist/utils/chain.util.cjs.map
vendored
2
dist/utils/chain.util.cjs.map
vendored
File diff suppressed because one or more lines are too long
4
dist/utils/chain.util.d.cts
vendored
4
dist/utils/chain.util.d.cts
vendored
@ -33,5 +33,7 @@ declare const sign: ({ user, token, amount, saltNonce, }: {
|
||||
saltNonce: string;
|
||||
signature: string;
|
||||
}>;
|
||||
declare function toEIP55(address: string): string;
|
||||
declare function checkPersionalSign(message: string, address: string, signature: string): boolean;
|
||||
|
||||
export { buildLoginSignMsg, formatAddress, recoverTypedSignatureV4, sign };
|
||||
export { buildLoginSignMsg, checkPersionalSign, formatAddress, recoverTypedSignatureV4, sign, toEIP55 };
|
||||
|
4
dist/utils/chain.util.d.ts
vendored
4
dist/utils/chain.util.d.ts
vendored
@ -33,5 +33,7 @@ declare const sign: ({ user, token, amount, saltNonce, }: {
|
||||
saltNonce: string;
|
||||
signature: string;
|
||||
}>;
|
||||
declare function toEIP55(address: string): string;
|
||||
declare function checkPersionalSign(message: string, address: string, signature: string): boolean;
|
||||
|
||||
export { buildLoginSignMsg, formatAddress, recoverTypedSignatureV4, sign };
|
||||
export { buildLoginSignMsg, checkPersionalSign, formatAddress, recoverTypedSignatureV4, sign, toEIP55 };
|
||||
|
1927
dist/utils/chain.util.js
vendored
1927
dist/utils/chain.util.js
vendored
File diff suppressed because it is too large
Load Diff
2
dist/utils/chain.util.js.map
vendored
2
dist/utils/chain.util.js.map
vendored
File diff suppressed because one or more lines are too long
@ -1,5 +1,8 @@
|
||||
import { recoverTypedSignature, SignTypedDataVersion } from '@metamask/eth-sig-util'
|
||||
import { soliditySha3, toWei } from 'web3-utils'
|
||||
import { bytesToHex } from '@noble/hashes/utils'
|
||||
import { keccak_256 } from '@noble/hashes/sha3'
|
||||
import { recoverPersonalSignature } from '@metamask/eth-sig-util'
|
||||
import Web3 from 'web3'
|
||||
|
||||
export function recoverTypedSignatureV4(signObj: any, signature: string) {
|
||||
@ -72,3 +75,25 @@ export const sign = async ({
|
||||
signature = signature.replace(/00$/, '1b').replace(/01$/, '1c')
|
||||
return { token, amount: amountBn, startTime, saltNonce, signature }
|
||||
}
|
||||
|
||||
export function toEIP55(address: string) {
|
||||
const lowerAddress = `${address}`.toLowerCase().replace('0x', '')
|
||||
var hash = bytesToHex(keccak_256(lowerAddress))
|
||||
var ret = '0x'
|
||||
for (var i = 0; i < lowerAddress.length; i++) {
|
||||
if (parseInt(hash[i], 16) >= 8) {
|
||||
ret += lowerAddress[i].toUpperCase()
|
||||
} else {
|
||||
ret += lowerAddress[i]
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
export function checkPersionalSign(message: string, address: string, signature: string) {
|
||||
if (!signature.startsWith('0x')) {
|
||||
signature = '0x' + signature
|
||||
}
|
||||
const recovered = recoverPersonalSignature({ data: message, signature })
|
||||
return recovered === address
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user