Skip to content

Commit

Permalink
chore: add lint and build PR checks (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Jun 20, 2023
1 parent bb24e2d commit cb2c6b8
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/dist/*
examples/**/*
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'FR: <My Feature Request>'
title: "FR: <My Feature Request>"
labels: feature request, needs-triage
assignees: ''
assignees: ""
---

**Is your feature request related to a problem? Please describe.**
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 9 additions & 10 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .prettierignore
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
67 changes: 34 additions & 33 deletions packages/core/src/__tests__/private-key-signer.test.ts
Original file line number Diff line number Diff line change
@@ -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
);

});
})
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);
});
});
20 changes: 11 additions & 9 deletions packages/core/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -83,7 +83,7 @@ export abstract class BaseSmartContractAccount<
}

async getNonce(): Promise<bigint> {
if(!await this.isAccountDeployed()) {
if (!(await this.isAccountDeployed())) {
return 0n;
}
const address = await this.getAddress();
Expand Down Expand Up @@ -128,15 +128,17 @@ export abstract class BaseSmartContractAccount<

// Extra implementations
async isAccountDeployed(): Promise<boolean> {
return await this.getDeploymentState() === DeploymentState.DEPLOYED
return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;
}

async getDeploymentState(): Promise<DeploymentState> {
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;
}
}
}
}
56 changes: 28 additions & 28 deletions packages/core/src/signer/hd-account.ts
Original file line number Diff line number Diff line change
@@ -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<Hex> {
if (typeof msg === "string") {
return this.owner.signMessage({
message: msg
})
} else {
return this.owner.signMessage({
message: {
raw: msg
}
})
}
signMessage(msg: Uint8Array | Hex | string): Promise<Hex> {
if (typeof msg === "string") {
return this.owner.signMessage({
message: msg,
});
} else {
return this.owner.signMessage({
message: {
raw: msg,
},
});
}
}

getAddress(): Promise<Address> {
return Promise.resolve(this.owner.address);
}
getAddress(): Promise<Address> {
return Promise.resolve(this.owner.address);
}

static mnemonicToAccountSigner(key: Hex): HdAccountSigner {
const owner = mnemonicToAccount(key)
return new HdAccountSigner(owner)
}
}
static mnemonicToAccountSigner(key: Hex): HdAccountSigner {
const owner = mnemonicToAccount(key);
return new HdAccountSigner(owner);
}
}
56 changes: 28 additions & 28 deletions packages/core/src/signer/private-key.ts
Original file line number Diff line number Diff line change
@@ -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<Hex> {
if (typeof msg === "string") {
return this.owner.signMessage({
message: msg
})
} else {
return this.owner.signMessage({
message: {
raw: msg
}
})
}
signMessage(msg: Uint8Array | Hex | string): Promise<Hex> {
if (typeof msg === "string") {
return this.owner.signMessage({
message: msg,
});
} else {
return this.owner.signMessage({
message: {
raw: msg,
},
});
}
}

getAddress(): Promise<Address> {
return Promise.resolve(this.owner.address);
}
getAddress(): Promise<Address> {
return Promise.resolve(this.owner.address);
}

static privateKeyToAccountSigner(key: Hex): PrivateKeySigner {
const owner = privateKeyToAccount(key)
return new PrivateKeySigner(owner)
}
}
static privateKeyToAccountSigner(key: Hex): PrivateKeySigner {
const owner = privateKeyToAccount(key);
return new PrivateKeySigner(owner);
}
}
10 changes: 5 additions & 5 deletions packages/core/src/signer/types.ts
Original file line number Diff line number Diff line change
@@ -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<Hex>;
getAddress: () => Promise<Address>;
}
signMessage: (msg: Uint8Array | Hex | string) => Promise<Hex>;
getAddress: () => Promise<Address>;
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit cb2c6b8

Please sign in to comment.