///
import { RpcError } from 'eosjs';
import { Models, Crypto, Chain, ChainError, ChainJsPlugin, ChainJsPluginOptions } from '@open-rights-exchange/chain-js';
import * as eoscrypto from './eosCrypto';
import { isValidEosPrivateKey, isValidEosPublicKey, toEosPublicKey, toEosPrivateKey, toEosSignature, isValidEosEntityName, isValidEosAsset, isValidEosDate, toEosEntityName, toEosAsset, toEosDate } from './helpers';
import { EosActionStruct, EosChainSettings, EosEntityName, EosDate, EosDecomposeReturn, EosChainEndpoint, EosSymbol, EosTransactionHistory } from './models';
/** Provides support for the EOS blockchain
* Provides EOS-specific implementations of the Chain interface
* Also includes some features only available on this platform */
declare class Plugin implements Chain {
private _endpoints;
private _settings;
private _chainState;
private _plugins;
constructor(endpoints: EosChainEndpoint[], settings?: EosChainSettings);
/** Connect to chain endpoint to verify that it is operational and to get latest block info */
connect(): Promise;
/** Return unique chain ID string */
get chainId(): string;
/** Retrieve lastest chain info including head block number and time */
get chainInfo(): Models.ChainInfo;
get endpoints(): EosChainEndpoint[];
get plugins(): ChainJsPlugin[];
/** Returns chain native token symbol and default token contract address */
get nativeToken(): {
defaultUnit: string;
symbol: EosSymbol;
tokenAddress: EosEntityName;
precision: number;
};
/** Returns the supported expiration option metadata */
get transactionExpirationOptions(): Models.TransactionExpirationOptions;
/** Get the token balance for an account from the chain
* If tokenAddress is not provided, uses eosio.token as default
* Returns a string representation of the value to accomodate large numbers */
fetchBalance(account: EosEntityName, symbol: EosSymbol, tokenAddress?: EosEntityName): Promise<{
balance: string;
}>;
/** Fetch data from an on-chain contract table */
fetchContractData(contract: EosEntityName, table: string, owner: EosEntityName, indexNumber?: number, lowerRow?: number, upperRow?: number, limit?: number, reverseOrder?: boolean, showPayer?: boolean, keyType?: string): Promise;
/** Compose an object for a chain contract action */
composeAction: (actionType: Models.ChainActionType, args: any) => Promise;
/** Decompose a contract action and return the action type (if any) and its data */
decomposeAction: (action: EosActionStruct) => Promise;
/** Returns a chain Account class
* Note: Does NOT create a new account - to create an account, use new.CreateAccount */
private newAccount;
/** Return a ChainTransaction class used to compose and send transactions */
private newCreateAccount;
/** Return a ChainTransaction class used to compose and send transactions */
private newTransaction;
private newSignMessage;
new: {
/** Returns a new chain Account object
* If an account name is provided, it will be fetched from the chain and loaded into the returned account object
* Note: Does NOT create a new account - to create an account, use new.CreateAccount */
Account: any;
/** Return a new CreateAccount object used to help with creating a new chain account */
CreateAccount: any;
/** Return a chain Transaction object used to compose and send transactions */
Transaction: any;
/** Return a Signed Message object */
SignMessage: any;
};
/** Return an exectued or pending transaction and status */
fetchTransaction(transactionId: string): Promise<{
status: Models.TransactionStatus;
transaction: EosTransactionHistory;
}>;
/** Primary cryptography curve used by this chain */
cryptoCurve: Models.CryptoCurve.Secp256k1;
/** Decrypts the encrypted value using a password, and optional parameters using AES algorithm and SHA256 hash function
* Expects the encrypted value to be a stringified JSON object */
decryptWithPassword: typeof eoscrypto.decryptWithPassword;
/** Encrypts a string using a password and optional parameters using AES algorithm and SHA256 hash function
* The returned, encrypted value is a stringified JSON object */
encryptWithPassword: typeof eoscrypto.encryptWithPassword;
/** Decrypts the encrypted value using a private key
* The encrypted value is either a stringified JSON object or a JSON object
* ... and must have been encrypted with the public key that matches the private ley provided */
decryptWithPrivateKey: typeof eoscrypto.decryptWithPrivateKey;
/** Encrypts a string using a public key
* The encrypted result can be decrypted with the matching private key */
encryptWithPublicKey: typeof eoscrypto.encryptWithPublicKey;
/** Unwraps an object produced by encryptWithPublicKeys() - resulting in the original ecrypted string
* each pass uses a private keys from privateKeys array param
* put the keys in the same order as public keys provided to encryptWithPublicKeys() - they will be applied in the right (reverse) order
* The result is the decrypted string */
decryptWithPrivateKeys: typeof eoscrypto.decryptWithPrivateKeys;
/** Use assymmetric encryption with multiple public keys - wrapping with each
* Returns an array of results with the last one including the final cipertext
* Encrypts using publicKeys in the order they appear in the array */
encryptWithPublicKeys: typeof eoscrypto.encryptWithPublicKeys;
/** Returns a public key given a signature and the original data was signed */
/** Returns a public key given a signature and the original data was signed */
getPublicKeyFromSignature: (signature: string | Buffer, data: string | Buffer) => Models.PublicKey;
/** Generates and returns a new public/private key pair */
generateKeyPair: typeof eoscrypto.generateKeyPair;
/** Verifies that the value is a valid, stringified JSON encryption result */
isSymEncryptedDataString: typeof eoscrypto.isSymEncryptedDataString;
/** Ensures that the value comforms to a well-formed stringified JSON encryption result */
toSymEncryptedDataString: typeof eoscrypto.toSymEncryptedDataString;
/** Verifies that the value is a valid, stringified JSON asymmetric encryption result */
isAsymEncryptedDataString: typeof Crypto.Asymmetric.isAsymEncryptedDataString;
/** Ensures that the value comforms to a well-formed stringified JSON encryption result */
toAsymEncryptedDataString: typeof Crypto.Asymmetric.toAsymEncryptedDataString;
/** Ensures that the value comforms to a well-formed private Key */
isValidPrivateKey: (value: string) => boolean;
/** Ensures that the value comforms to a well-formed Eos private Key */
isValidEosPrivateKey: typeof isValidEosPrivateKey;
/** Ensures that the value comforms to a well-formed public Key */
isValidPublicKey: (value: string) => boolean;
/** Ensures that the value comforms to a well-formed EOS public Key */
isValidEosPublicKey: typeof isValidEosPublicKey;
/** Generates new owner and active key pairs (public and private)
* Encrypts private keys with provided password and optional params
* Returns: { publicKeys:{owner, active}, privateKeys:{owner, active}, privateKeysEncrypted:{owner, active} } */
generateNewAccountKeysWithEncryptedPrivateKeys: typeof eoscrypto.generateNewAccountKeysAndEncryptPrivateKeys;
/** Generate a signature given some data and a private key */
sign: typeof eoscrypto.sign;
/** Signs data as a message using private key (Eos does not append additional fields for a message) */
signMessage: typeof eoscrypto.signMessage;
/** Whether the chain supports resources */
supportsFee: boolean;
/** Whether chain supports ability to get a publicKey from a signature */
supportsGetPublicKeyFromSignature: boolean;
/** Whether the chain supports resources */
supportsResources: boolean;
/** Whether the chain's signMessage feature supports signing a typed data object (ex: ERC712 data type for Ethereum) */
supportsSignMessageTypedData: boolean;
/** Verify that a 'personal message' was signed using the given key (Eos does not append additional fields for a message) */
verifySignedMessage: typeof eoscrypto.verifySignedMessage;
/** Verify that the signed data was signed using the given key (signed with the private key for the provided public key) */
verifySignedWithPublicKey: typeof eoscrypto.verifySignedWithPublicKey;
/** Verifies that the value is a valid chain entity name (e.g. an account name) */
isValidEntityName: (value: string) => boolean;
/** Verifies that the value is a valid EOS entity name (e.g. an account name) */
isValidEosEntityName: typeof isValidEosEntityName;
/** Verifies that the value is a valid EOS asset string */
isValidEosAsset: typeof isValidEosAsset;
/** Verifies that the value is a valid chain date */
isValidDate: (value: string) => boolean;
/** Verifies that the value is a valid EOS date */
isValidEosDate: typeof isValidEosDate;
/** Ensures that the value comforms to a well-formed EOS asset string */
toEosAsset: typeof toEosAsset;
/** Ensures that the value comforms to a well-formed chain entity name (e.g. an account name) */
toEntityName: (value: string) => Models.ChainEntityName;
/** Ensures that the value comforms to a well-formed EOS entity name
* e.g. account, permission, or contract name */
toEosEntityName: typeof toEosEntityName;
/** Ensures that the value comforms to a well-formed chain date string */
toDate: (value: string | Date | EosDate) => Models.ChainDate;
/** Ensures that the value comforms to a well-formed EOS date string */
toEosDate: typeof toEosDate;
/** Ensures that the value comforms to a well-formed public Key */
toPublicKey: (value: string) => Models.PublicKey;
/** Ensures that the value comforms to a well-formed EOS public Key */
toEosPublicKey: typeof toEosPublicKey;
/** Ensures that the value comforms to a well-formed private Key */
toPrivateKey: (value: string) => Models.PrivateKey;
/** Ensures that the value comforms to a well-formed EOS private Key */
toEosPrivateKey: typeof toEosPrivateKey;
/** Ensures that the value comforms to a well-formed EOS signature */
toSignature: (value: string) => Models.Signature;
/** Ensures that the value comforms to a well-formed EOS signature */
toEosSignature: typeof toEosSignature;
/** Returns chain type enum - resolves to chain family as a string e.g. 'eos' */
get chainType(): Models.ChainType;
static chainType: Models.ChainType;
static chainType2: Models.ChainType;
/** Returns chain plug-in name */
get description(): string;
/** Whether any info has been retrieved from the chain */
get isConnected(): boolean;
/** Map error from chain into a well-known ChainError type */
mapChainError: (error: RpcError | Error) => ChainError;
/** Confirm that we've connected to the chain - throw if not */
assertIsConnected(): void;
/** Install a plugin to this chain connection */
installPlugin(plugin: ChainJsPlugin, options?: ChainJsPluginOptions): Promise;
/** rules to check tha plugin is well-formed and supported */
private assertValidPlugin;
/** Access to underlying eosjs sdk
* Warning! You use chainjs functions wherever possible and only use this sdk as an escape hatch
*/
get eosjs(): {
api: import("eosjs").Api;
jsonRpc: import("eosjs").JsonRpc;
};
}
export default Plugin;