@nevermined-io/core-kit 0.4.5 → 0.5.1
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/Instantiable.abstract.js +15 -13
- package/dist/Instantiable.abstract.js.map +1 -0
- package/dist/artifacts/generated.d.ts +174 -40
- package/dist/artifacts/generated.d.ts.map +1 -1
- package/dist/artifacts/generated.js +22805 -7111
- package/dist/artifacts/generated.js.map +1 -0
- package/dist/contracts/AccessManager.js +12 -3
- package/dist/contracts/AccessManager.js.map +1 -0
- package/dist/contracts/AssetRegistry.d.ts +1 -0
- package/dist/contracts/AssetRegistry.d.ts.map +1 -1
- package/dist/contracts/AssetRegistry.js +134 -69
- package/dist/contracts/AssetRegistry.js.map +1 -0
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +173 -140
- package/dist/contracts/ContractBase.js.map +1 -0
- package/dist/contracts/ContractsApi.js +6 -54
- package/dist/contracts/ContractsApi.js.map +1 -0
- package/dist/contracts/CryptoTemplateBase.js +23 -11
- package/dist/contracts/CryptoTemplateBase.js.map +1 -0
- package/dist/contracts/FiatPaymentTemplate.js +9 -1
- package/dist/contracts/FiatPaymentTemplate.js.map +1 -0
- package/dist/contracts/FiatSettlementCondition.js +8 -1
- package/dist/contracts/FiatSettlementCondition.js.map +1 -0
- package/dist/contracts/FixedPaymentTemplate.js +42 -10
- package/dist/contracts/FixedPaymentTemplate.js.map +1 -0
- package/dist/contracts/NFT1155Base.js +48 -12
- package/dist/contracts/NFT1155Base.js.map +1 -0
- package/dist/contracts/NFT1155Credits.js +2 -0
- package/dist/contracts/NFT1155Credits.js.map +1 -0
- package/dist/contracts/NFT1155ExpirableCredits.js +26 -6
- package/dist/contracts/NFT1155ExpirableCredits.js.map +1 -0
- package/dist/contracts/NVMConfig.js +2 -0
- package/dist/contracts/NVMConfig.js.map +1 -0
- package/dist/contracts/PayAsYouGoTemplate.js +36 -10
- package/dist/contracts/PayAsYouGoTemplate.js.map +1 -0
- package/dist/contracts/ProtocolStandardFees.js +7 -1
- package/dist/contracts/ProtocolStandardFees.js.map +1 -0
- package/dist/contracts/Roles.js +2 -0
- package/dist/contracts/Roles.js.map +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/errors/NeverminedErrors.js +27 -26
- package/dist/errors/NeverminedErrors.js.map +1 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/models/AgentX402AccessToken.js +78 -46
- package/dist/models/AgentX402AccessToken.js.map +1 -0
- package/dist/models/Logger.js +12 -12
- package/dist/models/Logger.js.map +1 -0
- package/dist/models/NeverminedOptions.d.ts +3 -3
- package/dist/models/NeverminedOptions.d.ts.map +1 -1
- package/dist/models/NeverminedOptions.js +3 -28
- package/dist/models/NeverminedOptions.js.map +1 -0
- package/dist/models/NvmApiKey.js +96 -147
- package/dist/models/NvmApiKey.js.map +1 -0
- package/dist/models/Transactions.js +3 -1
- package/dist/models/Transactions.js.map +1 -0
- package/dist/models/index.js +2 -0
- package/dist/models/index.js.map +1 -0
- package/dist/nevermined/Nevermined.js +20 -42
- package/dist/nevermined/Nevermined.js.map +1 -0
- package/dist/nevermined/api/PaymentsApi.js +38 -43
- package/dist/nevermined/api/PaymentsApi.js.map +1 -0
- package/dist/nevermined/api/ServicesApi.js +7 -15
- package/dist/nevermined/api/ServicesApi.js.map +1 -0
- package/dist/nevermined/api/UtilsApi.js +7 -19
- package/dist/nevermined/api/UtilsApi.js.map +1 -0
- package/dist/nevermined/index.js +2 -0
- package/dist/nevermined/index.js.map +1 -0
- package/dist/nevermined/utils/AgentUtils.js +25 -23
- package/dist/nevermined/utils/AgentUtils.js.map +1 -0
- package/dist/nevermined/utils/AnvilHelpers.js +34 -19
- package/dist/nevermined/utils/AnvilHelpers.js.map +1 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +4 -4
- package/dist/nevermined/utils/BlockchainViemUtils.js +102 -108
- package/dist/nevermined/utils/BlockchainViemUtils.js.map +1 -0
- package/dist/nevermined/utils/JwtUtils.js +33 -28
- package/dist/nevermined/utils/JwtUtils.js.map +1 -0
- package/dist/nevermined/utils/SignatureUtils.js +23 -27
- package/dist/nevermined/utils/SignatureUtils.js.map +1 -0
- package/dist/nevermined/utils/WebServiceConnector.js +18 -20
- package/dist/nevermined/utils/WebServiceConnector.js.map +1 -0
- package/dist/nevermined/utils/ZeroDevPolicies.js +115 -75
- package/dist/nevermined/utils/ZeroDevPolicies.js.map +1 -0
- package/dist/nevermined/utils/index.js +2 -0
- package/dist/nevermined/utils/index.js.map +1 -0
- package/dist/services/Api.js +11 -5
- package/dist/services/Api.js.map +1 -0
- package/dist/services/Profiles.js +15 -20
- package/dist/services/Profiles.js.map +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/dist/utils/ConversionTypeHelpers.js +13 -6
- package/dist/utils/ConversionTypeHelpers.js.map +1 -0
- package/dist/utils/DeploymentInfo.js +12 -7
- package/dist/utils/DeploymentInfo.js.map +1 -0
- package/dist/utils/Network.js +27 -19
- package/dist/utils/Network.js.map +1 -0
- package/dist/utils/helpers.js +42 -31
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +17 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
2
|
-
import { deserializePermissionAccount, serializePermissionAccount, toPermissionValidator
|
|
2
|
+
import { deserializePermissionAccount, serializePermissionAccount, toPermissionValidator } from '@zerodev/permissions';
|
|
3
3
|
import { toECDSASigner } from '@zerodev/permissions/signers';
|
|
4
|
-
import { addressToEmptyAccount, createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient, getUserOperationGasPrice
|
|
4
|
+
import { addressToEmptyAccount, createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient, getUserOperationGasPrice } from '@zerodev/sdk';
|
|
5
5
|
import { KERNEL_V3_1, getEntryPoint } from '@zerodev/sdk/constants';
|
|
6
|
-
import { encodeAbiParameters, getAbiItem, getAddress, getContract, http, isAddress, pad, stringToBytes, stringToHex, toBytes, keccak256 as viemKeccak256
|
|
7
|
-
import { english, generateMnemonic, generatePrivateKey, mnemonicToAccount, privateKeyToAccount
|
|
6
|
+
import { encodeAbiParameters, getAbiItem, getAddress, getContract, http, isAddress, pad, stringToBytes, stringToHex, toBytes, keccak256 as viemKeccak256 } from 'viem';
|
|
7
|
+
import { english, generateMnemonic, generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
8
8
|
import { Instantiable } from '../../Instantiable.abstract.js';
|
|
9
9
|
import { ContractsError } from '../../errors/NeverminedErrors.js';
|
|
10
10
|
import { getChain } from '../../utils/Network.js';
|
|
@@ -12,9 +12,8 @@ const ENTRY_POINT_VERSION = '0.7';
|
|
|
12
12
|
/**
|
|
13
13
|
* Utility class with methods that allow the interaction with the blockchain.
|
|
14
14
|
* This class uses Viem library to interact with the blockchain.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
constructor(config) {
|
|
15
|
+
*/ export class BlockchainViemUtils extends Instantiable {
|
|
16
|
+
constructor(config){
|
|
18
17
|
super();
|
|
19
18
|
this.setInstanceConfig(config);
|
|
20
19
|
}
|
|
@@ -34,17 +33,15 @@ const TRANSACTION_RECEIPT_POLLING_INTERVAL_MS = 1_500;
|
|
|
34
33
|
* tx-replacement / reorgs natively.
|
|
35
34
|
* @param txHash - the transaction hash
|
|
36
35
|
* @returns the transaction receipt
|
|
37
|
-
*/
|
|
38
|
-
export async function getTransactionReceipt({ txHash, publicClient, }) {
|
|
36
|
+
*/ export async function getTransactionReceipt({ txHash, publicClient }) {
|
|
39
37
|
try {
|
|
40
38
|
return await publicClient.waitForTransactionReceipt({
|
|
41
39
|
hash: txHash,
|
|
42
40
|
timeout: TRANSACTION_RECEIPT_TIMEOUT_MS,
|
|
43
41
|
pollingInterval: TRANSACTION_RECEIPT_POLLING_INTERVAL_MS,
|
|
44
|
-
confirmations: 1
|
|
42
|
+
confirmations: 1
|
|
45
43
|
});
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
44
|
+
} catch (error) {
|
|
48
45
|
throw new ContractsError(`Unable to get transaction receipt with hash: ${txHash}. Error: ${error}`);
|
|
49
46
|
}
|
|
50
47
|
}
|
|
@@ -55,12 +52,14 @@ export async function getTransactionReceipt({ txHash, publicClient, }) {
|
|
|
55
52
|
* @param abi - the contract artifact
|
|
56
53
|
* @param client - the client to interact with the blockchain
|
|
57
54
|
* @returns a contract instance
|
|
58
|
-
*/
|
|
59
|
-
export async function getContractInstance(contractAddress, abi, client) {
|
|
55
|
+
*/ export async function getContractInstance(contractAddress, abi, client) {
|
|
60
56
|
return getContract({
|
|
61
57
|
abi,
|
|
62
58
|
address: contractAddress,
|
|
63
|
-
client: {
|
|
59
|
+
client: {
|
|
60
|
+
wallet: client.wallet,
|
|
61
|
+
public: client.public
|
|
62
|
+
}
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
///// ABIs
|
|
@@ -70,9 +69,12 @@ export async function getContractInstance(contractAddress, abi, client) {
|
|
|
70
69
|
* @param funcName the function name
|
|
71
70
|
* @param args the args of the function
|
|
72
71
|
* @returns the function found
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
*/ export function searchAbiFunction(abi, funcName, args = []) {
|
|
73
|
+
const func = getAbiItem({
|
|
74
|
+
abi,
|
|
75
|
+
name: funcName,
|
|
76
|
+
args
|
|
77
|
+
});
|
|
76
78
|
if (!func || func.type !== 'function') {
|
|
77
79
|
throw new ContractsError(`Function "${funcName}" is not part of contract`);
|
|
78
80
|
}
|
|
@@ -83,11 +85,10 @@ export function searchAbiFunction(abi, funcName, args = []) {
|
|
|
83
85
|
* @param abi the ABI of the contract
|
|
84
86
|
* @param funcName the event name
|
|
85
87
|
* @returns the event found
|
|
86
|
-
*/
|
|
87
|
-
export function searchAbiEvent(abi, eventName) {
|
|
88
|
+
*/ export function searchAbiEvent(abi, eventName) {
|
|
88
89
|
const event = getAbiItem({
|
|
89
90
|
abi,
|
|
90
|
-
name: eventName
|
|
91
|
+
name: eventName
|
|
91
92
|
});
|
|
92
93
|
if (!event || event.type !== 'event') {
|
|
93
94
|
throw new ContractsError(`Event "${event}" is not part of contract`);
|
|
@@ -100,8 +101,7 @@ export function searchAbiEvent(abi, eventName) {
|
|
|
100
101
|
* @param funcName the function name
|
|
101
102
|
* @param args the args of the function
|
|
102
103
|
* @returns the function found
|
|
103
|
-
*/
|
|
104
|
-
export function getSignatureOfFunction(abi, funcName, args = []) {
|
|
104
|
+
*/ export function getSignatureOfFunction(abi, funcName, args = []) {
|
|
105
105
|
return searchAbiFunction(abi, funcName, args);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
@@ -110,8 +110,7 @@ export function getSignatureOfFunction(abi, funcName, args = []) {
|
|
|
110
110
|
* @param funcName the function name
|
|
111
111
|
* @param args the args of the function
|
|
112
112
|
* @returns the function found
|
|
113
|
-
*/
|
|
114
|
-
export function getInputsOfFunction(abi, funcName, args = []) {
|
|
113
|
+
*/ export function getInputsOfFunction(abi, funcName, args = []) {
|
|
115
114
|
return searchAbiFunction(abi, funcName, args).inputs;
|
|
116
115
|
}
|
|
117
116
|
/**
|
|
@@ -120,12 +119,11 @@ export function getInputsOfFunction(abi, funcName, args = []) {
|
|
|
120
119
|
* @param funcName the function name
|
|
121
120
|
* @param args the args of the function
|
|
122
121
|
* @returns the function found
|
|
123
|
-
*/
|
|
124
|
-
|
|
125
|
-
return searchAbiFunction(abi, funcName, args).inputs.map((input, i) => {
|
|
122
|
+
*/ export function getInputsOfFunctionFormatted(abi, funcName, args = []) {
|
|
123
|
+
return searchAbiFunction(abi, funcName, args).inputs.map((input, i)=>{
|
|
126
124
|
return {
|
|
127
125
|
name: input.name,
|
|
128
|
-
value: args[i]
|
|
126
|
+
value: args[i]
|
|
129
127
|
};
|
|
130
128
|
});
|
|
131
129
|
}
|
|
@@ -134,16 +132,14 @@ export function getInputsOfFunctionFormatted(abi, funcName, args = []) {
|
|
|
134
132
|
* Given an address it returns that address in checksum format.
|
|
135
133
|
* @param address the address
|
|
136
134
|
* @returns the same address in checksum format
|
|
137
|
-
*/
|
|
138
|
-
export function getChecksumAddress(address) {
|
|
135
|
+
*/ export function getChecksumAddress(address) {
|
|
139
136
|
return getAddress(address);
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
142
139
|
* It checks if the address is a valid address.
|
|
143
140
|
* @param address the address to check
|
|
144
141
|
* @returns true of the address is valid
|
|
145
|
-
*/
|
|
146
|
-
export function isValidAddress(address) {
|
|
142
|
+
*/ export function isValidAddress(address) {
|
|
147
143
|
return isAddress(address);
|
|
148
144
|
}
|
|
149
145
|
/**
|
|
@@ -151,8 +147,7 @@ export function isValidAddress(address) {
|
|
|
151
147
|
|
|
152
148
|
* @param message the string to encode
|
|
153
149
|
* @returns the encoded byte array
|
|
154
|
-
*/
|
|
155
|
-
export function getBytes(message) {
|
|
150
|
+
*/ export function getBytes(message) {
|
|
156
151
|
return stringToBytes(message);
|
|
157
152
|
}
|
|
158
153
|
/**
|
|
@@ -160,17 +155,19 @@ export function getBytes(message) {
|
|
|
160
155
|
* @param value the value to pad
|
|
161
156
|
* @param length the expected longitutde of the value
|
|
162
157
|
* @returns the padded value
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
*/ export function zeroPadValue(value, length) {
|
|
159
|
+
return pad(value, {
|
|
160
|
+
size: length
|
|
161
|
+
});
|
|
166
162
|
}
|
|
167
163
|
/**
|
|
168
164
|
* Encodes a UTF-8 string into a hex string
|
|
169
165
|
* @param message the string to encode
|
|
170
166
|
* @returns the hex string
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
*/ export function encodeBytes32String(message) {
|
|
168
|
+
return stringToHex(message, {
|
|
169
|
+
size: 32
|
|
170
|
+
});
|
|
174
171
|
}
|
|
175
172
|
////// ACCOUNTS
|
|
176
173
|
/**
|
|
@@ -178,19 +175,19 @@ export function encodeBytes32String(message) {
|
|
|
178
175
|
* @param seedphrase - the seedphrase to be used to generate the account
|
|
179
176
|
* @param addressIndex - the address index
|
|
180
177
|
* @returns an account
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
|
|
178
|
+
*/ export function makeWallet(seedphrase, addressIndex = 0) {
|
|
179
|
+
return mnemonicToAccount(seedphrase, {
|
|
180
|
+
addressIndex
|
|
181
|
+
});
|
|
184
182
|
}
|
|
185
183
|
/**
|
|
186
184
|
* Given a seedphrase generates multiple accounts
|
|
187
185
|
* @param seedphrase - the seedphrase to be used to generate the account
|
|
188
186
|
* @param numAccounts - the number of accounts to create
|
|
189
187
|
* @returns the array of accounts
|
|
190
|
-
*/
|
|
191
|
-
export function makeWallets(seedphrase, numAccounts = 10) {
|
|
188
|
+
*/ export function makeWallets(seedphrase, numAccounts = 10) {
|
|
192
189
|
const accounts = [];
|
|
193
|
-
for
|
|
190
|
+
for(let i = 0; i < numAccounts; i++){
|
|
194
191
|
accounts.push(makeWallet(seedphrase, i));
|
|
195
192
|
}
|
|
196
193
|
return accounts;
|
|
@@ -198,8 +195,7 @@ export function makeWallets(seedphrase, numAccounts = 10) {
|
|
|
198
195
|
/**
|
|
199
196
|
* It generates a random account.
|
|
200
197
|
* @returns a new account
|
|
201
|
-
*/
|
|
202
|
-
export function makeRandomWallet() {
|
|
198
|
+
*/ export function makeRandomWallet() {
|
|
203
199
|
const mnemonic = generateMnemonic(english);
|
|
204
200
|
return makeWallet(mnemonic);
|
|
205
201
|
}
|
|
@@ -207,8 +203,7 @@ export function makeRandomWallet() {
|
|
|
207
203
|
* It generates a list of random accounts
|
|
208
204
|
* @param numAccounts - the number of accounts to create
|
|
209
205
|
* @returns the array of accounts
|
|
210
|
-
*/
|
|
211
|
-
export function makeRandomWallets(numAccounts = 10) {
|
|
206
|
+
*/ export function makeRandomWallets(numAccounts = 10) {
|
|
212
207
|
const mnemonic = generateMnemonic(english);
|
|
213
208
|
return makeWallets(mnemonic, numAccounts);
|
|
214
209
|
}
|
|
@@ -217,8 +212,7 @@ export function makeRandomWallets(numAccounts = 10) {
|
|
|
217
212
|
* It hashes a string using keccak256.
|
|
218
213
|
* @param seed the string to hash
|
|
219
214
|
* @returns the hash
|
|
220
|
-
*/
|
|
221
|
-
export function keccak256(seed) {
|
|
215
|
+
*/ export function keccak256(seed) {
|
|
222
216
|
return viemKeccak256(toBytes(seed));
|
|
223
217
|
}
|
|
224
218
|
/**
|
|
@@ -226,8 +220,7 @@ export function keccak256(seed) {
|
|
|
226
220
|
* @param types the types of the values
|
|
227
221
|
* @param values the values to encode
|
|
228
222
|
* @returns the hash
|
|
229
|
-
*/
|
|
230
|
-
export function keccak256WithEncode(types, values) {
|
|
223
|
+
*/ export function keccak256WithEncode(types, values) {
|
|
231
224
|
const encoded = encodeAbiParameters(types, values);
|
|
232
225
|
return keccak256(encoded);
|
|
233
226
|
}
|
|
@@ -236,8 +229,7 @@ export function keccak256WithEncode(types, values) {
|
|
|
236
229
|
* @param types the types of the values
|
|
237
230
|
* @param values the values to encode
|
|
238
231
|
* @returns the hash
|
|
239
|
-
*/
|
|
240
|
-
export function keccak256Packed(types, values) {
|
|
232
|
+
*/ export function keccak256Packed(types, values) {
|
|
241
233
|
return keccak256WithEncode(types, values);
|
|
242
234
|
}
|
|
243
235
|
/////// ZERO DEV
|
|
@@ -245,21 +237,18 @@ export function keccak256Packed(types, values) {
|
|
|
245
237
|
* Returns the bundler RPC URL. When `BUNDLER_RPC_URL_OVERRIDE` is set
|
|
246
238
|
* (used by tests against a local Alto + anvil-fork stack), it takes precedence
|
|
247
239
|
* over the canonical ZeroDev URL.
|
|
248
|
-
*/
|
|
249
|
-
export function getBundlerRpcUrl(zeroDevProjectId, chainId) {
|
|
240
|
+
*/ export function getBundlerRpcUrl(zeroDevProjectId, chainId) {
|
|
250
241
|
// `||` (not `??`) because Vite replaces missing browser env vars with the
|
|
251
242
|
// empty string at build time; an empty override is equivalent to "no
|
|
252
243
|
// override" for our purposes.
|
|
253
|
-
return
|
|
254
|
-
`https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`);
|
|
244
|
+
return process.env.BUNDLER_RPC_URL_OVERRIDE || `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`;
|
|
255
245
|
}
|
|
256
246
|
/**
|
|
257
247
|
* Returns the paymaster RPC URL (ZeroDev-only; the local fork stack uses
|
|
258
248
|
* `ultra-relay` which sponsors via the bundler's executor key without a
|
|
259
249
|
* paymaster, so this URL is not consulted when `BUNDLER_RPC_URL_OVERRIDE` is
|
|
260
250
|
* set).
|
|
261
|
-
*/
|
|
262
|
-
export function getPaymasterRpcUrl(zeroDevProjectId, chainId) {
|
|
251
|
+
*/ export function getPaymasterRpcUrl(zeroDevProjectId, chainId) {
|
|
263
252
|
return `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`;
|
|
264
253
|
}
|
|
265
254
|
/**
|
|
@@ -268,8 +257,7 @@ export function getPaymasterRpcUrl(zeroDevProjectId, chainId) {
|
|
|
268
257
|
* `ultra-relay` (ZeroDev's fork of Alto) on top of an anvil-fork. The relayer's
|
|
269
258
|
* executor key pays gas directly via `EntryPoint.handleOps`, avoiding the
|
|
270
259
|
* paymaster sponsorship handshake altogether.
|
|
271
|
-
*/
|
|
272
|
-
export function isRelayerMode() {
|
|
260
|
+
*/ export function isRelayerMode() {
|
|
273
261
|
return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE);
|
|
274
262
|
}
|
|
275
263
|
/**
|
|
@@ -277,10 +265,12 @@ export function isRelayerMode() {
|
|
|
277
265
|
* exposes a custom `zd_getUserOperationGasPrice` method; standard ERC-4337
|
|
278
266
|
* bundlers do not. In relayer mode the bundler accepts UserOps with zeroed
|
|
279
267
|
* `maxFeePerGas`/`maxPriorityFeePerGas` and pays gas itself.
|
|
280
|
-
*/
|
|
281
|
-
export async function estimateUserOperationFees(bundlerClient, _publicClient) {
|
|
268
|
+
*/ export async function estimateUserOperationFees(bundlerClient, _publicClient) {
|
|
282
269
|
if (isRelayerMode()) {
|
|
283
|
-
return {
|
|
270
|
+
return {
|
|
271
|
+
maxFeePerGas: 0n,
|
|
272
|
+
maxPriorityFeePerGas: 0n
|
|
273
|
+
};
|
|
284
274
|
}
|
|
285
275
|
return getUserOperationGasPrice(bundlerClient);
|
|
286
276
|
}
|
|
@@ -290,8 +280,7 @@ export async function estimateUserOperationFees(bundlerClient, _publicClient) {
|
|
|
290
280
|
* @param chainId the chain id
|
|
291
281
|
* @param zeroDevProjectId the zero dev project id, you can get it from the ZeroDev dashboard
|
|
292
282
|
* @returns the kernel client
|
|
293
|
-
*/
|
|
294
|
-
export async function createKernelClient(kernelAccount, chainId, zeroDevProjectId, publicClient) {
|
|
283
|
+
*/ export async function createKernelClient(kernelAccount, chainId, zeroDevProjectId, publicClient) {
|
|
295
284
|
const bundlerRpc = getBundlerRpcUrl(zeroDevProjectId, chainId);
|
|
296
285
|
const paymasterRpc = getPaymasterRpcUrl(zeroDevProjectId, chainId);
|
|
297
286
|
return createKernelAccountClient({
|
|
@@ -299,67 +288,69 @@ export async function createKernelClient(kernelAccount, chainId, zeroDevProjectI
|
|
|
299
288
|
chain: getChain(chainId),
|
|
300
289
|
bundlerTransport: http(bundlerRpc),
|
|
301
290
|
client: publicClient,
|
|
302
|
-
...
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
291
|
+
...isRelayerMode() ? {} : {
|
|
292
|
+
paymaster: {
|
|
293
|
+
getPaymasterData: (userOperation)=>{
|
|
294
|
+
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
295
|
+
chain: getChain(chainId),
|
|
296
|
+
transport: http(paymasterRpc)
|
|
297
|
+
});
|
|
298
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
299
|
+
userOperation
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
},
|
|
315
304
|
userOperation: {
|
|
316
|
-
estimateFeesPerGas: async ({ bundlerClient })
|
|
305
|
+
estimateFeesPerGas: async ({ bundlerClient })=>{
|
|
317
306
|
return estimateUserOperationFees(bundlerClient, publicClient);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
320
309
|
});
|
|
321
310
|
}
|
|
322
311
|
export async function createKernelSmartAccount(signer, publicClient) {
|
|
323
312
|
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
|
|
324
313
|
signer: signer,
|
|
325
314
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
326
|
-
kernelVersion: KERNEL_V3_1
|
|
315
|
+
kernelVersion: KERNEL_V3_1
|
|
327
316
|
});
|
|
328
317
|
return await createKernelAccount(publicClient, {
|
|
329
318
|
plugins: {
|
|
330
|
-
sudo: ecdsaValidator
|
|
319
|
+
sudo: ecdsaValidator
|
|
331
320
|
},
|
|
332
321
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
333
|
-
kernelVersion: KERNEL_V3_1
|
|
322
|
+
kernelVersion: KERNEL_V3_1
|
|
334
323
|
});
|
|
335
324
|
}
|
|
336
325
|
export async function getApproval(signer, publicClient, policies) {
|
|
337
326
|
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
|
|
338
327
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
339
328
|
signer,
|
|
340
|
-
kernelVersion: KERNEL_V3_1
|
|
329
|
+
kernelVersion: KERNEL_V3_1
|
|
341
330
|
});
|
|
342
331
|
const emptyAccount = addressToEmptyAccount(signer.address);
|
|
343
|
-
const emptySessionKeySigner = await toECDSASigner({
|
|
332
|
+
const emptySessionKeySigner = await toECDSASigner({
|
|
333
|
+
signer: emptyAccount
|
|
334
|
+
});
|
|
344
335
|
const permissionPlugin = await toPermissionValidator(publicClient, {
|
|
345
336
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
346
337
|
signer: emptySessionKeySigner,
|
|
347
338
|
policies: policies,
|
|
348
|
-
kernelVersion: KERNEL_V3_1
|
|
339
|
+
kernelVersion: KERNEL_V3_1
|
|
349
340
|
});
|
|
350
341
|
const sessionKeyAccount = await createKernelAccount(publicClient, {
|
|
351
342
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
352
343
|
plugins: {
|
|
353
344
|
sudo: ecdsaValidator,
|
|
354
|
-
regular: permissionPlugin
|
|
345
|
+
regular: permissionPlugin
|
|
355
346
|
},
|
|
356
|
-
kernelVersion: KERNEL_V3_1
|
|
347
|
+
kernelVersion: KERNEL_V3_1
|
|
357
348
|
});
|
|
358
349
|
return await serializePermissionAccount(sessionKeyAccount);
|
|
359
350
|
}
|
|
360
351
|
export async function useSessionKey(approval, signer, publicClient) {
|
|
361
352
|
const sessionKeySigner = await toECDSASigner({
|
|
362
|
-
signer
|
|
353
|
+
signer
|
|
363
354
|
});
|
|
364
355
|
const sessionKeyAccount = await deserializePermissionAccount(publicClient, getEntryPoint(ENTRY_POINT_VERSION), KERNEL_V3_1, approval, sessionKeySigner);
|
|
365
356
|
return sessionKeyAccount;
|
|
@@ -368,26 +359,26 @@ export async function createSessionKey(signer, publicClient, policies) {
|
|
|
368
359
|
const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
|
|
369
360
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
370
361
|
signer,
|
|
371
|
-
kernelVersion: KERNEL_V3_1
|
|
362
|
+
kernelVersion: KERNEL_V3_1
|
|
372
363
|
});
|
|
373
364
|
const sessionPrivateKey = generatePrivateKey();
|
|
374
365
|
const masterAccount = privateKeyToAccount(sessionPrivateKey);
|
|
375
366
|
const sessionKeySigner = await toECDSASigner({
|
|
376
|
-
signer: masterAccount
|
|
367
|
+
signer: masterAccount
|
|
377
368
|
});
|
|
378
369
|
const permissionPlugin = await toPermissionValidator(publicClient, {
|
|
379
370
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
380
371
|
signer: sessionKeySigner,
|
|
381
372
|
policies: policies,
|
|
382
|
-
kernelVersion: KERNEL_V3_1
|
|
373
|
+
kernelVersion: KERNEL_V3_1
|
|
383
374
|
});
|
|
384
375
|
const sessionKeyAccount = await createKernelAccount(publicClient, {
|
|
385
376
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
386
377
|
plugins: {
|
|
387
378
|
sudo: ecdsaValidator,
|
|
388
|
-
regular: permissionPlugin
|
|
379
|
+
regular: permissionPlugin
|
|
389
380
|
},
|
|
390
|
-
kernelVersion: KERNEL_V3_1
|
|
381
|
+
kernelVersion: KERNEL_V3_1
|
|
391
382
|
});
|
|
392
383
|
return serializePermissionAccount(sessionKeyAccount, sessionPrivateKey);
|
|
393
384
|
}
|
|
@@ -404,19 +395,20 @@ export async function getSessionKey(serializedSessionKey, publicClient) {
|
|
|
404
395
|
* @param publicClient Viem PublicClient instance
|
|
405
396
|
* @param policies Array of policies to enforce for this session key
|
|
406
397
|
* @returns Serialized session key string
|
|
407
|
-
*/
|
|
408
|
-
export async function createDelegatedSessionKeyFromKernel(kernelAccount, publicClient, policies) {
|
|
398
|
+
*/ export async function createDelegatedSessionKeyFromKernel(kernelAccount, publicClient, policies) {
|
|
409
399
|
// 1) Generate ephemeral session private key (used only for the permission plugin)
|
|
410
400
|
const sessionPrivateKey = generatePrivateKey();
|
|
411
401
|
const sessionAccount = privateKeyToAccount(sessionPrivateKey);
|
|
412
402
|
// 2) Wrap ephemeral key as ECDSA signer for permissions
|
|
413
|
-
const sessionKeySigner = await toECDSASigner({
|
|
403
|
+
const sessionKeySigner = await toECDSASigner({
|
|
404
|
+
signer: sessionAccount
|
|
405
|
+
});
|
|
414
406
|
// 3) Create the permission validator plugin
|
|
415
407
|
const permissionValidator = await toPermissionValidator(publicClient, {
|
|
416
408
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
417
409
|
signer: sessionKeySigner,
|
|
418
410
|
policies,
|
|
419
|
-
kernelVersion: KERNEL_V3_1
|
|
411
|
+
kernelVersion: KERNEL_V3_1
|
|
420
412
|
});
|
|
421
413
|
// 4) Extract the sudo validator from the existing kernel account
|
|
422
414
|
const kernelAccountTyped = kernelAccount;
|
|
@@ -428,10 +420,10 @@ export async function createDelegatedSessionKeyFromKernel(kernelAccount, publicC
|
|
|
428
420
|
const sessionKeyAccount = await createKernelAccount(publicClient, {
|
|
429
421
|
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
430
422
|
plugins: {
|
|
431
|
-
sudo: sudoValidator,
|
|
432
|
-
regular: permissionValidator
|
|
423
|
+
sudo: sudoValidator,
|
|
424
|
+
regular: permissionValidator
|
|
433
425
|
},
|
|
434
|
-
kernelVersion: KERNEL_V3_1
|
|
426
|
+
kernelVersion: KERNEL_V3_1
|
|
435
427
|
});
|
|
436
428
|
// 6) Serialize the session key account with the ephemeral private key
|
|
437
429
|
const serialized = await serializePermissionAccount(sessionKeyAccount, sessionPrivateKey);
|
|
@@ -441,5 +433,7 @@ export const WalletUtils = {
|
|
|
441
433
|
makeWallet,
|
|
442
434
|
makeWallets,
|
|
443
435
|
makeRandomWallet,
|
|
444
|
-
makeRandomWallets
|
|
436
|
+
makeRandomWallets
|
|
445
437
|
};
|
|
438
|
+
|
|
439
|
+
//# sourceMappingURL=BlockchainViemUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/nevermined/utils/BlockchainViemUtils.ts"],"sourcesContent":["import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator'\nimport {\n deserializePermissionAccount,\n serializePermissionAccount,\n toPermissionValidator,\n} from '@zerodev/permissions'\nimport { toECDSASigner } from '@zerodev/permissions/signers'\nimport {\n addressToEmptyAccount,\n createKernelAccount,\n createKernelAccountClient,\n createZeroDevPaymasterClient,\n getUserOperationGasPrice,\n KernelAccountClient,\n type KernelSmartAccountImplementation,\n} from '@zerodev/sdk'\nimport { KERNEL_V3_1, getEntryPoint } from '@zerodev/sdk/constants'\nimport {\n Address,\n encodeAbiParameters,\n getAbiItem,\n getAddress,\n getContract,\n http,\n isAddress,\n pad,\n stringToBytes,\n stringToHex,\n toBytes,\n keccak256 as viemKeccak256,\n type Abi,\n type AbiEvent,\n type AbiFunction,\n type Account,\n type PublicClient,\n type TransactionReceipt,\n} from 'viem'\nimport { SmartAccount } from 'viem/account-abstraction'\nimport {\n english,\n generateMnemonic,\n generatePrivateKey,\n mnemonicToAccount,\n privateKeyToAccount,\n} from 'viem/accounts'\nimport { Instantiable, InstantiableConfig, Web3Clients } from '../../Instantiable.abstract.js'\nimport { ContractsError } from '../../errors/NeverminedErrors.js'\nimport { getChain } from '../../utils/Network.js'\nimport { Signer } from '@zerodev/sdk/types'\n\nconst ENTRY_POINT_VERSION = '0.7'\n\n/**\n * Utility class with methods that allow the interaction with the blockchain.\n * This class uses Viem library to interact with the blockchain.\n */\nexport class BlockchainViemUtils extends Instantiable {\n constructor(config: InstantiableConfig) {\n super()\n this.setInstanceConfig(config)\n }\n}\n\n//////////////////////////\n///// UTILITIES //////////\n//////////////////////////\n\n///// CONTRACTS\n\n// Wait budget for an L2 block to be mined and the receipt to surface.\n// Base / Base Sepolia block time is ~2s; 30s ≈ 15 blocks of headroom.\nconst TRANSACTION_RECEIPT_TIMEOUT_MS = 30_000\nconst TRANSACTION_RECEIPT_POLLING_INTERVAL_MS = 1_500\n\n/**\n * Given a transaction hash, it returns the transaction receipt.\n * Uses viem's `waitForTransactionReceipt` which polls until the receipt is\n * available, retrying on `TransactionReceiptNotFoundError` and handling\n * tx-replacement / reorgs natively.\n * @param txHash - the transaction hash\n * @returns the transaction receipt\n */\nexport async function getTransactionReceipt({\n txHash,\n publicClient,\n}: {\n txHash: `0x${string}`\n publicClient: PublicClient\n iteration?: number\n}): Promise<TransactionReceipt> {\n try {\n return await publicClient.waitForTransactionReceipt({\n hash: txHash,\n timeout: TRANSACTION_RECEIPT_TIMEOUT_MS,\n pollingInterval: TRANSACTION_RECEIPT_POLLING_INTERVAL_MS,\n confirmations: 1,\n })\n } catch (error) {\n throw new ContractsError(\n `Unable to get transaction receipt with hash: ${txHash}. Error: ${error}`,\n )\n }\n}\n\n/**\n * Given an already deployed contract address and the ABI, it returns the contract instance.\n *\n * @param contractAddress - the contract address\n * @param abi - the contract artifact\n * @param client - the client to interact with the blockchain\n * @returns a contract instance\n */\nexport async function getContractInstance(contractAddress: string, abi: Abi, client: Web3Clients) {\n return getContract({\n abi,\n address: contractAddress as `0x${string}`,\n client: { wallet: client.wallet, public: client.public },\n })\n}\n\n///// ABIs\n\n/**\n * It searchs an ABI function in the ABI.\n * @param abi the ABI of the contract\n * @param funcName the function name\n * @param args the args of the function\n * @returns the function found\n */\nexport function searchAbiFunction(abi: Abi, funcName: string, args: any[] = []): AbiFunction {\n const func = getAbiItem({ abi, name: funcName, args })\n if (!func || func.type !== 'function') {\n throw new ContractsError(`Function \"${funcName}\" is not part of contract`)\n }\n return func as AbiFunction\n}\n\n/**\n * It searchs an ABI event in the ABI.\n * @param abi the ABI of the contract\n * @param funcName the event name\n * @returns the event found\n */\nexport function searchAbiEvent(abi: Abi, eventName: string): AbiEvent {\n const event = getAbiItem({\n abi,\n name: eventName,\n })\n if (!event || event.type !== 'event') {\n throw new ContractsError(`Event \"${event}\" is not part of contract`)\n }\n return event as AbiEvent\n}\n\n/**\n * It searchs an ABI function in the ABI.\n * @param abi the ABI of the contract\n * @param funcName the function name\n * @param args the args of the function\n * @returns the function found\n */\nexport function getSignatureOfFunction(abi: Abi, funcName: string, args: any[] = []): AbiFunction {\n return searchAbiFunction(abi, funcName, args)\n}\n\n/**\n * It searchs an ABI function in the ABI and return the inputs.\n * @param abi the ABI of the contract\n * @param funcName the function name\n * @param args the args of the function\n * @returns the function found\n */\nexport function getInputsOfFunction(abi: Abi, funcName: string, args: any[] = []) {\n return searchAbiFunction(abi, funcName, args).inputs\n}\n\n/**\n * It searchs an ABI function in the ABI and return the inputs formatted.\n * @param abi the ABI of the contract\n * @param funcName the function name\n * @param args the args of the function\n * @returns the function found\n */\nexport function getInputsOfFunctionFormatted(abi: Abi, funcName: string, args: any[] = []) {\n return searchAbiFunction(abi, funcName, args).inputs.map((input, i) => {\n return {\n name: input.name,\n value: args[i],\n }\n })\n}\n\n//////// UTILS\n\n/**\n * Given an address it returns that address in checksum format.\n * @param address the address\n * @returns the same address in checksum format\n */\nexport function getChecksumAddress(address: string): string {\n return getAddress(address)\n}\n\n/**\n * It checks if the address is a valid address.\n * @param address the address to check\n * @returns true of the address is valid\n */\nexport function isValidAddress(address: string): boolean {\n return isAddress(address)\n}\n\n/**\n * Encodes a UTF-8 string into a byte array.\n\n * @param message the string to encode\n * @returns the encoded byte array\n */\nexport function getBytes(message: string): Uint8Array {\n return stringToBytes(message)\n}\n\n/**\n * It pads a value with zeros.\n * @param value the value to pad\n * @param length the expected longitutde of the value\n * @returns the padded value\n */\nexport function zeroPadValue(value: `0x${string}` | Uint8Array, length: number): string {\n return pad(value, { size: length }) as `0x${string}`\n}\n\n/**\n * Encodes a UTF-8 string into a hex string\n * @param message the string to encode\n * @returns the hex string\n */\nexport function encodeBytes32String(message: string) {\n return stringToHex(message, { size: 32 })\n}\n\n////// ACCOUNTS\n/**\n * Given a seedphrase, it returns an account.\n * @param seedphrase - the seedphrase to be used to generate the account\n * @param addressIndex - the address index\n * @returns an account\n */\nexport function makeWallet(seedphrase: string, addressIndex = 0): Account {\n return mnemonicToAccount(seedphrase, { addressIndex })\n}\n\n/**\n * Given a seedphrase generates multiple accounts\n * @param seedphrase - the seedphrase to be used to generate the account\n * @param numAccounts - the number of accounts to create\n * @returns the array of accounts\n */\nexport function makeWallets(seedphrase: string, numAccounts = 10) {\n const accounts: Account[] = []\n for (let i = 0; i < numAccounts; i++) {\n accounts.push(makeWallet(seedphrase, i))\n }\n return accounts\n}\n\n/**\n * It generates a random account.\n * @returns a new account\n */\nexport function makeRandomWallet(): Account {\n const mnemonic = generateMnemonic(english)\n return makeWallet(mnemonic)\n}\n\n/**\n * It generates a list of random accounts\n * @param numAccounts - the number of accounts to create\n * @returns the array of accounts\n */\nexport function makeRandomWallets(numAccounts = 10): Account[] {\n const mnemonic = generateMnemonic(english)\n return makeWallets(mnemonic, numAccounts)\n}\n\n/////// HASHES\n\n/**\n * It hashes a string using keccak256.\n * @param seed the string to hash\n * @returns the hash\n */\nexport function keccak256(seed: string): string {\n return viemKeccak256(toBytes(seed))\n}\n\n/**\n * It encodes and hashes a list of primitive values into an ABI-encoded hex value.\n * @param types the types of the values\n * @param values the values to encode\n * @returns the hash\n */\nexport function keccak256WithEncode(types: any[], values: any[]): string {\n const encoded = encodeAbiParameters(types, values as never)\n return keccak256(encoded)\n}\n\n/**\n * It encodes and hashes a list of primitive values into an ABI-encoded hex value.\n * @param types the types of the values\n * @param values the values to encode\n * @returns the hash\n */\nexport function keccak256Packed(types: any[], values: any[]): string {\n return keccak256WithEncode(types, values)\n}\n\n/////// ZERO DEV\n\n/**\n * Returns the bundler RPC URL. When `BUNDLER_RPC_URL_OVERRIDE` is set\n * (used by tests against a local Alto + anvil-fork stack), it takes precedence\n * over the canonical ZeroDev URL.\n */\nexport function getBundlerRpcUrl(zeroDevProjectId: string, chainId: number): string {\n // `||` (not `??`) because Vite replaces missing browser env vars with the\n // empty string at build time; an empty override is equivalent to \"no\n // override\" for our purposes.\n return (\n process.env.BUNDLER_RPC_URL_OVERRIDE ||\n `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`\n )\n}\n\n/**\n * Returns the paymaster RPC URL (ZeroDev-only; the local fork stack uses\n * `ultra-relay` which sponsors via the bundler's executor key without a\n * paymaster, so this URL is not consulted when `BUNDLER_RPC_URL_OVERRIDE` is\n * set).\n */\nexport function getPaymasterRpcUrl(zeroDevProjectId: string, chainId: number): string {\n return `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`\n}\n\n/**\n * Returns true when the kernel client should run in \"relayer mode\" — no\n * paymaster, gas fees zeroed out. Used by tests against a local\n * `ultra-relay` (ZeroDev's fork of Alto) on top of an anvil-fork. The relayer's\n * executor key pays gas directly via `EntryPoint.handleOps`, avoiding the\n * paymaster sponsorship handshake altogether.\n */\nexport function isRelayerMode(): boolean {\n return Boolean(process.env.BUNDLER_RPC_URL_OVERRIDE)\n}\n\n/**\n * Returns gas prices for UserOperation fee estimation. ZeroDev's bundler\n * exposes a custom `zd_getUserOperationGasPrice` method; standard ERC-4337\n * bundlers do not. In relayer mode the bundler accepts UserOps with zeroed\n * `maxFeePerGas`/`maxPriorityFeePerGas` and pays gas itself.\n */\nexport async function estimateUserOperationFees(\n bundlerClient: any,\n _publicClient: any,\n): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }> {\n if (isRelayerMode()) {\n return { maxFeePerGas: 0n, maxPriorityFeePerGas: 0n }\n }\n return getUserOperationGasPrice(bundlerClient)\n}\n\n/**\n * It creates a ZeroDev Kernel client.\n * @param signer the signer account\n * @param chainId the chain id\n * @param zeroDevProjectId the zero dev project id, you can get it from the ZeroDev dashboard\n * @returns the kernel client\n */\nexport async function createKernelClient(\n kernelAccount: SmartAccount,\n chainId: number,\n zeroDevProjectId: string,\n publicClient: any,\n): Promise<KernelAccountClient> {\n const bundlerRpc = getBundlerRpcUrl(zeroDevProjectId, chainId)\n const paymasterRpc = getPaymasterRpcUrl(zeroDevProjectId, chainId)\n\n return createKernelAccountClient({\n account: kernelAccount,\n chain: getChain(chainId),\n bundlerTransport: http(bundlerRpc),\n client: publicClient,\n ...(isRelayerMode()\n ? {}\n : {\n paymaster: {\n getPaymasterData: (userOperation: any) => {\n const zerodevPaymaster = createZeroDevPaymasterClient({\n chain: getChain(chainId),\n transport: http(paymasterRpc),\n })\n return zerodevPaymaster.sponsorUserOperation({ userOperation })\n },\n },\n }),\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) => {\n return estimateUserOperationFees(bundlerClient, publicClient)\n },\n },\n })\n}\n\nexport async function createKernelSmartAccount(\n signer: Signer,\n publicClient: PublicClient,\n): Promise<SmartAccount> {\n const ecdsaValidator = await signerToEcdsaValidator(publicClient, {\n signer: signer,\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n kernelVersion: KERNEL_V3_1,\n })\n\n return await createKernelAccount(publicClient, {\n plugins: {\n sudo: ecdsaValidator,\n },\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n kernelVersion: KERNEL_V3_1,\n })\n}\n\nexport async function getApproval(signer: Signer, publicClient: any, policies: any[]) {\n const ecdsaValidator = await signerToEcdsaValidator(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n signer,\n kernelVersion: KERNEL_V3_1,\n })\n const emptyAccount = addressToEmptyAccount(signer.address as Address)\n const emptySessionKeySigner = await toECDSASigner({ signer: emptyAccount })\n\n const permissionPlugin = await toPermissionValidator(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n signer: emptySessionKeySigner,\n policies: policies,\n kernelVersion: KERNEL_V3_1,\n })\n const sessionKeyAccount = await createKernelAccount(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n plugins: {\n sudo: ecdsaValidator,\n regular: permissionPlugin,\n },\n kernelVersion: KERNEL_V3_1,\n })\n\n return await serializePermissionAccount(sessionKeyAccount)\n}\n\nexport async function useSessionKey(approval: string, signer: Signer, publicClient: any) {\n const sessionKeySigner = await toECDSASigner({\n signer,\n })\n const sessionKeyAccount = await deserializePermissionAccount(\n publicClient,\n getEntryPoint(ENTRY_POINT_VERSION),\n KERNEL_V3_1,\n approval,\n sessionKeySigner,\n )\n\n return sessionKeyAccount\n}\n\nexport async function createSessionKey(signer: Signer, publicClient: any, policies: any[]) {\n const ecdsaValidator = await signerToEcdsaValidator(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n signer,\n kernelVersion: KERNEL_V3_1,\n })\n const sessionPrivateKey = generatePrivateKey()\n const masterAccount = privateKeyToAccount(sessionPrivateKey)\n const sessionKeySigner = await toECDSASigner({\n signer: masterAccount,\n })\n\n const permissionPlugin = await toPermissionValidator(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n signer: sessionKeySigner,\n policies: policies,\n kernelVersion: KERNEL_V3_1,\n })\n\n const sessionKeyAccount = await createKernelAccount(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n plugins: {\n sudo: ecdsaValidator,\n regular: permissionPlugin,\n },\n kernelVersion: KERNEL_V3_1,\n })\n\n return serializePermissionAccount(sessionKeyAccount, sessionPrivateKey)\n}\n\nexport async function getSessionKey(serializedSessionKey: string, publicClient: any) {\n const sessionKeyAccount = await deserializePermissionAccount(\n publicClient,\n getEntryPoint(ENTRY_POINT_VERSION),\n KERNEL_V3_1,\n serializedSessionKey,\n )\n\n return sessionKeyAccount\n}\n\n/**\n * Creates a delegated session key for an existing kernel account.\n * The resulting serialized session key can be deserialized into a SmartAccount\n * that shares the same address as the kernel account but enforces the given policies.\n *\n * @param kernelAccount The existing SmartAccount (kernel) to delegate from\n * @param publicClient Viem PublicClient instance\n * @param policies Array of policies to enforce for this session key\n * @returns Serialized session key string\n */\nexport async function createDelegatedSessionKeyFromKernel(\n kernelAccount: SmartAccount,\n publicClient: PublicClient,\n policies: any[],\n): Promise<string> {\n // 1) Generate ephemeral session private key (used only for the permission plugin)\n const sessionPrivateKey = generatePrivateKey()\n const sessionAccount = privateKeyToAccount(sessionPrivateKey)\n\n // 2) Wrap ephemeral key as ECDSA signer for permissions\n const sessionKeySigner = await toECDSASigner({ signer: sessionAccount })\n\n // 3) Create the permission validator plugin\n const permissionValidator = await toPermissionValidator(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n signer: sessionKeySigner,\n policies,\n kernelVersion: KERNEL_V3_1,\n })\n\n // 4) Extract the sudo validator from the existing kernel account\n const kernelAccountTyped = kernelAccount as SmartAccount<KernelSmartAccountImplementation>\n const sudoValidator = kernelAccountTyped.kernelPluginManager.sudoValidator\n\n if (!sudoValidator) {\n throw new Error('Kernel account does not have a sudo validator')\n }\n\n // 5) Create a new kernel account with both sudo (from original) and permission validator\n const sessionKeyAccount = await createKernelAccount(publicClient, {\n entryPoint: getEntryPoint(ENTRY_POINT_VERSION),\n plugins: {\n sudo: sudoValidator, // Use existing sudo validator\n regular: permissionValidator,\n },\n kernelVersion: KERNEL_V3_1,\n })\n\n // 6) Serialize the session key account with the ephemeral private key\n const serialized = await serializePermissionAccount(sessionKeyAccount, sessionPrivateKey)\n\n return serialized\n}\n\nexport const WalletUtils = {\n makeWallet,\n makeWallets,\n makeRandomWallet,\n makeRandomWallets,\n}\n"],"names":["signerToEcdsaValidator","deserializePermissionAccount","serializePermissionAccount","toPermissionValidator","toECDSASigner","addressToEmptyAccount","createKernelAccount","createKernelAccountClient","createZeroDevPaymasterClient","getUserOperationGasPrice","KERNEL_V3_1","getEntryPoint","encodeAbiParameters","getAbiItem","getAddress","getContract","http","isAddress","pad","stringToBytes","stringToHex","toBytes","keccak256","viemKeccak256","english","generateMnemonic","generatePrivateKey","mnemonicToAccount","privateKeyToAccount","Instantiable","ContractsError","getChain","ENTRY_POINT_VERSION","BlockchainViemUtils","config","setInstanceConfig","TRANSACTION_RECEIPT_TIMEOUT_MS","TRANSACTION_RECEIPT_POLLING_INTERVAL_MS","getTransactionReceipt","txHash","publicClient","waitForTransactionReceipt","hash","timeout","pollingInterval","confirmations","error","getContractInstance","contractAddress","abi","client","address","wallet","public","searchAbiFunction","funcName","args","func","name","type","searchAbiEvent","eventName","event","getSignatureOfFunction","getInputsOfFunction","inputs","getInputsOfFunctionFormatted","map","input","i","value","getChecksumAddress","isValidAddress","getBytes","message","zeroPadValue","length","size","encodeBytes32String","makeWallet","seedphrase","addressIndex","makeWallets","numAccounts","accounts","push","makeRandomWallet","mnemonic","makeRandomWallets","seed","keccak256WithEncode","types","values","encoded","keccak256Packed","getBundlerRpcUrl","zeroDevProjectId","chainId","process","env","BUNDLER_RPC_URL_OVERRIDE","getPaymasterRpcUrl","isRelayerMode","Boolean","estimateUserOperationFees","bundlerClient","_publicClient","maxFeePerGas","maxPriorityFeePerGas","createKernelClient","kernelAccount","bundlerRpc","paymasterRpc","account","chain","bundlerTransport","paymaster","getPaymasterData","userOperation","zerodevPaymaster","transport","sponsorUserOperation","estimateFeesPerGas","createKernelSmartAccount","signer","ecdsaValidator","entryPoint","kernelVersion","plugins","sudo","getApproval","policies","emptyAccount","emptySessionKeySigner","permissionPlugin","sessionKeyAccount","regular","useSessionKey","approval","sessionKeySigner","createSessionKey","sessionPrivateKey","masterAccount","getSessionKey","serializedSessionKey","createDelegatedSessionKeyFromKernel","sessionAccount","permissionValidator","kernelAccountTyped","sudoValidator","kernelPluginManager","Error","serialized","WalletUtils"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,2BAA0B;AACjE,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,qBAAqB,QAChB,uBAAsB;AAC7B,SAASC,aAAa,QAAQ,+BAA8B;AAC5D,SACEC,qBAAqB,EACrBC,mBAAmB,EACnBC,yBAAyB,EACzBC,4BAA4B,EAC5BC,wBAAwB,QAGnB,eAAc;AACrB,SAASC,WAAW,EAAEC,aAAa,QAAQ,yBAAwB;AACnE,SAEEC,mBAAmB,EACnBC,UAAU,EACVC,UAAU,EACVC,WAAW,EACXC,IAAI,EACJC,SAAS,EACTC,GAAG,EACHC,aAAa,EACbC,WAAW,EACXC,OAAO,EACPC,aAAaC,aAAa,QAOrB,OAAM;AAEb,SACEC,OAAO,EACPC,gBAAgB,EAChBC,kBAAkB,EAClBC,iBAAiB,EACjBC,mBAAmB,QACd,gBAAe;AACtB,SAASC,YAAY,QAAyC,iCAAgC;AAC9F,SAASC,cAAc,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