Skip to content

Latest commit

 

History

History
273 lines (174 loc) · 5.15 KB

utils.md

File metadata and controls

273 lines (174 loc) · 5.15 KB

iexec / Exports / utils

Namespace: utils

Table of contents

Classes

Variables

Functions

Variables

NULL_ADDRESS

Const NULL_ADDRESS: string

ethereum null/zero address


NULL_BYTES32

Const NULL_BYTES32: string

null bytes32

Functions

decodeTag

decodeTag(tag): string[]

decode a bytes32 tag in an array of human readable tags

example:

console.log(decodeTag('0x0000000000000000000000000000000000000000000000000000000000000001'));

Parameters

Name Type
tag string

Returns

string[]


decryptResult

decryptResult(encrypted, beneficiaryKey): Promise<Buffer>

decrypt an encrypted result file

example:

// somehow load the beneficiary RSA private key
const beneficaryKey = await loadBeneficiaryKey();
const response = await iexec.task.fetchResults('0x5c959fd2e9ea2d5bdb965d7c2e7271c9cb91dd05b7bdcfa8204c34c52f8c8c19');
const encFileBuffer = await response.arrayBuffer();
const decryptedFileBuffer = await decryptResult(encFileBuffer, beneficaryKey);
const binary = new Blob([decryptedFileBuffer]);

Parameters

Name Type
encrypted string | ArrayBuffer | Uint8Array | Buffer
beneficiaryKey string | ArrayBuffer | Uint8Array | Buffer

Returns

Promise<Buffer>


encodeTag

encodeTag(tags): string

encode an array of human readable tags in a bytes32 tag readable by iExec's smart contracts

example:

console.log(encodeTag(['tee', 'gpu']));

Parameters

Name Type
tags string[]

Returns

string


formatEth

formatEth(wei): string

format a wei amount in Eth

example:

console.log('500000000 wei =' + formatEth('500000000')) + 'ether');

Parameters

Name Type
wei WeiAmount

Returns

string


formatRLC

formatRLC(nRLC): string

format a nRLC amount in RLC

  • example:
console.log('500000000 nRLC =' + formatRLC('500000000') + 'RLC');

Parameters

Name Type
nRLC NRLCAmount

Returns

string


getSignerFromPrivateKey

getSignerFromPrivateKey(host, privateKey, options?): EnhancedWallet

create a signer connected to the specified blockchain host from a private key

example:

const ethProvider = getSignerFromPrivateKey('http://localhost:8545', '0x564a9db84969c8159f7aa3d5393c5ecd014fce6a375842a45b12af6677b12407');
const iexec = new IExec({ ethProvider });

Parameters

Name Type Description
host string -
privateKey string -
options? Object -
options.gasPrice? string gas price override
options.providers ProviderOptions providers options
options.getTransactionCount? (blockTag?: BlockTag) => Promise<number> -

Returns

EnhancedWallet


parseEth

parseEth(value, defaultUnit?): BN

parse a string formatted Eht value in wei big number

supported units: 'wei', 'kwei', 'mwei', 'gwei', 'szabo', 'finney', 'ether' (or 'eth') default unit 'wei'

example:

console.log('5 gwei =' + parseEth('5 gwei') + 'wei');
console.log('5 gwei =' + parseEth(5, 'gwei') + 'wei');

Parameters

Name Type
value string
defaultUnit? string

Returns

BN


parseRLC

parseRLC(value, defaultUnit?): BN

parse a string formatted RLC value in nRLC big number

supported units: 'nRLC', 'RLC' default unit 'nRLC'

example:

console.log('5 RLC =' + parseEth('5 RLC') + 'nRLC');
console.log('5 RLC =' + parseEth(5, 'RLC') + 'nRLC');

Parameters

Name Type
value string
defaultUnit? string

Returns

BN


sumTags

sumTags(tags): string

sum an array of bytes32 tags

example:

const appTag = '0x0000000000000000000000000000000000000000000000000000000000000100';
const datasetTag = '0x0000000000000000000000000000000000000000000000000000000000000001';
const requestTag = '0x0000000000000000000000000000000000000000000000000000000000000000';
const workerpoolMinTag = sumTags([appTag, datasetTag, requestTag]);
console.log('workerpoolMinTag', workerpoolMinTag);

Parameters

Name Type
tags string[]

Returns

string