@getpara/viem-v2-integration 3.20.0 → 3.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 +22 -2
- package/dist/cjs/hashAuthorization.js +32 -0
- package/dist/cjs/viemWalletClient.js +24 -4
- package/dist/esm/aa/utils.js +20 -1
- package/dist/esm/hashAuthorization.js +10 -0
- package/dist/esm/viemWalletClient.js +26 -5
- package/dist/types/aa/utils.d.ts +11 -1
- package/dist/types/hashAuthorization.d.ts +5 -0
- package/package.json +8 -7
package/dist/cjs/aa/utils.js
CHANGED
|
@@ -60,7 +60,8 @@ __export(utils_exports, {
|
|
|
60
60
|
rejectExternalWallet7702: () => rejectExternalWallet7702,
|
|
61
61
|
resolveExternalSigner: () => resolveExternalSigner,
|
|
62
62
|
resolveSigner: () => resolveSigner,
|
|
63
|
-
resolveWalletIdentifier: () => resolveWalletIdentifier
|
|
63
|
+
resolveWalletIdentifier: () => resolveWalletIdentifier,
|
|
64
|
+
waitForDeployedCode: () => waitForDeployedCode
|
|
64
65
|
});
|
|
65
66
|
module.exports = __toCommonJS(utils_exports);
|
|
66
67
|
var import_viemWalletClient = require("../viemWalletClient.js");
|
|
@@ -155,6 +156,24 @@ function assertAccountAddress(address, clientLabel, provider) {
|
|
|
155
156
|
});
|
|
156
157
|
}
|
|
157
158
|
}
|
|
159
|
+
function waitForDeployedCode(_0, _1) {
|
|
160
|
+
return __async(this, arguments, function* (publicClient, {
|
|
161
|
+
address,
|
|
162
|
+
attempts,
|
|
163
|
+
intervalMs,
|
|
164
|
+
isReady = (code) => !!code && code !== "0x"
|
|
165
|
+
}) {
|
|
166
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
167
|
+
if (isReady(yield publicClient.getCode({ address }))) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (attempt < attempts - 1) {
|
|
171
|
+
yield new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
158
177
|
// Annotate the CommonJS export names for ESM import in node:
|
|
159
178
|
0 && (module.exports = {
|
|
160
179
|
assertAccountAddress,
|
|
@@ -163,5 +182,6 @@ function assertAccountAddress(address, clientLabel, provider) {
|
|
|
163
182
|
rejectExternalWallet7702,
|
|
164
183
|
resolveExternalSigner,
|
|
165
184
|
resolveSigner,
|
|
166
|
-
resolveWalletIdentifier
|
|
185
|
+
resolveWalletIdentifier,
|
|
186
|
+
waitForDeployedCode
|
|
167
187
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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 hashAuthorization_exports = {};
|
|
19
|
+
__export(hashAuthorization_exports, {
|
|
20
|
+
hashEip7702Authorization: () => hashEip7702Authorization
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(hashAuthorization_exports);
|
|
23
|
+
var import_viem = require("viem");
|
|
24
|
+
function hashEip7702Authorization({ address, chainId, nonce }) {
|
|
25
|
+
return (0, import_viem.keccak256)(
|
|
26
|
+
(0, import_viem.concatHex)(["0x05", (0, import_viem.toRlp)([chainId ? (0, import_viem.numberToHex)(chainId) : "0x", address, nonce ? (0, import_viem.numberToHex)(nonce) : "0x"])])
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
hashEip7702Authorization
|
|
32
|
+
});
|
|
@@ -68,14 +68,21 @@ __export(viemWalletClient_exports, {
|
|
|
68
68
|
});
|
|
69
69
|
module.exports = __toCommonJS(viemWalletClient_exports);
|
|
70
70
|
var import_viem = require("viem");
|
|
71
|
-
var import_utils = require("viem/utils");
|
|
72
71
|
var viemChains = __toESM(require("viem/chains"));
|
|
72
|
+
var import_hashAuthorization = require("./hashAuthorization.js");
|
|
73
73
|
var import_core_sdk = __toESM(require("@getpara/core-sdk"));
|
|
74
74
|
function normalizeSignature(rawSignature) {
|
|
75
75
|
const sigHex = `0x${rawSignature}`;
|
|
76
76
|
const parsed = (0, import_viem.parseSignature)(sigHex);
|
|
77
77
|
return (0, import_viem.serializeSignature)({ r: parsed.r, s: parsed.s, yParity: parsed.yParity });
|
|
78
78
|
}
|
|
79
|
+
function encodePersonalMessage(message) {
|
|
80
|
+
const bytes = typeof message === "string" ? (0, import_viem.toBytes)(message) : typeof message.raw === "string" ? (0, import_viem.toBytes)(message.raw) : message.raw;
|
|
81
|
+
return Buffer.from(bytes).toString("base64");
|
|
82
|
+
}
|
|
83
|
+
function stringifyTypedData(value) {
|
|
84
|
+
return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() : item);
|
|
85
|
+
}
|
|
79
86
|
function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
80
87
|
let para;
|
|
81
88
|
let resolvedAddress;
|
|
@@ -114,7 +121,15 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
114
121
|
/** Signs an EIP-191 personal message (prefixed and hashed). */
|
|
115
122
|
signMessage: (_0) => __async(null, [_0], function* ({ message }) {
|
|
116
123
|
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
117
|
-
const res = yield para.signMessage({
|
|
124
|
+
const res = yield para.signMessage({
|
|
125
|
+
walletId: currentWallet.id,
|
|
126
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)(hashedMessage),
|
|
127
|
+
canonicalMessage: {
|
|
128
|
+
walletType: "EVM",
|
|
129
|
+
signingType: "PERSONAL_MESSAGE",
|
|
130
|
+
messageBase64: encodePersonalMessage(message)
|
|
131
|
+
}
|
|
132
|
+
});
|
|
118
133
|
const signature = (0, import_core_sdk.requireSuccessfulSignature)(res);
|
|
119
134
|
return normalizeSignature(signature);
|
|
120
135
|
}),
|
|
@@ -148,7 +163,12 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
148
163
|
signTypedData: (typedDataDefinition) => __async(null, null, function* () {
|
|
149
164
|
const res = yield para.signMessage({
|
|
150
165
|
walletId: currentWallet.id,
|
|
151
|
-
messageBase64: (0, import_core_sdk.hexStringToBase64)((0, import_viem.hashTypedData)(typedDataDefinition))
|
|
166
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)((0, import_viem.hashTypedData)(typedDataDefinition)),
|
|
167
|
+
canonicalMessage: {
|
|
168
|
+
walletType: "EVM",
|
|
169
|
+
signingType: "TYPED_DATA",
|
|
170
|
+
typedDataJson: stringifyTypedData(typedDataDefinition)
|
|
171
|
+
}
|
|
152
172
|
});
|
|
153
173
|
const signature = (0, import_core_sdk.requireSuccessfulSignature)(res);
|
|
154
174
|
return normalizeSignature(signature);
|
|
@@ -160,7 +180,7 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
160
180
|
signAuthorization: (authorization) => __async(null, null, function* () {
|
|
161
181
|
var _a;
|
|
162
182
|
const address = (_a = authorization.contractAddress) != null ? _a : authorization.address;
|
|
163
|
-
const hash = (0,
|
|
183
|
+
const hash = (0, import_hashAuthorization.hashEip7702Authorization)({ address, chainId: authorization.chainId, nonce: authorization.nonce });
|
|
164
184
|
const res = yield para.signMessage({
|
|
165
185
|
walletId: currentWallet.id,
|
|
166
186
|
messageBase64: (0, import_core_sdk.hexStringToBase64)(hash)
|
package/dist/esm/aa/utils.js
CHANGED
|
@@ -95,6 +95,24 @@ function assertAccountAddress(address, clientLabel, provider) {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
function waitForDeployedCode(_0, _1) {
|
|
99
|
+
return __async(this, arguments, function* (publicClient, {
|
|
100
|
+
address,
|
|
101
|
+
attempts,
|
|
102
|
+
intervalMs,
|
|
103
|
+
isReady = (code) => !!code && code !== "0x"
|
|
104
|
+
}) {
|
|
105
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
106
|
+
if (isReady(yield publicClient.getCode({ address }))) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (attempt < attempts - 1) {
|
|
110
|
+
yield new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
98
116
|
export {
|
|
99
117
|
assertAccountAddress,
|
|
100
118
|
ensureExternalWalletChain,
|
|
@@ -102,5 +120,6 @@ export {
|
|
|
102
120
|
rejectExternalWallet7702,
|
|
103
121
|
resolveExternalSigner,
|
|
104
122
|
resolveSigner,
|
|
105
|
-
resolveWalletIdentifier
|
|
123
|
+
resolveWalletIdentifier,
|
|
124
|
+
waitForDeployedCode
|
|
106
125
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "./chunk-6FNC3XMI.js";
|
|
2
|
+
import { concatHex, keccak256, numberToHex, toRlp } from "viem";
|
|
3
|
+
function hashEip7702Authorization({ address, chainId, nonce }) {
|
|
4
|
+
return keccak256(
|
|
5
|
+
concatHex(["0x05", toRlp([chainId ? numberToHex(chainId) : "0x", address, nonce ? numberToHex(nonce) : "0x"])])
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
hashEip7702Authorization
|
|
10
|
+
};
|
|
@@ -8,16 +8,24 @@ import {
|
|
|
8
8
|
hashTypedData,
|
|
9
9
|
parseSignature,
|
|
10
10
|
serializeSignature,
|
|
11
|
-
serializeTransaction
|
|
11
|
+
serializeTransaction,
|
|
12
|
+
toBytes
|
|
12
13
|
} from "viem";
|
|
13
|
-
import { hashAuthorization } from "viem/utils";
|
|
14
14
|
import * as viemChains from "viem/chains";
|
|
15
|
+
import { hashEip7702Authorization } from "./hashAuthorization.js";
|
|
15
16
|
import ParaCore, { hexStringToBase64, requireSuccessfulSignature } from "@getpara/core-sdk";
|
|
16
17
|
function normalizeSignature(rawSignature) {
|
|
17
18
|
const sigHex = `0x${rawSignature}`;
|
|
18
19
|
const parsed = parseSignature(sigHex);
|
|
19
20
|
return serializeSignature({ r: parsed.r, s: parsed.s, yParity: parsed.yParity });
|
|
20
21
|
}
|
|
22
|
+
function encodePersonalMessage(message) {
|
|
23
|
+
const bytes = typeof message === "string" ? toBytes(message) : typeof message.raw === "string" ? toBytes(message.raw) : message.raw;
|
|
24
|
+
return Buffer.from(bytes).toString("base64");
|
|
25
|
+
}
|
|
26
|
+
function stringifyTypedData(value) {
|
|
27
|
+
return JSON.stringify(value, (_key, item) => typeof item === "bigint" ? item.toString() : item);
|
|
28
|
+
}
|
|
21
29
|
function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
22
30
|
let para;
|
|
23
31
|
let resolvedAddress;
|
|
@@ -56,7 +64,15 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
56
64
|
/** Signs an EIP-191 personal message (prefixed and hashed). */
|
|
57
65
|
signMessage: (_0) => __async(null, [_0], function* ({ message }) {
|
|
58
66
|
const hashedMessage = hashMessage(message);
|
|
59
|
-
const res = yield para.signMessage({
|
|
67
|
+
const res = yield para.signMessage({
|
|
68
|
+
walletId: currentWallet.id,
|
|
69
|
+
messageBase64: hexStringToBase64(hashedMessage),
|
|
70
|
+
canonicalMessage: {
|
|
71
|
+
walletType: "EVM",
|
|
72
|
+
signingType: "PERSONAL_MESSAGE",
|
|
73
|
+
messageBase64: encodePersonalMessage(message)
|
|
74
|
+
}
|
|
75
|
+
});
|
|
60
76
|
const signature = requireSuccessfulSignature(res);
|
|
61
77
|
return normalizeSignature(signature);
|
|
62
78
|
}),
|
|
@@ -90,7 +106,12 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
90
106
|
signTypedData: (typedDataDefinition) => __async(null, null, function* () {
|
|
91
107
|
const res = yield para.signMessage({
|
|
92
108
|
walletId: currentWallet.id,
|
|
93
|
-
messageBase64: hexStringToBase64(hashTypedData(typedDataDefinition))
|
|
109
|
+
messageBase64: hexStringToBase64(hashTypedData(typedDataDefinition)),
|
|
110
|
+
canonicalMessage: {
|
|
111
|
+
walletType: "EVM",
|
|
112
|
+
signingType: "TYPED_DATA",
|
|
113
|
+
typedDataJson: stringifyTypedData(typedDataDefinition)
|
|
114
|
+
}
|
|
94
115
|
});
|
|
95
116
|
const signature = requireSuccessfulSignature(res);
|
|
96
117
|
return normalizeSignature(signature);
|
|
@@ -102,7 +123,7 @@ function createParaViemAccount(paraOrOptions, walletAddress) {
|
|
|
102
123
|
signAuthorization: (authorization) => __async(null, null, function* () {
|
|
103
124
|
var _a;
|
|
104
125
|
const address = (_a = authorization.contractAddress) != null ? _a : authorization.address;
|
|
105
|
-
const hash =
|
|
126
|
+
const hash = hashEip7702Authorization({ address, chainId: authorization.chainId, nonce: authorization.nonce });
|
|
106
127
|
const res = yield para.signMessage({
|
|
107
128
|
walletId: currentWallet.id,
|
|
108
129
|
messageBase64: hexStringToBase64(hash)
|
package/dist/types/aa/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type ParaCore from '@getpara/core-sdk';
|
|
2
|
-
import type { Chain, Hex, LocalAccount, WalletClient } from 'viem';
|
|
2
|
+
import type { Chain, Hex, LocalAccount, PublicClient, WalletClient } from 'viem';
|
|
3
3
|
import type { BaseSmartAccountConfig, SmartAccountProvider } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Returns true if the signer is a WalletClient (external browser wallet).
|
|
@@ -60,3 +60,13 @@ export declare function rejectExternalWallet7702(signer: LocalAccount | WalletCl
|
|
|
60
60
|
* Use after creating the provider-specific client to ensure it produced an account.
|
|
61
61
|
*/
|
|
62
62
|
export declare function assertAccountAddress(address: Hex | undefined, clientLabel: string, provider: SmartAccountProvider): asserts address is Hex;
|
|
63
|
+
/**
|
|
64
|
+
* Polls `getCode` until `isReady` accepts the bytecode at `address`, up to `attempts` reads.
|
|
65
|
+
* Returns whether the code became ready. Waits `intervalMs` between reads, not after the last one.
|
|
66
|
+
*/
|
|
67
|
+
export declare function waitForDeployedCode(publicClient: Pick<PublicClient, 'getCode'>, { address, attempts, intervalMs, isReady, }: {
|
|
68
|
+
address: Hex;
|
|
69
|
+
attempts: number;
|
|
70
|
+
intervalMs: number;
|
|
71
|
+
isReady?: (code: Hex | undefined) => boolean;
|
|
72
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Address, AuthorizationRequest, Hash } from 'viem';
|
|
2
|
+
export type AuthorizationHashInput = Pick<AuthorizationRequest, 'chainId' | 'nonce'> & {
|
|
3
|
+
address: Address;
|
|
4
|
+
};
|
|
5
|
+
export declare function hashEip7702Authorization({ address, chainId, nonce }: AuthorizationHashInput): Hash;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/viem-v2-integration",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/core-sdk": "3.
|
|
5
|
+
"@getpara/core-sdk": "3.22.0"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"typescript": "^5.8.3",
|
|
@@ -24,19 +24,20 @@
|
|
|
24
24
|
"dist",
|
|
25
25
|
"package.json"
|
|
26
26
|
],
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "4ca50a0fc70e11370595f16daad0f1ac4da0edbc",
|
|
28
28
|
"main": "dist/cjs/index.js",
|
|
29
29
|
"module": "dist/esm/index.js",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"viem": "^2.
|
|
31
|
+
"viem": "^2.10.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
35
|
-
"test": "vitest run",
|
|
35
|
+
"test": "vitest run --coverage",
|
|
36
36
|
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
37
37
|
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
38
|
-
"build:types": "
|
|
39
|
-
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types"
|
|
38
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
39
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
40
41
|
},
|
|
41
42
|
"sideEffects": false,
|
|
42
43
|
"types": "dist/types/index.d.ts",
|