protectData
The iExec tool suite supports deployment of applications where the user of the application has complete and total control over access to their data. This ensures privacy and security when invoking these applications. Through use of the protectData
method, a user may encrypt and secure any type of data. Encryption occurs on the client side, supporting the user's control over their data.
Usage
This is an asynchronous method that supports both the promise and observable patterns. Examples of each are provided below. Regardless of the invocation pattern, the method accepts a JSON object containing the data to encrypt and an optional name to identify the data.
An email address, for example, may be submitted as:
Your object may contain any number of custom keys. The following example illustrates protection of multiple categories of data within one object:
Return value example
The exact style of result differs based on which invocation pattern you use but the overall content is the same. The result object includes the specified optional name
parameter, along with metadata including the owner, schema for the protected data, creation timestamp, transaction hash, and a uint8-encoded array representing the zipped data for the object.
Parameters
The protectData
method accepts the following parameters
data (required)
This is the actual data the user is protecting, provided as a JSON object with any number of custom keys. The data is encrypted and stored as an NFT.
name (optional)
Allows providing a descriptive name for the protected data. This is considered public metadata, describing the protected data.
The name is public and not encrypted. If you don't pass a name to your protected data we will automatically define it as "Untitled".
Result
The protectData
method returns the following fields, either as a JSON object or as individual fields depending on whether you use the promise or observable pattern respectively.
name
The optional name provided during invocation of the method. If no name is specified this value defaults to Untitled
.
address
The ETH address of the newly created protectedData
.
owner
The ETH address of the creator and owner of this protectedData
.
schema
Metadata describing the fields provided in the data
parameter. The data types are automatically detected and listed in the schema.
The following data types are automatically detected:
Scalars
boolean
number
string
Binary:
application/octet-stream
application/pdf
application/xml
application/zip
audio/midi
audio/mpeg
audio/x-wav
image/bmp
image/gif
image/jpeg
image/png
image/webp
video/mp4
video/mpeg
video/x-msvideo
Any undetected binary data type is categorized as application/octet-stream
creationTimestamp
A unix-style timestamp indicating the creation time of this protectedData
.
transactionHash
The ID of the transaction that happened on iExec's side chain. You may view details on the transaction using the iExec explorer.
zipFile
This is a binary representation of the data stored in the protectedData
. This is intended as debug data and we will remove this in a future SDK release.
encryptionKey
The encryption key generated by the client to encrypt the data. This key is for your own usage. You will not have to share it in the context of the iExec protocol or developer tools.
Example invocations
You may invoke the protectData
method using either the promise pattern or the observable pattern. Examples of both approaches are included below.
1. With promise
Sample invocation with promise pattern
Return value example with promise pattern
The zip file generated is a uint8array, so if you want to handle the binary data or download it consider adding a zip extension to it.
2. With observable
Sample invocation with observable pattern
Return value example with observable pattern
Message | Return value |
---|---|
DATA_SCHEMA_EXTRACTED | |
ZIP_FILE_CREATED | |
ENCRYPTION_KEY_CREATED | |
FILE_ENCRYPTED | |
ENCRYPTED_FILE_UPLOADED | |
PROTECTED_DATA_DEPLOYMENT_REQUEST | |
PROTECTED_DATA_DEPLOYMENT_SUCCESS | |
PUSH_SECRET_TO_SMS_SIGN_REQUEST | Empty |
PUSH_SECRET_TO_SMS_SUCCESS | Empty |
Last updated