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AO,mCAA2B,CAAC;IACrC,CAAC;IAED,OAAO,sCAA8B,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACU,QAAA,4BAA4B,GAAG,IAAA,oBAAM,EAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC,+BAAuB,EAAE,IAAA,sBAAQ,EAAC,2BAAmB,CAAC,CAAC;CACvE,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n  array,\n  size,\n  literal,\n  number,\n  object,\n  refine,\n  string,\n  record,\n  nullable,\n  optional,\n  boolean,\n  union,\n} from '@metamask/superstruct';\nimport {\n  CaipAccountIdStruct,\n  CaipAssetTypeOrIdStruct,\n  assert,\n  isObject,\n} from '@metamask/utils';\nimport type { CaipAssetTypeOrId } from '@metamask/utils';\n\nimport { selectiveUnion } from '../../internals';\n\nexport const FungibleAssetUnitStruct = object({\n  name: optional(string()),\n  symbol: optional(string()),\n  decimals: number(),\n});\n\n/**\n * A unit of a fungible asset, which can be used to represent\n * different denominations of the asset.\n *\n * @property name - The name of the unit, if available.\n * @property symbol - The symbol of the unit, if available.\n * @property decimals - The number of decimal places for the unit.\n */\nexport type FungibleAssetUnit = Infer<typeof FungibleAssetUnitStruct>;\n\nexport const AssetIconUrlStruct = refine(string(), 'Asset URL', (value) => {\n  try {\n    const url = new URL(value);\n    // For now, we require asset URLs to either be base64 SVGs or remote HTTPS URLs\n    assert(\n      url.protocol === 'https:' ||\n        value.startsWith('data:image/svg+xml;base64,'),\n    );\n    return true;\n  } catch {\n    return 'Invalid URL';\n  }\n});\n\n/**\n * A struct representing the metadata for a fungible asset.\n *\n * @property name - The name of the asset, if available.\n * @property symbol - The symbol of the asset, if available.\n * @property fungible - Indicates that this is a fungible asset. This is always `\n * true` for fungible assets.\n * @property iconUrl - The URL of the asset's icon, which can be a base64 SVG or a remote HTTPS URL.\n * @property units - An array of units for the asset, each represented by {@link FungibleAssetUnitStruct}.\n */\nexport const FungibleAssetMetadataStruct = object({\n  name: optional(string()),\n  symbol: optional(string()),\n  fungible: literal(true),\n  iconUrl: AssetIconUrlStruct,\n  units: size(array(FungibleAssetUnitStruct), 1, Infinity),\n});\n\n/**\n * A collection of non-fungible assets, which can be used to group\n * assets that share a common theme or creator.\n *\n * @property name - The name of the collection.\n * @property address - The CAIP-10 account ID of the collection's creator.\n * @property symbol - The symbol of the collection.\n * @property tokenCount - The number of tokens in the collection, if available.\n * @property creator - The CAIP-10 account ID of the collection's creator, if\n * available.\n * @property imageUrl - The URL of the collection's image.\n */\nexport const NonFungibleAssetCollectionStruct = object({\n  name: string(),\n  address: CaipAccountIdStruct,\n  symbol: string(),\n  tokenCount: optional(number()),\n  creator: optional(CaipAccountIdStruct),\n  imageUrl: optional(AssetIconUrlStruct),\n});\n\n/**\n * A collection of non-fungible assets, which can be used to group\n * assets that share a common theme or creator.\n *\n * @property name - The name of the collection.\n * @property address - The CAIP-10 account ID of the collection's creator.\n * @property symbol - The symbol of the collection.\n * @property tokenCount - The number of tokens in the collection, if available.\n * @property creator - The CAIP-10 account ID of the collection's creator, if\n * available.\n * @property imageUrl - The URL of the collection's image.\n */\nexport type NonFungibleAssetCollection = Infer<\n  typeof NonFungibleAssetCollectionStruct\n>;\n\n/**\n * A struct representing the metadata for a non-fungible asset.\n *\n * @property fungible - Indicates that this is a non-fungible asset.\n * This is always `false` for non-fungible assets.\n * @property name - The name of the asset, if available.\n * @property symbol - The symbol of the asset, if available.\n * @property imageUrl - The URL of the asset's image, which can be a base64 SVG or a remote HTTPS URL.\n * @property description - A description of the asset, if available.\n * @property acquiredAt - The timestamp when the asset was acquired, if available.\n * @property isPossibleSpam - Indicates if the asset is possibly spam, if available.\n * @property attributes - Additional attributes of the asset, represented as a record of string keys and\n * string or number values.\n * @property collection - The collection the asset belongs to, if available. See {@link NonFungibleAssetCollectionStruct}.\n */\nexport const NonFungibleAssetMetadataStruct = object({\n  fungible: literal(false),\n  name: optional(string()),\n  symbol: optional(string()),\n  imageUrl: optional(AssetIconUrlStruct),\n  description: optional(string()),\n  acquiredAt: optional(number()),\n  isPossibleSpam: optional(boolean()),\n  attributes: optional(record(string(), union([string(), number()]))),\n  collection: optional(NonFungibleAssetCollectionStruct),\n});\n\n/**\n * A struct representing the metadata for an asset, which can be either\n * {@link FungibleAssetMetadataStruct} or {@link NonFungibleAssetMetadataStruct}.\n */\nexport const AssetMetadataStruct = selectiveUnion((metadata) => {\n  if (isObject(metadata) && metadata.fungible) {\n    return FungibleAssetMetadataStruct;\n  }\n\n  return NonFungibleAssetMetadataStruct;\n});\n\n/**\n * A struct representing the response of the `onAssetsLookup` method.\n *\n * @property assets - An object containing a mapping between the CAIP-19 key and a metadata object or null.\n */\nexport const OnAssetsLookupResponseStruct = object({\n  assets: record(CaipAssetTypeOrIdStruct, nullable(AssetMetadataStruct)),\n});\n\n/**\n * The metadata for an asset, which can be either fungible or non-fungible.\n *\n */\nexport type AssetMetadata = Infer<typeof AssetMetadataStruct>;\n\n/**\n * The metadata for a fungible asset.\n *\n * @property fungible - Indicates that this is a fungible asset.\n * This is always `true` for fungible assets.\n * @property name - The name of the asset.\n * @property symbol - The symbol of the asset.\n * @property iconUrl - The URL of the asset's icon.\n * @property units - An array of units for the asset, each represented by {@link FungibleAssetUnit}.\n */\nexport type FungibleAssetMetadata = Infer<typeof FungibleAssetMetadataStruct>;\n\n/**\n * The metadata for a non-fungible asset.\n *\n * @property fungible - Indicates that this is a non-fungible asset.\n * This is always `false` for non-fungible assets.\n * @property name - The name of the asset.\n * @property symbol - The symbol of the asset.\n * @property imageUrl - The URL of the asset's image.\n * @property description - A description of the asset.\n * @property acquiredAt - The timestamp when the asset was acquired, if available.\n * @property isPossibleSpam - Indicates if the asset is possibly spam, if available.\n * @property attributes - Additional attributes of the asset, represented as a record of string keys and\n * string or number values.\n * @property collection - The collection the asset belongs to, if available. See {@link NonFungibleAssetCollection}.\n */\nexport type NonFungibleAssetMetadata = Infer<\n  typeof NonFungibleAssetMetadataStruct\n>;\n\n/**\n * The arguments for the `onAssetsLookup` handler.\n *\n * @property assets - An array of CAIP-19 asset types to look up.\n */\nexport type OnAssetsLookupArguments = {\n  assets: CaipAssetTypeOrId[];\n};\n\n/**\n * The `onAssetsLookup` handler. This is called by MetaMask when querying about specific assets on specific chains.\n *\n * @returns The metadata about each asset. See\n * {@link OnAssetsLookupResponse}.\n */\nexport type OnAssetsLookupHandler = (\n  args: OnAssetsLookupArguments,\n) => Promise<OnAssetsLookupResponse>;\n\n/**\n * The response from the query, containing metadata about each requested asset.\n *\n * @property assets - An object containing a mapping between the CAIP-19 key and a metadata object or null.\n */\nexport type OnAssetsLookupResponse = {\n  assets: Record<CaipAssetTypeOrId, AssetMetadata | null>;\n};\n"]}