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

7202 account abstraction #7311

Merged
merged 15 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions packages/web3-account-abstraction/.eslintignore
7 changes: 7 additions & 0 deletions packages/web3-account-abstraction/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: '../../.eslintrc.js',
parserOptions: {
project: './tsconfig.esm.json',
tsconfigRootDir: __dirname,
},
};
Empty file.
1 change: 1 addition & 0 deletions packages/web3-account-abstraction/.npmignore
1 change: 1 addition & 0 deletions packages/web3-account-abstraction/.npmrc
1 change: 1 addition & 0 deletions packages/web3-account-abstraction/.prettierignore
1 change: 1 addition & 0 deletions packages/web3-account-abstraction/.prettierrc.json
38 changes: 38 additions & 0 deletions packages/web3-account-abstraction/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- EXAMPLE

## [1.0.0]

### Added

- I've added feature XY (#1000)

### Changed

- I've cleaned up XY (#1000)

### Deprecated

- I've deprecated XY (#1000)

### Removed

- I've removed XY (#1000)

### Fixed

- I've fixed XY (#1000)

### Security

- I've improved the security in XY (#1000)

-->

## [Unreleased]
59 changes: 59 additions & 0 deletions packages/web3-account-abstraction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<p align="center">
<img src="assets/logo/web3js.jpg" width="500" alt="web3.js" />
</p>

# web3.js - Account Abstraction

![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-14.x-green)
[![NPM Package][npm-image]][npm-url]
[![Downloads][downloads-image]][npm-url]

This is a sub-package of [web3.js][repo].

`web3-account-abstraction` contains the ideal setup for a Web3.js package.

## Installation

You can install the package either using [NPM](https://www.npmjs.com/package/web3-account-abstraction) or using [Yarn](https://yarnpkg.com/package/web3-account-abstraction)

### Using NPM

```bash
npm install web3-account-abstraction
```

### Using Yarn

```bash
yarn add web3-account-abstraction
```

## Getting Started

- :writing_hand: If you have questions [submit an issue](https://github.com/ChainSafe/web3.js/issues/new) or join us on [Discord](https://discord.gg/yjyvFRP)
![Discord](https://img.shields.io/discord/593655374469660673.svg?label=Discord&logo=discord)

## Prerequisites

- :gear: [NodeJS](https://nodejs.org/) (LTS/Fermium)
- :toolbox: [Yarn](https://yarnpkg.com/)/[Lerna](https://lerna.js.org/)

## Package.json Scripts

| Script | Description |
| ---------------- | -------------------------------------------------- |
| clean | Uses `rimraf` to remove `dist/` |
| build | Uses `tsc` to build package and dependent packages |
| lint | Uses `eslint` to lint package |
| lint:fix | Uses `eslint` to check and fix any warnings |
| format | Uses `prettier` to format the code |
| test | Uses `jest` to run unit tests |
| test:integration | Uses `jest` to run tests under `/test/integration` |
| test:unit | Uses `jest` to run tests under `/test/unit` |

[docs]: https://docs.web3js.org/
[repo]: https://github.com/web3/web3.js/tree/4.x/tools/web3-account-abstraction
[npm-image]: https://img.shields.io/github/package-json/v/web3/web3.js/4.x?filename=tools%2Fweb3-account-abstraction%2Fpackage.json
[npm-url]: https://npmjs.org/package/web3-account-abstraction
[downloads-image]: https://img.shields.io/npm/dm/web3-account-abstraction?label=npm%20downloads
1,516 changes: 1,516 additions & 0 deletions packages/web3-account-abstraction/assets/logo/web3js.ai

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions packages/web3-account-abstraction/assets/logo/web3js.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions packages/web3-account-abstraction/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "web3-account-abstraction",
"version": "0.1.0-rc.0",
"description": "Web3 account abstraction package",
"main": "lib/index.js",
"repository": "https://github.com/ChainSafe/web3.js",
"author": "ChainSafe Systems",
"license": "LGPL-3.0",
"engines": {
"node": ">=14",
"npm": ">=6.12.0"
},
"files": [
"lib/**/*",
"src/**/*"
],
"scripts": {
"clean": "rimraf dist && rimraf lib",
"prebuild": "yarn clean",
"build": "concurrently --kill-others-on-fail \"yarn:build:*(!check)\"",
"build:cjs": "tsc --build tsconfig.cjs.json",
"build:esm": "tsc --build tsconfig.esm.json",
"build:types": "tsc --build tsconfig.types.json",
"build:check": "node -e \"require('./lib')\"",
"lint": "eslint --cache --cache-strategy content --ext .ts .",
"lint:fix": "eslint --fix --ext .js,.ts .",
"format": "prettier --write '**/*'",
"test": "jest --config=./test/unit/jest.config.js",
"test:coverage:unit": "jest --config=./test/unit/jest.config.js --coverage=true --coverage-reporters=text",
"test:coverage:integration": "jest --config=./test/integration/jest.config.js --passWithNoTests --coverage=true --coverage-reporters=text",
"test:ci": "jest --coverage=true --coverage-reporters=json --verbose",
"test:watch": "npm test -- --watch",
"test:unit": "jest --config=./test/unit/jest.config.js",
"test:integration": "jest --config=./test/integration/jest.config.js --passWithNoTests"
},
"devDependencies": {
"@types/jest": "^28.1.6",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",
"eslint-config-base-web3": "0.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"jest": "^29.7.0",
"jest-extended": "^3.0.1",
"prettier": "^2.7.1",
"ts-jest": "^29.1.1",
"typescript": "^4.7.4"
},
"dependencies": {
"web3-core": "^4.6.0",
"web3-types": "^1.8.0",
"web3-eth-abi": "^4.1.3",
"web3-utils": "^4.0.7",
"web3-validator": "^2.0.3"
}
}
23 changes: 23 additions & 0 deletions packages/web3-account-abstraction/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

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 { AccountAbstraction } from './web3_aa.js';

export * from './types.js';
export * from './utils.js';

export default AccountAbstraction;
107 changes: 107 additions & 0 deletions packages/web3-account-abstraction/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
This file is part of web3.js.

web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

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 {
Address,
Uint256,
HexStringBytes,
Uint,
HexString32Bytes,
TransactionHash,
LogAPI,
TransactionReceiptAPI,
} from 'web3-types';

export type ValidInputTypes = Uint8Array | bigint | string | number | boolean;

export interface UserOperation {
sender: Address;
nonce: Uint256;
initCode: HexStringBytes;
callData: HexStringBytes;
callGasLimit?: Uint256;
verificationGasLimit: Uint256;
preVerificationGas: Uint256;
maxFeePerGas?: Uint256;
maxPriorityFeePerGas?: Uint256;
paymasterAndData: HexStringBytes;
signature: HexStringBytes;
}
export interface UserOperationRequire
extends Omit<UserOperation, 'callGasLimit' | 'maxFeePerGas' | 'maxPriorityFeePerGas'> {
callGasLimit: Uint256;
maxFeePerGas: Uint256;
maxPriorityFeePerGas: Uint256;
}

export interface IUserOperation {
readonly callData: HexStringBytes;
readonly callGasLimit: Uint;
readonly initCode: HexStringBytes;
readonly maxFeePerGas: Uint;
readonly maxPriorityFeePerGas: Uint;
readonly nonce: Uint;
readonly paymasterAndData: HexStringBytes;
readonly preVerificationGas: Uint;
readonly sender: Address;
readonly signature: HexStringBytes;
readonly verificationGasLimit: Uint;
}

export interface GetUserOperationByHashAPI {
readonly blockHash: HexString32Bytes;
readonly blockNumber: Uint;
readonly entryPoint: Address;
readonly transactionHash: TransactionHash;
readonly userOperation: IUserOperation;
}

export interface EstimateUserOperationGasAPI {
readonly preVerificationGas: Uint;
readonly verificationGasLimit: Uint;
readonly callGasLimit: Uint;
}

export interface GetUserOperationReceiptAPI {
readonly userOpHash: HexString32Bytes;
readonly entryPoint: Address;
readonly sender: Address;
readonly nonce: Uint;
readonly paymaster: Address;
readonly actualGasCost: Uint;
readonly actualGasUsed: Uint;
readonly success: boolean;
readonly reason: HexStringBytes;
readonly logs: LogAPI[];
readonly receipt: TransactionReceiptAPI;
}

export type AARpcApi = {
eth_sendUserOperation: (userOperation: UserOperation, entryPoint: Address) => HexString32Bytes;
eth_estimateUserOperationGas: (
userOperation: UserOperation,
entryPoint: Address,
) => EstimateUserOperationGasAPI;
eth_getUserOperationByHash: (hash: HexStringBytes) => GetUserOperationByHashAPI;
eth_getUserOperationReceipt: (hash: HexStringBytes) => GetUserOperationReceiptAPI;
eth_supportedEntryPoints: () => Address[];
generateUserOpHash: (
userOp: UserOperationRequire,
entryPoint: string,
chainId: string,
) => string;
};
Loading
Loading