Reference / Modules / client / LogionClient
Class: LogionClient
client.LogionClient
An instance of LogionClient is connected to a Logion network and interacts with all its components (including the blockchain).
It features:
- Access to LGNT balance, transactions and transfer
- LOC management
- Account protection and recovery
- A vault (multisig)
Table of contents
Constructors
Properties
Accessors
- allLegalOfficers
- authenticatedCurrentAccount
- config
- currentAccount
- directoryClient
- invitedContributor
- legalOfficers
- logionApi
- networkState
- public
- sponsorship
- token
- tokens
- voter
Methods
- authenticate
- balanceState
- buildAxios
- buildMultiSourceHttpClient
- disconnect
- ensureConnected
- getLegalOfficer
- isLegalOfficer
- isProtected
- isRegisteredLegalOfficer
- isTokenValid
- isValidAddress
- locsState
- logout
- protectionState
- refreshLegalOfficers
- refreshTokens
- sponsorshipState
- updateNetworkState
- useTokens
- withCurrentAccount
- create
Constructors
constructor
• new LogionClient(sharedState): LogionClient
Parameters
| Name | Type |
|---|---|
sharedState | SharedState |
Returns
Defined in
packages/client/src/LogionClient.ts:69
Properties
_invitedContributor
• Private Readonly _invitedContributor: InvitedContributorApi
Defined in
packages/client/src/LogionClient.ts:82
_public
• Private _public: PublicApi
Defined in
packages/client/src/LogionClient.ts:78
_voter
• Private _voter: VoterApi
Defined in
packages/client/src/LogionClient.ts:80
sharedState
• Private sharedState: SharedState
Defined in
packages/client/src/LogionClient.ts:76
Accessors
allLegalOfficers
• get allLegalOfficers(): LegalOfficerClass[]
All legal officers, including the inactive (i.e. not attached to any node) ones.
Returns
Defined in
packages/client/src/LogionClient.ts:133
authenticatedCurrentAccount
• get authenticatedCurrentAccount(): ValidAccountId
The current account if authenticated (see authenticate). Throws an error otherwise.
Returns
ValidAccountId
Defined in
packages/client/src/LogionClient.ts:101
config
• get config(): LogionClientConfig
The configuration of this client.
Returns
Defined in
packages/client/src/LogionClient.ts:87
currentAccount
• get currentAccount(): undefined | ValidAccountId
The current account used to query data and sign extrinsics.
Returns
undefined | ValidAccountId
Defined in
packages/client/src/LogionClient.ts:94
directoryClient
• get directoryClient(): DirectoryClient
An instance of Directory client.
Returns
Defined in
packages/client/src/LogionClient.ts:119
invitedContributor
• get invitedContributor(): InvitedContributorApi
Invited contributors tools.
Returns
An instance of InvitedContributorApi
Defined in
packages/client/src/LogionClient.ts:501
legalOfficers
• get legalOfficers(): LegalOfficerClass[]
The available legal officers.
Returns
Defined in
packages/client/src/LogionClient.ts:126
logionApi
• get logionApi(): LogionNodeApiClass
An instance of Logion chain's client.
Returns
LogionNodeApiClass
Defined in
packages/client/src/LogionClient.ts:140
networkState
• get networkState(): NetworkState<LegalOfficerEndpoint>
Logion network's state (nodes up and down).
Returns
NetworkState<LegalOfficerEndpoint>
Defined in
packages/client/src/LogionClient.ts:430
public
• get public(): PublicApi
Queries which do not require authentication.
Returns
An instance of PublicApi
Defined in
packages/client/src/LogionClient.ts:483
sponsorship
• get sponsorship(): SponsorshipApi
Sponsors tools.
Returns
An instance of SponsorshipApi
Defined in
packages/client/src/LogionClient.ts:520
token
• get token(): undefined | Token
Returns
undefined | Token
Defined in
packages/client/src/LogionClient.ts:258
tokens
• get tokens(): AccountTokens
The JWT tokens attached to authenticated accounts.
Returns
Defined in
packages/client/src/LogionClient.ts:112
voter
• get voter(): VoterApi
Voters tools.
Returns
An instance of VoterApi
Defined in
packages/client/src/LogionClient.ts:492
Methods
authenticate
▸ authenticate(accounts, signer): Promise<LogionClient>
Authenticates the set of provided addresses. Authentication consists in getting a JWT token for each address. A valid JWT token is sent back by a Logion node if the client was able to sign a random challenge, hence proving that provided signer is indeed able to sign using provided addresses.
Note that the signer may be able to sign for more addresses than the once provided. A call to this method will merge the retrieved tokens with the ones already available. Older tokens are replaced.
Parameters
| Name | Type | Description |
|---|---|---|
accounts | ValidAccountId[] | The addresses for which an authentication token must be retrieved. |
signer | RawSigner | The signer that will sign the challenge. |
Returns
Promise<LogionClient>
An instance of client with retrived JWT tokens.
Defined in
packages/client/src/LogionClient.ts:307
balanceState
▸ balanceState(): Promise<BalanceState>
Builds a new instance of BalanceState for to current address.
Returns
Promise<BalanceState>
An instance of BalanceState
Defined in
packages/client/src/LogionClient.ts:438
buildAxios
▸ buildAxios(legalOfficer): AxiosInstance
Builds an axios instance enabling direct access to a legal officer's node REST API.
Parameters
| Name | Type | Description |
|---|---|---|
legalOfficer | LegalOfficer | The legal officer |
Returns
AxiosInstance
The axios instance
Deprecated
use LegalOfficerClass.buildAxiosToNode() instead
Defined in
packages/client/src/LogionClient.ts:368
buildMultiSourceHttpClient
▸ buildMultiSourceHttpClient(): MultiSourceHttpClient<LegalOfficerEndpoint>
Builds an instance of MultiSourceHttpClient that will connect to all legal officer nodes.
Returns
MultiSourceHttpClient<LegalOfficerEndpoint>
An instance of MultiSourceHttpClient
Defined in
packages/client/src/LogionClient.ts:387
disconnect
▸ disconnect(): Promise<void>
Disconnects the client from the Logion blockchain.
Returns
Promise<void>
Defined in
packages/client/src/LogionClient.ts:510
ensureConnected
▸ ensureConnected(): void
Returns
void
Defined in
packages/client/src/LogionClient.ts:160
getLegalOfficer
▸ getLegalOfficer(accountId): LegalOfficerClass
Gets the LegalOfficerClass associated with provided account. Will throw an error if no legal officer is linked to the account.
Parameters
| Name | Type | Description |
|---|---|---|
accountId | ValidAccountId | A Polkadot account. |
Returns
An instance of LegalOfficerClass
Defined in
packages/client/src/LogionClient.ts:342
isLegalOfficer
▸ isLegalOfficer(accountId): boolean
Tells if a given address is associated with a legal officer.
Parameters
| Name | Type | Description |
|---|---|---|
accountId | ValidAccountId | An SS58 Polkadot address. |
Returns
boolean
True if the provided address is linked to a legal officer, false otherwise.
Defined in
packages/client/src/LogionClient.ts:331
isProtected
▸ isProtected(accountId): Promise<boolean>
Queries the blockchain to tell if provided address is protected (see ProtectionState).
Parameters
| Name | Type | Description |
|---|---|---|
accountId | ValidAccountId | An SS58 Polkadot address. |
Returns
Promise<boolean>
True if the address is protected, false otherwise.
Defined in
packages/client/src/LogionClient.ts:454
isRegisteredLegalOfficer
▸ isRegisteredLegalOfficer(accountId): Promise<boolean>
Queries Logion blockchain to check if a given address is attached to a legal officer.
Parameters
| Name | Type | Description |
|---|---|---|
accountId | ValidAccountId | A Polkadot account. |
Returns
Promise<boolean>
True if provided account is attached to a legal officer.
Defined in
packages/client/src/LogionClient.ts:355
isTokenValid
▸ isTokenValid(now): boolean
Checks if the authentication token attached to current address is still valid (i.e. did not expire).
Parameters
| Name | Type | Description |
|---|---|---|
now | DateTime | Current time. |
Returns
boolean
True if the token did not yet expire, false if it did.
Defined in
packages/client/src/LogionClient.ts:289
isValidAddress
▸ isValidAddress(address): boolean
Tells if provided address is a valid Polkadot address.
Parameters
| Name | Type | Description |
|---|---|---|
address | string | A string that may or may not represent a valid Polkadot address. |
Returns
boolean
True if the address is valid, false otherwise.
Defined in
packages/client/src/LogionClient.ts:465
locsState
▸ locsState(params?): Promise<LocsState>
An instance of LocsState for current address.
Parameters
| Name | Type | Description |
|---|---|---|
params? | FetchAllLocsParams | Some optional spec to further control which LOCs will be fetched. Leave undefined unless you now what you do. |
Returns
Promise<LocsState>
An instance of LocsState
Defined in
packages/client/src/LogionClient.ts:474
logout
▸ logout(): LogionClient
Clears all authentication data (i.e. JWT tokens).
Returns
A client instance with no authentication data.
Defined in
packages/client/src/LogionClient.ts:243
protectionState
▸ protectionState(): Promise<ProtectionState>
The protection state attached to current address.
Returns
Promise<ProtectionState>
An instance of ProtectionState
Defined in
packages/client/src/LogionClient.ts:270
refreshLegalOfficers
▸ refreshLegalOfficers(sharedState, token?): SharedState
Parameters
| Name | Type |
|---|---|
sharedState | SharedState |
token? | string |
Returns
Defined in
packages/client/src/LogionClient.ts:197
refreshTokens
▸ refreshTokens(now, threshold?): Promise<LogionClient>
Postpones the expiration of valid (see isTokenValid) JWT tokens.
Parameters
| Name | Type | Description |
|---|---|---|
now | DateTime | Current time, used to check if tokens are still valid or not. |
threshold? | DurationLike | If at least one token's expiration falls between now and (now + threshold), then tokens are refreshed. Otherwise, they are not. |
Returns
Promise<LogionClient>
An authenticated client using refreshed tokens or this if no refresh occured.
Defined in
packages/client/src/LogionClient.ts:173
sponsorshipState
▸ sponsorshipState(sponsorshipId): Promise<SponsorshipState>
Sponsorship state.
Parameters
| Name | Type |
|---|---|
sponsorshipId | UUID |
Returns
Promise<SponsorshipState>
An instance of SponsorshipState
Defined in
packages/client/src/LogionClient.ts:532
updateNetworkState
▸ updateNetworkState(multiSourceClient): LogionClient
Updates network state given the an instance of MultiSourceHttpClient that interacted with the Logion network.
Parameters
| Name | Type | Description |
|---|---|---|
multiSourceClient | MultiSourceHttpClient<LegalOfficerEndpoint> | an instance of MultiSourceHttpClient. |
Returns
An instance of LogionClient with an updated network state.
Defined in
packages/client/src/LogionClient.ts:407
useTokens
▸ useTokens(tokens): LogionClient
Overrides current tokens.
Parameters
| Name | Type | Description |
|---|---|---|
tokens | AccountTokens | The new tokens. |
Returns
A copy of this client, but using the new tokens.
Defined in
packages/client/src/LogionClient.ts:150
withCurrentAccount
▸ withCurrentAccount(currentAccount?): LogionClient
Sets current account.
Parameters
| Name | Type | Description |
|---|---|---|
currentAccount? | ValidAccountId | The account to use as current. |
Returns
A client instance with provided current account.
Defined in
packages/client/src/LogionClient.ts:213
create
▸ create(config): Promise<LogionClient>
Instantiates a connected client.
Parameters
| Name | Type | Description |
|---|---|---|
config | LogionClientConfig | Parameters of a connection to the Logion network. |
Returns
Promise<LogionClient>
A connected client.