@metamask/smart-accounts-kit 1.1.0 → 1.3.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 (70) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +34 -2
  3. package/dist/actions/index.cjs +5 -5
  4. package/dist/actions/index.d.cts +2 -2
  5. package/dist/actions/index.d.ts +2 -2
  6. package/dist/actions/index.mjs +4 -4
  7. package/dist/{smartAccountsEnvironment-BIcho7e0.d.cts → caveats-CQbtzOKm.d.ts} +9 -2
  8. package/dist/{smartAccountsEnvironment-Bso0CIWt.d.ts → caveats-Cey0wm33.d.cts} +9 -2
  9. package/dist/{chunk-YSBBRLMT.mjs → chunk-26PADMXR.mjs} +5 -5
  10. package/dist/{chunk-BYWRJGSK.cjs → chunk-3PBVHNYP.cjs} +16 -16
  11. package/dist/{chunk-BYWRJGSK.cjs.map → chunk-3PBVHNYP.cjs.map} +1 -1
  12. package/dist/{chunk-TPBFVDVM.mjs → chunk-4QXIOE7F.mjs} +8 -6
  13. package/dist/chunk-4QXIOE7F.mjs.map +1 -0
  14. package/dist/{chunk-F2RG26RH.cjs → chunk-57I2FJY7.cjs} +105 -105
  15. package/dist/{chunk-F2RG26RH.cjs.map → chunk-57I2FJY7.cjs.map} +1 -1
  16. package/dist/{chunk-YTELOQ4I.mjs → chunk-AC2BQSYP.mjs} +2 -2
  17. package/dist/{chunk-QMRKCB7T.cjs → chunk-AJWMPR7X.cjs} +146 -48
  18. package/dist/chunk-AJWMPR7X.cjs.map +1 -0
  19. package/dist/{chunk-23YXLKTX.cjs → chunk-DLCTHNAE.cjs} +14 -14
  20. package/dist/{chunk-23YXLKTX.cjs.map → chunk-DLCTHNAE.cjs.map} +1 -1
  21. package/dist/{chunk-NOCLGZGB.mjs → chunk-FKI4OME5.mjs} +109 -11
  22. package/dist/chunk-FKI4OME5.mjs.map +1 -0
  23. package/dist/{chunk-UUOH2WAW.cjs → chunk-GZ7HHI2D.cjs} +12 -12
  24. package/dist/{chunk-UUOH2WAW.cjs.map → chunk-GZ7HHI2D.cjs.map} +1 -1
  25. package/dist/{chunk-WV2R7BXP.mjs → chunk-KBSFVKUB.mjs} +3 -3
  26. package/dist/{chunk-45GHWVQA.mjs → chunk-LQXOM3TA.mjs} +4 -4
  27. package/dist/{chunk-VLKX4BR6.cjs → chunk-MOHCTPYQ.cjs} +8 -6
  28. package/dist/chunk-MOHCTPYQ.cjs.map +1 -0
  29. package/dist/{chunk-YDLLC6PP.cjs → chunk-SZOX7K2V.cjs} +519 -16
  30. package/dist/chunk-SZOX7K2V.cjs.map +1 -0
  31. package/dist/{chunk-C5ZEEH2Z.mjs → chunk-Z4D7ZWVB.mjs} +517 -14
  32. package/dist/chunk-Z4D7ZWVB.mjs.map +1 -0
  33. package/dist/contracts/index.cjs +6 -6
  34. package/dist/contracts/index.d.cts +2 -2
  35. package/dist/contracts/index.d.ts +2 -2
  36. package/dist/contracts/index.mjs +5 -5
  37. package/dist/{delegation-DgmIOh21.d.ts → delegation-Bx4FEAIU.d.ts} +1 -1
  38. package/dist/{delegation-Ci3me5Rg.d.cts → delegation-KbWHzRxV.d.cts} +1 -1
  39. package/dist/experimental/index.cjs +36 -4
  40. package/dist/experimental/index.cjs.map +1 -1
  41. package/dist/experimental/index.d.cts +4 -1
  42. package/dist/experimental/index.d.ts +4 -1
  43. package/dist/experimental/index.mjs +35 -3
  44. package/dist/experimental/index.mjs.map +1 -1
  45. package/dist/{index-Uj_xXVko.d.cts → index-BDC55AA9.d.cts} +5 -3
  46. package/dist/{index-UF6eCzBC.d.ts → index-D2THBlfm.d.ts} +1 -1
  47. package/dist/{index-CSjEW7MJ.d.cts → index-DE87r5KY.d.cts} +1 -1
  48. package/dist/{index-D7fBuNV-.d.ts → index-DhG2lH80.d.ts} +5 -3
  49. package/dist/index.cjs +33 -17
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +9 -11
  52. package/dist/index.d.ts +9 -11
  53. package/dist/index.mjs +24 -8
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/utils/index.cjs +7 -5
  56. package/dist/utils/index.cjs.map +1 -1
  57. package/dist/utils/index.d.cts +2 -2
  58. package/dist/utils/index.d.ts +2 -2
  59. package/dist/utils/index.mjs +6 -4
  60. package/package.json +5 -4
  61. package/dist/chunk-C5ZEEH2Z.mjs.map +0 -1
  62. package/dist/chunk-NOCLGZGB.mjs.map +0 -1
  63. package/dist/chunk-QMRKCB7T.cjs.map +0 -1
  64. package/dist/chunk-TPBFVDVM.mjs.map +0 -1
  65. package/dist/chunk-VLKX4BR6.cjs.map +0 -1
  66. package/dist/chunk-YDLLC6PP.cjs.map +0 -1
  67. /package/dist/{chunk-YSBBRLMT.mjs.map → chunk-26PADMXR.mjs.map} +0 -0
  68. /package/dist/{chunk-YTELOQ4I.mjs.map → chunk-AC2BQSYP.mjs.map} +0 -0
  69. /package/dist/{chunk-WV2R7BXP.mjs.map → chunk-KBSFVKUB.mjs.map} +0 -0
  70. /package/dist/{chunk-45GHWVQA.mjs.map → chunk-LQXOM3TA.mjs.map} +0 -0
