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

Fix: Ledger Walletconnect v2 handling and build #1797

Merged
merged 6 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@web3-onboard/injected-wallets": "^2.10.1",
"@web3-onboard/keepkey": "^2.3.7",
"@web3-onboard/keystone": "^2.3.7",
"@web3-onboard/ledger": "^2.4.6",
"@web3-onboard/ledger": "^2.5.0-alpha.1",
"@web3-onboard/magic": "^2.1.7",
"@web3-onboard/mew-wallet": "^2.0.4",
"@web3-onboard/phantom": "^2.0.2",
Expand All @@ -77,7 +77,7 @@
"@web3-onboard/trust": "^2.0.4",
"@web3-onboard/uauth": "^2.0.5",
"@web3-onboard/venly": "^2.0.0",
"@web3-onboard/walletconnect": "^2.3.9",
"@web3-onboard/walletconnect": "^2.4.0-alpha.2",
"@web3-onboard/web3auth": "^2.2.3",
"@web3-onboard/xdefi": "^2.0.4",
"@web3-onboard/zeal": "^2.0.4",
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/services/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const intiOnboard = async (theme) => {
mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar']
}
})
const ledger = ledgerModule()
const ledger = ledgerModule({ projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5' })
const keystone = keystoneModule()
const keepkey = keepkeyModule()
const gnosis = gnosisModule()
Expand Down
44 changes: 20 additions & 24 deletions docs/src/routes/docs/[...4]wallets/[...13]ledger/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,44 @@ npm install @web3-onboard/core @web3-onboard/ledger
## Options

```typescript
interface LedgerOptions {
type LedgerOptionsWCv1 = {
/**
* Enable Ledger Connect Kit logs
* @deprecated
* Version 1 of WalletConnect has been deprecated by the WC team and the WC bridge is not available.
* To use version 1 a custom bridge url will need to be provided.
* Support will be completely remove from Web3-Onboard in the future
*/
walletConnectVersion?: 1
enableDebugLogs?: boolean
/**
* Defaults to walletConnectVersion: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
*/
chainId?: number
bridge?: string
infuraId?: string
rpc?: { [chainId: number]: string }
}

type LedgerOptionsWCv2 = {
walletConnectVersion: 2
enableDebugLogs?: boolean
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
projectId: string
/**
* List of Required Chain IDs for Ledger Live to support in number format (integer or hex)
* Defaults to [1] - Ethereum
* The chains defined within the web3-onboard config will define the
* optional chains for the WalletConnect module
* List of Optional Chain(s) ID for wallets to support in number format (integer or hex)
* Defaults to the chains provided within the web3-onboard init chain property
*/
requiredChains?: string[] | number[]
/**
* List of Required Methods for wallets to support
*/
requiredMethods?: string[]
/**
* List of Optional Methods for wallets to support
* Additional methods to be added to the default list of ['eth_sendTransaction', 'eth_signTransaction', 'personal_sign', 'eth_sign', 'eth_signTypedData', 'eth_signTypedData_v4']
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
*/
optionalMethods?: string[]
/**
* List of Required Events for wallets to support
*/
requiredEvents?: string[]
/**
* List of Optional Events for wallets to support
*/
optionalEvents?: string[]
/**
* List of Chain ID to URL mapping
*/
rpcMap?: { [chainId: number]: string }
}

type LedgerOptions = LedgerOptionsWCv1 | LedgerOptionsWCv2
```

## Usage
Expand All @@ -78,7 +75,6 @@ import Onboard from '@web3-onboard/core'
import ledgerModule from '@web3-onboard/ledger'

const ledger = ledgerModule({
walletConnectVersion: 2,
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@web3-onboard/injected-wallets": "^2.10.1",
"@web3-onboard/keepkey": "^2.3.7",
"@web3-onboard/keystone": "^2.3.7",
"@web3-onboard/ledger": "^2.4.5",
"@web3-onboard/ledger": "^2.5.0-alpha.1",
"@web3-onboard/magic": "^2.1.6",
"@web3-onboard/mew-wallet": "^2.0.3",
"@web3-onboard/phantom": "^2.0.1",
Expand Down
82 changes: 43 additions & 39 deletions packages/demo/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import { share } from 'rxjs/operators'
import VConsole from 'vconsole'
import blocknativeIcon from './blocknative-icon.js'
import DappAuth from '@dapperlabs/dappauth';
import DappAuth from '@dapperlabs/dappauth'

if (window.innerWidth < 700) {
new VConsole()
Expand Down Expand Up @@ -77,7 +77,7 @@
// displayUnavailable: true,
// ||
// display specific unavailable wallets
displayUnavailable: [ProviderLabel.MetaMask, ProviderLabel.Trust],
displayUnavailable: [ProviderLabel.MetaMask, ProviderLabel.Trust]
// but only show Binance and Bitski wallet if they are available
// filter: {
// [ProviderLabel.Binance]: 'unavailable',
Expand Down Expand Up @@ -128,7 +128,7 @@
'pillar'
]
},
requiredChains:[1, 56]
requiredChains: [1, 56]
})
const portis = portisModule({
apiKey: 'b2b7586f-2b1e-4c30-a7fb-c2d1533b153b'
Expand All @@ -145,7 +145,7 @@

const torus = torusModule()
const infinityWallet = infinityWalletModule()
const ledger = ledgerModule()
const ledger = ledgerModule({ projectId: 'f6bd6e2911b56f5ac3bc8b2d0e2d7ad5' })
const keepkey = keepkeyModule()
const keystone = keystoneModule()
const gnosis = gnosisModule()
Expand Down Expand Up @@ -462,8 +462,8 @@
const signer = ethersProvider?.getSigner()
const addr = await signer?.getAddress()
const signature = await signer?.signMessage(signMsg)
let verifySign = false;
let recoveredAddress = null;
let verifySign = false
let recoveredAddress = null

try {
recoveredAddress = recoverAddress(
Expand All @@ -472,15 +472,21 @@
)
verifySign = recoveredAddress === addr
} catch (error) {
console.error('Error recovering addressL', error);
console.error('Error recovering address', error)
verifySign = false
}

// contract wallets verify EIP-1654
const verifySignBy1654 = new DappAuth(provider);
const isAuthorizedSigner = await verifySignBy1654.isAuthorizedSigner(signMsg, signature, address);
const verifySignBy1654 = new DappAuth(provider)
const isAuthorizedSigner = await verifySignBy1654.isAuthorizedSigner(
signMsg,
signature,
address
)
if (!verifySign && !isAuthorizedSigner) {
console.error("Signature failed. Recovered address doesn' match signing address.");
console.error(
"Signature failed. Recovered address doesn' match signing address."
)
}

console.log({ signMsg, signature, recoveredAddress, addr })
Expand Down Expand Up @@ -663,31 +669,31 @@
}}>Send Success Notification</button
>
<button
on:click={() =>
onboard.state.actions.customNotification({
message:
'This is a custom DApp success notification to use however you want',
autoDismiss: 0,
type: 'pending'
})}>Send Pending Notification</button
>
<button
on:click={() =>
onboard.state.actions.customNotification({
type: 'error',
message:
'This is a custom DApp Error notification to use however you want',
autoDismiss: 0
})}>Send Error Notification</button
>
<button
on:click={() =>
onboard.state.actions.customNotification({
message:
'This is a custom non-descript DApp notification to use however you want',
autoDismiss: 0
})}>Send DApp Notification</button
>
on:click={() =>
onboard.state.actions.customNotification({
message:
'This is a custom DApp success notification to use however you want',
autoDismiss: 0,
type: 'pending'
})}>Send Pending Notification</button
>
<button
on:click={() =>
onboard.state.actions.customNotification({
type: 'error',
message:
'This is a custom DApp Error notification to use however you want',
autoDismiss: 0
})}>Send Error Notification</button
>
<button
on:click={() =>
onboard.state.actions.customNotification({
message:
'This is a custom non-descript DApp notification to use however you want',
autoDismiss: 0
})}>Send DApp Notification</button
>
</div>
<div class="switch-chain-container">
<button on:click={() => onboard.setChain({ chainId: '0x1' })}
Expand Down Expand Up @@ -742,8 +748,7 @@
>
<button
on:click={() =>
onboard.state.actions.updateAppMetadata(
{
onboard.state.actions.updateAppMetadata({
// Checkmark
icon: `<svg width="100%" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.59 8.59L12 13.17L7.41 8.59L6 10L12 16L18 10L16.59 8.59Z" fill="currentColor"/></svg>`,
// Hourglass
Expand All @@ -758,8 +763,7 @@
},
gettingStartedGuide: 'https://onboard.blocknative.com/',
explore: 'https://onboard.blocknative.com/'
}
)}>Update appMetadata</button
})}>Update appMetadata</button
>
</div>
</div>
Expand Down
55 changes: 30 additions & 25 deletions packages/ledger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,44 @@
### Options

