@getpara/viem-v2-integration 2.16.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.
@@ -32,6 +32,8 @@ const SMART_ACCOUNT_ERROR_CODES = [
32
32
  "AUTHORIZATION_FAILED",
33
33
  "DELEGATION_CONFLICT",
34
34
  "AUTHORIZATION_NONCE_MISMATCH",
35
+ // Chain
36
+ "CHAIN_MISMATCH",
35
37
  // Transaction Submission
36
38
  "BUNDLER_REJECTED",
37
39
  "GAS_ESTIMATION_FAILED",
@@ -57,7 +59,8 @@ class SmartAccountError extends Error {
57
59
  }
58
60
  }
59
61
  function classifyProviderError(error) {
60
- const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
62
+ var _a;
63
+ const msg = (error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error)).toLowerCase();
61
64
  if (msg.includes("rate limit") || msg.includes("429")) {
62
65
  return "PROVIDER_RATE_LIMITED";
63
66
  }
@@ -85,11 +88,12 @@ function classifyProviderError(error) {
85
88
  return "PROVIDER_ERROR";
86
89
  }
87
90
  function wrapProviderError(error, provider) {
91
+ var _a;
88
92
  if (error instanceof SmartAccountError) {
89
93
  return error;
90
94
  }
91
95
  const code = classifyProviderError(error);
92
- const message = error instanceof Error ? error.message : String(error);
96
+ const message = error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error);
93
97
  return new SmartAccountError({ code, message, provider, cause: error });
94
98
  }
95
99
  // Annotate the CommonJS export names for ESM import in node:
@@ -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
+ });
@@ -1,7 +1,24 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
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));
5
22
  var __export = (target, all) => {
6
23
  for (var name in all)
7
24
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,25 +32,136 @@ var __copyProps = (to, from, except, desc) => {
15
32
  return to;
16
33
  };
17
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
+ };
18
55
  var utils_exports = {};
19
56
  __export(utils_exports, {
57
+ assertAccountAddress: () => assertAccountAddress,
58
+ ensureExternalWalletChain: () => ensureExternalWalletChain,
59
+ isExternalWallet: () => isExternalWallet,
60
+ rejectExternalWallet7702: () => rejectExternalWallet7702,
61
+ resolveExternalSigner: () => resolveExternalSigner,
62
+ resolveSigner: () => resolveSigner,
20
63
  resolveWalletIdentifier: () => resolveWalletIdentifier
21
64
  });
22
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
+ }
23
118
  function resolveWalletIdentifier(para, params) {
24
- var _a;
25
119
  try {
26
120
  if (params.address) {
27
- const wallet = para.findWalletByAddress(params.address, { type: ["EVM"] });
28
- return wallet.address;
121
+ const wallet2 = para.findWalletByAddress(params.address, { type: ["EVM"] });
122
+ if (wallet2.isExternal) return null;
123
+ return wallet2.address;
29
124
  }
30
125
  const validId = para.findWalletId(params.walletId, { type: ["EVM"] });
31
- return (_a = para.wallets[validId]) == null ? void 0 : _a.address;
126
+ const wallet = para.wallets[validId];
127
+ if (!wallet || wallet.isExternal) return null;
128
+ return wallet.address;
32
129
  } catch (e) {
33
130
  return null;
34
131
  }
35
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
+ }
36
158
  // Annotate the CommonJS export names for ESM import in node:
37
159
  0 && (module.exports = {
160
+ assertAccountAddress,
161
+ ensureExternalWalletChain,
162
+ isExternalWallet,
163
+ rejectExternalWallet7702,
164
+ resolveExternalSigner,
165
+ resolveSigner,
38
166
  resolveWalletIdentifier
39
167
  });
