Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenLogin v5 #2372

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,314 changes: 981 additions & 1,333 deletions package-lock.json

Large diffs are not rendered by default.

109 changes: 55 additions & 54 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,48 +30,49 @@
"test:e2e:mobile": "env MOBILE_ENV=true mocha --timeout=60000 ./test/e2e"
},
"dependencies": {
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@ethereumjs/util": "^8.1.0",
"@ethereumjs/common": "^4.0.0",
"@ethereumjs/tx": "^5.0.0",
"@ethereumjs/util": "^9.0.0",
"@gtm-support/vue2-gtm": "^2.0.0",
"@metamask/contract-metadata": "^2.3.1",
"@metamask/eth-json-rpc-infura": "^8.1.1",
"@metamask/eth-json-rpc-middleware": "^11.0.1",
"@metamask/eth-json-rpc-provider": "^1.0.1",
"@metamask/eth-sig-util": "^6.0.0",
"@sentry/browser": "^7.64.0",
"@sentry/tracing": "^7.64.0",
"@sentry/vue": "^7.64.0",
"@toruslabs/broadcast-channel": "^7.0.0",
"@toruslabs/eccrypto": "^3.0.0",
"@toruslabs/http-helpers": "^4.0.0",
"@toruslabs/loglevel-sentry": "^5.0.0",
"@toruslabs/metadata-helpers": "^4.0.0",
"@toruslabs/openlogin": "^4.7.2",
"@toruslabs/openlogin-jrpc": "^4.7.2",
"@toruslabs/openlogin-session-manager": "^1.1.0",
"@toruslabs/openlogin-subkey": "^4.7.2",
"@toruslabs/openlogin-utils": "^4.7.0",
"@uniswap/default-token-list": "^11.5.0",
"@walletconnect/sign-client": "^2.10.0",
"@walletconnect/utils": "^2.10.0",
"@metamask/contract-metadata": "^2.4.0",
"@metamask/eth-json-rpc-infura": "^9.0.0",
"@metamask/eth-json-rpc-middleware": "^12.0.0",
"@metamask/eth-json-rpc-provider": "^2.2.0",
"@metamask/eth-sig-util": "^7.0.0",
"@sentry/browser": "^7.75.1",
"@sentry/tracing": "^7.75.1",
"@sentry/vue": "^7.75.1",
"@toruslabs/broadcast-channel": "^9.0.1",
"@toruslabs/eccrypto": "^4.0.0",
"@toruslabs/http-helpers": "^5.0.0",
"@toruslabs/loglevel-sentry": "^6.0.1",
"@toruslabs/metadata-helpers": "^5.0.0",
"@toruslabs/openlogin": "^5.3.0",
"@toruslabs/openlogin-jrpc": "^5.3.0",
"@toruslabs/openlogin-session-manager": "^3.0.0",
"@toruslabs/openlogin-subkey": "^5.0.0",
"@toruslabs/openlogin-utils": "^5.3.0",
"@uniswap/default-token-list": "^11.9.0",
"@walletconnect/sign-client": "^2.10.4",
"@walletconnect/utils": "^2.10.4",
"await-semaphore": "^0.1.3",
"bignumber.js": "^9.1.1",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"bowser": "^2.11.0",
"clone": "^2.1.2",
arch1995 marked this conversation as resolved.
Show resolved Hide resolved
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.32.0",
"core-js": "^3.33.1",
"das-sdk": "^1.9.3",
"deepmerge": "^4.3.1",
"eth-block-tracker": "^7.1.0",
"eth-json-rpc-filters": "^6.0.0",
"eth-block-tracker": "^8.1.0",
"eth-json-rpc-filters": "^6.0.1",
"eth-query": "^2.1.2",
"eth-rpc-errors": "^4.0.3",
"ethers": "^6.7.1",
"ethers": "^6.8.0",
"ethjs-query": "^0.3.8",
"fast-json-patch": "^3.1.1",
"jsonschema": "^1.4.1",
"jwt-decode": "^3.1.2",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"pify": "^5.0.0",
Expand All @@ -97,67 +98,67 @@
"workbox-strategies": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/eslint-parser": "^7.22.10",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/eslint-plugin": "^7.22.10",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
"@babel/preset-env": "^7.22.10",
"@babel/register": "^7.22.5",
"@sentry/cli": "^2.20.5",
"@babel/preset-env": "^7.23.2",
"@babel/register": "^7.22.15",
"@sentry/cli": "^2.21.2",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-plugin-pwa": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"@vue/eslint-config-standard": "^8.0.1",
"assert": "^2.0.0",
"assert": "^2.1.0",
"codecov": "^3.8.3",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"empty-module": "0.0.2",
"eslint": "^8.47.0",
"eslint": "^8.52.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-problems": "^8.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-n": "^16.0.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.2.0",
"eslint-plugin-only-error": "^1.0.2",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-switch-case": "^1.1.2",
"eslint-plugin-unicorn": "^47.0.0",
"eslint-plugin-vue": "^9.17.0",
"eslint-plugin-vue-scoped-css": "^2.5.0",
"eslint-plugin-unicorn": "^48.0.1",
"eslint-plugin-vue": "^9.18.1",
"eslint-plugin-vue-scoped-css": "^2.5.1",
"express": "^4.18.2",
"fibers": "^5.0.3",
"ganache": "^7.9.0",
"ganache": "^7.9.1",
"husky": "^8.0.3",
"jsdom": "^22.1.0",
"jsdom-global": "^3.0.2",
"lint-staged": "^14.0.0",
"lint-staged": "^15.0.2",
"lodash-es": "^4.17.21",
"luxon": "^3.4.0",
"luxon": "^3.4.3",
"mocha": "^10.2.0",
"nock": "13.3.2",
"node-fetch": "^3.3.2",
"nock": "13.3.6",
"nyc": "^15.1.0",
"prettier": "^3.0.2",
"prettier": "^3.0.3",
"process": "^0.11.10",
"puppeteer": "^21.0.3",
"sass": "~1.32.13",
"puppeteer": "^21.4.1",
"sass": "~1.69.5",
arch1995 marked this conversation as resolved.
Show resolved Hide resolved
"sass-loader": "^13.3.2",
"sinon": "^15.2.0",
"stylus": "^0.59.0",
"stylus": "^0.60.0",
"stylus-loader": "^7.1.3",
"terser-webpack-plugin": "^5.3.9",
"through2": "^4.0.2",
"uglifyify": "^5.0.2",
"url": "^0.11.1",
"undici": "^5.27.0",
"url": "^0.11.3",
"vue-cli-plugin-vuetify": "^2.5.8",
"vue-cli-plugin-webpack-bundle-analyzer": "~4.0.0",
"vue-template-compiler": "^2.7.14",
"vue-template-compiler": "^2.7.15",
"vuetify-loader": "^1.9.2",
"worker-loader": "^3.0.8"
},
Expand Down
3 changes: 1 addition & 2 deletions scripts/importLocales.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable unicorn/prefer-top-level-await */
/* eslint-disable import/no-extraneous-dependencies */

