diff --git a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts index 68537a37df..8a27c82d81 100644 --- a/modules/abstract-eth/src/abstractEthLikeNewCoins.ts +++ b/modules/abstract-eth/src/abstractEthLikeNewCoins.ts @@ -42,7 +42,13 @@ import { VerifyTransactionOptions, Wallet, } from '@bitgo/sdk-core'; -import { BaseCoin as StaticsBaseCoin, coins, EthereumNetwork as EthLikeNetwork, ethGasConfigs } from '@bitgo/statics'; +import { + BaseCoin as StaticsBaseCoin, + coins, + EthereumNetwork as EthLikeNetwork, + ethGasConfigs, + CoinMap, +} from '@bitgo/statics'; import type * as EthLikeTxLib from '@ethereumjs/tx'; import type * as EthLikeCommon from '@ethereumjs/common'; import { EcdsaPaillierProof, EcdsaRangeProof, EcdsaTypes } from '@bitgo/sdk-lib-mpc'; @@ -52,7 +58,6 @@ import { SignTypedDataVersion, TypedDataUtils, TypedMessage } from '@metamask/et import { calculateForwarderV1Address, - EthLikeCoinNameFromChainId, getCommon, getProxyInitcode, getToken, @@ -376,13 +381,18 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { this.sendMethodName = 'sendMultiSig'; } + /** + * Method to return the coin's network object + * @returns {EthLikeNetwork | undefined} + */ getNetwork(): EthLikeNetwork | undefined { return this.staticsCoin?.network as EthLikeNetwork; } /** * Evaluates whether an address string is valid for this coin - * @param address + * @param {string} address + * @returns {boolean} True if address is the valid ethlike adderss */ isValidAddress(address: string): boolean { return optionalDeps.ethUtil.isValidAddress(optionalDeps.ethUtil.addHexPrefix(address)); @@ -422,11 +432,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Method to get the custom chain common object based on params from recovery - * @param chainId {number} + * @param {number} chainId - the chain id of the custom chain * @returns {EthLikeCommon.default} */ static getCustomChainCommon(chainId: number): EthLikeCommon.default { - const coinName = EthLikeCoinNameFromChainId[chainId]; + const coinName = CoinMap.coinNameFromChainId(chainId); const coin = coins.get(coinName); const ethLikeCommon = getCommon(coin.network as EthLikeNetwork); return ethLikeCommon; @@ -434,10 +444,14 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Gets correct Eth Common object based on params from either recovery or tx building - * @param eip1559 {EIP1559} configs that specify whether we should construct an eip1559 tx - * @param replayProtectionOptions {ReplayProtectionOptions} check if chain id supports replay protection + * @param {EIP1559} eip1559 - configs that specify whether we should construct an eip1559 tx + * @param {ReplayProtectionOptions} replayProtectionOptions - check if chain id supports replay protection + * @returns {EthLikeCommon.default} */ - private static getEthLikeCommon(eip1559?: EIP1559, replayProtectionOptions?: ReplayProtectionOptions) { + private static getEthLikeCommon( + eip1559?: EIP1559, + replayProtectionOptions?: ReplayProtectionOptions + ): EthLikeCommon.default { // if eip1559 params are specified, default to london hardfork, otherwise, // default to tangerine whistle to avoid replay protection issues const defaultHardfork = !!eip1559 ? 'london' : optionalDeps.EthCommon.Hardfork.TangerineWhistle; @@ -448,8 +462,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Method to build the tx object - * @param params {BuildTransactionParams} - * @returns + * @param {BuildTransactionParams} params - params to build transaction + * @returns {EthLikeTxLib.FeeMarketEIP1559Transaction | EthLikeTxLib.Transaction} */ static buildTransaction( params: BuildTransactionParams @@ -487,7 +501,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Query explorer for the balance of an address - * @param address {String} the ETHLike address + * @param {String} address - the ETHLike address * @returns {BigNumber} address balance */ async queryAddressBalance(address: string): Promise { @@ -504,9 +518,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { } /** - * @param recipients {Recipient[]} - * @param expireTime {number} - * @param contractSequenceId {number} + * @param {Recipient[]} recipients - the recipients of the transaction + * @param {number} expireTime - the expire time of the transaction + * @param {number} contractSequenceId - the contract sequence id of the transaction * @returns {string} */ getOperationSha3ForExecuteAndConfirm( @@ -540,7 +554,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { throw new Error('Invalid address: ' + recipient.address); } - let amount; + let amount: BigNumber; try { amount = new BigNumber(recipient.amount); } catch (e) { @@ -562,9 +576,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Get transfer operation for coin - * @param recipient recipient info - * @param expireTime expiry time - * @param contractSequenceId sequence id + * @param {Recipient} recipient - recipient info + * @param {number} expireTime - expiry time + * @param {number} contractSequenceId - sequence id * @returns {Array} operation array */ getOperation(recipient: Recipient, expireTime: number, contractSequenceId: number): (string | Buffer)[][] { @@ -584,8 +598,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Queries the contract (via explorer API) for the next sequence ID - * @param address {String} address of the contract - * @returns {Number} sequence ID + * @param {String} address - address of the contract + * @returns {Promise} sequence ID */ async querySequenceId(address: string): Promise { // Get sequence ID using contract call @@ -610,13 +624,14 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { * Recover an unsupported token from a BitGo multisig wallet * This builds a half-signed transaction, for which there will be an admin route to co-sign and broadcast. Optionally * the user can set params.broadcast = true and the half-signed tx will be sent to BitGo for cosigning and broadcasting - * @param params - * @param params.wallet the wallet to recover the token from - * @param params.tokenContractAddress the contract address of the unsupported token - * @param params.recipient the destination address recovered tokens should be sent to - * @param params.walletPassphrase the wallet passphrase - * @param params.prv the xprv - * @param params.broadcast if true, we will automatically submit the half-signed tx to BitGo for cosigning and broadcasting + * @param {RecoverTokenOptions} params + * @param {Wallet} params.wallet - the wallet to recover the token from + * @param {string} params.tokenContractAddress - the contract address of the unsupported token + * @param {string} params.recipient - the destination address recovered tokens should be sent to + * @param {string} params.walletPassphrase - the wallet passphrase + * @param {string} params.prv - the xprv + * @param {boolean} params.broadcast - if true, we will automatically submit the half-signed tx to BitGo for cosigning and broadcasting + * @returns {Promise} */ async recoverToken(params: RecoverTokenOptions): Promise { const network = this.getNetwork() as EthLikeNetwork; @@ -757,9 +772,10 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Ensure either enterprise or newFeeAddress is passed, to know whether to create new key or use enterprise key - * @param params - * @param params.enterprise {String} the enterprise id to associate with this key - * @param params.newFeeAddress {Boolean} create a new fee address (enterprise not needed in this case) + * @param {PrecreateBitGoOptions} params + * @param {string} params.enterprise {String} the enterprise id to associate with this key + * @param {string} params.newFeeAddress {Boolean} create a new fee address (enterprise not needed in this case) + * @returns {void} */ preCreateBitGo(params: PrecreateBitGoOptions): void { // We always need params object, since either enterprise or newFeeAddress is required @@ -791,8 +807,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Queries public block explorer to get the next ETHLike coin's nonce that should be used for the given ETH address - * @param address - * @returns {*} + * @param {string} address + * @returns {Promise} */ async getAddressNonce(address: string): Promise { // Get nonce for backup key (should be 0) @@ -818,14 +834,14 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Helper function for recover() * This transforms the unsigned transaction information into a format the BitGo offline vault expects - * @param txInfo - * @param ethTx - * @param userKey - * @param backupKey - * @param gasPrice - * @param gasLimit - * @param eip1559 - * @param replayProtectionOptions + * @param {UnformattedTxInfo} txInfo - tx info + * @param {EthLikeTxLib.Transaction | EthLikeTxLib.FeeMarketEIP1559Transaction} ethTx - the ethereumjs tx object + * @param {string} userKey - the user's key + * @param {string} backupKey - the backup key + * @param {Buffer} gasPrice - gas price for the tx + * @param {number} gasLimit - gas limit for the tx + * @param {EIP1559} eip1559 - eip1559 params + * @param {ReplayProtectionOptions} replayProtectionOptions - replay protection options * @returns {Promise} */ async formatForOfflineVault( @@ -867,14 +883,15 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Helper function for recover() * This transforms the unsigned transaction information into a format the BitGo offline vault expects - * @param txInfo - * @param ethTx - * @param userKey - * @param backupKey - * @param gasPrice - * @param gasLimit - * @param eip1559 - * @param replayProtectionOptions + * @param {UnformattedTxInfo} txInfo - tx info + * @param {EthLikeTxLib.Transaction | EthLikeTxLib.FeeMarketEIP1559Transaction} ethTx - the ethereumjs tx object + * @param {string} userKey - the user's key + * @param {string} backupKey - the backup key + * @param {Buffer} gasPrice - gas price for the tx + * @param {number} gasLimit - gas limit for the tx + * @param {number} backupKeyNonce - the nonce of the backup key address + * @param {EIP1559} eip1559 - eip1559 params + * @param {ReplayProtectionOptions} replayProtectionOptions - replay protection options * @returns {Promise} */ formatForOfflineVaultTSS( @@ -913,8 +930,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Check whether the gas price passed in by user are within our max and min bounds * If they are not set, set them to the defaults - * @param userGasPrice user defined gas price - * @returns the gas price to use for this transaction + * @param {number} userGasPrice - user defined gas price + * @returns {number} the gas price to use for this transaction */ setGasPrice(userGasPrice?: number): number { if (!userGasPrice) { @@ -931,8 +948,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Check whether gas limit passed in by user are within our max and min bounds * If they are not set, set them to the defaults - * @param userGasLimit user defined gas limit - * @returns the gas limit to use for this transaction + * @param {number} userGasLimit user defined gas limit + * @returns {number} the gas limit to use for this transaction */ setGasLimit(userGasLimit?: number): number { if (!userGasLimit) { @@ -949,8 +966,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Helper function for signTransaction for the rare case that SDK is doing the second signature * Note: we are expecting this to be called from the offline vault - * @param params.txPrebuild - * @param params.prv + * @param {SignFinalOptions.txPrebuild} params.txPrebuild + * @param {string} params.prv * @returns {{txHex: string}} */ async signFinalEthLike(params: SignFinalOptions): Promise { @@ -973,7 +990,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Assemble half-sign prebuilt transaction - * @param params + * @param {SignTransactionOptions} params */ async signTransaction(params: SignTransactionOptions): Promise { // Normally the SDK provides the first signature for an POLYGON tx, but occasionally it provides the second and final one. @@ -1005,7 +1022,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Method to validate recovery params - * @param params {RecoverOptions} + * @param {RecoverOptions} params * @returns {void} */ validateRecoveryParams(params: RecoverOptions): void { @@ -1030,6 +1047,15 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { } } + /** + * Method to sign tss recovery transaction + * @param {ECDSA.KeyCombined} userKeyCombined + * @param {ECDSA.KeyCombined} backupKeyCombined + * @param {string} txHex + * @param {Object} options + * @param {EcdsaTypes.SerializedNtilde} options.rangeProofChallenge + * @returns {Promise} + */ private async signRecoveryTSS( userKeyCombined: ECDSA.KeyCombined, backupKeyCombined: ECDSA.KeyCombined, @@ -1120,7 +1146,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Helper which combines key shares of user and backup - * */ + * @param {string} userPublicOrPrivateKeyShare + * @param {string} backupPrivateOrPublicKeyShare + * @param {string} walletPassphrase + * @returns {[ECDSAMethodTypes.KeyCombined, ECDSAMethodTypes.KeyCombined]} + */ private getKeyCombinedFromTssKeyShares( userPublicOrPrivateKeyShare: string, backupPrivateOrPublicKeyShare: string, @@ -1175,7 +1205,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Helper which Adds signatures to tx object and re-serializes tx - * */ + * @param {EthLikeCommon.default} ethCommon + * @param {EthLikeTxLib.FeeMarketEIP1559Transaction | EthLikeTxLib.Transaction} tx + * @param {ECDSAMethodTypes.Signature} signature + * @returns {EthLikeTxLib.FeeMarketEIP1559Transaction | EthLikeTxLib.Transaction} + */ private getSignedTxFromSignature( ethCommon: EthLikeCommon.default, tx: EthLikeTxLib.FeeMarketEIP1559Transaction | EthLikeTxLib.Transaction, @@ -1223,14 +1257,14 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Builds a funds recovery transaction without BitGo * @param params - * @param params.userKey {String} [encrypted] xprv - * @param params.backupKey {String} [encrypted] xprv or xpub if the xprv is held by a KRS provider - * @param params.walletPassphrase {String} used to decrypt userKey and backupKey - * @param params.walletContractAddress {String} the ETH address of the wallet contract - * @param params.krsProvider {String} necessary if backup key is held by KRS - * @param params.recoveryDestination {String} target address to send recovered funds to - * @param params.bitgoFeeAddress {String} wrong chain wallet fee address for evm based cross chain recovery txn - * @param params.bitgoDestinationAddress {String} target bitgo address where fee will be sent for evm based cross chain recovery txn + * @param {string} params.userKey - [encrypted] xprv + * @param {string} params.backupKey - [encrypted] xprv or xpub if the xprv is held by a KRS provider + * @param {string} params.walletPassphrase - used to decrypt userKey and backupKey + * @param {string} params.walletContractAddress - the ETH address of the wallet contract + * @param {string} params.krsProvider - necessary if backup key is held by KRS + * @param {string} params.recoveryDestination - target address to send recovered funds to + * @param {string} params.bitgoFeeAddress - wrong chain wallet fee address for evm based cross chain recovery txn + * @param {string} params.bitgoDestinationAddress - target bitgo address where fee will be sent for evm based cross chain recovery txn */ async recover(params: RecoverOptions): Promise { if (params.isTss) { @@ -1239,17 +1273,19 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { return this.recoverEthLike(params); } + protected; + /** * Builds a funds recovery transaction without BitGo for non-TSS transaction * @param params - * @param {String} params.userKey [encrypted] xprv or xpub - * @param {String} params.backupKey [encrypted] xprv or xpub if the xprv is held by a KRS provider - * @param {String} params.walletPassphrase used to decrypt userKey and backupKey - * @param {String} params.walletContractAddress the Polygon address of the wallet contract - * @param {String} params.krsProvider necessary if backup key is held by KRS - * @param {String} params.recoveryDestination target address to send recovered funds to - * @param {String} params.bitgoFeeAddress wrong chain wallet fee address for evm based cross chain recovery txn - * @param {String} params.bitgoDestinationAddress target bitgo address where fee will be sent for evm based cross chain recovery txn + * @param {string} params.userKey [encrypted] xprv or xpub + * @param {string} params.backupKey [encrypted] xprv or xpub if the xprv is held by a KRS provider + * @param {string} params.walletPassphrase used to decrypt userKey and backupKey + * @param {string} params.walletContractAddress the Polygon address of the wallet contract + * @param {string} params.krsProvider necessary if backup key is held by KRS + * @param {string} params.recoveryDestination target address to send recovered funds to + * @param {string} params.bitgoFeeAddress wrong chain wallet fee address for evm based cross chain recovery txn + * @param {string} params.bitgoDestinationAddress target bitgo address where fee will be sent for evm based cross chain recovery txn * @returns {Promise} */ protected async recoverEthLike(params: RecoverOptions): Promise { @@ -1419,6 +1455,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { * half-signed (for hot wallet) evm cross chain recovery transaction with * same expected arguments as recover method. * This helps recover funds from evm based wrong chain. + * @param {RecoverOptions} params + * @returns {Promise} */ protected async recoverEthLikeforEvmBasedRecovery( params: RecoverOptions @@ -1604,8 +1642,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Query explorer for the balance of an address for a token - * @param tokenContractAddress {String} address where the token smart contract is hosted - * @param walletContractAddress {String} address of the wallet + * @param {string} tokenContractAddress - address where the token smart contract is hosted + * @param {string} walletContractAddress - address of the wallet * @returns {BigNumber} token balaance in base units */ async queryAddressTokenBalance(tokenContractAddress: string, walletContractAddress: string): Promise { @@ -1783,7 +1821,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Get the data required to make an ETH function call defined by the given types and values * - * @param functionName The name of the function being called, e.g. transfer + * @param {string} functionName - The name of the function being called, e.g. transfer * @param types The types of the function call in order * @param values The values of the function call in order * @return {Buffer} The combined data for the function call @@ -2014,10 +2052,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Validates that the hop prebuild from the HSM is valid and correct - * @param wallet The wallet that the prebuild is for - * @param hopPrebuild The prebuild to validate - * @param originalParams The original parameters passed to prebuildTransaction - * @returns void + * @param {IWallet} wallet - The wallet that the prebuild is for + * @param {HopPrebuild} hopPrebuild - The prebuild to validate + * @param {Object} originalParams - The original parameters passed to prebuildTransaction + * @param {Recipient[]} originalParams.recipients - The original recipients array + * @returns {void} * @throws Error if The prebuild is invalid */ async validateHopPrebuild( @@ -2077,7 +2116,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Gets the hop digest for the user to sign. This is validated in the HSM to prove that the user requested this tx - * @param paramsArr The parameters to hash together for the digest + * @param {string[]} paramsArr - The parameters to hash together for the digest + * @returns {Buffer} */ private static getHopDigest(paramsArr: string[]): Buffer { const hash = Keccak('keccak256'); @@ -2087,11 +2127,12 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Modify prebuild before sending it to the server. Add things like hop transaction params - * @param buildParams The whitelisted parameters for this prebuild - * @param buildParams.hop True if this should prebuild a hop tx, else false - * @param buildParams.recipients The recipients array of this transaction - * @param buildParams.wallet The wallet sending this tx - * @param buildParams.walletPassphrase the passphrase for this wallet + * @param {BuildOptions} buildParams - The whitelisted parameters for this prebuild + * @param {boolean} buildParams.hop - True if this should prebuild a hop tx, else false + * @param {Recipient[]} buildParams.recipients - The recipients array of this transaction + * @param {Wallet} buildParams.wallet - The wallet sending this tx + * @param {string} buildParams.walletPassphrase - the passphrase for this wallet + * @returns {Promise} */ async getExtraPrebuildParams(buildParams: BuildOptions): Promise { if ( @@ -2117,6 +2158,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Modify prebuild after receiving it from the server. Add things like nlocktime + * @param {TransactionPrebuild} params - The prebuild to modify + * @returns {TransactionPrebuild} The modified prebuild */ async postProcessPrebuild(params: TransactionPrebuild): Promise { if (!_.isUndefined(params.hopTransaction) && !_.isUndefined(params.wallet) && !_.isUndefined(params.buildParams)) { @@ -2127,7 +2170,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Coin-specific things done before signing a transaction, i.e. verification - * @param params + * @param {PresignTransactionOptions} params + * @returns {Promise} */ async presignTransaction(params: PresignTransactionOptions): Promise { if (!_.isUndefined(params.hopTransaction) && !_.isUndefined(params.wallet) && !_.isUndefined(params.buildParams)) { @@ -2138,10 +2182,10 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Fetch fee estimate information from the server - * @param {Object} params The params passed into the function - * @param {Boolean} [params.hop] True if we should estimate fee for a hop transaction - * @param {String} [params.recipient] The recipient of the transaction to estimate a send to - * @param {String} [params.data] The ETH tx data to estimate a send for + * @param {Object} params - The params passed into the function + * @param {boolean} [params.hop] - True if we should estimate fee for a hop transaction + * @param {string} [params.recipient] - The recipient of the transaction to estimate a send to + * @param {string} [params.data] - The ETH tx data to estimate a send for * @returns {Object} The fee info returned from the server */ async feeEstimate(params: FeeEstimateOptions): Promise { @@ -2165,8 +2209,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Generate secp256k1 key pair * - * @param seed - * @returns {Object} object with generated pub and prv + * @param {Buffer} seed + * @returns {KeyPair} object with generated pub and prv */ generateKeyPair(seed: Buffer): KeyPair { if (!seed) { @@ -2190,13 +2234,13 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Make sure an address is a wallet address and throw an error if it's not. * @param {Object} params - * @param {String} params.address The derived address string on the network - * @param {Object} params.coinSpecific Coin-specific details for the address such as a forwarderVersion - * @param {String} params.baseAddress The base address of the wallet on the network + * @param {string} params.address - The derived address string on the network + * @param {Object} params.coinSpecific - Coin-specific details for the address such as a forwarderVersion + * @param {string} params.baseAddress - The base address of the wallet on the network * @throws {InvalidAddressError} * @throws {InvalidAddressVerificationObjectPropertyError} * @throws {UnexpectedAddressError} - * @returns {Boolean} True iff address is a wallet address + * @returns {boolean} True iff address is a wallet address */ async isWalletAddress(params: VerifyEthAddressOptions): Promise { const ethUtil = optionalDeps.ethUtil; @@ -2250,10 +2294,24 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { return true; } + /** + * + * @param {TransactionPrebuild} txPrebuild + * @returns {boolean} + */ verifyCoin(txPrebuild: TransactionPrebuild): boolean { return txPrebuild.coin === this.getChain(); } + /** + * Verify if a tss transaction is valid + * + * @param {VerifyEthTransactionOptions} params + * @param {TransactionParams} params.txParams - params object passed to send + * @param {TransactionPrebuild} params.txPrebuild - prebuild object returned by server + * @param {Wallet} params.wallet - Wallet object to obtain keys to verify against + * @returns {boolean} + */ verifyTssTransaction(params: VerifyEthTransactionOptions): boolean { const { txParams, txPrebuild, wallet } = params; if ( @@ -2277,10 +2335,10 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Verify that a transaction prebuild complies with the original intention * - * @param params - * @param params.txParams params object passed to send - * @param params.txPrebuild prebuild object returned by server - * @param params.wallet Wallet object to obtain keys to verify against + * @param {VerifyEthTransactionOptions} params + * @param {TransactionParams} params.txParams - params object passed to send + * @param {TransactionPrebuild} params.txPrebuild - prebuild object returned by server + * @param {Wallet} params.wallet - Wallet object to obtain keys to verify against * @returns {boolean} */ async verifyTransaction(params: VerifyEthTransactionOptions): Promise { @@ -2371,14 +2429,19 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { return true; } + /** + * Check if address is valid eth address + * @param address + * @returns {boolean} + */ private isETHAddress(address: string): boolean { return !!address.match(/0x[a-fA-F0-9]{40}/); } /** * Transform message to accommodate specific blockchain requirements. - * @param message the message to prepare - * @return string the prepared message. + * @param {string} message - the message to prepare + * @return {string} the prepared message. */ encodeMessage(message: string): string { const prefix = `\u0019Ethereum Signed Message:\n${message.length}`; @@ -2387,8 +2450,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { /** * Transform the Typed data to accomodate the blockchain requirements (EIP-712) - * @param typedData the typed data to prepare - * @return a buffer of the result + * @param {TypedData} typedData - the typed data to prepare + * @return {Buffer} a buffer of the result */ encodeTypedData(typedData: TypedData): Buffer { const version = typedData.version; diff --git a/modules/abstract-eth/src/lib/index.ts b/modules/abstract-eth/src/lib/index.ts index aa5f658145..ae53d5a67b 100644 --- a/modules/abstract-eth/src/lib/index.ts +++ b/modules/abstract-eth/src/lib/index.ts @@ -9,7 +9,6 @@ export * from './transferBuilder'; export * from './types'; export * from './utils'; export * from './walletUtil'; -export * from './resources'; // for Backwards Compatibility import * as Interface from './iface'; diff --git a/modules/abstract-eth/src/lib/resources.ts b/modules/abstract-eth/src/lib/resources.ts deleted file mode 100644 index d4c2a0ff02..0000000000 --- a/modules/abstract-eth/src/lib/resources.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Mapping of all supported coins with their chainIds -export const EthLikeCoinNameFromChainId = { - 1: 'eth', - 42: 'teth', - 5: 'gteth', - 17000: 'hteth', - 10001: 'ethw', - 80001: 'tpolygon', - 137: 'polygon', - 56: 'bsc', - 97: 'tbsc', - 42161: 'arbeth', - 421614: 'tarbeth', - 10: 'opeth', - 11155420: 'topeth', -}; diff --git a/modules/sdk-coin-eth/src/eth.ts b/modules/sdk-coin-eth/src/eth.ts index 6fbc3f0ee7..c8af91290c 100644 --- a/modules/sdk-coin-eth/src/eth.ts +++ b/modules/sdk-coin-eth/src/eth.ts @@ -207,7 +207,7 @@ export class Eth extends AbstractEthLikeNewCoins { } } - let backupKeyAddress; + let backupKeyAddress: string; let backupSigningKey; if (isKrsRecovery || isUnsignedSweep) { diff --git a/modules/statics/src/map.ts b/modules/statics/src/map.ts index 9ecc16752e..8d1deb8f51 100644 --- a/modules/statics/src/map.ts +++ b/modules/statics/src/map.ts @@ -34,6 +34,25 @@ export class CoinMap { }, new CoinMap()); } + static coinNameFromChainId(chainId: number): string { + const ethLikeCoinFromChainId: Record = { + 1: 'eth', + 42: 'teth', + 5: 'gteth', + 17000: 'hteth', + 10001: 'ethw', + 80001: 'tpolygon', + 137: 'polygon', + 56: 'bsc', + 97: 'tbsc', + 42161: 'arbeth', + 421614: 'tarbeth', + 10: 'opeth', + 11155420: 'topeth', + }; + return ethLikeCoinFromChainId[chainId]; + } + /** * Override `get` to throw if a coin is missing, instead of returning undefined. * It will honor key equivalences in case given key is missing.