Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

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

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2803,3 +2803,9 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
- Fix Contract methods input param type any[] (#7340)

## [Unreleased]

### Fixed

#### web3

- Export Web3Account, Wallet and signature related types. (#7374)
4 changes: 4 additions & 0 deletions packages/web3-eth-accounts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ Documentation:
- `hashMessage` now has a new optional param `skipPrefix` with a default value of `false`. A new function `signRaw` was added to sign a message without prefix. (#7346)

## [Unreleased]

### Removed

- Move signature related types to web3-types. Re-export them for backwards compatibility. (#7374)
11 changes: 4 additions & 7 deletions packages/web3-eth-accounts/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ import {
KeyStore,
PBKDF2SHA256Params,
ScryptParams,
SignatureObject,
SignResult,
SignTransactionResult,
Transaction,
} from 'web3-types';
import {
Expand All @@ -90,13 +93,7 @@ import { isHexStrict, isNullish, isString, validator } from 'web3-validator';
import { secp256k1 } from './tx/constants.js';
import { keyStoreSchema } from './schemas.js';
import { TransactionFactory } from './tx/transactionFactory.js';
import type {
SignatureObject,
SignTransactionResult,
TypedTransaction,
Web3Account,
SignResult,
} from './types.js';
import type { TypedTransaction, Web3Account } from './types.js';

/**
* Get the private key Uint8Array after the validation.
Expand Down
38 changes: 8 additions & 30 deletions packages/web3-eth-accounts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,16 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { Web3BaseWalletAccount, HexString } from 'web3-types';
import { FeeMarketEIP1559TxData, AccessListEIP2930TxData, TxData } from './tx/types.js';
import {
HexString,
SignatureObject,
SignResult,
SignTransactionResult,
Web3BaseWalletAccount,
} from 'web3-types';
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.

messageHash: string;
r: string;
s: string;
v: string;
};

export type SignTransactionResult = SignatureObject & {
rawTransaction: string;
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

transaction:
| TxData
| AccessListEIP2930TxData
| FeeMarketEIP1559TxData
| Record<string, unknown>,
) => SignTransactionResult;

export type SignResult = SignatureObject & {
message?: string;
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


// https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
export { SignatureObject, SignResult, SignTransactionResult };

export interface Web3Account extends Web3BaseWalletAccount {
address: HexString;
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@ Documentation:
- `FilterParams` type added (#7353)

## [Unreleased]

#### Added

- Add signature related types. (#7374)
35 changes: 19 additions & 16 deletions packages/web3-types/src/web3_base_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,29 @@ export type KeyStore = {
address: string;
};

export type SignatureObject = {
messageHash: string;
r: string;
s: string;
v: string;
};

export type SignTransactionResult = SignatureObject & {
rawTransaction: string;
transactionHash: string;
};

export type SignResult = SignatureObject & {
message?: string;
signature: string;
};

export interface Web3BaseWalletAccount {
[key: string]: unknown;
readonly address: string;
readonly privateKey: string;
readonly signTransaction: (tx: Transaction) => Promise<{
readonly messageHash: HexString;
readonly r: HexString;
readonly s: HexString;
readonly v: HexString;
readonly rawTransaction: HexString;
readonly transactionHash: HexString;
}>;
readonly sign: (data: Record<string, unknown> | string) => {
readonly messageHash: HexString;
readonly r: HexString;
readonly s: HexString;
readonly v: HexString;
readonly message?: string;
readonly signature: HexString;
};
readonly signTransaction: (tx: Transaction) => Promise<SignTransactionResult>;
readonly sign: (data: Record<string, unknown> | string) => SignResult;
readonly encrypt: (password: string, options?: Record<string, unknown>) => Promise<KeyStore>;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/web3/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,9 @@ Documentation:
- Fix Contract methods input param type any[] (#7340)

## [Unreleased]

### Fixed

#### web3

- Export Web3Account, Wallet and signature related types. (#7374)
2 changes: 2 additions & 0 deletions packages/web3/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { Net } from 'web3-net';
import { Iban } from 'web3-eth-iban';
import { Personal } from 'web3-eth-personal';

export type { Web3Account, Wallet } from 'web3-eth-accounts';

/**
* The Ethereum interface for main web3 object. It provides extra methods in addition to `web3-eth` interface.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/web3/test/unit/accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.

import * as eth from 'web3-eth';
import * as ethAccounts from 'web3-eth-accounts';
import { SignTransactionResult, Web3Account } from 'web3-eth-accounts';
import { Web3Account } from 'web3-eth-accounts';
import type { SignTransactionResult } from 'web3-types';
import { Web3EthInterface } from '../../src/types';
import { Web3 } from '../../src';

Expand Down
Loading