@metamask/eth-ledger-bridge-keyring 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.0]
10
+ ### Changed
11
+ - **BREAKING**: Remove support for major node versions 14,15,17,19. Minimum Node.js version is now 16. ([#204](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/204))
12
+ - Bump `@metamask/eth-sig-util` from `^6.0.1` to `^7.0.0` ([#205](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/205))
13
+
14
+ ### Fixed
15
+ - Move `@metamask/utils` from deendencies to devDependencies ([#209](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/209))
16
+
17
+ ## [1.0.1]
18
+ ### Fixed
19
+ - Bump dependency `hdkey` from `0.8.0` to `^2.1.0` ([#196](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/196))
20
+ - Replace dependency `eth-sig-util@^2` with `@metamask/eth-sig-util@^6` ([#157](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/157))
21
+ - Replace dependency `ethereumjs-util@^7.0.9` with `@ethereumjs/util@^8.0.0` and `@ethereumjs/rlp` ([#153](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/153))
22
+
9
23
  ## [1.0.0]
10
24
  ### Changed
11
25
  - **BREAKING:** Separate the bridge from the keyring ([#156](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/156))
@@ -67,7 +81,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
67
81
  ### Added
68
82
  - Support new versions of ethereumjs/tx ([#68](https://github.com/MetaMask/eth-ledger-bridge-keyring/pull/68))
69
83
 
70
- [Unreleased]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v1.0.0...HEAD
84
+ [Unreleased]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v2.0.0...HEAD
85
+ [2.0.0]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v1.0.1...v2.0.0
86
+ [1.0.1]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v1.0.0...v1.0.1
71
87
  [1.0.0]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v0.15.0...v1.0.0
72
88
  [0.15.0]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v0.14.0...v0.15.0
73
89
  [0.14.0]: https://github.com/MetaMask/eth-ledger-bridge-keyring/compare/v0.13.0...v0.14.0
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { TypedTransaction } from '@ethereumjs/tx';
3
- import * as sigUtil from 'eth-sig-util';
3
+ import type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';
4
4
  import type OldEthJsTransaction from 'ethereumjs-tx';
5
5
  import { EventEmitter } from 'events';
6
6
  import HDKey from 'hdkey';
@@ -82,7 +82,7 @@ export declare class LedgerKeyring extends EventEmitter {
82
82
  signMessage(withAccount: string, data: string): Promise<string>;
83
83
  signPersonalMessage(withAccount: string, message: string): Promise<string>;
84
84
  unlockAccountByAddress(address: string): Promise<string | undefined>;
85
- signTypedData(withAccount: string, data: sigUtil.EIP712TypedData, options?: {
85
+ signTypedData<T extends MessageTypes>(withAccount: string, data: TypedMessage<T>, options?: {
86
86
  version?: string;
87
87
  }): Promise<string>;
88
88
  exportAccount(): void;
@@ -33,11 +33,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
33
  var _LedgerKeyring_instances, _LedgerKeyring_migrateAccountDetails, _LedgerKeyring_signTransaction, _LedgerKeyring_getPage, _LedgerKeyring_getAccountsBIP44, _LedgerKeyring_getAccountsLegacy, _LedgerKeyring_addressFromIndex, _LedgerKeyring_pathFromAddress, _LedgerKeyring_getPathForIndex, _LedgerKeyring_isLedgerLiveHdPath, _LedgerKeyring_toLedgerPath, _LedgerKeyring_hasPreviousTransactions, _LedgerKeyring_getApiUrl;
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.LedgerKeyring = void 0;
36
+ const rlp_1 = require("@ethereumjs/rlp");
36
37
  const tx_1 = require("@ethereumjs/tx");
38
+ const ethUtil = __importStar(require("@ethereumjs/util"));
39
+ const eth_sig_util_1 = require("@metamask/eth-sig-util");
37
40
  // eslint-disable-next-line import/no-nodejs-modules
38
41
  const buffer_1 = require("buffer");
39
- const sigUtil = __importStar(require("eth-sig-util"));
40
- const ethUtil = __importStar(require("ethereumjs-util"));
41
42
  // eslint-disable-next-line import/no-nodejs-modules
42
43
  const events_1 = require("events");
43
44
  const hdkey_1 = __importDefault(require("hdkey"));
@@ -251,7 +252,7 @@ class LedgerKeyring extends events_1.EventEmitter {
251
252
  const messageToSign = tx.getMessageToSign(false);
252
253
  rawTxHex = buffer_1.Buffer.isBuffer(messageToSign)
253
254
  ? messageToSign.toString('hex')
254
- : ethUtil.rlp.encode(messageToSign).toString('hex');
255
+ : rlp_1.RLP.encode(messageToSign).toString();
255
256
  return __classPrivateFieldGet(this, _LedgerKeyring_instances, "m", _LedgerKeyring_signTransaction).call(this, address, rawTxHex, (payload) => {
256
257
  // Because tx will be immutable, first get a plain javascript object that
257
258
  // represents the transaction. Using txData here as it aligns with the
@@ -297,10 +298,9 @@ class LedgerKeyring extends events_1.EventEmitter {
297
298
  recoveryId = `0${recoveryId}`;
298
299
  }
299
300
  const signature = `0x${payload.r}${payload.s}${recoveryId}`;
300
- const addressSignedWith = sigUtil.recoverPersonalSignature({
301
+ const addressSignedWith = (0, eth_sig_util_1.recoverPersonalSignature)({
301
302
  data: message,
302
- // eslint-disable-next-line id-denylist
303
- sig: signature,
303
+ signature,
304
304
  });
305
305
  if (ethUtil.toChecksumAddress(addressSignedWith) !==
306
306
  ethUtil.toChecksumAddress(withAccount)) {
@@ -328,15 +328,9 @@ class LedgerKeyring extends events_1.EventEmitter {
328
328
  if (!isV4) {
329
329
  throw new Error('Ledger: Only version 4 of typed data signing is supported');
330
330
  }
331
- const { domain, types, primaryType, message } = sigUtil.TypedDataUtils.sanitizeData(data);
332
- const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct('EIP712Domain', domain, types,
333
- // @ts-expect-error @types/eth-sig-util documents this function
334
- // as taking three arguments, but it actually takes four.
335
- // See: https://github.com/MetaMask/eth-sig-util/blob/v2.5.4/index.js#L174
336
- isV4).toString('hex');
337
- const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(primaryType, message, types,
338
- // @ts-expect-error see comment above
339
- isV4).toString('hex');
331
+ const { domain, types, primaryType, message } = eth_sig_util_1.TypedDataUtils.sanitizeData(data);
332
+ const domainSeparatorHex = eth_sig_util_1.TypedDataUtils.hashStruct('EIP712Domain', domain, types, eth_sig_util_1.SignTypedDataVersion.V4).toString('hex');
333
+ const hashStructMessageHex = eth_sig_util_1.TypedDataUtils.hashStruct(primaryType.toString(), message, types, eth_sig_util_1.SignTypedDataVersion.V4).toString('hex');
340
334
  const hdPath = await this.unlockAccountByAddress(withAccount);
341
335
  if (!hdPath) {
342
336
  throw new Error('Ledger: Unknown error while signing message');
@@ -359,13 +353,10 @@ class LedgerKeyring extends events_1.EventEmitter {
359
353
  recoveryId = `0${recoveryId}`;
360
354
  }
361
355
  const signature = `0x${payload.r}${payload.s}${recoveryId}`;
362
- // @ts-expect-error recoverTypedSignature_v4 is missing from
363
- // @types/eth-sig-util.
364
- // See: https://github.com/MetaMask/eth-sig-util/blob/v2.5.4/index.js#L464
365
- const addressSignedWith = sigUtil.recoverTypedSignature_v4({
356
+ const addressSignedWith = (0, eth_sig_util_1.recoverTypedSignature)({
366
357
  data,
367
- // eslint-disable-next-line id-denylist
368
- sig: signature,
358
+ signature,
359
+ version: eth_sig_util_1.SignTypedDataVersion.V4,
369
360
  });
370
361
  if (ethUtil.toChecksumAddress(addressSignedWith) !==
371
362
  ethUtil.toChecksumAddress(withAccount)) {
@@ -1 +1 @@
1
- {"version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AC","sourcesContent":["import { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx';\n// eslint-disable-next-line import/no-nodejs-modules\nimport { Buffer } from 'buffer';\nimport * as sigUtil from 'eth-sig-util';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\nimport * as ethUtil from 'ethereumjs-util';\n// eslint-disable-next-line import/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge } from './ledger-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\nconst BRIDGE_URL = 'https://metamask.github.io/eth-ledger-bridge-keyring';\n\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'http://api-ropsten.etherscan.io',\n Kovan = 'http://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = 'https://api.etherscan.io',\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge['deviceSignTransaction']>\n>;\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n bridgeUrl: string;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridgeUrl: string = BRIDGE_URL;\n\n bridge: LedgerBridge;\n\n constructor({ bridge }: { bridge: LedgerBridge }) {\n super();\n\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() {\n return this.bridge.init(this.bridgeUrl);\n }\n\n async destroy() {\n return this.bridge.destroy();\n }\n\n async serialize() {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n accountDetails: this.accountDetails,\n bridgeUrl: this.bridgeUrl,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(opts: Partial<LedgerBridgeKeyringOptions> = {}) {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.bridgeUrl = opts.bridgeUrl ?? BRIDGE_URL;\n this.accounts = opts.accounts ?? [];\n this.accountDetails = opts.accountDetails ?? {};\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n Object.keys(this.accountDetails).includes(\n ethUtil.toChecksumAddress(account),\n ),\n );\n\n return Promise.resolve();\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>) {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts\n .filter(\n (account) =>\n !Object.keys(this.accountDetails).includes(\n ethUtil.toChecksumAddress(account),\n ),\n )\n .forEach((account) => {\n try {\n this.accountDetails[ethUtil.toChecksumAddress(account)] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n } catch (error) {\n console.log(`failed to migrate account ${account}`);\n }\n });\n }\n }\n\n isUnlocked() {\n return Boolean(this.hdk?.publicKey);\n }\n\n isConnected() {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number | string) {\n this.unlockedAccount =\n typeof index === 'number' ? index : parseInt(index, 10);\n }\n\n setHdPath(hdPath: string) {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error ? error : new Error('Unknown error');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n }\n this.page = 0;\n }\n resolve(this.accounts.slice());\n })\n .catch(reject);\n });\n }\n\n async getFirstPage() {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage() {\n return this.#getPage(1);\n }\n\n async getPreviousPage() {\n return this.#getPage(-1);\n }\n\n async getAccounts() {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string) {\n if (\n !this.accounts.map((a) => a.toLowerCase()).includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp() {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string) {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : ethUtil.rlp.encode(messageToSign).toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (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: TxData = 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 async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string) {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(withAccount: string, message: string) {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = sigUtil.recoverPersonalSignature({\n data: message,\n // eslint-disable-next-line id-denylist\n sig: signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string) {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData(\n withAccount: string,\n data: sigUtil.EIP712TypedData,\n options: { version?: string } = {},\n ) {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n sigUtil.TypedDataUtils.sanitizeData(data);\n const domainSeparatorHex = sigUtil.TypedDataUtils.hashStruct(\n 'EIP712Domain',\n domain,\n types,\n // @ts-expect-error @types/eth-sig-util documents this function\n // as taking three arguments, but it actually takes four.\n // See: https://github.com/MetaMask/eth-sig-util/blob/v2.5.4/index.js#L174\n isV4,\n ).toString('hex');\n const hashStructMessageHex = sigUtil.TypedDataUtils.hashStruct(\n primaryType,\n message,\n types,\n // @ts-expect-error see comment above\n isV4,\n ).toString('hex');\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n // @ts-expect-error recoverTypedSignature_v4 is missing from\n // @types/eth-sig-util.\n // See: https://github.com/MetaMask/eth-sig-util/blob/v2.5.4/index.js#L464\n const addressSignedWith = sigUtil.recoverTypedSignature_v4({\n data,\n // eslint-disable-next-line id-denylist\n sig: signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount() {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice() {\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number) {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number) {\n const accounts: {\n address: string;\n balance: number | null;\n index: number;\n }[] = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number) {\n const accounts: {\n address: string;\n balance: number | null;\n index: number;\n }[] = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number) {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string) {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number) {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath() {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string) {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string) {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n if (parsedResponse.status !== '0' && parsedResponse.result.length > 0) {\n return true;\n }\n return false;\n }\n\n #getApiUrl() {\n return this.network;\n }\n}\n"]}
1
+ {"version":3,"file":"ledger-keyring.js","sourceRoot":"","sources":["../src/ledger-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAsC;AACtC,uCAA8E;AAC9E,0DAA4C;AAE5C,yDAKgC;AAChC,oDAAoD;AACpD,mCAAgC;AAEhC,oDAAoD;AACpD,mCAAsC;AACtC,kDAA0B;AAI1B,MAAM,QAAQ,GAAG,GAAG,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,QAAQ,aAAa,CAAC;AAC9C,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,UAAU,GAAG,sDAAsD,CAAC;AAE1E,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,IAAK,cAKJ;AALD,WAAK,cAAc;IACjB,6DAA2C,CAAA;IAC3C,yDAAuC,CAAA;IACvC,8DAA4C,CAAA;IAC5C,sDAAoC,CAAA;AACtC,CAAC,EALI,cAAc,KAAd,cAAc,QAKlB;AAqBD;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAC7B,EAA0C;IAE1C,OAAO,YAAY,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC,UAAU,KAAK,UAAU,CAAC;AACnE,CAAC;AAED,MAAa,aAAc,SAAQ,qBAAY;IA6B7C,YAAY,EAAE,MAAM,EAA4B;QAC9C,KAAK,EAAE,CAAC;;QA3BD,SAAI,GAAW,WAAW,CAAC;QAEpC,SAAI,GAAG,CAAC,CAAC;QAET,YAAO,GAAG,CAAC,CAAC;QAEZ,oBAAe,GAAG,CAAC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ACrE,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC;IAGC,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AA7kBM,kBAAI,GAAW,WAAW,CAAC","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx';\nimport * as ethUtil from '@ethereumjs/util';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport {\n recoverPersonalSignature,\n recoverTypedSignature,\n SignTypedDataVersion,\n TypedDataUtils,\n} from '@metamask/eth-sig-util';\n// eslint-disable-next-line import/no-nodejs-modules\nimport { Buffer } from 'buffer';\nimport type OldEthJsTransaction from 'ethereumjs-tx';\n// eslint-disable-next-line import/no-nodejs-modules\nimport { EventEmitter } from 'events';\nimport HDKey from 'hdkey';\n\nimport { LedgerBridge } from './ledger-bridge';\n\nconst pathBase = 'm';\nconst hdPathString = `${pathBase}/44'/60'/0'`;\nconst keyringType = 'Ledger Hardware';\n\nconst BRIDGE_URL = 'https://metamask.github.io/eth-ledger-bridge-keyring';\n\nconst MAX_INDEX = 1000;\n\nenum NetworkApiUrls {\n Ropsten = 'http://api-ropsten.etherscan.io',\n Kovan = 'http://api-kovan.etherscan.io',\n Rinkeby = 'https://api-rinkeby.etherscan.io',\n Mainnet = 'https://api.etherscan.io',\n}\n\ntype SignTransactionPayload = Awaited<\n ReturnType<LedgerBridge['deviceSignTransaction']>\n>;\n\nexport type AccountDetails = {\n index?: number;\n bip44?: boolean;\n hdPath?: string;\n};\n\nexport type LedgerBridgeKeyringOptions = {\n hdPath: string;\n accounts: readonly string[];\n accountDetails: Readonly<Record<string, AccountDetails>>;\n accountIndexes: Readonly<Record<string, number>>;\n bridgeUrl: string;\n implementFullBIP44: boolean;\n};\n\n/**\n * Check if the given transaction is made with ethereumjs-tx or @ethereumjs/tx\n *\n * Transactions built with older versions of ethereumjs-tx have a\n * getChainId method that newer versions do not.\n * Older versions are mutable\n * while newer versions default to being immutable.\n * Expected shape and type\n * of data for v, r and s differ (Buffer (old) vs BN (new)).\n *\n * @param tx - Transaction to check, instance of either ethereumjs-tx or @ethereumjs/tx.\n * @returns Returns `true` if tx is an old-style ethereumjs-tx transaction.\n */\nfunction isOldStyleEthereumjsTx(\n tx: TypedTransaction | OldEthJsTransaction,\n): tx is OldEthJsTransaction {\n return 'getChainId' in tx && typeof tx.getChainId === 'function';\n}\n\nexport class LedgerKeyring extends EventEmitter {\n static type: string = keyringType;\n\n readonly type: string = keyringType;\n\n page = 0;\n\n perPage = 5;\n\n unlockedAccount = 0;\n\n accounts: readonly string[] = [];\n\n accountDetails: Record<string, AccountDetails> = {};\n\n hdk = new HDKey();\n\n hdPath = hdPathString;\n\n paths: Record<string, number> = {};\n\n network: NetworkApiUrls = NetworkApiUrls.Mainnet;\n\n implementFullBIP44 = false;\n\n bridgeUrl: string = BRIDGE_URL;\n\n bridge: LedgerBridge;\n\n constructor({ bridge }: { bridge: LedgerBridge }) {\n super();\n\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() {\n return this.bridge.init(this.bridgeUrl);\n }\n\n async destroy() {\n return this.bridge.destroy();\n }\n\n async serialize() {\n return {\n hdPath: this.hdPath,\n accounts: this.accounts,\n accountDetails: this.accountDetails,\n bridgeUrl: this.bridgeUrl,\n implementFullBIP44: false,\n };\n }\n\n async deserialize(opts: Partial<LedgerBridgeKeyringOptions> = {}) {\n this.hdPath = opts.hdPath ?? hdPathString;\n this.bridgeUrl = opts.bridgeUrl ?? BRIDGE_URL;\n this.accounts = opts.accounts ?? [];\n this.accountDetails = opts.accountDetails ?? {};\n if (!opts.accountDetails) {\n this.#migrateAccountDetails(opts);\n }\n\n this.implementFullBIP44 = opts.implementFullBIP44 ?? false;\n\n // Remove accounts that don't have corresponding account details\n this.accounts = this.accounts.filter((account) =>\n Object.keys(this.accountDetails).includes(\n ethUtil.toChecksumAddress(account),\n ),\n );\n\n return Promise.resolve();\n }\n\n #migrateAccountDetails(opts: Partial<LedgerBridgeKeyringOptions>) {\n if (this.#isLedgerLiveHdPath() && opts.accountIndexes) {\n for (const [account, index] of Object.entries(opts.accountIndexes)) {\n this.accountDetails[account] = {\n bip44: true,\n hdPath: this.#getPathForIndex(index),\n };\n }\n }\n\n // try to migrate non-LedgerLive accounts too\n if (!this.#isLedgerLiveHdPath()) {\n this.accounts\n .filter(\n (account) =>\n !Object.keys(this.accountDetails).includes(\n ethUtil.toChecksumAddress(account),\n ),\n )\n .forEach((account) => {\n try {\n this.accountDetails[ethUtil.toChecksumAddress(account)] = {\n bip44: false,\n hdPath: this.#pathFromAddress(account),\n };\n } catch (error) {\n console.log(`failed to migrate account ${account}`);\n }\n });\n }\n }\n\n isUnlocked() {\n return Boolean(this.hdk?.publicKey);\n }\n\n isConnected() {\n return this.bridge.isDeviceConnected;\n }\n\n setAccountToUnlock(index: number | string) {\n this.unlockedAccount =\n typeof index === 'number' ? index : parseInt(index, 10);\n }\n\n setHdPath(hdPath: string) {\n // Reset HDKey if the path changes\n if (this.hdPath !== hdPath) {\n this.hdk = new HDKey();\n }\n this.hdPath = hdPath;\n }\n\n async unlock(hdPath?: string, updateHdk = true): Promise<string> {\n if (this.isUnlocked() && !hdPath) {\n return 'already unlocked';\n }\n const path = hdPath ? this.#toLedgerPath(hdPath) : this.hdPath;\n\n let payload;\n try {\n payload = await this.bridge.getPublicKey({\n hdPath: path,\n });\n } catch (error) {\n throw error instanceof Error ? error : new Error('Unknown error');\n }\n\n if (updateHdk && payload.chainCode) {\n this.hdk.publicKey = Buffer.from(payload.publicKey, 'hex');\n this.hdk.chainCode = Buffer.from(payload.chainCode, 'hex');\n }\n\n return payload.address;\n }\n\n async addAccounts(amount = 1): Promise<string[]> {\n return new Promise((resolve, reject) => {\n this.unlock()\n .then(async (_) => {\n const from = this.unlockedAccount;\n const to = from + amount;\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n let address;\n if (this.#isLedgerLiveHdPath()) {\n address = await this.unlock(path);\n } else {\n address = this.#addressFromIndex(pathBase, i);\n }\n\n this.accountDetails[ethUtil.toChecksumAddress(address)] = {\n // TODO: consider renaming this property, as the current name is misleading\n // It's currently used to represent whether an account uses the Ledger Live path.\n bip44: this.#isLedgerLiveHdPath(),\n hdPath: path,\n };\n\n if (!this.accounts.includes(address)) {\n this.accounts = [...this.accounts, address];\n }\n this.page = 0;\n }\n resolve(this.accounts.slice());\n })\n .catch(reject);\n });\n }\n\n async getFirstPage() {\n this.page = 0;\n return this.#getPage(1);\n }\n\n async getNextPage() {\n return this.#getPage(1);\n }\n\n async getPreviousPage() {\n return this.#getPage(-1);\n }\n\n async getAccounts() {\n return Promise.resolve(this.accounts.slice());\n }\n\n removeAccount(address: string) {\n if (\n !this.accounts.map((a) => a.toLowerCase()).includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.accounts = this.accounts.filter(\n (a) => a.toLowerCase() !== address.toLowerCase(),\n );\n delete this.accountDetails[ethUtil.toChecksumAddress(address)];\n }\n\n async attemptMakeApp() {\n return this.bridge.attemptMakeApp();\n }\n\n async updateTransportMethod(transportType: string) {\n return this.bridge.updateTransportMethod(transportType);\n }\n\n // tx is an instance of the ethereumjs-transaction class.\n async signTransaction(\n address: string,\n tx: TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n let rawTxHex;\n // transactions built with older versions of ethereumjs-tx have a\n // getChainId method that newer versions do not. Older versions are mutable\n // while newer versions default to being immutable. Expected shape and type\n // of data for v, r and s differ (Buffer (old) vs BN (new))\n if (isOldStyleEthereumjsTx(tx)) {\n // In this version of ethereumjs-tx we must add the chainId in hex format\n // to the initial v value. The chainId must be included in the serialized\n // transaction which is only communicated to ethereumjs-tx in this\n // value. In newer versions the chainId is communicated via the 'Common'\n // object.\n // @ts-expect-error tx.v should be a Buffer but we are assigning a string\n tx.v = ethUtil.bufferToHex(tx.getChainId());\n // @ts-expect-error tx.r should be a Buffer but we are assigning a string\n tx.r = '0x00';\n // @ts-expect-error tx.s should be a Buffer but we are assigning a string\n tx.s = '0x00';\n\n rawTxHex = tx.serialize().toString('hex');\n\n return this.#signTransaction(address, rawTxHex, (payload) => {\n tx.v = Buffer.from(payload.v, 'hex');\n tx.r = Buffer.from(payload.r, 'hex');\n tx.s = Buffer.from(payload.s, 'hex');\n return tx;\n });\n }\n\n // The below `encode` call is only necessary for legacy transactions, as `getMessageToSign`\n // calls `rlp.encode` internally for non-legacy transactions. As per the \"Transaction Execution\"\n // section of the ethereum yellow paper, transactions need to be \"well-formed RLP, with no additional\n // trailing bytes\".\n\n // Note also that `getMessageToSign` will return valid RLP for all transaction types, whereas the\n // `serialize` method will not for any transaction type except legacy. This is because `serialize` includes\n // empty r, s and v values in the encoded rlp. This is why we use `getMessageToSign` here instead of `serialize`.\n const messageToSign = tx.getMessageToSign(false);\n\n rawTxHex = Buffer.isBuffer(messageToSign)\n ? messageToSign.toString('hex')\n : RLP.encode(messageToSign).toString();\n\n return this.#signTransaction(address, rawTxHex, (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: TxData = 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 async #signTransaction(\n address: string,\n rawTxHex: string,\n handleSigning: (\n payload: SignTransactionPayload,\n ) => TypedTransaction | OldEthJsTransaction,\n ): Promise<TypedTransaction | OldEthJsTransaction> {\n const hdPath = await this.unlockAccountByAddress(address);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing transaction');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTransaction({\n tx: rawTxHex,\n hdPath,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing transaction');\n }\n\n const newOrMutatedTx = handleSigning(payload);\n const valid = newOrMutatedTx.verifySignature();\n if (valid) {\n return newOrMutatedTx;\n }\n throw new Error('Ledger: The transaction signature is not valid');\n }\n\n async signMessage(withAccount: string, data: string) {\n return this.signPersonalMessage(withAccount, data);\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(withAccount: string, message: string) {\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignMessage({\n hdPath,\n message: ethUtil.stripHexPrefix(message),\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverPersonalSignature({\n data: message,\n signature,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n async unlockAccountByAddress(address: string) {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n const accountDetails = this.accountDetails[checksummedAddress];\n if (!accountDetails) {\n throw new Error(\n `Ledger: Account for address '${checksummedAddress}' not found`,\n );\n }\n const { hdPath } = accountDetails;\n const unlockedAddress = await this.unlock(hdPath, false);\n\n // unlock resolves to the address for the given hdPath as reported by the ledger device\n // if that address is not the requested address, then this account belongs to a different device or seed\n if (unlockedAddress.toLowerCase() !== address.toLowerCase()) {\n throw new Error(\n `Ledger: Account ${address} does not belong to the connected device`,\n );\n }\n return hdPath;\n }\n\n async signTypedData<T extends MessageTypes>(\n withAccount: string,\n data: TypedMessage<T>,\n options: { version?: string } = {},\n ) {\n const isV4 = options.version === 'V4';\n if (!isV4) {\n throw new Error(\n 'Ledger: Only version 4 of typed data signing is supported',\n );\n }\n\n const { domain, types, primaryType, message } =\n TypedDataUtils.sanitizeData(data);\n const domainSeparatorHex = TypedDataUtils.hashStruct(\n 'EIP712Domain',\n domain,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n const hashStructMessageHex = TypedDataUtils.hashStruct(\n primaryType.toString(),\n message,\n types,\n SignTypedDataVersion.V4,\n ).toString('hex');\n\n const hdPath = await this.unlockAccountByAddress(withAccount);\n\n if (!hdPath) {\n throw new Error('Ledger: Unknown error while signing message');\n }\n\n let payload;\n try {\n payload = await this.bridge.deviceSignTypedData({\n hdPath,\n domainSeparatorHex,\n hashStructMessageHex,\n });\n } catch (error) {\n throw error instanceof Error\n ? error\n : new Error('Ledger: Unknown error while signing message');\n }\n\n let recoveryId = parseInt(String(payload.v), 10).toString(16);\n if (recoveryId.length < 2) {\n recoveryId = `0${recoveryId}`;\n }\n const signature = `0x${payload.r}${payload.s}${recoveryId}`;\n const addressSignedWith = recoverTypedSignature({\n data,\n signature,\n version: SignTypedDataVersion.V4,\n });\n if (\n ethUtil.toChecksumAddress(addressSignedWith) !==\n ethUtil.toChecksumAddress(withAccount)\n ) {\n throw new Error('Ledger: The signature doesnt match the right address');\n }\n return signature;\n }\n\n exportAccount() {\n throw new Error('Not supported on this device');\n }\n\n forgetDevice() {\n this.accounts = [];\n this.page = 0;\n this.unlockedAccount = 0;\n this.paths = {};\n this.accountDetails = {};\n this.hdk = new HDKey();\n }\n\n /* PRIVATE METHODS */\n async #getPage(increment: number) {\n this.page += increment;\n\n if (this.page <= 0) {\n this.page = 1;\n }\n const from = (this.page - 1) * this.perPage;\n const to = from + this.perPage;\n\n await this.unlock();\n let accounts;\n if (this.#isLedgerLiveHdPath()) {\n accounts = await this.#getAccountsBIP44(from, to);\n } else {\n accounts = this.#getAccountsLegacy(from, to);\n }\n return accounts;\n }\n\n async #getAccountsBIP44(from: number, to: number) {\n const accounts: {\n address: string;\n balance: number | null;\n index: number;\n }[] = [];\n\n for (let i = from; i < to; i++) {\n const path = this.#getPathForIndex(i);\n const address = await this.unlock(path);\n const valid = this.implementFullBIP44\n ? await this.#hasPreviousTransactions(address)\n : true;\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n\n // PER BIP44\n // \"Software should prevent a creation of an account if\n // a previous account does not have a transaction history\n // (meaning none of its addresses have been used before).\"\n if (!valid) {\n break;\n }\n }\n return accounts;\n }\n\n #getAccountsLegacy(from: number, to: number) {\n const accounts: {\n address: string;\n balance: number | null;\n index: number;\n }[] = [];\n\n for (let i = from; i < to; i++) {\n const address = this.#addressFromIndex(pathBase, i);\n accounts.push({\n address,\n balance: null,\n index: i,\n });\n this.paths[ethUtil.toChecksumAddress(address)] = i;\n }\n return accounts;\n }\n\n #addressFromIndex(basePath: string, i: number) {\n const dkey = this.hdk.derive(`${basePath}/${i}`);\n const address = ethUtil\n .publicToAddress(dkey.publicKey, true)\n .toString('hex');\n return ethUtil.toChecksumAddress(`0x${address}`);\n }\n\n #pathFromAddress(address: string) {\n const checksummedAddress = ethUtil.toChecksumAddress(address);\n let index = this.paths[checksummedAddress];\n if (typeof index === 'undefined') {\n for (let i = 0; i < MAX_INDEX; i++) {\n if (checksummedAddress === this.#addressFromIndex(pathBase, i)) {\n index = i;\n break;\n }\n }\n }\n\n if (typeof index === 'undefined') {\n throw new Error('Unknown address');\n }\n return this.#getPathForIndex(index);\n }\n\n #getPathForIndex(index: number) {\n // Check if the path is BIP 44 (Ledger Live)\n return this.#isLedgerLiveHdPath()\n ? `m/44'/60'/${index}'/0/0`\n : `${this.hdPath}/${index}`;\n }\n\n #isLedgerLiveHdPath() {\n return this.hdPath === `m/44'/60'/0'/0/0`;\n }\n\n #toLedgerPath(path: string) {\n return path.toString().replace('m/', '');\n }\n\n async #hasPreviousTransactions(address: string) {\n const apiUrl = this.#getApiUrl();\n const response = await window.fetch(\n `${apiUrl}/api?module=account&action=txlist&address=${address}&tag=latest&page=1&offset=1`,\n );\n const parsedResponse = await response.json();\n if (parsedResponse.status !== '0' && parsedResponse.result.length > 0) {\n return true;\n }\n return false;\n }\n\n #getApiUrl() {\n return this.network;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/eth-ledger-bridge-keyring",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "A MetaMask compatible keyring, for ledger hardware wallets",
5
5
  "keywords": [
6
6
  "ethereum",
@@ -37,27 +37,29 @@
37
37
  "test:watch": "jest --watch"
38
38
  },
39
39
  "dependencies": {
40
+ "@ethereumjs/rlp": "^4.0.0",
40
41
  "@ethereumjs/tx": "^4.1.1",
41
- "@metamask/utils": "^5.0.0",
42
- "eth-sig-util": "^2.0.0",
43
- "ethereumjs-util": "^7.0.9",
44
- "hdkey": "0.8.0"
42
+ "@ethereumjs/util": "^8.0.0",
43
+ "@metamask/eth-sig-util": "^7.0.0",
44
+ "hdkey": "^2.1.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@ethereumjs/common": "^3.1.1",
48
- "@lavamoat/allow-scripts": "^2.3.0",
48
+ "@lavamoat/allow-scripts": "^2.5.1",
49
49
  "@ledgerhq/hw-app-eth": "^6.32.0",
50
+ "@ledgerhq/types-cryptoassets": "^7.6.0",
51
+ "@ledgerhq/types-devices": "^6.22.4",
50
52
  "@metamask/auto-changelog": "^3.1.0",
51
53
  "@metamask/eslint-config": "^11.0.1",
52
54
  "@metamask/eslint-config-browser": "^11.0.0",
53
55
  "@metamask/eslint-config-jest": "^11.0.0",
54
56
  "@metamask/eslint-config-nodejs": "^11.0.0",
55
57
  "@metamask/eslint-config-typescript": "^11.0.0",
56
- "@types/eth-sig-util": "^2.1.1",
58
+ "@metamask/utils": "^8.2.0",
57
59
  "@types/ethereumjs-tx": "^1.0.1",
58
60
  "@types/hdkey": "^2.0.1",
59
61
  "@types/jest": "^28.1.6",
60
- "@types/node": "^14.0.0",
62
+ "@types/node": "^16.18.59",
61
63
  "@typescript-eslint/eslint-plugin": "^5.43.0",
62
64
  "@typescript-eslint/parser": "^5.43.0",
63
65
  "depcheck": "^1.4.3",
@@ -81,7 +83,7 @@
81
83
  },
82
84
  "packageManager": "yarn@3.4.1",
83
85
  "engines": {
84
- "node": ">=14.0.0"
86
+ "node": "^16.20 || ^18.16 || >=20"
85
87
  },
86
88
  "publishConfig": {
87
89
  "access": "public",
@@ -90,11 +92,9 @@
90
92
  "lavamoat": {
91
93
  "allowScripts": {
92
94
  "@lavamoat/preinstall-always-fail": false,
93
- "eth-sig-util>ethereumjs-abi>ethereumjs-util>keccak": false,
94
- "eth-sig-util>ethereumjs-util>keccak": false,
95
+ "@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
95
96
  "ethereumjs-tx>ethereumjs-util>keccak": false,
96
- "ethereumjs-util>ethereum-cryptography>keccak": false,
97
- "ethereumjs-util>ethereum-cryptography>secp256k1": false,
97
+ "ethereumjs-tx>ethereumjs-util>secp256k1": false,
98
98
  "hdkey>secp256k1": false
99
99
  }
100
100
  }