Skip to main content

ElvClient

See the Modules section on the sidebar for details about methods related to interacting with the Fabric.


For information about the Eluvio Wallet Client, go here.

Constructor​

new ElvClient({
  contentSpaceId,
  networkId,
  networkName,
  fabricVersion,
  fabricURIs,
  ethereumURIs,
  authServiceURIs,
  fileServiceURIs,
  searchURIs, // optional
  ethereumContractTimeout, // optional
  trustAuthorityId, // optional
  staticToken, // optional
  noCache, // optional
  noAuth, // optional
  assumeV3, // optional
  service // optional
}) → ElvClient

Create a new ElvClient

NOTE: It is highly recommended to use the FromConfigurationUrl or FromNetworkName method automatically import the client settings from the fabric

Returns: New ElvClient connected to the specified content fabric and blockchain

Parameters

NameTypeRequiredDescription
contentSpaceIdstring✓

ID of the content space

networkIdstring✓

ID of the blockchain network

networkNamestring✓

Name of the blockchain network

fabricVersionnumber✓

The version of the target content fabric

fabricURIsArray.<string>✓

A list of full URIs to content fabric nodes

ethereumURIsArray.<string>✓

A list of full URIs to ethereum nodes

authServiceURIsArray.<string>✓

A list of full URIs to auth service endpoints

fileServiceURIsArray.<string>✓

A list of full URIs to file service endpoints

searchURIsArray.<string>

A list of full URIs to search service endpoints

ethereumContractTimeoutnumber

Number of seconds to wait for contract calls

(default: 10)
trustAuthorityIdstring

(OAuth) The ID of the trust authority to use for OAuth authentication

staticTokenstring

Static token that will be used for all authorization in place of normal auth. Also known as an anonymous token containing the space

noCacheboolean

If enabled, blockchain transactions will not be cached

(default: false)
noAuthboolean

If enabled, blockchain authorization will not be performed

(default: false)
assumeV3boolean

If enabled, V3 fabric will be assumed

(default: false)
servicestring

The mode that determines how HttpClient will be initialized. If 'default' is set, HttpClient uris will use fabricUris. If 'search' is used, searchUris will be used

(default: default)

ClearCache​

ClearCache()

Clear saved access and state channel tokens

ClearSigner​

ClearSigner()

Remove the signer from this client

ClearStaticToken​

ClearStaticToken()

Clear the set static token for the client

Configuration​

Configuration({
  configUrl,
  kmsUrls,
  region, // optional
  clientIP // optional
}) → Promise.<Object>

Retrieve content space info and preferred fabric and blockchain URLs from the fabric

Returns: Object containing content space ID and fabric and ethereum URLs

Parameters

NameTypeRequiredDescription
configUrlstring✓

Full URL to the config endpoint

kmsUrlsArray.<string>✓

List of KMS urls to use for OAuth authentication

regionstring

Preferred region - the fabric will auto-detect the best region if not specified

  • Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
clientIPstring

IP address to use in determining the region to use

CreateAccount​

CreateAccount({
  tenantId,
  fundingToken,
  funds, // optional
  groupToken // optional
}) → string

Initialize a new account using the provided funding and group tokens.

This method will redeem the tokens for the current account (or create a new one if not set) in order to retrieve funds and optionally have the user added to appropriate access groups.

Returns: The address of the user

Parameters

NameTypeRequiredDescription
tenantIdstring✓

The ID of the tenant

fundingTokenstring✓

A token permitting the user to retrieve funds

fundsnumber

The amount to fund this user. The maximum amount is limited by the token issuer.

(default: 0.5)
groupTokenstring

A token permitting the user to be added to access groups

CreateFabricToken​

CreateFabricToken({
  duration,
  spec, // optional
  address, // optional
  Sign, // optional
  addEthereumPrefix // optional
})

Create a signed authorization token that can be used to authorize against the fabric

Parameters

NameTypeRequiredDescription
durationnumber✓

Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000). Default is 24 hours.

