Constructor
new ElvClient({contentSpaceId,networkId,networkName,fabricVersion,fabricURIs,ethereumURIs,authServiceURIs,searchURIsoptional,ethereumContractTimeoutoptional,trustAuthorityIdoptional,staticTokenoptional,noCacheoptional,noAuthoptional,assumeV3optional,serviceoptional}) → 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
Parameters:
Name | Type | Attributes | Default | 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 |
||
searchURIs |
Array.<string> |
<optional> |
A list of full URIs to search service endpoints |
|
ethereumContractTimeout |
number |
<optional> |
10 |
Number of seconds to wait for contract calls |
trustAuthorityId |
string |
<optional> |
(OAuth) The ID of the trust authority to use for OAuth authentication |
|
staticToken |
string |
<optional> |
Static token that will be used for all authorization in place of normal auth |
|
noCache |
boolean |
<optional> |
false |
If enabled, blockchain transactions will not be cached |
noAuth |
boolean |
<optional> |
false |
If enabled, blockchain authorization will not be performed |
assumeV3 |
boolean |
<optional> |
false |
If enabled, V3 fabric will be assumed |
service |
string |
<optional> |
default |
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 |
- Source:
Methods
ClearCache()
Clear saved access and state channel tokens
- Source:
ClearSigner()
Remove the signer from this client
- Source:
ClearStaticToken()
Clear the set static token for the client
- Source:
async CreateAccount({tenantId,fundingToken,fundsoptional,groupTokenoptional}) → 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.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tenantId |
string |
The ID of the tenant |
||
fundingToken |
string |
A token permitting the user to retrieve funds |
||
funds |
number |
<optional> |
0.5 |
The amount to fund this user. The maximum amount is limited by the token issuer. |
groupToken |
string |
<optional> |
A token permitting the user to be added to access groups |
- Source:
async CreateFabricToken({duration,specoptional,addressoptional,Signoptional,addEthereumPrefixoptional})
Create a signed authorization token that can be used to authorize against the fabric
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
duration |
number | 86400000 |
Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000). Default is 24 hours. |
|
spec |
Object |
<optional> |
Additional attributes for this token |
|
address |
string |
<optional> |
Address of the signing account - if not specified, the current signer address will be used. |
|
Sign |
function |
<optional> |
If specified, this function will be used to produce the signature instead of the client's current signer |
|
addEthereumPrefix |
boolean |
<optional> |
true |
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) |
- Source:
async CreateSignedToken({libraryIdoptional,objectIdoptional,versionHashoptional,policyIdoptional,subjectoptional,grantType,duration,allowDecryption,contextoptional})
Issue a self-signed authorization token
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
libraryId |
string |
<optional> |
Library ID to authorize |
|
objectId |
string |
<optional> |
Object ID to authorize |
|
versionHash |
string |
<optional> |
Version hash to authorize |
|
policyId |
string |
<optional> |
The object ID of the policy for this token |
|
subject |
string |
<optional> |
The subject of the token |
|
grantType |
string | read |
Permissions to grant for this token. Options: "access", "read", "create", "update", "read-crypt" |
|
duration |
number |
Time until the token expires, in milliseconds (1 hour = 60 * 60 * 1000 = 3600000) |
||
allowDecryption |
boolean | false |
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 |
|
context |
Object |
<optional> |
Additional JSON context |
- Source:
CurrentAccountAddress() → string
Get the account address of the current signer
- Source:
async DecryptECIES({message}) → Promise.<(string|Object)>
Decrypt the given encrypted message with the current signer's private key
Parameters:
Name | Type | Description |
---|---|---|
message |
string |
The message to decrypt |
- Source:
async EncryptECIES({message,publicKeyoptional}) → Promise.<string>
Encrypt the given string or object with the current signer's public key
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string | Object |
The string or object to encrypt |
|
publicKey |
string |
<optional> |
If specified, message will be encrypted with this public key instead of the current user's |
- Source:
GenerateWallet() → ElvWallet
Generate a new ElvWallet that is connected to the client's provider
Example
GenerateWallet(); { "provider": { "ready": "<Promise>", "_lastBlockNumber": -2, "_balances": {}, "_events": [], "_pollingInterval": 500, "_emitted": { "block": -2 }, "_fastQueryDate": 1615320562568, "connection": { "url": "https://host-34-65-65-227.testv2.contentfabric.io/eth/" }, "getCode": "<function>", "_network": { "chainId": 955203, "name": "unknown" }, "_fastBlockNumberPromise": "<Promise>", "_fastBlockNumber": 203392 }, "signers": {} }
- Source:
NetworkInfo() → Object
Return information about how the client was connected to the network
- Source:
async 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
Parameters:
Name | Type | Description |
---|---|---|
region |
string |
Region from which to retrieve the node ID |
- Source:
Nodes() → Promise.<Object>
Retrieve the fabric, ethereum, auth service, and search nodes currently used by the client, in preference order
- Source:
async Request(url,formatoptional,methodoptional,bodyoptional,headersoptional) → Promise.<*>
Request the specified URL with the given method and body, and return the result in the specified format
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
string |
URL to request |
||
format |
string |
<optional> |
"json" |
Format of response |
method |
string |
<optional> |
"GET" |
Request method |
body |
object |
<optional> |
Request body |
|
headers |
object |
<optional> |
Request headers |
- Source:
async 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
- Source:
SetNodes({fabricURIsoptional,ethereumURIsoptional,authServiceURIsoptional,searchURIsoptional})
Set the client to use the specified fabric, ethereum, auth service, and search nodes, in preference order
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fabricURIs |
Array.<string> |
<optional> |
A list of URLs for the fabric, in preference order |
ethereumURIs |
Array.<string> |
<optional> |
A list of URLs for the blockchain, in preference order |
authServiceURIs |
Array.<string> |
<optional> |
A list of URLs for the auth service, in preference order |
searchURIs |
Array.<string> |
<optional> |
A list of URLs for the search nodes, in preference order |
Examples
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io/", "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
SetNodes({ "fabricURIs": [ "https://host-34-105-49-255.testv2.contentfabric.io", "https://host-34-65-65-227.testv2.contentfabric.io" ] }); <No Return Value>
- Source:
async SetOauthToken({token})
Set the OAuth token for use in state channel calls
Parameters:
Name | Type | Description |
---|---|---|
token |
string |
The OAuth ID token |
- Source:
async 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:
Name | Type | Description |
---|---|---|
objectId |
string |
The ID of the policy object |
- Source:
async SetRemoteSigner({idTokenoptional,authTokenoptional,tenantIdoptional,extraDataoptional,signerURIsoptional,unsignedPublicAuthoptional})
Set signer using OAuth ID token
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
idToken |
string |
<optional> |
OAuth ID token |
|
authToken |
string |
<optional> |
Eluvio authorization token previously issued from OAuth ID token |
|
tenantId |
string |
<optional> |
If specified, user will be associated with the tenant |
|
extraData |
Object |
<optional> |
Additional data to pass to the login API |
|
signerURIs |
Array.<string> |
<optional> |
(Only if using custom OAuth) - URIs corresponding to the key server(s) to use |
|
unsignedPublicAuth |
boolean |
<optional> |
false |
If specified, the client will use an unsigned static token for calls that don't require authorization (reduces remote signature calls) |
- Source:
SetSigner({signer})
Set the signer for this client to use for blockchain transactions
Parameters:
Name | Type | Description |
---|---|---|
signer |
object |
The ethers.js signer object |
- Source:
async 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:
Name | Type | Description |
---|---|---|
token |
string |
The OAuth ID |
- Source:
async SetSignerFromWeb3Provider({provider})
Set the signer for this client to use for blockchain transactions from an existing web3 provider. Useful for integrating with MetaMask
Parameters:
Name | Type | Description |
---|---|---|
provider |
object |
The web3 provider object |
- Source:
SetStaticToken({tokenoptional})
Set a static token for the client to use for all authorization
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
token |
string |
<optional> |
The static token to use. If not provided, the default static token will be set. |
- Source:
async Sign(string) → Promise.<string>
Create a signature for the specified string
Parameters:
Name | Type | Description |
---|---|---|
string |
string |
The string to sign |
- Source:
ToggleLogging(enable,optionsoptional)
Enable or disable verbose logging
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enable |
boolean |
Set logging |
|
options |
Object |
<optional> |
Additional options for customizing logging
|
- Source:
async UseRegion({region}) → Promise.<Object>
Update fabric URLs to prefer the specified region.
Note: Client must have been initialized with FromConfigurationUrl or FromNetworkName
Parameters:
Name | Type | Description |
---|---|---|
region |
string |
Preferred region - the fabric will auto-detect the best region if not specified
|
- Source:
async, static Configuration({configUrl,kmsUrls,regionoptional,clientIPoptional}) → Promise.<Object>
Retrieve content space info and preferred fabric and blockchain URLs from the fabric
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
configUrl |
string |
Full URL to the config endpoint |
|
kmsUrls |
Array.<string> |
List of KMS urls to use for OAuth authentication |
|
region |
string |
<optional> |
Preferred region - the fabric will auto-detect the best region if not specified
|
clientIP |
string |
<optional> |
IP address to use in determining the region to use |
- Source:
async, static FromConfigurationUrl({configUrl,regionoptional,clientIPoptional,trustAuthorityIdoptional,staticTokenoptional,ethereumContractTimeoutoptional,noAuthoptional}) → Promise.<ElvClient>
Create a new ElvClient from the specified configuration URL
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
configUrl |
string |
Full URL to the config endpoint |
||
region |
string |
<optional> |
Preferred region - the fabric will auto-detect the best region if not specified
|
|
clientIP |
string |
<optional> |
IP address to use in determining the region to use |
|
trustAuthorityId |
string |
<optional> |
(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 |
<optional> |
Static token that will be used for all authorization in place of normal auth |
|
ethereumContractTimeout |
number |
<optional> |
10 |
Number of seconds to wait for contract calls |
noAuth |
boolean |
<optional> |
false |
If enabled, blockchain authorization will not be performed |
- Source:
async, static FromNetworkName({networkName,regionoptional,clientIPoptional,trustAuthorityIdoptional,staticTokenoptional,ethereumContractTimeoutoptional,noAuthoptional}) → Promise.<ElvClient>
Create a new ElvClient for the specified network
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
networkName |
string |
Name of the network to connect to ("main", "demo", "test) |
||
region |
string |
<optional> |
Preferred region - the fabric will auto-detect the best region if not specified
|
|
clientIP |
string |
<optional> |
IP address to use in determining the region to use |
|
trustAuthorityId |
string |
<optional> |
(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 |
<optional> |
Static token that will be used for all authorization in place of normal auth |
|
ethereumContractTimeout |
number |
<optional> |
10 |
Number of seconds to wait for contract calls |
noAuth |
boolean |
<optional> |
false |
If enabled, blockchain authorization will not be performed |
- Source: