Created
March 6, 2023 13:24
-
-
Save bogdan/81e099e3407e7fac6addfe40dbc696ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {pack} from '@ethersproject/solidity'; | |
import ethers from 'ethers'; | |
import {keccak256} from '@ethersproject/keccak256'; | |
import {verifyMessage} from '@ethersproject/wallet'; | |
import { BigNumber } from 'ethers'; | |
class SignedRecordUtils { | |
messageToSign( | |
tokenId: string, | |
ownerAddress: string, | |
key: string, | |
): string { | |
return keccak256(this.abiCoding(tokenId, ownerAddress, key)) | |
} | |
recoverAddress( | |
tokenId: string, | |
ownerAddress: string, | |
key: string, | |
signature: string, | |
): string { | |
return verifyMessage( | |
this.messageToSign(tokenId, ownerAddress, key), | |
signature, | |
); | |
} | |
abiCoding(tokenId: string, ownerAddress: string, key: string): string { | |
return pack( | |
['uint256', 'address', 'bytes32'], | |
[tokenId, ownerAddress, keccak256(key)], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment