diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..6c38e05072 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +**/dist/* +examples/**/* \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index e9e04cd931..2ef36b2c27 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,9 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: 'FR: ' +title: "FR: " labels: feature request, needs-triage -assignees: '' +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml new file mode 100644 index 0000000000..18a4f8a15a --- /dev/null +++ b/.github/workflows/on-pull-request.yml @@ -0,0 +1,26 @@ +name: Run checks on Pull Requests +on: + pull_request: + branches: + - main + +jobs: + build_and_lint: + name: Lint and Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint + run: yarn lint:check + + - name: Build + run: yarn build diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 28624bcd09..548a468c62 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -7,22 +7,21 @@ name: Mark stale issues and pull requests on: schedule: - - cron: '25 1 * * *' + - cron: "25 1 * * *" jobs: stale: - runs-on: ubuntu-latest permissions: issues: write pull-requests: write steps: - - uses: actions/stale@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs' - stale-pr-message: 'This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs' - stale-issue-label: 'no-issue-activity' - stale-pr-label: 'no-pr-activity' - days-before-stale: 30 + - uses: actions/stale@v5 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs" + stale-pr-message: "This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs" + stale-issue-label: "no-issue-activity" + stale-pr-label: "no-pr-activity" + days-before-stale: 30 diff --git a/.prettierignore b/.prettierignore new file mode 120000 index 0000000000..f62e2b436d --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +.eslintignore \ No newline at end of file diff --git a/package.json b/package.json index 9eaecf2f4a..76521fda41 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "clean": "lerna run clean", "test": "vitest run", "lint:write": "eslint . --fix && prettier --write --ignore-unknown .", - "lint:check": "eslint . && prettier --check . && npmPkgJsonLint -q .", + "lint:check": "eslint . && prettier --check .", "prepare": "husky install", "version": "yarn build" }, diff --git a/packages/core/src/__tests__/private-key-signer.test.ts b/packages/core/src/__tests__/private-key-signer.test.ts index b426bf9559..9d70d9619e 100644 --- a/packages/core/src/__tests__/private-key-signer.test.ts +++ b/packages/core/src/__tests__/private-key-signer.test.ts @@ -1,35 +1,36 @@ -import {PrivateKeySigner} from "../signer/private-key"; - +import { PrivateKeySigner } from "../signer/private-key"; describe("Private Key Account Signer Tests", () => { - - const dummyPrivateKey = "0x022430a80f723d8789f0d4fb346bdd013b546e4b96fcacf8aceca2b1a65a19dc" - const dummyAddress = "0xabcfC3DB1e0f5023F5a4f40c03D149f316E6A5cc" - - const signer: PrivateKeySigner = PrivateKeySigner.privateKeyToAccountSigner(dummyPrivateKey) - - it("should sign a hex message properly", async () => { - expect(await signer.signMessage("0xab3430fgk78")).toMatchInlineSnapshot( - `"0xcb2094233752c6f66fa660f2118c60d0b7b73a097004514c01100bf986f3950f5ffddcd38035774d2878b72b2fd2d8ad1be2739f1b0cd8f34352d7301fe368e61b"` - ); - - expect(await signer.signMessage("icanbreakthistestcase")).toMatchInlineSnapshot( - `"0xabd26de022c2785a7d86c5c388f4adef5d93358b39fbb757463bc9edc78b7b86566cb1ab8c7ff3a52b10d98de6398aacc7b48aec92a3e280065a47b9698209541b"` - ); - - expect(await signer.signMessage("i will definately break this test case")).toMatchInlineSnapshot( - `"0x907004e990bb1bca76d9fed6bf4a6b614a8d11b6430657cb99ae83fae55c9bc60571876d8c01832e4661dd4312fa08b799b6f59c9b9abddd67e181abc6aef17e1c"` - ); - - expect(await signer.signMessage(dummyAddress)).toMatchInlineSnapshot( - `"0x64e29e4786b3740ceffc2c1a932124ee74c29b552957ea3bde8913753d1763af4f03362e387d2badb33932e8fc4f7b3411a0a5ade32a5b708aa48c171632a6211b"` - ); - }); - - it("should return wallet address", async () => { - expect(await signer.getAddress()).eql( - dummyAddress - ); - - }); -}) \ No newline at end of file + const dummyPrivateKey = + "0x022430a80f723d8789f0d4fb346bdd013b546e4b96fcacf8aceca2b1a65a19dc"; + const dummyAddress = "0xabcfC3DB1e0f5023F5a4f40c03D149f316E6A5cc"; + + const signer: PrivateKeySigner = + PrivateKeySigner.privateKeyToAccountSigner(dummyPrivateKey); + + it("should sign a hex message properly", async () => { + expect(await signer.signMessage("0xab3430fgk78")).toMatchInlineSnapshot( + `"0xcb2094233752c6f66fa660f2118c60d0b7b73a097004514c01100bf986f3950f5ffddcd38035774d2878b72b2fd2d8ad1be2739f1b0cd8f34352d7301fe368e61b"` + ); + + expect( + await signer.signMessage("icanbreakthistestcase") + ).toMatchInlineSnapshot( + `"0xabd26de022c2785a7d86c5c388f4adef5d93358b39fbb757463bc9edc78b7b86566cb1ab8c7ff3a52b10d98de6398aacc7b48aec92a3e280065a47b9698209541b"` + ); + + expect( + await signer.signMessage("i will definately break this test case") + ).toMatchInlineSnapshot( + `"0x907004e990bb1bca76d9fed6bf4a6b614a8d11b6430657cb99ae83fae55c9bc60571876d8c01832e4661dd4312fa08b799b6f59c9b9abddd67e181abc6aef17e1c"` + ); + + expect(await signer.signMessage(dummyAddress)).toMatchInlineSnapshot( + `"0x64e29e4786b3740ceffc2c1a932124ee74c29b552957ea3bde8913753d1763af4f03362e387d2badb33932e8fc4f7b3411a0a5ade32a5b708aa48c171632a6211b"` + ); + }); + + it("should return wallet address", async () => { + expect(await signer.getAddress()).eql(dummyAddress); + }); +}); diff --git a/packages/core/src/account/base.ts b/packages/core/src/account/base.ts index 8968b35a58..365b8ecfc7 100644 --- a/packages/core/src/account/base.ts +++ b/packages/core/src/account/base.ts @@ -18,9 +18,9 @@ import type { ISmartContractAccount } from "./types.js"; import type { BatchUserOperationCallData } from "../types.js"; export enum DeploymentState { - UNDEFINED = '0x0', - NOT_DEPLOYED = '0x1', - DEPLOYED = '0x2', + UNDEFINED = "0x0", + NOT_DEPLOYED = "0x1", + DEPLOYED = "0x2", } export interface BaseSmartAccountParams< @@ -83,7 +83,7 @@ export abstract class BaseSmartContractAccount< } async getNonce(): Promise { - if(!await this.isAccountDeployed()) { + if (!(await this.isAccountDeployed())) { return 0n; } const address = await this.getAddress(); @@ -128,15 +128,17 @@ export abstract class BaseSmartContractAccount< // Extra implementations async isAccountDeployed(): Promise { - return await this.getDeploymentState() === DeploymentState.DEPLOYED + return (await this.getDeploymentState()) === DeploymentState.DEPLOYED; } async getDeploymentState(): Promise { - if(this.deploymentState === DeploymentState.UNDEFINED) { + if (this.deploymentState === DeploymentState.UNDEFINED) { const initCode = await this.getInitCode(); - return (initCode === "0x") ? DeploymentState.DEPLOYED : DeploymentState.NOT_DEPLOYED + return initCode === "0x" + ? DeploymentState.DEPLOYED + : DeploymentState.NOT_DEPLOYED; } else { - return this.deploymentState + return this.deploymentState; } } -} \ No newline at end of file +} diff --git a/packages/core/src/signer/hd-account.ts b/packages/core/src/signer/hd-account.ts index 84ee78d255..a55c1cba10 100644 --- a/packages/core/src/signer/hd-account.ts +++ b/packages/core/src/signer/hd-account.ts @@ -1,35 +1,35 @@ -import type {Address} from "abitype"; -import type {HDAccount, Hex} from "viem"; -import {mnemonicToAccount} from "viem/accounts"; -import type {SmartAccountSigner} from "./types"; +import type { Address } from "abitype"; +import type { HDAccount, Hex } from "viem"; +import { mnemonicToAccount } from "viem/accounts"; +import type { SmartAccountSigner } from "./types"; export class HdAccountSigner implements SmartAccountSigner { - owner: HDAccount + owner: HDAccount; - constructor(owner: HDAccount) { - this.owner = owner; - } + constructor(owner: HDAccount) { + this.owner = owner; + } - signMessage(msg: Uint8Array | Hex | string): Promise { - if (typeof msg === "string") { - return this.owner.signMessage({ - message: msg - }) - } else { - return this.owner.signMessage({ - message: { - raw: msg - } - }) - } + signMessage(msg: Uint8Array | Hex | string): Promise { + if (typeof msg === "string") { + return this.owner.signMessage({ + message: msg, + }); + } else { + return this.owner.signMessage({ + message: { + raw: msg, + }, + }); } + } - getAddress(): Promise
{ - return Promise.resolve(this.owner.address); - } + getAddress(): Promise
{ + return Promise.resolve(this.owner.address); + } - static mnemonicToAccountSigner(key: Hex): HdAccountSigner { - const owner = mnemonicToAccount(key) - return new HdAccountSigner(owner) - } -} \ No newline at end of file + static mnemonicToAccountSigner(key: Hex): HdAccountSigner { + const owner = mnemonicToAccount(key); + return new HdAccountSigner(owner); + } +} diff --git a/packages/core/src/signer/private-key.ts b/packages/core/src/signer/private-key.ts index 0c252183f8..2de3401574 100644 --- a/packages/core/src/signer/private-key.ts +++ b/packages/core/src/signer/private-key.ts @@ -1,35 +1,35 @@ -import type {Address} from "abitype"; -import type {Hex, PrivateKeyAccount} from "viem"; -import {privateKeyToAccount} from "viem/accounts"; -import type {SmartAccountSigner} from "./types"; +import type { Address } from "abitype"; +import type { Hex, PrivateKeyAccount } from "viem"; +import { privateKeyToAccount } from "viem/accounts"; +import type { SmartAccountSigner } from "./types"; export class PrivateKeySigner implements SmartAccountSigner { - owner: PrivateKeyAccount + owner: PrivateKeyAccount; - constructor(owner: PrivateKeyAccount) { - this.owner = owner; - } + constructor(owner: PrivateKeyAccount) { + this.owner = owner; + } - signMessage(msg: Uint8Array | Hex | string): Promise { - if (typeof msg === "string") { - return this.owner.signMessage({ - message: msg - }) - } else { - return this.owner.signMessage({ - message: { - raw: msg - } - }) - } + signMessage(msg: Uint8Array | Hex | string): Promise { + if (typeof msg === "string") { + return this.owner.signMessage({ + message: msg, + }); + } else { + return this.owner.signMessage({ + message: { + raw: msg, + }, + }); } + } - getAddress(): Promise
{ - return Promise.resolve(this.owner.address); - } + getAddress(): Promise
{ + return Promise.resolve(this.owner.address); + } - static privateKeyToAccountSigner(key: Hex): PrivateKeySigner { - const owner = privateKeyToAccount(key) - return new PrivateKeySigner(owner) - } -} \ No newline at end of file + static privateKeyToAccountSigner(key: Hex): PrivateKeySigner { + const owner = privateKeyToAccount(key); + return new PrivateKeySigner(owner); + } +} diff --git a/packages/core/src/signer/types.ts b/packages/core/src/signer/types.ts index a44db00b49..9828774e6c 100644 --- a/packages/core/src/signer/types.ts +++ b/packages/core/src/signer/types.ts @@ -1,7 +1,7 @@ -import type {Address} from "abitype"; -import type {Hex} from "viem"; +import type { Address } from "abitype"; +import type { Hex } from "viem"; export interface SmartAccountSigner { - signMessage: (msg: Uint8Array | Hex | string) => Promise; - getAddress: () => Promise
; -} \ No newline at end of file + signMessage: (msg: Uint8Array | Hex | string) => Promise; + getAddress: () => Promise
; +} diff --git a/yarn.lock b/yarn.lock index b0a3358047..74a95ac147 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,7 +8,7 @@ integrity sha512-iowxq3U30sghZotgl4s/oJRci6WPBfNO5YYgk2cIOMCHr3LeGPcsZjCEr+33Q4N+oV3OABDAtA+pyvWjbvBifQ== "@alchemy/aa-core@file:packages/core": - version "0.1.0-alpha.1" + version "0.1.0-alpha.5" dependencies: abitype "^0.8.3"