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;;GAMG;AACH,SAAgB,UAAU,CACxB,GAAY,EACZ,OAAwB,EAAE;IAE1B,OAAO,IAAA,gBAAE,EAAC,GAAG,EAAE,IAAA,eAAG,EAAC,IAAI,CAAC,CAAC,CAAC;AAC5B,CAAC;AALD,gCAKC;AAED,+CAA+C;AAClC,QAAA,0BAA0B,GAAG,aAAa,CAAC","sourcesContent":["import type { UriOptions } from '@metamask/snaps-sdk';\nimport { uri } from '@metamask/snaps-sdk';\nimport { is, optional, size, string, type } from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { definePattern, VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n  PackageJson = 'package.json',\n  Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n  definePattern(\n    'Snap Name',\n    /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n  ),\n  1,\n  214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n  version: VersionStruct,\n  name: NameStruct,\n  main: optional(size(string(), 1, Infinity)),\n  repository: optional(\n    type({\n      type: size(string(), 1, Infinity),\n      url: size(string(), 1, Infinity),\n    }),\n  ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n  Record<string, any>;\n\n/**\n * An extendable manifest, which consists of a base manifest, an optional\n * extended manifest, and the merged manifest, all unvalidated.\n */\nexport type UnvalidatedExtendableManifest = {\n  /**\n   * The main manifest, i.e., the manifest at the given path. This may extend\n   * another manifest, and can be partial.\n   */\n  mainManifest: VirtualFile<Json>;\n\n  /**\n   * The extended manifest, if any. This is the manifest that the main manifest\n   * extends. This can be partial.\n   */\n  extendedManifest?: Json;\n\n  /**\n   * The result of deep merging the main and extended manifests. This should\n   * always be a complete manifest.\n   */\n  mergedManifest: Json;\n\n  /**\n   * The set of file paths that were involved in creating this extendable\n   * manifest, including the main and extended manifests.\n   */\n  files: Set<string>;\n};\n\n/**\n * A utility type that makes all properties of a type optional, recursively.\n */\nexport type DeepPartial<Type> = Type extends string\n  ? Type\n  : {\n      [Property in keyof Type]?: Type[Property] extends (infer Value)[]\n        ? DeepPartial<Value>[]\n        : Type[Property] extends readonly (infer Value)[]\n          ? readonly DeepPartial<Value>[]\n          : Type[Property] extends object\n            ? DeepPartial<Type[Property]>\n            : Type[Property];\n    };\n\n/**\n * An extendable manifest, which consists of a main manifest, an optional\n * extended manifest, and the merged manifest.\n */\nexport type ExtendableManifest = {\n  /**\n   * The main manifest, i.e., the manifest at the given path. This may extend\n   * another manifest, and can be partial.\n   */\n  mainManifest: VirtualFile<DeepPartial<SnapManifest>>;\n\n  /**\n   * The extended manifest, if any. This is the manifest that the main manifest\n   * extends. This can be partial.\n   */\n  extendedManifest?: DeepPartial<SnapManifest>;\n\n  /**\n   * The result of deep merging the main and extended manifests. This should\n   * always be a complete manifest.\n   */\n  mergedManifest: SnapManifest;\n\n  /**\n   * The set of file paths that were involved in creating this extendable\n   * manifest, including the main and extended manifests.\n   */\n  files: Set<string>;\n};\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n  manifest?: UnvalidatedExtendableManifest;\n  packageJson?: VirtualFile<Json>;\n  sourceCode?: VirtualFile;\n  svgIcon?: VirtualFile;\n  auxiliaryFiles: VirtualFile[];\n  localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n  manifest: VirtualFile<SnapManifest>;\n  packageJson: VirtualFile<NpmSnapPackageJson>;\n  sourceCode: VirtualFile;\n  svgIcon?: VirtualFile;\n  auxiliaryFiles: VirtualFile[];\n  localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * The same as {@link SnapFiles} except that the manifest is an\n * {@link ExtendableManifest}.\n */\nexport type ExtendableSnapFiles = Omit<SnapFiles, 'manifest'> & {\n  manifest: ExtendableManifest;\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n  SnapFiles,\n  'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n  npm = 'npm:',\n  local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n  JSON_RPC = 'jsonRpc',\n  COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n  Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\nexport { uri } from '@metamask/snaps-sdk';\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n  url: unknown,\n  opts: UriOptions<any> = {},\n): url is string {\n  return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n  [WALLET_SNAP_PERMISSION_KEY]: {\n    caveats: [\n      {\n        type: SnapCaveatType.SnapIds;\n        value: Record<string, Json>;\n      },\n    ];\n  };\n};\n"]}