package/dist/cjs/index.js CHANGED
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
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
5
  var __copyProps = (to, from, except, desc) => {
10
6
  if (from && typeof from === "object" || typeof from === "function") {
11
7
  for (let key of __getOwnPropNames(from))
@@ -17,18 +13,9 @@ var __copyProps = (to, from, except, desc) => {
17
13
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
15
  var src_exports = {};
20
- __export(src_exports, {
21
- resolveWalletIdentifier: () => import_utils.resolveWalletIdentifier
22
- });
23
16
  module.exports = __toCommonJS(src_exports);
24
17
  __reExport(src_exports, require("./viemWalletClient.js"), module.exports);
25
- __reExport(src_exports, require("./aa/types.js"), module.exports);
26
- __reExport(src_exports, require("./aa/errors.js"), module.exports);
27
- var import_utils = require("./aa/utils.js");
28
18
  // Annotate the CommonJS export names for ESM import in node:
29
19
  0 && (module.exports = {
30
- resolveWalletIdentifier,
31
- ...require("./viemWalletClient.js"),
32
- ...require("./aa/types.js"),
33
- ...require("./aa/errors.js")
20
+ ...require("./viemWalletClient.js")
34
21
  });
@@ -1,4 +1,4 @@
1
- import "../chunk-HJO26HIQ.js";
1
+ import "../chunk-6FNC3XMI.js";
2
2
  const SMART_ACCOUNT_ERROR_CODES = [
3
3
  "MISSING_CHAIN",
4
4
  "MISSING_ACCOUNT_ADDRESS",
@@ -8,6 +8,8 @@ const SMART_ACCOUNT_ERROR_CODES = [
8
8
  "AUTHORIZATION_FAILED",
9
9
  "DELEGATION_CONFLICT",
10
10
  "AUTHORIZATION_NONCE_MISMATCH",
11
+ // Chain
12
+ "CHAIN_MISMATCH",
11
13
  // Transaction Submission
12
14
  "BUNDLER_REJECTED",
13
15
  "GAS_ESTIMATION_FAILED",
@@ -33,7 +35,8 @@ class SmartAccountError extends Error {
33
35
  }
34
36
  }
35
37
  function classifyProviderError(error) {
36
- const msg = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
38
+ var _a;
39
+ const msg = (error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error)).toLowerCase();
37
40
  if (msg.includes("rate limit") || msg.includes("429")) {
38
41
  return "PROVIDER_RATE_LIMITED";
39
42
  }
@@ -61,11 +64,12 @@ function classifyProviderError(error) {
61
64
  return "PROVIDER_ERROR";
62
65
  }
63
66
  function wrapProviderError(error, provider) {
67
+ var _a;
64
68
  if (error instanceof SmartAccountError) {
65
69
  return error;
66
70
  }
67
71
  const code = classifyProviderError(error);
68
- const message = error instanceof Error ? error.message : String(error);
72
+ const message = error instanceof Error ? (_a = error.message) != null ? _a : String(error) : String(error);
69
73
  return new SmartAccountError({ code, message, provider, cause: error });
70
74
  }
71
75
  export {
@@ -0,0 +1,3 @@
1
+ export * from "./types.js";
2
+ export * from "./errors.js";
3
+ export * from "./utils.js";
@@ -1,4 +1,4 @@
1
- import "../chunk-HJO26HIQ.js";
1
+ import "../chunk-6FNC3XMI.js";
2
2
  const SMART_ACCOUNT_PROVIDERS = [
3
3
  "ALCHEMY",
4
4
  "ZERODEV",
@@ -1,17 +1,106 @@
1
- import "../chunk-HJO26HIQ.js";
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
+ }
2
58
  function resolveWalletIdentifier(para, params) {
3
- var _a;
4
59
  try {
5
60
  if (params.address) {
6
- const wallet = para.findWalletByAddress(params.address, { type: ["EVM"] });
7
- return wallet.address;
61
+ const wallet2 = para.findWalletByAddress(params.address, { type: ["EVM"] });
62
+ if (wallet2.isExternal) return null;
63
+ return wallet2.address;
8
64
  }
9
65
  const validId = para.findWalletId(params.walletId, { type: ["EVM"] });
10
- return (_a = para.wallets[validId]) == null ? void 0 : _a.address;
66
+ const wallet = para.wallets[validId];
67
+ if (!wallet || wallet.isExternal) return null;
68
+ return wallet.address;
11
69
  } catch (e) {
12
70
  return null;
13
71
  }
14
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
+ }
15
98
  export {
99
+ assertAccountAddress,
100
+ ensureExternalWalletChain,
101
+ isExternalWallet,
102
+ rejectExternalWallet7702,
103
+ resolveExternalSigner,
104
+ resolveSigner,
16
105
  resolveWalletIdentifier
17
106
  };
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  var __async = (__this, __arguments, generator) => {
18
21
  return new Promise((resolve, reject) => {
19
22
  var fulfilled = (value) => {
@@ -37,5 +40,6 @@ var __async = (__this, __arguments, generator) => {
37
40
 
38
41
  export {
39
42
  __spreadValues,
43
+ __spreadProps,
40
44
  __async
41
45
  };
package/dist/esm/index.js CHANGED
@@ -1,8 +1 @@
1
- import "./chunk-HJO26HIQ.js";
2
1
  export * from "./viemWalletClient.js";
3
- export * from "./aa/types.js";
4
- export * from "./aa/errors.js";
5
- import { resolveWalletIdentifier } from "./aa/utils.js";
6
- export {
7
- resolveWalletIdentifier
8
- };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __async,
3
3
  __spreadValues
4
- } from "./chunk-HJO26HIQ.js";
4
+ } from "./chunk-6FNC3XMI.js";
5
5
  import {
6
6
  createWalletClient,
7
7
  hashMessage,
@@ -1,5 +1,5 @@
1
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", "BUNDLER_REJECTED", "GAS_ESTIMATION_FAILED", "SPONSORSHIP_DENIED", "RECEIPT_TIMEOUT", "TRANSACTION_REVERTED", "RECEIPT_MISSING", "PROVIDER_UNREACHABLE", "PROVIDER_RATE_LIMITED", "PROVIDER_ERROR"];
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
3
  export type SmartAccountErrorCode = (typeof SMART_ACCOUNT_ERROR_CODES)[number];
4
4
  export declare class SmartAccountError extends Error {
5
5
  readonly code: SmartAccountErrorCode;
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export * from './utils.js';
@@ -1,5 +1,5 @@
1
1
  import type ParaCore from '@getpara/core-sdk';
2
- import type { Chain, Hex, LocalAccount, TransactionReceipt } from 'viem';
2
+ import type { Chain, Hex, LocalAccount, TransactionReceipt, WalletClient } from 'viem';
3
3
  /**
4
4
  * Base configuration shared by all smart account implementations.
5
5
  */
@@ -8,6 +8,29 @@ export interface BaseSmartAccountConfig {
8
8
  address?: Hex;
9
9
  /** Optional wallet ID to use. Alternative to `address` for selecting a specific wallet. */
10
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;
11
34
  }
12
35
  /**
13
36
  * Configuration for smart accounts that require chain configuration.
@@ -111,43 +134,19 @@ interface SmartAccountBase<TClient = any> {
111
134
  provider: SmartAccountProvider;
112
135
  /**
113
136
  * Send a single transaction and wait for confirmation.
114
- *
115
- * @param params - Transaction parameters
116
- * @param options - Provider-specific options (paymaster config, gas settings, etc.)
117
- * @returns viem TransactionReceipt — full on-chain receipt with logs, gasUsed, status, etc.
118
137
  */
119
138
  sendTransaction(params: TransactionParams, options?: unknown): Promise<TransactionReceipt>;
120
139
  /**
121
140
  * Send multiple transactions in a batch and wait for confirmation.
122
- *
123
- * @param calls - Array of transaction calls
124
- * @param options - Provider-specific options (paymaster config, gas settings, etc.)
125
- * @returns viem TransactionReceipt — full on-chain receipt with logs, gasUsed, status, etc.
126
141
  */
127
142
  sendBatchTransaction(calls: TransactionParams[], options?: unknown): Promise<TransactionReceipt>;
128
143
  /**
129
144
  * The underlying provider-specific client
130
- * Use this to access provider-specific features beyond the unified interface
131
- *
132
- * @example
133
- * ```typescript
134
- * // Access provider-specific features
135
- * const nativeClient = smartAccount.client;
136
- * await nativeClient.simulateUserOperation({ ... });
137
- * ```
138
145
  */
139
146
  client: TClient;
140
147
  }
141
148
  /**
142
149
  * EIP-4337 smart account (user operations via bundler)
143
- *
144
- * Providers: Alchemy, ZeroDev, Biconomy, Pimlico, Safe, Thirdweb, Rhinestone, CDP
145
- *
146
- * @example
147
- * ```typescript
148
- * const account: SmartAccount4337 = createPimlicoSmartAccount(client);
149
- * await account.sendTransaction({ to, value, data });
150
- * ```
151
150
  */
152
151
  export interface SmartAccount4337<TClient = any> extends SmartAccountBase<TClient> {
153
152
  /** Discriminant — always `'4337'` for EIP-4337 accounts. */
@@ -155,15 +154,6 @@ export interface SmartAccount4337<TClient = any> extends SmartAccountBase<TClien
155
154
  }
156
155
  /**
157
156
  * EIP-7702 smart account (EOA delegation)
158
- *
159
- * Providers: Alchemy, ZeroDev, Biconomy, Pimlico, Gelato, Porto, Thirdweb
160
- *
161
- * @example
162
- * ```typescript
163
- * const account: SmartAccount7702 = createPortoSmartAccount(provider);
164
- * // smartAccountAddress === signer.address for 7702
165
- * // delegationAddress is the contract the EOA delegates to
166
- * ```
167
157
  */
168
158
  export interface SmartAccount7702<TClient = any> extends SmartAccountBase<TClient> {
169
159
  /** Discriminant — always `'7702'` for EIP-7702 accounts. */
@@ -177,20 +167,6 @@ export interface SmartAccount7702<TClient = any> extends SmartAccountBase<TClien
177
167
  }
178
168
  /**
179
169
  * Unified smart account type - discriminated union
180
- *
181
- * Use TypeScript's control flow analysis to narrow types based on the `mode` field:
182
- *
183
- * @example
184
- * ```typescript
185
- * function handleAccount(account: SmartAccount) {
186
- * if (account.mode === '7702') {
187
- * // TypeScript knows this is SmartAccount7702
188
- * console.log('Delegation:', account.delegationAddress);
189
- * }
190
- * // Both modes share sendTransaction, signer, chain
191
- * await account.sendTransaction({ to, value, data });
192
- * }
193
- * ```
194
170
  */
195
171
  export type SmartAccount<TClient = any> = SmartAccount4337<TClient> | SmartAccount7702<TClient>;
196
172
  /**
@@ -1,7 +1,29 @@
1
1
  import type ParaCore from '@getpara/core-sdk';
2
- import type { Hex } from 'viem';
2
+ import type { Chain, Hex, LocalAccount, WalletClient } from 'viem';
3
+ import type { BaseSmartAccountConfig, SmartAccountProvider } from './types.js';
3
4
  /**
4
- * Resolves an EVM wallet address from params. Returns `null` if no matching wallet exists.
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`).
5
27
  *
6
28
  * Priority:
7
29
  * 1. Explicit `address` — validated as an EVM wallet via `findWalletByAddress()`
@@ -12,3 +34,29 @@ export declare function resolveWalletIdentifier(para: ParaCore, params: {
12
34
  address?: Hex;
13
35
  walletId?: string;
14
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;
@@ -1,4 +1 @@
1
1
  export * from './viemWalletClient.js';
2
- export * from './aa/types.js';
3
- export * from './aa/errors.js';
4
- export { resolveWalletIdentifier } from './aa/utils.js';
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@getpara/viem-v2-integration",
3
- "version": "2.16.0",
3
+ "version": "2.17.0",
4
4
  "dependencies": {
5
- "@getpara/core-sdk": "2.16.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": "fbe96a062b308d04105213378c12c38ee973c798",
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
  }