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GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO,MAAM,SAAS,CAAC;YACrB,OAAO,EAAE;gBACP,IAAI,EAAE,IAAI;gBACV,QAAQ;gBACR,IAAI;aACL;SACF,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { mnemonicToSeed } from '@metamask/key-tree';\nimport type {\n  ActionConstraint,\n  EventConstraint,\n  MockAnyNamespace,\n  NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport {\n  PermissionDoesNotExistError,\n  type Caveat,\n  type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n  detectSnapLocation,\n  fetchSnap,\n  NodeThreadExecutionService,\n  setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n  TrackEventParams,\n  SnapId,\n  TraceRequest,\n  EndTraceRequest,\n  TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { Snap, VirtualFile } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { CaipAssetType, Hex, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n  getGetMnemonicImplementation,\n  getGetSnapImplementation,\n  getTrackEventImplementation,\n  getTrackErrorImplementation,\n  getEndTraceImplementation,\n  getStartTraceImplementation,\n  getSetCurrentChainImplementation,\n  getClearSnapStateMethodImplementation,\n  getGetSnapStateMethodImplementation,\n  getUpdateSnapStateMethodImplementation,\n  getRequestUserApprovalImplementation,\n  getShowInAppNotificationImplementation,\n  getShowNativeNotificationImplementation,\n} from './methods/hooks';\nimport { createJsonRpcEngine } from './middleware';\nimport type {\n  SimulationAccount,\n  SimulationOptions,\n  SimulationUserOptions,\n} from './options';\nimport { getOptions } from './options';\nimport type {\n  ApplicationState,\n  Interface,\n  RunSagaFunction,\n  Store,\n} from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n  Service extends new (...args: any[]) => any,\n> = Omit<\n  ConstructorParameters<Service>[0],\n  keyof ConstructorParameters<typeof ExecutionService>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n  Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n> =\n  ExecutionServiceOptions<Service> extends Record<string, never>\n    ? {\n        executionService: Service;\n        executionServiceOptions?: ExecutionServiceOptions<Service>;\n        options?: SimulationUserOptions;\n      }\n    : {\n        executionService: Service;\n        executionServiceOptions: ExecutionServiceOptions<Service>;\n        options?: SimulationUserOptions;\n      };\n\nexport type InstalledSnap = {\n  snapId: SnapId;\n  store: Store;\n  executionService: InstanceType<typeof ExecutionService>;\n  controllerMessenger: Messenger<\n    NamespacedName,\n    ActionConstraint,\n    EventConstraint\n  >;\n  runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n  /**\n   * A hook that returns the user's secret recovery phrase.\n   *\n   * @returns The user's secret recovery phrase.\n   */\n  getMnemonic: () => Promise<Uint8Array>;\n\n  /**\n   * A hook that returns whether the client is locked or not.\n   *\n   * @returns A boolean flag signaling whether the client is locked.\n   */\n  getIsLocked: () => boolean;\n\n  /**\n   * Get the cryptographic functions to use for the client. This may return an\n   * empty object to fall back to the default cryptographic functions.\n   *\n   * @returns The cryptographic functions to use for the client.\n   */\n  getClientCryptography: () => CryptographicFunctions;\n\n  /**\n   * A hook that returns metadata about a given Snap.\n   *\n   * @param snapId - The ID of a Snap.\n   * @returns The metadata for the given Snap.\n   */\n  getSnap: (snapId: string) => Snap;\n\n  /**\n   * A hook that sets the current chain ID.\n   *\n   * @param chainId - The chain ID.\n   */\n  setCurrentChain: (chainId: Hex) => null;\n\n  /**\n   * A hook that gets the current simulation state.\n   *\n   * @returns The simulation state.\n   */\n  getSimulationState: () => ApplicationState;\n};\n\nexport type PermittedMiddlewareHooks = {\n  /**\n   * A hook that returns a promise that resolves once the extension is unlocked.\n   *\n   * @param shouldShowUnlockRequest - Whether to show the unlock request.\n   * @returns A promise that resolves once the extension is unlocked.\n   */\n  getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n  /**\n   * A hook that returns whether the client is active or not.\n   *\n   * @returns A boolean flag signaling whether the client is opened.\n   */\n  getIsActive: () => boolean;\n\n  /**\n   * A hook that returns the client version.\n   *\n   * @returns A string that corresponds to the client version.\n   */\n  getVersion: () => string;\n\n  /**\n   * A hook that tracks an error.\n   *\n   * @param error - The error object containing error details and properties.\n   */\n  trackError(error: Error): void;\n\n  /**\n   * A hook that tracks an event.\n   *\n   * @param event - The event object containing event details and properties.\n   */\n  trackEvent(event: TrackEventParams['event']): void;\n\n  /**\n   * A hook that starts a performance trace.\n   *\n   * @param request - The trace request object containing trace details.\n   */\n  startTrace(request: TraceRequest): TraceContext;\n\n  /**\n   * A hook that ends a performance trace.\n   *\n   * @param request - The trace request object containing trace details.\n   * @returns The trace data.\n   */\n  endTrace(request: EndTraceRequest): void;\n\n  /**\n   * A hook that returns the allowed keyring methods.\n   *\n   * @returns The keyring methods.\n   */\n  getAllowedKeyringMethods(): string[];\n\n  /**\n   * A hook that returns a specialized messenger for the Snap.\n   *\n   * @returns The messenger.\n   */\n  getMessenger(args: {\n    actions?: string[];\n    events?: string[];\n  }): Messenger<string>;\n};\n\nexport type MultichainMiddlewareHooks = {\n  /**\n   * A hook that returns the simulated accounts.\n   *\n   * @returns The simulated accounts.\n   */\n  getAccounts: () => SimulationAccount[];\n\n  /**\n   * A hook that retrieves a caveat for a given permission.\n   *\n   * @param permission - The permission name.\n   * @param caveatType - The caveat type.\n   * @returns The caveat, if it exists.\n   */\n  getCaveat: (\n    permission: string,\n    caveatType: string,\n  ) => Caveat<string, Json> | undefined;\n\n  /**\n   * A hook that grants permissions to the origin.\n   *\n   * @param permissions - The permissions.\n   */\n  grantPermissions: (permissions: RequestedPermissions) => void;\n\n  /**\n   * A hook that revokes a permission for the origin.\n   *\n   * @param permission - The permission name.\n   */\n  revokePermission: (permission: string) => void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n  Service extends new (...args: any[]) => InstanceType<typeof ExecutionService>,\n>(\n  snapId: SnapId,\n  {\n    executionService,\n    executionServiceOptions,\n    options: rawOptions = {},\n  }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n  const options = getOptions(rawOptions);\n\n  // Fetch Snap files.\n  const location = detectSnapLocation(snapId, {\n    allowLocal: true,\n  });\n\n  const snapFiles = await fetchSnap(snapId, location);\n\n  // Create Redux store.\n  const { store, runSaga } = createStore(options);\n\n  const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n    namespace: MOCK_ANY_NAMESPACE,\n  });\n\n  registerActions(\n    controllerMessenger,\n    runSaga,\n    options,\n    snapId,\n    snapFiles.auxiliaryFiles,\n  );\n\n  // Set up controllers and JSON-RPC stack.\n  const restrictedHooks = getRestrictedHooks(options, store, runSaga);\n\n  const permittedHooks = getPermittedHooks(\n    snapId,\n    controllerMessenger,\n    runSaga,\n  );\n\n  const multichainHooks = getMultichainHooks(\n    snapId,\n    options,\n    controllerMessenger,\n  );\n\n  const { subjectMetadataController, permissionController } = getControllers({\n    controllerMessenger,\n    hooks: restrictedHooks,\n    runSaga,\n    options,\n  });\n\n  const engine = createJsonRpcEngine({\n    snapId,\n    messenger: controllerMessenger,\n    store,\n    restrictedHooks,\n    permittedHooks,\n    multichainHooks,\n    isMultichain: false,\n  });\n\n  const multichainEngine = createJsonRpcEngine({\n    snapId,\n    messenger: controllerMessenger,\n    store,\n    restrictedHooks,\n    permittedHooks,\n    multichainHooks,\n    isMultichain: true,\n  });\n\n  // Create execution service.\n  const ActualService = executionService ?? NodeThreadExecutionService;\n  const service = new ActualService({\n    ...executionServiceOptions,\n    messenger: new Messenger({\n      namespace: 'ExecutionService',\n      parent: controllerMessenger,\n    }),\n    setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n      const mux = setupMultiplex(rpcStream, 'snapStream');\n      const stream = mux.createStream('metamask-provider');\n      const providerStream = createEngineStream({ engine });\n\n      // Error function is difficult to test, so we ignore it.\n      /* istanbul ignore next 2 */\n      pipeline(stream, providerStream, stream, (error) => {\n        if (error && !error.message?.match('Premature close')) {\n          logError(`Provider stream failure.`, error);\n        }\n      });\n\n      const multichainStream = mux.createStream('metamask-multichain-provider');\n      const multichainProviderStream = createEngineStream({\n        engine: multichainEngine,\n      });\n\n      /* istanbul ignore next 2 */\n      pipeline(\n        multichainStream,\n        multichainProviderStream,\n        multichainStream,\n        (error) => {\n          if (error && !error.message?.match('Premature close')) {\n            logError(`Provider stream failure.`, error);\n          }\n        },\n      );\n    },\n  });\n\n  // Register the Snap. This sets up the Snap's permissions and subject\n  // metadata.\n  await registerSnap(snapId, snapFiles.manifest.result, {\n    permissionController,\n    subjectMetadataController,\n  });\n\n  // Run the Snap code in the execution service.\n  await service.executeSnap({\n    snapId,\n    sourceCode: snapFiles.sourceCode.toString('utf8'),\n    endowments: await getEndowments(permissionController, snapId),\n  });\n\n  const helpers = getHelpers({\n    snapId,\n    store,\n    controllerMessenger,\n    runSaga,\n    executionService: service,\n    options,\n  });\n\n  return {\n    snapId,\n    store,\n    executionService: service,\n    controllerMessenger,\n    runSaga,\n    ...helpers,\n  };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param store - The Redux store.\n * @param runSaga - The run saga function.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n  options: SimulationOptions,\n  store: Store,\n  runSaga: RunSagaFunction,\n): RestrictedMiddlewareHooks {\n  return {\n    getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n    getIsLocked: () => false,\n    getClientCryptography: () => ({}),\n    getSnap: getGetSnapImplementation(true),\n    setCurrentChain: getSetCurrentChainImplementation(runSaga),\n    getSimulationState: store.getState.bind(store),\n  };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n  snapId: string,\n  controllerMessenger: RootControllerMessenger,\n  runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n  return {\n    getUnlockPromise: asyncResolve(),\n    getIsActive: () => true,\n    getVersion: () => '13.6.0-flask.0',\n\n    getAllowedKeyringMethods: () => [],\n\n    trackError: getTrackErrorImplementation(runSaga),\n    trackEvent: getTrackEventImplementation(runSaga),\n    startTrace: getStartTraceImplementation(runSaga),\n    endTrace: getEndTraceImplementation(runSaga),\n\n    getMessenger: ({ actions, events }) => {\n      const messenger = new Messenger({\n        namespace: `${snapId}-messenger`,\n        parent: controllerMessenger,\n      });\n\n      controllerMessenger.delegate({\n        actions: actions as never[],\n        events: events as never[],\n        messenger,\n      });\n\n      return messenger;\n    },\n  };\n}\n\n/**\n * Get the hooks for the multichain middleware simulation.\n *\n * @param snapId - The Snap ID.\n * @param options - The simulation options.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the middleware.\n */\nexport function getMultichainHooks(\n  snapId: SnapId,\n  options: SimulationOptions,\n  controllerMessenger: RootControllerMessenger,\n): MultichainMiddlewareHooks {\n  return {\n    getAccounts: () => options.accounts,\n    getCaveat: (permission: string, caveatType: string) => {\n      try {\n        return controllerMessenger.call(\n          'PermissionController:getCaveat',\n          snapId,\n          permission,\n          caveatType,\n        );\n      } catch (error) {\n        if (error instanceof PermissionDoesNotExistError) {\n          return undefined;\n        }\n        /* istanbul ignore next */\n        throw error;\n      }\n    },\n    grantPermissions: (approvedPermissions: RequestedPermissions) => {\n      controllerMessenger.call('PermissionController:grantPermissions', {\n        subject: { origin: snapId },\n        approvedPermissions,\n      });\n    },\n    revokePermission: (permission: string) => {\n      try {\n        controllerMessenger.call('PermissionController:revokePermissions', {\n          [snapId]: [permission],\n        });\n      } catch (error) {\n        if (error instanceof PermissionDoesNotExistError) {\n          return;\n        }\n        /* istanbul ignore next */\n        throw error;\n      }\n    },\n  };\n}\n\n/**\n * Get the mock mnemonic for a given source ID.\n *\n * @param options - The simulation options.\n * @returns The mnemonic.\n */\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n * @param auxiliaryFiles - Auxiliary files from the fetched Snap.\n */\nexport function registerActions(\n  controllerMessenger: RootControllerMessenger,\n  runSaga: RunSagaFunction,\n  options: SimulationOptions,\n  snapId: SnapId,\n  auxiliaryFiles: VirtualFile[],\n) {\n  controllerMessenger.registerActionHandler(\n    'PhishingController:testOrigin',\n    () => ({ result: false, type: 'all' }),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'AccountsController:getAccountByAddress',\n    // @ts-expect-error - This is a partial account with only the necessary\n    // data used by the interface controller.\n    (address) => {\n      const matchingAccount = options.accounts.find(\n        (account) => address === account.address,\n      );\n\n      if (!matchingAccount) {\n        return undefined;\n      }\n\n      return addSnapMetadataToAccount(matchingAccount, snapId);\n    },\n  );\n\n  controllerMessenger.registerActionHandler(\n    'AccountsController:getSelectedMultichainAccount',\n    // @ts-expect-error - This is a partial account with only the necessary\n    // data used by the interface controller.\n    () => {\n      const selectedAccount = options.accounts.find(\n        (account) => account.selected,\n      );\n\n      if (!selectedAccount) {\n        return undefined;\n      }\n\n      return addSnapMetadataToAccount(selectedAccount, snapId);\n    },\n  );\n\n  controllerMessenger.registerActionHandler(\n    'AccountsController:listMultichainAccounts',\n\n    () =>\n      // @ts-expect-error - These are partial accounts with only the necessary\n      // data used by the interface controller.\n      options.accounts.map((account) =>\n        addSnapMetadataToAccount(account, snapId),\n      ),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'MultichainAssetsController:getState',\n    () => ({\n      // @ts-expect-error - These are partial assets with only the\n      // necessary data used by the interface controller.\n      assetsMetadata: options.assets,\n      accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n        (acc, account) => {\n          acc[account.id] = account.assets ?? [];\n          return acc;\n        },\n        {},\n      ),\n    }),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'ApprovalController:hasRequest',\n    (opts) => {\n      /**\n       * Get the current interface from the store.\n       *\n       * @yields Selects the current interface from the store.\n       * @returns The current interface.\n       */\n      function* getCurrentInterfaceSaga(): SagaIterator {\n        const currentInterface: Interface = yield select(getCurrentInterface);\n        return currentInterface;\n      }\n\n      const currentInterface: Interface | undefined = runSaga(\n        getCurrentInterfaceSaga,\n      ).result();\n      return (\n        currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n        currentInterface?.id === opts?.id\n      );\n    },\n  );\n\n  controllerMessenger.registerActionHandler(\n    'ApprovalController:acceptRequest',\n    async (_id: string, value: unknown) => {\n      await runSaga(resolveWithSaga, value).toPromise();\n\n      return { value };\n    },\n  );\n\n  controllerMessenger.registerActionHandler(\n    'ApprovalController:addRequest',\n    // @ts-expect-error Types of property 'requestData' are incompatible.\n    getRequestUserApprovalImplementation(runSaga),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'SnapController:getSnap',\n    getGetSnapImplementation(true),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'SnapController:getSnapState',\n    getGetSnapStateMethodImplementation(runSaga),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'SnapController:updateSnapState',\n    getUpdateSnapStateMethodImplementation(runSaga),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'SnapController:clearSnapState',\n    getClearSnapStateMethodImplementation(runSaga),\n  );\n\n  controllerMessenger.registerActionHandler(\n    'SnapController:getSnapFile',\n    async (_snapId, path, encoding) =>\n      getSnapFile(auxiliaryFiles, path, encoding),\n  );\n\n  const showNativeNotification =\n    getShowNativeNotificationImplementation(runSaga);\n  const showInAppNotification = getShowInAppNotificationImplementation(runSaga);\n\n  controllerMessenger.registerActionHandler(\n    // @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.\n    'RateLimitController:call',\n    async (\n      _origin: string,\n      type: 'showNativeNotification' | 'showInAppNotification',\n      ...args: unknown[]\n    ) => {\n      switch (type) {\n        case 'showNativeNotification':\n          return await showNativeNotification(args[0] as string, {\n            type: 'native',\n            message: args[1] as string,\n          });\n        case 'showInAppNotification':\n          return await showInAppNotification(\n            args[0] as string,\n            args[1] as Parameters<typeof showInAppNotification>[1],\n          );\n        /* istanbul ignore next */\n        default:\n          return assertExhaustive(type);\n      }\n    },\n  );\n\n  const getMnemonic = getGetMnemonicImplementation(\n    options.secretRecoveryPhrase,\n  );\n\n  controllerMessenger.registerActionHandler(\n    // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n    'KeyringController:getState',\n    () => ({\n      isUnlocked: true,\n      keyrings: [\n        {\n          type: 'HD Key Tree',\n          metadata: {\n            id: 'default',\n            name: 'Default Secret Recovery Phrase',\n          },\n        },\n        {\n          type: 'HD Key Tree',\n          metadata: {\n            id: 'alternative',\n            name: 'Alternative Secret Recovery Phrase',\n          },\n        },\n      ],\n    }),\n  );\n\n  controllerMessenger.registerActionHandler(\n    // @ts-expect-error - `KeyringController` is not part of the simulation messenger types.\n    'KeyringController:withKeyringV2Unsafe',\n    async (\n      selector: { type: string; index?: number } | { id: string },\n      operation: (args: {\n        keyring: { type: string; mnemonic: Uint8Array; seed: Uint8Array };\n      }) => Promise<unknown>,\n    ) => {\n      const source = hasProperty(selector, 'id')\n        ? (selector.id as string)\n        : undefined;\n\n      const mnemonic = await getMnemonic(source);\n      const seed = await mnemonicToSeed(mnemonic);\n\n      return await operation({\n        keyring: {\n          type: 'hd',\n          mnemonic,\n          seed,\n        },\n      });\n    },\n  );\n}\n"]}