🔐Auth

Introduction

To request the token, network, and other interface data for deposit and withdrawal services, you need to mount the authorization token to the HTTP request header.

How to use

For the configuration items used in the following examples, please refer to:

📃Configuration

Installation

📥Installation
npm install @etransfer/core
# OR
yarn add @etransfer/core

Usage

First, init the ETransferCore instance. You can find it in ETransfer SDK Quick Start.

Get the authorization token from the interface, and cache the data.

After getting the token, mount it to the request header and set it to storage.

Example

import { eTransferCore } from '@etransfer/core';

eTransferCore.setAuthUrl('etransfer auth url');
const token = await eTransferCore.getAuthTokenFromApi(methodParameters);

Method Parameters

FieldTypeRequiredRemarks

pubkey

string

true

user account pubkey

plain_text

string

true

signed text

The signature text can be customized, but it must end with a timestamp. For example: Nonce:<current timestamp>

signature

string

true

user signature

version

PortkeyVersion

true

Portkey version: 'v1' | 'v2'. Recommend using v2

source

AuthTokenSource

true

Wallet type: 'portkey' | 'nightElf'

ca_hash

string

false

user ca hash

If source='portkey', you must set this parameter.

chain_id

ChainId

false

'AELF' | 'tDVV'

If source='portkey', you must set this parameter.

managerAddress

string

false

user manager address.

recaptchaToken

string

false

Recaptcha result.

If source='portkey', you do not need to set this parameter.

If source='nightElf', you need to query the interface etransferCore.services.checkEOARegistration first. If it returns true, you do not need to set this parameter; if it returns false, set the obtained verification result through human-machine verification.

You can directly call the etransferCore.getReCaptcha method to help you quickly implement the above logic.

Method return value

FieldTypeRemarks

token

string

The authorization token.

Get the authorization token from the storage or interface, and cache the data.

Get data from the cache first. If the data in the storage has expired, it will get a new token from the interface.After getting the token, mount it to the request header and set it to storage.

Example

import { eTransferCore } from '@etransfer/core';

eTransferCore.setAuthUrl('etransfer auth url');
const token = await eTransferCore.getAuthToken(methodParameters);

Method Parameters

FieldTypeRequiredRemarks

pubkey

string

true

user account pubkey

plainText

string

true

signed text

The signature text can be customized, but it must end with a timestamp. For example: Nonce:<current timestamp>

signature

string

true

user signature

version

PortkeyVersion

true

Portkey version: 'v1' | 'v2'. Recommend using v2

managerAddress

string

true

user manager address

caHash

string

true

user ca hash If source='portkey', you must set this parameter.

chainId

ChainId

true

'AELF' | 'tDVV' If source='portkey', you must set this parameter.

source

AuthTokenSource

false

Wallet type: 'portkey' | 'nightElf'Default is 'portkey'

recaptchaToken

string

false

Recaptcha result.

If source='portkey', you do not need to set this parameter.

If source='nightElf', you need to query the interface etransferCore.services.checkEOARegistration first. If it returns true, you do not need to set this parameter; if it returns false, set the obtained verification result through human-machine verification.

You can directly call the etransferCore.getReCaptcha method to help you quickly implement the above logic.

Method return value

FieldTypeRemarks

token

string

The authorization token.

Get the authorization token from the storage.

The premise is that authorization token has been obtained from the interface before.

If the authorization token is expired, return undefined.

Example

import { eTransferCore } from '@etransfer/core';

const token = await eTransferCore.getAuthTokenFromStorage(methodParameters);

Method Parameters

FieldTypeRequiredRemarks

walletType

TWalletType

true

'portkey' | 'nightElf'

managerAddress

string

true

user manager address

caHash

string

false

user ca hash. If walletType='portkey', you should set user's caHash. If walletType='nightElf', you can not set this parameter, and storage key = 'nightElf'+managerAddress

Method return value

FieldTypeRemarks

token

string | undefined

The authorization token.

Only getting authorization tokens from the interface.

Get a new token without any additional business logic.

Example

import { eTransferCore } from '@etransfer/core';

const result = await eTransferCore.services.getAuthToken(methodParameters, { baseURL: 'etransfer auth url' });

// Combination token
const token = result.token_type + result.access_token;

// Token expiration time, unit is seconds
const tokenExpired = result.expires_in;

Method Parameters

FieldTypeRequiredRemarks

pubkey

string

true

user account pubkey

plain_text

string

true

signed text. The signature text can be customized, but it must end with a timestamp. For example: Nonce:<current timestamp>

signature

string

true

user signature

version

PortkeyVersion

true

Portkey version: 'v1' | 'v2'. Recommend using v2

managerAddress

string

true

user manager address

source

AuthTokenSource

true

Wallet type: 'portkey' | 'nightElf'

ca_hash

string

false

user ca hash.

If source='portkey', you must set this parameter.

chain_id

ChainId

false

'AELF' | 'tDVV'.

If source='portkey', you must set this parameter.

recaptchaToken

string

false

Recaptcha result.

If source='portkey', you do not need to set this parameter.

If source='nightElf', you need to query the interface etransferCore.services.checkEOARegistration first. If it returns true, you do not need to set this parameter; if it returns false, set the obtained verification result through human-machine verification.

You can directly call the etransferCore.getReCaptcha method to help you quickly implement the above logic

Method return value

FieldTypeRemarks

token_type

string

The return token type, such as Bearer.

access_token

string

The return token body.

expires_in

number

Token expiration time, unit is seconds.

Last updated