@metamask/smart-accounts-kit 0.1.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.APACHE2 +201 -0
  3. package/LICENSE.MIT0 +16 -0
  4. package/README.md +77 -0
  5. package/dist/actions/index.cjs +39 -0
  6. package/dist/actions/index.cjs.map +1 -0
  7. package/dist/actions/index.d.cts +8 -0
  8. package/dist/actions/index.d.ts +8 -0
  9. package/dist/actions/index.mjs +39 -0
  10. package/dist/actions/index.mjs.map +1 -0
  11. package/dist/chunk-2EIX7ZYT.cjs +1325 -0
  12. package/dist/chunk-2EIX7ZYT.cjs.map +1 -0
  13. package/dist/chunk-662KDAAG.cjs +831 -0
  14. package/dist/chunk-662KDAAG.cjs.map +1 -0
  15. package/dist/chunk-6RN5RBOR.mjs +1325 -0
  16. package/dist/chunk-6RN5RBOR.mjs.map +1 -0
  17. package/dist/chunk-7MRTROLV.mjs +274 -0
  18. package/dist/chunk-7MRTROLV.mjs.map +1 -0
  19. package/dist/chunk-BFDBNFIP.cjs +336 -0
  20. package/dist/chunk-BFDBNFIP.cjs.map +1 -0
  21. package/dist/chunk-CPLIK3VF.mjs +77 -0
  22. package/dist/chunk-CPLIK3VF.mjs.map +1 -0
  23. package/dist/chunk-D4ILRL6Z.cjs +299 -0
  24. package/dist/chunk-D4ILRL6Z.cjs.map +1 -0
  25. package/dist/chunk-HD4O6IVC.cjs +274 -0
  26. package/dist/chunk-HD4O6IVC.cjs.map +1 -0
  27. package/dist/chunk-HLCOMYYU.cjs +1472 -0
  28. package/dist/chunk-HLCOMYYU.cjs.map +1 -0
  29. package/dist/chunk-KUEXI4ME.mjs +299 -0
  30. package/dist/chunk-KUEXI4ME.mjs.map +1 -0
  31. package/dist/chunk-MVKT5CLQ.mjs +336 -0
  32. package/dist/chunk-MVKT5CLQ.mjs.map +1 -0
  33. package/dist/chunk-RB4SOJM3.mjs +729 -0
  34. package/dist/chunk-RB4SOJM3.mjs.map +1 -0
  35. package/dist/chunk-T6PSFUOZ.cjs +77 -0
  36. package/dist/chunk-T6PSFUOZ.cjs.map +1 -0
  37. package/dist/chunk-TEI2NRPU.mjs +831 -0
  38. package/dist/chunk-TEI2NRPU.mjs.map +1 -0
  39. package/dist/chunk-UUDQWENY.mjs +1472 -0
  40. package/dist/chunk-UUDQWENY.mjs.map +1 -0
  41. package/dist/chunk-WA2O2K3K.cjs +729 -0
  42. package/dist/chunk-WA2O2K3K.cjs.map +1 -0
  43. package/dist/contracts/index.cjs +57 -0
  44. package/dist/contracts/index.cjs.map +1 -0
  45. package/dist/contracts/index.d.cts +8 -0
  46. package/dist/contracts/index.d.ts +8 -0
  47. package/dist/contracts/index.mjs +57 -0
  48. package/dist/contracts/index.mjs.map +1 -0
  49. package/dist/delegation-7PtFix8Y.d.ts +376 -0
  50. package/dist/delegation-d52Owevd.d.cts +376 -0
  51. package/dist/experimental/index.cjs +143 -0
  52. package/dist/experimental/index.cjs.map +1 -0
  53. package/dist/experimental/index.d.cts +29 -0
  54. package/dist/experimental/index.d.ts +29 -0
  55. package/dist/experimental/index.mjs +143 -0
  56. package/dist/experimental/index.mjs.map +1 -0
  57. package/dist/index-0-B0YlEP.d.cts +21935 -0
  58. package/dist/index-18Alar1P.d.ts +1174 -0
  59. package/dist/index-CLkk7zr4.d.cts +1174 -0
  60. package/dist/index-D1WbhKCc.d.ts +21935 -0
  61. package/dist/index.cjs +424 -0
  62. package/dist/index.cjs.map +1 -0
  63. package/dist/index.d.cts +56 -0
  64. package/dist/index.d.ts +56 -0
  65. package/dist/index.mjs +424 -0
  66. package/dist/index.mjs.map +1 -0
  67. package/dist/smartAccountsEnvironment-BOhrxEnt.d.ts +12 -0
  68. package/dist/smartAccountsEnvironment-SVknZ_3f.d.cts +12 -0
  69. package/dist/types-Bwksz_U6.d.cts +136 -0
  70. package/dist/types-Bwksz_U6.d.ts +136 -0
  71. package/dist/userOp-CFv4wNkl.d.cts +33 -0
  72. package/dist/userOp-CFv4wNkl.d.ts +33 -0
  73. package/dist/utils/index.cjs +60 -0
  74. package/dist/utils/index.cjs.map +1 -0
  75. package/dist/utils/index.d.cts +47 -0
  76. package/dist/utils/index.d.ts +47 -0
  77. package/dist/utils/index.mjs +60 -0
  78. package/dist/utils/index.mjs.map +1 -0
  79. package/package.json +151 -0