```typescript
interface LedgerOptions {
type LedgerOptionsWCv1 = {
/**
* Enable Ledger Connect Kit logs
* @deprecated
* Version 1 of WalletConnect has been deprecated by the WC team and the WC bridge is not available.
* To use version 1 a custom bridge url will need to be provided.
* Support will be completely remove from Web3-Onboard in the future
*/
walletConnectVersion?: 1
enableDebugLogs?: boolean
/**
* Defaults to walletConnectVersion: 1 - this behavior will be deprecated after the WalletConnect v1 sunset
*/
chainId?: number
bridge?: string
infuraId?: string
rpc?: { [chainId: number]: string }
}

type LedgerOptionsWCv2 = {
walletConnectVersion: 2
enableDebugLogs?: boolean
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
projectId: string
/**
* List of Required Chain IDs for Ledger Live to support in number format (integer or hex)
* Defaults to [1] - Ethereum
* The chains defined within the web3-onboard config will define the
* optional chains for the WalletConnect module
* List of Optional Chain(s) ID for wallets to support in number format (integer or hex)
* Defaults to the chains provided within the web3-onboard init chain property
*/
requiredChains?: string[] | number[]
/**
* List of Required Methods for wallets to support
*/
requiredMethods?: string[]
/**
* List of Optional Methods for wallets to support
* Additional methods to be added to the default list of ['eth_sendTransaction', 'eth_signTransaction', 'personal_sign', 'eth_sign', 'eth_signTypedData', 'eth_signTypedData_v4']
* Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
*/
optionalMethods?: string[]
/**
* List of Required Events for wallets to support
*/
requiredEvents?: string[]
/**
* List of Optional Events for wallets to support
*/
optionalEvents?: string[]
/**
* List of Chain ID to URL mapping
*/
rpcMap?: { [chainId: number]: string }
}

type LedgerOptions = LedgerOptionsWCv1 | LedgerOptionsWCv2
```

