@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,1472 @@
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; }var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/caveatBuilder/caveatBuilder.ts
8
+ var INSECURE_UNRESTRICTED_DELEGATION_ERROR_MESSAGE = "No caveats found. If you definitely want to create an empty caveat collection, set `allowInsecureUnrestrictedDelegation` to `true`.";
9
+ var CaveatBuilder = class _CaveatBuilder {
10
+ #results = [];
11
+ #hasBeenBuilt = false;
12
+ #environment;
13
+ #config;
14
+ #enforcerBuilders;
15
+ constructor(environment, config = {}, enforcerBuilders = {}, builtCaveats = []) {
16
+ this.#environment = environment;
17
+ this.#config = config;
18
+ this.#enforcerBuilders = enforcerBuilders;
19
+ this.#results = builtCaveats;
20
+ }
21
+ /**
22
+ * Extends the CaveatBuilder with a new enforcer function.
23
+ * @template TEnforcerName - The name of the enforcer.
24
+ * @template TFunction - The type of the enforcer function.
25
+ * @param name - The name of the enforcer.
26
+ * @param fn - The enforcer function.
27
+ * @returns The extended CaveatBuilder instance.
28
+ */
29
+ extend(name, fn) {
30
+ return new _CaveatBuilder(
31
+ this.#environment,
32
+ this.#config,
33
+ { ...this.#enforcerBuilders, [name]: fn },
34
+ this.#results
35
+ );
36
+ }
37
+ addCaveat(nameOrCaveat, config) {
38
+ if (typeof nameOrCaveat === "object") {
39
+ const caveat = {
40
+ args: "0x",
41
+ ...nameOrCaveat
42
+ };
43
+ this.#results = [...this.#results, caveat];
44
+ return this;
45
+ }
46
+ const name = nameOrCaveat;
47
+ const func = this.#enforcerBuilders[name];
48
+ if (typeof func === "function") {
49
+ const result = func(this.#environment, config);
50
+ this.#results = [...this.#results, result];
51
+ return this;
52
+ }
53
+ throw new Error(`Function "${String(name)}" does not exist.`);
54
+ }
55
+ /**
56
+ * Returns the caveats that have been built using this CaveatBuilder.
57
+ * @returns The array of built caveats.
58
+ * @throws Error if the builder has already been built or if no caveats are found and empty caveats are not allowed.
59
+ */
60
+ build() {
61
+ if (this.#hasBeenBuilt) {
62
+ throw new Error("This CaveatBuilder has already been built.");
63
+ }
64
+ if (this.#results.length === 0 && !this.#config.allowInsecureUnrestrictedDelegation) {
65
+ throw new Error(INSECURE_UNRESTRICTED_DELEGATION_ERROR_MESSAGE);
66
+ }
67
+ this.#hasBeenBuilt = true;
68
+ return this.#results;
69
+ }
70
+ };
71
+
72
+ // src/caveatBuilder/types.ts
73
+ var BalanceChangeType = /* @__PURE__ */ ((BalanceChangeType2) => {
74
+ BalanceChangeType2[BalanceChangeType2["Increase"] = 0] = "Increase";
75
+ BalanceChangeType2[BalanceChangeType2["Decrease"] = 1] = "Decrease";
76
+ return BalanceChangeType2;
77
+ })(BalanceChangeType || {});
78
+
79
+ // src/caveatBuilder/allowedCalldataBuilder.ts
80
+ var _viem = require('viem');
81
+ var allowedCalldata = "allowedCalldata";
82
+ var allowedCalldataBuilder = (environment, config) => {
83
+ const { startIndex, value } = config;
84
+ if (!_viem.isHex.call(void 0, value)) {
85
+ throw new Error("Invalid value: must be a valid hex string");
86
+ }
87
+ if (startIndex < 0) {
88
+ throw new Error("Invalid startIndex: must be zero or positive");
89
+ }
90
+ if (!Number.isInteger(startIndex)) {
91
+ throw new Error("Invalid startIndex: must be a whole number");
92
+ }
93
+ const startIndexHex = _viem.toHex.call(void 0, startIndex, { size: 32 });
94
+ const terms = _viem.concat.call(void 0, [startIndexHex, value]);
95
+ const {
96
+ caveatEnforcers: { AllowedCalldataEnforcer }
97
+ } = environment;
98
+ if (!AllowedCalldataEnforcer) {
99
+ throw new Error("AllowedCalldataEnforcer not found in environment");
100
+ }
101
+ return {
102
+ enforcer: AllowedCalldataEnforcer,
103
+ terms,
104
+ args: "0x"
105
+ };
106
+ };
107
+
108
+ // src/caveatBuilder/allowedMethodsBuilder.ts
109
+
110
+ var allowedMethods = "allowedMethods";
111
+ var FUNCTION_SELECTOR_STRING_LENGTH = 10;
112
+ var allowedMethodsBuilder = (environment, config) => {
113
+ const { selectors } = config;
114
+ if (selectors.length === 0) {
115
+ throw new Error("Invalid selectors: must provide at least one selector");
116
+ }
117
+ const parsedSelectors = selectors.map(parseSelector);
118
+ const terms = _viem.concat.call(void 0, parsedSelectors);
119
+ const {
120
+ caveatEnforcers: { AllowedMethodsEnforcer }
121
+ } = environment;
122
+ if (!AllowedMethodsEnforcer) {
123
+ throw new Error("AllowedMethodsEnforcer not found in environment");
124
+ }
125
+ return {
126
+ enforcer: AllowedMethodsEnforcer,
127
+ terms,
128
+ args: "0x"
129
+ };
130
+ };
131
+ function parseSelector(selector) {
132
+ if (_viem.isHex.call(void 0, selector)) {
133
+ if (selector.length === FUNCTION_SELECTOR_STRING_LENGTH) {
134
+ return selector;
135
+ }
136
+ throw new Error(
137
+ "Invalid selector: must be a 4 byte hex string, abi function signature, or AbiFunction"
138
+ );
139
+ }
140
+ try {
141
+ return _viem.toFunctionSelector.call(void 0, selector);
142
+ } catch (rootError) {
143
+ throw new Error(
144
+ "Invalid selector: must be a 4 byte hex string, abi function signature, or AbiFunction",
145
+ { cause: rootError }
146
+ );
147
+ }
148
+ }
149
+
150
+ // src/caveatBuilder/allowedTargetsBuilder.ts
151
+
152
+ var allowedTargets = "allowedTargets";
153
+ var allowedTargetsBuilder = (environment, config) => {
154
+ const { targets } = config;
155
+ if (targets.length === 0) {
156
+ throw new Error(
157
+ "Invalid targets: must provide at least one target address"
158
+ );
159
+ }
160
+ const invalidAddresses = targets.filter(
161
+ (target) => !_viem.isAddress.call(void 0, target, { strict: false })
162
+ );
163
+ if (invalidAddresses.length > 0) {
164
+ throw new Error("Invalid targets: must be valid addresses");
165
+ }
166
+ const terms = _viem.concat.call(void 0, targets);
167
+ const {
168
+ caveatEnforcers: { AllowedTargetsEnforcer }
169
+ } = environment;
170
+ if (!AllowedTargetsEnforcer) {
171
+ throw new Error("AllowedTargetsEnforcer not found in environment");
172
+ }
173
+ return {
174
+ enforcer: AllowedTargetsEnforcer,
175
+ terms,
176
+ args: "0x"
177
+ };
178
+ };
179
+
180
+ // src/caveatBuilder/argsEqualityCheckBuilder.ts
181
+
182
+ var argsEqualityCheck = "argsEqualityCheck";
183
+ var argsEqualityCheckBuilder = (environment, config) => {
184
+ const { args } = config;
185
+ if (!_viem.isHex.call(void 0, args)) {
186
+ throw new Error("Invalid config: args must be a valid hex string");
187
+ }
188
+ const {
189
+ caveatEnforcers: { ArgsEqualityCheckEnforcer }
190
+ } = environment;
191
+ if (!ArgsEqualityCheckEnforcer) {
192
+ throw new Error("ArgsEqualityCheckEnforcer not found in environment");
193
+ }
194
+ return {
195
+ enforcer: ArgsEqualityCheckEnforcer,
196
+ terms: args,
197
+ args: "0x"
198
+ };
199
+ };
200
+
201
+ // src/caveatBuilder/blockNumberBuilder.ts
202
+
203
+ var blockNumber = "blockNumber";
204
+ var blockNumberBuilder = (environment, config) => {
205
+ const { afterThreshold, beforeThreshold } = config;
206
+ if (afterThreshold === 0n && beforeThreshold === 0n) {
207
+ throw new Error(
208
+ "Invalid thresholds: At least one of afterThreshold or beforeThreshold must be specified"
209
+ );
210
+ }
211
+ if (beforeThreshold !== 0n && afterThreshold >= beforeThreshold) {
212
+ throw new Error(
213
+ "Invalid thresholds: afterThreshold must be less than beforeThreshold if both are specified"
214
+ );
215
+ }
216
+ const terms = _viem.concat.call(void 0, [
217
+ _viem.toHex.call(void 0, afterThreshold, {
218
+ size: 16
219
+ }),
220
+ _viem.toHex.call(void 0, beforeThreshold, {
221
+ size: 16
222
+ })
223
+ ]);
224
+ const {
225
+ caveatEnforcers: { BlockNumberEnforcer }
226
+ } = environment;
227
+ if (!BlockNumberEnforcer) {
228
+ throw new Error("BlockNumberEnforcer not found in environment");
229
+ }
230
+ return {
231
+ enforcer: BlockNumberEnforcer,
232
+ terms,
233
+ args: "0x"
234
+ };
235
+ };
236
+
237
+ // src/caveatBuilder/deployedBuilder.ts
238
+
239
+ var deployed = "deployed";
240
+ var deployedBuilder = (environment, config) => {
241
+ const { contractAddress, salt, bytecode } = config;
242
+ if (!_viem.isAddress.call(void 0, contractAddress, { strict: false })) {
243
+ throw new Error(
244
+ `Invalid contractAddress: must be a valid Ethereum address`
245
+ );
246
+ }
247
+ if (!_viem.isHex.call(void 0, salt)) {
248
+ throw new Error("Invalid salt: must be a valid hexadecimal string");
249
+ }
250
+ if (!_viem.isHex.call(void 0, bytecode)) {
251
+ throw new Error("Invalid bytecode: must be a valid hexadecimal string");
252
+ }
253
+ const terms = _viem.concat.call(void 0, [contractAddress, _viem.pad.call(void 0, salt, { size: 32 }), bytecode]);
254
+ const {
255
+ caveatEnforcers: { DeployedEnforcer }
256
+ } = environment;
257
+ if (!DeployedEnforcer) {
258
+ throw new Error("DeployedEnforcer not found in environment");
259
+ }
260
+ return {
261
+ enforcer: DeployedEnforcer,
262
+ terms,
263
+ args: "0x"
264
+ };
265
+ };
266
+
267
+ // src/caveatBuilder/erc1155BalanceChangeBuilder.ts
268
+
269
+ var erc1155BalanceChange = "erc1155BalanceChange";
270
+ var erc1155BalanceChangeBuilder = (environment, config) => {
271
+ const { tokenAddress, recipient, tokenId, balance, changeType } = config;
272
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
273
+ throw new Error("Invalid tokenAddress: must be a valid address");
274
+ }
275
+ if (!_viem.isAddress.call(void 0, recipient, { strict: false })) {
276
+ throw new Error("Invalid recipient: must be a valid address");
277
+ }
278
+ if (balance <= 0n) {
279
+ throw new Error("Invalid balance: must be a positive number");
280
+ }
281
+ if (tokenId < 0n) {
282
+ throw new Error("Invalid tokenId: must be a non-negative number");
283
+ }
284
+ if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
285
+ throw new Error("Invalid changeType: must be either Increase or Decrease");
286
+ }
287
+ const terms = _viem.encodePacked.call(void 0,
288
+ ["uint8", "address", "address", "uint256", "uint256"],
289
+ [changeType, tokenAddress, recipient, tokenId, balance]
290
+ );
291
+ const {
292
+ caveatEnforcers: { ERC1155BalanceChangeEnforcer }
293
+ } = environment;
294
+ if (!ERC1155BalanceChangeEnforcer) {
295
+ throw new Error("ERC1155BalanceChangeEnforcer not found in environment");
296
+ }
297
+ return {
298
+ enforcer: ERC1155BalanceChangeEnforcer,
299
+ terms,
300
+ args: "0x"
301
+ };
302
+ };
303
+
304
+ // src/caveatBuilder/erc20BalanceChangeBuilder.ts
305
+
306
+ var erc20BalanceChange = "erc20BalanceChange";
307
+ var erc20BalanceChangeBuilder = (environment, config) => {
308
+ const { tokenAddress, recipient, balance, changeType } = config;
309
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
310
+ throw new Error("Invalid tokenAddress: must be a valid address");
311
+ }
312
+ if (balance <= 0n) {
313
+ throw new Error("Invalid balance: must be a positive number");
314
+ }
315
+ if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
316
+ throw new Error("Invalid changeType: must be either Increase or Decrease");
317
+ }
318
+ const terms = _viem.encodePacked.call(void 0,
319
+ ["uint8", "address", "address", "uint256"],
320
+ [changeType, tokenAddress, recipient, balance]
321
+ );
322
+ const {
323
+ caveatEnforcers: { ERC20BalanceChangeEnforcer }
324
+ } = environment;
325
+ if (!ERC20BalanceChangeEnforcer) {
326
+ throw new Error("ERC20BalanceChangeEnforcer not found in environment");
327
+ }
328
+ return {
329
+ enforcer: ERC20BalanceChangeEnforcer,
330
+ terms,
331
+ args: "0x"
332
+ };
333
+ };
334
+
335
+ // src/caveatBuilder/erc20PeriodTransferBuilder.ts
336
+ var _delegationcore = require('@metamask/delegation-core');
337
+ var erc20PeriodTransfer = "erc20PeriodTransfer";
338
+ var erc20PeriodTransferBuilder = (environment, config) => {
339
+ const { tokenAddress, periodAmount, periodDuration, startDate } = config;
340
+ const terms = _delegationcore.createERC20TokenPeriodTransferTerms.call(void 0, {
341
+ tokenAddress,
342
+ periodAmount,
343
+ periodDuration,
344
+ startDate
345
+ });
346
+ const {
347
+ caveatEnforcers: { ERC20PeriodTransferEnforcer }
348
+ } = environment;
349
+ if (!ERC20PeriodTransferEnforcer) {
350
+ throw new Error("ERC20PeriodTransferEnforcer not found in environment");
351
+ }
352
+ return {
353
+ enforcer: ERC20PeriodTransferEnforcer,
354
+ terms,
355
+ args: "0x"
356
+ };
357
+ };
358
+
359
+ // src/caveatBuilder/erc20StreamingBuilder.ts
360
+
361
+ var erc20Streaming = "erc20Streaming";
362
+ var erc20StreamingBuilder = (environment, config) => {
363
+ const { tokenAddress, initialAmount, maxAmount, amountPerSecond, startTime } = config;
364
+ const terms = _delegationcore.createERC20StreamingTerms.call(void 0, {
365
+ tokenAddress,
366
+ initialAmount,
367
+ maxAmount,
368
+ amountPerSecond,
369
+ startTime
370
+ });
371
+ const {
372
+ caveatEnforcers: { ERC20StreamingEnforcer }
373
+ } = environment;
374
+ if (!ERC20StreamingEnforcer) {
375
+ throw new Error("ERC20StreamingEnforcer not found in environment");
376
+ }
377
+ return {
378
+ enforcer: ERC20StreamingEnforcer,
379
+ terms,
380
+ args: "0x"
381
+ };
382
+ };
383
+
384
+ // src/caveatBuilder/erc20TransferAmountBuilder.ts
385
+
386
+ var erc20TransferAmount = "erc20TransferAmount";
387
+ var erc20TransferAmountBuilder = (environment, config) => {
388
+ const { tokenAddress, maxAmount } = config;
389
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
390
+ throw new Error("Invalid tokenAddress: must be a valid address");
391
+ }
392
+ if (maxAmount <= 0n) {
393
+ throw new Error("Invalid maxAmount: must be a positive number");
394
+ }
395
+ const terms = _viem.concat.call(void 0, [tokenAddress, _viem.toHex.call(void 0, maxAmount, { size: 32 })]);
396
+ const {
397
+ caveatEnforcers: { ERC20TransferAmountEnforcer }
398
+ } = environment;
399
+ if (!ERC20TransferAmountEnforcer) {
400
+ throw new Error("ERC20TransferAmountEnforcer not found in environment");
401
+ }
402
+ return {
403
+ enforcer: ERC20TransferAmountEnforcer,
404
+ terms,
405
+ args: "0x"
406
+ };
407
+ };
408
+
409
+ // src/caveatBuilder/erc721BalanceChangeBuilder.ts
410
+
411
+ var erc721BalanceChange = "erc721BalanceChange";
412
+ var erc721BalanceChangeBuilder = (environment, config) => {
413
+ const { tokenAddress, recipient, amount, changeType } = config;
414
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
415
+ throw new Error("Invalid tokenAddress: must be a valid address");
416
+ }
417
+ if (!_viem.isAddress.call(void 0, recipient, { strict: false })) {
418
+ throw new Error("Invalid recipient: must be a valid address");
419
+ }
420
+ if (amount <= 0n) {
421
+ throw new Error("Invalid balance: must be a positive number");
422
+ }
423
+ if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
424
+ throw new Error("Invalid changeType: must be either Increase or Decrease");
425
+ }
426
+ const terms = _viem.encodePacked.call(void 0,
427
+ ["uint8", "address", "address", "uint256"],
428
+ [changeType, tokenAddress, recipient, amount]
429
+ );
430
+ const {
431
+ caveatEnforcers: { ERC721BalanceChangeEnforcer }
432
+ } = environment;
433
+ if (!ERC721BalanceChangeEnforcer) {
434
+ throw new Error("ERC721BalanceChangeEnforcer not found in environment");
435
+ }
436
+ return {
437
+ enforcer: ERC721BalanceChangeEnforcer,
438
+ terms,
439
+ args: "0x"
440
+ };
441
+ };
442
+
443
+ // src/caveatBuilder/erc721TransferBuilder.ts
444
+
445
+ var erc721Transfer = "erc721Transfer";
446
+ var erc721TransferBuilder = (environment, config) => {
447
+ const { tokenAddress, tokenId } = config;
448
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
449
+ throw new Error("Invalid tokenAddress: must be a valid address");
450
+ }
451
+ if (tokenId < 0n) {
452
+ throw new Error("Invalid tokenId: must be a non-negative number");
453
+ }
454
+ const terms = _viem.concat.call(void 0, [tokenAddress, _viem.toHex.call(void 0, tokenId, { size: 32 })]);
455
+ const {
456
+ caveatEnforcers: { ERC721TransferEnforcer }
457
+ } = environment;
458
+ if (!ERC721TransferEnforcer) {
459
+ throw new Error("ERC721TransferEnforcer not found in environment");
460
+ }
461
+ return {
462
+ enforcer: ERC721TransferEnforcer,
463
+ terms,
464
+ args: "0x"
465
+ };
466
+ };
467
+
468
+ // src/caveatBuilder/exactCalldataBatchBuilder.ts
469
+
470
+ var exactCalldataBatch = "exactCalldataBatch";
471
+ var exactCalldataBatchBuilder = (environment, config) => {
472
+ const { executions } = config;
473
+ if (executions.length === 0) {
474
+ throw new Error("Invalid executions: array cannot be empty");
475
+ }
476
+ for (const execution of executions) {
477
+ if (!_viem.isAddress.call(void 0, execution.target, { strict: false })) {
478
+ throw new Error("Invalid target: must be a valid address");
479
+ }
480
+ if (execution.value < 0n) {
481
+ throw new Error("Invalid value: must be a non-negative number");
482
+ }
483
+ if (!execution.callData.startsWith("0x")) {
484
+ throw new Error(
485
+ "Invalid calldata: must be a hex string starting with 0x"
486
+ );
487
+ }
488
+ }
489
+ const terms = _viem.encodeAbiParameters.call(void 0,
490
+ [
491
+ {
492
+ type: "tuple[]",
493
+ components: [
494
+ { type: "address", name: "target" },
495
+ { type: "uint256", name: "value" },
496
+ { type: "bytes", name: "callData" }
497
+ ]
498
+ }
499
+ ],
500
+ [executions]
501
+ );
502
+ const {
503
+ caveatEnforcers: { ExactCalldataBatchEnforcer }
504
+ } = environment;
505
+ if (!ExactCalldataBatchEnforcer) {
506
+ throw new Error("ExactCalldataBatchEnforcer not found in environment");
507
+ }
508
+ return {
509
+ enforcer: ExactCalldataBatchEnforcer,
510
+ terms,
511
+ args: "0x"
512
+ };
513
+ };
514
+
515
+ // src/caveatBuilder/exactCalldataBuilder.ts
516
+
517
+ var exactCalldata = "exactCalldata";
518
+ var exactCalldataBuilder = (environment, config) => {
519
+ const { calldata } = config;
520
+ const terms = _delegationcore.createExactCalldataTerms.call(void 0, { calldata });
521
+ const {
522
+ caveatEnforcers: { ExactCalldataEnforcer }
523
+ } = environment;
524
+ if (!ExactCalldataEnforcer) {
525
+ throw new Error("ExactCalldataEnforcer not found in environment");
526
+ }
527
+ return {
528
+ enforcer: ExactCalldataEnforcer,
529
+ terms,
530
+ args: "0x"
531
+ };
532
+ };
533
+
534
+ // src/caveatBuilder/exactExecutionBatchBuilder.ts
535
+
536
+ var exactExecutionBatch = "exactExecutionBatch";
537
+ var exactExecutionBatchBuilder = (environment, config) => {
538
+ const { executions } = config;
539
+ if (executions.length === 0) {
540
+ throw new Error("Invalid executions: array cannot be empty");
541
+ }
542
+ for (const execution of executions) {
543
+ if (!_viem.isAddress.call(void 0, execution.target, { strict: false })) {
544
+ throw new Error("Invalid target: must be a valid address");
545
+ }
546
+ if (execution.value < 0n) {
547
+ throw new Error("Invalid value: must be a non-negative number");
548
+ }
549
+ if (!execution.callData.startsWith("0x")) {
550
+ throw new Error(
551
+ "Invalid calldata: must be a hex string starting with 0x"
552
+ );
553
+ }
554
+ }
555
+ const terms = _viem.encodeAbiParameters.call(void 0,
556
+ [
557
+ {
558
+ type: "tuple[]",
559
+ components: [
560
+ { type: "address", name: "target" },
561
+ { type: "uint256", name: "value" },
562
+ { type: "bytes", name: "callData" }
563
+ ]
564
+ }
565
+ ],
566
+ [executions]
567
+ );
568
+ const {
569
+ caveatEnforcers: { ExactExecutionBatchEnforcer }
570
+ } = environment;
571
+ if (!ExactExecutionBatchEnforcer) {
572
+ throw new Error("ExactExecutionBatchEnforcer not found in environment");
573
+ }
574
+ return {
575
+ enforcer: ExactExecutionBatchEnforcer,
576
+ terms,
577
+ args: "0x"
578
+ };
579
+ };
580
+
581
+ // src/caveatBuilder/exactExecutionBuilder.ts
582
+
583
+ var exactExecution = "exactExecution";
584
+ var exactExecutionBuilder = (environment, config) => {
585
+ const { execution } = config;
586
+ if (!_viem.isAddress.call(void 0, execution.target, { strict: false })) {
587
+ throw new Error("Invalid target: must be a valid address");
588
+ }
589
+ if (execution.value < 0n) {
590
+ throw new Error("Invalid value: must be a non-negative number");
591
+ }
592
+ if (!execution.callData.startsWith("0x")) {
593
+ throw new Error("Invalid calldata: must be a hex string starting with 0x");
594
+ }
595
+ const terms = _viem.concat.call(void 0, [
596
+ execution.target,
597
+ _viem.toHex.call(void 0, execution.value, { size: 32 }),
598
+ execution.callData
599
+ ]);
600
+ const {
601
+ caveatEnforcers: { ExactExecutionEnforcer }
602
+ } = environment;
603
+ if (!ExactExecutionEnforcer) {
604
+ throw new Error("ExactExecutionEnforcer not found in environment");
605
+ }
606
+ return {
607
+ enforcer: ExactExecutionEnforcer,
608
+ terms,
609
+ args: "0x"
610
+ };
611
+ };
612
+
613
+ // src/caveatBuilder/idBuilder.ts
614
+
615
+ var id = "id";
616
+ var idBuilder = (environment, config) => {
617
+ const { id: idValue } = config;
618
+ let idBigInt;
619
+ if (typeof idValue === "number") {
620
+ if (!Number.isInteger(idValue)) {
621
+ throw new Error("Invalid id: must be an integer");
622
+ }
623
+ idBigInt = BigInt(idValue);
624
+ } else if (typeof idValue === "bigint") {
625
+ idBigInt = idValue;
626
+ } else {
627
+ throw new Error("Invalid id: must be a bigint or number");
628
+ }
629
+ if (idBigInt < 0n) {
630
+ throw new Error("Invalid id: must be a non-negative number");
631
+ }
632
+ if (idBigInt > _viem.maxUint256) {
633
+ throw new Error("Invalid id: must be less than 2^256");
634
+ }
635
+ const terms = _viem.toHex.call(void 0, idBigInt, { size: 32 });
636
+ const {
637
+ caveatEnforcers: { IdEnforcer }
638
+ } = environment;
639
+ if (!IdEnforcer) {
640
+ throw new Error("IdEnforcer not found in environment");
641
+ }
642
+ return {
643
+ enforcer: IdEnforcer,
644
+ terms,
645
+ args: "0x"
646
+ };
647
+ };
648
+
649
+ // src/caveatBuilder/limitedCallsBuilder.ts
650
+
651
+ var limitedCalls = "limitedCalls";
652
+ var limitedCallsBuilder = (environment, config) => {
653
+ const { limit } = config;
654
+ if (!Number.isInteger(limit)) {
655
+ throw new Error("Invalid limit: must be an integer");
656
+ }
657
+ if (limit <= 0) {
658
+ throw new Error("Invalid limit: must be a positive integer");
659
+ }
660
+ const terms = _viem.pad.call(void 0, _viem.toHex.call(void 0, limit), { size: 32 });
661
+ const {
662
+ caveatEnforcers: { LimitedCallsEnforcer }
663
+ } = environment;
664
+ if (!LimitedCallsEnforcer) {
665
+ throw new Error("LimitedCallsEnforcer not found in environment");
666
+ }
667
+ return {
668
+ enforcer: LimitedCallsEnforcer,
669
+ terms,
670
+ args: "0x"
671
+ };
672
+ };
673
+
674
+ // src/caveatBuilder/multiTokenPeriodBuilder.ts
675
+
676
+ var multiTokenPeriod = "multiTokenPeriod";
677
+ var multiTokenPeriodBuilder = (environment, config) => {
678
+ if (!_optionalChain([config, 'optionalAccess', _ => _.tokenConfigs]) || config.tokenConfigs.length === 0) {
679
+ throw new Error(
680
+ "MultiTokenPeriodBuilder: tokenConfigs array cannot be empty"
681
+ );
682
+ }
683
+ config.tokenConfigs.forEach((tokenConfig) => {
684
+ if (!_viem.isAddress.call(void 0, tokenConfig.token)) {
685
+ throw new Error(`Invalid token address: ${String(tokenConfig.token)}`);
686
+ }
687
+ if (tokenConfig.periodAmount <= 0) {
688
+ throw new Error("Invalid period amount: must be greater than 0");
689
+ }
690
+ if (tokenConfig.periodDuration <= 0) {
691
+ throw new Error("Invalid period duration: must be greater than 0");
692
+ }
693
+ });
694
+ const termsArray = config.tokenConfigs.reduce(
695
+ (acc, { token, periodAmount, periodDuration, startDate }) => [
696
+ ...acc,
697
+ _viem.pad.call(void 0, token, { size: 20 }),
698
+ _viem.toHex.call(void 0, periodAmount, { size: 32 }),
699
+ _viem.toHex.call(void 0, periodDuration, { size: 32 }),
700
+ _viem.toHex.call(void 0, startDate, { size: 32 })
701
+ ],
702
+ []
703
+ );
704
+ const terms = _viem.concat.call(void 0, termsArray);
705
+ const {
706
+ caveatEnforcers: { MultiTokenPeriodEnforcer }
707
+ } = environment;
708
+ if (!MultiTokenPeriodEnforcer) {
709
+ throw new Error("MultiTokenPeriodEnforcer not found in environment");
710
+ }
711
+ return {
712
+ enforcer: MultiTokenPeriodEnforcer,
713
+ terms,
714
+ args: "0x"
715
+ };
716
+ };
717
+
718
+ // src/caveatBuilder/nativeBalanceChangeBuilder.ts
719
+
720
+ var nativeBalanceChange = "nativeBalanceChange";
721
+ var nativeBalanceChangeBuilder = (environment, config) => {
722
+ const { recipient, balance, changeType } = config;
723
+ if (!_viem.isAddress.call(void 0, recipient)) {
724
+ throw new Error("Invalid recipient: must be a valid Address");
725
+ }
726
+ if (balance <= 0n) {
727
+ throw new Error("Invalid balance: must be a positive number");
728
+ }
729
+ if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
730
+ throw new Error("Invalid changeType: must be either Increase or Decrease");
731
+ }
732
+ const terms = _viem.encodePacked.call(void 0,
733
+ ["uint8", "address", "uint256"],
734
+ [changeType, recipient, balance]
735
+ );
736
+ const {
737
+ caveatEnforcers: { NativeBalanceChangeEnforcer }
738
+ } = environment;
739
+ if (!NativeBalanceChangeEnforcer) {
740
+ throw new Error("NativeBalanceChangeEnforcer not found in environment");
741
+ }
742
+ return {
743
+ enforcer: NativeBalanceChangeEnforcer,
744
+ terms,
745
+ args: "0x"
746
+ };
747
+ };
748
+
749
+ // src/caveatBuilder/nativeTokenPaymentBuilder.ts
750
+
751
+ var nativeTokenPayment = "nativeTokenPayment";
752
+ var nativeTokenPaymentBuilder = (environment, config) => {
753
+ const { recipient, amount } = config;
754
+ if (amount <= 0n) {
755
+ throw new Error("Invalid amount: must be positive");
756
+ }
757
+ if (!_viem.isAddress.call(void 0, recipient)) {
758
+ throw new Error("Invalid recipient: must be a valid address");
759
+ }
760
+ const terms = _viem.encodePacked.call(void 0, ["address", "uint256"], [recipient, amount]);
761
+ const {
762
+ caveatEnforcers: { NativeTokenPaymentEnforcer }
763
+ } = environment;
764
+ if (!NativeTokenPaymentEnforcer) {
765
+ throw new Error("NativeTokenPaymentEnforcer not found in environment");
766
+ }
767
+ return {
768
+ enforcer: NativeTokenPaymentEnforcer,
769
+ terms,
770
+ args: "0x"
771
+ };
772
+ };
773
+
774
+ // src/caveatBuilder/nativeTokenPeriodTransferBuilder.ts
775
+
776
+ var nativeTokenPeriodTransfer = "nativeTokenPeriodTransfer";
777
+ var nativeTokenPeriodTransferBuilder = (environment, config) => {
778
+ const { periodAmount, periodDuration, startDate } = config;
779
+ const terms = _delegationcore.createNativeTokenPeriodTransferTerms.call(void 0, {
780
+ periodAmount,
781
+ periodDuration,
782
+ startDate
783
+ });
784
+ const {
785
+ caveatEnforcers: { NativeTokenPeriodTransferEnforcer }
786
+ } = environment;
787
+ if (!NativeTokenPeriodTransferEnforcer) {
788
+ throw new Error(
789
+ "NativeTokenPeriodTransferEnforcer not found in environment"
790
+ );
791
+ }
792
+ return {
793
+ enforcer: NativeTokenPeriodTransferEnforcer,
794
+ terms,
795
+ args: "0x"
796
+ };
797
+ };
798
+
799
+ // src/caveatBuilder/nativeTokenStreamingBuilder.ts
800
+
801
+ var nativeTokenStreaming = "nativeTokenStreaming";
802
+ var nativeTokenStreamingBuilder = (environment, config) => {
803
+ const { initialAmount, maxAmount, amountPerSecond, startTime } = config;
804
+ const terms = _delegationcore.createNativeTokenStreamingTerms.call(void 0, {
805
+ initialAmount,
806
+ maxAmount,
807
+ amountPerSecond,
808
+ startTime
809
+ });
810
+ const {
811
+ caveatEnforcers: { NativeTokenStreamingEnforcer }
812
+ } = environment;
813
+ if (!NativeTokenStreamingEnforcer) {
814
+ throw new Error("NativeTokenStreamingEnforcer not found in environment");
815
+ }
816
+ return {
817
+ enforcer: NativeTokenStreamingEnforcer,
818
+ terms,
819
+ args: "0x"
820
+ };
821
+ };
822
+
823
+ // src/caveatBuilder/nativeTokenTransferAmountBuilder.ts
824
+
825
+ var nativeTokenTransferAmount = "nativeTokenTransferAmount";
826
+ var nativeTokenTransferAmountBuilder = (environment, config) => {
827
+ const { maxAmount } = config;
828
+ if (maxAmount < 0n) {
829
+ throw new Error("Invalid maxAmount: must be zero or positive");
830
+ }
831
+ const terms = _viem.encodePacked.call(void 0, ["uint256"], [maxAmount]);
832
+ const {
833
+ caveatEnforcers: { NativeTokenTransferAmountEnforcer }
834
+ } = environment;
835
+ if (!NativeTokenTransferAmountEnforcer) {
836
+ throw new Error(
837
+ "NativeTokenTransferAmountEnforcer not found in environment"
838
+ );
839
+ }
840
+ return {
841
+ enforcer: NativeTokenTransferAmountEnforcer,
842
+ terms,
843
+ args: "0x"
844
+ };
845
+ };
846
+
847
+ // src/caveatBuilder/nonceBuilder.ts
848
+
849
+ var nonce = "nonce";
850
+ var nonceBuilder = (environment, config) => {
851
+ const { nonce: nonceValue } = config;
852
+ const terms = _delegationcore.createNonceTerms.call(void 0, { nonce: nonceValue });
853
+ const {
854
+ caveatEnforcers: { NonceEnforcer }
855
+ } = environment;
856
+ if (!NonceEnforcer) {
857
+ throw new Error("NonceEnforcer not found in environment");
858
+ }
859
+ return {
860
+ enforcer: NonceEnforcer,
861
+ terms,
862
+ args: "0x"
863
+ };
864
+ };
865
+
866
+ // src/caveatBuilder/ownershipTransferBuilder.ts
867
+
868
+ var ownershipTransfer = "ownershipTransfer";
869
+ var ownershipTransferBuilder = (environment, config) => {
870
+ const { contractAddress } = config;
871
+ if (!_viem.isAddress.call(void 0, contractAddress, { strict: false })) {
872
+ throw new Error("Invalid contractAddress: must be a valid address");
873
+ }
874
+ const terms = contractAddress;
875
+ const {
876
+ caveatEnforcers: { OwnershipTransferEnforcer }
877
+ } = environment;
878
+ if (!OwnershipTransferEnforcer) {
879
+ throw new Error("OwnershipTransferEnforcer not found in environment");
880
+ }
881
+ return {
882
+ enforcer: OwnershipTransferEnforcer,
883
+ terms,
884
+ args: "0x"
885
+ };
886
+ };
887
+
888
+ // src/caveatBuilder/redeemerBuilder.ts
889
+
890
+ var redeemer = "redeemer";
891
+ var redeemerBuilder = (environment, config) => {
892
+ const { redeemers } = config;
893
+ if (redeemers.length === 0) {
894
+ throw new Error(
895
+ "Invalid redeemers: must specify at least one redeemer address"
896
+ );
897
+ }
898
+ for (const redeemerAddress of redeemers) {
899
+ if (!_viem.isAddress.call(void 0, redeemerAddress)) {
900
+ throw new Error("Invalid redeemers: must be a valid address");
901
+ }
902
+ }
903
+ const terms = _viem.concat.call(void 0, redeemers);
904
+ const {
905
+ caveatEnforcers: { RedeemerEnforcer }
906
+ } = environment;
907
+ if (!RedeemerEnforcer) {
908
+ throw new Error("RedeemerEnforcer not found in environment");
909
+ }
910
+ return {
911
+ enforcer: RedeemerEnforcer,
912
+ terms,
913
+ args: "0x"
914
+ };
915
+ };
916
+
917
+ // src/caveatBuilder/specificActionERC20TransferBatchBuilder.ts
918
+
919
+ var specificActionERC20TransferBatch = "specificActionERC20TransferBatch";
920
+ var specificActionERC20TransferBatchBuilder = (environment, config) => {
921
+ const { tokenAddress, recipient, amount, target, calldata } = config;
922
+ if (!_viem.isAddress.call(void 0, tokenAddress, { strict: false })) {
923
+ throw new Error("Invalid tokenAddress: must be a valid address");
924
+ }
925
+ if (!_viem.isAddress.call(void 0, recipient, { strict: false })) {
926
+ throw new Error("Invalid recipient: must be a valid address");
927
+ }
928
+ if (!_viem.isAddress.call(void 0, target, { strict: false })) {
929
+ throw new Error("Invalid target: must be a valid address");
930
+ }
931
+ if (amount <= 0n) {
932
+ throw new Error("Invalid amount: must be a positive number");
933
+ }
934
+ const terms = _viem.concat.call(void 0, [
935
+ tokenAddress,
936
+ recipient,
937
+ _viem.toHex.call(void 0, amount, { size: 32 }),
938
+ target,
939
+ calldata
940
+ ]);
941
+ const {
942
+ caveatEnforcers: { SpecificActionERC20TransferBatchEnforcer }
943
+ } = environment;
944
+ if (!SpecificActionERC20TransferBatchEnforcer) {
945
+ throw new Error(
946
+ "SpecificActionERC20TransferBatchEnforcer not found in environment"
947
+ );
948
+ }
949
+ return {
950
+ enforcer: SpecificActionERC20TransferBatchEnforcer,
951
+ terms,
952
+ args: "0x"
953
+ };
954
+ };
955
+
956
+ // src/caveatBuilder/timestampBuilder.ts
957
+
958
+ var timestamp = "timestamp";
959
+ var timestampBuilder = (environment, config) => {
960
+ const { afterThreshold, beforeThreshold } = config;
961
+ const terms = _delegationcore.createTimestampTerms.call(void 0, {
962
+ timestampAfterThreshold: afterThreshold,
963
+ timestampBeforeThreshold: beforeThreshold
964
+ });
965
+ const {
966
+ caveatEnforcers: { TimestampEnforcer }
967
+ } = environment;
968
+ if (!TimestampEnforcer) {
969
+ throw new Error("TimestampEnforcer not found in environment");
970
+ }
971
+ return {
972
+ enforcer: TimestampEnforcer,
973
+ terms,
974
+ args: "0x"
975
+ };
976
+ };
977
+
978
+ // src/caveatBuilder/valueLteBuilder.ts
979
+
980
+ var valueLte = "valueLte";
981
+ var valueLteBuilder = (environment, config) => {
982
+ const { maxValue } = config;
983
+ const terms = _delegationcore.createValueLteTerms.call(void 0, { maxValue });
984
+ const {
985
+ caveatEnforcers: { ValueLteEnforcer }
986
+ } = environment;
987
+ if (!ValueLteEnforcer) {
988
+ throw new Error("ValueLteEnforcer not found in environment");
989
+ }
990
+ return {
991
+ enforcer: ValueLteEnforcer,
992
+ terms,
993
+ args: "0x"
994
+ };
995
+ };
996
+
997
+ // src/caveatBuilder/coreCaveatBuilder.ts
998
+ var createCaveatBuilder = (environment, config) => {
999
+ const caveatBuilder = new CaveatBuilder(environment, config).extend(allowedMethods, allowedMethodsBuilder).extend(allowedTargets, allowedTargetsBuilder).extend(deployed, deployedBuilder).extend(allowedCalldata, allowedCalldataBuilder).extend(erc20BalanceChange, erc20BalanceChangeBuilder).extend(erc721BalanceChange, erc721BalanceChangeBuilder).extend(erc1155BalanceChange, erc1155BalanceChangeBuilder).extend(valueLte, valueLteBuilder).extend(limitedCalls, limitedCallsBuilder).extend(id, idBuilder).extend(nonce, nonceBuilder).extend(timestamp, timestampBuilder).extend(blockNumber, blockNumberBuilder).extend(erc20TransferAmount, erc20TransferAmountBuilder).extend(erc20Streaming, erc20StreamingBuilder).extend(nativeTokenStreaming, nativeTokenStreamingBuilder).extend(erc721Transfer, erc721TransferBuilder).extend(nativeTokenTransferAmount, nativeTokenTransferAmountBuilder).extend(nativeBalanceChange, nativeBalanceChangeBuilder).extend(redeemer, redeemerBuilder).extend(nativeTokenPayment, nativeTokenPaymentBuilder).extend(argsEqualityCheck, argsEqualityCheckBuilder).extend(
1000
+ specificActionERC20TransferBatch,
1001
+ specificActionERC20TransferBatchBuilder
1002
+ ).extend(erc20PeriodTransfer, erc20PeriodTransferBuilder).extend(nativeTokenPeriodTransfer, nativeTokenPeriodTransferBuilder).extend(exactCalldataBatch, exactCalldataBatchBuilder).extend(exactCalldata, exactCalldataBuilder).extend(exactExecution, exactExecutionBuilder).extend(exactExecutionBatch, exactExecutionBatchBuilder).extend(multiTokenPeriod, multiTokenPeriodBuilder).extend(ownershipTransfer, ownershipTransferBuilder);
1003
+ return caveatBuilder;
1004
+ };
1005
+
1006
+ // src/caveatBuilder/scope/erc20PeriodicScope.ts
1007
+ function createErc20PeriodicCaveatBuilder(environment, config) {
1008
+ return createCaveatBuilder(environment).addCaveat("valueLte", {
1009
+ maxValue: 0n
1010
+ }).addCaveat("erc20PeriodTransfer", {
1011
+ tokenAddress: config.tokenAddress,
1012
+ periodAmount: config.periodAmount,
1013
+ periodDuration: config.periodDuration,
1014
+ startDate: config.startDate
1015
+ });
1016
+ }
1017
+
1018
+ // src/caveatBuilder/scope/erc20StreamingScope.ts
1019
+ function createErc20StreamingCaveatBuilder(environment, config) {
1020
+ return createCaveatBuilder(environment).addCaveat("valueLte", {
1021
+ maxValue: 0n
1022
+ }).addCaveat("erc20Streaming", {
1023
+ tokenAddress: config.tokenAddress,
1024
+ initialAmount: config.initialAmount,
1025
+ maxAmount: config.maxAmount,
1026
+ amountPerSecond: config.amountPerSecond,
1027
+ startTime: config.startTime
1028
+ });
1029
+ }
1030
+
1031
+ // src/caveatBuilder/scope/erc20TransferScope.ts
1032
+ function createErc20TransferCaveatBuilder(environment, config) {
1033
+ return createCaveatBuilder(environment).addCaveat("valueLte", {
1034
+ maxValue: 0n
1035
+ }).addCaveat("erc20TransferAmount", {
1036
+ tokenAddress: config.tokenAddress,
1037
+ maxAmount: config.maxAmount
1038
+ });
1039
+ }
1040
+
1041
+ // src/utils.ts
1042
+
1043
+ var hasProperties = (object, properties) => {
1044
+ return properties.every(
1045
+ (prop) => prop in object && object[prop] !== void 0
1046
+ );
1047
+ };
1048
+
1049
+ // src/caveatBuilder/scope/erc721Scope.ts
1050
+ var isErc721TransferConfig = (config) => {
1051
+ return hasProperties(
1052
+ config,
1053
+ ["tokenAddress", "tokenId"]
1054
+ );
1055
+ };
1056
+ function createErc721CaveatBuilder(environment, config) {
1057
+ if (!isErc721TransferConfig(config)) {
1058
+ throw new Error("Invalid ERC721 configuration");
1059
+ }
1060
+ const caveatBuilder = createCaveatBuilder(environment).addCaveat(
1061
+ "erc721Transfer",
1062
+ config
1063
+ );
1064
+ return caveatBuilder;
1065
+ }
1066
+
1067
+ // src/caveatBuilder/scope/functionCallScope.ts
1068
+ var isFunctionCallConfig = (config) => {
1069
+ return hasProperties(config, ["targets", "selectors"]);
1070
+ };
1071
+ function createFunctionCallCaveatBuilder(environment, config) {
1072
+ const { targets, selectors, allowedCalldata: allowedCalldata2, exactCalldata: exactCalldata2 } = config;
1073
+ if (!isFunctionCallConfig(config)) {
1074
+ throw new Error("Invalid Function Call configuration");
1075
+ }
1076
+ if (allowedCalldata2 && allowedCalldata2.length > 0 && exactCalldata2) {
1077
+ throw new Error(
1078
+ "Cannot specify both allowedCalldata and exactCalldata. Please use only one calldata restriction type."
1079
+ );
1080
+ }
1081
+ const caveatBuilder = createCaveatBuilder(environment).addCaveat("allowedTargets", { targets }).addCaveat("allowedMethods", { selectors });
1082
+ if (allowedCalldata2 && allowedCalldata2.length > 0) {
1083
+ allowedCalldata2.forEach((calldataConfig) => {
1084
+ caveatBuilder.addCaveat("allowedCalldata", calldataConfig);
1085
+ });
1086
+ } else if (exactCalldata2) {
1087
+ caveatBuilder.addCaveat("exactCalldata", exactCalldata2);
1088
+ }
1089
+ return caveatBuilder;
1090
+ }
1091
+
1092
+ // src/caveatBuilder/scope/nativeTokenPeriodicScope.ts
1093
+ function createNativeTokenPeriodicCaveatBuilder(environment, config) {
1094
+ const {
1095
+ periodAmount,
1096
+ periodDuration,
1097
+ startDate,
1098
+ allowedCalldata: allowedCalldata2,
1099
+ exactCalldata: exactCalldata2
1100
+ } = config;
1101
+ if (allowedCalldata2 && allowedCalldata2.length > 0 && exactCalldata2) {
1102
+ throw new Error(
1103
+ "Cannot specify both allowedCalldata and exactCalldata. Please use only one calldata restriction type."
1104
+ );
1105
+ }
1106
+ const caveatBuilder = createCaveatBuilder(environment);
1107
+ if (allowedCalldata2 && allowedCalldata2.length > 0) {
1108
+ allowedCalldata2.forEach((calldataConfig) => {
1109
+ caveatBuilder.addCaveat("allowedCalldata", calldataConfig);
1110
+ });
1111
+ } else if (exactCalldata2) {
1112
+ caveatBuilder.addCaveat("exactCalldata", exactCalldata2);
1113
+ } else {
1114
+ caveatBuilder.addCaveat("exactCalldata", {
1115
+ calldata: "0x"
1116
+ });
1117
+ }
1118
+ caveatBuilder.addCaveat("nativeTokenPeriodTransfer", {
1119
+ periodAmount,
1120
+ periodDuration,
1121
+ startDate
1122
+ });
1123
+ return caveatBuilder;
1124
+ }
1125
+
1126
+ // src/caveatBuilder/scope/nativeTokenStreamingScope.ts
1127
+ function createNativeTokenStreamingCaveatBuilder(environment, config) {
1128
+ const {
1129
+ initialAmount,
1130
+ maxAmount,
1131
+ amountPerSecond,
1132
+ startTime,
1133
+ allowedCalldata: allowedCalldata2,
1134
+ exactCalldata: exactCalldata2
1135
+ } = config;
1136
+ if (allowedCalldata2 && allowedCalldata2.length > 0 && exactCalldata2) {
1137
+ throw new Error(
1138
+ "Cannot specify both allowedCalldata and exactCalldata. Please use only one calldata restriction type."
1139
+ );
1140
+ }
1141
+ const caveatBuilder = createCaveatBuilder(environment);
1142
+ if (allowedCalldata2 && allowedCalldata2.length > 0) {
1143
+ allowedCalldata2.forEach((calldataConfig) => {
1144
+ caveatBuilder.addCaveat("allowedCalldata", calldataConfig);
1145
+ });
1146
+ } else if (exactCalldata2) {
1147
+ caveatBuilder.addCaveat("exactCalldata", exactCalldata2);
1148
+ } else {
1149
+ caveatBuilder.addCaveat("exactCalldata", {
1150
+ calldata: "0x"
1151
+ });
1152
+ }
1153
+ caveatBuilder.addCaveat("nativeTokenStreaming", {
1154
+ initialAmount,
1155
+ maxAmount,
1156
+ amountPerSecond,
1157
+ startTime
1158
+ });
1159
+ return caveatBuilder;
1160
+ }
1161
+
1162
+ // src/caveatBuilder/scope/nativeTokenTransferScope.ts
1163
+ function createNativeTokenTransferCaveatBuilder(environment, config) {
1164
+ const { maxAmount, allowedCalldata: allowedCalldata2, exactCalldata: exactCalldata2 } = config;
1165
+ if (allowedCalldata2 && allowedCalldata2.length > 0 && exactCalldata2) {
1166
+ throw new Error(
1167
+ "Cannot specify both allowedCalldata and exactCalldata. Please use only one calldata restriction type."
1168
+ );
1169
+ }
1170
+ const caveatBuilder = createCaveatBuilder(environment);
1171
+ if (allowedCalldata2 && allowedCalldata2.length > 0) {
1172
+ allowedCalldata2.forEach((calldataConfig) => {
1173
+ caveatBuilder.addCaveat("allowedCalldata", calldataConfig);
1174
+ });
1175
+ } else if (exactCalldata2) {
1176
+ caveatBuilder.addCaveat("exactCalldata", exactCalldata2);
1177
+ } else {
1178
+ caveatBuilder.addCaveat("exactCalldata", {
1179
+ calldata: "0x"
1180
+ });
1181
+ }
1182
+ caveatBuilder.addCaveat("nativeTokenTransferAmount", {
1183
+ maxAmount
1184
+ });
1185
+ return caveatBuilder;
1186
+ }
1187
+
1188
+ // src/caveatBuilder/scope/ownershipScope.ts
1189
+ var isOwnershipTransferConfig = (config) => {
1190
+ return hasProperties(
1191
+ config,
1192
+ ["contractAddress"]
1193
+ );
1194
+ };
1195
+ function createOwnershipCaveatBuilder(environment, config) {
1196
+ if (!isOwnershipTransferConfig(config)) {
1197
+ throw new Error("Invalid ownership transfer configuration");
1198
+ }
1199
+ const caveatBuilder = createCaveatBuilder(environment).addCaveat(
1200
+ "ownershipTransfer",
1201
+ config
1202
+ );
1203
+ return caveatBuilder;
1204
+ }
1205
+
1206
+ // src/caveatBuilder/scope/index.ts
1207
+ var createCaveatBuilderFromScope = (environment, scopeConfig) => {
1208
+ switch (scopeConfig.type) {
1209
+ case erc20TransferAmount:
1210
+ return createErc20TransferCaveatBuilder(environment, scopeConfig);
1211
+ case erc20Streaming:
1212
+ return createErc20StreamingCaveatBuilder(environment, scopeConfig);
1213
+ case erc20PeriodTransfer:
1214
+ return createErc20PeriodicCaveatBuilder(environment, scopeConfig);
1215
+ case nativeTokenTransferAmount:
1216
+ return createNativeTokenTransferCaveatBuilder(environment, scopeConfig);
1217
+ case nativeTokenStreaming:
1218
+ return createNativeTokenStreamingCaveatBuilder(environment, scopeConfig);
1219
+ case nativeTokenPeriodTransfer:
1220
+ return createNativeTokenPeriodicCaveatBuilder(environment, scopeConfig);
1221
+ case erc721Transfer:
1222
+ return createErc721CaveatBuilder(environment, scopeConfig);
1223
+ case ownershipTransfer:
1224
+ return createOwnershipCaveatBuilder(environment, scopeConfig);
1225
+ case "functionCall":
1226
+ return createFunctionCallCaveatBuilder(environment, scopeConfig);
1227
+ default:
1228
+ const exhaustivenessCheck = scopeConfig;
1229
+ throw new Error(
1230
+ `Invalid scope type: ${exhaustivenessCheck.type}`
1231
+ );
1232
+ }
1233
+ };
1234
+
1235
+ // src/caveatBuilder/resolveCaveats.ts
1236
+ var resolveCaveats = ({
1237
+ environment,
1238
+ scope,
1239
+ caveats
1240
+ }) => {
1241
+ const scopeCaveatBuilder = createCaveatBuilderFromScope(environment, scope);
1242
+ if (caveats) {
1243
+ if ("build" in caveats && typeof caveats.build === "function") {
1244
+ caveats.build().forEach((caveat) => {
1245
+ scopeCaveatBuilder.addCaveat(caveat);
1246
+ });
1247
+ } else if (Array.isArray(caveats)) {
1248
+ caveats.forEach((caveat) => {
1249
+ try {
1250
+ if ("type" in caveat) {
1251
+ const { type, ...config } = caveat;
1252
+ scopeCaveatBuilder.addCaveat(type, config);
1253
+ } else {
1254
+ scopeCaveatBuilder.addCaveat(caveat);
1255
+ }
1256
+ } catch (error) {
1257
+ throw new Error(`Invalid caveat: ${error.message}`);
1258
+ }
1259
+ });
1260
+ }
1261
+ }
1262
+ return scopeCaveatBuilder.build();
1263
+ };
1264
+
1265
+ // src/caveats.ts
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+
1273
+ var CAVEAT_ABI_TYPE_COMPONENTS = [
1274
+ { type: "address", name: "enforcer" },
1275
+ { type: "bytes", name: "terms" },
1276
+ { type: "bytes", name: "args" }
1277
+ ];
1278
+ var CAVEAT_TYPEHASH = _viem.keccak256.call(void 0,
1279
+ _viem.toHex.call(void 0, "Caveat(address enforcer,bytes terms)")
1280
+ );
1281
+ var createCaveat = (enforcer, terms, args = "0x") => ({
1282
+ enforcer,
1283
+ terms,
1284
+ args
1285
+ });
1286
+
1287
+ // src/delegation.ts
1288
+
1289
+
1290
+
1291
+
1292
+
1293
+
1294
+
1295
+
1296
+
1297
+
1298
+ var _accounts = require('viem/accounts');
1299
+ var DELEGATION_ABI_TYPE_COMPONENTS = [
1300
+ { type: "address", name: "delegate" },
1301
+ { type: "address", name: "delegator" },
1302
+ { type: "bytes32", name: "authority" },
1303
+ { type: "tuple[]", name: "caveats", components: CAVEAT_ABI_TYPE_COMPONENTS },
1304
+ { type: "uint256", name: "salt" },
1305
+ { type: "bytes", name: "signature" }
1306
+ ];
1307
+ var toDelegationStruct = (delegation) => {
1308
+ const caveats = delegation.caveats.map((caveat) => ({
1309
+ enforcer: _viem.getAddress.call(void 0, caveat.enforcer),
1310
+ terms: caveat.terms,
1311
+ args: caveat.args
1312
+ }));
1313
+ const salt = delegation.salt === "0x" ? 0n : BigInt(delegation.salt);
1314
+ return {
1315
+ delegate: _viem.getAddress.call(void 0, delegation.delegate),
1316
+ delegator: _viem.getAddress.call(void 0, delegation.delegator),
1317
+ authority: delegation.authority === void 0 ? _delegationcore.ROOT_AUTHORITY : delegation.authority,
1318
+ caveats,
1319
+ salt,
1320
+ signature: delegation.signature
1321
+ };
1322
+ };
1323
+ var toDelegation = (delegationStruct) => {
1324
+ return {
1325
+ ...delegationStruct,
1326
+ salt: _viem.toHex.call(void 0, delegationStruct.salt)
1327
+ };
1328
+ };
1329
+ var encodeDelegations = (delegations) => {
1330
+ const delegationStructs = delegations.map(toDelegationStruct);
1331
+ return _delegationcore.encodeDelegations.call(void 0, delegationStructs);
1332
+ };
1333
+ var encodePermissionContexts = (delegations) => {
1334
+ const encodedDelegations = delegations.map(
1335
+ (delegationChain) => encodeDelegations(delegationChain)
1336
+ );
1337
+ return encodedDelegations;
1338
+ };
1339
+ var decodeDelegations = (encoded) => {
1340
+ return _delegationcore.decodeDelegations.call(void 0, encoded).map(toDelegation);
1341
+ };
1342
+ var decodePermissionContexts = (encoded) => {
1343
+ const delegationChains = encoded.map(decodeDelegations);
1344
+ return delegationChains;
1345
+ };
1346
+ var SIGNABLE_DELEGATION_TYPED_DATA = {
1347
+ Caveat: [
1348
+ { name: "enforcer", type: "address" },
1349
+ { name: "terms", type: "bytes" }
1350
+ ],
1351
+ Delegation: [
1352
+ { name: "delegate", type: "address" },
1353
+ { name: "delegator", type: "address" },
1354
+ { name: "authority", type: "bytes32" },
1355
+ { name: "caveats", type: "Caveat[]" },
1356
+ { name: "salt", type: "uint256" }
1357
+ ]
1358
+ };
1359
+ var DELEGATION_ARRAY_ABI_TYPE = {
1360
+ type: "tuple[]",
1361
+ components: DELEGATION_ABI_TYPE_COMPONENTS
1362
+ };
1363
+ var getDelegationHashOffchain = (input) => {
1364
+ const delegationStruct = toDelegationStruct(input);
1365
+ return _delegationcore.hashDelegation.call(void 0, delegationStruct);
1366
+ };
1367
+ var resolveAuthority = (parentDelegation) => {
1368
+ if (!parentDelegation) {
1369
+ return _delegationcore.ROOT_AUTHORITY;
1370
+ }
1371
+ if (typeof parentDelegation === "string") {
1372
+ return parentDelegation;
1373
+ }
1374
+ return getDelegationHashOffchain(parentDelegation);
1375
+ };
1376
+ var createDelegation = (options) => {
1377
+ return {
1378
+ delegate: options.to,
1379
+ delegator: options.from,
1380
+ authority: resolveAuthority(options.parentDelegation),
1381
+ caveats: resolveCaveats(options),
1382
+ salt: _nullishCoalesce(options.salt, () => ( "0x")),
1383
+ signature: "0x"
1384
+ };
1385
+ };
1386
+ var createOpenDelegation = (options) => {
1387
+ return {
1388
+ delegate: _delegationcore.ANY_BENEFICIARY,
1389
+ delegator: options.from,
1390
+ authority: resolveAuthority(options.parentDelegation),
1391
+ caveats: resolveCaveats(options),
1392
+ salt: _nullishCoalesce(options.salt, () => ( "0x")),
1393
+ signature: "0x"
1394
+ };
1395
+ };
1396
+ var prepareSignDelegationTypedData = ({
1397
+ delegation,
1398
+ delegationManager,
1399
+ chainId,
1400
+ name = "DelegationManager",
1401
+ version = "1",
1402
+ allowInsecureUnrestrictedDelegation = false
1403
+ }) => {
1404
+ const delegationStruct = toDelegationStruct({
1405
+ ...delegation,
1406
+ signature: "0x"
1407
+ });
1408
+ if (delegationStruct.caveats.length === 0 && !allowInsecureUnrestrictedDelegation) {
1409
+ throw new Error(
1410
+ "No caveats found. If you definitely want to sign a delegation without caveats, set `allowInsecureUnrestrictedDelegation` to `true`."
1411
+ );
1412
+ }
1413
+ return {
1414
+ domain: {
1415
+ chainId,
1416
+ name,
1417
+ version,
1418
+ verifyingContract: delegationManager
1419
+ },
1420
+ types: SIGNABLE_DELEGATION_TYPED_DATA,
1421
+ primaryType: "Delegation",
1422
+ message: delegationStruct
1423
+ };
1424
+ };
1425
+ var signDelegation = async ({
1426
+ privateKey,
1427
+ delegation,
1428
+ delegationManager,
1429
+ chainId,
1430
+ name = "DelegationManager",
1431
+ version = "1",
1432
+ allowInsecureUnrestrictedDelegation = false
1433
+ }) => {
1434
+ const typedData = prepareSignDelegationTypedData({
1435
+ delegation,
1436
+ delegationManager,
1437
+ chainId,
1438
+ name,
1439
+ version,
1440
+ allowInsecureUnrestrictedDelegation
1441
+ });
1442
+ return _accounts.signTypedData.call(void 0, {
1443
+ privateKey,
1444
+ ...typedData
1445
+ });
1446
+ };
1447
+
1448
+
1449
+
1450
+
1451
+
1452
+
1453
+
1454
+
1455
+
1456
+
1457
+
1458
+
1459
+
1460
+
1461
+
1462
+
1463
+
1464
+
1465
+
1466
+
1467
+
1468
+
1469
+
1470
+
1471
+ exports.__export = __export; exports.CaveatBuilder = CaveatBuilder; exports.BalanceChangeType = BalanceChangeType; exports.createCaveatBuilder = createCaveatBuilder; exports.createCaveat = createCaveat; exports.ANY_BENEFICIARY = _delegationcore.ANY_BENEFICIARY; exports.DELEGATION_TYPEHASH = _delegationcore.DELEGATION_TYPEHASH; exports.ROOT_AUTHORITY = _delegationcore.ROOT_AUTHORITY; exports.DELEGATION_ABI_TYPE_COMPONENTS = DELEGATION_ABI_TYPE_COMPONENTS; exports.toDelegationStruct = toDelegationStruct; exports.toDelegation = toDelegation; exports.encodeDelegations = encodeDelegations; exports.encodePermissionContexts = encodePermissionContexts; exports.decodeDelegations = decodeDelegations; exports.decodePermissionContexts = decodePermissionContexts; exports.SIGNABLE_DELEGATION_TYPED_DATA = SIGNABLE_DELEGATION_TYPED_DATA; exports.DELEGATION_ARRAY_ABI_TYPE = DELEGATION_ARRAY_ABI_TYPE; exports.getDelegationHashOffchain = getDelegationHashOffchain; exports.createDelegation = createDelegation; exports.createOpenDelegation = createOpenDelegation; exports.prepareSignDelegationTypedData = prepareSignDelegationTypedData; exports.signDelegation = signDelegation;
1472
+ //# sourceMappingURL=chunk-HLCOMYYU.cjs.map