Skip to content

Commit

Permalink
Merge pull request #1981 from Web3Auth/feat/aa-gating
Browse files Browse the repository at this point in the history
add gating for using aa_providers on mainnet networks
  • Loading branch information
chaitanyapotti authored Oct 11, 2024
2 parents b0421f3 + d251a8a commit 07f9598
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 5 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/base/src/provider/IProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export const PROVIDER_EVENTS = {
INITIALIZED: "initialized",
ERRORED: "errored",
};

export interface IBaseSmartAccount {
name: string;
}
7 changes: 6 additions & 1 deletion packages/base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ export const signerHost = (web3AuthNetwork?: WEB3AUTH_NETWORK_TYPE): string => {
return SIGNER_MAP[web3AuthNetwork ?? WEB3AUTH_NETWORK.SAPPHIRE_MAINNET];
};

export const fetchProjectConfig = async (clientId: string, web3AuthNetwork: WEB3AUTH_NETWORK_TYPE): Promise<PROJECT_CONFIG_RESPONSE> => {
export const fetchProjectConfig = async (
clientId: string,
web3AuthNetwork: WEB3AUTH_NETWORK_TYPE,
aaProvider?: string
): Promise<PROJECT_CONFIG_RESPONSE> => {
const url = new URL(`${signerHost(web3AuthNetwork)}/api/configuration`);
url.searchParams.append("project_id", clientId);
url.searchParams.append("network", web3AuthNetwork);
url.searchParams.append("whitelist", "true");
if (aaProvider) url.searchParams.append("aa_provider", aaProvider);
const res = await get<PROJECT_CONFIG_RESPONSE>(url.href);
return res;
};
Expand Down
1 change: 1 addition & 0 deletions packages/modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@toruslabs/isomorphic-style-loader": "^5.3.3",
"@web3auth/account-abstraction-provider": "^9.2.1",
"@web3auth/auth": "^9.4.1",
"@web3auth/wallet-connect-v2-adapter": "^9.2.1",
"css-loader": "^7.1.2",
Expand Down
7 changes: 6 additions & 1 deletion packages/modal/src/modalManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AccountAbstractionProvider } from "@web3auth/account-abstraction-provider";
import { AuthAdapter, AuthOptions, getAuthDefaultOptions, LOGIN_PROVIDER, LoginConfig } from "@web3auth/auth-adapter";
import {
ADAPTER_CATEGORY,
Expand Down Expand Up @@ -75,7 +76,11 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {

let projectConfig: PROJECT_CONFIG_RESPONSE;
try {
projectConfig = await fetchProjectConfig(this.options.clientId, this.options.web3AuthNetwork);
projectConfig = await fetchProjectConfig(
this.options.clientId,
this.options.web3AuthNetwork,
(this.options.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.name
);
} catch (e) {
log.error("Failed to fetch project configurations", e);
throw WalletInitializationError.notReady("failed to fetch project configurations", e);
Expand Down
1 change: 1 addition & 0 deletions packages/no-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"deepmerge": "^4.3.1"
},
"devDependencies": {
"@web3auth/account-abstraction-provider": "^9.2.1",
"@web3auth/auth-adapter": "^9.2.1",
"@web3auth/wallet-connect-v2-adapter": "^9.2.1"
},
Expand Down
7 changes: 6 additions & 1 deletion packages/no-modal/src/noModal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AccountAbstractionProvider } from "@web3auth/account-abstraction-provider";
import { SafeEventEmitter, type SafeEventEmitterProvider } from "@web3auth/auth";
import { type AuthAdapter, LOGIN_PROVIDER, type LoginConfig } from "@web3auth/auth-adapter";
import {
Expand Down Expand Up @@ -97,7 +98,11 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp

let projectConfig: PROJECT_CONFIG_RESPONSE;
try {
projectConfig = await fetchProjectConfig(this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
projectConfig = await fetchProjectConfig(
this.coreOptions.clientId,
this.coreOptions.web3AuthNetwork,
(this.coreOptions.accountAbstractionProvider as AccountAbstractionProvider)?.config.smartAccountInit.name
);
} catch (e) {
log.error("Failed to fetch project configurations", e);
throw WalletInitializationError.notReady("failed to fetch project configurations", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { toBiconomySmartAccount, ToBiconomySmartAccountParameters } from "permis
import { Client, EIP1193Provider } from "viem";
import { entryPoint06Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type BiconomySmartAccountConfig = Pick<ToBiconomySmartAccountParameters, "entryPoint" | "ecdsaModuleAddress" | "factoryAddress">;

export class BiconomySmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.BICONOMY;

private options: BiconomySmartAccountConfig;

constructor(options?: BiconomySmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { toEcdsaKernelSmartAccount } from "permissionless/accounts";
import { Client, EIP1193Provider } from "viem";
import { SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type KernelSmartAccountParameters = Parameters<typeof toEcdsaKernelSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type KernelSmartAccountConfig = Omit<KernelSmartAccountParameters, "owners" | "client" | "address" | "nonceKey" | "index">;

export class KernelSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.KERNEL;

private options: KernelSmartAccountConfig;

constructor(options?: KernelSmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { toLightSmartAccount, ToLightSmartAccountParameters } from "permissionle
import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type LightSmartAccountConfig = Omit<ToLightSmartAccountParameters, "owner" | "client" | "index" | "address" | "nonceKey">;

export class LightSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.LIGHT;

private options: LightSmartAccountConfig;

constructor(options?: LightSmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { toSafeSmartAccount } from "permissionless/accounts";
import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type SafeSmartAccountParameters = Parameters<typeof toSafeSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type
Expand All @@ -13,6 +14,8 @@ type SafeSmartAccountConfig = Omit<
>;

export class SafeSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.SAFE;

private options: SafeSmartAccountConfig;

constructor(options?: SafeSmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { toSimpleSmartAccount } from "permissionless/accounts";
import { Client, EIP1193Provider } from "viem";
import { entryPoint07Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type SimpleSmartAccountParameters = Parameters<typeof toSimpleSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type SimpleSmartAccountConfig = Omit<SimpleSmartAccountParameters, "owner" | "client">;

export class SimpleSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.SIMPLE;

private options: SimpleSmartAccountConfig;

constructor(options?: SimpleSmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { toTrustSmartAccount } from "permissionless/accounts";
import { Client, EIP1193Provider } from "viem";
import { entryPoint06Address, SmartAccount } from "viem/account-abstraction";

import { SMART_ACCOUNT } from "./constants";
import { ISmartAccount } from "./types";

type TrustSmartAccountParameters = Parameters<typeof toTrustSmartAccount>[0]; // use type of function so we don't need to pass in generic to parameter type

type TrustSmartAccountConfig = Omit<TrustSmartAccountParameters, "owner" | "client" | "address" | "nonceKey" | "index">;

export class TrustSmartAccount implements ISmartAccount {
readonly name: string = SMART_ACCOUNT.TRUST;

private options: TrustSmartAccountConfig;

constructor(options?: TrustSmartAccountConfig) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SMART_ACCOUNT = {
BICONOMY: "biconomy",
KERNEL: "kernel",
LIGHT: "light",
SAFE: "safe",
SIMPLE: "simple",
TRUST: "trust",
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IProvider } from "@web3auth/base";
import { IBaseSmartAccount, IProvider } from "@web3auth/base";
import { Client } from "viem";
import { SmartAccount } from "viem/account-abstraction";

export interface ISmartAccount {
export interface ISmartAccount extends IBaseSmartAccount {
getSmartAccount(params: { owner: IProvider; client: Client }): Promise<SmartAccount>;
}

0 comments on commit 07f9598

Please sign in to comment.