diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d8d858ed7..6c97c573755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/web3-eth-accounts/CHANGELOG.md b/packages/web3-eth-accounts/CHANGELOG.md index 939bd836ce8..e707999a1c2 100644 --- a/packages/web3-eth-accounts/CHANGELOG.md +++ b/packages/web3-eth-accounts/CHANGELOG.md @@ -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) diff --git a/packages/web3-eth-accounts/src/account.ts b/packages/web3-eth-accounts/src/account.ts index 511ebcc92d2..9faed9ceaed 100644 --- a/packages/web3-eth-accounts/src/account.ts +++ b/packages/web3-eth-accounts/src/account.ts @@ -69,6 +69,9 @@ import { KeyStore, PBKDF2SHA256Params, ScryptParams, + SignatureObject, + SignResult, + SignTransactionResult, Transaction, } from 'web3-types'; import { @@ -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. diff --git a/packages/web3-eth-accounts/src/types.ts b/packages/web3-eth-accounts/src/types.ts index ed45ad94ffb..54a7aba7b78 100644 --- a/packages/web3-eth-accounts/src/types.ts +++ b/packages/web3-eth-accounts/src/types.ts @@ -15,38 +15,16 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -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 = { - messageHash: string; - r: string; - s: string; - v: string; -}; - -export type SignTransactionResult = SignatureObject & { - rawTransaction: string; - transactionHash: string; -}; - -export type SignTransactionFunction = ( - transaction: - | TxData - | AccessListEIP2930TxData - | FeeMarketEIP1559TxData - | Record, -) => SignTransactionResult; - -export type SignResult = SignatureObject & { - message?: string; - signature: string; -}; - -export type SignFunction = (data: string, privateKey: string) => SignResult; - -// https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition +export { SignatureObject, SignResult, SignTransactionResult }; export interface Web3Account extends Web3BaseWalletAccount { address: HexString; diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index 4158022da52..c78df9f3265 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -221,3 +221,7 @@ Documentation: - `FilterParams` type added (#7353) ## [Unreleased] + +#### Added + +- Add signature related types. (#7374) diff --git a/packages/web3-types/src/web3_base_wallet.ts b/packages/web3-types/src/web3_base_wallet.ts index 484e8072603..153a34450a1 100644 --- a/packages/web3-types/src/web3_base_wallet.ts +++ b/packages/web3-types/src/web3_base_wallet.ts @@ -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) => { - readonly messageHash: HexString; - readonly r: HexString; - readonly s: HexString; - readonly v: HexString; - readonly message?: string; - readonly signature: HexString; - }; + readonly signTransaction: (tx: Transaction) => Promise; + readonly sign: (data: Record | string) => SignResult; readonly encrypt: (password: string, options?: Record) => Promise; } diff --git a/packages/web3/CHANGELOG.md b/packages/web3/CHANGELOG.md index f3ec9b9679e..b1f440e0074 100644 --- a/packages/web3/CHANGELOG.md +++ b/packages/web3/CHANGELOG.md @@ -561,3 +561,9 @@ Documentation: - Fix Contract methods input param type any[] (#7340) ## [Unreleased] + +### Fixed + +#### web3 + +- Export Web3Account, Wallet and signature related types. (#7374) diff --git a/packages/web3/src/types.ts b/packages/web3/src/types.ts index 3b87896789c..341e017015c 100644 --- a/packages/web3/src/types.ts +++ b/packages/web3/src/types.ts @@ -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. * diff --git a/packages/web3/test/unit/accounts.test.ts b/packages/web3/test/unit/accounts.test.ts index 9cc2618d24b..2bd75cbe90e 100644 --- a/packages/web3/test/unit/accounts.test.ts +++ b/packages/web3/test/unit/accounts.test.ts @@ -17,7 +17,8 @@ along with web3.js. If not, see . 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';