import fs from 'fs'
import fetch from 'node-fetch'
import path from 'path'

const args = process.argv.slice(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</template>

<script>
import { addHexPrefix, isValidPrivate, stripHexPrefix, toBuffer } from '@ethereumjs/util'
import { addHexPrefix, isValidPrivate, stripHexPrefix } from '@ethereumjs/util'
import BN from 'bn.js'
import log from 'loglevel'

Expand Down Expand Up @@ -129,7 +129,7 @@ export default {
return this.t('walletSettings.customKey.privateKeyCannotBeZero') // 'Private key cannot be 0'
}
const prefixed = addHexPrefix(v)
const buffer = toBuffer(prefixed)
const buffer = Buffer.from(prefixed.slice(2), 'hex')
if (!isValidPrivate(buffer)) {
return this.t('walletSettings.customKey.invalidPrivateKey') // 'Invalid private key'
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/DecryptMessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, bufferToHex, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bytesToHex, stripHexPrefix } from '@ethereumjs/util'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
import log from 'loglevel'
Expand Down Expand Up @@ -309,6 +309,6 @@ export default class DecryptMessageManager extends EventEmitter {
log.debug('Message was not hex encoded, interpreting as utf8.')
}

return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
}
4 changes: 2 additions & 2 deletions src/controllers/MessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bufferToHex } from '@ethereumjs/util'
import { bytesToHex } from '@ethereumjs/util'
import { keccak256 } from '@toruslabs/metadata-helpers'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
Expand Down Expand Up @@ -290,5 +290,5 @@ function normalizeMessageData(data) {
return data
}
// data is unicode, convert to hex
return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
4 changes: 2 additions & 2 deletions src/controllers/PersonalMessageManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, bufferToHex, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bytesToHex, stripHexPrefix } from '@ethereumjs/util'
import { ethErrors } from 'eth-rpc-errors'
import EventEmitter from 'events'
import log from 'loglevel'
Expand Down Expand Up @@ -290,6 +290,6 @@ export default class PersonalMessageManager extends EventEmitter {
log.debug('Message was not hex encoded, interpreting as utf8.', error)
}

