File tree Expand file tree Collapse file tree 5 files changed +53
-1
lines changed Expand file tree Collapse file tree 5 files changed +53
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " thirdweb " : patch
3
+ ---
4
+
5
+ Expose inMemoryStorage for inAppWallet backend usage
Original file line number Diff line number Diff line change @@ -11,3 +11,4 @@ export {
11
11
type ResolveArweaveSchemeOptions ,
12
12
} from "../utils/arweave.js" ;
13
13
export type { AsyncStorage } from "../utils/storage/AsyncStorage.js" ;
14
+ export { inMemoryStorage } from "../utils/storage/inMemoryStorage.js" ;
Original file line number Diff line number Diff line change
1
+ import type { AsyncStorage } from "./AsyncStorage.js" ;
2
+
3
+ const store = new Map < string , string > ( ) ;
4
+
5
+ export const inMemoryStorage : AsyncStorage = {
6
+ getItem : async ( key : string ) => {
7
+ return store . get ( key ) ?? null ;
8
+ } ,
9
+ setItem : async ( key : string , value : string ) => {
10
+ store . set ( key , value ) ;
11
+ } ,
12
+ removeItem : async ( key : string ) => {
13
+ store . delete ( key ) ;
14
+ } ,
15
+ } ;
Original file line number Diff line number Diff line change @@ -141,10 +141,14 @@ import type { InAppWalletCreationOptions } from "../core/wallet/types.js";
141
141
*
142
142
* ### Connect to a backend account
143
143
*
144
+ * for usage in backends, you might also need to provide a 'storage' to store auth tokens. In-memory usually works for most purposes.
145
+ *
144
146
* ```ts
145
147
* import { inAppWallet } from "thirdweb/wallets";
146
148
*
147
- * const wallet = inAppWallet();
149
+ * const wallet = inAppWallet({
150
+ * storage: inMemoryStorage, // for usage in backends/scripts
151
+ * });
148
152
*
149
153
* const account = await wallet.connect({
150
154
* client,
Original file line number Diff line number Diff line change
1
+ import { describe , expect , it } from "vitest" ;
2
+ import { TEST_CLIENT } from "~test/test-clients.js" ;
3
+ import { sepolia } from "../../../../chains/chain-definitions/sepolia.js" ;
4
+ import { inMemoryStorage } from "../../../../utils/storage/inMemoryStorage.js" ;
5
+ import { inAppWallet } from "../in-app.js" ;
6
+
7
+ describe ( "InAppWallet" , ( ) => {
8
+ it ( "should sign a message with backend strategy" , async ( ) => {
9
+ const wallet = inAppWallet ( {
10
+ smartAccount : {
11
+ chain : sepolia ,
12
+ sponsorGas : true ,
13
+ } ,
14
+ storage : inMemoryStorage ,
15
+ } ) ;
16
+ const account = await wallet . connect ( {
17
+ client : TEST_CLIENT ,
18
+ strategy : "backend" ,
19
+ walletSecret : "test-secret" ,
20
+ } ) ;
21
+ expect ( account . address ) . toBeDefined ( ) ;
22
+ const message = await account . signMessage ( {
23
+ message : "Hello, world!" ,
24
+ } ) ;
25
+ expect ( message ) . toBeDefined ( ) ;
26
+ } ) ;
27
+ } ) ;
You can’t perform that action at this time.
0 commit comments