diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a59da05fa8..0d4d680282 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -14,7 +14,10 @@ export type { BaseSmartAccountParams } from "./account/types.js"; export { LocalAccountSigner } from "./signer/local-account.js"; export { SignerSchema } from "./signer/schema.js"; -export type { SmartAccountSigner } from "./signer/types.js"; +export type { + AuthSmartAccountSigner, + SmartAccountSigner, +} from "./signer/types.js"; export { verifyEIP6492Signature, wrapSignatureWith6492, diff --git a/packages/core/src/signer/types.ts b/packages/core/src/signer/types.ts index 2616ad9922..41c1ca4ee3 100644 --- a/packages/core/src/signer/types.ts +++ b/packages/core/src/signer/types.ts @@ -1,10 +1,33 @@ -import type { Address } from "abitype"; import type { Hash, Hex } from "viem"; import type { SignTypedDataParams } from "../account/types.js"; +export interface AuthSmartAccountSigner< + Inner = any, + AuthParams = any, + UserDetails = any +> extends SmartAccountSigner { + inner: Inner; + user: User | undefined; + + authenticateUser: (params: AuthParams) => Promise; + + getUserDetails: () => Promise; +} + export interface SmartAccountSigner { signerType: string; - signMessage: (msg: Uint8Array | Hex | string) => Promise; - signTypedData: (params: SignTypedDataParams) => Promise; - getAddress: () => Promise
; + + getAddress: () => Promise; + + signMessage: (msg: Uint8Array | Hex | string) => Promise; + + signTypedData: (params: SignTypedDataParams) => Promise; +} + +export interface User { + id: string; + + isAuthenticated: () => Promise; + + getDetails: () => Promise; } diff --git a/packages/signers/CHANGELOG.md b/packages/signers/CHANGELOG.md new file mode 100644 index 0000000000..041027cf10 --- /dev/null +++ b/packages/signers/CHANGELOG.md @@ -0,0 +1,168 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +# 0.2.0 (2023-11-03) + +### Features + +- merge development into main for new version release ([#207](https://github.com/alchemyplatform/aa-sdk/issues/207)) ([f06fd2a](https://github.com/alchemyplatform/aa-sdk/commit/f06fd2adf5e4aaf90214435d32f9d566d8502099)) + +## 0.1.1 (2023-10-20) + +### Bug Fixes + +- bad deploy script again ([2da8de2](https://github.com/alchemyplatform/aa-sdk/commit/2da8de2f4feb4c82fd454050e66f6203b61bcc2c)) + +# [0.1.0](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.32...v0.1.0) (2023-10-10) + +### Features + +- merge in all of the staged changes to the aa-sdk ([#120](https://github.com/alchemyplatform/aa-sdk/issues/120)) ([7a9effa](https://github.com/alchemyplatform/aa-sdk/commit/7a9effaa07c03a6a50c9cf856b5935e735adae3a)), closes [#1](https://github.com/alchemyplatform/aa-sdk/issues/1) [#2](https://github.com/alchemyplatform/aa-sdk/issues/2) [#3](https://github.com/alchemyplatform/aa-sdk/issues/3) [#7](https://github.com/alchemyplatform/aa-sdk/issues/7) [#8](https://github.com/alchemyplatform/aa-sdk/issues/8) [#9](https://github.com/alchemyplatform/aa-sdk/issues/9) + +# 0.1.0-alpha.32 (2023-09-18) + +### Bug Fixes + +- `baseGoerli` chainId in `chains.ts` ([#104](https://github.com/alchemyplatform/aa-sdk/issues/104)) ([2dda5dd](https://github.com/alchemyplatform/aa-sdk/commit/2dda5dd729124338ddf529c11bbf24afaea05dd4)) + +# 0.1.0-alpha.31 (2023-09-13) + +### Bug Fixes + +- remove all references to `SimpleSmartAccountOwner` ([#101](https://github.com/alchemyplatform/aa-sdk/issues/101)) ([a8f101d](https://github.com/alchemyplatform/aa-sdk/commit/a8f101dff7fbbd10598467ddaaa1c3c55f707e6d)) + +# 0.1.0-alpha.30 (2023-09-11) + +### Features + +- add base support to alchemy provider ([#100](https://github.com/alchemyplatform/aa-sdk/issues/100)) ([a5dc65c](https://github.com/alchemyplatform/aa-sdk/commit/a5dc65c4208614b935943ebdd8eececf3de03d29)) + +# 0.1.0-alpha.29 (2023-08-29) + +### Bug Fixes + +- **core:** add missing `null` return type of `eth_getUserOperation*` ([#93](https://github.com/alchemyplatform/aa-sdk/issues/93)) ([cba9a0c](https://github.com/alchemyplatform/aa-sdk/commit/cba9a0c79807612b37c9d8c300b494312c9bd752)) + +# 0.1.0-alpha.28 (2023-08-25) + +### Bug Fixes + +- pass overrides from tx to user op ([#88](https://github.com/alchemyplatform/aa-sdk/issues/88)) ([985cb99](https://github.com/alchemyplatform/aa-sdk/commit/985cb997691f5b251337ea0fbe6bd23e6b3fb455)) + +# 0.1.0-alpha.27 (2023-08-24) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# 0.1.0-alpha.26 (2023-08-23) + +### Features + +- add utils for getting the intermediary UO struct ([#86](https://github.com/alchemyplatform/aa-sdk/issues/86)) ([0e1a701](https://github.com/alchemyplatform/aa-sdk/commit/0e1a70174c0eeff2eedce4379914cad75f0629b2)) + +# 0.1.0-alpha.25 (2023-08-17) + +### Features + +- add jwt support for Alchemy providers ([#81](https://github.com/alchemyplatform/aa-sdk/issues/81)) ([af85aa4](https://github.com/alchemyplatform/aa-sdk/commit/af85aa41441825ca6545e850cbc7e834879cf236)) + +# 0.1.0-alpha.24 (2023-08-16) + +### Features + +- add utils for verifying 6492 sigs and ensip-11 utils ([#80](https://github.com/alchemyplatform/aa-sdk/issues/80)) ([52231b6](https://github.com/alchemyplatform/aa-sdk/commit/52231b6b4a521ee0713c4d3d3126ac4e5d66f14c)) + +# 0.1.0-alpha.23 (2023-08-14) + +### Features + +- **alchemy:** modify fee defaults ([0a0a65c](https://github.com/alchemyplatform/aa-sdk/commit/0a0a65c03a6991a1c57473ae9e65c4b727d937e2)) + +# 0.1.0-alpha.22 (2023-08-11) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# 0.1.0-alpha.21 (2023-08-08) + +### Features + +- allow overriding alchemy provider rpc url ([#70](https://github.com/alchemyplatform/aa-sdk/issues/70)) ([6b7c4b9](https://github.com/alchemyplatform/aa-sdk/commit/6b7c4b911b97dfcd1cfb00b2892548644fbe2fc6)) + +# 0.1.0-alpha.20 (2023-08-05) + +### Features + +- add signTypedData to providers ([#66](https://github.com/alchemyplatform/aa-sdk/issues/66)) ([e0a99f6](https://github.com/alchemyplatform/aa-sdk/commit/e0a99f694a6ed6e88b15d6cc73f99e74fd985667)) + +# 0.1.0-alpha.19 (2023-08-03) + +### Features + +- add event emitter to the provider so that we can listen to connected events in dapps ([#65](https://github.com/alchemyplatform/aa-sdk/issues/65)) ([35ee990](https://github.com/alchemyplatform/aa-sdk/commit/35ee990afa1c8be7c4685631af6654ac51b094cd)) + +# 0.1.0-alpha.18 (2023-07-28) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# 0.1.0-alpha.17 (2023-07-19) + +### Features + +- add support for fetch options when creating public clients ([#59](https://github.com/alchemyplatform/aa-sdk/issues/59)) ([5028e7b](https://github.com/alchemyplatform/aa-sdk/commit/5028e7b21a208ad8f88e81d455c2c8e24d57d953)) + +# 0.1.0-alpha.16 (2023-07-06) + +### Bug Fixes + +- always import with file extension ([#48](https://github.com/alchemyplatform/aa-sdk/issues/48)) ([4776d74](https://github.com/alchemyplatform/aa-sdk/commit/4776d7476f8cb622416c8846afa9bc17d16b97a6)) + +# 0.1.0-alpha.15 (2023-07-05) + +### Features + +- kernel batch transactions and gas estimation fixes ([#39](https://github.com/alchemyplatform/aa-sdk/issues/39)) ([f2a3d3d](https://github.com/alchemyplatform/aa-sdk/commit/f2a3d3d093ddbe1b564c0242c28b67487554f1ba)) + +# 0.1.0-alpha.14 (2023-06-29) + +### Bug Fixes + +- npm 404 error ([f34f581](https://github.com/alchemyplatform/aa-sdk/commit/f34f581a0399a2e30f33161d8b4cc1d778122b1f)) + +# 0.1.0-alpha.13 (2023-06-29) + +### Bug Fixes + +- add github user details to publish script ([2b812d3](https://github.com/alchemyplatform/aa-sdk/commit/2b812d34c041e11ba7d4c11a72c26da8f8e7af21)) + +# [0.1.0-alpha.11](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.10...v0.1.0-alpha.11) (2023-06-26) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# [0.1.0-alpha.10](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.8...v0.1.0-alpha.10) (2023-06-26) + +### Bug Fixes + +- types changed when updating to latest viem ([0aec96d](https://github.com/alchemyplatform/aa-sdk/commit/0aec96d184b5bcc3787ce9123260cf287f27f037)) + +# [0.1.0-alpha.9](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.8...v0.1.0-alpha.9) (2023-06-26) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# [0.1.0-alpha.8](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.7...v0.1.0-alpha.8) (2023-06-23) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# [0.1.0-alpha.7](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.6...v0.1.0-alpha.7) (2023-06-20) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# [0.1.0-alpha.5](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.4...v0.1.0-alpha.5) (2023-06-16) + +**Note:** Version bump only for package @alchemy/aa-accounts + +# [0.1.0-alpha.4](https://github.com/alchemyplatform/aa-sdk/compare/v0.1.0-alpha.3...v0.1.0-alpha.4) (2023-06-14) + +### Features + +- add aa-accounts subpackage ([#23](https://github.com/alchemyplatform/aa-sdk/issues/23)) ([a7fd5da](https://github.com/alchemyplatform/aa-sdk/commit/a7fd5da8600b0a346627df3a4b5cc338210aa256)) diff --git a/packages/signers/README.md b/packages/signers/README.md new file mode 100644 index 0000000000..daa130effe --- /dev/null +++ b/packages/signers/README.md @@ -0,0 +1,40 @@ +# `@alchemy/aa-accounts` + +This package contains various implementations of the [`BaseSmartContractAccount`](../core/src/account/base.ts) class defined in `aa-core`. This repo is community maintained and we welcome contributions! + +## Getting started + +If you are already using the `@alchemy/aa-core` package, you can simply install this package and start using the accounts. If you are not using `@alchemy/aa-core`, you can install it and follow the instructions in the [README](../../README.md) to get started. + +via `yarn` + +```bash +yarn add @alchemy/aa-accounts +``` + +via `npm` + +```bash +npm i -s @alchemy/aa-accounts +``` + +## Contributing + +If you are looking to add a new account type, please follow the following structure. + +1. Create a new folder in `src` with the name of your account type in `kebab-case` (we're following kebab casing for files throughout the project). +2. Create a new file in the folder you just created called `account.ts` and add your implementation for `BaseSmartContractAccount` +3. If needed, create a sub-folder in your account folder called `abis` and add your abis as `.ts` files. eg: + +```ts +export const MyContractAbi = [] as const; // the as const is important so we can get correct typing from viem +``` + +4. If you need to extend the [`SmartAccountProvider`](../core/src/provider/base.ts) class, add a file called `provider.ts` and add your implementation for `SmartAccountProvider`. + +- Ideally, your `Account` impl should _just_ work with the base provider provided by `aa-core`. +- If not, consider generalizing the use case and updating SmartAccountProvider + +5. Add some tests for your account and provider (if created) by creating a subfolder in your `account/my-account` called `__tests__` and make sure your files end with the `.test.ts` suffix +6. export the classes and types you've defined in `src/index.ts` +7. Open a PR and we'll review it as soon as possible! diff --git a/packages/signers/package.json b/packages/signers/package.json new file mode 100644 index 0000000000..c5e10fa231 --- /dev/null +++ b/packages/signers/package.json @@ -0,0 +1,63 @@ +{ + "name": "@alchemy/aa-signers", + "version": "0.2.0", + "description": "A collection of signers used to create ERC-4337 smart accounts", + "author": "Alchemy", + "license": "MIT", + "private": false, + "type": "module", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "typings": "./dist/types/index.d.ts", + "sideEffects": false, + "files": [ + "dist", + "src/**/*.ts", + "!dist/**/*.tsbuildinfo", + "!vitest.config.ts", + "!.env", + "!src/**/*.test.ts", + "!src/__tests__/**/*" + ], + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "default": "./dist/cjs/index.js" + }, + "./package.json": "./package.json" + }, + "scripts": { + "build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'", + "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'", + "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap", + "clean": "rm -rf ./dist", + "test": "vitest", + "test:run": "vitest run", + "test:run-e2e": "vitest run --config vitest.config.e2e.ts" + }, + "devDependencies": { + "typescript": "^5.0.4", + "typescript-template": "*", + "vitest": "^0.31.0" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/alchemyplatform/aa-sdk.git" + }, + "bugs": { + "url": "https://github.com/alchemyplatform/aa-sdk/issues" + }, + "homepage": "https://github.com/alchemyplatform/aa-sdk#readme", + "gitHead": "ee46e8bb857de3b631044fa70714ea706d9e317d", + "dependencies": { + "@alchemy/aa-core": "^0.2.0", + "viem": "^1.16.2" + } +} diff --git a/packages/signers/src/index.test.ts b/packages/signers/src/index.test.ts new file mode 100644 index 0000000000..d2e1a6b76b --- /dev/null +++ b/packages/signers/src/index.test.ts @@ -0,0 +1,5 @@ +describe("Tests", () => { + it("should pass", () => { + expect(true).toBe(true); + }); +}); diff --git a/packages/signers/src/index.ts b/packages/signers/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/signers/tsconfig.build.json b/packages/signers/tsconfig.build.json new file mode 100644 index 0000000000..345f8f3fab --- /dev/null +++ b/packages/signers/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "typescript-template/build.json", + "exclude": ["node_modules", "**/*/__tests__", "vitest.config.ts"], + "include": ["src"], + "compilerOptions": { + "sourceMap": true + } +} diff --git a/packages/signers/tsconfig.json b/packages/signers/tsconfig.json new file mode 100644 index 0000000000..748018d6a6 --- /dev/null +++ b/packages/signers/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "typescript-template/base.json" +} diff --git a/packages/signers/vitest.config.e2e.ts b/packages/signers/vitest.config.e2e.ts new file mode 100644 index 0000000000..b12027a9e4 --- /dev/null +++ b/packages/signers/vitest.config.e2e.ts @@ -0,0 +1,11 @@ +import { configDefaults, defineProject } from "vitest/config"; + +export default defineProject({ + test: { + singleThread: true, + globals: true, + setupFiles: ["../../.vitest/setupTests.ts"], + exclude: [...configDefaults.exclude, "**/__tests__/**/*.test.ts"], + name: "accounts", + }, +}); diff --git a/packages/signers/vitest.config.ts b/packages/signers/vitest.config.ts new file mode 100644 index 0000000000..2cfffbd66f --- /dev/null +++ b/packages/signers/vitest.config.ts @@ -0,0 +1,11 @@ +import { configDefaults, defineProject } from "vitest/config"; + +export default defineProject({ + test: { + singleThread: true, + globals: true, + setupFiles: ["../../.vitest/setupTests.ts"], + exclude: [...configDefaults.exclude, "**/e2e-tests/**/*.test.ts"], + name: "accounts", + }, +}); diff --git a/yarn.lock b/yarn.lock index 541b10fc1f..c765ba9f96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,31 +12,6 @@ resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.9.4.tgz#aae21cb858bbb0411949d5b7b3051f4209043f62" integrity sha512-UK0bHA7hh9cR39V+4gl2/NnBBjoXIxkuWAPCaY4X7fbH4L/azIi7ilWOCjMUYfpJgraLUAqkRi2BqrjME8Rynw== -"@alchemy/aa-accounts@^0.1.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@alchemy/aa-accounts/-/aa-accounts-0.1.1.tgz#7527e25fe2825eb91d80f6e4cb85d188606587a4" - integrity sha512-nHHnJuIHXGdvH5i+7DlTeSPa3RJtNLt4NpJP+G+T8G3QP/k6mxHNWFTybOhqxuCC798DACxKc4thOL2Lj8phgA== - dependencies: - "@alchemy/aa-core" "^0.1.1" - viem "^1.16.2" - -"@alchemy/aa-alchemy@^0.1.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@alchemy/aa-alchemy/-/aa-alchemy-0.1.1.tgz#f7f989b2aaae127a49a61e1dde6d6f52d40d0018" - integrity sha512-rVQZNb1QmfQoxDyaXuinB0pfrKENLydwH57TWXJn4wFW+3c+iM6xM/tsfx6zxzA7HTwodcRw8//wMvdF+5KQmg== - dependencies: - "@alchemy/aa-core" "^0.1.1" - viem "^1.16.2" - -"@alchemy/aa-core@^0.1.1": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@alchemy/aa-core/-/aa-core-0.1.1.tgz#2c81e34c0ca939897004c68d80250f1b4b423ff2" - integrity sha512-vEfCx9MJMTCMpmB3cY+TcM65znP8zcMTaiYE7By3+krhd7ViflWdEILe5HGGzCALGqdr6pUaBI7n08eVoyo6KQ== - dependencies: - abitype "^0.8.3" - eventemitter3 "^5.0.1" - viem "^1.16.2" - "@algolia/autocomplete-core@1.9.3": version "1.9.3" resolved "https://registry.yarnpkg.com/@algolia/autocomplete-core/-/autocomplete-core-1.9.3.tgz#1d56482a768c33aae0868c8533049e02e8961be7"