Skip to content

Commit

Permalink
fix: export Web3Account, Wallet and signature related types (#7374)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu authored Nov 13, 2024
1 parent 1724f35 commit 2011192
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 54 deletions.
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 = {
messageHash: string;
r: string;
s: string;
v: string;
};

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

export type SignTransactionFunction = (
transaction:
| TxData
| AccessListEIP2930TxData
| FeeMarketEIP1559TxData
| Record<string, unknown>,
) => 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;
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

0 comments on commit 2011192

Please sign in to comment.