Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created March 6, 2023 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan/81e099e3407e7fac6addfe40dbc696ec to your computer and use it in GitHub Desktop.
Save bogdan/81e099e3407e7fac6addfe40dbc696ec to your computer and use it in GitHub Desktop.
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