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,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,cAAc;YACvC,MAAM;SACP,CAAC,EACF,4BAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,EAAa,EACb,OAA8B;QAE9B,OAAO,UAAU,CACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE;SAC5C,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAa;QAC/B,MAAM,CACJ,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,OAAO,UAAU,CACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n  CreateAccountsResponseStruct,\n  DeleteAccountResponseStruct,\n  GetAccountResponseStruct,\n  GetAccountsResponseStruct,\n  SubmitRequestResponseStruct,\n  KeyringRpcMethod,\n  ExportAccountResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n  CreateAccountOptions,\n  ExportAccountOptions,\n  ExportedAccount,\n  KeyringRpc,\n  KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringRpc {\n  readonly #sender: Sender;\n\n  /**\n   * Create a new instance of `KeyringClient`.\n   *\n   * @param sender - The `Sender` instance to use to send requests to the snap.\n   */\n  constructor(sender: Sender) {\n    this.#sender = sender;\n  }\n\n  /**\n   * Send a request to the Snap and return the response.\n   *\n   * @param request - A partial JSON-RPC request (method and params).\n   * @returns A promise that resolves to the response to the request.\n   */\n  protected async send<RequestMethod extends KeyringRpcMethod>(\n    request: KeyringRpcRequest<RequestMethod>,\n  ): Promise<Json> {\n    return this.#sender.send({\n      ...request,\n    });\n  }\n\n  async getAccounts(): Promise<KeyringAccount[]> {\n    return strictMask(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.GetAccounts,\n      }),\n      GetAccountsResponseStruct,\n    );\n  }\n\n  async getAccount(id: string): Promise<KeyringAccount> {\n    return strictMask(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.GetAccount,\n        params: { id },\n      }),\n      GetAccountResponseStruct,\n    );\n  }\n\n  async createAccounts(\n    params: CreateAccountOptions,\n  ): Promise<KeyringAccount[]> {\n    return strictMask(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.CreateAccounts,\n        params,\n      }),\n      CreateAccountsResponseStruct,\n    );\n  }\n\n  async exportAccount(\n    id: AccountId,\n    options?: ExportAccountOptions,\n  ): Promise<ExportedAccount> {\n    return strictMask(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.ExportAccount,\n        params: { id, ...(options && { options }) },\n      }),\n      ExportAccountResponseStruct,\n    );\n  }\n\n  async deleteAccount(id: AccountId): Promise<void> {\n    assert(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.DeleteAccount,\n        params: { id },\n      }),\n      DeleteAccountResponseStruct,\n    );\n  }\n\n  async submitRequest(request: KeyringRequest): Promise<Json> {\n    return strictMask(\n      await this.send({\n        jsonrpc: '2.0',\n        id: uuid(),\n        method: KeyringRpcMethod.SubmitRequest,\n        params: request,\n      }),\n      SubmitRequestResponseStruct,\n    );\n  }\n}\n"]}