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IAED,OAAO,8BAA8B,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC,uBAAuB,EAAE,QAAQ,CAAC,mBAAmB,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"]}