mirror of
https://github.com/status-im/gasless-democracy.git
synced 2025-02-16 17:07:31 +00:00
add message signing
This commit is contained in:
parent
d8270179cc
commit
1a88c8393c
32
dapp/src/utils/signing.ts
Normal file
32
dapp/src/utils/signing.ts
Normal file
@ -0,0 +1,32 @@
|
||||
declare var web3: any
|
||||
|
||||
type signedMessage = {
|
||||
address: string,
|
||||
msg: string,
|
||||
sig: string,
|
||||
version: number
|
||||
}
|
||||
|
||||
export function sign(message: string): Promise<string> {
|
||||
return web3.eth.personal.sign(message, web3.eth.defaultAccount)
|
||||
}
|
||||
|
||||
export function verify(message: string, sig: string): Promise<string> {
|
||||
return web3.eth.personal.ecRecover(message, sig)
|
||||
}
|
||||
|
||||
export async function verifySignedMessage(message: signedMessage): Promise<boolean> {
|
||||
const { address, msg, sig } = message
|
||||
const resAddress = await verify(msg, sig)
|
||||
return address.toLowerCase() == resAddress.toLowerCase()
|
||||
}
|
||||
|
||||
export async function prettySign(message: string): Promise<signedMessage> {
|
||||
const sig = await sign(message)
|
||||
return {
|
||||
address: web3.eth.defaultAccount,
|
||||
msg: message,
|
||||
sig,
|
||||
version: 2
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user