@toruslabs/ethereum-controllers 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ethereumControllers.cjs.js +6153 -0
- package/dist/ethereumControllers.cjs.js.map +1 -0
- package/dist/ethereumControllers.esm.js +5570 -0
- package/dist/ethereumControllers.esm.js.map +1 -0
- package/dist/ethereumControllers.umd.min.js +3 -0
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +38 -0
- package/dist/ethereumControllers.umd.min.js.map +1 -0
- package/dist/types/Account/AccountTrackerController.d.ts +35 -0
- package/dist/types/Block/PollingBlockTracker.d.ts +14 -0
- package/dist/types/Currency/CurrencyController.d.ts +30 -0
- package/dist/types/Gas/GasFeeController.d.ts +64 -0
- package/dist/types/Gas/IGasFeeController.d.ts +49 -0
- package/dist/types/Gas/gasUtil.d.ts +21 -0
- package/dist/types/Keyring/KeyringController.d.ts +20 -0
- package/dist/types/Message/AbstractMessageController.d.ts +36 -0
- package/dist/types/Message/DecryptMessageController.d.ts +20 -0
- package/dist/types/Message/EncryptionPublicKeyController.d.ts +20 -0
- package/dist/types/Message/MessageController.d.ts +20 -0
- package/dist/types/Message/PersonalMessageController.d.ts +20 -0
- package/dist/types/Message/TypedMessageController.d.ts +21 -0
- package/dist/types/Message/utils.d.ts +10 -0
- package/dist/types/Network/NetworkController.d.ts +40 -0
- package/dist/types/Network/createEthereumMiddleware.d.ts +66 -0
- package/dist/types/Network/createJsonRpcClient.d.ts +9 -0
- package/dist/types/Nfts/INftsController.d.ts +10 -0
- package/dist/types/Nfts/NftHandler.d.ts +35 -0
- package/dist/types/Nfts/NftsController.d.ts +40 -0
- package/dist/types/Preferences/PreferencesController.d.ts +53 -0
- package/dist/types/Tokens/ITokensController.d.ts +10 -0
- package/dist/types/Tokens/TokenHandler.d.ts +20 -0
- package/dist/types/Tokens/TokenRatesController.d.ts +42 -0
- package/dist/types/Tokens/TokensController.d.ts +42 -0
- package/dist/types/Transaction/NonceTracker.d.ts +37 -0
- package/dist/types/Transaction/PendingTransactionTracker.d.ts +32 -0
- package/dist/types/Transaction/TransactionController.d.ts +67 -0
- package/dist/types/Transaction/TransactionGasUtil.d.ts +21 -0
- package/dist/types/Transaction/TransactionStateHistoryHelper.d.ts +16 -0
- package/dist/types/Transaction/TransactionStateManager.d.ts +30 -0
- package/dist/types/Transaction/TransactionUtils.d.ts +70 -0
- package/dist/types/index.d.ts +43 -0
- package/dist/types/utils/abiDecoder.d.ts +17 -0
- package/dist/types/utils/abis.d.ts +84 -0
- package/dist/types/utils/constants.d.ts +81 -0
- package/dist/types/utils/contractAddresses.d.ts +1 -0
- package/dist/types/utils/conversionUtils.d.ts +42 -0
- package/dist/types/utils/helpers.d.ts +24 -0
- package/dist/types/utils/interfaces.d.ts +384 -0
- package/package.json +71 -0
- package/src/Account/AccountTrackerController.ts +157 -0
- package/src/Block/PollingBlockTracker.ts +89 -0
- package/src/Currency/CurrencyController.ts +117 -0
- package/src/Gas/GasFeeController.ts +254 -0
- package/src/Gas/IGasFeeController.ts +56 -0
- package/src/Gas/gasUtil.ts +163 -0
- package/src/Keyring/KeyringController.ts +118 -0
- package/src/Message/AbstractMessageController.ts +136 -0
- package/src/Message/DecryptMessageController.ts +81 -0
- package/src/Message/EncryptionPublicKeyController.ts +83 -0
- package/src/Message/MessageController.ts +74 -0
- package/src/Message/PersonalMessageController.ts +74 -0
- package/src/Message/TypedMessageController.ts +112 -0
- package/src/Message/utils.ts +107 -0
- package/src/Network/NetworkController.ts +184 -0
- package/src/Network/createEthereumMiddleware.ts +307 -0
- package/src/Network/createJsonRpcClient.ts +59 -0
- package/src/Nfts/INftsController.ts +13 -0
- package/src/Nfts/NftHandler.ts +191 -0
- package/src/Nfts/NftsController.ts +230 -0
- package/src/Preferences/PreferencesController.ts +409 -0
- package/src/Tokens/ITokensController.ts +13 -0
- package/src/Tokens/TokenHandler.ts +60 -0
- package/src/Tokens/TokenRatesController.ts +134 -0
- package/src/Tokens/TokensController.ts +278 -0
- package/src/Transaction/NonceTracker.ts +152 -0
- package/src/Transaction/PendingTransactionTracker.ts +235 -0
- package/src/Transaction/TransactionController.ts +558 -0
- package/src/Transaction/TransactionGasUtil.ts +74 -0
- package/src/Transaction/TransactionStateHistoryHelper.ts +41 -0
- package/src/Transaction/TransactionStateManager.ts +315 -0
- package/src/Transaction/TransactionUtils.ts +333 -0
- package/src/index.ts +45 -0
- package/src/utils/abiDecoder.ts +195 -0
- package/src/utils/abis.ts +677 -0
- package/src/utils/constants.ts +379 -0
- package/src/utils/contractAddresses.ts +21 -0
- package/src/utils/conversionUtils.ts +269 -0
- package/src/utils/helpers.ts +177 -0
- package/src/utils/interfaces.ts +454 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AccountTrackerConfig, AccountTrackerState, BaseController, IAccountTrackerController, PreferencesState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { EthereumBlock, ExtendedAddressPreferences } from "../utils/interfaces";
|
|
6
|
+
interface AccountTrackerControllerOptions {
|
|
7
|
+
config: AccountTrackerConfig<EthereumBlock>;
|
|
8
|
+
state: Partial<AccountTrackerState>;
|
|
9
|
+
provider: SafeEventEmitterProvider;
|
|
10
|
+
blockTracker?: PollingBlockTracker;
|
|
11
|
+
getIdentities: () => PreferencesState<ExtendedAddressPreferences>["identities"];
|
|
12
|
+
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
13
|
+
getCurrentChainId: NetworkController["getNetworkIdentifier"];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Tracks accounts based on blocks.
|
|
17
|
+
* If block tracker provides latest block, we query accounts from it.
|
|
18
|
+
* Preferences state changes also retrigger accounts update.
|
|
19
|
+
* Network state changes also retrigger accounts update.
|
|
20
|
+
*/
|
|
21
|
+
declare class AccountTrackerController extends BaseController<AccountTrackerConfig<EthereumBlock>, AccountTrackerState> implements IAccountTrackerController<AccountTrackerConfig<EthereumBlock>, AccountTrackerState> {
|
|
22
|
+
private provider;
|
|
23
|
+
private blockTracker;
|
|
24
|
+
private mutex;
|
|
25
|
+
private ethersProvider;
|
|
26
|
+
private getIdentities;
|
|
27
|
+
private getCurrentChainId;
|
|
28
|
+
constructor({ config, state, provider, blockTracker, getIdentities, onPreferencesStateChange, getCurrentChainId, }: AccountTrackerControllerOptions);
|
|
29
|
+
syncAccounts(): boolean;
|
|
30
|
+
refresh(): Promise<void>;
|
|
31
|
+
private _updateAccounts;
|
|
32
|
+
private _updateAccount;
|
|
33
|
+
private _updateAccountsViaBalanceChecker;
|
|
34
|
+
}
|
|
35
|
+
export default AccountTrackerController;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseBlockTracker, PollingBlockTrackerConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { EthereumBlock, PollingBlockTrackerState } from "../utils/interfaces";
|
|
3
|
+
declare class PollingBlockTracker extends BaseBlockTracker<EthereumBlock, PollingBlockTrackerConfig, PollingBlockTrackerState> {
|
|
4
|
+
constructor({ config, state }: {
|
|
5
|
+
config: Partial<PollingBlockTrackerConfig>;
|
|
6
|
+
state: Partial<PollingBlockTrackerState>;
|
|
7
|
+
});
|
|
8
|
+
checkForLatestBlock(): Promise<EthereumBlock>;
|
|
9
|
+
protected _start(): void;
|
|
10
|
+
private _synchronize;
|
|
11
|
+
private _updateLatestBlock;
|
|
12
|
+
private _fetchLatestBlock;
|
|
13
|
+
}
|
|
14
|
+
export default PollingBlockTracker;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseCurrencyController, BaseCurrencyControllerConfig, BaseCurrencyControllerState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { EthereumNetworkState } from "../utils/interfaces";
|
|
3
|
+
export interface IEthereumCurrencyControllerState extends BaseCurrencyControllerState {
|
|
4
|
+
commonDenomination: string;
|
|
5
|
+
commonDenominatorPrice: number;
|
|
6
|
+
}
|
|
7
|
+
export default class CurrencyController extends BaseCurrencyController<BaseCurrencyControllerConfig, IEthereumCurrencyControllerState> {
|
|
8
|
+
private conversionInterval;
|
|
9
|
+
constructor({ config, state, onNetworkChanged, }: {
|
|
10
|
+
config: Partial<BaseCurrencyControllerConfig>;
|
|
11
|
+
state: Partial<IEthereumCurrencyControllerState>;
|
|
12
|
+
onNetworkChanged: (listener: (networkState: EthereumNetworkState) => void) => void;
|
|
13
|
+
});
|
|
14
|
+
setCommonDenomination(commonDenomination: string): void;
|
|
15
|
+
getCommonDenomination(): string;
|
|
16
|
+
setCommonDenominatorPrice(commonDenominatorPrice: number): void;
|
|
17
|
+
getCommonDenominatorPrice(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is
|
|
20
|
+
* stored at the controller's conversionInterval property. If it is called and such an id already exists, the
|
|
21
|
+
* previous interval is clear and a new one is created.
|
|
22
|
+
*/
|
|
23
|
+
scheduleConversionInterval(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Updates the conversionRate and conversionDate properties associated with the currentCurrency. Updated info is
|
|
26
|
+
* fetched from an external API
|
|
27
|
+
*/
|
|
28
|
+
updateConversionRate(): Promise<void>;
|
|
29
|
+
private retrieveConversionRate;
|
|
30
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { BaseController } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import NetworkController from "../Network/NetworkController";
|
|
4
|
+
import { EthereumNetworkState } from "../utils/interfaces";
|
|
5
|
+
import { EthereumGasConfig, EthereumGasFeeEstimates, EthereumGasState, EthereumLegacyGasFeeEstimates } from "./IGasFeeController";
|
|
6
|
+
interface IGasFeeControllerOptions {
|
|
7
|
+
config?: Partial<EthereumGasConfig>;
|
|
8
|
+
state?: Partial<EthereumGasState>;
|
|
9
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
10
|
+
getProvider: NetworkController["getProvider"];
|
|
11
|
+
getCurrentNetworkEIP1559Compatibility: NetworkController["getEIP1559Compatibility"];
|
|
12
|
+
getCurrentAccountEIP1559Compatibility: (address: string) => boolean;
|
|
13
|
+
getCurrentNetworkLegacyGasAPICompatibility: () => boolean;
|
|
14
|
+
fetchGasEstimates?: (url: string) => Promise<EthereumGasFeeEstimates>;
|
|
15
|
+
fetchEthGasPriceEstimate?: (provider: SafeEventEmitterProvider) => Promise<{
|
|
16
|
+
gasPrice: string;
|
|
17
|
+
}>;
|
|
18
|
+
fetchLegacyGasPriceEstimates?: (url: string) => Promise<EthereumLegacyGasFeeEstimates>;
|
|
19
|
+
fetchGasEstimatesViaEthFeeHistory?: (provider: SafeEventEmitterProvider) => Promise<EthereumGasFeeEstimates>;
|
|
20
|
+
onNetworkStateChange: (listener: (networkState: EthereumNetworkState) => void) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns gas prices in dec gwei
|
|
24
|
+
*/
|
|
25
|
+
export default class GasFeeController extends BaseController<EthereumGasConfig, EthereumGasState> {
|
|
26
|
+
name: string;
|
|
27
|
+
private intervalId;
|
|
28
|
+
private provider;
|
|
29
|
+
private currentChainId;
|
|
30
|
+
private getNetworkIdentifier;
|
|
31
|
+
private getProvider;
|
|
32
|
+
private fetchGasEstimates;
|
|
33
|
+
private fetchGasEstimatesViaEthFeeHistory;
|
|
34
|
+
private fetchEthGasPriceEstimate;
|
|
35
|
+
private fetchLegacyGasPriceEstimates;
|
|
36
|
+
private getCurrentNetworkEIP1559Compatibility;
|
|
37
|
+
private getCurrentAccountEIP1559Compatibility;
|
|
38
|
+
private getCurrentNetworkLegacyGasAPICompatibility;
|
|
39
|
+
constructor({ config, state, getNetworkIdentifier, getProvider, fetchGasEstimates, fetchEthGasPriceEstimate, fetchLegacyGasPriceEstimates, fetchGasEstimatesViaEthFeeHistory, getCurrentNetworkLegacyGasAPICompatibility, getCurrentNetworkEIP1559Compatibility, getCurrentAccountEIP1559Compatibility, onNetworkStateChange, }: IGasFeeControllerOptions);
|
|
40
|
+
onNetworkStateChange(): Promise<void>;
|
|
41
|
+
resetPolling(): Promise<void>;
|
|
42
|
+
fetchGasFeeEstimates(): Promise<EthereumGasState>;
|
|
43
|
+
getGasFeeEstimatesAndStartPolling(): Promise<void>;
|
|
44
|
+
disconnectPoller(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Prepare to discard this controller.
|
|
47
|
+
*
|
|
48
|
+
* This stops any active polling.
|
|
49
|
+
*/
|
|
50
|
+
destroy(): void;
|
|
51
|
+
stopPolling(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Gets and sets gasFeeEstimates in state
|
|
54
|
+
*
|
|
55
|
+
* @returns GasFeeEstimates
|
|
56
|
+
*/
|
|
57
|
+
private _fetchGasFeeEstimateData;
|
|
58
|
+
private _startPolling;
|
|
59
|
+
private _poll;
|
|
60
|
+
private resetState;
|
|
61
|
+
private getEIP1559Compatibility;
|
|
62
|
+
private getTimeEstimate;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BaseConfig, BaseState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { GAS_ESTIMATE_TYPES } from "../utils/constants";
|
|
3
|
+
export type GasFeeTimeBounds = {
|
|
4
|
+
lowerTimeBound?: null | number;
|
|
5
|
+
upperTimeBound?: string | number;
|
|
6
|
+
};
|
|
7
|
+
export type GasFeeEstimates = {
|
|
8
|
+
minWaitTimeEstimate: number;
|
|
9
|
+
maxWaitTimeEstimate: number;
|
|
10
|
+
suggestedMaxPriorityFeePerGas: string;
|
|
11
|
+
suggestedMaxFeePerGas: string;
|
|
12
|
+
};
|
|
13
|
+
export type EthereumGasFeeEstimates = {
|
|
14
|
+
estimatedBaseFee: string;
|
|
15
|
+
low: GasFeeEstimates;
|
|
16
|
+
medium: GasFeeEstimates;
|
|
17
|
+
high: GasFeeEstimates;
|
|
18
|
+
};
|
|
19
|
+
export type EthereumLegacyGasFeeEstimates = {
|
|
20
|
+
low: string;
|
|
21
|
+
medium: string;
|
|
22
|
+
high: string;
|
|
23
|
+
};
|
|
24
|
+
export interface GasEstimatesAPIResponse extends EthereumGasFeeEstimates {
|
|
25
|
+
estimatedBaseFee: string;
|
|
26
|
+
networkCongestion: number;
|
|
27
|
+
latestPriorityFeeRange: string[];
|
|
28
|
+
historicalPriorityFeeRange: string[];
|
|
29
|
+
historicalBaseFeeRange: string[];
|
|
30
|
+
priorityFeeTrend: "up" | "down" | "level";
|
|
31
|
+
baseFeeTrend: "up" | "down" | "level";
|
|
32
|
+
}
|
|
33
|
+
export interface GasEstimatesLegacyAPIResponse {
|
|
34
|
+
SafeGasPrice: string;
|
|
35
|
+
ProposeGasPrice: string;
|
|
36
|
+
FastGasPrice: string;
|
|
37
|
+
}
|
|
38
|
+
export interface EthereumGasConfig extends BaseConfig {
|
|
39
|
+
interval: number;
|
|
40
|
+
legacyAPIEndpoint: string;
|
|
41
|
+
EIP1559APIEndpoint: string;
|
|
42
|
+
}
|
|
43
|
+
export interface EthereumGasState extends BaseState {
|
|
44
|
+
gasFeeEstimates: EthereumGasFeeEstimates | EthereumLegacyGasFeeEstimates | {
|
|
45
|
+
gasPrice?: string;
|
|
46
|
+
};
|
|
47
|
+
estimatedGasFeeTimeBounds: GasFeeTimeBounds;
|
|
48
|
+
gasEstimateType: (typeof GAS_ESTIMATE_TYPES)[keyof typeof GAS_ESTIMATE_TYPES];
|
|
49
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import { EthereumGasFeeEstimates, EthereumLegacyGasFeeEstimates, GasFeeTimeBounds } from "./IGasFeeController";
|
|
4
|
+
export declare function normalizeGWEIDecimalNumbers(n: string | number): number | BigNumber;
|
|
5
|
+
export declare function fetchGasEstimates(url: string): Promise<EthereumGasFeeEstimates>;
|
|
6
|
+
export interface FeeHistoryResponse {
|
|
7
|
+
baseFeePerGas: string[];
|
|
8
|
+
gasUsedRatio: string[];
|
|
9
|
+
oldestBlock: string;
|
|
10
|
+
reward: string[][];
|
|
11
|
+
}
|
|
12
|
+
export declare function fetchGasEstimatesViaEthFeeHistory(provider: SafeEventEmitterProvider): Promise<EthereumGasFeeEstimates>;
|
|
13
|
+
/**
|
|
14
|
+
* Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium
|
|
15
|
+
* high values from that API.
|
|
16
|
+
*/
|
|
17
|
+
export declare function fetchLegacyGasPriceEstimates(url: string): Promise<EthereumLegacyGasFeeEstimates>;
|
|
18
|
+
export declare function fetchEthGasPriceEstimate(provider: SafeEventEmitterProvider): Promise<{
|
|
19
|
+
gasPrice: string;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function calculateTimeEstimate(maxPriorityFeePerGas: string, maxFeePerGas: string, gasFeeEstimates: EthereumGasFeeEstimates): GasFeeTimeBounds;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EthEncryptedData, MessageTypes, SignTypedDataVersion, TypedDataV1, TypedMessage } from "@metamask/eth-sig-util";
|
|
3
|
+
import { BaseConfig, BaseKeyringController, IKeyringController, KeyringControllerState } from "@toruslabs/base-controllers";
|
|
4
|
+
export default class KeyringController extends BaseKeyringController<Partial<BaseConfig>, KeyringControllerState> implements IKeyringController {
|
|
5
|
+
constructor({ config, state }: {
|
|
6
|
+
config: Partial<BaseConfig>;
|
|
7
|
+
state: Partial<KeyringControllerState>;
|
|
8
|
+
});
|
|
9
|
+
signTransaction<T, U>(tx: T, address: string): Promise<U>;
|
|
10
|
+
getAccounts(): string[];
|
|
11
|
+
importAccount(accountPrivateKey: string): string;
|
|
12
|
+
removeAccount(address: string): void;
|
|
13
|
+
getBufferPrivateKey(privateKey: string): Buffer;
|
|
14
|
+
signMessage(data: string, address: string): string;
|
|
15
|
+
signPersonalMessage(data: string, address: string): Promise<string>;
|
|
16
|
+
signTypedData<V extends SignTypedDataVersion, T extends MessageTypes>(typedData: V extends "V1" ? TypedDataV1 : TypedMessage<T>, address: string, version: V): Promise<string>;
|
|
17
|
+
signEncryptionPublicKey(address: string): string;
|
|
18
|
+
decryptMessage(data: EthEncryptedData, address: string): string;
|
|
19
|
+
private _getWalletForAccount;
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
2
|
+
import { BaseConfig, BaseController, BaseState } from "@toruslabs/base-controllers";
|
|
3
|
+
import { JRPCRequest, Json } from "@toruslabs/openlogin-jrpc";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { AbstractMessage, BaseRequestParams, MessageStatusType, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
export interface MessageControllerState<M extends AbstractMessage> extends BaseState {
|
|
7
|
+
unapprovedMessages: Record<string, M>;
|
|
8
|
+
unapprovedMessagesCount: number;
|
|
9
|
+
}
|
|
10
|
+
export default abstract class AbstractMessageController<M extends AbstractMessage, P extends BaseRequestParams> extends BaseController<BaseConfig, MessageControllerState<M>> {
|
|
11
|
+
protected messages: M[];
|
|
12
|
+
protected getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
13
|
+
/**
|
|
14
|
+
* Controller in charge of managing - storing, adding, removing, updating - Messages.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
constructor({ config, state, getNetworkIdentifier, }: {
|
|
18
|
+
config?: Partial<BaseConfig>;
|
|
19
|
+
state?: Partial<MessageControllerState<M>>;
|
|
20
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
21
|
+
});
|
|
22
|
+
getMessage(messageId: string): M;
|
|
23
|
+
getAllMessages(): M[];
|
|
24
|
+
setMetadata(messageId: string, metadata: Json): void;
|
|
25
|
+
getUnapprovedMessages(): {
|
|
26
|
+
[key: string]: M;
|
|
27
|
+
};
|
|
28
|
+
addMessage(message: M): Promise<void>;
|
|
29
|
+
approveMessage(messageParams: P): Promise<P>;
|
|
30
|
+
setMessageStatus(messageId: string, status: MessageStatusType): void;
|
|
31
|
+
waitForFinishStatus(msgParams: P, messageName: string): Promise<string>;
|
|
32
|
+
protected updateMessage(message: M): void;
|
|
33
|
+
protected saveMessageList(): void;
|
|
34
|
+
abstract prepMessageForSigning(messageParams: P): Promise<P>;
|
|
35
|
+
abstract addUnapprovedMessage(messageParams: P, request: JRPCRequest<P> & UserRequestApprovalParams, version?: SignTypedDataVersion): Promise<string>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { DecryptMessage, DecryptMessageParams, Message, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
7
|
+
export declare class DecryptMessageController extends AbstractMessageController<DecryptMessage, DecryptMessageParams> {
|
|
8
|
+
name: string;
|
|
9
|
+
protected decryptMessage: KeyringController["decryptMessage"];
|
|
10
|
+
constructor({ config, state, decryptMessage, getNetworkIdentifier, }: {
|
|
11
|
+
config: Partial<BaseConfig>;
|
|
12
|
+
state: Partial<MessageControllerState<Message>>;
|
|
13
|
+
decryptMessage: KeyringController["decryptMessage"];
|
|
14
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
15
|
+
});
|
|
16
|
+
processDecryptMessage(messageId: string): Promise<string>;
|
|
17
|
+
addNewUnapprovedMessage(messageParams: DecryptMessageParams, req: JRPCRequest<DecryptMessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
18
|
+
addUnapprovedMessage(messageParams: DecryptMessageParams, req?: JRPCRequest<DecryptMessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
19
|
+
prepMessageForSigning(messageParams: DecryptMessageParams): Promise<DecryptMessageParams>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { EncryptionPublicKey, EncryptionPublicKeyParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
7
|
+
export declare class EncryptionPublicKeyController extends AbstractMessageController<EncryptionPublicKey, EncryptionPublicKeyParams> {
|
|
8
|
+
name: string;
|
|
9
|
+
protected signEncryptionPublicKey: KeyringController["signEncryptionPublicKey"];
|
|
10
|
+
constructor({ config, state, signEncryptionPublicKey, getNetworkIdentifier, }: {
|
|
11
|
+
config: Partial<BaseConfig>;
|
|
12
|
+
state: Partial<MessageControllerState<EncryptionPublicKey>>;
|
|
13
|
+
signEncryptionPublicKey: KeyringController["signEncryptionPublicKey"];
|
|
14
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
15
|
+
});
|
|
16
|
+
processGetEncryptionPublicKey(messageId: string): Promise<string>;
|
|
17
|
+
addNewUnapprovedMessage(messageParams: EncryptionPublicKeyParams, req: JRPCRequest<EncryptionPublicKeyParams> & UserRequestApprovalParams): Promise<string>;
|
|
18
|
+
addUnapprovedMessage(messageParams: EncryptionPublicKeyParams, req?: JRPCRequest<EncryptionPublicKeyParams> & UserRequestApprovalParams): Promise<string>;
|
|
19
|
+
prepMessageForSigning(messageParams: EncryptionPublicKeyParams): Promise<EncryptionPublicKeyParams>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { Message, MessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
7
|
+
export declare class MessageController extends AbstractMessageController<Message, MessageParams> {
|
|
8
|
+
name: string;
|
|
9
|
+
protected signMessage: KeyringController["signMessage"];
|
|
10
|
+
constructor({ config, state, signMessage, getNetworkIdentifier, }: {
|
|
11
|
+
config: Partial<BaseConfig>;
|
|
12
|
+
state: Partial<MessageControllerState<Message>>;
|
|
13
|
+
signMessage: KeyringController["signMessage"];
|
|
14
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
15
|
+
});
|
|
16
|
+
processSignMessage(messageId: string): Promise<string>;
|
|
17
|
+
addNewUnapprovedMessage(messageParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
18
|
+
addUnapprovedMessage(messageParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
19
|
+
prepMessageForSigning(messageParams: MessageParams): Promise<MessageParams>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
4
|
+
import NetworkController from "../Network/NetworkController";
|
|
5
|
+
import { Message, MessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
6
|
+
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
7
|
+
export declare class PersonalMessageController extends AbstractMessageController<Message, MessageParams> {
|
|
8
|
+
name: string;
|
|
9
|
+
protected signPersonalMessage: KeyringController["signPersonalMessage"];
|
|
10
|
+
constructor({ config, state, signPersonalMessage, getNetworkIdentifier, }: {
|
|
11
|
+
config: Partial<BaseConfig>;
|
|
12
|
+
state: Partial<MessageControllerState<Message>>;
|
|
13
|
+
signPersonalMessage: KeyringController["signPersonalMessage"];
|
|
14
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
15
|
+
});
|
|
16
|
+
processPersonalSignMessage(messageId: string): Promise<string>;
|
|
17
|
+
addNewUnapprovedMessage(messageParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
18
|
+
addUnapprovedMessage(messageParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams): Promise<string>;
|
|
19
|
+
prepMessageForSigning(messageParams: MessageParams): Promise<MessageParams>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
2
|
+
import { BaseConfig } from "@toruslabs/base-controllers";
|
|
3
|
+
import { JRPCRequest } from "@toruslabs/openlogin-jrpc";
|
|
4
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
5
|
+
import NetworkController from "../Network/NetworkController";
|
|
6
|
+
import { TypedMessage, TypedMessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
7
|
+
import AbstractMessageController, { MessageControllerState } from "./AbstractMessageController";
|
|
8
|
+
export declare class TypedMessageController extends AbstractMessageController<TypedMessage, TypedMessageParams> {
|
|
9
|
+
name: string;
|
|
10
|
+
protected signTypedData: KeyringController["signTypedData"];
|
|
11
|
+
constructor({ config, state, signTypedData, getNetworkIdentifier, }: {
|
|
12
|
+
config: Partial<BaseConfig>;
|
|
13
|
+
state: Partial<MessageControllerState<TypedMessage>>;
|
|
14
|
+
signTypedData: KeyringController["signTypedData"];
|
|
15
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
16
|
+
});
|
|
17
|
+
processPersonalSignMessage(messageId: string): Promise<string>;
|
|
18
|
+
addNewUnapprovedMessage(messageParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams, version: SignTypedDataVersion): Promise<string>;
|
|
19
|
+
addUnapprovedMessage(messageParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams, version: SignTypedDataVersion): Promise<string>;
|
|
20
|
+
prepMessageForSigning(messageParams: TypedMessageParams): Promise<TypedMessageParams>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EthEncryptedData } from "@metamask/eth-sig-util";
|
|
2
|
+
import { DecryptMessageParams, EncryptionPublicKeyParams, MessageParams, TypedMessageParams } from "../utils/interfaces";
|
|
3
|
+
export declare function validateAddress(address: string, propertyName: string): void;
|
|
4
|
+
export declare function validateSignMessageData(messageData: MessageParams): void;
|
|
5
|
+
export declare function normalizeMessageData(data: string): string;
|
|
6
|
+
export declare function validateTypedSignMessageDataV1(messageData: TypedMessageParams): void;
|
|
7
|
+
export declare function validateTypedSignMessageDataV3V4(messageData: TypedMessageParams, currentChainId: string): void;
|
|
8
|
+
export declare function validateEncryptionPublicKeyMessageData(messageData: EncryptionPublicKeyParams): void;
|
|
9
|
+
export declare function validateDecryptedMessageData(messageData: DecryptMessageParams): void;
|
|
10
|
+
export declare function parseDecryptMessageData(data: string): EthEncryptedData;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaseController, INetworkController } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
import { EthereumNetworkConfig, EthereumNetworkState, EthereumProviderConfig } from "../utils/interfaces";
|
|
5
|
+
import { IProviderHandlers } from "./createEthereumMiddleware";
|
|
6
|
+
export default class NetworkController extends BaseController<EthereumNetworkConfig, EthereumNetworkState> implements INetworkController<EthereumNetworkConfig, EthereumNetworkState> {
|
|
7
|
+
name: string;
|
|
8
|
+
providerProxy: SafeEventEmitterProvider;
|
|
9
|
+
blockTrackerProxy: PollingBlockTracker;
|
|
10
|
+
private mutex;
|
|
11
|
+
private provider?;
|
|
12
|
+
private blockTracker?;
|
|
13
|
+
private baseProviderHandlers;
|
|
14
|
+
constructor({ config, state }: {
|
|
15
|
+
config?: Partial<EthereumNetworkConfig>;
|
|
16
|
+
state?: Partial<EthereumNetworkState>;
|
|
17
|
+
});
|
|
18
|
+
getNetworkIdentifier(): string;
|
|
19
|
+
getNetworkRPCUrl(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Called by orchestrator once while initializing the class
|
|
22
|
+
* @param providerHandlers - JRPC handlers for provider
|
|
23
|
+
* @returns - provider - Returns the providerProxy
|
|
24
|
+
*/
|
|
25
|
+
initializeProvider(providerHandlers: IProviderHandlers): SafeEventEmitterProvider;
|
|
26
|
+
getProvider(): SafeEventEmitterProvider;
|
|
27
|
+
getBlockTracker(): PollingBlockTracker;
|
|
28
|
+
getProviderConfig(): EthereumProviderConfig;
|
|
29
|
+
setProviderConfig(config: EthereumProviderConfig): void;
|
|
30
|
+
getEIP1559Compatibility(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Refreshes the current network code
|
|
33
|
+
*/
|
|
34
|
+
lookupNetwork(): Promise<void>;
|
|
35
|
+
private configureProvider;
|
|
36
|
+
private setNetworkClient;
|
|
37
|
+
private setProvider;
|
|
38
|
+
private configureStandardProvider;
|
|
39
|
+
private refreshNetwork;
|
|
40
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { InPageWalletProviderState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCEngineEndCallback, JRPCEngineNextCallback, JRPCMiddleware, JRPCRequest, JRPCResponse } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import { BlockParams, EthereumTransactionMeta, MessageParams, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
4
|
+
export interface IProviderHandlers {
|
|
5
|
+
version: string;
|
|
6
|
+
requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
7
|
+
getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
|
|
8
|
+
processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
|
|
9
|
+
processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
10
|
+
processTypedMessage?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
11
|
+
processTypedMessageV3?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
12
|
+
processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<TypedMessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
13
|
+
processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
14
|
+
processEncryptionPublicKey?: (address: string, req: JRPCRequest<string> & UserRequestApprovalParams) => Promise<string>;
|
|
15
|
+
processDecryptMessage?: (msgParams: MessageParams, req: JRPCRequest<MessageParams> & UserRequestApprovalParams) => Promise<string>;
|
|
16
|
+
getPendingNonce?: (nonceParams: {
|
|
17
|
+
address: string;
|
|
18
|
+
blockReference: string;
|
|
19
|
+
}, req: JRPCRequest<{
|
|
20
|
+
address: string;
|
|
21
|
+
blockReference: string;
|
|
22
|
+
}>) => Promise<string>;
|
|
23
|
+
getPendingTransactionByHash?: (hash: string, req: JRPCRequest<string>) => Promise<EthereumTransactionMeta>;
|
|
24
|
+
getProviderState: (req: JRPCRequest<[]>, res: JRPCResponse<InPageWalletProviderState>, next: JRPCEngineNextCallback, end: JRPCEngineEndCallback) => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function createGetAccountsMiddleware({ getAccounts }: {
|
|
27
|
+
getAccounts: IProviderHandlers["getAccounts"];
|
|
28
|
+
}): JRPCMiddleware<never, string[]>;
|
|
29
|
+
export declare function createProcessTransactionMiddleware({ processTransaction, }: {
|
|
30
|
+
processTransaction: IProviderHandlers["processTransaction"];
|
|
31
|
+
}): JRPCMiddleware<TransactionParams, string>;
|
|
32
|
+
export declare function createProcessEthSignMessage({ processEthSignMessage, }: {
|
|
33
|
+
processEthSignMessage: IProviderHandlers["processEthSignMessage"];
|
|
34
|
+
}): JRPCMiddleware<MessageParams, string>;
|
|
35
|
+
export declare function createProcessTypedMessage({ processTypedMessage, }: {
|
|
36
|
+
processTypedMessage: IProviderHandlers["processTypedMessage"];
|
|
37
|
+
}): JRPCMiddleware<MessageParams, string>;
|
|
38
|
+
export declare function createProcessTypedMessageV3({ processTypedMessageV3, }: {
|
|
39
|
+
processTypedMessageV3: IProviderHandlers["processTypedMessageV3"];
|
|
40
|
+
}): JRPCMiddleware<TypedMessageParams, string>;
|
|
41
|
+
export declare function createProcessTypedMessageV4({ processTypedMessageV4, }: {
|
|
42
|
+
processTypedMessageV4: IProviderHandlers["processTypedMessageV4"];
|
|
43
|
+
}): JRPCMiddleware<TypedMessageParams, string>;
|
|
44
|
+
export declare function createProcessPersonalMessage({ processPersonalMessage, }: {
|
|
45
|
+
processPersonalMessage: IProviderHandlers["processPersonalMessage"];
|
|
46
|
+
}): JRPCMiddleware<MessageParams, string>;
|
|
47
|
+
export declare function createPendingNonceMiddleware({ getPendingNonce, }: {
|
|
48
|
+
getPendingNonce: IProviderHandlers["getPendingNonce"];
|
|
49
|
+
}): JRPCMiddleware<{
|
|
50
|
+
address: string;
|
|
51
|
+
blockReference: BlockParams;
|
|
52
|
+
}, string>;
|
|
53
|
+
export declare function formatTxMetaForRpcResult(txMeta: EthereumTransactionMeta): TransactionRPCMeta;
|
|
54
|
+
export declare function createPendingTxMiddleware({ getPendingTransactionByHash, }: {
|
|
55
|
+
getPendingTransactionByHash: IProviderHandlers["getPendingTransactionByHash"];
|
|
56
|
+
}): JRPCMiddleware<string, TransactionRPCMeta>;
|
|
57
|
+
export declare function createProcessEncryptionPublicKeyMiddleware({ processEncryptionPublicKey, }: {
|
|
58
|
+
processEncryptionPublicKey: IProviderHandlers["processEncryptionPublicKey"];
|
|
59
|
+
}): JRPCMiddleware<string, string>;
|
|
60
|
+
export declare function createProcessDecryptMessageMiddleware({ processDecryptMessage, }: {
|
|
61
|
+
processDecryptMessage: IProviderHandlers["processDecryptMessage"];
|
|
62
|
+
}): JRPCMiddleware<MessageParams, string>;
|
|
63
|
+
export declare function createRequestAccountsMiddleware({ requestAccounts, }: {
|
|
64
|
+
requestAccounts: IProviderHandlers["requestAccounts"];
|
|
65
|
+
}): JRPCMiddleware<string[], unknown>;
|
|
66
|
+
export declare function createEthereumMiddleware(providerHandlers: IProviderHandlers): JRPCMiddleware<unknown, unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ProviderConfig } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCMiddleware } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
export declare function createChainIdMiddleware(chainId: string): JRPCMiddleware<unknown, string>;
|
|
5
|
+
export declare function createProviderConfigMiddleware(providerConfig: ProviderConfig): JRPCMiddleware<unknown, ProviderConfig>;
|
|
6
|
+
export declare function createJsonRpcClient(providerConfig: ProviderConfig): {
|
|
7
|
+
networkMiddleware: JRPCMiddleware<unknown, unknown>;
|
|
8
|
+
blockTracker: PollingBlockTracker;
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseConfig, BaseState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { CustomNftInfo } from "../utils/interfaces";
|
|
3
|
+
export interface NftsControllerConfig extends BaseConfig {
|
|
4
|
+
interval?: number;
|
|
5
|
+
selectedAddress: string;
|
|
6
|
+
chainId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NftsControllerState extends BaseState {
|
|
9
|
+
nfts: Record<string, CustomNftInfo[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BrowserProvider } from "ethers";
|
|
2
|
+
import { CustomNftInfo, CustomNftItemInfo } from "../utils/interfaces";
|
|
3
|
+
interface INftOptions {
|
|
4
|
+
contractAddress: string;
|
|
5
|
+
contractName?: string;
|
|
6
|
+
contractSymbol?: string;
|
|
7
|
+
contractImage?: string;
|
|
8
|
+
contractSupply?: string;
|
|
9
|
+
contractFallbackLogo?: string;
|
|
10
|
+
nftStandard?: "erc721" | "erc1155";
|
|
11
|
+
contractDescription?: string;
|
|
12
|
+
chainId: string;
|
|
13
|
+
provider: BrowserProvider;
|
|
14
|
+
}
|
|
15
|
+
export declare class NftHandler {
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
contractName: string;
|
|
18
|
+
contractSymbol: string;
|
|
19
|
+
contractImage: string;
|
|
20
|
+
contractSupply?: string;
|
|
21
|
+
contractFallbackLogo?: string;
|
|
22
|
+
nftStandard: "erc721" | "erc1155";
|
|
23
|
+
contractDescription?: string;
|
|
24
|
+
chainId: string;
|
|
25
|
+
provider: BrowserProvider;
|
|
26
|
+
isSpecial?: boolean;
|
|
27
|
+
constructor({ chainId, contractAddress, contractImage, contractName, contractSymbol, nftStandard, provider, contractDescription, contractFallbackLogo, contractSupply, }: INftOptions);
|
|
28
|
+
getNftMetadata(userAddress: string, tokenInfo: Partial<CustomNftItemInfo>): Promise<CustomNftItemInfo>;
|
|
29
|
+
getContractMetadata(): Promise<Omit<CustomNftInfo, "assets">>;
|
|
30
|
+
fetchNftBalance(userAddress: string, tokenId: string): Promise<string>;
|
|
31
|
+
private checkNftStandard;
|
|
32
|
+
private contractSupportsInterface;
|
|
33
|
+
private getCollectibleTokenURI;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BaseController, PreferencesState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import NetworkController from "../Network/NetworkController";
|
|
4
|
+
import PreferencesController from "../Preferences/PreferencesController";
|
|
5
|
+
import { CustomNftInfo, EthereumNetworkState, ExtendedAddressPreferences } from "../utils/interfaces";
|
|
6
|
+
import { NftsControllerConfig, NftsControllerState } from "./INftsController";
|
|
7
|
+
export interface INftsControllerOptions {
|
|
8
|
+
config?: Partial<NftsControllerConfig>;
|
|
9
|
+
state?: Partial<NftsControllerState>;
|
|
10
|
+
provider: SafeEventEmitterProvider;
|
|
11
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
12
|
+
getCustomNfts?: PreferencesController["getCustomNfts"];
|
|
13
|
+
getSimpleHashNfts: PreferencesController["getSimpleHashNfts"];
|
|
14
|
+
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
15
|
+
onNetworkStateChange: (listener: (networkState: EthereumNetworkState) => void) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare class NftsController extends BaseController<NftsControllerConfig, NftsControllerState> {
|
|
18
|
+
name: string;
|
|
19
|
+
private provider;
|
|
20
|
+
private ethersProvider;
|
|
21
|
+
private _timer;
|
|
22
|
+
private getNetworkIdentifier;
|
|
23
|
+
private getCustomNfts;
|
|
24
|
+
private getSimpleHashNfts;
|
|
25
|
+
constructor({ config, state, provider, getNetworkIdentifier, getCustomNfts, getSimpleHashNfts, onPreferencesStateChange, onNetworkStateChange, }: INftsControllerOptions);
|
|
26
|
+
get userSelectedAddress(): string;
|
|
27
|
+
get userNfts(): CustomNftInfo[];
|
|
28
|
+
get interval(): number;
|
|
29
|
+
set interval(interval: number);
|
|
30
|
+
startNftDetection(selectedAddress: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Restart nft detection polling period and call detectNewNfts
|
|
33
|
+
* in case of address change or user session initialization.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
restartNftDetection(): void;
|
|
37
|
+
detectNewNfts(): void;
|
|
38
|
+
refreshNftBalances(): Promise<void>;
|
|
39
|
+
getNftBalancesUsingHandler(customNfts: CustomNftInfo[]): Promise<void>;
|
|
40
|
+
}
|