@getpara/viem-v2-integration 2.21.0 → 2.22.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.
package/dist/cjs/aa/utils.js
CHANGED
|
@@ -136,7 +136,7 @@ function resolveSigner(para, params) {
|
|
|
136
136
|
}
|
|
137
137
|
const walletAddress = resolveWalletIdentifier(para, params);
|
|
138
138
|
if (!walletAddress) return null;
|
|
139
|
-
return (0, import_viemWalletClient.
|
|
139
|
+
return (0, import_viemWalletClient.createParaViemAccount)({ para, address: walletAddress });
|
|
140
140
|
}
|
|
141
141
|
function rejectExternalWallet7702(signer, provider) {
|
|
142
142
|
if (!signer || !isExternalWallet(signer)) return;
|
|
@@ -62,6 +62,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
62
62
|
var viemWalletClient_exports = {};
|
|
63
63
|
__export(viemWalletClient_exports, {
|
|
64
64
|
createParaAccount: () => createParaAccount,
|
|
65
|
+
createParaViemAccount: () => createParaViemAccount,
|
|
65
66
|
createParaViemClient: () => createParaViemClient,
|
|
66
67
|
getViemChain: () => getViemChain
|
|
67
68
|
});
|
|
@@ -69,16 +70,29 @@ module.exports = __toCommonJS(viemWalletClient_exports);
|
|
|
69
70
|
var import_viem = require("viem");
|
|
70
71
|
var import_utils = require("viem/utils");
|
|
71
72
|
var viemChains = __toESM(require("viem/chains"));
|
|
72
|
-
var import_core_sdk = require("@getpara/core-sdk");
|
|
73
|
+
var import_core_sdk = __toESM(require("@getpara/core-sdk"));
|
|
73
74
|
function normalizeSignature(rawSignature) {
|
|
74
75
|
const sigHex = `0x${rawSignature}`;
|
|
75
76
|
const parsed = (0, import_viem.parseSignature)(sigHex);
|
|
76
77
|
return (0, import_viem.serializeSignature)({ r: parsed.r, s: parsed.s, yParity: parsed.yParity });
|
|
77
78
|
}
|
|
78
|
-
function
|
|
79
|
+
function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
80
|
+
let para;
|
|
81
|
+
let resolvedAddress;
|
|
82
|
+
if (typeof paraOrOptions === "object" && "para" in paraOrOptions && !(paraOrOptions instanceof import_core_sdk.default)) {
|
|
83
|
+
para = paraOrOptions.para;
|
|
84
|
+
resolvedAddress = paraOrOptions.address;
|
|
85
|
+
if (!resolvedAddress && paraOrOptions.walletId) {
|
|
86
|
+
const w = para.wallets[paraOrOptions.walletId];
|
|
87
|
+
resolvedAddress = w == null ? void 0 : w.address;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
para = paraOrOptions;
|
|
91
|
+
resolvedAddress = walletAddress;
|
|
92
|
+
}
|
|
79
93
|
let currentWallet;
|
|
80
|
-
if (
|
|
81
|
-
currentWallet = para.findWalletByAddress(
|
|
94
|
+
if (resolvedAddress) {
|
|
95
|
+
currentWallet = para.findWalletByAddress(resolvedAddress, { type: ["EVM"] });
|
|
82
96
|
} else {
|
|
83
97
|
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
84
98
|
currentWallet = para.wallets[walletId];
|
|
@@ -174,14 +188,29 @@ function getViemChain(chainId) {
|
|
|
174
188
|
}
|
|
175
189
|
throw new Error(`chain with id ${chainId} not found`);
|
|
176
190
|
}
|
|
177
|
-
function createParaViemClient(
|
|
191
|
+
function createParaViemClient(paraOrOptions, params, opts) {
|
|
192
|
+
var _a, _b;
|
|
193
|
+
let para;
|
|
194
|
+
let config;
|
|
195
|
+
let noAccount;
|
|
196
|
+
if (typeof paraOrOptions === "object" && "para" in paraOrOptions && !(paraOrOptions instanceof import_core_sdk.default)) {
|
|
197
|
+
para = paraOrOptions.para;
|
|
198
|
+
config = paraOrOptions.walletClientConfig;
|
|
199
|
+
noAccount = (_a = paraOrOptions.noAccount) != null ? _a : false;
|
|
200
|
+
} else {
|
|
201
|
+
para = paraOrOptions;
|
|
202
|
+
config = params;
|
|
203
|
+
noAccount = (_b = opts == null ? void 0 : opts.noAccount) != null ? _b : false;
|
|
204
|
+
}
|
|
178
205
|
return (0, import_viem.createWalletClient)(__spreadValues({
|
|
179
|
-
account:
|
|
180
|
-
},
|
|
206
|
+
account: noAccount ? void 0 : createParaViemAccount({ para })
|
|
207
|
+
}, config));
|
|
181
208
|
}
|
|
209
|
+
const createParaAccount = createParaViemAccount;
|
|
182
210
|
// Annotate the CommonJS export names for ESM import in node:
|
|
183
211
|
0 && (module.exports = {
|
|
184
212
|
createParaAccount,
|
|
213
|
+
createParaViemAccount,
|
|
185
214
|
createParaViemClient,
|
|
186
215
|
getViemChain
|
|
187
216
|
});
|
package/dist/esm/aa/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__spreadProps,
|
|
4
4
|
__spreadValues
|
|
5
5
|
} from "../chunk-6FNC3XMI.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createParaViemAccount } from "../viemWalletClient.js";
|
|
7
7
|
import { SmartAccountError } from "@getpara/core-sdk";
|
|
8
8
|
function isExternalWallet(signer) {
|
|
9
9
|
return !!signer && typeof signer === "object" && "transport" in signer && "account" in signer;
|
|
@@ -76,7 +76,7 @@ function resolveSigner(para, params) {
|
|
|
76
76
|
}
|
|
77
77
|
const walletAddress = resolveWalletIdentifier(para, params);
|
|
78
78
|
if (!walletAddress) return null;
|
|
79
|
-
return
|
|
79
|
+
return createParaViemAccount({ para, address: walletAddress });
|
|
80
80
|
}
|
|
81
81
|
function rejectExternalWallet7702(signer, provider) {
|
|
82
82
|
if (!signer || !isExternalWallet(signer)) return;
|
|
@@ -12,16 +12,29 @@ import {
|
|
|
12
12
|
} from "viem";
|
|
13
13
|
import { hashAuthorization } from "viem/utils";
|
|
14
14
|
import * as viemChains from "viem/chains";
|
|
15
|
-
import { hexStringToBase64 } from "@getpara/core-sdk";
|
|
15
|
+
import ParaCore, { hexStringToBase64 } from "@getpara/core-sdk";
|
|
16
16
|
function normalizeSignature(rawSignature) {
|
|
17
17
|
const sigHex = `0x${rawSignature}`;
|
|
18
18
|
const parsed = parseSignature(sigHex);
|
|
19
19
|
return serializeSignature({ r: parsed.r, s: parsed.s, yParity: parsed.yParity });
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
22
|
+
let para;
|
|
23
|
+
let resolvedAddress;
|
|
24
|
+
if (typeof paraOrOptions === "object" && "para" in paraOrOptions && !(paraOrOptions instanceof ParaCore)) {
|
|
25
|
+
para = paraOrOptions.para;
|
|
26
|
+
resolvedAddress = paraOrOptions.address;
|
|
27
|
+
if (!resolvedAddress && paraOrOptions.walletId) {
|
|
28
|
+
const w = para.wallets[paraOrOptions.walletId];
|
|
29
|
+
resolvedAddress = w == null ? void 0 : w.address;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
para = paraOrOptions;
|
|
33
|
+
resolvedAddress = walletAddress;
|
|
34
|
+
}
|
|
22
35
|
let currentWallet;
|
|
23
|
-
if (
|
|
24
|
-
currentWallet = para.findWalletByAddress(
|
|
36
|
+
if (resolvedAddress) {
|
|
37
|
+
currentWallet = para.findWalletByAddress(resolvedAddress, { type: ["EVM"] });
|
|
25
38
|
} else {
|
|
26
39
|
const walletId = para.findWalletId(void 0, { type: ["EVM"] });
|
|
27
40
|
currentWallet = para.wallets[walletId];
|
|
@@ -117,13 +130,28 @@ function getViemChain(chainId) {
|
|
|
117
130
|
}
|
|
118
131
|
throw new Error(`chain with id ${chainId} not found`);
|
|
119
132
|
}
|
|
120
|
-
function createParaViemClient(
|
|
133
|
+
function createParaViemClient(paraOrOptions, params, opts) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
let para;
|
|
136
|
+
let config;
|
|
137
|
+
let noAccount;
|
|
138
|
+
if (typeof paraOrOptions === "object" && "para" in paraOrOptions && !(paraOrOptions instanceof ParaCore)) {
|
|
139
|
+
para = paraOrOptions.para;
|
|
140
|
+
config = paraOrOptions.walletClientConfig;
|
|
141
|
+
noAccount = (_a = paraOrOptions.noAccount) != null ? _a : false;
|
|
142
|
+
} else {
|
|
143
|
+
para = paraOrOptions;
|
|
144
|
+
config = params;
|
|
145
|
+
noAccount = (_b = opts == null ? void 0 : opts.noAccount) != null ? _b : false;
|
|
146
|
+
}
|
|
121
147
|
return createWalletClient(__spreadValues({
|
|
122
|
-
account:
|
|
123
|
-
},
|
|
148
|
+
account: noAccount ? void 0 : createParaViemAccount({ para })
|
|
149
|
+
}, config));
|
|
124
150
|
}
|
|
151
|
+
const createParaAccount = createParaViemAccount;
|
|
125
152
|
export {
|
|
126
153
|
createParaAccount,
|
|
154
|
+
createParaViemAccount,
|
|
127
155
|
createParaViemClient,
|
|
128
156
|
getViemChain
|
|
129
157
|
};
|
package/dist/types/aa/utils.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function ensureExternalWalletChain(signer: unknown, chain: Chain,
|
|
|
23
23
|
/**
|
|
24
24
|
* Resolves an EVM **embedded** wallet address from params. Returns `null` if no matching
|
|
25
25
|
* wallet exists or if the matched wallet is external (external wallets lack MPC share
|
|
26
|
-
* data and cannot be used with `
|
|
26
|
+
* data and cannot be used with `createParaViemAccount`).
|
|
27
27
|
*
|
|
28
28
|
* Priority:
|
|
29
29
|
* 1. Explicit `address` — validated as an EVM wallet via `findWalletByAddress()`
|
|
@@ -40,7 +40,7 @@ export declare function resolveWalletIdentifier(para: ParaCore, params: {
|
|
|
40
40
|
* - If `params.signer` is a `LocalAccount`, returns it directly.
|
|
41
41
|
* - If `params.signer` is a `WalletClient`, wraps it via `resolveExternalSigner`.
|
|
42
42
|
* - If no signer is provided, resolves an embedded Para wallet via `resolveWalletIdentifier`
|
|
43
|
-
* and creates a `LocalAccount` via `
|
|
43
|
+
* and creates a `LocalAccount` via `createParaViemAccount`.
|
|
44
44
|
*
|
|
45
45
|
* Returns `null` when no embedded wallet is found (callers should return `null` to the user).
|
|
46
46
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Chain, Hex, LocalAccount, RpcSchema, Transport, WalletClient, WalletClientConfig } from 'viem';
|
|
2
2
|
import * as viemChains from 'viem/chains';
|
|
3
|
+
import type { CreateParaSignerBaseOptions } from '@getpara/core-sdk';
|
|
3
4
|
import ParaCore from '@getpara/core-sdk';
|
|
4
5
|
/** Options for creating a Para viem client */
|
|
5
6
|
interface ViemClientOpts {
|
|
@@ -22,12 +23,19 @@ interface ViemClientOpts {
|
|
|
22
23
|
*
|
|
23
24
|
* @example
|
|
24
25
|
* ```ts
|
|
25
|
-
* const account =
|
|
26
|
+
* const account = createParaViemAccount({ para });
|
|
26
27
|
* const signature = await account.signMessage({ message: 'Hello' });
|
|
27
28
|
* // signature is properly formatted for ecrecover
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
export
|
|
31
|
+
export interface CreateParaViemAccountOptions extends CreateParaSignerBaseOptions {
|
|
32
|
+
address?: Hex;
|
|
33
|
+
}
|
|
34
|
+
/** @deprecated Use {@link CreateParaViemAccountOptions} instead. */
|
|
35
|
+
export type CreateParaAccountOptions = CreateParaViemAccountOptions;
|
|
36
|
+
export declare function createParaViemAccount(options: CreateParaViemAccountOptions): LocalAccount;
|
|
37
|
+
/** @deprecated Use the options-object overload instead. */
|
|
38
|
+
export declare function createParaViemAccount(para: ParaCore, walletAddress?: Hex): LocalAccount;
|
|
31
39
|
/**
|
|
32
40
|
* Looks up a viem Chain object by chain ID.
|
|
33
41
|
*
|
|
@@ -45,7 +53,7 @@ export declare function getViemChain(chainId: string): viemChains.Chain;
|
|
|
45
53
|
/**
|
|
46
54
|
* Creates a viem WalletClient configured with a Para account.
|
|
47
55
|
*
|
|
48
|
-
* This is a convenience function that combines `
|
|
56
|
+
* This is a convenience function that combines `createParaViemAccount` with viem's
|
|
49
57
|
* `createWalletClient`. The resulting client can be used for all standard
|
|
50
58
|
* wallet operations with properly formatted signatures.
|
|
51
59
|
*
|
|
@@ -69,5 +77,14 @@ export declare function getViemChain(chainId: string): viemChains.Chain;
|
|
|
69
77
|
* const hash = await client.sendTransaction({ to: '0x...', value: 1n });
|
|
70
78
|
* ```
|
|
71
79
|
*/
|
|
80
|
+
export interface CreateParaViemClientOptions {
|
|
81
|
+
para: ParaCore;
|
|
82
|
+
walletClientConfig: WalletClientConfig<Transport, Chain, LocalAccount, RpcSchema>;
|
|
83
|
+
noAccount?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export declare function createParaViemClient(options: CreateParaViemClientOptions): WalletClient<Transport, Chain, LocalAccount, RpcSchema>;
|
|
86
|
+
/** @deprecated Use the options-object overload instead. */
|
|
72
87
|
export declare function createParaViemClient(para: ParaCore, params: WalletClientConfig<Transport, Chain, LocalAccount, RpcSchema>, opts?: ViemClientOpts): WalletClient<Transport, Chain, LocalAccount, RpcSchema>;
|
|
88
|
+
/** @deprecated Use {@link createParaViemAccount} instead. */
|
|
89
|
+
export declare const createParaAccount: typeof createParaViemAccount;
|
|
73
90
|
export {};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/viem-v2-integration",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/core-sdk": "2.
|
|
5
|
+
"@getpara/core-sdk": "2.22.0"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"typescript": "^5.8.3",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist",
|
|
25
25
|
"package.json"
|
|
26
26
|
],
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "7191b8c823ec592eb1da16c9a085f8e69c6bf377",
|
|
28
28
|
"main": "dist/cjs/index.js",
|
|
29
29
|
"module": "dist/esm/index.js",
|
|
30
30
|
"peerDependencies": {
|