@getpara/viem-v2-integration 2.15.0 → 2.17.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,105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var errors_exports = {};
19
+ __export(errors_exports, {
20
+ SMART_ACCOUNT_ERROR_CODES: () => SMART_ACCOUNT_ERROR_CODES,
21
+ SmartAccountError: () => SmartAccountError,
22
+ classifyProviderError: () => classifyProviderError,
23
+ wrapProviderError: () => wrapProviderError
24
+ });
25
+ module.exports = __toCommonJS(errors_exports);
26
+ const SMART_ACCOUNT_ERROR_CODES = [
27
+ "MISSING_CHAIN",
28
+ "MISSING_ACCOUNT_ADDRESS",
29
+ "MISSING_API_KEY",
30
+ "INVALID_CONFIG",
31
+ // Authorization (7702)
32
+ "AUTHORIZATION_FAILED",
33
+ "DELEGATION_CONFLICT",
34
+ "AUTHORIZATION_NONCE_MISMATCH",
35
+ // Chain
36
+ "CHAIN_MISMATCH",
37
+ // Transaction Submission
38
+ "BUNDLER_REJECTED",
39
+ "GAS_ESTIMATION_FAILED",
40
+ "SPONSORSHIP_DENIED",
41
+ // Transaction Receipt
42
+ "RECEIPT_TIMEOUT",
43
+ "TRANSACTION_REVERTED",
44
+ "RECEIPT_MISSING",
45
+ // Provider
46
+ "PROVIDER_UNREACHABLE",
47
+ "PROVIDER_RATE_LIMITED",
48
+ "PROVIDER_ERROR"
49
+ ];
50
+ class SmartAccountError extends Error {
51
+ constructor(params) {
52
+ super(params.message);
53
+ this.name = "SmartAccountError";
54
+ this.code = params.code;
55
+ this.provider = params.provider;
56
+ if (params.cause !== void 0) {
57
+ this.cause = params.cause;
58
+ }
59
+ }
60
+ }
61
+ function classifyProviderError(error) {
62
+ var _a;
63
+ const msg = (error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error)).toLowerCase();
64
+ if (msg.includes("rate limit") || msg.includes("429")) {
65
+ return "PROVIDER_RATE_LIMITED";
66
+ }
67
+ if (msg.includes("gas") && (msg.includes("estimate") || msg.includes("estimation"))) {
68
+ return "GAS_ESTIMATION_FAILED";
69
+ }
70
+ if (msg.includes("paymaster") || msg.includes("sponsor")) {
71
+ return "SPONSORSHIP_DENIED";
72
+ }
73
+ if (msg.includes("useroperation") && (msg.includes("reverted") || msg.includes("rejected") || msg.includes("failed"))) {
74
+ return "BUNDLER_REJECTED";
75
+ }
76
+ if (msg.includes("nonce") && msg.includes("authorization")) {
77
+ return "AUTHORIZATION_NONCE_MISMATCH";
78
+ }
79
+ if (msg.includes("nonce") || msg.includes("aa25") || msg.includes("aa10")) {
80
+ return "BUNDLER_REJECTED";
81
+ }
82
+ if (msg.includes("authorization") || msg.includes("delegation")) {
83
+ return "AUTHORIZATION_FAILED";
84
+ }
85
+ if (msg.includes("econnrefused") || msg.includes("fetch failed") || msg.includes("network") || msg.includes("timeout")) {
86
+ return "PROVIDER_UNREACHABLE";
87
+ }
88
+ return "PROVIDER_ERROR";
89
+ }
90
+ function wrapProviderError(error, provider) {
91
+ var _a;
92
+ if (error instanceof SmartAccountError) {
93
+ return error;
94
+ }
95
+ const code = classifyProviderError(error);
96
+ const message = error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error);
97
+ return new SmartAccountError({ code, message, provider, cause: error });
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ SMART_ACCOUNT_ERROR_CODES,
102
+ SmartAccountError,
103
+ classifyProviderError,
104
+ wrapProviderError
105
+ });
@@ -0,0 +1,25 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var aa_exports = {};
16
+ module.exports = __toCommonJS(aa_exports);
17
+ __reExport(aa_exports, require("./types.js"), module.exports);
18
+ __reExport(aa_exports, require("./errors.js"), module.exports);
19
+ __reExport(aa_exports, require("./utils.js"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./types.js"),
23
+ ...require("./errors.js"),
24
+ ...require("./utils.js")
25
+ });
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var types_exports = {};
19
+ __export(types_exports, {
20
+ SMART_ACCOUNT_PROVIDERS: () => SMART_ACCOUNT_PROVIDERS,
21
+ isSmartAccount4337: () => isSmartAccount4337,
22
+ isSmartAccount7702: () => isSmartAccount7702
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ const SMART_ACCOUNT_PROVIDERS = [
26
+ "ALCHEMY",
27
+ "ZERODEV",
28
+ "BICONOMY",
29
+ "GELATO",
30
+ "PIMLICO",
31
+ "SAFE",
32
+ "THIRDWEB",
33
+ "RHINESTONE",
34
+ "PORTO",
35
+ "CDP"
36
+ ];
37
+ function isSmartAccount7702(account) {
38
+ return account.mode === "7702";
39
+ }
40
+ function isSmartAccount4337(account) {
41
+ return account.mode === "4337";
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ SMART_ACCOUNT_PROVIDERS,
46
+ isSmartAccount4337,
47
+ isSmartAccount7702
48
+ });
@@ -0,0 +1,167 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var __async = (__this, __arguments, generator) => {
36
+ return new Promise((resolve, reject) => {
37
+ var fulfilled = (value) => {
38
+ try {
39
+ step(generator.next(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var rejected = (value) => {
45
+ try {
46
+ step(generator.throw(value));
47
+ } catch (e) {
48
+ reject(e);
49
+ }
50
+ };
51
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
52
+ step((generator = generator.apply(__this, __arguments)).next());
53
+ });
54
+ };
55
+ var utils_exports = {};
56
+ __export(utils_exports, {
57
+ assertAccountAddress: () => assertAccountAddress,
58
+ ensureExternalWalletChain: () => ensureExternalWalletChain,
59
+ isExternalWallet: () => isExternalWallet,
60
+ rejectExternalWallet7702: () => rejectExternalWallet7702,
61
+ resolveExternalSigner: () => resolveExternalSigner,
62
+ resolveSigner: () => resolveSigner,
63
+ resolveWalletIdentifier: () => resolveWalletIdentifier
64
+ });
65
+ module.exports = __toCommonJS(utils_exports);
66
+ var import_viemWalletClient = require("../viemWalletClient.js");
67
+ var import_errors = require("./errors.js");
68
+ function isExternalWallet(signer) {
69
+ return !!signer && typeof signer === "object" && "transport" in signer && "account" in signer;
70
+ }
71
+ function resolveExternalSigner(signer) {
72
+ if (!isExternalWallet(signer)) {
73
+ return signer;
74
+ }
75
+ const account = signer.account;
76
+ if (!(account == null ? void 0 : account.address)) {
77
+ throw new Error(
78
+ "[resolveExternalSigner] WalletClient must have an account set. Call `await walletClient.requestAddresses()` first, then pass the account."
79
+ );
80
+ }
81
+ return {
82
+ address: account.address,
83
+ publicKey: "0x",
84
+ source: "custom",
85
+ type: "local",
86
+ sign: (_0) => __async(this, [_0], function* ({ hash }) {
87
+ return signer.signMessage({ account: account.address, message: { raw: hash } });
88
+ }),
89
+ signMessage: (_0) => __async(this, [_0], function* ({ message }) {
90
+ return signer.signMessage({ account: account.address, message });
91
+ }),
92
+ signTransaction: (tx) => __async(this, null, function* () {
93
+ return signer.signTransaction(__spreadProps(__spreadValues({}, tx), { account }));
94
+ }),
95
+ signTypedData: (typedData) => __async(this, null, function* () {
96
+ return signer.signTypedData(__spreadProps(__spreadValues({}, typedData), { account: account.address }));
97
+ }),
98
+ signAuthorization: () => __async(this, null, function* () {
99
+ throw new Error(
100
+ "EIP-7702 account delegation (signAuthorization) is not supported with external wallets. External wallets add an EIP-191 prefix to all signatures, which is incompatible with the raw ecrecover required by EIP-7702. Use an embedded Para wallet for 7702 mode, or use 4337 mode which works with any wallet."
101
+ );
102
+ })
103
+ };
104
+ }
105
+ function ensureExternalWalletChain(signer, chain, provider) {
106
+ return __async(this, null, function* () {
107
+ if (!isExternalWallet(signer)) return;
108
+ const currentChainId = yield signer.getChainId();
109
+ if (currentChainId !== chain.id) {
110
+ throw new import_errors.SmartAccountError({
111
+ code: "CHAIN_MISMATCH",
112
+ message: `External wallet is on chain ${currentChainId} but smart account targets chain ${chain.id} (${chain.name}). Switch your wallet to the correct network before sending transactions.`,
113
+ provider
114
+ });
115
+ }
116
+ });
117
+ }
118
+ function resolveWalletIdentifier(para, params) {
119
+ try {
120
+ if (params.address) {
121
+ const wallet2 = para.findWalletByAddress(params.address, { type: ["EVM"] });
122
+ if (wallet2.isExternal) return null;
123
+ return wallet2.address;
124
+ }
125
+ const validId = para.findWalletId(params.walletId, { type: ["EVM"] });
126
+ const wallet = para.wallets[validId];
127
+ if (!wallet || wallet.isExternal) return null;
128
+ return wallet.address;
129
+ } catch (e) {
130
+ return null;
131
+ }
132
+ }
133
+ function resolveSigner(para, params) {
134
+ if (params.signer) {
135
+ return resolveExternalSigner(params.signer);
136
+ }
137
+ const walletAddress = resolveWalletIdentifier(para, params);
138
+ if (!walletAddress) return null;
139
+ return (0, import_viemWalletClient.createParaAccount)(para, walletAddress);
140
+ }
141
+ function rejectExternalWallet7702(signer, provider) {
142
+ if (!signer || !isExternalWallet(signer)) return;
143
+ throw new import_errors.SmartAccountError({
144
+ code: "INVALID_CONFIG",
145
+ message: "EIP-7702 mode is not supported with external wallets. External wallets add an EIP-191 prefix to all signatures, which is incompatible with the raw ecrecover required by EIP-7702 authorization. Use an embedded Para wallet for 7702 mode, or use 4337 mode which works with any wallet.",
146
+ provider
147
+ });
148
+ }
149
+ function assertAccountAddress(address, clientLabel, provider) {
150
+ if (!address) {
151
+ throw new import_errors.SmartAccountError({
152
+ code: "MISSING_ACCOUNT_ADDRESS",
153
+ message: `${clientLabel} did not return a smart account address. Verify your configuration.`,
154
+ provider
155
+ });
156
+ }
157
+ }
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ assertAccountAddress,
161
+ ensureExternalWalletChain,
162
+ isExternalWallet,
163
+ rejectExternalWallet7702,
164
+ resolveExternalSigner,
165
+ resolveSigner,
166
+ resolveWalletIdentifier
167
+ });
@@ -0,0 +1,80 @@
1
+ import "../chunk-6FNC3XMI.js";
2
+ const SMART_ACCOUNT_ERROR_CODES = [
3
+ "MISSING_CHAIN",
4
+ "MISSING_ACCOUNT_ADDRESS",
5
+ "MISSING_API_KEY",
6
+ "INVALID_CONFIG",
7
+ // Authorization (7702)
8
+ "AUTHORIZATION_FAILED",
9
+ "DELEGATION_CONFLICT",
10
+ "AUTHORIZATION_NONCE_MISMATCH",
11
+ // Chain
12
+ "CHAIN_MISMATCH",
13
+ // Transaction Submission
14
+ "BUNDLER_REJECTED",
15
+ "GAS_ESTIMATION_FAILED",
16
+ "SPONSORSHIP_DENIED",
17
+ // Transaction Receipt
18
+ "RECEIPT_TIMEOUT",
19
+ "TRANSACTION_REVERTED",
20
+ "RECEIPT_MISSING",
21
+ // Provider
22
+ "PROVIDER_UNREACHABLE",
23
+ "PROVIDER_RATE_LIMITED",
24
+ "PROVIDER_ERROR"
25
+ ];
26
+ class SmartAccountError extends Error {
27
+ constructor(params) {
28
+ super(params.message);
29
+ this.name = "SmartAccountError";
30
+ this.code = params.code;
31
+ this.provider = params.provider;
32
+ if (params.cause !== void 0) {
33
+ this.cause = params.cause;
34
+ }
35
+ }
36
+ }
37
+ function classifyProviderError(error) {
38
+ var _a;
39
+ const msg = (error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error)).toLowerCase();
40
+ if (msg.includes("rate limit") || msg.includes("429")) {
41
+ return "PROVIDER_RATE_LIMITED";
42
+ }
43
+ if (msg.includes("gas") && (msg.includes("estimate") || msg.includes("estimation"))) {
44
+ return "GAS_ESTIMATION_FAILED";
45
+ }
46
+ if (msg.includes("paymaster") || msg.includes("sponsor")) {
47
+ return "SPONSORSHIP_DENIED";
48
+ }
49
+ if (msg.includes("useroperation") && (msg.includes("reverted") || msg.includes("rejected") || msg.includes("failed"))) {
50
+ return "BUNDLER_REJECTED";
51
+ }
52
+ if (msg.includes("nonce") && msg.includes("authorization")) {
53
+ return "AUTHORIZATION_NONCE_MISMATCH";
54
+ }
55
+ if (msg.includes("nonce") || msg.includes("aa25") || msg.includes("aa10")) {
56
+ return "BUNDLER_REJECTED";
57
+ }
58
+ if (msg.includes("authorization") || msg.includes("delegation")) {
59
+ return "AUTHORIZATION_FAILED";
60
+ }
61
+ if (msg.includes("econnrefused") || msg.includes("fetch failed") || msg.includes("network") || msg.includes("timeout")) {
62
+ return "PROVIDER_UNREACHABLE";
63
+ }
64
+ return "PROVIDER_ERROR";
65
+ }
66
+ function wrapProviderError(error, provider) {
67
+ var _a;
68
+ if (error instanceof SmartAccountError) {
69
+ return error;
70
+ }
71
+ const code = classifyProviderError(error);
72
+ const message = error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error);
73
+ return new SmartAccountError({ code, message, provider, cause: error });
74
+ }
75
+ export {
76
+ SMART_ACCOUNT_ERROR_CODES,
77
+ SmartAccountError,
78
+ classifyProviderError,
79
+ wrapProviderError
80
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./types.js";
2
+ export * from "./errors.js";
3
+ export * from "./utils.js";
@@ -0,0 +1,24 @@
1
+ import "../chunk-6FNC3XMI.js";
2
+ const SMART_ACCOUNT_PROVIDERS = [
3
+ "ALCHEMY",
4
+ "ZERODEV",
5
+ "BICONOMY",
6
+ "GELATO",
7
+ "PIMLICO",
8
+ "SAFE",
9
+ "THIRDWEB",
10
+ "RHINESTONE",
11
+ "PORTO",
12
+ "CDP"
13
+ ];
14
+ function isSmartAccount7702(account) {
15
+ return account.mode === "7702";
16
+ }
17
+ function isSmartAccount4337(account) {
18
+ return account.mode === "4337";
19
+ }
20
+ export {
21
+ SMART_ACCOUNT_PROVIDERS,
22
+ isSmartAccount4337,
23
+ isSmartAccount7702
24
+ };
@@ -0,0 +1,106 @@
1
+ import {
2
+ __async,
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "../chunk-6FNC3XMI.js";
6
+ import { createParaAccount } from "../viemWalletClient.js";
7
+ import { SmartAccountError } from "./errors.js";
8
+ function isExternalWallet(signer) {
9
+ return !!signer && typeof signer === "object" && "transport" in signer && "account" in signer;
10
+ }
11
+ function resolveExternalSigner(signer) {
12
+ if (!isExternalWallet(signer)) {
13
+ return signer;
14
+ }
15
+ const account = signer.account;
16
+ if (!(account == null ? void 0 : account.address)) {
17
+ throw new Error(
18
+ "[resolveExternalSigner] WalletClient must have an account set. Call `await walletClient.requestAddresses()` first, then pass the account."
19
+ );
20
+ }
21
+ return {
22
+ address: account.address,
23
+ publicKey: "0x",
24
+ source: "custom",
25
+ type: "local",
26
+ sign: (_0) => __async(this, [_0], function* ({ hash }) {
27
+ return signer.signMessage({ account: account.address, message: { raw: hash } });
28
+ }),
29
+ signMessage: (_0) => __async(this, [_0], function* ({ message }) {
30
+ return signer.signMessage({ account: account.address, message });
31
+ }),
32
+ signTransaction: (tx) => __async(this, null, function* () {
33
+ return signer.signTransaction(__spreadProps(__spreadValues({}, tx), { account }));
34
+ }),
35
+ signTypedData: (typedData) => __async(this, null, function* () {
36
+ return signer.signTypedData(__spreadProps(__spreadValues({}, typedData), { account: account.address }));
37
+ }),
38
+ signAuthorization: () => __async(this, null, function* () {
39
+ throw new Error(
40
+ "EIP-7702 account delegation (signAuthorization) is not supported with external wallets. External wallets add an EIP-191 prefix to all signatures, which is incompatible with the raw ecrecover required by EIP-7702. Use an embedded Para wallet for 7702 mode, or use 4337 mode which works with any wallet."
41
+ );
42
+ })
43
+ };
44
+ }
45
+ function ensureExternalWalletChain(signer, chain, provider) {
46
+ return __async(this, null, function* () {
47
+ if (!isExternalWallet(signer)) return;
48
+ const currentChainId = yield signer.getChainId();
49
+ if (currentChainId !== chain.id) {
50
+ throw new SmartAccountError({
51
+ code: "CHAIN_MISMATCH",
52
+ message: `External wallet is on chain ${currentChainId} but smart account targets chain ${chain.id} (${chain.name}). Switch your wallet to the correct network before sending transactions.`,
53
+ provider
54
+ });
55
+ }
56
+ });
57
+ }
58
+ function resolveWalletIdentifier(para, params) {
59
+ try {
60
+ if (params.address) {
61
+ const wallet2 = para.findWalletByAddress(params.address, { type: ["EVM"] });
62
+ if (wallet2.isExternal) return null;
63
+ return wallet2.address;
64
+ }
65
+ const validId = para.findWalletId(params.walletId, { type: ["EVM"] });
66
+ const wallet = para.wallets[validId];
67
+ if (!wallet || wallet.isExternal) return null;
68
+ return wallet.address;
69
+ } catch (e) {
70
+ return null;
71
+ }
72
+ }
73
+ function resolveSigner(para, params) {
74
+ if (params.signer) {
75
+ return resolveExternalSigner(params.signer);
76
+ }
77
+ const walletAddress = resolveWalletIdentifier(para, params);
78
+ if (!walletAddress) return null;
79
+ return createParaAccount(para, walletAddress);
80
+ }
81
+ function rejectExternalWallet7702(signer, provider) {
82
+ if (!signer || !isExternalWallet(signer)) return;
83
+ throw new SmartAccountError({
84
+ code: "INVALID_CONFIG",
85
+ message: "EIP-7702 mode is not supported with external wallets. External wallets add an EIP-191 prefix to all signatures, which is incompatible with the raw ecrecover required by EIP-7702 authorization. Use an embedded Para wallet for 7702 mode, or use 4337 mode which works with any wallet.",
86
+ provider
87
+ });
88
+ }
89
+ function assertAccountAddress(address, clientLabel, provider) {
90
+ if (!address) {
91
+ throw new SmartAccountError({
92
+ code: "MISSING_ACCOUNT_ADDRESS",
93
+ message: `${clientLabel} did not return a smart account address. Verify your configuration.`,
94
+ provider
95
+ });
96
+ }
97
+ }
98
+ export {
99
+ assertAccountAddress,
100
+ ensureExternalWalletChain,
101
+ isExternalWallet,
102
+ rejectExternalWallet7702,
103
+ resolveExternalSigner,
104
+ resolveSigner,
105
+ resolveWalletIdentifier
106
+ };
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+
41
+ export {
42
+ __spreadValues,
43
+ __spreadProps,
44
+ __async
45
+ };
@@ -1,39 +1,7 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __async = (__this, __arguments, generator) => {
18
- return new Promise((resolve, reject) => {
19
- var fulfilled = (value) => {
20
- try {
21
- step(generator.next(value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- };
26
- var rejected = (value) => {
27
- try {
28
- step(generator.throw(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- };
33
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
- step((generator = generator.apply(__this, __arguments)).next());
35
- });
36
- };
1
+ import {
2
+ __async,
3
+ __spreadValues
4
+ } from "./chunk-6FNC3XMI.js";
37
5
  import {
38
6
  createWalletClient,
39
7
  hashMessage,
@@ -0,0 +1,22 @@
1
+ import type { SmartAccountProvider } from './types.js';
2
+ export declare const SMART_ACCOUNT_ERROR_CODES: readonly ["MISSING_CHAIN", "MISSING_ACCOUNT_ADDRESS", "MISSING_API_KEY", "INVALID_CONFIG", "AUTHORIZATION_FAILED", "DELEGATION_CONFLICT", "AUTHORIZATION_NONCE_MISMATCH", "CHAIN_MISMATCH", "BUNDLER_REJECTED", "GAS_ESTIMATION_FAILED", "SPONSORSHIP_DENIED", "RECEIPT_TIMEOUT", "TRANSACTION_REVERTED", "RECEIPT_MISSING", "PROVIDER_UNREACHABLE", "PROVIDER_RATE_LIMITED", "PROVIDER_ERROR"];
3
+ export type SmartAccountErrorCode = (typeof SMART_ACCOUNT_ERROR_CODES)[number];
4
+ export declare class SmartAccountError extends Error {
5
+ readonly code: SmartAccountErrorCode;
6
+ readonly provider: SmartAccountProvider;
7
+ constructor(params: {
8
+ code: SmartAccountErrorCode;
9
+ message: string;
10
+ provider: SmartAccountProvider;
11
+ cause?: unknown;
12
+ });
13
+ }
14
+ /**
15
+ * Classifies an unknown provider error into a SmartAccountErrorCode.
16
+ * Inspects the error message for common patterns across AA providers.
17
+ */
18
+ export declare function classifyProviderError(error: unknown): SmartAccountErrorCode;
19
+ /**
20
+ * Wraps an unknown error thrown by a provider SDK into a SmartAccountError.
21
+ */
22
+ export declare function wrapProviderError(error: unknown, provider: SmartAccountProvider): SmartAccountError;
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export * from './utils.js';
@@ -0,0 +1,179 @@
1
+ import type ParaCore from '@getpara/core-sdk';
2
+ import type { Chain, Hex, LocalAccount, TransactionReceipt, WalletClient } from 'viem';
3
+ /**
4
+ * Base configuration shared by all smart account implementations.
5
+ */
6
+ export interface BaseSmartAccountConfig {
7
+ /** Optional wallet address to use. If none is provided, the first EVM wallet will be used. */
8
+ address?: Hex;
9
+ /** Optional wallet ID to use. Alternative to `address` for selecting a specific wallet. */
10
+ walletId?: string;
11
+ /**
12
+ * External signer — use when signing with a non-Para embedded wallet (e.g. MetaMask, Coinbase Wallet).
13
+ *
14
+ * When provided, Para's embedded MPC signing is bypassed entirely. The signer's address is used
15
+ * as the smart account owner instead of a Para wallet. `para.signMessage` is never called.
16
+ *
17
+ * Accepts either a viem `LocalAccount` or a connected `WalletClient` (e.g. from `createWalletClient`
18
+ * with `custom(window.ethereum)`). If a `WalletClient` is passed, its account must be set.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // MetaMask via viem
23
+ * const metamask = createWalletClient({ transport: custom(window.ethereum), chain });
24
+ * await metamask.requestAddresses(); // prompt MetaMask connection
25
+ * const [address] = await metamask.getAddresses();
26
+ *
27
+ * useAlchemySmartAccount({ apiKey, chain, signer: metamask });
28
+ * // or from an external wallet connector:
29
+ * const { walletClient } = useExternalWallet();
30
+ * useAlchemySmartAccount({ apiKey, chain, signer: walletClient });
31
+ * ```
32
+ */
33
+ signer?: LocalAccount | WalletClient;
34
+ }
35
+ /**
36
+ * Configuration for smart accounts that require chain configuration.
37
+ */
38
+ export interface ChainBasedSmartAccountConfig extends BaseSmartAccountConfig {
39
+ /** Target blockchain chain */
40
+ chain: Chain;
41
+ /** RPC URL for the chain. If not provided, defaults to the chain's built-in public RPC. */
42
+ rpcUrl?: string;
43
+ }
44
+ /**
45
+ * Configuration for smart accounts with API key authentication.
46
+ */
47
+ export interface ApiKeySmartAccountConfig extends ChainBasedSmartAccountConfig {
48
+ /** API key for the service */
49
+ apiKey: string;
50
+ }
51
+ /**
52
+ * Configuration for smart accounts with paymaster support.
53
+ */
54
+ export interface PaymasterSmartAccountConfig extends ChainBasedSmartAccountConfig {
55
+ /** Optional bundler RPC URL */
56
+ bundlerUrl?: string;
57
+ /** Optional paymaster RPC URL for gas sponsorship */
58
+ paymasterUrl?: string;
59
+ }
60
+ /**
61
+ * Adds `para: ParaCore` to a config type to produce the full action params.
62
+ */
63
+ export type CreateSmartAccountParams<T extends BaseSmartAccountConfig> = T & {
64
+ /** Para SDK instance */
65
+ para: ParaCore;
66
+ };
67
+ /**
68
+ * Smart account mode — the two execution models supported by AA providers.
69
+ * - '4337': EIP-4337 UserOperations via bundler
70
+ * - '7702': EIP-7702 EOA delegation (type 4 transactions)
71
+ */
72
+ export type SmartAccountMode = '4337' | '7702';
73
+ /**
74
+ * Maps a mode literal to the corresponding SmartAccount type.
75
+ * When mode is the full union or undefined, returns the union.
76
+ */
77
+ export type SmartAccountForMode<TMode extends SmartAccountMode | undefined, TClient = any> = TMode extends '7702' ? SmartAccount7702<TClient> : TMode extends '4337' ? SmartAccount4337<TClient> : SmartAccount<TClient>;
78
+ /**
79
+ * Mixin for params that support choosing between 4337 and 7702 execution modes.
80
+ */
81
+ export interface SmartAccountModeParam {
82
+ /**
83
+ * Account mode: EIP-4337 (bundler) or EIP-7702 (EOA delegation)
84
+ * @default '4337'
85
+ */
86
+ mode?: SmartAccountMode;
87
+ }
88
+ /**
89
+ * All supported AA provider names.
90
+ */
91
+ export declare const SMART_ACCOUNT_PROVIDERS: readonly ["ALCHEMY", "ZERODEV", "BICONOMY", "GELATO", "PIMLICO", "SAFE", "THIRDWEB", "RHINESTONE", "PORTO", "CDP"];
92
+ export type SmartAccountProvider = (typeof SMART_ACCOUNT_PROVIDERS)[number];
93
+ /**
94
+ * Transaction parameters
95
+ */
96
+ export interface TransactionParams {
97
+ /** Recipient address */
98
+ to: Hex;
99
+ /** Amount in wei. Use viem's `parseEther('0.1')` to convert from ETH. */
100
+ value?: bigint;
101
+ /** Encoded contract call data. Use viem's `encodeFunctionData()` to encode. */
102
+ data?: Hex;
103
+ }
104
+ /**
105
+ * Re-export viem's TransactionReceipt as the standard return type.
106
+ * All providers return a full on-chain receipt with logs, gasUsed, etc.
107
+ */
108
+ export type { TransactionReceipt } from 'viem';
109
+ /**
110
+ * Base smart account interface with shared functionality
111
+ * This contains methods available on ALL account types
112
+ */
113
+ interface SmartAccountBase<TClient = any> {
114
+ /**
115
+ * The smart account address — where transactions originate from on-chain.
116
+ * - EIP-4337: Counterfactual smart account address (different from signer EOA)
117
+ * - EIP-7702: EOA address (same as signer.address)
118
+ */
119
+ smartAccountAddress: Hex;
120
+ /**
121
+ * The Para viem LocalAccount that signs operations for this smart account.
122
+ * Provides signMessage, signTypedData, signTransaction, and signAuthorization.
123
+ * For 4337, signer.address differs from `smartAccountAddress` (signer EOA vs smart account).
124
+ * For 7702, signer.address equals `smartAccountAddress`.
125
+ */
126
+ signer: LocalAccount;
127
+ /**
128
+ * Chain this account is configured for.
129
+ */
130
+ chain: Chain;
131
+ /**
132
+ * Provider name
133
+ */
134
+ provider: SmartAccountProvider;
135
+ /**
136
+ * Send a single transaction and wait for confirmation.
137
+ */
138
+ sendTransaction(params: TransactionParams, options?: unknown): Promise<TransactionReceipt>;
139
+ /**
140
+ * Send multiple transactions in a batch and wait for confirmation.
141
+ */
142
+ sendBatchTransaction(calls: TransactionParams[], options?: unknown): Promise<TransactionReceipt>;
143
+ /**
144
+ * The underlying provider-specific client
145
+ */
146
+ client: TClient;
147
+ }
148
+ /**
149
+ * EIP-4337 smart account (user operations via bundler)
150
+ */
151
+ export interface SmartAccount4337<TClient = any> extends SmartAccountBase<TClient> {
152
+ /** Discriminant — always `'4337'` for EIP-4337 accounts. */
153
+ mode: '4337';
154
+ }
155
+ /**
156
+ * EIP-7702 smart account (EOA delegation)
157
+ */
158
+ export interface SmartAccount7702<TClient = any> extends SmartAccountBase<TClient> {
159
+ /** Discriminant — always `'7702'` for EIP-7702 accounts. */
160
+ mode: '7702';
161
+ /**
162
+ * The smart contract address the EOA delegates execution to.
163
+ * Each provider uses a different delegation contract.
164
+ * Undefined if the provider handles delegation internally.
165
+ */
166
+ delegationAddress?: Hex;
167
+ }
168
+ /**
169
+ * Unified smart account type - discriminated union
170
+ */
171
+ export type SmartAccount<TClient = any> = SmartAccount4337<TClient> | SmartAccount7702<TClient>;
172
+ /**
173
+ * Type guard to check if account supports EIP-7702
174
+ */
175
+ export declare function isSmartAccount7702<TClient = any>(account: SmartAccount<TClient>): account is SmartAccount7702<TClient>;
176
+ /**
177
+ * Type guard to check if account supports EIP-4337
178
+ */
179
+ export declare function isSmartAccount4337<TClient = any>(account: SmartAccount<TClient>): account is SmartAccount4337<TClient>;
@@ -0,0 +1,62 @@
1
+ import type ParaCore from '@getpara/core-sdk';
2
+ import type { Chain, Hex, LocalAccount, WalletClient } from 'viem';
3
+ import type { BaseSmartAccountConfig, SmartAccountProvider } from './types.js';
4
+ /**
5
+ * Returns true if the signer is a WalletClient (external browser wallet).
6
+ * Used to detect external wallets before mode-specific checks.
7
+ */
8
+ export declare function isExternalWallet(signer: unknown): signer is WalletClient;
9
+ /**
10
+ * Normalizes a `signer` param (LocalAccount | WalletClient) to a LocalAccount.
11
+ *
12
+ * - If it's already a `LocalAccount` (`type === 'local'`), returns it as-is.
13
+ * - If it's a `WalletClient`, wraps its signing methods into a LocalAccount shape.
14
+ * The WalletClient must have an `account` set.
15
+ */
16
+ export declare function resolveExternalSigner(signer: LocalAccount | WalletClient): LocalAccount;
17
+ /**
18
+ * Verifies an external wallet (WalletClient) is on the target chain.
19
+ * Throws a `SmartAccountError` with code `CHAIN_MISMATCH` if the wallet is on a different chain.
20
+ * No-op if the signer is not a WalletClient.
21
+ */
22
+ export declare function ensureExternalWalletChain(signer: unknown, chain: Chain, provider: SmartAccountProvider): Promise<void>;
23
+ /**
24
+ * Resolves an EVM **embedded** wallet address from params. Returns `null` if no matching
25
+ * wallet exists or if the matched wallet is external (external wallets lack MPC share
26
+ * data and cannot be used with `createParaAccount`).
27
+ *
28
+ * Priority:
29
+ * 1. Explicit `address` — validated as an EVM wallet via `findWalletByAddress()`
30
+ * 2. `walletId` — validated via `findWalletId()` and resolved to address
31
+ * 3. Neither — picks the first available EVM wallet via `findWalletId()`
32
+ */
33
+ export declare function resolveWalletIdentifier(para: ParaCore, params: {
34
+ address?: Hex;
35
+ walletId?: string;
36
+ }): Hex | null;
37
+ /**
38
+ * Resolves a viem LocalAccount signer from the action params.
39
+ *
40
+ * - If `params.signer` is a `LocalAccount`, returns it directly.
41
+ * - If `params.signer` is a `WalletClient`, wraps it via `resolveExternalSigner`.
42
+ * - If no signer is provided, resolves an embedded Para wallet via `resolveWalletIdentifier`
43
+ * and creates a `LocalAccount` via `createParaAccount`.
44
+ *
45
+ * Returns `null` when no embedded wallet is found (callers should return `null` to the user).
46
+ */
47
+ export declare function resolveSigner(para: ParaCore, params: BaseSmartAccountConfig): LocalAccount | null;
48
+ /**
49
+ * Throws a `SmartAccountError` if an external wallet signer is used with EIP-7702 mode.
50
+ * 7702 requires raw `signAuthorization` which external wallets cannot provide.
51
+ *
52
+ * Call at the top of dual-mode action functions when `mode === '7702'`.
53
+ * No-op if signer is undefined or a LocalAccount.
54
+ */
55
+ export declare function rejectExternalWallet7702(signer: LocalAccount | WalletClient | undefined, provider: SmartAccountProvider): void;
56
+ /**
57
+ * Asserts that a smart account address was resolved.
58
+ * Throws a `SmartAccountError` with code `MISSING_ACCOUNT_ADDRESS` if the address is falsy.
59
+ *
60
+ * Use after creating the provider-specific client to ensure it produced an account.
61
+ */
62
+ export declare function assertAccountAddress(address: Hex | undefined, clientLabel: string, provider: SmartAccountProvider): asserts address is Hex;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@getpara/viem-v2-integration",
3
- "version": "2.15.0",
3
+ "version": "2.17.0",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "2.15.0"
5
+ "@getpara/core-sdk": "2.17.0"
6
6
  },
7
7
  "devDependencies": {
8
8
  "typescript": "^5.8.3",
@@ -13,17 +13,22 @@
13
13
  "types": "./dist/types/index.d.ts",
14
14
  "import": "./dist/esm/index.js",
15
15
  "require": "./dist/cjs/index.js"
16
+ },
17
+ "./aa": {
18
+ "types": "./dist/types/aa/index.d.ts",
19
+ "import": "./dist/esm/aa/index.js",
20
+ "require": "./dist/cjs/aa/index.js"
16
21
  }
17
22
  },
18
23
  "files": [
19
24
  "dist",
20
25
  "package.json"
21
26
  ],
22
- "gitHead": "9cecc178e975a44d8ed4b03f46aeb57ddcb7a152",
27
+ "gitHead": "3ed1f835b97ae720f1ac747611296e3b86f61138",
23
28
  "main": "dist/cjs/index.js",
24
29
  "module": "dist/esm/index.js",
25
30
  "peerDependencies": {
26
- "viem": "2.x"
31
+ "viem": "^2.39.0"
27
32
  },
28
33
  "scripts": {
29
34
  "build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
@@ -34,5 +39,12 @@
34
39
  },
35
40
  "sideEffects": false,
36
41
  "types": "dist/types/index.d.ts",
42
+ "typesVersions": {
43
+ "*": {
44
+ "aa": [
45
+ "dist/types/aa/index.d.ts"
46
+ ]
47
+ }
48
+ },
37
49
  "typings": "dist/types/index.d.ts"
38
50
  }