Skip to content

Commit

Permalink
Merge pull request #732 from blocknative/release/1.35.3
Browse files Browse the repository at this point in the history
Release: 1.35.3 - Main
  • Loading branch information
taylorjdawson authored Oct 29, 2021
2 parents f066c09 + 81162a0 commit e870b1f
Show file tree
Hide file tree
Showing 7 changed files with 460 additions and 155 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-onboard",
"version": "1.35.2",
"version": "1.35.3",
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
"keywords": [
"ethereum",
Expand Down
12 changes: 10 additions & 2 deletions src/modules/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const desktopDefaultWalletNames = [
'frame',
'torus',
'opera',
'liquality'
'liquality',
'blankwallet'
]

const mobileDefaultWalletNames = [
Expand Down Expand Up @@ -65,7 +66,12 @@ function select(
wallet?.display &&
wallet?.display[isMobile ? 'mobile' : 'desktop'] === false

if (detectedWalletName) {
// If the detected wallet is already listed as a wallet option then don't inject it
const walletNotIncluded = wallets.every(
wallet => isWalletInit(wallet) && wallet.walletName !== detectedWalletName
)

if (detectedWalletName && walletNotIncluded) {
// This wallet is built into onboard so add the walletName and
// the code below will load it as a wallet module
wallets.unshift({ walletName: detectedWalletName })
Expand Down Expand Up @@ -214,6 +220,8 @@ function getModule(name: string): Promise<{
return import('./wallets/detectedwallet')
case 'tp':
return import('./wallets/tp')
case 'blankwallet':
return import('./wallets/blankwallet')
// case 'mewwallet':
// return import('./wallets/mewwallet')
default:
Expand Down
7 changes: 7 additions & 0 deletions src/modules/select/wallet-icons/icon-blankwallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const blankwalletIcon = `
<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 30C23.2843 30 30 23.2843 30 15C30 6.71573 23.2843 0 15 0C6.71573 0 0 6.71573 0 15C0 23.2843 6.71573 30 15 30ZM23.125 6.875H6.875V23.125H23.125V6.875Z" fill="currentColor"/>
</svg>
`

export default blankwalletIcon
43 changes: 43 additions & 0 deletions src/modules/select/wallets/blankwallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { extensionInstallMessage } from '../content'
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'

import blankwalletIcon from '../wallet-icons/icon-blankwallet'

function blankwallet(options: CommonWalletOptions): WalletModule {
const { preferred, label, iconSrc, svg } = options

return {
name: label || 'Blank Wallet',
iconSrc,
svg: svg || blankwalletIcon,
wallet: async (helpers: Helpers) => {
const {
getProviderName,
createModernProviderInterface,
createLegacyProviderInterface
} = helpers

const provider =
(window as any).ethereum ||
((window as any).web3 && (window as any).web3.currentProvider)

return {
provider,
interface:
provider && getProviderName(provider) === 'BlankWallet'
? typeof provider.enable === 'function'
? createModernProviderInterface(provider)
: createLegacyProviderInterface(provider)
: null
}
},
type: 'injected',
link: `https://www.goblank.io/`,
installMessage: extensionInstallMessage,
desktop: true,
mobile: false,
preferred
}
}

export default blankwallet
59 changes: 35 additions & 24 deletions src/modules/select/wallets/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ async function ledgerProvider(options: LedgerProviderOptions) {
const { generateAddresses, isValidPath } = await import('./hd-wallet')
const { default: Eth } = await import('@ledgerhq/hw-app-eth')

const { Transaction } = await import('@ethereumjs/tx')
const { default: Common } = await import('@ethereumjs/common')
const { TransactionFactory: Transaction, Capability } = await import(
'@ethereumjs/tx'
)
const { default: Common, Hardfork } = await import('@ethereumjs/common')
const ethUtil = await import('ethereumjs-util')
const { TypedDataUtils } = await import('eth-sig-util')

Expand Down Expand Up @@ -403,38 +405,47 @@ async function ledgerProvider(options: LedgerProviderOptions) {

async function signTransaction(transactionData: any) {
const path = [...addressToPath.values()][0]
const { BN, toBuffer } = ethUtil
const { rlp } = ethUtil
const common = new Common({
chain: customNetwork || networkName(networkId)
chain: customNetwork || networkName(networkId),
// Berlin is the minimum hardfork that will allow for EIP1559
hardfork: Hardfork.Berlin,
// List of supported EIPS
eips: [1559]
})
try {
// The below implemenation is adapted from:
// https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx#signing-with-a-hardware-or-external-wallet
transactionData.gasLimit = transactionData.gas ?? transactionData.gasLimit
const transaction = Transaction.fromTxData(
{
...transactionData,
gasLimit: transactionData.gas ?? transactionData.gasLimit
...transactionData
},
{ common, freeze: false }
{ common }
)
transaction.v = new BN(toBuffer(networkId))
transaction.r = transaction.s = new BN(toBuffer(0))

const ledgerResult = await eth.signTransaction(
path,
transaction.serialize().toString('hex')
)
let v = ledgerResult.v.toString(16)
// EIP155 support. check/recalc signature v value.
const rv = parseInt(v, 16)
let cv = networkId * 2 + 35
if (rv !== cv && (rv & cv) !== rv) {
cv += 1 // add signature v bit.
let unsignedTx = transaction.getMessageToSign(false)

// If this is not an EIP1559 transaction then it is legacy and it needs to be
// rlp encoded before being passed to ledger
if (!transaction.supports(Capability.EIP1559FeeMarket)) {
unsignedTx = rlp.encode(unsignedTx)
}
v = cv.toString(16)
transaction.v = new BN(toBuffer(`0x${v}`))
transaction.r = new BN(toBuffer(`0x${ledgerResult.r}`))
transaction.s = new BN(toBuffer(`0x${ledgerResult.s}`))

return `0x${transaction.serialize().toString('hex')}`
const { v, r, s } = await eth.signTransaction(path, unsignedTx)

// Reconstruct the signed transaction
const signedTx = Transaction.fromTxData(
{
...transactionData,
v: `0x${v}`,
r: `0x${r}`,
s: `0x${s}`
},
{ common }
)

return `0x${signedTx.serialize().toString('hex')}`
} catch (error) {
throw error
}
Expand Down
4 changes: 4 additions & 0 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ export function getProviderName(provider: any): string | undefined {
return 'tp'
}

if (provider.isBlank) {
return 'BlankWallet'
}

// =====================================
// When adding new wallet place above this metamask check as some providers
// have an isMetaMask property in addition to the wallet's own `is[WalletName]`
Expand Down
Loading

0 comments on commit e870b1f

Please sign in to comment.