Skip to content

Commit ed08b6d

Browse files
Merge pull request #562 from blocknative/release/1.26.0
Release 1.26.0
2 parents 70ca28d + 105540d commit ed08b6d

18 files changed

+589
-194
lines changed

package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.25.0",
3+
"version": "1.26.0",
44
"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.",
55
"keywords": [
66
"ethereum",
@@ -54,17 +54,20 @@
5454
},
5555
"dependencies": {
5656
"@cvbb/eth-keyring": "^1.1.0",
57-
"@ledgerhq/hw-app-eth": "^5.21.0",
57+
"@gnosis.pm/safe-apps-provider": "^0.3.0",
58+
"@gnosis.pm/safe-apps-sdk": "^2.3.0",
59+
"@ledgerhq/hw-app-eth": "^5.49.0",
5860
"@ledgerhq/hw-transport-u2f": "^5.21.0",
5961
"@portis/web3": "^4.0.0",
60-
"@toruslabs/torus-embed": "^1.9.2",
62+
"@toruslabs/torus-embed": "^1.10.11",
6163
"@walletconnect/web3-provider": "^1.4.1",
6264
"authereum": "^0.1.12",
6365
"bignumber.js": "^9.0.0",
64-
"bnc-sdk": "^3.2.0",
66+
"bnc-sdk": "^3.3.4",
6567
"bowser": "^2.10.0",
6668
"eth-lattice-keyring": "^0.2.7",
6769
"eth-provider": "^0.6.1",
70+
"eth-sig-util": "^3.0.1",
6871
"ethereumjs-tx": "^2.1.2",
6972
"ethereumjs-util": "^7.0.3",
7073
"fortmatic": "^2.2.1",
@@ -74,5 +77,10 @@
7477
"trezor-connect": "^8.1.9",
7578
"walletlink": "^2.1.0",
7679
"web3-provider-engine": "^15.0.4"
80+
},
81+
"resolutions": {
82+
"authereum/web3-utils/underscore": "^1.12.1",
83+
"authereum/ethers/elliptic": "^6.5.3",
84+
"@portis/web3/pocket-js-core/axios": "^0.21.1"
7785
}
7886
}

rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default {
6969
'ethereumjs-tx',
7070
'ethereumjs-util',
7171
'eth-lattice-keyring',
72+
'eth-sig-util',
7273
'@cvbb/eth-keyring',
7374
'hdkey',
7475
'@ledgerhq/hw-transport-u2f',
@@ -82,6 +83,8 @@ export default {
8283
'web3-provider-engine/subproviders/rpc',
8384
'web3-provider-engine/subproviders/subscriptions',
8485
'web3-provider-engine/subproviders/filters',
85-
'eth-provider'
86+
'eth-provider',
87+
'@gnosis.pm/safe-apps-sdk',
88+
'@gnosis.pm/safe-apps-provider'
8689
]
8790
}

src/@types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare module 'web3-provider-engine/subproviders/subscriptions'
88
declare module 'web3-provider-engine/subproviders/filters'
99
declare module 'trezor-connect'
1010
declare module 'eth-lattice-keyring'
11+
declare module 'eth-sig-util'
1112
declare module 'ethereumjs-tx'
1213
declare module 'ethereumjs-util'
1314
declare module 'hdkey'