return bufferToHex(Buffer.from(data, 'utf8'))
return bytesToHex(Buffer.from(data, 'utf8'))
}
}
2 changes: 1 addition & 1 deletion src/controllers/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PreferencesController extends SafeEventEmitter {
const messageToSign = await this.getMessageForSigning(address)
if (!messageToSign.startsWith('Torus Signin')) throw new Error('Cannot sign on invalid message')
const bufferedMessage = Buffer.from(messageToSign, 'utf8')
const hashedMessage = hashPersonalMessage(bufferedMessage).toString('hex')
const hashedMessage = Buffer.from(hashPersonalMessage(bufferedMessage)).toString('hex')
const signedMessage = await this.signMessage(address, hashedMessage)
response = await this.api.post(
`${config.api}/auth/verify`,
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/TorusKeyring.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bufferToHex, ecsign, stripHexPrefix } from '@ethereumjs/util'
import { bigIntToBytes, ecsign, stripHexPrefix } from '@ethereumjs/util'
import { concatSig, decrypt, getEncryptionPublicKey, personalSign, signTypedData } from '@metamask/eth-sig-util'
import { Wallet } from 'ethers'
import { EventEmitter } from 'events'
Expand Down Expand Up @@ -57,13 +57,13 @@ export default class TorusKeyring extends EventEmitter {
newWallets.push(Wallet.createRandom())
}
this.wallets = [...this.wallets, ...newWallets]
const hexWallets = newWallets.map((w) => bufferToHex(w.address))
const hexWallets = newWallets.map((w) => w.address)
return hexWallets
}

// Not using
async getAccounts() {
return this.wallets.map((w) => bufferToHex(w.address))
return this.wallets.map((w) => w.address)
}

