@iexec/dataprotector
Version:
This product enables users to confidentially store data–such as mail address, documents, personal information ...
22 lines • 1.21 kB
JavaScript
import { ethers } from 'ethers';
import { ErrorWithData } from '../../../utils/errors.js';
import { throwIfMissing } from '../../../utils/validators.js';
import { getPocoDatasetRegistryContract } from './getPocoRegistryContract.js';
export async function approveProtectedDataForCollectionContract({ iexec = throwIfMissing(), protectedData, sharingContractAddress, }) {
const pocoProtectedDataRegistryContract = await getPocoDatasetRegistryContract(iexec);
const protectedDataTokenId = ethers.getBigInt(protectedData).toString();
const approvedOperator = await pocoProtectedDataRegistryContract
.getApproved(protectedDataTokenId)
.catch(() => {
throw new ErrorWithData('This protected data does not seem to exist or it has been burned.', {
protectedData,
});
});
if (approvedOperator.toLowerCase() !== sharingContractAddress) {
const { txOptions } = await iexec.config.resolveContractsClient();
const tx = await pocoProtectedDataRegistryContract.approve(sharingContractAddress, protectedDataTokenId, txOptions);
await tx.wait();
return tx;
}
}
//# sourceMappingURL=approveProtectedDataForCollectionContract.js.map