src/interfaces.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export interface WalletModule {
120120
interface: WalletInterface | null
121121
instance?: any
122122
}>
123-
type: 'hardware' | 'injected' | 'sdk'
123+
type: WalletType
124124
link?: string
125125
installMessage?: (wallets: {
126126
currentWallet: string | undefined
@@ -132,6 +132,8 @@ export interface WalletModule {
132132
osExclusions?: Array<string>
133133
}
134134

135+
export type WalletType = 'hardware' | 'injected' | 'sdk'
136+
135137
export interface Helpers {
136138
getProviderName: (provider: any) => string | undefined
137139
createLegacyProviderInterface: (provider: any) => WalletInterface
@@ -179,6 +181,7 @@ export interface CommonWalletOptions {
179181
label?: string
180182
iconSrc?: string
181183
svg?: string
184+
networkId?: number
182185
}
183186

184187
export interface SdkWalletOptions extends CommonWalletOptions {

src/modules/select/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const mobileDefaultWalletNames = [
2424
'liquality',
2525
'alphawallet',
2626
'ownbit',
27+
'bitpie',
2728
'authereum'
2829
]
2930

@@ -135,10 +136,16 @@ function getModule(
135136
return import('./wallets/liquality')
136137
case 'frame':
137138
return import('./wallets/frame')
139+
case 'xdefi':
140+
return import('./wallets/xdefi')
138141
case 'alphawallet':
139142
return import('./wallets/alphawallet')
140143
case 'ownbit':
141144
return import('./wallets/ownbit')
145+
case 'bitpie':
146+
return import('./wallets/bitpie')
147+
case 'gnosis':
148+
return import('./wallets/gnosis')
142149
default:
143150
throw new Error(`${name} is not a valid walletName.`)
144151
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const bitpieIcon = `
2+
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.72147 0.714294H30.3108C35.1186 0.714294 39.0161 4.61182 39.0161 9.41965V31.0089C39.0161 35.8168 35.1186 39.7143 30.3108 39.7143H8.72147C3.91363 39.7143 0.0161133 35.8168 0.0161133 31.0089V9.41965C0.0161133 4.61182 3.91363 0.714294 8.72147 0.714294Z" fill="url(#paint0_linear)"/>
4+
<path d="M19.6902 35.1875C27.8635 35.1875 34.4893 28.5617 34.4893 20.3884C34.4893 12.2151 27.8635 5.58929 19.6902 5.58929C11.5169 5.58929 4.89111 12.2151 4.89111 20.3884C4.89111 28.5617 11.5169 35.1875 19.6902 35.1875Z" fill="white"/>
5+
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.5161 0.714294C30.2857 0.714294 39.0161 9.44474 39.0161 20.2143C39.0161 30.9838 30.2857 39.7143 19.5161 39.7143C8.74656 39.7143 0.0161133 30.9838 0.0161133 20.2143C0.0161133 9.44474 8.74656 0.714294 19.5161 0.714294ZM19.4287 5.34882C11.2187 5.34882 4.5632 12.0043 4.5632 20.2143C4.5632 28.4243 11.2187 35.0798 19.4287 35.0798C27.6386 35.0798 34.2941 28.4243 34.2941 20.2143C34.2941 12.0043 27.6386 5.34882 19.4287 5.34882Z" fill="url(#paint1_linear)"/>
6+
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.7479 27.6254C22.3598 28.6852 21.9967 30.0404 20.9369 30.6524C19.877 31.2643 18.5218 30.9011 17.9099 29.8413L17.2448 28.6899L16.0937 29.3546C15.0338 29.9665 13.6786 29.6034 13.0667 28.5435C12.4548 27.4837 12.8179 26.1285 13.8778 25.5166L15.0288 24.8517L13.2562 21.7814L12.105 22.4461C11.0452 23.058 9.68995 22.6949 9.07805 21.635C8.46614 20.5752 8.82927 19.2199 9.88913 18.608L11.0402 17.9432L10.3758 16.7918C9.76387 15.732 10.127 14.3768 11.1869 13.7649C12.2467 13.1529 13.6019 13.5161 14.2138 14.5759L14.8784 15.7271L17.9487 13.9545L17.2843 12.8032C16.6724 11.7434 17.0355 10.3881 18.0954 9.77622C19.1552 9.16431 20.5105 9.52745 21.1224 10.5873L21.7869 11.7385L22.9386 11.0739C23.9984 10.462 25.3536 10.8252 25.9655 11.885C26.5775 12.9449 26.2143 14.3001 25.1545 14.912L24.003 15.5768L25.7756 18.647L26.9272 17.9825C27.987 17.3706 29.3423 17.7337 29.9542 18.7935C30.5661 19.8534 30.203 21.2086 29.1431 21.8205L27.9916 22.4853L28.6565 23.6367C29.2684 24.6966 28.9052 26.0518 27.8454 26.6637C26.7855 27.2756 25.4303 26.9125 24.8184 25.8526L24.1533 24.7013L21.0831 26.4739L21.7479 27.6254ZM18.8671 22.6356L21.9373 20.863L20.1647 17.7928L17.0945 19.5654L18.8671 22.6356Z" fill="url(#paint2_linear)"/>
7+
<defs>
8+
<linearGradient id="paint0_linear" x1="20.509" y1="39.7143" x2="20.509" y2="0.714294" gradientUnits="userSpaceOnUse">
9+
<stop stop-color="#1E3DA0"/>
10+
<stop offset="1" stop-color="#3750DE"/>
11+
</linearGradient>
12+
<linearGradient id="paint1_linear" x1="19.5161" y1="0.714294" x2="19.5161" y2="39.7143" gradientUnits="userSpaceOnUse">
13+
<stop stop-color="#1D3BA3" stop-opacity="0"/>
14+
<stop offset="1" stop-color="#173793" stop-opacity="0.652938"/>
15+
</linearGradient>
16+
<linearGradient id="paint2_linear" x1="24.3911" y1="28.658" x2="14.6411" y2="11.7705" gradientUnits="userSpaceOnUse">
17+
<stop stop-color="#1E3DA0"/>
18+
<stop offset="1" stop-color="#3750DE"/>
19+
</linearGradient>
20+
</defs>
21+
</svg>
22+
`
23+
24+
export default bitpieIcon
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const gnosisWalletIcon = `
2+
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 440 440">
3+
<path d="M220,9.82C103.92,9.82,9.82,103.92,9.82,220S103.92,430.18,220,430.18,430.18,336.08,430.18,220,336.08,9.82,220,9.82ZM373.83,231.47H276.3a59.41,59.41,0,1,1,.45-20.67h97.08a10.34,10.34,0,1,1,0,20.67Z"/>
4+
</svg>
5+
`
6+
7+
export default gnosisWalletIcon
5.05 KB
Loading
Loading

src/modules/select/wallets/bitpie.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { mobileWalletInstallMessage } from '../content'
2+
import { WalletModule, Helpers, CommonWalletOptions } from '../../../interfaces'
3+
4+
import bitpieIcon from '../wallet-icons/icon-bitpie'
5+
6+
function bitpie(options: CommonWalletOptions): WalletModule {
7+
const { preferred, label, iconSrc, svg } = options
8+
9+
return {
10+
name: label || 'Bitpie',
11+
iconSrc,
12+
svg: svg || bitpieIcon,
13+
wallet: async (helpers: Helpers) => {
14+
const {
15+
getProviderName,
16+
createModernProviderInterface,
17+
createLegacyProviderInterface
18+
} = helpers
19+
20+
const provider =
21+
(window as any).ethereum ||
22+
((window as any).web3 && (window as any).web3.currentProvider)
23+
24+
return {
25+
provider,
26+
interface:
27+
provider && getProviderName(provider) === 'Bitpie'
28+
? typeof provider.enable === 'function'
29+
? createModernProviderInterface(provider)
30+
: createLegacyProviderInterface(provider)
31+
: null
32+
}
33+
},
34+
type: 'injected',
35+
link: `https://bitpiehk.com`,
36+
installMessage: mobileWalletInstallMessage,
37+
mobile: true,
38+
preferred
39+
}
40+
}
41+
42+
export default bitpie

src/modules/select/wallets/gnosis.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type SafeAppsSDK from '@gnosis.pm/safe-apps-sdk'
2+
import type { SafeInfo } from '@gnosis.pm/safe-apps-sdk'
3+
import { CommonWalletOptions, Helpers, WalletModule } from '../../../interfaces'
4+
import gnosisWalletIcon from '../wallet-icons/icon-gnosis'
5+
6+
const getSafe = (sdk: SafeAppsSDK): Promise<SafeInfo | undefined> =>
7+
Promise.race([
8+
sdk.getSafeInfo(),
9+
// Timeout need as this method hangs until it can find the safe info
10+
new Promise<undefined>(resolve => setTimeout(resolve, 200))
11+
])
12+
13+
/**
14+
* Checks to see if we are are within a Safe App context. If we are it executes
15+
* the callback function which self-selects this wallet.
16+
* @param selectWallet - A callback function which can call the `walletSelect` method
17+
* with the Gnosis wallet name.
18+
*/
19+
export const checkGnosisSafeContext = async (selectWallet: () => void) =>
20+
!!(await getSafe(new (await import('@gnosis.pm/safe-apps-sdk')).default())) &&
21+
selectWallet()
22+
23+
function gnosis(options: CommonWalletOptions): WalletModule {
24+
const { preferred, label, iconSrc, svg, networkId } = options
25+
26+
const network = networkId === 4 ? 'rinkeby.' : ''
27+
const link = `https://${network}gnosis-safe.io/app`
28+
29+
return {
30+
name: label || 'Gnosis Safe',
31+
iconSrc,
32+
svg: svg || gnosisWalletIcon,
33+
wallet: async ({ createModernProviderInterface }: Helpers) => {
34+
const sdk = new (await import('@gnosis.pm/safe-apps-sdk')).default()
35+
const { SafeAppProvider } = await import('@gnosis.pm/safe-apps-provider')
36+
37+
const safe: SafeInfo | undefined = await getSafe(sdk)
38+
// Checks if we are within the safe app context
39+
if (!safe) return { provider: undefined, interface: null }
40+
41+
const provider = new SafeAppProvider(safe, sdk)
42+
return {
43+
provider,
44+
interface: {
45+
...createModernProviderInterface(provider),
46+
connect: () => Promise.resolve([safe.safeAddress])
47+
}
48+
}
49+
},
50+
type: 'sdk',
51+
link,
52+
installMessage: () => `
53+
<p style="font-size: 0.889rem; font-family: inherit; margin: 0.889rem 0;">
54+
Click the button below to open the Gnosis Safe interface.
55+
</p>
56+
`,
57+
desktop: true,
58+
mobile: false,
59+
preferred
60+
}
61+
}
62+
63+
export default gnosis

src/modules/select/wallets/ledger.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { LedgerOptions, WalletModule, Helpers } from '../../../interfaces'
2-
32
import ledgerIcon from '../wallet-icons/icon-ledger'
43

54
const LEDGER_LIVE_PATH = `m/44'/60'`
@@ -80,6 +79,24 @@ async function ledgerProvider(options: {
8079
const EthereumTx = await import('ethereumjs-tx')
8180
const ethUtil = await import('ethereumjs-util')
8281
const buffer = await import('buffer')
82+
const { TypedDataUtils } = await import('eth-sig-util')
83+
84+
const domainHash = (message: any) => {
85+
return TypedDataUtils.hashStruct(
86+
'EIP712Domain',
87+
message.domain,
88+
message.types,
89+
true
90+
)
91+
}
92+
const messageHash = (message: any) => {
93+
return TypedDataUtils.hashStruct(
94+
message.primaryType,
95+
message.message,
96+
message.types,
97+
true
98+
)
99+
}
83100

84101
const {
85102
networkId,
@@ -130,6 +147,11 @@ async function ledgerProvider(options: {
130147
.then((res: string) => callback(null, res))
131148
.catch(err => callback(err, null))
132149
},
150+
signTypedMessage: (messageData: any, callback: any) => {
151+
signTypedMessage(messageData)
152+
.then((res: string) => callback(null, res))
153+
.catch(err => callback(err, null))
154+
},
133155
rpcUrl
134156
})
135157

@@ -406,6 +428,29 @@ async function ledgerProvider(options: {
406428
})
407429
}
408430

431+
async function signTypedMessage({ data }: { data: any }) {
432+
if (addressToPath.size === 0) {
433+
await enable()
434+
}
435+
436+
const path = [...addressToPath.values()][0]
437+
438+
return eth
439+
.signEIP712HashedMessage(
440+
path,
441+
ethUtil.bufferToHex(domainHash(data)),
442+
ethUtil.bufferToHex(messageHash(data))
443+
)
444+
.then((result: any) => {
445+
let v = (result['v'] - 27).toString(16)
446+
if (v.length < 2) {
447+
v = '0' + v
448+
}
449+
450+
return `0x${result['r']}${result['s']}${v}`
451+
})
452+
}
453+
409454
return provider
410455
}
411456

src/modules/select/wallets/providerEngine.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function createProvider(config: any) {
1616
processMessage,
1717
processPersonalMessage,
1818
signMessage,
19-
signPersonalMessage
19+
signPersonalMessage,
20+
signTypedMessage
2021
} = config
2122

2223
const pollingInterval = get(app).blockPollingInterval
@@ -29,7 +30,8 @@ function createProvider(config: any) {
2930
processMessage,
3031
processPersonalMessage,
3132
signMessage,
32-
signPersonalMessage
33+
signPersonalMessage,
34+
signTypedMessage
3335
})
3436

3537
const rpcSubProvider = new RpcSource({

src/modules/select/wallets/wallet-connect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ function walletConnect(
5353

5454
const balanceProvider = createProvider({ rpcUrl })
5555

56+
if (infuraKey && rpc) {
57+
throw new Error(
58+
'WalletConnect requires an Infura ID or a custom RPC object but not both.'
59+
)
60+
}
61+
5662
const provider = new WalletConnectProvider({
5763
infuraId: infuraKey,
5864
rpc,

0 commit comments

Comments
 (0)