setPortraitHashAsDelegate()
/**
* Set a User Portrait as delegate
* @param {UserPortraitAddress | UserPortraitENSName} identity - The identity of the user that the user would like to set a Portrait for.
* @param {string} hash - The hash of the User Portrait that the user would like to set.
* @param {number} blockNumber - The block number that the user would like to set the Portrait for.
* @param {string} signature - The signature of the user that the user would like to set a Portrait for.
*
* @remarks
* Wallet required.
*
* @returns {Promise<ethers.ContractTransaction>} - The transaction object, which contains the transaction hash.
*
* @throws {Error} - Will throw an error if the identity is not a valid address or ENS name.
* @throws {Error} - Will throw an error if the signature is not valid.
*/
setPortraitHashAsDelegate(
identity: UserPortraitAddress | UserPortraitENSName,
hash: string,
blockNumber: number,
signature: string,
): Promise<ethers.ContractTransaction> {
const address = isAddress(identity)
? identity
: this.portrait.defaultProvider.resolveName(identity);
const wallet = this.portrait.portraitProvider.getSigner();
const message = ethers.utils.solidityKeccak256(
['address', 'uint256', 'string'],
[address, blockNumber, hash],
);
const recoveredAddress = ethers.utils.verifyMessage(
ethers.utils.arrayify(message),
signature,
);
if (recoveredAddress !== address) {
throw new Error('Invalid signature');
}
return this.portrait.portraitUserContract.setPersonalIpfsCIDByDelegate(
address,
hash,
blockNumber,
signature,
);
}
Last updated