Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export Web3Account, Wallet and signature related types #7374

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

krzysu
Copy link
Contributor

@krzysu krzysu commented Nov 7, 2024

Description

Export types that represent the return values of method calls but aren’t currently available as standalone types. Specifically, this includes Web3Account, Wallet, and signature-related types like SignatureObject, SignResult, and SignTransactionResult.

Fixes #7341

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run lint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:coverage and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have linked Issue(s) with this PR in "Linked Issues" menu.

transactionHash: string;
};

export type SignTransactionFunction = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used anywhere

signature: string;
};

export type SignFunction = (data: string, privateKey: string) => SignResult;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not used anywhere

Copy link

github-actions bot commented Nov 7, 2024

Bundle Stats

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 649.88 kB → 649.08 kB (-823 B) -0.12%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
../lib/commonjs/types.d.ts 2.67 kB → 2.73 kB (+62 B) +2.27%

Smaller

Asset File Size % Changed
../lib/commonjs/accounts.d.ts 3.93 kB → 3.06 kB (-885 B) -22.01%

Unchanged

Asset File Size % Changed
web3.min.js 630.33 kB 0%
../lib/commonjs/index.d.ts 8.72 kB 0%
../lib/commonjs/web3.d.ts 1.38 kB 0%
../lib/commonjs/web3_eip6963.d.ts 1.28 kB 0%
../lib/commonjs/abi.d.ts 1.06 kB 0%
../lib/commonjs/eth.exports.d.ts 280 B 0%
../lib/commonjs/providers.exports.d.ts 183 B 0%
../lib/commonjs/version.d.ts 60 B 0%

@@ -364,3 +364,4 @@ export * as validator from 'web3-validator';
*/
export * from 'web3-errors';
export * from 'web3-types';
export type { Web3Account, Wallet } from 'web3-eth-accounts';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is any better place to export these, let me know!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from web3-accts pkg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all account types are exported from web3-eth-accounts but not from web3. See https://github.com/web3/web3.js/blob/7341-export-types/packages/web3-eth-accounts/src/index.ts#L42
How to solve that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the export of these to packages/web3/src/types.ts

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.51%. Comparing base (1724f35) to head (b886b1c).
Report is 1 commits behind head on 4.x.

Additional details and impacted files
@@           Coverage Diff           @@
##              4.x    #7374   +/-   ##
=======================================
  Coverage   94.51%   94.51%           
=======================================
  Files         218      218           
  Lines        8557     8557           
  Branches     2363     2363           
=======================================
  Hits         8088     8088           
  Misses        469      469           
Flag Coverage Δ
UnitTests 94.51% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

import { AccessListEIP2930Transaction, FeeMarketEIP1559Transaction, Transaction } from './tx';

export type SignatureObject = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll suggest to move only shared types that are used in 1+ packages in web3-types package, and for moved types re-export those from web3-eth-accounts package for backward compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that SignatureObject is used in web3-eth-accounts but is also part of the Web3BaseWalletAccount type in web3-types.
See the type details below:

export interface Web3BaseWalletAccount {
	// ..
	readonly signTransaction: (tx: Transaction) => Promise<SignTransactionResult>;
	readonly sign: (data: Record<string, unknown> | string) => SignResult;
	//
}

Also, none of the web3-eth-accounts types are exported from the umbrella web3 package, but I will reexport these for web3-eth-accounts backwards compatibility.

@krzysu krzysu merged commit 2011192 into 4.x Nov 13, 2024
54 checks passed
@krzysu krzysu deleted the 7341-export-types branch November 13, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export all return types such as Web3Account or the signature type
3 participants