From 94a29230bca76861505e48c4d886f59ce0dcaaae Mon Sep 17 00:00:00 2001 From: Aaron Barnard Date: Thu, 10 Feb 2022 14:18:43 +1100 Subject: [PATCH] Fixes and new packages --- packages/common/package.json | 2 +- packages/common/src/index.ts | 6 ++++-- packages/common/src/types.ts | 1 + packages/core/circle.yml | 1 + packages/core/package.json | 2 +- packages/fortmatic/circle.yml | 1 + packages/fortmatic/package.json | 2 +- packages/gnosis/circle.yml | 1 + packages/gnosis/package.json | 2 +- packages/injected/circle.yml | 1 + packages/injected/package.json | 2 +- packages/injected/tsconfig.json | 3 ++- packages/keepkey/circle.yml | 1 + packages/keepkey/package.json | 2 +- packages/keystone/circle.yml | 1 + packages/keystone/package.json | 2 +- packages/keystone/src/index.ts | 6 ++++-- packages/ledger/circle.yml | 1 + packages/ledger/package.json | 2 +- packages/ledger/src/index.ts | 18 ++++++++---------- packages/mew/circle.yml | 1 + packages/mew/package.json | 2 +- packages/portis/circle.yml | 1 + packages/portis/package.json | 2 +- packages/torus/circle.yml | 1 + packages/torus/package.json | 2 +- packages/trezor/circle.yml | 1 + packages/trezor/package.json | 2 +- packages/trezor/src/index.ts | 24 +++++++++++++++--------- packages/walletconnect/circle.yml | 1 + packages/walletconnect/package.json | 2 +- packages/walletconnect/src/index.ts | 18 ++++++++++++++---- packages/walletlink/circle.yml | 1 + packages/walletlink/package.json | 2 +- tsconfig.json | 2 +- 35 files changed, 76 insertions(+), 43 deletions(-) diff --git a/packages/common/package.json b/packages/common/package.json index 5023a89cb..c88a2ca59 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/common", - "version": "2.0.0-alpha.12", + "version": "2.0.0-alpha.13", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index c4dbe3d9c..1d523725b 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -60,7 +60,8 @@ import type { InjectedProvider, Chain, TokenSymbol, - CustomNetwork + CustomNetwork, + TransactionObject } from './types' export { @@ -138,5 +139,6 @@ export type { InjectedProvider, Chain, TokenSymbol, - CustomNetwork + CustomNetwork, + TransactionObject } diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 978fae1bf..23aa8a486 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -325,6 +325,7 @@ export interface TransactionObject { gasLimit?: string gasPrice?: string to: string + chainId: number value?: string maxFeePerGas?: string maxPriorityFeePerGas?: string diff --git a/packages/core/circle.yml b/packages/core/circle.yml index ae9f6b30a..21bebd9f8 100644 --- a/packages/core/circle.yml +++ b/packages/core/circle.yml @@ -45,3 +45,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/core/package.json b/packages/core/package.json index b08404fb4..c5d2af855 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/core", - "version": "2.0.0-alpha.17", + "version": "2.0.0-alpha.18", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", diff --git a/packages/fortmatic/circle.yml b/packages/fortmatic/circle.yml index 60c91bf04..f4a096a06 100644 --- a/packages/fortmatic/circle.yml +++ b/packages/fortmatic/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/fortmatic/package.json b/packages/fortmatic/package.json index a740f6a07..cc9e9d9f0 100644 --- a/packages/fortmatic/package.json +++ b/packages/fortmatic/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/fortmatic", - "version": "2.0.0-alpha.5", + "version": "2.0.0-alpha.6", "description": "Fortmatic module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/gnosis/circle.yml b/packages/gnosis/circle.yml index 973f59aa3..0e5a0d4bd 100644 --- a/packages/gnosis/circle.yml +++ b/packages/gnosis/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/gnosis/package.json b/packages/gnosis/package.json index 3a3b29962..989b4c19c 100644 --- a/packages/gnosis/package.json +++ b/packages/gnosis/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/gnosis", - "version": "2.0.0-alpha.5", + "version": "2.0.0-alpha.6", "description": "Gnosis module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/injected/circle.yml b/packages/injected/circle.yml index fb4539907..5ed888b95 100644 --- a/packages/injected/circle.yml +++ b/packages/injected/circle.yml @@ -43,3 +43,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/injected/package.json b/packages/injected/package.json index f5c00f774..3552b9d88 100644 --- a/packages/injected/package.json +++ b/packages/injected/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/injected-wallets", - "version": "2.0.0-alpha.7", + "version": "2.0.0-alpha.8", "description": "Injected wallets module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/injected/tsconfig.json b/packages/injected/tsconfig.json index 46dfd369d..fa1e029bc 100644 --- a/packages/injected/tsconfig.json +++ b/packages/injected/tsconfig.json @@ -1,11 +1,12 @@ { "extends": "../../tsconfig.json", "include": ["src/**/*"], - + "compilerOptions": { "outDir": "dist", "rootDir": "src", "declarationDir": "dist", + "allowSyntheticDefaultImports": true, "paths": { "*": ["./src/*", "./node_modules/*"] }, diff --git a/packages/keepkey/circle.yml b/packages/keepkey/circle.yml index 4475f827d..806a1a98a 100644 --- a/packages/keepkey/circle.yml +++ b/packages/keepkey/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/keepkey/package.json b/packages/keepkey/package.json index 8c0812b87..b7ad5c4bd 100644 --- a/packages/keepkey/package.json +++ b/packages/keepkey/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/keepkey", - "version": "2.0.0-alpha.8", + "version": "2.0.0-alpha.9", "description": "KeepKey module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/keystone/circle.yml b/packages/keystone/circle.yml index a7f017882..8b46a594c 100644 --- a/packages/keystone/circle.yml +++ b/packages/keystone/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/keystone/package.json b/packages/keystone/package.json index a77b71830..d4a4ee97d 100644 --- a/packages/keystone/package.json +++ b/packages/keystone/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/keystone", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.7", "description": "Keystone module for Onboard.js", "module": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/packages/keystone/src/index.ts b/packages/keystone/src/index.ts index 6054ed050..6ceec987a 100644 --- a/packages/keystone/src/index.ts +++ b/packages/keystone/src/index.ts @@ -5,7 +5,6 @@ import { createEIP1193Provider, CustomNetwork, ProviderRpcErrorCode, - GetInterfaceHelpers, ProviderRpcError, ScanAccountsOptions, WalletInit @@ -78,7 +77,7 @@ function keystone({ return { label: 'Keystone', getIcon, - getInterface: async ({ EventEmitter, chains }: GetInterfaceHelpers) => { + getInterface: async ({ EventEmitter, chains }) => { const { JsonRpcProvider } = await import('@ethersproject/providers') const { default: Common, Hardfork } = await import('@ethereumjs/common') @@ -170,6 +169,9 @@ function keystone({ // Set the `from` field to the currently selected account transactionObject = { ...transactionObject, from } + // @ts-ignore -- Due to weird commonjs exports + const CommonConstructor = Common.default || Common + const common = new Common({ chain: customNetwork || Number.parseInt(currentChain.id) || 1, // Berlin is the minimum hardfork that will allow for EIP1559 diff --git a/packages/ledger/circle.yml b/packages/ledger/circle.yml index 85e8fd1e9..7fd87e784 100644 --- a/packages/ledger/circle.yml +++ b/packages/ledger/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/ledger/package.json b/packages/ledger/package.json index f9e2f1346..29cf81682 100644 --- a/packages/ledger/package.json +++ b/packages/ledger/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/ledger", - "version": "2.0.0-alpha.12", + "version": "2.0.0-alpha.13", "description": "Ledger module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/ledger/src/index.ts b/packages/ledger/src/index.ts index a24af701f..b10d7c7a7 100644 --- a/packages/ledger/src/index.ts +++ b/packages/ledger/src/index.ts @@ -8,6 +8,10 @@ import type { GetInterfaceHelpers } from '@bn-onboard/common' +// these cannot be dynamically imported +import { TypedDataUtils } from '@metamask/eth-sig-util' +import { Buffer } from 'buffer' + import type Transport from '@ledgerhq/hw-transport' import type { providers } from 'ethers' @@ -64,7 +68,6 @@ const getAccount = async ( ): Promise => { //@ts-ignore const { default: HDKey } = await import('hdkey') - const { Buffer } = await import('buffer') const { publicToAddress, toChecksumAddress } = await import('ethereumjs-util') const hdk = new HDKey() @@ -132,11 +135,7 @@ function ledger({ const { compress } = (await import('eth-crypto')).publicKey const ethUtil = await import('ethereumjs-util') - const { - TypedDataUtils: { hashStruct }, - SignTypedDataVersion - } = await import('@metamask/eth-sig-util') - + const { SignTypedDataVersion } = await import('@metamask/eth-sig-util') const { JsonRpcProvider } = await import('@ethersproject/providers') const { accountSelect, createEIP1193Provider, ProviderRpcError } = @@ -275,8 +274,7 @@ function ledger({ transactionObject = { ...transactionObject, from } // @ts-ignore - const CommonConstructor = Common.default - + const CommonConstructor = Common.default || Common const common = new CommonConstructor({ chain: customNetwork || currentChain.hasOwnProperty('id') @@ -358,14 +356,14 @@ function ledger({ accounts.find(account => account.address === address) || accounts[0] - const domainHash = hashStruct( + const domainHash = TypedDataUtils.hashStruct( 'EIP712Domain', typedData.domain, typedData.types, SignTypedDataVersion.V3 ).toString('hex') - const messageHash = hashStruct( + const messageHash = TypedDataUtils.hashStruct( typedData.primaryType, typedData.message, typedData.types, diff --git a/packages/mew/circle.yml b/packages/mew/circle.yml index f4ad68e31..22f66c392 100644 --- a/packages/mew/circle.yml +++ b/packages/mew/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/mew/package.json b/packages/mew/package.json index 418afd50e..0e837aa26 100644 --- a/packages/mew/package.json +++ b/packages/mew/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/mew", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.7", "description": "MEW module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/portis/circle.yml b/packages/portis/circle.yml index 02d76f4b4..da9feabd0 100644 --- a/packages/portis/circle.yml +++ b/packages/portis/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/portis/package.json b/packages/portis/package.json index 27b1a7205..0f5812052 100644 --- a/packages/portis/package.json +++ b/packages/portis/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/portis", - "version": "2.0.0-alpha.5", + "version": "2.0.0-alpha.6", "description": "Portis module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/torus/circle.yml b/packages/torus/circle.yml index fb0a8d042..73e5469d9 100644 --- a/packages/torus/circle.yml +++ b/packages/torus/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/torus/package.json b/packages/torus/package.json index cb433060f..2e94e462a 100644 --- a/packages/torus/package.json +++ b/packages/torus/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/torus", - "version": "2.0.0-alpha.5", + "version": "2.0.0-alpha.6", "description": "Torus module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/trezor/circle.yml b/packages/trezor/circle.yml index 76578baf0..85c3923ca 100644 --- a/packages/trezor/circle.yml +++ b/packages/trezor/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/trezor/package.json b/packages/trezor/package.json index b9bc0c9a5..ca1b415d8 100644 --- a/packages/trezor/package.json +++ b/packages/trezor/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/trezor", - "version": "2.0.0-alpha.7", + "version": "2.0.0-alpha.8", "description": "Trezor module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/trezor/src/index.ts b/packages/trezor/src/index.ts index db351eb06..8755359d0 100644 --- a/packages/trezor/src/index.ts +++ b/packages/trezor/src/index.ts @@ -6,10 +6,17 @@ import { ScanAccountsOptions, TransactionObject, WalletInit -} from '@bn-onboard/common/src/types' -import type { providers } from 'ethers' -import type { BIP32Interface } from 'bip32' -import { EthereumTransaction, EthereumTransactionEIP1559 } from 'trezor-connect' +} from '@bn-onboard/common' + +// cannot be dynamically imported +import { Buffer } from 'buffer' + +import type { JsonRpcProvider } from '@ethersproject/providers' + +import type { + EthereumTransaction, + EthereumTransactionEIP1559 +} from 'trezor-connect' interface TrezorOptions { email: string @@ -42,11 +49,10 @@ const getAccount = async ( { publicKey, chainCode, path }: AccountData, asset: Asset, index: number, - provider: providers.JsonRpcProvider + provider: JsonRpcProvider ): Promise => { //@ts-ignore const { default: HDKey } = await import('hdkey') - const { Buffer } = await import('buffer') const { publicToAddress, toChecksumAddress } = await import('ethereumjs-util') const hdk = new HDKey() @@ -73,7 +79,7 @@ const getAccount = async ( const getAddresses = async ( account: AccountData, asset: Asset, - provider: providers.JsonRpcProvider + provider: JsonRpcProvider ): Promise => { const accounts = [] let index = 0 @@ -324,8 +330,8 @@ function trezor(options: TrezorOptions): WalletInit { const transactionData = createTrezorTransactionObject(transactionObject) - // @ts-ignore - const CommonConstructor = Common.default + // @ts-ignore -- Due to weird commonjs exports + const CommonConstructor = Common.default || Common const common = new CommonConstructor({ chain: customNetwork || Number.parseInt(currentChain.id) || 1, diff --git a/packages/walletconnect/circle.yml b/packages/walletconnect/circle.yml index 7ba5e2d2d..c47b8d674 100644 --- a/packages/walletconnect/circle.yml +++ b/packages/walletconnect/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/walletconnect/package.json b/packages/walletconnect/package.json index 5d39ad030..61ad857df 100644 --- a/packages/walletconnect/package.json +++ b/packages/walletconnect/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/walletconnect", - "version": "2.0.0-alpha.7", + "version": "2.0.0-alpha.8", "description": "WalletConnect module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/packages/walletconnect/src/index.ts b/packages/walletconnect/src/index.ts index 684907aa4..5a436b4f0 100644 --- a/packages/walletconnect/src/index.ts +++ b/packages/walletconnect/src/index.ts @@ -6,6 +6,7 @@ import { } from '@bn-onboard/common' import { ProviderRpcError } from '@bn-onboard/common' +import { EventEmitter } from 'stream' interface WalletConnectOptions { bridge?: string @@ -36,13 +37,19 @@ function walletConnect(options?: WalletConnectOptions): WalletInit { bridge }) - class EthProvider extends EventEmitter { + const emitter = new EventEmitter() + + class EthProvider { public request: EIP1193Provider['request'] public connector: InstanceType public chains: Chain[] public disconnect: EIP1193Provider['disconnect'] + public emit: EventEmitter['emit'] + public on: EventEmitter['on'] + public removeListener: EventEmitter['removeListener'] private disconnected$: InstanceType + constructor({ connector, chains @@ -50,7 +57,9 @@ function walletConnect(options?: WalletConnectOptions): WalletInit { connector: InstanceType chains: Chain[] }) { - super() + this.emit = emitter.emit.bind(emitter) + this.on = emitter.on.bind(emitter) + this.removeListener = emitter.removeListener.bind(emitter) this.connector = connector this.chains = chains @@ -158,13 +167,14 @@ function walletConnect(options?: WalletConnectOptions): WalletInit { // @ts-ignore if (method === 'eth_sendTransaction') { // @ts-ignore - return this.connector.sendTransaction(params) + return this.connector.sendTransaction(params[0]) } // @ts-ignore if (method === 'eth_signTransaction') { + console.log({ params }) // @ts-ignore - return this.connector.signTransaction(params) + return this.connector.signTransaction(params[0]) } // @ts-ignore diff --git a/packages/walletlink/circle.yml b/packages/walletlink/circle.yml index f4c2fdc0c..e1b4702e3 100644 --- a/packages/walletlink/circle.yml +++ b/packages/walletlink/circle.yml @@ -25,3 +25,4 @@ workflows: branches: only: - main + - feature/v2 diff --git a/packages/walletlink/package.json b/packages/walletlink/package.json index 15cacf232..2accd5ece 100644 --- a/packages/walletlink/package.json +++ b/packages/walletlink/package.json @@ -1,6 +1,6 @@ { "name": "@bn-onboard/walletlink", - "version": "2.0.0-alpha.5", + "version": "2.0.0-alpha.6", "description": "WalletLink module for Onboard.js", "module": "dist/index.js", "browser": "dist/index.js", diff --git a/tsconfig.json b/tsconfig.json index 52272ec52..688dda375 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -69,7 +69,7 @@ /* Interop Constraints */ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, + // "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,