{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,IAAY,mCAKX;AALD,WAAY,mCAAmC;IAC7C,mGAA4D,CAAA;IAC5D,mGAA4D,CAAA;IAC5D,yGAAkE,CAAA;IAClE,0HAAmF,CAAA;AACrF,CAAC,EALW,mCAAmC,mDAAnC,mCAAmC,QAK9C;AAED;;GAEG;AACH,IAAY,6BAKX;AALD,WAAY,6BAA6B;IACvC;;OAEG;IACH,sHAAqF,CAAA;AACvF,CAAC,EALW,6BAA6B,6CAA7B,6BAA6B,QAKxC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Enum for the error codes of the gator permissions controller.\n */\nexport enum GatorPermissionsControllerErrorCode {\n  GatorPermissionsFetchError = 'gator-permissions-fetch-error',\n  GatorPermissionsNotEnabled = 'gator-permissions-not-enabled',\n  GatorPermissionsProviderError = 'gator-permissions-provider-error',\n  GatorPermissionsMapSerializationError = 'gator-permissions-map-serialization-error',\n}\n\n/**\n * Enum for the RPC methods of the gator permissions provider snap.\n */\nexport enum GatorPermissionsSnapRpcMethod {\n  /**\n   * This method is used by the metamask to request a permissions provider to get granted permissions for all sites.\n   */\n  PermissionProviderGetGrantedPermissions = 'permissionsProvider_getGrantedPermissions',\n}\n\ntype BasePermission = {\n  type: string;\n\n  /**\n   * Data structure varies by permission type.\n   */\n  data: Record<string, unknown>;\n\n  /**\n   * set of restrictions or conditions that a signer must abide by when redeeming a Permission.\n   */\n  rules?: Record<string, unknown>;\n};\n\nexport type MetaMaskBasePermissionData = {\n  /**\n   * A human-readable explanation of why the permission is being requested.\n   */\n  justification: string;\n};\n\nexport type NativeTokenStreamPermission = BasePermission & {\n  type: 'native-token-stream';\n  data: MetaMaskBasePermissionData & {\n    initialAmount?: Hex;\n    maxAmount?: Hex;\n    amountPerSecond: Hex;\n    startTime: number;\n  };\n};\n\nexport type NativeTokenPeriodicPermission = BasePermission & {\n  type: 'native-token-periodic';\n  data: MetaMaskBasePermissionData & {\n    periodAmount: Hex;\n    periodDuration: number;\n    startTime: number;\n  };\n};\n\nexport type Erc20TokenStreamPermission = BasePermission & {\n  type: 'erc20-token-stream';\n  data: MetaMaskBasePermissionData & {\n    initialAmount?: Hex;\n    maxAmount?: Hex;\n    amountPerSecond: Hex;\n    startTime: number;\n    tokenAddress: Hex;\n  };\n};\n\nexport type Erc20TokenPeriodicPermission = BasePermission & {\n  type: 'erc20-token-periodic';\n  data: MetaMaskBasePermissionData & {\n    periodAmount: Hex;\n    periodDuration: number;\n    startTime: number;\n    tokenAddress: Hex;\n  };\n};\n\nexport type CustomPermission = BasePermission & {\n  type: 'custom';\n  data: MetaMaskBasePermissionData & Record<string, unknown>;\n};\n\n/**\n * Represents the type of the ERC-7715 permissions that can be granted.\n */\nexport type PermissionTypes =\n  | NativeTokenStreamPermission\n  | NativeTokenPeriodicPermission\n  | Erc20TokenStreamPermission\n  | Erc20TokenPeriodicPermission\n  | CustomPermission;\n\n/**\n * Represents an ERC-7715 account signer type.\n */\nexport type AccountSigner = {\n  type: 'account';\n  data: {\n    address: Hex;\n  };\n};\n\n/**\n * Represents an ERC-7715 wallet signer type.\n *\n */\nexport type WalletSigner = {\n  type: 'wallet';\n  data: Record<string, unknown>;\n};\n\nexport type SignerParam = AccountSigner | WalletSigner;\n\n/**\n * Represents a ERC-7715 permission request.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionRequest<\n  TSigner extends SignerParam,\n  TPermission extends PermissionTypes,\n> = {\n  /**\n   * hex-encoding of uint256 defined the chain with EIP-155\n   */\n  chainId: Hex;\n\n  /**\n   *\n   * The account being targeted for this permission request.\n   * It is optional to let the user choose which account to grant permission from.\n   */\n  address?: Hex;\n\n  /**\n   * unix timestamp in seconds\n   */\n  expiry: number;\n\n  /**\n   * Boolean value that allows DApp to define whether the permission can be attenuated–adjusted to meet the user’s terms.\n   */\n  isAdjustmentAllowed: boolean;\n\n  /**\n   * An account that is associated with the recipient of the granted 7715 permission or alternatively the wallet will manage the session.\n   */\n  signer: TSigner;\n\n  /**\n   * Defines the allowed behavior the signer can do on behalf of the account.\n   */\n  permission: TPermission;\n};\n\n/**\n * Represents a ERC-7715 permission response.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionResponse<\n  TSigner extends SignerParam,\n  TPermission extends PermissionTypes,\n> = PermissionRequest<TSigner, TPermission> & {\n  /**\n   * Is a catch-all to identify a permission for revoking permissions or submitting\n   * Defined in ERC-7710.\n   */\n  context: Hex;\n\n  /**\n   * The accountMeta field is required and contains information needed to deploy accounts.\n   * Each entry specifies a factory contract and its associated deployment data.\n   * If no account deployment is needed when redeeming the permission, this array must be empty.\n   * When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata.\n   * Defined in ERC-4337.\n   */\n  accountMeta: {\n    factory: Hex;\n    factoryData: Hex;\n  }[];\n\n  /**\n   * If the signer type is account then delegationManager is required as defined in ERC-7710.\n   */\n  signerMeta: {\n    delegationManager: Hex;\n  };\n};\n\n/**\n * Represents a sanitized version of the PermissionResponse type.\n * Some fields have been removed but the fields are still present in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type PermissionResponseSanitized<\n  TSigner extends SignerParam,\n  TPermission extends PermissionTypes,\n> = Omit<\n  PermissionResponse<TSigner, TPermission>,\n  'isAdjustmentAllowed' | 'accountMeta' | 'signer'\n>;\n\n/**\n * Represents a gator ERC-7715 granted(ie. signed by an user account) permission entry that is stored in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided\n */\nexport type StoredGatorPermission<\n  TSigner extends SignerParam,\n  TPermission extends PermissionTypes,\n> = {\n  permissionResponse: PermissionResponse<TSigner, TPermission>;\n  siteOrigin: string;\n};\n\n/**\n * Represents a sanitized version of the StoredGatorPermission type. Some fields have been removed but the fields are still present in profile sync.\n *\n * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner.\n * @template Permission - The type of the permission provided.\n */\nexport type StoredGatorPermissionSanitized<\n  TSigner extends SignerParam,\n  TPermission extends PermissionTypes,\n> = {\n  permissionResponse: PermissionResponseSanitized<TSigner, TPermission>;\n  siteOrigin: string;\n};\n\n/**\n * Represents a map of gator permissions by chainId and permission type.\n */\nexport type GatorPermissionsMap = {\n  'native-token-stream': {\n    [chainId: Hex]: StoredGatorPermissionSanitized<\n      SignerParam,\n      NativeTokenStreamPermission\n    >[];\n  };\n  'native-token-periodic': {\n    [chainId: Hex]: StoredGatorPermissionSanitized<\n      SignerParam,\n      NativeTokenPeriodicPermission\n    >[];\n  };\n  'erc20-token-stream': {\n    [chainId: Hex]: StoredGatorPermissionSanitized<\n      SignerParam,\n      Erc20TokenStreamPermission\n    >[];\n  };\n  'erc20-token-periodic': {\n    [chainId: Hex]: StoredGatorPermissionSanitized<\n      SignerParam,\n      Erc20TokenPeriodicPermission\n    >[];\n  };\n  other: {\n    [chainId: Hex]: StoredGatorPermissionSanitized<\n      SignerParam,\n      CustomPermission\n    >[];\n  };\n};\n\n/**\n * Represents the supported permission type(e.g. 'native-token-stream', 'native-token-periodic', 'erc20-token-stream', 'erc20-token-periodic') of the gator permissions map.\n */\nexport type SupportedGatorPermissionType = keyof GatorPermissionsMap;\n\n/**\n * Represents a map of gator permissions for a given permission type with key of chainId. The value being an array of gator permissions for that chainId.\n */\nexport type GatorPermissionsMapByPermissionType<\n  TPermissionType extends SupportedGatorPermissionType,\n> = GatorPermissionsMap[TPermissionType];\n\n/**\n * Represents an array of gator permissions for a given permission type and chainId.\n */\nexport type GatorPermissionsListByPermissionTypeAndChainId<\n  TPermissionType extends SupportedGatorPermissionType,\n> = GatorPermissionsMap[TPermissionType][Hex];\n"]}