@@ -0,0 +1,729 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+ var _chunkD4ILRL6Zcjs = require('./chunk-D4ILRL6Z.cjs');
8
+
9
+
10
+
11
+ var _chunkBFDBNFIPcjs = require('./chunk-BFDBNFIP.cjs');
12
+
13
+
14
+
15
+ var _chunkT6PSFUOZcjs = require('./chunk-T6PSFUOZ.cjs');
16
+
17
+
18
+
19
+
20
+ var _chunkHLCOMYYUcjs = require('./chunk-HLCOMYYU.cjs');
21
+
22
+ // src/actions/index.ts
23
+ var actions_exports = {};
24
+ _chunkHLCOMYYUcjs.__export.call(void 0, actions_exports, {
25
+ caveatEnforcerActions: () => caveatEnforcerActions,
26
+ erc7710BundlerActions: () => erc7710BundlerActions,
27
+ erc7710WalletActions: () => erc7710WalletActions,
28
+ erc7715ProviderActions: () => erc7715ProviderActions,
29
+ getErc20PeriodTransferEnforcerAvailableAmount: () => getErc20PeriodTransferEnforcerAvailableAmount,
30
+ getErc20StreamingEnforcerAvailableAmount: () => getErc20StreamingEnforcerAvailableAmount,
31
+ getMultiTokenPeriodEnforcerAvailableAmount: () => getMultiTokenPeriodEnforcerAvailableAmount,
32
+ getNativeTokenPeriodTransferEnforcerAvailableAmount: () => getNativeTokenPeriodTransferEnforcerAvailableAmount,
33
+ getNativeTokenStreamingEnforcerAvailableAmount: () => getNativeTokenStreamingEnforcerAvailableAmount,
34
+ isValid7702Implementation: () => isValid7702Implementation,
35
+ requestExecutionPermissions: () => erc7715RequestExecutionPermissionsAction,
36
+ signDelegation: () => signDelegation,
37
+ signDelegationActions: () => signDelegationActions,
38
+ signUserOperation: () => signUserOperation,
39
+ signUserOperationActions: () => signUserOperationActions
40
+ });
41
+
42
+ // src/actions/erc7710RedeemDelegationAction.ts
43
+ var _delegationabis = require('@metamask/delegation-abis');
44
+ var _viem = require('viem');
45
+ async function sendTransactionWithDelegationAction(client, args) {
46
+ if (!args.to) {
47
+ throw new Error(
48
+ "`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts."
49
+ );
50
+ }
51
+ const executions = [
52
+ _chunkT6PSFUOZcjs.createExecution.call(void 0, {
53
+ target: args.to,
54
+ value: args.value,
55
+ callData: args.data
56
+ })
57
+ ];
58
+ const calldata = _viem.encodeFunctionData.call(void 0, {
59
+ abi: _delegationabis.DelegationManager.abi,
60
+ functionName: "redeemDelegations",
61
+ args: [
62
+ [args.permissionsContext],
63
+ ["0x0000000000000000000000000000000000000000000000000000000000000000" /* SingleDefault */],
64
+ _chunkT6PSFUOZcjs.encodeExecutionCalldatas.call(void 0, [executions])
65
+ ]
66
+ });
67
+ const {
68
+ value: _value,
69
+ permissionsContext: _permissionsContext,
70
+ delegationManager: _delegationManager,
71
+ ...rest
72
+ } = args;
73
+ const hash = await client.sendTransaction({
74
+ ...rest,
75
+ to: args.delegationManager,
76
+ data: calldata
77
+ });
78
+ return hash;
79
+ }
80
+ async function sendUserOperationWithDelegationAction(client, parameters) {
81
+ if (parameters.accountMetadata) {
82
+ const { publicClient } = parameters;
83
+ const includedAccountKeys = {};
84
+ const chainId = _optionalChain([publicClient, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]);
85
+ if (!chainId) {
86
+ throw new Error("Chain ID is not set");
87
+ }
88
+ const { SimpleFactory } = _chunkBFDBNFIPcjs.getSmartAccountsEnvironment.call(void 0, chainId);
89
+ const uniqueAccountMetadatas = parameters.accountMetadata.filter(
90
+ (accountMetadata) => {
91
+ if (!_viem.isAddressEqual.call(void 0, accountMetadata.factory, SimpleFactory)) {
92
+ throw new Error(
93
+ `Invalid accountMetadata: ${accountMetadata.factory} is not allowed.`
94
+ );
95
+ }
96
+ const accountKey = _viem.concat.call(void 0, [
97
+ accountMetadata.factory,
98
+ accountMetadata.factoryData
99
+ ]);
100
+ const isDuplicate = includedAccountKeys[accountKey];
101
+ includedAccountKeys[accountKey] = true;
102
+ return !isDuplicate;
103
+ }
104
+ );
105
+ const factoryCalls = (await Promise.all(
106
+ uniqueAccountMetadatas.map(async ({ factory, factoryData }) => {
107
+ const isDeployed = await publicClient.call({
108
+ to: factory,
109
+ data: factoryData
110
+ }).then(() => false).catch(() => true);
111
+ if (isDeployed) {
112
+ return void 0;
113
+ }
114
+ return {
115
+ to: factory,
116
+ value: 0n,
117
+ data: factoryData
118
+ };
119
+ })
120
+ )).filter((call) => call !== void 0);
121
+ parameters.calls = [
122
+ ...factoryCalls,
123
+ ...parameters.calls
124
+ ];
125
+ }
126
+ return client.sendUserOperation(
127
+ parameters
128
+ );
129
+ }
130
+
131
+ // src/actions/erc7715RequestExecutionPermissionsAction.ts
132
+
133
+ async function erc7715RequestExecutionPermissionsAction(client, parameters) {
134
+ const formattedPermissionRequest = parameters.map(formatPermissionsRequest);
135
+ const result = await client.request(
136
+ {
137
+ method: "wallet_requestExecutionPermissions",
138
+ params: formattedPermissionRequest
139
+ },
140
+ { retryCount: 0 }
141
+ );
142
+ if (!result) {
143
+ throw new Error("Failed to grant permissions");
144
+ }
145
+ return result;
146
+ }
147
+ function formatPermissionsRequest(parameters) {
148
+ const { chainId, address, expiry, isAdjustmentAllowed } = parameters;
149
+ const permissionFormatter = getPermissionFormatter(
150
+ parameters.permission.type
151
+ );
152
+ const signerAddress = typeof parameters.signer === "string" ? parameters.signer : parameters.signer.data.address;
153
+ const rules = [
154
+ {
155
+ type: "expiry",
156
+ isAdjustmentAllowed,
157
+ data: {
158
+ timestamp: expiry
159
+ }
160
+ }
161
+ ];
162
+ const optionalFields = {
163
+ ...address ? { address } : {}
164
+ };
165
+ return {
166
+ ...optionalFields,
167
+ chainId: _viem.toHex.call(void 0, chainId),
168
+ permission: permissionFormatter({
169
+ permission: parameters.permission,
170
+ isAdjustmentAllowed
171
+ }),
172
+ signer: {
173
+ // MetaMask 7715 implementation only supports AccountSigner
174
+ type: "account",
175
+ data: {
176
+ address: signerAddress
177
+ }
178
+ },
179
+ rules
180
+ };
181
+ }
182
+ function isDefined(value) {
183
+ return value !== void 0 && value !== null;
184
+ }
185
+ function assertIsDefined(value, message) {
186
+ if (!isDefined(value)) {
187
+ throw new Error(_nullishCoalesce(message, () => ( "Invalid parameters: value is required")));
188
+ }
189
+ }
190
+ function toHexOrThrow(value, message) {
191
+ assertIsDefined(value, message);
192
+ if (typeof value === "string") {
193
+ if (!_viem.isHex.call(void 0, value)) {
194
+ throw new Error("Invalid parameters: invalid hex value");
195
+ }
196
+ return value;
197
+ }
198
+ return _viem.toHex.call(void 0, value);
199
+ }
200
+ function getPermissionFormatter(permissionType) {
201
+ switch (permissionType) {
202
+ case "native-token-stream":
203
+ return ({ permission, isAdjustmentAllowed }) => formatNativeTokenStreamPermission({
204
+ permission,
205
+ isAdjustmentAllowed
206
+ });
207
+ case "erc20-token-stream":
208
+ return ({ permission, isAdjustmentAllowed }) => formatErc20TokenStreamPermission({
209
+ permission,
210
+ isAdjustmentAllowed
211
+ });
212
+ case "native-token-periodic":
213
+ return ({ permission, isAdjustmentAllowed }) => formatNativeTokenPeriodicPermission({
214
+ permission,
215
+ isAdjustmentAllowed
216
+ });
217
+ case "erc20-token-periodic":
218
+ return ({ permission, isAdjustmentAllowed }) => formatErc20TokenPeriodicPermission({
219
+ permission,
220
+ isAdjustmentAllowed
221
+ });
222
+ default:
223
+ throw new Error(`Unsupported permission type: ${permissionType}`);
224
+ }
225
+ }
226
+ function formatNativeTokenStreamPermission({
227
+ permission,
228
+ isAdjustmentAllowed
229
+ }) {
230
+ const {
231
+ data: {
232
+ initialAmount,
233
+ justification,
234
+ maxAmount,
235
+ startTime,
236
+ amountPerSecond
237
+ }
238
+ } = permission;
239
+ const optionalFields = {
240
+ ...isDefined(initialAmount) && {
241
+ initialAmount: toHexOrThrow(initialAmount)
242
+ },
243
+ ...isDefined(maxAmount) && {
244
+ maxAmount: toHexOrThrow(maxAmount)
245
+ },
246
+ ...isDefined(startTime) && {
247
+ startTime: Number(startTime)
248
+ },
249
+ ...justification ? { justification } : {}
250
+ };
251
+ return {
252
+ type: "native-token-stream",
253
+ data: {
254
+ amountPerSecond: toHexOrThrow(
255
+ amountPerSecond,
256
+ "Invalid parameters: amountPerSecond is required"
257
+ ),
258
+ ...optionalFields
259
+ },
260
+ isAdjustmentAllowed
261
+ };
262
+ }
263
+ function formatErc20TokenStreamPermission({
264
+ permission,
265
+ isAdjustmentAllowed
266
+ }) {
267
+ const {
268
+ data: {
269
+ tokenAddress,
270
+ amountPerSecond,
271
+ initialAmount,
272
+ startTime,
273
+ maxAmount,
274
+ justification
275
+ }
276
+ } = permission;
277
+ const optionalFields = {
278
+ ...isDefined(initialAmount) && {
279
+ initialAmount: toHexOrThrow(initialAmount)
280
+ },
281
+ ...isDefined(maxAmount) && {
282
+ maxAmount: toHexOrThrow(maxAmount)
283
+ },
284
+ ...isDefined(startTime) && {
285
+ startTime: Number(startTime)
286
+ },
287
+ ...justification ? { justification } : {}
288
+ };
289
+ return {
290
+ type: "erc20-token-stream",
291
+ data: {
292
+ tokenAddress: toHexOrThrow(tokenAddress),
293
+ amountPerSecond: toHexOrThrow(amountPerSecond),
294
+ ...optionalFields
295
+ },
296
+ isAdjustmentAllowed
297
+ };
298
+ }
299
+ function formatNativeTokenPeriodicPermission({
300
+ permission,
301
+ isAdjustmentAllowed
302
+ }) {
303
+ const {
304
+ data: { periodAmount, periodDuration, startTime, justification }
305
+ } = permission;
306
+ const optionalFields = {
307
+ ...isDefined(startTime) && {
308
+ startTime: Number(startTime)
309
+ },
310
+ ...justification ? { justification } : {}
311
+ };
312
+ return {
313
+ type: "native-token-periodic",
314
+ data: {
315
+ periodAmount: toHexOrThrow(periodAmount),
316
+ periodDuration: Number(periodDuration),
317
+ ...optionalFields
318
+ },
319
+ isAdjustmentAllowed
320
+ };
321
+ }
322
+ function formatErc20TokenPeriodicPermission({
323
+ permission,
324
+ isAdjustmentAllowed
325
+ }) {
326
+ const {
327
+ data: {
328
+ tokenAddress,
329
+ periodAmount,
330
+ periodDuration,
331
+ startTime,
332
+ justification
333
+ }
334
+ } = permission;
335
+ const optionalFields = {
336
+ ...isDefined(startTime) && {
337
+ startTime: Number(startTime)
338
+ },
339
+ ...justification ? { justification } : {}
340
+ };
341
+ return {
342
+ type: "erc20-token-periodic",
343
+ data: {
344
+ tokenAddress: toHexOrThrow(tokenAddress),
345
+ periodAmount: toHexOrThrow(periodAmount),
346
+ periodDuration: Number(periodDuration),
347
+ ...optionalFields
348
+ },
349
+ isAdjustmentAllowed
350
+ };
351
+ }
352
+
353
+ // src/actions/getCaveatAvailableAmount.ts
354
+ function findMatchingCaveat({
355
+ delegation,
356
+ enforcerAddress,
357
+ enforcerName
358
+ }) {
359
+ const matchingCaveats = delegation.caveats.filter(
360
+ (caveat) => caveat.enforcer.toLowerCase() === enforcerAddress.toLowerCase()
361
+ );
362
+ if (matchingCaveats.length === 0) {
363
+ throw new Error(`No caveat found with enforcer matching ${enforcerName}`);
364
+ }
365
+ if (matchingCaveats.length > 1) {
366
+ throw new Error(
367
+ `Multiple caveats found with enforcer matching ${enforcerName}`
368
+ );
369
+ }
370
+ const [{ terms, args }] = matchingCaveats;
371
+ return {
372
+ terms,
373
+ args
374
+ };
375
+ }
376
+ function getDelegationManager(environment) {
377
+ if (!environment.DelegationManager) {
378
+ throw new Error("Delegation manager address not found");
379
+ }
380
+ return environment.DelegationManager;
381
+ }
382
+ function getEnforcerAddress({
383
+ enforcerName,
384
+ environment
385
+ }) {
386
+ const enforcerAddress = environment.caveatEnforcers[enforcerName];
387
+ if (!enforcerAddress) {
388
+ throw new Error(`${enforcerName} not found in environment`);
389
+ }
390
+ return enforcerAddress;
391
+ }
392
+ async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment, params) {
393
+ const enforcerName = "ERC20PeriodTransferEnforcer";
394
+ const delegationManager = getDelegationManager(environment);
395
+ const enforcerAddress = getEnforcerAddress({
396
+ enforcerName,
397
+ environment
398
+ });
399
+ const delegationHash = _chunkHLCOMYYUcjs.getDelegationHashOffchain.call(void 0, params.delegation);
400
+ const { terms } = findMatchingCaveat({
401
+ delegation: params.delegation,
402
+ enforcerAddress,
403
+ enforcerName
404
+ });
405
+ return _chunkD4ILRL6Zcjs.read_exports.getAvailableAmount({
406
+ client,
407
+ contractAddress: enforcerAddress,
408
+ delegationHash,
409
+ delegationManager,
410
+ terms
411
+ });
412
+ }
413
+ async function getErc20StreamingEnforcerAvailableAmount(client, environment, params) {
414
+ const enforcerName = "ERC20StreamingEnforcer";
415
+ const delegationManager = getDelegationManager(environment);
416
+ const enforcerAddress = getEnforcerAddress({
417
+ enforcerName,
418
+ environment
419
+ });
420
+ const delegationHash = _chunkHLCOMYYUcjs.getDelegationHashOffchain.call(void 0, params.delegation);
421
+ const { terms } = findMatchingCaveat({
422
+ delegation: params.delegation,
423
+ enforcerAddress,
424
+ enforcerName
425
+ });
426
+ return _chunkD4ILRL6Zcjs.read_exports2.getAvailableAmount({
427
+ client,
428
+ contractAddress: enforcerAddress,
429
+ delegationManager,
430
+ delegationHash,
431
+ terms
432
+ });
433
+ }
434
+ async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, params) {
435
+ const enforcerName = "MultiTokenPeriodEnforcer";
436
+ const delegationManager = getDelegationManager(environment);
437
+ const enforcerAddress = getEnforcerAddress({
438
+ enforcerName,
439
+ environment
440
+ });
441
+ const delegationHash = _chunkHLCOMYYUcjs.getDelegationHashOffchain.call(void 0, params.delegation);
442
+ const { terms, args } = findMatchingCaveat({
443
+ delegation: params.delegation,
444
+ enforcerAddress,
445
+ enforcerName
446
+ });
447
+ return _chunkD4ILRL6Zcjs.read_exports3.getAvailableAmount({
448
+ client,
449
+ contractAddress: enforcerAddress,
450
+ delegationHash,
451
+ delegationManager,
452
+ terms,
453
+ args
454
+ });
455
+ }
456
+ async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, environment, params) {
457
+ const enforcerName = "NativeTokenPeriodTransferEnforcer";
458
+ const delegationManager = getDelegationManager(environment);
459
+ const enforcerAddress = getEnforcerAddress({
460
+ enforcerName,
461
+ environment
462
+ });
463
+ const delegationHash = _chunkHLCOMYYUcjs.getDelegationHashOffchain.call(void 0, params.delegation);
464
+ const { terms } = findMatchingCaveat({
465
+ delegation: params.delegation,
466
+ enforcerAddress,
467
+ enforcerName
468
+ });
469
+ return _chunkD4ILRL6Zcjs.read_exports4.getAvailableAmount({
470
+ client,
471
+ contractAddress: enforcerAddress,
472
+ delegationHash,
473
+ delegationManager,
474
+ terms
475
+ });
476
+ }
477
+ async function getNativeTokenStreamingEnforcerAvailableAmount(client, environment, params) {
478
+ const enforcerName = "NativeTokenStreamingEnforcer";
479
+ const delegationManager = getDelegationManager(environment);
480
+ const enforcerAddress = getEnforcerAddress({
481
+ enforcerName,
482
+ environment
483
+ });
484
+ const delegationHash = _chunkHLCOMYYUcjs.getDelegationHashOffchain.call(void 0, params.delegation);
485
+ const { terms } = findMatchingCaveat({
486
+ delegation: params.delegation,
487
+ enforcerAddress,
488
+ enforcerName
489
+ });
490
+ return _chunkD4ILRL6Zcjs.read_exports5.getAvailableAmount({
491
+ client,
492
+ contractAddress: enforcerAddress,
493
+ delegationManager,
494
+ delegationHash,
495
+ terms
496
+ });
497
+ }
498
+ var caveatEnforcerActions = ({ environment }) => (client) => ({
499
+ /**
500
+ * Get available amount for ERC20 period transfer enforcer.
501
+ *
502
+ * @param params - The parameters for the ERC20 period transfer enforcer.
503
+ * @returns Promise resolving to the period transfer result.
504
+ */
505
+ getErc20PeriodTransferEnforcerAvailableAmount: async (params) => {
506
+ return getErc20PeriodTransferEnforcerAvailableAmount(
507
+ client,
508
+ environment,
509
+ params
510
+ );
511
+ },
512
+ /**
513
+ * Get available amount for ERC20 streaming enforcer.
514
+ *
515
+ * @param params - The parameters for the ERC20 streaming enforcer.
516
+ * @returns Promise resolving to the streaming result.
517
+ */
518
+ getErc20StreamingEnforcerAvailableAmount: async (params) => {
519
+ return getErc20StreamingEnforcerAvailableAmount(
520
+ client,
521
+ environment,
522
+ params
523
+ );
524
+ },
525
+ /**
526
+ * Get available amount for multi-token period enforcer.
527
+ *
528
+ * @param params - The parameters for the multi-token period enforcer.
529
+ * @returns Promise resolving to the period transfer result.
530
+ */
531
+ getMultiTokenPeriodEnforcerAvailableAmount: async (params) => {
532
+ return getMultiTokenPeriodEnforcerAvailableAmount(
533
+ client,
534
+ environment,
535
+ params
536
+ );
537
+ },
538
+ /**
539
+ * Get available amount for native token period transfer enforcer.
540
+ *
541
+ * @param params - The parameters for the native token period transfer enforcer.
542
+ * @returns Promise resolving to the period transfer result.
543
+ */
544
+ getNativeTokenPeriodTransferEnforcerAvailableAmount: async (params) => {
545
+ return getNativeTokenPeriodTransferEnforcerAvailableAmount(
546
+ client,
547
+ environment,
548
+ params
549
+ );
550
+ },
551
+ /**
552
+ * Get available amount for native token streaming enforcer.
553
+ *
554
+ * @param params - The parameters for the native token streaming enforcer.
555
+ * @returns Promise resolving to the streaming result.
556
+ */
557
+ getNativeTokenStreamingEnforcerAvailableAmount: async (params) => {
558
+ return getNativeTokenStreamingEnforcerAvailableAmount(
559
+ client,
560
+ environment,
561
+ params
562
+ );
563
+ }
564
+ });
565
+
566
+ // src/actions/isValid7702Implementation.ts
567
+
568
+ var _actions = require('viem/actions');
569
+ var DELEGATION_PREFIX = "0xef0100";
570
+ function extractDelegatedAddress(code) {
571
+ if (_optionalChain([code, 'optionalAccess', _3 => _3.length]) !== 48) {
572
+ return null;
573
+ }
574
+ if (!code.toLowerCase().startsWith(DELEGATION_PREFIX.toLowerCase())) {
575
+ return null;
576
+ }
577
+ const addressHex = code.slice(8);
578
+ return `0x${addressHex}`;
579
+ }
580
+ async function isValid7702Implementation({
581
+ client,
582
+ accountAddress,
583
+ environment
584
+ }) {
585
+ try {
586
+ const code = await _actions.getCode.call(void 0, client, {
587
+ address: accountAddress
588
+ });
589
+ const delegatedAddress = extractDelegatedAddress(code);
590
+ if (!delegatedAddress) {
591
+ return false;
592
+ }
593
+ const expectedImplementation = environment.implementations.EIP7702StatelessDeleGatorImpl;
594
+ if (!expectedImplementation) {
595
+ return false;
596
+ }
597
+ return _viem.isAddressEqual.call(void 0, delegatedAddress, expectedImplementation);
598
+ } catch (error) {
599
+ return false;
600
+ }
601
+ }
602
+
603
+ // src/actions/signDelegation.ts
604
+
605
+ var _accounts = require('viem/accounts');
606
+ async function signDelegation(client, parameters) {
607
+ const {
608
+ account: accountParam = client.account,
609
+ delegation,
610
+ delegationManager,
611
+ chainId,
612
+ name = "DelegationManager",
613
+ version = "1",
614
+ allowInsecureUnrestrictedDelegation = false
615
+ } = parameters;
616
+ if (!accountParam) {
617
+ throw new (0, _viem.BaseError)("Account not found. Please provide an account.");
618
+ }
619
+ const account = _accounts.parseAccount.call(void 0, accountParam);
620
+ const typedData = _chunkHLCOMYYUcjs.prepareSignDelegationTypedData.call(void 0, {
621
+ delegation,
622
+ delegationManager,
623
+ chainId,
624
+ name,
625
+ version,
626
+ allowInsecureUnrestrictedDelegation
627
+ });
628
+ return client.signTypedData({
629
+ account,
630
+ ...typedData
631
+ });
632
+ }
633
+ function signDelegationActions() {
634
+ return (client) => ({
635
+ signDelegation: async (parameters) => signDelegation(client, {
636
+ chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
637
+ if (!_optionalChain([client, 'access', _4 => _4.chain, 'optionalAccess', _5 => _5.id])) {
638
+ throw new (0, _viem.BaseError)(
639
+ "Chain ID is required. Either provide it in parameters or configure the client with a chain."
640
+ );
641
+ }
642
+ return client.chain.id;
643
+ })())),
644
+ ...parameters
645
+ })
646
+ });
647
+ }
648
+
649
+ // src/actions/signUserOperation.ts
650
+
651
+
652
+ async function signUserOperation(client, parameters) {
653
+ const {
654
+ account: accountParam = client.account,
655
+ userOperation,
656
+ entryPoint,
657
+ chainId,
658
+ name,
659
+ address,
660
+ version = "1"
661
+ } = parameters;
662
+ if (!accountParam) {
663
+ throw new (0, _viem.BaseError)("Account not found. Please provide an account.");
664
+ }
665
+ const account = _accounts.parseAccount.call(void 0, accountParam);
666
+ const typedData = _chunkBFDBNFIPcjs.prepareSignUserOperationTypedData.call(void 0, {
667
+ userOperation,
668
+ entryPoint,
669
+ chainId,
670
+ name,
671
+ address,
672
+ version
673
+ });
674
+ return client.signTypedData({
675
+ account,
676
+ ...typedData
677
+ });
678
+ }
679
+ function signUserOperationActions() {
680
+ return (client) => ({
681
+ signUserOperation: async (parameters) => signUserOperation(client, {
682
+ chainId: _nullishCoalesce(parameters.chainId, () => ( (() => {
683
+ if (!_optionalChain([client, 'access', _6 => _6.chain, 'optionalAccess', _7 => _7.id])) {
684
+ throw new (0, _viem.BaseError)(
685
+ "Chain ID is required. Either provide it in parameters or configure the client with a chain."
686
+ );
687
+ }
688
+ return client.chain.id;
689
+ })())),
690
+ ...parameters
691
+ })
692
+ });
693
+ }
694
+
695
+ // src/actions/index.ts
696
+ var erc7715ProviderActions = () => (client) => ({
697
+ requestExecutionPermissions: async (parameters) => {
698
+ return erc7715RequestExecutionPermissionsAction(
699
+ client,
700
+ parameters
701
+ );
702
+ }
703
+ });
704
+ var erc7710WalletActions = () => (client) => ({
705
+ sendTransactionWithDelegation: async (args) => sendTransactionWithDelegationAction(client, args)
706
+ });
707
+ var erc7710BundlerActions = () => (client) => ({
708
+ sendUserOperationWithDelegation: async (args) => sendUserOperationWithDelegationAction(client, args)
709
+ });
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+ exports.isValid7702Implementation = isValid7702Implementation; exports.erc7715RequestExecutionPermissionsAction = erc7715RequestExecutionPermissionsAction; exports.getErc20PeriodTransferEnforcerAvailableAmount = getErc20PeriodTransferEnforcerAvailableAmount; exports.getErc20StreamingEnforcerAvailableAmount = getErc20StreamingEnforcerAvailableAmount; exports.getMultiTokenPeriodEnforcerAvailableAmount = getMultiTokenPeriodEnforcerAvailableAmount; exports.getNativeTokenPeriodTransferEnforcerAvailableAmount = getNativeTokenPeriodTransferEnforcerAvailableAmount; exports.getNativeTokenStreamingEnforcerAvailableAmount = getNativeTokenStreamingEnforcerAvailableAmount; exports.caveatEnforcerActions = caveatEnforcerActions; exports.signDelegation = signDelegation; exports.signDelegationActions = signDelegationActions; exports.signUserOperation = signUserOperation; exports.signUserOperationActions = signUserOperationActions; exports.erc7715ProviderActions = erc7715ProviderActions; exports.erc7710WalletActions = erc7710WalletActions; exports.erc7710BundlerActions = erc7710BundlerActions; exports.actions_exports = actions_exports;
729
+ //# sourceMappingURL=chunk-WA2O2K3K.cjs.map