### Usage
Expand All @@ -59,7 +56,6 @@ import Onboard from '@web3-onboard/core'
import ledgerModule from '@web3-onboard/ledger'

const ledger = ledgerModule({
walletConnectVersion: 2,
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
Expand Down Expand Up @@ -90,7 +86,16 @@ You may decide that on certain platforms you do not want to display this wallet
import Onboard from '@web3-onboard/core'
import ledgerModule from '@web3-onboard/ledger'

const ledger = ledgerModule()
const ledger = ledgerModule({
/**
* Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
*/
projectId: 'abc123...',
/**
* Chains required to be supported by all wallets connecting to your DApp
*/
requiredChains: [1, 137]
})

const onboard = Onboard({
// ... other Onboard options
Expand Down
4 changes: 3 additions & 1 deletion packages/ledger/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@web3-onboard/ledger",
"version": "2.5.0-alpha.1",
"description": "Ledger hardare wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"description": "Ledger hardware wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"keywords": [
"Ethereum",
"Web3",
Expand Down Expand Up @@ -61,6 +61,8 @@
"dependencies": {
"@ledgerhq/connect-kit-loader": "^1.1.0",
"@walletconnect/client": "^1.8.0",
"@walletconnect/ethereum-provider": "2.8.4",
"@walletconnect/modal":"2.5.4",
"@web3-onboard/common": "^2.3.3",
"rxjs": "^7.5.2"
}
Expand Down
Loading