Skip to content

API

Functions

admin()

Initialize the worker-specific admin features

createContracts(enigmaContractAddr, tokenContractAddr)

Initialize the Enigma and Enigma token contracts

createTask(fn, args, gasLimit, gasPx, sender, scAddrOrPreCode, isContractDeploymentTask)Task

Create a base Task - a wrapper for a task (either contract deployments or regular tasks)

createTaskRecord(task)EventEmitter

Create and store a task record on chain (ETH). Task records are necessary for collecting the ENG computation fee and computing the immutable taskId (a unique value for each task computed from hash(hash(encrypted function signature, encrypted ABI-encoded arguments, gas limit, gas price, user's public key), user's nonce value monotonically increasing for every task deployment). Thus, task records have important implications for task ordering, fee payments, and verification.

createTaskRecords(tasks)EventEmitter

Create and store task records on chain (ETH). Task records are necessary for collecting the ENG computation fee and computing the immutable taskId (a unique value for each task computed from hash(hash(encrypted function signature, encrypted ABI-encoded arguments, gas limit, gas price, user's public key), user's nonce value monotonically increasing for every task deployment). Thus, task records have important implications for task ordering, fee payments, and verification.

getTaskRecordStatus(task)Promise

Get the Task's task record status from Ethereum

getTaskOutputHash(task)Promise

Fetch output hash at specified index position

getReport(custodian)Promise

Find SGX report

getWorkerParams(blockNumber)Promise

Given a block number, obtain the worker parameters. These parameters remain the same for a given secret contract and epoch (fixed number of blocks). These parameters are cached until the epoch changes.

selectWorkerGroup(scAddr, params, workerGroupSize)Array

Select the workers weighted-randomly based on the staked token amount that will run the computation task

sendTaskInput(task)EventEmitter

Send Task to Enigma p2p network for computation

getTaskResult(task)EventEmitter

Get task result from p2p network

decryptTaskResult(task)Task

Decrypt task result

pollTaskStatusGen(task, withResult)

Generator function for polling the Enigma p2p network for task status

innerPollTaskStatus(task, generator, emitter)

Inner poll status function that continues to poll the Enigma p2p network until the task has been verified

pollTaskStatus(task, withResult)EventEmitter

Poll the Enigma p2p network for a TaskInput's status

serializeTask(task)Object

Serialize Task for submission to the Enigma p2p network

obtainTaskKeyPair()Object

Deterministically generate a key-secret pair necessary for deriving a shared encryption key with the selected worker. This pair will be stored in local storage for quick retrieval.

deploySecretContract(fn, args, gasLimit, gasPx, sender, preCode)Task

Create a task to deploy a secret contract - creates base task, creates task record, and sends task to the Enigma network.

computeTask(fn, args, gasLimit, gasPx, sender, scAddr)Task

Create a compute task - creates base task, creates task record, and sends task to the Enigma network.

version()string

Return the version number of the library

admin()

Initialize the worker-specific admin features

Kind: global function

createContracts(enigmaContractAddr, tokenContractAddr)

Initialize the Enigma and Enigma token contracts

Kind: global function

Param Type
enigmaContractAddr string
tokenContractAddr string

createTask(fn, args, gasLimit, gasPx, sender, scAddrOrPreCode, isContractDeploymentTask) ⇒ Task

Create a base Task - a wrapper for a task (either contract deployments or regular tasks)

Kind: global function
Returns: Task - Task with base attributes to be used for remainder of task lifecycle

Param Type Description
fn string Function name
args Array Inputs for task in the form of [[arg1, ''], ..., [argn, '']]
gasLimit Number ENG gas limit for task computation
gasPx Number ENG gas price for task computation
sender string ETH address for task sender
scAddrOrPreCode string Either secret contract address or precode, depending on if user is running a contract deployment or regular task
isContractDeploymentTask boolean Is this task a contract deployment task (if not, it's a regular task)

createTaskRecord(task) ⇒ EventEmitter

Create and store a task record on chain (ETH). Task records are necessary for collecting the ENG computation fee and computing the immutable taskId (a unique value for each task computed from hash(hash(encrypted function signature, encrypted ABI-encoded arguments, gas limit, gas price, user's public key), user's nonce value monotonically increasing for every task deployment). Thus, task records have important implications for task ordering, fee payments, and verification.

Kind: global function
Returns: EventEmitter - EventEmitter to be listened to track creation of task record. Emits a Task with task record creation attributes to be used for remainder of task lifecycle

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

createTaskRecords(tasks) ⇒ EventEmitter

Create and store task records on chain (ETH). Task records are necessary for collecting the ENG computation fee and computing the immutable taskId (a unique value for each task computed from hash(hash(encrypted function signature, encrypted ABI-encoded arguments, gas limit, gas price, user's public key), user's nonce value monotonically increasing for every task deployment). Thus, task records have important implications for task ordering, fee payments, and verification.

Kind: global function
Returns: EventEmitter - EventEmitter to be listened to track creation of task records. Emits Tasks with task record creation attributes to be used for remainder of task lifecycle

Param Type Description
tasks Array Task wrappers for contract deployment and regular tasks

getTaskRecordStatus(task) ⇒ Promise

Get the Task's task record status from Ethereum

Kind: global function
Returns: Promise - Resolves to Task wrapper with updated ethStatus and proof properties

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

getTaskOutputHash(task) ⇒ Promise

Fetch output hash at specified index position

Kind: global function
Returns: Promise - - Resolves to output hash at the specified position

Param Type Description
task Task Task wrapper

getReport(custodian) ⇒ Promise

Find SGX report

Kind: global function
Returns: Promise - Resolves to SGX report for the worker

Param Type Description
custodian string Worker's address

getWorkerParams(blockNumber) ⇒ Promise

Given a block number, obtain the worker parameters. These parameters remain the same for a given secret contract and epoch (fixed number of blocks). These parameters are cached until the epoch changes.

Kind: global function
Returns: Promise - Resolves to the worker params, which includes a seed (random int generated from the principal node), first block number for the epoch, list of active work addresses (ordered list of workers that were logged in at the start of the epoch), and list of active worker balances

Param Type Description
blockNumber int Block number of task record's mining

selectWorkerGroup(scAddr, params, workerGroupSize) ⇒ Array

Select the workers weighted-randomly based on the staked token amount that will run the computation task

Kind: global function
Returns: Array - An array of selected workers where each selected worker is chosen with probability equal to number of staked tokens

Param Type Default Description
scAddr string Secret contract address
params Object Worker params: 1) Worker addresses; 2) Worker stakes; 3) Network seed
workerGroupSize number 5 Number of workers to be selected for task

sendTaskInput(task) ⇒ EventEmitter

Send Task to Enigma p2p network for computation

Kind: global function
Returns: EventEmitter - EventEmitter to be listened to track submission of Task to Enigma p2p network. Emits a response from the ENG network indicating whether client is ready to track the remainder of the task lifecycle

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

getTaskResult(task) ⇒ EventEmitter

Get task result from p2p network

Kind: global function
Returns: EventEmitter - EventEmitter to be listened to track getting result from Enigma network. Emits a response from the ENG network.

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

decryptTaskResult(task) ⇒ Task

Decrypt task result

Kind: global function
Returns: Task - Decrypted task result wrapper

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

pollTaskStatusGen(task, withResult)

Generator function for polling the Enigma p2p network for task status

Kind: global function

Param Type Description
task Task Task wrapper for contract deployment and regular tasks
withResult boolean Task wrapper for contract deployment and regular tasks

innerPollTaskStatus(task, generator, emitter)

Inner poll status function that continues to poll the Enigma p2p network until the task has been verified

Kind: global function

Param Type Description
task Task Task wrapper for contract deployment and regular tasks
generator pollTaskStatusGen Generator function for polling Enigma p2p network for task status
emitter EventEmitter EventEmitter to track Enigma p2p network polling for Task status

pollTaskStatus(task, withResult) ⇒ EventEmitter

Poll the Enigma p2p network for a TaskInput's status

Kind: global function
Returns: EventEmitter - EventEmitter to be listened to track polling the Enigma p2p network for a Task status. Emits a Task with task result attributes

Param Type Default Description
task Task Task wrapper for contract deployment and regular tasks
withResult boolean false Task wrapper for contract deployment and regular tasks

serializeTask(task) ⇒ Object

Serialize Task for submission to the Enigma p2p network

Kind: global function
Returns: Object - Serialized Task for submission to the Enigma p2p network

Param Type Description
task Task Task wrapper for contract deployment and regular tasks

obtainTaskKeyPair() ⇒ Object

Deterministically generate a key-secret pair necessary for deriving a shared encryption key with the selected worker. This pair will be stored in local storage for quick retrieval.

Kind: global function
Returns: Object - Public key-private key pair

deploySecretContract(fn, args, gasLimit, gasPx, sender, preCode) ⇒ Task

Create a task to deploy a secret contract - creates base task, creates task record, and sends task to the Enigma network.

Kind: global function
Returns: Task - Task with attributes necessary for task record and Enigma network

Param Type Description
fn string Function name
args Array Inputs for task in the form of [[arg1, ''], ..., [argn, '']]
gasLimit Number ENG gas limit for task computation
gasPx Number ENG gas price for task computation
sender string ETH address for task sender
preCode string Precode for contract deployment

computeTask(fn, args, gasLimit, gasPx, sender, scAddr) ⇒ Task

Create a compute task - creates base task, creates task record, and sends task to the Enigma network.

Kind: global function
Returns: Task - Task with attributes necessary for task record and Enigma network

Param Type Description
fn string Function name
args Array Inputs for task in the form of [[arg1, ''], ..., [argn, '']]
gasLimit Number ENG gas limit for task computation
gasPx Number ENG gas price for task computation
sender string ETH address for task sender
scAddr string Secret contract address

version() ⇒ string

Return the version number of the library

Kind: global function