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

Commit 2011192

Browse files
authored
fix: export Web3Account, Wallet and signature related types (#7374)
1 parent 1724f35 commit 2011192

File tree

9 files changed

+55
-54
lines changed

9 files changed

+55
-54
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,3 +2803,9 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
28032803
- Fix Contract methods input param type any[] (#7340)
28042804

28052805
## [Unreleased]
2806+
2807+
### Fixed
2808+
2809+
#### web3
2810+
2811+
- Export Web3Account, Wallet and signature related types. (#7374)

packages/web3-eth-accounts/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@ Documentation:
190190
- `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)
191191

192192
## [Unreleased]
193+
194+
### Removed
195+
196+
- Move signature related types to web3-types. Re-export them for backwards compatibility. (#7374)

packages/web3-eth-accounts/src/account.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ import {
6969
KeyStore,
7070
PBKDF2SHA256Params,
7171
ScryptParams,
72+
SignatureObject,
73+
SignResult,
74+
SignTransactionResult,
7275
Transaction,
7376
} from 'web3-types';
7477
import {
@@ -90,13 +93,7 @@ import { isHexStrict, isNullish, isString, validator } from 'web3-validator';
9093
import { secp256k1 } from './tx/constants.js';
9194
import { keyStoreSchema } from './schemas.js';
9295
import { TransactionFactory } from './tx/transactionFactory.js';
93-
import type {
94-
SignatureObject,
95-
SignTransactionResult,
96-
TypedTransaction,
97-
Web3Account,
98-
SignResult,
99-
} from './types.js';
96+
import type { TypedTransaction, Web3Account } from './types.js';
10097

10198
/**
10299
* Get the private key Uint8Array after the validation.

packages/web3-eth-accounts/src/types.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,16 @@ You should have received a copy of the GNU Lesser General Public License
1515
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import { Web3BaseWalletAccount, HexString } from 'web3-types';
19-
import { FeeMarketEIP1559TxData, AccessListEIP2930TxData, TxData } from './tx/types.js';
18+
import {
19+
HexString,
20+
SignatureObject,
21+
SignResult,
22+
SignTransactionResult,
23+
Web3BaseWalletAccount,
24+
} from 'web3-types';
2025
import { AccessListEIP2930Transaction, FeeMarketEIP1559Transaction, Transaction } from './tx';
2126

22-
export type SignatureObject = {
23-
messageHash: string;
24-
r: string;
25-
s: string;
26-
v: string;
27-
};
28-
29-
export type SignTransactionResult = SignatureObject & {
30-
rawTransaction: string;
31-
transactionHash: string;
32-
};
33-
34-
export type SignTransactionFunction = (
35-
transaction:
36-
| TxData
37-
| AccessListEIP2930TxData
38-
| FeeMarketEIP1559TxData
39-
| Record<string, unknown>,
40-
) => SignTransactionResult;
41-
42-
export type SignResult = SignatureObject & {
43-
message?: string;
44-
signature: string;
45-
};
46-
47-
export type SignFunction = (data: string, privateKey: string) => SignResult;
48-
49-
// https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
27+
export { SignatureObject, SignResult, SignTransactionResult };
5028

5129
export interface Web3Account extends Web3BaseWalletAccount {
5230
address: HexString;

packages/web3-types/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,7 @@ Documentation:
221221
- `FilterParams` type added (#7353)
222222

223223
## [Unreleased]
224+
225+
#### Added
226+
227+
- Add signature related types. (#7374)

packages/web3-types/src/web3_base_wallet.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,29 @@ export type KeyStore = {
6060
address: string;
6161
};
6262

63+
export type SignatureObject = {
64+
messageHash: string;
65+
r: string;
66+
s: string;
67+
v: string;
68+
};
69+
70+
export type SignTransactionResult = SignatureObject & {
71+
rawTransaction: string;
72+
transactionHash: string;
73+
};
74+
75+
export type SignResult = SignatureObject & {
76+
message?: string;
77+
signature: string;
78+
};
79+
6380
export interface Web3BaseWalletAccount {
6481
[key: string]: unknown;
6582
readonly address: string;
6683
readonly privateKey: string;
67-
readonly signTransaction: (tx: Transaction) => Promise<{
68-
readonly messageHash: HexString;
69-
readonly r: HexString;
70-
readonly s: HexString;
71-
readonly v: HexString;
72-
readonly rawTransaction: HexString;
73-
readonly transactionHash: HexString;
74-
}>;
75-
readonly sign: (data: Record<string, unknown> | string) => {
76-
readonly messageHash: HexString;
77-
readonly r: HexString;
78-
readonly s: HexString;
79-
readonly v: HexString;
80-
readonly message?: string;
81-
readonly signature: HexString;
82-
};
84+
readonly signTransaction: (tx: Transaction) => Promise<SignTransactionResult>;
85+
readonly sign: (data: Record<string, unknown> | string) => SignResult;
8386
readonly encrypt: (password: string, options?: Record<string, unknown>) => Promise<KeyStore>;
8487
}
8588

packages/web3/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,9 @@ Documentation:
561561
- Fix Contract methods input param type any[] (#7340)
562562

563563
## [Unreleased]
564+
565+
### Fixed
566+
567+
#### web3
568+
569+
- Export Web3Account, Wallet and signature related types. (#7374)

packages/web3/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { Net } from 'web3-net';
4242
import { Iban } from 'web3-eth-iban';
4343
import { Personal } from 'web3-eth-personal';
4444

45+
export type { Web3Account, Wallet } from 'web3-eth-accounts';
46+
4547
/**
4648
* The Ethereum interface for main web3 object. It provides extra methods in addition to `web3-eth` interface.
4749
*

packages/web3/test/unit/accounts.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
1717

1818
import * as eth from 'web3-eth';
1919
import * as ethAccounts from 'web3-eth-accounts';
20-
import { SignTransactionResult, Web3Account } from 'web3-eth-accounts';
20+
import { Web3Account } from 'web3-eth-accounts';
21+
import type { SignTransactionResult } from 'web3-types';
2122
import { Web3EthInterface } from '../../src/types';
2223
import { Web3 } from '../../src';
2324

0 commit comments

Comments
 (0)