(default: 86400000)
specObject

Additional attributes for this token

addressstring

Address of the signing account - if not specified, the current signer address will be used.

Signfunction

If specified, this function will be used to produce the signature instead of the client's current signer

addEthereumPrefixboolean

If specified, the 'Ethereum Signed Message' prefixed hash format will be performed. Disable this if the provided Sign method already does this (e.g. Metamask)

(default: true)

CreateSignedMessageJSON​

CreateSignedMessageJSON({ messasge })

Build a signed message (JSON) using the current signer. Signed messages have a similar format to signed access tokens and they include the message itself such that they can be both verified and decoded by the receiving entity.

Messages can be encoded and signed using different methods, and the encoding and signature types are described in the header of the resulting signed message blob.

Note this type of message can not be verified and decoded on chain.

Parameters

NameTypeRequiredDescription
messasgestring✓

A JSON object representing the message to sign

CreateSignedToken​

CreateSignedToken({
  libraryId, // optional
  objectId, // optional
  versionHash, // optional
  policyId, // optional
  subject, // optional
  grantType,
  duration,
  allowDecryption,
  context, // optional
  issueTime, // optional
  expirationTime // optional
})

Issue a self-signed authorization token

Parameters

NameTypeRequiredDescription
libraryIdstring

Library ID to authorize

objectIdstring

Object ID to authorize

versionHashstring

Version hash to authorize

policyIdstring

The object ID of the policy for this token

subjectstring

The subject of the token

grantTypestring✓

Permissions to grant for this token. Options: "access", "read", "create", "update", "read-crypt"

(default: read)
durationnumber✓

Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000)

allowDecryptionboolean✓

If specified, the re-encryption key will be included in the token, enabling the user of this token to download encrypted content from the specified object

(default: false)
contextObject

Additional JSON context

issueTimenumber

Issue Time in milliseconds

expirationTimenumber

Expiration Time in milliseconds

CreateStaticToken​

CreateStaticToken({ libraryId }) // optional → string

Create a static authorization token

Returns: The created static token

Parameters

NameTypeRequiredDescription
libraryIdstring

The library ID to associate with the static token

CurrentAccountAddress​

CurrentAccountAddress() → string

Get the account address of the current signer

Returns: The address of the current signer

DecodeSignedMessageJSON​

DecodeSignedMessageJSON({ signedMessage }) → Promise.<Object>

Verify and decode a signed message (JSON).

Returns: The decoded message, signer address, signature and signature type

Parameters

NameTypeRequiredDescription
signedMessagestring✓

a signed message as created by CreateSignedMessageJSON

DecryptECIES​

DecryptECIES({ message }) → Promise.<(string|Object)>

Decrypt the given encrypted message with the current signer's private key

Returns: The decrypted string or object

Parameters

NameTypeRequiredDescription
messagestring✓

The message to decrypt

EncryptECIES​

EncryptECIES({
  message,
  publicKey // optional
}) → Promise.<string>

Encrypt the given string or object with the current signer's public key

Returns: The encrypted message

Parameters

NameTypeRequiredDescription
messagestring | Object✓

The string or object to encrypt

publicKeystring

If specified, message will be encrypted with this public key instead of the current user's

FromConfigurationUrl​

FromConfigurationUrl({
  configUrl,
  region, // optional
  clientIP, // optional
  trustAuthorityId, // optional
  staticToken, // optional
  ethereumContractTimeout, // optional
  noAuth // optional
}) → Promise.<ElvClient>

Create a new ElvClient from the specified configuration URL

Returns: New ElvClient connected to the specified content fabric and blockchain

Parameters

NameTypeRequiredDescription
configUrlstring✓

Full URL to the config endpoint

regionstring

Preferred region - the fabric will auto-detect the best region if not specified

  • Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
clientIPstring

IP address to use in determining the region to use

trustAuthorityIdstring

(OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached

staticTokenstring

Static token that will be used for all authorization in place of normal auth

ethereumContractTimeoutnumber

Number of seconds to wait for contract calls

(default: 10)
noAuthboolean

If enabled, blockchain authorization will not be performed

(default: false)

FromNetworkName​

FromNetworkName({
  networkName,
  region, // optional
  clientIP, // optional
  trustAuthorityId, // optional
  staticToken, // optional
  ethereumContractTimeout, // optional
  noAuth // optional
}) → Promise.<ElvClient>

Create a new ElvClient for the specified network

Returns: New ElvClient connected to the specified content fabric and blockchain

Parameters

NameTypeRequiredDescription
networkNamestring✓

Name of the network to connect to ("main", "demo", "test)

regionstring

Preferred region - the fabric will auto-detect the best region if not specified

  • Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south
clientIPstring

IP address to use in determining the region to use

trustAuthorityIdstring

(OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached

staticTokenstring

Static token that will be used for all authorization in place of normal auth

ethereumContractTimeoutnumber

Number of seconds to wait for contract calls

(default: 10)
noAuthboolean

If enabled, blockchain authorization will not be performed

(default: false)

GenerateWallet​

GenerateWallet() → ElvWallet

Generate a new ElvWallet that is connected to the client's provider

Returns: ElvWallet instance with this client's provider

NetworkInfo​

NetworkInfo() → Object

Return information about how the client was connected to the network

Returns: The name, ID and configuration URL of the network

Networks​

Networks() → Object

Return a list of valid Eluvio Content Fabric network names and their associated configuration URLs

Returns: An object using network names as keys and configuration URLs as values.

NodeId​

NodeId({ region }) → Promise.<string>

Retrieve the node ID reported by the fabric for the specified region

Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName

Returns: The node ID reported by the fabric

Parameters

NameTypeRequiredDescription
regionstring✓

Region from which to retrieve the node ID

Nodes​

Nodes() → Promise.<Object>

Retrieve the fabric, ethereum, auth service, and search nodes currently used by the client, in preference order

Returns: An object containing the lists of fabric, ethereum, auth service, and search urls in use by the client

Request​

Request(
  url,
  format, // optional
  method, // optional
  body, // optional
  headers // optional
) → Promise.<*>

Request the specified URL with the given method and body, and return the result in the specified format

Returns: Response in the specified format

Parameters

NameTypeRequiredDescription
urlstring✓

URL to request

formatstring

Format of response

(default: "json")
methodstring

Request method

(default: "GET")
bodyobject

Request body

headersobject

Request headers

ResetRegion​

ResetRegion() → Promise.<Object>

Reset fabric URLs to prefer the best region auto-detected by the fabric.

Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName

Returns: An object containing the updated fabric and ethereum URLs in order of preference

SetNodes​

SetNodes({
  fabricURIs, // optional
  ethereumURIs, // optional
  authServiceURIs, // optional
  fileServiceURIs, // optional
  searchURIs // optional
})

Set the client to use the specified fabric, ethereum, auth service, and search nodes, in preference order

Parameters

NameTypeRequiredDescription
fabricURIsArray.<string>

A list of URLs for the fabric, in preference order

ethereumURIsArray.<string>

A list of URLs for the blockchain, in preference order

authServiceURIsArray.<string>

A list of URLs for the auth service, in preference order

fileServiceURIsArray.<string>

A list of URLs for file service jobs, in preference order

searchURIsArray.<string>

A list of URLs for the search nodes, in preference order

SetOauthToken​

SetOauthToken({ token })

Set the OAuth token for use in state channel calls

Parameters

NameTypeRequiredDescription
tokenstring✓

The OAuth ID token

SetPolicyAuthorization​

SetPolicyAuthorization({ objectId })

Authorize the client against the specified policy.

NOTE: After authorizing, the client will only be able to access content allowed by the policy

Parameters

NameTypeRequiredDescription
objectIdstring✓

The ID of the policy object

SetRemoteSigner​

SetRemoteSigner({
  idToken, // optional
  authToken, // optional
  tenantId, // optional
  extraData, // optional
  signerURIs, // optional
  unsignedPublicAuth // optional
})

Set signer using OAuth ID token

Parameters

NameTypeRequiredDescription
idTokenstring

OAuth ID token

authTokenstring

Eluvio authorization token previously issued from OAuth ID token

tenantIdstring

If specified, user will be associated with the tenant

extraDataObject

Additional data to pass to the login API

signerURIsArray.<string>

(Only if using custom OAuth) - URIs corresponding to the key server(s) to use

unsignedPublicAuthboolean

If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls)

(default: false)

SetSigner​

SetSigner({ signer })

Set the signer for this client to use for blockchain transactions

Parameters

NameTypeRequiredDescription
signerobject✓

The ethers.js signer object

SetSignerFromOauthToken​

SetSignerFromOauthToken({ token })

Set the signer for this client via OAuth token. The client will exchange the given token for the user's private key using the KMS specified in the configuration.

NOTE: The KMS URL(s) must be set in the initial configuration of the client (FromConfigurationUrl or FromNetworkName)

Parameters

NameTypeRequiredDescription
tokenstring✓

The OAuth ID

SetSignerFromWeb3Provider​

SetSignerFromWeb3Provider({ provider })

Set the signer for this client to use for blockchain transactions from an existing web3 provider. Useful for integrating with MetaMask

Parameters

NameTypeRequiredDescription
providerobject✓

The web3 provider object

SetStaticToken​

SetStaticToken({
  token, // optional
  update // optional
})

Set a static token for the client to use for all authorization

Parameters

NameTypeRequiredDescription
tokenstring

The static token to use. If not provided, the default static token will be set.

updateboolean

If specified, the static token will be used for update operations as well

(default: false)

Sign​

Sign(string) → Promise.<string>

Create a signature for the specified string

Returns: The signed string

Parameters

NameTypeRequiredDescription
stringstring✓

The string to sign

SpaceNodes​

SpaceNodes({
  matchEndpoint, // optional
  matchNodeId, // optional
  matchWriteToken // optional
}) → Promise.<Array.<Object>>

Return a list of nodes in the content space, optionally filtered by node ID or endpoint.

Returns: A list of nodes in the space matching the parameters

Parameters

NameTypeRequiredDescription
matchEndpointstring

Return node(s) matching the specified endpoint

matchNodeIdstring

Return node(s) matching the specified node ID

matchWriteTokenstring

Return node(s) matching the specified write token

ToggleLogging​

ToggleLogging(
  enable,
  options // optional
)

Enable or disable verbose logging

Parameters

NameTypeRequiredDescription
enableboolean✓

Set logging

optionsObject

Additional options for customizing logging

  • log: custom log() function
  • error: custom error() function
  • (custom functions must accept same arguments as console.log/console.error)

UseRegion​

UseRegion({ region }) → Promise.<Object>

Update fabric URLs to prefer the specified region.

Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName

Returns: An object containing the updated fabric, ethereum, auth service, and search URLs in order of preference

Parameters

NameTypeRequiredDescription
regionstring✓

Preferred region - the fabric will auto-detect the best region if not specified

  • Available regions: as-east, au-east, eu-east-north, eu-west-north, na-east-north, na-east-south, na-west-north, na-west-south, eu-east-south, eu-west-south

WriteTokenNodeUrlLocal​

WriteTokenNodeUrlLocal({ writeToken }) → string

Return node url for a given write token via local lookup

Returns: The node url for a write token

Parameters

NameTypeRequiredDescription
writeTokenstring✓

The write token to match to a node

WriteTokenNodeUrlNetwork​

WriteTokenNodeUrlNetwork({ writeToken }) → Promise.<string>

Return node url for a given write token via a network call

Returns: The node url for a write token

Parameters

NameTypeRequiredDescription
writeTokenstring✓

The write token to match to a node