// tx is an instance of the ethereumjs-transaction class.
Expand All @@ -85,7 +85,7 @@ export default class TorusKeyring extends EventEmitter {
const privKey = this.getBufferPrivateKey(wallet.privateKey)

const messageSig = ecsign(Buffer.from(message, 'hex'), privKey)
const rawMessageSig = concatSig(messageSig.v, messageSig.r, messageSig.s)
const rawMessageSig = concatSig(Buffer.from(bigIntToBytes(messageSig.v)), Buffer.from(messageSig.r), Buffer.from(messageSig.s))
return rawMessageSig
}

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/gas/GasFeeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class GasFeeController {

try {
if (isEIP1559Compatible) {
// TODO: kovan is not working due to a bug in metamask api
const estimates = await this.fetchGasEstimates(this.EIP1559APIEndpoint.replace('<chain_id>', `${chainId}`))
const { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = estimates.medium
const estimatedGasFeeTimeBounds = this.getTimeEstimate(suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas)
Expand All @@ -160,6 +159,7 @@ class GasFeeController {
}
} catch {
try {
log.log('fetching gas fee estimates from dqwd API')
arch1995 marked this conversation as resolved.
Show resolved Hide resolved
const estimates = await this.fetchEthGasPriceEstimate(this.ethQuery)
newState = {
gasFeeEstimates: estimates,
Expand Down
15 changes: 7 additions & 8 deletions src/controllers/transactions/TransactionController.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable require-atomic-updates */
import { Common } from '@ethereumjs/common'
import { Common, Hardfork } from '@ethereumjs/common'
import { TransactionFactory } from '@ethereumjs/tx'
import { addHexPrefix, bufferToHex, isHexString, stripHexPrefix } from '@ethereumjs/util'
import { addHexPrefix, bigIntToHex, isHexString, stripHexPrefix } from '@ethereumjs/util'
import { SafeEventEmitter } from '@toruslabs/openlogin-jrpc'
import { ethErrors } from 'eth-rpc-errors'
import { formatEther, keccak256 } from 'ethers'
Expand All @@ -20,7 +20,6 @@ import {
CONTRACT_TYPE_ERC1155,
CONTRACT_TYPE_ETH,
GAS_ESTIMATE_TYPES,
HARDFORKS,
INFURA_PROVIDER_TYPES,
OLD_ERC721_LIST,
RPC,
Expand Down Expand Up @@ -182,7 +181,7 @@ class TransactionController extends SafeEventEmitter {
// This logic below will have to be updated each time a hardfork happens
// that carries with it a new Transaction type. It is inconsequential for
// hardforks that do not include new types.
const hardfork = supportsEIP1559 ? HARDFORKS.LONDON : HARDFORKS.BERLIN
const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin

// type will be one of our default network names or 'rpc'. the default
// network names are sufficient configuration, simply pass the name as the
Expand Down Expand Up @@ -741,15 +740,15 @@ class TransactionController extends SafeEventEmitter {

// add r,s,v values for provider request purposes see createMetamaskMiddleware
// and JSON rpc standard for further explanation
txMeta.r = bufferToHex(signedEthTx.r)
txMeta.s = bufferToHex(signedEthTx.s)
txMeta.v = bufferToHex(signedEthTx.v)
txMeta.r = bigIntToHex(signedEthTx.r)
txMeta.s = bigIntToHex(signedEthTx.s)
txMeta.v = bigIntToHex(signedEthTx.v)

this.txStateManager.updateTransaction(txMeta, 'transactions#signTransaction: add r, s, v values')

// set state to signed
this.txStateManager.setTxStatusSigned(txMeta.id)
const rawTx = bufferToHex(signedEthTx.serialize())
const rawTx = addHexPrefix(Buffer.from(signedEthTx.serialize(), 'hex').toString('hex'))
return rawTx
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default {
dispatch('subscribeToControllers')
commit('setUserInfo', userInfo)

const selectedAddress = `0x${privateToAddress(Buffer.from(privateKey.padStart(64, '0'), 'hex')).toString('hex')}`
const selectedAddress = `0x${Buffer.from(privateToAddress(Buffer.from(privateKey.padStart(64, '0'), 'hex'))).toString('hex')}`
await dispatch('initTorusKeyring', {
keys: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/utils/accountImporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addHexPrefix, isValidPrivate, stripHexPrefix, toBuffer } from '@ethereumjs/util'
import { addHexPrefix, hexToBytes, isValidPrivate, stripHexPrefix } from '@ethereumjs/util'
import { Wallet } from 'ethers'

const accountImporter = {
Expand All @@ -15,7 +15,7 @@ const accountImporter = {
}

const prefixed = addHexPrefix(privateKey)
const buffer = toBuffer(prefixed)
const buffer = hexToBytes(prefixed)

if (!isValidPrivate(buffer)) {
throw new Error('Cannot import invalid private key.')
Expand Down
21 changes: 0 additions & 21 deletions src/utils/enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,27 +805,6 @@ export const TRANSACTION_ENVELOPE_TYPES = {
FEE_MARKET: '0x2',
}

/**
* Hardforks are points in the chain where logic is changed significantly
* enough where there is a fork and the new fork becomes the active chain.
* These constants are presented in chronological order starting with BERLIN
* because when we first needed to track the hardfork we had launched support
* for EIP-2718 (where transactions can have types and different shapes) and
* EIP-2930 (optional access lists), which were included in BERLIN.
*
* BERLIN - forked at block number 12,244,000, included typed transactions and
* optional access lists
* LONDON - future, upcoming fork that introduces the baseFeePerGas, an amount
* of the ETH transaction fees that will be burned instead of given to the
* miner. This change necessitated the third type of transaction envelope to
* specify maxFeePerGas and maxPriorityFeePerGas moving the fee bidding system
* to a second price auction model.
*/
export const HARDFORKS = {
BERLIN: 'berlin',
LONDON: 'london',
}

export const GAS_ESTIMATE_TYPES = {
FEE_MARKET: 'fee-market',
LEGACY: 'legacy',
Expand Down
Loading
Loading