From e618734f1e5b9c0325a26860cc77cab6ad89b93c Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Tue, 6 Aug 2024 16:27:06 +0800 Subject: [PATCH 01/28] feat: using InstanceType of class to void node16 module error --- src/types/Providers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/Providers.ts b/src/types/Providers.ts index ddc4cc2e..19bcd461 100644 --- a/src/types/Providers.ts +++ b/src/types/Providers.ts @@ -1,5 +1,5 @@ import { RawAxiosRequestHeaders, AxiosHeaders, HeadersDefaults } from 'axios'; -export type HeadersType = RawAxiosRequestHeaders | AxiosHeaders | Partial; +export type HeadersType = RawAxiosRequestHeaders | InstanceType | Partial; export type RequestHeaders = RawAxiosRequestHeaders; export interface HttpProviderInstance { From d753bfb9d055f6e42c2132ca5c88b1ddd2b0e501 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 14 Aug 2024 12:38:08 +0800 Subject: [PATCH 02/28] feat: add type for value in transactionBuilder and fix some type errors --- .../TransactionBuilder/TransactionBuilder.ts | 231 +++++++++++------- src/lib/TransactionBuilder/helper.ts | 8 +- src/types/Contract.ts | 35 ++- src/types/Transaction.ts | 6 +- test/lib/transactionBuilder.test.ts | 2 + 5 files changed, 161 insertions(+), 121 deletions(-) diff --git a/src/lib/TransactionBuilder/TransactionBuilder.ts b/src/lib/TransactionBuilder/TransactionBuilder.ts index eb5f5df1..ab925ebb 100644 --- a/src/lib/TransactionBuilder/TransactionBuilder.ts +++ b/src/lib/TransactionBuilder/TransactionBuilder.ts @@ -7,19 +7,43 @@ import { Validator } from '../../paramValidator/index.js'; import { GetSignWeightResponse } from '../../types/APIResponse.js'; import { isArray, isInteger, isNotNullOrUndefined, isObject, isString } from '../../utils/validations.js'; import { + AccountCreateContract, AccountPermissionUpdateContract, + AccountUpdateContract, AssetIssueContract, + CancelFreezeBalanceV2Contract, + ClearABIContract, + ContractParamter, ContractType, CreateSmartContract, DelegateResourceContract, DeployConstantContract, + ExchangeCreateContract, + ExchangeInjectContract, + ExchangeTransactionContract, + ExchangeWithdrawContract, FreezeBalanceContract, FreezeBalanceV2Contract, + ParticipateAssetIssueContract, Permission, + ProposalCreateContract, + ProposalDeleteContract, + SetAccountIdContract, + TransferAssetContract, + TransferContract, TriggerSmartContract, UnDelegateResourceContract, + UnfreezeBalanceContract, UnfreezeBalanceV2Contract, UpdateAssetContract, + UpdateBrokerageContract, + UpdateEnergyLimitContract, + UpdateSettingContract, + VoteProposalContract, + VoteWitnessContract, + WithdrawBalanceContract, + WithdrawExpireUnfreezeContract, + WitnessCreateContract, } from '../../types/Contract.js'; import { createTransaction, @@ -63,7 +87,7 @@ export class TransactionBuilder { amount = 0, from: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ): Promise { + ): Promise> { // accept amounts passed as strings amount = parseInt(amount); @@ -91,14 +115,14 @@ export class TransactionBuilder { }, ]); - const data = { + const data: TransferContract = { to_address: toHex(to), owner_address: toHex(from as string), amount: amount, }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.TransferContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.TransferContract, data, options?.permissionId, transactionOptions); } async sendToken( @@ -107,7 +131,7 @@ export class TransactionBuilder { tokenId: string, from: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ): Promise { + ): Promise> { amount = parseInt(amount); this.validator.notValid([ { @@ -138,7 +162,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: TransferAssetContract = { to_address: toHex(to), owner_address: toHex(from as string), asset_name: fromUtf8(tokenId as string), @@ -146,7 +170,7 @@ export class TransactionBuilder { }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.TransferAssetContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.TransferAssetContract, data, options?.permissionId, transactionOptions); } async purchaseToken( @@ -155,7 +179,7 @@ export class TransactionBuilder { amount = 0, buyer: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'buyer', @@ -185,7 +209,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ParticipateAssetIssueContract = { to_address: toHex(issuerAddress), owner_address: toHex(buyer as string), asset_name: fromUtf8(tokenId as string), @@ -193,7 +217,7 @@ export class TransactionBuilder { }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ParticipateAssetIssueContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ParticipateAssetIssueContract, data, options?.permissionId, transactionOptions); } async freezeBalance( @@ -203,7 +227,7 @@ export class TransactionBuilder { ownerAddress: string = this.tronWeb.defaultAddress.hex as string, receiverAddress?: string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -249,7 +273,7 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.FreezeBalanceContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.FreezeBalanceContract, data, options?.permissionId, transactionOptions); } async unfreezeBalance( @@ -257,7 +281,7 @@ export class TransactionBuilder { address: string = this.tronWeb.defaultAddress.hex as string, receiverAddress?: string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -277,7 +301,7 @@ export class TransactionBuilder { msg: 'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"', }, ]); - const data: { owner_address: string; resource?: Resource; receiver_address?: string } = { + const data: Partial = { owner_address: toHex(address as string), }; if (resource !== 'BANDWIDTH') { @@ -289,7 +313,7 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UnfreezeBalanceContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UnfreezeBalanceContract, data as UnfreezeBalanceContract, options?.permissionId, transactionOptions); } async freezeBalanceV2( @@ -297,7 +321,7 @@ export class TransactionBuilder { resource: Resource = 'BANDWIDTH', address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -326,7 +350,7 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.FreezeBalanceV2Contract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.FreezeBalanceV2Contract, data, options?.permissionId, transactionOptions); } async unfreezeBalanceV2( @@ -334,7 +358,7 @@ export class TransactionBuilder { resource: Resource = 'BANDWIDTH', address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -363,10 +387,13 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UnfreezeBalanceV2Contract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UnfreezeBalanceV2Contract, data, options?.permissionId, transactionOptions); } - async cancelUnfreezeBalanceV2(address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {}) { + async cancelUnfreezeBalanceV2( + address: string = this.tronWeb.defaultAddress.hex as string, + options: TransactionCommonOptions = {} + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -374,12 +401,12 @@ export class TransactionBuilder { value: address as string, }, ]); - const data = { + const data: CancelFreezeBalanceV2Contract = { owner_address: toHex(address as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.CancelAllUnfreezeV2Contract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.CancelAllUnfreezeV2Contract, data, options?.permissionId, transactionOptions); } async delegateResource( @@ -390,7 +417,7 @@ export class TransactionBuilder { lock = false, lockPeriod?: number, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'amount', @@ -447,7 +474,7 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.DelegateResourceContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.DelegateResourceContract, data, options?.permissionId, transactionOptions); } async undelegateResource( @@ -456,7 +483,7 @@ export class TransactionBuilder { resource: Resource = 'BANDWIDTH', address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -496,10 +523,13 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UnDelegateResourceContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UnDelegateResourceContract, data, options?.permissionId, transactionOptions); } - async withdrawExpireUnfreeze(address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {}) { + async withdrawExpireUnfreeze( + address: string = this.tronWeb.defaultAddress.hex as string, + options: TransactionCommonOptions = {} + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -508,15 +538,18 @@ export class TransactionBuilder { }, ]); - const data = { + const data: WithdrawExpireUnfreezeContract = { owner_address: toHex(address), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.WithdrawExpireUnfreezeContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.WithdrawExpireUnfreezeContract, data, options?.permissionId, transactionOptions); } - async withdrawBlockRewards(address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {}) { + async withdrawBlockRewards( + address: string = this.tronWeb.defaultAddress.hex as string, + options: TransactionCommonOptions = {} + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -525,15 +558,19 @@ export class TransactionBuilder { }, ]); - const data = { + const data: WithdrawBalanceContract = { owner_address: toHex(address as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.WithdrawBalanceContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.WithdrawBalanceContract, data, options?.permissionId, transactionOptions); } - async applyForSR(address: string = this.tronWeb.defaultAddress.hex as string, url = '', options: TransactionCommonOptions = {}) { + async applyForSR( + address: string = this.tronWeb.defaultAddress.hex as string, + url = '', + options: TransactionCommonOptions = {} + ): Promise> { this.validator.notValid([ { name: 'origin', @@ -555,20 +592,20 @@ export class TransactionBuilder { }, ]); - const data = { + const data: WitnessCreateContract = { owner_address: toHex(address as string), url: fromUtf8(url as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.WitnessCreateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.WitnessCreateContract, data, options?.permissionId, transactionOptions); } async vote( votes: VoteInfo = {}, voterAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'voter', @@ -606,13 +643,13 @@ export class TransactionBuilder { }; }); - const data = { + const data: VoteWitnessContract = { owner_address: toHex(voterAddress as string), votes: voteList, }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.VoteWitnessContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.VoteWitnessContract, data, options?.permissionId, transactionOptions); } async createSmartContract( @@ -961,7 +998,13 @@ export class TransactionBuilder { callValue?: number, feeLimit?: number ) { - const args: TriggerSmartContract = { + interface IArgs extends TriggerSmartContract { + function_selector?: string; + parameter?: string; + fee_limit?: number; + Permission_id?: number; + } + const args: IArgs = { contract_address: toHex(contractAddress), owner_address: toHex(issuerAddress), }; @@ -1135,7 +1178,7 @@ export class TransactionBuilder { value.token_id = args.token_id; } const transactionOptions = getTransactionOptions(options); - const transaction = await createTransaction( + const transaction = await createTransaction( this.tronWeb, ContractType.TriggerSmartContract, value, @@ -1243,10 +1286,10 @@ export class TransactionBuilder { contractAddress: string, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { if (!TronWeb.isAddress(contractAddress)) throw new Error('Invalid contract address provided'); if (!TronWeb.isAddress(ownerAddress)) throw new Error('Invalid owner address provided'); - const data = { + const data: ClearABIContract = { contract_address: toHex(contractAddress), owner_address: toHex(ownerAddress as string), }; @@ -1260,13 +1303,13 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ClearABIContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ClearABIContract, data, options?.permissionId, transactionOptions); } async updateBrokerage( brokerage: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { if (!isNotNullOrUndefined(brokerage)) throw new Error('Invalid brokerage provided'); if (!isInteger(brokerage) || brokerage < 0 || brokerage > 100) @@ -1274,19 +1317,19 @@ export class TransactionBuilder { if (!TronWeb.isAddress(ownerAddress)) throw new Error('Invalid owner address provided'); - const data = { + const data: UpdateBrokerageContract = { brokerage: parseInt(brokerage), owner_address: toHex(ownerAddress as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UpdateBrokerageContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UpdateBrokerageContract, data, options?.permissionId, transactionOptions); } async createToken( options: CreateTokenOptions = {} as CreateTokenOptions, issuerAddress: string = this.tronWeb.defaultAddress.hex as string - ) { + ): Promise> { const { name = false, abbreviation = false, @@ -1427,7 +1470,7 @@ export class TransactionBuilder { data.vote_score = parseInt(voteScore); } const transactionOptions = getTransactionOptions(options); - return createTransaction( + return createTransaction( this.tronWeb, ContractType.AssetIssueContract, data as AssetIssueContract, @@ -1440,7 +1483,7 @@ export class TransactionBuilder { accountAddress: string, address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'account', @@ -1453,20 +1496,20 @@ export class TransactionBuilder { value: address as string, }, ]); - const data = { + const data: AccountCreateContract = { owner_address: toHex(address as string), account_address: toHex(accountAddress), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.AccountCreateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.AccountCreateContract, data, options?.permissionId, transactionOptions); } async updateAccount( accountName: string, address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'Name', @@ -1483,20 +1526,20 @@ export class TransactionBuilder { }, ]); - const data = { + const data: AccountUpdateContract = { account_name: fromUtf8(accountName as string), owner_address: toHex(address as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.AccountUpdateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.AccountUpdateContract, data, options?.permissionId, transactionOptions); } async setAccountId( accountId: string, address: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { if (accountId && isString(accountId) && accountId.startsWith('0x')) { accountId = accountId.slice(2); } @@ -1521,19 +1564,19 @@ export class TransactionBuilder { }, ]); - const data = { + const data: SetAccountIdContract = { account_id: accountId, owner_address: toHex(address as string), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.SetAccountIdContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.SetAccountIdContract, data, options?.permissionId, transactionOptions); } async updateToken( options: UpdateTokenOptions = {} as UpdateTokenOptions, issuerAddress: string = this.tronWeb.defaultAddress.hex as string - ) { + ): Promise> { const { description = '', url = false, @@ -1580,7 +1623,7 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UpdateAssetContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UpdateAssetContract, data, options?.permissionId, transactionOptions); } async sendAsset( @@ -1622,7 +1665,7 @@ export class TransactionBuilder { parameters: Record | Record[], issuerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'issuer', @@ -1639,13 +1682,13 @@ export class TransactionBuilder { if (!isObject(parameter)) throw new Error(invalid); } - const data = { + const data: ProposalCreateContract = { owner_address: toHex(issuerAddress as string), parameters: newParams, }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ProposalCreateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ProposalCreateContract, data, options?.permissionId, transactionOptions); } /** @@ -1656,7 +1699,7 @@ export class TransactionBuilder { proposalID: number, issuerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'issuer', @@ -1671,13 +1714,13 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ProposalDeleteContract = { owner_address: toHex(issuerAddress as string), proposal_id: parseInt(proposalID as number), }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ProposalDeleteContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ProposalDeleteContract, data, options?.permissionId, transactionOptions); } /** @@ -1689,7 +1732,7 @@ export class TransactionBuilder { isApproval = false, voterAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'voter', @@ -1709,7 +1752,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: VoteProposalContract = { owner_address: toHex(voterAddress as string), proposal_id: parseInt(proposalID), is_add_approval: isApproval, @@ -1730,7 +1773,7 @@ export class TransactionBuilder { trxBalance: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -1754,7 +1797,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ExchangeCreateContract = { owner_address: toHex(ownerAddress as string), first_token_id: fromUtf8(tokenName), first_token_balance: tokenBalance, @@ -1779,7 +1822,7 @@ export class TransactionBuilder { secondTokenBalance: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -1808,7 +1851,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ExchangeCreateContract = { owner_address: toHex(ownerAddress as string), first_token_id: fromUtf8(firstTokenName), first_token_balance: firstTokenBalance, @@ -1817,7 +1860,7 @@ export class TransactionBuilder { }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ExchangeCreateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ExchangeCreateContract, data, options?.permissionId, transactionOptions); } /** @@ -1831,7 +1874,7 @@ export class TransactionBuilder { tokenAmount: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -1857,7 +1900,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ExchangeInjectContract = { owner_address: toHex(ownerAddress as string), exchange_id: parseInt(exchangeID), token_id: fromUtf8(tokenName), @@ -1879,7 +1922,7 @@ export class TransactionBuilder { tokenAmount: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -1905,7 +1948,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ExchangeWithdrawContract = { owner_address: toHex(ownerAddress as string), exchange_id: parseInt(exchangeID), token_id: fromUtf8(tokenName), @@ -1913,7 +1956,7 @@ export class TransactionBuilder { }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ExchangeWithdrawContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ExchangeWithdrawContract, data, options?.permissionId, transactionOptions); } /** @@ -1928,7 +1971,7 @@ export class TransactionBuilder { tokenAmountExpected: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -1960,7 +2003,7 @@ export class TransactionBuilder { }, ]); - const data = { + const data: ExchangeTransactionContract = { owner_address: toHex(ownerAddress as string), exchange_id: parseInt(exchangeID), token_id: TronWeb.fromAscii(tokenName).replace(/^0x/, ''), @@ -1969,7 +2012,7 @@ export class TransactionBuilder { }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.ExchangeTransactionContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.ExchangeTransactionContract, data, options?.permissionId, transactionOptions); } /** @@ -1980,7 +2023,7 @@ export class TransactionBuilder { userFeePercentage: number, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -2001,14 +2044,14 @@ export class TransactionBuilder { }, ]); - const data = { + const data: UpdateSettingContract = { owner_address: toHex(ownerAddress as string), contract_address: toHex(contractAddress), consume_user_resource_percent: userFeePercentage, }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UpdateSettingContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UpdateSettingContract, data, options?.permissionId, transactionOptions); } /** @@ -2019,7 +2062,7 @@ export class TransactionBuilder { originEnergyLimit = 0, ownerAddress: string = this.tronWeb.defaultAddress.hex as string, options: TransactionCommonOptions = {} - ) { + ): Promise> { this.validator.notValid([ { name: 'owner', @@ -2040,14 +2083,14 @@ export class TransactionBuilder { }, ]); - const data = { + const data: UpdateEnergyLimitContract = { owner_address: toHex(ownerAddress as string), contract_address: toHex(contractAddress), origin_energy_limit: originEnergyLimit, }; const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.UpdateEnergyLimitContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.UpdateEnergyLimitContract, data, options?.permissionId, transactionOptions); } private checkPermissions(permissions: Permission, type: number) { @@ -2083,7 +2126,7 @@ export class TransactionBuilder { witnessPermission?: Permission, activesPermissions?: Permission | Permission[], options: TransactionCommonOptions = {} - ) { + ): Promise> { if (!TronWeb.isAddress(ownerAddress as Address)) throw new Error('Invalid ownerAddress provided'); if (!this.checkPermissions(ownerPermission, 0)) { @@ -2149,14 +2192,14 @@ export class TransactionBuilder { } const transactionOptions = getTransactionOptions(options); - return createTransaction(this.tronWeb, ContractType.AccountPermissionUpdateContract, data, options?.permissionId, transactionOptions); + return createTransaction(this.tronWeb, ContractType.AccountPermissionUpdateContract, data, options?.permissionId, transactionOptions); } - async newTxID(transaction: SignedTransaction, options: { txLocal?: boolean } = {}) { + async newTxID | Transaction)>(transaction: U, options: { txLocal?: boolean } = {}): Promise { if (options?.txLocal) { const contract = transaction.raw_data.contract[0]; try { - const tx = await createTransaction( + const tx = await createTransaction( this.tronWeb, contract.type, contract.parameter.value, @@ -2170,9 +2213,9 @@ export class TransactionBuilder { timestamp: transaction.raw_data.timestamp, } ); - (tx as SignedTransaction).signature = transaction.signature; + (tx as SignedTransaction).signature = (transaction as SignedTransaction).signature; tx.visible = transaction.visible; - return tx; + return tx as U; } catch (e) { throw new Error('Error generating a new transaction id.'); } @@ -2191,7 +2234,7 @@ export class TransactionBuilder { // eslint-disable-next-line @typescript-eslint/ban-ts-comment /* @ts-ignore */ { data: transaction.raw_data.data, fee_limit: transaction.raw_data.fee_limit } - ); + ) as unknown as U; } catch (e) { throw new Error('Error generating a new transaction id.'); } @@ -2214,10 +2257,10 @@ export class TransactionBuilder { transaction.raw_data.expiration += options.extension; } - return await this.newTxID(transaction as SignedTransaction, { txLocal: options.txLocal }); + return await this.newTxID(transaction, { txLocal: options.txLocal }); } - async extendExpiration(transaction: SignedTransaction, extension: number, options: TxLocal = {}) { + async extendExpiration(transaction: Transaction, extension: number, options: TxLocal = {}) { return await this.alterTransaction(transaction, { extension, txLocal: options?.txLocal }); } diff --git a/src/lib/TransactionBuilder/helper.ts b/src/lib/TransactionBuilder/helper.ts index e00599f9..2adc4ba5 100644 --- a/src/lib/TransactionBuilder/helper.ts +++ b/src/lib/TransactionBuilder/helper.ts @@ -93,14 +93,14 @@ function checkBlockHeader(options = {} as Partial): boo return true; } -export async function createTransaction( +export async function createTransaction( tronWeb: TronWeb, type: ContractType, - value: ContractParamter, + value: T, Permission_id?: number, options = {} as Partial> -): Promise { - const tx: Transaction = { +): Promise> { + const tx: Transaction = { visible: false, txID: '', raw_data_hex: '', diff --git a/src/types/Contract.ts b/src/types/Contract.ts index 311b7be4..626779c6 100644 --- a/src/types/Contract.ts +++ b/src/types/Contract.ts @@ -86,7 +86,7 @@ export interface TransferContract { export interface TransferAssetContract { to_address: string; owner_address: string; - amount: string; + amount: number; asset_name: string; } @@ -100,15 +100,10 @@ export interface ParticipateAssetIssueContract { export interface TriggerSmartContract { owner_address: string; contract_address: string; - parameter?: string; - function_selector?: string; call_value?: number; call_token_value?: number; token_id?: number; data?: string; - - fee_limit?: number; - Permission_id?: number; } export interface FreezeBalanceContract { @@ -245,55 +240,55 @@ export interface ProposalCreateContract { export interface ProposalDeleteContract { owner_address: string; - proposal_id: string; + proposal_id: number; } export interface VoteProposalContract { owner_address: string; - proposal_id: string; - is_add_approval: string; + proposal_id: number; + is_add_approval: boolean; } export interface ExchangeCreateContract { owner_address: string; first_token_id: string; - first_token_balance: string; + first_token_balance: number; second_token_id: string; - second_token_balance: string; + second_token_balance: number; } export interface ExchangeInjectContract { owner_address: string; - exchange_id: string; + exchange_id: number; token_id: string; - quant: string; + quant: number; } export interface ExchangeWithdrawContract { owner_address: string; - exchange_id: string; + exchange_id: number; token_id: string; - quant: string; + quant: number; } export interface ExchangeTransactionContract { owner_address: string; - exchange_id: string; + exchange_id: number; token_id: string; - quant: string; - expected: string; + quant: number; + expected: number; } export interface UpdateSettingContract { owner_address: string; contract_address: string; - consume_user_resource_percent: string; + consume_user_resource_percent: number; } export interface UpdateEnergyLimitContract { owner_address: string; contract_address: string; - origin_energy_limit: string; + origin_energy_limit: number; } export interface AccountPermissionUpdateContract { diff --git a/src/types/Transaction.ts b/src/types/Transaction.ts index 4a094f33..56e129a0 100644 --- a/src/types/Transaction.ts +++ b/src/types/Transaction.ts @@ -1,4 +1,4 @@ -import { ContractParamter, ContractType, CreateSmartContract } from './Contract.js'; +import { ContractParamter, ContractType, CreateSmartContract, TriggerSmartContract } from './Contract.js'; export interface ContractParamterWrapper { value: T; @@ -44,7 +44,7 @@ export interface TransactionWrapper { /** * The transaction object created by calling contract function. */ - transaction: Transaction; + transaction: Transaction; /** * Energy required for successfully deploying new contract or trigger contract. * This is returned in `transactionBuilder.estimateEnergy()` and `transactionBuilder.deployConstantContract()` @@ -64,7 +64,7 @@ export interface TransactionWrapper { constant_result?: any; } -export interface SignedTransaction extends Transaction { +export interface SignedTransaction extends Transaction { signature: string[]; contract_address?: string; } diff --git a/test/lib/transactionBuilder.test.ts b/test/lib/transactionBuilder.test.ts index aeefcab2..4f2fbfd8 100644 --- a/test/lib/transactionBuilder.test.ts +++ b/test/lib/transactionBuilder.test.ts @@ -2278,6 +2278,7 @@ describe('TronWeb.transactionBuilder', function () { accounts.hex[7] ) ); + await wait(3); transactions.push( await tronWeb.transactionBuilder.createSmartContract( { @@ -2287,6 +2288,7 @@ describe('TronWeb.transactionBuilder', function () { accounts.hex[7] ) ); + await wait(3); transactions.push( await tronWeb.transactionBuilder.createSmartContract( { From 8d7e7829fd2b7a5ebc234d0dbb0506560899bfb3 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 14 Aug 2024 17:10:32 +0800 Subject: [PATCH 03/28] feat: add surfix .js for type files --- src/index.ts | 2 +- src/lib/TransactionBuilder/TransactionBuilder.ts | 12 ++++++------ src/lib/contract/method.ts | 2 +- src/lib/trx.ts | 2 +- src/tronweb.ts | 14 +++++++------- src/types/APIResponse.ts | 4 ++-- src/types/Contract.ts | 4 ++-- src/types/TransactionBuilder.ts | 4 ++-- src/types/TronWeb.ts | 3 +++ src/utils/validations.ts | 3 ++- 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/index.ts b/src/index.ts index bc8e6746..48a3ac87 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import utils from './utils/index.js'; export { utils }; -import { BigNumber } from 'bignumber.js'; +import BigNumber from 'bignumber.js'; export { BigNumber }; import { providers } from './lib/providers/index.js'; diff --git a/src/lib/TransactionBuilder/TransactionBuilder.ts b/src/lib/TransactionBuilder/TransactionBuilder.ts index ab925ebb..f18f50ca 100644 --- a/src/lib/TransactionBuilder/TransactionBuilder.ts +++ b/src/lib/TransactionBuilder/TransactionBuilder.ts @@ -71,6 +71,12 @@ import { import { Address } from '../../types/Trx.js'; import { ConstructorFragment, ContractAbiInterface, FunctionFragment } from '../../types/ABI.js'; +interface IArgs extends TriggerSmartContract { + function_selector?: string; + parameter?: string; + fee_limit?: number; + Permission_id?: number; +} export class TransactionBuilder { private tronWeb: TronWeb; private validator: Validator; @@ -998,12 +1004,6 @@ export class TransactionBuilder { callValue?: number, feeLimit?: number ) { - interface IArgs extends TriggerSmartContract { - function_selector?: string; - parameter?: string; - fee_limit?: number; - Permission_id?: number; - } const args: IArgs = { contract_address: toHex(contractAddress), owner_address: toHex(issuerAddress), diff --git a/src/lib/contract/method.ts b/src/lib/contract/method.ts index 8d4c707a..e4007524 100644 --- a/src/lib/contract/method.ts +++ b/src/lib/contract/method.ts @@ -38,7 +38,7 @@ import type { EventFragment, AbiInputsType, AbiOutputsType, -} from '../../types/ABI'; +} from '../../types/ABI.js'; export type AbiFragmentNoErrConstructor = FunctionFragment | EventFragment | FallbackFragment | ReceiveFragment; diff --git a/src/lib/trx.ts b/src/lib/trx.ts index b3bb4ab1..a5d56f83 100644 --- a/src/lib/trx.ts +++ b/src/lib/trx.ts @@ -24,7 +24,7 @@ import { } from '../types/Trx.js'; import { SignedTransaction, Transaction } from '../types/Transaction.js'; import { TypedDataDomain, TypedDataField } from '../utils/typedData.js'; -import { Resource } from '../types/TransactionBuilder'; +import { Resource } from '../types/TransactionBuilder.js'; const TRX_MESSAGE_HEADER = '\x19TRON Signed Message:\n32'; // it should be: '\x15TRON Signed Message:\n32'; diff --git a/src/tronweb.ts b/src/tronweb.ts index 1f3b7e19..3bd045d8 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -14,7 +14,7 @@ import { keccak256 } from './utils/ethersUtils.js'; import { fromHex, fromPrivateKey, isAddress, toHex } from './utils/address.js'; import { HeadersType } from './types/Providers.js'; import { isString } from './utils/validations.js'; -import { DefaultAddress, NodeProvider, TronWebOptions } from './types/TronWeb.js'; +import { DefaultAddress, NodeProvider, TronWebOptions, IBigNumber } from './types/TronWeb.js'; import { ContractAbiInterface } from './types/ABI.js'; import { Address } from './types/Trx.js'; @@ -288,7 +288,7 @@ export class TronWeb extends EventEmitter { } toHex: typeof TronWeb.toHex; - static toHex(val: string | number | boolean | Record | unknown[] | BigNumber) { + static toHex(val: string | number | boolean | Record | unknown[] | IBigNumber) { if (utils.isBoolean(val)) return TronWeb.fromDecimal(+val); if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val); @@ -357,12 +357,12 @@ export class TronWeb extends EventEmitter { } toDecimal: typeof TronWeb.toDecimal; - static toDecimal(value: string | number | BigNumber) { + static toDecimal(value: string | number | IBigNumber) { return TronWeb.toBigNumber(value).toNumber(); } fromDecimal: typeof TronWeb.fromDecimal; - static fromDecimal(value: number | BigNumber) { + static fromDecimal(value: number | IBigNumber) { const number = TronWeb.toBigNumber(value); const result = number.toString(16); @@ -370,19 +370,19 @@ export class TronWeb extends EventEmitter { } fromSun: typeof TronWeb.fromSun; - static fromSun(sun: number) { + static fromSun(sun: number): string | IBigNumber { const trx = TronWeb.toBigNumber(sun).div(1_000_000); return utils.isBigNumber(sun) ? trx : trx.toString(10); } toSun: typeof TronWeb.toSun; - static toSun(trx: number) { + static toSun(trx: number): string | IBigNumber { const sun = TronWeb.toBigNumber(trx).times(1_000_000); return utils.isBigNumber(trx) ? sun : sun.toString(10); } toBigNumber: typeof TronWeb.toBigNumber; - static toBigNumber(amount: string | number | BigNumber = 0) { + static toBigNumber(amount: string | number | IBigNumber = 0): IBigNumber { if (utils.isBigNumber(amount)) return amount; if (utils.isString(amount) && /^(-|)0x/.test(amount)) return new BigNumber(amount.replace('0x', ''), 16); diff --git a/src/types/APIResponse.ts b/src/types/APIResponse.ts index 95366d6d..a4e6e244 100644 --- a/src/types/APIResponse.ts +++ b/src/types/APIResponse.ts @@ -1,5 +1,5 @@ -import { Permission } from './Contract'; -import { Transaction, TransactionWrapper } from './Transaction'; +import { Permission } from './Contract.js'; +import { Transaction, TransactionWrapper } from './Transaction.js'; export interface BlockHeaderRawData { number: number; diff --git a/src/types/Contract.ts b/src/types/Contract.ts index 626779c6..1196abf1 100644 --- a/src/types/Contract.ts +++ b/src/types/Contract.ts @@ -1,5 +1,5 @@ -import { Resource } from '../types/TransactionBuilder'; -import { ContractAbiInterface } from './ABI'; +import { Resource } from '../types/TransactionBuilder.js'; +import { ContractAbiInterface } from './ABI.js'; export enum ContractType { AccountCreateContract = 'AccountCreateContract', TransferContract = 'TransferContract', diff --git a/src/types/TransactionBuilder.ts b/src/types/TransactionBuilder.ts index 40d298c4..e3e31ee1 100644 --- a/src/types/TransactionBuilder.ts +++ b/src/types/TransactionBuilder.ts @@ -1,5 +1,5 @@ -import { AbiFragment, ContractAbiInterface } from './ABI'; -import { Transaction } from './Transaction'; +import { AbiFragment, ContractAbiInterface } from './ABI.js'; +import { Transaction } from './Transaction.js'; export interface TransactionCommonOptions { /** diff --git a/src/types/TronWeb.ts b/src/types/TronWeb.ts index 45422585..8858f72d 100644 --- a/src/types/TronWeb.ts +++ b/src/types/TronWeb.ts @@ -1,7 +1,10 @@ import { AxiosRequestHeaders } from 'axios'; +import BigNumber from 'bignumber.js'; import type { HeadersType } from './Providers.js'; import HttpProvider from '../lib/providers/HttpProvider.js'; +export type IBigNumber = InstanceType; + export interface TronWebOptions { fullNode?: NodeProvider; solidityNode?: NodeProvider; diff --git a/src/utils/validations.ts b/src/utils/validations.ts index 7b77e1fa..4b18c6c6 100644 --- a/src/utils/validations.ts +++ b/src/utils/validations.ts @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'; import validator from 'validator'; import { ADDRESS_PREFIX } from './address.js'; import { AbiParamsCommon } from '../types/ABI.js'; +import { IBigNumber } from '../types/TronWeb.js'; export function isValidURL(url: string): boolean { if (typeof url !== 'string') return false; @@ -31,7 +32,7 @@ export function isBoolean(bool: unknown): bool is boolean { return typeof bool === 'boolean'; } -export function isBigNumber(number: unknown): number is BigNumber { +export function isBigNumber(number: unknown): number is IBigNumber { return !!number && (number instanceof BigNumber || (number.constructor && number.constructor.name === 'BigNumber')); } From 796cde860e47f970c504ff77f50127a0ffb2ed60 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 15 Aug 2024 12:05:56 +0800 Subject: [PATCH 04/28] fix: the return type of isBigNumber is changed by ts so change the return type --- src/tronweb.ts | 4 ++-- src/utils/validations.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/tronweb.ts b/src/tronweb.ts index 3bd045d8..b5b50e1a 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -291,7 +291,7 @@ export class TronWeb extends EventEmitter { static toHex(val: string | number | boolean | Record | unknown[] | IBigNumber) { if (utils.isBoolean(val)) return TronWeb.fromDecimal(+val); - if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val); + if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val as IBigNumber); if (typeof val === 'object') return TronWeb.fromUtf8(JSON.stringify(val)); @@ -383,7 +383,7 @@ export class TronWeb extends EventEmitter { toBigNumber: typeof TronWeb.toBigNumber; static toBigNumber(amount: string | number | IBigNumber = 0): IBigNumber { - if (utils.isBigNumber(amount)) return amount; + if (utils.isBigNumber(amount)) return amount as IBigNumber; if (utils.isString(amount) && /^(-|)0x/.test(amount)) return new BigNumber(amount.replace('0x', ''), 16); diff --git a/src/utils/validations.ts b/src/utils/validations.ts index 4b18c6c6..80e74e33 100644 --- a/src/utils/validations.ts +++ b/src/utils/validations.ts @@ -2,7 +2,6 @@ import BigNumber from 'bignumber.js'; import validator from 'validator'; import { ADDRESS_PREFIX } from './address.js'; import { AbiParamsCommon } from '../types/ABI.js'; -import { IBigNumber } from '../types/TronWeb.js'; export function isValidURL(url: string): boolean { if (typeof url !== 'string') return false; @@ -32,7 +31,7 @@ export function isBoolean(bool: unknown): bool is boolean { return typeof bool === 'boolean'; } -export function isBigNumber(number: unknown): number is IBigNumber { +export function isBigNumber(number: unknown) { return !!number && (number instanceof BigNumber || (number.constructor && number.constructor.name === 'BigNumber')); } From 46776a9b9d7b413fb38b91a39a8cab7f1f5e1c17 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 15 Aug 2024 12:11:25 +0800 Subject: [PATCH 05/28] feat: fix audit issue --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0fd1e1b5..07f8a748 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@babel/runtime": "^7.0.0", "@tronweb3/google-protobuf": "^3.21.2", - "axios": "^1.6.8", + "axios": "^1.7.4", "bignumber.js": "^9.0.1", "ethereum-cryptography": "^2.1.3", "ethers": "^6.13.1", @@ -3253,9 +3253,9 @@ } }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/package.json b/package.json index a0b23965..e362b2f7 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dependencies": { "@babel/runtime": "^7.0.0", "@tronweb3/google-protobuf": "^3.21.2", - "axios": "^1.6.8", + "axios": "^1.7.4", "bignumber.js": "^9.0.1", "ethereum-cryptography": "^2.1.3", "ethers": "^6.13.1", From d3c16e1a68f2833d94696d4adc85f2d45c12af1f Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 15 Aug 2024 12:45:35 +0800 Subject: [PATCH 06/28] chore: update typescript --- package-lock.json | 8 ++++---- package.json | 2 +- src/tronweb.ts | 4 ++-- src/utils/validations.ts | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 07f8a748..7bc4053a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,7 +70,7 @@ "rimraf": "^3.0.2", "source-map-support": "^0.5.19", "ts-loader": "^9.4.3", - "typescript": "^5.1.6", + "typescript": "^5.5.4", "webpack": "^5.78.0", "webpack-cli": "^5.0.1", "webpack-node-externals": "^3.0.0" @@ -9911,9 +9911,9 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index e362b2f7..fab084be 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "rimraf": "^3.0.2", "source-map-support": "^0.5.19", "ts-loader": "^9.4.3", - "typescript": "^5.1.6", + "typescript": "^5.5.4", "webpack": "^5.78.0", "webpack-cli": "^5.0.1", "webpack-node-externals": "^3.0.0" diff --git a/src/tronweb.ts b/src/tronweb.ts index b5b50e1a..3bd045d8 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -291,7 +291,7 @@ export class TronWeb extends EventEmitter { static toHex(val: string | number | boolean | Record | unknown[] | IBigNumber) { if (utils.isBoolean(val)) return TronWeb.fromDecimal(+val); - if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val as IBigNumber); + if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val); if (typeof val === 'object') return TronWeb.fromUtf8(JSON.stringify(val)); @@ -383,7 +383,7 @@ export class TronWeb extends EventEmitter { toBigNumber: typeof TronWeb.toBigNumber; static toBigNumber(amount: string | number | IBigNumber = 0): IBigNumber { - if (utils.isBigNumber(amount)) return amount as IBigNumber; + if (utils.isBigNumber(amount)) return amount; if (utils.isString(amount) && /^(-|)0x/.test(amount)) return new BigNumber(amount.replace('0x', ''), 16); diff --git a/src/utils/validations.ts b/src/utils/validations.ts index 80e74e33..4b18c6c6 100644 --- a/src/utils/validations.ts +++ b/src/utils/validations.ts @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'; import validator from 'validator'; import { ADDRESS_PREFIX } from './address.js'; import { AbiParamsCommon } from '../types/ABI.js'; +import { IBigNumber } from '../types/TronWeb.js'; export function isValidURL(url: string): boolean { if (typeof url !== 'string') return false; @@ -31,7 +32,7 @@ export function isBoolean(bool: unknown): bool is boolean { return typeof bool === 'boolean'; } -export function isBigNumber(number: unknown) { +export function isBigNumber(number: unknown): number is IBigNumber { return !!number && (number instanceof BigNumber || (number.constructor && number.constructor.name === 'BigNumber')); } From 0e2e6ca3f2fa5f0f3d89469c17e85b683d9500b0 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 15 Aug 2024 15:35:47 +0800 Subject: [PATCH 07/28] feat: change version --- package-lock.json | 4 ++-- package.json | 2 +- src/tronweb.ts | 2 +- test/helpers/BlockLib.ts | 2 +- test/helpers/GetNowBlock.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7bc4053a..7a4a9eec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tronweb", - "version": "6.0.0-beta.4", + "version": "6.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tronweb", - "version": "6.0.0-beta.4", + "version": "6.0.0", "license": "MIT", "dependencies": { "@babel/runtime": "^7.0.0", diff --git a/package.json b/package.json index fab084be..9076993d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tronweb", - "version": "6.0.0-beta.4", + "version": "6.0.0", "description": "JavaScript SDK that encapsulates the TRON HTTP API", "main": "./lib/commonjs/index.js", "module": "./lib/esm/index.js", diff --git a/src/tronweb.ts b/src/tronweb.ts index 3bd045d8..b00ec5bb 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -22,7 +22,7 @@ const DEFAULT_VERSION = '4.7.1'; const FEE_LIMIT = 150000000; -const version = '6.0.0-beta.4'; +const version = '6.0.0'; function isValidOptions(options: unknown): options is TronWebOptions { return ( diff --git a/test/helpers/BlockLib.ts b/test/helpers/BlockLib.ts index aa205667..284d5dcd 100644 --- a/test/helpers/BlockLib.ts +++ b/test/helpers/BlockLib.ts @@ -15,7 +15,7 @@ export default class BlockLib { pluginInterface() { return { - requires: '^6.0.0-beta.0', + requires: '^6.0.0', fullClass: true, }; } diff --git a/test/helpers/GetNowBlock.ts b/test/helpers/GetNowBlock.ts index 800b7a19..1dd5c517 100644 --- a/test/helpers/GetNowBlock.ts +++ b/test/helpers/GetNowBlock.ts @@ -25,7 +25,7 @@ export default class GetNowBlock { someParameter = options.someParameter; } return { - requires: '^6.0.0-beta.0', + requires: '^6.0.0', components: { trx: { // will be overridden From f0807236d1cd9d821f2aa74f5ee1ce6fd4df6594 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Fri, 16 Aug 2024 15:17:03 +0800 Subject: [PATCH 08/28] feat: using named import of bignumber.js --- src/index.ts | 2 +- src/tronweb.ts | 2 +- src/types/TronWeb.ts | 2 +- src/utils/validations.ts | 2 +- test/index.test.ts | 2 +- test/utils/index.test.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 48a3ac87..bc8e6746 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import utils from './utils/index.js'; export { utils }; -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; export { BigNumber }; import { providers } from './lib/providers/index.js'; diff --git a/src/tronweb.ts b/src/tronweb.ts index b00ec5bb..7050aaed 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -1,7 +1,7 @@ import { HttpProvider, providers } from './lib/providers/index.js'; import type { Providers } from './lib/providers/index.js'; import utils from './utils/index.js'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; import EventEmitter from 'eventemitter3'; import semver from 'semver'; diff --git a/src/types/TronWeb.ts b/src/types/TronWeb.ts index 8858f72d..08a35abd 100644 --- a/src/types/TronWeb.ts +++ b/src/types/TronWeb.ts @@ -1,5 +1,5 @@ import { AxiosRequestHeaders } from 'axios'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; import type { HeadersType } from './Providers.js'; import HttpProvider from '../lib/providers/HttpProvider.js'; diff --git a/src/utils/validations.ts b/src/utils/validations.ts index 4b18c6c6..9ad7ad4c 100644 --- a/src/utils/validations.ts +++ b/src/utils/validations.ts @@ -1,4 +1,4 @@ -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; import validator from 'validator'; import { ADDRESS_PREFIX } from './address.js'; import { AbiParamsCommon } from '../types/ABI.js'; diff --git a/test/index.test.ts b/test/index.test.ts index d751954f..c7bbdf6d 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -2,7 +2,7 @@ import { assert } from 'chai'; import Config from './helpers/config.js'; import { Contract, TronWeb, providers, Types } from './setup/TronWeb.js'; import tronWebBuilder from './helpers/tronWebBuilder.js'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; import broadcaster from './helpers/broadcaster.js'; import wait from './helpers/wait.js'; diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 8d4b0bdd..6368c6f7 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; import tronWebBuilder from '../helpers/tronWebBuilder.js'; -import BigNumber from 'bignumber.js'; +import { BigNumber } from 'bignumber.js'; describe('TronWeb.utils', function () { describe('#isValidURL()', function () { From 06c500f444d3c75317284b3d929af3d61f8f1d4f Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 21 Aug 2024 10:51:29 +0800 Subject: [PATCH 09/28] feat: change frozen type in Account type --- src/types/TransactionBuilder.ts | 2 +- src/types/Trx.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/types/TransactionBuilder.ts b/src/types/TransactionBuilder.ts index e3e31ee1..bee44c96 100644 --- a/src/types/TransactionBuilder.ts +++ b/src/types/TransactionBuilder.ts @@ -12,7 +12,7 @@ export interface TransactionCommonOptions { export type NumberLike = string | number; -export type Resource = 'BANDWIDTH' | 'ENERGY'; +export type Resource = 'BANDWIDTH' | 'ENERGY' | 'TRON_POWER'; export interface VoteInfo { [srAddress: string]: number; diff --git a/src/types/Trx.ts b/src/types/Trx.ts index d60356ce..15ec05cb 100644 --- a/src/types/Trx.ts +++ b/src/types/Trx.ts @@ -1,5 +1,6 @@ import { AccountType, Permission } from './Contract.js'; import { SignedTransaction, Transaction } from './Transaction.js'; +import { Resource } from './TransactionBuilder.js'; type HTTPMap = Record[]; @@ -62,11 +63,11 @@ export enum ResourceCode { } export interface FreezeV2 { - type: ResourceCode; + type: Resource; amount: number; } export interface UnFreezeV2 { - type: ResourceCode; + type: Resource; unfreeze_amount: number; unfreeze_expire_time: number; } From 2b497d17e25d2d3e84043858894ea771dc647316 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 22 Aug 2024 11:24:55 +0800 Subject: [PATCH 10/28] fix: fix parameters type in CreateSmartContractOptions --- src/lib/TransactionBuilder/TransactionBuilder.ts | 14 ++++++++------ src/types/TransactionBuilder.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/TransactionBuilder/TransactionBuilder.ts b/src/lib/TransactionBuilder/TransactionBuilder.ts index f18f50ca..0f82fcb1 100644 --- a/src/lib/TransactionBuilder/TransactionBuilder.ts +++ b/src/lib/TransactionBuilder/TransactionBuilder.ts @@ -674,7 +674,9 @@ export class TransactionBuilder { // @ts-ignore const tokenId = options.tokenId || options.token_id; - let { abi, parameters = [] } = options; + let { abi } = options; + const { parameters = [] } = options; + let parameter = ''; const { bytecode = false, name = '' } = options; if (abi && isString(abi)) { try { @@ -761,9 +763,9 @@ export class TransactionBuilder { const { rawParameter, funcABIV2, parametersV2 } = options as any; if (rawParameter && isString(rawParameter)) { - parameters = rawParameter.replace(/^(0x)/, ''); + parameter = rawParameter.replace(/^(0x)/, ''); } else if (funcABIV2) { - parameters = encodeParamsV2ByABI(funcABIV2, parametersV2).replace(/^(0x)/, ''); + parameter = encodeParamsV2ByABI(funcABIV2, parametersV2).replace(/^(0x)/, ''); } else { let constructorParams: any = entries.find((it: any) => { return it.type === 'constructor'; @@ -801,12 +803,12 @@ export class TransactionBuilder { } try { - parameters = abiCoder.encode(types, values).replace(/^(0x)/, ''); + parameter = abiCoder.encode(types, values).replace(/^(0x)/, ''); } catch (ex) { throw new Error(ex as string); } } else { - parameters = ''; + parameter = ''; } } @@ -818,7 +820,7 @@ export class TransactionBuilder { origin_energy_limit: originEnergyLimit, abi: JSON.stringify(abi), bytecode, - parameter: parameters, + parameter, name, }; diff --git a/src/types/TransactionBuilder.ts b/src/types/TransactionBuilder.ts index bee44c96..0201b7ba 100644 --- a/src/types/TransactionBuilder.ts +++ b/src/types/TransactionBuilder.ts @@ -57,7 +57,7 @@ export interface CreateSmartContractOptions extends TransactionCommonOptions { * It should be converted hexString after encoded according to ABI encoder. * If constructor has no parameter, this can be optional */ - parameters?: string; + parameters?: unknown[]; /** * Contract name string. */ From 2e8e27973955b9e9a34bc0f77444d3c994830799 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Mon, 26 Aug 2024 15:32:30 +0800 Subject: [PATCH 11/28] chore: updates micromatch package to address an audit issue --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a4a9eec..1a6ef427 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7706,9 +7706,9 @@ } }, "node_modules/micromatch": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", - "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { "braces": "^3.0.3", From 5c97a4ca783ae673397694db266ed0df187ff476 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Tue, 27 Aug 2024 15:36:08 +0800 Subject: [PATCH 12/28] feat: move all types in utils into a single file --- src/types/UtilsTypes.ts | 25 +++++++++++++++++++++++++ src/types/index.ts | 1 + src/utils/base58.ts | 2 +- src/utils/bytes.ts | 3 +-- src/utils/code.ts | 3 ++- src/utils/crypto.ts | 4 +++- src/utils/validations.ts | 26 ++------------------------ 7 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 src/types/UtilsTypes.ts diff --git a/src/types/UtilsTypes.ts b/src/types/UtilsTypes.ts new file mode 100644 index 00000000..d533329f --- /dev/null +++ b/src/types/UtilsTypes.ts @@ -0,0 +1,25 @@ +export type BytesLike = number[] | Uint8Array; + +export type EventQueryDataType = { + block_number: number; + block_timestamp: number; + contract_address: string; + event_name: string; + transaction_id: string; + result: unknown; + resource_Node: string; + _unconfirmed?: boolean; + _fingerprint?: string | undefined; +}; + +export type MapEventQueryDataType = { + block: number; + timestamp: number; + contract: string; + name: string; + transaction: string; + result: unknown; + resourceNode: string; + unconfirmed?: boolean; + fingerprint?: string | undefined; +}; diff --git a/src/types/index.ts b/src/types/index.ts index 1efc3af6..1f03726f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -6,3 +6,4 @@ export * from './Transaction.js'; export * from './TransactionBuilder.js'; export * from './TronWeb.js'; export * from './Trx.js'; +export * from './UtilsTypes.js'; diff --git a/src/utils/base58.ts b/src/utils/base58.ts index b06e8e2e..dd1b6abd 100644 --- a/src/utils/base58.ts +++ b/src/utils/base58.ts @@ -1,4 +1,4 @@ -import type { BytesLike } from './bytes.js'; +import type { BytesLike } from '../types/UtilsTypes.js'; const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; const ALPHABET_MAP = {} as Record; diff --git a/src/utils/bytes.ts b/src/utils/bytes.ts index f3b3cbcf..45344a0f 100644 --- a/src/utils/bytes.ts +++ b/src/utils/bytes.ts @@ -1,6 +1,5 @@ import { Base64 } from './base64.js'; - -export type BytesLike = number[] | Uint8Array; +import { BytesLike } from '../types/UtilsTypes.js'; export function byte2hexStr(byte: number) { if (byte < 0 || byte > 255) throw new Error('Input must be a byte'); diff --git a/src/utils/code.ts b/src/utils/code.ts index db4542ef..e8815ab6 100644 --- a/src/utils/code.ts +++ b/src/utils/code.ts @@ -6,7 +6,8 @@ import { base64DecodeFromString, base64EncodeToString, } from './bytes.js'; -import type { BytesLike } from './bytes.js'; + +import type { BytesLike } from '../types/UtilsTypes.js'; export function bin2String(array: BytesLike) { return bytesToString(array); diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index 749b1919..652353eb 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -1,13 +1,15 @@ import { ADDRESS_PREFIX, ADDRESS_PREFIX_BYTE, ADDRESS_SIZE } from './address.js'; import { base64EncodeToString, base64DecodeFromString, hexStr2byteArray } from './code.js'; import { encode58, decode58 } from './base58.js'; -import { BytesLike, byte2hexStr, byteArray2hexStr } from './bytes.js'; +import { byte2hexStr, byteArray2hexStr } from './bytes.js'; import { keccak256, sha256, SigningKey, recoverAddress, arrayify, Signature } from './ethersUtils.js'; import { TypedDataEncoder } from './typedData.js'; import { secp256k1 as secp } from 'ethereum-cryptography/secp256k1'; import type { TypedDataDomain, TypedDataField } from 'ethers'; import { SignedTransaction } from '../types/Transaction.js'; +import type { BytesLike } from '../types/UtilsTypes.js'; + function normalizePrivateKeyBytes(priKeyBytes: BytesLike) { return hexStr2byteArray(byteArray2hexStr(priKeyBytes).padStart(64, '0')); } diff --git a/src/utils/validations.ts b/src/utils/validations.ts index 9ad7ad4c..08f58648 100644 --- a/src/utils/validations.ts +++ b/src/utils/validations.ts @@ -4,6 +4,8 @@ import { ADDRESS_PREFIX } from './address.js'; import { AbiParamsCommon } from '../types/ABI.js'; import { IBigNumber } from '../types/TronWeb.js'; +import type { EventQueryDataType, MapEventQueryDataType } from '../types/UtilsTypes.js'; + export function isValidURL(url: string): boolean { if (typeof url !== 'string') return false; return validator.isURL(url.toString(), { @@ -68,30 +70,6 @@ export function hasProperties(obj: object, ...properties: (string | number | sym ); } -export type EventQueryDataType = { - block_number: number; - block_timestamp: number; - contract_address: string; - event_name: string; - transaction_id: string; - result: unknown; - resource_Node: string; - _unconfirmed?: boolean; - _fingerprint?: string | undefined; -}; - -export type MapEventQueryDataType = { - block: number; - timestamp: number; - contract: string; - name: string; - transaction: string; - result: unknown; - resourceNode: string; - unconfirmed?: boolean; - fingerprint?: string | undefined; -}; - export function mapEvent(event: EventQueryDataType) { const data: MapEventQueryDataType = { block: event.block_number, From 94d42ad029f5df6c221a91660a42f85312c2b636 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Tue, 27 Aug 2024 17:47:42 +0800 Subject: [PATCH 13/28] fix: import BytesLike from types --- src/utils/base64.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/base64.ts b/src/utils/base64.ts index d31bc366..37ccbb1b 100644 --- a/src/utils/base64.ts +++ b/src/utils/base64.ts @@ -1,4 +1,4 @@ -import { BytesLike } from './bytes.js'; +import type { BytesLike } from '../types/UtilsTypes.js'; const _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; From fbb68aaf32ddc093b0e77a0b7590329de40cd25e Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 28 Aug 2024 15:52:23 +0800 Subject: [PATCH 14/28] chore: upgrade webpack to solve xss problem --- package-lock.json | 45 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1a6ef427..8bcfb75a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2379,26 +2379,6 @@ "@types/node": "*" } }, - "node_modules/@types/eslint": { - "version": "8.56.10", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.10.tgz", - "integrity": "sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ==", - "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint-scope": { - "version": "3.7.7", - "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", - "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", - "dev": true, - "dependencies": { - "@types/eslint": "*", - "@types/estree": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -2953,10 +2933,10 @@ "node": ">=0.4.0" } }, - "node_modules/acorn-import-assertions": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/acorn-import-assertions/-/acorn-import-assertions-1.9.0.tgz", - "integrity": "sha512-cmMwop9x+8KFhxvKrKfPYmN6/pKTYYHBqLa0DfvVZcKMJWNyWLnaqND7dx/qn66R7ewM1UX5XMaDVP5wlVTaVA==", + "node_modules/acorn-import-attributes": { + "version": "1.9.5", + "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", + "integrity": "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==", "dev": true, "peerDependencies": { "acorn": "^8" @@ -4416,9 +4396,9 @@ } }, "node_modules/enhanced-resolve": { - "version": "5.17.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.0.tgz", - "integrity": "sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==", + "version": "5.17.1", + "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz", + "integrity": "sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==", "dev": true, "dependencies": { "graceful-fs": "^4.2.4", @@ -10167,21 +10147,20 @@ } }, "node_modules/webpack": { - "version": "5.91.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.91.0.tgz", - "integrity": "sha512-rzVwlLeBWHJbmgTC/8TvAcu5vpJNII+MelQpylD4jNERPwpBJOE2lEcko1zJX3QJeLjTTAnQxn/OJ8bjDzVQaw==", + "version": "5.94.0", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.94.0.tgz", + "integrity": "sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==", "dev": true, "dependencies": { - "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.5", "@webassemblyjs/ast": "^1.12.1", "@webassemblyjs/wasm-edit": "^1.12.1", "@webassemblyjs/wasm-parser": "^1.12.1", "acorn": "^8.7.1", - "acorn-import-assertions": "^1.9.0", + "acorn-import-attributes": "^1.9.5", "browserslist": "^4.21.10", "chrome-trace-event": "^1.0.2", - "enhanced-resolve": "^5.16.0", + "enhanced-resolve": "^5.17.1", "es-module-lexer": "^1.2.1", "eslint-scope": "5.1.1", "events": "^3.2.0", From 934b047514b03cb31dc31a81b42ff387bdca6e51 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 28 Aug 2024 16:53:29 +0800 Subject: [PATCH 15/28] feat: now only support two type of Resource --- src/types/TransactionBuilder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/TransactionBuilder.ts b/src/types/TransactionBuilder.ts index 0201b7ba..4ffdca5a 100644 --- a/src/types/TransactionBuilder.ts +++ b/src/types/TransactionBuilder.ts @@ -12,7 +12,7 @@ export interface TransactionCommonOptions { export type NumberLike = string | number; -export type Resource = 'BANDWIDTH' | 'ENERGY' | 'TRON_POWER'; +export type Resource = 'BANDWIDTH' | 'ENERGY'; export interface VoteInfo { [srAddress: string]: number; From ba2c702751bdd002a9e04e6195729971df45b526 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 29 Aug 2024 15:05:00 +0800 Subject: [PATCH 16/28] chore: bump webpack --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8bcfb75a..9c339c08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,7 +71,7 @@ "source-map-support": "^0.5.19", "ts-loader": "^9.4.3", "typescript": "^5.5.4", - "webpack": "^5.78.0", + "webpack": "^5.94.0", "webpack-cli": "^5.0.1", "webpack-node-externals": "^3.0.0" } diff --git a/package.json b/package.json index 9076993d..7563f945 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "source-map-support": "^0.5.19", "ts-loader": "^9.4.3", "typescript": "^5.5.4", - "webpack": "^5.78.0", + "webpack": "^5.94.0", "webpack-cli": "^5.0.1", "webpack-node-externals": "^3.0.0" }, From be99b361386619f10611c2d7b7e4b2841524829d Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Mon, 2 Sep 2024 16:30:52 +0800 Subject: [PATCH 17/28] feat: delete deprecated callback argument --- src/lib/contract/index.ts | 2 +- src/lib/trx.ts | 4 ---- src/tronweb.ts | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib/contract/index.ts b/src/lib/contract/index.ts index 42929a52..d4017a97 100644 --- a/src/lib/contract/index.ts +++ b/src/lib/contract/index.ts @@ -105,7 +105,7 @@ export class Contract { }; } - async new(options: CreateSmartContractOptions, privateKey = this.tronWeb.defaultPrivateKey, callback = false) { + async new(options: CreateSmartContractOptions, privateKey = this.tronWeb.defaultPrivateKey) { const address = this.tronWeb.address.fromPrivateKey(privateKey as string); const transaction = await this.tronWeb.transactionBuilder.createSmartContract(options, address as Address); const signedTransaction = await this.tronWeb.trx.sign(transaction, privateKey); diff --git a/src/lib/trx.ts b/src/lib/trx.ts index a5d56f83..e3bee6bb 100644 --- a/src/lib/trx.ts +++ b/src/lib/trx.ts @@ -655,7 +655,6 @@ export class Trx { * @param {message to be signed, should be Bytes or string} message * @param {privateKey for signature} privateKey * @param {reserved} options - * @param {callback function} callback */ signMessageV2(message: string | Uint8Array | Array, privateKey = this.tronWeb.defaultPrivateKey) { return Trx.signMessageV2(message, privateKey as string); @@ -872,7 +871,6 @@ export class Trx { * @param duration - is the duration in days to be frozen * @param resource - is the type, must be either "ENERGY" or "BANDWIDTH" * @param options - * @param callback */ async freezeBalance( amount = 0, @@ -924,7 +922,6 @@ export class Trx { * * @param resource - is the type, must be either "ENERGY" or "BANDWIDTH" * @param options - * @param callback */ async unfreezeBalance( resource: Resource = 'BANDWIDTH', @@ -964,7 +961,6 @@ export class Trx { * * @param privateKey - Account private Key * @param accountName - name of the account - * @param callback * * @return modified Transaction Object */ diff --git a/src/tronweb.ts b/src/tronweb.ts index 7050aaed..1dbd472b 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -420,7 +420,7 @@ export class TronWeb extends EventEmitter { return account; } - async isConnected(callback = false) { + async isConnected() { return { fullNode: await this.fullNode.isConnected(), solidityNode: await this.solidityNode.isConnected(), From 874c2ba7bdfe08a649dd84e9cfa1701a3b6e836d Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 4 Sep 2024 15:24:48 +0800 Subject: [PATCH 18/28] feat: add TronWeb.address.toChecksumAddress & isChecksumAddress --- src/tronweb.ts | 8 +++++++- src/utils/address.ts | 38 ++++++++++++++++++++++++++++++++++++++ test/index.test.ts | 15 +++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/tronweb.ts b/src/tronweb.ts index 1dbd472b..3041d7b2 100644 --- a/src/tronweb.ts +++ b/src/tronweb.ts @@ -11,7 +11,7 @@ import { Contract } from './lib/contract/index.js'; import { Plugin } from './lib/plugin.js'; import { Event } from './lib/event.js'; import { keccak256 } from './utils/ethersUtils.js'; -import { fromHex, fromPrivateKey, isAddress, toHex } from './utils/address.js'; +import { fromHex, fromPrivateKey, isAddress, toHex, toChecksumAddress, isChecksumAddress } from './utils/address.js'; import { HeadersType } from './types/Providers.js'; import { isString } from './utils/validations.js'; import { DefaultAddress, NodeProvider, TronWebOptions, IBigNumber } from './types/TronWeb.js'; @@ -276,6 +276,12 @@ export class TronWeb extends EventEmitter { toHex(address: string) { return toHex(address); }, + toChecksumAddress(address: string) { + return toChecksumAddress(address); + }, + isChecksumAddress(address: string) { + return isChecksumAddress(address); + }, fromPrivateKey(privateKey: string, strict = false) { return fromPrivateKey(privateKey, strict); }, diff --git a/src/utils/address.ts b/src/utils/address.ts index ad4d1974..8d88ddc1 100644 --- a/src/utils/address.ts +++ b/src/utils/address.ts @@ -1,6 +1,7 @@ import { hexStr2byteArray, byteArray2hexStr } from './code.js'; import { decodeBase58Address, getBase58CheckAddress, isAddressValid, pkToAddress } from './crypto.js'; import { isHex, isString } from './validations.js'; +import { keccak256 } from './ethersUtils.js'; export const ADDRESS_SIZE = 34; export const ADDRESS_PREFIX = '41'; @@ -22,6 +23,43 @@ export function toHex(address: string) { return byteArray2hexStr(decodeBase58Address(address) as number[]).toLowerCase(); } +function getChecksumAddress(address: string): string { + address = address.toLowerCase(); + + const chars = address.substring(2).split(''); + + const expanded = new Uint8Array(40); + for (let i = 0; i < 40; i++) { + expanded[i] = chars[i].charCodeAt(0); + } + + const hashed = hexStr2byteArray(keccak256(expanded).slice(2)); + + for (let i = 0; i < 40; i += 2) { + if ((hashed[i >> 1] >> 4) >= 8) { + chars[i] = chars[i].toUpperCase(); + } + if ((hashed[i >> 1] & 0x0f) >= 8) { + chars[i + 1] = chars[i + 1].toUpperCase(); + } + } + + return ADDRESS_PREFIX + chars.join(''); +} + +export function toChecksumAddress(address: string) { + return getChecksumAddress(toHex(address)); +} + +export function isChecksumAddress(address: string) { + if (!isHex(address) || address.length !== 42) return false; + try { + return toChecksumAddress(address) === address; + } catch { + return false; + } +} + export function fromPrivateKey(privateKey: string, strict = false) { try { return pkToAddress(privateKey, strict); diff --git a/test/index.test.ts b/test/index.test.ts index c7bbdf6d..a8d46e02 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -412,6 +412,21 @@ describe('TronWeb Instance', function () { }); }); + describe('#address.toChecksumAddress', function () { + it('should return the checksum address', function () { + const tronWeb = tronWebBuilder.createInstance(); + assert.equal(tronWeb.address.toChecksumAddress('TMVQGm1qAQYVdetCeGRRkTWYYrLXuHK2HC'), '417E5F4552091A69125d5DfCb7b8C2659029395Bdf') + }); + }); + + describe('#address.isChecksumAddress', function () { + it('should return the checksum address', function () { + const tronWeb = tronWebBuilder.createInstance(); + assert.isTrue(tronWeb.address.isChecksumAddress('417E5F4552091A69125d5DfCb7b8C2659029395Bdf')); + assert.isFalse(tronWeb.address.isChecksumAddress('417e5f4552091a69125d5dfcb7b8c2659029395bdf')); + }); + }); + describe('#sha3()', function () { it('should match web3 sha function', function () { const input = 'casa'; From 709d315c4e6ebcc55f26b6d6dcb19bfbf308e57c Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Wed, 4 Sep 2024 19:31:39 +0800 Subject: [PATCH 19/28] fix: check address before toChecksumAddress --- src/utils/address.ts | 1 + test/index.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/utils/address.ts b/src/utils/address.ts index 8d88ddc1..e74fdec8 100644 --- a/src/utils/address.ts +++ b/src/utils/address.ts @@ -48,6 +48,7 @@ function getChecksumAddress(address: string): string { } export function toChecksumAddress(address: string) { + if (!isAddress(address)) throw new Error(`'${address}' is not a valid address string`); return getChecksumAddress(toHex(address)); } diff --git a/test/index.test.ts b/test/index.test.ts index a8d46e02..c498d7c0 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -5,6 +5,7 @@ import tronWebBuilder from './helpers/tronWebBuilder.js'; import { BigNumber } from 'bignumber.js'; import broadcaster from './helpers/broadcaster.js'; import wait from './helpers/wait.js'; +import assertThrow from './helpers/assertThrow.js'; type Address = Types.Address; type RequestHeaders = Types.RequestHeaders; @@ -417,6 +418,13 @@ describe('TronWeb Instance', function () { const tronWeb = tronWebBuilder.createInstance(); assert.equal(tronWeb.address.toChecksumAddress('TMVQGm1qAQYVdetCeGRRkTWYYrLXuHK2HC'), '417E5F4552091A69125d5DfCb7b8C2659029395Bdf') }); + + it('should throw error', async function () { + const tronWeb = tronWebBuilder.createInstance(); + await assertThrow(() => { + tronWeb.address.toChecksumAddress('not a valid address'); + }, "'not a valid address' is not a valid address string"); + }); }); describe('#address.isChecksumAddress', function () { From 84e10024f37a4eb780a0a5c1a16ac6276c59bb20 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 5 Sep 2024 10:26:16 +0800 Subject: [PATCH 20/28] fix: should pass a promise to assertThrow --- test/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.test.ts b/test/index.test.ts index c498d7c0..e9114d1a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -421,9 +421,9 @@ describe('TronWeb Instance', function () { it('should throw error', async function () { const tronWeb = tronWebBuilder.createInstance(); - await assertThrow(() => { + await assertThrow((async () => { tronWeb.address.toChecksumAddress('not a valid address'); - }, "'not a valid address' is not a valid address string"); + })(), "'not a valid address' is not a valid address string"); }); }); From c4e5f9701d96c523e213e1e91410da7bd51cfe16 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 5 Sep 2024 11:31:32 +0800 Subject: [PATCH 21/28] chore: add change log --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcc49528..6e251f6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Change Log ========= +__6.0.0__ +- Fix [issue543](https://github.com/tronprotocol/tronweb/issues/543), replace type AxiosHeaders with InstanceType. +- Add type for value field in the return of the creation by TransactionBuilder methods. +- Fix known type errors. +- Bump axios from 1.6.8 to 1.7.4 and webpack from 5.78.0 to 5.94.0 to address security problems. +- Add TronWeb.address.toChecksumAddress and TronWeb.address.isChecksumAddress APIs. + __6.0.0-beta.4__ - Replace `ethers@v5/abi` with abiCoder of `ethers@v6`. - Bump ethers from v6.11.1 to v6.13.1. From 1c1751c261b768c34e9a71177d77799a8d7e577d Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 5 Sep 2024 17:50:16 +0800 Subject: [PATCH 22/28] fix: change instance type in HttpProvider --- src/lib/providers/HttpProvider.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/providers/HttpProvider.ts b/src/lib/providers/HttpProvider.ts index 25edd3d7..314fe6d5 100644 --- a/src/lib/providers/HttpProvider.ts +++ b/src/lib/providers/HttpProvider.ts @@ -1,6 +1,6 @@ -import axios, { Method } from 'axios'; +import axios, { Method, AxiosInstance } from 'axios'; import { hasProperties, isObject, isValidURL } from '../../utils/validations.js'; -import { HeadersType, HttpProviderInstance } from '../../types/Providers.js'; +import { HeadersType } from '../../types/Providers.js'; export default class HttpProvider { host: string; @@ -9,7 +9,7 @@ export default class HttpProvider { password: string; headers: HeadersType; statusPage: string; - instance: HttpProviderInstance; + instance: AxiosInstance; constructor(host: string, timeout = 30000, user = '', password = '', headers: HeadersType = {}, statusPage = '/') { if (!isValidURL(host)) throw new Error('Invalid URL provided to HttpProvider'); @@ -55,7 +55,7 @@ export default class HttpProvider { method = method.toLowerCase() as Method; return this.instance - .request<{ data: T }>({ + .request({ data: method == 'post' && Object.keys(payload).length ? payload : null, params: method == 'get' && payload, url, From b96c5cb8ff40031c1734eeb6e0dd0495200ddc7f Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 5 Sep 2024 18:23:50 +0800 Subject: [PATCH 23/28] fix: fix HttpProviderInstance type error --- src/lib/providers/HttpProvider.ts | 8 ++++---- src/types/Providers.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/providers/HttpProvider.ts b/src/lib/providers/HttpProvider.ts index 314fe6d5..ae22a668 100644 --- a/src/lib/providers/HttpProvider.ts +++ b/src/lib/providers/HttpProvider.ts @@ -1,6 +1,6 @@ -import axios, { Method, AxiosInstance } from 'axios'; +import axios, { Method } from 'axios'; import { hasProperties, isObject, isValidURL } from '../../utils/validations.js'; -import { HeadersType } from '../../types/Providers.js'; +import { HeadersType, HttpProviderInstance } from '../../types/Providers.js'; export default class HttpProvider { host: string; @@ -9,7 +9,7 @@ export default class HttpProvider { password: string; headers: HeadersType; statusPage: string; - instance: AxiosInstance; + instance: HttpProviderInstance; constructor(host: string, timeout = 30000, user = '', password = '', headers: HeadersType = {}, statusPage = '/') { if (!isValidURL(host)) throw new Error('Invalid URL provided to HttpProvider'); @@ -55,7 +55,7 @@ export default class HttpProvider { method = method.toLowerCase() as Method; return this.instance - .request({ + .request({ data: method == 'post' && Object.keys(payload).length ? payload : null, params: method == 'get' && payload, url, diff --git a/src/types/Providers.ts b/src/types/Providers.ts index 19bcd461..50873aba 100644 --- a/src/types/Providers.ts +++ b/src/types/Providers.ts @@ -3,5 +3,5 @@ export type HeadersType = RawAxiosRequestHeaders | InstanceType(config: any): Promise; + request(config: any): Promise<{ data: R }>; } \ No newline at end of file From fda803228bfd8edd6f2d5a8e3c9ab7ed584de01a Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 12 Sep 2024 15:37:27 +0800 Subject: [PATCH 24/28] chore: remove beta in readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1506cec4..b45e9df7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ [TronWeb](https://tronweb.network) aims to deliver a unified, seamless development experience influenced by Ethereum's [Web3](https://github.com/ethereum/web3.js/) implementation. We have taken the core ideas and expanded upon them to unlock the functionality of TRON's unique feature set along with offering new tools for integrating DApps in the browser, Node.js and IoT devices. -Please note that this version is an experimental beta version. To better support its use in TypeScript projects, we have rewritten the entire library in TypeScript. And to make the TronWeb API more secure and consistent, there are some breaking changes. Please check out [6.x API documentation](https://tronweb.network/docu/docs/intro/) for detailed changes so you can start using the new TypeScript version of TronWeb early. Any questions or feedback are welcome [here](https://github.com/tronprotocol/tronweb/issues/new). +To better support its use in TypeScript projects, we have rewritten the entire library in TypeScript. And to make the TronWeb API more secure and consistent, there are some breaking changes. Please check out [6.x API documentation](https://tronweb.network/docu/docs/intro/) for detailed changes so you can start using the new TypeScript version of TronWeb early. Any questions or feedback are welcome [here](https://github.com/tronprotocol/tronweb/issues/new). **Project scope** @@ -64,11 +64,11 @@ For recent history, see the [CHANGELOG](https://github.com/tronprotocol/tronweb/ ### Node.js ```bash -npm install tronweb@beta +npm install tronweb ``` or ```bash -yarn add tronweb@beta +yarn add tronweb ``` ### Browser @@ -118,7 +118,7 @@ First of all, in your typescript file, define TronWeb: import { TronWeb, utils as TronWebUtils, Trx, TransactionBuilder, Contract, Event, Plugin } from 'tronweb'; ``` -Please note that this is not the same as v5.x. If you want to dive into more differences, check out [migration guide](https://tronweb.network/docu/docs/6.0.0-beta.3/Migrating%20from%20v5) +Please note that this is not the same as v5.x. If you want to dive into more differences, check out [migration guide](https://tronweb.network/docu/docs/6.0.0/Migrating%20from%20v5) When you instantiate TronWeb you can define From 01501e77e3c8061c4ab3494bd6617740c015ca27 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Fri, 13 Sep 2024 12:00:04 +0800 Subject: [PATCH 25/28] fix: decodeInput in Method call decodeOutput directly without switch outputs and inputs --- src/lib/contract/method.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/contract/method.ts b/src/lib/contract/method.ts index e4007524..edecb1cf 100644 --- a/src/lib/contract/method.ts +++ b/src/lib/contract/method.ts @@ -107,7 +107,9 @@ export class Method { } decodeInput(data: string) { - return decodeOutput(this.abi, '0x' + data); + const abi = JSON.parse(JSON.stringify(this.abi)); + abi.outputs = abi.inputs; + return decodeOutput(abi, '0x' + data); } onMethod(...args: any[]) { From 80edc49930b276d02b19f8042791a1ad13d9e46d Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Sat, 14 Sep 2024 17:27:26 +0800 Subject: [PATCH 26/28] chore: add integrity check in readme and update change log --- CHANGELOG.md | 1 + README.md | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e251f6a..9196f903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ __6.0.0__ - Fix known type errors. - Bump axios from 1.6.8 to 1.7.4 and webpack from 5.78.0 to 5.94.0 to address security problems. - Add TronWeb.address.toChecksumAddress and TronWeb.address.isChecksumAddress APIs. +- Fix the wrong action of `deocdeInput` API in Contract module. [#557](https://github.com/tronprotocol/tronweb/issues/557) __6.0.0-beta.4__ - Replace `ethers@v5/abi` with abiCoder of `ethers@v6`. diff --git a/README.md b/README.md index b45e9df7..02b6a458 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,15 @@ const tronWeb = new TronWeb({ ) ``` +## Integrity Check + +The package files will be signed using a GPG key pair, and the correctness of the signature will be verified using the following public key: + +``` +pub: 4371 AB85 E5A5 8FAA 88AD 7FDF 9945 DBCA 8C4B B810 +uid: dev@tronweb.network +``` + ## Contributions In order to contribute you can From 846f0349b75e89d5ae297b40afb0298dbee27718 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 19 Sep 2024 12:15:43 +0800 Subject: [PATCH 27/28] chore: address audit problem --- package-lock.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9c339c08..ddaa312b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3460,9 +3460,9 @@ } }, "node_modules/body-parser": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", - "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", + "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", "dev": true, "dependencies": { "bytes": "3.1.2", @@ -3473,7 +3473,7 @@ "http-errors": "2.0.0", "iconv-lite": "0.4.24", "on-finished": "2.4.1", - "qs": "6.11.0", + "qs": "6.13.0", "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" @@ -8585,12 +8585,12 @@ } }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", "dev": true, "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" From cd98f0693ef96e539995fec459f839f1a589c046 Mon Sep 17 00:00:00 2001 From: Satan-web3 Date: Thu, 19 Sep 2024 14:24:22 +0800 Subject: [PATCH 28/28] chore: update change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9196f903..bf732e05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ __6.0.0__ - Fix [issue543](https://github.com/tronprotocol/tronweb/issues/543), replace type AxiosHeaders with InstanceType. - Add type for value field in the return of the creation by TransactionBuilder methods. - Fix known type errors. -- Bump axios from 1.6.8 to 1.7.4 and webpack from 5.78.0 to 5.94.0 to address security problems. +- Bump axios from 1.6.8 to 1.7.4 and webpack from 5.78.0 to 5.94.0. - Add TronWeb.address.toChecksumAddress and TronWeb.address.isChecksumAddress APIs. - Fix the wrong action of `deocdeInput` API in Contract module. [#557](https://github.com/tronprotocol/tronweb/issues/557)