@@ -1,4 +1,4 @@
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;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _class;var __defProp = Object.defineProperty;
2
2
  var __export = (target, all) => {
3
3
  for (var name in all)
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -999,8 +999,8 @@ var timestamp = "timestamp";
999
999
  var timestampBuilder = (environment, config) => {
1000
1000
  const { afterThreshold, beforeThreshold } = config;
1001
1001
  const terms = _delegationcore.createTimestampTerms.call(void 0, {
1002
- timestampAfterThreshold: afterThreshold,
1003
- timestampBeforeThreshold: beforeThreshold
1002
+ afterThreshold,
1003
+ beforeThreshold
1004
1004
  });
1005
1005
  const {
1006
1006
  caveatEnforcers: { TimestampEnforcer }
@@ -1360,6 +1360,39 @@ var resolveCaveats = ({
1360
1360
 
1361
1361
 
1362
1362
 
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+
1372
+
1373
+
1374
+
1375
+
1376
+
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+
1384
+
1385
+
1386
+
1387
+
1388
+
1389
+
1390
+
1391
+
1392
+
1393
+
1394
+
1395
+
1363
1396
  var CAVEAT_ABI_TYPE_COMPONENTS = [
1364
1397
  { type: "address", name: "enforcer" },
1365
1398
  { type: "bytes", name: "terms" },
@@ -1368,11 +1401,132 @@ var CAVEAT_ABI_TYPE_COMPONENTS = [
1368
1401
  var CAVEAT_TYPEHASH = _viem.keccak256.call(void 0,
1369
1402
  _viem.toHex.call(void 0, "Caveat(address enforcer,bytes terms)")
1370
1403
  );
1371
- var createCaveat = (enforcer, terms, args = "0x00") => ({
1372
- enforcer,
1373
- terms,
1374
- args
1375
- });
1404
+ var createCaveat = (enforcer, terms, args = "0x00") => {
1405
+ return {
1406
+ enforcer,
1407
+ terms,
1408
+ args
1409
+ };
1410
+ };
1411
+ var decodeCaveat = ({
1412
+ caveat: { enforcer, terms },
1413
+ environment: { caveatEnforcers }
1414
+ }) => {
1415
+ switch (enforcer.toLowerCase()) {
1416
+ case _optionalChain([caveatEnforcers, 'access', _2 => _2.AllowedCalldataEnforcer, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]):
1417
+ return { type: "allowedCalldata", ..._delegationcore.decodeAllowedCalldataTerms.call(void 0, terms) };
1418
+ case _optionalChain([caveatEnforcers, 'access', _5 => _5.AllowedMethodsEnforcer, 'optionalAccess', _6 => _6.toLowerCase, 'call', _7 => _7()]):
1419
+ return { type: "allowedMethods", ..._delegationcore.decodeAllowedMethodsTerms.call(void 0, terms) };
1420
+ case _optionalChain([caveatEnforcers, 'access', _8 => _8.AllowedTargetsEnforcer, 'optionalAccess', _9 => _9.toLowerCase, 'call', _10 => _10()]):
1421
+ return { type: "allowedTargets", ..._delegationcore.decodeAllowedTargetsTerms.call(void 0, terms) };
1422
+ case _optionalChain([caveatEnforcers, 'access', _11 => _11.ArgsEqualityCheckEnforcer, 'optionalAccess', _12 => _12.toLowerCase, 'call', _13 => _13()]):
1423
+ return {
1424
+ type: "argsEqualityCheck",
1425
+ ..._delegationcore.decodeArgsEqualityCheckTerms.call(void 0, terms)
1426
+ };
1427
+ case _optionalChain([caveatEnforcers, 'access', _14 => _14.BlockNumberEnforcer, 'optionalAccess', _15 => _15.toLowerCase, 'call', _16 => _16()]):
1428
+ return { type: "blockNumber", ..._delegationcore.decodeBlockNumberTerms.call(void 0, terms) };
1429
+ case _optionalChain([caveatEnforcers, 'access', _17 => _17.DeployedEnforcer, 'optionalAccess', _18 => _18.toLowerCase, 'call', _19 => _19()]):
1430
+ return { type: "deployed", ..._delegationcore.decodeDeployedTerms.call(void 0, terms) };
1431
+ case _optionalChain([caveatEnforcers, 'access', _20 => _20.ERC20BalanceChangeEnforcer, 'optionalAccess', _21 => _21.toLowerCase, 'call', _22 => _22()]):
1432
+ return {
1433
+ type: "erc20BalanceChange",
1434
+ ..._delegationcore.decodeERC20BalanceChangeTerms.call(void 0, terms)
1435
+ };
1436
+ case _optionalChain([caveatEnforcers, 'access', _23 => _23.ERC20TransferAmountEnforcer, 'optionalAccess', _24 => _24.toLowerCase, 'call', _25 => _25()]):
1437
+ return {
1438
+ type: "erc20TransferAmount",
1439
+ ..._delegationcore.decodeERC20TransferAmountTerms.call(void 0, terms)
1440
+ };
1441
+ case _optionalChain([caveatEnforcers, 'access', _26 => _26.ERC20StreamingEnforcer, 'optionalAccess', _27 => _27.toLowerCase, 'call', _28 => _28()]):
1442
+ return { type: "erc20Streaming", ..._delegationcore.decodeERC20StreamingTerms.call(void 0, terms) };
1443
+ case _optionalChain([caveatEnforcers, 'access', _29 => _29.ERC721BalanceChangeEnforcer, 'optionalAccess', _30 => _30.toLowerCase, 'call', _31 => _31()]):
1444
+ return {
1445
+ type: "erc721BalanceChange",
1446
+ ..._delegationcore.decodeERC721BalanceChangeTerms.call(void 0, terms)
1447
+ };
1448
+ case _optionalChain([caveatEnforcers, 'access', _32 => _32.ERC721TransferEnforcer, 'optionalAccess', _33 => _33.toLowerCase, 'call', _34 => _34()]):
1449
+ return { type: "erc721Transfer", ..._delegationcore.decodeERC721TransferTerms.call(void 0, terms) };
1450
+ case _optionalChain([caveatEnforcers, 'access', _35 => _35.ERC1155BalanceChangeEnforcer, 'optionalAccess', _36 => _36.toLowerCase, 'call', _37 => _37()]):
1451
+ return {
1452
+ type: "erc1155BalanceChange",
1453
+ ..._delegationcore.decodeERC1155BalanceChangeTerms.call(void 0, terms)
1454
+ };
1455
+ case _optionalChain([caveatEnforcers, 'access', _38 => _38.IdEnforcer, 'optionalAccess', _39 => _39.toLowerCase, 'call', _40 => _40()]):
1456
+ return { type: "id", ..._delegationcore.decodeIdTerms.call(void 0, terms) };
1457
+ case _optionalChain([caveatEnforcers, 'access', _41 => _41.LimitedCallsEnforcer, 'optionalAccess', _42 => _42.toLowerCase, 'call', _43 => _43()]):
1458
+ return { type: "limitedCalls", ..._delegationcore.decodeLimitedCallsTerms.call(void 0, terms) };
1459
+ case _optionalChain([caveatEnforcers, 'access', _44 => _44.NonceEnforcer, 'optionalAccess', _45 => _45.toLowerCase, 'call', _46 => _46()]):
1460
+ return { type: "nonce", ..._delegationcore.decodeNonceTerms.call(void 0, terms) };
1461
+ case _optionalChain([caveatEnforcers, 'access', _47 => _47.TimestampEnforcer, 'optionalAccess', _48 => _48.toLowerCase, 'call', _49 => _49()]):
1462
+ return { type: "timestamp", ..._delegationcore.decodeTimestampTerms.call(void 0, terms) };
1463
+ case _optionalChain([caveatEnforcers, 'access', _50 => _50.ValueLteEnforcer, 'optionalAccess', _51 => _51.toLowerCase, 'call', _52 => _52()]):
1464
+ return { type: "valueLte", ..._delegationcore.decodeValueLteTerms.call(void 0, terms) };
1465
+ case _optionalChain([caveatEnforcers, 'access', _53 => _53.NativeTokenTransferAmountEnforcer, 'optionalAccess', _54 => _54.toLowerCase, 'call', _55 => _55()]):
1466
+ return {
1467
+ type: "nativeTokenTransferAmount",
1468
+ ..._delegationcore.decodeNativeTokenTransferAmountTerms.call(void 0, terms)
1469
+ };
1470
+ case _optionalChain([caveatEnforcers, 'access', _56 => _56.NativeBalanceChangeEnforcer, 'optionalAccess', _57 => _57.toLowerCase, 'call', _58 => _58()]):
1471
+ return {
1472
+ type: "nativeBalanceChange",
1473
+ ..._delegationcore.decodeNativeBalanceChangeTerms.call(void 0, terms)
1474
+ };
1475
+ case _optionalChain([caveatEnforcers, 'access', _59 => _59.NativeTokenStreamingEnforcer, 'optionalAccess', _60 => _60.toLowerCase, 'call', _61 => _61()]):
1476
+ return {
1477
+ type: "nativeTokenStreaming",
1478
+ ..._delegationcore.decodeNativeTokenStreamingTerms.call(void 0, terms)
1479
+ };
1480
+ case _optionalChain([caveatEnforcers, 'access', _62 => _62.NativeTokenPaymentEnforcer, 'optionalAccess', _63 => _63.toLowerCase, 'call', _64 => _64()]):
1481
+ return {
1482
+ type: "nativeTokenPayment",
1483
+ ..._delegationcore.decodeNativeTokenPaymentTerms.call(void 0, terms)
1484
+ };
1485
+ case _optionalChain([caveatEnforcers, 'access', _65 => _65.RedeemerEnforcer, 'optionalAccess', _66 => _66.toLowerCase, 'call', _67 => _67()]):
1486
+ return { type: "redeemer", ..._delegationcore.decodeRedeemerTerms.call(void 0, terms) };
1487
+ case _optionalChain([caveatEnforcers, 'access', _68 => _68.SpecificActionERC20TransferBatchEnforcer, 'optionalAccess', _69 => _69.toLowerCase, 'call', _70 => _70()]):
1488
+ return {
1489
+ type: "specificActionERC20TransferBatch",
1490
+ ..._delegationcore.decodeSpecificActionERC20TransferBatchTerms.call(void 0, terms)
1491
+ };
1492
+ case _optionalChain([caveatEnforcers, 'access', _71 => _71.ERC20PeriodTransferEnforcer, 'optionalAccess', _72 => _72.toLowerCase, 'call', _73 => _73()]):
1493
+ return {
1494
+ type: "erc20PeriodTransfer",
1495
+ ..._delegationcore.decodeERC20TokenPeriodTransferTerms.call(void 0, terms)
1496
+ };
1497
+ case _optionalChain([caveatEnforcers, 'access', _74 => _74.NativeTokenPeriodTransferEnforcer, 'optionalAccess', _75 => _75.toLowerCase, 'call', _76 => _76()]):
1498
+ return {
1499
+ type: "nativeTokenPeriodTransfer",
1500
+ ..._delegationcore.decodeNativeTokenPeriodTransferTerms.call(void 0, terms)
1501
+ };
1502
+ case _optionalChain([caveatEnforcers, 'access', _77 => _77.ExactCalldataBatchEnforcer, 'optionalAccess', _78 => _78.toLowerCase, 'call', _79 => _79()]):
1503
+ return {
1504
+ type: "exactCalldataBatch",
1505
+ ..._delegationcore.decodeExactCalldataBatchTerms.call(void 0, terms)
1506
+ };
1507
+ case _optionalChain([caveatEnforcers, 'access', _80 => _80.ExactCalldataEnforcer, 'optionalAccess', _81 => _81.toLowerCase, 'call', _82 => _82()]):
1508
+ return { type: "exactCalldata", ..._delegationcore.decodeExactCalldataTerms.call(void 0, terms) };
1509
+ case _optionalChain([caveatEnforcers, 'access', _83 => _83.ExactExecutionEnforcer, 'optionalAccess', _84 => _84.toLowerCase, 'call', _85 => _85()]):
1510
+ return { type: "exactExecution", ..._delegationcore.decodeExactExecutionTerms.call(void 0, terms) };
1511
+ case _optionalChain([caveatEnforcers, 'access', _86 => _86.ExactExecutionBatchEnforcer, 'optionalAccess', _87 => _87.toLowerCase, 'call', _88 => _88()]):
1512
+ return {
1513
+ type: "exactExecutionBatch",
1514
+ ..._delegationcore.decodeExactExecutionBatchTerms.call(void 0, terms)
1515
+ };
1516
+ case _optionalChain([caveatEnforcers, 'access', _89 => _89.MultiTokenPeriodEnforcer, 'optionalAccess', _90 => _90.toLowerCase, 'call', _91 => _91()]):
1517
+ return {
1518
+ type: "multiTokenPeriod",
1519
+ ..._delegationcore.decodeMultiTokenPeriodTerms.call(void 0, terms)
1520
+ };
1521
+ case _optionalChain([caveatEnforcers, 'access', _92 => _92.OwnershipTransferEnforcer, 'optionalAccess', _93 => _93.toLowerCase, 'call', _94 => _94()]):
1522
+ return {
1523
+ type: "ownershipTransfer",
1524
+ ..._delegationcore.decodeOwnershipTransferTerms.call(void 0, terms)
1525
+ };
1526
+ default:
1527
+ throw new Error(`Unknown enforcer address: ${enforcer}`);
1528
+ }
1529
+ };
1376
1530
 
1377
1531
  // src/delegation.ts
1378
1532
 
@@ -1388,6 +1542,317 @@ var createCaveat = (enforcer, terms, args = "0x00") => ({
1388
1542
 
1389
1543
 
1390
1544
  var _accounts = require('viem/accounts');
1545
+
1546
+ // src/analytics/index.ts
1547
+ var _openapifetch = require('openapi-fetch'); var _openapifetch2 = _interopRequireDefault(_openapifetch);
1548
+
1549
+ // src/analytics/environment.ts
1550
+ var session;
1551
+ function createAnonId() {
1552
+ if (typeof _optionalChain([globalThis, 'access', _95 => _95.crypto, 'optionalAccess', _96 => _96.randomUUID]) === "function") {
1553
+ return globalThis.crypto.randomUUID();
1554
+ }
1555
+ return `00000000-0000-4000-8000-${Math.random().toString(16).slice(2, 14).padEnd(12, "0")}`;
1556
+ }
1557
+ function inferPlatform() {
1558
+ if (typeof globalThis === "undefined" || !("window" in globalThis)) {
1559
+ return "nodejs";
1560
+ }
1561
+ const nav = globalThis.navigator;
1562
+ const ua = typeof _optionalChain([nav, 'optionalAccess', _97 => _97.userAgent]) === "string" ? nav.userAgent : "";
1563
+ if (/Mobile|Android|iPhone|iPod|webOS|BlackBerry|IEMobile|Opera Mini/iu.test(ua)) {
1564
+ return "web-mobile";
1565
+ }
1566
+ return "web-desktop";
1567
+ }
1568
+ function inferDomain() {
1569
+ if (typeof globalThis !== "undefined" && "window" in globalThis) {
1570
+ const win = globalThis;
1571
+ const hostname = _optionalChain([win, 'access', _98 => _98.location, 'optionalAccess', _99 => _99.hostname]);
1572
+ if (typeof hostname === "string" && hostname.length > 0) {
1573
+ return { domain: hostname };
1574
+ }
1575
+ }
1576
+ return {};
1577
+ }
1578
+ function getInitializationContext(params) {
1579
+ if (!session) {
1580
+ session = {
1581
+ sdk_version: params.sdk_version,
1582
+ anon_id: _nullishCoalesce(params.anon_id, () => ( createAnonId())),
1583
+ platform: inferPlatform(),
1584
+ ...inferDomain()
1585
+ };
1586
+ return { ...session };
1587
+ }
1588
+ session = {
1589
+ ...session,
1590
+ sdk_version: params.sdk_version
1591
+ };
1592
+ return { ...session };
1593
+ }
1594
+ function getSessionBaseProperties() {
1595
+ if (!session) {
1596
+ throw new Error(
1597
+ "Smart Accounts Kit analytics: call getInitializationContext({ sdk_version }) at SDK startup before recording events."
1598
+ );
1599
+ }
1600
+ return { ...session };
1601
+ }
1602
+ function mergeSessionProperties(partial) {
1603
+ if (!session) {
1604
+ throw new Error(
1605
+ "Smart Accounts Kit analytics: call getInitializationContext before mergeSessionProperties."
1606
+ );
1607
+ }
1608
+ session = { ...session, ...partial };
1609
+ }
1610
+
1611
+ // src/analytics/sender.ts
1612
+ var Sender = class {
1613
+ #sendFn;
1614
+ #batchSize;
1615
+ #baseTimeoutMs;
1616
+ #maxFailureCount;
1617
+ #maxTimeoutMs;
1618
+ #isDisabled = false;
1619
+ #batch = [];
1620
+ #failureCount = 0;
1621
+ #timeoutId = null;
1622
+ #isSending = false;
1623
+ constructor(options) {
1624
+ this.#batchSize = options.batchSize;
1625
+ this.#baseTimeoutMs = options.baseTimeoutMs;
1626
+ this.#maxFailureCount = options.maxFailureCount;
1627
+ this.#sendFn = options.sendFn;
1628
+ this.#maxTimeoutMs = options.maxTimeoutMs;
1629
+ }
1630
+ enqueue(item) {
1631
+ if (this.#isDisabled) {
1632
+ return;
1633
+ }
1634
+ this.#batch.push(item);
1635
+ this.#schedule();
1636
+ }
1637
+ #schedule() {
1638
+ if (this.#isDisabled) {
1639
+ return;
1640
+ }
1641
+ if (this.#batch.length > 0 && !this.#timeoutId) {
1642
+ const { isRetry, timeoutMs } = this.#getTimeout();
1643
+ const timeout = setTimeout(() => {
1644
+ this.#timeoutId = null;
1645
+ this.#flush();
1646
+ }, timeoutMs);
1647
+ if (isRetry && timeout.unref) {
1648
+ timeout.unref();
1649
+ }
1650
+ this.#timeoutId = timeout;
1651
+ }
1652
+ }
1653
+ async #flush() {
1654
+ if (this.#isDisabled || this.#isSending || this.#batch.length === 0) {
1655
+ return;
1656
+ }
1657
+ this.#isSending = true;
1658
+ const current = this.#batch.slice(0, this.#batchSize);
1659
+ this.#batch = this.#batch.slice(this.#batchSize);
1660
+ try {
1661
+ await this.#sendFn(current);
1662
+ this.#failureCount = 0;
1663
+ } catch (e) {
1664
+ this.#failureCount += 1;
1665
+ if (this.#failureCount >= this.#maxFailureCount) {
1666
+ this.#isDisabled = true;
1667
+ this.#batch = [];
1668
+ if (this.#timeoutId !== null) {
1669
+ clearTimeout(this.#timeoutId);
1670
+ this.#timeoutId = null;
1671
+ }
1672
+ } else {
1673
+ this.#batch = [...current, ...this.#batch];
1674
+ }
1675
+ } finally {
1676
+ this.#isSending = false;
1677
+ this.#schedule();
1678
+ }
1679
+ }
1680
+ #getTimeout() {
1681
+ const isRetry = this.#failureCount > 0;
1682
+ const timeoutMs = Math.min(
1683
+ this.#baseTimeoutMs * 2 ** this.#failureCount,
1684
+ this.#maxTimeoutMs
1685
+ );
1686
+ return { isRetry, timeoutMs };
1687
+ }
1688
+ };
1689
+
1690
+ // package.json
1691
+ var version = "1.3.0";
1692
+
1693
+ // src/analytics/index.ts
1694
+ function isCompleteBase(value) {
1695
+ return typeof value.sdk_version === "string" && value.sdk_version.length > 0 && typeof value.anon_id === "string" && value.anon_id.length > 0 && typeof value.platform === "string" && value.platform.length > 0;
1696
+ }
1697
+ function normalise(batch) {
1698
+ const walk = (value) => {
1699
+ if (typeof value === "bigint") {
1700
+ return `${value}n`;
1701
+ }
1702
+ if (value === null || typeof value !== "object") {
1703
+ return value;
1704
+ }
1705
+ if (Array.isArray(value)) {
1706
+ return value.map((item) => walk(item));
1707
+ }
1708
+ const result = {};
1709
+ for (const [key, child] of Object.entries(
1710
+ value
1711
+ )) {
1712
+ result[key] = walk(child);
1713
+ }
1714
+ return result;
1715
+ };
1716
+ return walk(batch);
1717
+ }
1718
+ var METAMASK_ANALYTICS_ENDPOINT = "https://mm-sdk-analytics.api.cx.metamask.io/";
1719
+ var Analytics = (_class = class {
1720
+ __init() {this.enabled = false}
1721
+
1722
+ constructor(baseUrl) {;_class.prototype.__init.call(this);
1723
+ const client = _openapifetch2.default.call(void 0, { baseUrl });
1724
+ const sendFn = async (batch) => {
1725
+ const normalisedBatch = normalise(batch);
1726
+ const res = await client.POST("/v2/events", { body: normalisedBatch });
1727
+ if (res.response.status !== 200) {
1728
+ throw new Error(String(res.error));
1729
+ }
1730
+ };
1731
+ this.sender = new Sender({
1732
+ batchSize: 100,
1733
+ baseTimeoutMs: 100,
1734
+ maxFailureCount: 6,
1735
+ maxTimeoutMs: 1e4,
1736
+ sendFn
1737
+ });
1738
+ }
1739
+ enable() {
1740
+ this.enabled = true;
1741
+ }
1742
+ /**
1743
+ * Merges a field into the session base (shared with {@link getSessionBaseProperties}).
1744
+ *
1745
+ * @param key - Base property name.
1746
+ * @param value - Value for that property.
1747
+ */
1748
+ setGlobalProperty(key, value) {
1749
+ mergeSessionProperties({
1750
+ [key]: value
1751
+ });
1752
+ }
1753
+ /**
1754
+ * Sends `smart_accounts_kit_initialized` using the session base from {@link getInitializationContext}
1755
+ * plus optional per-event overrides. Updates the stored session with the merged snapshot.
1756
+ *
1757
+ * @param properties - Optional overrides; omit to use the current session base only.
1758
+ */
1759
+ trackInitialized(properties = {}) {
1760
+ if (!this.enabled) {
1761
+ return;
1762
+ }
1763
+ const merged = {
1764
+ ...getSessionBaseProperties(),
1765
+ ...properties
1766
+ };
1767
+ if (!isCompleteBase(merged)) {
1768
+ throw new Error(
1769
+ "Analytics: trackInitialized produced incomplete base configuration (ensure getInitializationContext ran and sdk_version, anon_id, platform are set)"
1770
+ );
1771
+ }
1772
+ mergeSessionProperties(merged);
1773
+ const event = {
1774
+ namespace: "metamask/smart-accounts-kit",
1775
+ event_name: "smart_accounts_kit_initialized",
1776
+ properties: merged
1777
+ };
1778
+ this.sender.enqueue(event);
1779
+ }
1780
+ /**
1781
+ * Sends `smart_accounts_kit_function_called` with session base plus the function name and optional
1782
+ * non-sensitive parameters. Does not mutate the session store (unlike {@link trackInitialized}).
1783
+ *
1784
+ * @param functionName - Public SDK entry name (use a stable string, e.g. `createDelegation`).
1785
+ * @param parameters - Safe primitives only; omit secrets, keys, and raw addresses if sensitive.
1786
+ * @param baseOverrides - Optional overrides for base fields (same as {@link trackInitialized}).
1787
+ */
1788
+ trackSdkFunctionCall(functionName, parameters, baseOverrides = {}) {
1789
+ if (!this.enabled) {
1790
+ return;
1791
+ }
1792
+ const mergedBase = {
1793
+ ...getSessionBaseProperties(),
1794
+ ...baseOverrides
1795
+ };
1796
+ if (!isCompleteBase(mergedBase)) {
1797
+ throw new Error(
1798
+ "Analytics: trackSdkFunctionCall requires session (call getInitializationContext before tracking)"
1799
+ );
1800
+ }
1801
+ const props = {
1802
+ ...mergedBase,
1803
+ function_name: functionName,
1804
+ ...parameters !== void 0 && Object.keys(parameters).length > 0 ? { parameters } : {}
1805
+ };
1806
+ const event = {
1807
+ namespace: "metamask/smart-accounts-kit",
1808
+ event_name: "smart_accounts_kit_function_called",
1809
+ properties: props
1810
+ };
1811
+ this.sender.enqueue(event);
1812
+ }
1813
+ }, _class);
1814
+ var analytics = new Analytics(METAMASK_ANALYTICS_ENDPOINT);
1815
+ function isAnalyticsDisabled() {
1816
+ const dntValues = [];
1817
+ if (typeof process !== "undefined") {
1818
+ dntValues.push(_optionalChain([process, 'access', _100 => _100.env, 'optionalAccess', _101 => _101.CI]));
1819
+ dntValues.push(_optionalChain([process, 'access', _102 => _102.env, 'optionalAccess', _103 => _103.DO_NOT_TRACK]));
1820
+ }
1821
+ if (typeof navigator !== "undefined") {
1822
+ dntValues.push(navigator.doNotTrack);
1823
+ }
1824
+ if (typeof window !== "undefined") {
1825
+ dntValues.push(window.doNotTrack);
1826
+ }
1827
+ return dntValues.some(
1828
+ (dntValue) => dntValue === "1" || _optionalChain([dntValue, 'optionalAccess', _104 => _104.toLowerCase, 'call', _105 => _105()]) === "yes" || _optionalChain([dntValue, 'optionalAccess', _106 => _106.toLowerCase, 'call', _107 => _107()]) === "true"
1829
+ );
1830
+ }
1831
+ var hasBootstrapped = false;
1832
+ function ensureSmartAccountsKitAnalyticsBootstrapped() {
1833
+ if (hasBootstrapped) {
1834
+ return;
1835
+ }
1836
+ hasBootstrapped = true;
1837
+ if (isAnalyticsDisabled()) {
1838
+ return;
1839
+ }
1840
+ try {
1841
+ getInitializationContext({ sdk_version: version });
1842
+ analytics.enable();
1843
+ analytics.trackInitialized();
1844
+ } catch (e2) {
1845
+ }
1846
+ }
1847
+ function trackSmartAccountsKitFunctionCall(functionName, parameters) {
1848
+ ensureSmartAccountsKitAnalyticsBootstrapped();
1849
+ try {
1850
+ analytics.trackSdkFunctionCall(functionName, parameters);
1851
+ } catch (e3) {
1852
+ }
1853
+ }
1854
+
1855
+ // src/delegation.ts
1391
1856
  var DELEGATION_ABI_TYPE_COMPONENTS = [
1392
1857
  { type: "address", name: "delegate" },
1393
1858
  { type: "address", name: "delegator" },
@@ -1482,22 +1947,58 @@ var resolveAuthority = (parentDelegation) => {
1482
1947
  }
1483
1948
  return hashDelegation(parentDelegation);
1484
1949
  };
1950
+ var getCaveatNames = ({
1951
+ caveats,
1952
+ environment: { caveatEnforcers }
1953
+ }) => {
1954
+ if (Array.isArray(caveats)) {
1955
+ const knownEnforcers = Object.entries(caveatEnforcers).map(
1956
+ ([name, address]) => ({ name, address: address.toLowerCase() })
1957
+ );
1958
+ return caveats.map((caveat) => {
1959
+ const enforcerAddressLowercase = _optionalChain([caveat, 'access', _108 => _108.enforcer, 'optionalAccess', _109 => _109.toLowerCase, 'call', _110 => _110()]);
1960
+ const matchingCaveat = knownEnforcers.find(
1961
+ ({ address }) => address === enforcerAddressLowercase
1962
+ );
1963
+ return _nullishCoalesce(_optionalChain([matchingCaveat, 'optionalAccess', _111 => _111.name]), () => ( "Unknown"));
1964
+ });
1965
+ }
1966
+ return [];
1967
+ };
1485
1968
  var createDelegation = (options) => {
1969
+ const caveats = resolveCaveats(options);
1970
+ trackSmartAccountsKitFunctionCall("createDelegation", {
1971
+ hasParentDelegation: options.parentDelegation !== void 0,
1972
+ scope: options.scope.type,
1973
+ caveatNames: getCaveatNames({
1974
+ caveats,
1975
+ environment: options.environment
1976
+ })
1977
+ });
1486
1978
  return {
1487
1979
  delegate: options.to,
1488
1980
  delegator: options.from,
1489
1981
  authority: resolveAuthority(options.parentDelegation),
1490
- caveats: resolveCaveats(options),
1982
+ caveats,
1491
1983
  salt: _nullishCoalesce(options.salt, () => ( "0x00")),
1492
1984
  signature: "0x"
1493
1985
  };
1494
1986
  };
1495
1987
  var createOpenDelegation = (options) => {
1988
+ const caveats = resolveCaveats(options);
1989
+ trackSmartAccountsKitFunctionCall("createOpenDelegation", {
1990
+ hasParentDelegation: options.parentDelegation !== void 0,
1991
+ scope: options.scope.type,
1992
+ caveatNames: getCaveatNames({
1993
+ caveats,
1994
+ environment: options.environment
1995
+ })
1996
+ });
1496
1997
  return {
1497
1998
  delegate: _delegationcore.ANY_BENEFICIARY,
1498
1999
  delegator: options.from,
1499
2000
  authority: resolveAuthority(options.parentDelegation),
1500
- caveats: resolveCaveats(options),
2001
+ caveats,
1501
2002
  salt: _nullishCoalesce(options.salt, () => ( "0x00")),
1502
2003
  signature: "0x"
1503
2004
  };
@@ -1507,7 +2008,7 @@ var prepareSignDelegationTypedData = ({
1507
2008
  delegationManager,
1508
2009
  chainId,
1509
2010
  name = "DelegationManager",
1510
- version = "1",
2011
+ version: version2 = "1",
1511
2012
  allowInsecureUnrestrictedDelegation = false
1512
2013
  }) => {
1513
2014
  const delegationStruct = toDelegationStruct({
@@ -1523,7 +2024,7 @@ var prepareSignDelegationTypedData = ({
1523
2024
  domain: {
1524
2025
  chainId,
1525
2026
  name,
1526
- version,
2027
+ version: version2,
1527
2028
  verifyingContract: delegationManager
1528
2029
  },
1529
2030
  types: SIGNABLE_DELEGATION_TYPED_DATA,
@@ -1537,7 +2038,7 @@ var signDelegation = async ({
1537
2038
  delegationManager,
1538
2039
  chainId,
1539
2040
  name = "DelegationManager",
1540
- version = "1",
2041
+ version: version2 = "1",
1541
2042
  allowInsecureUnrestrictedDelegation = false
1542
2043
  }) => {
1543
2044
  const typedData = prepareSignDelegationTypedData({
@@ -1545,7 +2046,7 @@ var signDelegation = async ({
1545
2046
  delegationManager,
1546
2047
  chainId,
1547
2048
  name,
1548
- version,
2049
+ version: version2,
1549
2050
  allowInsecureUnrestrictedDelegation
1550
2051
  });
1551
2052
  return _accounts.signTypedData.call(void 0, {
@@ -1584,5 +2085,7 @@ var signDelegation = async ({
1584
2085
 
1585
2086
 
1586
2087
 
1587
- exports.__export = __export; exports.Implementation = Implementation; exports.TransferWindow = TransferWindow; exports.ScopeType = ScopeType; exports.CaveatType = CaveatType; exports.CaveatBuilder = CaveatBuilder; exports.BalanceChangeType = BalanceChangeType; exports.createCaveatBuilder = createCaveatBuilder; exports.isDefined = isDefined; exports.toHexOrThrow = toHexOrThrow; 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.encodeDelegation = encodeDelegation; exports.decodeDelegations = decodeDelegations; exports.decodeDelegation = decodeDelegation; exports.SIGNABLE_DELEGATION_TYPED_DATA = SIGNABLE_DELEGATION_TYPED_DATA; exports.DELEGATION_ARRAY_ABI_TYPE = DELEGATION_ARRAY_ABI_TYPE; exports.DELEGATION_ABI_TYPE = DELEGATION_ABI_TYPE; exports.hashDelegation = hashDelegation; exports.createDelegation = createDelegation; exports.createOpenDelegation = createOpenDelegation; exports.prepareSignDelegationTypedData = prepareSignDelegationTypedData; exports.signDelegation = signDelegation;
1588
- //# sourceMappingURL=chunk-YDLLC6PP.cjs.map
2088
+
2089
+
2090
+ exports.__export = __export; exports.trackSmartAccountsKitFunctionCall = trackSmartAccountsKitFunctionCall; exports.Implementation = Implementation; exports.TransferWindow = TransferWindow; exports.ScopeType = ScopeType; exports.CaveatType = CaveatType; exports.CaveatBuilder = CaveatBuilder; exports.BalanceChangeType = BalanceChangeType; exports.createCaveatBuilder = createCaveatBuilder; exports.isDefined = isDefined; exports.toHexOrThrow = toHexOrThrow; exports.createCaveat = createCaveat; exports.decodeCaveat = decodeCaveat; 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.encodeDelegation = encodeDelegation; exports.decodeDelegations = decodeDelegations; exports.decodeDelegation = decodeDelegation; exports.SIGNABLE_DELEGATION_TYPED_DATA = SIGNABLE_DELEGATION_TYPED_DATA; exports.DELEGATION_ARRAY_ABI_TYPE = DELEGATION_ARRAY_ABI_TYPE; exports.DELEGATION_ABI_TYPE = DELEGATION_ABI_TYPE; exports.hashDelegation = hashDelegation; exports.createDelegation = createDelegation; exports.createOpenDelegation = createOpenDelegation; exports.prepareSignDelegationTypedData = prepareSignDelegationTypedData; exports.signDelegation = signDelegation;
2091
+ //# sourceMappingURL=chunk-SZOX7K2V.cjs.map