iexec / IExecDatasetModule
module exposing dataset methods
new IExecDatasetModule(
configOrArgs,options?):IExecDatasetModule
Create an IExecModule instance
IExecDatasetModule
config:
IExecConfig
current IExecConfig
checkDatasetSecretExists(
datasetAddress,options?):Promise<boolean>
check if a the dataset secret exists in the Secret Management Service
example:
const isSecretSet = await checkDatasetSecretExists(datasetAddress);
console.log('secret exists:', isSecretSet);string
Promise<boolean>
checkDeployedDataset(
datasetAddress):Promise<Boolean>
check if an dataset is deployed at a given address
example:
const isDeployed = await checkDeployedDataset(address);
console.log('dataset deployed', isDeployed);string
Promise<Boolean>
computeEncryptedFileChecksum(
encryptedFile):Promise<string>
compute the encrypted dataset file's checksum required for dataset deployment
the dataset checksum is the encrypted file checksum, use this method on the encrypted file but DO NOT use it on the original dataset file
NB:
- the dataset checksum is the sha256sum of the encrypted dataset file
- the checksum is used in the computation workflow to ensure the dataset's integrity
example:
const encryptedDataset = await encrypt(
datasetFile,
encryptionKey,
);
const checksum = await computeEncryptedFileChecksum(
encryptedDataset,
);ArrayBuffer | Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>
Promise<string>
countUserDatasets(
userAddress):Promise<BN>
count the datasets owned by an address.
example:
const count = await countUserDatasets(userAddress);
console.log('dataset count:', count);string
Promise<BN>
deployDataset(
dataset):Promise<{address:string;txHash:string; }>
SIGNER REQUIRED
deploy a dataset contract on the blockchain
example:
const { address } = await deployDataset({
owner: address,
name: 'cat.jpeg',
multiaddr: '/ipfs/Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u',
checksum: '0x84a3f860d54f3f5f65e91df081c8d776e8bcfb5fbc234afce2f0d7e9d26e160d',
});
console.log('deployed at', address);Promise<{ address: string; txHash: string; }>
encrypt(
datasetFile,encyptionKey):Promise<Buffer<ArrayBufferLike>>
encrypt the dataset file with the specified key using AES-256-CBC
NB:
- the supplied key must be 256 bits base64 encoded
- DO NOT leak the key and DO NOT use the same key for encrypting different datasets
example:
// somehow load the dataset file
const datasetFile = await readDatasetAsArrayBuffer();
// generate a key DO NOT leak this key
const encryptionKey = generateEncryptionKey();
// encrypt
const encryptedDataset = await encrypt(
datasetFile,
encryptionKey,
);
// the encrypted binary can be shared
const binary = new Blob([encryptedDataset]);ArrayBuffer | Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>
string
Promise<Buffer<ArrayBufferLike>>
generateEncryptionKey():
string
generate an encryption key to encrypt a dataset
NB: this method returns a base64 encoded 256 bits key
example:
const encryptionKey = generateEncryptionKey();
console.log('encryption key:', encryptionKey);string
predictDatasetAddress(
dataset):Promise<string>
predict the dataset contract address given the dataset deployment arguments
example:
const address = await predictDatasetAddress({
owner: address,
name: 'cat.jpeg',
multiaddr: '/ipfs/Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u',
checksum: '0x84a3f860d54f3f5f65e91df081c8d776e8bcfb5fbc234afce2f0d7e9d26e160d',
});
console.log('address', address);Promise<string>
pushDatasetSecret(
datasetAddress,encryptionKey,options?):Promise<boolean>
SIGNER REQUIRED, ONLY DATASET OWNER
push the dataset's encryption key to the Secret Management Service
WARNING: pushed secrets CAN NOT be updated
example:
const pushed = await pushDatasetSecret(datasetAddress, encryptionKey);
console.log('secret pushed:', pushed);string
string
Promise<boolean>
showDataset(
datasetAddress):Promise<{dataset:Dataset;objAddress:string; }>
show a deployed dataset details
example:
const { dataset } = await showDataset('0xb9b56f1c78f39504263835342e7affe96536d1ea');
console.log('dataset:', dataset);string
Promise<{ dataset: Dataset; objAddress: string; }>
showUserDataset(
index,address):Promise<{dataset:Dataset;objAddress:string; }>
show deployed dataset details by index for specified user user
example:
const { dataset } = await showUserDataset(0, userAddress);
console.log('dataset:', dataset);string
Promise<{ dataset: Dataset; objAddress: string; }>
transferDataset(
datasetAddress,to):Promise<{address:string;to:string;txHash:string; }>
ONLY DATASET OWNER
transfer the ownership of a dataset to the specified address
NB: when transferring the ownership to a contract, the receiver contract must implement the ERC721 token receiver interface
example:
const { address, to, txHash } = await transferDataset(datasetAddress, receiverAddress);
console.log(`dataset ${address} ownership transferred to ${address} in tx ${txHash}`);string
string
Promise<{ address: string; to: string; txHash: string; }>
staticfromConfig(config):IExecDatasetModule
Create an IExecDatasetModule instance using an IExecConfig instance
IExecDatasetModule