@getpara/aa-thirdweb 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import { type Account } from 'thirdweb/wallets';
2
+ import type { SmartAccount4337, SmartAccount7702 } from '@getpara/viem-v2-integration';
3
+ import type { CreateThirdwebSmartAccountParams } from './types.js';
4
+ export type { CreateThirdwebSmartAccountParams } from './types.js';
5
+ /**
6
+ * Creates a Thirdweb smart wallet using Para for signing.
7
+ *
8
+ * Supports both EIP-4337 (smart wallet via bundler) and EIP-7702 (EOA delegation).
9
+ *
10
+ * @param params - Configuration parameters
11
+ * @returns Unified SmartAccount interface or null if no EVM wallet exists
12
+ */
13
+ export declare function createThirdwebSmartAccount(params: CreateThirdwebSmartAccountParams & {
14
+ mode: '7702';
15
+ }): Promise<SmartAccount7702<Account> | null>;
16
+ export declare function createThirdwebSmartAccount(params: CreateThirdwebSmartAccountParams & {
17
+ mode?: '4337';
18
+ }): Promise<SmartAccount4337<Account> | null>;
19
+ export declare function createThirdwebSmartAccount(params: CreateThirdwebSmartAccountParams): Promise<SmartAccount4337<Account> | SmartAccount7702<Account> | null>;
package/dist/action.js ADDED
@@ -0,0 +1,132 @@
1
+ import { createThirdwebClient } from "thirdweb";
2
+ import { defineChain } from "thirdweb/chains";
3
+ import { smartWallet } from "thirdweb/wallets";
4
+ import { create7702MinimalAccount } from "thirdweb/wallets/smart";
5
+ import { createParaAccount } from "@getpara/viem-v2-integration";
6
+ import { wrapProviderError, resolveWalletIdentifier } from "@getpara/viem-v2-integration";
7
+ import { createPublicClient, http } from "viem";
8
+ async function createThirdwebSmartAccount(params) {
9
+ const { para, clientId, chain, mode = "4337", sponsorGas = true, factoryAddress, accountAddress } = params;
10
+ const walletAddress = resolveWalletIdentifier(para, params);
11
+ if (!walletAddress) return null;
12
+ const viemAccount = createParaAccount(para, walletAddress);
13
+ const publicClient = createPublicClient({
14
+ chain,
15
+ transport: http()
16
+ });
17
+ const thirdwebChain = defineChain(chain.id);
18
+ const client = createThirdwebClient({
19
+ clientId
20
+ });
21
+ let thirdwebAccount;
22
+ if (mode === "7702") {
23
+ const adminAccount = {
24
+ address: viemAccount.address,
25
+ signMessage: async ({ message }) => {
26
+ const sig = await viemAccount.signMessage({ message });
27
+ return sig;
28
+ },
29
+ signTransaction: async (transaction) => {
30
+ const sig = await viemAccount.signTransaction(transaction);
31
+ return sig;
32
+ },
33
+ signTypedData: async (typedData) => {
34
+ const sig = await viemAccount.signTypedData(typedData);
35
+ return sig;
36
+ },
37
+ signAuthorization: async (authorization) => {
38
+ return viemAccount.signAuthorization({
39
+ ...authorization,
40
+ nonce: Number(authorization.nonce)
41
+ });
42
+ },
43
+ sendTransaction: async (_tx) => {
44
+ throw new Error("Non-sponsored sendTransaction not supported for thirdweb 7702. Use sponsorGas: true.");
45
+ }
46
+ };
47
+ thirdwebAccount = create7702MinimalAccount({
48
+ client,
49
+ adminAccount,
50
+ sponsorGas
51
+ });
52
+ } else {
53
+ const wallet = smartWallet({
54
+ chain: thirdwebChain,
55
+ sponsorGas,
56
+ ...factoryAddress && { factoryAddress },
57
+ ...accountAddress && { overrides: { accountAddress } }
58
+ });
59
+ const personalAccount = {
60
+ address: viemAccount.address,
61
+ signMessage: async ({ message }) => {
62
+ const sig = await viemAccount.signMessage({ message });
63
+ return sig;
64
+ },
65
+ signTransaction: async (transaction) => {
66
+ const sig = await viemAccount.signTransaction(transaction);
67
+ return sig;
68
+ },
69
+ signTypedData: async (typedData) => {
70
+ const sig = await viemAccount.signTypedData(typedData);
71
+ return sig;
72
+ }
73
+ };
74
+ thirdwebAccount = await wallet.connect({
75
+ client,
76
+ personalAccount,
77
+ chain: thirdwebChain
78
+ });
79
+ }
80
+ const sendTransaction = async ({ to, value, data }, txOptions) => {
81
+ const thirdwebOptions = txOptions;
82
+ try {
83
+ const result = await thirdwebAccount.sendTransaction({
84
+ to,
85
+ value: value || BigInt(0),
86
+ data: data || "0x",
87
+ chainId: thirdwebOptions?.chainId || chain?.id,
88
+ ...thirdwebOptions?.gas && { gas: thirdwebOptions.gas }
89
+ });
90
+ return publicClient.getTransactionReceipt({ hash: result.transactionHash });
91
+ } catch (error) {
92
+ throw wrapProviderError(error, "THIRDWEB");
93
+ }
94
+ };
95
+ const sendBatchTransaction = async (calls, txOptions) => {
96
+ const thirdwebOptions = txOptions;
97
+ const txChainId = thirdwebOptions?.chainId || chain?.id;
98
+ try {
99
+ if (!thirdwebAccount.sendBatchTransaction) {
100
+ let lastReceipt;
101
+ for (const call of calls) {
102
+ lastReceipt = await sendTransaction(call, txOptions);
103
+ }
104
+ return lastReceipt;
105
+ }
106
+ const result = await thirdwebAccount.sendBatchTransaction(
107
+ calls.map((call) => ({
108
+ to: call.to,
109
+ value: call.value || BigInt(0),
110
+ data: call.data || "0x",
111
+ chainId: txChainId
112
+ }))
113
+ );
114
+ return publicClient.getTransactionReceipt({ hash: result.transactionHash });
115
+ } catch (error) {
116
+ throw wrapProviderError(error, "THIRDWEB");
117
+ }
118
+ };
119
+ return {
120
+ smartAccountAddress: thirdwebAccount.address,
121
+ signer: viemAccount,
122
+ chain,
123
+ mode,
124
+ provider: "THIRDWEB",
125
+ sendTransaction,
126
+ sendBatchTransaction,
127
+ client: thirdwebAccount
128
+ };
129
+ }
130
+ export {
131
+ createThirdwebSmartAccount
132
+ };
@@ -0,0 +1,2 @@
1
+ export { createThirdwebSmartAccount } from './action.js';
2
+ export type { ThirdwebSmartAccountConfig, CreateThirdwebSmartAccountParams, UseThirdwebSmartAccountParams, } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { createThirdwebSmartAccount } from "./action.js";
2
+ export {
3
+ createThirdwebSmartAccount
4
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,40 @@
1
+ import type { ChainBasedSmartAccountConfig, CreateSmartAccountParams, SmartAccountModeParam } from '@getpara/viem-v2-integration';
2
+ /**
3
+ * Configuration for Thirdweb smart account.
4
+ *
5
+ * Supports both EIP-4337 (smart wallet via bundler) and EIP-7702 (EOA delegation).
6
+ * Uses Thirdweb's infrastructure with optional gas sponsorship.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const config: ThirdwebSmartAccountConfig = {
11
+ * clientId: 'YOUR_THIRDWEB_CLIENT_ID',
12
+ * chain: baseSepolia,
13
+ * mode: '4337',
14
+ * sponsorGas: true,
15
+ * };
16
+ * ```
17
+ */
18
+ export interface ThirdwebSmartAccountConfig extends ChainBasedSmartAccountConfig, SmartAccountModeParam {
19
+ /** Thirdweb client ID or secret key */
20
+ clientId: string;
21
+ /**
22
+ * Enable gas sponsorship via Thirdweb paymaster
23
+ * @default true
24
+ */
25
+ sponsorGas?: boolean;
26
+ /** Optional factory address for custom smart wallet deployment (4337 only) */
27
+ factoryAddress?: string;
28
+ /** Optional account address override (for existing smart accounts, 4337 only) */
29
+ accountAddress?: string;
30
+ }
31
+ /**
32
+ * Parameters for `createThirdwebSmartAccount`.
33
+ * Includes all config fields plus `para` (the Para SDK instance).
34
+ */
35
+ export type CreateThirdwebSmartAccountParams = CreateSmartAccountParams<ThirdwebSmartAccountConfig>;
36
+ /**
37
+ * Parameters for the `useThirdwebSmartAccount` hook.
38
+ * Same as {@link ThirdwebSmartAccountConfig} — `para` is provided automatically via context.
39
+ */
40
+ export type UseThirdwebSmartAccountParams = ThirdwebSmartAccountConfig;
package/dist/types.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@getpara/aa-thirdweb",
3
+ "version": "2.16.0",
4
+ "description": "Thirdweb smart account integration for Para",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "package.json"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
21
+ "typegen": "tsc --emitDeclarationOnly --outDir dist",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "dependencies": {
25
+ "@getpara/viem-v2-integration": "2.16.0",
26
+ "thirdweb": "^5.118.2"
27
+ },
28
+ "peerDependencies": {
29
+ "viem": ">=2.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "typescript": "^5.8.3"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "gitHead": "fbe96a062b308d04105213378c12c38ee973c798"
38
+ }