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
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
| Name | Type | Required | Description |
|---|---|---|---|
contentSpaceId | string | ✓ | ID of the content space |
networkId | string | ✓ | ID of the blockchain network |
networkName | string | ✓ | Name of the blockchain network |
fabricVersion | number | ✓ | The version of the target content fabric |
fabricURIs | Array.<string> | ✓ | A list of full URIs to content fabric nodes |
ethereumURIs | Array.<string> | ✓ | A list of full URIs to ethereum nodes |
authServiceURIs | Array.<string> | ✓ | A list of full URIs to auth service endpoints |
fileServiceURIs | Array.<string> | ✓ | A list of full URIs to file service endpoints |
searchURIs | Array.<string> | A list of full URIs to search service endpoints | |
ethereumContractTimeout | number | Number of seconds to wait for contract calls (default:10) | |
trustAuthorityId | string | (OAuth) The ID of the trust authority to use for OAuth authentication | |
staticToken | string | Static token that will be used for all authorization in place of normal auth. Also known as an anonymous token containing the space | |
noCache | boolean | If enabled, blockchain transactions will not be cached (default:false) | |
noAuth | boolean | If enabled, blockchain authorization will not be performed (default:false) | |
assumeV3 | boolean | If enabled, V3 fabric will be assumed (default:false) | |
service | string | 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
Clear saved access and state channel tokens
ClearSigner
Remove the signer from this client
ClearStaticToken
Clear the set static token for the client
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
| Name | Type | Required | Description |
|---|---|---|---|
configUrl | string | ✓ | Full URL to the config endpoint |
kmsUrls | Array.<string> | ✓ | List of KMS urls to use for OAuth authentication |
region | string | Preferred region - the fabric will auto-detect the best region if not specified
| |
clientIP | string | IP address to use in determining the region to use |
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
| Name | Type | Required | Description |
|---|---|---|---|
tenantId | string | ✓ | The ID of the tenant |
fundingToken | string | ✓ | A token permitting the user to retrieve funds |
funds | number | The amount to fund this user. The maximum amount is limited by the token issuer. (default:0.5) | |
groupToken | string | A token permitting the user to be added to access groups |
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
| Name | Type | Required | Description |
|---|---|---|---|
duration | number | ✓ | Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000). Default is 24 hours. (default:86400000) |
spec | Object | Additional attributes for this token | |
address | string | Address of the signing account - if not specified, the current signer address will be used. | |
Sign | function | If specified, this function will be used to produce the signature instead of the client's current signer | |
addEthereumPrefix | boolean | 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
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
| Name | Type | Required | Description |
|---|---|---|---|
messasge | string | ✓ | A JSON object representing the message to sign |
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
| Name | Type | Required | Description |
|---|---|---|---|
libraryId | string | Library ID to authorize | |
objectId | string | Object ID to authorize | |
versionHash | string | Version hash to authorize | |
policyId | string | The object ID of the policy for this token | |
subject | string | The subject of the token | |
grantType | string | ✓ | Permissions to grant for this token. Options: "access", "read", "create", "update", "read-crypt" (default:read) |
duration | number | ✓ | Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000) |
allowDecryption | boolean | ✓ | 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) |
context | Object | Additional JSON context | |
issueTime | number | Issue Time in milliseconds | |
expirationTime | number | Expiration Time in milliseconds |
CreateStaticToken
Create a static authorization token
Returns: The created static token
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
libraryId | string | The library ID to associate with the static token |
CurrentAccountAddress
Get the account address of the current signer
Returns: The address of the current signer
DecodeSignedMessageJSON
Verify and decode a signed message (JSON).
Returns: The decoded message, signer address, signature and signature type
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
signedMessage | string | ✓ | a signed message as created by CreateSignedMessageJSON |
DecryptECIES
Decrypt the given encrypted message with the current signer's private key
Returns: The decrypted string or object
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
message | string | ✓ | The message to decrypt |
EncryptECIES
message,
publicKey // optional
}) → Promise.<string>
Encrypt the given string or object with the current signer's public key
Returns: The encrypted message
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
message | string | Object | ✓ | The string or object to encrypt |
publicKey | string | If specified, message will be encrypted with this public key instead of the current user's |
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
| Name | Type | Required | Description |
|---|---|---|---|
configUrl | string | ✓ | Full URL to the config endpoint |
region | string | Preferred region - the fabric will auto-detect the best region if not specified
| |
clientIP | string | IP address to use in determining the region to use | |
trustAuthorityId | string | (OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached | |
staticToken | string | Static token that will be used for all authorization in place of normal auth | |
ethereumContractTimeout | number | Number of seconds to wait for contract calls (default:10) | |
noAuth | boolean | If enabled, blockchain authorization will not be performed (default:false) |
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
| Name | Type | Required | Description |
|---|---|---|---|
networkName | string | ✓ | Name of the network to connect to ("main", "demo", "test) |
region | string | Preferred region - the fabric will auto-detect the best region if not specified
| |
clientIP | string | IP address to use in determining the region to use | |
trustAuthorityId | string | (OAuth) The ID of the trust authority to use for OAuth authentication * @param {boolean=} noCache=false - If enabled, blockchain transactions will not be cached | |
staticToken | string | Static token that will be used for all authorization in place of normal auth | |
ethereumContractTimeout | number | Number of seconds to wait for contract calls (default:10) | |
noAuth | boolean | If enabled, blockchain authorization will not be performed (default:false) |
GenerateWallet
Generate a new ElvWallet that is connected to the client's provider
Returns: ElvWallet instance with this client's provider
NetworkInfo
Return information about how the client was connected to the network
Returns: The name, ID and configuration URL of the network
Networks
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
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
| Name | Type | Required | Description |
|---|---|---|---|
region | string | ✓ | Region from which to retrieve the node ID |
Nodes
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
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
| Name | Type | Required | Description |
|---|---|---|---|
url | string | ✓ | URL to request |
format | string | Format of response (default:"json") | |
method | string | Request method (default:"GET") | |
body | object | Request body | |
headers | object | Request headers |
ResetRegion
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
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
| Name | Type | Required | Description |
|---|---|---|---|
fabricURIs | Array.<string> | A list of URLs for the fabric, in preference order | |
ethereumURIs | Array.<string> | A list of URLs for the blockchain, in preference order | |
authServiceURIs | Array.<string> | A list of URLs for the auth service, in preference order | |
fileServiceURIs | Array.<string> | A list of URLs for file service jobs, in preference order | |
searchURIs | Array.<string> | A list of URLs for the search nodes, in preference order |
SetOauthToken
Set the OAuth token for use in state channel calls
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
token | string | ✓ | The OAuth ID token |
SetPolicyAuthorization
Authorize the client against the specified policy.
NOTE: After authorizing, the client will only be able to access content allowed by the policy
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
objectId | string | ✓ | The ID of the policy object |
SetRemoteSigner
idToken, // optional
authToken, // optional
tenantId, // optional
extraData, // optional
signerURIs, // optional
unsignedPublicAuth // optional
})
Set signer using OAuth ID token
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
idToken | string | OAuth ID token | |
authToken | string | Eluvio authorization token previously issued from OAuth ID token | |
tenantId | string | If specified, user will be associated with the tenant | |
extraData | Object | Additional data to pass to the login API | |
signerURIs | Array.<string> | (Only if using custom OAuth) - URIs corresponding to the key server(s) to use | |
unsignedPublicAuth | boolean | If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls) (default:false) |
SetSigner
Set the signer for this client to use for blockchain transactions
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
signer | object | ✓ | The ethers.js signer object |
SetSignerFromOauthToken
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
| Name | Type | Required | Description |
|---|---|---|---|
token | string | ✓ | The OAuth ID |
SetSignerFromWeb3Provider
Set the signer for this client to use for blockchain transactions from an existing web3 provider. Useful for integrating with MetaMask
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
provider | object | ✓ | The web3 provider object |
SetStaticToken
token, // optional
update // optional
})
Set a static token for the client to use for all authorization
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
token | string | The static token to use. If not provided, the default static token will be set. | |
update | boolean | If specified, the static token will be used for update operations as well (default:false) |
Sign
Create a signature for the specified string
Returns: The signed string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
string | string | ✓ | The string to sign |
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
| Name | Type | Required | Description |
|---|---|---|---|
matchEndpoint | string | Return node(s) matching the specified endpoint | |
matchNodeId | string | Return node(s) matching the specified node ID | |
matchWriteToken | string | Return node(s) matching the specified write token |
ToggleLogging
enable,
options // optional
)
Enable or disable verbose logging
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
enable | boolean | ✓ | Set logging |
options | Object | Additional options for customizing logging
|
UseRegion
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
| Name | Type | Required | Description |
|---|---|---|---|
region | string | ✓ | Preferred region - the fabric will auto-detect the best region if not specified
|
WriteTokenNodeUrlLocal
Return node url for a given write token via local lookup
Returns: The node url for a write token
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
writeToken | string | ✓ | The write token to match to a node |
WriteTokenNodeUrlNetwork
Return node url for a given write token via a network call
Returns: The node url for a write token
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
writeToken | string | ✓ | The write token to match to a node |