import { Transaction } from 'web3-eth'; import { Interfaces, Models, Crypto, Errors } from '@open-rights-exchange/chain-js'; import * as ethcrypto from './ethCrypto'; import { EthereumTransaction } from './ethTransaction'; import { EthereumCreateAccount } from './ethCreateAccount'; import { EthereumAccount } from './ethAccount'; import { EthereumAddress, EthereumChainActionType, EthereumChainEndpoint, EthereumChainSettings, EthereumCreateAccountOptions, EthereumDate, EthereumDecomposeReturn, EthereumPublicKey, EthereumSymbol, EthereumTransactionAction, EthUnit } from './models'; import { isValidEthereumDateString, isValidEthereumEntityName, isValidEthereumPublicKey, isValidEthereumPrivateKey, toEthereumEntityName, toEthereumPublicKey, toEthereumPrivateKey, toEthereumSignature } from './helpers'; import { EthereumMultisigPlugin } from './plugins/multisig/ethereumMultisigPlugin'; import { EthereumSignMessage } from './ethSignMessage'; /** Provides support for the Ethereum blockchain * Provides Ethereum-specific implementations of the Chain interface * Also includes some features only available on this platform */ declare class Plugin implements Interfaces.Chain { private _endpoints; private _settings; private _chainState; private _plugins; constructor(endpoints: EthereumChainEndpoint[], settings?: EthereumChainSettings); get isConnected(): boolean; /** Connect to chain endpoint to verify that it is operational and to get latest block info */ /** Returns chain type enum - resolves to chain family as a string e.g. 'ethereum' */ get chainType(): Models.ChainType; static chainType: Models.ChainType; connect(): Promise; get chainId(): string; get chainInfo(): Models.ChainInfo; get endpoints(): EthereumChainEndpoint[]; get plugins(): Interfaces.ChainJsPlugin[]; composeAction: (actionType: Models.ChainActionType | EthereumChainActionType, args: any) => Promise; decomposeAction: (action: EthereumTransactionAction) => Promise; get description(): string; /** Returns chain native token symbol and default token contract address */ get nativeToken(): { defaultUnit: EthUnit; symbol: EthereumSymbol; tokenAddress: EthereumAddress; precision: number; }; /** Get the balance for an account from the chain * If tokenAddress is provided, returns balance for ERC20 token * If symbol = 'eth', returns Eth balance (in units of Ether) * Returns a string representation of the value to accomodate large numbers */ fetchBalance(account: EthereumAddress, symbol: EthereumSymbol, tokenAddress?: EthereumAddress): Promise<{ balance: string; }>; /** Fetch data from an on-chain contract table */ fetchContractData: (contract: string, table: string, owner: string, indexNumber: number, lowerRow: number, upperRow: number, limit: number, reverseOrder: boolean, showPayer: boolean, keyType: string) => Promise; /** Returns a chain Account class * Note: Does NOT create a new ethereum address - to create an address, use new.CreateAccount */ private newAccount; private newCreateAccount; private newTransaction; private newSignMessage; new: { Account: (address?: EthereumAddress) => Promise; CreateAccount: (options?: EthereumCreateAccountOptions) => Promise; Transaction: (options?: any) => Promise; SignMessage: (data: string, options?: any) => Promise; }; /** Gets an executed or pending transaction and its status * A transaction that has been added to the transction pool but not yet exectured will have a status of Pending * Until the transaction is added to the TX pool, this function will throw a TxNotFoundOnChain chain error */ fetchTransaction(transactionId: string): Promise<{ status: Models.TransactionStatus; transaction: Transaction; }>; /** 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 ethcrypto.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 ethcrypto.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 ethcrypto.decryptWithPrivateKey; /** Encrypts a string using a public key * The encrypted result can be decrypted with the matching private key */ encryptWithPublicKey: typeof ethcrypto.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 ethcrypto.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 ethcrypto.encryptWithPublicKeys; /** Returns a public key given a signature and the original data was signed */ getPublicKeyFromSignature: typeof ethcrypto.getEthereumPublicKeyFromSignature; /** Verifies that the value is a valid, stringified JSON asymmetric encryption result */ isSymEncryptedDataString: typeof ethcrypto.isSymEncryptedDataString; /** Ensures that the value comforms to a well-formed stringified JSON encryption result */ toSymEncryptedDataString: typeof ethcrypto.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 Eos private Key */ isValidPrivateKey: typeof isValidEthereumPrivateKey; /** Ensures that the value comforms to a well-formed public Key */ isValidPublicKey: typeof isValidEthereumPublicKey; /** Generates and returns a new public/private key pair */ generateKeyPair: typeof ethcrypto.generateKeyPair; /** Generates new key pairs (public and private) * Encrypts private key with provided password (and optional salt) * Returns: { privateKey, publicKey, encryptedPrivateKey } */ generateNewAccountKeysWithEncryptedPrivateKeys: typeof ethcrypto.generateNewAccountKeysAndEncryptPrivateKeys; /** Generate a signature given some data and a private key */ sign: typeof ethcrypto.sign; /** Signs data as a message using private key (first appending additional required data if any) */ signMessage: typeof ethcrypto.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 (signed with the private key for the provided public key) * A message differs than verifySignedWithPublicKey() because it might additional strings appended (as required by chain best-practices) * This differs from verifySignedWithPublicKey() because a message might include additional strings appended (as required by chain best-practices) */ verifySignedMessage: typeof ethcrypto.verifySignedMessage; /** Verify that the signed data was signed using the given key (signed with the private key for the provided public key) */ verifySignedWithPublicKey: typeof ethcrypto.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 Ethereum entity name (e.g. an account name) */ isValidEthereumEntityName: typeof isValidEthereumEntityName; /** Verifies that the value is a valid chain date */ isValidDate: (value: string) => boolean; /** Verifies that the value is a valid Ethereum date */ isValidEthereumDate: typeof isValidEthereumDateString; /** 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 Ethereum entity name * e.g. account, permission, or contract name */ toEthereumEntityName: typeof toEthereumEntityName; /** Ensures that the value comforms to a well-formed chain date string */ toDate: (value: string | Date | EthereumDate) => Models.ChainDate; /** Ensures that the value comforms to a well-formed EOS public Key */ toPublicKey: typeof toEthereumPublicKey; /** Ensures that the value comforms to a well-formed private Key */ toPrivateKey: typeof toEthereumPrivateKey; /** Ensures that the value comforms to a well-formed signature */ toSignature: typeof toEthereumSignature; /** Returns a new EthereumAccount class using the provided ethereum public key */ setPublicKey: (publicKey: EthereumPublicKey) => Promise; /** Map error from chain into a well-known ChainError type */ mapChainError: (error: Error) => Errors.ChainError; /** Confirm that we've connected to the chain - throw if not */ assertIsConnected(): void; /** Install a plugin to this chain connection */ installPlugin(plugin: Interfaces.ChainJsPlugin, options?: Interfaces.ChainJsPluginOptions): Promise; get multisigPlugin(): EthereumMultisigPlugin; /** rules to check tha plugin is well-formed and supported */ private assertValidPlugin; /** Access to underlying web3 sdk * Warning! You use chainjs functions wherever possible and only use this sdk as an escape hatch */ get web3(): import("web3").default; /** Transaction expiration constraints */ get transactionExpirationOptions(): Models.TransactionExpirationOptions; } export default Plugin;