You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// read the original file// exemple with FileReader in browserconstdatasetFileBytes=awaitnewPromise((resolve,reject)=>{constfileReader=newFileReader();fileReader.readAsArrayBuffer(file);fileReader.onload=e=>resolve(e.target.result);fileReader.onerror=()=>reject(Error(`Failed to read file: ${fileReader.error}`));fileReader.onabort=()=>reject(Error(`Failed to read file: aborted`));});// encrypt the fileconstkey=iexec.dataset.generateEncryptionKey();constencryptedFileBuffer=awaitiexec.dataset.encrypt(datasetFileBytes,key);// compute the encrypted file checksumconstdatasetChecksum=awaitiexec.dataset.computeChecksum(encryptedFileBuffer);// upload the encrypted file and get a direct download uri (formated as standard url or multiaddr)// exemple with ipfs packageconstmultiaddr=awaitnewPromise((resolve,reject)=>{try{constuploadResult=awaitipfs.add(encrypted);const{ cid }=uploadResult;return=`/ipfs/${cid.toSting()}`;}catch(e){reject(Error(`Failed to upload encrypted file: ${e}`));}})// get the dataset checksumconstchecksum=awaitiexec.dataset.computeChecksum(encryptedFileBuffer);// deploy the dataset on the blockchainconst{ address }=awaitiexec.dataset.deployDataset({owner: awaitiexec.wallet.getAddress(),// set the current wallet as ownername: file.name,
multiaddr,
checksum
});// push the dataset decryption key to the SMSawaitiexec.dataset.pushDatasetSecret(datasetAddress,key);// define usage policy in a datsetorderconstdatasetorder=awaitiexec.order.signDatasetorder(awaitiexec.order.createDatasetorder({dataset: address,tag: ['tee'],// use tag tee to ensure your dataset will never be used by apps running outside a Trusted Execution Environmentdatasetprice: 0,// you may want to receive an income when someone use your datasetvolume: 1000000000,// total number of use of the dataset orderapprestrict: 'my-trusted-app.eth'// restrict the usage of your dataset to a trusted app (no apprestrict will let any app being able to use your dataset and leave your data unprotected against malicious apps)}));// publish the datasetorder to the marketplaceawaitiexec.order.publishDatasetorder(datasetorder);