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AxB,IAAI,CAAsB,EAAE,CAAC;QAC/B,OAAO,SAAS,KAAK,kBAAkB,CAAC;IAC1C,CAAC;IACD,IAAI,uBAAA,IAAI,qEAAsB,MAA1B,IAAI,CAAwB,EAAE,CAAC;QACjC,OAAO,SAAS,KAAK,gBAAgB,CAAC;IACxC,CAAC;IACD,IAAI,uBAAA,IAAI,sEAAuB,MAA3B,IAAI,CAAyB,EAAE,CAAC;QAClC,OAAO,SAAS,KAAK,kBAAkB,IAAI,SAAS,KAAK,aAAa,CAAC;IACzE,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;AACnC,CAAC;AA5fM,kBAAI,GAAW,WAAW,AAAtB,CAAuB","sourcesContent":["import type { TypedTransaction, TypedTxData } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n  SignTypedDataVersion,\n  TypedDataUtils,\n  recoverPersonalSignature,\n  recoverTypedSignature,\n} from '@metamask/eth-sig-util';\nimport type { Keyring } from '@metamask/keyring-utils';\nimport type { Hex } from '@metamask/utils';\nimport type {\n  ConnectSettings,\n  EthereumSignTypedDataMessage,\n  EthereumSignTypedDataTypes,\n  EVMSignedTx,\n  EVMSignTransactionParams,\n} from '@onekeyfe/hd-core';\n// eslint-disable-next-line @typescript-eslint/no-shadow, n/prefer-global/buffer\nimport { Buffer } from 'buffer';\n// eslint-disable-next-line @typescript-eslint/naming-convention\nimport HDKey from 'hdkey';\n\nimport type { OneKeyBridge } from './onekey-bridge';\n\nconst pathBase = 'm';\nconst defaultHdPath = `${pathBase}/44'/60'/0'/0`;\nconst keyringType = 'OneKey Hardware';\n\nconst hdPathString = `m/44'/60'/0'/0/x`;\nconst ledgerLegacyHdPathString = `m/44'/60'/0'/x`;\n\nconst ALLOWED_HD_PATHS: Record<string, boolean> = {\n  [defaultHdPath]: true,\n  [hdPathString]: true,\n  [ledgerLegacyHdPathString]: true,\n} as const;\n\nexport type AccountDetails = {\n  index?: number;\n  hdPath: string;\n  passphraseState?: string | undefined;\n};\n\nexport type AccountPageEntry = {\n  address: string;\n  balance: number | null;\n  index: number;\n};\n\nexport type AccountPage = AccountPageEntry[];\n\nexport type OneKeyControllerOptions = {\n  hdPath?: string;\n  accounts?: Hex[];\n  accountDetails?: Readonly<Record<string, AccountDetails>>;\n  page?: number;\n  passphraseState?: string;\n  // onUIEvent?: (event: HardwareUIEvent) => void;\n};\n\nexport type OneKeyControllerState = {\n  hdPath: string;\n  accounts: string[];\n  accountDetails: Record<string, AccountDetails>;\n  page: number;\n  passphraseState?: string;\n};\n\n/**\n * Check if the given value has a hex prefix.\n *\n * @param value - The value to check.\n * @returns Returns `true` if the value has a hex prefix.\n */\nfunction hasHexPrefix(value: string): boolean {\n  return value.startsWith('0x');\n}\n\n/**\n * Add a hex prefix to the given value.\n *\n * @param value - The value to add a hex prefix to.\n * @returns Returns the value with a hex prefix.\n */\nfunction addHexPrefix(value: string): string {\n  if (hasHexPrefix(value)) {\n    return value;\n  }\n  return `0x${value}`;\n}\n\n/**\n * Check if the passphrase state is empty.\n *\n * @param passphraseState - The passphrase state to check.\n * @returns Returns `true` if the passphrase state is empty.\n */\nfunction isEmptyPassphrase(passphraseState: string | undefined): boolean {\n  return (\n    passphraseState === null ||\n    passphraseState === undefined ||\n    passphraseState === ''\n  );\n}\n\nexport class OneKeyKeyring implements Keyring {\n  readonly type: string = keyringType;\n\n  static type: string = keyringType;\n\n  page = 0;\n\n  perPage = 5;\n\n  unlockedAccount = 0;\n\n  hdk = new HDKey();\n\n  accounts: readonly Hex[] = [];\n\n  accountDetails: Record<string, AccountDetails> = {};\n\n  passphraseState: string | undefined;\n\n  hdPath = defaultHdPath;\n\n  readonly bridge: OneKeyBridge;\n\n  constructor({ bridge }: { bridge: OneKeyBridge }) {\n    if (!bridge) {\n      throw new Error('Bridge is a required dependency for the keyring');\n    }\n\n    this.bridge = bridge;\n  }\n\n  async init(): Promise<void> {\n    return this.bridge.init();\n  }\n\n  async destroy(): Promise<void> {\n    return this.bridge.dispose();\n  }\n\n  async serialize(): Promise<OneKeyControllerState> {\n    return {\n      hdPath: this.hdPath,\n      accounts: [...this.accounts],\n      accountDetails: { ...this.accountDetails },\n      page: this.page,\n    };\n  }\n\n  async deserialize(state: OneKeyControllerOptions): Promise<void> {\n    this.hdPath = state.hdPath ?? defaultHdPath;\n    this.accounts = state.accounts ?? [];\n    this.accountDetails = state.accountDetails ?? {};\n    this.page = state.page ?? 0;\n  }\n\n  getModel(): string | undefined {\n    return this.bridge.model;\n  }\n\n  setAccountToUnlock(index: number): void {\n    this.unlockedAccount = index;\n  }\n\n  setHdPath(hdPath: string): void {\n    if (!ALLOWED_HD_PATHS[hdPath]) {\n      throw new Error('Unknown HD path');\n    }\n\n    // Reset HDKey if the path changes\n    if (!this.#isSameHdPath(hdPath)) {\n      this.hdk = new HDKey();\n      this.accounts = [];\n      this.page = 0;\n      this.perPage = 5;\n      this.unlockedAccount = 0;\n      this.accountDetails = {};\n    }\n    this.hdPath = hdPath;\n  }\n\n  lock(): void {\n    this.hdk = new HDKey();\n  }\n\n  isUnlocked(): boolean {\n    return Boolean(this.hdk?.publicKey);\n  }\n\n  async unlock(): Promise<string> {\n    if (this.isUnlocked()) {\n      return 'already unlocked';\n    }\n\n    return new Promise((resolve, reject) => {\n      // eslint-disable-next-line no-void\n      void this.bridge\n        .getPassphraseState()\n        .then((passphraseResponse) => {\n          if (!passphraseResponse.success) {\n            throw new Error(\n              passphraseResponse.payload?.error || 'Unknown error',\n            );\n          }\n          this.passphraseState = passphraseResponse.payload;\n\n          // eslint-disable-next-line no-void\n          void this.bridge\n            .getPublicKey({\n              showOnOneKey: false,\n              chainId: 1,\n              path: this.#getBasePath(),\n              passphraseState: this.passphraseState ?? '',\n            })\n            .then(async (res) => {\n              if (res.success) {\n                this.hdk.publicKey = Buffer.from(res.payload.publicKey, 'hex');\n                this.hdk.chainCode = Buffer.from(res.payload.chainCode, 'hex');\n                resolve('just unlocked');\n              } else {\n                reject(new Error('getPublicKey failed'));\n              }\n            })\n            .catch((error) => {\n              reject(new Error(error?.toString() || 'Unknown error'));\n            });\n        })\n        .catch((error) => {\n          reject(new Error(error?.toString() || 'Unknown error'));\n        });\n    });\n  }\n\n  async addAccounts(numberOfAccounts = 1): Promise<Hex[]> {\n    await this.unlock();\n\n    const from = this.unlockedAccount;\n    const to = from + numberOfAccounts;\n    const newAccounts: Hex[] = [];\n\n    for (let i = from; i < to; i++) {\n      const address = this.#addressFromIndex(i);\n      const hdPath = this.#getPathForIndex(i);\n      if (typeof address === 'undefined') {\n        throw new Error('Unknown error');\n      }\n      if (!this.accounts.includes(address)) {\n        this.accounts = [...this.accounts, address];\n        newAccounts.push(address);\n      }\n      if (!this.accountDetails[address]) {\n        this.accountDetails[address] = {\n          index: i,\n          hdPath,\n          passphraseState: this.passphraseState,\n        };\n      }\n      this.page = 0;\n    }\n\n    return newAccounts;\n  }\n\n  getName(): string {\n    return keyringType;\n  }\n\n  async getFirstPage(): Promise<AccountPage> {\n    this.page = 0;\n    return this.#getPage(1);\n  }\n\n  async getNextPage(): Promise<AccountPage> {\n    return this.#getPage(1);\n  }\n\n  async getPreviousPage(): Promise<AccountPage> {\n    return this.#getPage(-1);\n  }\n\n  async getAccounts(): Promise<Hex[]> {\n    return Promise.resolve(this.accounts.slice());\n  }\n\n  removeAccount(address: string): void {\n    const filteredAccounts = this.accounts.filter(\n      (a) => a.toLowerCase() !== address.toLowerCase(),\n    );\n\n    if (filteredAccounts.length === this.accounts.length) {\n      throw new Error(`Address ${address} not found in this keyring`);\n    }\n\n    this.accounts = filteredAccounts;\n    delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n  }\n\n  async updateTransportMethod(\n    transportType: ConnectSettings['env'],\n  ): Promise<void> {\n    return this.bridge.updateTransportMethod(transportType);\n  }\n\n  #normalize(buffer: Buffer): string {\n    return ethUtil.bytesToHex(new Uint8Array(buffer));\n  }\n\n  /**\n   * Signs a transaction using OneKey.\n   *\n   * Accepts either an ethereumjs-tx or @ethereumjs/tx transaction, and returns\n   * the same type.\n   *\n   * @param address - Hex string address.\n   * @param tx - Instance of either new-style or old-style ethereumjs transaction.\n   * @returns The signed transaction, an instance of either new-style or old-style\n   * ethereumjs transaction.\n   */\n  async signTransaction(\n    address: Hex,\n    tx: TypedTransaction,\n  ): Promise<TypedTransaction> {\n    return this.#signTransaction(\n      address,\n      Number(tx.common.chainId()),\n      tx,\n      (payload) => {\n        // Because tx will be immutable, first get a plain javascript object that\n        // represents the transaction. Using txData here as it aligns with the\n        // nomenclature of ethereumjs/tx.\n        const txData: TypedTxData = tx.toJSON();\n        // The fromTxData utility expects a type to support transactions with a type other than 0\n        txData.type = tx.type;\n        // The fromTxData utility expects v,r and s to be hex prefixed\n        txData.v = ethUtil.addHexPrefix(payload.v);\n        txData.r = ethUtil.addHexPrefix(payload.r);\n        txData.s = ethUtil.addHexPrefix(payload.s);\n        // Adopt the 'common' option from the original transaction and set the\n        // returned object to be frozen if the original is frozen.\n        return TransactionFactory.fromTxData(txData, {\n          common: tx.common,\n          freeze: Object.isFrozen(tx),\n        });\n      },\n    );\n  }\n\n  async #signTransaction<TXData extends TypedTransaction>(\n    address: string,\n    chainId: number,\n    tx: TXData,\n    handleSigning: (tx: EVMSignedTx) => TXData,\n  ): Promise<TXData> {\n    // new-style transaction from @ethereumjs/tx package\n    // we can just copy tx.toJSON() for everything except chainId, which must be a number\n    const transaction: EVMSignTransactionParams['transaction'] = {\n      ...tx.toJSON(),\n      chainId,\n      to: this.#normalize(Buffer.from(tx.to?.bytes ?? [])),\n    } as unknown as EVMSignTransactionParams['transaction'];\n\n    try {\n      const details = this.#accountDetailsFromAddress(address);\n      const response = await this.bridge.ethereumSignTransaction({\n        path: details.hdPath,\n        passphraseState: details.passphraseState ?? '',\n        useEmptyPassphrase: isEmptyPassphrase(details.passphraseState),\n        transaction,\n      });\n      if (response.success) {\n        const newOrMutatedTx = handleSigning(response.payload);\n\n        const addressSignedWith = ethUtil.toChecksumAddress(\n          ethUtil.addHexPrefix(newOrMutatedTx.getSenderAddress().toString()),\n        );\n        const correctAddress = ethUtil.toChecksumAddress(address);\n        if (addressSignedWith !== correctAddress) {\n          throw new Error(\"signature doesn't match the right address\");\n        }\n\n        return newOrMutatedTx;\n      }\n      throw new Error(response.payload?.error || 'Unknown error');\n    } catch (error) {\n      throw new Error(error?.toString() ?? 'Unknown error');\n    }\n  }\n\n  async signMessage(withAccount: string, data: string): Promise<string> {\n    return this.signPersonalMessage(withAccount, data);\n  }\n\n  // For personal_sign, we need to prefix the message:\n  async signPersonalMessage(\n    withAccount: string,\n    message: string,\n  ): Promise<string> {\n    return new Promise((resolve, reject) => {\n      const details = this.#accountDetailsFromAddress(withAccount);\n      this.bridge\n        .ethereumSignMessage({\n          path: details.hdPath,\n          passphraseState: details.passphraseState ?? '',\n          useEmptyPassphrase: isEmptyPassphrase(details.passphraseState),\n          messageHex: ethUtil.stripHexPrefix(message),\n        })\n        .then((response) => {\n          if (response.success) {\n            const signature = addHexPrefix(response.payload.signature);\n            const addressSignedWith = recoverPersonalSignature({\n              data: message,\n              signature,\n            });\n            if (\n              ethUtil.toChecksumAddress(addressSignedWith) !==\n              ethUtil.toChecksumAddress(withAccount)\n            ) {\n              reject(new Error('signature doesnt match the right address'));\n            }\n            // eslint-disable-next-line promise/no-multiple-resolved\n            resolve(signature);\n          } else {\n            reject(new Error(response.payload?.error || 'Unknown error'));\n          }\n        })\n        .catch((error) => {\n          reject(new Error(error?.toString() || 'Unknown error'));\n        });\n    });\n  }\n\n  // EIP-712 Sign Typed Data\n  async signTypedData<Types extends MessageTypes>(\n    address: string,\n    data: TypedMessage<Types>,\n    { version }: { version?: SignTypedDataVersion },\n  ): Promise<string> {\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n    const useV4 = version === SignTypedDataVersion.V4;\n    const dataVersion = useV4\n      ? SignTypedDataVersion.V4\n      : SignTypedDataVersion.V3;\n    const typedData = TypedDataUtils.sanitizeData(data);\n    const domainHash = TypedDataUtils.hashStruct(\n      'EIP712Domain',\n      typedData.domain,\n      typedData.types,\n      dataVersion,\n    ).toString('hex');\n    const messageHash = TypedDataUtils.hashStruct(\n      typedData.primaryType as string,\n      typedData.message,\n      typedData.types,\n      dataVersion,\n    ).toString('hex');\n\n    const details = this.#accountDetailsFromAddress(address);\n    const response = await this.bridge.ethereumSignTypedData({\n      path: details.hdPath,\n      passphraseState: details.passphraseState ?? '',\n      useEmptyPassphrase: isEmptyPassphrase(details.passphraseState),\n      data: data as EthereumSignTypedDataMessage<EthereumSignTypedDataTypes>,\n      domainHash,\n      messageHash,\n      metamaskV4Compat: Boolean(useV4), // eslint-disable-line camelcase\n    });\n\n    if (response.success) {\n      const signature = addHexPrefix(response.payload.signature);\n      const addressSignedWith = recoverTypedSignature({\n        data: typedData,\n        signature,\n        version: dataVersion,\n      });\n      if (\n        ethUtil.toChecksumAddress(addressSignedWith) !==\n        ethUtil.toChecksumAddress(address)\n      ) {\n        throw new Error('signature doesnt match the right address');\n      }\n      return signature;\n    }\n\n    throw new Error(response.payload?.error || 'Unknown error');\n  }\n\n  forgetDevice(): void {\n    this.hdk = new HDKey();\n    this.accounts = [];\n    this.page = 0;\n    this.unlockedAccount = 0;\n    this.accountDetails = {};\n    this.passphraseState = undefined;\n  }\n\n  async #getPage(\n    increment: number,\n  ): Promise<{ address: string; balance: number | null; index: number }[]> {\n    this.page += increment;\n\n    if (this.page <= 0) {\n      this.page = 1;\n    }\n\n    return new Promise((resolve, reject) => {\n      const from = (this.page - 1) * this.perPage;\n      const to = from + this.perPage;\n\n      const accounts: {\n        address: string;\n        balance: number | null;\n        index: number;\n      }[] = [];\n\n      this.unlock()\n        .then(async () => {\n          for (let i = from; i < to; i++) {\n            const address = this.#addressFromIndex(i);\n            if (typeof address === 'undefined') {\n              throw new Error('Unknown error');\n            }\n            accounts.push({\n              index: i,\n              address,\n              balance: null,\n            });\n          }\n          resolve(accounts);\n        })\n        .catch((error) => {\n          // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n          reject(error);\n        });\n    });\n  }\n\n  #accountDetailsFromAddress(address: string): AccountDetails {\n    const checksummedAddress = ethUtil.toChecksumAddress(address);\n    const accountDetails = this.accountDetails[checksummedAddress];\n    if (typeof accountDetails === 'undefined') {\n      throw new Error('Unknown address');\n    }\n    return accountDetails;\n  }\n\n  #addressFromIndex(i: number): Hex {\n    const dkey = this.hdk.derive(this.#getDerivePath(i));\n    const address = ethUtil.bytesToHex(\n      ethUtil.publicToAddress(new Uint8Array(dkey.publicKey), true),\n    );\n    return ethUtil.toChecksumAddress(address);\n  }\n\n  #getDerivePath(index: number): string {\n    if (this.#isLedgerLiveHdPath()) {\n      throw new Error('Ledger Live is not supported');\n    }\n    if (this.#isStandardBip44HdPath()) {\n      return `${pathBase}/0/${index}`;\n    }\n    return `${pathBase}/${index}`;\n  }\n\n  #getBasePath(): string {\n    if (this.#isLedgerLiveHdPath()) {\n      throw new Error('Ledger Live is not supported');\n    }\n    return \"m/44'/60'/0'\";\n  }\n\n  #getPathForIndex(index: number): string {\n    // Check if the path is BIP 44 (Ledger Live)\n    if (this.#isLedgerLiveHdPath()) {\n      return `m/44'/60'/${index}'/0/0`;\n    }\n\n    if (this.#isLedgerLegacyHdPath()) {\n      return `m/44'/60'/0'/${index}`;\n    }\n\n    if (this.#isStandardBip44HdPath()) {\n      return `m/44'/60'/0'/0/${index}`;\n    }\n\n    // default path: m/44'/60'/0'/0/x\n    return `${this.hdPath}/${index}`;\n  }\n\n  #isLedgerLiveHdPath(): boolean {\n    return this.hdPath === `m/44'/60'/x'/0/0`;\n  }\n\n  #isLedgerLegacyHdPath(): boolean {\n    return this.hdPath === `m/44'/60'/0'/x`;\n  }\n\n  #isStandardBip44HdPath(): boolean {\n    return this.hdPath === `m/44'/60'/0'/0/x` || this.hdPath === defaultHdPath;\n  }\n\n  #isSameHdPath(newHdPath: string): boolean {\n    if (this.#isLedgerLiveHdPath()) {\n      return newHdPath === `m/44'/60'/x'/0/0`;\n    }\n    if (this.#isLedgerLegacyHdPath()) {\n      return newHdPath === `m/44'/60'/0'/x`;\n    }\n    if (this.#isStandardBip44HdPath()) {\n      return newHdPath === `m/44'/60'/0'/0/x` || newHdPath === defaultHdPath;\n    }\n\n    return this.hdPath === newHdPath;\n  }\n}\n"]}