Skip to content

Commit 157daff

Browse files
author
Nguyen Anh Tu
committed
feat(app): account abstraction - add AA support
1 parent 6b78daa commit 157daff

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Web3Auth.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
WEB3AUTH_NETWORK,
1010
WEB3AUTH_NETWORK_TYPE,
1111
} from "@web3auth/auth";
12-
import { type IBaseProvider, type IProvider } from "@web3auth/base";
12+
import { type IProvider } from "@web3auth/base";
1313
import clonedeep from "lodash.clonedeep";
1414
import merge from "lodash.merge";
1515
import log from "loglevel";
@@ -50,7 +50,9 @@ class Web3Auth implements IWeb3Auth {
5050

5151
private addVersionInUrls = true;
5252

53-
private privateKeyProvider: IBaseProvider<string>;
53+
private privateKeyProvider: SdkInitParams["privateKeyProvider"];
54+
55+
private accountAbstractionProvider?: SdkInitParams["accountAbstractionProvider"];
5456

5557
constructor(webBrowser: IWebBrowser, storage: SecureStore | EncryptedStorage, options: SdkInitParams) {
5658
if (!options.clientId) throw InitializationError.invalidParams("clientId is required");
@@ -117,6 +119,9 @@ class Web3Auth implements IWeb3Auth {
117119
this.webBrowser = webBrowser;
118120
this.keyStore = new KeyStore(storage);
119121
this.privateKeyProvider = options.privateKeyProvider;
122+
if (options.accountAbstractionProvider) {
123+
this.accountAbstractionProvider = options.accountAbstractionProvider;
124+
}
120125
this.state = {};
121126
}
122127

@@ -126,7 +131,7 @@ class Web3Auth implements IWeb3Auth {
126131

127132
get provider(): IProvider | null {
128133
if (this.privateKeyProvider) {
129-
return this.privateKeyProvider;
134+
return this.accountAbstractionProvider ?? this.privateKeyProvider;
130135
}
131136
return null;
132137
}
@@ -184,6 +189,10 @@ class Web3Auth implements IWeb3Auth {
184189
const finalPrivKey = this.getFinalPrivKey();
185190
if (!finalPrivKey) return;
186191
await this.privateKeyProvider.setupProvider(finalPrivKey);
192+
// setup aa provider after private key provider is setup
193+
if (this.accountAbstractionProvider) {
194+
await this.accountAbstractionProvider.setupProvider(this.privateKeyProvider);
195+
}
187196
} else {
188197
await this.keyStore.remove("sessionId");
189198
this.updateState({});
@@ -253,6 +262,10 @@ class Web3Auth implements IWeb3Auth {
253262
const finalPrivKey = this.getFinalPrivKey();
254263
if (!finalPrivKey) throw LoginError.loginFailed("final private key not found");
255264
await this.privateKeyProvider.setupProvider(finalPrivKey);
265+
// setup aa provider after private key provider is setup
266+
if (this.accountAbstractionProvider) {
267+
await this.accountAbstractionProvider.setupProvider(this.privateKeyProvider);
268+
}
256269

257270
return this.provider;
258271
}

src/types/interface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
WEB3AUTH_NETWORK,
1313
THEME_MODES,
1414
} from "@web3auth/auth";
15-
import type { IBaseProvider, IProvider } from "@web3auth/base"
15+
import type { IBaseProvider, IProvider } from "@web3auth/base";
1616

1717
type SdkSpecificInitParams = {
1818
enableLogging?: boolean;
@@ -22,6 +22,10 @@ type SdkSpecificInitParams = {
2222
* Private key provider for your chain namespace
2323
*/
2424
privateKeyProvider: IBaseProvider<string>;
25+
/**
26+
* Account abstraction provider for your chain namespace
27+
*/
28+
accountAbstractionProvider?: IBaseProvider<IProvider>;
2529
};
2630

2731
export type SdkInitParams = Omit<AuthOptions & SdkSpecificInitParams, "uxMode" | "replaceUrlOnRedirect" | "storageKey"> &

0 commit comments

Comments
 (0)